highmaps.src.js 523 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license Highmaps JS v1.1.9 (2015-10-07)
  5. *
  6. * (c) 2009-2014 Torstein Honsi
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. // JSLint options:
  11. /*global Highcharts, HighchartsAdapter, document, window, navigator, setInterval, clearInterval, clearTimeout, setTimeout, location, jQuery, $, console, each, grep */
  12. /*jslint ass: true, sloppy: true, forin: true, plusplus: true, nomen: true, vars: true, regexp: true, newcap: true, browser: true, continue: true, white: true */
  13. (function () {
  14. // encapsulated variables
  15. var UNDEFINED,
  16. doc = document,
  17. win = window,
  18. math = Math,
  19. mathRound = math.round,
  20. mathFloor = math.floor,
  21. mathCeil = math.ceil,
  22. mathMax = math.max,
  23. mathMin = math.min,
  24. mathAbs = math.abs,
  25. mathCos = math.cos,
  26. mathSin = math.sin,
  27. mathPI = math.PI,
  28. deg2rad = mathPI * 2 / 360,
  29. // some variables
  30. userAgent = navigator.userAgent,
  31. isOpera = win.opera,
  32. isMS = /(msie|trident|edge)/i.test(userAgent) && !isOpera,
  33. docMode8 = doc.documentMode === 8,
  34. isWebKit = !isMS && /AppleWebKit/.test(userAgent),
  35. isFirefox = /Firefox/.test(userAgent),
  36. isTouchDevice = /(Mobile|Android|Windows Phone)/.test(userAgent),
  37. SVG_NS = 'http://www.w3.org/2000/svg',
  38. hasSVG = !!doc.createElementNS && !!doc.createElementNS(SVG_NS, 'svg').createSVGRect,
  39. hasBidiBug = isFirefox && parseInt(userAgent.split('Firefox/')[1], 10) < 4, // issue #38
  40. useCanVG = !hasSVG && !isMS && !!doc.createElement('canvas').getContext,
  41. Renderer,
  42. hasTouch,
  43. symbolSizes = {},
  44. idCounter = 0,
  45. garbageBin,
  46. defaultOptions,
  47. dateFormat, // function
  48. pathAnim,
  49. timeUnits,
  50. noop = function () { return UNDEFINED; },
  51. charts = [],
  52. chartCount = 0,
  53. PRODUCT = 'Highmaps',
  54. VERSION = '1.1.9',
  55. // some constants for frequently used strings
  56. DIV = 'div',
  57. ABSOLUTE = 'absolute',
  58. RELATIVE = 'relative',
  59. HIDDEN = 'hidden',
  60. PREFIX = 'highcharts-',
  61. VISIBLE = 'visible',
  62. PX = 'px',
  63. NONE = 'none',
  64. M = 'M',
  65. L = 'L',
  66. numRegex = /^[0-9]+$/,
  67. NORMAL_STATE = '',
  68. HOVER_STATE = 'hover',
  69. SELECT_STATE = 'select',
  70. marginNames = ['plotTop', 'marginRight', 'marginBottom', 'plotLeft'],
  71. // Object for extending Axis
  72. AxisPlotLineOrBandExtension,
  73. // constants for attributes
  74. STROKE_WIDTH = 'stroke-width',
  75. // time methods, changed based on whether or not UTC is used
  76. Date, // Allow using a different Date class
  77. makeTime,
  78. timezoneOffset,
  79. getTimezoneOffset,
  80. getMinutes,
  81. getHours,
  82. getDay,
  83. getDate,
  84. getMonth,
  85. getFullYear,
  86. setMilliseconds,
  87. setSeconds,
  88. setMinutes,
  89. setHours,
  90. setDate,
  91. setMonth,
  92. setFullYear,
  93. // lookup over the types and the associated classes
  94. seriesTypes = {},
  95. Highcharts;
  96. // The Highcharts namespace
  97. Highcharts = win.Highcharts = win.Highcharts ? error(16, true) : {};
  98. Highcharts.seriesTypes = seriesTypes;
  99. /**
  100. * Extend an object with the members of another
  101. * @param {Object} a The object to be extended
  102. * @param {Object} b The object to add to the first one
  103. */
  104. var extend = Highcharts.extend = function (a, b) {
  105. var n;
  106. if (!a) {
  107. a = {};
  108. }
  109. for (n in b) {
  110. a[n] = b[n];
  111. }
  112. return a;
  113. };
  114. /**
  115. * Deep merge two or more objects and return a third object. If the first argument is
  116. * true, the contents of the second object is copied into the first object.
  117. * Previously this function redirected to jQuery.extend(true), but this had two limitations.
  118. * First, it deep merged arrays, which lead to workarounds in Highcharts. Second,
  119. * it copied properties from extended prototypes.
  120. */
  121. function merge() {
  122. var i,
  123. args = arguments,
  124. len,
  125. ret = {},
  126. doCopy = function (copy, original) {
  127. var value, key;
  128. // An object is replacing a primitive
  129. if (typeof copy !== 'object') {
  130. copy = {};
  131. }
  132. for (key in original) {
  133. if (original.hasOwnProperty(key)) {
  134. value = original[key];
  135. // Copy the contents of objects, but not arrays or DOM nodes
  136. if (value && typeof value === 'object' && Object.prototype.toString.call(value) !== '[object Array]' &&
  137. key !== 'renderTo' && typeof value.nodeType !== 'number') {
  138. copy[key] = doCopy(copy[key] || {}, value);
  139. // Primitives and arrays are copied over directly
  140. } else {
  141. copy[key] = original[key];
  142. }
  143. }
  144. }
  145. return copy;
  146. };
  147. // If first argument is true, copy into the existing object. Used in setOptions.
  148. if (args[0] === true) {
  149. ret = args[1];
  150. args = Array.prototype.slice.call(args, 2);
  151. }
  152. // For each argument, extend the return
  153. len = args.length;
  154. for (i = 0; i < len; i++) {
  155. ret = doCopy(ret, args[i]);
  156. }
  157. return ret;
  158. }
  159. /**
  160. * Shortcut for parseInt
  161. * @param {Object} s
  162. * @param {Number} mag Magnitude
  163. */
  164. function pInt(s, mag) {
  165. return parseInt(s, mag || 10);
  166. }
  167. /**
  168. * Check for string
  169. * @param {Object} s
  170. */
  171. function isString(s) {
  172. return typeof s === 'string';
  173. }
  174. /**
  175. * Check for object
  176. * @param {Object} obj
  177. */
  178. function isObject(obj) {
  179. return obj && typeof obj === 'object';
  180. }
  181. /**
  182. * Check for array
  183. * @param {Object} obj
  184. */
  185. function isArray(obj) {
  186. return Object.prototype.toString.call(obj) === '[object Array]';
  187. }
  188. /**
  189. * Check for number
  190. * @param {Object} n
  191. */
  192. function isNumber(n) {
  193. return typeof n === 'number';
  194. }
  195. function log2lin(num) {
  196. return math.log(num) / math.LN10;
  197. }
  198. function lin2log(num) {
  199. return math.pow(10, num);
  200. }
  201. /**
  202. * Remove last occurence of an item from an array
  203. * @param {Array} arr
  204. * @param {Mixed} item
  205. */
  206. function erase(arr, item) {
  207. var i = arr.length;
  208. while (i--) {
  209. if (arr[i] === item) {
  210. arr.splice(i, 1);
  211. break;
  212. }
  213. }
  214. //return arr;
  215. }
  216. /**
  217. * Returns true if the object is not null or undefined. Like MooTools' $.defined.
  218. * @param {Object} obj
  219. */
  220. function defined(obj) {
  221. return obj !== UNDEFINED && obj !== null;
  222. }
  223. /**
  224. * Set or get an attribute or an object of attributes. Can't use jQuery attr because
  225. * it attempts to set expando properties on the SVG element, which is not allowed.
  226. *
  227. * @param {Object} elem The DOM element to receive the attribute(s)
  228. * @param {String|Object} prop The property or an abject of key-value pairs
  229. * @param {String} value The value if a single property is set
  230. */
  231. function attr(elem, prop, value) {
  232. var key,
  233. ret;
  234. // if the prop is a string
  235. if (isString(prop)) {
  236. // set the value
  237. if (defined(value)) {
  238. elem.setAttribute(prop, value);
  239. // get the value
  240. } else if (elem && elem.getAttribute) { // elem not defined when printing pie demo...
  241. ret = elem.getAttribute(prop);
  242. }
  243. // else if prop is defined, it is a hash of key/value pairs
  244. } else if (defined(prop) && isObject(prop)) {
  245. for (key in prop) {
  246. elem.setAttribute(key, prop[key]);
  247. }
  248. }
  249. return ret;
  250. }
  251. /**
  252. * Check if an element is an array, and if not, make it into an array. Like
  253. * MooTools' $.splat.
  254. */
  255. function splat(obj) {
  256. return isArray(obj) ? obj : [obj];
  257. }
  258. /**
  259. * Return the first value that is defined. Like MooTools' $.pick.
  260. */
  261. var pick = Highcharts.pick = function () {
  262. var args = arguments,
  263. i,
  264. arg,
  265. length = args.length;
  266. for (i = 0; i < length; i++) {
  267. arg = args[i];
  268. if (arg !== UNDEFINED && arg !== null) {
  269. return arg;
  270. }
  271. }
  272. };
  273. /**
  274. * Set CSS on a given element
  275. * @param {Object} el
  276. * @param {Object} styles Style object with camel case property names
  277. */
  278. function css(el, styles) {
  279. if (isMS && !hasSVG) { // #2686
  280. if (styles && styles.opacity !== UNDEFINED) {
  281. styles.filter = 'alpha(opacity=' + (styles.opacity * 100) + ')';
  282. }
  283. }
  284. extend(el.style, styles);
  285. }
  286. /**
  287. * Utility function to create element with attributes and styles
  288. * @param {Object} tag
  289. * @param {Object} attribs
  290. * @param {Object} styles
  291. * @param {Object} parent
  292. * @param {Object} nopad
  293. */
  294. function createElement(tag, attribs, styles, parent, nopad) {
  295. var el = doc.createElement(tag);
  296. if (attribs) {
  297. extend(el, attribs);
  298. }
  299. if (nopad) {
  300. css(el, {padding: 0, border: NONE, margin: 0});
  301. }
  302. if (styles) {
  303. css(el, styles);
  304. }
  305. if (parent) {
  306. parent.appendChild(el);
  307. }
  308. return el;
  309. }
  310. /**
  311. * Extend a prototyped class by new members
  312. * @param {Object} parent
  313. * @param {Object} members
  314. */
  315. function extendClass(parent, members) {
  316. var object = function () { return UNDEFINED; };
  317. object.prototype = new parent();
  318. extend(object.prototype, members);
  319. return object;
  320. }
  321. /**
  322. * Pad a string to a given length by adding 0 to the beginning
  323. * @param {Number} number
  324. * @param {Number} length
  325. */
  326. function pad(number, length) {
  327. // Create an array of the remaining length +1 and join it with 0's
  328. return new Array((length || 2) + 1 - String(number).length).join(0) + number;
  329. }
  330. /**
  331. * Return a length based on either the integer value, or a percentage of a base.
  332. */
  333. function relativeLength (value, base) {
  334. return (/%$/).test(value) ? base * parseFloat(value) / 100 : parseFloat(value);
  335. }
  336. /**
  337. * Wrap a method with extended functionality, preserving the original function
  338. * @param {Object} obj The context object that the method belongs to
  339. * @param {String} method The name of the method to extend
  340. * @param {Function} func A wrapper function callback. This function is called with the same arguments
  341. * as the original function, except that the original function is unshifted and passed as the first
  342. * argument.
  343. */
  344. var wrap = Highcharts.wrap = function (obj, method, func) {
  345. var proceed = obj[method];
  346. obj[method] = function () {
  347. var args = Array.prototype.slice.call(arguments);
  348. args.unshift(proceed);
  349. return func.apply(this, args);
  350. };
  351. };
  352. function getTZOffset(timestamp) {
  353. return ((getTimezoneOffset && getTimezoneOffset(timestamp)) || timezoneOffset || 0) * 60000;
  354. }
  355. /**
  356. * Based on http://www.php.net/manual/en/function.strftime.php
  357. * @param {String} format
  358. * @param {Number} timestamp
  359. * @param {Boolean} capitalize
  360. */
  361. dateFormat = function (format, timestamp, capitalize) {
  362. if (!defined(timestamp) || isNaN(timestamp)) {
  363. return defaultOptions.lang.invalidDate || '';
  364. }
  365. format = pick(format, '%Y-%m-%d %H:%M:%S');
  366. var date = new Date(timestamp - getTZOffset(timestamp)),
  367. key, // used in for constuct below
  368. // get the basic time values
  369. hours = date[getHours](),
  370. day = date[getDay](),
  371. dayOfMonth = date[getDate](),
  372. month = date[getMonth](),
  373. fullYear = date[getFullYear](),
  374. lang = defaultOptions.lang,
  375. langWeekdays = lang.weekdays,
  376. // List all format keys. Custom formats can be added from the outside.
  377. replacements = extend({
  378. // Day
  379. 'a': langWeekdays[day].substr(0, 3), // Short weekday, like 'Mon'
  380. 'A': langWeekdays[day], // Long weekday, like 'Monday'
  381. 'd': pad(dayOfMonth), // Two digit day of the month, 01 to 31
  382. 'e': dayOfMonth, // Day of the month, 1 through 31
  383. 'w': day,
  384. // Week (none implemented)
  385. //'W': weekNumber(),
  386. // Month
  387. 'b': lang.shortMonths[month], // Short month, like 'Jan'
  388. 'B': lang.months[month], // Long month, like 'January'
  389. 'm': pad(month + 1), // Two digit month number, 01 through 12
  390. // Year
  391. 'y': fullYear.toString().substr(2, 2), // Two digits year, like 09 for 2009
  392. 'Y': fullYear, // Four digits year, like 2009
  393. // Time
  394. 'H': pad(hours), // Two digits hours in 24h format, 00 through 23
  395. 'k': hours, // Hours in 24h format, 0 through 23
  396. 'I': pad((hours % 12) || 12), // Two digits hours in 12h format, 00 through 11
  397. 'l': (hours % 12) || 12, // Hours in 12h format, 1 through 12
  398. 'M': pad(date[getMinutes]()), // Two digits minutes, 00 through 59
  399. 'p': hours < 12 ? 'AM' : 'PM', // Upper case AM or PM
  400. 'P': hours < 12 ? 'am' : 'pm', // Lower case AM or PM
  401. 'S': pad(date.getSeconds()), // Two digits seconds, 00 through 59
  402. 'L': pad(mathRound(timestamp % 1000), 3) // Milliseconds (naming from Ruby)
  403. }, Highcharts.dateFormats);
  404. // do the replaces
  405. for (key in replacements) {
  406. while (format.indexOf('%' + key) !== -1) { // regex would do it in one line, but this is faster
  407. format = format.replace('%' + key, typeof replacements[key] === 'function' ? replacements[key](timestamp) : replacements[key]);
  408. }
  409. }
  410. // Optionally capitalize the string and return
  411. return capitalize ? format.substr(0, 1).toUpperCase() + format.substr(1) : format;
  412. };
  413. /**
  414. * Format a single variable. Similar to sprintf, without the % prefix.
  415. */
  416. function formatSingle(format, val) {
  417. var floatRegex = /f$/,
  418. decRegex = /\.([0-9])/,
  419. lang = defaultOptions.lang,
  420. decimals;
  421. if (floatRegex.test(format)) { // float
  422. decimals = format.match(decRegex);
  423. decimals = decimals ? decimals[1] : -1;
  424. if (val !== null) {
  425. val = Highcharts.numberFormat(
  426. val,
  427. decimals,
  428. lang.decimalPoint,
  429. format.indexOf(',') > -1 ? lang.thousandsSep : ''
  430. );
  431. }
  432. } else {
  433. val = dateFormat(format, val);
  434. }
  435. return val;
  436. }
  437. /**
  438. * Format a string according to a subset of the rules of Python's String.format method.
  439. */
  440. function format(str, ctx) {
  441. var splitter = '{',
  442. isInside = false,
  443. segment,
  444. valueAndFormat,
  445. path,
  446. i,
  447. len,
  448. ret = [],
  449. val,
  450. index;
  451. while ((index = str.indexOf(splitter)) !== -1) {
  452. segment = str.slice(0, index);
  453. if (isInside) { // we're on the closing bracket looking back
  454. valueAndFormat = segment.split(':');
  455. path = valueAndFormat.shift().split('.'); // get first and leave format
  456. len = path.length;
  457. val = ctx;
  458. // Assign deeper paths
  459. for (i = 0; i < len; i++) {
  460. val = val[path[i]];
  461. }
  462. // Format the replacement
  463. if (valueAndFormat.length) {
  464. val = formatSingle(valueAndFormat.join(':'), val);
  465. }
  466. // Push the result and advance the cursor
  467. ret.push(val);
  468. } else {
  469. ret.push(segment);
  470. }
  471. str = str.slice(index + 1); // the rest
  472. isInside = !isInside; // toggle
  473. splitter = isInside ? '}' : '{'; // now look for next matching bracket
  474. }
  475. ret.push(str);
  476. return ret.join('');
  477. }
  478. /**
  479. * Get the magnitude of a number
  480. */
  481. function getMagnitude(num) {
  482. return math.pow(10, mathFloor(math.log(num) / math.LN10));
  483. }
  484. /**
  485. * Take an interval and normalize it to multiples of 1, 2, 2.5 and 5
  486. * @param {Number} interval
  487. * @param {Array} multiples
  488. * @param {Number} magnitude
  489. * @param {Object} options
  490. */
  491. function normalizeTickInterval(interval, multiples, magnitude, allowDecimals, preventExceed) {
  492. var normalized,
  493. i,
  494. retInterval = interval;
  495. // round to a tenfold of 1, 2, 2.5 or 5
  496. magnitude = pick(magnitude, 1);
  497. normalized = interval / magnitude;
  498. // multiples for a linear scale
  499. if (!multiples) {
  500. multiples = [1, 2, 2.5, 5, 10];
  501. // the allowDecimals option
  502. if (allowDecimals === false) {
  503. if (magnitude === 1) {
  504. multiples = [1, 2, 5, 10];
  505. } else if (magnitude <= 0.1) {
  506. multiples = [1 / magnitude];
  507. }
  508. }
  509. }
  510. // normalize the interval to the nearest multiple
  511. for (i = 0; i < multiples.length; i++) {
  512. retInterval = multiples[i];
  513. if ((preventExceed && retInterval * magnitude >= interval) || // only allow tick amounts smaller than natural
  514. (!preventExceed && (normalized <= (multiples[i] + (multiples[i + 1] || multiples[i])) / 2))) {
  515. break;
  516. }
  517. }
  518. // multiply back to the correct magnitude
  519. retInterval *= magnitude;
  520. return retInterval;
  521. }
  522. /**
  523. * Utility method that sorts an object array and keeping the order of equal items.
  524. * ECMA script standard does not specify the behaviour when items are equal.
  525. */
  526. function stableSort(arr, sortFunction) {
  527. var length = arr.length,
  528. sortValue,
  529. i;
  530. // Add index to each item
  531. for (i = 0; i < length; i++) {
  532. arr[i].ss_i = i; // stable sort index
  533. }
  534. arr.sort(function (a, b) {
  535. sortValue = sortFunction(a, b);
  536. return sortValue === 0 ? a.ss_i - b.ss_i : sortValue;
  537. });
  538. // Remove index from items
  539. for (i = 0; i < length; i++) {
  540. delete arr[i].ss_i; // stable sort index
  541. }
  542. }
  543. /**
  544. * Non-recursive method to find the lowest member of an array. Math.min raises a maximum
  545. * call stack size exceeded error in Chrome when trying to apply more than 150.000 points. This
  546. * method is slightly slower, but safe.
  547. */
  548. function arrayMin(data) {
  549. var i = data.length,
  550. min = data[0];
  551. while (i--) {
  552. if (data[i] < min) {
  553. min = data[i];
  554. }
  555. }
  556. return min;
  557. }
  558. /**
  559. * Non-recursive method to find the lowest member of an array. Math.min raises a maximum
  560. * call stack size exceeded error in Chrome when trying to apply more than 150.000 points. This
  561. * method is slightly slower, but safe.
  562. */
  563. function arrayMax(data) {
  564. var i = data.length,
  565. max = data[0];
  566. while (i--) {
  567. if (data[i] > max) {
  568. max = data[i];
  569. }
  570. }
  571. return max;
  572. }
  573. /**
  574. * Utility method that destroys any SVGElement or VMLElement that are properties on the given object.
  575. * It loops all properties and invokes destroy if there is a destroy method. The property is
  576. * then delete'ed.
  577. * @param {Object} The object to destroy properties on
  578. * @param {Object} Exception, do not destroy this property, only delete it.
  579. */
  580. function destroyObjectProperties(obj, except) {
  581. var n;
  582. for (n in obj) {
  583. // If the object is non-null and destroy is defined
  584. if (obj[n] && obj[n] !== except && obj[n].destroy) {
  585. // Invoke the destroy
  586. obj[n].destroy();
  587. }
  588. // Delete the property from the object.
  589. delete obj[n];
  590. }
  591. }
  592. /**
  593. * Discard an element by moving it to the bin and delete
  594. * @param {Object} The HTML node to discard
  595. */
  596. function discardElement(element) {
  597. // create a garbage bin element, not part of the DOM
  598. if (!garbageBin) {
  599. garbageBin = createElement(DIV);
  600. }
  601. // move the node and empty bin
  602. if (element) {
  603. garbageBin.appendChild(element);
  604. }
  605. garbageBin.innerHTML = '';
  606. }
  607. /**
  608. * Provide error messages for debugging, with links to online explanation
  609. */
  610. function error (code, stop) {
  611. var msg = 'Highcharts error #' + code + ': www.highcharts.com/errors/' + code;
  612. if (stop) {
  613. throw msg;
  614. }
  615. // else ...
  616. if (win.console) {
  617. console.log(msg);
  618. }
  619. }
  620. /**
  621. * Fix JS round off float errors
  622. * @param {Number} num
  623. */
  624. function correctFloat(num, prec) {
  625. return parseFloat(
  626. num.toPrecision(prec || 14)
  627. );
  628. }
  629. /**
  630. * Set the global animation to either a given value, or fall back to the
  631. * given chart's animation option
  632. * @param {Object} animation
  633. * @param {Object} chart
  634. */
  635. function setAnimation(animation, chart) {
  636. chart.renderer.globalAnimation = pick(animation, chart.animation);
  637. }
  638. /**
  639. * The time unit lookup
  640. */
  641. timeUnits = {
  642. millisecond: 1,
  643. second: 1000,
  644. minute: 60000,
  645. hour: 3600000,
  646. day: 24 * 3600000,
  647. week: 7 * 24 * 3600000,
  648. month: 28 * 24 * 3600000,
  649. year: 364 * 24 * 3600000
  650. };
  651. /**
  652. * Format a number and return a string based on input settings
  653. * @param {Number} number The input number to format
  654. * @param {Number} decimals The amount of decimals
  655. * @param {String} decPoint The decimal point, defaults to the one given in the lang options
  656. * @param {String} thousandsSep The thousands separator, defaults to the one given in the lang options
  657. */
  658. Highcharts.numberFormat = function (number, decimals, decPoint, thousandsSep) {
  659. var lang = defaultOptions.lang,
  660. // http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_number_format/
  661. n = +number || 0,
  662. c = decimals === -1 ?
  663. mathMin((n.toString().split('.')[1] || '').length, 20) : // Preserve decimals. Not huge numbers (#3793).
  664. (isNaN(decimals = mathAbs(decimals)) ? 2 : decimals),
  665. d = decPoint === undefined ? lang.decimalPoint : decPoint,
  666. t = thousandsSep === undefined ? lang.thousandsSep : thousandsSep,
  667. s = n < 0 ? "-" : "",
  668. i = String(pInt(n = mathAbs(n).toFixed(c))),
  669. j = i.length > 3 ? i.length % 3 : 0;
  670. return (s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) +
  671. (c ? d + mathAbs(n - i).toFixed(c).slice(2) : ""));
  672. };
  673. /**
  674. * Path interpolation algorithm used across adapters
  675. */
  676. pathAnim = {
  677. /**
  678. * Prepare start and end values so that the path can be animated one to one
  679. */
  680. init: function (elem, fromD, toD) {
  681. fromD = fromD || '';
  682. var shift = elem.shift,
  683. bezier = fromD.indexOf('C') > -1,
  684. numParams = bezier ? 7 : 3,
  685. endLength,
  686. slice,
  687. i,
  688. start = fromD.split(' '),
  689. end = [].concat(toD), // copy
  690. startBaseLine,
  691. endBaseLine,
  692. sixify = function (arr) { // in splines make move points have six parameters like bezier curves
  693. i = arr.length;
  694. while (i--) {
  695. if (arr[i] === M) {
  696. arr.splice(i + 1, 0, arr[i + 1], arr[i + 2], arr[i + 1], arr[i + 2]);
  697. }
  698. }
  699. };
  700. if (bezier) {
  701. sixify(start);
  702. sixify(end);
  703. }
  704. // pull out the base lines before padding
  705. if (elem.isArea) {
  706. startBaseLine = start.splice(start.length - 6, 6);
  707. endBaseLine = end.splice(end.length - 6, 6);
  708. }
  709. // if shifting points, prepend a dummy point to the end path
  710. if (shift <= end.length / numParams && start.length === end.length) {
  711. while (shift--) {
  712. end = [].concat(end).splice(0, numParams).concat(end);
  713. }
  714. }
  715. elem.shift = 0; // reset for following animations
  716. // copy and append last point until the length matches the end length
  717. if (start.length) {
  718. endLength = end.length;
  719. while (start.length < endLength) {
  720. //bezier && sixify(start);
  721. slice = [].concat(start).splice(start.length - numParams, numParams);
  722. if (bezier) { // disable first control point
  723. slice[numParams - 6] = slice[numParams - 2];
  724. slice[numParams - 5] = slice[numParams - 1];
  725. }
  726. start = start.concat(slice);
  727. }
  728. }
  729. if (startBaseLine) { // append the base lines for areas
  730. start = start.concat(startBaseLine);
  731. end = end.concat(endBaseLine);
  732. }
  733. return [start, end];
  734. },
  735. /**
  736. * Interpolate each value of the path and return the array
  737. */
  738. step: function (start, end, pos, complete) {
  739. var ret = [],
  740. i = start.length,
  741. startVal;
  742. if (pos === 1) { // land on the final path without adjustment points appended in the ends
  743. ret = complete;
  744. } else if (i === end.length && pos < 1) {
  745. while (i--) {
  746. startVal = parseFloat(start[i]);
  747. ret[i] =
  748. isNaN(startVal) ? // a letter instruction like M or L
  749. start[i] :
  750. pos * (parseFloat(end[i] - startVal)) + startVal;
  751. }
  752. } else { // if animation is finished or length not matching, land on right value
  753. ret = end;
  754. }
  755. return ret;
  756. }
  757. };
  758. (function ($) {
  759. /**
  760. * The default HighchartsAdapter for jQuery
  761. */
  762. win.HighchartsAdapter = win.HighchartsAdapter || ($ && {
  763. /**
  764. * Initialize the adapter by applying some extensions to jQuery
  765. */
  766. init: function (pathAnim) {
  767. // extend the animate function to allow SVG animations
  768. var Fx = $.fx;
  769. /*jslint unparam: true*//* allow unused param x in this function */
  770. $.extend($.easing, {
  771. easeOutQuad: function (x, t, b, c, d) {
  772. return -c * (t /= d) * (t - 2) + b;
  773. }
  774. });
  775. /*jslint unparam: false*/
  776. // extend some methods to check for elem.attr, which means it is a Highcharts SVG object
  777. $.each(['cur', '_default', 'width', 'height', 'opacity'], function (i, fn) {
  778. var obj = Fx.step,
  779. base;
  780. // Handle different parent objects
  781. if (fn === 'cur') {
  782. obj = Fx.prototype; // 'cur', the getter, relates to Fx.prototype
  783. } else if (fn === '_default' && $.Tween) { // jQuery 1.8 model
  784. obj = $.Tween.propHooks[fn];
  785. fn = 'set';
  786. }
  787. // Overwrite the method
  788. base = obj[fn];
  789. if (base) { // step.width and step.height don't exist in jQuery < 1.7
  790. // create the extended function replacement
  791. obj[fn] = function (fx) {
  792. var elem;
  793. // Fx.prototype.cur does not use fx argument
  794. fx = i ? fx : this;
  795. // Don't run animations on textual properties like align (#1821)
  796. if (fx.prop === 'align') {
  797. return;
  798. }
  799. // shortcut
  800. elem = fx.elem;
  801. // Fx.prototype.cur returns the current value. The other ones are setters
  802. // and returning a value has no effect.
  803. return elem.attr ? // is SVG element wrapper
  804. elem.attr(fx.prop, fn === 'cur' ? UNDEFINED : fx.now) : // apply the SVG wrapper's method
  805. base.apply(this, arguments); // use jQuery's built-in method
  806. };
  807. }
  808. });
  809. // Extend the opacity getter, needed for fading opacity with IE9 and jQuery 1.10+
  810. wrap($.cssHooks.opacity, 'get', function (proceed, elem, computed) {
  811. return elem.attr ? (elem.opacity || 0) : proceed.call(this, elem, computed);
  812. });
  813. // Define the setter function for d (path definitions)
  814. this.addAnimSetter('d', function (fx) {
  815. var elem = fx.elem,
  816. ends;
  817. // Normally start and end should be set in state == 0, but sometimes,
  818. // for reasons unknown, this doesn't happen. Perhaps state == 0 is skipped
  819. // in these cases
  820. if (!fx.started) {
  821. ends = pathAnim.init(elem, elem.d, elem.toD);
  822. fx.start = ends[0];
  823. fx.end = ends[1];
  824. fx.started = true;
  825. }
  826. // Interpolate each value of the path
  827. elem.attr('d', pathAnim.step(fx.start, fx.end, fx.pos, elem.toD));
  828. });
  829. /**
  830. * Utility for iterating over an array. Parameters are reversed compared to jQuery.
  831. * @param {Array} arr
  832. * @param {Function} fn
  833. */
  834. this.each = Array.prototype.forEach ?
  835. function (arr, fn) { // modern browsers
  836. return Array.prototype.forEach.call(arr, fn);
  837. } :
  838. function (arr, fn) { // legacy
  839. var i,
  840. len = arr.length;
  841. for (i = 0; i < len; i++) {
  842. if (fn.call(arr[i], arr[i], i, arr) === false) {
  843. return i;
  844. }
  845. }
  846. };
  847. /**
  848. * Register Highcharts as a plugin in the respective framework
  849. */
  850. $.fn.highcharts = function () {
  851. var constr = 'Chart', // default constructor
  852. args = arguments,
  853. options,
  854. ret,
  855. chart;
  856. if (this[0]) {
  857. if (isString(args[0])) {
  858. constr = args[0];
  859. args = Array.prototype.slice.call(args, 1);
  860. }
  861. options = args[0];
  862. // Create the chart
  863. if (options !== UNDEFINED) {
  864. /*jslint unused:false*/
  865. options.chart = options.chart || {};
  866. options.chart.renderTo = this[0];
  867. chart = new Highcharts[constr](options, args[1]);
  868. ret = this;
  869. /*jslint unused:true*/
  870. }
  871. // When called without parameters or with the return argument, get a predefined chart
  872. if (options === UNDEFINED) {
  873. ret = charts[attr(this[0], 'data-highcharts-chart')];
  874. }
  875. }
  876. return ret;
  877. };
  878. },
  879. /**
  880. * Add an animation setter for a specific property
  881. */
  882. addAnimSetter: function (prop, setter) {
  883. // jQuery 1.8 style
  884. if ($.Tween) {
  885. $.Tween.propHooks[prop] = {
  886. set: setter
  887. };
  888. // pre 1.8
  889. } else {
  890. $.fx.step[prop] = setter;
  891. }
  892. },
  893. /**
  894. * Downloads a script and executes a callback when done.
  895. * @param {String} scriptLocation
  896. * @param {Function} callback
  897. */
  898. getScript: $.getScript,
  899. /**
  900. * Return the index of an item in an array, or -1 if not found
  901. */
  902. inArray: $.inArray,
  903. /**
  904. * A direct link to jQuery methods. MooTools and Prototype adapters must be implemented for each case of method.
  905. * @param {Object} elem The HTML element
  906. * @param {String} method Which method to run on the wrapped element
  907. */
  908. adapterRun: function (elem, method) {
  909. return $(elem)[method]();
  910. },
  911. /**
  912. * Filter an array
  913. */
  914. grep: $.grep,
  915. /**
  916. * Map an array
  917. * @param {Array} arr
  918. * @param {Function} fn
  919. */
  920. map: function (arr, fn) {
  921. //return jQuery.map(arr, fn);
  922. var results = [],
  923. i = 0,
  924. len = arr.length;
  925. for (; i < len; i++) {
  926. results[i] = fn.call(arr[i], arr[i], i, arr);
  927. }
  928. return results;
  929. },
  930. /**
  931. * Get the position of an element relative to the top left of the page
  932. */
  933. offset: function (el) {
  934. return $(el).offset();
  935. },
  936. /**
  937. * Add an event listener
  938. * @param {Object} el A HTML element or custom object
  939. * @param {String} event The event type
  940. * @param {Function} fn The event handler
  941. */
  942. addEvent: function (el, event, fn) {
  943. $(el).bind(event, fn);
  944. },
  945. /**
  946. * Remove event added with addEvent
  947. * @param {Object} el The object
  948. * @param {String} eventType The event type. Leave blank to remove all events.
  949. * @param {Function} handler The function to remove
  950. */
  951. removeEvent: function (el, eventType, handler) {
  952. // workaround for jQuery issue with unbinding custom events:
  953. // http://forum.jQuery.com/topic/javascript-error-when-unbinding-a-custom-event-using-jQuery-1-4-2
  954. var func = doc.removeEventListener ? 'removeEventListener' : 'detachEvent';
  955. if (doc[func] && el && !el[func]) {
  956. el[func] = function () {};
  957. }
  958. $(el).unbind(eventType, handler);
  959. },
  960. /**
  961. * Fire an event on a custom object
  962. * @param {Object} el
  963. * @param {String} type
  964. * @param {Object} eventArguments
  965. * @param {Function} defaultFunction
  966. */
  967. fireEvent: function (el, type, eventArguments, defaultFunction) {
  968. var event = $.Event(type),
  969. detachedType = 'detached' + type,
  970. defaultPrevented;
  971. // Remove warnings in Chrome when accessing returnValue (#2790), layerX and layerY. Although Highcharts
  972. // never uses these properties, Chrome includes them in the default click event and
  973. // raises the warning when they are copied over in the extend statement below.
  974. //
  975. // To avoid problems in IE (see #1010) where we cannot delete the properties and avoid
  976. // testing if they are there (warning in chrome) the only option is to test if running IE.
  977. if (!isMS && eventArguments) {
  978. delete eventArguments.layerX;
  979. delete eventArguments.layerY;
  980. delete eventArguments.returnValue;
  981. }
  982. extend(event, eventArguments);
  983. // Prevent jQuery from triggering the object method that is named the
  984. // same as the event. For example, if the event is 'select', jQuery
  985. // attempts calling el.select and it goes into a loop.
  986. if (el[type]) {
  987. el[detachedType] = el[type];
  988. el[type] = null;
  989. }
  990. // Wrap preventDefault and stopPropagation in try/catch blocks in
  991. // order to prevent JS errors when cancelling events on non-DOM
  992. // objects. #615.
  993. /*jslint unparam: true*/
  994. $.each(['preventDefault', 'stopPropagation'], function (i, fn) {
  995. var base = event[fn];
  996. event[fn] = function () {
  997. try {
  998. base.call(event);
  999. } catch (e) {
  1000. if (fn === 'preventDefault') {
  1001. defaultPrevented = true;
  1002. }
  1003. }
  1004. };
  1005. });
  1006. /*jslint unparam: false*/
  1007. // trigger it
  1008. $(el).trigger(event);
  1009. // attach the method
  1010. if (el[detachedType]) {
  1011. el[type] = el[detachedType];
  1012. el[detachedType] = null;
  1013. }
  1014. if (defaultFunction && !event.isDefaultPrevented() && !defaultPrevented) {
  1015. defaultFunction(event);
  1016. }
  1017. },
  1018. /**
  1019. * Extension method needed for MooTools
  1020. */
  1021. washMouseEvent: function (e) {
  1022. var ret = e.originalEvent || e;
  1023. // computed by jQuery, needed by IE8
  1024. if (ret.pageX === UNDEFINED) { // #1236
  1025. ret.pageX = e.pageX;
  1026. ret.pageY = e.pageY;
  1027. }
  1028. return ret;
  1029. },
  1030. /**
  1031. * Animate a HTML element or SVG element wrapper
  1032. * @param {Object} el
  1033. * @param {Object} params
  1034. * @param {Object} options jQuery-like animation options: duration, easing, callback
  1035. */
  1036. animate: function (el, params, options) {
  1037. var $el = $(el);
  1038. if (!el.style) {
  1039. el.style = {}; // #1881
  1040. }
  1041. if (params.d) {
  1042. el.toD = params.d; // keep the array form for paths, used in $.fx.step.d
  1043. params.d = 1; // because in jQuery, animating to an array has a different meaning
  1044. }
  1045. $el.stop();
  1046. if (params.opacity !== UNDEFINED && el.attr) {
  1047. params.opacity += 'px'; // force jQuery to use same logic as width and height (#2161)
  1048. }
  1049. el.hasAnim = 1; // #3342
  1050. $el.animate(params, options);
  1051. },
  1052. /**
  1053. * Stop running animation
  1054. */
  1055. stop: function (el) {
  1056. if (el.hasAnim) { // #3342, memory leak on calling $(el) from destroy
  1057. $(el).stop();
  1058. }
  1059. }
  1060. });
  1061. }(win.jQuery));
  1062. // check for a custom HighchartsAdapter defined prior to this file
  1063. var globalAdapter = win.HighchartsAdapter,
  1064. adapter = globalAdapter || {};
  1065. // Initialize the adapter
  1066. if (globalAdapter) {
  1067. globalAdapter.init.call(globalAdapter, pathAnim);
  1068. }
  1069. // Utility functions. If the HighchartsAdapter is not defined, adapter is an empty object
  1070. // and all the utility functions will be null. In that case they are populated by the
  1071. // default adapters below.
  1072. var adapterRun = adapter.adapterRun,
  1073. getScript = adapter.getScript,
  1074. inArray = adapter.inArray,
  1075. each = Highcharts.each = adapter.each,
  1076. grep = adapter.grep,
  1077. offset = adapter.offset,
  1078. map = adapter.map,
  1079. addEvent = adapter.addEvent,
  1080. removeEvent = adapter.removeEvent,
  1081. fireEvent = adapter.fireEvent,
  1082. washMouseEvent = adapter.washMouseEvent,
  1083. animate = adapter.animate,
  1084. stop = adapter.stop;
  1085. /* ****************************************************************************
  1086. * Handle the options *
  1087. *****************************************************************************/
  1088. defaultOptions = {
  1089. colors: ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c',
  1090. '#8085e9', '#f15c80', '#e4d354', '#2b908f', '#f45b5b', '#91e8e1'],
  1091. symbols: ['circle', 'diamond', 'square', 'triangle', 'triangle-down'],
  1092. lang: {
  1093. loading: 'Loading...',
  1094. months: ['January', 'February', 'March', 'April', 'May', 'June', 'July',
  1095. 'August', 'September', 'October', 'November', 'December'],
  1096. shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  1097. weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  1098. // invalidDate: '',
  1099. decimalPoint: '.',
  1100. numericSymbols: ['k', 'M', 'G', 'T', 'P', 'E'], // SI prefixes used in axis labels
  1101. resetZoom: 'Reset zoom',
  1102. resetZoomTitle: 'Reset zoom level 1:1',
  1103. thousandsSep: ' '
  1104. },
  1105. global: {
  1106. useUTC: true,
  1107. //timezoneOffset: 0,
  1108. canvasToolsURL: 'http://code.highcharts.com/maps/1.1.9/modules/canvas-tools.js',
  1109. VMLRadialGradientURL: 'http://code.highcharts.com/maps/1.1.9/gfx/vml-radial-gradient.png'
  1110. },
  1111. chart: {
  1112. //animation: true,
  1113. //alignTicks: false,
  1114. //reflow: true,
  1115. //className: null,
  1116. //events: { load, selection },
  1117. //margin: [null],
  1118. //marginTop: null,
  1119. //marginRight: null,
  1120. //marginBottom: null,
  1121. //marginLeft: null,
  1122. borderColor: '#4572A7',
  1123. //borderWidth: 0,
  1124. borderRadius: 0,
  1125. defaultSeriesType: 'line',
  1126. ignoreHiddenSeries: true,
  1127. //inverted: false,
  1128. //shadow: false,
  1129. spacing: [10, 10, 15, 10],
  1130. //spacingTop: 10,
  1131. //spacingRight: 10,
  1132. //spacingBottom: 15,
  1133. //spacingLeft: 10,
  1134. //style: {
  1135. // fontFamily: '"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif', // default font
  1136. // fontSize: '12px'
  1137. //},
  1138. backgroundColor: '#FFFFFF',
  1139. //plotBackgroundColor: null,
  1140. plotBorderColor: '#C0C0C0',
  1141. //plotBorderWidth: 0,
  1142. //plotShadow: false,
  1143. //zoomType: ''
  1144. resetZoomButton: {
  1145. theme: {
  1146. zIndex: 20
  1147. },
  1148. position: {
  1149. align: 'right',
  1150. x: -10,
  1151. //verticalAlign: 'top',
  1152. y: 10
  1153. }
  1154. // relativeTo: 'plot'
  1155. }
  1156. },
  1157. title: {
  1158. text: 'Chart title',
  1159. align: 'center',
  1160. // floating: false,
  1161. margin: 15,
  1162. // x: 0,
  1163. // verticalAlign: 'top',
  1164. // y: null,
  1165. style: {
  1166. color: '#333333',
  1167. fontSize: '18px'
  1168. }
  1169. },
  1170. subtitle: {
  1171. text: '',
  1172. align: 'center',
  1173. // floating: false
  1174. // x: 0,
  1175. // verticalAlign: 'top',
  1176. // y: null,
  1177. style: {
  1178. color: '#555555'
  1179. }
  1180. },
  1181. plotOptions: {
  1182. line: { // base series options
  1183. allowPointSelect: false,
  1184. showCheckbox: false,
  1185. animation: {
  1186. duration: 1000
  1187. },
  1188. //connectNulls: false,
  1189. //cursor: 'default',
  1190. //clip: true,
  1191. //dashStyle: null,
  1192. //enableMouseTracking: true,
  1193. events: {},
  1194. //legendIndex: 0,
  1195. //linecap: 'round',
  1196. lineWidth: 2,
  1197. //shadow: false,
  1198. // stacking: null,
  1199. marker: {
  1200. //enabled: true,
  1201. //symbol: null,
  1202. lineWidth: 0,
  1203. radius: 4,
  1204. lineColor: '#FFFFFF',
  1205. //fillColor: null,
  1206. states: { // states for a single point
  1207. hover: {
  1208. enabled: true,
  1209. lineWidthPlus: 1,
  1210. radiusPlus: 2
  1211. },
  1212. select: {
  1213. fillColor: '#FFFFFF',
  1214. lineColor: '#000000',
  1215. lineWidth: 2
  1216. }
  1217. }
  1218. },
  1219. point: {
  1220. events: {}
  1221. },
  1222. dataLabels: {
  1223. align: 'center',
  1224. // defer: true,
  1225. // enabled: false,
  1226. formatter: function () {
  1227. return this.y === null ? '' : Highcharts.numberFormat(this.y, -1);
  1228. },
  1229. style: {
  1230. color: 'contrast',
  1231. fontSize: '11px',
  1232. fontWeight: 'bold',
  1233. textShadow: '0 0 6px contrast, 0 0 3px contrast'
  1234. },
  1235. verticalAlign: 'bottom', // above singular point
  1236. x: 0,
  1237. y: 0,
  1238. // backgroundColor: undefined,
  1239. // borderColor: undefined,
  1240. // borderRadius: undefined,
  1241. // borderWidth: undefined,
  1242. padding: 5
  1243. // shadow: false
  1244. },
  1245. cropThreshold: 300, // draw points outside the plot area when the number of points is less than this
  1246. pointRange: 0,
  1247. //pointStart: 0,
  1248. //pointInterval: 1,
  1249. //showInLegend: null, // auto: true for standalone series, false for linked series
  1250. softThreshold: true,
  1251. states: { // states for the entire series
  1252. hover: {
  1253. //enabled: false,
  1254. lineWidthPlus: 1,
  1255. marker: {
  1256. // lineWidth: base + 1,
  1257. // radius: base + 1
  1258. },
  1259. halo: {
  1260. size: 10,
  1261. opacity: 0.25
  1262. }
  1263. },
  1264. select: {
  1265. marker: {}
  1266. }
  1267. },
  1268. stickyTracking: true,
  1269. //tooltip: {
  1270. //pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.y}</b>'
  1271. //valueDecimals: null,
  1272. //xDateFormat: '%A, %b %e, %Y',
  1273. //valuePrefix: '',
  1274. //ySuffix: ''
  1275. //}
  1276. turboThreshold: 1000
  1277. // zIndex: null
  1278. }
  1279. },
  1280. labels: {
  1281. //items: [],
  1282. style: {
  1283. //font: defaultFont,
  1284. position: ABSOLUTE,
  1285. color: '#3E576F'
  1286. }
  1287. },
  1288. legend: {
  1289. enabled: true,
  1290. align: 'center',
  1291. //floating: false,
  1292. layout: 'horizontal',
  1293. labelFormatter: function () {
  1294. return this.name;
  1295. },
  1296. //borderWidth: 0,
  1297. borderColor: '#909090',
  1298. borderRadius: 0,
  1299. navigation: {
  1300. // animation: true,
  1301. activeColor: '#274b6d',
  1302. // arrowSize: 12
  1303. inactiveColor: '#CCC'
  1304. // style: {} // text styles
  1305. },
  1306. // margin: 20,
  1307. // reversed: false,
  1308. shadow: false,
  1309. // backgroundColor: null,
  1310. /*style: {
  1311. padding: '5px'
  1312. },*/
  1313. itemStyle: {
  1314. color: '#333333',
  1315. fontSize: '12px',
  1316. fontWeight: 'bold'
  1317. },
  1318. itemHoverStyle: {
  1319. //cursor: 'pointer', removed as of #601
  1320. color: '#000'
  1321. },
  1322. itemHiddenStyle: {
  1323. color: '#CCC'
  1324. },
  1325. itemCheckboxStyle: {
  1326. position: ABSOLUTE,
  1327. width: '13px', // for IE precision
  1328. height: '13px'
  1329. },
  1330. // itemWidth: undefined,
  1331. // symbolRadius: 0,
  1332. // symbolWidth: 16,
  1333. symbolPadding: 5,
  1334. verticalAlign: 'bottom',
  1335. // width: undefined,
  1336. x: 0,
  1337. y: 0,
  1338. title: {
  1339. //text: null,
  1340. style: {
  1341. fontWeight: 'bold'
  1342. }
  1343. }
  1344. },
  1345. loading: {
  1346. // hideDuration: 100,
  1347. labelStyle: {
  1348. fontWeight: 'bold',
  1349. position: RELATIVE,
  1350. top: '45%'
  1351. },
  1352. // showDuration: 0,
  1353. style: {
  1354. position: ABSOLUTE,
  1355. backgroundColor: 'white',
  1356. opacity: 0.5,
  1357. textAlign: 'center'
  1358. }
  1359. },
  1360. tooltip: {
  1361. enabled: true,
  1362. animation: hasSVG,
  1363. //crosshairs: null,
  1364. backgroundColor: 'rgba(249, 249, 249, .85)',
  1365. borderWidth: 1,
  1366. borderRadius: 3,
  1367. dateTimeLabelFormats: {
  1368. millisecond: '%A, %b %e, %H:%M:%S.%L',
  1369. second: '%A, %b %e, %H:%M:%S',
  1370. minute: '%A, %b %e, %H:%M',
  1371. hour: '%A, %b %e, %H:%M',
  1372. day: '%A, %b %e, %Y',
  1373. week: 'Week from %A, %b %e, %Y',
  1374. month: '%B %Y',
  1375. year: '%Y'
  1376. },
  1377. footerFormat: '',
  1378. //formatter: defaultFormatter,
  1379. headerFormat: '<span style="font-size: 10px">{point.key}</span><br/>',
  1380. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.y}</b><br/>',
  1381. shadow: true,
  1382. //shape: 'callout',
  1383. //shared: false,
  1384. snap: isTouchDevice ? 25 : 10,
  1385. style: {
  1386. color: '#333333',
  1387. cursor: 'default',
  1388. fontSize: '12px',
  1389. padding: '8px',
  1390. pointerEvents: 'none', // #1686 http://caniuse.com/#feat=pointer-events
  1391. whiteSpace: 'nowrap'
  1392. }
  1393. //xDateFormat: '%A, %b %e, %Y',
  1394. //valueDecimals: null,
  1395. //valuePrefix: '',
  1396. //valueSuffix: ''
  1397. },
  1398. credits: {
  1399. enabled: true,
  1400. text: 'Highcharts.com',
  1401. href: 'http://www.highcharts.com',
  1402. position: {
  1403. align: 'right',
  1404. x: -10,
  1405. verticalAlign: 'bottom',
  1406. y: -5
  1407. },
  1408. style: {
  1409. cursor: 'pointer',
  1410. color: '#909090',
  1411. fontSize: '9px'
  1412. }
  1413. }
  1414. };
  1415. // Series defaults
  1416. var defaultPlotOptions = defaultOptions.plotOptions,
  1417. defaultSeriesOptions = defaultPlotOptions.line;
  1418. // set the default time methods
  1419. setTimeMethods();
  1420. /**
  1421. * Set the time methods globally based on the useUTC option. Time method can be either
  1422. * local time or UTC (default).
  1423. */
  1424. function setTimeMethods() {
  1425. var globalOptions = defaultOptions.global,
  1426. useUTC = globalOptions.useUTC,
  1427. GET = useUTC ? 'getUTC' : 'get',
  1428. SET = useUTC ? 'setUTC' : 'set';
  1429. Date = globalOptions.Date || window.Date;
  1430. timezoneOffset = useUTC && globalOptions.timezoneOffset;
  1431. getTimezoneOffset = useUTC && globalOptions.getTimezoneOffset;
  1432. makeTime = function (year, month, date, hours, minutes, seconds) {
  1433. var d;
  1434. if (useUTC) {
  1435. d = Date.UTC.apply(0, arguments);
  1436. d += getTZOffset(d);
  1437. } else {
  1438. d = new Date(
  1439. year,
  1440. month,
  1441. pick(date, 1),
  1442. pick(hours, 0),
  1443. pick(minutes, 0),
  1444. pick(seconds, 0)
  1445. ).getTime();
  1446. }
  1447. return d;
  1448. };
  1449. getMinutes = GET + 'Minutes';
  1450. getHours = GET + 'Hours';
  1451. getDay = GET + 'Day';
  1452. getDate = GET + 'Date';
  1453. getMonth = GET + 'Month';
  1454. getFullYear = GET + 'FullYear';
  1455. setMilliseconds = SET + 'Milliseconds';
  1456. setSeconds = SET + 'Seconds';
  1457. setMinutes = SET + 'Minutes';
  1458. setHours = SET + 'Hours';
  1459. setDate = SET + 'Date';
  1460. setMonth = SET + 'Month';
  1461. setFullYear = SET + 'FullYear';
  1462. }
  1463. /**
  1464. * Merge the default options with custom options and return the new options structure
  1465. * @param {Object} options The new custom options
  1466. */
  1467. function setOptions(options) {
  1468. // Copy in the default options
  1469. defaultOptions = merge(true, defaultOptions, options);
  1470. // Apply UTC
  1471. setTimeMethods();
  1472. return defaultOptions;
  1473. }
  1474. /**
  1475. * Get the updated default options. Until 3.0.7, merely exposing defaultOptions for outside modules
  1476. * wasn't enough because the setOptions method created a new object.
  1477. */
  1478. function getOptions() {
  1479. return defaultOptions;
  1480. }
  1481. /**
  1482. * Handle color operations. The object methods are chainable.
  1483. * @param {String} input The input color in either rbga or hex format
  1484. */
  1485. var rgbaRegEx = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]?(?:\.[0-9]+)?)\s*\)/,
  1486. hexRegEx = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,
  1487. rgbRegEx = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/;
  1488. var Color = function (input) {
  1489. // declare variables
  1490. var rgba = [], result, stops;
  1491. /**
  1492. * Parse the input color to rgba array
  1493. * @param {String} input
  1494. */
  1495. function init(input) {
  1496. // Gradients
  1497. if (input && input.stops) {
  1498. stops = map(input.stops, function (stop) {
  1499. return Color(stop[1]);
  1500. });
  1501. // Solid colors
  1502. } else {
  1503. // rgba
  1504. result = rgbaRegEx.exec(input);
  1505. if (result) {
  1506. rgba = [pInt(result[1]), pInt(result[2]), pInt(result[3]), parseFloat(result[4], 10)];
  1507. } else {
  1508. // hex
  1509. result = hexRegEx.exec(input);
  1510. if (result) {
  1511. rgba = [pInt(result[1], 16), pInt(result[2], 16), pInt(result[3], 16), 1];
  1512. } else {
  1513. // rgb
  1514. result = rgbRegEx.exec(input);
  1515. if (result) {
  1516. rgba = [pInt(result[1]), pInt(result[2]), pInt(result[3]), 1];
  1517. }
  1518. }
  1519. }
  1520. }
  1521. }
  1522. /**
  1523. * Return the color a specified format
  1524. * @param {String} format
  1525. */
  1526. function get(format) {
  1527. var ret;
  1528. if (stops) {
  1529. ret = merge(input);
  1530. ret.stops = [].concat(ret.stops);
  1531. each(stops, function (stop, i) {
  1532. ret.stops[i] = [ret.stops[i][0], stop.get(format)];
  1533. });
  1534. // it's NaN if gradient colors on a column chart
  1535. } else if (rgba && !isNaN(rgba[0])) {
  1536. if (format === 'rgb') {
  1537. ret = 'rgb(' + rgba[0] + ',' + rgba[1] + ',' + rgba[2] + ')';
  1538. } else if (format === 'a') {
  1539. ret = rgba[3];
  1540. } else {
  1541. ret = 'rgba(' + rgba.join(',') + ')';
  1542. }
  1543. } else {
  1544. ret = input;
  1545. }
  1546. return ret;
  1547. }
  1548. /**
  1549. * Brighten the color
  1550. * @param {Number} alpha
  1551. */
  1552. function brighten(alpha) {
  1553. if (stops) {
  1554. each(stops, function (stop) {
  1555. stop.brighten(alpha);
  1556. });
  1557. } else if (isNumber(alpha) && alpha !== 0) {
  1558. var i;
  1559. for (i = 0; i < 3; i++) {
  1560. rgba[i] += pInt(alpha * 255);
  1561. if (rgba[i] < 0) {
  1562. rgba[i] = 0;
  1563. }
  1564. if (rgba[i] > 255) {
  1565. rgba[i] = 255;
  1566. }
  1567. }
  1568. }
  1569. return this;
  1570. }
  1571. /**
  1572. * Set the color's opacity to a given alpha value
  1573. * @param {Number} alpha
  1574. */
  1575. function setOpacity(alpha) {
  1576. rgba[3] = alpha;
  1577. return this;
  1578. }
  1579. // initialize: parse the input
  1580. init(input);
  1581. // public methods
  1582. return {
  1583. get: get,
  1584. brighten: brighten,
  1585. rgba: rgba,
  1586. setOpacity: setOpacity,
  1587. raw: input
  1588. };
  1589. };
  1590. /**
  1591. * A wrapper object for SVG elements
  1592. */
  1593. function SVGElement() {}
  1594. SVGElement.prototype = {
  1595. // Default base for animation
  1596. opacity: 1,
  1597. // For labels, these CSS properties are applied to the <text> node directly
  1598. textProps: ['fontSize', 'fontWeight', 'fontFamily', 'fontStyle', 'color',
  1599. 'lineHeight', 'width', 'textDecoration', 'textOverflow', 'textShadow'],
  1600. /**
  1601. * Initialize the SVG renderer
  1602. * @param {Object} renderer
  1603. * @param {String} nodeName
  1604. */
  1605. init: function (renderer, nodeName) {
  1606. var wrapper = this;
  1607. wrapper.element = nodeName === 'span' ?
  1608. createElement(nodeName) :
  1609. doc.createElementNS(SVG_NS, nodeName);
  1610. wrapper.renderer = renderer;
  1611. },
  1612. /**
  1613. * Animate a given attribute
  1614. * @param {Object} params
  1615. * @param {Number} options The same options as in jQuery animation
  1616. * @param {Function} complete Function to perform at the end of animation
  1617. */
  1618. animate: function (params, options, complete) {
  1619. var animOptions = pick(options, this.renderer.globalAnimation, true);
  1620. stop(this); // stop regardless of animation actually running, or reverting to .attr (#607)
  1621. if (animOptions) {
  1622. animOptions = merge(animOptions, {}); //#2625
  1623. if (complete) { // allows using a callback with the global animation without overwriting it
  1624. animOptions.complete = complete;
  1625. }
  1626. animate(this, params, animOptions);
  1627. } else {
  1628. this.attr(params, null, complete);
  1629. }
  1630. return this;
  1631. },
  1632. /**
  1633. * Build an SVG gradient out of a common JavaScript configuration object
  1634. */
  1635. colorGradient: function (color, prop, elem) {
  1636. var renderer = this.renderer,
  1637. colorObject,
  1638. gradName,
  1639. gradAttr,
  1640. radAttr,
  1641. gradients,
  1642. gradientObject,
  1643. stops,
  1644. stopColor,
  1645. stopOpacity,
  1646. radialReference,
  1647. n,
  1648. id,
  1649. key = [];
  1650. // Apply linear or radial gradients
  1651. if (color.linearGradient) {
  1652. gradName = 'linearGradient';
  1653. } else if (color.radialGradient) {
  1654. gradName = 'radialGradient';
  1655. }
  1656. if (gradName) {
  1657. gradAttr = color[gradName];
  1658. gradients = renderer.gradients;
  1659. stops = color.stops;
  1660. radialReference = elem.radialReference;
  1661. // Keep < 2.2 kompatibility
  1662. if (isArray(gradAttr)) {
  1663. color[gradName] = gradAttr = {
  1664. x1: gradAttr[0],
  1665. y1: gradAttr[1],
  1666. x2: gradAttr[2],
  1667. y2: gradAttr[3],
  1668. gradientUnits: 'userSpaceOnUse'
  1669. };
  1670. }
  1671. // Correct the radial gradient for the radial reference system
  1672. if (gradName === 'radialGradient' && radialReference && !defined(gradAttr.gradientUnits)) {
  1673. radAttr = gradAttr; // Save the radial attributes for updating
  1674. gradAttr = merge(gradAttr,
  1675. renderer.getRadialAttr(radialReference, radAttr),
  1676. { gradientUnits: 'userSpaceOnUse' }
  1677. );
  1678. }
  1679. // Build the unique key to detect whether we need to create a new element (#1282)
  1680. for (n in gradAttr) {
  1681. if (n !== 'id') {
  1682. key.push(n, gradAttr[n]);
  1683. }
  1684. }
  1685. for (n in stops) {
  1686. key.push(stops[n]);
  1687. }
  1688. key = key.join(',');
  1689. // Check if a gradient object with the same config object is created within this renderer
  1690. if (gradients[key]) {
  1691. id = gradients[key].attr('id');
  1692. } else {
  1693. // Set the id and create the element
  1694. gradAttr.id = id = PREFIX + idCounter++;
  1695. gradients[key] = gradientObject = renderer.createElement(gradName)
  1696. .attr(gradAttr)
  1697. .add(renderer.defs);
  1698. gradientObject.radAttr = radAttr;
  1699. // The gradient needs to keep a list of stops to be able to destroy them
  1700. gradientObject.stops = [];
  1701. each(stops, function (stop) {
  1702. var stopObject;
  1703. if (stop[1].indexOf('rgba') === 0) {
  1704. colorObject = Color(stop[1]);
  1705. stopColor = colorObject.get('rgb');
  1706. stopOpacity = colorObject.get('a');
  1707. } else {
  1708. stopColor = stop[1];
  1709. stopOpacity = 1;
  1710. }
  1711. stopObject = renderer.createElement('stop').attr({
  1712. offset: stop[0],
  1713. 'stop-color': stopColor,
  1714. 'stop-opacity': stopOpacity
  1715. }).add(gradientObject);
  1716. // Add the stop element to the gradient
  1717. gradientObject.stops.push(stopObject);
  1718. });
  1719. }
  1720. // Set the reference to the gradient object
  1721. elem.setAttribute(prop, 'url(' + renderer.url + '#' + id + ')');
  1722. elem.gradient = key;
  1723. }
  1724. },
  1725. /**
  1726. * Apply a polyfill to the text-stroke CSS property, by copying the text element
  1727. * and apply strokes to the copy.
  1728. *
  1729. * Contrast checks at http://jsfiddle.net/highcharts/43soe9m1/2/
  1730. *
  1731. * docs: update default, document the polyfill and the limitations on hex colors and pixel values, document contrast pseudo-color
  1732. */
  1733. applyTextShadow: function (textShadow) {
  1734. var elem = this.element,
  1735. tspans,
  1736. hasContrast = textShadow.indexOf('contrast') !== -1,
  1737. styles = {},
  1738. forExport = this.renderer.forExport,
  1739. // IE10 and IE11 report textShadow in elem.style even though it doesn't work. Check
  1740. // this again with new IE release. In exports, the rendering is passed to PhantomJS.
  1741. supports = forExport || (elem.style.textShadow !== UNDEFINED && !isMS);
  1742. // When the text shadow is set to contrast, use dark stroke for light text and vice versa
  1743. if (hasContrast) {
  1744. styles.textShadow = textShadow = textShadow.replace(/contrast/g, this.renderer.getContrast(elem.style.fill));
  1745. }
  1746. // Safari with retina displays as well as PhantomJS bug (#3974). Firefox does not tolerate this,
  1747. // it removes the text shadows.
  1748. if (isWebKit || forExport) {
  1749. styles.textRendering = 'geometricPrecision';
  1750. }
  1751. /* Selective side-by-side testing in supported browser (http://jsfiddle.net/highcharts/73L1ptrh/)
  1752. if (elem.textContent.indexOf('2.') === 0) {
  1753. elem.style['text-shadow'] = 'none';
  1754. supports = false;
  1755. }
  1756. // */
  1757. // No reason to polyfill, we've got native support
  1758. if (supports) {
  1759. this.css(styles); // Apply altered textShadow or textRendering workaround
  1760. } else {
  1761. this.fakeTS = true; // Fake text shadow
  1762. // In order to get the right y position of the clones,
  1763. // copy over the y setter
  1764. this.ySetter = this.xSetter;
  1765. tspans = [].slice.call(elem.getElementsByTagName('tspan'));
  1766. each(textShadow.split(/\s?,\s?/g), function (textShadow) {
  1767. var firstChild = elem.firstChild,
  1768. color,
  1769. strokeWidth;
  1770. textShadow = textShadow.split(' ');
  1771. color = textShadow[textShadow.length - 1];
  1772. // Approximately tune the settings to the text-shadow behaviour
  1773. strokeWidth = textShadow[textShadow.length - 2];
  1774. if (strokeWidth) {
  1775. each(tspans, function (tspan, y) {
  1776. var clone;
  1777. // Let the first line start at the correct X position
  1778. if (y === 0) {
  1779. tspan.setAttribute('x', elem.getAttribute('x'));
  1780. y = elem.getAttribute('y');
  1781. tspan.setAttribute('y', y || 0);
  1782. if (y === null) {
  1783. elem.setAttribute('y', 0);
  1784. }
  1785. }
  1786. // Create the clone and apply shadow properties
  1787. clone = tspan.cloneNode(1);
  1788. attr(clone, {
  1789. 'class': PREFIX + 'text-shadow',
  1790. 'fill': color,
  1791. 'stroke': color,
  1792. 'stroke-opacity': 1 / mathMax(pInt(strokeWidth), 3),
  1793. 'stroke-width': strokeWidth,
  1794. 'stroke-linejoin': 'round'
  1795. });
  1796. elem.insertBefore(clone, firstChild);
  1797. });
  1798. }
  1799. });
  1800. }
  1801. },
  1802. /**
  1803. * Set or get a given attribute
  1804. * @param {Object|String} hash
  1805. * @param {Mixed|Undefined} val
  1806. */
  1807. attr: function (hash, val, complete) {
  1808. var key,
  1809. value,
  1810. element = this.element,
  1811. hasSetSymbolSize,
  1812. ret = this,
  1813. skipAttr;
  1814. // single key-value pair
  1815. if (typeof hash === 'string' && val !== UNDEFINED) {
  1816. key = hash;
  1817. hash = {};
  1818. hash[key] = val;
  1819. }
  1820. // used as a getter: first argument is a string, second is undefined
  1821. if (typeof hash === 'string') {
  1822. ret = (this[hash + 'Getter'] || this._defaultGetter).call(this, hash, element);
  1823. // setter
  1824. } else {
  1825. for (key in hash) {
  1826. value = hash[key];
  1827. skipAttr = false;
  1828. if (this.symbolName && /^(x|y|width|height|r|start|end|innerR|anchorX|anchorY)/.test(key)) {
  1829. if (!hasSetSymbolSize) {
  1830. this.symbolAttr(hash);
  1831. hasSetSymbolSize = true;
  1832. }
  1833. skipAttr = true;
  1834. }
  1835. if (this.rotation && (key === 'x' || key === 'y')) {
  1836. this.doTransform = true;
  1837. }
  1838. if (!skipAttr) {
  1839. (this[key + 'Setter'] || this._defaultSetter).call(this, value, key, element);
  1840. }
  1841. // Let the shadow follow the main element
  1842. if (this.shadows && /^(width|height|visibility|x|y|d|transform|cx|cy|r)$/.test(key)) {
  1843. this.updateShadows(key, value);
  1844. }
  1845. }
  1846. // Update transform. Do this outside the loop to prevent redundant updating for batch setting
  1847. // of attributes.
  1848. if (this.doTransform) {
  1849. this.updateTransform();
  1850. this.doTransform = false;
  1851. }
  1852. }
  1853. // In accordance with animate, run a complete callback
  1854. if (complete) {
  1855. complete();
  1856. }
  1857. return ret;
  1858. },
  1859. updateShadows: function (key, value) {
  1860. var shadows = this.shadows,
  1861. i = shadows.length;
  1862. while (i--) {
  1863. shadows[i].setAttribute(
  1864. key,
  1865. key === 'height' ?
  1866. mathMax(value - (shadows[i].cutHeight || 0), 0) :
  1867. key === 'd' ? this.d : value
  1868. );
  1869. }
  1870. },
  1871. /**
  1872. * Add a class name to an element
  1873. */
  1874. addClass: function (className) {
  1875. var element = this.element,
  1876. currentClassName = attr(element, 'class') || '';
  1877. if (currentClassName.indexOf(className) === -1) {
  1878. attr(element, 'class', currentClassName + ' ' + className);
  1879. }
  1880. return this;
  1881. },
  1882. /* hasClass and removeClass are not (yet) needed
  1883. hasClass: function (className) {
  1884. return attr(this.element, 'class').indexOf(className) !== -1;
  1885. },
  1886. removeClass: function (className) {
  1887. attr(this.element, 'class', attr(this.element, 'class').replace(className, ''));
  1888. return this;
  1889. },
  1890. */
  1891. /**
  1892. * If one of the symbol size affecting parameters are changed,
  1893. * check all the others only once for each call to an element's
  1894. * .attr() method
  1895. * @param {Object} hash
  1896. */
  1897. symbolAttr: function (hash) {
  1898. var wrapper = this;
  1899. each(['x', 'y', 'r', 'start', 'end', 'width', 'height', 'innerR', 'anchorX', 'anchorY'], function (key) {
  1900. wrapper[key] = pick(hash[key], wrapper[key]);
  1901. });
  1902. wrapper.attr({
  1903. d: wrapper.renderer.symbols[wrapper.symbolName](
  1904. wrapper.x,
  1905. wrapper.y,
  1906. wrapper.width,
  1907. wrapper.height,
  1908. wrapper
  1909. )
  1910. });
  1911. },
  1912. /**
  1913. * Apply a clipping path to this object
  1914. * @param {String} id
  1915. */
  1916. clip: function (clipRect) {
  1917. return this.attr('clip-path', clipRect ? 'url(' + this.renderer.url + '#' + clipRect.id + ')' : NONE);
  1918. },
  1919. /**
  1920. * Calculate the coordinates needed for drawing a rectangle crisply and return the
  1921. * calculated attributes
  1922. * @param {Number} strokeWidth
  1923. * @param {Number} x
  1924. * @param {Number} y
  1925. * @param {Number} width
  1926. * @param {Number} height
  1927. */
  1928. crisp: function (rect) {
  1929. var wrapper = this,
  1930. key,
  1931. attribs = {},
  1932. normalizer,
  1933. strokeWidth = rect.strokeWidth || wrapper.strokeWidth || 0;
  1934. normalizer = mathRound(strokeWidth) % 2 / 2; // mathRound because strokeWidth can sometimes have roundoff errors
  1935. // normalize for crisp edges
  1936. rect.x = mathFloor(rect.x || wrapper.x || 0) + normalizer;
  1937. rect.y = mathFloor(rect.y || wrapper.y || 0) + normalizer;
  1938. rect.width = mathFloor((rect.width || wrapper.width || 0) - 2 * normalizer);
  1939. rect.height = mathFloor((rect.height || wrapper.height || 0) - 2 * normalizer);
  1940. rect.strokeWidth = strokeWidth;
  1941. for (key in rect) {
  1942. if (wrapper[key] !== rect[key]) { // only set attribute if changed
  1943. wrapper[key] = attribs[key] = rect[key];
  1944. }
  1945. }
  1946. return attribs;
  1947. },
  1948. /**
  1949. * Set styles for the element
  1950. * @param {Object} styles
  1951. */
  1952. css: function (styles) {
  1953. var elemWrapper = this,
  1954. oldStyles = elemWrapper.styles,
  1955. newStyles = {},
  1956. elem = elemWrapper.element,
  1957. textWidth,
  1958. n,
  1959. serializedCss = '',
  1960. hyphenate,
  1961. hasNew = !oldStyles;
  1962. // convert legacy
  1963. if (styles && styles.color) {
  1964. styles.fill = styles.color;
  1965. }
  1966. // Filter out existing styles to increase performance (#2640)
  1967. if (oldStyles) {
  1968. for (n in styles) {
  1969. if (styles[n] !== oldStyles[n]) {
  1970. newStyles[n] = styles[n];
  1971. hasNew = true;
  1972. }
  1973. }
  1974. }
  1975. if (hasNew) {
  1976. textWidth = elemWrapper.textWidth =
  1977. (styles && styles.width && elem.nodeName.toLowerCase() === 'text' && pInt(styles.width)) ||
  1978. elemWrapper.textWidth; // #3501
  1979. // Merge the new styles with the old ones
  1980. if (oldStyles) {
  1981. styles = extend(
  1982. oldStyles,
  1983. newStyles
  1984. );
  1985. }
  1986. // store object
  1987. elemWrapper.styles = styles;
  1988. if (textWidth && (useCanVG || (!hasSVG && elemWrapper.renderer.forExport))) {
  1989. delete styles.width;
  1990. }
  1991. // serialize and set style attribute
  1992. if (isMS && !hasSVG) {
  1993. css(elemWrapper.element, styles);
  1994. } else {
  1995. /*jslint unparam: true*/
  1996. hyphenate = function (a, b) { return '-' + b.toLowerCase(); };
  1997. /*jslint unparam: false*/
  1998. for (n in styles) {
  1999. serializedCss += n.replace(/([A-Z])/g, hyphenate) + ':' + styles[n] + ';';
  2000. }
  2001. attr(elem, 'style', serializedCss); // #1881
  2002. }
  2003. // re-build text
  2004. if (textWidth && elemWrapper.added) {
  2005. elemWrapper.renderer.buildText(elemWrapper);
  2006. }
  2007. }
  2008. return elemWrapper;
  2009. },
  2010. /**
  2011. * Add an event listener
  2012. * @param {String} eventType
  2013. * @param {Function} handler
  2014. */
  2015. on: function (eventType, handler) {
  2016. var svgElement = this,
  2017. element = svgElement.element;
  2018. // touch
  2019. if (hasTouch && eventType === 'click') {
  2020. element.ontouchstart = function (e) {
  2021. svgElement.touchEventFired = Date.now();
  2022. e.preventDefault();
  2023. handler.call(element, e);
  2024. };
  2025. element.onclick = function (e) {
  2026. if (userAgent.indexOf('Android') === -1 || Date.now() - (svgElement.touchEventFired || 0) > 1100) { // #2269
  2027. handler.call(element, e);
  2028. }
  2029. };
  2030. } else {
  2031. // simplest possible event model for internal use
  2032. element['on' + eventType] = handler;
  2033. }
  2034. return this;
  2035. },
  2036. /**
  2037. * Set the coordinates needed to draw a consistent radial gradient across
  2038. * pie slices regardless of positioning inside the chart. The format is
  2039. * [centerX, centerY, diameter] in pixels.
  2040. */
  2041. setRadialReference: function (coordinates) {
  2042. var existingGradient = this.renderer.gradients[this.element.gradient];
  2043. this.element.radialReference = coordinates;
  2044. // On redrawing objects with an existing gradient, the gradient needs
  2045. // to be repositioned (#3801)
  2046. if (existingGradient && existingGradient.radAttr) {
  2047. existingGradient.animate(
  2048. this.renderer.getRadialAttr(
  2049. coordinates,
  2050. existingGradient.radAttr
  2051. )
  2052. );
  2053. }
  2054. return this;
  2055. },
  2056. /**
  2057. * Move an object and its children by x and y values
  2058. * @param {Number} x
  2059. * @param {Number} y
  2060. */
  2061. translate: function (x, y) {
  2062. return this.attr({
  2063. translateX: x,
  2064. translateY: y
  2065. });
  2066. },
  2067. /**
  2068. * Invert a group, rotate and flip
  2069. */
  2070. invert: function () {
  2071. var wrapper = this;
  2072. wrapper.inverted = true;
  2073. wrapper.updateTransform();
  2074. return wrapper;
  2075. },
  2076. /**
  2077. * Private method to update the transform attribute based on internal
  2078. * properties
  2079. */
  2080. updateTransform: function () {
  2081. var wrapper = this,
  2082. translateX = wrapper.translateX || 0,
  2083. translateY = wrapper.translateY || 0,
  2084. scaleX = wrapper.scaleX,
  2085. scaleY = wrapper.scaleY,
  2086. inverted = wrapper.inverted,
  2087. rotation = wrapper.rotation,
  2088. element = wrapper.element,
  2089. transform;
  2090. // flipping affects translate as adjustment for flipping around the group's axis
  2091. if (inverted) {
  2092. translateX += wrapper.attr('width');
  2093. translateY += wrapper.attr('height');
  2094. }
  2095. // Apply translate. Nearly all transformed elements have translation, so instead
  2096. // of checking for translate = 0, do it always (#1767, #1846).
  2097. transform = ['translate(' + translateX + ',' + translateY + ')'];
  2098. // apply rotation
  2099. if (inverted) {
  2100. transform.push('rotate(90) scale(-1,1)');
  2101. } else if (rotation) { // text rotation
  2102. transform.push('rotate(' + rotation + ' ' + (element.getAttribute('x') || 0) + ' ' + (element.getAttribute('y') || 0) + ')');
  2103. // Delete bBox memo when the rotation changes
  2104. //delete wrapper.bBox;
  2105. }
  2106. // apply scale
  2107. if (defined(scaleX) || defined(scaleY)) {
  2108. transform.push('scale(' + pick(scaleX, 1) + ' ' + pick(scaleY, 1) + ')');
  2109. }
  2110. if (transform.length) {
  2111. element.setAttribute('transform', transform.join(' '));
  2112. }
  2113. },
  2114. /**
  2115. * Bring the element to the front
  2116. */
  2117. toFront: function () {
  2118. var element = this.element;
  2119. element.parentNode.appendChild(element);
  2120. return this;
  2121. },
  2122. /**
  2123. * Break down alignment options like align, verticalAlign, x and y
  2124. * to x and y relative to the chart.
  2125. *
  2126. * @param {Object} alignOptions
  2127. * @param {Boolean} alignByTranslate
  2128. * @param {String[Object} box The box to align to, needs a width and height. When the
  2129. * box is a string, it refers to an object in the Renderer. For example, when
  2130. * box is 'spacingBox', it refers to Renderer.spacingBox which holds width, height
  2131. * x and y properties.
  2132. *
  2133. */
  2134. align: function (alignOptions, alignByTranslate, box) {
  2135. var align,
  2136. vAlign,
  2137. x,
  2138. y,
  2139. attribs = {},
  2140. alignTo,
  2141. renderer = this.renderer,
  2142. alignedObjects = renderer.alignedObjects;
  2143. // First call on instanciate
  2144. if (alignOptions) {
  2145. this.alignOptions = alignOptions;
  2146. this.alignByTranslate = alignByTranslate;
  2147. if (!box || isString(box)) { // boxes other than renderer handle this internally
  2148. this.alignTo = alignTo = box || 'renderer';
  2149. erase(alignedObjects, this); // prevent duplicates, like legendGroup after resize
  2150. alignedObjects.push(this);
  2151. box = null; // reassign it below
  2152. }
  2153. // When called on resize, no arguments are supplied
  2154. } else {
  2155. alignOptions = this.alignOptions;
  2156. alignByTranslate = this.alignByTranslate;
  2157. alignTo = this.alignTo;
  2158. }
  2159. box = pick(box, renderer[alignTo], renderer);
  2160. // Assign variables
  2161. align = alignOptions.align;
  2162. vAlign = alignOptions.verticalAlign;
  2163. x = (box.x || 0) + (alignOptions.x || 0); // default: left align
  2164. y = (box.y || 0) + (alignOptions.y || 0); // default: top align
  2165. // Align
  2166. if (align === 'right' || align === 'center') {
  2167. x += (box.width - (alignOptions.width || 0)) /
  2168. { right: 1, center: 2 }[align];
  2169. }
  2170. attribs[alignByTranslate ? 'translateX' : 'x'] = mathRound(x);
  2171. // Vertical align
  2172. if (vAlign === 'bottom' || vAlign === 'middle') {
  2173. y += (box.height - (alignOptions.height || 0)) /
  2174. ({ bottom: 1, middle: 2 }[vAlign] || 1);
  2175. }
  2176. attribs[alignByTranslate ? 'translateY' : 'y'] = mathRound(y);
  2177. // Animate only if already placed
  2178. this[this.placed ? 'animate' : 'attr'](attribs);
  2179. this.placed = true;
  2180. this.alignAttr = attribs;
  2181. return this;
  2182. },
  2183. /**
  2184. * Get the bounding box (width, height, x and y) for the element
  2185. */
  2186. getBBox: function (reload) {
  2187. var wrapper = this,
  2188. bBox,// = wrapper.bBox,
  2189. renderer = wrapper.renderer,
  2190. width,
  2191. height,
  2192. rotation = wrapper.rotation,
  2193. element = wrapper.element,
  2194. styles = wrapper.styles,
  2195. rad = rotation * deg2rad,
  2196. textStr = wrapper.textStr,
  2197. textShadow,
  2198. elemStyle = element.style,
  2199. toggleTextShadowShim,
  2200. cacheKey;
  2201. if (textStr !== UNDEFINED) {
  2202. // Properties that affect bounding box
  2203. cacheKey = ['', rotation || 0, styles && styles.fontSize, element.style.width].join(',');
  2204. // Since numbers are monospaced, and numerical labels appear a lot in a chart,
  2205. // we assume that a label of n characters has the same bounding box as others
  2206. // of the same length.
  2207. if (textStr === '' || numRegex.test(textStr)) {
  2208. cacheKey = 'num:' + textStr.toString().length + cacheKey;
  2209. // Caching all strings reduces rendering time by 4-5%.
  2210. } else {
  2211. cacheKey = textStr + cacheKey;
  2212. }
  2213. }
  2214. if (cacheKey && !reload) {
  2215. bBox = renderer.cache[cacheKey];
  2216. }
  2217. // No cache found
  2218. if (!bBox) {
  2219. // SVG elements
  2220. if (element.namespaceURI === SVG_NS || renderer.forExport) {
  2221. try { // Fails in Firefox if the container has display: none.
  2222. // When the text shadow shim is used, we need to hide the fake shadows
  2223. // to get the correct bounding box (#3872)
  2224. toggleTextShadowShim = this.fakeTS && function (display) {
  2225. each(element.querySelectorAll('.' + PREFIX + 'text-shadow'), function (tspan) {
  2226. tspan.style.display = display;
  2227. });
  2228. };
  2229. // Workaround for #3842, Firefox reporting wrong bounding box for shadows
  2230. if (isFirefox && elemStyle.textShadow) {
  2231. textShadow = elemStyle.textShadow;
  2232. elemStyle.textShadow = '';
  2233. } else if (toggleTextShadowShim) {
  2234. toggleTextShadowShim(NONE);
  2235. }
  2236. bBox = element.getBBox ?
  2237. // SVG: use extend because IE9 is not allowed to change width and height in case
  2238. // of rotation (below)
  2239. extend({}, element.getBBox()) :
  2240. // Canvas renderer and legacy IE in export mode
  2241. {
  2242. width: element.offsetWidth,
  2243. height: element.offsetHeight
  2244. };
  2245. // #3842
  2246. if (textShadow) {
  2247. elemStyle.textShadow = textShadow;
  2248. } else if (toggleTextShadowShim) {
  2249. toggleTextShadowShim('');
  2250. }
  2251. } catch (e) {}
  2252. // If the bBox is not set, the try-catch block above failed. The other condition
  2253. // is for Opera that returns a width of -Infinity on hidden elements.
  2254. if (!bBox || bBox.width < 0) {
  2255. bBox = { width: 0, height: 0 };
  2256. }
  2257. // VML Renderer or useHTML within SVG
  2258. } else {
  2259. bBox = wrapper.htmlGetBBox();
  2260. }
  2261. // True SVG elements as well as HTML elements in modern browsers using the .useHTML option
  2262. // need to compensated for rotation
  2263. if (renderer.isSVG) {
  2264. width = bBox.width;
  2265. height = bBox.height;
  2266. // Workaround for wrong bounding box in IE9 and IE10 (#1101, #1505, #1669, #2568)
  2267. if (isMS && styles && styles.fontSize === '11px' && height.toPrecision(3) === '16.9') {
  2268. bBox.height = height = 14;
  2269. }
  2270. // Adjust for rotated text
  2271. if (rotation) {
  2272. bBox.width = mathAbs(height * mathSin(rad)) + mathAbs(width * mathCos(rad));
  2273. bBox.height = mathAbs(height * mathCos(rad)) + mathAbs(width * mathSin(rad));
  2274. }
  2275. }
  2276. // Cache it
  2277. if (cacheKey) {
  2278. renderer.cache[cacheKey] = bBox;
  2279. }
  2280. }
  2281. return bBox;
  2282. },
  2283. /**
  2284. * Show the element
  2285. */
  2286. show: function (inherit) {
  2287. return this.attr({ visibility: inherit ? 'inherit' : VISIBLE });
  2288. },
  2289. /**
  2290. * Hide the element
  2291. */
  2292. hide: function () {
  2293. return this.attr({ visibility: HIDDEN });
  2294. },
  2295. fadeOut: function (duration) {
  2296. var elemWrapper = this;
  2297. elemWrapper.animate({
  2298. opacity: 0
  2299. }, {
  2300. duration: duration || 150,
  2301. complete: function () {
  2302. elemWrapper.attr({ y: -9999 }); // #3088, assuming we're only using this for tooltips
  2303. }
  2304. });
  2305. },
  2306. /**
  2307. * Add the element
  2308. * @param {Object|Undefined} parent Can be an element, an element wrapper or undefined
  2309. * to append the element to the renderer.box.
  2310. */
  2311. add: function (parent) {
  2312. var renderer = this.renderer,
  2313. element = this.element,
  2314. inserted;
  2315. if (parent) {
  2316. this.parentGroup = parent;
  2317. }
  2318. // mark as inverted
  2319. this.parentInverted = parent && parent.inverted;
  2320. // build formatted text
  2321. if (this.textStr !== undefined) {
  2322. renderer.buildText(this);
  2323. }
  2324. // Mark as added
  2325. this.added = true;
  2326. // If we're adding to renderer root, or other elements in the group
  2327. // have a z index, we need to handle it
  2328. if (!parent || parent.handleZ || this.zIndex) {
  2329. inserted = this.zIndexSetter();
  2330. }
  2331. // If zIndex is not handled, append at the end
  2332. if (!inserted) {
  2333. (parent ? parent.element : renderer.box).appendChild(element);
  2334. }
  2335. // fire an event for internal hooks
  2336. if (this.onAdd) {
  2337. this.onAdd();
  2338. }
  2339. return this;
  2340. },
  2341. /**
  2342. * Removes a child either by removeChild or move to garbageBin.
  2343. * Issue 490; in VML removeChild results in Orphaned nodes according to sIEve, discardElement does not.
  2344. */
  2345. safeRemoveChild: function (element) {
  2346. var parentNode = element.parentNode;
  2347. if (parentNode) {
  2348. parentNode.removeChild(element);
  2349. }
  2350. },
  2351. /**
  2352. * Destroy the element and element wrapper
  2353. */
  2354. destroy: function () {
  2355. var wrapper = this,
  2356. element = wrapper.element || {},
  2357. shadows = wrapper.shadows,
  2358. parentToClean = wrapper.renderer.isSVG && element.nodeName === 'SPAN' && wrapper.parentGroup,
  2359. grandParent,
  2360. key,
  2361. i;
  2362. // remove events
  2363. element.onclick = element.onmouseout = element.onmouseover = element.onmousemove = element.point = null;
  2364. stop(wrapper); // stop running animations
  2365. if (wrapper.clipPath) {
  2366. wrapper.clipPath = wrapper.clipPath.destroy();
  2367. }
  2368. // Destroy stops in case this is a gradient object
  2369. if (wrapper.stops) {
  2370. for (i = 0; i < wrapper.stops.length; i++) {
  2371. wrapper.stops[i] = wrapper.stops[i].destroy();
  2372. }
  2373. wrapper.stops = null;
  2374. }
  2375. // remove element
  2376. wrapper.safeRemoveChild(element);
  2377. // destroy shadows
  2378. if (shadows) {
  2379. each(shadows, function (shadow) {
  2380. wrapper.safeRemoveChild(shadow);
  2381. });
  2382. }
  2383. // In case of useHTML, clean up empty containers emulating SVG groups (#1960, #2393, #2697).
  2384. while (parentToClean && parentToClean.div && parentToClean.div.childNodes.length === 0) {
  2385. grandParent = parentToClean.parentGroup;
  2386. wrapper.safeRemoveChild(parentToClean.div);
  2387. delete parentToClean.div;
  2388. parentToClean = grandParent;
  2389. }
  2390. // remove from alignObjects
  2391. if (wrapper.alignTo) {
  2392. erase(wrapper.renderer.alignedObjects, wrapper);
  2393. }
  2394. for (key in wrapper) {
  2395. delete wrapper[key];
  2396. }
  2397. return null;
  2398. },
  2399. /**
  2400. * Add a shadow to the element. Must be done after the element is added to the DOM
  2401. * @param {Boolean|Object} shadowOptions
  2402. */
  2403. shadow: function (shadowOptions, group, cutOff) {
  2404. var shadows = [],
  2405. i,
  2406. shadow,
  2407. element = this.element,
  2408. strokeWidth,
  2409. shadowWidth,
  2410. shadowElementOpacity,
  2411. // compensate for inverted plot area
  2412. transform;
  2413. if (shadowOptions) {
  2414. shadowWidth = pick(shadowOptions.width, 3);
  2415. shadowElementOpacity = (shadowOptions.opacity || 0.15) / shadowWidth;
  2416. transform = this.parentInverted ?
  2417. '(-1,-1)' :
  2418. '(' + pick(shadowOptions.offsetX, 1) + ', ' + pick(shadowOptions.offsetY, 1) + ')';
  2419. for (i = 1; i <= shadowWidth; i++) {
  2420. shadow = element.cloneNode(0);
  2421. strokeWidth = (shadowWidth * 2) + 1 - (2 * i);
  2422. attr(shadow, {
  2423. 'isShadow': 'true',
  2424. 'stroke': shadowOptions.color || 'black',
  2425. 'stroke-opacity': shadowElementOpacity * i,
  2426. 'stroke-width': strokeWidth,
  2427. 'transform': 'translate' + transform,
  2428. 'fill': NONE
  2429. });
  2430. if (cutOff) {
  2431. attr(shadow, 'height', mathMax(attr(shadow, 'height') - strokeWidth, 0));
  2432. shadow.cutHeight = strokeWidth;
  2433. }
  2434. if (group) {
  2435. group.element.appendChild(shadow);
  2436. } else {
  2437. element.parentNode.insertBefore(shadow, element);
  2438. }
  2439. shadows.push(shadow);
  2440. }
  2441. this.shadows = shadows;
  2442. }
  2443. return this;
  2444. },
  2445. xGetter: function (key) {
  2446. if (this.element.nodeName === 'circle') {
  2447. key = { x: 'cx', y: 'cy' }[key] || key;
  2448. }
  2449. return this._defaultGetter(key);
  2450. },
  2451. /**
  2452. * Get the current value of an attribute or pseudo attribute, used mainly
  2453. * for animation.
  2454. */
  2455. _defaultGetter: function (key) {
  2456. var ret = pick(this[key], this.element ? this.element.getAttribute(key) : null, 0);
  2457. if (/^[\-0-9\.]+$/.test(ret)) { // is numerical
  2458. ret = parseFloat(ret);
  2459. }
  2460. return ret;
  2461. },
  2462. dSetter: function (value, key, element) {
  2463. if (value && value.join) { // join path
  2464. value = value.join(' ');
  2465. }
  2466. if (/(NaN| {2}|^$)/.test(value)) {
  2467. value = 'M 0 0';
  2468. }
  2469. element.setAttribute(key, value);
  2470. this[key] = value;
  2471. },
  2472. dashstyleSetter: function (value) {
  2473. var i;
  2474. value = value && value.toLowerCase();
  2475. if (value) {
  2476. value = value
  2477. .replace('shortdashdotdot', '3,1,1,1,1,1,')
  2478. .replace('shortdashdot', '3,1,1,1')
  2479. .replace('shortdot', '1,1,')
  2480. .replace('shortdash', '3,1,')
  2481. .replace('longdash', '8,3,')
  2482. .replace(/dot/g, '1,3,')
  2483. .replace('dash', '4,3,')
  2484. .replace(/,$/, '')
  2485. .split(','); // ending comma
  2486. i = value.length;
  2487. while (i--) {
  2488. value[i] = pInt(value[i]) * this['stroke-width'];
  2489. }
  2490. value = value.join(',')
  2491. .replace('NaN', 'none'); // #3226
  2492. this.element.setAttribute('stroke-dasharray', value);
  2493. }
  2494. },
  2495. alignSetter: function (value) {
  2496. this.element.setAttribute('text-anchor', { left: 'start', center: 'middle', right: 'end' }[value]);
  2497. },
  2498. opacitySetter: function (value, key, element) {
  2499. this[key] = value;
  2500. element.setAttribute(key, value);
  2501. },
  2502. titleSetter: function (value) {
  2503. var titleNode = this.element.getElementsByTagName('title')[0];
  2504. if (!titleNode) {
  2505. titleNode = doc.createElementNS(SVG_NS, 'title');
  2506. this.element.appendChild(titleNode);
  2507. }
  2508. titleNode.appendChild(
  2509. doc.createTextNode(
  2510. (String(pick(value), '')).replace(/<[^>]*>/g, '') // #3276, #3895
  2511. )
  2512. );
  2513. },
  2514. textSetter: function (value) {
  2515. if (value !== this.textStr) {
  2516. // Delete bBox memo when the text changes
  2517. delete this.bBox;
  2518. this.textStr = value;
  2519. if (this.added) {
  2520. this.renderer.buildText(this);
  2521. }
  2522. }
  2523. },
  2524. fillSetter: function (value, key, element) {
  2525. if (typeof value === 'string') {
  2526. element.setAttribute(key, value);
  2527. } else if (value) {
  2528. this.colorGradient(value, key, element);
  2529. }
  2530. },
  2531. visibilitySetter: function (value, key, element) {
  2532. // IE9-11 doesn't handle visibilty:inherit well, so we remove the attribute instead (#2881, #3909)
  2533. if (value === 'inherit') {
  2534. element.removeAttribute(key);
  2535. } else {
  2536. element.setAttribute(key, value);
  2537. }
  2538. },
  2539. zIndexSetter: function (value, key) {
  2540. var renderer = this.renderer,
  2541. parentGroup = this.parentGroup,
  2542. parentWrapper = parentGroup || renderer,
  2543. parentNode = parentWrapper.element || renderer.box,
  2544. childNodes,
  2545. otherElement,
  2546. otherZIndex,
  2547. element = this.element,
  2548. inserted,
  2549. run = this.added,
  2550. i;
  2551. if (defined(value)) {
  2552. element.setAttribute(key, value); // So we can read it for other elements in the group
  2553. value = +value;
  2554. if (this[key] === value) { // Only update when needed (#3865)
  2555. run = false;
  2556. }
  2557. this[key] = value;
  2558. }
  2559. // Insert according to this and other elements' zIndex. Before .add() is called,
  2560. // nothing is done. Then on add, or by later calls to zIndexSetter, the node
  2561. // is placed on the right place in the DOM.
  2562. if (run) {
  2563. value = this.zIndex;
  2564. if (value && parentGroup) {
  2565. parentGroup.handleZ = true;
  2566. }
  2567. childNodes = parentNode.childNodes;
  2568. for (i = 0; i < childNodes.length && !inserted; i++) {
  2569. otherElement = childNodes[i];
  2570. otherZIndex = attr(otherElement, 'zIndex');
  2571. if (otherElement !== element && (
  2572. // Insert before the first element with a higher zIndex
  2573. pInt(otherZIndex) > value ||
  2574. // If no zIndex given, insert before the first element with a zIndex
  2575. (!defined(value) && defined(otherZIndex))
  2576. )) {
  2577. parentNode.insertBefore(element, otherElement);
  2578. inserted = true;
  2579. }
  2580. }
  2581. if (!inserted) {
  2582. parentNode.appendChild(element);
  2583. }
  2584. }
  2585. return inserted;
  2586. },
  2587. _defaultSetter: function (value, key, element) {
  2588. element.setAttribute(key, value);
  2589. }
  2590. };
  2591. // Some shared setters and getters
  2592. SVGElement.prototype.yGetter = SVGElement.prototype.xGetter;
  2593. SVGElement.prototype.translateXSetter = SVGElement.prototype.translateYSetter =
  2594. SVGElement.prototype.rotationSetter = SVGElement.prototype.verticalAlignSetter =
  2595. SVGElement.prototype.scaleXSetter = SVGElement.prototype.scaleYSetter = function (value, key) {
  2596. this[key] = value;
  2597. this.doTransform = true;
  2598. };
  2599. // WebKit and Batik have problems with a stroke-width of zero, so in this case we remove the
  2600. // stroke attribute altogether. #1270, #1369, #3065, #3072.
  2601. SVGElement.prototype['stroke-widthSetter'] = SVGElement.prototype.strokeSetter = function (value, key, element) {
  2602. this[key] = value;
  2603. // Only apply the stroke attribute if the stroke width is defined and larger than 0
  2604. if (this.stroke && this['stroke-width']) {
  2605. this.strokeWidth = this['stroke-width'];
  2606. SVGElement.prototype.fillSetter.call(this, this.stroke, 'stroke', element); // use prototype as instance may be overridden
  2607. element.setAttribute('stroke-width', this['stroke-width']);
  2608. this.hasStroke = true;
  2609. } else if (key === 'stroke-width' && value === 0 && this.hasStroke) {
  2610. element.removeAttribute('stroke');
  2611. this.hasStroke = false;
  2612. }
  2613. };
  2614. /**
  2615. * The default SVG renderer
  2616. */
  2617. var SVGRenderer = function () {
  2618. this.init.apply(this, arguments);
  2619. };
  2620. SVGRenderer.prototype = {
  2621. Element: SVGElement,
  2622. /**
  2623. * Initialize the SVGRenderer
  2624. * @param {Object} container
  2625. * @param {Number} width
  2626. * @param {Number} height
  2627. * @param {Boolean} forExport
  2628. */
  2629. init: function (container, width, height, style, forExport, allowHTML) {
  2630. var renderer = this,
  2631. loc = location,
  2632. boxWrapper,
  2633. element,
  2634. desc;
  2635. boxWrapper = renderer.createElement('svg')
  2636. .attr({
  2637. version: '1.1'
  2638. })
  2639. .css(this.getStyle(style));
  2640. element = boxWrapper.element;
  2641. container.appendChild(element);
  2642. // For browsers other than IE, add the namespace attribute (#1978)
  2643. if (container.innerHTML.indexOf('xmlns') === -1) {
  2644. attr(element, 'xmlns', SVG_NS);
  2645. }
  2646. // object properties
  2647. renderer.isSVG = true;
  2648. renderer.box = element;
  2649. renderer.boxWrapper = boxWrapper;
  2650. renderer.alignedObjects = [];
  2651. // Page url used for internal references. #24, #672, #1070
  2652. renderer.url = (isFirefox || isWebKit) && doc.getElementsByTagName('base').length ?
  2653. loc.href
  2654. .replace(/#.*?$/, '') // remove the hash
  2655. .replace(/([\('\)])/g, '\\$1') // escape parantheses and quotes
  2656. .replace(/ /g, '%20') : // replace spaces (needed for Safari only)
  2657. '';
  2658. // Add description
  2659. desc = this.createElement('desc').add();
  2660. desc.element.appendChild(doc.createTextNode('Created with ' + PRODUCT + ' ' + VERSION));
  2661. renderer.defs = this.createElement('defs').add();
  2662. renderer.allowHTML = allowHTML;
  2663. renderer.forExport = forExport;
  2664. renderer.gradients = {}; // Object where gradient SvgElements are stored
  2665. renderer.cache = {}; // Cache for numerical bounding boxes
  2666. renderer.setSize(width, height, false);
  2667. // Issue 110 workaround:
  2668. // In Firefox, if a div is positioned by percentage, its pixel position may land
  2669. // between pixels. The container itself doesn't display this, but an SVG element
  2670. // inside this container will be drawn at subpixel precision. In order to draw
  2671. // sharp lines, this must be compensated for. This doesn't seem to work inside
  2672. // iframes though (like in jsFiddle).
  2673. var subPixelFix, rect;
  2674. if (isFirefox && container.getBoundingClientRect) {
  2675. renderer.subPixelFix = subPixelFix = function () {
  2676. css(container, { left: 0, top: 0 });
  2677. rect = container.getBoundingClientRect();
  2678. css(container, {
  2679. left: (mathCeil(rect.left) - rect.left) + PX,
  2680. top: (mathCeil(rect.top) - rect.top) + PX
  2681. });
  2682. };
  2683. // run the fix now
  2684. subPixelFix();
  2685. // run it on resize
  2686. addEvent(win, 'resize', subPixelFix);
  2687. }
  2688. },
  2689. getStyle: function (style) {
  2690. return (this.style = extend({
  2691. fontFamily: '"Lucida Grande", "Lucida Sans Unicode", Arial, Helvetica, sans-serif', // default font
  2692. fontSize: '12px'
  2693. }, style));
  2694. },
  2695. /**
  2696. * Detect whether the renderer is hidden. This happens when one of the parent elements
  2697. * has display: none. #608.
  2698. */
  2699. isHidden: function () {
  2700. return !this.boxWrapper.getBBox().width;
  2701. },
  2702. /**
  2703. * Destroys the renderer and its allocated members.
  2704. */
  2705. destroy: function () {
  2706. var renderer = this,
  2707. rendererDefs = renderer.defs;
  2708. renderer.box = null;
  2709. renderer.boxWrapper = renderer.boxWrapper.destroy();
  2710. // Call destroy on all gradient elements
  2711. destroyObjectProperties(renderer.gradients || {});
  2712. renderer.gradients = null;
  2713. // Defs are null in VMLRenderer
  2714. // Otherwise, destroy them here.
  2715. if (rendererDefs) {
  2716. renderer.defs = rendererDefs.destroy();
  2717. }
  2718. // Remove sub pixel fix handler
  2719. // We need to check that there is a handler, otherwise all functions that are registered for event 'resize' are removed
  2720. // See issue #982
  2721. if (renderer.subPixelFix) {
  2722. removeEvent(win, 'resize', renderer.subPixelFix);
  2723. }
  2724. renderer.alignedObjects = null;
  2725. return null;
  2726. },
  2727. /**
  2728. * Create a wrapper for an SVG element
  2729. * @param {Object} nodeName
  2730. */
  2731. createElement: function (nodeName) {
  2732. var wrapper = new this.Element();
  2733. wrapper.init(this, nodeName);
  2734. return wrapper;
  2735. },
  2736. /**
  2737. * Dummy function for use in canvas renderer
  2738. */
  2739. draw: function () {},
  2740. /**
  2741. * Get converted radial gradient attributes
  2742. */
  2743. getRadialAttr: function (radialReference, gradAttr) {
  2744. return {
  2745. cx: (radialReference[0] - radialReference[2] / 2) + gradAttr.cx * radialReference[2],
  2746. cy: (radialReference[1] - radialReference[2] / 2) + gradAttr.cy * radialReference[2],
  2747. r: gradAttr.r * radialReference[2]
  2748. };
  2749. },
  2750. /**
  2751. * Parse a simple HTML string into SVG tspans
  2752. *
  2753. * @param {Object} textNode The parent text SVG node
  2754. */
  2755. buildText: function (wrapper) {
  2756. var textNode = wrapper.element,
  2757. renderer = this,
  2758. forExport = renderer.forExport,
  2759. textStr = pick(wrapper.textStr, '').toString(),
  2760. hasMarkup = textStr.indexOf('<') !== -1,
  2761. lines,
  2762. childNodes = textNode.childNodes,
  2763. styleRegex,
  2764. hrefRegex,
  2765. parentX = attr(textNode, 'x'),
  2766. textStyles = wrapper.styles,
  2767. width = wrapper.textWidth,
  2768. textLineHeight = textStyles && textStyles.lineHeight,
  2769. textShadow = textStyles && textStyles.textShadow,
  2770. ellipsis = textStyles && textStyles.textOverflow === 'ellipsis',
  2771. i = childNodes.length,
  2772. tempParent = width && !wrapper.added && this.box,
  2773. getLineHeight = function (tspan) {
  2774. return textLineHeight ?
  2775. pInt(textLineHeight) :
  2776. renderer.fontMetrics(
  2777. /(px|em)$/.test(tspan && tspan.style.fontSize) ?
  2778. tspan.style.fontSize :
  2779. ((textStyles && textStyles.fontSize) || renderer.style.fontSize || 12),
  2780. tspan
  2781. ).h;
  2782. },
  2783. unescapeAngleBrackets = function (inputStr) {
  2784. return inputStr.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
  2785. };
  2786. /// remove old text
  2787. while (i--) {
  2788. textNode.removeChild(childNodes[i]);
  2789. }
  2790. // Skip tspans, add text directly to text node. The forceTSpan is a hook
  2791. // used in text outline hack.
  2792. if (!hasMarkup && !textShadow && !ellipsis && textStr.indexOf(' ') === -1) {
  2793. textNode.appendChild(doc.createTextNode(unescapeAngleBrackets(textStr)));
  2794. return;
  2795. // Complex strings, add more logic
  2796. } else {
  2797. styleRegex = /<.*style="([^"]+)".*>/;
  2798. hrefRegex = /<.*href="(http[^"]+)".*>/;
  2799. if (tempParent) {
  2800. tempParent.appendChild(textNode); // attach it to the DOM to read offset width
  2801. }
  2802. if (hasMarkup) {
  2803. lines = textStr
  2804. .replace(/<(b|strong)>/g, '<span style="font-weight:bold">')
  2805. .replace(/<(i|em)>/g, '<span style="font-style:italic">')
  2806. .replace(/<a/g, '<span')
  2807. .replace(/<\/(b|strong|i|em|a)>/g, '</span>')
  2808. .split(/<br.*?>/g);
  2809. } else {
  2810. lines = [textStr];
  2811. }
  2812. // remove empty line at end
  2813. if (lines[lines.length - 1] === '') {
  2814. lines.pop();
  2815. }
  2816. // build the lines
  2817. each(lines, function (line, lineNo) {
  2818. var spans, spanNo = 0;
  2819. line = line.replace(/<span/g, '|||<span').replace(/<\/span>/g, '</span>|||');
  2820. spans = line.split('|||');
  2821. each(spans, function (span) {
  2822. if (span !== '' || spans.length === 1) {
  2823. var attributes = {},
  2824. tspan = doc.createElementNS(SVG_NS, 'tspan'),
  2825. spanStyle; // #390
  2826. if (styleRegex.test(span)) {
  2827. spanStyle = span.match(styleRegex)[1].replace(/(;| |^)color([ :])/, '$1fill$2');
  2828. attr(tspan, 'style', spanStyle);
  2829. }
  2830. if (hrefRegex.test(span) && !forExport) { // Not for export - #1529
  2831. attr(tspan, 'onclick', 'location.href=\"' + span.match(hrefRegex)[1] + '\"');
  2832. css(tspan, { cursor: 'pointer' });
  2833. }
  2834. span = unescapeAngleBrackets(span.replace(/<(.|\n)*?>/g, '') || ' ');
  2835. // Nested tags aren't supported, and cause crash in Safari (#1596)
  2836. if (span !== ' ') {
  2837. // add the text node
  2838. tspan.appendChild(doc.createTextNode(span));
  2839. if (!spanNo) { // first span in a line, align it to the left
  2840. if (lineNo && parentX !== null) {
  2841. attributes.x = parentX;
  2842. }
  2843. } else {
  2844. attributes.dx = 0; // #16
  2845. }
  2846. // add attributes
  2847. attr(tspan, attributes);
  2848. // Append it
  2849. textNode.appendChild(tspan);
  2850. // first span on subsequent line, add the line height
  2851. if (!spanNo && lineNo) {
  2852. // allow getting the right offset height in exporting in IE
  2853. if (!hasSVG && forExport) {
  2854. css(tspan, { display: 'block' });
  2855. }
  2856. // Set the line height based on the font size of either
  2857. // the text element or the tspan element
  2858. attr(
  2859. tspan,
  2860. 'dy',
  2861. getLineHeight(tspan)
  2862. );
  2863. }
  2864. /*if (width) {
  2865. renderer.breakText(wrapper, width);
  2866. }*/
  2867. // Check width and apply soft breaks or ellipsis
  2868. if (width) {
  2869. var words = span.replace(/([^\^])-/g, '$1- ').split(' '), // #1273
  2870. hasWhiteSpace = spans.length > 1 || lineNo || (words.length > 1 && textStyles.whiteSpace !== 'nowrap'),
  2871. tooLong,
  2872. wasTooLong,
  2873. actualWidth,
  2874. rest = [],
  2875. dy = getLineHeight(tspan),
  2876. softLineNo = 1,
  2877. rotation = wrapper.rotation,
  2878. wordStr = span, // for ellipsis
  2879. cursor = wordStr.length, // binary search cursor
  2880. bBox;
  2881. while ((hasWhiteSpace || ellipsis) && (words.length || rest.length)) {
  2882. wrapper.rotation = 0; // discard rotation when computing box
  2883. bBox = wrapper.getBBox(true);
  2884. actualWidth = bBox.width;
  2885. // Old IE cannot measure the actualWidth for SVG elements (#2314)
  2886. if (!hasSVG && renderer.forExport) {
  2887. actualWidth = renderer.measureSpanWidth(tspan.firstChild.data, wrapper.styles);
  2888. }
  2889. tooLong = actualWidth > width;
  2890. // For ellipsis, do a binary search for the correct string length
  2891. if (wasTooLong === undefined) {
  2892. wasTooLong = tooLong; // First time
  2893. }
  2894. if (ellipsis && wasTooLong) {
  2895. cursor /= 2;
  2896. if (wordStr === '' || (!tooLong && cursor < 0.5)) {
  2897. words = []; // All ok, break out
  2898. } else {
  2899. if (tooLong) {
  2900. wasTooLong = true;
  2901. }
  2902. wordStr = span.substring(0, wordStr.length + (tooLong ? -1 : 1) * mathCeil(cursor));
  2903. words = [wordStr + (width > 3 ? '\u2026' : '')];
  2904. tspan.removeChild(tspan.firstChild);
  2905. }
  2906. // Looping down, this is the first word sequence that is not too long,
  2907. // so we can move on to build the next line.
  2908. } else if (!tooLong || words.length === 1) {
  2909. words = rest;
  2910. rest = [];
  2911. if (words.length) {
  2912. softLineNo++;
  2913. tspan = doc.createElementNS(SVG_NS, 'tspan');
  2914. attr(tspan, {
  2915. dy: dy,
  2916. x: parentX
  2917. });
  2918. if (spanStyle) { // #390
  2919. attr(tspan, 'style', spanStyle);
  2920. }
  2921. textNode.appendChild(tspan);
  2922. }
  2923. if (actualWidth > width) { // a single word is pressing it out
  2924. width = actualWidth;
  2925. }
  2926. } else { // append to existing line tspan
  2927. tspan.removeChild(tspan.firstChild);
  2928. rest.unshift(words.pop());
  2929. }
  2930. if (words.length) {
  2931. tspan.appendChild(doc.createTextNode(words.join(' ').replace(/- /g, '-')));
  2932. }
  2933. }
  2934. if (wasTooLong) {
  2935. wrapper.attr('title', wrapper.textStr);
  2936. }
  2937. wrapper.rotation = rotation;
  2938. }
  2939. spanNo++;
  2940. }
  2941. }
  2942. });
  2943. });
  2944. if (tempParent) {
  2945. tempParent.removeChild(textNode); // attach it to the DOM to read offset width
  2946. }
  2947. // Apply the text shadow
  2948. if (textShadow && wrapper.applyTextShadow) {
  2949. wrapper.applyTextShadow(textShadow);
  2950. }
  2951. }
  2952. },
  2953. /*
  2954. breakText: function (wrapper, width) {
  2955. var bBox = wrapper.getBBox(),
  2956. node = wrapper.element,
  2957. textLength = node.textContent.length,
  2958. pos = mathRound(width * textLength / bBox.width), // try this position first, based on average character width
  2959. increment = 0,
  2960. finalPos;
  2961. if (bBox.width > width) {
  2962. while (finalPos === undefined) {
  2963. textLength = node.getSubStringLength(0, pos);
  2964. if (textLength <= width) {
  2965. if (increment === -1) {
  2966. finalPos = pos;
  2967. } else {
  2968. increment = 1;
  2969. }
  2970. } else {
  2971. if (increment === 1) {
  2972. finalPos = pos - 1;
  2973. } else {
  2974. increment = -1;
  2975. }
  2976. }
  2977. pos += increment;
  2978. }
  2979. }
  2980. console.log(finalPos, node.getSubStringLength(0, finalPos))
  2981. },
  2982. */
  2983. /**
  2984. * Returns white for dark colors and black for bright colors
  2985. */
  2986. getContrast: function (color) {
  2987. color = Color(color).rgba;
  2988. return color[0] + color[1] + color[2] > 384 ? '#000000' : '#FFFFFF';
  2989. },
  2990. /**
  2991. * Create a button with preset states
  2992. * @param {String} text
  2993. * @param {Number} x
  2994. * @param {Number} y
  2995. * @param {Function} callback
  2996. * @param {Object} normalState
  2997. * @param {Object} hoverState
  2998. * @param {Object} pressedState
  2999. */
  3000. button: function (text, x, y, callback, normalState, hoverState, pressedState, disabledState, shape) {
  3001. var label = this.label(text, x, y, shape, null, null, null, null, 'button'),
  3002. curState = 0,
  3003. stateOptions,
  3004. stateStyle,
  3005. normalStyle,
  3006. hoverStyle,
  3007. pressedStyle,
  3008. disabledStyle,
  3009. verticalGradient = { x1: 0, y1: 0, x2: 0, y2: 1 };
  3010. // Normal state - prepare the attributes
  3011. normalState = merge({
  3012. 'stroke-width': 1,
  3013. stroke: '#CCCCCC',
  3014. fill: {
  3015. linearGradient: verticalGradient,
  3016. stops: [
  3017. [0, '#FEFEFE'],
  3018. [1, '#F6F6F6']
  3019. ]
  3020. },
  3021. r: 2,
  3022. padding: 5,
  3023. style: {
  3024. color: 'black'
  3025. }
  3026. }, normalState);
  3027. normalStyle = normalState.style;
  3028. delete normalState.style;
  3029. // Hover state
  3030. hoverState = merge(normalState, {
  3031. stroke: '#68A',
  3032. fill: {
  3033. linearGradient: verticalGradient,
  3034. stops: [
  3035. [0, '#FFF'],
  3036. [1, '#ACF']
  3037. ]
  3038. }
  3039. }, hoverState);
  3040. hoverStyle = hoverState.style;
  3041. delete hoverState.style;
  3042. // Pressed state
  3043. pressedState = merge(normalState, {
  3044. stroke: '#68A',
  3045. fill: {
  3046. linearGradient: verticalGradient,
  3047. stops: [
  3048. [0, '#9BD'],
  3049. [1, '#CDF']
  3050. ]
  3051. }
  3052. }, pressedState);
  3053. pressedStyle = pressedState.style;
  3054. delete pressedState.style;
  3055. // Disabled state
  3056. disabledState = merge(normalState, {
  3057. style: {
  3058. color: '#CCC'
  3059. }
  3060. }, disabledState);
  3061. disabledStyle = disabledState.style;
  3062. delete disabledState.style;
  3063. // Add the events. IE9 and IE10 need mouseover and mouseout to funciton (#667).
  3064. addEvent(label.element, isMS ? 'mouseover' : 'mouseenter', function () {
  3065. if (curState !== 3) {
  3066. label.attr(hoverState)
  3067. .css(hoverStyle);
  3068. }
  3069. });
  3070. addEvent(label.element, isMS ? 'mouseout' : 'mouseleave', function () {
  3071. if (curState !== 3) {
  3072. stateOptions = [normalState, hoverState, pressedState][curState];
  3073. stateStyle = [normalStyle, hoverStyle, pressedStyle][curState];
  3074. label.attr(stateOptions)
  3075. .css(stateStyle);
  3076. }
  3077. });
  3078. label.setState = function (state) {
  3079. label.state = curState = state;
  3080. if (!state) {
  3081. label.attr(normalState)
  3082. .css(normalStyle);
  3083. } else if (state === 2) {
  3084. label.attr(pressedState)
  3085. .css(pressedStyle);
  3086. } else if (state === 3) {
  3087. label.attr(disabledState)
  3088. .css(disabledStyle);
  3089. }
  3090. };
  3091. return label
  3092. .on('click', function (e) {
  3093. if (curState !== 3) {
  3094. callback.call(label, e);
  3095. }
  3096. })
  3097. .attr(normalState)
  3098. .css(extend({ cursor: 'default' }, normalStyle));
  3099. },
  3100. /**
  3101. * Make a straight line crisper by not spilling out to neighbour pixels
  3102. * @param {Array} points
  3103. * @param {Number} width
  3104. */
  3105. crispLine: function (points, width) {
  3106. // points format: [M, 0, 0, L, 100, 0]
  3107. // normalize to a crisp line
  3108. if (points[1] === points[4]) {
  3109. // Substract due to #1129. Now bottom and left axis gridlines behave the same.
  3110. points[1] = points[4] = mathRound(points[1]) - (width % 2 / 2);
  3111. }
  3112. if (points[2] === points[5]) {
  3113. points[2] = points[5] = mathRound(points[2]) + (width % 2 / 2);
  3114. }
  3115. return points;
  3116. },
  3117. /**
  3118. * Draw a path
  3119. * @param {Array} path An SVG path in array form
  3120. */
  3121. path: function (path) {
  3122. var attr = {
  3123. fill: NONE
  3124. };
  3125. if (isArray(path)) {
  3126. attr.d = path;
  3127. } else if (isObject(path)) { // attributes
  3128. extend(attr, path);
  3129. }
  3130. return this.createElement('path').attr(attr);
  3131. },
  3132. /**
  3133. * Draw and return an SVG circle
  3134. * @param {Number} x The x position
  3135. * @param {Number} y The y position
  3136. * @param {Number} r The radius
  3137. */
  3138. circle: function (x, y, r) {
  3139. var attr = isObject(x) ?
  3140. x :
  3141. {
  3142. x: x,
  3143. y: y,
  3144. r: r
  3145. },
  3146. wrapper = this.createElement('circle');
  3147. wrapper.xSetter = function (value) {
  3148. this.element.setAttribute('cx', value);
  3149. };
  3150. wrapper.ySetter = function (value) {
  3151. this.element.setAttribute('cy', value);
  3152. };
  3153. return wrapper.attr(attr);
  3154. },
  3155. /**
  3156. * Draw and return an arc
  3157. * @param {Number} x X position
  3158. * @param {Number} y Y position
  3159. * @param {Number} r Radius
  3160. * @param {Number} innerR Inner radius like used in donut charts
  3161. * @param {Number} start Starting angle
  3162. * @param {Number} end Ending angle
  3163. */
  3164. arc: function (x, y, r, innerR, start, end) {
  3165. var arc;
  3166. if (isObject(x)) {
  3167. y = x.y;
  3168. r = x.r;
  3169. innerR = x.innerR;
  3170. start = x.start;
  3171. end = x.end;
  3172. x = x.x;
  3173. }
  3174. // Arcs are defined as symbols for the ability to set
  3175. // attributes in attr and animate
  3176. arc = this.symbol('arc', x || 0, y || 0, r || 0, r || 0, {
  3177. innerR: innerR || 0,
  3178. start: start || 0,
  3179. end: end || 0
  3180. });
  3181. arc.r = r; // #959
  3182. return arc;
  3183. },
  3184. /**
  3185. * Draw and return a rectangle
  3186. * @param {Number} x Left position
  3187. * @param {Number} y Top position
  3188. * @param {Number} width
  3189. * @param {Number} height
  3190. * @param {Number} r Border corner radius
  3191. * @param {Number} strokeWidth A stroke width can be supplied to allow crisp drawing
  3192. */
  3193. rect: function (x, y, width, height, r, strokeWidth) {
  3194. r = isObject(x) ? x.r : r;
  3195. var wrapper = this.createElement('rect'),
  3196. attribs = isObject(x) ? x : x === UNDEFINED ? {} : {
  3197. x: x,
  3198. y: y,
  3199. width: mathMax(width, 0),
  3200. height: mathMax(height, 0)
  3201. };
  3202. if (strokeWidth !== UNDEFINED) {
  3203. attribs.strokeWidth = strokeWidth;
  3204. attribs = wrapper.crisp(attribs);
  3205. }
  3206. if (r) {
  3207. attribs.r = r;
  3208. }
  3209. wrapper.rSetter = function (value) {
  3210. attr(this.element, {
  3211. rx: value,
  3212. ry: value
  3213. });
  3214. };
  3215. return wrapper.attr(attribs);
  3216. },
  3217. /**
  3218. * Resize the box and re-align all aligned elements
  3219. * @param {Object} width
  3220. * @param {Object} height
  3221. * @param {Boolean} animate
  3222. *
  3223. */
  3224. setSize: function (width, height, animate) {
  3225. var renderer = this,
  3226. alignedObjects = renderer.alignedObjects,
  3227. i = alignedObjects.length;
  3228. renderer.width = width;
  3229. renderer.height = height;
  3230. renderer.boxWrapper[pick(animate, true) ? 'animate' : 'attr']({
  3231. width: width,
  3232. height: height
  3233. });
  3234. while (i--) {
  3235. alignedObjects[i].align();
  3236. }
  3237. },
  3238. /**
  3239. * Create a group
  3240. * @param {String} name The group will be given a class name of 'highcharts-{name}'.
  3241. * This can be used for styling and scripting.
  3242. */
  3243. g: function (name) {
  3244. var elem = this.createElement('g');
  3245. return defined(name) ? elem.attr({ 'class': PREFIX + name }) : elem;
  3246. },
  3247. /**
  3248. * Display an image
  3249. * @param {String} src
  3250. * @param {Number} x
  3251. * @param {Number} y
  3252. * @param {Number} width
  3253. * @param {Number} height
  3254. */
  3255. image: function (src, x, y, width, height) {
  3256. var attribs = {
  3257. preserveAspectRatio: NONE
  3258. },
  3259. elemWrapper;
  3260. // optional properties
  3261. if (arguments.length > 1) {
  3262. extend(attribs, {
  3263. x: x,
  3264. y: y,
  3265. width: width,
  3266. height: height
  3267. });
  3268. }
  3269. elemWrapper = this.createElement('image').attr(attribs);
  3270. // set the href in the xlink namespace
  3271. if (elemWrapper.element.setAttributeNS) {
  3272. elemWrapper.element.setAttributeNS('http://www.w3.org/1999/xlink',
  3273. 'href', src);
  3274. } else {
  3275. // could be exporting in IE
  3276. // using href throws "not supported" in ie7 and under, requries regex shim to fix later
  3277. elemWrapper.element.setAttribute('hc-svg-href', src);
  3278. }
  3279. return elemWrapper;
  3280. },
  3281. /**
  3282. * Draw a symbol out of pre-defined shape paths from the namespace 'symbol' object.
  3283. *
  3284. * @param {Object} symbol
  3285. * @param {Object} x
  3286. * @param {Object} y
  3287. * @param {Object} radius
  3288. * @param {Object} options
  3289. */
  3290. symbol: function (symbol, x, y, width, height, options) {
  3291. var obj,
  3292. // get the symbol definition function
  3293. symbolFn = this.symbols[symbol],
  3294. // check if there's a path defined for this symbol
  3295. path = symbolFn && symbolFn(
  3296. mathRound(x),
  3297. mathRound(y),
  3298. width,
  3299. height,
  3300. options
  3301. ),
  3302. imageElement,
  3303. imageRegex = /^url\((.*?)\)$/,
  3304. imageSrc,
  3305. imageSize,
  3306. centerImage;
  3307. if (path) {
  3308. obj = this.path(path);
  3309. // expando properties for use in animate and attr
  3310. extend(obj, {
  3311. symbolName: symbol,
  3312. x: x,
  3313. y: y,
  3314. width: width,
  3315. height: height
  3316. });
  3317. if (options) {
  3318. extend(obj, options);
  3319. }
  3320. // image symbols
  3321. } else if (imageRegex.test(symbol)) {
  3322. // On image load, set the size and position
  3323. centerImage = function (img, size) {
  3324. if (img.element) { // it may be destroyed in the meantime (#1390)
  3325. img.attr({
  3326. width: size[0],
  3327. height: size[1]
  3328. });
  3329. if (!img.alignByTranslate) { // #185
  3330. img.translate(
  3331. mathRound((width - size[0]) / 2), // #1378
  3332. mathRound((height - size[1]) / 2)
  3333. );
  3334. }
  3335. }
  3336. };
  3337. imageSrc = symbol.match(imageRegex)[1];
  3338. imageSize = symbolSizes[imageSrc] || (options && options.width && options.height && [options.width, options.height]);
  3339. // Ireate the image synchronously, add attribs async
  3340. obj = this.image(imageSrc)
  3341. .attr({
  3342. x: x,
  3343. y: y
  3344. });
  3345. obj.isImg = true;
  3346. if (imageSize) {
  3347. centerImage(obj, imageSize);
  3348. } else {
  3349. // Initialize image to be 0 size so export will still function if there's no cached sizes.
  3350. obj.attr({ width: 0, height: 0 });
  3351. // Create a dummy JavaScript image to get the width and height. Due to a bug in IE < 8,
  3352. // the created element must be assigned to a variable in order to load (#292).
  3353. imageElement = createElement('img', {
  3354. onload: function () {
  3355. // Special case for SVGs on IE11, the width is not accessible until the image is
  3356. // part of the DOM (#2854).
  3357. if (this.width === 0) {
  3358. css(this, {
  3359. position: ABSOLUTE,
  3360. top: '-999em'
  3361. });
  3362. document.body.appendChild(this);
  3363. }
  3364. // Center the image
  3365. centerImage(obj, symbolSizes[imageSrc] = [this.width, this.height]);
  3366. // Clean up after #2854 workaround.
  3367. if (this.parentNode) {
  3368. this.parentNode.removeChild(this);
  3369. }
  3370. },
  3371. src: imageSrc
  3372. });
  3373. }
  3374. }
  3375. return obj;
  3376. },
  3377. /**
  3378. * An extendable collection of functions for defining symbol paths.
  3379. */
  3380. symbols: {
  3381. 'circle': function (x, y, w, h) {
  3382. var cpw = 0.166 * w;
  3383. return [
  3384. M, x + w / 2, y,
  3385. 'C', x + w + cpw, y, x + w + cpw, y + h, x + w / 2, y + h,
  3386. 'C', x - cpw, y + h, x - cpw, y, x + w / 2, y,
  3387. 'Z'
  3388. ];
  3389. },
  3390. 'square': function (x, y, w, h) {
  3391. return [
  3392. M, x, y,
  3393. L, x + w, y,
  3394. x + w, y + h,
  3395. x, y + h,
  3396. 'Z'
  3397. ];
  3398. },
  3399. 'triangle': function (x, y, w, h) {
  3400. return [
  3401. M, x + w / 2, y,
  3402. L, x + w, y + h,
  3403. x, y + h,
  3404. 'Z'
  3405. ];
  3406. },
  3407. 'triangle-down': function (x, y, w, h) {
  3408. return [
  3409. M, x, y,
  3410. L, x + w, y,
  3411. x + w / 2, y + h,
  3412. 'Z'
  3413. ];
  3414. },
  3415. 'diamond': function (x, y, w, h) {
  3416. return [
  3417. M, x + w / 2, y,
  3418. L, x + w, y + h / 2,
  3419. x + w / 2, y + h,
  3420. x, y + h / 2,
  3421. 'Z'
  3422. ];
  3423. },
  3424. 'arc': function (x, y, w, h, options) {
  3425. var start = options.start,
  3426. radius = options.r || w || h,
  3427. end = options.end - 0.001, // to prevent cos and sin of start and end from becoming equal on 360 arcs (related: #1561)
  3428. innerRadius = options.innerR,
  3429. open = options.open,
  3430. cosStart = mathCos(start),
  3431. sinStart = mathSin(start),
  3432. cosEnd = mathCos(end),
  3433. sinEnd = mathSin(end),
  3434. longArc = options.end - start < mathPI ? 0 : 1;
  3435. return [
  3436. M,
  3437. x + radius * cosStart,
  3438. y + radius * sinStart,
  3439. 'A', // arcTo
  3440. radius, // x radius
  3441. radius, // y radius
  3442. 0, // slanting
  3443. longArc, // long or short arc
  3444. 1, // clockwise
  3445. x + radius * cosEnd,
  3446. y + radius * sinEnd,
  3447. open ? M : L,
  3448. x + innerRadius * cosEnd,
  3449. y + innerRadius * sinEnd,
  3450. 'A', // arcTo
  3451. innerRadius, // x radius
  3452. innerRadius, // y radius
  3453. 0, // slanting
  3454. longArc, // long or short arc
  3455. 0, // clockwise
  3456. x + innerRadius * cosStart,
  3457. y + innerRadius * sinStart,
  3458. open ? '' : 'Z' // close
  3459. ];
  3460. },
  3461. /**
  3462. * Callout shape used for default tooltips, also used for rounded rectangles in VML
  3463. */
  3464. callout: function (x, y, w, h, options) {
  3465. var arrowLength = 6,
  3466. halfDistance = 6,
  3467. r = mathMin((options && options.r) || 0, w, h),
  3468. safeDistance = r + halfDistance,
  3469. anchorX = options && options.anchorX,
  3470. anchorY = options && options.anchorY,
  3471. path;
  3472. path = [
  3473. 'M', x + r, y,
  3474. 'L', x + w - r, y, // top side
  3475. 'C', x + w, y, x + w, y, x + w, y + r, // top-right corner
  3476. 'L', x + w, y + h - r, // right side
  3477. 'C', x + w, y + h, x + w, y + h, x + w - r, y + h, // bottom-right corner
  3478. 'L', x + r, y + h, // bottom side
  3479. 'C', x, y + h, x, y + h, x, y + h - r, // bottom-left corner
  3480. 'L', x, y + r, // left side
  3481. 'C', x, y, x, y, x + r, y // top-right corner
  3482. ];
  3483. if (anchorX && anchorX > w && anchorY > y + safeDistance && anchorY < y + h - safeDistance) { // replace right side
  3484. path.splice(13, 3,
  3485. 'L', x + w, anchorY - halfDistance,
  3486. x + w + arrowLength, anchorY,
  3487. x + w, anchorY + halfDistance,
  3488. x + w, y + h - r
  3489. );
  3490. } else if (anchorX && anchorX < 0 && anchorY > y + safeDistance && anchorY < y + h - safeDistance) { // replace left side
  3491. path.splice(33, 3,
  3492. 'L', x, anchorY + halfDistance,
  3493. x - arrowLength, anchorY,
  3494. x, anchorY - halfDistance,
  3495. x, y + r
  3496. );
  3497. } else if (anchorY && anchorY > h && anchorX > x + safeDistance && anchorX < x + w - safeDistance) { // replace bottom
  3498. path.splice(23, 3,
  3499. 'L', anchorX + halfDistance, y + h,
  3500. anchorX, y + h + arrowLength,
  3501. anchorX - halfDistance, y + h,
  3502. x + r, y + h
  3503. );
  3504. } else if (anchorY && anchorY < 0 && anchorX > x + safeDistance && anchorX < x + w - safeDistance) { // replace top
  3505. path.splice(3, 3,
  3506. 'L', anchorX - halfDistance, y,
  3507. anchorX, y - arrowLength,
  3508. anchorX + halfDistance, y,
  3509. w - r, y
  3510. );
  3511. }
  3512. return path;
  3513. }
  3514. },
  3515. /**
  3516. * Define a clipping rectangle
  3517. * @param {String} id
  3518. * @param {Number} x
  3519. * @param {Number} y
  3520. * @param {Number} width
  3521. * @param {Number} height
  3522. */
  3523. clipRect: function (x, y, width, height) {
  3524. var wrapper,
  3525. id = PREFIX + idCounter++,
  3526. clipPath = this.createElement('clipPath').attr({
  3527. id: id
  3528. }).add(this.defs);
  3529. wrapper = this.rect(x, y, width, height, 0).add(clipPath);
  3530. wrapper.id = id;
  3531. wrapper.clipPath = clipPath;
  3532. wrapper.count = 0;
  3533. return wrapper;
  3534. },
  3535. /**
  3536. * Add text to the SVG object
  3537. * @param {String} str
  3538. * @param {Number} x Left position
  3539. * @param {Number} y Top position
  3540. * @param {Boolean} useHTML Use HTML to render the text
  3541. */
  3542. text: function (str, x, y, useHTML) {
  3543. // declare variables
  3544. var renderer = this,
  3545. fakeSVG = useCanVG || (!hasSVG && renderer.forExport),
  3546. wrapper,
  3547. attr = {};
  3548. if (useHTML && (renderer.allowHTML || !renderer.forExport)) {
  3549. return renderer.html(str, x, y);
  3550. }
  3551. attr.x = Math.round(x || 0); // X is always needed for line-wrap logic
  3552. if (y) {
  3553. attr.y = Math.round(y);
  3554. }
  3555. if (str || str === 0) {
  3556. attr.text = str;
  3557. }
  3558. wrapper = renderer.createElement('text')
  3559. .attr(attr);
  3560. // Prevent wrapping from creating false offsetWidths in export in legacy IE (#1079, #1063)
  3561. if (fakeSVG) {
  3562. wrapper.css({
  3563. position: ABSOLUTE
  3564. });
  3565. }
  3566. if (!useHTML) {
  3567. wrapper.xSetter = function (value, key, element) {
  3568. var tspans = element.getElementsByTagName('tspan'),
  3569. tspan,
  3570. parentVal = element.getAttribute(key),
  3571. i;
  3572. for (i = 0; i < tspans.length; i++) {
  3573. tspan = tspans[i];
  3574. // If the x values are equal, the tspan represents a linebreak
  3575. if (tspan.getAttribute(key) === parentVal) {
  3576. tspan.setAttribute(key, value);
  3577. }
  3578. }
  3579. element.setAttribute(key, value);
  3580. };
  3581. }
  3582. return wrapper;
  3583. },
  3584. /**
  3585. * Utility to return the baseline offset and total line height from the font size
  3586. */
  3587. fontMetrics: function (fontSize, elem) {
  3588. var lineHeight,
  3589. baseline,
  3590. style;
  3591. fontSize = fontSize || this.style.fontSize;
  3592. if (!fontSize && elem && win.getComputedStyle) {
  3593. elem = elem.element || elem; // SVGElement
  3594. style = win.getComputedStyle(elem, "");
  3595. fontSize = style && style.fontSize; // #4309, the style doesn't exist inside a hidden iframe in Firefox
  3596. }
  3597. fontSize = /px/.test(fontSize) ? pInt(fontSize) : /em/.test(fontSize) ? parseFloat(fontSize) * 12 : 12;
  3598. // Empirical values found by comparing font size and bounding box height.
  3599. // Applies to the default font family. http://jsfiddle.net/highcharts/7xvn7/
  3600. lineHeight = fontSize < 24 ? fontSize + 3 : mathRound(fontSize * 1.2);
  3601. baseline = mathRound(lineHeight * 0.8);
  3602. return {
  3603. h: lineHeight,
  3604. b: baseline,
  3605. f: fontSize
  3606. };
  3607. },
  3608. /**
  3609. * Correct X and Y positioning of a label for rotation (#1764)
  3610. */
  3611. rotCorr: function (baseline, rotation, alterY) {
  3612. var y = baseline;
  3613. if (rotation && alterY) {
  3614. y = mathMax(y * mathCos(rotation * deg2rad), 4);
  3615. }
  3616. return {
  3617. x: (-baseline / 3) * mathSin(rotation * deg2rad),
  3618. y: y
  3619. };
  3620. },
  3621. /**
  3622. * Add a label, a text item that can hold a colored or gradient background
  3623. * as well as a border and shadow.
  3624. * @param {string} str
  3625. * @param {Number} x
  3626. * @param {Number} y
  3627. * @param {String} shape
  3628. * @param {Number} anchorX In case the shape has a pointer, like a flag, this is the
  3629. * coordinates it should be pinned to
  3630. * @param {Number} anchorY
  3631. * @param {Boolean} baseline Whether to position the label relative to the text baseline,
  3632. * like renderer.text, or to the upper border of the rectangle.
  3633. * @param {String} className Class name for the group
  3634. */
  3635. label: function (str, x, y, shape, anchorX, anchorY, useHTML, baseline, className) {
  3636. var renderer = this,
  3637. wrapper = renderer.g(className),
  3638. text = renderer.text('', 0, 0, useHTML)
  3639. .attr({
  3640. zIndex: 1
  3641. }),
  3642. //.add(wrapper),
  3643. box,
  3644. bBox,
  3645. alignFactor = 0,
  3646. padding = 3,
  3647. paddingLeft = 0,
  3648. width,
  3649. height,
  3650. wrapperX,
  3651. wrapperY,
  3652. crispAdjust = 0,
  3653. deferredAttr = {},
  3654. baselineOffset,
  3655. needsBox;
  3656. /**
  3657. * This function runs after the label is added to the DOM (when the bounding box is
  3658. * available), and after the text of the label is updated to detect the new bounding
  3659. * box and reflect it in the border box.
  3660. */
  3661. function updateBoxSize() {
  3662. var boxX,
  3663. boxY,
  3664. style = text.element.style;
  3665. bBox = (width === undefined || height === undefined || wrapper.styles.textAlign) && defined(text.textStr) &&
  3666. text.getBBox(); //#3295 && 3514 box failure when string equals 0
  3667. wrapper.width = (width || bBox.width || 0) + 2 * padding + paddingLeft;
  3668. wrapper.height = (height || bBox.height || 0) + 2 * padding;
  3669. // update the label-scoped y offset
  3670. baselineOffset = padding + renderer.fontMetrics(style && style.fontSize, text).b;
  3671. if (needsBox) {
  3672. // create the border box if it is not already present
  3673. if (!box) {
  3674. boxX = mathRound(-alignFactor * padding) + crispAdjust;
  3675. boxY = (baseline ? -baselineOffset : 0) + crispAdjust;
  3676. wrapper.box = box = shape ?
  3677. renderer.symbol(shape, boxX, boxY, wrapper.width, wrapper.height, deferredAttr) :
  3678. renderer.rect(boxX, boxY, wrapper.width, wrapper.height, 0, deferredAttr[STROKE_WIDTH]);
  3679. if (!box.isImg) { // #4324, fill "none" causes it to be ignored by mouse events in IE
  3680. box.attr('fill', NONE);
  3681. }
  3682. box.add(wrapper);
  3683. }
  3684. // apply the box attributes
  3685. if (!box.isImg) { // #1630
  3686. box.attr(extend({
  3687. width: mathRound(wrapper.width),
  3688. height: mathRound(wrapper.height)
  3689. }, deferredAttr));
  3690. }
  3691. deferredAttr = null;
  3692. }
  3693. }
  3694. /**
  3695. * This function runs after setting text or padding, but only if padding is changed
  3696. */
  3697. function updateTextPadding() {
  3698. var styles = wrapper.styles,
  3699. textAlign = styles && styles.textAlign,
  3700. x = paddingLeft + padding * (1 - alignFactor),
  3701. y;
  3702. // determin y based on the baseline
  3703. y = baseline ? 0 : baselineOffset;
  3704. // compensate for alignment
  3705. if (defined(width) && bBox && (textAlign === 'center' || textAlign === 'right')) {
  3706. x += { center: 0.5, right: 1 }[textAlign] * (width - bBox.width);
  3707. }
  3708. // update if anything changed
  3709. if (x !== text.x || y !== text.y) {
  3710. text.attr('x', x);
  3711. if (y !== UNDEFINED) {
  3712. text.attr('y', y);
  3713. }
  3714. }
  3715. // record current values
  3716. text.x = x;
  3717. text.y = y;
  3718. }
  3719. /**
  3720. * Set a box attribute, or defer it if the box is not yet created
  3721. * @param {Object} key
  3722. * @param {Object} value
  3723. */
  3724. function boxAttr(key, value) {
  3725. if (box) {
  3726. box.attr(key, value);
  3727. } else {
  3728. deferredAttr[key] = value;
  3729. }
  3730. }
  3731. /**
  3732. * After the text element is added, get the desired size of the border box
  3733. * and add it before the text in the DOM.
  3734. */
  3735. wrapper.onAdd = function () {
  3736. text.add(wrapper);
  3737. wrapper.attr({
  3738. text: (str || str === 0) ? str : '', // alignment is available now // #3295: 0 not rendered if given as a value
  3739. x: x,
  3740. y: y
  3741. });
  3742. if (box && defined(anchorX)) {
  3743. wrapper.attr({
  3744. anchorX: anchorX,
  3745. anchorY: anchorY
  3746. });
  3747. }
  3748. };
  3749. /*
  3750. * Add specific attribute setters.
  3751. */
  3752. // only change local variables
  3753. wrapper.widthSetter = function (value) {
  3754. width = value;
  3755. };
  3756. wrapper.heightSetter = function (value) {
  3757. height = value;
  3758. };
  3759. wrapper.paddingSetter = function (value) {
  3760. if (defined(value) && value !== padding) {
  3761. padding = wrapper.padding = value;
  3762. updateTextPadding();
  3763. }
  3764. };
  3765. wrapper.paddingLeftSetter = function (value) {
  3766. if (defined(value) && value !== paddingLeft) {
  3767. paddingLeft = value;
  3768. updateTextPadding();
  3769. }
  3770. };
  3771. // change local variable and prevent setting attribute on the group
  3772. wrapper.alignSetter = function (value) {
  3773. alignFactor = { left: 0, center: 0.5, right: 1 }[value];
  3774. };
  3775. // apply these to the box and the text alike
  3776. wrapper.textSetter = function (value) {
  3777. if (value !== UNDEFINED) {
  3778. text.textSetter(value);
  3779. }
  3780. updateBoxSize();
  3781. updateTextPadding();
  3782. };
  3783. // apply these to the box but not to the text
  3784. wrapper['stroke-widthSetter'] = function (value, key) {
  3785. if (value) {
  3786. needsBox = true;
  3787. }
  3788. crispAdjust = value % 2 / 2;
  3789. boxAttr(key, value);
  3790. };
  3791. wrapper.strokeSetter = wrapper.fillSetter = wrapper.rSetter = function (value, key) {
  3792. if (key === 'fill' && value) {
  3793. needsBox = true;
  3794. }
  3795. boxAttr(key, value);
  3796. };
  3797. wrapper.anchorXSetter = function (value, key) {
  3798. anchorX = value;
  3799. boxAttr(key, mathRound(value) - crispAdjust - wrapperX);
  3800. };
  3801. wrapper.anchorYSetter = function (value, key) {
  3802. anchorY = value;
  3803. boxAttr(key, value - wrapperY);
  3804. };
  3805. // rename attributes
  3806. wrapper.xSetter = function (value) {
  3807. wrapper.x = value; // for animation getter
  3808. if (alignFactor) {
  3809. value -= alignFactor * ((width || bBox.width) + padding);
  3810. }
  3811. wrapperX = mathRound(value);
  3812. wrapper.attr('translateX', wrapperX);
  3813. };
  3814. wrapper.ySetter = function (value) {
  3815. wrapperY = wrapper.y = mathRound(value);
  3816. wrapper.attr('translateY', wrapperY);
  3817. };
  3818. // Redirect certain methods to either the box or the text
  3819. var baseCss = wrapper.css;
  3820. return extend(wrapper, {
  3821. /**
  3822. * Pick up some properties and apply them to the text instead of the wrapper
  3823. */
  3824. css: function (styles) {
  3825. if (styles) {
  3826. var textStyles = {};
  3827. styles = merge(styles); // create a copy to avoid altering the original object (#537)
  3828. each(wrapper.textProps, function (prop) {
  3829. if (styles[prop] !== UNDEFINED) {
  3830. textStyles[prop] = styles[prop];
  3831. delete styles[prop];
  3832. }
  3833. });
  3834. text.css(textStyles);
  3835. }
  3836. return baseCss.call(wrapper, styles);
  3837. },
  3838. /**
  3839. * Return the bounding box of the box, not the group
  3840. */
  3841. getBBox: function () {
  3842. return {
  3843. width: bBox.width + 2 * padding,
  3844. height: bBox.height + 2 * padding,
  3845. x: bBox.x - padding,
  3846. y: bBox.y - padding
  3847. };
  3848. },
  3849. /**
  3850. * Apply the shadow to the box
  3851. */
  3852. shadow: function (b) {
  3853. if (box) {
  3854. box.shadow(b);
  3855. }
  3856. return wrapper;
  3857. },
  3858. /**
  3859. * Destroy and release memory.
  3860. */
  3861. destroy: function () {
  3862. // Added by button implementation
  3863. removeEvent(wrapper.element, 'mouseenter');
  3864. removeEvent(wrapper.element, 'mouseleave');
  3865. if (text) {
  3866. text = text.destroy();
  3867. }
  3868. if (box) {
  3869. box = box.destroy();
  3870. }
  3871. // Call base implementation to destroy the rest
  3872. SVGElement.prototype.destroy.call(wrapper);
  3873. // Release local pointers (#1298)
  3874. wrapper = renderer = updateBoxSize = updateTextPadding = boxAttr = null;
  3875. }
  3876. });
  3877. }
  3878. }; // end SVGRenderer
  3879. // general renderer
  3880. Renderer = SVGRenderer;
  3881. // extend SvgElement for useHTML option
  3882. extend(SVGElement.prototype, {
  3883. /**
  3884. * Apply CSS to HTML elements. This is used in text within SVG rendering and
  3885. * by the VML renderer
  3886. */
  3887. htmlCss: function (styles) {
  3888. var wrapper = this,
  3889. element = wrapper.element,
  3890. textWidth = styles && element.tagName === 'SPAN' && styles.width;
  3891. if (textWidth) {
  3892. delete styles.width;
  3893. wrapper.textWidth = textWidth;
  3894. wrapper.updateTransform();
  3895. }
  3896. if (styles && styles.textOverflow === 'ellipsis') {
  3897. styles.whiteSpace = 'nowrap';
  3898. styles.overflow = 'hidden';
  3899. }
  3900. wrapper.styles = extend(wrapper.styles, styles);
  3901. css(wrapper.element, styles);
  3902. return wrapper;
  3903. },
  3904. /**
  3905. * VML and useHTML method for calculating the bounding box based on offsets
  3906. * @param {Boolean} refresh Whether to force a fresh value from the DOM or to
  3907. * use the cached value
  3908. *
  3909. * @return {Object} A hash containing values for x, y, width and height
  3910. */
  3911. htmlGetBBox: function () {
  3912. var wrapper = this,
  3913. element = wrapper.element;
  3914. // faking getBBox in exported SVG in legacy IE
  3915. // faking getBBox in exported SVG in legacy IE (is this a duplicate of the fix for #1079?)
  3916. if (element.nodeName === 'text') {
  3917. element.style.position = ABSOLUTE;
  3918. }
  3919. return {
  3920. x: element.offsetLeft,
  3921. y: element.offsetTop,
  3922. width: element.offsetWidth,
  3923. height: element.offsetHeight
  3924. };
  3925. },
  3926. /**
  3927. * VML override private method to update elements based on internal
  3928. * properties based on SVG transform
  3929. */
  3930. htmlUpdateTransform: function () {
  3931. // aligning non added elements is expensive
  3932. if (!this.added) {
  3933. this.alignOnAdd = true;
  3934. return;
  3935. }
  3936. var wrapper = this,
  3937. renderer = wrapper.renderer,
  3938. elem = wrapper.element,
  3939. translateX = wrapper.translateX || 0,
  3940. translateY = wrapper.translateY || 0,
  3941. x = wrapper.x || 0,
  3942. y = wrapper.y || 0,
  3943. align = wrapper.textAlign || 'left',
  3944. alignCorrection = { left: 0, center: 0.5, right: 1 }[align],
  3945. shadows = wrapper.shadows,
  3946. styles = wrapper.styles;
  3947. // apply translate
  3948. css(elem, {
  3949. marginLeft: translateX,
  3950. marginTop: translateY
  3951. });
  3952. if (shadows) { // used in labels/tooltip
  3953. each(shadows, function (shadow) {
  3954. css(shadow, {
  3955. marginLeft: translateX + 1,
  3956. marginTop: translateY + 1
  3957. });
  3958. });
  3959. }
  3960. // apply inversion
  3961. if (wrapper.inverted) { // wrapper is a group
  3962. each(elem.childNodes, function (child) {
  3963. renderer.invertChild(child, elem);
  3964. });
  3965. }
  3966. if (elem.tagName === 'SPAN') {
  3967. var width,
  3968. rotation = wrapper.rotation,
  3969. baseline,
  3970. textWidth = pInt(wrapper.textWidth),
  3971. currentTextTransform = [rotation, align, elem.innerHTML, wrapper.textWidth, wrapper.textAlign].join(',');
  3972. if (currentTextTransform !== wrapper.cTT) { // do the calculations and DOM access only if properties changed
  3973. baseline = renderer.fontMetrics(elem.style.fontSize).b;
  3974. // Renderer specific handling of span rotation
  3975. if (defined(rotation)) {
  3976. wrapper.setSpanRotation(rotation, alignCorrection, baseline);
  3977. }
  3978. width = pick(wrapper.elemWidth, elem.offsetWidth);
  3979. // Update textWidth
  3980. if (width > textWidth && /[ \-]/.test(elem.textContent || elem.innerText)) { // #983, #1254
  3981. css(elem, {
  3982. width: textWidth + PX,
  3983. display: 'block',
  3984. whiteSpace: (styles && styles.whiteSpace) || 'normal' // #3331
  3985. });
  3986. width = textWidth;
  3987. }
  3988. wrapper.getSpanCorrection(width, baseline, alignCorrection, rotation, align);
  3989. }
  3990. // apply position with correction
  3991. css(elem, {
  3992. left: (x + (wrapper.xCorr || 0)) + PX,
  3993. top: (y + (wrapper.yCorr || 0)) + PX
  3994. });
  3995. // force reflow in webkit to apply the left and top on useHTML element (#1249)
  3996. if (isWebKit) {
  3997. baseline = elem.offsetHeight; // assigned to baseline for JSLint purpose
  3998. }
  3999. // record current text transform
  4000. wrapper.cTT = currentTextTransform;
  4001. }
  4002. },
  4003. /**
  4004. * Set the rotation of an individual HTML span
  4005. */
  4006. setSpanRotation: function (rotation, alignCorrection, baseline) {
  4007. var rotationStyle = {},
  4008. cssTransformKey = isMS ? '-ms-transform' : isWebKit ? '-webkit-transform' : isFirefox ? 'MozTransform' : isOpera ? '-o-transform' : '';
  4009. rotationStyle[cssTransformKey] = rotationStyle.transform = 'rotate(' + rotation + 'deg)';
  4010. rotationStyle[cssTransformKey + (isFirefox ? 'Origin' : '-origin')] = rotationStyle.transformOrigin = (alignCorrection * 100) + '% ' + baseline + 'px';
  4011. css(this.element, rotationStyle);
  4012. },
  4013. /**
  4014. * Get the correction in X and Y positioning as the element is rotated.
  4015. */
  4016. getSpanCorrection: function (width, baseline, alignCorrection) {
  4017. this.xCorr = -width * alignCorrection;
  4018. this.yCorr = -baseline;
  4019. }
  4020. });
  4021. // Extend SvgRenderer for useHTML option.
  4022. extend(SVGRenderer.prototype, {
  4023. /**
  4024. * Create HTML text node. This is used by the VML renderer as well as the SVG
  4025. * renderer through the useHTML option.
  4026. *
  4027. * @param {String} str
  4028. * @param {Number} x
  4029. * @param {Number} y
  4030. */
  4031. html: function (str, x, y) {
  4032. var wrapper = this.createElement('span'),
  4033. element = wrapper.element,
  4034. renderer = wrapper.renderer;
  4035. // Text setter
  4036. wrapper.textSetter = function (value) {
  4037. if (value !== element.innerHTML) {
  4038. delete this.bBox;
  4039. }
  4040. element.innerHTML = this.textStr = value;
  4041. wrapper.htmlUpdateTransform();
  4042. };
  4043. // Various setters which rely on update transform
  4044. wrapper.xSetter = wrapper.ySetter = wrapper.alignSetter = wrapper.rotationSetter = function (value, key) {
  4045. if (key === 'align') {
  4046. key = 'textAlign'; // Do not overwrite the SVGElement.align method. Same as VML.
  4047. }
  4048. wrapper[key] = value;
  4049. wrapper.htmlUpdateTransform();
  4050. };
  4051. // Set the default attributes
  4052. wrapper.attr({
  4053. text: str,
  4054. x: mathRound(x),
  4055. y: mathRound(y)
  4056. })
  4057. .css({
  4058. position: ABSOLUTE,
  4059. fontFamily: this.style.fontFamily,
  4060. fontSize: this.style.fontSize
  4061. });
  4062. // Keep the whiteSpace style outside the wrapper.styles collection
  4063. element.style.whiteSpace = 'nowrap';
  4064. // Use the HTML specific .css method
  4065. wrapper.css = wrapper.htmlCss;
  4066. // This is specific for HTML within SVG
  4067. if (renderer.isSVG) {
  4068. wrapper.add = function (svgGroupWrapper) {
  4069. var htmlGroup,
  4070. container = renderer.box.parentNode,
  4071. parentGroup,
  4072. parents = [];
  4073. this.parentGroup = svgGroupWrapper;
  4074. // Create a mock group to hold the HTML elements
  4075. if (svgGroupWrapper) {
  4076. htmlGroup = svgGroupWrapper.div;
  4077. if (!htmlGroup) {
  4078. // Read the parent chain into an array and read from top down
  4079. parentGroup = svgGroupWrapper;
  4080. while (parentGroup) {
  4081. parents.push(parentGroup);
  4082. // Move up to the next parent group
  4083. parentGroup = parentGroup.parentGroup;
  4084. }
  4085. // Ensure dynamically updating position when any parent is translated
  4086. each(parents.reverse(), function (parentGroup) {
  4087. var htmlGroupStyle,
  4088. cls = attr(parentGroup.element, 'class');
  4089. if (cls) {
  4090. cls = { className: cls };
  4091. } // else null
  4092. // Create a HTML div and append it to the parent div to emulate
  4093. // the SVG group structure
  4094. htmlGroup = parentGroup.div = parentGroup.div || createElement(DIV, cls, {
  4095. position: ABSOLUTE,
  4096. left: (parentGroup.translateX || 0) + PX,
  4097. top: (parentGroup.translateY || 0) + PX
  4098. }, htmlGroup || container); // the top group is appended to container
  4099. // Shortcut
  4100. htmlGroupStyle = htmlGroup.style;
  4101. // Set listeners to update the HTML div's position whenever the SVG group
  4102. // position is changed
  4103. extend(parentGroup, {
  4104. translateXSetter: function (value, key) {
  4105. htmlGroupStyle.left = value + PX;
  4106. parentGroup[key] = value;
  4107. parentGroup.doTransform = true;
  4108. },
  4109. translateYSetter: function (value, key) {
  4110. htmlGroupStyle.top = value + PX;
  4111. parentGroup[key] = value;
  4112. parentGroup.doTransform = true;
  4113. }
  4114. });
  4115. // These properties are set as attributes on the SVG group, and as
  4116. // identical CSS properties on the div. (#3542)
  4117. each(['opacity', 'visibility'], function (prop) {
  4118. wrap(parentGroup, prop + 'Setter', function (proceed, value, key, elem) {
  4119. proceed.call(this, value, key, elem);
  4120. htmlGroupStyle[key] = value;
  4121. });
  4122. });
  4123. });
  4124. }
  4125. } else {
  4126. htmlGroup = container;
  4127. }
  4128. htmlGroup.appendChild(element);
  4129. // Shared with VML:
  4130. wrapper.added = true;
  4131. if (wrapper.alignOnAdd) {
  4132. wrapper.htmlUpdateTransform();
  4133. }
  4134. return wrapper;
  4135. };
  4136. }
  4137. return wrapper;
  4138. }
  4139. });
  4140. /* ****************************************************************************
  4141. * *
  4142. * START OF INTERNET EXPLORER <= 8 SPECIFIC CODE *
  4143. * *
  4144. * For applications and websites that don't need IE support, like platform *
  4145. * targeted mobile apps and web apps, this code can be removed. *
  4146. * *
  4147. *****************************************************************************/
  4148. /**
  4149. * @constructor
  4150. */
  4151. var VMLRenderer, VMLElement;
  4152. if (!hasSVG && !useCanVG) {
  4153. /**
  4154. * The VML element wrapper.
  4155. */
  4156. VMLElement = {
  4157. /**
  4158. * Initialize a new VML element wrapper. It builds the markup as a string
  4159. * to minimize DOM traffic.
  4160. * @param {Object} renderer
  4161. * @param {Object} nodeName
  4162. */
  4163. init: function (renderer, nodeName) {
  4164. var wrapper = this,
  4165. markup = ['<', nodeName, ' filled="f" stroked="f"'],
  4166. style = ['position: ', ABSOLUTE, ';'],
  4167. isDiv = nodeName === DIV;
  4168. // divs and shapes need size
  4169. if (nodeName === 'shape' || isDiv) {
  4170. style.push('left:0;top:0;width:1px;height:1px;');
  4171. }
  4172. style.push('visibility: ', isDiv ? HIDDEN : VISIBLE);
  4173. markup.push(' style="', style.join(''), '"/>');
  4174. // create element with default attributes and style
  4175. if (nodeName) {
  4176. markup = isDiv || nodeName === 'span' || nodeName === 'img' ?
  4177. markup.join('')
  4178. : renderer.prepVML(markup);
  4179. wrapper.element = createElement(markup);
  4180. }
  4181. wrapper.renderer = renderer;
  4182. },
  4183. /**
  4184. * Add the node to the given parent
  4185. * @param {Object} parent
  4186. */
  4187. add: function (parent) {
  4188. var wrapper = this,
  4189. renderer = wrapper.renderer,
  4190. element = wrapper.element,
  4191. box = renderer.box,
  4192. inverted = parent && parent.inverted,
  4193. // get the parent node
  4194. parentNode = parent ?
  4195. parent.element || parent :
  4196. box;
  4197. // if the parent group is inverted, apply inversion on all children
  4198. if (inverted) { // only on groups
  4199. renderer.invertChild(element, parentNode);
  4200. }
  4201. // append it
  4202. parentNode.appendChild(element);
  4203. // align text after adding to be able to read offset
  4204. wrapper.added = true;
  4205. if (wrapper.alignOnAdd && !wrapper.deferUpdateTransform) {
  4206. wrapper.updateTransform();
  4207. }
  4208. // fire an event for internal hooks
  4209. if (wrapper.onAdd) {
  4210. wrapper.onAdd();
  4211. }
  4212. return wrapper;
  4213. },
  4214. /**
  4215. * VML always uses htmlUpdateTransform
  4216. */
  4217. updateTransform: SVGElement.prototype.htmlUpdateTransform,
  4218. /**
  4219. * Set the rotation of a span with oldIE's filter
  4220. */
  4221. setSpanRotation: function () {
  4222. // Adjust for alignment and rotation. Rotation of useHTML content is not yet implemented
  4223. // but it can probably be implemented for Firefox 3.5+ on user request. FF3.5+
  4224. // has support for CSS3 transform. The getBBox method also needs to be updated
  4225. // to compensate for the rotation, like it currently does for SVG.
  4226. // Test case: http://jsfiddle.net/highcharts/Ybt44/
  4227. var rotation = this.rotation,
  4228. costheta = mathCos(rotation * deg2rad),
  4229. sintheta = mathSin(rotation * deg2rad);
  4230. css(this.element, {
  4231. filter: rotation ? ['progid:DXImageTransform.Microsoft.Matrix(M11=', costheta,
  4232. ', M12=', -sintheta, ', M21=', sintheta, ', M22=', costheta,
  4233. ', sizingMethod=\'auto expand\')'].join('') : NONE
  4234. });
  4235. },
  4236. /**
  4237. * Get the positioning correction for the span after rotating.
  4238. */
  4239. getSpanCorrection: function (width, baseline, alignCorrection, rotation, align) {
  4240. var costheta = rotation ? mathCos(rotation * deg2rad) : 1,
  4241. sintheta = rotation ? mathSin(rotation * deg2rad) : 0,
  4242. height = pick(this.elemHeight, this.element.offsetHeight),
  4243. quad,
  4244. nonLeft = align && align !== 'left';
  4245. // correct x and y
  4246. this.xCorr = costheta < 0 && -width;
  4247. this.yCorr = sintheta < 0 && -height;
  4248. // correct for baseline and corners spilling out after rotation
  4249. quad = costheta * sintheta < 0;
  4250. this.xCorr += sintheta * baseline * (quad ? 1 - alignCorrection : alignCorrection);
  4251. this.yCorr -= costheta * baseline * (rotation ? (quad ? alignCorrection : 1 - alignCorrection) : 1);
  4252. // correct for the length/height of the text
  4253. if (nonLeft) {
  4254. this.xCorr -= width * alignCorrection * (costheta < 0 ? -1 : 1);
  4255. if (rotation) {
  4256. this.yCorr -= height * alignCorrection * (sintheta < 0 ? -1 : 1);
  4257. }
  4258. css(this.element, {
  4259. textAlign: align
  4260. });
  4261. }
  4262. },
  4263. /**
  4264. * Converts a subset of an SVG path definition to its VML counterpart. Takes an array
  4265. * as the parameter and returns a string.
  4266. */
  4267. pathToVML: function (value) {
  4268. // convert paths
  4269. var i = value.length,
  4270. path = [];
  4271. while (i--) {
  4272. // Multiply by 10 to allow subpixel precision.
  4273. // Substracting half a pixel seems to make the coordinates
  4274. // align with SVG, but this hasn't been tested thoroughly
  4275. if (isNumber(value[i])) {
  4276. path[i] = mathRound(value[i] * 10) - 5;
  4277. } else if (value[i] === 'Z') { // close the path
  4278. path[i] = 'x';
  4279. } else {
  4280. path[i] = value[i];
  4281. // When the start X and end X coordinates of an arc are too close,
  4282. // they are rounded to the same value above. In this case, substract or
  4283. // add 1 from the end X and Y positions. #186, #760, #1371, #1410.
  4284. if (value.isArc && (value[i] === 'wa' || value[i] === 'at')) {
  4285. // Start and end X
  4286. if (path[i + 5] === path[i + 7]) {
  4287. path[i + 7] += value[i + 7] > value[i + 5] ? 1 : -1;
  4288. }
  4289. // Start and end Y
  4290. if (path[i + 6] === path[i + 8]) {
  4291. path[i + 8] += value[i + 8] > value[i + 6] ? 1 : -1;
  4292. }
  4293. }
  4294. }
  4295. }
  4296. // Loop up again to handle path shortcuts (#2132)
  4297. /*while (i++ < path.length) {
  4298. if (path[i] === 'H') { // horizontal line to
  4299. path[i] = 'L';
  4300. path.splice(i + 2, 0, path[i - 1]);
  4301. } else if (path[i] === 'V') { // vertical line to
  4302. path[i] = 'L';
  4303. path.splice(i + 1, 0, path[i - 2]);
  4304. }
  4305. }*/
  4306. return path.join(' ') || 'x';
  4307. },
  4308. /**
  4309. * Set the element's clipping to a predefined rectangle
  4310. *
  4311. * @param {String} id The id of the clip rectangle
  4312. */
  4313. clip: function (clipRect) {
  4314. var wrapper = this,
  4315. clipMembers,
  4316. cssRet;
  4317. if (clipRect) {
  4318. clipMembers = clipRect.members;
  4319. erase(clipMembers, wrapper); // Ensure unique list of elements (#1258)
  4320. clipMembers.push(wrapper);
  4321. wrapper.destroyClip = function () {
  4322. erase(clipMembers, wrapper);
  4323. };
  4324. cssRet = clipRect.getCSS(wrapper);
  4325. } else {
  4326. if (wrapper.destroyClip) {
  4327. wrapper.destroyClip();
  4328. }
  4329. cssRet = { clip: docMode8 ? 'inherit' : 'rect(auto)' }; // #1214
  4330. }
  4331. return wrapper.css(cssRet);
  4332. },
  4333. /**
  4334. * Set styles for the element
  4335. * @param {Object} styles
  4336. */
  4337. css: SVGElement.prototype.htmlCss,
  4338. /**
  4339. * Removes a child either by removeChild or move to garbageBin.
  4340. * Issue 490; in VML removeChild results in Orphaned nodes according to sIEve, discardElement does not.
  4341. */
  4342. safeRemoveChild: function (element) {
  4343. // discardElement will detach the node from its parent before attaching it
  4344. // to the garbage bin. Therefore it is important that the node is attached and have parent.
  4345. if (element.parentNode) {
  4346. discardElement(element);
  4347. }
  4348. },
  4349. /**
  4350. * Extend element.destroy by removing it from the clip members array
  4351. */
  4352. destroy: function () {
  4353. if (this.destroyClip) {
  4354. this.destroyClip();
  4355. }
  4356. return SVGElement.prototype.destroy.apply(this);
  4357. },
  4358. /**
  4359. * Add an event listener. VML override for normalizing event parameters.
  4360. * @param {String} eventType
  4361. * @param {Function} handler
  4362. */
  4363. on: function (eventType, handler) {
  4364. // simplest possible event model for internal use
  4365. this.element['on' + eventType] = function () {
  4366. var evt = win.event;
  4367. evt.target = evt.srcElement;
  4368. handler(evt);
  4369. };
  4370. return this;
  4371. },
  4372. /**
  4373. * In stacked columns, cut off the shadows so that they don't overlap
  4374. */
  4375. cutOffPath: function (path, length) {
  4376. var len;
  4377. path = path.split(/[ ,]/);
  4378. len = path.length;
  4379. if (len === 9 || len === 11) {
  4380. path[len - 4] = path[len - 2] = pInt(path[len - 2]) - 10 * length;
  4381. }
  4382. return path.join(' ');
  4383. },
  4384. /**
  4385. * Apply a drop shadow by copying elements and giving them different strokes
  4386. * @param {Boolean|Object} shadowOptions
  4387. */
  4388. shadow: function (shadowOptions, group, cutOff) {
  4389. var shadows = [],
  4390. i,
  4391. element = this.element,
  4392. renderer = this.renderer,
  4393. shadow,
  4394. elemStyle = element.style,
  4395. markup,
  4396. path = element.path,
  4397. strokeWidth,
  4398. modifiedPath,
  4399. shadowWidth,
  4400. shadowElementOpacity;
  4401. // some times empty paths are not strings
  4402. if (path && typeof path.value !== 'string') {
  4403. path = 'x';
  4404. }
  4405. modifiedPath = path;
  4406. if (shadowOptions) {
  4407. shadowWidth = pick(shadowOptions.width, 3);
  4408. shadowElementOpacity = (shadowOptions.opacity || 0.15) / shadowWidth;
  4409. for (i = 1; i <= 3; i++) {
  4410. strokeWidth = (shadowWidth * 2) + 1 - (2 * i);
  4411. // Cut off shadows for stacked column items
  4412. if (cutOff) {
  4413. modifiedPath = this.cutOffPath(path.value, strokeWidth + 0.5);
  4414. }
  4415. markup = ['<shape isShadow="true" strokeweight="', strokeWidth,
  4416. '" filled="false" path="', modifiedPath,
  4417. '" coordsize="10 10" style="', element.style.cssText, '" />'];
  4418. shadow = createElement(renderer.prepVML(markup),
  4419. null, {
  4420. left: pInt(elemStyle.left) + pick(shadowOptions.offsetX, 1),
  4421. top: pInt(elemStyle.top) + pick(shadowOptions.offsetY, 1)
  4422. }
  4423. );
  4424. if (cutOff) {
  4425. shadow.cutOff = strokeWidth + 1;
  4426. }
  4427. // apply the opacity
  4428. markup = ['<stroke color="', shadowOptions.color || 'black', '" opacity="', shadowElementOpacity * i, '"/>'];
  4429. createElement(renderer.prepVML(markup), null, null, shadow);
  4430. // insert it
  4431. if (group) {
  4432. group.element.appendChild(shadow);
  4433. } else {
  4434. element.parentNode.insertBefore(shadow, element);
  4435. }
  4436. // record it
  4437. shadows.push(shadow);
  4438. }
  4439. this.shadows = shadows;
  4440. }
  4441. return this;
  4442. },
  4443. updateShadows: noop, // Used in SVG only
  4444. setAttr: function (key, value) {
  4445. if (docMode8) { // IE8 setAttribute bug
  4446. this.element[key] = value;
  4447. } else {
  4448. this.element.setAttribute(key, value);
  4449. }
  4450. },
  4451. classSetter: function (value) {
  4452. // IE8 Standards mode has problems retrieving the className unless set like this
  4453. this.element.className = value;
  4454. },
  4455. dashstyleSetter: function (value, key, element) {
  4456. var strokeElem = element.getElementsByTagName('stroke')[0] ||
  4457. createElement(this.renderer.prepVML(['<stroke/>']), null, null, element);
  4458. strokeElem[key] = value || 'solid';
  4459. this[key] = value; /* because changing stroke-width will change the dash length
  4460. and cause an epileptic effect */
  4461. },
  4462. dSetter: function (value, key, element) {
  4463. var i,
  4464. shadows = this.shadows;
  4465. value = value || [];
  4466. this.d = value.join && value.join(' '); // used in getter for animation
  4467. element.path = value = this.pathToVML(value);
  4468. // update shadows
  4469. if (shadows) {
  4470. i = shadows.length;
  4471. while (i--) {
  4472. shadows[i].path = shadows[i].cutOff ? this.cutOffPath(value, shadows[i].cutOff) : value;
  4473. }
  4474. }
  4475. this.setAttr(key, value);
  4476. },
  4477. fillSetter: function (value, key, element) {
  4478. var nodeName = element.nodeName;
  4479. if (nodeName === 'SPAN') { // text color
  4480. element.style.color = value;
  4481. } else if (nodeName !== 'IMG') { // #1336
  4482. element.filled = value !== NONE;
  4483. this.setAttr('fillcolor', this.renderer.color(value, element, key, this));
  4484. }
  4485. },
  4486. opacitySetter: noop, // Don't bother - animation is too slow and filters introduce artifacts
  4487. rotationSetter: function (value, key, element) {
  4488. var style = element.style;
  4489. this[key] = style[key] = value; // style is for #1873
  4490. // Correction for the 1x1 size of the shape container. Used in gauge needles.
  4491. style.left = -mathRound(mathSin(value * deg2rad) + 1) + PX;
  4492. style.top = mathRound(mathCos(value * deg2rad)) + PX;
  4493. },
  4494. strokeSetter: function (value, key, element) {
  4495. this.setAttr('strokecolor', this.renderer.color(value, element, key));
  4496. },
  4497. 'stroke-widthSetter': function (value, key, element) {
  4498. element.stroked = !!value; // VML "stroked" attribute
  4499. this[key] = value; // used in getter, issue #113
  4500. if (isNumber(value)) {
  4501. value += PX;
  4502. }
  4503. this.setAttr('strokeweight', value);
  4504. },
  4505. titleSetter: function (value, key) {
  4506. this.setAttr(key, value);
  4507. },
  4508. visibilitySetter: function (value, key, element) {
  4509. // Handle inherited visibility
  4510. if (value === 'inherit') {
  4511. value = VISIBLE;
  4512. }
  4513. // Let the shadow follow the main element
  4514. if (this.shadows) {
  4515. each(this.shadows, function (shadow) {
  4516. shadow.style[key] = value;
  4517. });
  4518. }
  4519. // Instead of toggling the visibility CSS property, move the div out of the viewport.
  4520. // This works around #61 and #586
  4521. if (element.nodeName === 'DIV') {
  4522. value = value === HIDDEN ? '-999em' : 0;
  4523. // In order to redraw, IE7 needs the div to be visible when tucked away
  4524. // outside the viewport. So the visibility is actually opposite of
  4525. // the expected value. This applies to the tooltip only.
  4526. if (!docMode8) {
  4527. element.style[key] = value ? VISIBLE : HIDDEN;
  4528. }
  4529. key = 'top';
  4530. }
  4531. element.style[key] = value;
  4532. },
  4533. xSetter: function (value, key, element) {
  4534. this[key] = value; // used in getter
  4535. if (key === 'x') {
  4536. key = 'left';
  4537. } else if (key === 'y') {
  4538. key = 'top';
  4539. }/* else {
  4540. value = mathMax(0, value); // don't set width or height below zero (#311)
  4541. }*/
  4542. // clipping rectangle special
  4543. if (this.updateClipping) {
  4544. this[key] = value; // the key is now 'left' or 'top' for 'x' and 'y'
  4545. this.updateClipping();
  4546. } else {
  4547. // normal
  4548. element.style[key] = value;
  4549. }
  4550. },
  4551. zIndexSetter: function (value, key, element) {
  4552. element.style[key] = value;
  4553. }
  4554. };
  4555. Highcharts.VMLElement = VMLElement = extendClass(SVGElement, VMLElement);
  4556. // Some shared setters
  4557. VMLElement.prototype.ySetter =
  4558. VMLElement.prototype.widthSetter =
  4559. VMLElement.prototype.heightSetter =
  4560. VMLElement.prototype.xSetter;
  4561. /**
  4562. * The VML renderer
  4563. */
  4564. var VMLRendererExtension = { // inherit SVGRenderer
  4565. Element: VMLElement,
  4566. isIE8: userAgent.indexOf('MSIE 8.0') > -1,
  4567. /**
  4568. * Initialize the VMLRenderer
  4569. * @param {Object} container
  4570. * @param {Number} width
  4571. * @param {Number} height
  4572. */
  4573. init: function (container, width, height, style) {
  4574. var renderer = this,
  4575. boxWrapper,
  4576. box,
  4577. css;
  4578. renderer.alignedObjects = [];
  4579. boxWrapper = renderer.createElement(DIV)
  4580. .css(extend(this.getStyle(style), { position: RELATIVE}));
  4581. box = boxWrapper.element;
  4582. container.appendChild(boxWrapper.element);
  4583. // generate the containing box
  4584. renderer.isVML = true;
  4585. renderer.box = box;
  4586. renderer.boxWrapper = boxWrapper;
  4587. renderer.cache = {};
  4588. renderer.setSize(width, height, false);
  4589. // The only way to make IE6 and IE7 print is to use a global namespace. However,
  4590. // with IE8 the only way to make the dynamic shapes visible in screen and print mode
  4591. // seems to be to add the xmlns attribute and the behaviour style inline.
  4592. if (!doc.namespaces.hcv) {
  4593. doc.namespaces.add('hcv', 'urn:schemas-microsoft-com:vml');
  4594. // Setup default CSS (#2153, #2368, #2384)
  4595. css = 'hcv\\:fill, hcv\\:path, hcv\\:shape, hcv\\:stroke' +
  4596. '{ behavior:url(#default#VML); display: inline-block; } ';
  4597. try {
  4598. doc.createStyleSheet().cssText = css;
  4599. } catch (e) {
  4600. doc.styleSheets[0].cssText += css;
  4601. }
  4602. }
  4603. },
  4604. /**
  4605. * Detect whether the renderer is hidden. This happens when one of the parent elements
  4606. * has display: none
  4607. */
  4608. isHidden: function () {
  4609. return !this.box.offsetWidth;
  4610. },
  4611. /**
  4612. * Define a clipping rectangle. In VML it is accomplished by storing the values
  4613. * for setting the CSS style to all associated members.
  4614. *
  4615. * @param {Number} x
  4616. * @param {Number} y
  4617. * @param {Number} width
  4618. * @param {Number} height
  4619. */
  4620. clipRect: function (x, y, width, height) {
  4621. // create a dummy element
  4622. var clipRect = this.createElement(),
  4623. isObj = isObject(x);
  4624. // mimic a rectangle with its style object for automatic updating in attr
  4625. return extend(clipRect, {
  4626. members: [],
  4627. count: 0,
  4628. left: (isObj ? x.x : x) + 1,
  4629. top: (isObj ? x.y : y) + 1,
  4630. width: (isObj ? x.width : width) - 1,
  4631. height: (isObj ? x.height : height) - 1,
  4632. getCSS: function (wrapper) {
  4633. var element = wrapper.element,
  4634. nodeName = element.nodeName,
  4635. isShape = nodeName === 'shape',
  4636. inverted = wrapper.inverted,
  4637. rect = this,
  4638. top = rect.top - (isShape ? element.offsetTop : 0),
  4639. left = rect.left,
  4640. right = left + rect.width,
  4641. bottom = top + rect.height,
  4642. ret = {
  4643. clip: 'rect(' +
  4644. mathRound(inverted ? left : top) + 'px,' +
  4645. mathRound(inverted ? bottom : right) + 'px,' +
  4646. mathRound(inverted ? right : bottom) + 'px,' +
  4647. mathRound(inverted ? top : left) + 'px)'
  4648. };
  4649. // issue 74 workaround
  4650. if (!inverted && docMode8 && nodeName === 'DIV') {
  4651. extend(ret, {
  4652. width: right + PX,
  4653. height: bottom + PX
  4654. });
  4655. }
  4656. return ret;
  4657. },
  4658. // used in attr and animation to update the clipping of all members
  4659. updateClipping: function () {
  4660. each(clipRect.members, function (member) {
  4661. if (member.element) { // Deleted series, like in stock/members/series-remove demo. Should be removed from members, but this will do.
  4662. member.css(clipRect.getCSS(member));
  4663. }
  4664. });
  4665. }
  4666. });
  4667. },
  4668. /**
  4669. * Take a color and return it if it's a string, make it a gradient if it's a
  4670. * gradient configuration object, and apply opacity.
  4671. *
  4672. * @param {Object} color The color or config object
  4673. */
  4674. color: function (color, elem, prop, wrapper) {
  4675. var renderer = this,
  4676. colorObject,
  4677. regexRgba = /^rgba/,
  4678. markup,
  4679. fillType,
  4680. ret = NONE;
  4681. // Check for linear or radial gradient
  4682. if (color && color.linearGradient) {
  4683. fillType = 'gradient';
  4684. } else if (color && color.radialGradient) {
  4685. fillType = 'pattern';
  4686. }
  4687. if (fillType) {
  4688. var stopColor,
  4689. stopOpacity,
  4690. gradient = color.linearGradient || color.radialGradient,
  4691. x1,
  4692. y1,
  4693. x2,
  4694. y2,
  4695. opacity1,
  4696. opacity2,
  4697. color1,
  4698. color2,
  4699. fillAttr = '',
  4700. stops = color.stops,
  4701. firstStop,
  4702. lastStop,
  4703. colors = [],
  4704. addFillNode = function () {
  4705. // Add the fill subnode. When colors attribute is used, the meanings of opacity and o:opacity2
  4706. // are reversed.
  4707. markup = ['<fill colors="' + colors.join(',') + '" opacity="', opacity2, '" o:opacity2="', opacity1,
  4708. '" type="', fillType, '" ', fillAttr, 'focus="100%" method="any" />'];
  4709. createElement(renderer.prepVML(markup), null, null, elem);
  4710. };
  4711. // Extend from 0 to 1
  4712. firstStop = stops[0];
  4713. lastStop = stops[stops.length - 1];
  4714. if (firstStop[0] > 0) {
  4715. stops.unshift([
  4716. 0,
  4717. firstStop[1]
  4718. ]);
  4719. }
  4720. if (lastStop[0] < 1) {
  4721. stops.push([
  4722. 1,
  4723. lastStop[1]
  4724. ]);
  4725. }
  4726. // Compute the stops
  4727. each(stops, function (stop, i) {
  4728. if (regexRgba.test(stop[1])) {
  4729. colorObject = Color(stop[1]);
  4730. stopColor = colorObject.get('rgb');
  4731. stopOpacity = colorObject.get('a');
  4732. } else {
  4733. stopColor = stop[1];
  4734. stopOpacity = 1;
  4735. }
  4736. // Build the color attribute
  4737. colors.push((stop[0] * 100) + '% ' + stopColor);
  4738. // Only start and end opacities are allowed, so we use the first and the last
  4739. if (!i) {
  4740. opacity1 = stopOpacity;
  4741. color2 = stopColor;
  4742. } else {
  4743. opacity2 = stopOpacity;
  4744. color1 = stopColor;
  4745. }
  4746. });
  4747. // Apply the gradient to fills only.
  4748. if (prop === 'fill') {
  4749. // Handle linear gradient angle
  4750. if (fillType === 'gradient') {
  4751. x1 = gradient.x1 || gradient[0] || 0;
  4752. y1 = gradient.y1 || gradient[1] || 0;
  4753. x2 = gradient.x2 || gradient[2] || 0;
  4754. y2 = gradient.y2 || gradient[3] || 0;
  4755. fillAttr = 'angle="' + (90 - math.atan(
  4756. (y2 - y1) / // y vector
  4757. (x2 - x1) // x vector
  4758. ) * 180 / mathPI) + '"';
  4759. addFillNode();
  4760. // Radial (circular) gradient
  4761. } else {
  4762. var r = gradient.r,
  4763. sizex = r * 2,
  4764. sizey = r * 2,
  4765. cx = gradient.cx,
  4766. cy = gradient.cy,
  4767. radialReference = elem.radialReference,
  4768. bBox,
  4769. applyRadialGradient = function () {
  4770. if (radialReference) {
  4771. bBox = wrapper.getBBox();
  4772. cx += (radialReference[0] - bBox.x) / bBox.width - 0.5;
  4773. cy += (radialReference[1] - bBox.y) / bBox.height - 0.5;
  4774. sizex *= radialReference[2] / bBox.width;
  4775. sizey *= radialReference[2] / bBox.height;
  4776. }
  4777. fillAttr = 'src="' + defaultOptions.global.VMLRadialGradientURL + '" ' +
  4778. 'size="' + sizex + ',' + sizey + '" ' +
  4779. 'origin="0.5,0.5" ' +
  4780. 'position="' + cx + ',' + cy + '" ' +
  4781. 'color2="' + color2 + '" ';
  4782. addFillNode();
  4783. };
  4784. // Apply radial gradient
  4785. if (wrapper.added) {
  4786. applyRadialGradient();
  4787. } else {
  4788. // We need to know the bounding box to get the size and position right
  4789. wrapper.onAdd = applyRadialGradient;
  4790. }
  4791. // The fill element's color attribute is broken in IE8 standards mode, so we
  4792. // need to set the parent shape's fillcolor attribute instead.
  4793. ret = color1;
  4794. }
  4795. // Gradients are not supported for VML stroke, return the first color. #722.
  4796. } else {
  4797. ret = stopColor;
  4798. }
  4799. // if the color is an rgba color, split it and add a fill node
  4800. // to hold the opacity component
  4801. } else if (regexRgba.test(color) && elem.tagName !== 'IMG') {
  4802. colorObject = Color(color);
  4803. markup = ['<', prop, ' opacity="', colorObject.get('a'), '"/>'];
  4804. createElement(this.prepVML(markup), null, null, elem);
  4805. ret = colorObject.get('rgb');
  4806. } else {
  4807. var propNodes = elem.getElementsByTagName(prop); // 'stroke' or 'fill' node
  4808. if (propNodes.length) {
  4809. propNodes[0].opacity = 1;
  4810. propNodes[0].type = 'solid';
  4811. }
  4812. ret = color;
  4813. }
  4814. return ret;
  4815. },
  4816. /**
  4817. * Take a VML string and prepare it for either IE8 or IE6/IE7.
  4818. * @param {Array} markup A string array of the VML markup to prepare
  4819. */
  4820. prepVML: function (markup) {
  4821. var vmlStyle = 'display:inline-block;behavior:url(#default#VML);',
  4822. isIE8 = this.isIE8;
  4823. markup = markup.join('');
  4824. if (isIE8) { // add xmlns and style inline
  4825. markup = markup.replace('/>', ' xmlns="urn:schemas-microsoft-com:vml" />');
  4826. if (markup.indexOf('style="') === -1) {
  4827. markup = markup.replace('/>', ' style="' + vmlStyle + '" />');
  4828. } else {
  4829. markup = markup.replace('style="', 'style="' + vmlStyle);
  4830. }
  4831. } else { // add namespace
  4832. markup = markup.replace('<', '<hcv:');
  4833. }
  4834. return markup;
  4835. },
  4836. /**
  4837. * Create rotated and aligned text
  4838. * @param {String} str
  4839. * @param {Number} x
  4840. * @param {Number} y
  4841. */
  4842. text: SVGRenderer.prototype.html,
  4843. /**
  4844. * Create and return a path element
  4845. * @param {Array} path
  4846. */
  4847. path: function (path) {
  4848. var attr = {
  4849. // subpixel precision down to 0.1 (width and height = 1px)
  4850. coordsize: '10 10'
  4851. };
  4852. if (isArray(path)) {
  4853. attr.d = path;
  4854. } else if (isObject(path)) { // attributes
  4855. extend(attr, path);
  4856. }
  4857. // create the shape
  4858. return this.createElement('shape').attr(attr);
  4859. },
  4860. /**
  4861. * Create and return a circle element. In VML circles are implemented as
  4862. * shapes, which is faster than v:oval
  4863. * @param {Number} x
  4864. * @param {Number} y
  4865. * @param {Number} r
  4866. */
  4867. circle: function (x, y, r) {
  4868. var circle = this.symbol('circle');
  4869. if (isObject(x)) {
  4870. r = x.r;
  4871. y = x.y;
  4872. x = x.x;
  4873. }
  4874. circle.isCircle = true; // Causes x and y to mean center (#1682)
  4875. circle.r = r;
  4876. return circle.attr({ x: x, y: y });
  4877. },
  4878. /**
  4879. * Create a group using an outer div and an inner v:group to allow rotating
  4880. * and flipping. A simple v:group would have problems with positioning
  4881. * child HTML elements and CSS clip.
  4882. *
  4883. * @param {String} name The name of the group
  4884. */
  4885. g: function (name) {
  4886. var wrapper,
  4887. attribs;
  4888. // set the class name
  4889. if (name) {
  4890. attribs = { 'className': PREFIX + name, 'class': PREFIX + name };
  4891. }
  4892. // the div to hold HTML and clipping
  4893. wrapper = this.createElement(DIV).attr(attribs);
  4894. return wrapper;
  4895. },
  4896. /**
  4897. * VML override to create a regular HTML image
  4898. * @param {String} src
  4899. * @param {Number} x
  4900. * @param {Number} y
  4901. * @param {Number} width
  4902. * @param {Number} height
  4903. */
  4904. image: function (src, x, y, width, height) {
  4905. var obj = this.createElement('img')
  4906. .attr({ src: src });
  4907. if (arguments.length > 1) {
  4908. obj.attr({
  4909. x: x,
  4910. y: y,
  4911. width: width,
  4912. height: height
  4913. });
  4914. }
  4915. return obj;
  4916. },
  4917. /**
  4918. * For rectangles, VML uses a shape for rect to overcome bugs and rotation problems
  4919. */
  4920. createElement: function (nodeName) {
  4921. return nodeName === 'rect' ? this.symbol(nodeName) : SVGRenderer.prototype.createElement.call(this, nodeName);
  4922. },
  4923. /**
  4924. * In the VML renderer, each child of an inverted div (group) is inverted
  4925. * @param {Object} element
  4926. * @param {Object} parentNode
  4927. */
  4928. invertChild: function (element, parentNode) {
  4929. var ren = this,
  4930. parentStyle = parentNode.style,
  4931. imgStyle = element.tagName === 'IMG' && element.style; // #1111
  4932. css(element, {
  4933. flip: 'x',
  4934. left: pInt(parentStyle.width) - (imgStyle ? pInt(imgStyle.top) : 1),
  4935. top: pInt(parentStyle.height) - (imgStyle ? pInt(imgStyle.left) : 1),
  4936. rotation: -90
  4937. });
  4938. // Recursively invert child elements, needed for nested composite shapes like box plots and error bars. #1680, #1806.
  4939. each(element.childNodes, function (child) {
  4940. ren.invertChild(child, element);
  4941. });
  4942. },
  4943. /**
  4944. * Symbol definitions that override the parent SVG renderer's symbols
  4945. *
  4946. */
  4947. symbols: {
  4948. // VML specific arc function
  4949. arc: function (x, y, w, h, options) {
  4950. var start = options.start,
  4951. end = options.end,
  4952. radius = options.r || w || h,
  4953. innerRadius = options.innerR,
  4954. cosStart = mathCos(start),
  4955. sinStart = mathSin(start),
  4956. cosEnd = mathCos(end),
  4957. sinEnd = mathSin(end),
  4958. ret;
  4959. if (end - start === 0) { // no angle, don't show it.
  4960. return ['x'];
  4961. }
  4962. ret = [
  4963. 'wa', // clockwise arc to
  4964. x - radius, // left
  4965. y - radius, // top
  4966. x + radius, // right
  4967. y + radius, // bottom
  4968. x + radius * cosStart, // start x
  4969. y + radius * sinStart, // start y
  4970. x + radius * cosEnd, // end x
  4971. y + radius * sinEnd // end y
  4972. ];
  4973. if (options.open && !innerRadius) {
  4974. ret.push(
  4975. 'e',
  4976. M,
  4977. x,// - innerRadius,
  4978. y// - innerRadius
  4979. );
  4980. }
  4981. ret.push(
  4982. 'at', // anti clockwise arc to
  4983. x - innerRadius, // left
  4984. y - innerRadius, // top
  4985. x + innerRadius, // right
  4986. y + innerRadius, // bottom
  4987. x + innerRadius * cosEnd, // start x
  4988. y + innerRadius * sinEnd, // start y
  4989. x + innerRadius * cosStart, // end x
  4990. y + innerRadius * sinStart, // end y
  4991. 'x', // finish path
  4992. 'e' // close
  4993. );
  4994. ret.isArc = true;
  4995. return ret;
  4996. },
  4997. // Add circle symbol path. This performs significantly faster than v:oval.
  4998. circle: function (x, y, w, h, wrapper) {
  4999. if (wrapper) {
  5000. w = h = 2 * wrapper.r;
  5001. }
  5002. // Center correction, #1682
  5003. if (wrapper && wrapper.isCircle) {
  5004. x -= w / 2;
  5005. y -= h / 2;
  5006. }
  5007. // Return the path
  5008. return [
  5009. 'wa', // clockwisearcto
  5010. x, // left
  5011. y, // top
  5012. x + w, // right
  5013. y + h, // bottom
  5014. x + w, // start x
  5015. y + h / 2, // start y
  5016. x + w, // end x
  5017. y + h / 2, // end y
  5018. //'x', // finish path
  5019. 'e' // close
  5020. ];
  5021. },
  5022. /**
  5023. * Add rectangle symbol path which eases rotation and omits arcsize problems
  5024. * compared to the built-in VML roundrect shape. When borders are not rounded,
  5025. * use the simpler square path, else use the callout path without the arrow.
  5026. */
  5027. rect: function (x, y, w, h, options) {
  5028. return SVGRenderer.prototype.symbols[
  5029. !defined(options) || !options.r ? 'square' : 'callout'
  5030. ].call(0, x, y, w, h, options);
  5031. }
  5032. }
  5033. };
  5034. Highcharts.VMLRenderer = VMLRenderer = function () {
  5035. this.init.apply(this, arguments);
  5036. };
  5037. VMLRenderer.prototype = merge(SVGRenderer.prototype, VMLRendererExtension);
  5038. // general renderer
  5039. Renderer = VMLRenderer;
  5040. }
  5041. // This method is used with exporting in old IE, when emulating SVG (see #2314)
  5042. SVGRenderer.prototype.measureSpanWidth = function (text, styles) {
  5043. var measuringSpan = doc.createElement('span'),
  5044. offsetWidth,
  5045. textNode = doc.createTextNode(text);
  5046. measuringSpan.appendChild(textNode);
  5047. css(measuringSpan, styles);
  5048. this.box.appendChild(measuringSpan);
  5049. offsetWidth = measuringSpan.offsetWidth;
  5050. discardElement(measuringSpan); // #2463
  5051. return offsetWidth;
  5052. };
  5053. /* ****************************************************************************
  5054. * *
  5055. * END OF INTERNET EXPLORER <= 8 SPECIFIC CODE *
  5056. * *
  5057. *****************************************************************************/
  5058. /* ****************************************************************************
  5059. * *
  5060. * START OF ANDROID < 3 SPECIFIC CODE. THIS CAN BE REMOVED IF YOU'RE NOT *
  5061. * TARGETING THAT SYSTEM. *
  5062. * *
  5063. *****************************************************************************/
  5064. var CanVGRenderer,
  5065. CanVGController;
  5066. if (useCanVG) {
  5067. /**
  5068. * The CanVGRenderer is empty from start to keep the source footprint small.
  5069. * When requested, the CanVGController downloads the rest of the source packaged
  5070. * together with the canvg library.
  5071. */
  5072. Highcharts.CanVGRenderer = CanVGRenderer = function () {
  5073. // Override the global SVG namespace to fake SVG/HTML that accepts CSS
  5074. SVG_NS = 'http://www.w3.org/1999/xhtml';
  5075. };
  5076. /**
  5077. * Start with an empty symbols object. This is needed when exporting is used (exporting.src.js will add a few symbols), but
  5078. * the implementation from SvgRenderer will not be merged in until first render.
  5079. */
  5080. CanVGRenderer.prototype.symbols = {};
  5081. /**
  5082. * Handles on demand download of canvg rendering support.
  5083. */
  5084. CanVGController = (function () {
  5085. // List of renderering calls
  5086. var deferredRenderCalls = [];
  5087. /**
  5088. * When downloaded, we are ready to draw deferred charts.
  5089. */
  5090. function drawDeferred() {
  5091. var callLength = deferredRenderCalls.length,
  5092. callIndex;
  5093. // Draw all pending render calls
  5094. for (callIndex = 0; callIndex < callLength; callIndex++) {
  5095. deferredRenderCalls[callIndex]();
  5096. }
  5097. // Clear the list
  5098. deferredRenderCalls = [];
  5099. }
  5100. return {
  5101. push: function (func, scriptLocation) {
  5102. // Only get the script once
  5103. if (deferredRenderCalls.length === 0) {
  5104. getScript(scriptLocation, drawDeferred);
  5105. }
  5106. // Register render call
  5107. deferredRenderCalls.push(func);
  5108. }
  5109. };
  5110. }());
  5111. Renderer = CanVGRenderer;
  5112. } // end CanVGRenderer
  5113. /* ****************************************************************************
  5114. * *
  5115. * END OF ANDROID < 3 SPECIFIC CODE *
  5116. * *
  5117. *****************************************************************************/
  5118. /**
  5119. * The Tick class
  5120. */
  5121. function Tick(axis, pos, type, noLabel) {
  5122. this.axis = axis;
  5123. this.pos = pos;
  5124. this.type = type || '';
  5125. this.isNew = true;
  5126. if (!type && !noLabel) {
  5127. this.addLabel();
  5128. }
  5129. }
  5130. Tick.prototype = {
  5131. /**
  5132. * Write the tick label
  5133. */
  5134. addLabel: function () {
  5135. var tick = this,
  5136. axis = tick.axis,
  5137. options = axis.options,
  5138. chart = axis.chart,
  5139. categories = axis.categories,
  5140. names = axis.names,
  5141. pos = tick.pos,
  5142. labelOptions = options.labels,
  5143. str,
  5144. tickPositions = axis.tickPositions,
  5145. isFirst = pos === tickPositions[0],
  5146. isLast = pos === tickPositions[tickPositions.length - 1],
  5147. value = categories ?
  5148. pick(categories[pos], names[pos], pos) :
  5149. pos,
  5150. label = tick.label,
  5151. tickPositionInfo = tickPositions.info,
  5152. dateTimeLabelFormat;
  5153. // Set the datetime label format. If a higher rank is set for this position, use that. If not,
  5154. // use the general format.
  5155. if (axis.isDatetimeAxis && tickPositionInfo) {
  5156. dateTimeLabelFormat = options.dateTimeLabelFormats[tickPositionInfo.higherRanks[pos] || tickPositionInfo.unitName];
  5157. }
  5158. // set properties for access in render method
  5159. tick.isFirst = isFirst;
  5160. tick.isLast = isLast;
  5161. // get the string
  5162. str = axis.labelFormatter.call({
  5163. axis: axis,
  5164. chart: chart,
  5165. isFirst: isFirst,
  5166. isLast: isLast,
  5167. dateTimeLabelFormat: dateTimeLabelFormat,
  5168. value: axis.isLog ? correctFloat(lin2log(value)) : value
  5169. });
  5170. // prepare CSS
  5171. //css = width && { width: mathMax(1, mathRound(width - 2 * (labelOptions.padding || 10))) + PX };
  5172. // first call
  5173. if (!defined(label)) {
  5174. tick.label = label =
  5175. defined(str) && labelOptions.enabled ?
  5176. chart.renderer.text(
  5177. str,
  5178. 0,
  5179. 0,
  5180. labelOptions.useHTML
  5181. )
  5182. //.attr(attr)
  5183. // without position absolute, IE export sometimes is wrong
  5184. .css(merge(labelOptions.style))
  5185. .add(axis.labelGroup) :
  5186. null;
  5187. tick.labelLength = label && label.getBBox().width; // Un-rotated length
  5188. tick.rotation = 0; // Base value to detect change for new calls to getBBox
  5189. // update
  5190. } else if (label) {
  5191. label.attr({ text: str });
  5192. }
  5193. },
  5194. /**
  5195. * Get the offset height or width of the label
  5196. */
  5197. getLabelSize: function () {
  5198. return this.label ?
  5199. this.label.getBBox()[this.axis.horiz ? 'height' : 'width'] :
  5200. 0;
  5201. },
  5202. /**
  5203. * Handle the label overflow by adjusting the labels to the left and right edge, or
  5204. * hide them if they collide into the neighbour label.
  5205. */
  5206. handleOverflow: function (xy) {
  5207. var axis = this.axis,
  5208. pxPos = xy.x,
  5209. chartWidth = axis.chart.chartWidth,
  5210. spacing = axis.chart.spacing,
  5211. leftBound = pick(axis.labelLeft, mathMin(axis.pos, spacing[3])),
  5212. rightBound = pick(axis.labelRight, mathMax(axis.pos + axis.len, chartWidth - spacing[1])),
  5213. label = this.label,
  5214. rotation = this.rotation,
  5215. factor = { left: 0, center: 0.5, right: 1 }[axis.labelAlign],
  5216. labelWidth = label.getBBox().width,
  5217. slotWidth = axis.slotWidth,
  5218. xCorrection = factor,
  5219. goRight = 1,
  5220. leftPos,
  5221. rightPos,
  5222. textWidth,
  5223. css = {};
  5224. // Check if the label overshoots the chart spacing box. If it does, move it.
  5225. // If it now overshoots the slotWidth, add ellipsis.
  5226. if (!rotation) {
  5227. leftPos = pxPos - factor * labelWidth;
  5228. rightPos = pxPos + (1 - factor) * labelWidth;
  5229. if (leftPos < leftBound) {
  5230. slotWidth = xy.x + slotWidth * (1 - factor) - leftBound;
  5231. } else if (rightPos > rightBound) {
  5232. slotWidth = rightBound - xy.x + slotWidth * factor;
  5233. goRight = -1;
  5234. }
  5235. slotWidth = mathMin(axis.slotWidth, slotWidth); // #4177
  5236. if (slotWidth < axis.slotWidth && axis.labelAlign === 'center') {
  5237. xy.x += goRight * (axis.slotWidth - slotWidth - xCorrection * (axis.slotWidth - mathMin(labelWidth, slotWidth)));
  5238. }
  5239. // If the label width exceeds the available space, set a text width to be
  5240. // picked up below. Also, if a width has been set before, we need to set a new
  5241. // one because the reported labelWidth will be limited by the box (#3938).
  5242. if (labelWidth > slotWidth || (axis.autoRotation && label.styles.width)) {
  5243. textWidth = slotWidth;
  5244. }
  5245. // Add ellipsis to prevent rotated labels to be clipped against the edge of the chart
  5246. } else if (rotation < 0 && pxPos - factor * labelWidth < leftBound) {
  5247. textWidth = mathRound(pxPos / mathCos(rotation * deg2rad) - leftBound);
  5248. } else if (rotation > 0 && pxPos + factor * labelWidth > rightBound) {
  5249. textWidth = mathRound((chartWidth - pxPos) / mathCos(rotation * deg2rad));
  5250. }
  5251. if (textWidth) {
  5252. css.width = textWidth;
  5253. if (!axis.options.labels.style.textOverflow) {
  5254. css.textOverflow = 'ellipsis';
  5255. }
  5256. label.css(css);
  5257. }
  5258. },
  5259. /**
  5260. * Get the x and y position for ticks and labels
  5261. */
  5262. getPosition: function (horiz, pos, tickmarkOffset, old) {
  5263. var axis = this.axis,
  5264. chart = axis.chart,
  5265. cHeight = (old && chart.oldChartHeight) || chart.chartHeight;
  5266. return {
  5267. x: horiz ?
  5268. axis.translate(pos + tickmarkOffset, null, null, old) + axis.transB :
  5269. axis.left + axis.offset + (axis.opposite ? ((old && chart.oldChartWidth) || chart.chartWidth) - axis.right - axis.left : 0),
  5270. y: horiz ?
  5271. cHeight - axis.bottom + axis.offset - (axis.opposite ? axis.height : 0) :
  5272. cHeight - axis.translate(pos + tickmarkOffset, null, null, old) - axis.transB
  5273. };
  5274. },
  5275. /**
  5276. * Get the x, y position of the tick label
  5277. */
  5278. getLabelPosition: function (x, y, label, horiz, labelOptions, tickmarkOffset, index, step) {
  5279. var axis = this.axis,
  5280. transA = axis.transA,
  5281. reversed = axis.reversed,
  5282. staggerLines = axis.staggerLines,
  5283. rotCorr = axis.tickRotCorr || { x: 0, y: 0 },
  5284. yOffset = pick(labelOptions.y, rotCorr.y + (axis.side === 2 ? 8 : -(label.getBBox().height / 2))),
  5285. line;
  5286. x = x + labelOptions.x + rotCorr.x - (tickmarkOffset && horiz ?
  5287. tickmarkOffset * transA * (reversed ? -1 : 1) : 0);
  5288. y = y + yOffset - (tickmarkOffset && !horiz ?
  5289. tickmarkOffset * transA * (reversed ? 1 : -1) : 0);
  5290. // Correct for staggered labels
  5291. if (staggerLines) {
  5292. line = (index / (step || 1) % staggerLines);
  5293. y += line * (axis.labelOffset / staggerLines);
  5294. }
  5295. return {
  5296. x: x,
  5297. y: mathRound(y)
  5298. };
  5299. },
  5300. /**
  5301. * Extendible method to return the path of the marker
  5302. */
  5303. getMarkPath: function (x, y, tickLength, tickWidth, horiz, renderer) {
  5304. return renderer.crispLine([
  5305. M,
  5306. x,
  5307. y,
  5308. L,
  5309. x + (horiz ? 0 : -tickLength),
  5310. y + (horiz ? tickLength : 0)
  5311. ], tickWidth);
  5312. },
  5313. /**
  5314. * Put everything in place
  5315. *
  5316. * @param index {Number}
  5317. * @param old {Boolean} Use old coordinates to prepare an animation into new position
  5318. */
  5319. render: function (index, old, opacity) {
  5320. var tick = this,
  5321. axis = tick.axis,
  5322. options = axis.options,
  5323. chart = axis.chart,
  5324. renderer = chart.renderer,
  5325. horiz = axis.horiz,
  5326. type = tick.type,
  5327. label = tick.label,
  5328. pos = tick.pos,
  5329. labelOptions = options.labels,
  5330. gridLine = tick.gridLine,
  5331. gridPrefix = type ? type + 'Grid' : 'grid',
  5332. tickPrefix = type ? type + 'Tick' : 'tick',
  5333. gridLineWidth = options[gridPrefix + 'LineWidth'],
  5334. gridLineColor = options[gridPrefix + 'LineColor'],
  5335. dashStyle = options[gridPrefix + 'LineDashStyle'],
  5336. tickLength = options[tickPrefix + 'Length'],
  5337. tickWidth = pick(options[tickPrefix + 'Width'], !type && axis.isXAxis ? 1 : 0), // X axis defaults to 1
  5338. tickColor = options[tickPrefix + 'Color'],
  5339. tickPosition = options[tickPrefix + 'Position'],
  5340. gridLinePath,
  5341. mark = tick.mark,
  5342. markPath,
  5343. step = /*axis.labelStep || */labelOptions.step,
  5344. attribs,
  5345. show = true,
  5346. tickmarkOffset = axis.tickmarkOffset,
  5347. xy = tick.getPosition(horiz, pos, tickmarkOffset, old),
  5348. x = xy.x,
  5349. y = xy.y,
  5350. reverseCrisp = ((horiz && x === axis.pos + axis.len) || (!horiz && y === axis.pos)) ? -1 : 1; // #1480, #1687
  5351. opacity = pick(opacity, 1);
  5352. this.isActive = true;
  5353. // create the grid line
  5354. if (gridLineWidth) {
  5355. gridLinePath = axis.getPlotLinePath(pos + tickmarkOffset, gridLineWidth * reverseCrisp, old, true);
  5356. if (gridLine === UNDEFINED) {
  5357. attribs = {
  5358. stroke: gridLineColor,
  5359. 'stroke-width': gridLineWidth
  5360. };
  5361. if (dashStyle) {
  5362. attribs.dashstyle = dashStyle;
  5363. }
  5364. if (!type) {
  5365. attribs.zIndex = 1;
  5366. }
  5367. if (old) {
  5368. attribs.opacity = 0;
  5369. }
  5370. tick.gridLine = gridLine =
  5371. gridLineWidth ?
  5372. renderer.path(gridLinePath)
  5373. .attr(attribs).add(axis.gridGroup) :
  5374. null;
  5375. }
  5376. // If the parameter 'old' is set, the current call will be followed
  5377. // by another call, therefore do not do any animations this time
  5378. if (!old && gridLine && gridLinePath) {
  5379. gridLine[tick.isNew ? 'attr' : 'animate']({
  5380. d: gridLinePath,
  5381. opacity: opacity
  5382. });
  5383. }
  5384. }
  5385. // create the tick mark
  5386. if (tickWidth && tickLength) {
  5387. // negate the length
  5388. if (tickPosition === 'inside') {
  5389. tickLength = -tickLength;
  5390. }
  5391. if (axis.opposite) {
  5392. tickLength = -tickLength;
  5393. }
  5394. markPath = tick.getMarkPath(x, y, tickLength, tickWidth * reverseCrisp, horiz, renderer);
  5395. if (mark) { // updating
  5396. mark.animate({
  5397. d: markPath,
  5398. opacity: opacity
  5399. });
  5400. } else { // first time
  5401. tick.mark = renderer.path(
  5402. markPath
  5403. ).attr({
  5404. stroke: tickColor,
  5405. 'stroke-width': tickWidth,
  5406. opacity: opacity
  5407. }).add(axis.axisGroup);
  5408. }
  5409. }
  5410. // the label is created on init - now move it into place
  5411. if (label && !isNaN(x)) {
  5412. label.xy = xy = tick.getLabelPosition(x, y, label, horiz, labelOptions, tickmarkOffset, index, step);
  5413. // Apply show first and show last. If the tick is both first and last, it is
  5414. // a single centered tick, in which case we show the label anyway (#2100).
  5415. if ((tick.isFirst && !tick.isLast && !pick(options.showFirstLabel, 1)) ||
  5416. (tick.isLast && !tick.isFirst && !pick(options.showLastLabel, 1))) {
  5417. show = false;
  5418. // Handle label overflow and show or hide accordingly
  5419. } else if (horiz && !axis.isRadial && !labelOptions.step && !labelOptions.rotation && !old && opacity !== 0) {
  5420. tick.handleOverflow(xy);
  5421. }
  5422. // apply step
  5423. if (step && index % step) {
  5424. // show those indices dividable by step
  5425. show = false;
  5426. }
  5427. // Set the new position, and show or hide
  5428. if (show && !isNaN(xy.y)) {
  5429. xy.opacity = opacity;
  5430. label[tick.isNew ? 'attr' : 'animate'](xy);
  5431. tick.isNew = false;
  5432. } else {
  5433. label.attr('y', -9999); // #1338
  5434. }
  5435. }
  5436. },
  5437. /**
  5438. * Destructor for the tick prototype
  5439. */
  5440. destroy: function () {
  5441. destroyObjectProperties(this, this.axis);
  5442. }
  5443. };
  5444. /**
  5445. * Create a new axis object
  5446. * @param {Object} chart
  5447. * @param {Object} options
  5448. */
  5449. var Axis = Highcharts.Axis = function () {
  5450. this.init.apply(this, arguments);
  5451. };
  5452. Axis.prototype = {
  5453. /**
  5454. * Default options for the X axis - the Y axis has extended defaults
  5455. */
  5456. defaultOptions: {
  5457. // allowDecimals: null,
  5458. // alternateGridColor: null,
  5459. // categories: [],
  5460. dateTimeLabelFormats: {
  5461. millisecond: '%H:%M:%S.%L',
  5462. second: '%H:%M:%S',
  5463. minute: '%H:%M',
  5464. hour: '%H:%M',
  5465. day: '%e. %b',
  5466. week: '%e. %b',
  5467. month: '%b \'%y',
  5468. year: '%Y'
  5469. },
  5470. endOnTick: false,
  5471. gridLineColor: '#D8D8D8',
  5472. // gridLineDashStyle: 'solid',
  5473. // gridLineWidth: 0,
  5474. // reversed: false,
  5475. labels: {
  5476. enabled: true,
  5477. // rotation: 0,
  5478. // align: 'center',
  5479. // step: null,
  5480. style: {
  5481. color: '#606060',
  5482. cursor: 'default',
  5483. fontSize: '11px'
  5484. },
  5485. x: 0,
  5486. y: 15
  5487. /*formatter: function () {
  5488. return this.value;
  5489. },*/
  5490. },
  5491. lineColor: '#C0D0E0',
  5492. lineWidth: 1,
  5493. //linkedTo: null,
  5494. //max: undefined,
  5495. //min: undefined,
  5496. minPadding: 0.01,
  5497. maxPadding: 0.01,
  5498. //minRange: null,
  5499. minorGridLineColor: '#E0E0E0',
  5500. // minorGridLineDashStyle: null,
  5501. minorGridLineWidth: 1,
  5502. minorTickColor: '#A0A0A0',
  5503. //minorTickInterval: null,
  5504. minorTickLength: 2,
  5505. minorTickPosition: 'outside', // inside or outside
  5506. //minorTickWidth: 0,
  5507. //opposite: false,
  5508. //offset: 0,
  5509. //plotBands: [{
  5510. // events: {},
  5511. // zIndex: 1,
  5512. // labels: { align, x, verticalAlign, y, style, rotation, textAlign }
  5513. //}],
  5514. //plotLines: [{
  5515. // events: {}
  5516. // dashStyle: {}
  5517. // zIndex:
  5518. // labels: { align, x, verticalAlign, y, style, rotation, textAlign }
  5519. //}],
  5520. //reversed: false,
  5521. // showFirstLabel: true,
  5522. // showLastLabel: true,
  5523. startOfWeek: 1,
  5524. startOnTick: false,
  5525. tickColor: '#C0D0E0',
  5526. //tickInterval: null,
  5527. tickLength: 10,
  5528. tickmarkPlacement: 'between', // on or between
  5529. tickPixelInterval: 100,
  5530. tickPosition: 'outside',
  5531. //tickWidth: 1,
  5532. title: {
  5533. //text: null,
  5534. align: 'middle', // low, middle or high
  5535. //margin: 0 for horizontal, 10 for vertical axes,
  5536. //rotation: 0,
  5537. //side: 'outside',
  5538. style: {
  5539. color: '#707070'
  5540. }
  5541. //x: 0,
  5542. //y: 0
  5543. },
  5544. type: 'linear' // linear, logarithmic or datetime
  5545. //visible: true
  5546. },
  5547. /**
  5548. * This options set extends the defaultOptions for Y axes
  5549. */
  5550. defaultYAxisOptions: {
  5551. endOnTick: true,
  5552. gridLineWidth: 1,
  5553. tickPixelInterval: 72,
  5554. showLastLabel: true,
  5555. labels: {
  5556. x: -8,
  5557. y: 3
  5558. },
  5559. lineWidth: 0,
  5560. maxPadding: 0.05,
  5561. minPadding: 0.05,
  5562. startOnTick: true,
  5563. //tickWidth: 0,
  5564. title: {
  5565. rotation: 270,
  5566. text: 'Values'
  5567. },
  5568. stackLabels: {
  5569. enabled: false,
  5570. //align: dynamic,
  5571. //y: dynamic,
  5572. //x: dynamic,
  5573. //verticalAlign: dynamic,
  5574. //textAlign: dynamic,
  5575. //rotation: 0,
  5576. formatter: function () {
  5577. return Highcharts.numberFormat(this.total, -1);
  5578. },
  5579. style: merge(defaultPlotOptions.line.dataLabels.style, { color: '#000000' })
  5580. }
  5581. },
  5582. /**
  5583. * These options extend the defaultOptions for left axes
  5584. */
  5585. defaultLeftAxisOptions: {
  5586. labels: {
  5587. x: -15,
  5588. y: null
  5589. },
  5590. title: {
  5591. rotation: 270
  5592. }
  5593. },
  5594. /**
  5595. * These options extend the defaultOptions for right axes
  5596. */
  5597. defaultRightAxisOptions: {
  5598. labels: {
  5599. x: 15,
  5600. y: null
  5601. },
  5602. title: {
  5603. rotation: 90
  5604. }
  5605. },
  5606. /**
  5607. * These options extend the defaultOptions for bottom axes
  5608. */
  5609. defaultBottomAxisOptions: {
  5610. labels: {
  5611. autoRotation: [-45],
  5612. x: 0,
  5613. y: null // based on font size
  5614. // overflow: undefined,
  5615. // staggerLines: null
  5616. },
  5617. title: {
  5618. rotation: 0
  5619. }
  5620. },
  5621. /**
  5622. * These options extend the defaultOptions for top axes
  5623. */
  5624. defaultTopAxisOptions: {
  5625. labels: {
  5626. autoRotation: [-45],
  5627. x: 0,
  5628. y: -15
  5629. // overflow: undefined
  5630. // staggerLines: null
  5631. },
  5632. title: {
  5633. rotation: 0
  5634. }
  5635. },
  5636. /**
  5637. * Initialize the axis
  5638. */
  5639. init: function (chart, userOptions) {
  5640. var isXAxis = userOptions.isX,
  5641. axis = this;
  5642. axis.chart = chart;
  5643. // Flag, is the axis horizontal
  5644. axis.horiz = chart.inverted ? !isXAxis : isXAxis;
  5645. // Flag, isXAxis
  5646. axis.isXAxis = isXAxis;
  5647. axis.coll = isXAxis ? 'xAxis' : 'yAxis';
  5648. axis.opposite = userOptions.opposite; // needed in setOptions
  5649. axis.side = userOptions.side || (axis.horiz ?
  5650. (axis.opposite ? 0 : 2) : // top : bottom
  5651. (axis.opposite ? 1 : 3)); // right : left
  5652. axis.setOptions(userOptions);
  5653. var options = this.options,
  5654. type = options.type,
  5655. isDatetimeAxis = type === 'datetime';
  5656. axis.labelFormatter = options.labels.formatter || axis.defaultLabelFormatter; // can be overwritten by dynamic format
  5657. // Flag, stagger lines or not
  5658. axis.userOptions = userOptions;
  5659. //axis.axisTitleMargin = UNDEFINED,// = options.title.margin,
  5660. axis.minPixelPadding = 0;
  5661. axis.reversed = options.reversed;
  5662. axis.visible = options.visible !== false;
  5663. axis.zoomEnabled = options.zoomEnabled !== false;
  5664. // Initial categories
  5665. axis.categories = options.categories || type === 'category';
  5666. axis.names = axis.names || []; // Preserve on update (#3830)
  5667. // Elements
  5668. //axis.axisGroup = UNDEFINED;
  5669. //axis.gridGroup = UNDEFINED;
  5670. //axis.axisTitle = UNDEFINED;
  5671. //axis.axisLine = UNDEFINED;
  5672. // Shorthand types
  5673. axis.isLog = type === 'logarithmic';
  5674. axis.isDatetimeAxis = isDatetimeAxis;
  5675. // Flag, if axis is linked to another axis
  5676. axis.isLinked = defined(options.linkedTo);
  5677. // Linked axis.
  5678. //axis.linkedParent = UNDEFINED;
  5679. // Tick positions
  5680. //axis.tickPositions = UNDEFINED; // array containing predefined positions
  5681. // Tick intervals
  5682. //axis.tickInterval = UNDEFINED;
  5683. //axis.minorTickInterval = UNDEFINED;
  5684. // Major ticks
  5685. axis.ticks = {};
  5686. axis.labelEdge = [];
  5687. // Minor ticks
  5688. axis.minorTicks = {};
  5689. // List of plotLines/Bands
  5690. axis.plotLinesAndBands = [];
  5691. // Alternate bands
  5692. axis.alternateBands = {};
  5693. // Axis metrics
  5694. //axis.left = UNDEFINED;
  5695. //axis.top = UNDEFINED;
  5696. //axis.width = UNDEFINED;
  5697. //axis.height = UNDEFINED;
  5698. //axis.bottom = UNDEFINED;
  5699. //axis.right = UNDEFINED;
  5700. //axis.transA = UNDEFINED;
  5701. //axis.transB = UNDEFINED;
  5702. //axis.oldTransA = UNDEFINED;
  5703. axis.len = 0;
  5704. //axis.oldMin = UNDEFINED;
  5705. //axis.oldMax = UNDEFINED;
  5706. //axis.oldUserMin = UNDEFINED;
  5707. //axis.oldUserMax = UNDEFINED;
  5708. //axis.oldAxisLength = UNDEFINED;
  5709. axis.minRange = axis.userMinRange = options.minRange || options.maxZoom;
  5710. axis.range = options.range;
  5711. axis.offset = options.offset || 0;
  5712. // Dictionary for stacks
  5713. axis.stacks = {};
  5714. axis.oldStacks = {};
  5715. axis.stacksTouched = 0;
  5716. // Min and max in the data
  5717. //axis.dataMin = UNDEFINED,
  5718. //axis.dataMax = UNDEFINED,
  5719. // The axis range
  5720. axis.max = null;
  5721. axis.min = null;
  5722. // User set min and max
  5723. //axis.userMin = UNDEFINED,
  5724. //axis.userMax = UNDEFINED,
  5725. // Crosshair options
  5726. axis.crosshair = pick(options.crosshair, splat(chart.options.tooltip.crosshairs)[isXAxis ? 0 : 1], false);
  5727. // Run Axis
  5728. var eventType,
  5729. events = axis.options.events;
  5730. // Register
  5731. if (inArray(axis, chart.axes) === -1) { // don't add it again on Axis.update()
  5732. if (isXAxis && !this.isColorAxis) { // #2713
  5733. chart.axes.splice(chart.xAxis.length, 0, axis);
  5734. } else {
  5735. chart.axes.push(axis);
  5736. }
  5737. chart[axis.coll].push(axis);
  5738. }
  5739. axis.series = axis.series || []; // populated by Series
  5740. // inverted charts have reversed xAxes as default
  5741. if (chart.inverted && isXAxis && axis.reversed === UNDEFINED) {
  5742. axis.reversed = true;
  5743. }
  5744. axis.removePlotBand = axis.removePlotBandOrLine;
  5745. axis.removePlotLine = axis.removePlotBandOrLine;
  5746. // register event listeners
  5747. for (eventType in events) {
  5748. addEvent(axis, eventType, events[eventType]);
  5749. }
  5750. // extend logarithmic axis
  5751. if (axis.isLog) {
  5752. axis.val2lin = log2lin;
  5753. axis.lin2val = lin2log;
  5754. }
  5755. },
  5756. /**
  5757. * Merge and set options
  5758. */
  5759. setOptions: function (userOptions) {
  5760. this.options = merge(
  5761. this.defaultOptions,
  5762. this.isXAxis ? {} : this.defaultYAxisOptions,
  5763. [this.defaultTopAxisOptions, this.defaultRightAxisOptions,
  5764. this.defaultBottomAxisOptions, this.defaultLeftAxisOptions][this.side],
  5765. merge(
  5766. defaultOptions[this.coll], // if set in setOptions (#1053)
  5767. userOptions
  5768. )
  5769. );
  5770. },
  5771. /**
  5772. * The default label formatter. The context is a special config object for the label.
  5773. */
  5774. defaultLabelFormatter: function () {
  5775. var axis = this.axis,
  5776. value = this.value,
  5777. categories = axis.categories,
  5778. dateTimeLabelFormat = this.dateTimeLabelFormat,
  5779. numericSymbols = defaultOptions.lang.numericSymbols,
  5780. i = numericSymbols && numericSymbols.length,
  5781. multi,
  5782. ret,
  5783. formatOption = axis.options.labels.format,
  5784. // make sure the same symbol is added for all labels on a linear axis
  5785. numericSymbolDetector = axis.isLog ? value : axis.tickInterval;
  5786. if (formatOption) {
  5787. ret = format(formatOption, this);
  5788. } else if (categories) {
  5789. ret = value;
  5790. } else if (dateTimeLabelFormat) { // datetime axis
  5791. ret = dateFormat(dateTimeLabelFormat, value);
  5792. } else if (i && numericSymbolDetector >= 1000) {
  5793. // Decide whether we should add a numeric symbol like k (thousands) or M (millions).
  5794. // If we are to enable this in tooltip or other places as well, we can move this
  5795. // logic to the numberFormatter and enable it by a parameter.
  5796. while (i-- && ret === UNDEFINED) {
  5797. multi = Math.pow(1000, i + 1);
  5798. if (numericSymbolDetector >= multi && (value * 10) % multi === 0 && numericSymbols[i] !== null) {
  5799. ret = Highcharts.numberFormat(value / multi, -1) + numericSymbols[i];
  5800. }
  5801. }
  5802. }
  5803. if (ret === UNDEFINED) {
  5804. if (mathAbs(value) >= 10000) { // add thousands separators
  5805. ret = Highcharts.numberFormat(value, -1);
  5806. } else { // small numbers
  5807. ret = Highcharts.numberFormat(value, -1, UNDEFINED, ''); // #2466
  5808. }
  5809. }
  5810. return ret;
  5811. },
  5812. /**
  5813. * Get the minimum and maximum for the series of each axis
  5814. */
  5815. getSeriesExtremes: function () {
  5816. var axis = this,
  5817. chart = axis.chart;
  5818. axis.hasVisibleSeries = false;
  5819. // Reset properties in case we're redrawing (#3353)
  5820. axis.dataMin = axis.dataMax = axis.threshold = null;
  5821. axis.softThreshold = !axis.isXAxis;
  5822. if (axis.buildStacks) {
  5823. axis.buildStacks();
  5824. }
  5825. // loop through this axis' series
  5826. each(axis.series, function (series) {
  5827. if (series.visible || !chart.options.chart.ignoreHiddenSeries) {
  5828. var seriesOptions = series.options,
  5829. xData,
  5830. threshold = seriesOptions.threshold,
  5831. seriesDataMin,
  5832. seriesDataMax;
  5833. axis.hasVisibleSeries = true;
  5834. // Validate threshold in logarithmic axes
  5835. if (axis.isLog && threshold <= 0) {
  5836. threshold = null;
  5837. }
  5838. // Get dataMin and dataMax for X axes
  5839. if (axis.isXAxis) {
  5840. xData = series.xData;
  5841. if (xData.length) {
  5842. axis.dataMin = mathMin(pick(axis.dataMin, xData[0]), arrayMin(xData));
  5843. axis.dataMax = mathMax(pick(axis.dataMax, xData[0]), arrayMax(xData));
  5844. }
  5845. // Get dataMin and dataMax for Y axes, as well as handle stacking and processed data
  5846. } else {
  5847. // Get this particular series extremes
  5848. series.getExtremes();
  5849. seriesDataMax = series.dataMax;
  5850. seriesDataMin = series.dataMin;
  5851. // Get the dataMin and dataMax so far. If percentage is used, the min and max are
  5852. // always 0 and 100. If seriesDataMin and seriesDataMax is null, then series
  5853. // doesn't have active y data, we continue with nulls
  5854. if (defined(seriesDataMin) && defined(seriesDataMax)) {
  5855. axis.dataMin = mathMin(pick(axis.dataMin, seriesDataMin), seriesDataMin);
  5856. axis.dataMax = mathMax(pick(axis.dataMax, seriesDataMax), seriesDataMax);
  5857. }
  5858. // Adjust to threshold
  5859. if (defined(threshold)) {
  5860. axis.threshold = threshold;
  5861. }
  5862. // If any series has a hard threshold, it takes precedence
  5863. if (!seriesOptions.softThreshold || axis.isLog) {
  5864. axis.softThreshold = false;
  5865. }
  5866. }
  5867. }
  5868. });
  5869. },
  5870. /**
  5871. * Translate from axis value to pixel position on the chart, or back
  5872. *
  5873. */
  5874. translate: function (val, backwards, cvsCoord, old, handleLog, pointPlacement) {
  5875. var axis = this.linkedParent || this, // #1417
  5876. sign = 1,
  5877. cvsOffset = 0,
  5878. localA = old ? axis.oldTransA : axis.transA,
  5879. localMin = old ? axis.oldMin : axis.min,
  5880. returnValue,
  5881. minPixelPadding = axis.minPixelPadding,
  5882. doPostTranslate = (axis.doPostTranslate || (axis.isLog && handleLog)) && axis.lin2val;
  5883. if (!localA) {
  5884. localA = axis.transA;
  5885. }
  5886. // In vertical axes, the canvas coordinates start from 0 at the top like in
  5887. // SVG.
  5888. if (cvsCoord) {
  5889. sign *= -1; // canvas coordinates inverts the value
  5890. cvsOffset = axis.len;
  5891. }
  5892. // Handle reversed axis
  5893. if (axis.reversed) {
  5894. sign *= -1;
  5895. cvsOffset -= sign * (axis.sector || axis.len);
  5896. }
  5897. // From pixels to value
  5898. if (backwards) { // reverse translation
  5899. val = val * sign + cvsOffset;
  5900. val -= minPixelPadding;
  5901. returnValue = val / localA + localMin; // from chart pixel to value
  5902. if (doPostTranslate) { // log and ordinal axes
  5903. returnValue = axis.lin2val(returnValue);
  5904. }
  5905. // From value to pixels
  5906. } else {
  5907. if (doPostTranslate) { // log and ordinal axes
  5908. val = axis.val2lin(val);
  5909. }
  5910. if (pointPlacement === 'between') {
  5911. pointPlacement = 0.5;
  5912. }
  5913. returnValue = sign * (val - localMin) * localA + cvsOffset + (sign * minPixelPadding) +
  5914. (isNumber(pointPlacement) ? localA * pointPlacement * axis.pointRange : 0);
  5915. }
  5916. return returnValue;
  5917. },
  5918. /**
  5919. * Utility method to translate an axis value to pixel position.
  5920. * @param {Number} value A value in terms of axis units
  5921. * @param {Boolean} paneCoordinates Whether to return the pixel coordinate relative to the chart
  5922. * or just the axis/pane itself.
  5923. */
  5924. toPixels: function (value, paneCoordinates) {
  5925. return this.translate(value, false, !this.horiz, null, true) + (paneCoordinates ? 0 : this.pos);
  5926. },
  5927. /*
  5928. * Utility method to translate a pixel position in to an axis value
  5929. * @param {Number} pixel The pixel value coordinate
  5930. * @param {Boolean} paneCoordiantes Whether the input pixel is relative to the chart or just the
  5931. * axis/pane itself.
  5932. */
  5933. toValue: function (pixel, paneCoordinates) {
  5934. return this.translate(pixel - (paneCoordinates ? 0 : this.pos), true, !this.horiz, null, true);
  5935. },
  5936. /**
  5937. * Create the path for a plot line that goes from the given value on
  5938. * this axis, across the plot to the opposite side
  5939. * @param {Number} value
  5940. * @param {Number} lineWidth Used for calculation crisp line
  5941. * @param {Number] old Use old coordinates (for resizing and rescaling)
  5942. */
  5943. getPlotLinePath: function (value, lineWidth, old, force, translatedValue) {
  5944. var axis = this,
  5945. chart = axis.chart,
  5946. axisLeft = axis.left,
  5947. axisTop = axis.top,
  5948. x1,
  5949. y1,
  5950. x2,
  5951. y2,
  5952. cHeight = (old && chart.oldChartHeight) || chart.chartHeight,
  5953. cWidth = (old && chart.oldChartWidth) || chart.chartWidth,
  5954. skip,
  5955. transB = axis.transB,
  5956. /**
  5957. * Check if x is between a and b. If not, either move to a/b or skip,
  5958. * depending on the force parameter.
  5959. */
  5960. between = function (x, a, b) {
  5961. if (x < a || x > b) {
  5962. if (force) {
  5963. x = mathMin(mathMax(a, x), b);
  5964. } else {
  5965. skip = true;
  5966. }
  5967. }
  5968. return x;
  5969. };
  5970. translatedValue = pick(translatedValue, axis.translate(value, null, null, old));
  5971. x1 = x2 = mathRound(translatedValue + transB);
  5972. y1 = y2 = mathRound(cHeight - translatedValue - transB);
  5973. if (isNaN(translatedValue)) { // no min or max
  5974. skip = true;
  5975. } else if (axis.horiz) {
  5976. y1 = axisTop;
  5977. y2 = cHeight - axis.bottom;
  5978. x1 = x2 = between(x1, axisLeft, axisLeft + axis.width);
  5979. } else {
  5980. x1 = axisLeft;
  5981. x2 = cWidth - axis.right;
  5982. y1 = y2 = between(y1, axisTop, axisTop + axis.height);
  5983. }
  5984. return skip && !force ?
  5985. null :
  5986. chart.renderer.crispLine([M, x1, y1, L, x2, y2], lineWidth || 1);
  5987. },
  5988. /**
  5989. * Set the tick positions of a linear axis to round values like whole tens or every five.
  5990. */
  5991. getLinearTickPositions: function (tickInterval, min, max) {
  5992. var pos,
  5993. lastPos,
  5994. roundedMin = correctFloat(mathFloor(min / tickInterval) * tickInterval),
  5995. roundedMax = correctFloat(mathCeil(max / tickInterval) * tickInterval),
  5996. tickPositions = [];
  5997. // For single points, add a tick regardless of the relative position (#2662)
  5998. if (min === max && isNumber(min)) {
  5999. return [min];
  6000. }
  6001. // Populate the intermediate values
  6002. pos = roundedMin;
  6003. while (pos <= roundedMax) {
  6004. // Place the tick on the rounded value
  6005. tickPositions.push(pos);
  6006. // Always add the raw tickInterval, not the corrected one.
  6007. pos = correctFloat(pos + tickInterval);
  6008. // If the interval is not big enough in the current min - max range to actually increase
  6009. // the loop variable, we need to break out to prevent endless loop. Issue #619
  6010. if (pos === lastPos) {
  6011. break;
  6012. }
  6013. // Record the last value
  6014. lastPos = pos;
  6015. }
  6016. return tickPositions;
  6017. },
  6018. /**
  6019. * Return the minor tick positions. For logarithmic axes, reuse the same logic
  6020. * as for major ticks.
  6021. */
  6022. getMinorTickPositions: function () {
  6023. var axis = this,
  6024. options = axis.options,
  6025. tickPositions = axis.tickPositions,
  6026. minorTickInterval = axis.minorTickInterval,
  6027. minorTickPositions = [],
  6028. pos,
  6029. i,
  6030. pointRangePadding = axis.pointRangePadding || 0,
  6031. min = axis.min - pointRangePadding, // #1498
  6032. max = axis.max + pointRangePadding, // #1498
  6033. range = max - min,
  6034. len;
  6035. // If minor ticks get too dense, they are hard to read, and may cause long running script. So we don't draw them.
  6036. if (range && range / minorTickInterval < axis.len / 3) { // #3875
  6037. if (axis.isLog) {
  6038. len = tickPositions.length;
  6039. for (i = 1; i < len; i++) {
  6040. minorTickPositions = minorTickPositions.concat(
  6041. axis.getLogTickPositions(minorTickInterval, tickPositions[i - 1], tickPositions[i], true)
  6042. );
  6043. }
  6044. } else if (axis.isDatetimeAxis && options.minorTickInterval === 'auto') { // #1314
  6045. minorTickPositions = minorTickPositions.concat(
  6046. axis.getTimeTicks(
  6047. axis.normalizeTimeTickInterval(minorTickInterval),
  6048. min,
  6049. max,
  6050. options.startOfWeek
  6051. )
  6052. );
  6053. } else {
  6054. for (pos = min + (tickPositions[0] - min) % minorTickInterval; pos <= max; pos += minorTickInterval) {
  6055. minorTickPositions.push(pos);
  6056. }
  6057. }
  6058. }
  6059. if(minorTickPositions.length !== 0) { // don't change the extremes, when there is no minor ticks
  6060. axis.trimTicks(minorTickPositions, options.startOnTick, options.endOnTick); // #3652 #3743 #1498
  6061. }
  6062. return minorTickPositions;
  6063. },
  6064. /**
  6065. * Adjust the min and max for the minimum range. Keep in mind that the series data is
  6066. * not yet processed, so we don't have information on data cropping and grouping, or
  6067. * updated axis.pointRange or series.pointRange. The data can't be processed until
  6068. * we have finally established min and max.
  6069. */
  6070. adjustForMinRange: function () {
  6071. var axis = this,
  6072. options = axis.options,
  6073. min = axis.min,
  6074. max = axis.max,
  6075. zoomOffset,
  6076. spaceAvailable = axis.dataMax - axis.dataMin >= axis.minRange,
  6077. closestDataRange,
  6078. i,
  6079. distance,
  6080. xData,
  6081. loopLength,
  6082. minArgs,
  6083. maxArgs,
  6084. minRange;
  6085. // Set the automatic minimum range based on the closest point distance
  6086. if (axis.isXAxis && axis.minRange === UNDEFINED && !axis.isLog) {
  6087. if (defined(options.min) || defined(options.max)) {
  6088. axis.minRange = null; // don't do this again
  6089. } else {
  6090. // Find the closest distance between raw data points, as opposed to
  6091. // closestPointRange that applies to processed points (cropped and grouped)
  6092. each(axis.series, function (series) {
  6093. xData = series.xData;
  6094. loopLength = series.xIncrement ? 1 : xData.length - 1;
  6095. for (i = loopLength; i > 0; i--) {
  6096. distance = xData[i] - xData[i - 1];
  6097. if (closestDataRange === UNDEFINED || distance < closestDataRange) {
  6098. closestDataRange = distance;
  6099. }
  6100. }
  6101. });
  6102. axis.minRange = mathMin(closestDataRange * 5, axis.dataMax - axis.dataMin);
  6103. }
  6104. }
  6105. // if minRange is exceeded, adjust
  6106. if (max - min < axis.minRange) {
  6107. minRange = axis.minRange;
  6108. zoomOffset = (minRange - max + min) / 2;
  6109. // if min and max options have been set, don't go beyond it
  6110. minArgs = [min - zoomOffset, pick(options.min, min - zoomOffset)];
  6111. if (spaceAvailable) { // if space is available, stay within the data range
  6112. minArgs[2] = axis.dataMin;
  6113. }
  6114. min = arrayMax(minArgs);
  6115. maxArgs = [min + minRange, pick(options.max, min + minRange)];
  6116. if (spaceAvailable) { // if space is availabe, stay within the data range
  6117. maxArgs[2] = axis.dataMax;
  6118. }
  6119. max = arrayMin(maxArgs);
  6120. // now if the max is adjusted, adjust the min back
  6121. if (max - min < minRange) {
  6122. minArgs[0] = max - minRange;
  6123. minArgs[1] = pick(options.min, max - minRange);
  6124. min = arrayMax(minArgs);
  6125. }
  6126. }
  6127. // Record modified extremes
  6128. axis.min = min;
  6129. axis.max = max;
  6130. },
  6131. /**
  6132. * Update translation information
  6133. */
  6134. setAxisTranslation: function (saveOld) {
  6135. var axis = this,
  6136. range = axis.max - axis.min,
  6137. pointRange = axis.axisPointRange || 0,
  6138. closestPointRange,
  6139. minPointOffset = 0,
  6140. pointRangePadding = 0,
  6141. linkedParent = axis.linkedParent,
  6142. ordinalCorrection,
  6143. hasCategories = !!axis.categories,
  6144. transA = axis.transA,
  6145. isXAxis = axis.isXAxis;
  6146. // Adjust translation for padding. Y axis with categories need to go through the same (#1784).
  6147. if (isXAxis || hasCategories || pointRange) {
  6148. if (linkedParent) {
  6149. minPointOffset = linkedParent.minPointOffset;
  6150. pointRangePadding = linkedParent.pointRangePadding;
  6151. } else {
  6152. each(axis.series, function (series) {
  6153. var seriesPointRange = hasCategories ? 1 : (isXAxis ? series.pointRange : (axis.axisPointRange || 0)), // #2806
  6154. pointPlacement = series.options.pointPlacement,
  6155. seriesClosestPointRange = series.closestPointRange;
  6156. pointRange = mathMax(pointRange, seriesPointRange);
  6157. if (!axis.single) {
  6158. // minPointOffset is the value padding to the left of the axis in order to make
  6159. // room for points with a pointRange, typically columns. When the pointPlacement option
  6160. // is 'between' or 'on', this padding does not apply.
  6161. minPointOffset = mathMax(
  6162. minPointOffset,
  6163. isString(pointPlacement) ? 0 : seriesPointRange / 2
  6164. );
  6165. // Determine the total padding needed to the length of the axis to make room for the
  6166. // pointRange. If the series' pointPlacement is 'on', no padding is added.
  6167. pointRangePadding = mathMax(
  6168. pointRangePadding,
  6169. pointPlacement === 'on' ? 0 : seriesPointRange
  6170. );
  6171. }
  6172. // Set the closestPointRange
  6173. if (!series.noSharedTooltip && defined(seriesClosestPointRange)) {
  6174. closestPointRange = defined(closestPointRange) ?
  6175. mathMin(closestPointRange, seriesClosestPointRange) :
  6176. seriesClosestPointRange;
  6177. }
  6178. });
  6179. }
  6180. // Record minPointOffset and pointRangePadding
  6181. ordinalCorrection = axis.ordinalSlope && closestPointRange ? axis.ordinalSlope / closestPointRange : 1; // #988, #1853
  6182. axis.minPointOffset = minPointOffset = minPointOffset * ordinalCorrection;
  6183. axis.pointRangePadding = pointRangePadding = pointRangePadding * ordinalCorrection;
  6184. // pointRange means the width reserved for each point, like in a column chart
  6185. axis.pointRange = mathMin(pointRange, range);
  6186. // closestPointRange means the closest distance between points. In columns
  6187. // it is mostly equal to pointRange, but in lines pointRange is 0 while closestPointRange
  6188. // is some other value
  6189. if (isXAxis) {
  6190. axis.closestPointRange = closestPointRange;
  6191. }
  6192. }
  6193. // Secondary values
  6194. if (saveOld) {
  6195. axis.oldTransA = transA;
  6196. }
  6197. axis.translationSlope = axis.transA = transA = axis.len / ((range + pointRangePadding) || 1);
  6198. axis.transB = axis.horiz ? axis.left : axis.bottom; // translation addend
  6199. axis.minPixelPadding = transA * minPointOffset;
  6200. },
  6201. minFromRange: function () {
  6202. return this.max - this.range;
  6203. },
  6204. /**
  6205. * Set the tick positions to round values and optionally extend the extremes
  6206. * to the nearest tick
  6207. */
  6208. setTickInterval: function (secondPass) {
  6209. var axis = this,
  6210. chart = axis.chart,
  6211. options = axis.options,
  6212. isLog = axis.isLog,
  6213. isDatetimeAxis = axis.isDatetimeAxis,
  6214. isXAxis = axis.isXAxis,
  6215. isLinked = axis.isLinked,
  6216. maxPadding = options.maxPadding,
  6217. minPadding = options.minPadding,
  6218. length,
  6219. linkedParentExtremes,
  6220. tickIntervalOption = options.tickInterval,
  6221. minTickInterval,
  6222. tickPixelIntervalOption = options.tickPixelInterval,
  6223. categories = axis.categories,
  6224. threshold = axis.threshold,
  6225. softThreshold = axis.softThreshold,
  6226. thresholdMin,
  6227. thresholdMax,
  6228. hardMin,
  6229. hardMax;
  6230. if (!isDatetimeAxis && !categories && !isLinked) {
  6231. this.getTickAmount();
  6232. }
  6233. // Min or max set either by zooming/setExtremes or initial options
  6234. hardMin = pick(axis.userMin, options.min);
  6235. hardMax = pick(axis.userMax, options.max);
  6236. // Linked axis gets the extremes from the parent axis
  6237. if (isLinked) {
  6238. axis.linkedParent = chart[axis.coll][options.linkedTo];
  6239. linkedParentExtremes = axis.linkedParent.getExtremes();
  6240. axis.min = pick(linkedParentExtremes.min, linkedParentExtremes.dataMin);
  6241. axis.max = pick(linkedParentExtremes.max, linkedParentExtremes.dataMax);
  6242. if (options.type !== axis.linkedParent.options.type) {
  6243. error(11, 1); // Can't link axes of different type
  6244. }
  6245. // Initial min and max from the extreme data values
  6246. } else {
  6247. // Adjust to hard threshold
  6248. if (!softThreshold && defined(threshold)) {
  6249. if (axis.dataMin >= threshold) {
  6250. thresholdMin = threshold;
  6251. minPadding = 0;
  6252. } else if (axis.dataMax <= threshold) {
  6253. thresholdMax = threshold;
  6254. maxPadding = 0;
  6255. }
  6256. }
  6257. axis.min = pick(hardMin, thresholdMin, axis.dataMin);
  6258. axis.max = pick(hardMax, thresholdMax, axis.dataMax);
  6259. }
  6260. if (isLog) {
  6261. if (!secondPass && mathMin(axis.min, pick(axis.dataMin, axis.min)) <= 0) { // #978
  6262. error(10, 1); // Can't plot negative values on log axis
  6263. }
  6264. // The correctFloat cures #934, float errors on full tens. But it
  6265. // was too aggressive for #4360 because of conversion back to lin,
  6266. // therefore use precision 15.
  6267. axis.min = correctFloat(log2lin(axis.min), 15);
  6268. axis.max = correctFloat(log2lin(axis.max), 15);
  6269. }
  6270. // handle zoomed range
  6271. if (axis.range && defined(axis.max)) {
  6272. axis.userMin = axis.min = hardMin = mathMax(axis.min, axis.minFromRange()); // #618
  6273. axis.userMax = hardMax = axis.max;
  6274. axis.range = null; // don't use it when running setExtremes
  6275. }
  6276. // Hook for adjusting this.min and this.max. Used by bubble series.
  6277. if (axis.beforePadding) {
  6278. axis.beforePadding();
  6279. }
  6280. // adjust min and max for the minimum range
  6281. axis.adjustForMinRange();
  6282. // Pad the values to get clear of the chart's edges. To avoid tickInterval taking the padding
  6283. // into account, we do this after computing tick interval (#1337).
  6284. if (!categories && !axis.axisPointRange && !axis.usePercentage && !isLinked && defined(axis.min) && defined(axis.max)) {
  6285. length = axis.max - axis.min;
  6286. if (length) {
  6287. if (!defined(hardMin) && minPadding) {
  6288. axis.min -= length * minPadding;
  6289. }
  6290. if (!defined(hardMax) && maxPadding) {
  6291. axis.max += length * maxPadding;
  6292. }
  6293. }
  6294. }
  6295. // Stay within floor and ceiling
  6296. if (isNumber(options.floor)) {
  6297. axis.min = mathMax(axis.min, options.floor);
  6298. }
  6299. if (isNumber(options.ceiling)) {
  6300. axis.max = mathMin(axis.max, options.ceiling);
  6301. }
  6302. // When the threshold is soft, adjust the extreme value only if
  6303. // the data extreme and the padded extreme land on either side of the threshold. For example,
  6304. // a series of [0, 1, 2, 3] would make the yAxis add a tick for -1 because of the
  6305. // default minPadding and startOnTick options. This is prevented by the softThreshold
  6306. // option.
  6307. if (softThreshold && defined(axis.dataMin)) {
  6308. threshold = threshold || 0;
  6309. if (!defined(hardMin) && axis.min < threshold && axis.dataMin >= threshold) {
  6310. axis.min = threshold;
  6311. } else if (!defined(hardMax) && axis.max > threshold && axis.dataMax <= threshold) {
  6312. axis.max = threshold;
  6313. }
  6314. }
  6315. // get tickInterval
  6316. if (axis.min === axis.max || axis.min === undefined || axis.max === undefined) {
  6317. axis.tickInterval = 1;
  6318. } else if (isLinked && !tickIntervalOption &&
  6319. tickPixelIntervalOption === axis.linkedParent.options.tickPixelInterval) {
  6320. axis.tickInterval = tickIntervalOption = axis.linkedParent.tickInterval;
  6321. } else {
  6322. axis.tickInterval = pick(
  6323. tickIntervalOption,
  6324. this.tickAmount ? ((axis.max - axis.min) / mathMax(this.tickAmount - 1, 1)) : undefined,
  6325. categories ? // for categoried axis, 1 is default, for linear axis use tickPix
  6326. 1 :
  6327. // don't let it be more than the data range
  6328. (axis.max - axis.min) * tickPixelIntervalOption / mathMax(axis.len, tickPixelIntervalOption)
  6329. );
  6330. }
  6331. // Now we're finished detecting min and max, crop and group series data. This
  6332. // is in turn needed in order to find tick positions in ordinal axes.
  6333. if (isXAxis && !secondPass) {
  6334. each(axis.series, function (series) {
  6335. series.processData(axis.min !== axis.oldMin || axis.max !== axis.oldMax);
  6336. });
  6337. }
  6338. // set the translation factor used in translate function
  6339. axis.setAxisTranslation(true);
  6340. // hook for ordinal axes and radial axes
  6341. if (axis.beforeSetTickPositions) {
  6342. axis.beforeSetTickPositions();
  6343. }
  6344. // hook for extensions, used in Highstock ordinal axes
  6345. if (axis.postProcessTickInterval) {
  6346. axis.tickInterval = axis.postProcessTickInterval(axis.tickInterval);
  6347. }
  6348. // In column-like charts, don't cramp in more ticks than there are points (#1943)
  6349. if (axis.pointRange) {
  6350. axis.tickInterval = mathMax(axis.pointRange, axis.tickInterval);
  6351. }
  6352. // Before normalizing the tick interval, handle minimum tick interval. This applies only if tickInterval is not defined.
  6353. minTickInterval = pick(options.minTickInterval, axis.isDatetimeAxis && axis.closestPointRange);
  6354. if (!tickIntervalOption && axis.tickInterval < minTickInterval) {
  6355. axis.tickInterval = minTickInterval;
  6356. }
  6357. // for linear axes, get magnitude and normalize the interval
  6358. if (!isDatetimeAxis && !isLog && !tickIntervalOption) {
  6359. axis.tickInterval = normalizeTickInterval(
  6360. axis.tickInterval,
  6361. null,
  6362. getMagnitude(axis.tickInterval),
  6363. // If the tick interval is between 0.5 and 5 and the axis max is in the order of
  6364. // thousands, chances are we are dealing with years. Don't allow decimals. #3363.
  6365. pick(options.allowDecimals, !(axis.tickInterval > 0.5 && axis.tickInterval < 5 && axis.max > 1000 && axis.max < 9999)),
  6366. !!this.tickAmount
  6367. );
  6368. }
  6369. // Prevent ticks from getting so close that we can't draw the labels
  6370. if (!this.tickAmount && this.len) { // Color axis with disabled legend has no length
  6371. axis.tickInterval = axis.unsquish();
  6372. }
  6373. this.setTickPositions();
  6374. },
  6375. /**
  6376. * Now we have computed the normalized tickInterval, get the tick positions
  6377. */
  6378. setTickPositions: function () {
  6379. var options = this.options,
  6380. tickPositions,
  6381. tickPositionsOption = options.tickPositions,
  6382. tickPositioner = options.tickPositioner,
  6383. startOnTick = options.startOnTick,
  6384. endOnTick = options.endOnTick,
  6385. single;
  6386. // Set the tickmarkOffset
  6387. this.tickmarkOffset = (this.categories && options.tickmarkPlacement === 'between' &&
  6388. this.tickInterval === 1) ? 0.5 : 0; // #3202
  6389. // get minorTickInterval
  6390. this.minorTickInterval = options.minorTickInterval === 'auto' && this.tickInterval ?
  6391. this.tickInterval / 5 : options.minorTickInterval;
  6392. // Find the tick positions
  6393. this.tickPositions = tickPositions = tickPositionsOption && tickPositionsOption.slice(); // Work on a copy (#1565)
  6394. if (!tickPositions) {
  6395. if (this.isDatetimeAxis) {
  6396. tickPositions = this.getTimeTicks(
  6397. this.normalizeTimeTickInterval(this.tickInterval, options.units),
  6398. this.min,
  6399. this.max,
  6400. options.startOfWeek,
  6401. this.ordinalPositions,
  6402. this.closestPointRange,
  6403. true
  6404. );
  6405. } else if (this.isLog) {
  6406. tickPositions = this.getLogTickPositions(this.tickInterval, this.min, this.max);
  6407. } else {
  6408. tickPositions = this.getLinearTickPositions(this.tickInterval, this.min, this.max);
  6409. }
  6410. // Too dense ticks, keep only the first and last (#4477)
  6411. if (tickPositions.length > this.len) {
  6412. tickPositions = [tickPositions[0], tickPositions.pop()];
  6413. }
  6414. this.tickPositions = tickPositions;
  6415. // Run the tick positioner callback, that allows modifying auto tick positions.
  6416. if (tickPositioner) {
  6417. tickPositioner = tickPositioner.apply(this, [this.min, this.max]);
  6418. if (tickPositioner) {
  6419. this.tickPositions = tickPositions = tickPositioner;
  6420. }
  6421. }
  6422. }
  6423. if (!this.isLinked) {
  6424. // reset min/max or remove extremes based on start/end on tick
  6425. this.trimTicks(tickPositions, startOnTick, endOnTick);
  6426. // When there is only one point, or all points have the same value on this axis, then min
  6427. // and max are equal and tickPositions.length is 0 or 1. In this case, add some padding
  6428. // in order to center the point, but leave it with one tick. #1337.
  6429. if (this.min === this.max && defined(this.min) && !this.tickAmount) {
  6430. // Substract half a unit (#2619, #2846, #2515, #3390)
  6431. single = true;
  6432. this.min -= 0.5;
  6433. this.max += 0.5;
  6434. }
  6435. this.single = single;
  6436. if (!tickPositionsOption && !tickPositioner) {
  6437. this.adjustTickAmount();
  6438. }
  6439. }
  6440. },
  6441. /**
  6442. * Handle startOnTick and endOnTick by either adapting to padding min/max or rounded min/max
  6443. */
  6444. trimTicks: function (tickPositions, startOnTick, endOnTick) {
  6445. var roundedMin = tickPositions[0],
  6446. roundedMax = tickPositions[tickPositions.length - 1],
  6447. minPointOffset = this.minPointOffset || 0;
  6448. if (startOnTick) {
  6449. this.min = roundedMin;
  6450. } else if (this.min - minPointOffset > roundedMin) {
  6451. tickPositions.shift();
  6452. }
  6453. if (endOnTick) {
  6454. this.max = roundedMax;
  6455. } else if (this.max + minPointOffset < roundedMax) {
  6456. tickPositions.pop();
  6457. }
  6458. // If no tick are left, set one tick in the middle (#3195)
  6459. if (tickPositions.length === 0 && defined(roundedMin)) {
  6460. tickPositions.push((roundedMax + roundedMin) / 2);
  6461. }
  6462. },
  6463. /**
  6464. * Set the max ticks of either the x and y axis collection
  6465. */
  6466. getTickAmount: function () {
  6467. var others = {}, // Whether there is another axis to pair with this one
  6468. hasOther,
  6469. options = this.options,
  6470. tickAmount = options.tickAmount,
  6471. tickPixelInterval = options.tickPixelInterval;
  6472. if (!defined(options.tickInterval) && this.len < tickPixelInterval && !this.isRadial &&
  6473. !this.isLog && options.startOnTick && options.endOnTick) {
  6474. tickAmount = 2;
  6475. }
  6476. if (!tickAmount && this.chart.options.chart.alignTicks !== false && options.alignTicks !== false) {
  6477. // Check if there are multiple axes in the same pane
  6478. each(this.chart[this.coll], function (axis) {
  6479. var options = axis.options,
  6480. horiz = axis.horiz,
  6481. key = [horiz ? options.left : options.top, horiz ? options.width : options.height, options.pane].join(',');
  6482. if (axis.series.length) { // #4442
  6483. if (others[key]) {
  6484. hasOther = true; // #4201
  6485. } else {
  6486. others[key] = 1;
  6487. }
  6488. }
  6489. });
  6490. if (hasOther) {
  6491. // Add 1 because 4 tick intervals require 5 ticks (including first and last)
  6492. tickAmount = mathCeil(this.len / tickPixelInterval) + 1;
  6493. }
  6494. }
  6495. // For tick amounts of 2 and 3, compute five ticks and remove the intermediate ones. This
  6496. // prevents the axis from adding ticks that are too far away from the data extremes.
  6497. if (tickAmount < 4) {
  6498. this.finalTickAmt = tickAmount;
  6499. tickAmount = 5;
  6500. }
  6501. this.tickAmount = tickAmount;
  6502. },
  6503. /**
  6504. * When using multiple axes, adjust the number of ticks to match the highest
  6505. * number of ticks in that group
  6506. */
  6507. adjustTickAmount: function () {
  6508. var tickInterval = this.tickInterval,
  6509. tickPositions = this.tickPositions,
  6510. tickAmount = this.tickAmount,
  6511. finalTickAmt = this.finalTickAmt,
  6512. currentTickAmount = tickPositions && tickPositions.length,
  6513. i,
  6514. len;
  6515. if (currentTickAmount < tickAmount) { // TODO: Check #3411
  6516. while (tickPositions.length < tickAmount) {
  6517. tickPositions.push(correctFloat(
  6518. tickPositions[tickPositions.length - 1] + tickInterval
  6519. ));
  6520. }
  6521. this.transA *= (currentTickAmount - 1) / (tickAmount - 1);
  6522. this.max = tickPositions[tickPositions.length - 1];
  6523. // We have too many ticks, run second pass to try to reduce ticks
  6524. } else if (currentTickAmount > tickAmount) {
  6525. this.tickInterval *= 2;
  6526. this.setTickPositions();
  6527. }
  6528. // The finalTickAmt property is set in getTickAmount
  6529. if (defined(finalTickAmt)) {
  6530. i = len = tickPositions.length;
  6531. while (i--) {
  6532. if (
  6533. (finalTickAmt === 3 && i % 2 === 1) || // Remove every other tick
  6534. (finalTickAmt <= 2 && i > 0 && i < len - 1) // Remove all but first and last
  6535. ) {
  6536. tickPositions.splice(i, 1);
  6537. }
  6538. }
  6539. this.finalTickAmt = UNDEFINED;
  6540. }
  6541. },
  6542. /**
  6543. * Set the scale based on data min and max, user set min and max or options
  6544. *
  6545. */
  6546. setScale: function () {
  6547. var axis = this,
  6548. isDirtyData,
  6549. isDirtyAxisLength;
  6550. axis.oldMin = axis.min;
  6551. axis.oldMax = axis.max;
  6552. axis.oldAxisLength = axis.len;
  6553. // set the new axisLength
  6554. axis.setAxisSize();
  6555. //axisLength = horiz ? axisWidth : axisHeight;
  6556. isDirtyAxisLength = axis.len !== axis.oldAxisLength;
  6557. // is there new data?
  6558. each(axis.series, function (series) {
  6559. if (series.isDirtyData || series.isDirty ||
  6560. series.xAxis.isDirty) { // when x axis is dirty, we need new data extremes for y as well
  6561. isDirtyData = true;
  6562. }
  6563. });
  6564. // do we really need to go through all this?
  6565. if (isDirtyAxisLength || isDirtyData || axis.isLinked || axis.forceRedraw ||
  6566. axis.userMin !== axis.oldUserMin || axis.userMax !== axis.oldUserMax) {
  6567. if (axis.resetStacks) {
  6568. axis.resetStacks();
  6569. }
  6570. axis.forceRedraw = false;
  6571. // get data extremes if needed
  6572. axis.getSeriesExtremes();
  6573. // get fixed positions based on tickInterval
  6574. axis.setTickInterval();
  6575. // record old values to decide whether a rescale is necessary later on (#540)
  6576. axis.oldUserMin = axis.userMin;
  6577. axis.oldUserMax = axis.userMax;
  6578. // Mark as dirty if it is not already set to dirty and extremes have changed. #595.
  6579. if (!axis.isDirty) {
  6580. axis.isDirty = isDirtyAxisLength || axis.min !== axis.oldMin || axis.max !== axis.oldMax;
  6581. }
  6582. } else if (axis.cleanStacks) {
  6583. axis.cleanStacks();
  6584. }
  6585. },
  6586. /**
  6587. * Set the extremes and optionally redraw
  6588. * @param {Number} newMin
  6589. * @param {Number} newMax
  6590. * @param {Boolean} redraw
  6591. * @param {Boolean|Object} animation Whether to apply animation, and optionally animation
  6592. * configuration
  6593. * @param {Object} eventArguments
  6594. *
  6595. */
  6596. setExtremes: function (newMin, newMax, redraw, animation, eventArguments) {
  6597. var axis = this,
  6598. chart = axis.chart;
  6599. redraw = pick(redraw, true); // defaults to true
  6600. each(axis.series, function (serie) {
  6601. delete serie.kdTree;
  6602. });
  6603. // Extend the arguments with min and max
  6604. eventArguments = extend(eventArguments, {
  6605. min: newMin,
  6606. max: newMax
  6607. });
  6608. // Fire the event
  6609. fireEvent(axis, 'setExtremes', eventArguments, function () { // the default event handler
  6610. axis.userMin = newMin;
  6611. axis.userMax = newMax;
  6612. axis.eventArgs = eventArguments;
  6613. if (redraw) {
  6614. chart.redraw(animation);
  6615. }
  6616. });
  6617. },
  6618. /**
  6619. * Overridable method for zooming chart. Pulled out in a separate method to allow overriding
  6620. * in stock charts.
  6621. */
  6622. zoom: function (newMin, newMax) {
  6623. var dataMin = this.dataMin,
  6624. dataMax = this.dataMax,
  6625. options = this.options,
  6626. min = mathMin(dataMin, pick(options.min, dataMin)),
  6627. max = mathMax(dataMax, pick(options.max, dataMax));
  6628. // Prevent pinch zooming out of range. Check for defined is for #1946. #1734.
  6629. if (!this.allowZoomOutside) {
  6630. if (defined(dataMin) && newMin <= min) {
  6631. newMin = min;
  6632. }
  6633. if (defined(dataMax) && newMax >= max) {
  6634. newMax = max;
  6635. }
  6636. }
  6637. // In full view, displaying the reset zoom button is not required
  6638. this.displayBtn = newMin !== UNDEFINED || newMax !== UNDEFINED;
  6639. // Do it
  6640. this.setExtremes(
  6641. newMin,
  6642. newMax,
  6643. false,
  6644. UNDEFINED,
  6645. { trigger: 'zoom' }
  6646. );
  6647. return true;
  6648. },
  6649. /**
  6650. * Update the axis metrics
  6651. */
  6652. setAxisSize: function () {
  6653. var chart = this.chart,
  6654. options = this.options,
  6655. offsetLeft = options.offsetLeft || 0,
  6656. offsetRight = options.offsetRight || 0,
  6657. horiz = this.horiz,
  6658. width = pick(options.width, chart.plotWidth - offsetLeft + offsetRight),
  6659. height = pick(options.height, chart.plotHeight),
  6660. top = pick(options.top, chart.plotTop),
  6661. left = pick(options.left, chart.plotLeft + offsetLeft),
  6662. percentRegex = /%$/;
  6663. // Check for percentage based input values
  6664. if (percentRegex.test(height)) {
  6665. height = parseFloat(height) / 100 * chart.plotHeight;
  6666. }
  6667. if (percentRegex.test(top)) {
  6668. top = parseFloat(top) / 100 * chart.plotHeight + chart.plotTop;
  6669. }
  6670. // Expose basic values to use in Series object and navigator
  6671. this.left = left;
  6672. this.top = top;
  6673. this.width = width;
  6674. this.height = height;
  6675. this.bottom = chart.chartHeight - height - top;
  6676. this.right = chart.chartWidth - width - left;
  6677. // Direction agnostic properties
  6678. this.len = mathMax(horiz ? width : height, 0); // mathMax fixes #905
  6679. this.pos = horiz ? left : top; // distance from SVG origin
  6680. },
  6681. /**
  6682. * Get the actual axis extremes
  6683. */
  6684. getExtremes: function () {
  6685. var axis = this,
  6686. isLog = axis.isLog;
  6687. return {
  6688. min: isLog ? correctFloat(lin2log(axis.min)) : axis.min,
  6689. max: isLog ? correctFloat(lin2log(axis.max)) : axis.max,
  6690. dataMin: axis.dataMin,
  6691. dataMax: axis.dataMax,
  6692. userMin: axis.userMin,
  6693. userMax: axis.userMax
  6694. };
  6695. },
  6696. /**
  6697. * Get the zero plane either based on zero or on the min or max value.
  6698. * Used in bar and area plots
  6699. */
  6700. getThreshold: function (threshold) {
  6701. var axis = this,
  6702. isLog = axis.isLog,
  6703. realMin = isLog ? lin2log(axis.min) : axis.min,
  6704. realMax = isLog ? lin2log(axis.max) : axis.max;
  6705. // With a threshold of null, make the columns/areas rise from the top or bottom
  6706. // depending on the value, assuming an actual threshold of 0 (#4233).
  6707. if (threshold === null) {
  6708. threshold = realMax < 0 ? realMax : realMin;
  6709. } else if (realMin > threshold) {
  6710. threshold = realMin;
  6711. } else if (realMax < threshold) {
  6712. threshold = realMax;
  6713. }
  6714. return axis.translate(threshold, 0, 1, 0, 1);
  6715. },
  6716. /**
  6717. * Compute auto alignment for the axis label based on which side the axis is on
  6718. * and the given rotation for the label
  6719. */
  6720. autoLabelAlign: function (rotation) {
  6721. var ret,
  6722. angle = (pick(rotation, 0) - (this.side * 90) + 720) % 360;
  6723. if (angle > 15 && angle < 165) {
  6724. ret = 'right';
  6725. } else if (angle > 195 && angle < 345) {
  6726. ret = 'left';
  6727. } else {
  6728. ret = 'center';
  6729. }
  6730. return ret;
  6731. },
  6732. /**
  6733. * Prevent the ticks from getting so close we can't draw the labels. On a horizontal
  6734. * axis, this is handled by rotating the labels, removing ticks and adding ellipsis.
  6735. * On a vertical axis remove ticks and add ellipsis.
  6736. */
  6737. unsquish: function () {
  6738. var chart = this.chart,
  6739. ticks = this.ticks,
  6740. labelOptions = this.options.labels,
  6741. horiz = this.horiz,
  6742. tickInterval = this.tickInterval,
  6743. newTickInterval = tickInterval,
  6744. slotSize = this.len / (((this.categories ? 1 : 0) + this.max - this.min) / tickInterval),
  6745. rotation,
  6746. rotationOption = labelOptions.rotation,
  6747. labelMetrics = chart.renderer.fontMetrics(labelOptions.style.fontSize, ticks[0] && ticks[0].label),
  6748. step,
  6749. bestScore = Number.MAX_VALUE,
  6750. autoRotation,
  6751. // Return the multiple of tickInterval that is needed to avoid collision
  6752. getStep = function (spaceNeeded) {
  6753. var step = spaceNeeded / (slotSize || 1);
  6754. step = step > 1 ? mathCeil(step) : 1;
  6755. return step * tickInterval;
  6756. };
  6757. if (horiz) {
  6758. autoRotation = !labelOptions.staggerLines && !labelOptions.step && ( // #3971
  6759. defined(rotationOption) ?
  6760. [rotationOption] :
  6761. slotSize < pick(labelOptions.autoRotationLimit, 80) && labelOptions.autoRotation
  6762. );
  6763. if (autoRotation) {
  6764. // Loop over the given autoRotation options, and determine which gives the best score. The
  6765. // best score is that with the lowest number of steps and a rotation closest to horizontal.
  6766. each(autoRotation, function (rot) {
  6767. var score;
  6768. if (rot === rotationOption || (rot && rot >= -90 && rot <= 90)) { // #3891
  6769. step = getStep(mathAbs(labelMetrics.h / mathSin(deg2rad * rot)));
  6770. score = step + mathAbs(rot / 360);
  6771. if (score < bestScore) {
  6772. bestScore = score;
  6773. rotation = rot;
  6774. newTickInterval = step;
  6775. }
  6776. }
  6777. });
  6778. }
  6779. } else if (!labelOptions.step) { // #4411
  6780. newTickInterval = getStep(labelMetrics.h);
  6781. }
  6782. this.autoRotation = autoRotation;
  6783. this.labelRotation = pick(rotation, rotationOption);
  6784. return newTickInterval;
  6785. },
  6786. renderUnsquish: function () {
  6787. var chart = this.chart,
  6788. renderer = chart.renderer,
  6789. tickPositions = this.tickPositions,
  6790. ticks = this.ticks,
  6791. labelOptions = this.options.labels,
  6792. horiz = this.horiz,
  6793. margin = chart.margin,
  6794. slotCount = this.categories ? tickPositions.length : tickPositions.length - 1,
  6795. slotWidth = this.slotWidth = (horiz && !labelOptions.step && !labelOptions.rotation &&
  6796. ((this.staggerLines || 1) * chart.plotWidth) / slotCount) ||
  6797. (!horiz && ((margin[3] && (margin[3] - chart.spacing[3])) || chart.chartWidth * 0.33)), // #1580, #1931,
  6798. innerWidth = mathMax(1, mathRound(slotWidth - 2 * (labelOptions.padding || 5))),
  6799. attr = {},
  6800. labelMetrics = renderer.fontMetrics(labelOptions.style.fontSize, ticks[0] && ticks[0].label),
  6801. textOverflowOption = labelOptions.style.textOverflow,
  6802. css,
  6803. labelLength = 0,
  6804. label,
  6805. i,
  6806. pos;
  6807. // Set rotation option unless it is "auto", like in gauges
  6808. if (!isString(labelOptions.rotation)) {
  6809. attr.rotation = labelOptions.rotation || 0; // #4443
  6810. }
  6811. // Handle auto rotation on horizontal axis
  6812. if (this.autoRotation) {
  6813. // Get the longest label length
  6814. each(tickPositions, function (tick) {
  6815. tick = ticks[tick];
  6816. if (tick && tick.labelLength > labelLength) {
  6817. labelLength = tick.labelLength;
  6818. }
  6819. });
  6820. // Apply rotation only if the label is too wide for the slot, and
  6821. // the label is wider than its height.
  6822. if (labelLength > innerWidth && labelLength > labelMetrics.h) {
  6823. attr.rotation = this.labelRotation;
  6824. } else {
  6825. this.labelRotation = 0;
  6826. }
  6827. // Handle word-wrap or ellipsis on vertical axis
  6828. } else if (slotWidth) {
  6829. // For word-wrap or ellipsis
  6830. css = { width: innerWidth + PX };
  6831. if (!textOverflowOption) {
  6832. css.textOverflow = 'clip';
  6833. // On vertical axis, only allow word wrap if there is room for more lines.
  6834. i = tickPositions.length;
  6835. while (!horiz && i--) {
  6836. pos = tickPositions[i];
  6837. label = ticks[pos].label;
  6838. if (label) {
  6839. // Reset ellipsis in order to get the correct bounding box (#4070)
  6840. if (label.styles.textOverflow === 'ellipsis') {
  6841. label.css({ textOverflow: 'clip' });
  6842. }
  6843. if (label.getBBox().height > this.len / tickPositions.length - (labelMetrics.h - labelMetrics.f)) {
  6844. label.specCss = { textOverflow: 'ellipsis' };
  6845. }
  6846. }
  6847. }
  6848. }
  6849. }
  6850. // Add ellipsis if the label length is significantly longer than ideal
  6851. if (attr.rotation) {
  6852. css = {
  6853. width: (labelLength > chart.chartHeight * 0.5 ? chart.chartHeight * 0.33 : chart.chartHeight) + PX
  6854. };
  6855. if (!textOverflowOption) {
  6856. css.textOverflow = 'ellipsis';
  6857. }
  6858. }
  6859. // Set the explicit or automatic label alignment
  6860. this.labelAlign = attr.align = labelOptions.align || this.autoLabelAlign(this.labelRotation);
  6861. // Apply general and specific CSS
  6862. each(tickPositions, function (pos) {
  6863. var tick = ticks[pos],
  6864. label = tick && tick.label;
  6865. if (label) {
  6866. label.attr(attr); // This needs to go before the CSS in old IE (#4502)
  6867. if (css) {
  6868. label.css(merge(css, label.specCss));
  6869. }
  6870. delete label.specCss;
  6871. tick.rotation = attr.rotation;
  6872. }
  6873. });
  6874. // TODO: Why not part of getLabelPosition?
  6875. this.tickRotCorr = renderer.rotCorr(labelMetrics.b, this.labelRotation || 0, this.side === 2);
  6876. },
  6877. /**
  6878. * Return true if the axis has associated data
  6879. */
  6880. hasData: function () {
  6881. return this.hasVisibleSeries || (defined(this.min) && defined(this.max) && !!this.tickPositions);
  6882. },
  6883. /**
  6884. * Render the tick labels to a preliminary position to get their sizes
  6885. */
  6886. getOffset: function () {
  6887. var axis = this,
  6888. chart = axis.chart,
  6889. renderer = chart.renderer,
  6890. options = axis.options,
  6891. tickPositions = axis.tickPositions,
  6892. ticks = axis.ticks,
  6893. horiz = axis.horiz,
  6894. side = axis.side,
  6895. invertedSide = chart.inverted ? [1, 0, 3, 2][side] : side,
  6896. hasData,
  6897. showAxis,
  6898. titleOffset = 0,
  6899. titleOffsetOption,
  6900. titleMargin = 0,
  6901. axisTitleOptions = options.title,
  6902. labelOptions = options.labels,
  6903. labelOffset = 0, // reset
  6904. labelOffsetPadded,
  6905. axisOffset = chart.axisOffset,
  6906. clipOffset = chart.clipOffset,
  6907. clip,
  6908. directionFactor = [-1, 1, 1, -1][side],
  6909. n,
  6910. axisParent = axis.axisParent, // Used in color axis
  6911. lineHeightCorrection;
  6912. // For reuse in Axis.render
  6913. hasData = axis.hasData();
  6914. axis.showAxis = showAxis = hasData || pick(options.showEmpty, true);
  6915. // Set/reset staggerLines
  6916. axis.staggerLines = axis.horiz && labelOptions.staggerLines;
  6917. // Create the axisGroup and gridGroup elements on first iteration
  6918. if (!axis.axisGroup) {
  6919. axis.gridGroup = renderer.g('grid')
  6920. .attr({ zIndex: options.gridZIndex || 1 })
  6921. .add(axisParent);
  6922. axis.axisGroup = renderer.g('axis')
  6923. .attr({ zIndex: options.zIndex || 2 })
  6924. .add(axisParent);
  6925. axis.labelGroup = renderer.g('axis-labels')
  6926. .attr({ zIndex: labelOptions.zIndex || 7 })
  6927. .addClass(PREFIX + axis.coll.toLowerCase() + '-labels')
  6928. .add(axisParent);
  6929. }
  6930. if (hasData || axis.isLinked) {
  6931. // Generate ticks
  6932. each(tickPositions, function (pos) {
  6933. if (!ticks[pos]) {
  6934. ticks[pos] = new Tick(axis, pos);
  6935. } else {
  6936. ticks[pos].addLabel(); // update labels depending on tick interval
  6937. }
  6938. });
  6939. axis.renderUnsquish();
  6940. each(tickPositions, function (pos) {
  6941. // left side must be align: right and right side must have align: left for labels
  6942. if (side === 0 || side === 2 || { 1: 'left', 3: 'right' }[side] === axis.labelAlign) {
  6943. // get the highest offset
  6944. labelOffset = mathMax(
  6945. ticks[pos].getLabelSize(),
  6946. labelOffset
  6947. );
  6948. }
  6949. });
  6950. if (axis.staggerLines) {
  6951. labelOffset *= axis.staggerLines;
  6952. axis.labelOffset = labelOffset;
  6953. }
  6954. } else { // doesn't have data
  6955. for (n in ticks) {
  6956. ticks[n].destroy();
  6957. delete ticks[n];
  6958. }
  6959. }
  6960. if (axisTitleOptions && axisTitleOptions.text && axisTitleOptions.enabled !== false) {
  6961. if (!axis.axisTitle) {
  6962. axis.axisTitle = renderer.text(
  6963. axisTitleOptions.text,
  6964. 0,
  6965. 0,
  6966. axisTitleOptions.useHTML
  6967. )
  6968. .attr({
  6969. zIndex: 7,
  6970. rotation: axisTitleOptions.rotation || 0,
  6971. align:
  6972. axisTitleOptions.textAlign ||
  6973. { low: 'left', middle: 'center', high: 'right' }[axisTitleOptions.align]
  6974. })
  6975. .addClass(PREFIX + this.coll.toLowerCase() + '-title')
  6976. .css(axisTitleOptions.style)
  6977. .add(axis.axisGroup);
  6978. axis.axisTitle.isNew = true;
  6979. }
  6980. if (showAxis) {
  6981. titleOffset = axis.axisTitle.getBBox()[horiz ? 'height' : 'width'];
  6982. titleOffsetOption = axisTitleOptions.offset;
  6983. titleMargin = defined(titleOffsetOption) ? 0 : pick(axisTitleOptions.margin, horiz ? 5 : 10);
  6984. }
  6985. // hide or show the title depending on whether showEmpty is set
  6986. axis.axisTitle[showAxis ? 'show' : 'hide']();
  6987. }
  6988. // handle automatic or user set offset
  6989. axis.offset = directionFactor * pick(options.offset, axisOffset[side]);
  6990. axis.tickRotCorr = axis.tickRotCorr || { x: 0, y: 0 }; // polar
  6991. lineHeightCorrection = side === 2 ? axis.tickRotCorr.y : 0;
  6992. labelOffsetPadded = labelOffset + titleMargin +
  6993. (labelOffset && (directionFactor * (horiz ? pick(labelOptions.y, axis.tickRotCorr.y + 8) : labelOptions.x) - lineHeightCorrection));
  6994. axis.axisTitleMargin = pick(titleOffsetOption, labelOffsetPadded);
  6995. axisOffset[side] = mathMax(
  6996. axisOffset[side],
  6997. axis.axisTitleMargin + titleOffset + directionFactor * axis.offset,
  6998. labelOffsetPadded // #3027
  6999. );
  7000. // Decide the clipping needed to keep the graph inside the plot area and axis lines
  7001. clip = options.offset ? 0 : mathFloor(options.lineWidth / 2) * 2; // #4308, #4371
  7002. clipOffset[invertedSide] = mathMax(clipOffset[invertedSide], clip);
  7003. },
  7004. /**
  7005. * Get the path for the axis line
  7006. */
  7007. getLinePath: function (lineWidth) {
  7008. var chart = this.chart,
  7009. opposite = this.opposite,
  7010. offset = this.offset,
  7011. horiz = this.horiz,
  7012. lineLeft = this.left + (opposite ? this.width : 0) + offset,
  7013. lineTop = chart.chartHeight - this.bottom - (opposite ? this.height : 0) + offset;
  7014. if (opposite) {
  7015. lineWidth *= -1; // crispify the other way - #1480, #1687
  7016. }
  7017. return chart.renderer.crispLine([
  7018. M,
  7019. horiz ?
  7020. this.left :
  7021. lineLeft,
  7022. horiz ?
  7023. lineTop :
  7024. this.top,
  7025. L,
  7026. horiz ?
  7027. chart.chartWidth - this.right :
  7028. lineLeft,
  7029. horiz ?
  7030. lineTop :
  7031. chart.chartHeight - this.bottom
  7032. ], lineWidth);
  7033. },
  7034. /**
  7035. * Position the title
  7036. */
  7037. getTitlePosition: function () {
  7038. // compute anchor points for each of the title align options
  7039. var horiz = this.horiz,
  7040. axisLeft = this.left,
  7041. axisTop = this.top,
  7042. axisLength = this.len,
  7043. axisTitleOptions = this.options.title,
  7044. margin = horiz ? axisLeft : axisTop,
  7045. opposite = this.opposite,
  7046. offset = this.offset,
  7047. xOption = axisTitleOptions.x || 0,
  7048. yOption = axisTitleOptions.y || 0,
  7049. fontSize = pInt(axisTitleOptions.style.fontSize || 12),
  7050. // the position in the length direction of the axis
  7051. alongAxis = {
  7052. low: margin + (horiz ? 0 : axisLength),
  7053. middle: margin + axisLength / 2,
  7054. high: margin + (horiz ? axisLength : 0)
  7055. }[axisTitleOptions.align],
  7056. // the position in the perpendicular direction of the axis
  7057. offAxis = (horiz ? axisTop + this.height : axisLeft) +
  7058. (horiz ? 1 : -1) * // horizontal axis reverses the margin
  7059. (opposite ? -1 : 1) * // so does opposite axes
  7060. this.axisTitleMargin +
  7061. (this.side === 2 ? fontSize : 0);
  7062. return {
  7063. x: horiz ?
  7064. alongAxis + xOption :
  7065. offAxis + (opposite ? this.width : 0) + offset + xOption,
  7066. y: horiz ?
  7067. offAxis + yOption - (opposite ? this.height : 0) + offset :
  7068. alongAxis + yOption
  7069. };
  7070. },
  7071. /**
  7072. * Render the axis
  7073. */
  7074. render: function () {
  7075. var axis = this,
  7076. chart = axis.chart,
  7077. renderer = chart.renderer,
  7078. options = axis.options,
  7079. isLog = axis.isLog,
  7080. isLinked = axis.isLinked,
  7081. tickPositions = axis.tickPositions,
  7082. axisTitle = axis.axisTitle,
  7083. ticks = axis.ticks,
  7084. minorTicks = axis.minorTicks,
  7085. alternateBands = axis.alternateBands,
  7086. stackLabelOptions = options.stackLabels,
  7087. alternateGridColor = options.alternateGridColor,
  7088. tickmarkOffset = axis.tickmarkOffset,
  7089. lineWidth = options.lineWidth,
  7090. linePath,
  7091. hasRendered = chart.hasRendered,
  7092. slideInTicks = hasRendered && defined(axis.oldMin) && !isNaN(axis.oldMin),
  7093. showAxis = axis.showAxis,
  7094. globalAnimation = renderer.globalAnimation,
  7095. from,
  7096. to;
  7097. // Reset
  7098. axis.labelEdge.length = 0;
  7099. //axis.justifyToPlot = overflow === 'justify';
  7100. axis.overlap = false;
  7101. // Mark all elements inActive before we go over and mark the active ones
  7102. each([ticks, minorTicks, alternateBands], function (coll) {
  7103. var pos;
  7104. for (pos in coll) {
  7105. coll[pos].isActive = false;
  7106. }
  7107. });
  7108. // If the series has data draw the ticks. Else only the line and title
  7109. if (axis.hasData() || isLinked) {
  7110. // minor ticks
  7111. if (axis.minorTickInterval && !axis.categories) {
  7112. each(axis.getMinorTickPositions(), function (pos) {
  7113. if (!minorTicks[pos]) {
  7114. minorTicks[pos] = new Tick(axis, pos, 'minor');
  7115. }
  7116. // render new ticks in old position
  7117. if (slideInTicks && minorTicks[pos].isNew) {
  7118. minorTicks[pos].render(null, true);
  7119. }
  7120. minorTicks[pos].render(null, false, 1);
  7121. });
  7122. }
  7123. // Major ticks. Pull out the first item and render it last so that
  7124. // we can get the position of the neighbour label. #808.
  7125. if (tickPositions.length) { // #1300
  7126. each(tickPositions, function (pos, i) {
  7127. // linked axes need an extra check to find out if
  7128. if (!isLinked || (pos >= axis.min && pos <= axis.max)) {
  7129. if (!ticks[pos]) {
  7130. ticks[pos] = new Tick(axis, pos);
  7131. }
  7132. // render new ticks in old position
  7133. if (slideInTicks && ticks[pos].isNew) {
  7134. ticks[pos].render(i, true, 0.1);
  7135. }
  7136. ticks[pos].render(i);
  7137. }
  7138. });
  7139. // In a categorized axis, the tick marks are displayed between labels. So
  7140. // we need to add a tick mark and grid line at the left edge of the X axis.
  7141. if (tickmarkOffset && (axis.min === 0 || axis.single)) {
  7142. if (!ticks[-1]) {
  7143. ticks[-1] = new Tick(axis, -1, null, true);
  7144. }
  7145. ticks[-1].render(-1);
  7146. }
  7147. }
  7148. // alternate grid color
  7149. if (alternateGridColor) {
  7150. each(tickPositions, function (pos, i) {
  7151. to = tickPositions[i + 1] !== UNDEFINED ? tickPositions[i + 1] + tickmarkOffset : axis.max - tickmarkOffset;
  7152. if (i % 2 === 0 && pos < axis.max && to <= axis.max - tickmarkOffset) { // #2248
  7153. if (!alternateBands[pos]) {
  7154. alternateBands[pos] = new Highcharts.PlotLineOrBand(axis);
  7155. }
  7156. from = pos + tickmarkOffset; // #949
  7157. alternateBands[pos].options = {
  7158. from: isLog ? lin2log(from) : from,
  7159. to: isLog ? lin2log(to) : to,
  7160. color: alternateGridColor
  7161. };
  7162. alternateBands[pos].render();
  7163. alternateBands[pos].isActive = true;
  7164. }
  7165. });
  7166. }
  7167. // custom plot lines and bands
  7168. if (!axis._addedPlotLB) { // only first time
  7169. each((options.plotLines || []).concat(options.plotBands || []), function (plotLineOptions) {
  7170. axis.addPlotBandOrLine(plotLineOptions);
  7171. });
  7172. axis._addedPlotLB = true;
  7173. }
  7174. } // end if hasData
  7175. // Remove inactive ticks
  7176. each([ticks, minorTicks, alternateBands], function (coll) {
  7177. var pos,
  7178. i,
  7179. forDestruction = [],
  7180. delay = globalAnimation ? globalAnimation.duration || 500 : 0,
  7181. destroyInactiveItems = function () {
  7182. i = forDestruction.length;
  7183. while (i--) {
  7184. // When resizing rapidly, the same items may be destroyed in different timeouts,
  7185. // or the may be reactivated
  7186. if (coll[forDestruction[i]] && !coll[forDestruction[i]].isActive) {
  7187. coll[forDestruction[i]].destroy();
  7188. delete coll[forDestruction[i]];
  7189. }
  7190. }
  7191. };
  7192. for (pos in coll) {
  7193. if (!coll[pos].isActive) {
  7194. // Render to zero opacity
  7195. coll[pos].render(pos, false, 0);
  7196. coll[pos].isActive = false;
  7197. forDestruction.push(pos);
  7198. }
  7199. }
  7200. // When the objects are finished fading out, destroy them
  7201. if (coll === alternateBands || !chart.hasRendered || !delay) {
  7202. destroyInactiveItems();
  7203. } else if (delay) {
  7204. setTimeout(destroyInactiveItems, delay);
  7205. }
  7206. });
  7207. // Static items. As the axis group is cleared on subsequent calls
  7208. // to render, these items are added outside the group.
  7209. // axis line
  7210. if (lineWidth) {
  7211. linePath = axis.getLinePath(lineWidth);
  7212. if (!axis.axisLine) {
  7213. axis.axisLine = renderer.path(linePath)
  7214. .attr({
  7215. stroke: options.lineColor,
  7216. 'stroke-width': lineWidth,
  7217. zIndex: 7
  7218. })
  7219. .add(axis.axisGroup);
  7220. } else {
  7221. axis.axisLine.animate({ d: linePath });
  7222. }
  7223. // show or hide the line depending on options.showEmpty
  7224. axis.axisLine[showAxis ? 'show' : 'hide']();
  7225. }
  7226. if (axisTitle && showAxis) {
  7227. axisTitle[axisTitle.isNew ? 'attr' : 'animate'](
  7228. axis.getTitlePosition()
  7229. );
  7230. axisTitle.isNew = false;
  7231. }
  7232. // Stacked totals:
  7233. if (stackLabelOptions && stackLabelOptions.enabled) {
  7234. axis.renderStackTotals();
  7235. }
  7236. // End stacked totals
  7237. axis.isDirty = false;
  7238. },
  7239. /**
  7240. * Redraw the axis to reflect changes in the data or axis extremes
  7241. */
  7242. redraw: function () {
  7243. if (this.visible) {
  7244. // render the axis
  7245. this.render();
  7246. // move plot lines and bands
  7247. each(this.plotLinesAndBands, function (plotLine) {
  7248. plotLine.render();
  7249. });
  7250. }
  7251. // mark associated series as dirty and ready for redraw
  7252. each(this.series, function (series) {
  7253. series.isDirty = true;
  7254. });
  7255. },
  7256. /**
  7257. * Destroys an Axis instance.
  7258. */
  7259. destroy: function (keepEvents) {
  7260. var axis = this,
  7261. stacks = axis.stacks,
  7262. stackKey,
  7263. plotLinesAndBands = axis.plotLinesAndBands,
  7264. i;
  7265. // Remove the events
  7266. if (!keepEvents) {
  7267. removeEvent(axis);
  7268. }
  7269. // Destroy each stack total
  7270. for (stackKey in stacks) {
  7271. destroyObjectProperties(stacks[stackKey]);
  7272. stacks[stackKey] = null;
  7273. }
  7274. // Destroy collections
  7275. each([axis.ticks, axis.minorTicks, axis.alternateBands], function (coll) {
  7276. destroyObjectProperties(coll);
  7277. });
  7278. i = plotLinesAndBands.length;
  7279. while (i--) { // #1975
  7280. plotLinesAndBands[i].destroy();
  7281. }
  7282. // Destroy local variables
  7283. each(['stackTotalGroup', 'axisLine', 'axisTitle', 'axisGroup', 'cross', 'gridGroup', 'labelGroup'], function (prop) {
  7284. if (axis[prop]) {
  7285. axis[prop] = axis[prop].destroy();
  7286. }
  7287. });
  7288. // Destroy crosshair
  7289. if (this.cross) {
  7290. this.cross.destroy();
  7291. }
  7292. },
  7293. /**
  7294. * Draw the crosshair
  7295. */
  7296. drawCrosshair: function (e, point) { // docs: Missing docs for Axis.crosshair. Also for properties.
  7297. var path,
  7298. options = this.crosshair,
  7299. animation = options.animation,
  7300. pos,
  7301. attribs,
  7302. categorized;
  7303. if (
  7304. // Disabled in options
  7305. !this.crosshair ||
  7306. // Snap
  7307. ((defined(point) || !pick(this.crosshair.snap, true)) === false) ||
  7308. // Not on this axis (#4095, #2888)
  7309. (point && point.series && point.series[this.coll] !== this)
  7310. ) {
  7311. this.hideCrosshair();
  7312. } else {
  7313. // Get the path
  7314. if (!pick(options.snap, true)) {
  7315. pos = (this.horiz ? e.chartX - this.pos : this.len - e.chartY + this.pos);
  7316. } else if (defined(point)) {
  7317. /*jslint eqeq: true*/
  7318. pos = this.isXAxis ? point.plotX : this.len - point.plotY; // #3834
  7319. /*jslint eqeq: false*/
  7320. }
  7321. if (this.isRadial) {
  7322. path = this.getPlotLinePath(this.isXAxis ? point.x : pick(point.stackY, point.y)) || null; // #3189
  7323. } else {
  7324. path = this.getPlotLinePath(null, null, null, null, pos) || null; // #3189
  7325. }
  7326. if (path === null) {
  7327. this.hideCrosshair();
  7328. return;
  7329. }
  7330. // Draw the cross
  7331. if (this.cross) {
  7332. this.cross
  7333. .attr({ visibility: VISIBLE })[animation ? 'animate' : 'attr']({ d: path }, animation);
  7334. } else {
  7335. categorized = this.categories && !this.isRadial;
  7336. attribs = {
  7337. 'stroke-width': options.width || (categorized ? this.transA : 1),
  7338. stroke: options.color || (categorized ? 'rgba(155,200,255,0.2)' : '#C0C0C0'),
  7339. zIndex: options.zIndex || 2
  7340. };
  7341. if (options.dashStyle) {
  7342. attribs.dashstyle = options.dashStyle;
  7343. }
  7344. this.cross = this.chart.renderer.path(path).attr(attribs).add();
  7345. }
  7346. }
  7347. },
  7348. /**
  7349. * Hide the crosshair.
  7350. */
  7351. hideCrosshair: function () {
  7352. if (this.cross) {
  7353. this.cross.hide();
  7354. }
  7355. }
  7356. }; // end Axis
  7357. extend(Axis.prototype, AxisPlotLineOrBandExtension);
  7358. /**
  7359. * Methods defined on the Axis prototype
  7360. */
  7361. /**
  7362. * Set the tick positions of a logarithmic axis
  7363. */
  7364. Axis.prototype.getLogTickPositions = function (interval, min, max, minor) {
  7365. var axis = this,
  7366. options = axis.options,
  7367. axisLength = axis.len,
  7368. // Since we use this method for both major and minor ticks,
  7369. // use a local variable and return the result
  7370. positions = [];
  7371. // Reset
  7372. if (!minor) {
  7373. axis._minorAutoInterval = null;
  7374. }
  7375. // First case: All ticks fall on whole logarithms: 1, 10, 100 etc.
  7376. if (interval >= 0.5) {
  7377. interval = mathRound(interval);
  7378. positions = axis.getLinearTickPositions(interval, min, max);
  7379. // Second case: We need intermediary ticks. For example
  7380. // 1, 2, 4, 6, 8, 10, 20, 40 etc.
  7381. } else if (interval >= 0.08) {
  7382. var roundedMin = mathFloor(min),
  7383. intermediate,
  7384. i,
  7385. j,
  7386. len,
  7387. pos,
  7388. lastPos,
  7389. break2;
  7390. if (interval > 0.3) {
  7391. intermediate = [1, 2, 4];
  7392. } else if (interval > 0.15) { // 0.2 equals five minor ticks per 1, 10, 100 etc
  7393. intermediate = [1, 2, 4, 6, 8];
  7394. } else { // 0.1 equals ten minor ticks per 1, 10, 100 etc
  7395. intermediate = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  7396. }
  7397. for (i = roundedMin; i < max + 1 && !break2; i++) {
  7398. len = intermediate.length;
  7399. for (j = 0; j < len && !break2; j++) {
  7400. pos = log2lin(lin2log(i) * intermediate[j]);
  7401. if (pos > min && (!minor || lastPos <= max) && lastPos !== UNDEFINED) { // #1670, lastPos is #3113
  7402. positions.push(lastPos);
  7403. }
  7404. if (lastPos > max) {
  7405. break2 = true;
  7406. }
  7407. lastPos = pos;
  7408. }
  7409. }
  7410. // Third case: We are so deep in between whole logarithmic values that
  7411. // we might as well handle the tick positions like a linear axis. For
  7412. // example 1.01, 1.02, 1.03, 1.04.
  7413. } else {
  7414. var realMin = lin2log(min),
  7415. realMax = lin2log(max),
  7416. tickIntervalOption = options[minor ? 'minorTickInterval' : 'tickInterval'],
  7417. filteredTickIntervalOption = tickIntervalOption === 'auto' ? null : tickIntervalOption,
  7418. tickPixelIntervalOption = options.tickPixelInterval / (minor ? 5 : 1),
  7419. totalPixelLength = minor ? axisLength / axis.tickPositions.length : axisLength;
  7420. interval = pick(
  7421. filteredTickIntervalOption,
  7422. axis._minorAutoInterval,
  7423. (realMax - realMin) * tickPixelIntervalOption / (totalPixelLength || 1)
  7424. );
  7425. interval = normalizeTickInterval(
  7426. interval,
  7427. null,
  7428. getMagnitude(interval)
  7429. );
  7430. positions = map(axis.getLinearTickPositions(
  7431. interval,
  7432. realMin,
  7433. realMax
  7434. ), log2lin);
  7435. if (!minor) {
  7436. axis._minorAutoInterval = interval / 5;
  7437. }
  7438. }
  7439. // Set the axis-level tickInterval variable
  7440. if (!minor) {
  7441. axis.tickInterval = interval;
  7442. }
  7443. return positions;
  7444. };/**
  7445. * The tooltip object
  7446. * @param {Object} chart The chart instance
  7447. * @param {Object} options Tooltip options
  7448. */
  7449. var Tooltip = Highcharts.Tooltip = function () {
  7450. this.init.apply(this, arguments);
  7451. };
  7452. Tooltip.prototype = {
  7453. init: function (chart, options) {
  7454. var borderWidth = options.borderWidth,
  7455. style = options.style,
  7456. padding = pInt(style.padding);
  7457. // Save the chart and options
  7458. this.chart = chart;
  7459. this.options = options;
  7460. // Keep track of the current series
  7461. //this.currentSeries = UNDEFINED;
  7462. // List of crosshairs
  7463. this.crosshairs = [];
  7464. // Current values of x and y when animating
  7465. this.now = { x: 0, y: 0 };
  7466. // The tooltip is initially hidden
  7467. this.isHidden = true;
  7468. // create the label
  7469. this.label = chart.renderer.label('', 0, 0, options.shape || 'callout', null, null, options.useHTML, null, 'tooltip')
  7470. .attr({
  7471. padding: padding,
  7472. fill: options.backgroundColor,
  7473. 'stroke-width': borderWidth,
  7474. r: options.borderRadius,
  7475. zIndex: 8
  7476. })
  7477. .css(style)
  7478. .css({ padding: 0 }) // Remove it from VML, the padding is applied as an attribute instead (#1117)
  7479. .add()
  7480. .attr({ y: -9999 }); // #2301, #2657
  7481. // When using canVG the shadow shows up as a gray circle
  7482. // even if the tooltip is hidden.
  7483. if (!useCanVG) {
  7484. this.label.shadow(options.shadow);
  7485. }
  7486. // Public property for getting the shared state.
  7487. this.shared = options.shared;
  7488. },
  7489. /**
  7490. * Destroy the tooltip and its elements.
  7491. */
  7492. destroy: function () {
  7493. // Destroy and clear local variables
  7494. if (this.label) {
  7495. this.label = this.label.destroy();
  7496. }
  7497. clearTimeout(this.hideTimer);
  7498. clearTimeout(this.tooltipTimeout);
  7499. },
  7500. /**
  7501. * Provide a soft movement for the tooltip
  7502. *
  7503. * @param {Number} x
  7504. * @param {Number} y
  7505. * @private
  7506. */
  7507. move: function (x, y, anchorX, anchorY) {
  7508. var tooltip = this,
  7509. now = tooltip.now,
  7510. animate = tooltip.options.animation !== false && !tooltip.isHidden &&
  7511. // When we get close to the target position, abort animation and land on the right place (#3056)
  7512. (mathAbs(x - now.x) > 1 || mathAbs(y - now.y) > 1),
  7513. skipAnchor = tooltip.followPointer || tooltip.len > 1;
  7514. // Get intermediate values for animation
  7515. extend(now, {
  7516. x: animate ? (2 * now.x + x) / 3 : x,
  7517. y: animate ? (now.y + y) / 2 : y,
  7518. anchorX: skipAnchor ? UNDEFINED : animate ? (2 * now.anchorX + anchorX) / 3 : anchorX,
  7519. anchorY: skipAnchor ? UNDEFINED : animate ? (now.anchorY + anchorY) / 2 : anchorY
  7520. });
  7521. // Move to the intermediate value
  7522. tooltip.label.attr(now);
  7523. // Run on next tick of the mouse tracker
  7524. if (animate) {
  7525. // Never allow two timeouts
  7526. clearTimeout(this.tooltipTimeout);
  7527. // Set the fixed interval ticking for the smooth tooltip
  7528. this.tooltipTimeout = setTimeout(function () {
  7529. // The interval function may still be running during destroy, so check that the chart is really there before calling.
  7530. if (tooltip) {
  7531. tooltip.move(x, y, anchorX, anchorY);
  7532. }
  7533. }, 32);
  7534. }
  7535. },
  7536. /**
  7537. * Hide the tooltip
  7538. */
  7539. hide: function (delay) {
  7540. var tooltip = this,
  7541. hoverPoints;
  7542. clearTimeout(this.hideTimer); // disallow duplicate timers (#1728, #1766)
  7543. if (!this.isHidden) {
  7544. hoverPoints = this.chart.hoverPoints;
  7545. this.hideTimer = setTimeout(function () {
  7546. tooltip.label.fadeOut();
  7547. tooltip.isHidden = true;
  7548. }, pick(delay, this.options.hideDelay, 500));
  7549. }
  7550. },
  7551. /**
  7552. * Extendable method to get the anchor position of the tooltip
  7553. * from a point or set of points
  7554. */
  7555. getAnchor: function (points, mouseEvent) {
  7556. var ret,
  7557. chart = this.chart,
  7558. inverted = chart.inverted,
  7559. plotTop = chart.plotTop,
  7560. plotLeft = chart.plotLeft,
  7561. plotX = 0,
  7562. plotY = 0,
  7563. yAxis,
  7564. xAxis;
  7565. points = splat(points);
  7566. // Pie uses a special tooltipPos
  7567. ret = points[0].tooltipPos;
  7568. // When tooltip follows mouse, relate the position to the mouse
  7569. if (this.followPointer && mouseEvent) {
  7570. if (mouseEvent.chartX === UNDEFINED) {
  7571. mouseEvent = chart.pointer.normalize(mouseEvent);
  7572. }
  7573. ret = [
  7574. mouseEvent.chartX - chart.plotLeft,
  7575. mouseEvent.chartY - plotTop
  7576. ];
  7577. }
  7578. // When shared, use the average position
  7579. if (!ret) {
  7580. each(points, function (point) {
  7581. yAxis = point.series.yAxis;
  7582. xAxis = point.series.xAxis;
  7583. plotX += point.plotX + (!inverted && xAxis ? xAxis.left - plotLeft : 0);
  7584. plotY += (point.plotLow ? (point.plotLow + point.plotHigh) / 2 : point.plotY) +
  7585. (!inverted && yAxis ? yAxis.top - plotTop : 0); // #1151
  7586. });
  7587. plotX /= points.length;
  7588. plotY /= points.length;
  7589. ret = [
  7590. inverted ? chart.plotWidth - plotY : plotX,
  7591. this.shared && !inverted && points.length > 1 && mouseEvent ?
  7592. mouseEvent.chartY - plotTop : // place shared tooltip next to the mouse (#424)
  7593. inverted ? chart.plotHeight - plotX : plotY
  7594. ];
  7595. }
  7596. return map(ret, mathRound);
  7597. },
  7598. /**
  7599. * Place the tooltip in a chart without spilling over
  7600. * and not covering the point it self.
  7601. */
  7602. getPosition: function (boxWidth, boxHeight, point) {
  7603. var chart = this.chart,
  7604. distance = this.distance,
  7605. ret = {},
  7606. h = point.h || 0, // #4117
  7607. swapped,
  7608. first = ['y', chart.chartHeight, boxHeight, point.plotY + chart.plotTop, chart.plotTop, chart.plotTop + chart.plotHeight],
  7609. second = ['x', chart.chartWidth, boxWidth, point.plotX + chart.plotLeft, chart.plotLeft, chart.plotLeft + chart.plotWidth],
  7610. // The far side is right or bottom
  7611. preferFarSide = pick(point.ttBelow, (chart.inverted && !point.negative) || (!chart.inverted && point.negative)),
  7612. /**
  7613. * Handle the preferred dimension. When the preferred dimension is tooltip
  7614. * on top or bottom of the point, it will look for space there.
  7615. */
  7616. firstDimension = function (dim, outerSize, innerSize, point, min, max) {
  7617. var roomLeft = innerSize < point - distance,
  7618. roomRight = point + distance + innerSize < outerSize,
  7619. alignedLeft = point - distance - innerSize,
  7620. alignedRight = point + distance;
  7621. if (preferFarSide && roomRight) {
  7622. ret[dim] = alignedRight;
  7623. } else if (!preferFarSide && roomLeft) {
  7624. ret[dim] = alignedLeft;
  7625. } else if (roomLeft) {
  7626. ret[dim] = mathMin(max - innerSize, alignedLeft - h < 0 ? alignedLeft : alignedLeft - h);
  7627. } else if (roomRight) {
  7628. ret[dim] = mathMax(min, alignedRight + h + innerSize > outerSize ? alignedRight : alignedRight + h);
  7629. } else {
  7630. return false;
  7631. }
  7632. },
  7633. /**
  7634. * Handle the secondary dimension. If the preferred dimension is tooltip
  7635. * on top or bottom of the point, the second dimension is to align the tooltip
  7636. * above the point, trying to align center but allowing left or right
  7637. * align within the chart box.
  7638. */
  7639. secondDimension = function (dim, outerSize, innerSize, point) {
  7640. // Too close to the edge, return false and swap dimensions
  7641. if (point < distance || point > outerSize - distance) {
  7642. return false;
  7643. // Align left/top
  7644. } else if (point < innerSize / 2) {
  7645. ret[dim] = 1;
  7646. // Align right/bottom
  7647. } else if (point > outerSize - innerSize / 2) {
  7648. ret[dim] = outerSize - innerSize - 2;
  7649. // Align center
  7650. } else {
  7651. ret[dim] = point - innerSize / 2;
  7652. }
  7653. },
  7654. /**
  7655. * Swap the dimensions
  7656. */
  7657. swap = function (count) {
  7658. var temp = first;
  7659. first = second;
  7660. second = temp;
  7661. swapped = count;
  7662. },
  7663. run = function () {
  7664. if (firstDimension.apply(0, first) !== false) {
  7665. if (secondDimension.apply(0, second) === false && !swapped) {
  7666. swap(true);
  7667. run();
  7668. }
  7669. } else if (!swapped) {
  7670. swap(true);
  7671. run();
  7672. } else {
  7673. ret.x = ret.y = 0;
  7674. }
  7675. };
  7676. // Under these conditions, prefer the tooltip on the side of the point
  7677. if (chart.inverted || this.len > 1) {
  7678. swap();
  7679. }
  7680. run();
  7681. return ret;
  7682. },
  7683. /**
  7684. * In case no user defined formatter is given, this will be used. Note that the context
  7685. * here is an object holding point, series, x, y etc.
  7686. */
  7687. defaultFormatter: function (tooltip) {
  7688. var items = this.points || splat(this),
  7689. s;
  7690. // build the header
  7691. s = [tooltip.tooltipFooterHeaderFormatter(items[0])]; //#3397: abstraction to enable formatting of footer and header
  7692. // build the values
  7693. s = s.concat(tooltip.bodyFormatter(items));
  7694. // footer
  7695. s.push(tooltip.tooltipFooterHeaderFormatter(items[0], true)); //#3397: abstraction to enable formatting of footer and header
  7696. return s.join('');
  7697. },
  7698. /**
  7699. * Refresh the tooltip's text and position.
  7700. * @param {Object} point
  7701. */
  7702. refresh: function (point, mouseEvent) {
  7703. var tooltip = this,
  7704. chart = tooltip.chart,
  7705. label = tooltip.label,
  7706. options = tooltip.options,
  7707. x,
  7708. y,
  7709. anchor,
  7710. textConfig = {},
  7711. text,
  7712. pointConfig = [],
  7713. formatter = options.formatter || tooltip.defaultFormatter,
  7714. hoverPoints = chart.hoverPoints,
  7715. borderColor,
  7716. shared = tooltip.shared,
  7717. currentSeries;
  7718. clearTimeout(this.hideTimer);
  7719. // get the reference point coordinates (pie charts use tooltipPos)
  7720. tooltip.followPointer = splat(point)[0].series.tooltipOptions.followPointer;
  7721. anchor = tooltip.getAnchor(point, mouseEvent);
  7722. x = anchor[0];
  7723. y = anchor[1];
  7724. // shared tooltip, array is sent over
  7725. if (shared && !(point.series && point.series.noSharedTooltip)) {
  7726. // hide previous hoverPoints and set new
  7727. chart.hoverPoints = point;
  7728. if (hoverPoints) {
  7729. each(hoverPoints, function (point) {
  7730. point.setState();
  7731. });
  7732. }
  7733. each(point, function (item) {
  7734. item.setState(HOVER_STATE);
  7735. pointConfig.push(item.getLabelConfig());
  7736. });
  7737. textConfig = {
  7738. x: point[0].category,
  7739. y: point[0].y
  7740. };
  7741. textConfig.points = pointConfig;
  7742. this.len = pointConfig.length;
  7743. point = point[0];
  7744. // single point tooltip
  7745. } else {
  7746. textConfig = point.getLabelConfig();
  7747. }
  7748. text = formatter.call(textConfig, tooltip);
  7749. // register the current series
  7750. currentSeries = point.series;
  7751. this.distance = pick(currentSeries.tooltipOptions.distance, 16);
  7752. // update the inner HTML
  7753. if (text === false) {
  7754. this.hide();
  7755. } else {
  7756. // show it
  7757. if (tooltip.isHidden) {
  7758. stop(label);
  7759. label.attr('opacity', 1).show();
  7760. }
  7761. // update text
  7762. label.attr({
  7763. text: text
  7764. });
  7765. // set the stroke color of the box
  7766. borderColor = options.borderColor || point.color || currentSeries.color || '#606060';
  7767. label.attr({
  7768. stroke: borderColor
  7769. });
  7770. tooltip.updatePosition({
  7771. plotX: x,
  7772. plotY: y,
  7773. negative: point.negative,
  7774. ttBelow: point.ttBelow,
  7775. h: anchor[2] || 0
  7776. });
  7777. this.isHidden = false;
  7778. }
  7779. fireEvent(chart, 'tooltipRefresh', {
  7780. text: text,
  7781. x: x + chart.plotLeft,
  7782. y: y + chart.plotTop,
  7783. borderColor: borderColor
  7784. });
  7785. },
  7786. /**
  7787. * Find the new position and perform the move
  7788. */
  7789. updatePosition: function (point) {
  7790. var chart = this.chart,
  7791. label = this.label,
  7792. pos = (this.options.positioner || this.getPosition).call(
  7793. this,
  7794. label.width,
  7795. label.height,
  7796. point
  7797. );
  7798. // do the move
  7799. this.move(
  7800. mathRound(pos.x),
  7801. mathRound(pos.y || 0), // can be undefined (#3977)
  7802. point.plotX + chart.plotLeft,
  7803. point.plotY + chart.plotTop
  7804. );
  7805. },
  7806. /**
  7807. * Get the best X date format based on the closest point range on the axis.
  7808. */
  7809. getXDateFormat: function (point, options, xAxis) {
  7810. var xDateFormat,
  7811. dateTimeLabelFormats = options.dateTimeLabelFormats,
  7812. closestPointRange = xAxis && xAxis.closestPointRange,
  7813. n,
  7814. blank = '01-01 00:00:00.000',
  7815. strpos = {
  7816. millisecond: 15,
  7817. second: 12,
  7818. minute: 9,
  7819. hour: 6,
  7820. day: 3
  7821. },
  7822. date,
  7823. lastN = 'millisecond'; // for sub-millisecond data, #4223
  7824. if (closestPointRange) {
  7825. date = dateFormat('%m-%d %H:%M:%S.%L', point.x);
  7826. for (n in timeUnits) {
  7827. // If the range is exactly one week and we're looking at a Sunday/Monday, go for the week format
  7828. if (closestPointRange === timeUnits.week && +dateFormat('%w', point.x) === xAxis.options.startOfWeek &&
  7829. date.substr(6) === blank.substr(6)) {
  7830. n = 'week';
  7831. break;
  7832. // The first format that is too great for the range
  7833. } else if (timeUnits[n] > closestPointRange) {
  7834. n = lastN;
  7835. break;
  7836. // If the point is placed every day at 23:59, we need to show
  7837. // the minutes as well. #2637.
  7838. } else if (strpos[n] && date.substr(strpos[n]) !== blank.substr(strpos[n])) {
  7839. break;
  7840. }
  7841. // Weeks are outside the hierarchy, only apply them on Mondays/Sundays like in the first condition
  7842. if (n !== 'week') {
  7843. lastN = n;
  7844. }
  7845. }
  7846. if (n) {
  7847. xDateFormat = dateTimeLabelFormats[n];
  7848. }
  7849. } else {
  7850. xDateFormat = dateTimeLabelFormats.day;
  7851. }
  7852. return xDateFormat || dateTimeLabelFormats.year; // #2546, 2581
  7853. },
  7854. /**
  7855. * Format the footer/header of the tooltip
  7856. * #3397: abstraction to enable formatting of footer and header
  7857. */
  7858. tooltipFooterHeaderFormatter: function (point, isFooter) {
  7859. var footOrHead = isFooter ? 'footer' : 'header',
  7860. series = point.series,
  7861. tooltipOptions = series.tooltipOptions,
  7862. xDateFormat = tooltipOptions.xDateFormat,
  7863. xAxis = series.xAxis,
  7864. isDateTime = xAxis && xAxis.options.type === 'datetime' && isNumber(point.key),
  7865. formatString = tooltipOptions[footOrHead+'Format'];
  7866. // Guess the best date format based on the closest point distance (#568, #3418)
  7867. if (isDateTime && !xDateFormat) {
  7868. xDateFormat = this.getXDateFormat(point, tooltipOptions, xAxis);
  7869. }
  7870. // Insert the footer date format if any
  7871. if (isDateTime && xDateFormat) {
  7872. formatString = formatString.replace('{point.key}', '{point.key:' + xDateFormat + '}');
  7873. }
  7874. return format(formatString, {
  7875. point: point,
  7876. series: series
  7877. });
  7878. },
  7879. /**
  7880. * Build the body (lines) of the tooltip by iterating over the items and returning one entry for each item,
  7881. * abstracting this functionality allows to easily overwrite and extend it.
  7882. */
  7883. bodyFormatter: function (items) {
  7884. return map(items, function (item) {
  7885. var tooltipOptions = item.series.tooltipOptions;
  7886. return (tooltipOptions.pointFormatter || item.point.tooltipFormatter).call(item.point, tooltipOptions.pointFormat);
  7887. });
  7888. }
  7889. };
  7890. var hoverChartIndex;
  7891. // Global flag for touch support
  7892. hasTouch = doc.documentElement.ontouchstart !== UNDEFINED;
  7893. /**
  7894. * The mouse tracker object. All methods starting with "on" are primary DOM event handlers.
  7895. * Subsequent methods should be named differently from what they are doing.
  7896. * @param {Object} chart The Chart instance
  7897. * @param {Object} options The root options object
  7898. */
  7899. var Pointer = Highcharts.Pointer = function (chart, options) {
  7900. this.init(chart, options);
  7901. };
  7902. Pointer.prototype = {
  7903. /**
  7904. * Initialize Pointer
  7905. */
  7906. init: function (chart, options) {
  7907. var chartOptions = options.chart,
  7908. chartEvents = chartOptions.events,
  7909. zoomType = useCanVG ? '' : chartOptions.zoomType,
  7910. inverted = chart.inverted,
  7911. zoomX,
  7912. zoomY;
  7913. // Store references
  7914. this.options = options;
  7915. this.chart = chart;
  7916. // Zoom status
  7917. this.zoomX = zoomX = /x/.test(zoomType);
  7918. this.zoomY = zoomY = /y/.test(zoomType);
  7919. this.zoomHor = (zoomX && !inverted) || (zoomY && inverted);
  7920. this.zoomVert = (zoomY && !inverted) || (zoomX && inverted);
  7921. this.hasZoom = zoomX || zoomY;
  7922. // Do we need to handle click on a touch device?
  7923. this.runChartClick = chartEvents && !!chartEvents.click;
  7924. this.pinchDown = [];
  7925. this.lastValidTouch = {};
  7926. if (Highcharts.Tooltip && options.tooltip.enabled) {
  7927. chart.tooltip = new Tooltip(chart, options.tooltip);
  7928. this.followTouchMove = pick(options.tooltip.followTouchMove, true);
  7929. }
  7930. this.setDOMEvents();
  7931. },
  7932. /**
  7933. * Add crossbrowser support for chartX and chartY
  7934. * @param {Object} e The event object in standard browsers
  7935. */
  7936. normalize: function (e, chartPosition) {
  7937. var chartX,
  7938. chartY,
  7939. ePos;
  7940. // common IE normalizing
  7941. e = e || window.event;
  7942. // Framework specific normalizing (#1165)
  7943. e = washMouseEvent(e);
  7944. // More IE normalizing, needs to go after washMouseEvent
  7945. if (!e.target) {
  7946. e.target = e.srcElement;
  7947. }
  7948. // iOS (#2757)
  7949. ePos = e.touches ? (e.touches.length ? e.touches.item(0) : e.changedTouches[0]) : e;
  7950. // Get mouse position
  7951. if (!chartPosition) {
  7952. this.chartPosition = chartPosition = offset(this.chart.container);
  7953. }
  7954. // chartX and chartY
  7955. if (ePos.pageX === UNDEFINED) { // IE < 9. #886.
  7956. chartX = mathMax(e.x, e.clientX - chartPosition.left); // #2005, #2129: the second case is
  7957. // for IE10 quirks mode within framesets
  7958. chartY = e.y;
  7959. } else {
  7960. chartX = ePos.pageX - chartPosition.left;
  7961. chartY = ePos.pageY - chartPosition.top;
  7962. }
  7963. return extend(e, {
  7964. chartX: mathRound(chartX),
  7965. chartY: mathRound(chartY)
  7966. });
  7967. },
  7968. /**
  7969. * Get the click position in terms of axis values.
  7970. *
  7971. * @param {Object} e A pointer event
  7972. */
  7973. getCoordinates: function (e) {
  7974. var coordinates = {
  7975. xAxis: [],
  7976. yAxis: []
  7977. };
  7978. each(this.chart.axes, function (axis) {
  7979. coordinates[axis.isXAxis ? 'xAxis' : 'yAxis'].push({
  7980. axis: axis,
  7981. value: axis.toValue(e[axis.horiz ? 'chartX' : 'chartY'])
  7982. });
  7983. });
  7984. return coordinates;
  7985. },
  7986. /**
  7987. * With line type charts with a single tracker, get the point closest to the mouse.
  7988. * Run Point.onMouseOver and display tooltip for the point or points.
  7989. */
  7990. runPointActions: function (e) {
  7991. var pointer = this,
  7992. chart = pointer.chart,
  7993. series = chart.series,
  7994. tooltip = chart.tooltip,
  7995. shared = tooltip ? tooltip.shared : false,
  7996. followPointer,
  7997. hoverPoint = chart.hoverPoint,
  7998. hoverSeries = chart.hoverSeries,
  7999. i,
  8000. distance = Number.MAX_VALUE, // #4511
  8001. anchor,
  8002. noSharedTooltip,
  8003. stickToHoverSeries,
  8004. directTouch,
  8005. kdpoints = [],
  8006. kdpoint,
  8007. kdpointT;
  8008. // For hovering over the empty parts of the plot area (hoverSeries is undefined).
  8009. // If there is one series with point tracking (combo chart), don't go to nearest neighbour.
  8010. if (!shared && !hoverSeries) {
  8011. for (i = 0; i < series.length; i++) {
  8012. if (series[i].directTouch || !series[i].options.stickyTracking) {
  8013. series = [];
  8014. }
  8015. }
  8016. }
  8017. // If it has a hoverPoint and that series requires direct touch (like columns, #3899), or we're on
  8018. // a noSharedTooltip series among shared tooltip series (#4546), use the hoverPoint . Otherwise,
  8019. // search the k-d tree.
  8020. stickToHoverSeries = hoverSeries && (shared ? hoverSeries.noSharedTooltip : hoverSeries.directTouch);
  8021. if (stickToHoverSeries && hoverPoint) {
  8022. kdpoint = hoverPoint;
  8023. // Handle shared tooltip or cases where a series is not yet hovered
  8024. } else {
  8025. // Find nearest points on all series
  8026. each(series, function (s) {
  8027. // Skip hidden series
  8028. noSharedTooltip = s.noSharedTooltip && shared;
  8029. directTouch = !shared && s.directTouch;
  8030. if (s.visible && !noSharedTooltip && !directTouch && pick(s.options.enableMouseTracking, true)) { // #3821
  8031. kdpointT = s.searchPoint(e, !noSharedTooltip && s.kdDimensions === 1); // #3828
  8032. if (kdpointT) {
  8033. kdpoints.push(kdpointT);
  8034. }
  8035. }
  8036. });
  8037. // Find absolute nearest point
  8038. each(kdpoints, function (p) {
  8039. if (p && typeof p.dist === 'number' && p.dist < distance) {
  8040. distance = p.dist;
  8041. kdpoint = p;
  8042. }
  8043. });
  8044. }
  8045. // Refresh tooltip for kdpoint if new hover point or tooltip was hidden // #3926, #4200
  8046. if (kdpoint && (kdpoint !== this.prevKDPoint || (tooltip && tooltip.isHidden))) {
  8047. // Draw tooltip if necessary
  8048. if (shared && !kdpoint.series.noSharedTooltip) {
  8049. i = kdpoints.length;
  8050. while (i--) {
  8051. if (kdpoints[i].clientX !== kdpoint.clientX || kdpoints[i].series.noSharedTooltip) {
  8052. kdpoints.splice(i, 1);
  8053. }
  8054. }
  8055. if (kdpoints.length && tooltip) {
  8056. tooltip.refresh(kdpoints, e);
  8057. }
  8058. // Do mouseover on all points (#3919, #3985, #4410)
  8059. each(kdpoints, function (point) {
  8060. point.onMouseOver(e, point !== ((hoverSeries && hoverSeries.directTouch && hoverPoint) || kdpoint));
  8061. });
  8062. } else {
  8063. if (tooltip) {
  8064. tooltip.refresh(kdpoint, e);
  8065. }
  8066. if(!hoverSeries || !hoverSeries.directTouch) { // #4448
  8067. kdpoint.onMouseOver(e);
  8068. }
  8069. }
  8070. this.prevKDPoint = kdpoint;
  8071. // Update positions (regardless of kdpoint or hoverPoint)
  8072. } else {
  8073. followPointer = hoverSeries && hoverSeries.tooltipOptions.followPointer;
  8074. if (tooltip && followPointer && !tooltip.isHidden) {
  8075. anchor = tooltip.getAnchor([{}], e);
  8076. tooltip.updatePosition({ plotX: anchor[0], plotY: anchor[1] });
  8077. }
  8078. }
  8079. // Start the event listener to pick up the tooltip
  8080. if (tooltip && !pointer._onDocumentMouseMove) {
  8081. pointer._onDocumentMouseMove = function (e) {
  8082. if (charts[hoverChartIndex]) {
  8083. charts[hoverChartIndex].pointer.onDocumentMouseMove(e);
  8084. }
  8085. };
  8086. addEvent(doc, 'mousemove', pointer._onDocumentMouseMove);
  8087. }
  8088. // Crosshair
  8089. each(chart.axes, function (axis) {
  8090. axis.drawCrosshair(e, pick(kdpoint, hoverPoint));
  8091. });
  8092. },
  8093. /**
  8094. * Reset the tracking by hiding the tooltip, the hover series state and the hover point
  8095. *
  8096. * @param allowMove {Boolean} Instead of destroying the tooltip altogether, allow moving it if possible
  8097. */
  8098. reset: function (allowMove, delay) {
  8099. var pointer = this,
  8100. chart = pointer.chart,
  8101. hoverSeries = chart.hoverSeries,
  8102. hoverPoint = chart.hoverPoint,
  8103. hoverPoints = chart.hoverPoints,
  8104. tooltip = chart.tooltip,
  8105. tooltipPoints = tooltip && tooltip.shared ? hoverPoints : hoverPoint;
  8106. // Narrow in allowMove
  8107. allowMove = allowMove && tooltip && tooltipPoints;
  8108. // Check if the points have moved outside the plot area, #1003
  8109. if (allowMove && splat(tooltipPoints)[0].plotX === UNDEFINED) {
  8110. allowMove = false;
  8111. }
  8112. // Just move the tooltip, #349
  8113. if (allowMove) {
  8114. tooltip.refresh(tooltipPoints);
  8115. if (hoverPoint) { // #2500
  8116. hoverPoint.setState(hoverPoint.state, true);
  8117. each(chart.axes, function (axis) {
  8118. if (pick(axis.options.crosshair && axis.options.crosshair.snap, true)) {
  8119. axis.drawCrosshair(null, hoverPoint);
  8120. } else {
  8121. axis.hideCrosshair();
  8122. }
  8123. });
  8124. }
  8125. // Full reset
  8126. } else {
  8127. if (hoverPoint) {
  8128. hoverPoint.onMouseOut();
  8129. }
  8130. if (hoverPoints) {
  8131. each(hoverPoints, function (point) {
  8132. point.setState();
  8133. });
  8134. }
  8135. if (hoverSeries) {
  8136. hoverSeries.onMouseOut();
  8137. }
  8138. if (tooltip) {
  8139. tooltip.hide(delay);
  8140. }
  8141. if (pointer._onDocumentMouseMove) {
  8142. removeEvent(doc, 'mousemove', pointer._onDocumentMouseMove);
  8143. pointer._onDocumentMouseMove = null;
  8144. }
  8145. // Remove crosshairs
  8146. each(chart.axes, function (axis) {
  8147. axis.hideCrosshair();
  8148. });
  8149. pointer.hoverX = chart.hoverPoints = chart.hoverPoint = null;
  8150. }
  8151. },
  8152. /**
  8153. * Scale series groups to a certain scale and translation
  8154. */
  8155. scaleGroups: function (attribs, clip) {
  8156. var chart = this.chart,
  8157. seriesAttribs;
  8158. // Scale each series
  8159. each(chart.series, function (series) {
  8160. seriesAttribs = attribs || series.getPlotBox(); // #1701
  8161. if (series.xAxis && series.xAxis.zoomEnabled) {
  8162. series.group.attr(seriesAttribs);
  8163. if (series.markerGroup) {
  8164. series.markerGroup.attr(seriesAttribs);
  8165. series.markerGroup.clip(clip ? chart.clipRect : null);
  8166. }
  8167. if (series.dataLabelsGroup) {
  8168. series.dataLabelsGroup.attr(seriesAttribs);
  8169. }
  8170. }
  8171. });
  8172. // Clip
  8173. chart.clipRect.attr(clip || chart.clipBox);
  8174. },
  8175. /**
  8176. * Start a drag operation
  8177. */
  8178. dragStart: function (e) {
  8179. var chart = this.chart;
  8180. // Record the start position
  8181. chart.mouseIsDown = e.type;
  8182. chart.cancelClick = false;
  8183. chart.mouseDownX = this.mouseDownX = e.chartX;
  8184. chart.mouseDownY = this.mouseDownY = e.chartY;
  8185. },
  8186. /**
  8187. * Perform a drag operation in response to a mousemove event while the mouse is down
  8188. */
  8189. drag: function (e) {
  8190. var chart = this.chart,
  8191. chartOptions = chart.options.chart,
  8192. chartX = e.chartX,
  8193. chartY = e.chartY,
  8194. zoomHor = this.zoomHor,
  8195. zoomVert = this.zoomVert,
  8196. plotLeft = chart.plotLeft,
  8197. plotTop = chart.plotTop,
  8198. plotWidth = chart.plotWidth,
  8199. plotHeight = chart.plotHeight,
  8200. clickedInside,
  8201. size,
  8202. selectionMarker = this.selectionMarker,
  8203. mouseDownX = this.mouseDownX,
  8204. mouseDownY = this.mouseDownY,
  8205. panKey = chartOptions.panKey && e[chartOptions.panKey + 'Key'];
  8206. // If the device supports both touch and mouse (like IE11), and we are touch-dragging
  8207. // inside the plot area, don't handle the mouse event. #4339.
  8208. if (selectionMarker && selectionMarker.touch) {
  8209. return;
  8210. }
  8211. // If the mouse is outside the plot area, adjust to cooordinates
  8212. // inside to prevent the selection marker from going outside
  8213. if (chartX < plotLeft) {
  8214. chartX = plotLeft;
  8215. } else if (chartX > plotLeft + plotWidth) {
  8216. chartX = plotLeft + plotWidth;
  8217. }
  8218. if (chartY < plotTop) {
  8219. chartY = plotTop;
  8220. } else if (chartY > plotTop + plotHeight) {
  8221. chartY = plotTop + plotHeight;
  8222. }
  8223. // determine if the mouse has moved more than 10px
  8224. this.hasDragged = Math.sqrt(
  8225. Math.pow(mouseDownX - chartX, 2) +
  8226. Math.pow(mouseDownY - chartY, 2)
  8227. );
  8228. if (this.hasDragged > 10) {
  8229. clickedInside = chart.isInsidePlot(mouseDownX - plotLeft, mouseDownY - plotTop);
  8230. // make a selection
  8231. if (chart.hasCartesianSeries && (this.zoomX || this.zoomY) && clickedInside && !panKey) {
  8232. if (!selectionMarker) {
  8233. this.selectionMarker = selectionMarker = chart.renderer.rect(
  8234. plotLeft,
  8235. plotTop,
  8236. zoomHor ? 1 : plotWidth,
  8237. zoomVert ? 1 : plotHeight,
  8238. 0
  8239. )
  8240. .attr({
  8241. fill: chartOptions.selectionMarkerFill || 'rgba(69,114,167,0.25)',
  8242. zIndex: 7
  8243. })
  8244. .add();
  8245. }
  8246. }
  8247. // adjust the width of the selection marker
  8248. if (selectionMarker && zoomHor) {
  8249. size = chartX - mouseDownX;
  8250. selectionMarker.attr({
  8251. width: mathAbs(size),
  8252. x: (size > 0 ? 0 : size) + mouseDownX
  8253. });
  8254. }
  8255. // adjust the height of the selection marker
  8256. if (selectionMarker && zoomVert) {
  8257. size = chartY - mouseDownY;
  8258. selectionMarker.attr({
  8259. height: mathAbs(size),
  8260. y: (size > 0 ? 0 : size) + mouseDownY
  8261. });
  8262. }
  8263. // panning
  8264. if (clickedInside && !selectionMarker && chartOptions.panning) {
  8265. chart.pan(e, chartOptions.panning);
  8266. }
  8267. }
  8268. },
  8269. /**
  8270. * On mouse up or touch end across the entire document, drop the selection.
  8271. */
  8272. drop: function (e) {
  8273. var pointer = this,
  8274. chart = this.chart,
  8275. hasPinched = this.hasPinched;
  8276. if (this.selectionMarker) {
  8277. var selectionData = {
  8278. xAxis: [],
  8279. yAxis: [],
  8280. originalEvent: e.originalEvent || e
  8281. },
  8282. selectionBox = this.selectionMarker,
  8283. selectionLeft = selectionBox.attr ? selectionBox.attr('x') : selectionBox.x,
  8284. selectionTop = selectionBox.attr ? selectionBox.attr('y') : selectionBox.y,
  8285. selectionWidth = selectionBox.attr ? selectionBox.attr('width') : selectionBox.width,
  8286. selectionHeight = selectionBox.attr ? selectionBox.attr('height') : selectionBox.height,
  8287. runZoom;
  8288. // a selection has been made
  8289. if (this.hasDragged || hasPinched) {
  8290. // record each axis' min and max
  8291. each(chart.axes, function (axis) {
  8292. if (axis.zoomEnabled && defined(axis.min) && (hasPinched || pointer[{ xAxis: 'zoomX', yAxis: 'zoomY' }[axis.coll]])) { // #859, #3569
  8293. var horiz = axis.horiz,
  8294. minPixelPadding = e.type === 'touchend' ? axis.minPixelPadding: 0, // #1207, #3075
  8295. selectionMin = axis.toValue((horiz ? selectionLeft : selectionTop) + minPixelPadding),
  8296. selectionMax = axis.toValue((horiz ? selectionLeft + selectionWidth : selectionTop + selectionHeight) - minPixelPadding);
  8297. selectionData[axis.coll].push({
  8298. axis: axis,
  8299. min: mathMin(selectionMin, selectionMax), // for reversed axes
  8300. max: mathMax(selectionMin, selectionMax)
  8301. });
  8302. runZoom = true;
  8303. }
  8304. });
  8305. if (runZoom) {
  8306. fireEvent(chart, 'selection', selectionData, function (args) {
  8307. chart.zoom(extend(args, hasPinched ? { animation: false } : null));
  8308. });
  8309. }
  8310. }
  8311. this.selectionMarker = this.selectionMarker.destroy();
  8312. // Reset scaling preview
  8313. if (hasPinched) {
  8314. this.scaleGroups();
  8315. }
  8316. }
  8317. // Reset all
  8318. if (chart) { // it may be destroyed on mouse up - #877
  8319. css(chart.container, { cursor: chart._cursor });
  8320. chart.cancelClick = this.hasDragged > 10; // #370
  8321. chart.mouseIsDown = this.hasDragged = this.hasPinched = false;
  8322. this.pinchDown = [];
  8323. }
  8324. },
  8325. onContainerMouseDown: function (e) {
  8326. e = this.normalize(e);
  8327. // issue #295, dragging not always working in Firefox
  8328. if (e.preventDefault) {
  8329. e.preventDefault();
  8330. }
  8331. this.dragStart(e);
  8332. },
  8333. onDocumentMouseUp: function (e) {
  8334. if (charts[hoverChartIndex]) {
  8335. charts[hoverChartIndex].pointer.drop(e);
  8336. }
  8337. },
  8338. /**
  8339. * Special handler for mouse move that will hide the tooltip when the mouse leaves the plotarea.
  8340. * Issue #149 workaround. The mouseleave event does not always fire.
  8341. */
  8342. onDocumentMouseMove: function (e) {
  8343. var chart = this.chart,
  8344. chartPosition = this.chartPosition;
  8345. e = this.normalize(e, chartPosition);
  8346. // If we're outside, hide the tooltip
  8347. if (chartPosition && !this.inClass(e.target, 'highcharts-tracker') &&
  8348. !chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop)) {
  8349. this.reset();
  8350. }
  8351. },
  8352. /**
  8353. * When mouse leaves the container, hide the tooltip.
  8354. */
  8355. onContainerMouseLeave: function () {
  8356. var chart = charts[hoverChartIndex];
  8357. if (chart) {
  8358. chart.pointer.reset();
  8359. chart.pointer.chartPosition = null; // also reset the chart position, used in #149 fix
  8360. }
  8361. },
  8362. // The mousemove, touchmove and touchstart event handler
  8363. onContainerMouseMove: function (e) {
  8364. var chart = this.chart;
  8365. hoverChartIndex = chart.index;
  8366. e = this.normalize(e);
  8367. e.returnValue = false; // #2251, #3224
  8368. if (chart.mouseIsDown === 'mousedown') {
  8369. this.drag(e);
  8370. }
  8371. // Show the tooltip and run mouse over events (#977)
  8372. if ((this.inClass(e.target, 'highcharts-tracker') ||
  8373. chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop)) && !chart.openMenu) {
  8374. this.runPointActions(e);
  8375. }
  8376. },
  8377. /**
  8378. * Utility to detect whether an element has, or has a parent with, a specific
  8379. * class name. Used on detection of tracker objects and on deciding whether
  8380. * hovering the tooltip should cause the active series to mouse out.
  8381. */
  8382. inClass: function (element, className) {
  8383. var elemClassName;
  8384. while (element) {
  8385. elemClassName = attr(element, 'class');
  8386. if (elemClassName) {
  8387. if (elemClassName.indexOf(className) !== -1) {
  8388. return true;
  8389. } else if (elemClassName.indexOf(PREFIX + 'container') !== -1) {
  8390. return false;
  8391. }
  8392. }
  8393. element = element.parentNode;
  8394. }
  8395. },
  8396. onTrackerMouseOut: function (e) {
  8397. var series = this.chart.hoverSeries,
  8398. relatedTarget = e.relatedTarget || e.toElement;
  8399. if (series && !series.options.stickyTracking &&
  8400. !this.inClass(relatedTarget, PREFIX + 'tooltip') &&
  8401. !this.inClass(relatedTarget, PREFIX + 'series-' + series.index)) { // #2499, #4465
  8402. series.onMouseOut();
  8403. }
  8404. },
  8405. onContainerClick: function (e) {
  8406. var chart = this.chart,
  8407. hoverPoint = chart.hoverPoint,
  8408. plotLeft = chart.plotLeft,
  8409. plotTop = chart.plotTop;
  8410. e = this.normalize(e);
  8411. e.originalEvent = e; // #3913
  8412. if (!chart.cancelClick) {
  8413. // On tracker click, fire the series and point events. #783, #1583
  8414. if (hoverPoint && this.inClass(e.target, PREFIX + 'tracker')) {
  8415. // the series click event
  8416. fireEvent(hoverPoint.series, 'click', extend(e, {
  8417. point: hoverPoint
  8418. }));
  8419. // the point click event
  8420. if (chart.hoverPoint) { // it may be destroyed (#1844)
  8421. hoverPoint.firePointEvent('click', e);
  8422. }
  8423. // When clicking outside a tracker, fire a chart event
  8424. } else {
  8425. extend(e, this.getCoordinates(e));
  8426. // fire a click event in the chart
  8427. if (chart.isInsidePlot(e.chartX - plotLeft, e.chartY - plotTop)) {
  8428. fireEvent(chart, 'click', e);
  8429. }
  8430. }
  8431. }
  8432. },
  8433. /**
  8434. * Set the JS DOM events on the container and document. This method should contain
  8435. * a one-to-one assignment between methods and their handlers. Any advanced logic should
  8436. * be moved to the handler reflecting the event's name.
  8437. */
  8438. setDOMEvents: function () {
  8439. var pointer = this,
  8440. container = pointer.chart.container;
  8441. container.onmousedown = function (e) {
  8442. pointer.onContainerMouseDown(e);
  8443. };
  8444. container.onmousemove = function (e) {
  8445. pointer.onContainerMouseMove(e);
  8446. };
  8447. container.onclick = function (e) {
  8448. pointer.onContainerClick(e);
  8449. };
  8450. addEvent(container, 'mouseleave', pointer.onContainerMouseLeave);
  8451. if (chartCount === 1) {
  8452. addEvent(doc, 'mouseup', pointer.onDocumentMouseUp);
  8453. }
  8454. if (hasTouch) {
  8455. container.ontouchstart = function (e) {
  8456. pointer.onContainerTouchStart(e);
  8457. };
  8458. container.ontouchmove = function (e) {
  8459. pointer.onContainerTouchMove(e);
  8460. };
  8461. if (chartCount === 1) {
  8462. addEvent(doc, 'touchend', pointer.onDocumentTouchEnd);
  8463. }
  8464. }
  8465. },
  8466. /**
  8467. * Destroys the Pointer object and disconnects DOM events.
  8468. */
  8469. destroy: function () {
  8470. var prop;
  8471. removeEvent(this.chart.container, 'mouseleave', this.onContainerMouseLeave);
  8472. if (!chartCount) {
  8473. removeEvent(doc, 'mouseup', this.onDocumentMouseUp);
  8474. removeEvent(doc, 'touchend', this.onDocumentTouchEnd);
  8475. }
  8476. // memory and CPU leak
  8477. clearInterval(this.tooltipTimeout);
  8478. for (prop in this) {
  8479. this[prop] = null;
  8480. }
  8481. }
  8482. };
  8483. /* Support for touch devices */
  8484. extend(Highcharts.Pointer.prototype, {
  8485. /**
  8486. * Run translation operations
  8487. */
  8488. pinchTranslate: function (pinchDown, touches, transform, selectionMarker, clip, lastValidTouch) {
  8489. if (this.zoomHor || this.pinchHor) {
  8490. this.pinchTranslateDirection(true, pinchDown, touches, transform, selectionMarker, clip, lastValidTouch);
  8491. }
  8492. if (this.zoomVert || this.pinchVert) {
  8493. this.pinchTranslateDirection(false, pinchDown, touches, transform, selectionMarker, clip, lastValidTouch);
  8494. }
  8495. },
  8496. /**
  8497. * Run translation operations for each direction (horizontal and vertical) independently
  8498. */
  8499. pinchTranslateDirection: function (horiz, pinchDown, touches, transform, selectionMarker, clip, lastValidTouch, forcedScale) {
  8500. var chart = this.chart,
  8501. xy = horiz ? 'x' : 'y',
  8502. XY = horiz ? 'X' : 'Y',
  8503. sChartXY = 'chart' + XY,
  8504. wh = horiz ? 'width' : 'height',
  8505. plotLeftTop = chart['plot' + (horiz ? 'Left' : 'Top')],
  8506. selectionWH,
  8507. selectionXY,
  8508. clipXY,
  8509. scale = forcedScale || 1,
  8510. inverted = chart.inverted,
  8511. bounds = chart.bounds[horiz ? 'h' : 'v'],
  8512. singleTouch = pinchDown.length === 1,
  8513. touch0Start = pinchDown[0][sChartXY],
  8514. touch0Now = touches[0][sChartXY],
  8515. touch1Start = !singleTouch && pinchDown[1][sChartXY],
  8516. touch1Now = !singleTouch && touches[1][sChartXY],
  8517. outOfBounds,
  8518. transformScale,
  8519. scaleKey,
  8520. setScale = function () {
  8521. if (!singleTouch && mathAbs(touch0Start - touch1Start) > 20) { // Don't zoom if fingers are too close on this axis
  8522. scale = forcedScale || mathAbs(touch0Now - touch1Now) / mathAbs(touch0Start - touch1Start);
  8523. }
  8524. clipXY = ((plotLeftTop - touch0Now) / scale) + touch0Start;
  8525. selectionWH = chart['plot' + (horiz ? 'Width' : 'Height')] / scale;
  8526. };
  8527. // Set the scale, first pass
  8528. setScale();
  8529. selectionXY = clipXY; // the clip position (x or y) is altered if out of bounds, the selection position is not
  8530. // Out of bounds
  8531. if (selectionXY < bounds.min) {
  8532. selectionXY = bounds.min;
  8533. outOfBounds = true;
  8534. } else if (selectionXY + selectionWH > bounds.max) {
  8535. selectionXY = bounds.max - selectionWH;
  8536. outOfBounds = true;
  8537. }
  8538. // Is the chart dragged off its bounds, determined by dataMin and dataMax?
  8539. if (outOfBounds) {
  8540. // Modify the touchNow position in order to create an elastic drag movement. This indicates
  8541. // to the user that the chart is responsive but can't be dragged further.
  8542. touch0Now -= 0.8 * (touch0Now - lastValidTouch[xy][0]);
  8543. if (!singleTouch) {
  8544. touch1Now -= 0.8 * (touch1Now - lastValidTouch[xy][1]);
  8545. }
  8546. // Set the scale, second pass to adapt to the modified touchNow positions
  8547. setScale();
  8548. } else {
  8549. lastValidTouch[xy] = [touch0Now, touch1Now];
  8550. }
  8551. // Set geometry for clipping, selection and transformation
  8552. if (!inverted) { // TODO: implement clipping for inverted charts
  8553. clip[xy] = clipXY - plotLeftTop;
  8554. clip[wh] = selectionWH;
  8555. }
  8556. scaleKey = inverted ? (horiz ? 'scaleY' : 'scaleX') : 'scale' + XY;
  8557. transformScale = inverted ? 1 / scale : scale;
  8558. selectionMarker[wh] = selectionWH;
  8559. selectionMarker[xy] = selectionXY;
  8560. transform[scaleKey] = scale;
  8561. transform['translate' + XY] = (transformScale * plotLeftTop) + (touch0Now - (transformScale * touch0Start));
  8562. },
  8563. /**
  8564. * Handle touch events with two touches
  8565. */
  8566. pinch: function (e) {
  8567. var self = this,
  8568. chart = self.chart,
  8569. pinchDown = self.pinchDown,
  8570. touches = e.touches,
  8571. touchesLength = touches.length,
  8572. lastValidTouch = self.lastValidTouch,
  8573. hasZoom = self.hasZoom,
  8574. selectionMarker = self.selectionMarker,
  8575. transform = {},
  8576. fireClickEvent = touchesLength === 1 && ((self.inClass(e.target, PREFIX + 'tracker') &&
  8577. chart.runTrackerClick) || self.runChartClick),
  8578. clip = {};
  8579. // Don't initiate panning until the user has pinched. This prevents us from
  8580. // blocking page scrolling as users scroll down a long page (#4210).
  8581. if (touchesLength > 1) {
  8582. self.initiated = true;
  8583. }
  8584. // On touch devices, only proceed to trigger click if a handler is defined
  8585. if (hasZoom && self.initiated && !fireClickEvent) {
  8586. e.preventDefault();
  8587. }
  8588. // Normalize each touch
  8589. map(touches, function (e) {
  8590. return self.normalize(e);
  8591. });
  8592. // Register the touch start position
  8593. if (e.type === 'touchstart') {
  8594. each(touches, function (e, i) {
  8595. pinchDown[i] = { chartX: e.chartX, chartY: e.chartY };
  8596. });
  8597. lastValidTouch.x = [pinchDown[0].chartX, pinchDown[1] && pinchDown[1].chartX];
  8598. lastValidTouch.y = [pinchDown[0].chartY, pinchDown[1] && pinchDown[1].chartY];
  8599. // Identify the data bounds in pixels
  8600. each(chart.axes, function (axis) {
  8601. if (axis.zoomEnabled) {
  8602. var bounds = chart.bounds[axis.horiz ? 'h' : 'v'],
  8603. minPixelPadding = axis.minPixelPadding,
  8604. min = axis.toPixels(pick(axis.options.min, axis.dataMin)),
  8605. max = axis.toPixels(pick(axis.options.max, axis.dataMax)),
  8606. absMin = mathMin(min, max),
  8607. absMax = mathMax(min, max);
  8608. // Store the bounds for use in the touchmove handler
  8609. bounds.min = mathMin(axis.pos, absMin - minPixelPadding);
  8610. bounds.max = mathMax(axis.pos + axis.len, absMax + minPixelPadding);
  8611. }
  8612. });
  8613. self.res = true; // reset on next move
  8614. // Event type is touchmove, handle panning and pinching
  8615. } else if (pinchDown.length) { // can be 0 when releasing, if touchend fires first
  8616. // Set the marker
  8617. if (!selectionMarker) {
  8618. self.selectionMarker = selectionMarker = extend({
  8619. destroy: noop,
  8620. touch: true
  8621. }, chart.plotBox);
  8622. }
  8623. self.pinchTranslate(pinchDown, touches, transform, selectionMarker, clip, lastValidTouch);
  8624. self.hasPinched = hasZoom;
  8625. // Scale and translate the groups to provide visual feedback during pinching
  8626. self.scaleGroups(transform, clip);
  8627. // Optionally move the tooltip on touchmove
  8628. if (!hasZoom && self.followTouchMove && touchesLength === 1) {
  8629. this.runPointActions(self.normalize(e));
  8630. } else if (self.res) {
  8631. self.res = false;
  8632. this.reset(false, 0);
  8633. }
  8634. }
  8635. },
  8636. /**
  8637. * General touch handler shared by touchstart and touchmove.
  8638. */
  8639. touch: function (e, start) {
  8640. var chart = this.chart;
  8641. hoverChartIndex = chart.index;
  8642. if (e.touches.length === 1) {
  8643. e = this.normalize(e);
  8644. if (chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop) && !chart.openMenu) {
  8645. // Run mouse events and display tooltip etc
  8646. if (start) {
  8647. this.runPointActions(e);
  8648. }
  8649. this.pinch(e);
  8650. } else if (start) {
  8651. // Hide the tooltip on touching outside the plot area (#1203)
  8652. this.reset();
  8653. }
  8654. } else if (e.touches.length === 2) {
  8655. this.pinch(e);
  8656. }
  8657. },
  8658. onContainerTouchStart: function (e) {
  8659. this.touch(e, true);
  8660. },
  8661. onContainerTouchMove: function (e) {
  8662. this.touch(e);
  8663. },
  8664. onDocumentTouchEnd: function (e) {
  8665. if (charts[hoverChartIndex]) {
  8666. charts[hoverChartIndex].pointer.drop(e);
  8667. }
  8668. }
  8669. });
  8670. if (win.PointerEvent || win.MSPointerEvent) {
  8671. // The touches object keeps track of the points being touched at all times
  8672. var touches = {},
  8673. hasPointerEvent = !!win.PointerEvent,
  8674. getWebkitTouches = function () {
  8675. var key, fake = [];
  8676. fake.item = function (i) { return this[i]; };
  8677. for (key in touches) {
  8678. if (touches.hasOwnProperty(key)) {
  8679. fake.push({
  8680. pageX: touches[key].pageX,
  8681. pageY: touches[key].pageY,
  8682. target: touches[key].target
  8683. });
  8684. }
  8685. }
  8686. return fake;
  8687. },
  8688. translateMSPointer = function (e, method, wktype, callback) {
  8689. var p;
  8690. e = e.originalEvent || e;
  8691. if ((e.pointerType === 'touch' || e.pointerType === e.MSPOINTER_TYPE_TOUCH) && charts[hoverChartIndex]) {
  8692. callback(e);
  8693. p = charts[hoverChartIndex].pointer;
  8694. p[method]({
  8695. type: wktype,
  8696. target: e.currentTarget,
  8697. preventDefault: noop,
  8698. touches: getWebkitTouches()
  8699. });
  8700. }
  8701. };
  8702. /**
  8703. * Extend the Pointer prototype with methods for each event handler and more
  8704. */
  8705. extend(Pointer.prototype, {
  8706. onContainerPointerDown: function (e) {
  8707. translateMSPointer(e, 'onContainerTouchStart', 'touchstart', function (e) {
  8708. touches[e.pointerId] = { pageX: e.pageX, pageY: e.pageY, target: e.currentTarget };
  8709. });
  8710. },
  8711. onContainerPointerMove: function (e) {
  8712. translateMSPointer(e, 'onContainerTouchMove', 'touchmove', function (e) {
  8713. touches[e.pointerId] = { pageX: e.pageX, pageY: e.pageY };
  8714. if (!touches[e.pointerId].target) {
  8715. touches[e.pointerId].target = e.currentTarget;
  8716. }
  8717. });
  8718. },
  8719. onDocumentPointerUp: function (e) {
  8720. translateMSPointer(e, 'onDocumentTouchEnd', 'touchend', function (e) {
  8721. delete touches[e.pointerId];
  8722. });
  8723. },
  8724. /**
  8725. * Add or remove the MS Pointer specific events
  8726. */
  8727. batchMSEvents: function (fn) {
  8728. fn(this.chart.container, hasPointerEvent ? 'pointerdown' : 'MSPointerDown', this.onContainerPointerDown);
  8729. fn(this.chart.container, hasPointerEvent ? 'pointermove' : 'MSPointerMove', this.onContainerPointerMove);
  8730. fn(doc, hasPointerEvent ? 'pointerup' : 'MSPointerUp', this.onDocumentPointerUp);
  8731. }
  8732. });
  8733. // Disable default IE actions for pinch and such on chart element
  8734. wrap(Pointer.prototype, 'init', function (proceed, chart, options) {
  8735. proceed.call(this, chart, options);
  8736. if (this.hasZoom) { // #4014
  8737. css(chart.container, {
  8738. '-ms-touch-action': NONE,
  8739. 'touch-action': NONE
  8740. });
  8741. }
  8742. });
  8743. // Add IE specific touch events to chart
  8744. wrap(Pointer.prototype, 'setDOMEvents', function (proceed) {
  8745. proceed.apply(this);
  8746. if (this.hasZoom || this.followTouchMove) {
  8747. this.batchMSEvents(addEvent);
  8748. }
  8749. });
  8750. // Destroy MS events also
  8751. wrap(Pointer.prototype, 'destroy', function (proceed) {
  8752. this.batchMSEvents(removeEvent);
  8753. proceed.call(this);
  8754. });
  8755. }
  8756. /**
  8757. * The overview of the chart's series
  8758. */
  8759. var Legend = Highcharts.Legend = function (chart, options) {
  8760. this.init(chart, options);
  8761. };
  8762. Legend.prototype = {
  8763. /**
  8764. * Initialize the legend
  8765. */
  8766. init: function (chart, options) {
  8767. var legend = this,
  8768. itemStyle = options.itemStyle,
  8769. padding,
  8770. itemMarginTop = options.itemMarginTop || 0;
  8771. this.options = options;
  8772. if (!options.enabled) {
  8773. return;
  8774. }
  8775. legend.itemStyle = itemStyle;
  8776. legend.itemHiddenStyle = merge(itemStyle, options.itemHiddenStyle);
  8777. legend.itemMarginTop = itemMarginTop;
  8778. legend.padding = padding = pick(options.padding, 8);
  8779. legend.initialItemX = padding;
  8780. legend.initialItemY = padding - 5; // 5 is the number of pixels above the text
  8781. legend.maxItemWidth = 0;
  8782. legend.chart = chart;
  8783. legend.itemHeight = 0;
  8784. legend.symbolWidth = pick(options.symbolWidth, 16);
  8785. legend.pages = [];
  8786. // Render it
  8787. legend.render();
  8788. // move checkboxes
  8789. addEvent(legend.chart, 'endResize', function () {
  8790. legend.positionCheckboxes();
  8791. });
  8792. },
  8793. /**
  8794. * Set the colors for the legend item
  8795. * @param {Object} item A Series or Point instance
  8796. * @param {Object} visible Dimmed or colored
  8797. */
  8798. colorizeItem: function (item, visible) {
  8799. var legend = this,
  8800. options = legend.options,
  8801. legendItem = item.legendItem,
  8802. legendLine = item.legendLine,
  8803. legendSymbol = item.legendSymbol,
  8804. hiddenColor = legend.itemHiddenStyle.color,
  8805. textColor = visible ? options.itemStyle.color : hiddenColor,
  8806. symbolColor = visible ? (item.legendColor || item.color || '#CCC') : hiddenColor,
  8807. markerOptions = item.options && item.options.marker,
  8808. symbolAttr = { fill: symbolColor },
  8809. key,
  8810. val;
  8811. if (legendItem) {
  8812. legendItem.css({ fill: textColor, color: textColor }); // color for #1553, oldIE
  8813. }
  8814. if (legendLine) {
  8815. legendLine.attr({ stroke: symbolColor });
  8816. }
  8817. if (legendSymbol) {
  8818. // Apply marker options
  8819. if (markerOptions && legendSymbol.isMarker) { // #585
  8820. symbolAttr.stroke = symbolColor;
  8821. markerOptions = item.convertAttribs(markerOptions);
  8822. for (key in markerOptions) {
  8823. val = markerOptions[key];
  8824. if (val !== UNDEFINED) {
  8825. symbolAttr[key] = val;
  8826. }
  8827. }
  8828. }
  8829. legendSymbol.attr(symbolAttr);
  8830. }
  8831. },
  8832. /**
  8833. * Position the legend item
  8834. * @param {Object} item A Series or Point instance
  8835. */
  8836. positionItem: function (item) {
  8837. var legend = this,
  8838. options = legend.options,
  8839. symbolPadding = options.symbolPadding,
  8840. ltr = !options.rtl,
  8841. legendItemPos = item._legendItemPos,
  8842. itemX = legendItemPos[0],
  8843. itemY = legendItemPos[1],
  8844. checkbox = item.checkbox,
  8845. legendGroup = item.legendGroup;
  8846. if (legendGroup && legendGroup.element) {
  8847. legendGroup.translate(
  8848. ltr ? itemX : legend.legendWidth - itemX - 2 * symbolPadding - 4,
  8849. itemY
  8850. );
  8851. }
  8852. if (checkbox) {
  8853. checkbox.x = itemX;
  8854. checkbox.y = itemY;
  8855. }
  8856. },
  8857. /**
  8858. * Destroy a single legend item
  8859. * @param {Object} item The series or point
  8860. */
  8861. destroyItem: function (item) {
  8862. var checkbox = item.checkbox;
  8863. // destroy SVG elements
  8864. each(['legendItem', 'legendLine', 'legendSymbol', 'legendGroup'], function (key) {
  8865. if (item[key]) {
  8866. item[key] = item[key].destroy();
  8867. }
  8868. });
  8869. if (checkbox) {
  8870. discardElement(item.checkbox);
  8871. }
  8872. },
  8873. /**
  8874. * Destroys the legend.
  8875. */
  8876. destroy: function () {
  8877. var legend = this,
  8878. legendGroup = legend.group,
  8879. box = legend.box;
  8880. if (box) {
  8881. legend.box = box.destroy();
  8882. }
  8883. if (legendGroup) {
  8884. legend.group = legendGroup.destroy();
  8885. }
  8886. },
  8887. /**
  8888. * Position the checkboxes after the width is determined
  8889. */
  8890. positionCheckboxes: function (scrollOffset) {
  8891. var alignAttr = this.group.alignAttr,
  8892. translateY,
  8893. clipHeight = this.clipHeight || this.legendHeight;
  8894. if (alignAttr) {
  8895. translateY = alignAttr.translateY;
  8896. each(this.allItems, function (item) {
  8897. var checkbox = item.checkbox,
  8898. top;
  8899. if (checkbox) {
  8900. top = (translateY + checkbox.y + (scrollOffset || 0) + 3);
  8901. css(checkbox, {
  8902. left: (alignAttr.translateX + item.checkboxOffset + checkbox.x - 20) + PX,
  8903. top: top + PX,
  8904. display: top > translateY - 6 && top < translateY + clipHeight - 6 ? '' : NONE
  8905. });
  8906. }
  8907. });
  8908. }
  8909. },
  8910. /**
  8911. * Render the legend title on top of the legend
  8912. */
  8913. renderTitle: function () {
  8914. var options = this.options,
  8915. padding = this.padding,
  8916. titleOptions = options.title,
  8917. titleHeight = 0,
  8918. bBox;
  8919. if (titleOptions.text) {
  8920. if (!this.title) {
  8921. this.title = this.chart.renderer.label(titleOptions.text, padding - 3, padding - 4, null, null, null, null, null, 'legend-title')
  8922. .attr({ zIndex: 1 })
  8923. .css(titleOptions.style)
  8924. .add(this.group);
  8925. }
  8926. bBox = this.title.getBBox();
  8927. titleHeight = bBox.height;
  8928. this.offsetWidth = bBox.width; // #1717
  8929. this.contentGroup.attr({ translateY: titleHeight });
  8930. }
  8931. this.titleHeight = titleHeight;
  8932. },
  8933. /**
  8934. * Set the legend item text
  8935. */
  8936. setText: function (item) {
  8937. var options = this.options;
  8938. item.legendItem.attr({
  8939. text: options.labelFormat ? format(options.labelFormat, item) : options.labelFormatter.call(item)
  8940. });
  8941. },
  8942. /**
  8943. * Render a single specific legend item
  8944. * @param {Object} item A series or point
  8945. */
  8946. renderItem: function (item) {
  8947. var legend = this,
  8948. chart = legend.chart,
  8949. renderer = chart.renderer,
  8950. options = legend.options,
  8951. horizontal = options.layout === 'horizontal',
  8952. symbolWidth = legend.symbolWidth,
  8953. symbolPadding = options.symbolPadding,
  8954. itemStyle = legend.itemStyle,
  8955. itemHiddenStyle = legend.itemHiddenStyle,
  8956. padding = legend.padding,
  8957. itemDistance = horizontal ? pick(options.itemDistance, 20) : 0,
  8958. ltr = !options.rtl,
  8959. itemHeight,
  8960. widthOption = options.width,
  8961. itemMarginBottom = options.itemMarginBottom || 0,
  8962. itemMarginTop = legend.itemMarginTop,
  8963. initialItemX = legend.initialItemX,
  8964. bBox,
  8965. itemWidth,
  8966. li = item.legendItem,
  8967. series = item.series && item.series.drawLegendSymbol ? item.series : item,
  8968. seriesOptions = series.options,
  8969. showCheckbox = legend.createCheckboxForItem && seriesOptions && seriesOptions.showCheckbox,
  8970. useHTML = options.useHTML;
  8971. if (!li) { // generate it once, later move it
  8972. // Generate the group box
  8973. // A group to hold the symbol and text. Text is to be appended in Legend class.
  8974. item.legendGroup = renderer.g('legend-item')
  8975. .attr({ zIndex: 1 })
  8976. .add(legend.scrollGroup);
  8977. // Generate the list item text and add it to the group
  8978. item.legendItem = li = renderer.text(
  8979. '',
  8980. ltr ? symbolWidth + symbolPadding : -symbolPadding,
  8981. legend.baseline || 0,
  8982. useHTML
  8983. )
  8984. .css(merge(item.visible ? itemStyle : itemHiddenStyle)) // merge to prevent modifying original (#1021)
  8985. .attr({
  8986. align: ltr ? 'left' : 'right',
  8987. zIndex: 2
  8988. })
  8989. .add(item.legendGroup);
  8990. // Get the baseline for the first item - the font size is equal for all
  8991. if (!legend.baseline) {
  8992. legend.fontMetrics = renderer.fontMetrics(itemStyle.fontSize, li);
  8993. legend.baseline = legend.fontMetrics.f + 3 + itemMarginTop;
  8994. li.attr('y', legend.baseline);
  8995. }
  8996. // Draw the legend symbol inside the group box
  8997. series.drawLegendSymbol(legend, item);
  8998. if (legend.setItemEvents) {
  8999. legend.setItemEvents(item, li, useHTML, itemStyle, itemHiddenStyle);
  9000. }
  9001. // Colorize the items
  9002. legend.colorizeItem(item, item.visible);
  9003. // add the HTML checkbox on top
  9004. if (showCheckbox) {
  9005. legend.createCheckboxForItem(item);
  9006. }
  9007. }
  9008. // Always update the text
  9009. legend.setText(item);
  9010. // calculate the positions for the next line
  9011. bBox = li.getBBox();
  9012. itemWidth = item.checkboxOffset =
  9013. options.itemWidth ||
  9014. item.legendItemWidth ||
  9015. symbolWidth + symbolPadding + bBox.width + itemDistance + (showCheckbox ? 20 : 0);
  9016. legend.itemHeight = itemHeight = mathRound(item.legendItemHeight || bBox.height);
  9017. // if the item exceeds the width, start a new line
  9018. if (horizontal && legend.itemX - initialItemX + itemWidth >
  9019. (widthOption || (chart.chartWidth - 2 * padding - initialItemX - options.x))) {
  9020. legend.itemX = initialItemX;
  9021. legend.itemY += itemMarginTop + legend.lastLineHeight + itemMarginBottom;
  9022. legend.lastLineHeight = 0; // reset for next line (#915, #3976)
  9023. }
  9024. // If the item exceeds the height, start a new column
  9025. /*if (!horizontal && legend.itemY + options.y + itemHeight > chart.chartHeight - spacingTop - spacingBottom) {
  9026. legend.itemY = legend.initialItemY;
  9027. legend.itemX += legend.maxItemWidth;
  9028. legend.maxItemWidth = 0;
  9029. }*/
  9030. // Set the edge positions
  9031. legend.maxItemWidth = mathMax(legend.maxItemWidth, itemWidth);
  9032. legend.lastItemY = itemMarginTop + legend.itemY + itemMarginBottom;
  9033. legend.lastLineHeight = mathMax(itemHeight, legend.lastLineHeight); // #915
  9034. // cache the position of the newly generated or reordered items
  9035. item._legendItemPos = [legend.itemX, legend.itemY];
  9036. // advance
  9037. if (horizontal) {
  9038. legend.itemX += itemWidth;
  9039. } else {
  9040. legend.itemY += itemMarginTop + itemHeight + itemMarginBottom;
  9041. legend.lastLineHeight = itemHeight;
  9042. }
  9043. // the width of the widest item
  9044. legend.offsetWidth = widthOption || mathMax(
  9045. (horizontal ? legend.itemX - initialItemX - itemDistance : itemWidth) + padding,
  9046. legend.offsetWidth
  9047. );
  9048. },
  9049. /**
  9050. * Get all items, which is one item per series for normal series and one item per point
  9051. * for pie series.
  9052. */
  9053. getAllItems: function () {
  9054. var allItems = [];
  9055. each(this.chart.series, function (series) {
  9056. var seriesOptions = series.options;
  9057. // Handle showInLegend. If the series is linked to another series, defaults to false.
  9058. if (!pick(seriesOptions.showInLegend, !defined(seriesOptions.linkedTo) ? UNDEFINED : false, true)) {
  9059. return;
  9060. }
  9061. // use points or series for the legend item depending on legendType
  9062. allItems = allItems.concat(
  9063. series.legendItems ||
  9064. (seriesOptions.legendType === 'point' ?
  9065. series.data :
  9066. series)
  9067. );
  9068. });
  9069. return allItems;
  9070. },
  9071. /**
  9072. * Adjust the chart margins by reserving space for the legend on only one side
  9073. * of the chart. If the position is set to a corner, top or bottom is reserved
  9074. * for horizontal legends and left or right for vertical ones.
  9075. */
  9076. adjustMargins: function (margin, spacing) {
  9077. var chart = this.chart,
  9078. options = this.options,
  9079. // Use the first letter of each alignment option in order to detect the side
  9080. alignment = options.align.charAt(0) + options.verticalAlign.charAt(0) + options.layout.charAt(0); // #4189 - use charAt(x) notation instead of [x] for IE7
  9081. if (this.display && !options.floating) {
  9082. each([
  9083. /(lth|ct|rth)/,
  9084. /(rtv|rm|rbv)/,
  9085. /(rbh|cb|lbh)/,
  9086. /(lbv|lm|ltv)/
  9087. ], function (alignments, side) {
  9088. if (alignments.test(alignment) && !defined(margin[side])) {
  9089. // Now we have detected on which side of the chart we should reserve space for the legend
  9090. chart[marginNames[side]] = mathMax(
  9091. chart[marginNames[side]],
  9092. chart.legend[(side + 1) % 2 ? 'legendHeight' : 'legendWidth'] +
  9093. [1, -1, -1, 1][side] * options[(side % 2) ? 'x' : 'y'] +
  9094. pick(options.margin, 12) +
  9095. spacing[side]
  9096. );
  9097. }
  9098. });
  9099. }
  9100. },
  9101. /**
  9102. * Render the legend. This method can be called both before and after
  9103. * chart.render. If called after, it will only rearrange items instead
  9104. * of creating new ones.
  9105. */
  9106. render: function () {
  9107. var legend = this,
  9108. chart = legend.chart,
  9109. renderer = chart.renderer,
  9110. legendGroup = legend.group,
  9111. allItems,
  9112. display,
  9113. legendWidth,
  9114. legendHeight,
  9115. box = legend.box,
  9116. options = legend.options,
  9117. padding = legend.padding,
  9118. legendBorderWidth = options.borderWidth,
  9119. legendBackgroundColor = options.backgroundColor;
  9120. legend.itemX = legend.initialItemX;
  9121. legend.itemY = legend.initialItemY;
  9122. legend.offsetWidth = 0;
  9123. legend.lastItemY = 0;
  9124. if (!legendGroup) {
  9125. legend.group = legendGroup = renderer.g('legend')
  9126. .attr({ zIndex: 7 })
  9127. .add();
  9128. legend.contentGroup = renderer.g()
  9129. .attr({ zIndex: 1 }) // above background
  9130. .add(legendGroup);
  9131. legend.scrollGroup = renderer.g()
  9132. .add(legend.contentGroup);
  9133. }
  9134. legend.renderTitle();
  9135. // add each series or point
  9136. allItems = legend.getAllItems();
  9137. // sort by legendIndex
  9138. stableSort(allItems, function (a, b) {
  9139. return ((a.options && a.options.legendIndex) || 0) - ((b.options && b.options.legendIndex) || 0);
  9140. });
  9141. // reversed legend
  9142. if (options.reversed) {
  9143. allItems.reverse();
  9144. }
  9145. legend.allItems = allItems;
  9146. legend.display = display = !!allItems.length;
  9147. // render the items
  9148. legend.lastLineHeight = 0;
  9149. each(allItems, function (item) {
  9150. legend.renderItem(item);
  9151. });
  9152. // Get the box
  9153. legendWidth = (options.width || legend.offsetWidth) + padding;
  9154. legendHeight = legend.lastItemY + legend.lastLineHeight + legend.titleHeight;
  9155. legendHeight = legend.handleOverflow(legendHeight);
  9156. legendHeight += padding;
  9157. // Draw the border and/or background
  9158. if (legendBorderWidth || legendBackgroundColor) {
  9159. if (!box) {
  9160. legend.box = box = renderer.rect(
  9161. 0,
  9162. 0,
  9163. legendWidth,
  9164. legendHeight,
  9165. options.borderRadius,
  9166. legendBorderWidth || 0
  9167. ).attr({
  9168. stroke: options.borderColor,
  9169. 'stroke-width': legendBorderWidth || 0,
  9170. fill: legendBackgroundColor || NONE
  9171. })
  9172. .add(legendGroup)
  9173. .shadow(options.shadow);
  9174. box.isNew = true;
  9175. } else if (legendWidth > 0 && legendHeight > 0) {
  9176. box[box.isNew ? 'attr' : 'animate'](
  9177. box.crisp({ width: legendWidth, height: legendHeight })
  9178. );
  9179. box.isNew = false;
  9180. }
  9181. // hide the border if no items
  9182. box[display ? 'show' : 'hide']();
  9183. }
  9184. legend.legendWidth = legendWidth;
  9185. legend.legendHeight = legendHeight;
  9186. // Now that the legend width and height are established, put the items in the
  9187. // final position
  9188. each(allItems, function (item) {
  9189. legend.positionItem(item);
  9190. });
  9191. // 1.x compatibility: positioning based on style
  9192. /*var props = ['left', 'right', 'top', 'bottom'],
  9193. prop,
  9194. i = 4;
  9195. while (i--) {
  9196. prop = props[i];
  9197. if (options.style[prop] && options.style[prop] !== 'auto') {
  9198. options[i < 2 ? 'align' : 'verticalAlign'] = prop;
  9199. options[i < 2 ? 'x' : 'y'] = pInt(options.style[prop]) * (i % 2 ? -1 : 1);
  9200. }
  9201. }*/
  9202. if (display) {
  9203. legendGroup.align(extend({
  9204. width: legendWidth,
  9205. height: legendHeight
  9206. }, options), true, 'spacingBox');
  9207. }
  9208. if (!chart.isResizing) {
  9209. this.positionCheckboxes();
  9210. }
  9211. },
  9212. /**
  9213. * Set up the overflow handling by adding navigation with up and down arrows below the
  9214. * legend.
  9215. */
  9216. handleOverflow: function (legendHeight) {
  9217. var legend = this,
  9218. chart = this.chart,
  9219. renderer = chart.renderer,
  9220. options = this.options,
  9221. optionsY = options.y,
  9222. alignTop = options.verticalAlign === 'top',
  9223. spaceHeight = chart.spacingBox.height + (alignTop ? -optionsY : optionsY) - this.padding,
  9224. maxHeight = options.maxHeight,
  9225. clipHeight,
  9226. clipRect = this.clipRect,
  9227. navOptions = options.navigation,
  9228. animation = pick(navOptions.animation, true),
  9229. arrowSize = navOptions.arrowSize || 12,
  9230. nav = this.nav,
  9231. pages = this.pages,
  9232. padding = this.padding,
  9233. lastY,
  9234. allItems = this.allItems,
  9235. clipToHeight = function (height) {
  9236. clipRect.attr({
  9237. height: height
  9238. });
  9239. // useHTML
  9240. if (legend.contentGroup.div) {
  9241. legend.contentGroup.div.style.clip = 'rect(' + padding + 'px,9999px,' + (padding + height) + 'px,0)';
  9242. }
  9243. };
  9244. // Adjust the height
  9245. if (options.layout === 'horizontal') {
  9246. spaceHeight /= 2;
  9247. }
  9248. if (maxHeight) {
  9249. spaceHeight = mathMin(spaceHeight, maxHeight);
  9250. }
  9251. // Reset the legend height and adjust the clipping rectangle
  9252. pages.length = 0;
  9253. if (legendHeight > spaceHeight) {
  9254. this.clipHeight = clipHeight = mathMax(spaceHeight - 20 - this.titleHeight - padding, 0);
  9255. this.currentPage = pick(this.currentPage, 1);
  9256. this.fullHeight = legendHeight;
  9257. // Fill pages with Y positions so that the top of each a legend item defines
  9258. // the scroll top for each page (#2098)
  9259. each(allItems, function (item, i) {
  9260. var y = item._legendItemPos[1],
  9261. h = mathRound(item.legendItem.getBBox().height),
  9262. len = pages.length;
  9263. if (!len || (y - pages[len - 1] > clipHeight && (lastY || y) !== pages[len - 1])) {
  9264. pages.push(lastY || y);
  9265. len++;
  9266. }
  9267. if (i === allItems.length - 1 && y + h - pages[len - 1] > clipHeight) {
  9268. pages.push(y);
  9269. }
  9270. if (y !== lastY) {
  9271. lastY = y;
  9272. }
  9273. });
  9274. // Only apply clipping if needed. Clipping causes blurred legend in PDF export (#1787)
  9275. if (!clipRect) {
  9276. clipRect = legend.clipRect = renderer.clipRect(0, padding, 9999, 0);
  9277. legend.contentGroup.clip(clipRect);
  9278. }
  9279. clipToHeight(clipHeight);
  9280. // Add navigation elements
  9281. if (!nav) {
  9282. this.nav = nav = renderer.g().attr({ zIndex: 1 }).add(this.group);
  9283. this.up = renderer.symbol('triangle', 0, 0, arrowSize, arrowSize)
  9284. .on('click', function () {
  9285. legend.scroll(-1, animation);
  9286. })
  9287. .add(nav);
  9288. this.pager = renderer.text('', 15, 10)
  9289. .css(navOptions.style)
  9290. .add(nav);
  9291. this.down = renderer.symbol('triangle-down', 0, 0, arrowSize, arrowSize)
  9292. .on('click', function () {
  9293. legend.scroll(1, animation);
  9294. })
  9295. .add(nav);
  9296. }
  9297. // Set initial position
  9298. legend.scroll(0);
  9299. legendHeight = spaceHeight;
  9300. } else if (nav) {
  9301. clipToHeight(chart.chartHeight);
  9302. nav.hide();
  9303. this.scrollGroup.attr({
  9304. translateY: 1
  9305. });
  9306. this.clipHeight = 0; // #1379
  9307. }
  9308. return legendHeight;
  9309. },
  9310. /**
  9311. * Scroll the legend by a number of pages
  9312. * @param {Object} scrollBy
  9313. * @param {Object} animation
  9314. */
  9315. scroll: function (scrollBy, animation) {
  9316. var pages = this.pages,
  9317. pageCount = pages.length,
  9318. currentPage = this.currentPage + scrollBy,
  9319. clipHeight = this.clipHeight,
  9320. navOptions = this.options.navigation,
  9321. activeColor = navOptions.activeColor,
  9322. inactiveColor = navOptions.inactiveColor,
  9323. pager = this.pager,
  9324. padding = this.padding,
  9325. scrollOffset;
  9326. // When resizing while looking at the last page
  9327. if (currentPage > pageCount) {
  9328. currentPage = pageCount;
  9329. }
  9330. if (currentPage > 0) {
  9331. if (animation !== UNDEFINED) {
  9332. setAnimation(animation, this.chart);
  9333. }
  9334. this.nav.attr({
  9335. translateX: padding,
  9336. translateY: clipHeight + this.padding + 7 + this.titleHeight,
  9337. visibility: VISIBLE
  9338. });
  9339. this.up.attr({
  9340. fill: currentPage === 1 ? inactiveColor : activeColor
  9341. })
  9342. .css({
  9343. cursor: currentPage === 1 ? 'default' : 'pointer'
  9344. });
  9345. pager.attr({
  9346. text: currentPage + '/' + pageCount
  9347. });
  9348. this.down.attr({
  9349. x: 18 + this.pager.getBBox().width, // adjust to text width
  9350. fill: currentPage === pageCount ? inactiveColor : activeColor
  9351. })
  9352. .css({
  9353. cursor: currentPage === pageCount ? 'default' : 'pointer'
  9354. });
  9355. scrollOffset = -pages[currentPage - 1] + this.initialItemY;
  9356. this.scrollGroup.animate({
  9357. translateY: scrollOffset
  9358. });
  9359. this.currentPage = currentPage;
  9360. this.positionCheckboxes(scrollOffset);
  9361. }
  9362. }
  9363. };
  9364. /*
  9365. * LegendSymbolMixin
  9366. */
  9367. var LegendSymbolMixin = Highcharts.LegendSymbolMixin = {
  9368. /**
  9369. * Get the series' symbol in the legend
  9370. *
  9371. * @param {Object} legend The legend object
  9372. * @param {Object} item The series (this) or point
  9373. */
  9374. drawRectangle: function (legend, item) {
  9375. var symbolHeight = legend.options.symbolHeight || legend.fontMetrics.f;
  9376. item.legendSymbol = this.chart.renderer.rect(
  9377. 0,
  9378. legend.baseline - symbolHeight + 1, // #3988
  9379. legend.symbolWidth,
  9380. symbolHeight,
  9381. legend.options.symbolRadius || 0
  9382. ).attr({
  9383. zIndex: 3
  9384. }).add(item.legendGroup);
  9385. },
  9386. /**
  9387. * Get the series' symbol in the legend. This method should be overridable to create custom
  9388. * symbols through Highcharts.seriesTypes[type].prototype.drawLegendSymbols.
  9389. *
  9390. * @param {Object} legend The legend object
  9391. */
  9392. drawLineMarker: function (legend) {
  9393. var options = this.options,
  9394. markerOptions = options.marker,
  9395. radius,
  9396. legendSymbol,
  9397. symbolWidth = legend.symbolWidth,
  9398. renderer = this.chart.renderer,
  9399. legendItemGroup = this.legendGroup,
  9400. verticalCenter = legend.baseline - mathRound(legend.fontMetrics.b * 0.3),
  9401. attr;
  9402. // Draw the line
  9403. if (options.lineWidth) {
  9404. attr = {
  9405. 'stroke-width': options.lineWidth
  9406. };
  9407. if (options.dashStyle) {
  9408. attr.dashstyle = options.dashStyle;
  9409. }
  9410. this.legendLine = renderer.path([
  9411. M,
  9412. 0,
  9413. verticalCenter,
  9414. L,
  9415. symbolWidth,
  9416. verticalCenter
  9417. ])
  9418. .attr(attr)
  9419. .add(legendItemGroup);
  9420. }
  9421. // Draw the marker
  9422. if (markerOptions && markerOptions.enabled !== false) {
  9423. radius = markerOptions.radius;
  9424. this.legendSymbol = legendSymbol = renderer.symbol(
  9425. this.symbol,
  9426. (symbolWidth / 2) - radius,
  9427. verticalCenter - radius,
  9428. 2 * radius,
  9429. 2 * radius
  9430. )
  9431. .add(legendItemGroup);
  9432. legendSymbol.isMarker = true;
  9433. }
  9434. }
  9435. };
  9436. // Workaround for #2030, horizontal legend items not displaying in IE11 Preview,
  9437. // and for #2580, a similar drawing flaw in Firefox 26.
  9438. // TODO: Explore if there's a general cause for this. The problem may be related
  9439. // to nested group elements, as the legend item texts are within 4 group elements.
  9440. if (/Trident\/7\.0/.test(userAgent) || isFirefox) {
  9441. wrap(Legend.prototype, 'positionItem', function (proceed, item) {
  9442. var legend = this,
  9443. runPositionItem = function () { // If chart destroyed in sync, this is undefined (#2030)
  9444. if (item._legendItemPos) {
  9445. proceed.call(legend, item);
  9446. }
  9447. };
  9448. // Do it now, for export and to get checkbox placement
  9449. runPositionItem();
  9450. // Do it after to work around the core issue
  9451. setTimeout(runPositionItem);
  9452. });
  9453. }
  9454. /**
  9455. * The chart class
  9456. * @param {Object} options
  9457. * @param {Function} callback Function to run when the chart has loaded
  9458. */
  9459. var Chart = Highcharts.Chart = function () {
  9460. this.init.apply(this, arguments);
  9461. };
  9462. Chart.prototype = {
  9463. /**
  9464. * Hook for modules
  9465. */
  9466. callbacks: [],
  9467. /**
  9468. * Initialize the chart
  9469. */
  9470. init: function (userOptions, callback) {
  9471. // Handle regular options
  9472. var options,
  9473. seriesOptions = userOptions.series; // skip merging data points to increase performance
  9474. userOptions.series = null;
  9475. options = merge(defaultOptions, userOptions); // do the merge
  9476. options.series = userOptions.series = seriesOptions; // set back the series data
  9477. this.userOptions = userOptions;
  9478. var optionsChart = options.chart;
  9479. // Create margin & spacing array
  9480. this.margin = this.splashArray('margin', optionsChart);
  9481. this.spacing = this.splashArray('spacing', optionsChart);
  9482. var chartEvents = optionsChart.events;
  9483. //this.runChartClick = chartEvents && !!chartEvents.click;
  9484. this.bounds = { h: {}, v: {} }; // Pixel data bounds for touch zoom
  9485. this.callback = callback;
  9486. this.isResizing = 0;
  9487. this.options = options;
  9488. //chartTitleOptions = UNDEFINED;
  9489. //chartSubtitleOptions = UNDEFINED;
  9490. this.axes = [];
  9491. this.series = [];
  9492. this.hasCartesianSeries = optionsChart.showAxes;
  9493. //this.axisOffset = UNDEFINED;
  9494. //this.maxTicks = UNDEFINED; // handle the greatest amount of ticks on grouped axes
  9495. //this.inverted = UNDEFINED;
  9496. //this.loadingShown = UNDEFINED;
  9497. //this.container = UNDEFINED;
  9498. //this.chartWidth = UNDEFINED;
  9499. //this.chartHeight = UNDEFINED;
  9500. //this.marginRight = UNDEFINED;
  9501. //this.marginBottom = UNDEFINED;
  9502. //this.containerWidth = UNDEFINED;
  9503. //this.containerHeight = UNDEFINED;
  9504. //this.oldChartWidth = UNDEFINED;
  9505. //this.oldChartHeight = UNDEFINED;
  9506. //this.renderTo = UNDEFINED;
  9507. //this.renderToClone = UNDEFINED;
  9508. //this.spacingBox = UNDEFINED
  9509. //this.legend = UNDEFINED;
  9510. // Elements
  9511. //this.chartBackground = UNDEFINED;
  9512. //this.plotBackground = UNDEFINED;
  9513. //this.plotBGImage = UNDEFINED;
  9514. //this.plotBorder = UNDEFINED;
  9515. //this.loadingDiv = UNDEFINED;
  9516. //this.loadingSpan = UNDEFINED;
  9517. var chart = this,
  9518. eventType;
  9519. // Add the chart to the global lookup
  9520. chart.index = charts.length;
  9521. charts.push(chart);
  9522. chartCount++;
  9523. // Set up auto resize
  9524. if (optionsChart.reflow !== false) {
  9525. addEvent(chart, 'load', function () {
  9526. chart.initReflow();
  9527. });
  9528. }
  9529. // Chart event handlers
  9530. if (chartEvents) {
  9531. for (eventType in chartEvents) {
  9532. addEvent(chart, eventType, chartEvents[eventType]);
  9533. }
  9534. }
  9535. chart.xAxis = [];
  9536. chart.yAxis = [];
  9537. // Expose methods and variables
  9538. chart.animation = useCanVG ? false : pick(optionsChart.animation, true);
  9539. chart.pointCount = chart.colorCounter = chart.symbolCounter = 0;
  9540. chart.firstRender();
  9541. },
  9542. /**
  9543. * Initialize an individual series, called internally before render time
  9544. */
  9545. initSeries: function (options) {
  9546. var chart = this,
  9547. optionsChart = chart.options.chart,
  9548. type = options.type || optionsChart.type || optionsChart.defaultSeriesType,
  9549. series,
  9550. constr = seriesTypes[type];
  9551. // No such series type
  9552. if (!constr) {
  9553. error(17, true);
  9554. }
  9555. series = new constr();
  9556. series.init(this, options);
  9557. return series;
  9558. },
  9559. /**
  9560. * Check whether a given point is within the plot area
  9561. *
  9562. * @param {Number} plotX Pixel x relative to the plot area
  9563. * @param {Number} plotY Pixel y relative to the plot area
  9564. * @param {Boolean} inverted Whether the chart is inverted
  9565. */
  9566. isInsidePlot: function (plotX, plotY, inverted) {
  9567. var x = inverted ? plotY : plotX,
  9568. y = inverted ? plotX : plotY;
  9569. return x >= 0 &&
  9570. x <= this.plotWidth &&
  9571. y >= 0 &&
  9572. y <= this.plotHeight;
  9573. },
  9574. /**
  9575. * Redraw legend, axes or series based on updated data
  9576. *
  9577. * @param {Boolean|Object} animation Whether to apply animation, and optionally animation
  9578. * configuration
  9579. */
  9580. redraw: function (animation) {
  9581. var chart = this,
  9582. axes = chart.axes,
  9583. series = chart.series,
  9584. pointer = chart.pointer,
  9585. legend = chart.legend,
  9586. redrawLegend = chart.isDirtyLegend,
  9587. hasStackedSeries,
  9588. hasDirtyStacks,
  9589. hasCartesianSeries = chart.hasCartesianSeries,
  9590. isDirtyBox = chart.isDirtyBox, // todo: check if it has actually changed?
  9591. seriesLength = series.length,
  9592. i = seriesLength,
  9593. serie,
  9594. renderer = chart.renderer,
  9595. isHiddenChart = renderer.isHidden(),
  9596. afterRedraw = [];
  9597. setAnimation(animation, chart);
  9598. if (isHiddenChart) {
  9599. chart.cloneRenderTo();
  9600. }
  9601. // Adjust title layout (reflow multiline text)
  9602. chart.layOutTitles();
  9603. // link stacked series
  9604. while (i--) {
  9605. serie = series[i];
  9606. if (serie.options.stacking) {
  9607. hasStackedSeries = true;
  9608. if (serie.isDirty) {
  9609. hasDirtyStacks = true;
  9610. break;
  9611. }
  9612. }
  9613. }
  9614. if (hasDirtyStacks) { // mark others as dirty
  9615. i = seriesLength;
  9616. while (i--) {
  9617. serie = series[i];
  9618. if (serie.options.stacking) {
  9619. serie.isDirty = true;
  9620. }
  9621. }
  9622. }
  9623. // Handle updated data in the series
  9624. each(series, function (serie) {
  9625. if (serie.isDirty) {
  9626. if (serie.options.legendType === 'point') {
  9627. if (serie.updateTotals) {
  9628. serie.updateTotals();
  9629. }
  9630. redrawLegend = true;
  9631. }
  9632. }
  9633. });
  9634. // handle added or removed series
  9635. if (redrawLegend && legend.options.enabled) { // series or pie points are added or removed
  9636. // draw legend graphics
  9637. legend.render();
  9638. chart.isDirtyLegend = false;
  9639. }
  9640. // reset stacks
  9641. if (hasStackedSeries) {
  9642. chart.getStacks();
  9643. }
  9644. if (hasCartesianSeries) {
  9645. if (!chart.isResizing) {
  9646. // reset maxTicks
  9647. chart.maxTicks = null;
  9648. // set axes scales
  9649. each(axes, function (axis) {
  9650. axis.setScale();
  9651. });
  9652. }
  9653. }
  9654. chart.getMargins(); // #3098
  9655. if (hasCartesianSeries) {
  9656. // If one axis is dirty, all axes must be redrawn (#792, #2169)
  9657. each(axes, function (axis) {
  9658. if (axis.isDirty) {
  9659. isDirtyBox = true;
  9660. }
  9661. });
  9662. // redraw axes
  9663. each(axes, function (axis) {
  9664. // Fire 'afterSetExtremes' only if extremes are set
  9665. var key = axis.min + ',' + axis.max;
  9666. if (axis.extKey !== key) { // #821, #4452
  9667. axis.extKey = key;
  9668. afterRedraw.push(function () { // prevent a recursive call to chart.redraw() (#1119)
  9669. fireEvent(axis, 'afterSetExtremes', extend(axis.eventArgs, axis.getExtremes())); // #747, #751
  9670. delete axis.eventArgs;
  9671. });
  9672. }
  9673. if (isDirtyBox || hasStackedSeries) {
  9674. axis.redraw();
  9675. }
  9676. });
  9677. }
  9678. // the plot areas size has changed
  9679. if (isDirtyBox) {
  9680. chart.drawChartBox();
  9681. }
  9682. // redraw affected series
  9683. each(series, function (serie) {
  9684. if (serie.isDirty && serie.visible &&
  9685. (!serie.isCartesian || serie.xAxis)) { // issue #153
  9686. serie.redraw();
  9687. }
  9688. });
  9689. // move tooltip or reset
  9690. if (pointer) {
  9691. pointer.reset(true);
  9692. }
  9693. // redraw if canvas
  9694. renderer.draw();
  9695. // fire the event
  9696. fireEvent(chart, 'redraw'); // jQuery breaks this when calling it from addEvent. Overwrites chart.redraw
  9697. if (isHiddenChart) {
  9698. chart.cloneRenderTo(true);
  9699. }
  9700. // Fire callbacks that are put on hold until after the redraw
  9701. each(afterRedraw, function (callback) {
  9702. callback.call();
  9703. });
  9704. },
  9705. /**
  9706. * Get an axis, series or point object by id.
  9707. * @param id {String} The id as given in the configuration options
  9708. */
  9709. get: function (id) {
  9710. var chart = this,
  9711. axes = chart.axes,
  9712. series = chart.series;
  9713. var i,
  9714. j,
  9715. points;
  9716. // search axes
  9717. for (i = 0; i < axes.length; i++) {
  9718. if (axes[i].options.id === id) {
  9719. return axes[i];
  9720. }
  9721. }
  9722. // search series
  9723. for (i = 0; i < series.length; i++) {
  9724. if (series[i].options.id === id) {
  9725. return series[i];
  9726. }
  9727. }
  9728. // search points
  9729. for (i = 0; i < series.length; i++) {
  9730. points = series[i].points || [];
  9731. for (j = 0; j < points.length; j++) {
  9732. if (points[j].id === id) {
  9733. return points[j];
  9734. }
  9735. }
  9736. }
  9737. return null;
  9738. },
  9739. /**
  9740. * Create the Axis instances based on the config options
  9741. */
  9742. getAxes: function () {
  9743. var chart = this,
  9744. options = this.options,
  9745. xAxisOptions = options.xAxis = splat(options.xAxis || {}),
  9746. yAxisOptions = options.yAxis = splat(options.yAxis || {}),
  9747. optionsArray,
  9748. axis;
  9749. // make sure the options are arrays and add some members
  9750. each(xAxisOptions, function (axis, i) {
  9751. axis.index = i;
  9752. axis.isX = true;
  9753. });
  9754. each(yAxisOptions, function (axis, i) {
  9755. axis.index = i;
  9756. });
  9757. // concatenate all axis options into one array
  9758. optionsArray = xAxisOptions.concat(yAxisOptions);
  9759. each(optionsArray, function (axisOptions) {
  9760. axis = new Axis(chart, axisOptions);
  9761. });
  9762. },
  9763. /**
  9764. * Get the currently selected points from all series
  9765. */
  9766. getSelectedPoints: function () {
  9767. var points = [];
  9768. each(this.series, function (serie) {
  9769. points = points.concat(grep(serie.points || [], function (point) {
  9770. return point.selected;
  9771. }));
  9772. });
  9773. return points;
  9774. },
  9775. /**
  9776. * Get the currently selected series
  9777. */
  9778. getSelectedSeries: function () {
  9779. return grep(this.series, function (serie) {
  9780. return serie.selected;
  9781. });
  9782. },
  9783. /**
  9784. * Show the title and subtitle of the chart
  9785. *
  9786. * @param titleOptions {Object} New title options
  9787. * @param subtitleOptions {Object} New subtitle options
  9788. *
  9789. */
  9790. setTitle: function (titleOptions, subtitleOptions, redraw) {
  9791. var chart = this,
  9792. options = chart.options,
  9793. chartTitleOptions,
  9794. chartSubtitleOptions;
  9795. chartTitleOptions = options.title = merge(options.title, titleOptions);
  9796. chartSubtitleOptions = options.subtitle = merge(options.subtitle, subtitleOptions);
  9797. // add title and subtitle
  9798. each([
  9799. ['title', titleOptions, chartTitleOptions],
  9800. ['subtitle', subtitleOptions, chartSubtitleOptions]
  9801. ], function (arr) {
  9802. var name = arr[0],
  9803. title = chart[name],
  9804. titleOptions = arr[1],
  9805. chartTitleOptions = arr[2];
  9806. if (title && titleOptions) {
  9807. chart[name] = title = title.destroy(); // remove old
  9808. }
  9809. if (chartTitleOptions && chartTitleOptions.text && !title) {
  9810. chart[name] = chart.renderer.text(
  9811. chartTitleOptions.text,
  9812. 0,
  9813. 0,
  9814. chartTitleOptions.useHTML
  9815. )
  9816. .attr({
  9817. align: chartTitleOptions.align,
  9818. 'class': PREFIX + name,
  9819. zIndex: chartTitleOptions.zIndex || 4
  9820. })
  9821. .css(chartTitleOptions.style)
  9822. .add();
  9823. }
  9824. });
  9825. chart.layOutTitles(redraw);
  9826. },
  9827. /**
  9828. * Lay out the chart titles and cache the full offset height for use in getMargins
  9829. */
  9830. layOutTitles: function (redraw) {
  9831. var titleOffset = 0,
  9832. title = this.title,
  9833. subtitle = this.subtitle,
  9834. options = this.options,
  9835. titleOptions = options.title,
  9836. subtitleOptions = options.subtitle,
  9837. requiresDirtyBox,
  9838. renderer = this.renderer,
  9839. autoWidth = this.spacingBox.width - 44; // 44 makes room for default context button
  9840. if (title) {
  9841. title
  9842. .css({ width: (titleOptions.width || autoWidth) + PX })
  9843. .align(extend({
  9844. y: renderer.fontMetrics(titleOptions.style.fontSize, title).b - 3
  9845. }, titleOptions), false, 'spacingBox');
  9846. if (!titleOptions.floating && !titleOptions.verticalAlign) {
  9847. titleOffset = title.getBBox().height;
  9848. }
  9849. }
  9850. if (subtitle) {
  9851. subtitle
  9852. .css({ width: (subtitleOptions.width || autoWidth) + PX })
  9853. .align(extend({
  9854. y: titleOffset + (titleOptions.margin - 13) + renderer.fontMetrics(subtitleOptions.style.fontSize, title).b
  9855. }, subtitleOptions), false, 'spacingBox');
  9856. if (!subtitleOptions.floating && !subtitleOptions.verticalAlign) {
  9857. titleOffset = mathCeil(titleOffset + subtitle.getBBox().height);
  9858. }
  9859. }
  9860. requiresDirtyBox = this.titleOffset !== titleOffset;
  9861. this.titleOffset = titleOffset; // used in getMargins
  9862. if (!this.isDirtyBox && requiresDirtyBox) {
  9863. this.isDirtyBox = requiresDirtyBox;
  9864. // Redraw if necessary (#2719, #2744)
  9865. if (this.hasRendered && pick(redraw, true) && this.isDirtyBox) {
  9866. this.redraw();
  9867. }
  9868. }
  9869. },
  9870. /**
  9871. * Get chart width and height according to options and container size
  9872. */
  9873. getChartSize: function () {
  9874. var chart = this,
  9875. optionsChart = chart.options.chart,
  9876. widthOption = optionsChart.width,
  9877. heightOption = optionsChart.height,
  9878. renderTo = chart.renderToClone || chart.renderTo;
  9879. // get inner width and height from jQuery (#824)
  9880. if (!defined(widthOption)) {
  9881. chart.containerWidth = adapterRun(renderTo, 'width');
  9882. }
  9883. if (!defined(heightOption)) {
  9884. chart.containerHeight = adapterRun(renderTo, 'height');
  9885. }
  9886. chart.chartWidth = mathMax(0, widthOption || chart.containerWidth || 600); // #1393, 1460
  9887. chart.chartHeight = mathMax(0, pick(heightOption,
  9888. // the offsetHeight of an empty container is 0 in standard browsers, but 19 in IE7:
  9889. chart.containerHeight > 19 ? chart.containerHeight : 400));
  9890. },
  9891. /**
  9892. * Create a clone of the chart's renderTo div and place it outside the viewport to allow
  9893. * size computation on chart.render and chart.redraw
  9894. */
  9895. cloneRenderTo: function (revert) {
  9896. var clone = this.renderToClone,
  9897. container = this.container;
  9898. // Destroy the clone and bring the container back to the real renderTo div
  9899. if (revert) {
  9900. if (clone) {
  9901. this.renderTo.appendChild(container);
  9902. discardElement(clone);
  9903. delete this.renderToClone;
  9904. }
  9905. // Set up the clone
  9906. } else {
  9907. if (container && container.parentNode === this.renderTo) {
  9908. this.renderTo.removeChild(container); // do not clone this
  9909. }
  9910. this.renderToClone = clone = this.renderTo.cloneNode(0);
  9911. css(clone, {
  9912. position: ABSOLUTE,
  9913. top: '-9999px',
  9914. display: 'block' // #833
  9915. });
  9916. if (clone.style.setProperty) { // #2631
  9917. clone.style.setProperty('display', 'block', 'important');
  9918. }
  9919. doc.body.appendChild(clone);
  9920. if (container) {
  9921. clone.appendChild(container);
  9922. }
  9923. }
  9924. },
  9925. /**
  9926. * Get the containing element, determine the size and create the inner container
  9927. * div to hold the chart
  9928. */
  9929. getContainer: function () {
  9930. var chart = this,
  9931. container,
  9932. options = chart.options,
  9933. optionsChart = options.chart,
  9934. chartWidth,
  9935. chartHeight,
  9936. renderTo,
  9937. indexAttrName = 'data-highcharts-chart',
  9938. oldChartIndex,
  9939. Ren,
  9940. containerId;
  9941. chart.renderTo = renderTo = optionsChart.renderTo;
  9942. containerId = PREFIX + idCounter++;
  9943. if (isString(renderTo)) {
  9944. chart.renderTo = renderTo = doc.getElementById(renderTo);
  9945. }
  9946. // Display an error if the renderTo is wrong
  9947. if (!renderTo) {
  9948. error(13, true);
  9949. }
  9950. // If the container already holds a chart, destroy it. The check for hasRendered is there
  9951. // because web pages that are saved to disk from the browser, will preserve the data-highcharts-chart
  9952. // attribute and the SVG contents, but not an interactive chart. So in this case,
  9953. // charts[oldChartIndex] will point to the wrong chart if any (#2609).
  9954. oldChartIndex = pInt(attr(renderTo, indexAttrName));
  9955. if (!isNaN(oldChartIndex) && charts[oldChartIndex] && charts[oldChartIndex].hasRendered) {
  9956. charts[oldChartIndex].destroy();
  9957. }
  9958. // Make a reference to the chart from the div
  9959. attr(renderTo, indexAttrName, chart.index);
  9960. // remove previous chart
  9961. renderTo.innerHTML = '';
  9962. // If the container doesn't have an offsetWidth, it has or is a child of a node
  9963. // that has display:none. We need to temporarily move it out to a visible
  9964. // state to determine the size, else the legend and tooltips won't render
  9965. // properly. The allowClone option is used in sparklines as a micro optimization,
  9966. // saving about 1-2 ms each chart.
  9967. if (!optionsChart.skipClone && !renderTo.offsetWidth) {
  9968. chart.cloneRenderTo();
  9969. }
  9970. // get the width and height
  9971. chart.getChartSize();
  9972. chartWidth = chart.chartWidth;
  9973. chartHeight = chart.chartHeight;
  9974. // create the inner container
  9975. chart.container = container = createElement(DIV, {
  9976. className: PREFIX + 'container' +
  9977. (optionsChart.className ? ' ' + optionsChart.className : ''),
  9978. id: containerId
  9979. }, extend({
  9980. position: RELATIVE,
  9981. overflow: HIDDEN, // needed for context menu (avoid scrollbars) and
  9982. // content overflow in IE
  9983. width: chartWidth + PX,
  9984. height: chartHeight + PX,
  9985. textAlign: 'left',
  9986. lineHeight: 'normal', // #427
  9987. zIndex: 0, // #1072
  9988. '-webkit-tap-highlight-color': 'rgba(0,0,0,0)'
  9989. }, optionsChart.style),
  9990. chart.renderToClone || renderTo
  9991. );
  9992. // cache the cursor (#1650)
  9993. chart._cursor = container.style.cursor;
  9994. // Initialize the renderer
  9995. Ren = Highcharts[optionsChart.renderer] || Renderer;
  9996. chart.renderer = new Ren(
  9997. container,
  9998. chartWidth,
  9999. chartHeight,
  10000. optionsChart.style,
  10001. optionsChart.forExport,
  10002. options.exporting && options.exporting.allowHTML
  10003. );
  10004. if (useCanVG) {
  10005. // If we need canvg library, extend and configure the renderer
  10006. // to get the tracker for translating mouse events
  10007. chart.renderer.create(chart, container, chartWidth, chartHeight);
  10008. }
  10009. // Add a reference to the charts index
  10010. chart.renderer.chartIndex = chart.index;
  10011. },
  10012. /**
  10013. * Calculate margins by rendering axis labels in a preliminary position. Title,
  10014. * subtitle and legend have already been rendered at this stage, but will be
  10015. * moved into their final positions
  10016. */
  10017. getMargins: function (skipAxes) {
  10018. var chart = this,
  10019. spacing = chart.spacing,
  10020. margin = chart.margin,
  10021. titleOffset = chart.titleOffset;
  10022. chart.resetMargins();
  10023. // Adjust for title and subtitle
  10024. if (titleOffset && !defined(margin[0])) {
  10025. chart.plotTop = mathMax(chart.plotTop, titleOffset + chart.options.title.margin + spacing[0]);
  10026. }
  10027. // Adjust for legend
  10028. chart.legend.adjustMargins(margin, spacing);
  10029. // adjust for scroller
  10030. if (chart.extraBottomMargin) {
  10031. chart.marginBottom += chart.extraBottomMargin;
  10032. }
  10033. if (chart.extraTopMargin) {
  10034. chart.plotTop += chart.extraTopMargin;
  10035. }
  10036. if (!skipAxes) {
  10037. this.getAxisMargins();
  10038. }
  10039. },
  10040. getAxisMargins: function () {
  10041. var chart = this,
  10042. axisOffset = chart.axisOffset = [0, 0, 0, 0], // top, right, bottom, left
  10043. margin = chart.margin;
  10044. // pre-render axes to get labels offset width
  10045. if (chart.hasCartesianSeries) {
  10046. each(chart.axes, function (axis) {
  10047. if (axis.visible) {
  10048. axis.getOffset();
  10049. }
  10050. });
  10051. }
  10052. // Add the axis offsets
  10053. each(marginNames, function (m, side) {
  10054. if (!defined(margin[side])) {
  10055. chart[m] += axisOffset[side];
  10056. }
  10057. });
  10058. chart.setChartSize();
  10059. },
  10060. /**
  10061. * Resize the chart to its container if size is not explicitly set
  10062. */
  10063. reflow: function (e) {
  10064. var chart = this,
  10065. optionsChart = chart.options.chart,
  10066. renderTo = chart.renderTo,
  10067. width = optionsChart.width || adapterRun(renderTo, 'width'),
  10068. height = optionsChart.height || adapterRun(renderTo, 'height'),
  10069. target = e ? e.target : win, // #805 - MooTools doesn't supply e
  10070. doReflow = function () {
  10071. if (chart.container) { // It may have been destroyed in the meantime (#1257)
  10072. chart.setSize(width, height, false);
  10073. chart.hasUserSize = null;
  10074. }
  10075. };
  10076. // Width and height checks for display:none. Target is doc in IE8 and Opera,
  10077. // win in Firefox, Chrome and IE9.
  10078. if (!chart.hasUserSize && !chart.isPrinting && width && height && (target === win || target === doc)) { // #1093
  10079. if (width !== chart.containerWidth || height !== chart.containerHeight) {
  10080. clearTimeout(chart.reflowTimeout);
  10081. if (e) { // Called from window.resize
  10082. chart.reflowTimeout = setTimeout(doReflow, 100);
  10083. } else { // Called directly (#2224)
  10084. doReflow();
  10085. }
  10086. }
  10087. chart.containerWidth = width;
  10088. chart.containerHeight = height;
  10089. }
  10090. },
  10091. /**
  10092. * Add the event handlers necessary for auto resizing
  10093. */
  10094. initReflow: function () {
  10095. var chart = this,
  10096. reflow = function (e) {
  10097. chart.reflow(e);
  10098. };
  10099. addEvent(win, 'resize', reflow);
  10100. addEvent(chart, 'destroy', function () {
  10101. removeEvent(win, 'resize', reflow);
  10102. });
  10103. },
  10104. /**
  10105. * Resize the chart to a given width and height
  10106. * @param {Number} width
  10107. * @param {Number} height
  10108. * @param {Object|Boolean} animation
  10109. */
  10110. setSize: function (width, height, animation) {
  10111. var chart = this,
  10112. chartWidth,
  10113. chartHeight,
  10114. fireEndResize,
  10115. renderer = chart.renderer,
  10116. globalAnimation;
  10117. // Handle the isResizing counter
  10118. chart.isResizing += 1;
  10119. fireEndResize = function () {
  10120. if (chart) {
  10121. fireEvent(chart, 'endResize', null, function () {
  10122. chart.isResizing -= 1;
  10123. });
  10124. }
  10125. };
  10126. // set the animation for the current process
  10127. setAnimation(animation, chart);
  10128. chart.oldChartHeight = chart.chartHeight;
  10129. chart.oldChartWidth = chart.chartWidth;
  10130. if (defined(width)) {
  10131. chart.chartWidth = chartWidth = mathMax(0, mathRound(width));
  10132. chart.hasUserSize = !!chartWidth;
  10133. }
  10134. if (defined(height)) {
  10135. chart.chartHeight = chartHeight = mathMax(0, mathRound(height));
  10136. }
  10137. // Resize the container with the global animation applied if enabled (#2503)
  10138. globalAnimation = renderer.globalAnimation;
  10139. (globalAnimation ? animate : css)(chart.container, {
  10140. width: chartWidth + PX,
  10141. height: chartHeight + PX
  10142. }, globalAnimation);
  10143. chart.setChartSize(true);
  10144. renderer.setSize(chartWidth, chartHeight, animation);
  10145. // handle axes
  10146. chart.maxTicks = null;
  10147. each(chart.axes, function (axis) {
  10148. axis.isDirty = true;
  10149. axis.setScale();
  10150. });
  10151. // make sure non-cartesian series are also handled
  10152. each(chart.series, function (serie) {
  10153. serie.isDirty = true;
  10154. });
  10155. chart.isDirtyLegend = true; // force legend redraw
  10156. chart.isDirtyBox = true; // force redraw of plot and chart border
  10157. chart.layOutTitles(); // #2857
  10158. chart.getMargins();
  10159. chart.redraw(animation);
  10160. chart.oldChartHeight = null;
  10161. fireEvent(chart, 'resize');
  10162. // Fire endResize and set isResizing back. If animation is disabled, fire without delay
  10163. globalAnimation = renderer.globalAnimation; // Reassign it before using it, it may have changed since the top of this function.
  10164. if (globalAnimation === false) {
  10165. fireEndResize();
  10166. } else { // else set a timeout with the animation duration
  10167. setTimeout(fireEndResize, (globalAnimation && globalAnimation.duration) || 500);
  10168. }
  10169. },
  10170. /**
  10171. * Set the public chart properties. This is done before and after the pre-render
  10172. * to determine margin sizes
  10173. */
  10174. setChartSize: function (skipAxes) {
  10175. var chart = this,
  10176. inverted = chart.inverted,
  10177. renderer = chart.renderer,
  10178. chartWidth = chart.chartWidth,
  10179. chartHeight = chart.chartHeight,
  10180. optionsChart = chart.options.chart,
  10181. spacing = chart.spacing,
  10182. clipOffset = chart.clipOffset,
  10183. clipX,
  10184. clipY,
  10185. plotLeft,
  10186. plotTop,
  10187. plotWidth,
  10188. plotHeight,
  10189. plotBorderWidth;
  10190. chart.plotLeft = plotLeft = mathRound(chart.plotLeft);
  10191. chart.plotTop = plotTop = mathRound(chart.plotTop);
  10192. chart.plotWidth = plotWidth = mathMax(0, mathRound(chartWidth - plotLeft - chart.marginRight));
  10193. chart.plotHeight = plotHeight = mathMax(0, mathRound(chartHeight - plotTop - chart.marginBottom));
  10194. chart.plotSizeX = inverted ? plotHeight : plotWidth;
  10195. chart.plotSizeY = inverted ? plotWidth : plotHeight;
  10196. chart.plotBorderWidth = optionsChart.plotBorderWidth || 0;
  10197. // Set boxes used for alignment
  10198. chart.spacingBox = renderer.spacingBox = {
  10199. x: spacing[3],
  10200. y: spacing[0],
  10201. width: chartWidth - spacing[3] - spacing[1],
  10202. height: chartHeight - spacing[0] - spacing[2]
  10203. };
  10204. chart.plotBox = renderer.plotBox = {
  10205. x: plotLeft,
  10206. y: plotTop,
  10207. width: plotWidth,
  10208. height: plotHeight
  10209. };
  10210. plotBorderWidth = 2 * mathFloor(chart.plotBorderWidth / 2);
  10211. clipX = mathCeil(mathMax(plotBorderWidth, clipOffset[3]) / 2);
  10212. clipY = mathCeil(mathMax(plotBorderWidth, clipOffset[0]) / 2);
  10213. chart.clipBox = {
  10214. x: clipX,
  10215. y: clipY,
  10216. width: mathFloor(chart.plotSizeX - mathMax(plotBorderWidth, clipOffset[1]) / 2 - clipX),
  10217. height: mathMax(0, mathFloor(chart.plotSizeY - mathMax(plotBorderWidth, clipOffset[2]) / 2 - clipY))
  10218. };
  10219. if (!skipAxes) {
  10220. each(chart.axes, function (axis) {
  10221. axis.setAxisSize();
  10222. axis.setAxisTranslation();
  10223. });
  10224. }
  10225. },
  10226. /**
  10227. * Initial margins before auto size margins are applied
  10228. */
  10229. resetMargins: function () {
  10230. var chart = this;
  10231. each(marginNames, function (m, side) {
  10232. chart[m] = pick(chart.margin[side], chart.spacing[side]);
  10233. });
  10234. chart.axisOffset = [0, 0, 0, 0]; // top, right, bottom, left
  10235. chart.clipOffset = [0, 0, 0, 0];
  10236. },
  10237. /**
  10238. * Draw the borders and backgrounds for chart and plot area
  10239. */
  10240. drawChartBox: function () {
  10241. var chart = this,
  10242. optionsChart = chart.options.chart,
  10243. renderer = chart.renderer,
  10244. chartWidth = chart.chartWidth,
  10245. chartHeight = chart.chartHeight,
  10246. chartBackground = chart.chartBackground,
  10247. plotBackground = chart.plotBackground,
  10248. plotBorder = chart.plotBorder,
  10249. plotBGImage = chart.plotBGImage,
  10250. chartBorderWidth = optionsChart.borderWidth || 0,
  10251. chartBackgroundColor = optionsChart.backgroundColor,
  10252. plotBackgroundColor = optionsChart.plotBackgroundColor,
  10253. plotBackgroundImage = optionsChart.plotBackgroundImage,
  10254. plotBorderWidth = optionsChart.plotBorderWidth || 0,
  10255. mgn,
  10256. bgAttr,
  10257. plotLeft = chart.plotLeft,
  10258. plotTop = chart.plotTop,
  10259. plotWidth = chart.plotWidth,
  10260. plotHeight = chart.plotHeight,
  10261. plotBox = chart.plotBox,
  10262. clipRect = chart.clipRect,
  10263. clipBox = chart.clipBox;
  10264. // Chart area
  10265. mgn = chartBorderWidth + (optionsChart.shadow ? 8 : 0);
  10266. if (chartBorderWidth || chartBackgroundColor) {
  10267. if (!chartBackground) {
  10268. bgAttr = {
  10269. fill: chartBackgroundColor || NONE
  10270. };
  10271. if (chartBorderWidth) { // #980
  10272. bgAttr.stroke = optionsChart.borderColor;
  10273. bgAttr['stroke-width'] = chartBorderWidth;
  10274. }
  10275. chart.chartBackground = renderer.rect(mgn / 2, mgn / 2, chartWidth - mgn, chartHeight - mgn,
  10276. optionsChart.borderRadius, chartBorderWidth)
  10277. .attr(bgAttr)
  10278. .addClass(PREFIX + 'background')
  10279. .add()
  10280. .shadow(optionsChart.shadow);
  10281. } else { // resize
  10282. chartBackground.animate(
  10283. chartBackground.crisp({ width: chartWidth - mgn, height: chartHeight - mgn })
  10284. );
  10285. }
  10286. }
  10287. // Plot background
  10288. if (plotBackgroundColor) {
  10289. if (!plotBackground) {
  10290. chart.plotBackground = renderer.rect(plotLeft, plotTop, plotWidth, plotHeight, 0)
  10291. .attr({
  10292. fill: plotBackgroundColor
  10293. })
  10294. .add()
  10295. .shadow(optionsChart.plotShadow);
  10296. } else {
  10297. plotBackground.animate(plotBox);
  10298. }
  10299. }
  10300. if (plotBackgroundImage) {
  10301. if (!plotBGImage) {
  10302. chart.plotBGImage = renderer.image(plotBackgroundImage, plotLeft, plotTop, plotWidth, plotHeight)
  10303. .add();
  10304. } else {
  10305. plotBGImage.animate(plotBox);
  10306. }
  10307. }
  10308. // Plot clip
  10309. if (!clipRect) {
  10310. chart.clipRect = renderer.clipRect(clipBox);
  10311. } else {
  10312. clipRect.animate({
  10313. width: clipBox.width,
  10314. height: clipBox.height
  10315. });
  10316. }
  10317. // Plot area border
  10318. if (plotBorderWidth) {
  10319. if (!plotBorder) {
  10320. chart.plotBorder = renderer.rect(plotLeft, plotTop, plotWidth, plotHeight, 0, -plotBorderWidth)
  10321. .attr({
  10322. stroke: optionsChart.plotBorderColor,
  10323. 'stroke-width': plotBorderWidth,
  10324. fill: NONE,
  10325. zIndex: 1
  10326. })
  10327. .add();
  10328. } else {
  10329. plotBorder.animate(
  10330. plotBorder.crisp({ x: plotLeft, y: plotTop, width: plotWidth, height: plotHeight, strokeWidth: -plotBorderWidth }) //#3282 plotBorder should be negative
  10331. );
  10332. }
  10333. }
  10334. // reset
  10335. chart.isDirtyBox = false;
  10336. },
  10337. /**
  10338. * Detect whether a certain chart property is needed based on inspecting its options
  10339. * and series. This mainly applies to the chart.invert property, and in extensions to
  10340. * the chart.angular and chart.polar properties.
  10341. */
  10342. propFromSeries: function () {
  10343. var chart = this,
  10344. optionsChart = chart.options.chart,
  10345. klass,
  10346. seriesOptions = chart.options.series,
  10347. i,
  10348. value;
  10349. each(['inverted', 'angular', 'polar'], function (key) {
  10350. // The default series type's class
  10351. klass = seriesTypes[optionsChart.type || optionsChart.defaultSeriesType];
  10352. // Get the value from available chart-wide properties
  10353. value = (
  10354. chart[key] || // 1. it is set before
  10355. optionsChart[key] || // 2. it is set in the options
  10356. (klass && klass.prototype[key]) // 3. it's default series class requires it
  10357. );
  10358. // 4. Check if any the chart's series require it
  10359. i = seriesOptions && seriesOptions.length;
  10360. while (!value && i--) {
  10361. klass = seriesTypes[seriesOptions[i].type];
  10362. if (klass && klass.prototype[key]) {
  10363. value = true;
  10364. }
  10365. }
  10366. // Set the chart property
  10367. chart[key] = value;
  10368. });
  10369. },
  10370. /**
  10371. * Link two or more series together. This is done initially from Chart.render,
  10372. * and after Chart.addSeries and Series.remove.
  10373. */
  10374. linkSeries: function () {
  10375. var chart = this,
  10376. chartSeries = chart.series;
  10377. // Reset links
  10378. each(chartSeries, function (series) {
  10379. series.linkedSeries.length = 0;
  10380. });
  10381. // Apply new links
  10382. each(chartSeries, function (series) {
  10383. var linkedTo = series.options.linkedTo;
  10384. if (isString(linkedTo)) {
  10385. if (linkedTo === ':previous') {
  10386. linkedTo = chart.series[series.index - 1];
  10387. } else {
  10388. linkedTo = chart.get(linkedTo);
  10389. }
  10390. if (linkedTo) {
  10391. linkedTo.linkedSeries.push(series);
  10392. series.linkedParent = linkedTo;
  10393. series.visible = pick(series.options.visible, linkedTo.options.visible, series.visible); // #3879
  10394. }
  10395. }
  10396. });
  10397. },
  10398. /**
  10399. * Render series for the chart
  10400. */
  10401. renderSeries: function () {
  10402. each(this.series, function (serie) {
  10403. serie.translate();
  10404. serie.render();
  10405. });
  10406. },
  10407. /**
  10408. * Render labels for the chart
  10409. */
  10410. renderLabels: function () {
  10411. var chart = this,
  10412. labels = chart.options.labels;
  10413. if (labels.items) {
  10414. each(labels.items, function (label) {
  10415. var style = extend(labels.style, label.style),
  10416. x = pInt(style.left) + chart.plotLeft,
  10417. y = pInt(style.top) + chart.plotTop + 12;
  10418. // delete to prevent rewriting in IE
  10419. delete style.left;
  10420. delete style.top;
  10421. chart.renderer.text(
  10422. label.html,
  10423. x,
  10424. y
  10425. )
  10426. .attr({ zIndex: 2 })
  10427. .css(style)
  10428. .add();
  10429. });
  10430. }
  10431. },
  10432. /**
  10433. * Render all graphics for the chart
  10434. */
  10435. render: function () {
  10436. var chart = this,
  10437. axes = chart.axes,
  10438. renderer = chart.renderer,
  10439. options = chart.options,
  10440. tempWidth,
  10441. tempHeight,
  10442. redoHorizontal,
  10443. redoVertical;
  10444. // Title
  10445. chart.setTitle();
  10446. // Legend
  10447. chart.legend = new Legend(chart, options.legend);
  10448. // Get stacks
  10449. if (chart.getStacks) {
  10450. chart.getStacks();
  10451. }
  10452. // Get chart margins
  10453. chart.getMargins(true);
  10454. chart.setChartSize();
  10455. // Record preliminary dimensions for later comparison
  10456. tempWidth = chart.plotWidth;
  10457. tempHeight = chart.plotHeight = chart.plotHeight - 13; // 13 is the most common height of X axis labels
  10458. // Get margins by pre-rendering axes
  10459. each(axes, function (axis) {
  10460. axis.setScale();
  10461. });
  10462. chart.getAxisMargins();
  10463. // If the plot area size has changed significantly, calculate tick positions again
  10464. redoHorizontal = tempWidth / chart.plotWidth > 1.1;
  10465. redoVertical = tempHeight / chart.plotHeight > 1.1;
  10466. if (redoHorizontal || redoVertical) {
  10467. chart.maxTicks = null; // reset for second pass
  10468. each(axes, function (axis) {
  10469. if ((axis.horiz && redoHorizontal) || (!axis.horiz && redoVertical)) {
  10470. axis.setTickInterval(true); // update to reflect the new margins
  10471. }
  10472. });
  10473. chart.getMargins(); // second pass to check for new labels
  10474. }
  10475. // Draw the borders and backgrounds
  10476. chart.drawChartBox();
  10477. // Axes
  10478. if (chart.hasCartesianSeries) {
  10479. each(axes, function (axis) {
  10480. if (axis.visible) {
  10481. axis.render();
  10482. }
  10483. });
  10484. }
  10485. // The series
  10486. if (!chart.seriesGroup) {
  10487. chart.seriesGroup = renderer.g('series-group')
  10488. .attr({ zIndex: 3 })
  10489. .add();
  10490. }
  10491. chart.renderSeries();
  10492. // Labels
  10493. chart.renderLabels();
  10494. // Credits
  10495. chart.showCredits(options.credits);
  10496. // Set flag
  10497. chart.hasRendered = true;
  10498. },
  10499. /**
  10500. * Show chart credits based on config options
  10501. */
  10502. showCredits: function (credits) {
  10503. if (credits.enabled && !this.credits) {
  10504. this.credits = this.renderer.text(
  10505. credits.text,
  10506. 0,
  10507. 0
  10508. )
  10509. .on('click', function () {
  10510. if (credits.href) {
  10511. location.href = credits.href;
  10512. }
  10513. })
  10514. .attr({
  10515. align: credits.position.align,
  10516. zIndex: 8
  10517. })
  10518. .css(credits.style)
  10519. .add()
  10520. .align(credits.position);
  10521. }
  10522. },
  10523. /**
  10524. * Clean up memory usage
  10525. */
  10526. destroy: function () {
  10527. var chart = this,
  10528. axes = chart.axes,
  10529. series = chart.series,
  10530. container = chart.container,
  10531. i,
  10532. parentNode = container && container.parentNode;
  10533. // fire the chart.destoy event
  10534. fireEvent(chart, 'destroy');
  10535. // Delete the chart from charts lookup array
  10536. charts[chart.index] = UNDEFINED;
  10537. chartCount--;
  10538. chart.renderTo.removeAttribute('data-highcharts-chart');
  10539. // remove events
  10540. removeEvent(chart);
  10541. // ==== Destroy collections:
  10542. // Destroy axes
  10543. i = axes.length;
  10544. while (i--) {
  10545. axes[i] = axes[i].destroy();
  10546. }
  10547. // Destroy each series
  10548. i = series.length;
  10549. while (i--) {
  10550. series[i] = series[i].destroy();
  10551. }
  10552. // ==== Destroy chart properties:
  10553. each(['title', 'subtitle', 'chartBackground', 'plotBackground', 'plotBGImage',
  10554. 'plotBorder', 'seriesGroup', 'clipRect', 'credits', 'pointer', 'scroller',
  10555. 'rangeSelector', 'legend', 'resetZoomButton', 'tooltip', 'renderer'], function (name) {
  10556. var prop = chart[name];
  10557. if (prop && prop.destroy) {
  10558. chart[name] = prop.destroy();
  10559. }
  10560. });
  10561. // remove container and all SVG
  10562. if (container) { // can break in IE when destroyed before finished loading
  10563. container.innerHTML = '';
  10564. removeEvent(container);
  10565. if (parentNode) {
  10566. discardElement(container);
  10567. }
  10568. }
  10569. // clean it all up
  10570. for (i in chart) {
  10571. delete chart[i];
  10572. }
  10573. },
  10574. /**
  10575. * VML namespaces can't be added until after complete. Listening
  10576. * for Perini's doScroll hack is not enough.
  10577. */
  10578. isReadyToRender: function () {
  10579. var chart = this;
  10580. // Note: in spite of JSLint's complaints, win == win.top is required
  10581. /*jslint eqeq: true*/
  10582. if ((!hasSVG && (win == win.top && doc.readyState !== 'complete')) || (useCanVG && !win.canvg)) {
  10583. /*jslint eqeq: false*/
  10584. if (useCanVG) {
  10585. // Delay rendering until canvg library is downloaded and ready
  10586. CanVGController.push(function () { chart.firstRender(); }, chart.options.global.canvasToolsURL);
  10587. } else {
  10588. doc.attachEvent('onreadystatechange', function () {
  10589. doc.detachEvent('onreadystatechange', chart.firstRender);
  10590. if (doc.readyState === 'complete') {
  10591. chart.firstRender();
  10592. }
  10593. });
  10594. }
  10595. return false;
  10596. }
  10597. return true;
  10598. },
  10599. /**
  10600. * Prepare for first rendering after all data are loaded
  10601. */
  10602. firstRender: function () {
  10603. var chart = this,
  10604. options = chart.options,
  10605. callback = chart.callback;
  10606. // Check whether the chart is ready to render
  10607. if (!chart.isReadyToRender()) {
  10608. return;
  10609. }
  10610. // Create the container
  10611. chart.getContainer();
  10612. // Run an early event after the container and renderer are established
  10613. fireEvent(chart, 'init');
  10614. chart.resetMargins();
  10615. chart.setChartSize();
  10616. // Set the common chart properties (mainly invert) from the given series
  10617. chart.propFromSeries();
  10618. // get axes
  10619. chart.getAxes();
  10620. // Initialize the series
  10621. each(options.series || [], function (serieOptions) {
  10622. chart.initSeries(serieOptions);
  10623. });
  10624. chart.linkSeries();
  10625. // Run an event after axes and series are initialized, but before render. At this stage,
  10626. // the series data is indexed and cached in the xData and yData arrays, so we can access
  10627. // those before rendering. Used in Highstock.
  10628. fireEvent(chart, 'beforeRender');
  10629. // depends on inverted and on margins being set
  10630. if (Highcharts.Pointer) {
  10631. chart.pointer = new Pointer(chart, options);
  10632. }
  10633. chart.render();
  10634. // add canvas
  10635. chart.renderer.draw();
  10636. // run callbacks
  10637. if (callback) {
  10638. callback.apply(chart, [chart]);
  10639. }
  10640. each(chart.callbacks, function (fn) {
  10641. if (chart.index !== UNDEFINED) { // Chart destroyed in its own callback (#3600)
  10642. fn.apply(chart, [chart]);
  10643. }
  10644. });
  10645. // Fire the load event
  10646. fireEvent(chart, 'load');
  10647. // If the chart was rendered outside the top container, put it back in (#3679)
  10648. chart.cloneRenderTo(true);
  10649. },
  10650. /**
  10651. * Creates arrays for spacing and margin from given options.
  10652. */
  10653. splashArray: function (target, options) {
  10654. var oVar = options[target],
  10655. tArray = isObject(oVar) ? oVar : [oVar, oVar, oVar, oVar];
  10656. return [pick(options[target + 'Top'], tArray[0]),
  10657. pick(options[target + 'Right'], tArray[1]),
  10658. pick(options[target + 'Bottom'], tArray[2]),
  10659. pick(options[target + 'Left'], tArray[3])];
  10660. }
  10661. }; // end Chart
  10662. /**
  10663. * The Point object and prototype. Inheritable and used as base for PiePoint
  10664. */
  10665. var Point = function () {};
  10666. Point.prototype = {
  10667. /**
  10668. * Initialize the point
  10669. * @param {Object} series The series object containing this point
  10670. * @param {Object} options The data in either number, array or object format
  10671. */
  10672. init: function (series, options, x) {
  10673. var point = this,
  10674. colors;
  10675. point.series = series;
  10676. point.color = series.color; // #3445
  10677. point.applyOptions(options, x);
  10678. point.pointAttr = {};
  10679. if (series.options.colorByPoint) {
  10680. colors = series.options.colors || series.chart.options.colors;
  10681. point.color = point.color || colors[series.colorCounter++];
  10682. // loop back to zero
  10683. if (series.colorCounter === colors.length) {
  10684. series.colorCounter = 0;
  10685. }
  10686. }
  10687. series.chart.pointCount++;
  10688. return point;
  10689. },
  10690. /**
  10691. * Apply the options containing the x and y data and possible some extra properties.
  10692. * This is called on point init or from point.update.
  10693. *
  10694. * @param {Object} options
  10695. */
  10696. applyOptions: function (options, x) {
  10697. var point = this,
  10698. series = point.series,
  10699. pointValKey = series.options.pointValKey || series.pointValKey;
  10700. options = Point.prototype.optionsToObject.call(this, options);
  10701. // copy options directly to point
  10702. extend(point, options);
  10703. point.options = point.options ? extend(point.options, options) : options;
  10704. // For higher dimension series types. For instance, for ranges, point.y is mapped to point.low.
  10705. if (pointValKey) {
  10706. point.y = point[pointValKey];
  10707. }
  10708. // If no x is set by now, get auto incremented value. All points must have an
  10709. // x value, however the y value can be null to create a gap in the series
  10710. if (point.x === UNDEFINED && series) {
  10711. point.x = x === UNDEFINED ? series.autoIncrement() : x;
  10712. }
  10713. return point;
  10714. },
  10715. /**
  10716. * Transform number or array configs into objects
  10717. */
  10718. optionsToObject: function (options) {
  10719. var ret = {},
  10720. series = this.series,
  10721. keys = series.options.keys,
  10722. pointArrayMap = keys || series.pointArrayMap || ['y'],
  10723. valueCount = pointArrayMap.length,
  10724. firstItemType,
  10725. i = 0,
  10726. j = 0;
  10727. if (typeof options === 'number' || options === null) {
  10728. ret[pointArrayMap[0]] = options;
  10729. } else if (isArray(options)) {
  10730. // with leading x value
  10731. if (!keys && options.length > valueCount) {
  10732. firstItemType = typeof options[0];
  10733. if (firstItemType === 'string') {
  10734. ret.name = options[0];
  10735. } else if (firstItemType === 'number') {
  10736. ret.x = options[0];
  10737. }
  10738. i++;
  10739. }
  10740. while (j < valueCount) {
  10741. if (!keys || options[i] !== undefined) { // Skip undefined positions for keys
  10742. ret[pointArrayMap[j]] = options[i];
  10743. }
  10744. i++;
  10745. j++;
  10746. }
  10747. } else if (typeof options === 'object') {
  10748. ret = options;
  10749. // This is the fastest way to detect if there are individual point dataLabels that need
  10750. // to be considered in drawDataLabels. These can only occur in object configs.
  10751. if (options.dataLabels) {
  10752. series._hasPointLabels = true;
  10753. }
  10754. // Same approach as above for markers
  10755. if (options.marker) {
  10756. series._hasPointMarkers = true;
  10757. }
  10758. }
  10759. return ret;
  10760. },
  10761. /**
  10762. * Destroy a point to clear memory. Its reference still stays in series.data.
  10763. */
  10764. destroy: function () {
  10765. var point = this,
  10766. series = point.series,
  10767. chart = series.chart,
  10768. hoverPoints = chart.hoverPoints,
  10769. prop;
  10770. chart.pointCount--;
  10771. if (hoverPoints) {
  10772. point.setState();
  10773. erase(hoverPoints, point);
  10774. if (!hoverPoints.length) {
  10775. chart.hoverPoints = null;
  10776. }
  10777. }
  10778. if (point === chart.hoverPoint) {
  10779. point.onMouseOut();
  10780. }
  10781. // remove all events
  10782. if (point.graphic || point.dataLabel) { // removeEvent and destroyElements are performance expensive
  10783. removeEvent(point);
  10784. point.destroyElements();
  10785. }
  10786. if (point.legendItem) { // pies have legend items
  10787. chart.legend.destroyItem(point);
  10788. }
  10789. for (prop in point) {
  10790. point[prop] = null;
  10791. }
  10792. },
  10793. /**
  10794. * Destroy SVG elements associated with the point
  10795. */
  10796. destroyElements: function () {
  10797. var point = this,
  10798. props = ['graphic', 'dataLabel', 'dataLabelUpper', 'connector', 'shadowGroup'],
  10799. prop,
  10800. i = 6;
  10801. while (i--) {
  10802. prop = props[i];
  10803. if (point[prop]) {
  10804. point[prop] = point[prop].destroy();
  10805. }
  10806. }
  10807. },
  10808. /**
  10809. * Return the configuration hash needed for the data label and tooltip formatters
  10810. */
  10811. getLabelConfig: function () {
  10812. return {
  10813. x: this.category,
  10814. y: this.y,
  10815. color: this.color,
  10816. key: this.name || this.category,
  10817. series: this.series,
  10818. point: this,
  10819. percentage: this.percentage,
  10820. total: this.total || this.stackTotal
  10821. };
  10822. },
  10823. /**
  10824. * Extendable method for formatting each point's tooltip line
  10825. *
  10826. * @return {String} A string to be concatenated in to the common tooltip text
  10827. */
  10828. tooltipFormatter: function (pointFormat) {
  10829. // Insert options for valueDecimals, valuePrefix, and valueSuffix
  10830. var series = this.series,
  10831. seriesTooltipOptions = series.tooltipOptions,
  10832. valueDecimals = pick(seriesTooltipOptions.valueDecimals, ''),
  10833. valuePrefix = seriesTooltipOptions.valuePrefix || '',
  10834. valueSuffix = seriesTooltipOptions.valueSuffix || '';
  10835. // Loop over the point array map and replace unformatted values with sprintf formatting markup
  10836. each(series.pointArrayMap || ['y'], function (key) {
  10837. key = '{point.' + key; // without the closing bracket
  10838. if (valuePrefix || valueSuffix) {
  10839. pointFormat = pointFormat.replace(key + '}', valuePrefix + key + '}' + valueSuffix);
  10840. }
  10841. pointFormat = pointFormat.replace(key + '}', key + ':,.' + valueDecimals + 'f}');
  10842. });
  10843. return format(pointFormat, {
  10844. point: this,
  10845. series: this.series
  10846. });
  10847. },
  10848. /**
  10849. * Fire an event on the Point object. Must not be renamed to fireEvent, as this
  10850. * causes a name clash in MooTools
  10851. * @param {String} eventType
  10852. * @param {Object} eventArgs Additional event arguments
  10853. * @param {Function} defaultFunction Default event handler
  10854. */
  10855. firePointEvent: function (eventType, eventArgs, defaultFunction) {
  10856. var point = this,
  10857. series = this.series,
  10858. seriesOptions = series.options;
  10859. // load event handlers on demand to save time on mouseover/out
  10860. if (seriesOptions.point.events[eventType] || (point.options && point.options.events && point.options.events[eventType])) {
  10861. this.importEvents();
  10862. }
  10863. // add default handler if in selection mode
  10864. if (eventType === 'click' && seriesOptions.allowPointSelect) {
  10865. defaultFunction = function (event) {
  10866. // Control key is for Windows, meta (= Cmd key) for Mac, Shift for Opera
  10867. if (point.select) { // Could be destroyed by prior event handlers (#2911)
  10868. point.select(null, event.ctrlKey || event.metaKey || event.shiftKey);
  10869. }
  10870. };
  10871. }
  10872. fireEvent(this, eventType, eventArgs, defaultFunction);
  10873. },
  10874. visible: true
  10875. };/**
  10876. * @classDescription The base function which all other series types inherit from. The data in the series is stored
  10877. * in various arrays.
  10878. *
  10879. * - First, series.options.data contains all the original config options for
  10880. * each point whether added by options or methods like series.addPoint.
  10881. * - Next, series.data contains those values converted to points, but in case the series data length
  10882. * exceeds the cropThreshold, or if the data is grouped, series.data doesn't contain all the points. It
  10883. * only contains the points that have been created on demand.
  10884. * - Then there's series.points that contains all currently visible point objects. In case of cropping,
  10885. * the cropped-away points are not part of this array. The series.points array starts at series.cropStart
  10886. * compared to series.data and series.options.data. If however the series data is grouped, these can't
  10887. * be correlated one to one.
  10888. * - series.xData and series.processedXData contain clean x values, equivalent to series.data and series.points.
  10889. * - series.yData and series.processedYData contain clean x values, equivalent to series.data and series.points.
  10890. *
  10891. * @param {Object} chart
  10892. * @param {Object} options
  10893. */
  10894. var Series = Highcharts.Series = function () {};
  10895. Series.prototype = {
  10896. isCartesian: true,
  10897. type: 'line',
  10898. pointClass: Point,
  10899. sorted: true, // requires the data to be sorted
  10900. requireSorting: true,
  10901. pointAttrToOptions: { // mapping between SVG attributes and the corresponding options
  10902. stroke: 'lineColor',
  10903. 'stroke-width': 'lineWidth',
  10904. fill: 'fillColor',
  10905. r: 'radius'
  10906. },
  10907. directTouch: false,
  10908. axisTypes: ['xAxis', 'yAxis'],
  10909. colorCounter: 0,
  10910. parallelArrays: ['x', 'y'], // each point's x and y values are stored in this.xData and this.yData
  10911. init: function (chart, options) {
  10912. var series = this,
  10913. eventType,
  10914. events,
  10915. chartSeries = chart.series,
  10916. sortByIndex = function (a, b) {
  10917. return pick(a.options.index, a._i) - pick(b.options.index, b._i);
  10918. };
  10919. series.chart = chart;
  10920. series.options = options = series.setOptions(options); // merge with plotOptions
  10921. series.linkedSeries = [];
  10922. // bind the axes
  10923. series.bindAxes();
  10924. // set some variables
  10925. extend(series, {
  10926. name: options.name,
  10927. state: NORMAL_STATE,
  10928. pointAttr: {},
  10929. visible: options.visible !== false, // true by default
  10930. selected: options.selected === true // false by default
  10931. });
  10932. // special
  10933. if (useCanVG) {
  10934. options.animation = false;
  10935. }
  10936. // register event listeners
  10937. events = options.events;
  10938. for (eventType in events) {
  10939. addEvent(series, eventType, events[eventType]);
  10940. }
  10941. if (
  10942. (events && events.click) ||
  10943. (options.point && options.point.events && options.point.events.click) ||
  10944. options.allowPointSelect
  10945. ) {
  10946. chart.runTrackerClick = true;
  10947. }
  10948. series.getColor();
  10949. series.getSymbol();
  10950. // Set the data
  10951. each(series.parallelArrays, function (key) {
  10952. series[key + 'Data'] = [];
  10953. });
  10954. series.setData(options.data, false);
  10955. // Mark cartesian
  10956. if (series.isCartesian) {
  10957. chart.hasCartesianSeries = true;
  10958. }
  10959. // Register it in the chart
  10960. chartSeries.push(series);
  10961. series._i = chartSeries.length - 1;
  10962. // Sort series according to index option (#248, #1123, #2456)
  10963. stableSort(chartSeries, sortByIndex);
  10964. if (this.yAxis) {
  10965. stableSort(this.yAxis.series, sortByIndex);
  10966. }
  10967. each(chartSeries, function (series, i) {
  10968. series.index = i;
  10969. series.name = series.name || 'Series ' + (i + 1);
  10970. });
  10971. },
  10972. /**
  10973. * Set the xAxis and yAxis properties of cartesian series, and register the series
  10974. * in the axis.series array
  10975. */
  10976. bindAxes: function () {
  10977. var series = this,
  10978. seriesOptions = series.options,
  10979. chart = series.chart,
  10980. axisOptions;
  10981. each(series.axisTypes || [], function (AXIS) { // repeat for xAxis and yAxis
  10982. each(chart[AXIS], function (axis) { // loop through the chart's axis objects
  10983. axisOptions = axis.options;
  10984. // apply if the series xAxis or yAxis option mathches the number of the
  10985. // axis, or if undefined, use the first axis
  10986. if ((seriesOptions[AXIS] === axisOptions.index) ||
  10987. (seriesOptions[AXIS] !== UNDEFINED && seriesOptions[AXIS] === axisOptions.id) ||
  10988. (seriesOptions[AXIS] === UNDEFINED && axisOptions.index === 0)) {
  10989. // register this series in the axis.series lookup
  10990. axis.series.push(series);
  10991. // set this series.xAxis or series.yAxis reference
  10992. series[AXIS] = axis;
  10993. // mark dirty for redraw
  10994. axis.isDirty = true;
  10995. }
  10996. });
  10997. // The series needs an X and an Y axis
  10998. if (!series[AXIS] && series.optionalAxis !== AXIS) {
  10999. error(18, true);
  11000. }
  11001. });
  11002. },
  11003. /**
  11004. * For simple series types like line and column, the data values are held in arrays like
  11005. * xData and yData for quick lookup to find extremes and more. For multidimensional series
  11006. * like bubble and map, this can be extended with arrays like zData and valueData by
  11007. * adding to the series.parallelArrays array.
  11008. */
  11009. updateParallelArrays: function (point, i) {
  11010. var series = point.series,
  11011. args = arguments,
  11012. fn = typeof i === 'number' ?
  11013. // Insert the value in the given position
  11014. function (key) {
  11015. var val = key === 'y' && series.toYData ? series.toYData(point) : point[key];
  11016. series[key + 'Data'][i] = val;
  11017. } :
  11018. // Apply the method specified in i with the following arguments as arguments
  11019. function (key) {
  11020. Array.prototype[i].apply(series[key + 'Data'], Array.prototype.slice.call(args, 2));
  11021. };
  11022. each(series.parallelArrays, fn);
  11023. },
  11024. /**
  11025. * Return an auto incremented x value based on the pointStart and pointInterval options.
  11026. * This is only used if an x value is not given for the point that calls autoIncrement.
  11027. */
  11028. autoIncrement: function () {
  11029. var options = this.options,
  11030. xIncrement = this.xIncrement,
  11031. date,
  11032. pointInterval,
  11033. pointIntervalUnit = options.pointIntervalUnit;
  11034. xIncrement = pick(xIncrement, options.pointStart, 0);
  11035. this.pointInterval = pointInterval = pick(this.pointInterval, options.pointInterval, 1);
  11036. // Added code for pointInterval strings
  11037. if (pointIntervalUnit === 'month' || pointIntervalUnit === 'year') {
  11038. date = new Date(xIncrement);
  11039. date = (pointIntervalUnit === 'month') ?
  11040. +date[setMonth](date[getMonth]() + pointInterval) :
  11041. +date[setFullYear](date[getFullYear]() + pointInterval);
  11042. pointInterval = date - xIncrement;
  11043. }
  11044. this.xIncrement = xIncrement + pointInterval;
  11045. return xIncrement;
  11046. },
  11047. /**
  11048. * Divide the series data into segments divided by null values.
  11049. */
  11050. getSegments: function () {
  11051. var series = this,
  11052. lastNull = -1,
  11053. segments = [],
  11054. i,
  11055. points = series.points,
  11056. pointsLength = points.length;
  11057. if (pointsLength) { // no action required for []
  11058. // if connect nulls, just remove null points
  11059. if (series.options.connectNulls) {
  11060. i = pointsLength;
  11061. while (i--) {
  11062. if (points[i].y === null) {
  11063. points.splice(i, 1);
  11064. }
  11065. }
  11066. if (points.length) {
  11067. segments = [points];
  11068. }
  11069. // else, split on null points
  11070. } else {
  11071. each(points, function (point, i) {
  11072. if (point.y === null) {
  11073. if (i > lastNull + 1) {
  11074. segments.push(points.slice(lastNull + 1, i));
  11075. }
  11076. lastNull = i;
  11077. } else if (i === pointsLength - 1) { // last value
  11078. segments.push(points.slice(lastNull + 1, i + 1));
  11079. }
  11080. });
  11081. }
  11082. }
  11083. // register it
  11084. series.segments = segments;
  11085. },
  11086. /**
  11087. * Set the series options by merging from the options tree
  11088. * @param {Object} itemOptions
  11089. */
  11090. setOptions: function (itemOptions) {
  11091. var chart = this.chart,
  11092. chartOptions = chart.options,
  11093. plotOptions = chartOptions.plotOptions,
  11094. userOptions = chart.userOptions || {},
  11095. userPlotOptions = userOptions.plotOptions || {},
  11096. typeOptions = plotOptions[this.type],
  11097. options,
  11098. zones;
  11099. this.userOptions = itemOptions;
  11100. // General series options take precedence over type options because otherwise, default
  11101. // type options like column.animation would be overwritten by the general option.
  11102. // But issues have been raised here (#3881), and the solution may be to distinguish
  11103. // between default option and userOptions like in the tooltip below.
  11104. options = merge(
  11105. typeOptions,
  11106. plotOptions.series,
  11107. itemOptions
  11108. );
  11109. // The tooltip options are merged between global and series specific options
  11110. this.tooltipOptions = merge(
  11111. defaultOptions.tooltip,
  11112. defaultOptions.plotOptions[this.type].tooltip,
  11113. userOptions.tooltip,
  11114. userPlotOptions.series && userPlotOptions.series.tooltip,
  11115. userPlotOptions[this.type] && userPlotOptions[this.type].tooltip,
  11116. itemOptions.tooltip
  11117. );
  11118. // Delete marker object if not allowed (#1125)
  11119. if (typeOptions.marker === null) {
  11120. delete options.marker;
  11121. }
  11122. // Handle color zones
  11123. this.zoneAxis = options.zoneAxis;
  11124. zones = this.zones = (options.zones || []).slice();
  11125. if ((options.negativeColor || options.negativeFillColor) && !options.zones) {
  11126. zones.push({
  11127. value: options[this.zoneAxis + 'Threshold'] || options.threshold || 0,
  11128. color: options.negativeColor,
  11129. fillColor: options.negativeFillColor
  11130. });
  11131. }
  11132. if (zones.length) { // Push one extra zone for the rest
  11133. if (defined(zones[zones.length - 1].value)) {
  11134. zones.push({
  11135. color: this.color,
  11136. fillColor: this.fillColor
  11137. });
  11138. }
  11139. }
  11140. return options;
  11141. },
  11142. getCyclic: function (prop, value, defaults) {
  11143. var i,
  11144. userOptions = this.userOptions,
  11145. indexName = '_' + prop + 'Index',
  11146. counterName = prop + 'Counter';
  11147. if (!value) {
  11148. if (defined(userOptions[indexName])) { // after Series.update()
  11149. i = userOptions[indexName];
  11150. } else {
  11151. userOptions[indexName] = i = this.chart[counterName] % defaults.length;
  11152. this.chart[counterName] += 1;
  11153. }
  11154. value = defaults[i];
  11155. }
  11156. this[prop] = value;
  11157. },
  11158. /**
  11159. * Get the series' color
  11160. */
  11161. getColor: function () {
  11162. if (this.options.colorByPoint) {
  11163. this.options.color = null; // #4359, selected slice got series.color even when colorByPoint was set.
  11164. } else {
  11165. this.getCyclic('color', this.options.color || defaultPlotOptions[this.type].color, this.chart.options.colors);
  11166. }
  11167. },
  11168. /**
  11169. * Get the series' symbol
  11170. */
  11171. getSymbol: function () {
  11172. var seriesMarkerOption = this.options.marker;
  11173. this.getCyclic('symbol', seriesMarkerOption.symbol, this.chart.options.symbols);
  11174. // don't substract radius in image symbols (#604)
  11175. if (/^url/.test(this.symbol)) {
  11176. seriesMarkerOption.radius = 0;
  11177. }
  11178. },
  11179. drawLegendSymbol: LegendSymbolMixin.drawLineMarker,
  11180. /**
  11181. * Replace the series data with a new set of data
  11182. * @param {Object} data
  11183. * @param {Object} redraw
  11184. */
  11185. setData: function (data, redraw, animation, updatePoints) {
  11186. var series = this,
  11187. oldData = series.points,
  11188. oldDataLength = (oldData && oldData.length) || 0,
  11189. dataLength,
  11190. options = series.options,
  11191. chart = series.chart,
  11192. firstPoint = null,
  11193. xAxis = series.xAxis,
  11194. hasCategories = xAxis && !!xAxis.categories,
  11195. i,
  11196. turboThreshold = options.turboThreshold,
  11197. pt,
  11198. xData = this.xData,
  11199. yData = this.yData,
  11200. pointArrayMap = series.pointArrayMap,
  11201. valueCount = pointArrayMap && pointArrayMap.length;
  11202. data = data || [];
  11203. dataLength = data.length;
  11204. redraw = pick(redraw, true);
  11205. // If the point count is the same as is was, just run Point.update which is
  11206. // cheaper, allows animation, and keeps references to points.
  11207. if (updatePoints !== false && dataLength && oldDataLength === dataLength && !series.cropped && !series.hasGroupedData && series.visible) {
  11208. each(data, function (point, i) {
  11209. if (oldData[i].update) { // Linked, previously hidden series (#3709)
  11210. oldData[i].update(point, false, null, false);
  11211. }
  11212. });
  11213. } else {
  11214. // Reset properties
  11215. series.xIncrement = null;
  11216. series.pointRange = hasCategories ? 1 : options.pointRange;
  11217. series.colorCounter = 0; // for series with colorByPoint (#1547)
  11218. // Update parallel arrays
  11219. each(this.parallelArrays, function (key) {
  11220. series[key + 'Data'].length = 0;
  11221. });
  11222. // In turbo mode, only one- or twodimensional arrays of numbers are allowed. The
  11223. // first value is tested, and we assume that all the rest are defined the same
  11224. // way. Although the 'for' loops are similar, they are repeated inside each
  11225. // if-else conditional for max performance.
  11226. if (turboThreshold && dataLength > turboThreshold) {
  11227. // find the first non-null point
  11228. i = 0;
  11229. while (firstPoint === null && i < dataLength) {
  11230. firstPoint = data[i];
  11231. i++;
  11232. }
  11233. if (isNumber(firstPoint)) { // assume all points are numbers
  11234. var x = pick(options.pointStart, 0),
  11235. pointInterval = pick(options.pointInterval, 1);
  11236. for (i = 0; i < dataLength; i++) {
  11237. xData[i] = x;
  11238. yData[i] = data[i];
  11239. x += pointInterval;
  11240. }
  11241. series.xIncrement = x;
  11242. } else if (isArray(firstPoint)) { // assume all points are arrays
  11243. if (valueCount) { // [x, low, high] or [x, o, h, l, c]
  11244. for (i = 0; i < dataLength; i++) {
  11245. pt = data[i];
  11246. xData[i] = pt[0];
  11247. yData[i] = pt.slice(1, valueCount + 1);
  11248. }
  11249. } else { // [x, y]
  11250. for (i = 0; i < dataLength; i++) {
  11251. pt = data[i];
  11252. xData[i] = pt[0];
  11253. yData[i] = pt[1];
  11254. }
  11255. }
  11256. } else {
  11257. error(12); // Highcharts expects configs to be numbers or arrays in turbo mode
  11258. }
  11259. } else {
  11260. for (i = 0; i < dataLength; i++) {
  11261. if (data[i] !== UNDEFINED) { // stray commas in oldIE
  11262. pt = { series: series };
  11263. series.pointClass.prototype.applyOptions.apply(pt, [data[i]]);
  11264. series.updateParallelArrays(pt, i);
  11265. if (hasCategories && defined(pt.name)) { // #4401
  11266. xAxis.names[pt.x] = pt.name; // #2046
  11267. }
  11268. }
  11269. }
  11270. }
  11271. // Forgetting to cast strings to numbers is a common caveat when handling CSV or JSON
  11272. if (isString(yData[0])) {
  11273. error(14, true);
  11274. }
  11275. series.data = [];
  11276. series.options.data = data;
  11277. //series.zData = zData;
  11278. // destroy old points
  11279. i = oldDataLength;
  11280. while (i--) {
  11281. if (oldData[i] && oldData[i].destroy) {
  11282. oldData[i].destroy();
  11283. }
  11284. }
  11285. // reset minRange (#878)
  11286. if (xAxis) {
  11287. xAxis.minRange = xAxis.userMinRange;
  11288. }
  11289. // redraw
  11290. series.isDirty = series.isDirtyData = chart.isDirtyBox = true;
  11291. animation = false;
  11292. }
  11293. // Typically for pie series, points need to be processed and generated
  11294. // prior to rendering the legend
  11295. if (options.legendType === 'point') { // docs: legendType now supported on more series types (at least column and pie)
  11296. this.processData();
  11297. this.generatePoints();
  11298. }
  11299. if (redraw) {
  11300. chart.redraw(animation);
  11301. }
  11302. },
  11303. /**
  11304. * Process the data by cropping away unused data points if the series is longer
  11305. * than the crop threshold. This saves computing time for lage series.
  11306. */
  11307. processData: function (force) {
  11308. var series = this,
  11309. processedXData = series.xData, // copied during slice operation below
  11310. processedYData = series.yData,
  11311. dataLength = processedXData.length,
  11312. croppedData,
  11313. cropStart = 0,
  11314. cropped,
  11315. distance,
  11316. closestPointRange,
  11317. xAxis = series.xAxis,
  11318. i, // loop variable
  11319. options = series.options,
  11320. cropThreshold = options.cropThreshold,
  11321. getExtremesFromAll = series.getExtremesFromAll || options.getExtremesFromAll, // #4599
  11322. isCartesian = series.isCartesian,
  11323. xExtremes,
  11324. min,
  11325. max;
  11326. // If the series data or axes haven't changed, don't go through this. Return false to pass
  11327. // the message on to override methods like in data grouping.
  11328. if (isCartesian && !series.isDirty && !xAxis.isDirty && !series.yAxis.isDirty && !force) {
  11329. return false;
  11330. }
  11331. if (xAxis) {
  11332. xExtremes = xAxis.getExtremes(); // corrected for log axis (#3053)
  11333. min = xExtremes.min;
  11334. max = xExtremes.max;
  11335. }
  11336. // optionally filter out points outside the plot area
  11337. if (isCartesian && series.sorted && !getExtremesFromAll && (!cropThreshold || dataLength > cropThreshold || series.forceCrop)) {
  11338. // it's outside current extremes
  11339. if (processedXData[dataLength - 1] < min || processedXData[0] > max) {
  11340. processedXData = [];
  11341. processedYData = [];
  11342. // only crop if it's actually spilling out
  11343. } else if (processedXData[0] < min || processedXData[dataLength - 1] > max) {
  11344. croppedData = this.cropData(series.xData, series.yData, min, max);
  11345. processedXData = croppedData.xData;
  11346. processedYData = croppedData.yData;
  11347. cropStart = croppedData.start;
  11348. cropped = true;
  11349. }
  11350. }
  11351. // Find the closest distance between processed points
  11352. for (i = processedXData.length - 1; i >= 0; i--) {
  11353. distance = processedXData[i] - processedXData[i - 1];
  11354. if (distance > 0 && (closestPointRange === UNDEFINED || distance < closestPointRange)) {
  11355. closestPointRange = distance;
  11356. // Unsorted data is not supported by the line tooltip, as well as data grouping and
  11357. // navigation in Stock charts (#725) and width calculation of columns (#1900)
  11358. } else if (distance < 0 && series.requireSorting) {
  11359. error(15);
  11360. }
  11361. }
  11362. // Record the properties
  11363. series.cropped = cropped; // undefined or true
  11364. series.cropStart = cropStart;
  11365. series.processedXData = processedXData;
  11366. series.processedYData = processedYData;
  11367. if (options.pointRange === null) { // null means auto, as for columns, candlesticks and OHLC
  11368. series.pointRange = closestPointRange || 1;
  11369. }
  11370. series.closestPointRange = closestPointRange;
  11371. },
  11372. /**
  11373. * Iterate over xData and crop values between min and max. Returns object containing crop start/end
  11374. * cropped xData with corresponding part of yData, dataMin and dataMax within the cropped range
  11375. */
  11376. cropData: function (xData, yData, min, max) {
  11377. var dataLength = xData.length,
  11378. cropStart = 0,
  11379. cropEnd = dataLength,
  11380. cropShoulder = pick(this.cropShoulder, 1), // line-type series need one point outside
  11381. i;
  11382. // iterate up to find slice start
  11383. for (i = 0; i < dataLength; i++) {
  11384. if (xData[i] >= min) {
  11385. cropStart = mathMax(0, i - cropShoulder);
  11386. break;
  11387. }
  11388. }
  11389. // proceed to find slice end
  11390. for (; i < dataLength; i++) {
  11391. if (xData[i] > max) {
  11392. cropEnd = i + cropShoulder;
  11393. break;
  11394. }
  11395. }
  11396. return {
  11397. xData: xData.slice(cropStart, cropEnd),
  11398. yData: yData.slice(cropStart, cropEnd),
  11399. start: cropStart,
  11400. end: cropEnd
  11401. };
  11402. },
  11403. /**
  11404. * Generate the data point after the data has been processed by cropping away
  11405. * unused points and optionally grouped in Highcharts Stock.
  11406. */
  11407. generatePoints: function () {
  11408. var series = this,
  11409. options = series.options,
  11410. dataOptions = options.data,
  11411. data = series.data,
  11412. dataLength,
  11413. processedXData = series.processedXData,
  11414. processedYData = series.processedYData,
  11415. pointClass = series.pointClass,
  11416. processedDataLength = processedXData.length,
  11417. cropStart = series.cropStart || 0,
  11418. cursor,
  11419. hasGroupedData = series.hasGroupedData,
  11420. point,
  11421. points = [],
  11422. i;
  11423. if (!data && !hasGroupedData) {
  11424. var arr = [];
  11425. arr.length = dataOptions.length;
  11426. data = series.data = arr;
  11427. }
  11428. for (i = 0; i < processedDataLength; i++) {
  11429. cursor = cropStart + i;
  11430. if (!hasGroupedData) {
  11431. if (data[cursor]) {
  11432. point = data[cursor];
  11433. } else if (dataOptions[cursor] !== UNDEFINED) { // #970
  11434. data[cursor] = point = (new pointClass()).init(series, dataOptions[cursor], processedXData[i]);
  11435. }
  11436. points[i] = point;
  11437. } else {
  11438. // splat the y data in case of ohlc data array
  11439. points[i] = (new pointClass()).init(series, [processedXData[i]].concat(splat(processedYData[i])));
  11440. }
  11441. points[i].index = cursor; // For faster access in Point.update
  11442. }
  11443. // Hide cropped-away points - this only runs when the number of points is above cropThreshold, or when
  11444. // swithching view from non-grouped data to grouped data (#637)
  11445. if (data && (processedDataLength !== (dataLength = data.length) || hasGroupedData)) {
  11446. for (i = 0; i < dataLength; i++) {
  11447. if (i === cropStart && !hasGroupedData) { // when has grouped data, clear all points
  11448. i += processedDataLength;
  11449. }
  11450. if (data[i]) {
  11451. data[i].destroyElements();
  11452. data[i].plotX = UNDEFINED; // #1003
  11453. }
  11454. }
  11455. }
  11456. series.data = data;
  11457. series.points = points;
  11458. },
  11459. /**
  11460. * Calculate Y extremes for visible data
  11461. */
  11462. getExtremes: function (yData) {
  11463. var xAxis = this.xAxis,
  11464. yAxis = this.yAxis,
  11465. xData = this.processedXData,
  11466. yDataLength,
  11467. activeYData = [],
  11468. activeCounter = 0,
  11469. xExtremes = xAxis.getExtremes(), // #2117, need to compensate for log X axis
  11470. xMin = xExtremes.min,
  11471. xMax = xExtremes.max,
  11472. validValue,
  11473. withinRange,
  11474. x,
  11475. y,
  11476. i,
  11477. j;
  11478. yData = yData || this.stackedYData || this.processedYData;
  11479. yDataLength = yData.length;
  11480. for (i = 0; i < yDataLength; i++) {
  11481. x = xData[i];
  11482. y = yData[i];
  11483. // For points within the visible range, including the first point outside the
  11484. // visible range, consider y extremes
  11485. validValue = y !== null && y !== UNDEFINED && (!yAxis.isLog || (y.length || y > 0));
  11486. withinRange = this.getExtremesFromAll || this.options.getExtremesFromAll || this.cropped ||
  11487. ((xData[i + 1] || x) >= xMin && (xData[i - 1] || x) <= xMax);
  11488. if (validValue && withinRange) {
  11489. j = y.length;
  11490. if (j) { // array, like ohlc or range data
  11491. while (j--) {
  11492. if (y[j] !== null) {
  11493. activeYData[activeCounter++] = y[j];
  11494. }
  11495. }
  11496. } else {
  11497. activeYData[activeCounter++] = y;
  11498. }
  11499. }
  11500. }
  11501. this.dataMin = arrayMin(activeYData);
  11502. this.dataMax = arrayMax(activeYData);
  11503. },
  11504. /**
  11505. * Translate data points from raw data values to chart specific positioning data
  11506. * needed later in drawPoints, drawGraph and drawTracker.
  11507. */
  11508. translate: function () {
  11509. if (!this.processedXData) { // hidden series
  11510. this.processData();
  11511. }
  11512. this.generatePoints();
  11513. var series = this,
  11514. options = series.options,
  11515. stacking = options.stacking,
  11516. xAxis = series.xAxis,
  11517. categories = xAxis.categories,
  11518. yAxis = series.yAxis,
  11519. points = series.points,
  11520. dataLength = points.length,
  11521. hasModifyValue = !!series.modifyValue,
  11522. i,
  11523. pointPlacement = options.pointPlacement,
  11524. dynamicallyPlaced = pointPlacement === 'between' || isNumber(pointPlacement),
  11525. threshold = options.threshold,
  11526. stackThreshold = options.startFromThreshold ? threshold : 0,
  11527. plotX,
  11528. plotY,
  11529. lastPlotX,
  11530. stackIndicator,
  11531. closestPointRangePx = Number.MAX_VALUE;
  11532. // Translate each point
  11533. for (i = 0; i < dataLength; i++) {
  11534. var point = points[i],
  11535. xValue = point.x,
  11536. yValue = point.y,
  11537. yBottom = point.low,
  11538. stack = stacking && yAxis.stacks[(series.negStacks && yValue < (stackThreshold ? 0 : threshold) ? '-' : '') + series.stackKey],
  11539. pointStack,
  11540. stackValues;
  11541. // Discard disallowed y values for log axes (#3434)
  11542. if (yAxis.isLog && yValue !== null && yValue <= 0) {
  11543. point.y = yValue = null;
  11544. error(10);
  11545. }
  11546. // Get the plotX translation
  11547. point.plotX = plotX = mathMin(mathMax(-1e5, xAxis.translate(xValue, 0, 0, 0, 1, pointPlacement, this.type === 'flags')), 1e5); // #3923
  11548. // Calculate the bottom y value for stacked series
  11549. if (stacking && series.visible && stack && stack[xValue]) {
  11550. stackIndicator = series.getStackIndicator(stackIndicator, xValue, series.index);
  11551. pointStack = stack[xValue];
  11552. stackValues = pointStack.points[stackIndicator.key];
  11553. yBottom = stackValues[0];
  11554. yValue = stackValues[1];
  11555. if (yBottom === stackThreshold) {
  11556. yBottom = pick(threshold, yAxis.min);
  11557. }
  11558. if (yAxis.isLog && yBottom <= 0) { // #1200, #1232
  11559. yBottom = null;
  11560. }
  11561. point.total = point.stackTotal = pointStack.total;
  11562. point.percentage = pointStack.total && (point.y / pointStack.total * 100);
  11563. point.stackY = yValue;
  11564. // Place the stack label
  11565. pointStack.setOffset(series.pointXOffset || 0, series.barW || 0);
  11566. }
  11567. // Set translated yBottom or remove it
  11568. point.yBottom = defined(yBottom) ?
  11569. yAxis.translate(yBottom, 0, 1, 0, 1) :
  11570. null;
  11571. // general hook, used for Highstock compare mode
  11572. if (hasModifyValue) {
  11573. yValue = series.modifyValue(yValue, point);
  11574. }
  11575. // Set the the plotY value, reset it for redraws
  11576. point.plotY = plotY = (typeof yValue === 'number' && yValue !== Infinity) ?
  11577. mathMin(mathMax(-1e5, yAxis.translate(yValue, 0, 1, 0, 1)), 1e5) : // #3201
  11578. UNDEFINED;
  11579. point.isInside = plotY !== UNDEFINED && plotY >= 0 && plotY <= yAxis.len && // #3519
  11580. plotX >= 0 && plotX <= xAxis.len;
  11581. // Set client related positions for mouse tracking
  11582. point.clientX = dynamicallyPlaced ? xAxis.translate(xValue, 0, 0, 0, 1) : plotX; // #1514
  11583. point.negative = point.y < (threshold || 0);
  11584. // some API data
  11585. point.category = categories && categories[point.x] !== UNDEFINED ?
  11586. categories[point.x] : point.x;
  11587. // Determine auto enabling of markers (#3635)
  11588. if (i) {
  11589. closestPointRangePx = mathMin(closestPointRangePx, mathAbs(plotX - lastPlotX));
  11590. }
  11591. lastPlotX = plotX;
  11592. }
  11593. series.closestPointRangePx = closestPointRangePx;
  11594. // now that we have the cropped data, build the segments
  11595. series.getSegments();
  11596. },
  11597. /**
  11598. * Set the clipping for the series. For animated series it is called twice, first to initiate
  11599. * animating the clip then the second time without the animation to set the final clip.
  11600. */
  11601. setClip: function (animation) {
  11602. var chart = this.chart,
  11603. options = this.options,
  11604. renderer = chart.renderer,
  11605. inverted = chart.inverted,
  11606. seriesClipBox = this.clipBox,
  11607. clipBox = seriesClipBox || chart.clipBox,
  11608. sharedClipKey = this.sharedClipKey || ['_sharedClip', animation && animation.duration, animation && animation.easing, clipBox.height, options.xAxis, options.yAxis].join(','), // #4526
  11609. clipRect = chart[sharedClipKey],
  11610. markerClipRect = chart[sharedClipKey + 'm'];
  11611. // If a clipping rectangle with the same properties is currently present in the chart, use that.
  11612. if (!clipRect) {
  11613. // When animation is set, prepare the initial positions
  11614. if (animation) {
  11615. clipBox.width = 0;
  11616. chart[sharedClipKey + 'm'] = markerClipRect = renderer.clipRect(
  11617. -99, // include the width of the first marker
  11618. inverted ? -chart.plotLeft : -chart.plotTop,
  11619. 99,
  11620. inverted ? chart.chartWidth : chart.chartHeight
  11621. );
  11622. }
  11623. chart[sharedClipKey] = clipRect = renderer.clipRect(clipBox);
  11624. }
  11625. if (animation) {
  11626. clipRect.count += 1;
  11627. }
  11628. if (options.clip !== false) {
  11629. this.group.clip(animation || seriesClipBox ? clipRect : chart.clipRect);
  11630. this.markerGroup.clip(markerClipRect);
  11631. this.sharedClipKey = sharedClipKey;
  11632. }
  11633. // Remove the shared clipping rectangle when all series are shown
  11634. if (!animation) {
  11635. clipRect.count -= 1;
  11636. if (clipRect.count <= 0 && sharedClipKey && chart[sharedClipKey]) {
  11637. if (!seriesClipBox) {
  11638. chart[sharedClipKey] = chart[sharedClipKey].destroy();
  11639. }
  11640. if (chart[sharedClipKey + 'm']) {
  11641. chart[sharedClipKey + 'm'] = chart[sharedClipKey + 'm'].destroy();
  11642. }
  11643. }
  11644. }
  11645. },
  11646. /**
  11647. * Animate in the series
  11648. */
  11649. animate: function (init) {
  11650. var series = this,
  11651. chart = series.chart,
  11652. clipRect,
  11653. animation = series.options.animation,
  11654. sharedClipKey;
  11655. // Animation option is set to true
  11656. if (animation && !isObject(animation)) {
  11657. animation = defaultPlotOptions[series.type].animation;
  11658. }
  11659. // Initialize the animation. Set up the clipping rectangle.
  11660. if (init) {
  11661. series.setClip(animation);
  11662. // Run the animation
  11663. } else {
  11664. sharedClipKey = this.sharedClipKey;
  11665. clipRect = chart[sharedClipKey];
  11666. if (clipRect) {
  11667. clipRect.animate({
  11668. width: chart.plotSizeX
  11669. }, animation);
  11670. }
  11671. if (chart[sharedClipKey + 'm']) {
  11672. chart[sharedClipKey + 'm'].animate({
  11673. width: chart.plotSizeX + 99
  11674. }, animation);
  11675. }
  11676. // Delete this function to allow it only once
  11677. series.animate = null;
  11678. }
  11679. },
  11680. /**
  11681. * This runs after animation to land on the final plot clipping
  11682. */
  11683. afterAnimate: function () {
  11684. this.setClip();
  11685. fireEvent(this, 'afterAnimate');
  11686. },
  11687. /**
  11688. * Draw the markers
  11689. */
  11690. drawPoints: function () {
  11691. var series = this,
  11692. pointAttr,
  11693. points = series.points,
  11694. chart = series.chart,
  11695. plotX,
  11696. plotY,
  11697. i,
  11698. point,
  11699. radius,
  11700. symbol,
  11701. isImage,
  11702. graphic,
  11703. options = series.options,
  11704. seriesMarkerOptions = options.marker,
  11705. seriesPointAttr = series.pointAttr[''],
  11706. pointMarkerOptions,
  11707. hasPointMarker,
  11708. enabled,
  11709. isInside,
  11710. markerGroup = series.markerGroup,
  11711. xAxis = series.xAxis,
  11712. globallyEnabled = pick(
  11713. seriesMarkerOptions.enabled,
  11714. xAxis.isRadial,
  11715. series.closestPointRangePx > 2 * seriesMarkerOptions.radius
  11716. );
  11717. if (seriesMarkerOptions.enabled !== false || series._hasPointMarkers) {
  11718. i = points.length;
  11719. while (i--) {
  11720. point = points[i];
  11721. plotX = mathFloor(point.plotX); // #1843
  11722. plotY = point.plotY;
  11723. graphic = point.graphic;
  11724. pointMarkerOptions = point.marker || {};
  11725. hasPointMarker = !!point.marker;
  11726. enabled = (globallyEnabled && pointMarkerOptions.enabled === UNDEFINED) || pointMarkerOptions.enabled;
  11727. isInside = point.isInside;
  11728. // only draw the point if y is defined
  11729. if (enabled && plotY !== UNDEFINED && !isNaN(plotY) && point.y !== null) {
  11730. // shortcuts
  11731. pointAttr = point.pointAttr[point.selected ? SELECT_STATE : NORMAL_STATE] || seriesPointAttr;
  11732. radius = pointAttr.r;
  11733. symbol = pick(pointMarkerOptions.symbol, series.symbol);
  11734. isImage = symbol.indexOf('url') === 0;
  11735. if (graphic) { // update
  11736. graphic[isInside ? 'show' : 'hide'](true) // Since the marker group isn't clipped, each individual marker must be toggled
  11737. .animate(extend({
  11738. x: plotX - radius,
  11739. y: plotY - radius
  11740. }, graphic.symbolName ? { // don't apply to image symbols #507
  11741. width: 2 * radius,
  11742. height: 2 * radius
  11743. } : {}));
  11744. } else if (isInside && (radius > 0 || isImage)) {
  11745. point.graphic = graphic = chart.renderer.symbol(
  11746. symbol,
  11747. plotX - radius,
  11748. plotY - radius,
  11749. 2 * radius,
  11750. 2 * radius,
  11751. hasPointMarker ? pointMarkerOptions : seriesMarkerOptions
  11752. )
  11753. .attr(pointAttr)
  11754. .add(markerGroup);
  11755. }
  11756. } else if (graphic) {
  11757. point.graphic = graphic.destroy(); // #1269
  11758. }
  11759. }
  11760. }
  11761. },
  11762. /**
  11763. * Convert state properties from API naming conventions to SVG attributes
  11764. *
  11765. * @param {Object} options API options object
  11766. * @param {Object} base1 SVG attribute object to inherit from
  11767. * @param {Object} base2 Second level SVG attribute object to inherit from
  11768. */
  11769. convertAttribs: function (options, base1, base2, base3) {
  11770. var conversion = this.pointAttrToOptions,
  11771. attr,
  11772. option,
  11773. obj = {};
  11774. options = options || {};
  11775. base1 = base1 || {};
  11776. base2 = base2 || {};
  11777. base3 = base3 || {};
  11778. for (attr in conversion) {
  11779. option = conversion[attr];
  11780. obj[attr] = pick(options[option], base1[attr], base2[attr], base3[attr]);
  11781. }
  11782. return obj;
  11783. },
  11784. /**
  11785. * Get the state attributes. Each series type has its own set of attributes
  11786. * that are allowed to change on a point's state change. Series wide attributes are stored for
  11787. * all series, and additionally point specific attributes are stored for all
  11788. * points with individual marker options. If such options are not defined for the point,
  11789. * a reference to the series wide attributes is stored in point.pointAttr.
  11790. */
  11791. getAttribs: function () {
  11792. var series = this,
  11793. seriesOptions = series.options,
  11794. normalOptions = defaultPlotOptions[series.type].marker ? seriesOptions.marker : seriesOptions,
  11795. stateOptions = normalOptions.states,
  11796. stateOptionsHover = stateOptions[HOVER_STATE],
  11797. pointStateOptionsHover,
  11798. seriesColor = series.color,
  11799. seriesNegativeColor = series.options.negativeColor,
  11800. normalDefaults = {
  11801. stroke: seriesColor,
  11802. fill: seriesColor
  11803. },
  11804. points = series.points || [], // #927
  11805. i,
  11806. j,
  11807. threshold,
  11808. point,
  11809. seriesPointAttr = [],
  11810. pointAttr,
  11811. pointAttrToOptions = series.pointAttrToOptions,
  11812. hasPointSpecificOptions = series.hasPointSpecificOptions,
  11813. defaultLineColor = normalOptions.lineColor,
  11814. defaultFillColor = normalOptions.fillColor,
  11815. turboThreshold = seriesOptions.turboThreshold,
  11816. zones = series.zones,
  11817. zoneAxis = series.zoneAxis || 'y',
  11818. attr,
  11819. key;
  11820. // series type specific modifications
  11821. if (seriesOptions.marker) { // line, spline, area, areaspline, scatter
  11822. // if no hover radius is given, default to normal radius + 2
  11823. stateOptionsHover.radius = stateOptionsHover.radius || normalOptions.radius + stateOptionsHover.radiusPlus;
  11824. stateOptionsHover.lineWidth = stateOptionsHover.lineWidth || normalOptions.lineWidth + stateOptionsHover.lineWidthPlus;
  11825. } else { // column, bar, pie
  11826. // if no hover color is given, brighten the normal color
  11827. stateOptionsHover.color = stateOptionsHover.color ||
  11828. Color(stateOptionsHover.color || seriesColor)
  11829. .brighten(stateOptionsHover.brightness).get();
  11830. // if no hover negativeColor is given, brighten the normal negativeColor
  11831. stateOptionsHover.negativeColor = stateOptionsHover.negativeColor ||
  11832. Color(stateOptionsHover.negativeColor || seriesNegativeColor)
  11833. .brighten(stateOptionsHover.brightness).get();
  11834. }
  11835. // general point attributes for the series normal state
  11836. seriesPointAttr[NORMAL_STATE] = series.convertAttribs(normalOptions, normalDefaults);
  11837. // HOVER_STATE and SELECT_STATE states inherit from normal state except the default radius
  11838. each([HOVER_STATE, SELECT_STATE], function (state) {
  11839. seriesPointAttr[state] =
  11840. series.convertAttribs(stateOptions[state], seriesPointAttr[NORMAL_STATE]);
  11841. });
  11842. // set it
  11843. series.pointAttr = seriesPointAttr;
  11844. // Generate the point-specific attribute collections if specific point
  11845. // options are given. If not, create a referance to the series wide point
  11846. // attributes
  11847. i = points.length;
  11848. if (!turboThreshold || i < turboThreshold || hasPointSpecificOptions) {
  11849. while (i--) {
  11850. point = points[i];
  11851. normalOptions = (point.options && point.options.marker) || point.options;
  11852. if (normalOptions && normalOptions.enabled === false) {
  11853. normalOptions.radius = 0;
  11854. }
  11855. if (zones.length) {
  11856. j = 0;
  11857. threshold = zones[j];
  11858. while (point[zoneAxis] >= threshold.value) {
  11859. threshold = zones[++j];
  11860. }
  11861. point.color = point.fillColor = pick(threshold.color, series.color); // #3636, #4267, #4430 - inherit color from series, when color is undefined
  11862. }
  11863. hasPointSpecificOptions = seriesOptions.colorByPoint || point.color; // #868
  11864. // check if the point has specific visual options
  11865. if (point.options) {
  11866. for (key in pointAttrToOptions) {
  11867. if (defined(normalOptions[pointAttrToOptions[key]])) {
  11868. hasPointSpecificOptions = true;
  11869. }
  11870. }
  11871. }
  11872. // a specific marker config object is defined for the individual point:
  11873. // create it's own attribute collection
  11874. if (hasPointSpecificOptions) {
  11875. normalOptions = normalOptions || {};
  11876. pointAttr = [];
  11877. stateOptions = normalOptions.states || {}; // reassign for individual point
  11878. pointStateOptionsHover = stateOptions[HOVER_STATE] = stateOptions[HOVER_STATE] || {};
  11879. // Handle colors for column and pies
  11880. if (!seriesOptions.marker || (point.negative && !pointStateOptionsHover.fillColor && !stateOptionsHover.fillColor)) { // column, bar, point or negative threshold for series with markers (#3636)
  11881. // If no hover color is given, brighten the normal color. #1619, #2579
  11882. pointStateOptionsHover[series.pointAttrToOptions.fill] = pointStateOptionsHover.color || (!point.options.color && stateOptionsHover[(point.negative && seriesNegativeColor ? 'negativeColor' : 'color')]) ||
  11883. Color(point.color)
  11884. .brighten(pointStateOptionsHover.brightness || stateOptionsHover.brightness)
  11885. .get();
  11886. }
  11887. // normal point state inherits series wide normal state
  11888. attr = { color: point.color }; // #868
  11889. if (!defaultFillColor) { // Individual point color or negative color markers (#2219)
  11890. attr.fillColor = point.color;
  11891. }
  11892. if (!defaultLineColor) {
  11893. attr.lineColor = point.color; // Bubbles take point color, line markers use white
  11894. }
  11895. // Color is explicitly set to null or undefined (#1288, #4068)
  11896. if (normalOptions.hasOwnProperty('color') && !normalOptions.color) {
  11897. delete normalOptions.color;
  11898. }
  11899. pointAttr[NORMAL_STATE] = series.convertAttribs(extend(attr, normalOptions), seriesPointAttr[NORMAL_STATE]);
  11900. // inherit from point normal and series hover
  11901. pointAttr[HOVER_STATE] = series.convertAttribs(
  11902. stateOptions[HOVER_STATE],
  11903. seriesPointAttr[HOVER_STATE],
  11904. pointAttr[NORMAL_STATE]
  11905. );
  11906. // inherit from point normal and series hover
  11907. pointAttr[SELECT_STATE] = series.convertAttribs(
  11908. stateOptions[SELECT_STATE],
  11909. seriesPointAttr[SELECT_STATE],
  11910. pointAttr[NORMAL_STATE]
  11911. );
  11912. // no marker config object is created: copy a reference to the series-wide
  11913. // attribute collection
  11914. } else {
  11915. pointAttr = seriesPointAttr;
  11916. }
  11917. point.pointAttr = pointAttr;
  11918. }
  11919. }
  11920. },
  11921. /**
  11922. * Clear DOM objects and free up memory
  11923. */
  11924. destroy: function () {
  11925. var series = this,
  11926. chart = series.chart,
  11927. issue134 = /AppleWebKit\/533/.test(userAgent),
  11928. destroy,
  11929. i,
  11930. data = series.data || [],
  11931. point,
  11932. prop,
  11933. axis;
  11934. // add event hook
  11935. fireEvent(series, 'destroy');
  11936. // remove all events
  11937. removeEvent(series);
  11938. // erase from axes
  11939. each(series.axisTypes || [], function (AXIS) {
  11940. axis = series[AXIS];
  11941. if (axis) {
  11942. erase(axis.series, series);
  11943. axis.isDirty = axis.forceRedraw = true;
  11944. }
  11945. });
  11946. // remove legend items
  11947. if (series.legendItem) {
  11948. series.chart.legend.destroyItem(series);
  11949. }
  11950. // destroy all points with their elements
  11951. i = data.length;
  11952. while (i--) {
  11953. point = data[i];
  11954. if (point && point.destroy) {
  11955. point.destroy();
  11956. }
  11957. }
  11958. series.points = null;
  11959. // Clear the animation timeout if we are destroying the series during initial animation
  11960. clearTimeout(series.animationTimeout);
  11961. // Destroy all SVGElements associated to the series
  11962. for (prop in series) {
  11963. if (series[prop] instanceof SVGElement && !series[prop].survive) { // Survive provides a hook for not destroying
  11964. // issue 134 workaround
  11965. destroy = issue134 && prop === 'group' ?
  11966. 'hide' :
  11967. 'destroy';
  11968. series[prop][destroy]();
  11969. }
  11970. }
  11971. // remove from hoverSeries
  11972. if (chart.hoverSeries === series) {
  11973. chart.hoverSeries = null;
  11974. }
  11975. erase(chart.series, series);
  11976. // clear all members
  11977. for (prop in series) {
  11978. delete series[prop];
  11979. }
  11980. },
  11981. /**
  11982. * Return the graph path of a segment
  11983. */
  11984. getSegmentPath: function (segment) {
  11985. var series = this,
  11986. segmentPath = [],
  11987. step = series.options.step;
  11988. // build the segment line
  11989. each(segment, function (point, i) {
  11990. var plotX = point.plotX,
  11991. plotY = point.plotY,
  11992. lastPoint;
  11993. if (series.getPointSpline) { // generate the spline as defined in the SplineSeries object
  11994. segmentPath.push.apply(segmentPath, series.getPointSpline(segment, point, i));
  11995. } else {
  11996. // moveTo or lineTo
  11997. segmentPath.push(i ? L : M);
  11998. // step line?
  11999. if (step && i) {
  12000. lastPoint = segment[i - 1];
  12001. if (step === 'right') {
  12002. segmentPath.push(
  12003. lastPoint.plotX,
  12004. plotY,
  12005. L
  12006. );
  12007. } else if (step === 'center') {
  12008. segmentPath.push(
  12009. (lastPoint.plotX + plotX) / 2,
  12010. lastPoint.plotY,
  12011. L,
  12012. (lastPoint.plotX + plotX) / 2,
  12013. plotY,
  12014. L
  12015. );
  12016. } else {
  12017. segmentPath.push(
  12018. plotX,
  12019. lastPoint.plotY,
  12020. L
  12021. );
  12022. }
  12023. }
  12024. // normal line to next point
  12025. segmentPath.push(
  12026. point.plotX,
  12027. point.plotY
  12028. );
  12029. }
  12030. });
  12031. return segmentPath;
  12032. },
  12033. /**
  12034. * Get the graph path
  12035. */
  12036. getGraphPath: function () {
  12037. var series = this,
  12038. graphPath = [],
  12039. segmentPath,
  12040. singlePoints = []; // used in drawTracker
  12041. // Divide into segments and build graph and area paths
  12042. each(series.segments, function (segment) {
  12043. segmentPath = series.getSegmentPath(segment);
  12044. // add the segment to the graph, or a single point for tracking
  12045. if (segment.length > 1) {
  12046. graphPath = graphPath.concat(segmentPath);
  12047. } else {
  12048. singlePoints.push(segment[0]);
  12049. }
  12050. });
  12051. // Record it for use in drawGraph and drawTracker, and return graphPath
  12052. series.singlePoints = singlePoints;
  12053. series.graphPath = graphPath;
  12054. return graphPath;
  12055. },
  12056. /**
  12057. * Draw the actual graph
  12058. */
  12059. drawGraph: function () {
  12060. var series = this,
  12061. options = this.options,
  12062. props = [['graph', options.lineColor || this.color, options.dashStyle]],
  12063. lineWidth = options.lineWidth,
  12064. roundCap = options.linecap !== 'square',
  12065. graphPath = this.getGraphPath(),
  12066. fillColor = (this.fillGraph && this.color) || NONE, // polygon series use filled graph
  12067. zones = this.zones;
  12068. each(zones, function (threshold, i) {
  12069. props.push(['zoneGraph' + i, threshold.color || series.color, threshold.dashStyle || options.dashStyle]);
  12070. });
  12071. // Draw the graph
  12072. each(props, function (prop, i) {
  12073. var graphKey = prop[0],
  12074. graph = series[graphKey],
  12075. attribs;
  12076. if (graph) {
  12077. graph.animate({ d: graphPath });
  12078. } else if ((lineWidth || fillColor) && graphPath.length) { // #1487
  12079. attribs = {
  12080. stroke: prop[1],
  12081. 'stroke-width': lineWidth,
  12082. fill: fillColor,
  12083. zIndex: 1 // #1069
  12084. };
  12085. if (prop[2]) {
  12086. attribs.dashstyle = prop[2];
  12087. } else if (roundCap) {
  12088. attribs['stroke-linecap'] = attribs['stroke-linejoin'] = 'round';
  12089. }
  12090. series[graphKey] = series.chart.renderer.path(graphPath)
  12091. .attr(attribs)
  12092. .add(series.group)
  12093. .shadow((i < 2) && options.shadow); // add shadow to normal series (0) or to first zone (1) #3932
  12094. }
  12095. });
  12096. },
  12097. /**
  12098. * Clip the graphs into the positive and negative coloured graphs
  12099. */
  12100. applyZones: function () {
  12101. var series = this,
  12102. chart = this.chart,
  12103. renderer = chart.renderer,
  12104. zones = this.zones,
  12105. translatedFrom,
  12106. translatedTo,
  12107. clips = this.clips || [],
  12108. clipAttr,
  12109. graph = this.graph,
  12110. area = this.area,
  12111. chartSizeMax = mathMax(chart.chartWidth, chart.chartHeight),
  12112. axis = this[(this.zoneAxis || 'y') + 'Axis'],
  12113. extremes,
  12114. reversed = axis.reversed,
  12115. inverted = chart.inverted,
  12116. horiz = axis.horiz,
  12117. pxRange,
  12118. pxPosMin,
  12119. pxPosMax,
  12120. ignoreZones = false;
  12121. if (zones.length && (graph || area) && axis.min !== UNDEFINED) {
  12122. // The use of the Color Threshold assumes there are no gaps
  12123. // so it is safe to hide the original graph and area
  12124. if (graph) {
  12125. graph.hide();
  12126. }
  12127. if (area) {
  12128. area.hide();
  12129. }
  12130. // Create the clips
  12131. extremes = axis.getExtremes();
  12132. each(zones, function (threshold, i) {
  12133. translatedFrom = reversed ?
  12134. (horiz ? chart.plotWidth : 0) :
  12135. (horiz ? 0 : axis.toPixels(extremes.min));
  12136. translatedFrom = mathMin(mathMax(pick(translatedTo, translatedFrom), 0), chartSizeMax);
  12137. translatedTo = mathMin(mathMax(mathRound(axis.toPixels(pick(threshold.value, extremes.max), true)), 0), chartSizeMax);
  12138. if (ignoreZones) {
  12139. translatedFrom = translatedTo = axis.toPixels(extremes.max);
  12140. }
  12141. pxRange = Math.abs(translatedFrom - translatedTo);
  12142. pxPosMin = mathMin(translatedFrom, translatedTo);
  12143. pxPosMax = mathMax(translatedFrom, translatedTo);
  12144. if (axis.isXAxis) {
  12145. clipAttr = {
  12146. x: inverted ? pxPosMax : pxPosMin,
  12147. y: 0,
  12148. width: pxRange,
  12149. height: chartSizeMax
  12150. };
  12151. if (!horiz) {
  12152. clipAttr.x = chart.plotHeight - clipAttr.x;
  12153. }
  12154. } else {
  12155. clipAttr = {
  12156. x: 0,
  12157. y: inverted ? pxPosMax : pxPosMin,
  12158. width: chartSizeMax,
  12159. height: pxRange
  12160. };
  12161. if (horiz) {
  12162. clipAttr.y = chart.plotWidth - clipAttr.y;
  12163. }
  12164. }
  12165. /// VML SUPPPORT
  12166. if (chart.inverted && renderer.isVML) {
  12167. if (axis.isXAxis) {
  12168. clipAttr = {
  12169. x: 0,
  12170. y: reversed ? pxPosMin : pxPosMax,
  12171. height: clipAttr.width,
  12172. width: chart.chartWidth
  12173. };
  12174. } else {
  12175. clipAttr = {
  12176. x: clipAttr.y - chart.plotLeft - chart.spacingBox.x,
  12177. y: 0,
  12178. width: clipAttr.height,
  12179. height: chart.chartHeight
  12180. };
  12181. }
  12182. }
  12183. /// END OF VML SUPPORT
  12184. if (clips[i]) {
  12185. clips[i].animate(clipAttr);
  12186. } else {
  12187. clips[i] = renderer.clipRect(clipAttr);
  12188. if (graph) {
  12189. series['zoneGraph' + i].clip(clips[i]);
  12190. }
  12191. if (area) {
  12192. series['zoneArea' + i].clip(clips[i]);
  12193. }
  12194. }
  12195. // if this zone extends out of the axis, ignore the others
  12196. ignoreZones = threshold.value > extremes.max;
  12197. });
  12198. this.clips = clips;
  12199. }
  12200. },
  12201. /**
  12202. * Initialize and perform group inversion on series.group and series.markerGroup
  12203. */
  12204. invertGroups: function () {
  12205. var series = this,
  12206. chart = series.chart;
  12207. // Pie, go away (#1736)
  12208. if (!series.xAxis) {
  12209. return;
  12210. }
  12211. // A fixed size is needed for inversion to work
  12212. function setInvert() {
  12213. var size = {
  12214. width: series.yAxis.len,
  12215. height: series.xAxis.len
  12216. };
  12217. each(['group', 'markerGroup'], function (groupName) {
  12218. if (series[groupName]) {
  12219. series[groupName].attr(size).invert();
  12220. }
  12221. });
  12222. }
  12223. addEvent(chart, 'resize', setInvert); // do it on resize
  12224. addEvent(series, 'destroy', function () {
  12225. removeEvent(chart, 'resize', setInvert);
  12226. });
  12227. // Do it now
  12228. setInvert(); // do it now
  12229. // On subsequent render and redraw, just do setInvert without setting up events again
  12230. series.invertGroups = setInvert;
  12231. },
  12232. /**
  12233. * General abstraction for creating plot groups like series.group, series.dataLabelsGroup and
  12234. * series.markerGroup. On subsequent calls, the group will only be adjusted to the updated plot size.
  12235. */
  12236. plotGroup: function (prop, name, visibility, zIndex, parent) {
  12237. var group = this[prop],
  12238. isNew = !group;
  12239. // Generate it on first call
  12240. if (isNew) {
  12241. this[prop] = group = this.chart.renderer.g(name)
  12242. .attr({
  12243. visibility: visibility,
  12244. zIndex: zIndex || 0.1 // IE8 needs this
  12245. })
  12246. .add(parent);
  12247. group.addClass('highcharts-series-' + this.index);
  12248. }
  12249. // Place it on first and subsequent (redraw) calls
  12250. group[isNew ? 'attr' : 'animate'](this.getPlotBox());
  12251. return group;
  12252. },
  12253. /**
  12254. * Get the translation and scale for the plot area of this series
  12255. */
  12256. getPlotBox: function () {
  12257. var chart = this.chart,
  12258. xAxis = this.xAxis,
  12259. yAxis = this.yAxis;
  12260. // Swap axes for inverted (#2339)
  12261. if (chart.inverted) {
  12262. xAxis = yAxis;
  12263. yAxis = this.xAxis;
  12264. }
  12265. return {
  12266. translateX: xAxis ? xAxis.left : chart.plotLeft,
  12267. translateY: yAxis ? yAxis.top : chart.plotTop,
  12268. scaleX: 1, // #1623
  12269. scaleY: 1
  12270. };
  12271. },
  12272. /**
  12273. * Render the graph and markers
  12274. */
  12275. render: function () {
  12276. var series = this,
  12277. chart = series.chart,
  12278. group,
  12279. options = series.options,
  12280. animation = options.animation,
  12281. // Animation doesn't work in IE8 quirks when the group div is hidden,
  12282. // and looks bad in other oldIE
  12283. animDuration = (animation && !!series.animate && chart.renderer.isSVG && pick(animation.duration, 500)) || 0,
  12284. visibility = series.visible ? VISIBLE : HIDDEN,
  12285. zIndex = options.zIndex,
  12286. hasRendered = series.hasRendered,
  12287. chartSeriesGroup = chart.seriesGroup;
  12288. // the group
  12289. group = series.plotGroup(
  12290. 'group',
  12291. 'series',
  12292. visibility,
  12293. zIndex,
  12294. chartSeriesGroup
  12295. );
  12296. series.markerGroup = series.plotGroup(
  12297. 'markerGroup',
  12298. 'markers',
  12299. visibility,
  12300. zIndex,
  12301. chartSeriesGroup
  12302. );
  12303. // initiate the animation
  12304. if (animDuration) {
  12305. series.animate(true);
  12306. }
  12307. // cache attributes for shapes
  12308. series.getAttribs();
  12309. // SVGRenderer needs to know this before drawing elements (#1089, #1795)
  12310. group.inverted = series.isCartesian ? chart.inverted : false;
  12311. // draw the graph if any
  12312. if (series.drawGraph) {
  12313. series.drawGraph();
  12314. series.applyZones();
  12315. }
  12316. each(series.points, function (point) {
  12317. if (point.redraw) {
  12318. point.redraw();
  12319. }
  12320. });
  12321. // draw the data labels (inn pies they go before the points)
  12322. if (series.drawDataLabels) {
  12323. series.drawDataLabels();
  12324. }
  12325. // draw the points
  12326. if (series.visible) {
  12327. series.drawPoints();
  12328. }
  12329. // draw the mouse tracking area
  12330. if (series.drawTracker && series.options.enableMouseTracking !== false) {
  12331. series.drawTracker();
  12332. }
  12333. // Handle inverted series and tracker groups
  12334. if (chart.inverted) {
  12335. series.invertGroups();
  12336. }
  12337. // Initial clipping, must be defined after inverting groups for VML. Applies to columns etc. (#3839).
  12338. if (options.clip !== false && !series.sharedClipKey && !hasRendered) {
  12339. group.clip(chart.clipRect);
  12340. }
  12341. // Run the animation
  12342. if (animDuration) {
  12343. series.animate();
  12344. }
  12345. // Call the afterAnimate function on animation complete (but don't overwrite the animation.complete option
  12346. // which should be available to the user).
  12347. if (!hasRendered) {
  12348. if (animDuration) {
  12349. series.animationTimeout = setTimeout(function () {
  12350. series.afterAnimate();
  12351. }, animDuration);
  12352. } else {
  12353. series.afterAnimate();
  12354. }
  12355. }
  12356. series.isDirty = series.isDirtyData = false; // means data is in accordance with what you see
  12357. // (See #322) series.isDirty = series.isDirtyData = false; // means data is in accordance with what you see
  12358. series.hasRendered = true;
  12359. },
  12360. /**
  12361. * Redraw the series after an update in the axes.
  12362. */
  12363. redraw: function () {
  12364. var series = this,
  12365. chart = series.chart,
  12366. wasDirtyData = series.isDirtyData, // cache it here as it is set to false in render, but used after
  12367. wasDirty = series.isDirty,
  12368. group = series.group,
  12369. xAxis = series.xAxis,
  12370. yAxis = series.yAxis;
  12371. // reposition on resize
  12372. if (group) {
  12373. if (chart.inverted) {
  12374. group.attr({
  12375. width: chart.plotWidth,
  12376. height: chart.plotHeight
  12377. });
  12378. }
  12379. group.animate({
  12380. translateX: pick(xAxis && xAxis.left, chart.plotLeft),
  12381. translateY: pick(yAxis && yAxis.top, chart.plotTop)
  12382. });
  12383. }
  12384. series.translate();
  12385. series.render();
  12386. if (wasDirtyData) {
  12387. fireEvent(series, 'updatedData');
  12388. }
  12389. if (wasDirty || wasDirtyData) { // #3945 recalculate the kdtree when dirty
  12390. delete this.kdTree; // #3868 recalculate the kdtree with dirty data
  12391. }
  12392. },
  12393. /**
  12394. * KD Tree && PointSearching Implementation
  12395. */
  12396. kdDimensions: 1,
  12397. kdAxisArray: ['clientX', 'plotY'],
  12398. searchPoint: function (e, compareX) {
  12399. var series = this,
  12400. xAxis = series.xAxis,
  12401. yAxis = series.yAxis,
  12402. inverted = series.chart.inverted;
  12403. return this.searchKDTree({
  12404. clientX: inverted ? xAxis.len - e.chartY + xAxis.pos : e.chartX - xAxis.pos,
  12405. plotY: inverted ? yAxis.len - e.chartX + yAxis.pos : e.chartY - yAxis.pos
  12406. }, compareX);
  12407. },
  12408. buildKDTree: function () {
  12409. var series = this,
  12410. dimensions = series.kdDimensions;
  12411. // Internal function
  12412. function _kdtree(points, depth, dimensions) {
  12413. var axis, median, length = points && points.length;
  12414. if (length) {
  12415. // alternate between the axis
  12416. axis = series.kdAxisArray[depth % dimensions];
  12417. // sort point array
  12418. points.sort(function(a, b) {
  12419. return a[axis] - b[axis];
  12420. });
  12421. median = Math.floor(length / 2);
  12422. // build and return nod
  12423. return {
  12424. point: points[median],
  12425. left: _kdtree(points.slice(0, median), depth + 1, dimensions),
  12426. right: _kdtree(points.slice(median + 1), depth + 1, dimensions)
  12427. };
  12428. }
  12429. }
  12430. // Start the recursive build process with a clone of the points array and null points filtered out (#3873)
  12431. function startRecursive() {
  12432. var points = grep(series.points || [], function (point) { // #4390
  12433. return point.y !== null;
  12434. });
  12435. series.kdTree = _kdtree(points, dimensions, dimensions);
  12436. }
  12437. delete series.kdTree;
  12438. if (series.options.kdSync) { // For testing tooltips, don't build async
  12439. startRecursive();
  12440. } else {
  12441. setTimeout(startRecursive);
  12442. }
  12443. },
  12444. searchKDTree: function (point, compareX) {
  12445. var series = this,
  12446. kdX = this.kdAxisArray[0],
  12447. kdY = this.kdAxisArray[1],
  12448. kdComparer = compareX ? 'distX' : 'dist';
  12449. // Set the one and two dimensional distance on the point object
  12450. function setDistance(p1, p2) {
  12451. var x = (defined(p1[kdX]) && defined(p2[kdX])) ? Math.pow(p1[kdX] - p2[kdX], 2) : null,
  12452. y = (defined(p1[kdY]) && defined(p2[kdY])) ? Math.pow(p1[kdY] - p2[kdY], 2) : null,
  12453. r = (x || 0) + (y || 0);
  12454. p2.dist = defined(r) ? Math.sqrt(r) : Number.MAX_VALUE;
  12455. p2.distX = defined(x) ? Math.sqrt(x) : Number.MAX_VALUE;
  12456. }
  12457. function _search(search, tree, depth, dimensions) {
  12458. var point = tree.point,
  12459. axis = series.kdAxisArray[depth % dimensions],
  12460. tdist,
  12461. sideA,
  12462. sideB,
  12463. ret = point,
  12464. nPoint1,
  12465. nPoint2;
  12466. setDistance(search, point);
  12467. // Pick side based on distance to splitting point
  12468. tdist = search[axis] - point[axis];
  12469. sideA = tdist < 0 ? 'left' : 'right';
  12470. sideB = tdist < 0 ? 'right' : 'left';
  12471. // End of tree
  12472. if (tree[sideA]) {
  12473. nPoint1 =_search(search, tree[sideA], depth + 1, dimensions);
  12474. ret = (nPoint1[kdComparer] < ret[kdComparer] ? nPoint1 : point);
  12475. }
  12476. if (tree[sideB]) {
  12477. // compare distance to current best to splitting point to decide wether to check side B or not
  12478. if (Math.sqrt(tdist * tdist) < ret[kdComparer]) {
  12479. nPoint2 = _search(search, tree[sideB], depth + 1, dimensions);
  12480. ret = (nPoint2[kdComparer] < ret[kdComparer] ? nPoint2 : ret);
  12481. }
  12482. }
  12483. return ret;
  12484. }
  12485. if (!this.kdTree) {
  12486. this.buildKDTree();
  12487. }
  12488. if (this.kdTree) {
  12489. return _search(point,
  12490. this.kdTree, this.kdDimensions, this.kdDimensions);
  12491. }
  12492. }
  12493. }; // end Series prototype
  12494. // Extend the Chart prototype for dynamic methods
  12495. extend(Chart.prototype, {
  12496. /**
  12497. * Add a series dynamically after time
  12498. *
  12499. * @param {Object} options The config options
  12500. * @param {Boolean} redraw Whether to redraw the chart after adding. Defaults to true.
  12501. * @param {Boolean|Object} animation Whether to apply animation, and optionally animation
  12502. * configuration
  12503. *
  12504. * @return {Object} series The newly created series object
  12505. */
  12506. addSeries: function (options, redraw, animation) {
  12507. var series,
  12508. chart = this;
  12509. if (options) {
  12510. redraw = pick(redraw, true); // defaults to true
  12511. fireEvent(chart, 'addSeries', { options: options }, function () {
  12512. series = chart.initSeries(options);
  12513. chart.isDirtyLegend = true; // the series array is out of sync with the display
  12514. chart.linkSeries();
  12515. if (redraw) {
  12516. chart.redraw(animation);
  12517. }
  12518. });
  12519. }
  12520. return series;
  12521. },
  12522. /**
  12523. * Add an axis to the chart
  12524. * @param {Object} options The axis option
  12525. * @param {Boolean} isX Whether it is an X axis or a value axis
  12526. */
  12527. addAxis: function (options, isX, redraw, animation) {
  12528. var key = isX ? 'xAxis' : 'yAxis',
  12529. chartOptions = this.options,
  12530. axis;
  12531. /*jslint unused: false*/
  12532. axis = new Axis(this, merge(options, {
  12533. index: this[key].length,
  12534. isX: isX
  12535. }));
  12536. /*jslint unused: true*/
  12537. // Push the new axis options to the chart options
  12538. chartOptions[key] = splat(chartOptions[key] || {});
  12539. chartOptions[key].push(options);
  12540. if (pick(redraw, true)) {
  12541. this.redraw(animation);
  12542. }
  12543. },
  12544. /**
  12545. * Dim the chart and show a loading text or symbol
  12546. * @param {String} str An optional text to show in the loading label instead of the default one
  12547. */
  12548. showLoading: function (str) {
  12549. var chart = this,
  12550. options = chart.options,
  12551. loadingDiv = chart.loadingDiv,
  12552. loadingOptions = options.loading,
  12553. setLoadingSize = function () {
  12554. if (loadingDiv) {
  12555. css(loadingDiv, {
  12556. left: chart.plotLeft + PX,
  12557. top: chart.plotTop + PX,
  12558. width: chart.plotWidth + PX,
  12559. height: chart.plotHeight + PX
  12560. });
  12561. }
  12562. };
  12563. // create the layer at the first call
  12564. if (!loadingDiv) {
  12565. chart.loadingDiv = loadingDiv = createElement(DIV, {
  12566. className: PREFIX + 'loading'
  12567. }, extend(loadingOptions.style, {
  12568. zIndex: 10,
  12569. display: NONE
  12570. }), chart.container);
  12571. chart.loadingSpan = createElement(
  12572. 'span',
  12573. null,
  12574. loadingOptions.labelStyle,
  12575. loadingDiv
  12576. );
  12577. addEvent(chart, 'redraw', setLoadingSize); // #1080
  12578. }
  12579. // update text
  12580. chart.loadingSpan.innerHTML = str || options.lang.loading;
  12581. // show it
  12582. if (!chart.loadingShown) {
  12583. css(loadingDiv, {
  12584. opacity: 0,
  12585. display: ''
  12586. });
  12587. animate(loadingDiv, {
  12588. opacity: loadingOptions.style.opacity
  12589. }, {
  12590. duration: loadingOptions.showDuration || 0
  12591. });
  12592. chart.loadingShown = true;
  12593. }
  12594. setLoadingSize();
  12595. },
  12596. /**
  12597. * Hide the loading layer
  12598. */
  12599. hideLoading: function () {
  12600. var options = this.options,
  12601. loadingDiv = this.loadingDiv;
  12602. if (loadingDiv) {
  12603. animate(loadingDiv, {
  12604. opacity: 0
  12605. }, {
  12606. duration: options.loading.hideDuration || 100,
  12607. complete: function () {
  12608. css(loadingDiv, { display: NONE });
  12609. }
  12610. });
  12611. }
  12612. this.loadingShown = false;
  12613. }
  12614. });
  12615. // extend the Point prototype for dynamic methods
  12616. extend(Point.prototype, {
  12617. /**
  12618. * Update the point with new options (typically x/y data) and optionally redraw the series.
  12619. *
  12620. * @param {Object} options Point options as defined in the series.data array
  12621. * @param {Boolean} redraw Whether to redraw the chart or wait for an explicit call
  12622. * @param {Boolean|Object} animation Whether to apply animation, and optionally animation
  12623. * configuration
  12624. *
  12625. */
  12626. update: function (options, redraw, animation, runEvent) {
  12627. var point = this,
  12628. series = point.series,
  12629. graphic = point.graphic,
  12630. i,
  12631. chart = series.chart,
  12632. seriesOptions = series.options,
  12633. names = series.xAxis && series.xAxis.names;
  12634. redraw = pick(redraw, true);
  12635. function update() {
  12636. point.applyOptions(options);
  12637. // Update visuals
  12638. if (point.y === null && graphic) { // #4146
  12639. point.graphic = graphic.destroy();
  12640. }
  12641. if (isObject(options) && !isArray(options)) {
  12642. // Defer the actual redraw until getAttribs has been called (#3260)
  12643. point.redraw = function () {
  12644. if (graphic && graphic.element) {
  12645. if (options && options.marker && options.marker.symbol) {
  12646. point.graphic = graphic.destroy();
  12647. }
  12648. }
  12649. if (options && options.dataLabels && point.dataLabel) { // #2468
  12650. point.dataLabel = point.dataLabel.destroy();
  12651. }
  12652. point.redraw = null;
  12653. };
  12654. }
  12655. // record changes in the parallel arrays
  12656. i = point.index;
  12657. series.updateParallelArrays(point, i);
  12658. if (names && point.name) {
  12659. names[point.x] = point.name;
  12660. }
  12661. seriesOptions.data[i] = point.options;
  12662. // redraw
  12663. series.isDirty = series.isDirtyData = true;
  12664. if (!series.fixedBox && series.hasCartesianSeries) { // #1906, #2320
  12665. chart.isDirtyBox = true;
  12666. }
  12667. if (seriesOptions.legendType === 'point') { // #1831, #1885
  12668. chart.isDirtyLegend = true;
  12669. }
  12670. if (redraw) {
  12671. chart.redraw(animation);
  12672. }
  12673. }
  12674. // Fire the event with a default handler of doing the update
  12675. if (runEvent === false) { // When called from setData
  12676. update();
  12677. } else {
  12678. point.firePointEvent('update', { options: options }, update);
  12679. }
  12680. },
  12681. /**
  12682. * Remove a point and optionally redraw the series and if necessary the axes
  12683. * @param {Boolean} redraw Whether to redraw the chart or wait for an explicit call
  12684. * @param {Boolean|Object} animation Whether to apply animation, and optionally animation
  12685. * configuration
  12686. */
  12687. remove: function (redraw, animation) {
  12688. this.series.removePoint(inArray(this, this.series.data), redraw, animation);
  12689. }
  12690. });
  12691. // Extend the series prototype for dynamic methods
  12692. extend(Series.prototype, {
  12693. /**
  12694. * Add a point dynamically after chart load time
  12695. * @param {Object} options Point options as given in series.data
  12696. * @param {Boolean} redraw Whether to redraw the chart or wait for an explicit call
  12697. * @param {Boolean} shift If shift is true, a point is shifted off the start
  12698. * of the series as one is appended to the end.
  12699. * @param {Boolean|Object} animation Whether to apply animation, and optionally animation
  12700. * configuration
  12701. */
  12702. addPoint: function (options, redraw, shift, animation) {
  12703. var series = this,
  12704. seriesOptions = series.options,
  12705. data = series.data,
  12706. graph = series.graph,
  12707. area = series.area,
  12708. chart = series.chart,
  12709. names = series.xAxis && series.xAxis.names,
  12710. currentShift = (graph && graph.shift) || 0,
  12711. shiftShapes = ['graph', 'area'],
  12712. dataOptions = seriesOptions.data,
  12713. point,
  12714. isInTheMiddle,
  12715. xData = series.xData,
  12716. i,
  12717. x;
  12718. setAnimation(animation, chart);
  12719. // Make graph animate sideways
  12720. if (shift) {
  12721. i = series.zones.length;
  12722. while (i--) {
  12723. shiftShapes.push('zoneGraph' + i, 'zoneArea' + i);
  12724. }
  12725. each(shiftShapes, function (shape) {
  12726. if (series[shape]) {
  12727. series[shape].shift = currentShift + (seriesOptions.step ? 2 : 1);
  12728. }
  12729. });
  12730. }
  12731. if (area) {
  12732. area.isArea = true; // needed in animation, both with and without shift
  12733. }
  12734. // Optional redraw, defaults to true
  12735. redraw = pick(redraw, true);
  12736. // Get options and push the point to xData, yData and series.options. In series.generatePoints
  12737. // the Point instance will be created on demand and pushed to the series.data array.
  12738. point = { series: series };
  12739. series.pointClass.prototype.applyOptions.apply(point, [options]);
  12740. x = point.x;
  12741. // Get the insertion point
  12742. i = xData.length;
  12743. if (series.requireSorting && x < xData[i - 1]) {
  12744. isInTheMiddle = true;
  12745. while (i && xData[i - 1] > x) {
  12746. i--;
  12747. }
  12748. }
  12749. series.updateParallelArrays(point, 'splice', i, 0, 0); // insert undefined item
  12750. series.updateParallelArrays(point, i); // update it
  12751. if (names && point.name) {
  12752. names[x] = point.name;
  12753. }
  12754. dataOptions.splice(i, 0, options);
  12755. if (isInTheMiddle) {
  12756. series.data.splice(i, 0, null);
  12757. series.processData();
  12758. }
  12759. // Generate points to be added to the legend (#1329)
  12760. if (seriesOptions.legendType === 'point') {
  12761. series.generatePoints();
  12762. }
  12763. // Shift the first point off the parallel arrays
  12764. // todo: consider series.removePoint(i) method
  12765. if (shift) {
  12766. if (data[0] && data[0].remove) {
  12767. data[0].remove(false);
  12768. } else {
  12769. data.shift();
  12770. series.updateParallelArrays(point, 'shift');
  12771. dataOptions.shift();
  12772. }
  12773. }
  12774. // redraw
  12775. series.isDirty = true;
  12776. series.isDirtyData = true;
  12777. if (redraw) {
  12778. series.getAttribs(); // #1937
  12779. chart.redraw();
  12780. }
  12781. },
  12782. /**
  12783. * Remove a point (rendered or not), by index
  12784. */
  12785. removePoint: function (i, redraw, animation) {
  12786. var series = this,
  12787. data = series.data,
  12788. point = data[i],
  12789. points = series.points,
  12790. chart = series.chart,
  12791. remove = function () {
  12792. if (data.length === points.length) {
  12793. points.splice(i, 1);
  12794. }
  12795. data.splice(i, 1);
  12796. series.options.data.splice(i, 1);
  12797. series.updateParallelArrays(point || { series: series }, 'splice', i, 1);
  12798. if (point) {
  12799. point.destroy();
  12800. }
  12801. // redraw
  12802. series.isDirty = true;
  12803. series.isDirtyData = true;
  12804. if (redraw) {
  12805. chart.redraw();
  12806. }
  12807. };
  12808. setAnimation(animation, chart);
  12809. redraw = pick(redraw, true);
  12810. // Fire the event with a default handler of removing the point
  12811. if (point) {
  12812. point.firePointEvent('remove', null, remove);
  12813. } else {
  12814. remove();
  12815. }
  12816. },
  12817. /**
  12818. * Remove a series and optionally redraw the chart
  12819. *
  12820. * @param {Boolean} redraw Whether to redraw the chart or wait for an explicit call
  12821. * @param {Boolean|Object} animation Whether to apply animation, and optionally animation
  12822. * configuration
  12823. */
  12824. remove: function (redraw, animation) {
  12825. var series = this,
  12826. chart = series.chart;
  12827. redraw = pick(redraw, true);
  12828. if (!series.isRemoving) { /* prevent triggering native event in jQuery
  12829. (calling the remove function from the remove event) */
  12830. series.isRemoving = true;
  12831. // fire the event with a default handler of removing the point
  12832. fireEvent(series, 'remove', null, function () {
  12833. // destroy elements
  12834. series.destroy();
  12835. // redraw
  12836. chart.isDirtyLegend = chart.isDirtyBox = true;
  12837. chart.linkSeries();
  12838. if (redraw) {
  12839. chart.redraw(animation);
  12840. }
  12841. });
  12842. }
  12843. series.isRemoving = false;
  12844. },
  12845. /**
  12846. * Update the series with a new set of options
  12847. */
  12848. update: function (newOptions, redraw) {
  12849. var series = this,
  12850. chart = this.chart,
  12851. // must use user options when changing type because this.options is merged
  12852. // in with type specific plotOptions
  12853. oldOptions = this.userOptions,
  12854. oldType = this.type,
  12855. proto = seriesTypes[oldType].prototype,
  12856. preserve = ['group', 'markerGroup', 'dataLabelsGroup'],
  12857. n;
  12858. // If we're changing type or zIndex, create new groups (#3380, #3404)
  12859. if ((newOptions.type && newOptions.type !== oldType) || newOptions.zIndex !== undefined) {
  12860. preserve.length = 0;
  12861. }
  12862. // Make sure groups are not destroyed (#3094)
  12863. each(preserve, function (prop) {
  12864. preserve[prop] = series[prop];
  12865. delete series[prop];
  12866. });
  12867. // Do the merge, with some forced options
  12868. newOptions = merge(oldOptions, {
  12869. animation: false,
  12870. index: this.index,
  12871. pointStart: this.xData[0] // when updating after addPoint
  12872. }, { data: this.options.data }, newOptions);
  12873. // Destroy the series and delete all properties. Reinsert all methods
  12874. // and properties from the new type prototype (#2270, #3719)
  12875. this.remove(false);
  12876. for (n in proto) {
  12877. this[n] = UNDEFINED;
  12878. }
  12879. extend(this, seriesTypes[newOptions.type || oldType].prototype);
  12880. // Re-register groups (#3094)
  12881. each(preserve, function (prop) {
  12882. series[prop] = preserve[prop];
  12883. });
  12884. this.init(chart, newOptions);
  12885. chart.linkSeries(); // Links are lost in this.remove (#3028)
  12886. if (pick(redraw, true)) {
  12887. chart.redraw(false);
  12888. }
  12889. }
  12890. });
  12891. // Extend the Axis.prototype for dynamic methods
  12892. extend(Axis.prototype, {
  12893. /**
  12894. * Update the axis with a new options structure
  12895. */
  12896. update: function (newOptions, redraw) {
  12897. var chart = this.chart;
  12898. newOptions = chart.options[this.coll][this.options.index] = merge(this.userOptions, newOptions);
  12899. this.destroy(true);
  12900. this._addedPlotLB = this.chart._labelPanes = UNDEFINED; // #1611, #2887, #4314
  12901. this.init(chart, extend(newOptions, { events: UNDEFINED }));
  12902. chart.isDirtyBox = true;
  12903. if (pick(redraw, true)) {
  12904. chart.redraw();
  12905. }
  12906. },
  12907. /**
  12908. * Remove the axis from the chart
  12909. */
  12910. remove: function (redraw) {
  12911. var chart = this.chart,
  12912. key = this.coll, // xAxis or yAxis
  12913. axisSeries = this.series,
  12914. i = axisSeries.length;
  12915. // Remove associated series (#2687)
  12916. while (i--) {
  12917. if (axisSeries[i]) {
  12918. axisSeries[i].remove(false);
  12919. }
  12920. }
  12921. // Remove the axis
  12922. erase(chart.axes, this);
  12923. erase(chart[key], this);
  12924. chart.options[key].splice(this.options.index, 1);
  12925. each(chart[key], function (axis, i) { // Re-index, #1706
  12926. axis.options.index = i;
  12927. });
  12928. this.destroy();
  12929. chart.isDirtyBox = true;
  12930. if (pick(redraw, true)) {
  12931. chart.redraw();
  12932. }
  12933. },
  12934. /**
  12935. * Update the axis title by options
  12936. */
  12937. setTitle: function (newTitleOptions, redraw) {
  12938. this.update({ title: newTitleOptions }, redraw);
  12939. },
  12940. /**
  12941. * Set new axis categories and optionally redraw
  12942. * @param {Array} categories
  12943. * @param {Boolean} redraw
  12944. */
  12945. setCategories: function (categories, redraw) {
  12946. this.update({ categories: categories }, redraw);
  12947. }
  12948. });
  12949. /**
  12950. * LineSeries object
  12951. */
  12952. var LineSeries = extendClass(Series);
  12953. seriesTypes.line = LineSeries;
  12954. /**
  12955. * Set the default options for column
  12956. */
  12957. defaultPlotOptions.column = merge(defaultSeriesOptions, {
  12958. borderColor: '#FFFFFF',
  12959. //borderWidth: 1,
  12960. borderRadius: 0,
  12961. //colorByPoint: undefined,
  12962. groupPadding: 0.2,
  12963. //grouping: true,
  12964. marker: null, // point options are specified in the base options
  12965. pointPadding: 0.1,
  12966. //pointWidth: null,
  12967. minPointLength: 0,
  12968. cropThreshold: 50, // when there are more points, they will not animate out of the chart on xAxis.setExtremes
  12969. pointRange: null, // null means auto, meaning 1 in a categorized axis and least distance between points if not categories
  12970. states: {
  12971. hover: {
  12972. brightness: 0.1,
  12973. shadow: false,
  12974. halo: false
  12975. },
  12976. select: {
  12977. color: '#C0C0C0',
  12978. borderColor: '#000000',
  12979. shadow: false
  12980. }
  12981. },
  12982. dataLabels: {
  12983. align: null, // auto
  12984. verticalAlign: null, // auto
  12985. y: null
  12986. },
  12987. softThreshold: false,
  12988. startFromThreshold: true, // docs (but false doesn't work well): http://jsfiddle.net/highcharts/hz8fopan/14/
  12989. stickyTracking: false,
  12990. tooltip: {
  12991. distance: 6
  12992. },
  12993. threshold: 0
  12994. });
  12995. /**
  12996. * ColumnSeries object
  12997. */
  12998. var ColumnSeries = extendClass(Series, {
  12999. type: 'column',
  13000. pointAttrToOptions: { // mapping between SVG attributes and the corresponding options
  13001. stroke: 'borderColor',
  13002. fill: 'color',
  13003. r: 'borderRadius'
  13004. },
  13005. cropShoulder: 0,
  13006. directTouch: true, // When tooltip is not shared, this series (and derivatives) requires direct touch/hover. KD-tree does not apply.
  13007. trackerGroups: ['group', 'dataLabelsGroup'],
  13008. negStacks: true, // use separate negative stacks, unlike area stacks where a negative
  13009. // point is substracted from previous (#1910)
  13010. /**
  13011. * Initialize the series
  13012. */
  13013. init: function () {
  13014. Series.prototype.init.apply(this, arguments);
  13015. var series = this,
  13016. chart = series.chart;
  13017. // if the series is added dynamically, force redraw of other
  13018. // series affected by a new column
  13019. if (chart.hasRendered) {
  13020. each(chart.series, function (otherSeries) {
  13021. if (otherSeries.type === series.type) {
  13022. otherSeries.isDirty = true;
  13023. }
  13024. });
  13025. }
  13026. },
  13027. /**
  13028. * Return the width and x offset of the columns adjusted for grouping, groupPadding, pointPadding,
  13029. * pointWidth etc.
  13030. */
  13031. getColumnMetrics: function () {
  13032. var series = this,
  13033. options = series.options,
  13034. xAxis = series.xAxis,
  13035. yAxis = series.yAxis,
  13036. reversedXAxis = xAxis.reversed,
  13037. stackKey,
  13038. stackGroups = {},
  13039. columnIndex,
  13040. columnCount = 0;
  13041. // Get the total number of column type series.
  13042. // This is called on every series. Consider moving this logic to a
  13043. // chart.orderStacks() function and call it on init, addSeries and removeSeries
  13044. if (options.grouping === false) {
  13045. columnCount = 1;
  13046. } else {
  13047. each(series.chart.series, function (otherSeries) {
  13048. var otherOptions = otherSeries.options,
  13049. otherYAxis = otherSeries.yAxis;
  13050. if (otherSeries.type === series.type && otherSeries.visible &&
  13051. yAxis.len === otherYAxis.len && yAxis.pos === otherYAxis.pos) { // #642, #2086
  13052. if (otherOptions.stacking) {
  13053. stackKey = otherSeries.stackKey;
  13054. if (stackGroups[stackKey] === UNDEFINED) {
  13055. stackGroups[stackKey] = columnCount++;
  13056. }
  13057. columnIndex = stackGroups[stackKey];
  13058. } else if (otherOptions.grouping !== false) { // #1162
  13059. columnIndex = columnCount++;
  13060. }
  13061. otherSeries.columnIndex = columnIndex;
  13062. }
  13063. });
  13064. }
  13065. var categoryWidth = mathMin(
  13066. mathAbs(xAxis.transA) * (xAxis.ordinalSlope || options.pointRange || xAxis.closestPointRange || xAxis.tickInterval || 1), // #2610
  13067. xAxis.len // #1535
  13068. ),
  13069. groupPadding = categoryWidth * options.groupPadding,
  13070. groupWidth = categoryWidth - 2 * groupPadding,
  13071. pointOffsetWidth = groupWidth / columnCount,
  13072. pointWidth = mathMin(
  13073. options.maxPointWidth || xAxis.len,
  13074. pick(options.pointWidth, pointOffsetWidth * (1 - 2 * options.pointPadding))
  13075. ),
  13076. pointPadding = (pointOffsetWidth - pointWidth) / 2,
  13077. colIndex = (reversedXAxis ?
  13078. columnCount - (series.columnIndex || 0) : // #1251
  13079. series.columnIndex) || 0,
  13080. pointXOffset = pointPadding + (groupPadding + colIndex *
  13081. pointOffsetWidth - (categoryWidth / 2)) *
  13082. (reversedXAxis ? -1 : 1);
  13083. // Save it for reading in linked series (Error bars particularly)
  13084. return (series.columnMetrics = {
  13085. width: pointWidth,
  13086. offset: pointXOffset
  13087. });
  13088. },
  13089. /**
  13090. * Make the columns crisp. The edges are rounded to the nearest full pixel.
  13091. */
  13092. crispCol: function (x, y, w, h) {
  13093. var chart = this.chart,
  13094. borderWidth = this.borderWidth,
  13095. xCrisp = -(borderWidth % 2 ? 0.5 : 0),
  13096. yCrisp = borderWidth % 2 ? 0.5 : 1,
  13097. right,
  13098. bottom,
  13099. fromTop;
  13100. if (chart.inverted && chart.renderer.isVML) {
  13101. yCrisp += 1;
  13102. }
  13103. // Horizontal. We need to first compute the exact right edge, then round it
  13104. // and compute the width from there.
  13105. right = Math.round(x + w) + xCrisp;
  13106. x = Math.round(x) + xCrisp;
  13107. w = right - x;
  13108. // Vertical
  13109. fromTop = mathAbs(y) <= 0.5; // #4504
  13110. bottom = Math.round(y + h) + yCrisp;
  13111. y = Math.round(y) + yCrisp;
  13112. h = bottom - y;
  13113. // Top edges are exceptions
  13114. if (fromTop) {
  13115. y -= 1;
  13116. h += 1;
  13117. }
  13118. return {
  13119. x: x,
  13120. y: y,
  13121. width: w,
  13122. height: h
  13123. };
  13124. },
  13125. /**
  13126. * Translate each point to the plot area coordinate system and find shape positions
  13127. */
  13128. translate: function () {
  13129. var series = this,
  13130. chart = series.chart,
  13131. options = series.options,
  13132. borderWidth = series.borderWidth = pick(
  13133. options.borderWidth,
  13134. series.closestPointRange * series.xAxis.transA < 2 ? 0 : 1 // #3635
  13135. ),
  13136. yAxis = series.yAxis,
  13137. threshold = options.threshold,
  13138. translatedThreshold = series.translatedThreshold = yAxis.getThreshold(threshold),
  13139. minPointLength = pick(options.minPointLength, 5),
  13140. metrics = series.getColumnMetrics(),
  13141. pointWidth = metrics.width,
  13142. seriesBarW = series.barW = mathMax(pointWidth, 1 + 2 * borderWidth), // postprocessed for border width
  13143. pointXOffset = series.pointXOffset = metrics.offset;
  13144. if (chart.inverted) {
  13145. translatedThreshold -= 0.5; // #3355
  13146. }
  13147. // When the pointPadding is 0, we want the columns to be packed tightly, so we allow individual
  13148. // columns to have individual sizes. When pointPadding is greater, we strive for equal-width
  13149. // columns (#2694).
  13150. if (options.pointPadding) {
  13151. seriesBarW = mathCeil(seriesBarW);
  13152. }
  13153. Series.prototype.translate.apply(series);
  13154. // Record the new values
  13155. each(series.points, function (point) {
  13156. var yBottom = mathMin(pick(point.yBottom, translatedThreshold), 9e4), // #3575
  13157. safeDistance = 999 + mathAbs(yBottom),
  13158. plotY = mathMin(mathMax(-safeDistance, point.plotY), yAxis.len + safeDistance), // Don't draw too far outside plot area (#1303, #2241, #4264)
  13159. barX = point.plotX + pointXOffset,
  13160. barW = seriesBarW,
  13161. barY = mathMin(plotY, yBottom),
  13162. up,
  13163. barH = mathMax(plotY, yBottom) - barY;
  13164. // Handle options.minPointLength
  13165. if (mathAbs(barH) < minPointLength) {
  13166. if (minPointLength) {
  13167. barH = minPointLength;
  13168. up = (!yAxis.reversed && !point.negative) || (yAxis.reversed && point.negative);
  13169. barY = mathAbs(barY - translatedThreshold) > minPointLength ? // stacked
  13170. yBottom - minPointLength : // keep position
  13171. translatedThreshold - (up ? minPointLength : 0); // #1485, #4051
  13172. }
  13173. }
  13174. // Cache for access in polar
  13175. point.barX = barX;
  13176. point.pointWidth = pointWidth;
  13177. // Fix the tooltip on center of grouped columns (#1216, #424, #3648)
  13178. point.tooltipPos = chart.inverted ?
  13179. [yAxis.len + yAxis.pos - chart.plotLeft - plotY, series.xAxis.len - barX - barW / 2, barH] :
  13180. [barX + barW / 2, plotY + yAxis.pos - chart.plotTop, barH];
  13181. // Register shape type and arguments to be used in drawPoints
  13182. point.shapeType = 'rect';
  13183. point.shapeArgs = series.crispCol(barX, barY, barW, barH);
  13184. });
  13185. },
  13186. getSymbol: noop,
  13187. /**
  13188. * Use a solid rectangle like the area series types
  13189. */
  13190. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  13191. /**
  13192. * Columns have no graph
  13193. */
  13194. drawGraph: noop,
  13195. /**
  13196. * Draw the columns. For bars, the series.group is rotated, so the same coordinates
  13197. * apply for columns and bars. This method is inherited by scatter series.
  13198. *
  13199. */
  13200. drawPoints: function () {
  13201. var series = this,
  13202. chart = this.chart,
  13203. options = series.options,
  13204. renderer = chart.renderer,
  13205. animationLimit = options.animationLimit || 250,
  13206. shapeArgs,
  13207. pointAttr;
  13208. // draw the columns
  13209. each(series.points, function (point) {
  13210. var plotY = point.plotY,
  13211. graphic = point.graphic,
  13212. borderAttr;
  13213. if (plotY !== UNDEFINED && !isNaN(plotY) && point.y !== null) {
  13214. shapeArgs = point.shapeArgs;
  13215. borderAttr = defined(series.borderWidth) ? {
  13216. 'stroke-width': series.borderWidth
  13217. } : {};
  13218. pointAttr = point.pointAttr[point.selected ? SELECT_STATE : NORMAL_STATE] || series.pointAttr[NORMAL_STATE];
  13219. if (graphic) { // update
  13220. stop(graphic);
  13221. graphic.attr(borderAttr)[chart.pointCount < animationLimit ? 'animate' : 'attr'](merge(shapeArgs));
  13222. } else {
  13223. point.graphic = graphic = renderer[point.shapeType](shapeArgs)
  13224. .attr(borderAttr)
  13225. .attr(pointAttr)
  13226. .add(point.group || series.group)
  13227. .shadow(options.shadow, null, options.stacking && !options.borderRadius);
  13228. }
  13229. } else if (graphic) {
  13230. point.graphic = graphic.destroy(); // #1269
  13231. }
  13232. });
  13233. },
  13234. /**
  13235. * Animate the column heights one by one from zero
  13236. * @param {Boolean} init Whether to initialize the animation or run it
  13237. */
  13238. animate: function (init) {
  13239. var series = this,
  13240. yAxis = this.yAxis,
  13241. options = series.options,
  13242. inverted = this.chart.inverted,
  13243. attr = {},
  13244. translatedThreshold;
  13245. if (hasSVG) { // VML is too slow anyway
  13246. if (init) {
  13247. attr.scaleY = 0.001;
  13248. translatedThreshold = mathMin(yAxis.pos + yAxis.len, mathMax(yAxis.pos, yAxis.toPixels(options.threshold)));
  13249. if (inverted) {
  13250. attr.translateX = translatedThreshold - yAxis.len;
  13251. } else {
  13252. attr.translateY = translatedThreshold;
  13253. }
  13254. series.group.attr(attr);
  13255. } else { // run the animation
  13256. attr.scaleY = 1;
  13257. attr[inverted ? 'translateX' : 'translateY'] = yAxis.pos;
  13258. series.group.animate(attr, series.options.animation);
  13259. // delete this function to allow it only once
  13260. series.animate = null;
  13261. }
  13262. }
  13263. },
  13264. /**
  13265. * Remove this series from the chart
  13266. */
  13267. remove: function () {
  13268. var series = this,
  13269. chart = series.chart;
  13270. // column and bar series affects other series of the same type
  13271. // as they are either stacked or grouped
  13272. if (chart.hasRendered) {
  13273. each(chart.series, function (otherSeries) {
  13274. if (otherSeries.type === series.type) {
  13275. otherSeries.isDirty = true;
  13276. }
  13277. });
  13278. }
  13279. Series.prototype.remove.apply(series, arguments);
  13280. }
  13281. });
  13282. seriesTypes.column = ColumnSeries;
  13283. /**
  13284. * Set the default options for scatter
  13285. */
  13286. defaultPlotOptions.scatter = merge(defaultSeriesOptions, {
  13287. lineWidth: 0,
  13288. marker: {
  13289. enabled: true // Overrides auto-enabling in line series (#3647)
  13290. },
  13291. tooltip: {
  13292. headerFormat: '<span style="color:{point.color}">\u25CF</span> <span style="font-size: 10px;"> {series.name}</span><br/>',
  13293. pointFormat: 'x: <b>{point.x}</b><br/>y: <b>{point.y}</b><br/>'
  13294. }
  13295. });
  13296. /**
  13297. * The scatter series class
  13298. */
  13299. var ScatterSeries = extendClass(Series, {
  13300. type: 'scatter',
  13301. sorted: false,
  13302. requireSorting: false,
  13303. noSharedTooltip: true,
  13304. trackerGroups: ['group', 'markerGroup', 'dataLabelsGroup'],
  13305. takeOrdinalPosition: false, // #2342
  13306. kdDimensions: 2,
  13307. drawGraph: function () {
  13308. if (this.options.lineWidth) {
  13309. Series.prototype.drawGraph.call(this);
  13310. }
  13311. }
  13312. });
  13313. seriesTypes.scatter = ScatterSeries;
  13314. /**
  13315. * Draw the data labels
  13316. */
  13317. Series.prototype.drawDataLabels = function () {
  13318. var series = this,
  13319. seriesOptions = series.options,
  13320. cursor = seriesOptions.cursor,
  13321. options = seriesOptions.dataLabels,
  13322. points = series.points,
  13323. pointOptions,
  13324. generalOptions,
  13325. hasRendered = series.hasRendered || 0,
  13326. str,
  13327. dataLabelsGroup,
  13328. renderer = series.chart.renderer;
  13329. if (options.enabled || series._hasPointLabels) {
  13330. // Process default alignment of data labels for columns
  13331. if (series.dlProcessOptions) {
  13332. series.dlProcessOptions(options);
  13333. }
  13334. // Create a separate group for the data labels to avoid rotation
  13335. dataLabelsGroup = series.plotGroup(
  13336. 'dataLabelsGroup',
  13337. 'data-labels',
  13338. options.defer ? HIDDEN : VISIBLE,
  13339. options.zIndex || 6
  13340. );
  13341. if (pick(options.defer, true)) {
  13342. dataLabelsGroup.attr({ opacity: +hasRendered }); // #3300
  13343. if (!hasRendered) {
  13344. addEvent(series, 'afterAnimate', function () {
  13345. if (series.visible) { // #3023, #3024
  13346. dataLabelsGroup.show();
  13347. }
  13348. dataLabelsGroup[seriesOptions.animation ? 'animate' : 'attr']({ opacity: 1 }, { duration: 200 });
  13349. });
  13350. }
  13351. }
  13352. // Make the labels for each point
  13353. generalOptions = options;
  13354. each(points, function (point) {
  13355. var enabled,
  13356. dataLabel = point.dataLabel,
  13357. labelConfig,
  13358. attr,
  13359. name,
  13360. rotation,
  13361. connector = point.connector,
  13362. isNew = true,
  13363. style,
  13364. moreStyle = {};
  13365. // Determine if each data label is enabled
  13366. pointOptions = point.dlOptions || (point.options && point.options.dataLabels); // dlOptions is used in treemaps
  13367. enabled = pick(pointOptions && pointOptions.enabled, generalOptions.enabled); // #2282
  13368. // If the point is outside the plot area, destroy it. #678, #820
  13369. if (dataLabel && !enabled) {
  13370. point.dataLabel = dataLabel.destroy();
  13371. // Individual labels are disabled if the are explicitly disabled
  13372. // in the point options, or if they fall outside the plot area.
  13373. } else if (enabled) {
  13374. // Create individual options structure that can be extended without
  13375. // affecting others
  13376. options = merge(generalOptions, pointOptions);
  13377. style = options.style;
  13378. rotation = options.rotation;
  13379. // Get the string
  13380. labelConfig = point.getLabelConfig();
  13381. str = options.format ?
  13382. format(options.format, labelConfig) :
  13383. options.formatter.call(labelConfig, options);
  13384. // Determine the color
  13385. style.color = pick(options.color, style.color, series.color, 'black');
  13386. // update existing label
  13387. if (dataLabel) {
  13388. if (defined(str)) {
  13389. dataLabel
  13390. .attr({
  13391. text: str
  13392. });
  13393. isNew = false;
  13394. } else { // #1437 - the label is shown conditionally
  13395. point.dataLabel = dataLabel = dataLabel.destroy();
  13396. if (connector) {
  13397. point.connector = connector.destroy();
  13398. }
  13399. }
  13400. // create new label
  13401. } else if (defined(str)) {
  13402. attr = {
  13403. //align: align,
  13404. fill: options.backgroundColor,
  13405. stroke: options.borderColor,
  13406. 'stroke-width': options.borderWidth,
  13407. r: options.borderRadius || 0,
  13408. rotation: rotation,
  13409. padding: options.padding,
  13410. zIndex: 1
  13411. };
  13412. // Get automated contrast color
  13413. if (style.color === 'contrast') {
  13414. moreStyle.color = options.inside || options.distance < 0 || !!seriesOptions.stacking ?
  13415. renderer.getContrast(point.color || series.color) :
  13416. '#000000';
  13417. }
  13418. if (cursor) {
  13419. moreStyle.cursor = cursor;
  13420. }
  13421. // Remove unused attributes (#947)
  13422. for (name in attr) {
  13423. if (attr[name] === UNDEFINED) {
  13424. delete attr[name];
  13425. }
  13426. }
  13427. dataLabel = point.dataLabel = renderer[rotation ? 'text' : 'label']( // labels don't support rotation
  13428. str,
  13429. 0,
  13430. -999,
  13431. options.shape,
  13432. null,
  13433. null,
  13434. options.useHTML
  13435. )
  13436. .attr(attr)
  13437. .css(extend(style, moreStyle))
  13438. .add(dataLabelsGroup)
  13439. .shadow(options.shadow);
  13440. }
  13441. if (dataLabel) {
  13442. // Now the data label is created and placed at 0,0, so we need to align it
  13443. series.alignDataLabel(point, dataLabel, options, null, isNew);
  13444. }
  13445. }
  13446. });
  13447. }
  13448. };
  13449. /**
  13450. * Align each individual data label
  13451. */
  13452. Series.prototype.alignDataLabel = function (point, dataLabel, options, alignTo, isNew) {
  13453. var chart = this.chart,
  13454. inverted = chart.inverted,
  13455. plotX = pick(point.plotX, -999),
  13456. plotY = pick(point.plotY, -999),
  13457. bBox = dataLabel.getBBox(),
  13458. baseline = chart.renderer.fontMetrics(options.style.fontSize).b,
  13459. rotCorr, // rotation correction
  13460. // Math.round for rounding errors (#2683), alignTo to allow column labels (#2700)
  13461. visible = this.visible && (point.series.forceDL || chart.isInsidePlot(plotX, mathRound(plotY), inverted) ||
  13462. (alignTo && chart.isInsidePlot(plotX, inverted ? alignTo.x + 1 : alignTo.y + alignTo.height - 1, inverted))),
  13463. alignAttr; // the final position;
  13464. if (visible) {
  13465. // The alignment box is a singular point
  13466. alignTo = extend({
  13467. x: inverted ? chart.plotWidth - plotY : plotX,
  13468. y: mathRound(inverted ? chart.plotHeight - plotX : plotY),
  13469. width: 0,
  13470. height: 0
  13471. }, alignTo);
  13472. // Add the text size for alignment calculation
  13473. extend(options, {
  13474. width: bBox.width,
  13475. height: bBox.height
  13476. });
  13477. // Allow a hook for changing alignment in the last moment, then do the alignment
  13478. if (options.rotation) { // Fancy box alignment isn't supported for rotated text
  13479. rotCorr = chart.renderer.rotCorr(baseline, options.rotation); // #3723
  13480. dataLabel[isNew ? 'attr' : 'animate']({
  13481. x: alignTo.x + options.x + alignTo.width / 2 + rotCorr.x,
  13482. y: alignTo.y + options.y + alignTo.height / 2
  13483. })
  13484. .attr({ // #3003
  13485. align: options.align
  13486. });
  13487. } else {
  13488. dataLabel.align(options, null, alignTo);
  13489. alignAttr = dataLabel.alignAttr;
  13490. // Handle justify or crop
  13491. if (pick(options.overflow, 'justify') === 'justify') {
  13492. this.justifyDataLabel(dataLabel, options, alignAttr, bBox, alignTo, isNew);
  13493. } else if (pick(options.crop, true)) {
  13494. // Now check that the data label is within the plot area
  13495. visible = chart.isInsidePlot(alignAttr.x, alignAttr.y) && chart.isInsidePlot(alignAttr.x + bBox.width, alignAttr.y + bBox.height);
  13496. }
  13497. // When we're using a shape, make it possible with a connector or an arrow pointing to thie point
  13498. if (options.shape) {
  13499. dataLabel.attr({
  13500. anchorX: point.plotX,
  13501. anchorY: point.plotY
  13502. });
  13503. }
  13504. }
  13505. }
  13506. // Show or hide based on the final aligned position
  13507. if (!visible) {
  13508. stop(dataLabel);
  13509. dataLabel.attr({ y: -999 });
  13510. dataLabel.placed = false; // don't animate back in
  13511. }
  13512. };
  13513. /**
  13514. * If data labels fall partly outside the plot area, align them back in, in a way that
  13515. * doesn't hide the point.
  13516. */
  13517. Series.prototype.justifyDataLabel = function (dataLabel, options, alignAttr, bBox, alignTo, isNew) {
  13518. var chart = this.chart,
  13519. align = options.align,
  13520. verticalAlign = options.verticalAlign,
  13521. off,
  13522. justified,
  13523. padding = dataLabel.box ? 0 : (dataLabel.padding || 0);
  13524. // Off left
  13525. off = alignAttr.x + padding;
  13526. if (off < 0) {
  13527. if (align === 'right') {
  13528. options.align = 'left';
  13529. } else {
  13530. options.x = -off;
  13531. }
  13532. justified = true;
  13533. }
  13534. // Off right
  13535. off = alignAttr.x + bBox.width - padding;
  13536. if (off > chart.plotWidth) {
  13537. if (align === 'left') {
  13538. options.align = 'right';
  13539. } else {
  13540. options.x = chart.plotWidth - off;
  13541. }
  13542. justified = true;
  13543. }
  13544. // Off top
  13545. off = alignAttr.y + padding;
  13546. if (off < 0) {
  13547. if (verticalAlign === 'bottom') {
  13548. options.verticalAlign = 'top';
  13549. } else {
  13550. options.y = -off;
  13551. }
  13552. justified = true;
  13553. }
  13554. // Off bottom
  13555. off = alignAttr.y + bBox.height - padding;
  13556. if (off > chart.plotHeight) {
  13557. if (verticalAlign === 'top') {
  13558. options.verticalAlign = 'bottom';
  13559. } else {
  13560. options.y = chart.plotHeight - off;
  13561. }
  13562. justified = true;
  13563. }
  13564. if (justified) {
  13565. dataLabel.placed = !isNew;
  13566. dataLabel.align(options, null, alignTo);
  13567. }
  13568. };
  13569. /**
  13570. * Override the base drawDataLabels method by pie specific functionality
  13571. */
  13572. if (seriesTypes.pie) {
  13573. seriesTypes.pie.prototype.drawDataLabels = function () {
  13574. var series = this,
  13575. data = series.data,
  13576. point,
  13577. chart = series.chart,
  13578. options = series.options.dataLabels,
  13579. connectorPadding = pick(options.connectorPadding, 10),
  13580. connectorWidth = pick(options.connectorWidth, 1),
  13581. plotWidth = chart.plotWidth,
  13582. plotHeight = chart.plotHeight,
  13583. connector,
  13584. connectorPath,
  13585. softConnector = pick(options.softConnector, true),
  13586. distanceOption = options.distance,
  13587. seriesCenter = series.center,
  13588. radius = seriesCenter[2] / 2,
  13589. centerY = seriesCenter[1],
  13590. outside = distanceOption > 0,
  13591. dataLabel,
  13592. dataLabelWidth,
  13593. labelPos,
  13594. labelHeight,
  13595. halves = [// divide the points into right and left halves for anti collision
  13596. [], // right
  13597. [] // left
  13598. ],
  13599. x,
  13600. y,
  13601. visibility,
  13602. rankArr,
  13603. i,
  13604. j,
  13605. overflow = [0, 0, 0, 0], // top, right, bottom, left
  13606. sort = function (a, b) {
  13607. return b.y - a.y;
  13608. };
  13609. // get out if not enabled
  13610. if (!series.visible || (!options.enabled && !series._hasPointLabels)) {
  13611. return;
  13612. }
  13613. // run parent method
  13614. Series.prototype.drawDataLabels.apply(series);
  13615. // arrange points for detection collision
  13616. each(data, function (point) {
  13617. if (point.dataLabel && point.visible) { // #407, #2510
  13618. halves[point.half].push(point);
  13619. }
  13620. });
  13621. /* Loop over the points in each half, starting from the top and bottom
  13622. * of the pie to detect overlapping labels.
  13623. */
  13624. i = 2;
  13625. while (i--) {
  13626. var slots = [],
  13627. slotsLength,
  13628. usedSlots = [],
  13629. points = halves[i],
  13630. pos,
  13631. bottom,
  13632. length = points.length,
  13633. slotIndex;
  13634. if (!length) {
  13635. continue;
  13636. }
  13637. // Sort by angle
  13638. series.sortByAngle(points, i - 0.5);
  13639. // Assume equal label heights on either hemisphere (#2630)
  13640. j = labelHeight = 0;
  13641. while (!labelHeight && points[j]) { // #1569
  13642. labelHeight = points[j] && points[j].dataLabel && (points[j].dataLabel.getBBox().height || 21); // 21 is for #968
  13643. j++;
  13644. }
  13645. // Only do anti-collision when we are outside the pie and have connectors (#856)
  13646. if (distanceOption > 0) {
  13647. // Build the slots
  13648. bottom = mathMin(centerY + radius + distanceOption, chart.plotHeight);
  13649. for (pos = mathMax(0, centerY - radius - distanceOption); pos <= bottom; pos += labelHeight) {
  13650. slots.push(pos);
  13651. }
  13652. slotsLength = slots.length;
  13653. /* Visualize the slots
  13654. if (!series.slotElements) {
  13655. series.slotElements = [];
  13656. }
  13657. if (i === 1) {
  13658. series.slotElements.forEach(function (elem) {
  13659. elem.destroy();
  13660. });
  13661. series.slotElements.length = 0;
  13662. }
  13663. slots.forEach(function (pos, no) {
  13664. var slotX = series.getX(pos, i) + chart.plotLeft - (i ? 100 : 0),
  13665. slotY = pos + chart.plotTop;
  13666. if (!isNaN(slotX)) {
  13667. series.slotElements.push(chart.renderer.rect(slotX, slotY - 7, 100, labelHeight, 1)
  13668. .attr({
  13669. 'stroke-width': 1,
  13670. stroke: 'silver',
  13671. fill: 'rgba(0,0,255,0.1)'
  13672. })
  13673. .add());
  13674. series.slotElements.push(chart.renderer.text('Slot '+ no, slotX, slotY + 4)
  13675. .attr({
  13676. fill: 'silver'
  13677. }).add());
  13678. }
  13679. });
  13680. // */
  13681. // if there are more values than available slots, remove lowest values
  13682. if (length > slotsLength) {
  13683. // create an array for sorting and ranking the points within each quarter
  13684. rankArr = [].concat(points);
  13685. rankArr.sort(sort);
  13686. j = length;
  13687. while (j--) {
  13688. rankArr[j].rank = j;
  13689. }
  13690. j = length;
  13691. while (j--) {
  13692. if (points[j].rank >= slotsLength) {
  13693. points.splice(j, 1);
  13694. }
  13695. }
  13696. length = points.length;
  13697. }
  13698. // The label goes to the nearest open slot, but not closer to the edge than
  13699. // the label's index.
  13700. for (j = 0; j < length; j++) {
  13701. point = points[j];
  13702. labelPos = point.labelPos;
  13703. var closest = 9999,
  13704. distance,
  13705. slotI;
  13706. // find the closest slot index
  13707. for (slotI = 0; slotI < slotsLength; slotI++) {
  13708. distance = mathAbs(slots[slotI] - labelPos[1]);
  13709. if (distance < closest) {
  13710. closest = distance;
  13711. slotIndex = slotI;
  13712. }
  13713. }
  13714. // if that slot index is closer to the edges of the slots, move it
  13715. // to the closest appropriate slot
  13716. if (slotIndex < j && slots[j] !== null) { // cluster at the top
  13717. slotIndex = j;
  13718. } else if (slotsLength < length - j + slotIndex && slots[j] !== null) { // cluster at the bottom
  13719. slotIndex = slotsLength - length + j;
  13720. while (slots[slotIndex] === null) { // make sure it is not taken
  13721. slotIndex++;
  13722. }
  13723. } else {
  13724. // Slot is taken, find next free slot below. In the next run, the next slice will find the
  13725. // slot above these, because it is the closest one
  13726. while (slots[slotIndex] === null) { // make sure it is not taken
  13727. slotIndex++;
  13728. }
  13729. }
  13730. usedSlots.push({ i: slotIndex, y: slots[slotIndex] });
  13731. slots[slotIndex] = null; // mark as taken
  13732. }
  13733. // sort them in order to fill in from the top
  13734. usedSlots.sort(sort);
  13735. }
  13736. // now the used slots are sorted, fill them up sequentially
  13737. for (j = 0; j < length; j++) {
  13738. var slot, naturalY;
  13739. point = points[j];
  13740. labelPos = point.labelPos;
  13741. dataLabel = point.dataLabel;
  13742. visibility = point.visible === false ? HIDDEN : 'inherit';
  13743. naturalY = labelPos[1];
  13744. if (distanceOption > 0) {
  13745. slot = usedSlots.pop();
  13746. slotIndex = slot.i;
  13747. // if the slot next to currrent slot is free, the y value is allowed
  13748. // to fall back to the natural position
  13749. y = slot.y;
  13750. if ((naturalY > y && slots[slotIndex + 1] !== null) ||
  13751. (naturalY < y && slots[slotIndex - 1] !== null)) {
  13752. y = mathMin(mathMax(0, naturalY), chart.plotHeight);
  13753. }
  13754. } else {
  13755. y = naturalY;
  13756. }
  13757. // get the x - use the natural x position for first and last slot, to prevent the top
  13758. // and botton slice connectors from touching each other on either side
  13759. x = options.justify ?
  13760. seriesCenter[0] + (i ? -1 : 1) * (radius + distanceOption) :
  13761. series.getX(y === centerY - radius - distanceOption || y === centerY + radius + distanceOption ? naturalY : y, i);
  13762. // Record the placement and visibility
  13763. dataLabel._attr = {
  13764. visibility: visibility,
  13765. align: labelPos[6]
  13766. };
  13767. dataLabel._pos = {
  13768. x: x + options.x +
  13769. ({ left: connectorPadding, right: -connectorPadding }[labelPos[6]] || 0),
  13770. y: y + options.y - 10 // 10 is for the baseline (label vs text)
  13771. };
  13772. dataLabel.connX = x;
  13773. dataLabel.connY = y;
  13774. // Detect overflowing data labels
  13775. if (this.options.size === null) {
  13776. dataLabelWidth = dataLabel.width;
  13777. // Overflow left
  13778. if (x - dataLabelWidth < connectorPadding) {
  13779. overflow[3] = mathMax(mathRound(dataLabelWidth - x + connectorPadding), overflow[3]);
  13780. // Overflow right
  13781. } else if (x + dataLabelWidth > plotWidth - connectorPadding) {
  13782. overflow[1] = mathMax(mathRound(x + dataLabelWidth - plotWidth + connectorPadding), overflow[1]);
  13783. }
  13784. // Overflow top
  13785. if (y - labelHeight / 2 < 0) {
  13786. overflow[0] = mathMax(mathRound(-y + labelHeight / 2), overflow[0]);
  13787. // Overflow left
  13788. } else if (y + labelHeight / 2 > plotHeight) {
  13789. overflow[2] = mathMax(mathRound(y + labelHeight / 2 - plotHeight), overflow[2]);
  13790. }
  13791. }
  13792. } // for each point
  13793. } // for each half
  13794. // Do not apply the final placement and draw the connectors until we have verified
  13795. // that labels are not spilling over.
  13796. if (arrayMax(overflow) === 0 || this.verifyDataLabelOverflow(overflow)) {
  13797. // Place the labels in the final position
  13798. this.placeDataLabels();
  13799. // Draw the connectors
  13800. if (outside && connectorWidth) {
  13801. each(this.points, function (point) {
  13802. connector = point.connector;
  13803. labelPos = point.labelPos;
  13804. dataLabel = point.dataLabel;
  13805. if (dataLabel && dataLabel._pos && point.visible) {
  13806. visibility = dataLabel._attr.visibility;
  13807. x = dataLabel.connX;
  13808. y = dataLabel.connY;
  13809. connectorPath = softConnector ? [
  13810. M,
  13811. x + (labelPos[6] === 'left' ? 5 : -5), y, // end of the string at the label
  13812. 'C',
  13813. x, y, // first break, next to the label
  13814. 2 * labelPos[2] - labelPos[4], 2 * labelPos[3] - labelPos[5],
  13815. labelPos[2], labelPos[3], // second break
  13816. L,
  13817. labelPos[4], labelPos[5] // base
  13818. ] : [
  13819. M,
  13820. x + (labelPos[6] === 'left' ? 5 : -5), y, // end of the string at the label
  13821. L,
  13822. labelPos[2], labelPos[3], // second break
  13823. L,
  13824. labelPos[4], labelPos[5] // base
  13825. ];
  13826. if (connector) {
  13827. connector.animate({ d: connectorPath });
  13828. connector.attr('visibility', visibility);
  13829. } else {
  13830. point.connector = connector = series.chart.renderer.path(connectorPath).attr({
  13831. 'stroke-width': connectorWidth,
  13832. stroke: options.connectorColor || point.color || '#606060',
  13833. visibility: visibility
  13834. //zIndex: 0 // #2722 (reversed)
  13835. })
  13836. .add(series.dataLabelsGroup);
  13837. }
  13838. } else if (connector) {
  13839. point.connector = connector.destroy();
  13840. }
  13841. });
  13842. }
  13843. }
  13844. };
  13845. /**
  13846. * Perform the final placement of the data labels after we have verified that they
  13847. * fall within the plot area.
  13848. */
  13849. seriesTypes.pie.prototype.placeDataLabels = function () {
  13850. each(this.points, function (point) {
  13851. var dataLabel = point.dataLabel,
  13852. _pos;
  13853. if (dataLabel && point.visible) {
  13854. _pos = dataLabel._pos;
  13855. if (_pos) {
  13856. dataLabel.attr(dataLabel._attr);
  13857. dataLabel[dataLabel.moved ? 'animate' : 'attr'](_pos);
  13858. dataLabel.moved = true;
  13859. } else if (dataLabel) {
  13860. dataLabel.attr({ y: -999 });
  13861. }
  13862. }
  13863. });
  13864. };
  13865. seriesTypes.pie.prototype.alignDataLabel = noop;
  13866. /**
  13867. * Verify whether the data labels are allowed to draw, or we should run more translation and data
  13868. * label positioning to keep them inside the plot area. Returns true when data labels are ready
  13869. * to draw.
  13870. */
  13871. seriesTypes.pie.prototype.verifyDataLabelOverflow = function (overflow) {
  13872. var center = this.center,
  13873. options = this.options,
  13874. centerOption = options.center,
  13875. minSize = options.minSize || 80,
  13876. newSize = minSize,
  13877. ret;
  13878. // Handle horizontal size and center
  13879. if (centerOption[0] !== null) { // Fixed center
  13880. newSize = mathMax(center[2] - mathMax(overflow[1], overflow[3]), minSize);
  13881. } else { // Auto center
  13882. newSize = mathMax(
  13883. center[2] - overflow[1] - overflow[3], // horizontal overflow
  13884. minSize
  13885. );
  13886. center[0] += (overflow[3] - overflow[1]) / 2; // horizontal center
  13887. }
  13888. // Handle vertical size and center
  13889. if (centerOption[1] !== null) { // Fixed center
  13890. newSize = mathMax(mathMin(newSize, center[2] - mathMax(overflow[0], overflow[2])), minSize);
  13891. } else { // Auto center
  13892. newSize = mathMax(
  13893. mathMin(
  13894. newSize,
  13895. center[2] - overflow[0] - overflow[2] // vertical overflow
  13896. ),
  13897. minSize
  13898. );
  13899. center[1] += (overflow[0] - overflow[2]) / 2; // vertical center
  13900. }
  13901. // If the size must be decreased, we need to run translate and drawDataLabels again
  13902. if (newSize < center[2]) {
  13903. center[2] = newSize;
  13904. center[3] = Math.min(relativeLength(options.innerSize || 0, newSize), newSize); // #3632
  13905. this.translate(center);
  13906. each(this.points, function (point) {
  13907. if (point.dataLabel) {
  13908. point.dataLabel._pos = null; // reset
  13909. }
  13910. });
  13911. if (this.drawDataLabels) {
  13912. this.drawDataLabels();
  13913. }
  13914. // Else, return true to indicate that the pie and its labels is within the plot area
  13915. } else {
  13916. ret = true;
  13917. }
  13918. return ret;
  13919. };
  13920. }
  13921. if (seriesTypes.column) {
  13922. /**
  13923. * Override the basic data label alignment by adjusting for the position of the column
  13924. */
  13925. seriesTypes.column.prototype.alignDataLabel = function (point, dataLabel, options, alignTo, isNew) {
  13926. var inverted = this.chart.inverted,
  13927. series = point.series,
  13928. dlBox = point.dlBox || point.shapeArgs, // data label box for alignment
  13929. below = pick(point.below, point.plotY > pick(this.translatedThreshold, series.yAxis.len)), // point.below is used in range series
  13930. inside = pick(options.inside, !!this.options.stacking); // draw it inside the box?
  13931. // Align to the column itself, or the top of it
  13932. if (dlBox) { // Area range uses this method but not alignTo
  13933. alignTo = merge(dlBox);
  13934. if (inverted) {
  13935. alignTo = {
  13936. x: series.yAxis.len - alignTo.y - alignTo.height,
  13937. y: series.xAxis.len - alignTo.x - alignTo.width,
  13938. width: alignTo.height,
  13939. height: alignTo.width
  13940. };
  13941. }
  13942. // Compute the alignment box
  13943. if (!inside) {
  13944. if (inverted) {
  13945. alignTo.x += below ? 0 : alignTo.width;
  13946. alignTo.width = 0;
  13947. } else {
  13948. alignTo.y += below ? alignTo.height : 0;
  13949. alignTo.height = 0;
  13950. }
  13951. }
  13952. }
  13953. // When alignment is undefined (typically columns and bars), display the individual
  13954. // point below or above the point depending on the threshold
  13955. options.align = pick(
  13956. options.align,
  13957. !inverted || inside ? 'center' : below ? 'right' : 'left'
  13958. );
  13959. options.verticalAlign = pick(
  13960. options.verticalAlign,
  13961. inverted || inside ? 'middle' : below ? 'top' : 'bottom'
  13962. );
  13963. // Call the parent method
  13964. Series.prototype.alignDataLabel.call(this, point, dataLabel, options, alignTo, isNew);
  13965. };
  13966. }
  13967. /**
  13968. * Highmaps JS v1.1.9 (2015-10-07)
  13969. * Highcharts module to hide overlapping data labels. This module is included by default in Highmaps.
  13970. *
  13971. * (c) 2010-2014 Torstein Honsi
  13972. *
  13973. * License: www.highcharts.com/license
  13974. */
  13975. /*global Highcharts, HighchartsAdapter */
  13976. (function (H) {
  13977. var Chart = H.Chart,
  13978. each = H.each,
  13979. pick = H.pick,
  13980. addEvent = HighchartsAdapter.addEvent;
  13981. // Collect potensial overlapping data labels. Stack labels probably don't need to be
  13982. // considered because they are usually accompanied by data labels that lie inside the columns.
  13983. Chart.prototype.callbacks.push(function (chart) {
  13984. function collectAndHide() {
  13985. var labels = [];
  13986. each(chart.series, function (series) {
  13987. var dlOptions = series.options.dataLabels,
  13988. collections = series.dataLabelCollections || ['dataLabel']; // Range series have two collections
  13989. if ((dlOptions.enabled || series._hasPointLabels) && !dlOptions.allowOverlap && series.visible) { // #3866
  13990. each(collections, function (coll) {
  13991. each(series.points, function (point) {
  13992. if (point[coll]) {
  13993. point[coll].labelrank = pick(point.labelrank, point.shapeArgs && point.shapeArgs.height); // #4118
  13994. labels.push(point[coll]);
  13995. }
  13996. });
  13997. });
  13998. }
  13999. });
  14000. chart.hideOverlappingLabels(labels);
  14001. }
  14002. // Do it now ...
  14003. collectAndHide();
  14004. // ... and after each chart redraw
  14005. addEvent(chart, 'redraw', collectAndHide);
  14006. });
  14007. /**
  14008. * Hide overlapping labels. Labels are moved and faded in and out on zoom to provide a smooth
  14009. * visual imression.
  14010. */
  14011. Chart.prototype.hideOverlappingLabels = function (labels) {
  14012. var len = labels.length,
  14013. label,
  14014. i,
  14015. j,
  14016. label1,
  14017. label2,
  14018. isIntersecting,
  14019. pos1,
  14020. pos2,
  14021. padding,
  14022. intersectRect = function (x1, y1, w1, h1, x2, y2, w2, h2) {
  14023. return !(
  14024. x2 > x1 + w1 ||
  14025. x2 + w2 < x1 ||
  14026. y2 > y1 + h1 ||
  14027. y2 + h2 < y1
  14028. );
  14029. };
  14030. // Mark with initial opacity
  14031. for (i = 0; i < len; i++) {
  14032. label = labels[i];
  14033. if (label) {
  14034. label.oldOpacity = label.opacity;
  14035. label.newOpacity = 1;
  14036. }
  14037. }
  14038. // Prevent a situation in a gradually rising slope, that each label
  14039. // will hide the previous one because the previous one always has
  14040. // lower rank.
  14041. labels.sort(function (a, b) {
  14042. return (b.labelrank || 0) - (a.labelrank || 0);
  14043. });
  14044. // Detect overlapping labels
  14045. for (i = 0; i < len; i++) {
  14046. label1 = labels[i];
  14047. for (j = i + 1; j < len; ++j) {
  14048. label2 = labels[j];
  14049. if (label1 && label2 && label1.placed && label2.placed && label1.newOpacity !== 0 && label2.newOpacity !== 0) {
  14050. pos1 = label1.alignAttr;
  14051. pos2 = label2.alignAttr;
  14052. padding = 2 * (label1.box ? 0 : label1.padding); // Substract the padding if no background or border (#4333)
  14053. isIntersecting = intersectRect(
  14054. pos1.x,
  14055. pos1.y,
  14056. label1.width - padding,
  14057. label1.height - padding,
  14058. pos2.x,
  14059. pos2.y,
  14060. label2.width - padding,
  14061. label2.height - padding
  14062. );
  14063. if (isIntersecting) {
  14064. (label1.labelrank < label2.labelrank ? label1 : label2).newOpacity = 0;
  14065. }
  14066. }
  14067. }
  14068. }
  14069. // Hide or show
  14070. each(labels, function (label) {
  14071. var complete,
  14072. newOpacity;
  14073. if (label) {
  14074. newOpacity = label.newOpacity;
  14075. if (label.oldOpacity !== newOpacity && label.placed) {
  14076. // Make sure the label is completely hidden to avoid catching clicks (#4362)
  14077. if (newOpacity) {
  14078. label.show(true);
  14079. } else {
  14080. complete = function () {
  14081. label.hide();
  14082. };
  14083. }
  14084. // Animate or set the opacity
  14085. label.alignAttr.opacity = newOpacity;
  14086. label[label.isOld ? 'animate' : 'attr'](label.alignAttr, null, complete);
  14087. }
  14088. label.isOld = true;
  14089. }
  14090. });
  14091. };
  14092. }(Highcharts));/**
  14093. * Override to use the extreme coordinates from the SVG shape, not the
  14094. * data values
  14095. */
  14096. wrap(Axis.prototype, 'getSeriesExtremes', function (proceed) {
  14097. var isXAxis = this.isXAxis,
  14098. dataMin,
  14099. dataMax,
  14100. xData = [],
  14101. useMapGeometry;
  14102. // Remove the xData array and cache it locally so that the proceed method doesn't use it
  14103. if (isXAxis) {
  14104. each(this.series, function (series, i) {
  14105. if (series.useMapGeometry) {
  14106. xData[i] = series.xData;
  14107. series.xData = [];
  14108. }
  14109. });
  14110. }
  14111. // Call base to reach normal cartesian series (like mappoint)
  14112. proceed.call(this);
  14113. // Run extremes logic for map and mapline
  14114. if (isXAxis) {
  14115. dataMin = pick(this.dataMin, Number.MAX_VALUE);
  14116. dataMax = pick(this.dataMax, -Number.MAX_VALUE);
  14117. each(this.series, function (series, i) {
  14118. if (series.useMapGeometry) {
  14119. dataMin = Math.min(dataMin, pick(series.minX, dataMin));
  14120. dataMax = Math.max(dataMax, pick(series.maxX, dataMin));
  14121. series.xData = xData[i]; // Reset xData array
  14122. useMapGeometry = true;
  14123. }
  14124. });
  14125. if (useMapGeometry) {
  14126. this.dataMin = dataMin;
  14127. this.dataMax = dataMax;
  14128. }
  14129. }
  14130. });
  14131. /**
  14132. * Override axis translation to make sure the aspect ratio is always kept
  14133. */
  14134. wrap(Axis.prototype, 'setAxisTranslation', function (proceed) {
  14135. var chart = this.chart,
  14136. mapRatio,
  14137. plotRatio = chart.plotWidth / chart.plotHeight,
  14138. adjustedAxisLength,
  14139. xAxis = chart.xAxis[0],
  14140. padAxis,
  14141. fixTo,
  14142. fixDiff,
  14143. preserveAspectRatio;
  14144. // Run the parent method
  14145. proceed.call(this);
  14146. // Check for map-like series
  14147. if (this.coll === 'yAxis' && xAxis.transA !== UNDEFINED) {
  14148. each(this.series, function (series) {
  14149. if (series.preserveAspectRatio) {
  14150. preserveAspectRatio = true;
  14151. }
  14152. });
  14153. }
  14154. // On Y axis, handle both
  14155. if (preserveAspectRatio) {
  14156. // Use the same translation for both axes
  14157. this.transA = xAxis.transA = Math.min(this.transA, xAxis.transA);
  14158. mapRatio = plotRatio / ((xAxis.max - xAxis.min) / (this.max - this.min));
  14159. // What axis to pad to put the map in the middle
  14160. padAxis = mapRatio < 1 ? this : xAxis;
  14161. // Pad it
  14162. adjustedAxisLength = (padAxis.max - padAxis.min) * padAxis.transA;
  14163. padAxis.pixelPadding = padAxis.len - adjustedAxisLength;
  14164. padAxis.minPixelPadding = padAxis.pixelPadding / 2;
  14165. fixTo = padAxis.fixTo;
  14166. if (fixTo) {
  14167. fixDiff = fixTo[1] - padAxis.toValue(fixTo[0], true);
  14168. fixDiff *= padAxis.transA;
  14169. if (Math.abs(fixDiff) > padAxis.minPixelPadding || (padAxis.min === padAxis.dataMin && padAxis.max === padAxis.dataMax)) { // zooming out again, keep within restricted area
  14170. fixDiff = 0;
  14171. }
  14172. padAxis.minPixelPadding -= fixDiff;
  14173. }
  14174. }
  14175. });
  14176. /**
  14177. * Override Axis.render in order to delete the fixTo prop
  14178. */
  14179. wrap(Axis.prototype, 'render', function (proceed) {
  14180. proceed.call(this);
  14181. this.fixTo = null;
  14182. });
  14183. /**
  14184. * The ColorAxis object for inclusion in gradient legends
  14185. */
  14186. var ColorAxis = Highcharts.ColorAxis = function () {
  14187. this.isColorAxis = true;
  14188. this.init.apply(this, arguments);
  14189. };
  14190. extend(ColorAxis.prototype, Axis.prototype);
  14191. extend(ColorAxis.prototype, {
  14192. defaultColorAxisOptions: {
  14193. lineWidth: 0,
  14194. minPadding: 0,
  14195. maxPadding: 0,
  14196. gridLineWidth: 1,
  14197. tickPixelInterval: 72,
  14198. startOnTick: true,
  14199. endOnTick: true,
  14200. offset: 0,
  14201. marker: {
  14202. animation: {
  14203. duration: 50
  14204. },
  14205. color: 'gray',
  14206. width: 0.01
  14207. },
  14208. labels: {
  14209. overflow: 'justify'
  14210. },
  14211. minColor: '#EFEFFF',
  14212. maxColor: '#003875',
  14213. tickLength: 5
  14214. },
  14215. init: function (chart, userOptions) {
  14216. var horiz = chart.options.legend.layout !== 'vertical',
  14217. options;
  14218. // Build the options
  14219. options = merge(this.defaultColorAxisOptions, {
  14220. side: horiz ? 2 : 1,
  14221. reversed: !horiz
  14222. }, userOptions, {
  14223. opposite: !horiz,
  14224. showEmpty: false,
  14225. title: null,
  14226. isColor: true
  14227. });
  14228. Axis.prototype.init.call(this, chart, options);
  14229. // Base init() pushes it to the xAxis array, now pop it again
  14230. //chart[this.isXAxis ? 'xAxis' : 'yAxis'].pop();
  14231. // Prepare data classes
  14232. if (userOptions.dataClasses) {
  14233. this.initDataClasses(userOptions);
  14234. }
  14235. this.initStops(userOptions);
  14236. // Override original axis properties
  14237. this.horiz = horiz;
  14238. this.zoomEnabled = false;
  14239. },
  14240. /*
  14241. * Return an intermediate color between two colors, according to pos where 0
  14242. * is the from color and 1 is the to color.
  14243. * NOTE: Changes here should be copied
  14244. * to the same function in drilldown.src.js and solid-gauge-src.js.
  14245. */
  14246. tweenColors: function (from, to, pos) {
  14247. // Check for has alpha, because rgba colors perform worse due to lack of
  14248. // support in WebKit.
  14249. var hasAlpha,
  14250. ret;
  14251. // Unsupported color, return to-color (#3920)
  14252. if (!to.rgba.length || !from.rgba.length) {
  14253. ret = to.raw || 'none';
  14254. // Interpolate
  14255. } else {
  14256. from = from.rgba;
  14257. to = to.rgba;
  14258. hasAlpha = (to[3] !== 1 || from[3] !== 1);
  14259. ret = (hasAlpha ? 'rgba(' : 'rgb(') +
  14260. Math.round(to[0] + (from[0] - to[0]) * (1 - pos)) + ',' +
  14261. Math.round(to[1] + (from[1] - to[1]) * (1 - pos)) + ',' +
  14262. Math.round(to[2] + (from[2] - to[2]) * (1 - pos)) +
  14263. (hasAlpha ? (',' + (to[3] + (from[3] - to[3]) * (1 - pos))) : '') + ')';
  14264. }
  14265. return ret;
  14266. },
  14267. initDataClasses: function (userOptions) {
  14268. var axis = this,
  14269. chart = this.chart,
  14270. dataClasses,
  14271. colorCounter = 0,
  14272. options = this.options,
  14273. len = userOptions.dataClasses.length;
  14274. this.dataClasses = dataClasses = [];
  14275. this.legendItems = [];
  14276. each(userOptions.dataClasses, function (dataClass, i) {
  14277. var colors;
  14278. dataClass = merge(dataClass);
  14279. dataClasses.push(dataClass);
  14280. if (!dataClass.color) {
  14281. if (options.dataClassColor === 'category') {
  14282. colors = chart.options.colors;
  14283. dataClass.color = colors[colorCounter++];
  14284. // loop back to zero
  14285. if (colorCounter === colors.length) {
  14286. colorCounter = 0;
  14287. }
  14288. } else {
  14289. dataClass.color = axis.tweenColors(
  14290. Color(options.minColor),
  14291. Color(options.maxColor),
  14292. len < 2 ? 0.5 : i / (len - 1) // #3219
  14293. );
  14294. }
  14295. }
  14296. });
  14297. },
  14298. initStops: function (userOptions) {
  14299. this.stops = userOptions.stops || [
  14300. [0, this.options.minColor],
  14301. [1, this.options.maxColor]
  14302. ];
  14303. each(this.stops, function (stop) {
  14304. stop.color = Color(stop[1]);
  14305. });
  14306. },
  14307. /**
  14308. * Extend the setOptions method to process extreme colors and color
  14309. * stops.
  14310. */
  14311. setOptions: function (userOptions) {
  14312. Axis.prototype.setOptions.call(this, userOptions);
  14313. this.options.crosshair = this.options.marker;
  14314. this.coll = 'colorAxis';
  14315. },
  14316. setAxisSize: function () {
  14317. var symbol = this.legendSymbol,
  14318. chart = this.chart,
  14319. x,
  14320. y,
  14321. width,
  14322. height;
  14323. if (symbol) {
  14324. this.left = x = symbol.attr('x');
  14325. this.top = y = symbol.attr('y');
  14326. this.width = width = symbol.attr('width');
  14327. this.height = height = symbol.attr('height');
  14328. this.right = chart.chartWidth - x - width;
  14329. this.bottom = chart.chartHeight - y - height;
  14330. this.len = this.horiz ? width : height;
  14331. this.pos = this.horiz ? x : y;
  14332. }
  14333. },
  14334. /**
  14335. * Translate from a value to a color
  14336. */
  14337. toColor: function (value, point) {
  14338. var pos,
  14339. stops = this.stops,
  14340. from,
  14341. to,
  14342. color,
  14343. dataClasses = this.dataClasses,
  14344. dataClass,
  14345. i;
  14346. if (dataClasses) {
  14347. i = dataClasses.length;
  14348. while (i--) {
  14349. dataClass = dataClasses[i];
  14350. from = dataClass.from;
  14351. to = dataClass.to;
  14352. if ((from === UNDEFINED || value >= from) && (to === UNDEFINED || value <= to)) {
  14353. color = dataClass.color;
  14354. if (point) {
  14355. point.dataClass = i;
  14356. }
  14357. break;
  14358. }
  14359. }
  14360. } else {
  14361. if (this.isLog) {
  14362. value = this.val2lin(value);
  14363. }
  14364. pos = 1 - ((this.max - value) / ((this.max - this.min) || 1));
  14365. i = stops.length;
  14366. while (i--) {
  14367. if (pos > stops[i][0]) {
  14368. break;
  14369. }
  14370. }
  14371. from = stops[i] || stops[i + 1];
  14372. to = stops[i + 1] || from;
  14373. // The position within the gradient
  14374. pos = 1 - (to[0] - pos) / ((to[0] - from[0]) || 1);
  14375. color = this.tweenColors(
  14376. from.color,
  14377. to.color,
  14378. pos
  14379. );
  14380. }
  14381. return color;
  14382. },
  14383. /**
  14384. * Override the getOffset method to add the whole axis groups inside the legend.
  14385. */
  14386. getOffset: function () {
  14387. var group = this.legendGroup,
  14388. sideOffset = this.chart.axisOffset[this.side];
  14389. if (group) {
  14390. // Hook for the getOffset method to add groups to this parent group
  14391. this.axisParent = group;
  14392. // Call the base
  14393. Axis.prototype.getOffset.call(this);
  14394. // First time only
  14395. if (!this.added) {
  14396. this.added = true;
  14397. this.labelLeft = 0;
  14398. this.labelRight = this.width;
  14399. }
  14400. // Reset it to avoid color axis reserving space
  14401. this.chart.axisOffset[this.side] = sideOffset;
  14402. }
  14403. },
  14404. /**
  14405. * Create the color gradient
  14406. */
  14407. setLegendColor: function () {
  14408. var grad,
  14409. horiz = this.horiz,
  14410. options = this.options,
  14411. reversed = this.reversed;
  14412. grad = horiz ? [+reversed, 0, +!reversed, 0] : [0, +!reversed, 0, +reversed]; // #3190
  14413. this.legendColor = {
  14414. linearGradient: { x1: grad[0], y1: grad[1], x2: grad[2], y2: grad[3] },
  14415. stops: options.stops || [
  14416. [0, options.minColor],
  14417. [1, options.maxColor]
  14418. ]
  14419. };
  14420. },
  14421. /**
  14422. * The color axis appears inside the legend and has its own legend symbol
  14423. */
  14424. drawLegendSymbol: function (legend, item) {
  14425. var padding = legend.padding,
  14426. legendOptions = legend.options,
  14427. horiz = this.horiz,
  14428. box,
  14429. width = pick(legendOptions.symbolWidth, horiz ? 200 : 12),
  14430. height = pick(legendOptions.symbolHeight, horiz ? 12 : 200),
  14431. labelPadding = pick(legendOptions.labelPadding, horiz ? 16 : 30),
  14432. itemDistance = pick(legendOptions.itemDistance, 10);
  14433. this.setLegendColor();
  14434. // Create the gradient
  14435. item.legendSymbol = this.chart.renderer.rect(
  14436. 0,
  14437. legend.baseline - 11,
  14438. width,
  14439. height
  14440. ).attr({
  14441. zIndex: 1
  14442. }).add(item.legendGroup);
  14443. box = item.legendSymbol.getBBox();
  14444. // Set how much space this legend item takes up
  14445. this.legendItemWidth = width + padding + (horiz ? itemDistance : labelPadding);
  14446. this.legendItemHeight = height + padding + (horiz ? labelPadding : 0);
  14447. },
  14448. /**
  14449. * Fool the legend
  14450. */
  14451. setState: noop,
  14452. visible: true,
  14453. setVisible: noop,
  14454. getSeriesExtremes: function () {
  14455. var series;
  14456. if (this.series.length) {
  14457. series = this.series[0];
  14458. this.dataMin = series.valueMin;
  14459. this.dataMax = series.valueMax;
  14460. }
  14461. },
  14462. drawCrosshair: function (e, point) {
  14463. var plotX = point && point.plotX,
  14464. plotY = point && point.plotY,
  14465. crossPos,
  14466. axisPos = this.pos,
  14467. axisLen = this.len;
  14468. if (point) {
  14469. crossPos = this.toPixels(point[point.series.colorKey]);
  14470. if (crossPos < axisPos) {
  14471. crossPos = axisPos - 2;
  14472. } else if (crossPos > axisPos + axisLen) {
  14473. crossPos = axisPos + axisLen + 2;
  14474. }
  14475. point.plotX = crossPos;
  14476. point.plotY = this.len - crossPos;
  14477. Axis.prototype.drawCrosshair.call(this, e, point);
  14478. point.plotX = plotX;
  14479. point.plotY = plotY;
  14480. if (this.cross) {
  14481. this.cross
  14482. .attr({
  14483. fill: this.crosshair.color
  14484. })
  14485. .add(this.legendGroup);
  14486. }
  14487. }
  14488. },
  14489. getPlotLinePath: function (a, b, c, d, pos) {
  14490. if (typeof pos === 'number') { // crosshairs only // #3969 pos can be 0 !!
  14491. return this.horiz ?
  14492. ['M', pos - 4, this.top - 6, 'L', pos + 4, this.top - 6, pos, this.top, 'Z'] :
  14493. ['M', this.left, pos, 'L', this.left - 6, pos + 6, this.left - 6, pos - 6, 'Z'];
  14494. } else {
  14495. return Axis.prototype.getPlotLinePath.call(this, a, b, c, d);
  14496. }
  14497. },
  14498. update: function (newOptions, redraw) {
  14499. var chart = this.chart,
  14500. legend = chart.legend;
  14501. each(this.series, function (series) {
  14502. series.isDirtyData = true; // Needed for Axis.update when choropleth colors change
  14503. });
  14504. // When updating data classes, destroy old items and make sure new ones are created (#3207)
  14505. if (newOptions.dataClasses && legend.allItems) {
  14506. each(legend.allItems, function (item) {
  14507. if (item.isDataClass) {
  14508. item.legendGroup.destroy();
  14509. }
  14510. });
  14511. chart.isDirtyLegend = true;
  14512. }
  14513. // Keep the options structure updated for export. Unlike xAxis and yAxis, the colorAxis is
  14514. // not an array. (#3207)
  14515. chart.options[this.coll] = merge(this.userOptions, newOptions);
  14516. Axis.prototype.update.call(this, newOptions, redraw);
  14517. if (this.legendItem) {
  14518. this.setLegendColor();
  14519. legend.colorizeItem(this, true);
  14520. }
  14521. },
  14522. /**
  14523. * Get the legend item symbols for data classes
  14524. */
  14525. getDataClassLegendSymbols: function () {
  14526. var axis = this,
  14527. chart = this.chart,
  14528. legendItems = this.legendItems,
  14529. legendOptions = chart.options.legend,
  14530. valueDecimals = legendOptions.valueDecimals,
  14531. valueSuffix = legendOptions.valueSuffix || '',
  14532. name;
  14533. if (!legendItems.length) {
  14534. each(this.dataClasses, function (dataClass, i) {
  14535. var vis = true,
  14536. from = dataClass.from,
  14537. to = dataClass.to;
  14538. // Assemble the default name. This can be overridden by legend.options.labelFormatter
  14539. name = '';
  14540. if (from === UNDEFINED) {
  14541. name = '< ';
  14542. } else if (to === UNDEFINED) {
  14543. name = '> ';
  14544. }
  14545. if (from !== UNDEFINED) {
  14546. name += Highcharts.numberFormat(from, valueDecimals) + valueSuffix;
  14547. }
  14548. if (from !== UNDEFINED && to !== UNDEFINED) {
  14549. name += ' - ';
  14550. }
  14551. if (to !== UNDEFINED) {
  14552. name += Highcharts.numberFormat(to, valueDecimals) + valueSuffix;
  14553. }
  14554. // Add a mock object to the legend items
  14555. legendItems.push(extend({
  14556. chart: chart,
  14557. name: name,
  14558. options: {},
  14559. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  14560. visible: true,
  14561. setState: noop,
  14562. isDataClass: true,
  14563. setVisible: function () {
  14564. vis = this.visible = !vis;
  14565. each(axis.series, function (series) {
  14566. each(series.points, function (point) {
  14567. if (point.dataClass === i) {
  14568. point.setVisible(vis);
  14569. }
  14570. });
  14571. });
  14572. chart.legend.colorizeItem(this, vis);
  14573. }
  14574. }, dataClass));
  14575. });
  14576. }
  14577. return legendItems;
  14578. },
  14579. name: '' // Prevents 'undefined' in legend in IE8
  14580. });
  14581. /**
  14582. * Handle animation of the color attributes directly
  14583. */
  14584. each(['fill', 'stroke'], function (prop) {
  14585. HighchartsAdapter.addAnimSetter(prop, function (fx) {
  14586. fx.elem.attr(prop, ColorAxis.prototype.tweenColors(Color(fx.start), Color(fx.end), fx.pos));
  14587. });
  14588. });
  14589. /**
  14590. * Extend the chart getAxes method to also get the color axis
  14591. */
  14592. wrap(Chart.prototype, 'getAxes', function (proceed) {
  14593. var options = this.options,
  14594. colorAxisOptions = options.colorAxis;
  14595. proceed.call(this);
  14596. this.colorAxis = [];
  14597. if (colorAxisOptions) {
  14598. proceed = new ColorAxis(this, colorAxisOptions); // Fake assignment for jsLint
  14599. }
  14600. });
  14601. /**
  14602. * Wrap the legend getAllItems method to add the color axis. This also removes the
  14603. * axis' own series to prevent them from showing up individually.
  14604. */
  14605. wrap(Legend.prototype, 'getAllItems', function (proceed) {
  14606. var allItems = [],
  14607. colorAxis = this.chart.colorAxis[0];
  14608. if (colorAxis) {
  14609. // Data classes
  14610. if (colorAxis.options.dataClasses) {
  14611. allItems = allItems.concat(colorAxis.getDataClassLegendSymbols());
  14612. // Gradient legend
  14613. } else {
  14614. // Add this axis on top
  14615. allItems.push(colorAxis);
  14616. }
  14617. // Don't add the color axis' series
  14618. each(colorAxis.series, function (series) {
  14619. series.options.showInLegend = false;
  14620. });
  14621. }
  14622. return allItems.concat(proceed.call(this));
  14623. });/**
  14624. * Mixin for maps and heatmaps
  14625. */
  14626. var colorPointMixin = {
  14627. /**
  14628. * Set the visibility of a single point
  14629. */
  14630. setVisible: function (vis) {
  14631. var point = this,
  14632. method = vis ? 'show' : 'hide';
  14633. // Show and hide associated elements
  14634. each(['graphic', 'dataLabel'], function (key) {
  14635. if (point[key]) {
  14636. point[key][method]();
  14637. }
  14638. });
  14639. }
  14640. };
  14641. var colorSeriesMixin = {
  14642. pointAttrToOptions: { // mapping between SVG attributes and the corresponding options
  14643. stroke: 'borderColor',
  14644. 'stroke-width': 'borderWidth',
  14645. fill: 'color',
  14646. dashstyle: 'dashStyle'
  14647. },
  14648. pointArrayMap: ['value'],
  14649. axisTypes: ['xAxis', 'yAxis', 'colorAxis'],
  14650. optionalAxis: 'colorAxis',
  14651. trackerGroups: ['group', 'markerGroup', 'dataLabelsGroup'],
  14652. getSymbol: noop,
  14653. parallelArrays: ['x', 'y', 'value'],
  14654. colorKey: 'value',
  14655. /**
  14656. * In choropleth maps, the color is a result of the value, so this needs translation too
  14657. */
  14658. translateColors: function () {
  14659. var series = this,
  14660. nullColor = this.options.nullColor,
  14661. colorAxis = this.colorAxis,
  14662. colorKey = this.colorKey;
  14663. each(this.data, function (point) {
  14664. var value = point[colorKey],
  14665. color;
  14666. color = point.options.color ||
  14667. (value === null ? nullColor : (colorAxis && value !== undefined) ? colorAxis.toColor(value, point) : point.color || series.color);
  14668. if (color) {
  14669. point.color = color;
  14670. }
  14671. });
  14672. }
  14673. };
  14674. // The vector-effect attribute is not supported in IE <= 11 (at least), so we need
  14675. // diffent logic (#3218)
  14676. var supportsVectorEffect = document.documentElement.style.vectorEffect !== undefined;
  14677. /**
  14678. * Extend the default options with map options
  14679. */
  14680. defaultPlotOptions.map = merge(defaultPlotOptions.scatter, {
  14681. allAreas: true,
  14682. animation: false, // makes the complex shapes slow
  14683. nullColor: '#F8F8F8',
  14684. borderColor: 'silver',
  14685. borderWidth: 1,
  14686. marker: null,
  14687. stickyTracking: false,
  14688. dataLabels: {
  14689. formatter: function () { // #2945
  14690. return this.point.value;
  14691. },
  14692. inside: true, // for the color
  14693. verticalAlign: 'middle',
  14694. crop: false,
  14695. overflow: false,
  14696. padding: 0
  14697. },
  14698. turboThreshold: 0,
  14699. tooltip: {
  14700. followPointer: true,
  14701. pointFormat: '{point.name}: {point.value}<br/>'
  14702. },
  14703. states: {
  14704. normal: {
  14705. animation: true
  14706. },
  14707. hover: {
  14708. brightness: 0.2,
  14709. halo: null
  14710. }
  14711. }
  14712. });
  14713. /**
  14714. * The MapAreaPoint object
  14715. */
  14716. var MapAreaPoint = extendClass(Point, extend({
  14717. /**
  14718. * Extend the Point object to split paths
  14719. */
  14720. applyOptions: function (options, x) {
  14721. var point = Point.prototype.applyOptions.call(this, options, x),
  14722. series = this.series,
  14723. joinBy = series.joinBy,
  14724. mapPoint;
  14725. if (series.mapData) {
  14726. mapPoint = point[joinBy[1]] !== undefined && series.mapMap[point[joinBy[1]]];
  14727. if (mapPoint) {
  14728. // This applies only to bubbles
  14729. if (series.xyFromShape) {
  14730. point.x = mapPoint._midX;
  14731. point.y = mapPoint._midY;
  14732. }
  14733. extend(point, mapPoint); // copy over properties
  14734. } else {
  14735. point.value = point.value || null;
  14736. }
  14737. }
  14738. return point;
  14739. },
  14740. /**
  14741. * Stop the fade-out
  14742. */
  14743. onMouseOver: function (e) {
  14744. clearTimeout(this.colorInterval);
  14745. if (this.value !== null) {
  14746. Point.prototype.onMouseOver.call(this, e);
  14747. } else { //#3401 Tooltip doesn't hide when hovering over null points
  14748. this.series.onMouseOut(e);
  14749. }
  14750. },
  14751. /**
  14752. * Custom animation for tweening out the colors. Animation reduces blinking when hovering
  14753. * over islands and coast lines. We run a custom implementation of animation becuase we
  14754. * need to be able to run this independently from other animations like zoom redraw. Also,
  14755. * adding color animation to the adapters would introduce almost the same amount of code.
  14756. */
  14757. onMouseOut: function () {
  14758. var point = this,
  14759. start = +new Date(),
  14760. normalColor = Color(point.color),
  14761. hoverColor = Color(point.pointAttr.hover.fill),
  14762. animation = point.series.options.states.normal.animation,
  14763. duration = animation && (animation.duration || 500),
  14764. fill;
  14765. if (duration && normalColor.rgba.length === 4 && hoverColor.rgba.length === 4 && point.state !== 'select') {
  14766. fill = point.pointAttr[''].fill;
  14767. delete point.pointAttr[''].fill; // avoid resetting it in Point.setState
  14768. clearTimeout(point.colorInterval);
  14769. point.colorInterval = setInterval(function () {
  14770. var pos = (new Date() - start) / duration,
  14771. graphic = point.graphic;
  14772. if (pos > 1) {
  14773. pos = 1;
  14774. }
  14775. if (graphic) {
  14776. graphic.attr('fill', ColorAxis.prototype.tweenColors.call(0, hoverColor, normalColor, pos));
  14777. }
  14778. if (pos >= 1) {
  14779. clearTimeout(point.colorInterval);
  14780. }
  14781. }, 13);
  14782. }
  14783. Point.prototype.onMouseOut.call(point);
  14784. if (fill) {
  14785. point.pointAttr[''].fill = fill;
  14786. }
  14787. },
  14788. /**
  14789. * Zoom the chart to view a specific area point
  14790. */
  14791. zoomTo: function () {
  14792. var point = this,
  14793. series = point.series;
  14794. series.xAxis.setExtremes(
  14795. point._minX,
  14796. point._maxX,
  14797. false
  14798. );
  14799. series.yAxis.setExtremes(
  14800. point._minY,
  14801. point._maxY,
  14802. false
  14803. );
  14804. series.chart.redraw();
  14805. }
  14806. }, colorPointMixin)
  14807. );
  14808. /**
  14809. * Add the series type
  14810. */
  14811. seriesTypes.map = extendClass(seriesTypes.scatter, merge(colorSeriesMixin, {
  14812. type: 'map',
  14813. pointClass: MapAreaPoint,
  14814. supportsDrilldown: true,
  14815. getExtremesFromAll: true,
  14816. useMapGeometry: true, // get axis extremes from paths, not values
  14817. forceDL: true,
  14818. searchPoint: noop,
  14819. directTouch: true, // When tooltip is not shared, this series (and derivatives) requires direct touch/hover. KD-tree does not apply.
  14820. preserveAspectRatio: true, // X axis and Y axis must have same translation slope
  14821. /**
  14822. * Get the bounding box of all paths in the map combined.
  14823. */
  14824. getBox: function (paths) {
  14825. var MAX_VALUE = Number.MAX_VALUE,
  14826. maxX = -MAX_VALUE,
  14827. minX = MAX_VALUE,
  14828. maxY = -MAX_VALUE,
  14829. minY = MAX_VALUE,
  14830. minRange = MAX_VALUE,
  14831. xAxis = this.xAxis,
  14832. yAxis = this.yAxis,
  14833. hasBox;
  14834. // Find the bounding box
  14835. each(paths || [], function (point) {
  14836. if (point.path) {
  14837. if (typeof point.path === 'string') {
  14838. point.path = Highcharts.splitPath(point.path);
  14839. }
  14840. var path = point.path || [],
  14841. i = path.length,
  14842. even = false, // while loop reads from the end
  14843. pointMaxX = -MAX_VALUE,
  14844. pointMinX = MAX_VALUE,
  14845. pointMaxY = -MAX_VALUE,
  14846. pointMinY = MAX_VALUE,
  14847. properties = point.properties;
  14848. // The first time a map point is used, analyze its box
  14849. if (!point._foundBox) {
  14850. while (i--) {
  14851. if (typeof path[i] === 'number' && !isNaN(path[i])) {
  14852. if (even) { // even = x
  14853. pointMaxX = Math.max(pointMaxX, path[i]);
  14854. pointMinX = Math.min(pointMinX, path[i]);
  14855. } else { // odd = Y
  14856. pointMaxY = Math.max(pointMaxY, path[i]);
  14857. pointMinY = Math.min(pointMinY, path[i]);
  14858. }
  14859. even = !even;
  14860. }
  14861. }
  14862. // Cache point bounding box for use to position data labels, bubbles etc
  14863. point._midX = pointMinX + (pointMaxX - pointMinX) *
  14864. (point.middleX || (properties && properties['hc-middle-x']) || 0.5); // pick is slower and very marginally needed
  14865. point._midY = pointMinY + (pointMaxY - pointMinY) *
  14866. (point.middleY || (properties && properties['hc-middle-y']) || 0.5);
  14867. point._maxX = pointMaxX;
  14868. point._minX = pointMinX;
  14869. point._maxY = pointMaxY;
  14870. point._minY = pointMinY;
  14871. point.labelrank = pick(point.labelrank, (pointMaxX - pointMinX) * (pointMaxY - pointMinY));
  14872. point._foundBox = true;
  14873. }
  14874. maxX = Math.max(maxX, point._maxX);
  14875. minX = Math.min(minX, point._minX);
  14876. maxY = Math.max(maxY, point._maxY);
  14877. minY = Math.min(minY, point._minY);
  14878. minRange = Math.min(point._maxX - point._minX, point._maxY - point._minY, minRange);
  14879. hasBox = true;
  14880. }
  14881. });
  14882. // Set the box for the whole series
  14883. if (hasBox) {
  14884. this.minY = Math.min(minY, pick(this.minY, MAX_VALUE));
  14885. this.maxY = Math.max(maxY, pick(this.maxY, -MAX_VALUE));
  14886. this.minX = Math.min(minX, pick(this.minX, MAX_VALUE));
  14887. this.maxX = Math.max(maxX, pick(this.maxX, -MAX_VALUE));
  14888. // If no minRange option is set, set the default minimum zooming range to 5 times the
  14889. // size of the smallest element
  14890. if (xAxis && xAxis.options.minRange === undefined) {
  14891. xAxis.minRange = Math.min(5 * minRange, (this.maxX - this.minX) / 5, xAxis.minRange || MAX_VALUE);
  14892. }
  14893. if (yAxis && yAxis.options.minRange === undefined) {
  14894. yAxis.minRange = Math.min(5 * minRange, (this.maxY - this.minY) / 5, yAxis.minRange || MAX_VALUE);
  14895. }
  14896. }
  14897. },
  14898. getExtremes: function () {
  14899. // Get the actual value extremes for colors
  14900. Series.prototype.getExtremes.call(this, this.valueData);
  14901. // Recalculate box on updated data
  14902. if (this.chart.hasRendered && this.isDirtyData) {
  14903. this.getBox(this.options.data);
  14904. }
  14905. this.valueMin = this.dataMin;
  14906. this.valueMax = this.dataMax;
  14907. // Extremes for the mock Y axis
  14908. this.dataMin = this.minY;
  14909. this.dataMax = this.maxY;
  14910. },
  14911. /**
  14912. * Translate the path so that it automatically fits into the plot area box
  14913. * @param {Object} path
  14914. */
  14915. translatePath: function (path) {
  14916. var series = this,
  14917. even = false, // while loop reads from the end
  14918. xAxis = series.xAxis,
  14919. yAxis = series.yAxis,
  14920. xMin = xAxis.min,
  14921. xTransA = xAxis.transA,
  14922. xMinPixelPadding = xAxis.minPixelPadding,
  14923. yMin = yAxis.min,
  14924. yTransA = yAxis.transA,
  14925. yMinPixelPadding = yAxis.minPixelPadding,
  14926. i,
  14927. ret = []; // Preserve the original
  14928. // Do the translation
  14929. if (path) {
  14930. i = path.length;
  14931. while (i--) {
  14932. if (typeof path[i] === 'number') {
  14933. ret[i] = even ?
  14934. (path[i] - xMin) * xTransA + xMinPixelPadding :
  14935. (path[i] - yMin) * yTransA + yMinPixelPadding;
  14936. even = !even;
  14937. } else {
  14938. ret[i] = path[i];
  14939. }
  14940. }
  14941. }
  14942. return ret;
  14943. },
  14944. /**
  14945. * Extend setData to join in mapData. If the allAreas option is true, all areas
  14946. * from the mapData are used, and those that don't correspond to a data value
  14947. * are given null values.
  14948. */
  14949. setData: function (data, redraw) {
  14950. var options = this.options,
  14951. mapData = options.mapData,
  14952. joinBy = options.joinBy,
  14953. joinByNull = joinBy === null,
  14954. dataUsed = [],
  14955. mapPoint,
  14956. transform,
  14957. mapTransforms,
  14958. props,
  14959. i;
  14960. if (joinByNull) {
  14961. joinBy = '_i';
  14962. }
  14963. joinBy = this.joinBy = Highcharts.splat(joinBy);
  14964. if (!joinBy[1]) {
  14965. joinBy[1] = joinBy[0];
  14966. }
  14967. // Pick up numeric values, add index
  14968. if (data) {
  14969. each(data, function (val, i) {
  14970. if (typeof val === 'number') {
  14971. data[i] = {
  14972. value: val
  14973. };
  14974. }
  14975. if (joinByNull) {
  14976. data[i]._i = i;
  14977. }
  14978. });
  14979. }
  14980. this.getBox(data);
  14981. if (mapData) {
  14982. if (mapData.type === 'FeatureCollection') {
  14983. if (mapData['hc-transform']) {
  14984. this.chart.mapTransforms = mapTransforms = mapData['hc-transform'];
  14985. // Cache cos/sin of transform rotation angle
  14986. for (transform in mapTransforms) {
  14987. if (mapTransforms.hasOwnProperty(transform) && transform.rotation) {
  14988. transform.cosAngle = Math.cos(transform.rotation);
  14989. transform.sinAngle = Math.sin(transform.rotation);
  14990. }
  14991. }
  14992. }
  14993. mapData = Highcharts.geojson(mapData, this.type, this);
  14994. }
  14995. this.getBox(mapData);
  14996. this.mapData = mapData;
  14997. this.mapMap = {};
  14998. for (i = 0; i < mapData.length; i++) {
  14999. mapPoint = mapData[i];
  15000. props = mapPoint.properties;
  15001. mapPoint._i = i;
  15002. // Copy the property over to root for faster access
  15003. if (joinBy[0] && props && props[joinBy[0]]) {
  15004. mapPoint[joinBy[0]] = props[joinBy[0]];
  15005. }
  15006. this.mapMap[mapPoint[joinBy[0]]] = mapPoint;
  15007. }
  15008. if (options.allAreas) {
  15009. data = data || [];
  15010. // Registered the point codes that actually hold data
  15011. if (joinBy[1]) {
  15012. each(data, function (point) {
  15013. dataUsed.push(point[joinBy[1]]);
  15014. });
  15015. }
  15016. // Add those map points that don't correspond to data, which will be drawn as null points
  15017. dataUsed = '|' + dataUsed.join('|') + '|'; // String search is faster than array.indexOf
  15018. each(mapData, function (mapPoint) {
  15019. if (!joinBy[0] || dataUsed.indexOf('|' + mapPoint[joinBy[0]] + '|') === -1) {
  15020. data.push(merge(mapPoint, { value: null }));
  15021. }
  15022. });
  15023. }
  15024. }
  15025. Series.prototype.setData.call(this, data, redraw);
  15026. },
  15027. /**
  15028. * No graph for the map series
  15029. */
  15030. drawGraph: noop,
  15031. /**
  15032. * We need the points' bounding boxes in order to draw the data labels, so
  15033. * we skip it now and call it from drawPoints instead.
  15034. */
  15035. drawDataLabels: noop,
  15036. /**
  15037. * Allow a quick redraw by just translating the area group. Used for zooming and panning
  15038. * in capable browsers.
  15039. */
  15040. doFullTranslate: function () {
  15041. return this.isDirtyData || this.chart.isResizing || this.chart.renderer.isVML || !this.baseTrans;
  15042. },
  15043. /**
  15044. * Add the path option for data points. Find the max value for color calculation.
  15045. */
  15046. translate: function () {
  15047. var series = this,
  15048. xAxis = series.xAxis,
  15049. yAxis = series.yAxis,
  15050. doFullTranslate = series.doFullTranslate();
  15051. series.generatePoints();
  15052. each(series.data, function (point) {
  15053. // Record the middle point (loosely based on centroid), determined
  15054. // by the middleX and middleY options.
  15055. point.plotX = xAxis.toPixels(point._midX, true);
  15056. point.plotY = yAxis.toPixels(point._midY, true);
  15057. if (doFullTranslate) {
  15058. point.shapeType = 'path';
  15059. point.shapeArgs = {
  15060. d: series.translatePath(point.path)
  15061. };
  15062. if (supportsVectorEffect) {
  15063. point.shapeArgs['vector-effect'] = 'non-scaling-stroke';
  15064. }
  15065. }
  15066. });
  15067. series.translateColors();
  15068. },
  15069. /**
  15070. * Use the drawPoints method of column, that is able to handle simple shapeArgs.
  15071. * Extend it by assigning the tooltip position.
  15072. */
  15073. drawPoints: function () {
  15074. var series = this,
  15075. xAxis = series.xAxis,
  15076. yAxis = series.yAxis,
  15077. group = series.group,
  15078. chart = series.chart,
  15079. renderer = chart.renderer,
  15080. scaleX,
  15081. scaleY,
  15082. translateX,
  15083. translateY,
  15084. baseTrans = this.baseTrans;
  15085. // Set a group that handles transform during zooming and panning in order to preserve clipping
  15086. // on series.group
  15087. if (!series.transformGroup) {
  15088. series.transformGroup = renderer.g()
  15089. .attr({
  15090. scaleX: 1,
  15091. scaleY: 1
  15092. })
  15093. .add(group);
  15094. series.transformGroup.survive = true;
  15095. }
  15096. // Draw the shapes again
  15097. if (series.doFullTranslate()) {
  15098. // Individual point actions
  15099. if (chart.hasRendered && series.pointAttrToOptions.fill === 'color') {
  15100. each(series.points, function (point) {
  15101. // Reset color on update/redraw
  15102. if (point.shapeArgs) {
  15103. point.shapeArgs.fill = point.pointAttr[pick(point.state, '')].fill; // #3529
  15104. }
  15105. });
  15106. }
  15107. // If vector-effect is not supported, we set the stroke-width on the group element
  15108. // and let all point graphics inherit. That way we don't have to iterate over all
  15109. // points to update the stroke-width on zooming.
  15110. if (!supportsVectorEffect) {
  15111. each(series.points, function (point) {
  15112. var attr = point.pointAttr[''];
  15113. if (attr['stroke-width'] === series.pointAttr['']['stroke-width']) {
  15114. attr['stroke-width'] = 'inherit';
  15115. }
  15116. });
  15117. }
  15118. // Draw them in transformGroup
  15119. series.group = series.transformGroup;
  15120. seriesTypes.column.prototype.drawPoints.apply(series);
  15121. series.group = group; // Reset
  15122. // Add class names
  15123. each(series.points, function (point) {
  15124. if (point.graphic) {
  15125. if (point.name) {
  15126. point.graphic.addClass('highcharts-name-' + point.name.replace(' ', '-').toLowerCase());
  15127. }
  15128. if (point.properties && point.properties['hc-key']) {
  15129. point.graphic.addClass('highcharts-key-' + point.properties['hc-key'].toLowerCase());
  15130. }
  15131. if (!supportsVectorEffect) {
  15132. point.graphic['stroke-widthSetter'] = noop;
  15133. }
  15134. }
  15135. });
  15136. // Set the base for later scale-zooming. The originX and originY properties are the
  15137. // axis values in the plot area's upper left corner.
  15138. this.baseTrans = {
  15139. originX: xAxis.min - xAxis.minPixelPadding / xAxis.transA,
  15140. originY: yAxis.min - yAxis.minPixelPadding / yAxis.transA + (yAxis.reversed ? 0 : yAxis.len / yAxis.transA),
  15141. transAX: xAxis.transA,
  15142. transAY: yAxis.transA
  15143. };
  15144. // Reset transformation in case we're doing a full translate (#3789)
  15145. this.transformGroup.animate({
  15146. translateX: 0,
  15147. translateY: 0,
  15148. scaleX: 1,
  15149. scaleY: 1
  15150. });
  15151. // Just update the scale and transform for better performance
  15152. } else {
  15153. scaleX = xAxis.transA / baseTrans.transAX;
  15154. scaleY = yAxis.transA / baseTrans.transAY;
  15155. translateX = xAxis.toPixels(baseTrans.originX, true);
  15156. translateY = yAxis.toPixels(baseTrans.originY, true);
  15157. // Handle rounding errors in normal view (#3789)
  15158. if (scaleX > 0.99 && scaleX < 1.01 && scaleY > 0.99 && scaleY < 1.01) {
  15159. scaleX = 1;
  15160. scaleY = 1;
  15161. translateX = Math.round(translateX);
  15162. translateY = Math.round(translateY);
  15163. }
  15164. this.transformGroup.animate({
  15165. translateX: translateX,
  15166. translateY: translateY,
  15167. scaleX: scaleX,
  15168. scaleY: scaleY
  15169. });
  15170. }
  15171. // Set the stroke-width directly on the group element so the children inherit it. We need to use
  15172. // setAttribute directly, because the stroke-widthSetter method expects a stroke color also to be
  15173. // set.
  15174. if (!supportsVectorEffect) {
  15175. series.group.element.setAttribute('stroke-width', series.options.borderWidth / (scaleX || 1));
  15176. }
  15177. this.drawMapDataLabels();
  15178. },
  15179. /**
  15180. * Draw the data labels. Special for maps is the time that the data labels are drawn (after points),
  15181. * and the clipping of the dataLabelsGroup.
  15182. */
  15183. drawMapDataLabels: function () {
  15184. Series.prototype.drawDataLabels.call(this);
  15185. if (this.dataLabelsGroup) {
  15186. this.dataLabelsGroup.clip(this.chart.clipRect);
  15187. }
  15188. },
  15189. /**
  15190. * Override render to throw in an async call in IE8. Otherwise it chokes on the US counties demo.
  15191. */
  15192. render: function () {
  15193. var series = this,
  15194. render = Series.prototype.render;
  15195. // Give IE8 some time to breathe.
  15196. if (series.chart.renderer.isVML && series.data.length > 3000) {
  15197. setTimeout(function () {
  15198. render.call(series);
  15199. });
  15200. } else {
  15201. render.call(series);
  15202. }
  15203. },
  15204. /**
  15205. * The initial animation for the map series. By default, animation is disabled.
  15206. * Animation of map shapes is not at all supported in VML browsers.
  15207. */
  15208. animate: function (init) {
  15209. var chart = this.chart,
  15210. animation = this.options.animation,
  15211. group = this.group,
  15212. xAxis = this.xAxis,
  15213. yAxis = this.yAxis,
  15214. left = xAxis.pos,
  15215. top = yAxis.pos;
  15216. if (chart.renderer.isSVG) {
  15217. if (animation === true) {
  15218. animation = {
  15219. duration: 1000
  15220. };
  15221. }
  15222. // Initialize the animation
  15223. if (init) {
  15224. // Scale down the group and place it in the center
  15225. group.attr({
  15226. translateX: left + xAxis.len / 2,
  15227. translateY: top + yAxis.len / 2,
  15228. scaleX: 0.001, // #1499
  15229. scaleY: 0.001
  15230. });
  15231. // Run the animation
  15232. } else {
  15233. group.animate({
  15234. translateX: left,
  15235. translateY: top,
  15236. scaleX: 1,
  15237. scaleY: 1
  15238. }, animation);
  15239. // Delete this function to allow it only once
  15240. this.animate = null;
  15241. }
  15242. }
  15243. },
  15244. /**
  15245. * Animate in the new series from the clicked point in the old series.
  15246. * Depends on the drilldown.js module
  15247. */
  15248. animateDrilldown: function (init) {
  15249. var toBox = this.chart.plotBox,
  15250. level = this.chart.drilldownLevels[this.chart.drilldownLevels.length - 1],
  15251. fromBox = level.bBox,
  15252. animationOptions = this.chart.options.drilldown.animation,
  15253. scale;
  15254. if (!init) {
  15255. scale = Math.min(fromBox.width / toBox.width, fromBox.height / toBox.height);
  15256. level.shapeArgs = {
  15257. scaleX: scale,
  15258. scaleY: scale,
  15259. translateX: fromBox.x,
  15260. translateY: fromBox.y
  15261. };
  15262. // TODO: Animate this.group instead
  15263. each(this.points, function (point) {
  15264. if (point.graphic) {
  15265. point.graphic
  15266. .attr(level.shapeArgs)
  15267. .animate({
  15268. scaleX: 1,
  15269. scaleY: 1,
  15270. translateX: 0,
  15271. translateY: 0
  15272. }, animationOptions);
  15273. }
  15274. });
  15275. this.animate = null;
  15276. }
  15277. },
  15278. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  15279. /**
  15280. * When drilling up, pull out the individual point graphics from the lower series
  15281. * and animate them into the origin point in the upper series.
  15282. */
  15283. animateDrillupFrom: function (level) {
  15284. seriesTypes.column.prototype.animateDrillupFrom.call(this, level);
  15285. },
  15286. /**
  15287. * When drilling up, keep the upper series invisible until the lower series has
  15288. * moved into place
  15289. */
  15290. animateDrillupTo: function (init) {
  15291. seriesTypes.column.prototype.animateDrillupTo.call(this, init);
  15292. }
  15293. }));/**
  15294. * Highmaps JS v1.1.9 (2015-10-07)
  15295. * Highcharts module to hide overlapping data labels. This module is included by default in Highmaps.
  15296. *
  15297. * (c) 2010-2014 Torstein Honsi
  15298. *
  15299. * License: www.highcharts.com/license
  15300. */
  15301. /*global Highcharts, HighchartsAdapter */
  15302. (function (H) {
  15303. var Chart = H.Chart,
  15304. each = H.each,
  15305. pick = H.pick,
  15306. addEvent = HighchartsAdapter.addEvent;
  15307. // Collect potensial overlapping data labels. Stack labels probably don't need to be
  15308. // considered because they are usually accompanied by data labels that lie inside the columns.
  15309. Chart.prototype.callbacks.push(function (chart) {
  15310. function collectAndHide() {
  15311. var labels = [];
  15312. each(chart.series, function (series) {
  15313. var dlOptions = series.options.dataLabels,
  15314. collections = series.dataLabelCollections || ['dataLabel']; // Range series have two collections
  15315. if ((dlOptions.enabled || series._hasPointLabels) && !dlOptions.allowOverlap && series.visible) { // #3866
  15316. each(collections, function (coll) {
  15317. each(series.points, function (point) {
  15318. if (point[coll]) {
  15319. point[coll].labelrank = pick(point.labelrank, point.shapeArgs && point.shapeArgs.height); // #4118
  15320. labels.push(point[coll]);
  15321. }
  15322. });
  15323. });
  15324. }
  15325. });
  15326. chart.hideOverlappingLabels(labels);
  15327. }
  15328. // Do it now ...
  15329. collectAndHide();
  15330. // ... and after each chart redraw
  15331. addEvent(chart, 'redraw', collectAndHide);
  15332. });
  15333. /**
  15334. * Hide overlapping labels. Labels are moved and faded in and out on zoom to provide a smooth
  15335. * visual imression.
  15336. */
  15337. Chart.prototype.hideOverlappingLabels = function (labels) {
  15338. var len = labels.length,
  15339. label,
  15340. i,
  15341. j,
  15342. label1,
  15343. label2,
  15344. isIntersecting,
  15345. pos1,
  15346. pos2,
  15347. padding,
  15348. intersectRect = function (x1, y1, w1, h1, x2, y2, w2, h2) {
  15349. return !(
  15350. x2 > x1 + w1 ||
  15351. x2 + w2 < x1 ||
  15352. y2 > y1 + h1 ||
  15353. y2 + h2 < y1
  15354. );
  15355. };
  15356. // Mark with initial opacity
  15357. for (i = 0; i < len; i++) {
  15358. label = labels[i];
  15359. if (label) {
  15360. label.oldOpacity = label.opacity;
  15361. label.newOpacity = 1;
  15362. }
  15363. }
  15364. // Prevent a situation in a gradually rising slope, that each label
  15365. // will hide the previous one because the previous one always has
  15366. // lower rank.
  15367. labels.sort(function (a, b) {
  15368. return (b.labelrank || 0) - (a.labelrank || 0);
  15369. });
  15370. // Detect overlapping labels
  15371. for (i = 0; i < len; i++) {
  15372. label1 = labels[i];
  15373. for (j = i + 1; j < len; ++j) {
  15374. label2 = labels[j];
  15375. if (label1 && label2 && label1.placed && label2.placed && label1.newOpacity !== 0 && label2.newOpacity !== 0) {
  15376. pos1 = label1.alignAttr;
  15377. pos2 = label2.alignAttr;
  15378. padding = 2 * (label1.box ? 0 : label1.padding); // Substract the padding if no background or border (#4333)
  15379. isIntersecting = intersectRect(
  15380. pos1.x,
  15381. pos1.y,
  15382. label1.width - padding,
  15383. label1.height - padding,
  15384. pos2.x,
  15385. pos2.y,
  15386. label2.width - padding,
  15387. label2.height - padding
  15388. );
  15389. if (isIntersecting) {
  15390. (label1.labelrank < label2.labelrank ? label1 : label2).newOpacity = 0;
  15391. }
  15392. }
  15393. }
  15394. }
  15395. // Hide or show
  15396. each(labels, function (label) {
  15397. var complete,
  15398. newOpacity;
  15399. if (label) {
  15400. newOpacity = label.newOpacity;
  15401. if (label.oldOpacity !== newOpacity && label.placed) {
  15402. // Make sure the label is completely hidden to avoid catching clicks (#4362)
  15403. if (newOpacity) {
  15404. label.show(true);
  15405. } else {
  15406. complete = function () {
  15407. label.hide();
  15408. };
  15409. }
  15410. // Animate or set the opacity
  15411. label.alignAttr.opacity = newOpacity;
  15412. label[label.isOld ? 'animate' : 'attr'](label.alignAttr, null, complete);
  15413. }
  15414. label.isOld = true;
  15415. }
  15416. });
  15417. };
  15418. }(Highcharts));
  15419. // Add events to the Chart object itself
  15420. extend(Chart.prototype, {
  15421. renderMapNavigation: function () {
  15422. var chart = this,
  15423. options = this.options.mapNavigation,
  15424. buttons = options.buttons,
  15425. n,
  15426. button,
  15427. buttonOptions,
  15428. attr,
  15429. states,
  15430. stopEvent = function (e) {
  15431. if (e) {
  15432. if (e.preventDefault) {
  15433. e.preventDefault();
  15434. }
  15435. if (e.stopPropagation) {
  15436. e.stopPropagation();
  15437. }
  15438. e.cancelBubble = true;
  15439. }
  15440. },
  15441. outerHandler = function (e) {
  15442. this.handler.call(chart, e);
  15443. stopEvent(e); // Stop default click event (#4444)
  15444. };
  15445. if (pick(options.enableButtons, options.enabled) && !chart.renderer.forExport) {
  15446. for (n in buttons) {
  15447. if (buttons.hasOwnProperty(n)) {
  15448. buttonOptions = merge(options.buttonOptions, buttons[n]);
  15449. attr = buttonOptions.theme;
  15450. attr.style = merge(buttonOptions.theme.style, buttonOptions.style); // #3203
  15451. states = attr.states;
  15452. button = chart.renderer.button(
  15453. buttonOptions.text,
  15454. 0,
  15455. 0,
  15456. outerHandler,
  15457. attr,
  15458. states && states.hover,
  15459. states && states.select,
  15460. 0,
  15461. n === 'zoomIn' ? 'topbutton' : 'bottombutton'
  15462. )
  15463. .attr({
  15464. width: buttonOptions.width,
  15465. height: buttonOptions.height,
  15466. title: chart.options.lang[n],
  15467. zIndex: 5
  15468. })
  15469. .add();
  15470. button.handler = buttonOptions.onclick;
  15471. button.align(extend(buttonOptions, { width: button.width, height: 2 * button.height }), null, buttonOptions.alignTo);
  15472. addEvent(button.element, 'dblclick', stopEvent); // Stop double click event (#4444)
  15473. }
  15474. }
  15475. }
  15476. },
  15477. /**
  15478. * Fit an inner box to an outer. If the inner box overflows left or right, align it to the sides of the
  15479. * outer. If it overflows both sides, fit it within the outer. This is a pattern that occurs more places
  15480. * in Highcharts, perhaps it should be elevated to a common utility function.
  15481. */
  15482. fitToBox: function (inner, outer) {
  15483. each([['x', 'width'], ['y', 'height']], function (dim) {
  15484. var pos = dim[0],
  15485. size = dim[1];
  15486. if (inner[pos] + inner[size] > outer[pos] + outer[size]) { // right overflow
  15487. if (inner[size] > outer[size]) { // the general size is greater, fit fully to outer
  15488. inner[size] = outer[size];
  15489. inner[pos] = outer[pos];
  15490. } else { // align right
  15491. inner[pos] = outer[pos] + outer[size] - inner[size];
  15492. }
  15493. }
  15494. if (inner[size] > outer[size]) {
  15495. inner[size] = outer[size];
  15496. }
  15497. if (inner[pos] < outer[pos]) {
  15498. inner[pos] = outer[pos];
  15499. }
  15500. });
  15501. return inner;
  15502. },
  15503. /**
  15504. * Zoom the map in or out by a certain amount. Less than 1 zooms in, greater than 1 zooms out.
  15505. */
  15506. mapZoom: function (howMuch, centerXArg, centerYArg, mouseX, mouseY) {
  15507. /*if (this.isMapZooming) {
  15508. this.mapZoomQueue = arguments;
  15509. return;
  15510. }*/
  15511. var chart = this,
  15512. xAxis = chart.xAxis[0],
  15513. xRange = xAxis.max - xAxis.min,
  15514. centerX = pick(centerXArg, xAxis.min + xRange / 2),
  15515. newXRange = xRange * howMuch,
  15516. yAxis = chart.yAxis[0],
  15517. yRange = yAxis.max - yAxis.min,
  15518. centerY = pick(centerYArg, yAxis.min + yRange / 2),
  15519. newYRange = yRange * howMuch,
  15520. fixToX = mouseX ? ((mouseX - xAxis.pos) / xAxis.len) : 0.5,
  15521. fixToY = mouseY ? ((mouseY - yAxis.pos) / yAxis.len) : 0.5,
  15522. newXMin = centerX - newXRange * fixToX,
  15523. newYMin = centerY - newYRange * fixToY,
  15524. newExt = chart.fitToBox({
  15525. x: newXMin,
  15526. y: newYMin,
  15527. width: newXRange,
  15528. height: newYRange
  15529. }, {
  15530. x: xAxis.dataMin,
  15531. y: yAxis.dataMin,
  15532. width: xAxis.dataMax - xAxis.dataMin,
  15533. height: yAxis.dataMax - yAxis.dataMin
  15534. });
  15535. // When mousewheel zooming, fix the point under the mouse
  15536. if (mouseX) {
  15537. xAxis.fixTo = [mouseX - xAxis.pos, centerXArg];
  15538. }
  15539. if (mouseY) {
  15540. yAxis.fixTo = [mouseY - yAxis.pos, centerYArg];
  15541. }
  15542. // Zoom
  15543. if (howMuch !== undefined) {
  15544. xAxis.setExtremes(newExt.x, newExt.x + newExt.width, false);
  15545. yAxis.setExtremes(newExt.y, newExt.y + newExt.height, false);
  15546. // Reset zoom
  15547. } else {
  15548. xAxis.setExtremes(undefined, undefined, false);
  15549. yAxis.setExtremes(undefined, undefined, false);
  15550. }
  15551. // Prevent zooming until this one is finished animating
  15552. /*chart.holdMapZoom = true;
  15553. setTimeout(function () {
  15554. chart.holdMapZoom = false;
  15555. }, 200);*/
  15556. /*delay = animation ? animation.duration || 500 : 0;
  15557. if (delay) {
  15558. chart.isMapZooming = true;
  15559. setTimeout(function () {
  15560. chart.isMapZooming = false;
  15561. if (chart.mapZoomQueue) {
  15562. chart.mapZoom.apply(chart, chart.mapZoomQueue);
  15563. }
  15564. chart.mapZoomQueue = null;
  15565. }, delay);
  15566. }*/
  15567. chart.redraw();
  15568. }
  15569. });
  15570. /**
  15571. * Extend the Chart.render method to add zooming and panning
  15572. */
  15573. wrap(Chart.prototype, 'render', function (proceed) {
  15574. var chart = this,
  15575. mapNavigation = chart.options.mapNavigation;
  15576. // Render the plus and minus buttons. Doing this before the shapes makes getBBox much quicker, at least in Chrome.
  15577. chart.renderMapNavigation();
  15578. proceed.call(chart);
  15579. // Add the double click event
  15580. if (pick(mapNavigation.enableDoubleClickZoom, mapNavigation.enabled) || mapNavigation.enableDoubleClickZoomTo) {
  15581. addEvent(chart.container, 'dblclick', function (e) {
  15582. chart.pointer.onContainerDblClick(e);
  15583. });
  15584. }
  15585. // Add the mousewheel event
  15586. if (pick(mapNavigation.enableMouseWheelZoom, mapNavigation.enabled)) {
  15587. addEvent(chart.container, document.onmousewheel === undefined ? 'DOMMouseScroll' : 'mousewheel', function (e) {
  15588. chart.pointer.onContainerMouseWheel(e);
  15589. return false;
  15590. });
  15591. }
  15592. });
  15593. // Extend the Pointer
  15594. extend(Pointer.prototype, {
  15595. /**
  15596. * The event handler for the doubleclick event
  15597. */
  15598. onContainerDblClick: function (e) {
  15599. var chart = this.chart;
  15600. e = this.normalize(e);
  15601. if (chart.options.mapNavigation.enableDoubleClickZoomTo) {
  15602. if (chart.pointer.inClass(e.target, 'highcharts-tracker')) {
  15603. chart.hoverPoint.zoomTo();
  15604. }
  15605. } else if (chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop)) {
  15606. chart.mapZoom(
  15607. 0.5,
  15608. chart.xAxis[0].toValue(e.chartX),
  15609. chart.yAxis[0].toValue(e.chartY),
  15610. e.chartX,
  15611. e.chartY
  15612. );
  15613. }
  15614. },
  15615. /**
  15616. * The event handler for the mouse scroll event
  15617. */
  15618. onContainerMouseWheel: function (e) {
  15619. var chart = this.chart,
  15620. delta;
  15621. e = this.normalize(e);
  15622. // Firefox uses e.detail, WebKit and IE uses wheelDelta
  15623. delta = e.detail || -(e.wheelDelta / 120);
  15624. if (chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop)) {
  15625. chart.mapZoom(
  15626. //delta > 0 ? 2 : 0.5,
  15627. Math.pow(2, delta),
  15628. chart.xAxis[0].toValue(e.chartX),
  15629. chart.yAxis[0].toValue(e.chartY),
  15630. e.chartX,
  15631. e.chartY
  15632. );
  15633. }
  15634. }
  15635. });
  15636. // Implement the pinchType option
  15637. wrap(Pointer.prototype, 'init', function (proceed, chart, options) {
  15638. proceed.call(this, chart, options);
  15639. // Pinch status
  15640. if (pick(options.mapNavigation.enableTouchZoom, options.mapNavigation.enabled)) {
  15641. this.pinchX = this.pinchHor = this.pinchY = this.pinchVert = this.hasZoom = true;
  15642. }
  15643. });
  15644. // Extend the pinchTranslate method to preserve fixed ratio when zooming
  15645. wrap(Pointer.prototype, 'pinchTranslate', function (proceed, pinchDown, touches, transform, selectionMarker, clip, lastValidTouch) {
  15646. var xBigger;
  15647. proceed.call(this, pinchDown, touches, transform, selectionMarker, clip, lastValidTouch);
  15648. // Keep ratio
  15649. if (this.chart.options.chart.type === 'map' && this.hasZoom) {
  15650. xBigger = transform.scaleX > transform.scaleY;
  15651. this.pinchTranslateDirection(
  15652. !xBigger,
  15653. pinchDown,
  15654. touches,
  15655. transform,
  15656. selectionMarker,
  15657. clip,
  15658. lastValidTouch,
  15659. xBigger ? transform.scaleX : transform.scaleY
  15660. );
  15661. }
  15662. });
  15663. // The mapline series type
  15664. defaultPlotOptions.mapline = merge(defaultPlotOptions.map, {
  15665. lineWidth: 1,
  15666. fillColor: 'none'
  15667. });
  15668. seriesTypes.mapline = extendClass(seriesTypes.map, {
  15669. type: 'mapline',
  15670. pointAttrToOptions: { // mapping between SVG attributes and the corresponding options
  15671. stroke: 'color',
  15672. 'stroke-width': 'lineWidth',
  15673. fill: 'fillColor',
  15674. dashstyle: 'dashStyle'
  15675. },
  15676. drawLegendSymbol: seriesTypes.line.prototype.drawLegendSymbol
  15677. });
  15678. // The mappoint series type
  15679. defaultPlotOptions.mappoint = merge(defaultPlotOptions.scatter, {
  15680. dataLabels: {
  15681. enabled: true,
  15682. formatter: function () { // #2945
  15683. return this.point.name;
  15684. },
  15685. crop: false,
  15686. defer: false,
  15687. overflow: false,
  15688. style: {
  15689. color: '#000000'
  15690. }
  15691. }
  15692. });
  15693. seriesTypes.mappoint = extendClass(seriesTypes.scatter, {
  15694. type: 'mappoint',
  15695. forceDL: true,
  15696. pointClass: extendClass(Point, {
  15697. applyOptions: function (options, x) {
  15698. var point = Point.prototype.applyOptions.call(this, options, x);
  15699. if (options.lat !== undefined && options.lon !== undefined) {
  15700. point = extend(point, this.series.chart.fromLatLonToPoint(point));
  15701. }
  15702. return point;
  15703. }
  15704. })
  15705. });/* ****************************************************************************
  15706. * Start Bubble series code *
  15707. *****************************************************************************/
  15708. // 1 - set default options
  15709. defaultPlotOptions.bubble = merge(defaultPlotOptions.scatter, {
  15710. dataLabels: {
  15711. formatter: function () { // #2945
  15712. return this.point.z;
  15713. },
  15714. inside: true,
  15715. verticalAlign: 'middle'
  15716. },
  15717. // displayNegative: true,
  15718. marker: {
  15719. // fillOpacity: 0.5,
  15720. lineColor: null, // inherit from series.color
  15721. lineWidth: 1
  15722. },
  15723. minSize: 8,
  15724. maxSize: '20%',
  15725. // negativeColor: null,
  15726. // sizeBy: 'area'
  15727. softThreshold: false,
  15728. states: {
  15729. hover: {
  15730. halo: {
  15731. size: 5
  15732. }
  15733. }
  15734. },
  15735. tooltip: {
  15736. pointFormat: '({point.x}, {point.y}), Size: {point.z}'
  15737. },
  15738. turboThreshold: 0,
  15739. zThreshold: 0,
  15740. zoneAxis: 'z'
  15741. });
  15742. var BubblePoint = extendClass(Point, {
  15743. haloPath: function () {
  15744. return Point.prototype.haloPath.call(this, this.shapeArgs.r + this.series.options.states.hover.halo.size);
  15745. },
  15746. ttBelow: false
  15747. });
  15748. // 2 - Create the series object
  15749. seriesTypes.bubble = extendClass(seriesTypes.scatter, {
  15750. type: 'bubble',
  15751. pointClass: BubblePoint,
  15752. pointArrayMap: ['y', 'z'],
  15753. parallelArrays: ['x', 'y', 'z'],
  15754. trackerGroups: ['group', 'dataLabelsGroup'],
  15755. bubblePadding: true,
  15756. zoneAxis: 'z',
  15757. /**
  15758. * Mapping between SVG attributes and the corresponding options
  15759. */
  15760. pointAttrToOptions: {
  15761. stroke: 'lineColor',
  15762. 'stroke-width': 'lineWidth',
  15763. fill: 'fillColor'
  15764. },
  15765. /**
  15766. * Apply the fillOpacity to all fill positions
  15767. */
  15768. applyOpacity: function (fill) {
  15769. var markerOptions = this.options.marker,
  15770. fillOpacity = pick(markerOptions.fillOpacity, 0.5);
  15771. // When called from Legend.colorizeItem, the fill isn't predefined
  15772. fill = fill || markerOptions.fillColor || this.color;
  15773. if (fillOpacity !== 1) {
  15774. fill = Color(fill).setOpacity(fillOpacity).get('rgba');
  15775. }
  15776. return fill;
  15777. },
  15778. /**
  15779. * Extend the convertAttribs method by applying opacity to the fill
  15780. */
  15781. convertAttribs: function () {
  15782. var obj = Series.prototype.convertAttribs.apply(this, arguments);
  15783. obj.fill = this.applyOpacity(obj.fill);
  15784. return obj;
  15785. },
  15786. /**
  15787. * Get the radius for each point based on the minSize, maxSize and each point's Z value. This
  15788. * must be done prior to Series.translate because the axis needs to add padding in
  15789. * accordance with the point sizes.
  15790. */
  15791. getRadii: function (zMin, zMax, minSize, maxSize) {
  15792. var len,
  15793. i,
  15794. pos,
  15795. zData = this.zData,
  15796. radii = [],
  15797. options = this.options,
  15798. sizeByArea = options.sizeBy !== 'width',
  15799. zThreshold = options.zThreshold,
  15800. zRange = zMax - zMin,
  15801. value,
  15802. radius;
  15803. // Set the shape type and arguments to be picked up in drawPoints
  15804. for (i = 0, len = zData.length; i < len; i++) {
  15805. value = zData[i];
  15806. // When sizing by threshold, the absolute value of z determines the size
  15807. // of the bubble.
  15808. if (options.sizeByAbsoluteValue) {
  15809. value = Math.abs(value - zThreshold);
  15810. zMax = Math.max(zMax - zThreshold, Math.abs(zMin - zThreshold));
  15811. zMin = 0;
  15812. }
  15813. if (value === null) {
  15814. radius = null;
  15815. // Issue #4419 - if value is less than zMin, push a radius that's always smaller than the minimum size
  15816. } else if (value < zMin) {
  15817. radius = minSize / 2 - 1;
  15818. } else {
  15819. // Relative size, a number between 0 and 1
  15820. pos = zRange > 0 ? (value - zMin) / zRange : 0.5;
  15821. if (sizeByArea && pos >= 0) {
  15822. pos = Math.sqrt(pos);
  15823. }
  15824. radius = math.ceil(minSize + pos * (maxSize - minSize)) / 2;
  15825. }
  15826. radii.push(radius);
  15827. }
  15828. this.radii = radii;
  15829. },
  15830. /**
  15831. * Perform animation on the bubbles
  15832. */
  15833. animate: function (init) {
  15834. var animation = this.options.animation;
  15835. if (!init) { // run the animation
  15836. each(this.points, function (point) {
  15837. var graphic = point.graphic,
  15838. shapeArgs = point.shapeArgs;
  15839. if (graphic && shapeArgs) {
  15840. // start values
  15841. graphic.attr('r', 1);
  15842. // animate
  15843. graphic.animate({
  15844. r: shapeArgs.r
  15845. }, animation);
  15846. }
  15847. });
  15848. // delete this function to allow it only once
  15849. this.animate = null;
  15850. }
  15851. },
  15852. /**
  15853. * Extend the base translate method to handle bubble size
  15854. */
  15855. translate: function () {
  15856. var i,
  15857. data = this.data,
  15858. point,
  15859. radius,
  15860. radii = this.radii;
  15861. // Run the parent method
  15862. seriesTypes.scatter.prototype.translate.call(this);
  15863. // Set the shape type and arguments to be picked up in drawPoints
  15864. i = data.length;
  15865. while (i--) {
  15866. point = data[i];
  15867. radius = radii ? radii[i] : 0; // #1737
  15868. if (typeof radius === 'number' && radius >= this.minPxSize / 2) {
  15869. // Shape arguments
  15870. point.shapeType = 'circle';
  15871. point.shapeArgs = {
  15872. x: point.plotX,
  15873. y: point.plotY,
  15874. r: radius
  15875. };
  15876. // Alignment box for the data label
  15877. point.dlBox = {
  15878. x: point.plotX - radius,
  15879. y: point.plotY - radius,
  15880. width: 2 * radius,
  15881. height: 2 * radius
  15882. };
  15883. } else { // below zThreshold or z = null
  15884. point.shapeArgs = point.plotY = point.dlBox = UNDEFINED; // #1691
  15885. }
  15886. }
  15887. },
  15888. /**
  15889. * Get the series' symbol in the legend
  15890. *
  15891. * @param {Object} legend The legend object
  15892. * @param {Object} item The series (this) or point
  15893. */
  15894. drawLegendSymbol: function (legend, item) {
  15895. var radius = pInt(legend.itemStyle.fontSize) / 2;
  15896. item.legendSymbol = this.chart.renderer.circle(
  15897. radius,
  15898. legend.baseline - radius,
  15899. radius
  15900. ).attr({
  15901. zIndex: 3
  15902. }).add(item.legendGroup);
  15903. item.legendSymbol.isMarker = true;
  15904. },
  15905. drawPoints: seriesTypes.column.prototype.drawPoints,
  15906. alignDataLabel: seriesTypes.column.prototype.alignDataLabel,
  15907. buildKDTree: noop,
  15908. applyZones: noop
  15909. });
  15910. /**
  15911. * Add logic to pad each axis with the amount of pixels
  15912. * necessary to avoid the bubbles to overflow.
  15913. */
  15914. Axis.prototype.beforePadding = function () {
  15915. var axis = this,
  15916. axisLength = this.len,
  15917. chart = this.chart,
  15918. pxMin = 0,
  15919. pxMax = axisLength,
  15920. isXAxis = this.isXAxis,
  15921. dataKey = isXAxis ? 'xData' : 'yData',
  15922. min = this.min,
  15923. extremes = {},
  15924. smallestSize = math.min(chart.plotWidth, chart.plotHeight),
  15925. zMin = Number.MAX_VALUE,
  15926. zMax = -Number.MAX_VALUE,
  15927. range = this.max - min,
  15928. transA = axisLength / range,
  15929. activeSeries = [];
  15930. // Handle padding on the second pass, or on redraw
  15931. each(this.series, function (series) {
  15932. var seriesOptions = series.options,
  15933. zData;
  15934. if (series.bubblePadding && (series.visible || !chart.options.chart.ignoreHiddenSeries)) {
  15935. // Correction for #1673
  15936. axis.allowZoomOutside = true;
  15937. // Cache it
  15938. activeSeries.push(series);
  15939. if (isXAxis) { // because X axis is evaluated first
  15940. // For each series, translate the size extremes to pixel values
  15941. each(['minSize', 'maxSize'], function (prop) {
  15942. var length = seriesOptions[prop],
  15943. isPercent = /%$/.test(length);
  15944. length = pInt(length);
  15945. extremes[prop] = isPercent ?
  15946. smallestSize * length / 100 :
  15947. length;
  15948. });
  15949. series.minPxSize = extremes.minSize;
  15950. series.maxPxSize = extremes.maxSize;
  15951. // Find the min and max Z
  15952. zData = series.zData;
  15953. if (zData.length) { // #1735
  15954. zMin = pick(seriesOptions.zMin, math.min(
  15955. zMin,
  15956. math.max(
  15957. arrayMin(zData),
  15958. seriesOptions.displayNegative === false ? seriesOptions.zThreshold : -Number.MAX_VALUE
  15959. )
  15960. ));
  15961. zMax = pick(seriesOptions.zMax, math.max(zMax, arrayMax(zData)));
  15962. }
  15963. }
  15964. }
  15965. });
  15966. each(activeSeries, function (series) {
  15967. var data = series[dataKey],
  15968. i = data.length,
  15969. radius;
  15970. if (isXAxis) {
  15971. series.getRadii(zMin, zMax, series.minPxSize, series.maxPxSize);
  15972. }
  15973. if (range > 0) {
  15974. while (i--) {
  15975. if (typeof data[i] === 'number') {
  15976. radius = series.radii[i];
  15977. pxMin = Math.min(((data[i] - min) * transA) - radius, pxMin);
  15978. pxMax = Math.max(((data[i] - min) * transA) + radius, pxMax);
  15979. }
  15980. }
  15981. }
  15982. });
  15983. if (activeSeries.length && range > 0 && !this.isLog) {
  15984. pxMax -= axisLength;
  15985. transA *= (axisLength + pxMin - pxMax) / axisLength;
  15986. each([['min', 'userMin', pxMin], ['max', 'userMax', pxMax]], function (keys) {
  15987. if (pick(axis.options[keys[0]], axis[keys[1]]) === UNDEFINED) {
  15988. axis[keys[0]] += keys[2] / transA;
  15989. }
  15990. });
  15991. }
  15992. };
  15993. /* ****************************************************************************
  15994. * End Bubble series code *
  15995. *****************************************************************************/
  15996. // The mapbubble series type
  15997. if (seriesTypes.bubble) {
  15998. defaultPlotOptions.mapbubble = merge(defaultPlotOptions.bubble, {
  15999. animationLimit: 500,
  16000. tooltip: {
  16001. pointFormat: '{point.name}: {point.z}'
  16002. }
  16003. });
  16004. seriesTypes.mapbubble = extendClass(seriesTypes.bubble, {
  16005. pointClass: extendClass(Point, {
  16006. applyOptions: function (options, x) {
  16007. var point;
  16008. if (options && options.lat !== undefined && options.lon !== undefined) {
  16009. point = Point.prototype.applyOptions.call(this, options, x);
  16010. point = extend(point, this.series.chart.fromLatLonToPoint(point));
  16011. } else {
  16012. point = MapAreaPoint.prototype.applyOptions.call(this, options, x);
  16013. }
  16014. return point;
  16015. },
  16016. ttBelow: false
  16017. }),
  16018. xyFromShape: true,
  16019. type: 'mapbubble',
  16020. pointArrayMap: ['z'], // If one single value is passed, it is interpreted as z
  16021. /**
  16022. * Return the map area identified by the dataJoinBy option
  16023. */
  16024. getMapData: seriesTypes.map.prototype.getMapData,
  16025. getBox: seriesTypes.map.prototype.getBox,
  16026. setData: seriesTypes.map.prototype.setData
  16027. });
  16028. }
  16029. /**
  16030. * Test for point in polygon. Polygon defined as array of [x,y] points.
  16031. */
  16032. function pointInPolygon(point, polygon) {
  16033. var i, j, rel1, rel2, c = false,
  16034. x = point.x,
  16035. y = point.y;
  16036. for (i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
  16037. rel1 = polygon[i][1] > y;
  16038. rel2 = polygon[j][1] > y;
  16039. if (rel1 !== rel2 && (x < (polygon[j][0] - polygon[i][0]) * (y - polygon[i][1]) / (polygon[j][1] - polygon[i][1]) + polygon[i][0])) {
  16040. c = !c;
  16041. }
  16042. }
  16043. return c;
  16044. }
  16045. /**
  16046. * Get point from latLon using specified transform definition
  16047. */
  16048. Chart.prototype.transformFromLatLon = function (latLon, transform) {
  16049. if (window.proj4 === undefined) {
  16050. error(21);
  16051. return {
  16052. x: 0,
  16053. y: null
  16054. };
  16055. }
  16056. var projected = window.proj4(transform.crs, [latLon.lon, latLon.lat]),
  16057. cosAngle = transform.cosAngle || (transform.rotation && Math.cos(transform.rotation)),
  16058. sinAngle = transform.sinAngle || (transform.rotation && Math.sin(transform.rotation)),
  16059. rotated = transform.rotation ? [projected[0] * cosAngle + projected[1] * sinAngle, -projected[0] * sinAngle + projected[1] * cosAngle] : projected;
  16060. return {
  16061. x: ((rotated[0] - (transform.xoffset || 0)) * (transform.scale || 1) + (transform.xpan || 0)) * (transform.jsonres || 1) + (transform.jsonmarginX || 0),
  16062. y: (((transform.yoffset || 0) - rotated[1]) * (transform.scale || 1) + (transform.ypan || 0)) * (transform.jsonres || 1) - (transform.jsonmarginY || 0)
  16063. };
  16064. };
  16065. /**
  16066. * Get latLon from point using specified transform definition
  16067. */
  16068. Chart.prototype.transformToLatLon = function (point, transform) {
  16069. if (window.proj4 === undefined) {
  16070. error(21);
  16071. return;
  16072. }
  16073. var normalized = {
  16074. x: ((point.x - (transform.jsonmarginX || 0)) / (transform.jsonres || 1) - (transform.xpan || 0)) / (transform.scale || 1) + (transform.xoffset || 0),
  16075. y: ((-point.y - (transform.jsonmarginY || 0)) / (transform.jsonres || 1) + (transform.ypan || 0)) / (transform.scale || 1) + (transform.yoffset || 0)
  16076. },
  16077. cosAngle = transform.cosAngle || (transform.rotation && Math.cos(transform.rotation)),
  16078. sinAngle = transform.sinAngle || (transform.rotation && Math.sin(transform.rotation)),
  16079. // Note: Inverted sinAngle to reverse rotation direction
  16080. projected = window.proj4(transform.crs, 'WGS84', transform.rotation ? {
  16081. x: normalized.x * cosAngle + normalized.y * -sinAngle,
  16082. y: normalized.x * sinAngle + normalized.y * cosAngle
  16083. } : normalized);
  16084. return {lat: projected.y, lon: projected.x};
  16085. };
  16086. Chart.prototype.fromPointToLatLon = function (point) {
  16087. var transforms = this.mapTransforms,
  16088. transform;
  16089. if (!transforms) {
  16090. error(22);
  16091. return;
  16092. }
  16093. for (transform in transforms) {
  16094. if (transforms.hasOwnProperty(transform) && transforms[transform].hitZone && pointInPolygon({x: point.x, y: -point.y}, transforms[transform].hitZone.coordinates[0])) {
  16095. return this.transformToLatLon(point, transforms[transform]);
  16096. }
  16097. }
  16098. return this.transformToLatLon(point, transforms['default']);
  16099. };
  16100. Chart.prototype.fromLatLonToPoint = function (latLon) {
  16101. var transforms = this.mapTransforms,
  16102. transform,
  16103. coords;
  16104. if (!transforms) {
  16105. error(22);
  16106. return {
  16107. x: 0,
  16108. y: null
  16109. };
  16110. }
  16111. for (transform in transforms) {
  16112. if (transforms.hasOwnProperty(transform) && transforms[transform].hitZone) {
  16113. coords = this.transformFromLatLon(latLon, transforms[transform]);
  16114. if (pointInPolygon({x: coords.x, y: -coords.y}, transforms[transform].hitZone.coordinates[0])) {
  16115. return coords;
  16116. }
  16117. }
  16118. }
  16119. return this.transformFromLatLon(latLon, transforms['default']);
  16120. };
  16121. /**
  16122. * Convert a geojson object to map data of a given Highcharts type (map, mappoint or mapline).
  16123. */
  16124. Highcharts.geojson = function (geojson, hType, series) {
  16125. var mapData = [],
  16126. path = [],
  16127. polygonToPath = function (polygon) {
  16128. var i = 0,
  16129. len = polygon.length;
  16130. path.push('M');
  16131. for (; i < len; i++) {
  16132. if (i === 1) {
  16133. path.push('L');
  16134. }
  16135. path.push(polygon[i][0], -polygon[i][1]);
  16136. }
  16137. };
  16138. hType = hType || 'map';
  16139. each(geojson.features, function (feature) {
  16140. var geometry = feature.geometry,
  16141. type = geometry.type,
  16142. coordinates = geometry.coordinates,
  16143. properties = feature.properties,
  16144. point;
  16145. path = [];
  16146. if (hType === 'map' || hType === 'mapbubble') {
  16147. if (type === 'Polygon') {
  16148. each(coordinates, polygonToPath);
  16149. path.push('Z');
  16150. } else if (type === 'MultiPolygon') {
  16151. each(coordinates, function (items) {
  16152. each(items, polygonToPath);
  16153. });
  16154. path.push('Z');
  16155. }
  16156. if (path.length) {
  16157. point = { path: path };
  16158. }
  16159. } else if (hType === 'mapline') {
  16160. if (type === 'LineString') {
  16161. polygonToPath(coordinates);
  16162. } else if (type === 'MultiLineString') {
  16163. each(coordinates, polygonToPath);
  16164. }
  16165. if (path.length) {
  16166. point = { path: path };
  16167. }
  16168. } else if (hType === 'mappoint') {
  16169. if (type === 'Point') {
  16170. point = {
  16171. x: coordinates[0],
  16172. y: -coordinates[1]
  16173. };
  16174. }
  16175. }
  16176. if (point) {
  16177. mapData.push(extend(point, {
  16178. name: properties.name || properties.NAME,
  16179. properties: properties
  16180. }));
  16181. }
  16182. });
  16183. // Create a credits text that includes map source, to be picked up in Chart.showCredits
  16184. if (series && geojson.copyrightShort) {
  16185. series.chart.mapCredits = '<a href="http://www.highcharts.com">Highcharts</a> \u00A9 ' +
  16186. '<a href="' + geojson.copyrightUrl + '">' + geojson.copyrightShort + '</a>';
  16187. series.chart.mapCreditsFull = geojson.copyright;
  16188. }
  16189. return mapData;
  16190. };
  16191. /**
  16192. * Override showCredits to include map source by default
  16193. */
  16194. wrap(Chart.prototype, 'showCredits', function (proceed, credits) {
  16195. if (defaultOptions.credits.text === this.options.credits.text && this.mapCredits) { // default text and mapCredits is set
  16196. credits.text = this.mapCredits;
  16197. credits.href = null;
  16198. }
  16199. proceed.call(this, credits);
  16200. if (this.credits) {
  16201. this.credits.attr({
  16202. title: this.mapCreditsFull
  16203. });
  16204. }
  16205. });
  16206. // Add language
  16207. extend(defaultOptions.lang, {
  16208. zoomIn: 'Zoom in',
  16209. zoomOut: 'Zoom out'
  16210. });
  16211. // Set the default map navigation options
  16212. defaultOptions.mapNavigation = {
  16213. buttonOptions: {
  16214. alignTo: 'plotBox',
  16215. align: 'left',
  16216. verticalAlign: 'top',
  16217. x: 0,
  16218. width: 18,
  16219. height: 18,
  16220. style: {
  16221. fontSize: '15px',
  16222. fontWeight: 'bold',
  16223. textAlign: 'center'
  16224. },
  16225. theme: {
  16226. 'stroke-width': 1
  16227. }
  16228. },
  16229. buttons: {
  16230. zoomIn: {
  16231. onclick: function () {
  16232. this.mapZoom(0.5);
  16233. },
  16234. text: '+',
  16235. y: 0
  16236. },
  16237. zoomOut: {
  16238. onclick: function () {
  16239. this.mapZoom(2);
  16240. },
  16241. text: '-',
  16242. y: 28
  16243. }
  16244. }
  16245. // enabled: false,
  16246. // enableButtons: null, // inherit from enabled
  16247. // enableTouchZoom: null, // inherit from enabled
  16248. // enableDoubleClickZoom: null, // inherit from enabled
  16249. // enableDoubleClickZoomTo: false
  16250. // enableMouseWheelZoom: null, // inherit from enabled
  16251. };
  16252. /**
  16253. * Utility for reading SVG paths directly.
  16254. */
  16255. Highcharts.splitPath = function (path) {
  16256. var i;
  16257. // Move letters apart
  16258. path = path.replace(/([A-Za-z])/g, ' $1 ');
  16259. // Trim
  16260. path = path.replace(/^\s*/, "").replace(/\s*$/, "");
  16261. // Split on spaces and commas
  16262. path = path.split(/[ ,]+/);
  16263. // Parse numbers
  16264. for (i = 0; i < path.length; i++) {
  16265. if (!/[a-zA-Z]/.test(path[i])) {
  16266. path[i] = parseFloat(path[i]);
  16267. }
  16268. }
  16269. return path;
  16270. };
  16271. // A placeholder for map definitions
  16272. Highcharts.maps = {};
  16273. // Create symbols for the zoom buttons
  16274. function selectiveRoundedRect(x, y, w, h, rTopLeft, rTopRight, rBottomRight, rBottomLeft) {
  16275. return ['M', x + rTopLeft, y,
  16276. // top side
  16277. 'L', x + w - rTopRight, y,
  16278. // top right corner
  16279. 'C', x + w - rTopRight / 2, y, x + w, y + rTopRight / 2, x + w, y + rTopRight,
  16280. // right side
  16281. 'L', x + w, y + h - rBottomRight,
  16282. // bottom right corner
  16283. 'C', x + w, y + h - rBottomRight / 2, x + w - rBottomRight / 2, y + h, x + w - rBottomRight, y + h,
  16284. // bottom side
  16285. 'L', x + rBottomLeft, y + h,
  16286. // bottom left corner
  16287. 'C', x + rBottomLeft / 2, y + h, x, y + h - rBottomLeft / 2, x, y + h - rBottomLeft,
  16288. // left side
  16289. 'L', x, y + rTopLeft,
  16290. // top left corner
  16291. 'C', x, y + rTopLeft / 2, x + rTopLeft / 2, y, x + rTopLeft, y,
  16292. 'Z'
  16293. ];
  16294. }
  16295. SVGRenderer.prototype.symbols.topbutton = function (x, y, w, h, attr) {
  16296. return selectiveRoundedRect(x - 1, y - 1, w, h, attr.r, attr.r, 0, 0);
  16297. };
  16298. SVGRenderer.prototype.symbols.bottombutton = function (x, y, w, h, attr) {
  16299. return selectiveRoundedRect(x - 1, y - 1, w, h, 0, 0, attr.r, attr.r);
  16300. };
  16301. // The symbol callbacks are generated on the SVGRenderer object in all browsers. Even
  16302. // VML browsers need this in order to generate shapes in export. Now share
  16303. // them with the VMLRenderer.
  16304. if (Renderer === VMLRenderer) {
  16305. each(['topbutton', 'bottombutton'], function (shape) {
  16306. VMLRenderer.prototype.symbols[shape] = SVGRenderer.prototype.symbols[shape];
  16307. });
  16308. }
  16309. /**
  16310. * A wrapper for Chart with all the default values for a Map
  16311. */
  16312. Highcharts.Map = function (options, callback) {
  16313. var hiddenAxis = {
  16314. endOnTick: false,
  16315. gridLineWidth: 0,
  16316. lineWidth: 0,
  16317. minPadding: 0,
  16318. maxPadding: 0,
  16319. startOnTick: false,
  16320. title: null,
  16321. tickPositions: []
  16322. },
  16323. seriesOptions;
  16324. /* For visual testing
  16325. hiddenAxis.gridLineWidth = 1;
  16326. hiddenAxis.gridZIndex = 10;
  16327. hiddenAxis.tickPositions = undefined;
  16328. // */
  16329. // Don't merge the data
  16330. seriesOptions = options.series;
  16331. options.series = null;
  16332. options = merge({
  16333. chart: {
  16334. panning: 'xy',
  16335. type: 'map'
  16336. },
  16337. xAxis: hiddenAxis,
  16338. yAxis: merge(hiddenAxis, { reversed: true })
  16339. },
  16340. options, // user's options
  16341. { // forced options
  16342. chart: {
  16343. inverted: false,
  16344. alignTicks: false
  16345. }
  16346. });
  16347. options.series = seriesOptions;
  16348. return new Chart(options, callback);
  16349. };
  16350. /**
  16351. * Extend the default options with map options
  16352. */
  16353. defaultOptions.plotOptions.heatmap = merge(defaultOptions.plotOptions.scatter, {
  16354. animation: false,
  16355. borderWidth: 0,
  16356. nullColor: '#F8F8F8',
  16357. dataLabels: {
  16358. formatter: function () { // #2945
  16359. return this.point.value;
  16360. },
  16361. inside: true,
  16362. verticalAlign: 'middle',
  16363. crop: false,
  16364. overflow: false,
  16365. padding: 0 // #3837
  16366. },
  16367. marker: null,
  16368. pointRange: null, // dynamically set to colsize by default
  16369. tooltip: {
  16370. pointFormat: '{point.x}, {point.y}: {point.value}<br/>'
  16371. },
  16372. states: {
  16373. normal: {
  16374. animation: true
  16375. },
  16376. hover: {
  16377. halo: false, // #3406, halo is not required on heatmaps
  16378. brightness: 0.2
  16379. }
  16380. }
  16381. });
  16382. // The Heatmap series type
  16383. seriesTypes.heatmap = extendClass(seriesTypes.scatter, merge(colorSeriesMixin, {
  16384. type: 'heatmap',
  16385. pointArrayMap: ['y', 'value'],
  16386. hasPointSpecificOptions: true,
  16387. pointClass: extendClass(Point, colorPointMixin),
  16388. supportsDrilldown: true,
  16389. getExtremesFromAll: true,
  16390. directTouch: true,
  16391. /**
  16392. * Override the init method to add point ranges on both axes.
  16393. */
  16394. init: function () {
  16395. var options;
  16396. seriesTypes.scatter.prototype.init.apply(this, arguments);
  16397. options = this.options;
  16398. this.pointRange = options.pointRange = pick(options.pointRange, options.colsize || 1); // #3758, prevent resetting in setData
  16399. this.yAxis.axisPointRange = options.rowsize || 1; // general point range
  16400. },
  16401. translate: function () {
  16402. var series = this,
  16403. options = series.options,
  16404. xAxis = series.xAxis,
  16405. yAxis = series.yAxis,
  16406. between = function (x, a, b) {
  16407. return Math.min(Math.max(a, x), b);
  16408. };
  16409. series.generatePoints();
  16410. each(series.points, function (point) {
  16411. var xPad = (options.colsize || 1) / 2,
  16412. yPad = (options.rowsize || 1) / 2,
  16413. x1 = between(Math.round(xAxis.len - xAxis.translate(point.x - xPad, 0, 1, 0, 1)), 0, xAxis.len),
  16414. x2 = between(Math.round(xAxis.len - xAxis.translate(point.x + xPad, 0, 1, 0, 1)), 0, xAxis.len),
  16415. y1 = between(Math.round(yAxis.translate(point.y - yPad, 0, 1, 0, 1)), 0, yAxis.len),
  16416. y2 = between(Math.round(yAxis.translate(point.y + yPad, 0, 1, 0, 1)), 0, yAxis.len);
  16417. // Set plotX and plotY for use in K-D-Tree and more
  16418. point.plotX = point.clientX = (x1 + x2) / 2;
  16419. point.plotY = (y1 + y2) / 2;
  16420. point.shapeType = 'rect';
  16421. point.shapeArgs = {
  16422. x: Math.min(x1, x2),
  16423. y: Math.min(y1, y2),
  16424. width: Math.abs(x2 - x1),
  16425. height: Math.abs(y2 - y1)
  16426. };
  16427. });
  16428. series.translateColors();
  16429. // Make sure colors are updated on colorAxis update (#2893)
  16430. if (this.chart.hasRendered) {
  16431. each(series.points, function (point) {
  16432. point.shapeArgs.fill = point.options.color || point.color; // #3311
  16433. });
  16434. }
  16435. },
  16436. drawPoints: seriesTypes.column.prototype.drawPoints,
  16437. animate: noop,
  16438. getBox: noop,
  16439. drawLegendSymbol: LegendSymbolMixin.drawRectangle,
  16440. getExtremes: function () {
  16441. // Get the extremes from the value data
  16442. Series.prototype.getExtremes.call(this, this.valueData);
  16443. this.valueMin = this.dataMin;
  16444. this.valueMax = this.dataMax;
  16445. // Get the extremes from the y data
  16446. Series.prototype.getExtremes.call(this);
  16447. }
  16448. }));
  16449. /**
  16450. * TrackerMixin for points and graphs
  16451. */
  16452. var TrackerMixin = Highcharts.TrackerMixin = {
  16453. drawTrackerPoint: function () {
  16454. var series = this,
  16455. chart = series.chart,
  16456. pointer = chart.pointer,
  16457. cursor = series.options.cursor,
  16458. css = cursor && { cursor: cursor },
  16459. onMouseOver = function (e) {
  16460. var target = e.target,
  16461. point;
  16462. while (target && !point) {
  16463. point = target.point;
  16464. target = target.parentNode;
  16465. }
  16466. if (point !== UNDEFINED && point !== chart.hoverPoint) { // undefined on graph in scatterchart
  16467. point.onMouseOver(e);
  16468. }
  16469. };
  16470. // Add reference to the point
  16471. each(series.points, function (point) {
  16472. if (point.graphic) {
  16473. point.graphic.element.point = point;
  16474. }
  16475. if (point.dataLabel) {
  16476. point.dataLabel.element.point = point;
  16477. }
  16478. });
  16479. // Add the event listeners, we need to do this only once
  16480. if (!series._hasTracking) {
  16481. each(series.trackerGroups, function (key) {
  16482. if (series[key]) { // we don't always have dataLabelsGroup
  16483. series[key]
  16484. .addClass(PREFIX + 'tracker')
  16485. .on('mouseover', onMouseOver)
  16486. .on('mouseout', function (e) { pointer.onTrackerMouseOut(e); })
  16487. .css(css);
  16488. if (hasTouch) {
  16489. series[key].on('touchstart', onMouseOver);
  16490. }
  16491. }
  16492. });
  16493. series._hasTracking = true;
  16494. }
  16495. },
  16496. /**
  16497. * Draw the tracker object that sits above all data labels and markers to
  16498. * track mouse events on the graph or points. For the line type charts
  16499. * the tracker uses the same graphPath, but with a greater stroke width
  16500. * for better control.
  16501. */
  16502. drawTrackerGraph: function () {
  16503. var series = this,
  16504. options = series.options,
  16505. trackByArea = options.trackByArea,
  16506. trackerPath = [].concat(trackByArea ? series.areaPath : series.graphPath),
  16507. trackerPathLength = trackerPath.length,
  16508. chart = series.chart,
  16509. pointer = chart.pointer,
  16510. renderer = chart.renderer,
  16511. snap = chart.options.tooltip.snap,
  16512. tracker = series.tracker,
  16513. cursor = options.cursor,
  16514. css = cursor && { cursor: cursor },
  16515. singlePoints = series.singlePoints,
  16516. singlePoint,
  16517. i,
  16518. onMouseOver = function () {
  16519. if (chart.hoverSeries !== series) {
  16520. series.onMouseOver();
  16521. }
  16522. },
  16523. /*
  16524. * Empirical lowest possible opacities for TRACKER_FILL for an element to stay invisible but clickable
  16525. * IE6: 0.002
  16526. * IE7: 0.002
  16527. * IE8: 0.002
  16528. * IE9: 0.00000000001 (unlimited)
  16529. * IE10: 0.0001 (exporting only)
  16530. * FF: 0.00000000001 (unlimited)
  16531. * Chrome: 0.000001
  16532. * Safari: 0.000001
  16533. * Opera: 0.00000000001 (unlimited)
  16534. */
  16535. TRACKER_FILL = 'rgba(192,192,192,' + (hasSVG ? 0.0001 : 0.002) + ')';
  16536. // Extend end points. A better way would be to use round linecaps,
  16537. // but those are not clickable in VML.
  16538. if (trackerPathLength && !trackByArea) {
  16539. i = trackerPathLength + 1;
  16540. while (i--) {
  16541. if (trackerPath[i] === M) { // extend left side
  16542. trackerPath.splice(i + 1, 0, trackerPath[i + 1] - snap, trackerPath[i + 2], L);
  16543. }
  16544. if ((i && trackerPath[i] === M) || i === trackerPathLength) { // extend right side
  16545. trackerPath.splice(i, 0, L, trackerPath[i - 2] + snap, trackerPath[i - 1]);
  16546. }
  16547. }
  16548. }
  16549. // handle single points
  16550. for (i = 0; i < singlePoints.length; i++) {
  16551. singlePoint = singlePoints[i];
  16552. trackerPath.push(M, singlePoint.plotX - snap, singlePoint.plotY,
  16553. L, singlePoint.plotX + snap, singlePoint.plotY);
  16554. }
  16555. // draw the tracker
  16556. if (tracker) {
  16557. tracker.attr({ d: trackerPath });
  16558. } else { // create
  16559. series.tracker = renderer.path(trackerPath)
  16560. .attr({
  16561. 'stroke-linejoin': 'round', // #1225
  16562. visibility: series.visible ? VISIBLE : HIDDEN,
  16563. stroke: TRACKER_FILL,
  16564. fill: trackByArea ? TRACKER_FILL : NONE,
  16565. 'stroke-width' : options.lineWidth + (trackByArea ? 0 : 2 * snap),
  16566. zIndex: 2
  16567. })
  16568. .add(series.group);
  16569. // The tracker is added to the series group, which is clipped, but is covered
  16570. // by the marker group. So the marker group also needs to capture events.
  16571. each([series.tracker, series.markerGroup], function (tracker) {
  16572. tracker.addClass(PREFIX + 'tracker')
  16573. .on('mouseover', onMouseOver)
  16574. .on('mouseout', function (e) { pointer.onTrackerMouseOut(e); })
  16575. .css(css);
  16576. if (hasTouch) {
  16577. tracker.on('touchstart', onMouseOver);
  16578. }
  16579. });
  16580. }
  16581. }
  16582. };
  16583. /* End TrackerMixin */
  16584. /**
  16585. * Add tracking event listener to the series group, so the point graphics
  16586. * themselves act as trackers
  16587. */
  16588. if (seriesTypes.column) {
  16589. ColumnSeries.prototype.drawTracker = TrackerMixin.drawTrackerPoint;
  16590. }
  16591. if (seriesTypes.pie) {
  16592. seriesTypes.pie.prototype.drawTracker = TrackerMixin.drawTrackerPoint;
  16593. }
  16594. if (seriesTypes.scatter) {
  16595. ScatterSeries.prototype.drawTracker = TrackerMixin.drawTrackerPoint;
  16596. }
  16597. /*
  16598. * Extend Legend for item events
  16599. */
  16600. extend(Legend.prototype, {
  16601. setItemEvents: function (item, legendItem, useHTML, itemStyle, itemHiddenStyle) {
  16602. var legend = this;
  16603. // Set the events on the item group, or in case of useHTML, the item itself (#1249)
  16604. (useHTML ? legendItem : item.legendGroup).on('mouseover', function () {
  16605. item.setState(HOVER_STATE);
  16606. legendItem.css(legend.options.itemHoverStyle);
  16607. })
  16608. .on('mouseout', function () {
  16609. legendItem.css(item.visible ? itemStyle : itemHiddenStyle);
  16610. item.setState();
  16611. })
  16612. .on('click', function (event) {
  16613. var strLegendItemClick = 'legendItemClick',
  16614. fnLegendItemClick = function () {
  16615. if (item.setVisible) {
  16616. item.setVisible();
  16617. }
  16618. };
  16619. // Pass over the click/touch event. #4.
  16620. event = {
  16621. browserEvent: event
  16622. };
  16623. // click the name or symbol
  16624. if (item.firePointEvent) { // point
  16625. item.firePointEvent(strLegendItemClick, event, fnLegendItemClick);
  16626. } else {
  16627. fireEvent(item, strLegendItemClick, event, fnLegendItemClick);
  16628. }
  16629. });
  16630. },
  16631. createCheckboxForItem: function (item) {
  16632. var legend = this;
  16633. item.checkbox = createElement('input', {
  16634. type: 'checkbox',
  16635. checked: item.selected,
  16636. defaultChecked: item.selected // required by IE7
  16637. }, legend.options.itemCheckboxStyle, legend.chart.container);
  16638. addEvent(item.checkbox, 'click', function (event) {
  16639. var target = event.target;
  16640. fireEvent(item.series || item, 'checkboxClick', { // #3712
  16641. checked: target.checked,
  16642. item: item
  16643. },
  16644. function () {
  16645. item.select();
  16646. }
  16647. );
  16648. });
  16649. }
  16650. });
  16651. /*
  16652. * Add pointer cursor to legend itemstyle in defaultOptions
  16653. */
  16654. defaultOptions.legend.itemStyle.cursor = 'pointer';
  16655. /*
  16656. * Extend the Chart object with interaction
  16657. */
  16658. extend(Chart.prototype, {
  16659. /**
  16660. * Display the zoom button
  16661. */
  16662. showResetZoom: function () {
  16663. var chart = this,
  16664. lang = defaultOptions.lang,
  16665. btnOptions = chart.options.chart.resetZoomButton,
  16666. theme = btnOptions.theme,
  16667. states = theme.states,
  16668. alignTo = btnOptions.relativeTo === 'chart' ? null : 'plotBox';
  16669. this.resetZoomButton = chart.renderer.button(lang.resetZoom, null, null, function () { chart.zoomOut(); }, theme, states && states.hover)
  16670. .attr({
  16671. align: btnOptions.position.align,
  16672. title: lang.resetZoomTitle
  16673. })
  16674. .add()
  16675. .align(btnOptions.position, false, alignTo);
  16676. },
  16677. /**
  16678. * Zoom out to 1:1
  16679. */
  16680. zoomOut: function () {
  16681. var chart = this;
  16682. fireEvent(chart, 'selection', { resetSelection: true }, function () {
  16683. chart.zoom();
  16684. });
  16685. },
  16686. /**
  16687. * Zoom into a given portion of the chart given by axis coordinates
  16688. * @param {Object} event
  16689. */
  16690. zoom: function (event) {
  16691. var chart = this,
  16692. hasZoomed,
  16693. pointer = chart.pointer,
  16694. displayButton = false,
  16695. resetZoomButton;
  16696. // If zoom is called with no arguments, reset the axes
  16697. if (!event || event.resetSelection) {
  16698. each(chart.axes, function (axis) {
  16699. hasZoomed = axis.zoom();
  16700. });
  16701. } else { // else, zoom in on all axes
  16702. each(event.xAxis.concat(event.yAxis), function (axisData) {
  16703. var axis = axisData.axis,
  16704. isXAxis = axis.isXAxis;
  16705. // don't zoom more than minRange
  16706. if (pointer[isXAxis ? 'zoomX' : 'zoomY'] || pointer[isXAxis ? 'pinchX' : 'pinchY']) {
  16707. hasZoomed = axis.zoom(axisData.min, axisData.max);
  16708. if (axis.displayBtn) {
  16709. displayButton = true;
  16710. }
  16711. }
  16712. });
  16713. }
  16714. // Show or hide the Reset zoom button
  16715. resetZoomButton = chart.resetZoomButton;
  16716. if (displayButton && !resetZoomButton) {
  16717. chart.showResetZoom();
  16718. } else if (!displayButton && isObject(resetZoomButton)) {
  16719. chart.resetZoomButton = resetZoomButton.destroy();
  16720. }
  16721. // Redraw
  16722. if (hasZoomed) {
  16723. chart.redraw(
  16724. pick(chart.options.chart.animation, event && event.animation, chart.pointCount < 100) // animation
  16725. );
  16726. }
  16727. },
  16728. /**
  16729. * Pan the chart by dragging the mouse across the pane. This function is called
  16730. * on mouse move, and the distance to pan is computed from chartX compared to
  16731. * the first chartX position in the dragging operation.
  16732. */
  16733. pan: function (e, panning) {
  16734. var chart = this,
  16735. hoverPoints = chart.hoverPoints,
  16736. doRedraw;
  16737. // remove active points for shared tooltip
  16738. if (hoverPoints) {
  16739. each(hoverPoints, function (point) {
  16740. point.setState();
  16741. });
  16742. }
  16743. each(panning === 'xy' ? [1, 0] : [1], function (isX) { // xy is used in maps
  16744. var mousePos = e[isX ? 'chartX' : 'chartY'],
  16745. axis = chart[isX ? 'xAxis' : 'yAxis'][0],
  16746. startPos = chart[isX ? 'mouseDownX' : 'mouseDownY'],
  16747. halfPointRange = (axis.pointRange || 0) / 2,
  16748. extremes = axis.getExtremes(),
  16749. newMin = axis.toValue(startPos - mousePos, true) + halfPointRange,
  16750. newMax = axis.toValue(startPos + chart[isX ? 'plotWidth' : 'plotHeight'] - mousePos, true) - halfPointRange,
  16751. goingLeft = startPos > mousePos; // #3613
  16752. if (axis.series.length &&
  16753. (goingLeft || newMin > mathMin(extremes.dataMin, extremes.min)) &&
  16754. (!goingLeft || newMax < mathMax(extremes.dataMax, extremes.max))) {
  16755. axis.setExtremes(newMin, newMax, false, false, { trigger: 'pan' });
  16756. doRedraw = true;
  16757. }
  16758. chart[isX ? 'mouseDownX' : 'mouseDownY'] = mousePos; // set new reference for next run
  16759. });
  16760. if (doRedraw) {
  16761. chart.redraw(false);
  16762. }
  16763. css(chart.container, { cursor: 'move' });
  16764. }
  16765. });
  16766. /*
  16767. * Extend the Point object with interaction
  16768. */
  16769. extend(Point.prototype, {
  16770. /**
  16771. * Toggle the selection status of a point
  16772. * @param {Boolean} selected Whether to select or unselect the point.
  16773. * @param {Boolean} accumulate Whether to add to the previous selection. By default,
  16774. * this happens if the control key (Cmd on Mac) was pressed during clicking.
  16775. */
  16776. select: function (selected, accumulate) {
  16777. var point = this,
  16778. series = point.series,
  16779. chart = series.chart;
  16780. selected = pick(selected, !point.selected);
  16781. // fire the event with the defalut handler
  16782. point.firePointEvent(selected ? 'select' : 'unselect', { accumulate: accumulate }, function () {
  16783. point.selected = point.options.selected = selected;
  16784. series.options.data[inArray(point, series.data)] = point.options;
  16785. point.setState(selected && SELECT_STATE);
  16786. // unselect all other points unless Ctrl or Cmd + click
  16787. if (!accumulate) {
  16788. each(chart.getSelectedPoints(), function (loopPoint) {
  16789. if (loopPoint.selected && loopPoint !== point) {
  16790. loopPoint.selected = loopPoint.options.selected = false;
  16791. series.options.data[inArray(loopPoint, series.data)] = loopPoint.options;
  16792. loopPoint.setState(NORMAL_STATE);
  16793. loopPoint.firePointEvent('unselect');
  16794. }
  16795. });
  16796. }
  16797. });
  16798. },
  16799. /**
  16800. * Runs on mouse over the point
  16801. *
  16802. * @param {Object} e The event arguments
  16803. * @param {Boolean} byProximity Falsy for kd points that are closest to the mouse, or to
  16804. * actually hovered points. True for other points in shared tooltip.
  16805. */
  16806. onMouseOver: function (e, byProximity) {
  16807. var point = this,
  16808. series = point.series,
  16809. chart = series.chart,
  16810. tooltip = chart.tooltip,
  16811. hoverPoint = chart.hoverPoint;
  16812. if (chart.hoverSeries !== series) {
  16813. series.onMouseOver();
  16814. }
  16815. // set normal state to previous series
  16816. if (hoverPoint && hoverPoint !== point) {
  16817. hoverPoint.onMouseOut();
  16818. }
  16819. if (point.series) { // It may have been destroyed, #4130
  16820. // trigger the event
  16821. point.firePointEvent('mouseOver');
  16822. // update the tooltip
  16823. if (tooltip && (!tooltip.shared || series.noSharedTooltip)) {
  16824. tooltip.refresh(point, e);
  16825. }
  16826. // hover this
  16827. point.setState(HOVER_STATE);
  16828. if (!byProximity) {
  16829. chart.hoverPoint = point;
  16830. }
  16831. }
  16832. },
  16833. /**
  16834. * Runs on mouse out from the point
  16835. */
  16836. onMouseOut: function () {
  16837. var chart = this.series.chart,
  16838. hoverPoints = chart.hoverPoints;
  16839. this.firePointEvent('mouseOut');
  16840. if (!hoverPoints || inArray(this, hoverPoints) === -1) { // #887, #2240
  16841. this.setState();
  16842. chart.hoverPoint = null;
  16843. }
  16844. },
  16845. /**
  16846. * Import events from the series' and point's options. Only do it on
  16847. * demand, to save processing time on hovering.
  16848. */
  16849. importEvents: function () {
  16850. if (!this.hasImportedEvents) {
  16851. var point = this,
  16852. options = merge(point.series.options.point, point.options),
  16853. events = options.events,
  16854. eventType;
  16855. point.events = events;
  16856. for (eventType in events) {
  16857. addEvent(point, eventType, events[eventType]);
  16858. }
  16859. this.hasImportedEvents = true;
  16860. }
  16861. },
  16862. /**
  16863. * Set the point's state
  16864. * @param {String} state
  16865. */
  16866. setState: function (state, move) {
  16867. var point = this,
  16868. plotX = mathFloor(point.plotX), // #4586
  16869. plotY = point.plotY,
  16870. series = point.series,
  16871. stateOptions = series.options.states,
  16872. markerOptions = defaultPlotOptions[series.type].marker && series.options.marker,
  16873. normalDisabled = markerOptions && !markerOptions.enabled,
  16874. markerStateOptions = markerOptions && markerOptions.states[state],
  16875. stateDisabled = markerStateOptions && markerStateOptions.enabled === false,
  16876. stateMarkerGraphic = series.stateMarkerGraphic,
  16877. pointMarker = point.marker || {},
  16878. chart = series.chart,
  16879. radius,
  16880. halo = series.halo,
  16881. haloOptions,
  16882. newSymbol,
  16883. pointAttr;
  16884. state = state || NORMAL_STATE; // empty string
  16885. pointAttr = point.pointAttr[state] || series.pointAttr[state];
  16886. if (
  16887. // already has this state
  16888. (state === point.state && !move) ||
  16889. // selected points don't respond to hover
  16890. (point.selected && state !== SELECT_STATE) ||
  16891. // series' state options is disabled
  16892. (stateOptions[state] && stateOptions[state].enabled === false) ||
  16893. // general point marker's state options is disabled
  16894. (state && (stateDisabled || (normalDisabled && markerStateOptions.enabled === false))) ||
  16895. // individual point marker's state options is disabled
  16896. (state && pointMarker.states && pointMarker.states[state] && pointMarker.states[state].enabled === false) // #1610
  16897. ) {
  16898. return;
  16899. }
  16900. // apply hover styles to the existing point
  16901. if (point.graphic) {
  16902. radius = markerOptions && point.graphic.symbolName && pointAttr.r;
  16903. point.graphic.attr(merge(
  16904. pointAttr,
  16905. radius ? { // new symbol attributes (#507, #612)
  16906. x: plotX - radius,
  16907. y: plotY - radius,
  16908. width: 2 * radius,
  16909. height: 2 * radius
  16910. } : {}
  16911. ));
  16912. // Zooming in from a range with no markers to a range with markers
  16913. if (stateMarkerGraphic) {
  16914. stateMarkerGraphic.hide();
  16915. }
  16916. } else {
  16917. // if a graphic is not applied to each point in the normal state, create a shared
  16918. // graphic for the hover state
  16919. if (state && markerStateOptions) {
  16920. radius = markerStateOptions.radius;
  16921. newSymbol = pointMarker.symbol || series.symbol;
  16922. // If the point has another symbol than the previous one, throw away the
  16923. // state marker graphic and force a new one (#1459)
  16924. if (stateMarkerGraphic && stateMarkerGraphic.currentSymbol !== newSymbol) {
  16925. stateMarkerGraphic = stateMarkerGraphic.destroy();
  16926. }
  16927. // Add a new state marker graphic
  16928. if (!stateMarkerGraphic) {
  16929. if (newSymbol) {
  16930. series.stateMarkerGraphic = stateMarkerGraphic = chart.renderer.symbol(
  16931. newSymbol,
  16932. plotX - radius,
  16933. plotY - radius,
  16934. 2 * radius,
  16935. 2 * radius
  16936. )
  16937. .attr(pointAttr)
  16938. .add(series.markerGroup);
  16939. stateMarkerGraphic.currentSymbol = newSymbol;
  16940. }
  16941. // Move the existing graphic
  16942. } else {
  16943. stateMarkerGraphic[move ? 'animate' : 'attr']({ // #1054
  16944. x: plotX - radius,
  16945. y: plotY - radius
  16946. });
  16947. }
  16948. }
  16949. if (stateMarkerGraphic) {
  16950. stateMarkerGraphic[state && chart.isInsidePlot(plotX, plotY, chart.inverted) ? 'show' : 'hide'](); // #2450
  16951. stateMarkerGraphic.element.point = point; // #4310
  16952. }
  16953. }
  16954. // Show me your halo
  16955. haloOptions = stateOptions[state] && stateOptions[state].halo;
  16956. if (haloOptions && haloOptions.size) {
  16957. if (!halo) {
  16958. series.halo = halo = chart.renderer.path()
  16959. .add(chart.seriesGroup);
  16960. }
  16961. halo.attr(extend({
  16962. fill: Color(point.color || series.color).setOpacity(haloOptions.opacity).get()
  16963. }, haloOptions.attributes))[move ? 'animate' : 'attr']({
  16964. d: point.haloPath(haloOptions.size)
  16965. });
  16966. } else if (halo) {
  16967. halo.attr({ d: [] });
  16968. }
  16969. point.state = state;
  16970. },
  16971. haloPath: function (size) {
  16972. var series = this.series,
  16973. chart = series.chart,
  16974. plotBox = series.getPlotBox(),
  16975. inverted = chart.inverted;
  16976. return chart.renderer.symbols.circle(
  16977. plotBox.translateX + (inverted ? series.yAxis.len - this.plotY : this.plotX) - size,
  16978. plotBox.translateY + (inverted ? series.xAxis.len - this.plotX : this.plotY) - size,
  16979. size * 2,
  16980. size * 2
  16981. );
  16982. }
  16983. });
  16984. /*
  16985. * Extend the Series object with interaction
  16986. */
  16987. extend(Series.prototype, {
  16988. /**
  16989. * Series mouse over handler
  16990. */
  16991. onMouseOver: function () {
  16992. var series = this,
  16993. chart = series.chart,
  16994. hoverSeries = chart.hoverSeries;
  16995. // set normal state to previous series
  16996. if (hoverSeries && hoverSeries !== series) {
  16997. hoverSeries.onMouseOut();
  16998. }
  16999. // trigger the event, but to save processing time,
  17000. // only if defined
  17001. if (series.options.events.mouseOver) {
  17002. fireEvent(series, 'mouseOver');
  17003. }
  17004. // hover this
  17005. series.setState(HOVER_STATE);
  17006. chart.hoverSeries = series;
  17007. },
  17008. /**
  17009. * Series mouse out handler
  17010. */
  17011. onMouseOut: function () {
  17012. // trigger the event only if listeners exist
  17013. var series = this,
  17014. options = series.options,
  17015. chart = series.chart,
  17016. tooltip = chart.tooltip,
  17017. hoverPoint = chart.hoverPoint;
  17018. chart.hoverSeries = null; // #182, set to null before the mouseOut event fires
  17019. // trigger mouse out on the point, which must be in this series
  17020. if (hoverPoint) {
  17021. hoverPoint.onMouseOut();
  17022. }
  17023. // fire the mouse out event
  17024. if (series && options.events.mouseOut) {
  17025. fireEvent(series, 'mouseOut');
  17026. }
  17027. // hide the tooltip
  17028. if (tooltip && !options.stickyTracking && (!tooltip.shared || series.noSharedTooltip)) {
  17029. tooltip.hide();
  17030. }
  17031. // set normal state
  17032. series.setState();
  17033. },
  17034. /**
  17035. * Set the state of the graph
  17036. */
  17037. setState: function (state) {
  17038. var series = this,
  17039. options = series.options,
  17040. graph = series.graph,
  17041. stateOptions = options.states,
  17042. lineWidth = options.lineWidth,
  17043. attribs,
  17044. i = 0;
  17045. state = state || NORMAL_STATE;
  17046. if (series.state !== state) {
  17047. series.state = state;
  17048. if (stateOptions[state] && stateOptions[state].enabled === false) {
  17049. return;
  17050. }
  17051. if (state) {
  17052. lineWidth = stateOptions[state].lineWidth || lineWidth + (stateOptions[state].lineWidthPlus || 0); // #4035
  17053. }
  17054. if (graph && !graph.dashstyle) { // hover is turned off for dashed lines in VML
  17055. attribs = {
  17056. 'stroke-width': lineWidth
  17057. };
  17058. // use attr because animate will cause any other animation on the graph to stop
  17059. graph.attr(attribs);
  17060. while (series['zoneGraph' + i]) {
  17061. series['zoneGraph' + i].attr(attribs);
  17062. i = i + 1;
  17063. }
  17064. }
  17065. }
  17066. },
  17067. /**
  17068. * Set the visibility of the graph
  17069. *
  17070. * @param vis {Boolean} True to show the series, false to hide. If UNDEFINED,
  17071. * the visibility is toggled.
  17072. */
  17073. setVisible: function (vis, redraw) {
  17074. var series = this,
  17075. chart = series.chart,
  17076. legendItem = series.legendItem,
  17077. showOrHide,
  17078. ignoreHiddenSeries = chart.options.chart.ignoreHiddenSeries,
  17079. oldVisibility = series.visible;
  17080. // if called without an argument, toggle visibility
  17081. series.visible = vis = series.userOptions.visible = vis === UNDEFINED ? !oldVisibility : vis;
  17082. showOrHide = vis ? 'show' : 'hide';
  17083. // show or hide elements
  17084. each(['group', 'dataLabelsGroup', 'markerGroup', 'tracker'], function (key) {
  17085. if (series[key]) {
  17086. series[key][showOrHide]();
  17087. }
  17088. });
  17089. // hide tooltip (#1361)
  17090. if (chart.hoverSeries === series || (chart.hoverPoint && chart.hoverPoint.series) === series) {
  17091. series.onMouseOut();
  17092. }
  17093. if (legendItem) {
  17094. chart.legend.colorizeItem(series, vis);
  17095. }
  17096. // rescale or adapt to resized chart
  17097. series.isDirty = true;
  17098. // in a stack, all other series are affected
  17099. if (series.options.stacking) {
  17100. each(chart.series, function (otherSeries) {
  17101. if (otherSeries.options.stacking && otherSeries.visible) {
  17102. otherSeries.isDirty = true;
  17103. }
  17104. });
  17105. }
  17106. // show or hide linked series
  17107. each(series.linkedSeries, function (otherSeries) {
  17108. otherSeries.setVisible(vis, false);
  17109. });
  17110. if (ignoreHiddenSeries) {
  17111. chart.isDirtyBox = true;
  17112. }
  17113. if (redraw !== false) {
  17114. chart.redraw();
  17115. }
  17116. fireEvent(series, showOrHide);
  17117. },
  17118. /**
  17119. * Show the graph
  17120. */
  17121. show: function () {
  17122. this.setVisible(true);
  17123. },
  17124. /**
  17125. * Hide the graph
  17126. */
  17127. hide: function () {
  17128. this.setVisible(false);
  17129. },
  17130. /**
  17131. * Set the selected state of the graph
  17132. *
  17133. * @param selected {Boolean} True to select the series, false to unselect. If
  17134. * UNDEFINED, the selection state is toggled.
  17135. */
  17136. select: function (selected) {
  17137. var series = this;
  17138. // if called without an argument, toggle
  17139. series.selected = selected = (selected === UNDEFINED) ? !series.selected : selected;
  17140. if (series.checkbox) {
  17141. series.checkbox.checked = selected;
  17142. }
  17143. fireEvent(series, selected ? 'select' : 'unselect');
  17144. },
  17145. drawTracker: TrackerMixin.drawTrackerGraph
  17146. });
  17147. // global variables
  17148. extend(Highcharts, {
  17149. // Constructors
  17150. Color: Color,
  17151. Point: Point,
  17152. Tick: Tick,
  17153. Renderer: Renderer,
  17154. SVGElement: SVGElement,
  17155. SVGRenderer: SVGRenderer,
  17156. // Various
  17157. arrayMin: arrayMin,
  17158. arrayMax: arrayMax,
  17159. charts: charts,
  17160. dateFormat: dateFormat,
  17161. error: error,
  17162. format: format,
  17163. pathAnim: pathAnim,
  17164. getOptions: getOptions,
  17165. hasBidiBug: hasBidiBug,
  17166. isTouchDevice: isTouchDevice,
  17167. setOptions: setOptions,
  17168. addEvent: addEvent,
  17169. removeEvent: removeEvent,
  17170. createElement: createElement,
  17171. discardElement: discardElement,
  17172. css: css,
  17173. each: each,
  17174. map: map,
  17175. merge: merge,
  17176. splat: splat,
  17177. extendClass: extendClass,
  17178. pInt: pInt,
  17179. svg: hasSVG,
  17180. canvas: useCanVG,
  17181. vml: !hasSVG && !useCanVG,
  17182. product: PRODUCT,
  17183. version: VERSION
  17184. });
  17185. }());