d3.js 330 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550
  1. !function() {
  2. var d3 = {
  3. version: "3.5.8"
  4. };
  5. var d3_arraySlice = [].slice, d3_array = function(list) {
  6. return d3_arraySlice.call(list);
  7. };
  8. var d3_document = this.document;
  9. function d3_documentElement(node) {
  10. return node && (node.ownerDocument || node.document || node).documentElement;
  11. }
  12. function d3_window(node) {
  13. return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
  14. }
  15. if (d3_document) {
  16. try {
  17. d3_array(d3_document.documentElement.childNodes)[0].nodeType;
  18. } catch (e) {
  19. d3_array = function(list) {
  20. var i = list.length, array = new Array(i);
  21. while (i--) array[i] = list[i];
  22. return array;
  23. };
  24. }
  25. }
  26. if (!Date.now) Date.now = function() {
  27. return +new Date();
  28. };
  29. if (d3_document) {
  30. try {
  31. d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
  32. } catch (error) {
  33. var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
  34. d3_element_prototype.setAttribute = function(name, value) {
  35. d3_element_setAttribute.call(this, name, value + "");
  36. };
  37. d3_element_prototype.setAttributeNS = function(space, local, value) {
  38. d3_element_setAttributeNS.call(this, space, local, value + "");
  39. };
  40. d3_style_prototype.setProperty = function(name, value, priority) {
  41. d3_style_setProperty.call(this, name, value + "", priority);
  42. };
  43. }
  44. }
  45. d3.ascending = d3_ascending;
  46. function d3_ascending(a, b) {
  47. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  48. }
  49. d3.descending = function(a, b) {
  50. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  51. };
  52. d3.min = function(array, f) {
  53. var i = -1, n = array.length, a, b;
  54. if (arguments.length === 1) {
  55. while (++i < n) if ((b = array[i]) != null && b >= b) {
  56. a = b;
  57. break;
  58. }
  59. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  60. } else {
  61. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  62. a = b;
  63. break;
  64. }
  65. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  66. }
  67. return a;
  68. };
  69. d3.max = function(array, f) {
  70. var i = -1, n = array.length, a, b;
  71. if (arguments.length === 1) {
  72. while (++i < n) if ((b = array[i]) != null && b >= b) {
  73. a = b;
  74. break;
  75. }
  76. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  77. } else {
  78. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  79. a = b;
  80. break;
  81. }
  82. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  83. }
  84. return a;
  85. };
  86. d3.extent = function(array, f) {
  87. var i = -1, n = array.length, a, b, c;
  88. if (arguments.length === 1) {
  89. while (++i < n) if ((b = array[i]) != null && b >= b) {
  90. a = c = b;
  91. break;
  92. }
  93. while (++i < n) if ((b = array[i]) != null) {
  94. if (a > b) a = b;
  95. if (c < b) c = b;
  96. }
  97. } else {
  98. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  99. a = c = b;
  100. break;
  101. }
  102. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  103. if (a > b) a = b;
  104. if (c < b) c = b;
  105. }
  106. }
  107. return [ a, c ];
  108. };
  109. function d3_number(x) {
  110. return x === null ? NaN : +x;
  111. }
  112. function d3_numeric(x) {
  113. return !isNaN(x);
  114. }
  115. d3.sum = function(array, f) {
  116. var s = 0, n = array.length, a, i = -1;
  117. if (arguments.length === 1) {
  118. while (++i < n) if (d3_numeric(a = +array[i])) s += a;
  119. } else {
  120. while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
  121. }
  122. return s;
  123. };
  124. d3.mean = function(array, f) {
  125. var s = 0, n = array.length, a, i = -1, j = n;
  126. if (arguments.length === 1) {
  127. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
  128. } else {
  129. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
  130. }
  131. if (j) return s / j;
  132. };
  133. d3.quantile = function(values, p) {
  134. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  135. return e ? v + e * (values[h] - v) : v;
  136. };
  137. d3.median = function(array, f) {
  138. var numbers = [], n = array.length, a, i = -1;
  139. if (arguments.length === 1) {
  140. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
  141. } else {
  142. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
  143. }
  144. if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
  145. };
  146. d3.variance = function(array, f) {
  147. var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
  148. if (arguments.length === 1) {
  149. while (++i < n) {
  150. if (d3_numeric(a = d3_number(array[i]))) {
  151. d = a - m;
  152. m += d / ++j;
  153. s += d * (a - m);
  154. }
  155. }
  156. } else {
  157. while (++i < n) {
  158. if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
  159. d = a - m;
  160. m += d / ++j;
  161. s += d * (a - m);
  162. }
  163. }
  164. }
  165. if (j > 1) return s / (j - 1);
  166. };
  167. d3.deviation = function() {
  168. var v = d3.variance.apply(this, arguments);
  169. return v ? Math.sqrt(v) : v;
  170. };
  171. function d3_bisector(compare) {
  172. return {
  173. left: function(a, x, lo, hi) {
  174. if (arguments.length < 3) lo = 0;
  175. if (arguments.length < 4) hi = a.length;
  176. while (lo < hi) {
  177. var mid = lo + hi >>> 1;
  178. if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
  179. }
  180. return lo;
  181. },
  182. right: function(a, x, lo, hi) {
  183. if (arguments.length < 3) lo = 0;
  184. if (arguments.length < 4) hi = a.length;
  185. while (lo < hi) {
  186. var mid = lo + hi >>> 1;
  187. if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
  188. }
  189. return lo;
  190. }
  191. };
  192. }
  193. var d3_bisect = d3_bisector(d3_ascending);
  194. d3.bisectLeft = d3_bisect.left;
  195. d3.bisect = d3.bisectRight = d3_bisect.right;
  196. d3.bisector = function(f) {
  197. return d3_bisector(f.length === 1 ? function(d, x) {
  198. return d3_ascending(f(d), x);
  199. } : f);
  200. };
  201. d3.shuffle = function(array, i0, i1) {
  202. if ((m = arguments.length) < 3) {
  203. i1 = array.length;
  204. if (m < 2) i0 = 0;
  205. }
  206. var m = i1 - i0, t, i;
  207. while (m) {
  208. i = Math.random() * m-- | 0;
  209. t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
  210. }
  211. return array;
  212. };
  213. d3.permute = function(array, indexes) {
  214. var i = indexes.length, permutes = new Array(i);
  215. while (i--) permutes[i] = array[indexes[i]];
  216. return permutes;
  217. };
  218. d3.pairs = function(array) {
  219. var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
  220. while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
  221. return pairs;
  222. };
  223. d3.zip = function() {
  224. if (!(n = arguments.length)) return [];
  225. for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
  226. for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
  227. zip[j] = arguments[j][i];
  228. }
  229. }
  230. return zips;
  231. };
  232. function d3_zipLength(d) {
  233. return d.length;
  234. }
  235. d3.transpose = function(matrix) {
  236. return d3.zip.apply(d3, matrix);
  237. };
  238. d3.keys = function(map) {
  239. var keys = [];
  240. for (var key in map) keys.push(key);
  241. return keys;
  242. };
  243. d3.values = function(map) {
  244. var values = [];
  245. for (var key in map) values.push(map[key]);
  246. return values;
  247. };
  248. d3.entries = function(map) {
  249. var entries = [];
  250. for (var key in map) entries.push({
  251. key: key,
  252. value: map[key]
  253. });
  254. return entries;
  255. };
  256. d3.merge = function(arrays) {
  257. var n = arrays.length, m, i = -1, j = 0, merged, array;
  258. while (++i < n) j += arrays[i].length;
  259. merged = new Array(j);
  260. while (--n >= 0) {
  261. array = arrays[n];
  262. m = array.length;
  263. while (--m >= 0) {
  264. merged[--j] = array[m];
  265. }
  266. }
  267. return merged;
  268. };
  269. var abs = Math.abs;
  270. d3.range = function(start, stop, step) {
  271. if (arguments.length < 3) {
  272. step = 1;
  273. if (arguments.length < 2) {
  274. stop = start;
  275. start = 0;
  276. }
  277. }
  278. if ((stop - start) / step === Infinity) throw new Error("infinite range");
  279. var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
  280. start *= k, stop *= k, step *= k;
  281. if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
  282. return range;
  283. };
  284. function d3_range_integerScale(x) {
  285. var k = 1;
  286. while (x * k % 1) k *= 10;
  287. return k;
  288. }
  289. function d3_class(ctor, properties) {
  290. for (var key in properties) {
  291. Object.defineProperty(ctor.prototype, key, {
  292. value: properties[key],
  293. enumerable: false
  294. });
  295. }
  296. }
  297. d3.map = function(object, f) {
  298. var map = new d3_Map();
  299. if (object instanceof d3_Map) {
  300. object.forEach(function(key, value) {
  301. map.set(key, value);
  302. });
  303. } else if (Array.isArray(object)) {
  304. var i = -1, n = object.length, o;
  305. if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
  306. } else {
  307. for (var key in object) map.set(key, object[key]);
  308. }
  309. return map;
  310. };
  311. function d3_Map() {
  312. this._ = Object.create(null);
  313. }
  314. var d3_map_proto = "__proto__", d3_map_zero = "\x00";
  315. d3_class(d3_Map, {
  316. has: d3_map_has,
  317. get: function(key) {
  318. return this._[d3_map_escape(key)];
  319. },
  320. set: function(key, value) {
  321. return this._[d3_map_escape(key)] = value;
  322. },
  323. remove: d3_map_remove,
  324. keys: d3_map_keys,
  325. values: function() {
  326. var values = [];
  327. for (var key in this._) values.push(this._[key]);
  328. return values;
  329. },
  330. entries: function() {
  331. var entries = [];
  332. for (var key in this._) entries.push({
  333. key: d3_map_unescape(key),
  334. value: this._[key]
  335. });
  336. return entries;
  337. },
  338. size: d3_map_size,
  339. empty: d3_map_empty,
  340. forEach: function(f) {
  341. for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
  342. }
  343. });
  344. function d3_map_escape(key) {
  345. return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
  346. }
  347. function d3_map_unescape(key) {
  348. return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
  349. }
  350. function d3_map_has(key) {
  351. return d3_map_escape(key) in this._;
  352. }
  353. function d3_map_remove(key) {
  354. return (key = d3_map_escape(key)) in this._ && delete this._[key];
  355. }
  356. function d3_map_keys() {
  357. var keys = [];
  358. for (var key in this._) keys.push(d3_map_unescape(key));
  359. return keys;
  360. }
  361. function d3_map_size() {
  362. var size = 0;
  363. for (var key in this._) ++size;
  364. return size;
  365. }
  366. function d3_map_empty() {
  367. for (var key in this._) return false;
  368. return true;
  369. }
  370. d3.nest = function() {
  371. var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
  372. function map(mapType, array, depth) {
  373. if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
  374. var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
  375. while (++i < n) {
  376. if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
  377. values.push(object);
  378. } else {
  379. valuesByKey.set(keyValue, [ object ]);
  380. }
  381. }
  382. if (mapType) {
  383. object = mapType();
  384. setter = function(keyValue, values) {
  385. object.set(keyValue, map(mapType, values, depth));
  386. };
  387. } else {
  388. object = {};
  389. setter = function(keyValue, values) {
  390. object[keyValue] = map(mapType, values, depth);
  391. };
  392. }
  393. valuesByKey.forEach(setter);
  394. return object;
  395. }
  396. function entries(map, depth) {
  397. if (depth >= keys.length) return map;
  398. var array = [], sortKey = sortKeys[depth++];
  399. map.forEach(function(key, keyMap) {
  400. array.push({
  401. key: key,
  402. values: entries(keyMap, depth)
  403. });
  404. });
  405. return sortKey ? array.sort(function(a, b) {
  406. return sortKey(a.key, b.key);
  407. }) : array;
  408. }
  409. nest.map = function(array, mapType) {
  410. return map(mapType, array, 0);
  411. };
  412. nest.entries = function(array) {
  413. return entries(map(d3.map, array, 0), 0);
  414. };
  415. nest.key = function(d) {
  416. keys.push(d);
  417. return nest;
  418. };
  419. nest.sortKeys = function(order) {
  420. sortKeys[keys.length - 1] = order;
  421. return nest;
  422. };
  423. nest.sortValues = function(order) {
  424. sortValues = order;
  425. return nest;
  426. };
  427. nest.rollup = function(f) {
  428. rollup = f;
  429. return nest;
  430. };
  431. return nest;
  432. };
  433. d3.set = function(array) {
  434. var set = new d3_Set();
  435. if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
  436. return set;
  437. };
  438. function d3_Set() {
  439. this._ = Object.create(null);
  440. }
  441. d3_class(d3_Set, {
  442. has: d3_map_has,
  443. add: function(key) {
  444. this._[d3_map_escape(key += "")] = true;
  445. return key;
  446. },
  447. remove: d3_map_remove,
  448. values: d3_map_keys,
  449. size: d3_map_size,
  450. empty: d3_map_empty,
  451. forEach: function(f) {
  452. for (var key in this._) f.call(this, d3_map_unescape(key));
  453. }
  454. });
  455. d3.behavior = {};
  456. function d3_identity(d) {
  457. return d;
  458. }
  459. d3.rebind = function(target, source) {
  460. var i = 1, n = arguments.length, method;
  461. while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
  462. return target;
  463. };
  464. function d3_rebind(target, source, method) {
  465. return function() {
  466. var value = method.apply(source, arguments);
  467. return value === source ? target : value;
  468. };
  469. }
  470. function d3_vendorSymbol(object, name) {
  471. if (name in object) return name;
  472. name = name.charAt(0).toUpperCase() + name.slice(1);
  473. for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
  474. var prefixName = d3_vendorPrefixes[i] + name;
  475. if (prefixName in object) return prefixName;
  476. }
  477. }
  478. var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
  479. function d3_noop() {}
  480. d3.dispatch = function() {
  481. var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
  482. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  483. return dispatch;
  484. };
  485. function d3_dispatch() {}
  486. d3_dispatch.prototype.on = function(type, listener) {
  487. var i = type.indexOf("."), name = "";
  488. if (i >= 0) {
  489. name = type.slice(i + 1);
  490. type = type.slice(0, i);
  491. }
  492. if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
  493. if (arguments.length === 2) {
  494. if (listener == null) for (type in this) {
  495. if (this.hasOwnProperty(type)) this[type].on(name, null);
  496. }
  497. return this;
  498. }
  499. };
  500. function d3_dispatch_event(dispatch) {
  501. var listeners = [], listenerByName = new d3_Map();
  502. function event() {
  503. var z = listeners, i = -1, n = z.length, l;
  504. while (++i < n) if (l = z[i].on) l.apply(this, arguments);
  505. return dispatch;
  506. }
  507. event.on = function(name, listener) {
  508. var l = listenerByName.get(name), i;
  509. if (arguments.length < 2) return l && l.on;
  510. if (l) {
  511. l.on = null;
  512. listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
  513. listenerByName.remove(name);
  514. }
  515. if (listener) listeners.push(listenerByName.set(name, {
  516. on: listener
  517. }));
  518. return dispatch;
  519. };
  520. return event;
  521. }
  522. d3.event = null;
  523. function d3_eventPreventDefault() {
  524. d3.event.preventDefault();
  525. }
  526. function d3_eventSource() {
  527. var e = d3.event, s;
  528. while (s = e.sourceEvent) e = s;
  529. return e;
  530. }
  531. function d3_eventDispatch(target) {
  532. var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
  533. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  534. dispatch.of = function(thiz, argumentz) {
  535. return function(e1) {
  536. try {
  537. var e0 = e1.sourceEvent = d3.event;
  538. e1.target = target;
  539. d3.event = e1;
  540. dispatch[e1.type].apply(thiz, argumentz);
  541. } finally {
  542. d3.event = e0;
  543. }
  544. };
  545. };
  546. return dispatch;
  547. }
  548. d3.requote = function(s) {
  549. return s.replace(d3_requote_re, "\\$&");
  550. };
  551. var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  552. var d3_subclass = {}.__proto__ ? function(object, prototype) {
  553. object.__proto__ = prototype;
  554. } : function(object, prototype) {
  555. for (var property in prototype) object[property] = prototype[property];
  556. };
  557. function d3_selection(groups) {
  558. d3_subclass(groups, d3_selectionPrototype);
  559. return groups;
  560. }
  561. var d3_select = function(s, n) {
  562. return n.querySelector(s);
  563. }, d3_selectAll = function(s, n) {
  564. return n.querySelectorAll(s);
  565. }, d3_selectMatches = function(n, s) {
  566. var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
  567. d3_selectMatches = function(n, s) {
  568. return d3_selectMatcher.call(n, s);
  569. };
  570. return d3_selectMatches(n, s);
  571. };
  572. if (typeof Sizzle === "function") {
  573. d3_select = function(s, n) {
  574. return Sizzle(s, n)[0] || null;
  575. };
  576. d3_selectAll = Sizzle;
  577. d3_selectMatches = Sizzle.matchesSelector;
  578. }
  579. d3.selection = function() {
  580. return d3.select(d3_document.documentElement);
  581. };
  582. var d3_selectionPrototype = d3.selection.prototype = [];
  583. d3_selectionPrototype.select = function(selector) {
  584. var subgroups = [], subgroup, subnode, group, node;
  585. selector = d3_selection_selector(selector);
  586. for (var j = -1, m = this.length; ++j < m; ) {
  587. subgroups.push(subgroup = []);
  588. subgroup.parentNode = (group = this[j]).parentNode;
  589. for (var i = -1, n = group.length; ++i < n; ) {
  590. if (node = group[i]) {
  591. subgroup.push(subnode = selector.call(node, node.__data__, i, j));
  592. if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
  593. } else {
  594. subgroup.push(null);
  595. }
  596. }
  597. }
  598. return d3_selection(subgroups);
  599. };
  600. function d3_selection_selector(selector) {
  601. return typeof selector === "function" ? selector : function() {
  602. return d3_select(selector, this);
  603. };
  604. }
  605. d3_selectionPrototype.selectAll = function(selector) {
  606. var subgroups = [], subgroup, node;
  607. selector = d3_selection_selectorAll(selector);
  608. for (var j = -1, m = this.length; ++j < m; ) {
  609. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  610. if (node = group[i]) {
  611. subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
  612. subgroup.parentNode = node;
  613. }
  614. }
  615. }
  616. return d3_selection(subgroups);
  617. };
  618. function d3_selection_selectorAll(selector) {
  619. return typeof selector === "function" ? selector : function() {
  620. return d3_selectAll(selector, this);
  621. };
  622. }
  623. var d3_nsPrefix = {
  624. svg: "http://www.w3.org/2000/svg",
  625. xhtml: "http://www.w3.org/1999/xhtml",
  626. xlink: "http://www.w3.org/1999/xlink",
  627. xml: "http://www.w3.org/XML/1998/namespace",
  628. xmlns: "http://www.w3.org/2000/xmlns/"
  629. };
  630. d3.ns = {
  631. prefix: d3_nsPrefix,
  632. qualify: function(name) {
  633. var i = name.indexOf(":"), prefix = name;
  634. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  635. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  636. space: d3_nsPrefix[prefix],
  637. local: name
  638. } : name;
  639. }
  640. };
  641. d3_selectionPrototype.attr = function(name, value) {
  642. if (arguments.length < 2) {
  643. if (typeof name === "string") {
  644. var node = this.node();
  645. name = d3.ns.qualify(name);
  646. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  647. }
  648. for (value in name) this.each(d3_selection_attr(value, name[value]));
  649. return this;
  650. }
  651. return this.each(d3_selection_attr(name, value));
  652. };
  653. function d3_selection_attr(name, value) {
  654. name = d3.ns.qualify(name);
  655. function attrNull() {
  656. this.removeAttribute(name);
  657. }
  658. function attrNullNS() {
  659. this.removeAttributeNS(name.space, name.local);
  660. }
  661. function attrConstant() {
  662. this.setAttribute(name, value);
  663. }
  664. function attrConstantNS() {
  665. this.setAttributeNS(name.space, name.local, value);
  666. }
  667. function attrFunction() {
  668. var x = value.apply(this, arguments);
  669. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  670. }
  671. function attrFunctionNS() {
  672. var x = value.apply(this, arguments);
  673. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  674. }
  675. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  676. }
  677. function d3_collapse(s) {
  678. return s.trim().replace(/\s+/g, " ");
  679. }
  680. d3_selectionPrototype.classed = function(name, value) {
  681. if (arguments.length < 2) {
  682. if (typeof name === "string") {
  683. var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
  684. if (value = node.classList) {
  685. while (++i < n) if (!value.contains(name[i])) return false;
  686. } else {
  687. value = node.getAttribute("class");
  688. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  689. }
  690. return true;
  691. }
  692. for (value in name) this.each(d3_selection_classed(value, name[value]));
  693. return this;
  694. }
  695. return this.each(d3_selection_classed(name, value));
  696. };
  697. function d3_selection_classedRe(name) {
  698. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  699. }
  700. function d3_selection_classes(name) {
  701. return (name + "").trim().split(/^|\s+/);
  702. }
  703. function d3_selection_classed(name, value) {
  704. name = d3_selection_classes(name).map(d3_selection_classedName);
  705. var n = name.length;
  706. function classedConstant() {
  707. var i = -1;
  708. while (++i < n) name[i](this, value);
  709. }
  710. function classedFunction() {
  711. var i = -1, x = value.apply(this, arguments);
  712. while (++i < n) name[i](this, x);
  713. }
  714. return typeof value === "function" ? classedFunction : classedConstant;
  715. }
  716. function d3_selection_classedName(name) {
  717. var re = d3_selection_classedRe(name);
  718. return function(node, value) {
  719. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  720. var c = node.getAttribute("class") || "";
  721. if (value) {
  722. re.lastIndex = 0;
  723. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  724. } else {
  725. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  726. }
  727. };
  728. }
  729. d3_selectionPrototype.style = function(name, value, priority) {
  730. var n = arguments.length;
  731. if (n < 3) {
  732. if (typeof name !== "string") {
  733. if (n < 2) value = "";
  734. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  735. return this;
  736. }
  737. if (n < 2) {
  738. var node = this.node();
  739. return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
  740. }
  741. priority = "";
  742. }
  743. return this.each(d3_selection_style(name, value, priority));
  744. };
  745. function d3_selection_style(name, value, priority) {
  746. function styleNull() {
  747. this.style.removeProperty(name);
  748. }
  749. function styleConstant() {
  750. this.style.setProperty(name, value, priority);
  751. }
  752. function styleFunction() {
  753. var x = value.apply(this, arguments);
  754. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  755. }
  756. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  757. }
  758. d3_selectionPrototype.property = function(name, value) {
  759. if (arguments.length < 2) {
  760. if (typeof name === "string") return this.node()[name];
  761. for (value in name) this.each(d3_selection_property(value, name[value]));
  762. return this;
  763. }
  764. return this.each(d3_selection_property(name, value));
  765. };
  766. function d3_selection_property(name, value) {
  767. function propertyNull() {
  768. delete this[name];
  769. }
  770. function propertyConstant() {
  771. this[name] = value;
  772. }
  773. function propertyFunction() {
  774. var x = value.apply(this, arguments);
  775. if (x == null) delete this[name]; else this[name] = x;
  776. }
  777. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  778. }
  779. d3_selectionPrototype.text = function(value) {
  780. return arguments.length ? this.each(typeof value === "function" ? function() {
  781. var v = value.apply(this, arguments);
  782. this.textContent = v == null ? "" : v;
  783. } : value == null ? function() {
  784. this.textContent = "";
  785. } : function() {
  786. this.textContent = value;
  787. }) : this.node().textContent;
  788. };
  789. d3_selectionPrototype.html = function(value) {
  790. return arguments.length ? this.each(typeof value === "function" ? function() {
  791. var v = value.apply(this, arguments);
  792. this.innerHTML = v == null ? "" : v;
  793. } : value == null ? function() {
  794. this.innerHTML = "";
  795. } : function() {
  796. this.innerHTML = value;
  797. }) : this.node().innerHTML;
  798. };
  799. d3_selectionPrototype.append = function(name) {
  800. name = d3_selection_creator(name);
  801. return this.select(function() {
  802. return this.appendChild(name.apply(this, arguments));
  803. });
  804. };
  805. function d3_selection_creator(name) {
  806. function create() {
  807. var document = this.ownerDocument, namespace = this.namespaceURI;
  808. return namespace ? document.createElementNS(namespace, name) : document.createElement(name);
  809. }
  810. function createNS() {
  811. return this.ownerDocument.createElementNS(name.space, name.local);
  812. }
  813. return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
  814. }
  815. d3_selectionPrototype.insert = function(name, before) {
  816. name = d3_selection_creator(name);
  817. before = d3_selection_selector(before);
  818. return this.select(function() {
  819. return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
  820. });
  821. };
  822. d3_selectionPrototype.remove = function() {
  823. return this.each(d3_selectionRemove);
  824. };
  825. function d3_selectionRemove() {
  826. var parent = this.parentNode;
  827. if (parent) parent.removeChild(this);
  828. }
  829. d3_selectionPrototype.data = function(value, key) {
  830. var i = -1, n = this.length, group, node;
  831. if (!arguments.length) {
  832. value = new Array(n = (group = this[0]).length);
  833. while (++i < n) {
  834. if (node = group[i]) {
  835. value[i] = node.__data__;
  836. }
  837. }
  838. return value;
  839. }
  840. function bind(group, groupData) {
  841. var i, n = group.length, m = groupData.length, n0 = Math.min(n, m), updateNodes = new Array(m), enterNodes = new Array(m), exitNodes = new Array(n), node, nodeData;
  842. if (key) {
  843. var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
  844. for (i = -1; ++i < n; ) {
  845. if (node = group[i]) {
  846. if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
  847. exitNodes[i] = node;
  848. } else {
  849. nodeByKeyValue.set(keyValue, node);
  850. }
  851. keyValues[i] = keyValue;
  852. }
  853. }
  854. for (i = -1; ++i < m; ) {
  855. if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
  856. enterNodes[i] = d3_selection_dataNode(nodeData);
  857. } else if (node !== true) {
  858. updateNodes[i] = node;
  859. node.__data__ = nodeData;
  860. }
  861. nodeByKeyValue.set(keyValue, true);
  862. }
  863. for (i = -1; ++i < n; ) {
  864. if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {
  865. exitNodes[i] = group[i];
  866. }
  867. }
  868. } else {
  869. for (i = -1; ++i < n0; ) {
  870. node = group[i];
  871. nodeData = groupData[i];
  872. if (node) {
  873. node.__data__ = nodeData;
  874. updateNodes[i] = node;
  875. } else {
  876. enterNodes[i] = d3_selection_dataNode(nodeData);
  877. }
  878. }
  879. for (;i < m; ++i) {
  880. enterNodes[i] = d3_selection_dataNode(groupData[i]);
  881. }
  882. for (;i < n; ++i) {
  883. exitNodes[i] = group[i];
  884. }
  885. }
  886. enterNodes.update = updateNodes;
  887. enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
  888. enter.push(enterNodes);
  889. update.push(updateNodes);
  890. exit.push(exitNodes);
  891. }
  892. var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
  893. if (typeof value === "function") {
  894. while (++i < n) {
  895. bind(group = this[i], value.call(group, group.parentNode.__data__, i));
  896. }
  897. } else {
  898. while (++i < n) {
  899. bind(group = this[i], value);
  900. }
  901. }
  902. update.enter = function() {
  903. return enter;
  904. };
  905. update.exit = function() {
  906. return exit;
  907. };
  908. return update;
  909. };
  910. function d3_selection_dataNode(data) {
  911. return {
  912. __data__: data
  913. };
  914. }
  915. d3_selectionPrototype.datum = function(value) {
  916. return arguments.length ? this.property("__data__", value) : this.property("__data__");
  917. };
  918. d3_selectionPrototype.filter = function(filter) {
  919. var subgroups = [], subgroup, group, node;
  920. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  921. for (var j = 0, m = this.length; j < m; j++) {
  922. subgroups.push(subgroup = []);
  923. subgroup.parentNode = (group = this[j]).parentNode;
  924. for (var i = 0, n = group.length; i < n; i++) {
  925. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  926. subgroup.push(node);
  927. }
  928. }
  929. }
  930. return d3_selection(subgroups);
  931. };
  932. function d3_selection_filter(selector) {
  933. return function() {
  934. return d3_selectMatches(this, selector);
  935. };
  936. }
  937. d3_selectionPrototype.order = function() {
  938. for (var j = -1, m = this.length; ++j < m; ) {
  939. for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
  940. if (node = group[i]) {
  941. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  942. next = node;
  943. }
  944. }
  945. }
  946. return this;
  947. };
  948. d3_selectionPrototype.sort = function(comparator) {
  949. comparator = d3_selection_sortComparator.apply(this, arguments);
  950. for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
  951. return this.order();
  952. };
  953. function d3_selection_sortComparator(comparator) {
  954. if (!arguments.length) comparator = d3_ascending;
  955. return function(a, b) {
  956. return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
  957. };
  958. }
  959. d3_selectionPrototype.each = function(callback) {
  960. return d3_selection_each(this, function(node, i, j) {
  961. callback.call(node, node.__data__, i, j);
  962. });
  963. };
  964. function d3_selection_each(groups, callback) {
  965. for (var j = 0, m = groups.length; j < m; j++) {
  966. for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
  967. if (node = group[i]) callback(node, i, j);
  968. }
  969. }
  970. return groups;
  971. }
  972. d3_selectionPrototype.call = function(callback) {
  973. var args = d3_array(arguments);
  974. callback.apply(args[0] = this, args);
  975. return this;
  976. };
  977. d3_selectionPrototype.empty = function() {
  978. return !this.node();
  979. };
  980. d3_selectionPrototype.node = function() {
  981. for (var j = 0, m = this.length; j < m; j++) {
  982. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  983. var node = group[i];
  984. if (node) return node;
  985. }
  986. }
  987. return null;
  988. };
  989. d3_selectionPrototype.size = function() {
  990. var n = 0;
  991. d3_selection_each(this, function() {
  992. ++n;
  993. });
  994. return n;
  995. };
  996. function d3_selection_enter(selection) {
  997. d3_subclass(selection, d3_selection_enterPrototype);
  998. return selection;
  999. }
  1000. var d3_selection_enterPrototype = [];
  1001. d3.selection.enter = d3_selection_enter;
  1002. d3.selection.enter.prototype = d3_selection_enterPrototype;
  1003. d3_selection_enterPrototype.append = d3_selectionPrototype.append;
  1004. d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
  1005. d3_selection_enterPrototype.node = d3_selectionPrototype.node;
  1006. d3_selection_enterPrototype.call = d3_selectionPrototype.call;
  1007. d3_selection_enterPrototype.size = d3_selectionPrototype.size;
  1008. d3_selection_enterPrototype.select = function(selector) {
  1009. var subgroups = [], subgroup, subnode, upgroup, group, node;
  1010. for (var j = -1, m = this.length; ++j < m; ) {
  1011. upgroup = (group = this[j]).update;
  1012. subgroups.push(subgroup = []);
  1013. subgroup.parentNode = group.parentNode;
  1014. for (var i = -1, n = group.length; ++i < n; ) {
  1015. if (node = group[i]) {
  1016. subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
  1017. subnode.__data__ = node.__data__;
  1018. } else {
  1019. subgroup.push(null);
  1020. }
  1021. }
  1022. }
  1023. return d3_selection(subgroups);
  1024. };
  1025. d3_selection_enterPrototype.insert = function(name, before) {
  1026. if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
  1027. return d3_selectionPrototype.insert.call(this, name, before);
  1028. };
  1029. function d3_selection_enterInsertBefore(enter) {
  1030. var i0, j0;
  1031. return function(d, i, j) {
  1032. var group = enter[j].update, n = group.length, node;
  1033. if (j != j0) j0 = j, i0 = 0;
  1034. if (i >= i0) i0 = i + 1;
  1035. while (!(node = group[i0]) && ++i0 < n) ;
  1036. return node;
  1037. };
  1038. }
  1039. d3.select = function(node) {
  1040. var group;
  1041. if (typeof node === "string") {
  1042. group = [ d3_select(node, d3_document) ];
  1043. group.parentNode = d3_document.documentElement;
  1044. } else {
  1045. group = [ node ];
  1046. group.parentNode = d3_documentElement(node);
  1047. }
  1048. return d3_selection([ group ]);
  1049. };
  1050. d3.selectAll = function(nodes) {
  1051. var group;
  1052. if (typeof nodes === "string") {
  1053. group = d3_array(d3_selectAll(nodes, d3_document));
  1054. group.parentNode = d3_document.documentElement;
  1055. } else {
  1056. group = d3_array(nodes);
  1057. group.parentNode = null;
  1058. }
  1059. return d3_selection([ group ]);
  1060. };
  1061. d3_selectionPrototype.on = function(type, listener, capture) {
  1062. var n = arguments.length;
  1063. if (n < 3) {
  1064. if (typeof type !== "string") {
  1065. if (n < 2) listener = false;
  1066. for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
  1067. return this;
  1068. }
  1069. if (n < 2) return (n = this.node()["__on" + type]) && n._;
  1070. capture = false;
  1071. }
  1072. return this.each(d3_selection_on(type, listener, capture));
  1073. };
  1074. function d3_selection_on(type, listener, capture) {
  1075. var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
  1076. if (i > 0) type = type.slice(0, i);
  1077. var filter = d3_selection_onFilters.get(type);
  1078. if (filter) type = filter, wrap = d3_selection_onFilter;
  1079. function onRemove() {
  1080. var l = this[name];
  1081. if (l) {
  1082. this.removeEventListener(type, l, l.$);
  1083. delete this[name];
  1084. }
  1085. }
  1086. function onAdd() {
  1087. var l = wrap(listener, d3_array(arguments));
  1088. onRemove.call(this);
  1089. this.addEventListener(type, this[name] = l, l.$ = capture);
  1090. l._ = listener;
  1091. }
  1092. function removeAll() {
  1093. var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
  1094. for (var name in this) {
  1095. if (match = name.match(re)) {
  1096. var l = this[name];
  1097. this.removeEventListener(match[1], l, l.$);
  1098. delete this[name];
  1099. }
  1100. }
  1101. }
  1102. return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
  1103. }
  1104. var d3_selection_onFilters = d3.map({
  1105. mouseenter: "mouseover",
  1106. mouseleave: "mouseout"
  1107. });
  1108. if (d3_document) {
  1109. d3_selection_onFilters.forEach(function(k) {
  1110. if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
  1111. });
  1112. }
  1113. function d3_selection_onListener(listener, argumentz) {
  1114. return function(e) {
  1115. var o = d3.event;
  1116. d3.event = e;
  1117. argumentz[0] = this.__data__;
  1118. try {
  1119. listener.apply(this, argumentz);
  1120. } finally {
  1121. d3.event = o;
  1122. }
  1123. };
  1124. }
  1125. function d3_selection_onFilter(listener, argumentz) {
  1126. var l = d3_selection_onListener(listener, argumentz);
  1127. return function(e) {
  1128. var target = this, related = e.relatedTarget;
  1129. if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
  1130. l.call(target, e);
  1131. }
  1132. };
  1133. }
  1134. var d3_event_dragSelect, d3_event_dragId = 0;
  1135. function d3_event_dragSuppress(node) {
  1136. var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window(node)).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
  1137. if (d3_event_dragSelect == null) {
  1138. d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
  1139. }
  1140. if (d3_event_dragSelect) {
  1141. var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
  1142. style[d3_event_dragSelect] = "none";
  1143. }
  1144. return function(suppressClick) {
  1145. w.on(name, null);
  1146. if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
  1147. if (suppressClick) {
  1148. var off = function() {
  1149. w.on(click, null);
  1150. };
  1151. w.on(click, function() {
  1152. d3_eventPreventDefault();
  1153. off();
  1154. }, true);
  1155. setTimeout(off, 0);
  1156. }
  1157. };
  1158. }
  1159. d3.mouse = function(container) {
  1160. return d3_mousePoint(container, d3_eventSource());
  1161. };
  1162. var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
  1163. function d3_mousePoint(container, e) {
  1164. if (e.changedTouches) e = e.changedTouches[0];
  1165. var svg = container.ownerSVGElement || container;
  1166. if (svg.createSVGPoint) {
  1167. var point = svg.createSVGPoint();
  1168. if (d3_mouse_bug44083 < 0) {
  1169. var window = d3_window(container);
  1170. if (window.scrollX || window.scrollY) {
  1171. svg = d3.select("body").append("svg").style({
  1172. position: "absolute",
  1173. top: 0,
  1174. left: 0,
  1175. margin: 0,
  1176. padding: 0,
  1177. border: "none"
  1178. }, "important");
  1179. var ctm = svg[0][0].getScreenCTM();
  1180. d3_mouse_bug44083 = !(ctm.f || ctm.e);
  1181. svg.remove();
  1182. }
  1183. }
  1184. if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
  1185. point.y = e.clientY;
  1186. point = point.matrixTransform(container.getScreenCTM().inverse());
  1187. return [ point.x, point.y ];
  1188. }
  1189. var rect = container.getBoundingClientRect();
  1190. return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
  1191. }
  1192. d3.touch = function(container, touches, identifier) {
  1193. if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
  1194. if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
  1195. if ((touch = touches[i]).identifier === identifier) {
  1196. return d3_mousePoint(container, touch);
  1197. }
  1198. }
  1199. };
  1200. d3.behavior.drag = function() {
  1201. var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend");
  1202. function drag() {
  1203. this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
  1204. }
  1205. function dragstart(id, position, subject, move, end) {
  1206. return function() {
  1207. var that = this, target = d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
  1208. if (origin) {
  1209. dragOffset = origin.apply(that, arguments);
  1210. dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
  1211. } else {
  1212. dragOffset = [ 0, 0 ];
  1213. }
  1214. dispatch({
  1215. type: "dragstart"
  1216. });
  1217. function moved() {
  1218. var position1 = position(parent, dragId), dx, dy;
  1219. if (!position1) return;
  1220. dx = position1[0] - position0[0];
  1221. dy = position1[1] - position0[1];
  1222. dragged |= dx | dy;
  1223. position0 = position1;
  1224. dispatch({
  1225. type: "drag",
  1226. x: position1[0] + dragOffset[0],
  1227. y: position1[1] + dragOffset[1],
  1228. dx: dx,
  1229. dy: dy
  1230. });
  1231. }
  1232. function ended() {
  1233. if (!position(parent, dragId)) return;
  1234. dragSubject.on(move + dragName, null).on(end + dragName, null);
  1235. dragRestore(dragged && d3.event.target === target);
  1236. dispatch({
  1237. type: "dragend"
  1238. });
  1239. }
  1240. };
  1241. }
  1242. drag.origin = function(x) {
  1243. if (!arguments.length) return origin;
  1244. origin = x;
  1245. return drag;
  1246. };
  1247. return d3.rebind(drag, event, "on");
  1248. };
  1249. function d3_behavior_dragTouchId() {
  1250. return d3.event.changedTouches[0].identifier;
  1251. }
  1252. d3.touches = function(container, touches) {
  1253. if (arguments.length < 2) touches = d3_eventSource().touches;
  1254. return touches ? d3_array(touches).map(function(touch) {
  1255. var point = d3_mousePoint(container, touch);
  1256. point.identifier = touch.identifier;
  1257. return point;
  1258. }) : [];
  1259. };
  1260. var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
  1261. function d3_sgn(x) {
  1262. return x > 0 ? 1 : x < 0 ? -1 : 0;
  1263. }
  1264. function d3_cross2d(a, b, c) {
  1265. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  1266. }
  1267. function d3_acos(x) {
  1268. return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
  1269. }
  1270. function d3_asin(x) {
  1271. return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
  1272. }
  1273. function d3_sinh(x) {
  1274. return ((x = Math.exp(x)) - 1 / x) / 2;
  1275. }
  1276. function d3_cosh(x) {
  1277. return ((x = Math.exp(x)) + 1 / x) / 2;
  1278. }
  1279. function d3_tanh(x) {
  1280. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  1281. }
  1282. function d3_haversin(x) {
  1283. return (x = Math.sin(x / 2)) * x;
  1284. }
  1285. var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
  1286. d3.interpolateZoom = function(p0, p1) {
  1287. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;
  1288. if (d2 < ε2) {
  1289. S = Math.log(w1 / w0) / ρ;
  1290. i = function(t) {
  1291. return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];
  1292. };
  1293. } else {
  1294. var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  1295. S = (r1 - r0) / ρ;
  1296. i = function(t) {
  1297. var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
  1298. return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
  1299. };
  1300. }
  1301. i.duration = S * 1e3;
  1302. return i;
  1303. };
  1304. d3.behavior.zoom = function() {
  1305. var view = {
  1306. x: 0,
  1307. y: 0,
  1308. k: 1
  1309. }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
  1310. if (!d3_behavior_zoomWheel) {
  1311. d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1312. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  1313. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1314. return d3.event.wheelDelta;
  1315. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  1316. return -d3.event.detail;
  1317. }, "MozMousePixelScroll");
  1318. }
  1319. function zoom(g) {
  1320. g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
  1321. }
  1322. zoom.event = function(g) {
  1323. g.each(function() {
  1324. var dispatch = event.of(this, arguments), view1 = view;
  1325. if (d3_transitionInheritId) {
  1326. d3.select(this).transition().each("start.zoom", function() {
  1327. view = this.__chart__ || {
  1328. x: 0,
  1329. y: 0,
  1330. k: 1
  1331. };
  1332. zoomstarted(dispatch);
  1333. }).tween("zoom:zoom", function() {
  1334. var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
  1335. return function(t) {
  1336. var l = i(t), k = dx / l[2];
  1337. this.__chart__ = view = {
  1338. x: cx - l[0] * k,
  1339. y: cy - l[1] * k,
  1340. k: k
  1341. };
  1342. zoomed(dispatch);
  1343. };
  1344. }).each("interrupt.zoom", function() {
  1345. zoomended(dispatch);
  1346. }).each("end.zoom", function() {
  1347. zoomended(dispatch);
  1348. });
  1349. } else {
  1350. this.__chart__ = view;
  1351. zoomstarted(dispatch);
  1352. zoomed(dispatch);
  1353. zoomended(dispatch);
  1354. }
  1355. });
  1356. };
  1357. zoom.translate = function(_) {
  1358. if (!arguments.length) return [ view.x, view.y ];
  1359. view = {
  1360. x: +_[0],
  1361. y: +_[1],
  1362. k: view.k
  1363. };
  1364. rescale();
  1365. return zoom;
  1366. };
  1367. zoom.scale = function(_) {
  1368. if (!arguments.length) return view.k;
  1369. view = {
  1370. x: view.x,
  1371. y: view.y,
  1372. k: null
  1373. };
  1374. scaleTo(+_);
  1375. rescale();
  1376. return zoom;
  1377. };
  1378. zoom.scaleExtent = function(_) {
  1379. if (!arguments.length) return scaleExtent;
  1380. scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
  1381. return zoom;
  1382. };
  1383. zoom.center = function(_) {
  1384. if (!arguments.length) return center;
  1385. center = _ && [ +_[0], +_[1] ];
  1386. return zoom;
  1387. };
  1388. zoom.size = function(_) {
  1389. if (!arguments.length) return size;
  1390. size = _ && [ +_[0], +_[1] ];
  1391. return zoom;
  1392. };
  1393. zoom.duration = function(_) {
  1394. if (!arguments.length) return duration;
  1395. duration = +_;
  1396. return zoom;
  1397. };
  1398. zoom.x = function(z) {
  1399. if (!arguments.length) return x1;
  1400. x1 = z;
  1401. x0 = z.copy();
  1402. view = {
  1403. x: 0,
  1404. y: 0,
  1405. k: 1
  1406. };
  1407. return zoom;
  1408. };
  1409. zoom.y = function(z) {
  1410. if (!arguments.length) return y1;
  1411. y1 = z;
  1412. y0 = z.copy();
  1413. view = {
  1414. x: 0,
  1415. y: 0,
  1416. k: 1
  1417. };
  1418. return zoom;
  1419. };
  1420. function location(p) {
  1421. return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
  1422. }
  1423. function point(l) {
  1424. return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
  1425. }
  1426. function scaleTo(s) {
  1427. view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  1428. }
  1429. function translateTo(p, l) {
  1430. l = point(l);
  1431. view.x += p[0] - l[0];
  1432. view.y += p[1] - l[1];
  1433. }
  1434. function zoomTo(that, p, l, k) {
  1435. that.__chart__ = {
  1436. x: view.x,
  1437. y: view.y,
  1438. k: view.k
  1439. };
  1440. scaleTo(Math.pow(2, k));
  1441. translateTo(center0 = p, l);
  1442. that = d3.select(that);
  1443. if (duration > 0) that = that.transition().duration(duration);
  1444. that.call(zoom.event);
  1445. }
  1446. function rescale() {
  1447. if (x1) x1.domain(x0.range().map(function(x) {
  1448. return (x - view.x) / view.k;
  1449. }).map(x0.invert));
  1450. if (y1) y1.domain(y0.range().map(function(y) {
  1451. return (y - view.y) / view.k;
  1452. }).map(y0.invert));
  1453. }
  1454. function zoomstarted(dispatch) {
  1455. if (!zooming++) dispatch({
  1456. type: "zoomstart"
  1457. });
  1458. }
  1459. function zoomed(dispatch) {
  1460. rescale();
  1461. dispatch({
  1462. type: "zoom",
  1463. scale: view.k,
  1464. translate: [ view.x, view.y ]
  1465. });
  1466. }
  1467. function zoomended(dispatch) {
  1468. if (!--zooming) dispatch({
  1469. type: "zoomend"
  1470. }), center0 = null;
  1471. }
  1472. function mousedowned() {
  1473. var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
  1474. d3_selection_interrupt.call(that);
  1475. zoomstarted(dispatch);
  1476. function moved() {
  1477. dragged = 1;
  1478. translateTo(d3.mouse(that), location0);
  1479. zoomed(dispatch);
  1480. }
  1481. function ended() {
  1482. subject.on(mousemove, null).on(mouseup, null);
  1483. dragRestore(dragged && d3.event.target === target);
  1484. zoomended(dispatch);
  1485. }
  1486. }
  1487. function touchstarted() {
  1488. var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);
  1489. started();
  1490. zoomstarted(dispatch);
  1491. subject.on(mousedown, null).on(touchstart, started);
  1492. function relocate() {
  1493. var touches = d3.touches(that);
  1494. scale0 = view.k;
  1495. touches.forEach(function(t) {
  1496. if (t.identifier in locations0) locations0[t.identifier] = location(t);
  1497. });
  1498. return touches;
  1499. }
  1500. function started() {
  1501. var target = d3.event.target;
  1502. d3.select(target).on(touchmove, moved).on(touchend, ended);
  1503. targets.push(target);
  1504. var changed = d3.event.changedTouches;
  1505. for (var i = 0, n = changed.length; i < n; ++i) {
  1506. locations0[changed[i].identifier] = null;
  1507. }
  1508. var touches = relocate(), now = Date.now();
  1509. if (touches.length === 1) {
  1510. if (now - touchtime < 500) {
  1511. var p = touches[0];
  1512. zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
  1513. d3_eventPreventDefault();
  1514. }
  1515. touchtime = now;
  1516. } else if (touches.length > 1) {
  1517. var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
  1518. distance0 = dx * dx + dy * dy;
  1519. }
  1520. }
  1521. function moved() {
  1522. var touches = d3.touches(that), p0, l0, p1, l1;
  1523. d3_selection_interrupt.call(that);
  1524. for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
  1525. p1 = touches[i];
  1526. if (l1 = locations0[p1.identifier]) {
  1527. if (l0) break;
  1528. p0 = p1, l0 = l1;
  1529. }
  1530. }
  1531. if (l1) {
  1532. var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
  1533. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  1534. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  1535. scaleTo(scale1 * scale0);
  1536. }
  1537. touchtime = null;
  1538. translateTo(p0, l0);
  1539. zoomed(dispatch);
  1540. }
  1541. function ended() {
  1542. if (d3.event.touches.length) {
  1543. var changed = d3.event.changedTouches;
  1544. for (var i = 0, n = changed.length; i < n; ++i) {
  1545. delete locations0[changed[i].identifier];
  1546. }
  1547. for (var identifier in locations0) {
  1548. return void relocate();
  1549. }
  1550. }
  1551. d3.selectAll(targets).on(zoomName, null);
  1552. subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
  1553. dragRestore();
  1554. zoomended(dispatch);
  1555. }
  1556. }
  1557. function mousewheeled() {
  1558. var dispatch = event.of(this, arguments);
  1559. if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
  1560. translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
  1561. mousewheelTimer = setTimeout(function() {
  1562. mousewheelTimer = null;
  1563. zoomended(dispatch);
  1564. }, 50);
  1565. d3_eventPreventDefault();
  1566. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
  1567. translateTo(center0, translate0);
  1568. zoomed(dispatch);
  1569. }
  1570. function dblclicked() {
  1571. var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
  1572. zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
  1573. }
  1574. return d3.rebind(zoom, event, "on");
  1575. };
  1576. var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
  1577. d3.color = d3_color;
  1578. function d3_color() {}
  1579. d3_color.prototype.toString = function() {
  1580. return this.rgb() + "";
  1581. };
  1582. d3.hsl = d3_hsl;
  1583. function d3_hsl(h, s, l) {
  1584. return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
  1585. }
  1586. var d3_hslPrototype = d3_hsl.prototype = new d3_color();
  1587. d3_hslPrototype.brighter = function(k) {
  1588. k = Math.pow(.7, arguments.length ? k : 1);
  1589. return new d3_hsl(this.h, this.s, this.l / k);
  1590. };
  1591. d3_hslPrototype.darker = function(k) {
  1592. k = Math.pow(.7, arguments.length ? k : 1);
  1593. return new d3_hsl(this.h, this.s, k * this.l);
  1594. };
  1595. d3_hslPrototype.rgb = function() {
  1596. return d3_hsl_rgb(this.h, this.s, this.l);
  1597. };
  1598. function d3_hsl_rgb(h, s, l) {
  1599. var m1, m2;
  1600. h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
  1601. s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
  1602. l = l < 0 ? 0 : l > 1 ? 1 : l;
  1603. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  1604. m1 = 2 * l - m2;
  1605. function v(h) {
  1606. if (h > 360) h -= 360; else if (h < 0) h += 360;
  1607. if (h < 60) return m1 + (m2 - m1) * h / 60;
  1608. if (h < 180) return m2;
  1609. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  1610. return m1;
  1611. }
  1612. function vv(h) {
  1613. return Math.round(v(h) * 255);
  1614. }
  1615. return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  1616. }
  1617. d3.hcl = d3_hcl;
  1618. function d3_hcl(h, c, l) {
  1619. return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);
  1620. }
  1621. var d3_hclPrototype = d3_hcl.prototype = new d3_color();
  1622. d3_hclPrototype.brighter = function(k) {
  1623. return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  1624. };
  1625. d3_hclPrototype.darker = function(k) {
  1626. return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  1627. };
  1628. d3_hclPrototype.rgb = function() {
  1629. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  1630. };
  1631. function d3_hcl_lab(h, c, l) {
  1632. if (isNaN(h)) h = 0;
  1633. if (isNaN(c)) c = 0;
  1634. return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  1635. }
  1636. d3.lab = d3_lab;
  1637. function d3_lab(l, a, b) {
  1638. return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
  1639. }
  1640. var d3_lab_K = 18;
  1641. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  1642. var d3_labPrototype = d3_lab.prototype = new d3_color();
  1643. d3_labPrototype.brighter = function(k) {
  1644. return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1645. };
  1646. d3_labPrototype.darker = function(k) {
  1647. return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1648. };
  1649. d3_labPrototype.rgb = function() {
  1650. return d3_lab_rgb(this.l, this.a, this.b);
  1651. };
  1652. function d3_lab_rgb(l, a, b) {
  1653. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  1654. x = d3_lab_xyz(x) * d3_lab_X;
  1655. y = d3_lab_xyz(y) * d3_lab_Y;
  1656. z = d3_lab_xyz(z) * d3_lab_Z;
  1657. return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
  1658. }
  1659. function d3_lab_hcl(l, a, b) {
  1660. return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
  1661. }
  1662. function d3_lab_xyz(x) {
  1663. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  1664. }
  1665. function d3_xyz_lab(x) {
  1666. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  1667. }
  1668. function d3_xyz_rgb(r) {
  1669. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  1670. }
  1671. d3.rgb = d3_rgb;
  1672. function d3_rgb(r, g, b) {
  1673. return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
  1674. }
  1675. function d3_rgbNumber(value) {
  1676. return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
  1677. }
  1678. function d3_rgbString(value) {
  1679. return d3_rgbNumber(value) + "";
  1680. }
  1681. var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
  1682. d3_rgbPrototype.brighter = function(k) {
  1683. k = Math.pow(.7, arguments.length ? k : 1);
  1684. var r = this.r, g = this.g, b = this.b, i = 30;
  1685. if (!r && !g && !b) return new d3_rgb(i, i, i);
  1686. if (r && r < i) r = i;
  1687. if (g && g < i) g = i;
  1688. if (b && b < i) b = i;
  1689. return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
  1690. };
  1691. d3_rgbPrototype.darker = function(k) {
  1692. k = Math.pow(.7, arguments.length ? k : 1);
  1693. return new d3_rgb(k * this.r, k * this.g, k * this.b);
  1694. };
  1695. d3_rgbPrototype.hsl = function() {
  1696. return d3_rgb_hsl(this.r, this.g, this.b);
  1697. };
  1698. d3_rgbPrototype.toString = function() {
  1699. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  1700. };
  1701. function d3_rgb_hex(v) {
  1702. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  1703. }
  1704. function d3_rgb_parse(format, rgb, hsl) {
  1705. var r = 0, g = 0, b = 0, m1, m2, color;
  1706. m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
  1707. if (m1) {
  1708. m2 = m1[2].split(",");
  1709. switch (m1[1]) {
  1710. case "hsl":
  1711. {
  1712. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  1713. }
  1714. case "rgb":
  1715. {
  1716. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  1717. }
  1718. }
  1719. }
  1720. if (color = d3_rgb_names.get(format)) {
  1721. return rgb(color.r, color.g, color.b);
  1722. }
  1723. if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
  1724. if (format.length === 4) {
  1725. r = (color & 3840) >> 4;
  1726. r = r >> 4 | r;
  1727. g = color & 240;
  1728. g = g >> 4 | g;
  1729. b = color & 15;
  1730. b = b << 4 | b;
  1731. } else if (format.length === 7) {
  1732. r = (color & 16711680) >> 16;
  1733. g = (color & 65280) >> 8;
  1734. b = color & 255;
  1735. }
  1736. }
  1737. return rgb(r, g, b);
  1738. }
  1739. function d3_rgb_hsl(r, g, b) {
  1740. var min = Math.min(r /= 255, g /= 255, b /= 255), max = Math.max(r, g, b), d = max - min, h, s, l = (max + min) / 2;
  1741. if (d) {
  1742. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  1743. if (r == max) h = (g - b) / d + (g < b ? 6 : 0); else if (g == max) h = (b - r) / d + 2; else h = (r - g) / d + 4;
  1744. h *= 60;
  1745. } else {
  1746. h = NaN;
  1747. s = l > 0 && l < 1 ? 0 : h;
  1748. }
  1749. return new d3_hsl(h, s, l);
  1750. }
  1751. function d3_rgb_lab(r, g, b) {
  1752. r = d3_rgb_xyz(r);
  1753. g = d3_rgb_xyz(g);
  1754. b = d3_rgb_xyz(b);
  1755. var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);
  1756. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  1757. }
  1758. function d3_rgb_xyz(r) {
  1759. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  1760. }
  1761. function d3_rgb_parseNumber(c) {
  1762. var f = parseFloat(c);
  1763. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  1764. }
  1765. var d3_rgb_names = d3.map({
  1766. aliceblue: 15792383,
  1767. antiquewhite: 16444375,
  1768. aqua: 65535,
  1769. aquamarine: 8388564,
  1770. azure: 15794175,
  1771. beige: 16119260,
  1772. bisque: 16770244,
  1773. black: 0,
  1774. blanchedalmond: 16772045,
  1775. blue: 255,
  1776. blueviolet: 9055202,
  1777. brown: 10824234,
  1778. burlywood: 14596231,
  1779. cadetblue: 6266528,
  1780. chartreuse: 8388352,
  1781. chocolate: 13789470,
  1782. coral: 16744272,
  1783. cornflowerblue: 6591981,
  1784. cornsilk: 16775388,
  1785. crimson: 14423100,
  1786. cyan: 65535,
  1787. darkblue: 139,
  1788. darkcyan: 35723,
  1789. darkgoldenrod: 12092939,
  1790. darkgray: 11119017,
  1791. darkgreen: 25600,
  1792. darkgrey: 11119017,
  1793. darkkhaki: 12433259,
  1794. darkmagenta: 9109643,
  1795. darkolivegreen: 5597999,
  1796. darkorange: 16747520,
  1797. darkorchid: 10040012,
  1798. darkred: 9109504,
  1799. darksalmon: 15308410,
  1800. darkseagreen: 9419919,
  1801. darkslateblue: 4734347,
  1802. darkslategray: 3100495,
  1803. darkslategrey: 3100495,
  1804. darkturquoise: 52945,
  1805. darkviolet: 9699539,
  1806. deeppink: 16716947,
  1807. deepskyblue: 49151,
  1808. dimgray: 6908265,
  1809. dimgrey: 6908265,
  1810. dodgerblue: 2003199,
  1811. firebrick: 11674146,
  1812. floralwhite: 16775920,
  1813. forestgreen: 2263842,
  1814. fuchsia: 16711935,
  1815. gainsboro: 14474460,
  1816. ghostwhite: 16316671,
  1817. gold: 16766720,
  1818. goldenrod: 14329120,
  1819. gray: 8421504,
  1820. green: 32768,
  1821. greenyellow: 11403055,
  1822. grey: 8421504,
  1823. honeydew: 15794160,
  1824. hotpink: 16738740,
  1825. indianred: 13458524,
  1826. indigo: 4915330,
  1827. ivory: 16777200,
  1828. khaki: 15787660,
  1829. lavender: 15132410,
  1830. lavenderblush: 16773365,
  1831. lawngreen: 8190976,
  1832. lemonchiffon: 16775885,
  1833. lightblue: 11393254,
  1834. lightcoral: 15761536,
  1835. lightcyan: 14745599,
  1836. lightgoldenrodyellow: 16448210,
  1837. lightgray: 13882323,
  1838. lightgreen: 9498256,
  1839. lightgrey: 13882323,
  1840. lightpink: 16758465,
  1841. lightsalmon: 16752762,
  1842. lightseagreen: 2142890,
  1843. lightskyblue: 8900346,
  1844. lightslategray: 7833753,
  1845. lightslategrey: 7833753,
  1846. lightsteelblue: 11584734,
  1847. lightyellow: 16777184,
  1848. lime: 65280,
  1849. limegreen: 3329330,
  1850. linen: 16445670,
  1851. magenta: 16711935,
  1852. maroon: 8388608,
  1853. mediumaquamarine: 6737322,
  1854. mediumblue: 205,
  1855. mediumorchid: 12211667,
  1856. mediumpurple: 9662683,
  1857. mediumseagreen: 3978097,
  1858. mediumslateblue: 8087790,
  1859. mediumspringgreen: 64154,
  1860. mediumturquoise: 4772300,
  1861. mediumvioletred: 13047173,
  1862. midnightblue: 1644912,
  1863. mintcream: 16121850,
  1864. mistyrose: 16770273,
  1865. moccasin: 16770229,
  1866. navajowhite: 16768685,
  1867. navy: 128,
  1868. oldlace: 16643558,
  1869. olive: 8421376,
  1870. olivedrab: 7048739,
  1871. orange: 16753920,
  1872. orangered: 16729344,
  1873. orchid: 14315734,
  1874. palegoldenrod: 15657130,
  1875. palegreen: 10025880,
  1876. paleturquoise: 11529966,
  1877. palevioletred: 14381203,
  1878. papayawhip: 16773077,
  1879. peachpuff: 16767673,
  1880. peru: 13468991,
  1881. pink: 16761035,
  1882. plum: 14524637,
  1883. powderblue: 11591910,
  1884. purple: 8388736,
  1885. rebeccapurple: 6697881,
  1886. red: 16711680,
  1887. rosybrown: 12357519,
  1888. royalblue: 4286945,
  1889. saddlebrown: 9127187,
  1890. salmon: 16416882,
  1891. sandybrown: 16032864,
  1892. seagreen: 3050327,
  1893. seashell: 16774638,
  1894. sienna: 10506797,
  1895. silver: 12632256,
  1896. skyblue: 8900331,
  1897. slateblue: 6970061,
  1898. slategray: 7372944,
  1899. slategrey: 7372944,
  1900. snow: 16775930,
  1901. springgreen: 65407,
  1902. steelblue: 4620980,
  1903. tan: 13808780,
  1904. teal: 32896,
  1905. thistle: 14204888,
  1906. tomato: 16737095,
  1907. turquoise: 4251856,
  1908. violet: 15631086,
  1909. wheat: 16113331,
  1910. white: 16777215,
  1911. whitesmoke: 16119285,
  1912. yellow: 16776960,
  1913. yellowgreen: 10145074
  1914. });
  1915. d3_rgb_names.forEach(function(key, value) {
  1916. d3_rgb_names.set(key, d3_rgbNumber(value));
  1917. });
  1918. function d3_functor(v) {
  1919. return typeof v === "function" ? v : function() {
  1920. return v;
  1921. };
  1922. }
  1923. d3.functor = d3_functor;
  1924. d3.xhr = d3_xhrType(d3_identity);
  1925. function d3_xhrType(response) {
  1926. return function(url, mimeType, callback) {
  1927. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  1928. mimeType = null;
  1929. return d3_xhr(url, mimeType, response, callback);
  1930. };
  1931. }
  1932. function d3_xhr(url, mimeType, response, callback) {
  1933. var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
  1934. if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
  1935. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  1936. request.readyState > 3 && respond();
  1937. };
  1938. function respond() {
  1939. var status = request.status, result;
  1940. if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
  1941. try {
  1942. result = response.call(xhr, request);
  1943. } catch (e) {
  1944. dispatch.error.call(xhr, e);
  1945. return;
  1946. }
  1947. dispatch.load.call(xhr, result);
  1948. } else {
  1949. dispatch.error.call(xhr, request);
  1950. }
  1951. }
  1952. request.onprogress = function(event) {
  1953. var o = d3.event;
  1954. d3.event = event;
  1955. try {
  1956. dispatch.progress.call(xhr, request);
  1957. } finally {
  1958. d3.event = o;
  1959. }
  1960. };
  1961. xhr.header = function(name, value) {
  1962. name = (name + "").toLowerCase();
  1963. if (arguments.length < 2) return headers[name];
  1964. if (value == null) delete headers[name]; else headers[name] = value + "";
  1965. return xhr;
  1966. };
  1967. xhr.mimeType = function(value) {
  1968. if (!arguments.length) return mimeType;
  1969. mimeType = value == null ? null : value + "";
  1970. return xhr;
  1971. };
  1972. xhr.responseType = function(value) {
  1973. if (!arguments.length) return responseType;
  1974. responseType = value;
  1975. return xhr;
  1976. };
  1977. xhr.response = function(value) {
  1978. response = value;
  1979. return xhr;
  1980. };
  1981. [ "get", "post" ].forEach(function(method) {
  1982. xhr[method] = function() {
  1983. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  1984. };
  1985. });
  1986. xhr.send = function(method, data, callback) {
  1987. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  1988. request.open(method, url, true);
  1989. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  1990. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  1991. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  1992. if (responseType != null) request.responseType = responseType;
  1993. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  1994. callback(null, request);
  1995. });
  1996. dispatch.beforesend.call(xhr, request);
  1997. request.send(data == null ? null : data);
  1998. return xhr;
  1999. };
  2000. xhr.abort = function() {
  2001. request.abort();
  2002. return xhr;
  2003. };
  2004. d3.rebind(xhr, dispatch, "on");
  2005. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  2006. }
  2007. function d3_xhr_fixCallback(callback) {
  2008. return callback.length === 1 ? function(error, request) {
  2009. callback(error == null ? request : null);
  2010. } : callback;
  2011. }
  2012. function d3_xhrHasResponse(request) {
  2013. var type = request.responseType;
  2014. return type && type !== "text" ? request.response : request.responseText;
  2015. }
  2016. d3.dsv = function(delimiter, mimeType) {
  2017. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  2018. function dsv(url, row, callback) {
  2019. if (arguments.length < 3) callback = row, row = null;
  2020. var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
  2021. xhr.row = function(_) {
  2022. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  2023. };
  2024. return xhr;
  2025. }
  2026. function response(request) {
  2027. return dsv.parse(request.responseText);
  2028. }
  2029. function typedResponse(f) {
  2030. return function(request) {
  2031. return dsv.parse(request.responseText, f);
  2032. };
  2033. }
  2034. dsv.parse = function(text, f) {
  2035. var o;
  2036. return dsv.parseRows(text, function(row, i) {
  2037. if (o) return o(row, i - 1);
  2038. var a = new Function("d", "return {" + row.map(function(name, i) {
  2039. return JSON.stringify(name) + ": d[" + i + "]";
  2040. }).join(",") + "}");
  2041. o = f ? function(row, i) {
  2042. return f(a(row), i);
  2043. } : a;
  2044. });
  2045. };
  2046. dsv.parseRows = function(text, f) {
  2047. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  2048. function token() {
  2049. if (I >= N) return EOF;
  2050. if (eol) return eol = false, EOL;
  2051. var j = I;
  2052. if (text.charCodeAt(j) === 34) {
  2053. var i = j;
  2054. while (i++ < N) {
  2055. if (text.charCodeAt(i) === 34) {
  2056. if (text.charCodeAt(i + 1) !== 34) break;
  2057. ++i;
  2058. }
  2059. }
  2060. I = i + 2;
  2061. var c = text.charCodeAt(i + 1);
  2062. if (c === 13) {
  2063. eol = true;
  2064. if (text.charCodeAt(i + 2) === 10) ++I;
  2065. } else if (c === 10) {
  2066. eol = true;
  2067. }
  2068. return text.slice(j + 1, i).replace(/""/g, '"');
  2069. }
  2070. while (I < N) {
  2071. var c = text.charCodeAt(I++), k = 1;
  2072. if (c === 10) eol = true; else if (c === 13) {
  2073. eol = true;
  2074. if (text.charCodeAt(I) === 10) ++I, ++k;
  2075. } else if (c !== delimiterCode) continue;
  2076. return text.slice(j, I - k);
  2077. }
  2078. return text.slice(j);
  2079. }
  2080. while ((t = token()) !== EOF) {
  2081. var a = [];
  2082. while (t !== EOL && t !== EOF) {
  2083. a.push(t);
  2084. t = token();
  2085. }
  2086. if (f && (a = f(a, n++)) == null) continue;
  2087. rows.push(a);
  2088. }
  2089. return rows;
  2090. };
  2091. dsv.format = function(rows) {
  2092. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  2093. var fieldSet = new d3_Set(), fields = [];
  2094. rows.forEach(function(row) {
  2095. for (var field in row) {
  2096. if (!fieldSet.has(field)) {
  2097. fields.push(fieldSet.add(field));
  2098. }
  2099. }
  2100. });
  2101. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  2102. return fields.map(function(field) {
  2103. return formatValue(row[field]);
  2104. }).join(delimiter);
  2105. })).join("\n");
  2106. };
  2107. dsv.formatRows = function(rows) {
  2108. return rows.map(formatRow).join("\n");
  2109. };
  2110. function formatRow(row) {
  2111. return row.map(formatValue).join(delimiter);
  2112. }
  2113. function formatValue(text) {
  2114. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  2115. }
  2116. return dsv;
  2117. };
  2118. d3.csv = d3.dsv(",", "text/csv");
  2119. d3.tsv = d3.dsv(" ", "text/tab-separated-values");
  2120. var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
  2121. setTimeout(callback, 17);
  2122. };
  2123. d3.timer = function() {
  2124. d3_timer.apply(this, arguments);
  2125. };
  2126. function d3_timer(callback, delay, then) {
  2127. var n = arguments.length;
  2128. if (n < 2) delay = 0;
  2129. if (n < 3) then = Date.now();
  2130. var time = then + delay, timer = {
  2131. c: callback,
  2132. t: time,
  2133. n: null
  2134. };
  2135. if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
  2136. d3_timer_queueTail = timer;
  2137. if (!d3_timer_interval) {
  2138. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  2139. d3_timer_interval = 1;
  2140. d3_timer_frame(d3_timer_step);
  2141. }
  2142. return timer;
  2143. }
  2144. function d3_timer_step() {
  2145. var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
  2146. if (delay > 24) {
  2147. if (isFinite(delay)) {
  2148. clearTimeout(d3_timer_timeout);
  2149. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  2150. }
  2151. d3_timer_interval = 0;
  2152. } else {
  2153. d3_timer_interval = 1;
  2154. d3_timer_frame(d3_timer_step);
  2155. }
  2156. }
  2157. d3.timer.flush = function() {
  2158. d3_timer_mark();
  2159. d3_timer_sweep();
  2160. };
  2161. function d3_timer_mark() {
  2162. var now = Date.now(), timer = d3_timer_queueHead;
  2163. while (timer) {
  2164. if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
  2165. timer = timer.n;
  2166. }
  2167. return now;
  2168. }
  2169. function d3_timer_sweep() {
  2170. var t0, t1 = d3_timer_queueHead, time = Infinity;
  2171. while (t1) {
  2172. if (t1.c) {
  2173. if (t1.t < time) time = t1.t;
  2174. t1 = (t0 = t1).n;
  2175. } else {
  2176. t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
  2177. }
  2178. }
  2179. d3_timer_queueTail = t0;
  2180. return time;
  2181. }
  2182. function d3_format_precision(x, p) {
  2183. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  2184. }
  2185. d3.round = function(x, n) {
  2186. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  2187. };
  2188. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  2189. d3.formatPrefix = function(value, precision) {
  2190. var i = 0;
  2191. if (value = +value) {
  2192. if (value < 0) value *= -1;
  2193. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  2194. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  2195. i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
  2196. }
  2197. return d3_formatPrefixes[8 + i / 3];
  2198. };
  2199. function d3_formatPrefix(d, i) {
  2200. var k = Math.pow(10, abs(8 - i) * 3);
  2201. return {
  2202. scale: i > 8 ? function(d) {
  2203. return d / k;
  2204. } : function(d) {
  2205. return d * k;
  2206. },
  2207. symbol: d
  2208. };
  2209. }
  2210. function d3_locale_numberFormat(locale) {
  2211. var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {
  2212. var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
  2213. while (i > 0 && g > 0) {
  2214. if (length + g + 1 > width) g = Math.max(1, width - length);
  2215. t.push(value.substring(i -= g, i + g));
  2216. if ((length += g + 1) > width) break;
  2217. g = locale_grouping[j = (j + 1) % locale_grouping.length];
  2218. }
  2219. return t.reverse().join(locale_thousands);
  2220. } : d3_identity;
  2221. return function(specifier) {
  2222. var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true;
  2223. if (precision) precision = +precision.substring(1);
  2224. if (zfill || fill === "0" && align === "=") {
  2225. zfill = fill = "0";
  2226. align = "=";
  2227. }
  2228. switch (type) {
  2229. case "n":
  2230. comma = true;
  2231. type = "g";
  2232. break;
  2233. case "%":
  2234. scale = 100;
  2235. suffix = "%";
  2236. type = "f";
  2237. break;
  2238. case "p":
  2239. scale = 100;
  2240. suffix = "%";
  2241. type = "r";
  2242. break;
  2243. case "b":
  2244. case "o":
  2245. case "x":
  2246. case "X":
  2247. if (symbol === "#") prefix = "0" + type.toLowerCase();
  2248. case "c":
  2249. exponent = false;
  2250. case "d":
  2251. integer = true;
  2252. precision = 0;
  2253. break;
  2254. case "s":
  2255. scale = -1;
  2256. type = "r";
  2257. break;
  2258. }
  2259. if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
  2260. if (type == "r" && !precision) type = "g";
  2261. if (precision != null) {
  2262. if (type == "g") precision = Math.max(1, Math.min(21, precision)); else if (type == "e" || type == "f") precision = Math.max(0, Math.min(20, precision));
  2263. }
  2264. type = d3_format_types.get(type) || d3_format_typeDefault;
  2265. var zcomma = zfill && comma;
  2266. return function(value) {
  2267. var fullSuffix = suffix;
  2268. if (integer && value % 1) return "";
  2269. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
  2270. if (scale < 0) {
  2271. var unit = d3.formatPrefix(value, precision);
  2272. value = unit.scale(value);
  2273. fullSuffix = unit.symbol + suffix;
  2274. } else {
  2275. value *= scale;
  2276. }
  2277. value = type(value, precision);
  2278. var i = value.lastIndexOf("."), before, after;
  2279. if (i < 0) {
  2280. var j = exponent ? value.lastIndexOf("e") : -1;
  2281. if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
  2282. } else {
  2283. before = value.substring(0, i);
  2284. after = locale_decimal + value.substring(i + 1);
  2285. }
  2286. if (!zfill && comma) before = formatGroup(before, Infinity);
  2287. var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  2288. if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
  2289. negative += prefix;
  2290. value = before + after;
  2291. return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix;
  2292. };
  2293. };
  2294. }
  2295. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  2296. var d3_format_types = d3.map({
  2297. b: function(x) {
  2298. return x.toString(2);
  2299. },
  2300. c: function(x) {
  2301. return String.fromCharCode(x);
  2302. },
  2303. o: function(x) {
  2304. return x.toString(8);
  2305. },
  2306. x: function(x) {
  2307. return x.toString(16);
  2308. },
  2309. X: function(x) {
  2310. return x.toString(16).toUpperCase();
  2311. },
  2312. g: function(x, p) {
  2313. return x.toPrecision(p);
  2314. },
  2315. e: function(x, p) {
  2316. return x.toExponential(p);
  2317. },
  2318. f: function(x, p) {
  2319. return x.toFixed(p);
  2320. },
  2321. r: function(x, p) {
  2322. return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p))));
  2323. }
  2324. });
  2325. function d3_format_typeDefault(x) {
  2326. return x + "";
  2327. }
  2328. var d3_time = d3.time = {}, d3_date = Date;
  2329. function d3_date_utc() {
  2330. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  2331. }
  2332. d3_date_utc.prototype = {
  2333. getDate: function() {
  2334. return this._.getUTCDate();
  2335. },
  2336. getDay: function() {
  2337. return this._.getUTCDay();
  2338. },
  2339. getFullYear: function() {
  2340. return this._.getUTCFullYear();
  2341. },
  2342. getHours: function() {
  2343. return this._.getUTCHours();
  2344. },
  2345. getMilliseconds: function() {
  2346. return this._.getUTCMilliseconds();
  2347. },
  2348. getMinutes: function() {
  2349. return this._.getUTCMinutes();
  2350. },
  2351. getMonth: function() {
  2352. return this._.getUTCMonth();
  2353. },
  2354. getSeconds: function() {
  2355. return this._.getUTCSeconds();
  2356. },
  2357. getTime: function() {
  2358. return this._.getTime();
  2359. },
  2360. getTimezoneOffset: function() {
  2361. return 0;
  2362. },
  2363. valueOf: function() {
  2364. return this._.valueOf();
  2365. },
  2366. setDate: function() {
  2367. d3_time_prototype.setUTCDate.apply(this._, arguments);
  2368. },
  2369. setDay: function() {
  2370. d3_time_prototype.setUTCDay.apply(this._, arguments);
  2371. },
  2372. setFullYear: function() {
  2373. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  2374. },
  2375. setHours: function() {
  2376. d3_time_prototype.setUTCHours.apply(this._, arguments);
  2377. },
  2378. setMilliseconds: function() {
  2379. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  2380. },
  2381. setMinutes: function() {
  2382. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  2383. },
  2384. setMonth: function() {
  2385. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  2386. },
  2387. setSeconds: function() {
  2388. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  2389. },
  2390. setTime: function() {
  2391. d3_time_prototype.setTime.apply(this._, arguments);
  2392. }
  2393. };
  2394. var d3_time_prototype = Date.prototype;
  2395. function d3_time_interval(local, step, number) {
  2396. function round(date) {
  2397. var d0 = local(date), d1 = offset(d0, 1);
  2398. return date - d0 < d1 - date ? d0 : d1;
  2399. }
  2400. function ceil(date) {
  2401. step(date = local(new d3_date(date - 1)), 1);
  2402. return date;
  2403. }
  2404. function offset(date, k) {
  2405. step(date = new d3_date(+date), k);
  2406. return date;
  2407. }
  2408. function range(t0, t1, dt) {
  2409. var time = ceil(t0), times = [];
  2410. if (dt > 1) {
  2411. while (time < t1) {
  2412. if (!(number(time) % dt)) times.push(new Date(+time));
  2413. step(time, 1);
  2414. }
  2415. } else {
  2416. while (time < t1) times.push(new Date(+time)), step(time, 1);
  2417. }
  2418. return times;
  2419. }
  2420. function range_utc(t0, t1, dt) {
  2421. try {
  2422. d3_date = d3_date_utc;
  2423. var utc = new d3_date_utc();
  2424. utc._ = t0;
  2425. return range(utc, t1, dt);
  2426. } finally {
  2427. d3_date = Date;
  2428. }
  2429. }
  2430. local.floor = local;
  2431. local.round = round;
  2432. local.ceil = ceil;
  2433. local.offset = offset;
  2434. local.range = range;
  2435. var utc = local.utc = d3_time_interval_utc(local);
  2436. utc.floor = utc;
  2437. utc.round = d3_time_interval_utc(round);
  2438. utc.ceil = d3_time_interval_utc(ceil);
  2439. utc.offset = d3_time_interval_utc(offset);
  2440. utc.range = range_utc;
  2441. return local;
  2442. }
  2443. function d3_time_interval_utc(method) {
  2444. return function(date, k) {
  2445. try {
  2446. d3_date = d3_date_utc;
  2447. var utc = new d3_date_utc();
  2448. utc._ = date;
  2449. return method(utc, k)._;
  2450. } finally {
  2451. d3_date = Date;
  2452. }
  2453. };
  2454. }
  2455. d3_time.year = d3_time_interval(function(date) {
  2456. date = d3_time.day(date);
  2457. date.setMonth(0, 1);
  2458. return date;
  2459. }, function(date, offset) {
  2460. date.setFullYear(date.getFullYear() + offset);
  2461. }, function(date) {
  2462. return date.getFullYear();
  2463. });
  2464. d3_time.years = d3_time.year.range;
  2465. d3_time.years.utc = d3_time.year.utc.range;
  2466. d3_time.day = d3_time_interval(function(date) {
  2467. var day = new d3_date(2e3, 0);
  2468. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  2469. return day;
  2470. }, function(date, offset) {
  2471. date.setDate(date.getDate() + offset);
  2472. }, function(date) {
  2473. return date.getDate() - 1;
  2474. });
  2475. d3_time.days = d3_time.day.range;
  2476. d3_time.days.utc = d3_time.day.utc.range;
  2477. d3_time.dayOfYear = function(date) {
  2478. var year = d3_time.year(date);
  2479. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  2480. };
  2481. [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
  2482. i = 7 - i;
  2483. var interval = d3_time[day] = d3_time_interval(function(date) {
  2484. (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  2485. return date;
  2486. }, function(date, offset) {
  2487. date.setDate(date.getDate() + Math.floor(offset) * 7);
  2488. }, function(date) {
  2489. var day = d3_time.year(date).getDay();
  2490. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  2491. });
  2492. d3_time[day + "s"] = interval.range;
  2493. d3_time[day + "s"].utc = interval.utc.range;
  2494. d3_time[day + "OfYear"] = function(date) {
  2495. var day = d3_time.year(date).getDay();
  2496. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
  2497. };
  2498. });
  2499. d3_time.week = d3_time.sunday;
  2500. d3_time.weeks = d3_time.sunday.range;
  2501. d3_time.weeks.utc = d3_time.sunday.utc.range;
  2502. d3_time.weekOfYear = d3_time.sundayOfYear;
  2503. function d3_locale_timeFormat(locale) {
  2504. var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;
  2505. function d3_time_format(template) {
  2506. var n = template.length;
  2507. function format(date) {
  2508. var string = [], i = -1, j = 0, c, p, f;
  2509. while (++i < n) {
  2510. if (template.charCodeAt(i) === 37) {
  2511. string.push(template.slice(j, i));
  2512. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  2513. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  2514. string.push(c);
  2515. j = i + 1;
  2516. }
  2517. }
  2518. string.push(template.slice(j, i));
  2519. return string.join("");
  2520. }
  2521. format.parse = function(string) {
  2522. var d = {
  2523. y: 1900,
  2524. m: 0,
  2525. d: 1,
  2526. H: 0,
  2527. M: 0,
  2528. S: 0,
  2529. L: 0,
  2530. Z: null
  2531. }, i = d3_time_parse(d, template, string, 0);
  2532. if (i != string.length) return null;
  2533. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  2534. var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
  2535. if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) {
  2536. if (!("w" in d)) d.w = "W" in d ? 1 : 0;
  2537. date.setFullYear(d.y, 0, 1);
  2538. date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);
  2539. } else date.setFullYear(d.y, d.m, d.d);
  2540. date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
  2541. return localZ ? date._ : date;
  2542. };
  2543. format.toString = function() {
  2544. return template;
  2545. };
  2546. return format;
  2547. }
  2548. function d3_time_parse(date, template, string, j) {
  2549. var c, p, t, i = 0, n = template.length, m = string.length;
  2550. while (i < n) {
  2551. if (j >= m) return -1;
  2552. c = template.charCodeAt(i++);
  2553. if (c === 37) {
  2554. t = template.charAt(i++);
  2555. p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
  2556. if (!p || (j = p(date, string, j)) < 0) return -1;
  2557. } else if (c != string.charCodeAt(j++)) {
  2558. return -1;
  2559. }
  2560. }
  2561. return j;
  2562. }
  2563. d3_time_format.utc = function(template) {
  2564. var local = d3_time_format(template);
  2565. function format(date) {
  2566. try {
  2567. d3_date = d3_date_utc;
  2568. var utc = new d3_date();
  2569. utc._ = date;
  2570. return local(utc);
  2571. } finally {
  2572. d3_date = Date;
  2573. }
  2574. }
  2575. format.parse = function(string) {
  2576. try {
  2577. d3_date = d3_date_utc;
  2578. var date = local.parse(string);
  2579. return date && date._;
  2580. } finally {
  2581. d3_date = Date;
  2582. }
  2583. };
  2584. format.toString = local.toString;
  2585. return format;
  2586. };
  2587. d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
  2588. var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths);
  2589. locale_periods.forEach(function(p, i) {
  2590. d3_time_periodLookup.set(p.toLowerCase(), i);
  2591. });
  2592. var d3_time_formats = {
  2593. a: function(d) {
  2594. return locale_shortDays[d.getDay()];
  2595. },
  2596. A: function(d) {
  2597. return locale_days[d.getDay()];
  2598. },
  2599. b: function(d) {
  2600. return locale_shortMonths[d.getMonth()];
  2601. },
  2602. B: function(d) {
  2603. return locale_months[d.getMonth()];
  2604. },
  2605. c: d3_time_format(locale_dateTime),
  2606. d: function(d, p) {
  2607. return d3_time_formatPad(d.getDate(), p, 2);
  2608. },
  2609. e: function(d, p) {
  2610. return d3_time_formatPad(d.getDate(), p, 2);
  2611. },
  2612. H: function(d, p) {
  2613. return d3_time_formatPad(d.getHours(), p, 2);
  2614. },
  2615. I: function(d, p) {
  2616. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  2617. },
  2618. j: function(d, p) {
  2619. return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
  2620. },
  2621. L: function(d, p) {
  2622. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  2623. },
  2624. m: function(d, p) {
  2625. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  2626. },
  2627. M: function(d, p) {
  2628. return d3_time_formatPad(d.getMinutes(), p, 2);
  2629. },
  2630. p: function(d) {
  2631. return locale_periods[+(d.getHours() >= 12)];
  2632. },
  2633. S: function(d, p) {
  2634. return d3_time_formatPad(d.getSeconds(), p, 2);
  2635. },
  2636. U: function(d, p) {
  2637. return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
  2638. },
  2639. w: function(d) {
  2640. return d.getDay();
  2641. },
  2642. W: function(d, p) {
  2643. return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
  2644. },
  2645. x: d3_time_format(locale_date),
  2646. X: d3_time_format(locale_time),
  2647. y: function(d, p) {
  2648. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  2649. },
  2650. Y: function(d, p) {
  2651. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  2652. },
  2653. Z: d3_time_zone,
  2654. "%": function() {
  2655. return "%";
  2656. }
  2657. };
  2658. var d3_time_parsers = {
  2659. a: d3_time_parseWeekdayAbbrev,
  2660. A: d3_time_parseWeekday,
  2661. b: d3_time_parseMonthAbbrev,
  2662. B: d3_time_parseMonth,
  2663. c: d3_time_parseLocaleFull,
  2664. d: d3_time_parseDay,
  2665. e: d3_time_parseDay,
  2666. H: d3_time_parseHour24,
  2667. I: d3_time_parseHour24,
  2668. j: d3_time_parseDayOfYear,
  2669. L: d3_time_parseMilliseconds,
  2670. m: d3_time_parseMonthNumber,
  2671. M: d3_time_parseMinutes,
  2672. p: d3_time_parseAmPm,
  2673. S: d3_time_parseSeconds,
  2674. U: d3_time_parseWeekNumberSunday,
  2675. w: d3_time_parseWeekdayNumber,
  2676. W: d3_time_parseWeekNumberMonday,
  2677. x: d3_time_parseLocaleDate,
  2678. X: d3_time_parseLocaleTime,
  2679. y: d3_time_parseYear,
  2680. Y: d3_time_parseFullYear,
  2681. Z: d3_time_parseZone,
  2682. "%": d3_time_parseLiteralPercent
  2683. };
  2684. function d3_time_parseWeekdayAbbrev(date, string, i) {
  2685. d3_time_dayAbbrevRe.lastIndex = 0;
  2686. var n = d3_time_dayAbbrevRe.exec(string.slice(i));
  2687. return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2688. }
  2689. function d3_time_parseWeekday(date, string, i) {
  2690. d3_time_dayRe.lastIndex = 0;
  2691. var n = d3_time_dayRe.exec(string.slice(i));
  2692. return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2693. }
  2694. function d3_time_parseMonthAbbrev(date, string, i) {
  2695. d3_time_monthAbbrevRe.lastIndex = 0;
  2696. var n = d3_time_monthAbbrevRe.exec(string.slice(i));
  2697. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2698. }
  2699. function d3_time_parseMonth(date, string, i) {
  2700. d3_time_monthRe.lastIndex = 0;
  2701. var n = d3_time_monthRe.exec(string.slice(i));
  2702. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2703. }
  2704. function d3_time_parseLocaleFull(date, string, i) {
  2705. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  2706. }
  2707. function d3_time_parseLocaleDate(date, string, i) {
  2708. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  2709. }
  2710. function d3_time_parseLocaleTime(date, string, i) {
  2711. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  2712. }
  2713. function d3_time_parseAmPm(date, string, i) {
  2714. var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
  2715. return n == null ? -1 : (date.p = n, i);
  2716. }
  2717. return d3_time_format;
  2718. }
  2719. var d3_time_formatPads = {
  2720. "-": "",
  2721. _: " ",
  2722. "0": "0"
  2723. }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
  2724. function d3_time_formatPad(value, fill, width) {
  2725. var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
  2726. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  2727. }
  2728. function d3_time_formatRe(names) {
  2729. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  2730. }
  2731. function d3_time_formatLookup(names) {
  2732. var map = new d3_Map(), i = -1, n = names.length;
  2733. while (++i < n) map.set(names[i].toLowerCase(), i);
  2734. return map;
  2735. }
  2736. function d3_time_parseWeekdayNumber(date, string, i) {
  2737. d3_time_numberRe.lastIndex = 0;
  2738. var n = d3_time_numberRe.exec(string.slice(i, i + 1));
  2739. return n ? (date.w = +n[0], i + n[0].length) : -1;
  2740. }
  2741. function d3_time_parseWeekNumberSunday(date, string, i) {
  2742. d3_time_numberRe.lastIndex = 0;
  2743. var n = d3_time_numberRe.exec(string.slice(i));
  2744. return n ? (date.U = +n[0], i + n[0].length) : -1;
  2745. }
  2746. function d3_time_parseWeekNumberMonday(date, string, i) {
  2747. d3_time_numberRe.lastIndex = 0;
  2748. var n = d3_time_numberRe.exec(string.slice(i));
  2749. return n ? (date.W = +n[0], i + n[0].length) : -1;
  2750. }
  2751. function d3_time_parseFullYear(date, string, i) {
  2752. d3_time_numberRe.lastIndex = 0;
  2753. var n = d3_time_numberRe.exec(string.slice(i, i + 4));
  2754. return n ? (date.y = +n[0], i + n[0].length) : -1;
  2755. }
  2756. function d3_time_parseYear(date, string, i) {
  2757. d3_time_numberRe.lastIndex = 0;
  2758. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2759. return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
  2760. }
  2761. function d3_time_parseZone(date, string, i) {
  2762. return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
  2763. i + 5) : -1;
  2764. }
  2765. function d3_time_expandYear(d) {
  2766. return d + (d > 68 ? 1900 : 2e3);
  2767. }
  2768. function d3_time_parseMonthNumber(date, string, i) {
  2769. d3_time_numberRe.lastIndex = 0;
  2770. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2771. return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
  2772. }
  2773. function d3_time_parseDay(date, string, i) {
  2774. d3_time_numberRe.lastIndex = 0;
  2775. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2776. return n ? (date.d = +n[0], i + n[0].length) : -1;
  2777. }
  2778. function d3_time_parseDayOfYear(date, string, i) {
  2779. d3_time_numberRe.lastIndex = 0;
  2780. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2781. return n ? (date.j = +n[0], i + n[0].length) : -1;
  2782. }
  2783. function d3_time_parseHour24(date, string, i) {
  2784. d3_time_numberRe.lastIndex = 0;
  2785. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2786. return n ? (date.H = +n[0], i + n[0].length) : -1;
  2787. }
  2788. function d3_time_parseMinutes(date, string, i) {
  2789. d3_time_numberRe.lastIndex = 0;
  2790. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2791. return n ? (date.M = +n[0], i + n[0].length) : -1;
  2792. }
  2793. function d3_time_parseSeconds(date, string, i) {
  2794. d3_time_numberRe.lastIndex = 0;
  2795. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2796. return n ? (date.S = +n[0], i + n[0].length) : -1;
  2797. }
  2798. function d3_time_parseMilliseconds(date, string, i) {
  2799. d3_time_numberRe.lastIndex = 0;
  2800. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2801. return n ? (date.L = +n[0], i + n[0].length) : -1;
  2802. }
  2803. function d3_time_zone(d) {
  2804. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
  2805. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  2806. }
  2807. function d3_time_parseLiteralPercent(date, string, i) {
  2808. d3_time_percentRe.lastIndex = 0;
  2809. var n = d3_time_percentRe.exec(string.slice(i, i + 1));
  2810. return n ? i + n[0].length : -1;
  2811. }
  2812. function d3_time_formatMulti(formats) {
  2813. var n = formats.length, i = -1;
  2814. while (++i < n) formats[i][0] = this(formats[i][0]);
  2815. return function(date) {
  2816. var i = 0, f = formats[i];
  2817. while (!f[1](date)) f = formats[++i];
  2818. return f[0](date);
  2819. };
  2820. }
  2821. d3.locale = function(locale) {
  2822. return {
  2823. numberFormat: d3_locale_numberFormat(locale),
  2824. timeFormat: d3_locale_timeFormat(locale)
  2825. };
  2826. };
  2827. var d3_locale_enUS = d3.locale({
  2828. decimal: ".",
  2829. thousands: ",",
  2830. grouping: [ 3 ],
  2831. currency: [ "$", "" ],
  2832. dateTime: "%a %b %e %X %Y",
  2833. date: "%m/%d/%Y",
  2834. time: "%H:%M:%S",
  2835. periods: [ "AM", "PM" ],
  2836. days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
  2837. shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
  2838. months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  2839. shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
  2840. });
  2841. d3.format = d3_locale_enUS.numberFormat;
  2842. d3.geo = {};
  2843. function d3_adder() {}
  2844. d3_adder.prototype = {
  2845. s: 0,
  2846. t: 0,
  2847. add: function(y) {
  2848. d3_adderSum(y, this.t, d3_adderTemp);
  2849. d3_adderSum(d3_adderTemp.s, this.s, this);
  2850. if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
  2851. },
  2852. reset: function() {
  2853. this.s = this.t = 0;
  2854. },
  2855. valueOf: function() {
  2856. return this.s;
  2857. }
  2858. };
  2859. var d3_adderTemp = new d3_adder();
  2860. function d3_adderSum(a, b, o) {
  2861. var x = o.s = a + b, bv = x - a, av = x - bv;
  2862. o.t = a - av + (b - bv);
  2863. }
  2864. d3.geo.stream = function(object, listener) {
  2865. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  2866. d3_geo_streamObjectType[object.type](object, listener);
  2867. } else {
  2868. d3_geo_streamGeometry(object, listener);
  2869. }
  2870. };
  2871. function d3_geo_streamGeometry(geometry, listener) {
  2872. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  2873. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  2874. }
  2875. }
  2876. var d3_geo_streamObjectType = {
  2877. Feature: function(feature, listener) {
  2878. d3_geo_streamGeometry(feature.geometry, listener);
  2879. },
  2880. FeatureCollection: function(object, listener) {
  2881. var features = object.features, i = -1, n = features.length;
  2882. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  2883. }
  2884. };
  2885. var d3_geo_streamGeometryType = {
  2886. Sphere: function(object, listener) {
  2887. listener.sphere();
  2888. },
  2889. Point: function(object, listener) {
  2890. object = object.coordinates;
  2891. listener.point(object[0], object[1], object[2]);
  2892. },
  2893. MultiPoint: function(object, listener) {
  2894. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2895. while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
  2896. },
  2897. LineString: function(object, listener) {
  2898. d3_geo_streamLine(object.coordinates, listener, 0);
  2899. },
  2900. MultiLineString: function(object, listener) {
  2901. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2902. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  2903. },
  2904. Polygon: function(object, listener) {
  2905. d3_geo_streamPolygon(object.coordinates, listener);
  2906. },
  2907. MultiPolygon: function(object, listener) {
  2908. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2909. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  2910. },
  2911. GeometryCollection: function(object, listener) {
  2912. var geometries = object.geometries, i = -1, n = geometries.length;
  2913. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  2914. }
  2915. };
  2916. function d3_geo_streamLine(coordinates, listener, closed) {
  2917. var i = -1, n = coordinates.length - closed, coordinate;
  2918. listener.lineStart();
  2919. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
  2920. listener.lineEnd();
  2921. }
  2922. function d3_geo_streamPolygon(coordinates, listener) {
  2923. var i = -1, n = coordinates.length;
  2924. listener.polygonStart();
  2925. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  2926. listener.polygonEnd();
  2927. }
  2928. d3.geo.area = function(object) {
  2929. d3_geo_areaSum = 0;
  2930. d3.geo.stream(object, d3_geo_area);
  2931. return d3_geo_areaSum;
  2932. };
  2933. var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
  2934. var d3_geo_area = {
  2935. sphere: function() {
  2936. d3_geo_areaSum += 4 * π;
  2937. },
  2938. point: d3_noop,
  2939. lineStart: d3_noop,
  2940. lineEnd: d3_noop,
  2941. polygonStart: function() {
  2942. d3_geo_areaRingSum.reset();
  2943. d3_geo_area.lineStart = d3_geo_areaRingStart;
  2944. },
  2945. polygonEnd: function() {
  2946. var area = 2 * d3_geo_areaRingSum;
  2947. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  2948. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  2949. }
  2950. };
  2951. function d3_geo_areaRingStart() {
  2952. var λ00, φ00, λ0, cosφ0, sinφ0;
  2953. d3_geo_area.point = function(λ, φ) {
  2954. d3_geo_area.point = nextPoint;
  2955. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  2956. sinφ0 = Math.sin(φ);
  2957. };
  2958. function nextPoint(λ, φ) {
  2959. λ *= d3_radians;
  2960. φ = φ * d3_radians / 2 + π / 4;
  2961. var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
  2962. d3_geo_areaRingSum.add(Math.atan2(v, u));
  2963. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  2964. }
  2965. d3_geo_area.lineEnd = function() {
  2966. nextPoint(λ00, φ00);
  2967. };
  2968. }
  2969. function d3_geo_cartesian(spherical) {
  2970. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  2971. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  2972. }
  2973. function d3_geo_cartesianDot(a, b) {
  2974. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  2975. }
  2976. function d3_geo_cartesianCross(a, b) {
  2977. return [ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0] ];
  2978. }
  2979. function d3_geo_cartesianAdd(a, b) {
  2980. a[0] += b[0];
  2981. a[1] += b[1];
  2982. a[2] += b[2];
  2983. }
  2984. function d3_geo_cartesianScale(vector, k) {
  2985. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  2986. }
  2987. function d3_geo_cartesianNormalize(d) {
  2988. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  2989. d[0] /= l;
  2990. d[1] /= l;
  2991. d[2] /= l;
  2992. }
  2993. function d3_geo_spherical(cartesian) {
  2994. return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
  2995. }
  2996. function d3_geo_sphericalEqual(a, b) {
  2997. return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
  2998. }
  2999. d3.geo.bounds = function() {
  3000. var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
  3001. var bound = {
  3002. point: point,
  3003. lineStart: lineStart,
  3004. lineEnd: lineEnd,
  3005. polygonStart: function() {
  3006. bound.point = ringPoint;
  3007. bound.lineStart = ringStart;
  3008. bound.lineEnd = ringEnd;
  3009. dλSum = 0;
  3010. d3_geo_area.polygonStart();
  3011. },
  3012. polygonEnd: function() {
  3013. d3_geo_area.polygonEnd();
  3014. bound.point = point;
  3015. bound.lineStart = lineStart;
  3016. bound.lineEnd = lineEnd;
  3017. if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
  3018. range[0] = λ0, range[1] = λ1;
  3019. }
  3020. };
  3021. function point(λ, φ) {
  3022. ranges.push(range = [ λ0 = λ, λ1 = λ ]);
  3023. if (φ < φ0) φ0 = φ;
  3024. if (φ > φ1) φ1 = φ;
  3025. }
  3026. function linePoint(λ, φ) {
  3027. var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
  3028. if (p0) {
  3029. var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
  3030. d3_geo_cartesianNormalize(inflection);
  3031. inflection = d3_geo_spherical(inflection);
  3032. var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
  3033. if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3034. var φi = inflection[1] * d3_degrees;
  3035. if (φi > φ1) φ1 = φi;
  3036. } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3037. var φi = -inflection[1] * d3_degrees;
  3038. if (φi < φ0) φ0 = φi;
  3039. } else {
  3040. if (φ < φ0) φ0 = φ;
  3041. if (φ > φ1) φ1 = φ;
  3042. }
  3043. if (antimeridian) {
  3044. if (λ < λ_) {
  3045. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3046. } else {
  3047. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3048. }
  3049. } else {
  3050. if (λ1 >= λ0) {
  3051. if (λ < λ0) λ0 = λ;
  3052. if (λ > λ1) λ1 = λ;
  3053. } else {
  3054. if (λ > λ_) {
  3055. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3056. } else {
  3057. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3058. }
  3059. }
  3060. }
  3061. } else {
  3062. point(λ, φ);
  3063. }
  3064. p0 = p, λ_ = λ;
  3065. }
  3066. function lineStart() {
  3067. bound.point = linePoint;
  3068. }
  3069. function lineEnd() {
  3070. range[0] = λ0, range[1] = λ1;
  3071. bound.point = point;
  3072. p0 = null;
  3073. }
  3074. function ringPoint(λ, φ) {
  3075. if (p0) {
  3076. var dλ = λ - λ_;
  3077. dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
  3078. } else λ__ = λ, φ__ = φ;
  3079. d3_geo_area.point(λ, φ);
  3080. linePoint(λ, φ);
  3081. }
  3082. function ringStart() {
  3083. d3_geo_area.lineStart();
  3084. }
  3085. function ringEnd() {
  3086. ringPoint(λ__, φ__);
  3087. d3_geo_area.lineEnd();
  3088. if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
  3089. range[0] = λ0, range[1] = λ1;
  3090. p0 = null;
  3091. }
  3092. function angle(λ0, λ1) {
  3093. return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
  3094. }
  3095. function compareRanges(a, b) {
  3096. return a[0] - b[0];
  3097. }
  3098. function withinRange(x, range) {
  3099. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  3100. }
  3101. return function(feature) {
  3102. φ1 = λ1 = -(λ0 = φ0 = Infinity);
  3103. ranges = [];
  3104. d3.geo.stream(feature, bound);
  3105. var n = ranges.length;
  3106. if (n) {
  3107. ranges.sort(compareRanges);
  3108. for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
  3109. b = ranges[i];
  3110. if (withinRange(b[0], a) || withinRange(b[1], a)) {
  3111. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  3112. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  3113. } else {
  3114. merged.push(a = b);
  3115. }
  3116. }
  3117. var best = -Infinity, dλ;
  3118. for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
  3119. b = merged[i];
  3120. if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
  3121. }
  3122. }
  3123. ranges = range = null;
  3124. return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
  3125. };
  3126. }();
  3127. d3.geo.centroid = function(object) {
  3128. d3_geo_centroidW0 = d3_geo_centroidW1 = d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
  3129. d3.geo.stream(object, d3_geo_centroid);
  3130. var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
  3131. if (m < ε2) {
  3132. x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
  3133. if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
  3134. m = x * x + y * y + z * z;
  3135. if (m < ε2) return [ NaN, NaN ];
  3136. }
  3137. return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
  3138. };
  3139. var d3_geo_centroidW0, d3_geo_centroidW1, d3_geo_centroidX0, d3_geo_centroidY0, d3_geo_centroidZ0, d3_geo_centroidX1, d3_geo_centroidY1, d3_geo_centroidZ1, d3_geo_centroidX2, d3_geo_centroidY2, d3_geo_centroidZ2;
  3140. var d3_geo_centroid = {
  3141. sphere: d3_noop,
  3142. point: d3_geo_centroidPoint,
  3143. lineStart: d3_geo_centroidLineStart,
  3144. lineEnd: d3_geo_centroidLineEnd,
  3145. polygonStart: function() {
  3146. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  3147. },
  3148. polygonEnd: function() {
  3149. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  3150. }
  3151. };
  3152. function d3_geo_centroidPoint(λ, φ) {
  3153. λ *= d3_radians;
  3154. var cosφ = Math.cos(φ *= d3_radians);
  3155. d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
  3156. }
  3157. function d3_geo_centroidPointXYZ(x, y, z) {
  3158. ++d3_geo_centroidW0;
  3159. d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
  3160. d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
  3161. d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
  3162. }
  3163. function d3_geo_centroidLineStart() {
  3164. var x0, y0, z0;
  3165. d3_geo_centroid.point = function(λ, φ) {
  3166. λ *= d3_radians;
  3167. var cosφ = Math.cos(φ *= d3_radians);
  3168. x0 = cosφ * Math.cos(λ);
  3169. y0 = cosφ * Math.sin(λ);
  3170. z0 = Math.sin(φ);
  3171. d3_geo_centroid.point = nextPoint;
  3172. d3_geo_centroidPointXYZ(x0, y0, z0);
  3173. };
  3174. function nextPoint(λ, φ) {
  3175. λ *= d3_radians;
  3176. var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), w = Math.atan2(Math.sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
  3177. d3_geo_centroidW1 += w;
  3178. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3179. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3180. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3181. d3_geo_centroidPointXYZ(x0, y0, z0);
  3182. }
  3183. }
  3184. function d3_geo_centroidLineEnd() {
  3185. d3_geo_centroid.point = d3_geo_centroidPoint;
  3186. }
  3187. function d3_geo_centroidRingStart() {
  3188. var λ00, φ00, x0, y0, z0;
  3189. d3_geo_centroid.point = function(λ, φ) {
  3190. λ00 = λ, φ00 = φ;
  3191. d3_geo_centroid.point = nextPoint;
  3192. λ *= d3_radians;
  3193. var cosφ = Math.cos(φ *= d3_radians);
  3194. x0 = cosφ * Math.cos(λ);
  3195. y0 = cosφ * Math.sin(λ);
  3196. z0 = Math.sin(φ);
  3197. d3_geo_centroidPointXYZ(x0, y0, z0);
  3198. };
  3199. d3_geo_centroid.lineEnd = function() {
  3200. nextPoint(λ00, φ00);
  3201. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  3202. d3_geo_centroid.point = d3_geo_centroidPoint;
  3203. };
  3204. function nextPoint(λ, φ) {
  3205. λ *= d3_radians;
  3206. var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), cx = y0 * z - z0 * y, cy = z0 * x - x0 * z, cz = x0 * y - y0 * x, m = Math.sqrt(cx * cx + cy * cy + cz * cz), u = x0 * x + y0 * y + z0 * z, v = m && -d3_acos(u) / m, w = Math.atan2(m, u);
  3207. d3_geo_centroidX2 += v * cx;
  3208. d3_geo_centroidY2 += v * cy;
  3209. d3_geo_centroidZ2 += v * cz;
  3210. d3_geo_centroidW1 += w;
  3211. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3212. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3213. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3214. d3_geo_centroidPointXYZ(x0, y0, z0);
  3215. }
  3216. }
  3217. function d3_geo_compose(a, b) {
  3218. function compose(x, y) {
  3219. return x = a(x, y), b(x[0], x[1]);
  3220. }
  3221. if (a.invert && b.invert) compose.invert = function(x, y) {
  3222. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  3223. };
  3224. return compose;
  3225. }
  3226. function d3_true() {
  3227. return true;
  3228. }
  3229. function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
  3230. var subject = [], clip = [];
  3231. segments.forEach(function(segment) {
  3232. if ((n = segment.length - 1) <= 0) return;
  3233. var n, p0 = segment[0], p1 = segment[n];
  3234. if (d3_geo_sphericalEqual(p0, p1)) {
  3235. listener.lineStart();
  3236. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  3237. listener.lineEnd();
  3238. return;
  3239. }
  3240. var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
  3241. a.o = b;
  3242. subject.push(a);
  3243. clip.push(b);
  3244. a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
  3245. b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
  3246. a.o = b;
  3247. subject.push(a);
  3248. clip.push(b);
  3249. });
  3250. clip.sort(compare);
  3251. d3_geo_clipPolygonLinkCircular(subject);
  3252. d3_geo_clipPolygonLinkCircular(clip);
  3253. if (!subject.length) return;
  3254. for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
  3255. clip[i].e = entry = !entry;
  3256. }
  3257. var start = subject[0], points, point;
  3258. while (1) {
  3259. var current = start, isSubject = true;
  3260. while (current.v) if ((current = current.n) === start) return;
  3261. points = current.z;
  3262. listener.lineStart();
  3263. do {
  3264. current.v = current.o.v = true;
  3265. if (current.e) {
  3266. if (isSubject) {
  3267. for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
  3268. } else {
  3269. interpolate(current.x, current.n.x, 1, listener);
  3270. }
  3271. current = current.n;
  3272. } else {
  3273. if (isSubject) {
  3274. points = current.p.z;
  3275. for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
  3276. } else {
  3277. interpolate(current.x, current.p.x, -1, listener);
  3278. }
  3279. current = current.p;
  3280. }
  3281. current = current.o;
  3282. points = current.z;
  3283. isSubject = !isSubject;
  3284. } while (!current.v);
  3285. listener.lineEnd();
  3286. }
  3287. }
  3288. function d3_geo_clipPolygonLinkCircular(array) {
  3289. if (!(n = array.length)) return;
  3290. var n, i = 0, a = array[0], b;
  3291. while (++i < n) {
  3292. a.n = b = array[i];
  3293. b.p = a;
  3294. a = b;
  3295. }
  3296. a.n = b = array[0];
  3297. b.p = a;
  3298. }
  3299. function d3_geo_clipPolygonIntersection(point, points, other, entry) {
  3300. this.x = point;
  3301. this.z = points;
  3302. this.o = other;
  3303. this.e = entry;
  3304. this.v = false;
  3305. this.n = this.p = null;
  3306. }
  3307. function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
  3308. return function(rotate, listener) {
  3309. var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
  3310. var clip = {
  3311. point: point,
  3312. lineStart: lineStart,
  3313. lineEnd: lineEnd,
  3314. polygonStart: function() {
  3315. clip.point = pointRing;
  3316. clip.lineStart = ringStart;
  3317. clip.lineEnd = ringEnd;
  3318. segments = [];
  3319. polygon = [];
  3320. },
  3321. polygonEnd: function() {
  3322. clip.point = point;
  3323. clip.lineStart = lineStart;
  3324. clip.lineEnd = lineEnd;
  3325. segments = d3.merge(segments);
  3326. var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
  3327. if (segments.length) {
  3328. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3329. d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
  3330. } else if (clipStartInside) {
  3331. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3332. listener.lineStart();
  3333. interpolate(null, null, 1, listener);
  3334. listener.lineEnd();
  3335. }
  3336. if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
  3337. segments = polygon = null;
  3338. },
  3339. sphere: function() {
  3340. listener.polygonStart();
  3341. listener.lineStart();
  3342. interpolate(null, null, 1, listener);
  3343. listener.lineEnd();
  3344. listener.polygonEnd();
  3345. }
  3346. };
  3347. function point(λ, φ) {
  3348. var point = rotate(λ, φ);
  3349. if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
  3350. }
  3351. function pointLine(λ, φ) {
  3352. var point = rotate(λ, φ);
  3353. line.point(point[0], point[1]);
  3354. }
  3355. function lineStart() {
  3356. clip.point = pointLine;
  3357. line.lineStart();
  3358. }
  3359. function lineEnd() {
  3360. clip.point = point;
  3361. line.lineEnd();
  3362. }
  3363. var segments;
  3364. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
  3365. function pointRing(λ, φ) {
  3366. ring.push([ λ, φ ]);
  3367. var point = rotate(λ, φ);
  3368. ringListener.point(point[0], point[1]);
  3369. }
  3370. function ringStart() {
  3371. ringListener.lineStart();
  3372. ring = [];
  3373. }
  3374. function ringEnd() {
  3375. pointRing(ring[0][0], ring[0][1]);
  3376. ringListener.lineEnd();
  3377. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  3378. ring.pop();
  3379. polygon.push(ring);
  3380. ring = null;
  3381. if (!n) return;
  3382. if (clean & 1) {
  3383. segment = ringSegments[0];
  3384. var n = segment.length - 1, i = -1, point;
  3385. if (n > 0) {
  3386. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3387. listener.lineStart();
  3388. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  3389. listener.lineEnd();
  3390. }
  3391. return;
  3392. }
  3393. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  3394. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  3395. }
  3396. return clip;
  3397. };
  3398. }
  3399. function d3_geo_clipSegmentLength1(segment) {
  3400. return segment.length > 1;
  3401. }
  3402. function d3_geo_clipBufferListener() {
  3403. var lines = [], line;
  3404. return {
  3405. lineStart: function() {
  3406. lines.push(line = []);
  3407. },
  3408. point: function(λ, φ) {
  3409. line.push([ λ, φ ]);
  3410. },
  3411. lineEnd: d3_noop,
  3412. buffer: function() {
  3413. var buffer = lines;
  3414. lines = [];
  3415. line = null;
  3416. return buffer;
  3417. },
  3418. rejoin: function() {
  3419. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  3420. }
  3421. };
  3422. }
  3423. function d3_geo_clipSort(a, b) {
  3424. return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
  3425. }
  3426. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
  3427. function d3_geo_clipAntimeridianLine(listener) {
  3428. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  3429. return {
  3430. lineStart: function() {
  3431. listener.lineStart();
  3432. clean = 1;
  3433. },
  3434. point: function(λ1, φ1) {
  3435. var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
  3436. if (abs(dλ - π) < ε) {
  3437. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
  3438. listener.point(sλ0, φ0);
  3439. listener.lineEnd();
  3440. listener.lineStart();
  3441. listener.point(sλ1, φ0);
  3442. listener.point(λ1, φ0);
  3443. clean = 0;
  3444. } else if (sλ0 !== sλ1 && dλ >= π) {
  3445. if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  3446. if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  3447. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  3448. listener.point(sλ0, φ0);
  3449. listener.lineEnd();
  3450. listener.lineStart();
  3451. listener.point(sλ1, φ0);
  3452. clean = 0;
  3453. }
  3454. listener.point(λ0 = λ1, φ0 = φ1);
  3455. sλ0 = sλ1;
  3456. },
  3457. lineEnd: function() {
  3458. listener.lineEnd();
  3459. λ0 = φ0 = NaN;
  3460. },
  3461. clean: function() {
  3462. return 2 - clean;
  3463. }
  3464. };
  3465. }
  3466. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  3467. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  3468. return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
  3469. }
  3470. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  3471. var φ;
  3472. if (from == null) {
  3473. φ = direction * halfπ;
  3474. listener.point(-π, φ);
  3475. listener.point(0, φ);
  3476. listener.point(π, φ);
  3477. listener.point(π, 0);
  3478. listener.point(π, -φ);
  3479. listener.point(0, -φ);
  3480. listener.point(-π, -φ);
  3481. listener.point(-π, 0);
  3482. listener.point(-π, φ);
  3483. } else if (abs(from[0] - to[0]) > ε) {
  3484. var s = from[0] < to[0] ? π : -π;
  3485. φ = direction * s / 2;
  3486. listener.point(-s, φ);
  3487. listener.point(0, φ);
  3488. listener.point(s, φ);
  3489. } else {
  3490. listener.point(to[0], to[1]);
  3491. }
  3492. }
  3493. function d3_geo_pointInPolygon(point, polygon) {
  3494. var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
  3495. d3_geo_areaRingSum.reset();
  3496. for (var i = 0, n = polygon.length; i < n; ++i) {
  3497. var ring = polygon[i], m = ring.length;
  3498. if (!m) continue;
  3499. var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
  3500. while (true) {
  3501. if (j === m) j = 0;
  3502. point = ring[j];
  3503. var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;
  3504. d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
  3505. polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
  3506. if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
  3507. var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
  3508. d3_geo_cartesianNormalize(arc);
  3509. var intersection = d3_geo_cartesianCross(meridianNormal, arc);
  3510. d3_geo_cartesianNormalize(intersection);
  3511. var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
  3512. if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
  3513. winding += antimeridian ^ dλ >= 0 ? 1 : -1;
  3514. }
  3515. }
  3516. if (!j++) break;
  3517. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
  3518. }
  3519. }
  3520. return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
  3521. }
  3522. function d3_geo_clipCircle(radius) {
  3523. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  3524. return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
  3525. function visible(λ, φ) {
  3526. return Math.cos(λ) * Math.cos(φ) > cr;
  3527. }
  3528. function clipLine(listener) {
  3529. var point0, c0, v0, v00, clean;
  3530. return {
  3531. lineStart: function() {
  3532. v00 = v0 = false;
  3533. clean = 1;
  3534. },
  3535. point: function(λ, φ) {
  3536. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  3537. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  3538. if (v !== v0) {
  3539. point2 = intersect(point0, point1);
  3540. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  3541. point1[0] += ε;
  3542. point1[1] += ε;
  3543. v = visible(point1[0], point1[1]);
  3544. }
  3545. }
  3546. if (v !== v0) {
  3547. clean = 0;
  3548. if (v) {
  3549. listener.lineStart();
  3550. point2 = intersect(point1, point0);
  3551. listener.point(point2[0], point2[1]);
  3552. } else {
  3553. point2 = intersect(point0, point1);
  3554. listener.point(point2[0], point2[1]);
  3555. listener.lineEnd();
  3556. }
  3557. point0 = point2;
  3558. } else if (notHemisphere && point0 && smallRadius ^ v) {
  3559. var t;
  3560. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  3561. clean = 0;
  3562. if (smallRadius) {
  3563. listener.lineStart();
  3564. listener.point(t[0][0], t[0][1]);
  3565. listener.point(t[1][0], t[1][1]);
  3566. listener.lineEnd();
  3567. } else {
  3568. listener.point(t[1][0], t[1][1]);
  3569. listener.lineEnd();
  3570. listener.lineStart();
  3571. listener.point(t[0][0], t[0][1]);
  3572. }
  3573. }
  3574. }
  3575. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  3576. listener.point(point1[0], point1[1]);
  3577. }
  3578. point0 = point1, v0 = v, c0 = c;
  3579. },
  3580. lineEnd: function() {
  3581. if (v0) listener.lineEnd();
  3582. point0 = null;
  3583. },
  3584. clean: function() {
  3585. return clean | (v00 && v0) << 1;
  3586. }
  3587. };
  3588. }
  3589. function intersect(a, b, two) {
  3590. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  3591. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  3592. if (!determinant) return !two && a;
  3593. var c1 = cr * n2n2 / determinant, c2 = -cr * n1n2 / determinant, n1xn2 = d3_geo_cartesianCross(n1, n2), A = d3_geo_cartesianScale(n1, c1), B = d3_geo_cartesianScale(n2, c2);
  3594. d3_geo_cartesianAdd(A, B);
  3595. var u = n1xn2, w = d3_geo_cartesianDot(A, u), uu = d3_geo_cartesianDot(u, u), t2 = w * w - uu * (d3_geo_cartesianDot(A, A) - 1);
  3596. if (t2 < 0) return;
  3597. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  3598. d3_geo_cartesianAdd(q, A);
  3599. q = d3_geo_spherical(q);
  3600. if (!two) return q;
  3601. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  3602. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  3603. var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
  3604. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  3605. if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
  3606. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  3607. d3_geo_cartesianAdd(q1, A);
  3608. return [ q, d3_geo_spherical(q1) ];
  3609. }
  3610. }
  3611. function code(λ, φ) {
  3612. var r = smallRadius ? radius : π - radius, code = 0;
  3613. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  3614. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  3615. return code;
  3616. }
  3617. }
  3618. function d3_geom_clipLine(x0, y0, x1, y1) {
  3619. return function(line) {
  3620. var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
  3621. r = x0 - ax;
  3622. if (!dx && r > 0) return;
  3623. r /= dx;
  3624. if (dx < 0) {
  3625. if (r < t0) return;
  3626. if (r < t1) t1 = r;
  3627. } else if (dx > 0) {
  3628. if (r > t1) return;
  3629. if (r > t0) t0 = r;
  3630. }
  3631. r = x1 - ax;
  3632. if (!dx && r < 0) return;
  3633. r /= dx;
  3634. if (dx < 0) {
  3635. if (r > t1) return;
  3636. if (r > t0) t0 = r;
  3637. } else if (dx > 0) {
  3638. if (r < t0) return;
  3639. if (r < t1) t1 = r;
  3640. }
  3641. r = y0 - ay;
  3642. if (!dy && r > 0) return;
  3643. r /= dy;
  3644. if (dy < 0) {
  3645. if (r < t0) return;
  3646. if (r < t1) t1 = r;
  3647. } else if (dy > 0) {
  3648. if (r > t1) return;
  3649. if (r > t0) t0 = r;
  3650. }
  3651. r = y1 - ay;
  3652. if (!dy && r < 0) return;
  3653. r /= dy;
  3654. if (dy < 0) {
  3655. if (r > t1) return;
  3656. if (r > t0) t0 = r;
  3657. } else if (dy > 0) {
  3658. if (r < t0) return;
  3659. if (r < t1) t1 = r;
  3660. }
  3661. if (t0 > 0) line.a = {
  3662. x: ax + t0 * dx,
  3663. y: ay + t0 * dy
  3664. };
  3665. if (t1 < 1) line.b = {
  3666. x: ax + t1 * dx,
  3667. y: ay + t1 * dy
  3668. };
  3669. return line;
  3670. };
  3671. }
  3672. var d3_geo_clipExtentMAX = 1e9;
  3673. d3.geo.clipExtent = function() {
  3674. var x0, y0, x1, y1, stream, clip, clipExtent = {
  3675. stream: function(output) {
  3676. if (stream) stream.valid = false;
  3677. stream = clip(output);
  3678. stream.valid = true;
  3679. return stream;
  3680. },
  3681. extent: function(_) {
  3682. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3683. clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
  3684. if (stream) stream.valid = false, stream = null;
  3685. return clipExtent;
  3686. }
  3687. };
  3688. return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
  3689. };
  3690. function d3_geo_clipExtent(x0, y0, x1, y1) {
  3691. return function(listener) {
  3692. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
  3693. var clip = {
  3694. point: point,
  3695. lineStart: lineStart,
  3696. lineEnd: lineEnd,
  3697. polygonStart: function() {
  3698. listener = bufferListener;
  3699. segments = [];
  3700. polygon = [];
  3701. clean = true;
  3702. },
  3703. polygonEnd: function() {
  3704. listener = listener_;
  3705. segments = d3.merge(segments);
  3706. var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
  3707. if (inside || visible) {
  3708. listener.polygonStart();
  3709. if (inside) {
  3710. listener.lineStart();
  3711. interpolate(null, null, 1, listener);
  3712. listener.lineEnd();
  3713. }
  3714. if (visible) {
  3715. d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
  3716. }
  3717. listener.polygonEnd();
  3718. }
  3719. segments = polygon = ring = null;
  3720. }
  3721. };
  3722. function insidePolygon(p) {
  3723. var wn = 0, n = polygon.length, y = p[1];
  3724. for (var i = 0; i < n; ++i) {
  3725. for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
  3726. b = v[j];
  3727. if (a[1] <= y) {
  3728. if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
  3729. } else {
  3730. if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
  3731. }
  3732. a = b;
  3733. }
  3734. }
  3735. return wn !== 0;
  3736. }
  3737. function interpolate(from, to, direction, listener) {
  3738. var a = 0, a1 = 0;
  3739. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  3740. do {
  3741. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  3742. } while ((a = (a + direction + 4) % 4) !== a1);
  3743. } else {
  3744. listener.point(to[0], to[1]);
  3745. }
  3746. }
  3747. function pointVisible(x, y) {
  3748. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  3749. }
  3750. function point(x, y) {
  3751. if (pointVisible(x, y)) listener.point(x, y);
  3752. }
  3753. var x__, y__, v__, x_, y_, v_, first, clean;
  3754. function lineStart() {
  3755. clip.point = linePoint;
  3756. if (polygon) polygon.push(ring = []);
  3757. first = true;
  3758. v_ = false;
  3759. x_ = y_ = NaN;
  3760. }
  3761. function lineEnd() {
  3762. if (segments) {
  3763. linePoint(x__, y__);
  3764. if (v__ && v_) bufferListener.rejoin();
  3765. segments.push(bufferListener.buffer());
  3766. }
  3767. clip.point = point;
  3768. if (v_) listener.lineEnd();
  3769. }
  3770. function linePoint(x, y) {
  3771. x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
  3772. y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
  3773. var v = pointVisible(x, y);
  3774. if (polygon) ring.push([ x, y ]);
  3775. if (first) {
  3776. x__ = x, y__ = y, v__ = v;
  3777. first = false;
  3778. if (v) {
  3779. listener.lineStart();
  3780. listener.point(x, y);
  3781. }
  3782. } else {
  3783. if (v && v_) listener.point(x, y); else {
  3784. var l = {
  3785. a: {
  3786. x: x_,
  3787. y: y_
  3788. },
  3789. b: {
  3790. x: x,
  3791. y: y
  3792. }
  3793. };
  3794. if (clipLine(l)) {
  3795. if (!v_) {
  3796. listener.lineStart();
  3797. listener.point(l.a.x, l.a.y);
  3798. }
  3799. listener.point(l.b.x, l.b.y);
  3800. if (!v) listener.lineEnd();
  3801. clean = false;
  3802. } else if (v) {
  3803. listener.lineStart();
  3804. listener.point(x, y);
  3805. clean = false;
  3806. }
  3807. }
  3808. }
  3809. x_ = x, y_ = y, v_ = v;
  3810. }
  3811. return clip;
  3812. };
  3813. function corner(p, direction) {
  3814. return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
  3815. }
  3816. function compare(a, b) {
  3817. return comparePoints(a.x, b.x);
  3818. }
  3819. function comparePoints(a, b) {
  3820. var ca = corner(a, 1), cb = corner(b, 1);
  3821. return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
  3822. }
  3823. }
  3824. function d3_geo_conic(projectAt) {
  3825. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  3826. p.parallels = function(_) {
  3827. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  3828. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  3829. };
  3830. return p;
  3831. }
  3832. function d3_geo_conicEqualArea(φ0, φ1) {
  3833. var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
  3834. function forward(λ, φ) {
  3835. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  3836. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  3837. }
  3838. forward.invert = function(x, y) {
  3839. var ρ0_y = ρ0 - y;
  3840. return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  3841. };
  3842. return forward;
  3843. }
  3844. (d3.geo.conicEqualArea = function() {
  3845. return d3_geo_conic(d3_geo_conicEqualArea);
  3846. }).raw = d3_geo_conicEqualArea;
  3847. d3.geo.albers = function() {
  3848. return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
  3849. };
  3850. d3.geo.albersUsa = function() {
  3851. var lower48 = d3.geo.albers();
  3852. var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
  3853. var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
  3854. var point, pointStream = {
  3855. point: function(x, y) {
  3856. point = [ x, y ];
  3857. }
  3858. }, lower48Point, alaskaPoint, hawaiiPoint;
  3859. function albersUsa(coordinates) {
  3860. var x = coordinates[0], y = coordinates[1];
  3861. point = null;
  3862. (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
  3863. return point;
  3864. }
  3865. albersUsa.invert = function(coordinates) {
  3866. var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
  3867. return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
  3868. };
  3869. albersUsa.stream = function(stream) {
  3870. var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
  3871. return {
  3872. point: function(x, y) {
  3873. lower48Stream.point(x, y);
  3874. alaskaStream.point(x, y);
  3875. hawaiiStream.point(x, y);
  3876. },
  3877. sphere: function() {
  3878. lower48Stream.sphere();
  3879. alaskaStream.sphere();
  3880. hawaiiStream.sphere();
  3881. },
  3882. lineStart: function() {
  3883. lower48Stream.lineStart();
  3884. alaskaStream.lineStart();
  3885. hawaiiStream.lineStart();
  3886. },
  3887. lineEnd: function() {
  3888. lower48Stream.lineEnd();
  3889. alaskaStream.lineEnd();
  3890. hawaiiStream.lineEnd();
  3891. },
  3892. polygonStart: function() {
  3893. lower48Stream.polygonStart();
  3894. alaskaStream.polygonStart();
  3895. hawaiiStream.polygonStart();
  3896. },
  3897. polygonEnd: function() {
  3898. lower48Stream.polygonEnd();
  3899. alaskaStream.polygonEnd();
  3900. hawaiiStream.polygonEnd();
  3901. }
  3902. };
  3903. };
  3904. albersUsa.precision = function(_) {
  3905. if (!arguments.length) return lower48.precision();
  3906. lower48.precision(_);
  3907. alaska.precision(_);
  3908. hawaii.precision(_);
  3909. return albersUsa;
  3910. };
  3911. albersUsa.scale = function(_) {
  3912. if (!arguments.length) return lower48.scale();
  3913. lower48.scale(_);
  3914. alaska.scale(_ * .35);
  3915. hawaii.scale(_);
  3916. return albersUsa.translate(lower48.translate());
  3917. };
  3918. albersUsa.translate = function(_) {
  3919. if (!arguments.length) return lower48.translate();
  3920. var k = lower48.scale(), x = +_[0], y = +_[1];
  3921. lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
  3922. alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
  3923. hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
  3924. return albersUsa;
  3925. };
  3926. return albersUsa.scale(1070);
  3927. };
  3928. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  3929. point: d3_noop,
  3930. lineStart: d3_noop,
  3931. lineEnd: d3_noop,
  3932. polygonStart: function() {
  3933. d3_geo_pathAreaPolygon = 0;
  3934. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  3935. },
  3936. polygonEnd: function() {
  3937. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  3938. d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
  3939. }
  3940. };
  3941. function d3_geo_pathAreaRingStart() {
  3942. var x00, y00, x0, y0;
  3943. d3_geo_pathArea.point = function(x, y) {
  3944. d3_geo_pathArea.point = nextPoint;
  3945. x00 = x0 = x, y00 = y0 = y;
  3946. };
  3947. function nextPoint(x, y) {
  3948. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  3949. x0 = x, y0 = y;
  3950. }
  3951. d3_geo_pathArea.lineEnd = function() {
  3952. nextPoint(x00, y00);
  3953. };
  3954. }
  3955. var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
  3956. var d3_geo_pathBounds = {
  3957. point: d3_geo_pathBoundsPoint,
  3958. lineStart: d3_noop,
  3959. lineEnd: d3_noop,
  3960. polygonStart: d3_noop,
  3961. polygonEnd: d3_noop
  3962. };
  3963. function d3_geo_pathBoundsPoint(x, y) {
  3964. if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
  3965. if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
  3966. if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
  3967. if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
  3968. }
  3969. function d3_geo_pathBuffer() {
  3970. var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
  3971. var stream = {
  3972. point: point,
  3973. lineStart: function() {
  3974. stream.point = pointLineStart;
  3975. },
  3976. lineEnd: lineEnd,
  3977. polygonStart: function() {
  3978. stream.lineEnd = lineEndPolygon;
  3979. },
  3980. polygonEnd: function() {
  3981. stream.lineEnd = lineEnd;
  3982. stream.point = point;
  3983. },
  3984. pointRadius: function(_) {
  3985. pointCircle = d3_geo_pathBufferCircle(_);
  3986. return stream;
  3987. },
  3988. result: function() {
  3989. if (buffer.length) {
  3990. var result = buffer.join("");
  3991. buffer = [];
  3992. return result;
  3993. }
  3994. }
  3995. };
  3996. function point(x, y) {
  3997. buffer.push("M", x, ",", y, pointCircle);
  3998. }
  3999. function pointLineStart(x, y) {
  4000. buffer.push("M", x, ",", y);
  4001. stream.point = pointLine;
  4002. }
  4003. function pointLine(x, y) {
  4004. buffer.push("L", x, ",", y);
  4005. }
  4006. function lineEnd() {
  4007. stream.point = point;
  4008. }
  4009. function lineEndPolygon() {
  4010. buffer.push("Z");
  4011. }
  4012. return stream;
  4013. }
  4014. function d3_geo_pathBufferCircle(radius) {
  4015. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
  4016. }
  4017. var d3_geo_pathCentroid = {
  4018. point: d3_geo_pathCentroidPoint,
  4019. lineStart: d3_geo_pathCentroidLineStart,
  4020. lineEnd: d3_geo_pathCentroidLineEnd,
  4021. polygonStart: function() {
  4022. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  4023. },
  4024. polygonEnd: function() {
  4025. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4026. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  4027. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  4028. }
  4029. };
  4030. function d3_geo_pathCentroidPoint(x, y) {
  4031. d3_geo_centroidX0 += x;
  4032. d3_geo_centroidY0 += y;
  4033. ++d3_geo_centroidZ0;
  4034. }
  4035. function d3_geo_pathCentroidLineStart() {
  4036. var x0, y0;
  4037. d3_geo_pathCentroid.point = function(x, y) {
  4038. d3_geo_pathCentroid.point = nextPoint;
  4039. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4040. };
  4041. function nextPoint(x, y) {
  4042. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4043. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4044. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4045. d3_geo_centroidZ1 += z;
  4046. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4047. }
  4048. }
  4049. function d3_geo_pathCentroidLineEnd() {
  4050. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4051. }
  4052. function d3_geo_pathCentroidRingStart() {
  4053. var x00, y00, x0, y0;
  4054. d3_geo_pathCentroid.point = function(x, y) {
  4055. d3_geo_pathCentroid.point = nextPoint;
  4056. d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
  4057. };
  4058. function nextPoint(x, y) {
  4059. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4060. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4061. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4062. d3_geo_centroidZ1 += z;
  4063. z = y0 * x - x0 * y;
  4064. d3_geo_centroidX2 += z * (x0 + x);
  4065. d3_geo_centroidY2 += z * (y0 + y);
  4066. d3_geo_centroidZ2 += z * 3;
  4067. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4068. }
  4069. d3_geo_pathCentroid.lineEnd = function() {
  4070. nextPoint(x00, y00);
  4071. };
  4072. }
  4073. function d3_geo_pathContext(context) {
  4074. var pointRadius = 4.5;
  4075. var stream = {
  4076. point: point,
  4077. lineStart: function() {
  4078. stream.point = pointLineStart;
  4079. },
  4080. lineEnd: lineEnd,
  4081. polygonStart: function() {
  4082. stream.lineEnd = lineEndPolygon;
  4083. },
  4084. polygonEnd: function() {
  4085. stream.lineEnd = lineEnd;
  4086. stream.point = point;
  4087. },
  4088. pointRadius: function(_) {
  4089. pointRadius = _;
  4090. return stream;
  4091. },
  4092. result: d3_noop
  4093. };
  4094. function point(x, y) {
  4095. context.moveTo(x + pointRadius, y);
  4096. context.arc(x, y, pointRadius, 0, τ);
  4097. }
  4098. function pointLineStart(x, y) {
  4099. context.moveTo(x, y);
  4100. stream.point = pointLine;
  4101. }
  4102. function pointLine(x, y) {
  4103. context.lineTo(x, y);
  4104. }
  4105. function lineEnd() {
  4106. stream.point = point;
  4107. }
  4108. function lineEndPolygon() {
  4109. context.closePath();
  4110. }
  4111. return stream;
  4112. }
  4113. function d3_geo_resample(project) {
  4114. var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
  4115. function resample(stream) {
  4116. return (maxDepth ? resampleRecursive : resampleNone)(stream);
  4117. }
  4118. function resampleNone(stream) {
  4119. return d3_geo_transformPoint(stream, function(x, y) {
  4120. x = project(x, y);
  4121. stream.point(x[0], x[1]);
  4122. });
  4123. }
  4124. function resampleRecursive(stream) {
  4125. var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
  4126. var resample = {
  4127. point: point,
  4128. lineStart: lineStart,
  4129. lineEnd: lineEnd,
  4130. polygonStart: function() {
  4131. stream.polygonStart();
  4132. resample.lineStart = ringStart;
  4133. },
  4134. polygonEnd: function() {
  4135. stream.polygonEnd();
  4136. resample.lineStart = lineStart;
  4137. }
  4138. };
  4139. function point(x, y) {
  4140. x = project(x, y);
  4141. stream.point(x[0], x[1]);
  4142. }
  4143. function lineStart() {
  4144. x0 = NaN;
  4145. resample.point = linePoint;
  4146. stream.lineStart();
  4147. }
  4148. function linePoint(λ, φ) {
  4149. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  4150. resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
  4151. stream.point(x0, y0);
  4152. }
  4153. function lineEnd() {
  4154. resample.point = point;
  4155. stream.lineEnd();
  4156. }
  4157. function ringStart() {
  4158. lineStart();
  4159. resample.point = ringPoint;
  4160. resample.lineEnd = ringEnd;
  4161. }
  4162. function ringPoint(λ, φ) {
  4163. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  4164. resample.point = linePoint;
  4165. }
  4166. function ringEnd() {
  4167. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  4168. resample.lineEnd = lineEnd;
  4169. lineEnd();
  4170. }
  4171. return resample;
  4172. }
  4173. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  4174. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  4175. if (d2 > 4 * δ2 && depth--) {
  4176. var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = abs(abs(c) - 1) < ε || abs(λ0 - λ1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
  4177. if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
  4178. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  4179. stream.point(x2, y2);
  4180. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  4181. }
  4182. }
  4183. }
  4184. resample.precision = function(_) {
  4185. if (!arguments.length) return Math.sqrt(δ2);
  4186. maxDepth = (δ2 = _ * _) > 0 && 16;
  4187. return resample;
  4188. };
  4189. return resample;
  4190. }
  4191. d3.geo.path = function() {
  4192. var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
  4193. function path(object) {
  4194. if (object) {
  4195. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  4196. if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
  4197. d3.geo.stream(object, cacheStream);
  4198. }
  4199. return contextStream.result();
  4200. }
  4201. path.area = function(object) {
  4202. d3_geo_pathAreaSum = 0;
  4203. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  4204. return d3_geo_pathAreaSum;
  4205. };
  4206. path.centroid = function(object) {
  4207. d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
  4208. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  4209. return d3_geo_centroidZ2 ? [ d3_geo_centroidX2 / d3_geo_centroidZ2, d3_geo_centroidY2 / d3_geo_centroidZ2 ] : d3_geo_centroidZ1 ? [ d3_geo_centroidX1 / d3_geo_centroidZ1, d3_geo_centroidY1 / d3_geo_centroidZ1 ] : d3_geo_centroidZ0 ? [ d3_geo_centroidX0 / d3_geo_centroidZ0, d3_geo_centroidY0 / d3_geo_centroidZ0 ] : [ NaN, NaN ];
  4210. };
  4211. path.bounds = function(object) {
  4212. d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
  4213. d3.geo.stream(object, projectStream(d3_geo_pathBounds));
  4214. return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
  4215. };
  4216. path.projection = function(_) {
  4217. if (!arguments.length) return projection;
  4218. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  4219. return reset();
  4220. };
  4221. path.context = function(_) {
  4222. if (!arguments.length) return context;
  4223. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  4224. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  4225. return reset();
  4226. };
  4227. path.pointRadius = function(_) {
  4228. if (!arguments.length) return pointRadius;
  4229. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  4230. return path;
  4231. };
  4232. function reset() {
  4233. cacheStream = null;
  4234. return path;
  4235. }
  4236. return path.projection(d3.geo.albersUsa()).context(null);
  4237. };
  4238. function d3_geo_pathProjectStream(project) {
  4239. var resample = d3_geo_resample(function(x, y) {
  4240. return project([ x * d3_degrees, y * d3_degrees ]);
  4241. });
  4242. return function(stream) {
  4243. return d3_geo_projectionRadians(resample(stream));
  4244. };
  4245. }
  4246. d3.geo.transform = function(methods) {
  4247. return {
  4248. stream: function(stream) {
  4249. var transform = new d3_geo_transform(stream);
  4250. for (var k in methods) transform[k] = methods[k];
  4251. return transform;
  4252. }
  4253. };
  4254. };
  4255. function d3_geo_transform(stream) {
  4256. this.stream = stream;
  4257. }
  4258. d3_geo_transform.prototype = {
  4259. point: function(x, y) {
  4260. this.stream.point(x, y);
  4261. },
  4262. sphere: function() {
  4263. this.stream.sphere();
  4264. },
  4265. lineStart: function() {
  4266. this.stream.lineStart();
  4267. },
  4268. lineEnd: function() {
  4269. this.stream.lineEnd();
  4270. },
  4271. polygonStart: function() {
  4272. this.stream.polygonStart();
  4273. },
  4274. polygonEnd: function() {
  4275. this.stream.polygonEnd();
  4276. }
  4277. };
  4278. function d3_geo_transformPoint(stream, point) {
  4279. return {
  4280. point: point,
  4281. sphere: function() {
  4282. stream.sphere();
  4283. },
  4284. lineStart: function() {
  4285. stream.lineStart();
  4286. },
  4287. lineEnd: function() {
  4288. stream.lineEnd();
  4289. },
  4290. polygonStart: function() {
  4291. stream.polygonStart();
  4292. },
  4293. polygonEnd: function() {
  4294. stream.polygonEnd();
  4295. }
  4296. };
  4297. }
  4298. d3.geo.projection = d3_geo_projection;
  4299. d3.geo.projectionMutator = d3_geo_projectionMutator;
  4300. function d3_geo_projection(project) {
  4301. return d3_geo_projectionMutator(function() {
  4302. return project;
  4303. })();
  4304. }
  4305. function d3_geo_projectionMutator(projectAt) {
  4306. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  4307. x = project(x, y);
  4308. return [ x[0] * k + δx, δy - x[1] * k ];
  4309. }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null, stream;
  4310. function projection(point) {
  4311. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  4312. return [ point[0] * k + δx, δy - point[1] * k ];
  4313. }
  4314. function invert(point) {
  4315. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  4316. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  4317. }
  4318. projection.stream = function(output) {
  4319. if (stream) stream.valid = false;
  4320. stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
  4321. stream.valid = true;
  4322. return stream;
  4323. };
  4324. projection.clipAngle = function(_) {
  4325. if (!arguments.length) return clipAngle;
  4326. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  4327. return invalidate();
  4328. };
  4329. projection.clipExtent = function(_) {
  4330. if (!arguments.length) return clipExtent;
  4331. clipExtent = _;
  4332. postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
  4333. return invalidate();
  4334. };
  4335. projection.scale = function(_) {
  4336. if (!arguments.length) return k;
  4337. k = +_;
  4338. return reset();
  4339. };
  4340. projection.translate = function(_) {
  4341. if (!arguments.length) return [ x, y ];
  4342. x = +_[0];
  4343. y = +_[1];
  4344. return reset();
  4345. };
  4346. projection.center = function(_) {
  4347. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  4348. λ = _[0] % 360 * d3_radians;
  4349. φ = _[1] % 360 * d3_radians;
  4350. return reset();
  4351. };
  4352. projection.rotate = function(_) {
  4353. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  4354. δλ = _[0] % 360 * d3_radians;
  4355. δφ = _[1] % 360 * d3_radians;
  4356. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  4357. return reset();
  4358. };
  4359. d3.rebind(projection, projectResample, "precision");
  4360. function reset() {
  4361. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  4362. var center = project(λ, φ);
  4363. δx = x - center[0] * k;
  4364. δy = y + center[1] * k;
  4365. return invalidate();
  4366. }
  4367. function invalidate() {
  4368. if (stream) stream.valid = false, stream = null;
  4369. return projection;
  4370. }
  4371. return function() {
  4372. project = projectAt.apply(this, arguments);
  4373. projection.invert = project.invert && invert;
  4374. return reset();
  4375. };
  4376. }
  4377. function d3_geo_projectionRadians(stream) {
  4378. return d3_geo_transformPoint(stream, function(x, y) {
  4379. stream.point(x * d3_radians, y * d3_radians);
  4380. });
  4381. }
  4382. function d3_geo_equirectangular(λ, φ) {
  4383. return [ λ, φ ];
  4384. }
  4385. (d3.geo.equirectangular = function() {
  4386. return d3_geo_projection(d3_geo_equirectangular);
  4387. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  4388. d3.geo.rotation = function(rotate) {
  4389. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  4390. function forward(coordinates) {
  4391. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4392. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4393. }
  4394. forward.invert = function(coordinates) {
  4395. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4396. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4397. };
  4398. return forward;
  4399. };
  4400. function d3_geo_identityRotation(λ, φ) {
  4401. return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4402. }
  4403. d3_geo_identityRotation.invert = d3_geo_equirectangular;
  4404. function d3_geo_rotation(δλ, δφ, δγ) {
  4405. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
  4406. }
  4407. function d3_geo_forwardRotationλ(δλ) {
  4408. return function(λ, φ) {
  4409. return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4410. };
  4411. }
  4412. function d3_geo_rotationλ(δλ) {
  4413. var rotation = d3_geo_forwardRotationλ(δλ);
  4414. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  4415. return rotation;
  4416. }
  4417. function d3_geo_rotationφγ(δφ, δγ) {
  4418. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  4419. function rotation(λ, φ) {
  4420. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  4421. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
  4422. }
  4423. rotation.invert = function(λ, φ) {
  4424. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  4425. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
  4426. };
  4427. return rotation;
  4428. }
  4429. d3.geo.circle = function() {
  4430. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  4431. function circle() {
  4432. var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert, ring = [];
  4433. interpolate(null, null, 1, {
  4434. point: function(x, y) {
  4435. ring.push(x = rotate(x, y));
  4436. x[0] *= d3_degrees, x[1] *= d3_degrees;
  4437. }
  4438. });
  4439. return {
  4440. type: "Polygon",
  4441. coordinates: [ ring ]
  4442. };
  4443. }
  4444. circle.origin = function(x) {
  4445. if (!arguments.length) return origin;
  4446. origin = x;
  4447. return circle;
  4448. };
  4449. circle.angle = function(x) {
  4450. if (!arguments.length) return angle;
  4451. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  4452. return circle;
  4453. };
  4454. circle.precision = function(_) {
  4455. if (!arguments.length) return precision;
  4456. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  4457. return circle;
  4458. };
  4459. return circle.angle(90);
  4460. };
  4461. function d3_geo_circleInterpolate(radius, precision) {
  4462. var cr = Math.cos(radius), sr = Math.sin(radius);
  4463. return function(from, to, direction, listener) {
  4464. var step = direction * precision;
  4465. if (from != null) {
  4466. from = d3_geo_circleAngle(cr, from);
  4467. to = d3_geo_circleAngle(cr, to);
  4468. if (direction > 0 ? from < to : from > to) from += direction * τ;
  4469. } else {
  4470. from = radius + direction * τ;
  4471. to = radius - .5 * step;
  4472. }
  4473. for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
  4474. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  4475. }
  4476. };
  4477. }
  4478. function d3_geo_circleAngle(cr, point) {
  4479. var a = d3_geo_cartesian(point);
  4480. a[0] -= cr;
  4481. d3_geo_cartesianNormalize(a);
  4482. var angle = d3_acos(-a[1]);
  4483. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  4484. }
  4485. d3.geo.distance = function(a, b) {
  4486. var Δλ = (b[0] - a[0]) * d3_radians, φ0 = a[1] * d3_radians, φ1 = b[1] * d3_radians, sinΔλ = Math.sin(Δλ), cosΔλ = Math.cos(Δλ), sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), t;
  4487. return Math.atan2(Math.sqrt((t = cosφ1 * sinΔλ) * t + (t = cosφ0 * sinφ1 - sinφ0 * cosφ1 * cosΔλ) * t), sinφ0 * sinφ1 + cosφ0 * cosφ1 * cosΔλ);
  4488. };
  4489. d3.geo.graticule = function() {
  4490. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  4491. function graticule() {
  4492. return {
  4493. type: "MultiLineString",
  4494. coordinates: lines()
  4495. };
  4496. }
  4497. function lines() {
  4498. return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) {
  4499. return abs(x % DX) > ε;
  4500. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  4501. return abs(y % DY) > ε;
  4502. }).map(y));
  4503. }
  4504. graticule.lines = function() {
  4505. return lines().map(function(coordinates) {
  4506. return {
  4507. type: "LineString",
  4508. coordinates: coordinates
  4509. };
  4510. });
  4511. };
  4512. graticule.outline = function() {
  4513. return {
  4514. type: "Polygon",
  4515. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  4516. };
  4517. };
  4518. graticule.extent = function(_) {
  4519. if (!arguments.length) return graticule.minorExtent();
  4520. return graticule.majorExtent(_).minorExtent(_);
  4521. };
  4522. graticule.majorExtent = function(_) {
  4523. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  4524. X0 = +_[0][0], X1 = +_[1][0];
  4525. Y0 = +_[0][1], Y1 = +_[1][1];
  4526. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  4527. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  4528. return graticule.precision(precision);
  4529. };
  4530. graticule.minorExtent = function(_) {
  4531. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  4532. x0 = +_[0][0], x1 = +_[1][0];
  4533. y0 = +_[0][1], y1 = +_[1][1];
  4534. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  4535. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  4536. return graticule.precision(precision);
  4537. };
  4538. graticule.step = function(_) {
  4539. if (!arguments.length) return graticule.minorStep();
  4540. return graticule.majorStep(_).minorStep(_);
  4541. };
  4542. graticule.majorStep = function(_) {
  4543. if (!arguments.length) return [ DX, DY ];
  4544. DX = +_[0], DY = +_[1];
  4545. return graticule;
  4546. };
  4547. graticule.minorStep = function(_) {
  4548. if (!arguments.length) return [ dx, dy ];
  4549. dx = +_[0], dy = +_[1];
  4550. return graticule;
  4551. };
  4552. graticule.precision = function(_) {
  4553. if (!arguments.length) return precision;
  4554. precision = +_;
  4555. x = d3_geo_graticuleX(y0, y1, 90);
  4556. y = d3_geo_graticuleY(x0, x1, precision);
  4557. X = d3_geo_graticuleX(Y0, Y1, 90);
  4558. Y = d3_geo_graticuleY(X0, X1, precision);
  4559. return graticule;
  4560. };
  4561. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  4562. };
  4563. function d3_geo_graticuleX(y0, y1, dy) {
  4564. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  4565. return function(x) {
  4566. return y.map(function(y) {
  4567. return [ x, y ];
  4568. });
  4569. };
  4570. }
  4571. function d3_geo_graticuleY(x0, x1, dx) {
  4572. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  4573. return function(y) {
  4574. return x.map(function(x) {
  4575. return [ x, y ];
  4576. });
  4577. };
  4578. }
  4579. function d3_source(d) {
  4580. return d.source;
  4581. }
  4582. function d3_target(d) {
  4583. return d.target;
  4584. }
  4585. d3.geo.greatArc = function() {
  4586. var source = d3_source, source_, target = d3_target, target_;
  4587. function greatArc() {
  4588. return {
  4589. type: "LineString",
  4590. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  4591. };
  4592. }
  4593. greatArc.distance = function() {
  4594. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  4595. };
  4596. greatArc.source = function(_) {
  4597. if (!arguments.length) return source;
  4598. source = _, source_ = typeof _ === "function" ? null : _;
  4599. return greatArc;
  4600. };
  4601. greatArc.target = function(_) {
  4602. if (!arguments.length) return target;
  4603. target = _, target_ = typeof _ === "function" ? null : _;
  4604. return greatArc;
  4605. };
  4606. greatArc.precision = function() {
  4607. return arguments.length ? greatArc : 0;
  4608. };
  4609. return greatArc;
  4610. };
  4611. d3.geo.interpolate = function(source, target) {
  4612. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  4613. };
  4614. function d3_geo_interpolate(x0, y0, x1, y1) {
  4615. var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = 2 * Math.asin(Math.sqrt(d3_haversin(y1 - y0) + cy0 * cy1 * d3_haversin(x1 - x0))), k = 1 / Math.sin(d);
  4616. var interpolate = d ? function(t) {
  4617. var B = Math.sin(t *= d) * k, A = Math.sin(d - t) * k, x = A * kx0 + B * kx1, y = A * ky0 + B * ky1, z = A * sy0 + B * sy1;
  4618. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  4619. } : function() {
  4620. return [ x0 * d3_degrees, y0 * d3_degrees ];
  4621. };
  4622. interpolate.distance = d;
  4623. return interpolate;
  4624. }
  4625. d3.geo.length = function(object) {
  4626. d3_geo_lengthSum = 0;
  4627. d3.geo.stream(object, d3_geo_length);
  4628. return d3_geo_lengthSum;
  4629. };
  4630. var d3_geo_lengthSum;
  4631. var d3_geo_length = {
  4632. sphere: d3_noop,
  4633. point: d3_noop,
  4634. lineStart: d3_geo_lengthLineStart,
  4635. lineEnd: d3_noop,
  4636. polygonStart: d3_noop,
  4637. polygonEnd: d3_noop
  4638. };
  4639. function d3_geo_lengthLineStart() {
  4640. var λ0, sinφ0, cosφ0;
  4641. d3_geo_length.point = function(λ, φ) {
  4642. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  4643. d3_geo_length.point = nextPoint;
  4644. };
  4645. d3_geo_length.lineEnd = function() {
  4646. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  4647. };
  4648. function nextPoint(λ, φ) {
  4649. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  4650. d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);
  4651. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  4652. }
  4653. }
  4654. function d3_geo_azimuthal(scale, angle) {
  4655. function azimuthal(λ, φ) {
  4656. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  4657. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  4658. }
  4659. azimuthal.invert = function(x, y) {
  4660. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  4661. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  4662. };
  4663. return azimuthal;
  4664. }
  4665. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  4666. return Math.sqrt(2 / (1 + cosλcosφ));
  4667. }, function(ρ) {
  4668. return 2 * Math.asin(ρ / 2);
  4669. });
  4670. (d3.geo.azimuthalEqualArea = function() {
  4671. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  4672. }).raw = d3_geo_azimuthalEqualArea;
  4673. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  4674. var c = Math.acos(cosλcosφ);
  4675. return c && c / Math.sin(c);
  4676. }, d3_identity);
  4677. (d3.geo.azimuthalEquidistant = function() {
  4678. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  4679. }).raw = d3_geo_azimuthalEquidistant;
  4680. function d3_geo_conicConformal(φ0, φ1) {
  4681. var cosφ0 = Math.cos(φ0), t = function(φ) {
  4682. return Math.tan(π / 4 + φ / 2);
  4683. }, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;
  4684. if (!n) return d3_geo_mercator;
  4685. function forward(λ, φ) {
  4686. if (F > 0) {
  4687. if (φ < -halfπ + ε) φ = -halfπ + ε;
  4688. } else {
  4689. if (φ > halfπ - ε) φ = halfπ - ε;
  4690. }
  4691. var ρ = F / Math.pow(t(φ), n);
  4692. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  4693. }
  4694. forward.invert = function(x, y) {
  4695. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  4696. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
  4697. };
  4698. return forward;
  4699. }
  4700. (d3.geo.conicConformal = function() {
  4701. return d3_geo_conic(d3_geo_conicConformal);
  4702. }).raw = d3_geo_conicConformal;
  4703. function d3_geo_conicEquidistant(φ0, φ1) {
  4704. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  4705. if (abs(n) < ε) return d3_geo_equirectangular;
  4706. function forward(λ, φ) {
  4707. var ρ = G - φ;
  4708. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  4709. }
  4710. forward.invert = function(x, y) {
  4711. var ρ0_y = G - y;
  4712. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  4713. };
  4714. return forward;
  4715. }
  4716. (d3.geo.conicEquidistant = function() {
  4717. return d3_geo_conic(d3_geo_conicEquidistant);
  4718. }).raw = d3_geo_conicEquidistant;
  4719. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  4720. return 1 / cosλcosφ;
  4721. }, Math.atan);
  4722. (d3.geo.gnomonic = function() {
  4723. return d3_geo_projection(d3_geo_gnomonic);
  4724. }).raw = d3_geo_gnomonic;
  4725. function d3_geo_mercator(λ, φ) {
  4726. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  4727. }
  4728. d3_geo_mercator.invert = function(x, y) {
  4729. return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
  4730. };
  4731. function d3_geo_mercatorProjection(project) {
  4732. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  4733. m.scale = function() {
  4734. var v = scale.apply(m, arguments);
  4735. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4736. };
  4737. m.translate = function() {
  4738. var v = translate.apply(m, arguments);
  4739. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4740. };
  4741. m.clipExtent = function(_) {
  4742. var v = clipExtent.apply(m, arguments);
  4743. if (v === m) {
  4744. if (clipAuto = _ == null) {
  4745. var k = π * scale(), t = translate();
  4746. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  4747. }
  4748. } else if (clipAuto) {
  4749. v = null;
  4750. }
  4751. return v;
  4752. };
  4753. return m.clipExtent(null);
  4754. }
  4755. (d3.geo.mercator = function() {
  4756. return d3_geo_mercatorProjection(d3_geo_mercator);
  4757. }).raw = d3_geo_mercator;
  4758. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  4759. return 1;
  4760. }, Math.asin);
  4761. (d3.geo.orthographic = function() {
  4762. return d3_geo_projection(d3_geo_orthographic);
  4763. }).raw = d3_geo_orthographic;
  4764. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  4765. return 1 / (1 + cosλcosφ);
  4766. }, function(ρ) {
  4767. return 2 * Math.atan(ρ);
  4768. });
  4769. (d3.geo.stereographic = function() {
  4770. return d3_geo_projection(d3_geo_stereographic);
  4771. }).raw = d3_geo_stereographic;
  4772. function d3_geo_transverseMercator(λ, φ) {
  4773. return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
  4774. }
  4775. d3_geo_transverseMercator.invert = function(x, y) {
  4776. return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
  4777. };
  4778. (d3.geo.transverseMercator = function() {
  4779. var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
  4780. projection.center = function(_) {
  4781. return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
  4782. };
  4783. projection.rotate = function(_) {
  4784. return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
  4785. [ _[0], _[1], _[2] - 90 ]);
  4786. };
  4787. return rotate([ 0, 0, 90 ]);
  4788. }).raw = d3_geo_transverseMercator;
  4789. d3.geom = {};
  4790. function d3_geom_pointX(d) {
  4791. return d[0];
  4792. }
  4793. function d3_geom_pointY(d) {
  4794. return d[1];
  4795. }
  4796. d3.geom.hull = function(vertices) {
  4797. var x = d3_geom_pointX, y = d3_geom_pointY;
  4798. if (arguments.length) return hull(vertices);
  4799. function hull(data) {
  4800. if (data.length < 3) return [];
  4801. var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
  4802. for (i = 0; i < n; i++) {
  4803. points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
  4804. }
  4805. points.sort(d3_geom_hullOrder);
  4806. for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
  4807. var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
  4808. var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
  4809. for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
  4810. for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
  4811. return polygon;
  4812. }
  4813. hull.x = function(_) {
  4814. return arguments.length ? (x = _, hull) : x;
  4815. };
  4816. hull.y = function(_) {
  4817. return arguments.length ? (y = _, hull) : y;
  4818. };
  4819. return hull;
  4820. };
  4821. function d3_geom_hullUpper(points) {
  4822. var n = points.length, hull = [ 0, 1 ], hs = 2;
  4823. for (var i = 2; i < n; i++) {
  4824. while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
  4825. hull[hs++] = i;
  4826. }
  4827. return hull.slice(0, hs);
  4828. }
  4829. function d3_geom_hullOrder(a, b) {
  4830. return a[0] - b[0] || a[1] - b[1];
  4831. }
  4832. d3.geom.polygon = function(coordinates) {
  4833. d3_subclass(coordinates, d3_geom_polygonPrototype);
  4834. return coordinates;
  4835. };
  4836. var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
  4837. d3_geom_polygonPrototype.area = function() {
  4838. var i = -1, n = this.length, a, b = this[n - 1], area = 0;
  4839. while (++i < n) {
  4840. a = b;
  4841. b = this[i];
  4842. area += a[1] * b[0] - a[0] * b[1];
  4843. }
  4844. return area * .5;
  4845. };
  4846. d3_geom_polygonPrototype.centroid = function(k) {
  4847. var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
  4848. if (!arguments.length) k = -1 / (6 * this.area());
  4849. while (++i < n) {
  4850. a = b;
  4851. b = this[i];
  4852. c = a[0] * b[1] - b[0] * a[1];
  4853. x += (a[0] + b[0]) * c;
  4854. y += (a[1] + b[1]) * c;
  4855. }
  4856. return [ x * k, y * k ];
  4857. };
  4858. d3_geom_polygonPrototype.clip = function(subject) {
  4859. var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d;
  4860. while (++i < n) {
  4861. input = subject.slice();
  4862. subject.length = 0;
  4863. b = this[i];
  4864. c = input[(m = input.length - closed) - 1];
  4865. j = -1;
  4866. while (++j < m) {
  4867. d = input[j];
  4868. if (d3_geom_polygonInside(d, a, b)) {
  4869. if (!d3_geom_polygonInside(c, a, b)) {
  4870. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4871. }
  4872. subject.push(d);
  4873. } else if (d3_geom_polygonInside(c, a, b)) {
  4874. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4875. }
  4876. c = d;
  4877. }
  4878. if (closed) subject.push(subject[0]);
  4879. a = b;
  4880. }
  4881. return subject;
  4882. };
  4883. function d3_geom_polygonInside(p, a, b) {
  4884. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  4885. }
  4886. function d3_geom_polygonIntersect(c, d, a, b) {
  4887. var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21);
  4888. return [ x1 + ua * x21, y1 + ua * y21 ];
  4889. }
  4890. function d3_geom_polygonClosed(coordinates) {
  4891. var a = coordinates[0], b = coordinates[coordinates.length - 1];
  4892. return !(a[0] - b[0] || a[1] - b[1]);
  4893. }
  4894. var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
  4895. function d3_geom_voronoiBeach() {
  4896. d3_geom_voronoiRedBlackNode(this);
  4897. this.edge = this.site = this.circle = null;
  4898. }
  4899. function d3_geom_voronoiCreateBeach(site) {
  4900. var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
  4901. beach.site = site;
  4902. return beach;
  4903. }
  4904. function d3_geom_voronoiDetachBeach(beach) {
  4905. d3_geom_voronoiDetachCircle(beach);
  4906. d3_geom_voronoiBeaches.remove(beach);
  4907. d3_geom_voronoiBeachPool.push(beach);
  4908. d3_geom_voronoiRedBlackNode(beach);
  4909. }
  4910. function d3_geom_voronoiRemoveBeach(beach) {
  4911. var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
  4912. x: x,
  4913. y: y
  4914. }, previous = beach.P, next = beach.N, disappearing = [ beach ];
  4915. d3_geom_voronoiDetachBeach(beach);
  4916. var lArc = previous;
  4917. while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
  4918. previous = lArc.P;
  4919. disappearing.unshift(lArc);
  4920. d3_geom_voronoiDetachBeach(lArc);
  4921. lArc = previous;
  4922. }
  4923. disappearing.unshift(lArc);
  4924. d3_geom_voronoiDetachCircle(lArc);
  4925. var rArc = next;
  4926. while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
  4927. next = rArc.N;
  4928. disappearing.push(rArc);
  4929. d3_geom_voronoiDetachBeach(rArc);
  4930. rArc = next;
  4931. }
  4932. disappearing.push(rArc);
  4933. d3_geom_voronoiDetachCircle(rArc);
  4934. var nArcs = disappearing.length, iArc;
  4935. for (iArc = 1; iArc < nArcs; ++iArc) {
  4936. rArc = disappearing[iArc];
  4937. lArc = disappearing[iArc - 1];
  4938. d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  4939. }
  4940. lArc = disappearing[0];
  4941. rArc = disappearing[nArcs - 1];
  4942. rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
  4943. d3_geom_voronoiAttachCircle(lArc);
  4944. d3_geom_voronoiAttachCircle(rArc);
  4945. }
  4946. function d3_geom_voronoiAddBeach(site) {
  4947. var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
  4948. while (node) {
  4949. dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
  4950. if (dxl > ε) node = node.L; else {
  4951. dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
  4952. if (dxr > ε) {
  4953. if (!node.R) {
  4954. lArc = node;
  4955. break;
  4956. }
  4957. node = node.R;
  4958. } else {
  4959. if (dxl > -ε) {
  4960. lArc = node.P;
  4961. rArc = node;
  4962. } else if (dxr > -ε) {
  4963. lArc = node;
  4964. rArc = node.N;
  4965. } else {
  4966. lArc = rArc = node;
  4967. }
  4968. break;
  4969. }
  4970. }
  4971. }
  4972. var newArc = d3_geom_voronoiCreateBeach(site);
  4973. d3_geom_voronoiBeaches.insert(lArc, newArc);
  4974. if (!lArc && !rArc) return;
  4975. if (lArc === rArc) {
  4976. d3_geom_voronoiDetachCircle(lArc);
  4977. rArc = d3_geom_voronoiCreateBeach(lArc.site);
  4978. d3_geom_voronoiBeaches.insert(newArc, rArc);
  4979. newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4980. d3_geom_voronoiAttachCircle(lArc);
  4981. d3_geom_voronoiAttachCircle(rArc);
  4982. return;
  4983. }
  4984. if (!rArc) {
  4985. newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4986. return;
  4987. }
  4988. d3_geom_voronoiDetachCircle(lArc);
  4989. d3_geom_voronoiDetachCircle(rArc);
  4990. var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
  4991. x: (cy * hb - by * hc) / d + ax,
  4992. y: (bx * hc - cx * hb) / d + ay
  4993. };
  4994. d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
  4995. newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
  4996. rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
  4997. d3_geom_voronoiAttachCircle(lArc);
  4998. d3_geom_voronoiAttachCircle(rArc);
  4999. }
  5000. function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
  5001. var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
  5002. if (!pby2) return rfocx;
  5003. var lArc = arc.P;
  5004. if (!lArc) return -Infinity;
  5005. site = lArc.site;
  5006. var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
  5007. if (!plby2) return lfocx;
  5008. var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
  5009. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  5010. return (rfocx + lfocx) / 2;
  5011. }
  5012. function d3_geom_voronoiRightBreakPoint(arc, directrix) {
  5013. var rArc = arc.N;
  5014. if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
  5015. var site = arc.site;
  5016. return site.y === directrix ? site.x : Infinity;
  5017. }
  5018. function d3_geom_voronoiCell(site) {
  5019. this.site = site;
  5020. this.edges = [];
  5021. }
  5022. d3_geom_voronoiCell.prototype.prepare = function() {
  5023. var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
  5024. while (iHalfEdge--) {
  5025. edge = halfEdges[iHalfEdge].edge;
  5026. if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
  5027. }
  5028. halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
  5029. return halfEdges.length;
  5030. };
  5031. function d3_geom_voronoiCloseCells(extent) {
  5032. var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
  5033. while (iCell--) {
  5034. cell = cells[iCell];
  5035. if (!cell || !cell.prepare()) continue;
  5036. halfEdges = cell.edges;
  5037. nHalfEdges = halfEdges.length;
  5038. iHalfEdge = 0;
  5039. while (iHalfEdge < nHalfEdges) {
  5040. end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
  5041. start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
  5042. if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
  5043. halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
  5044. x: x0,
  5045. y: abs(x2 - x0) < ε ? y2 : y1
  5046. } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
  5047. x: abs(y2 - y1) < ε ? x2 : x1,
  5048. y: y1
  5049. } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
  5050. x: x1,
  5051. y: abs(x2 - x1) < ε ? y2 : y0
  5052. } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
  5053. x: abs(y2 - y0) < ε ? x2 : x0,
  5054. y: y0
  5055. } : null), cell.site, null));
  5056. ++nHalfEdges;
  5057. }
  5058. }
  5059. }
  5060. }
  5061. function d3_geom_voronoiHalfEdgeOrder(a, b) {
  5062. return b.angle - a.angle;
  5063. }
  5064. function d3_geom_voronoiCircle() {
  5065. d3_geom_voronoiRedBlackNode(this);
  5066. this.x = this.y = this.arc = this.site = this.cy = null;
  5067. }
  5068. function d3_geom_voronoiAttachCircle(arc) {
  5069. var lArc = arc.P, rArc = arc.N;
  5070. if (!lArc || !rArc) return;
  5071. var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
  5072. if (lSite === rSite) return;
  5073. var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
  5074. var d = 2 * (ax * cy - ay * cx);
  5075. if (d >= -ε2) return;
  5076. var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
  5077. var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
  5078. circle.arc = arc;
  5079. circle.site = cSite;
  5080. circle.x = x + bx;
  5081. circle.y = cy + Math.sqrt(x * x + y * y);
  5082. circle.cy = cy;
  5083. arc.circle = circle;
  5084. var before = null, node = d3_geom_voronoiCircles._;
  5085. while (node) {
  5086. if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
  5087. if (node.L) node = node.L; else {
  5088. before = node.P;
  5089. break;
  5090. }
  5091. } else {
  5092. if (node.R) node = node.R; else {
  5093. before = node;
  5094. break;
  5095. }
  5096. }
  5097. }
  5098. d3_geom_voronoiCircles.insert(before, circle);
  5099. if (!before) d3_geom_voronoiFirstCircle = circle;
  5100. }
  5101. function d3_geom_voronoiDetachCircle(arc) {
  5102. var circle = arc.circle;
  5103. if (circle) {
  5104. if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
  5105. d3_geom_voronoiCircles.remove(circle);
  5106. d3_geom_voronoiCirclePool.push(circle);
  5107. d3_geom_voronoiRedBlackNode(circle);
  5108. arc.circle = null;
  5109. }
  5110. }
  5111. function d3_geom_voronoiClipEdges(extent) {
  5112. var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
  5113. while (i--) {
  5114. e = edges[i];
  5115. if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
  5116. e.a = e.b = null;
  5117. edges.splice(i, 1);
  5118. }
  5119. }
  5120. }
  5121. function d3_geom_voronoiConnectEdge(edge, extent) {
  5122. var vb = edge.b;
  5123. if (vb) return true;
  5124. var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
  5125. if (ry === ly) {
  5126. if (fx < x0 || fx >= x1) return;
  5127. if (lx > rx) {
  5128. if (!va) va = {
  5129. x: fx,
  5130. y: y0
  5131. }; else if (va.y >= y1) return;
  5132. vb = {
  5133. x: fx,
  5134. y: y1
  5135. };
  5136. } else {
  5137. if (!va) va = {
  5138. x: fx,
  5139. y: y1
  5140. }; else if (va.y < y0) return;
  5141. vb = {
  5142. x: fx,
  5143. y: y0
  5144. };
  5145. }
  5146. } else {
  5147. fm = (lx - rx) / (ry - ly);
  5148. fb = fy - fm * fx;
  5149. if (fm < -1 || fm > 1) {
  5150. if (lx > rx) {
  5151. if (!va) va = {
  5152. x: (y0 - fb) / fm,
  5153. y: y0
  5154. }; else if (va.y >= y1) return;
  5155. vb = {
  5156. x: (y1 - fb) / fm,
  5157. y: y1
  5158. };
  5159. } else {
  5160. if (!va) va = {
  5161. x: (y1 - fb) / fm,
  5162. y: y1
  5163. }; else if (va.y < y0) return;
  5164. vb = {
  5165. x: (y0 - fb) / fm,
  5166. y: y0
  5167. };
  5168. }
  5169. } else {
  5170. if (ly < ry) {
  5171. if (!va) va = {
  5172. x: x0,
  5173. y: fm * x0 + fb
  5174. }; else if (va.x >= x1) return;
  5175. vb = {
  5176. x: x1,
  5177. y: fm * x1 + fb
  5178. };
  5179. } else {
  5180. if (!va) va = {
  5181. x: x1,
  5182. y: fm * x1 + fb
  5183. }; else if (va.x < x0) return;
  5184. vb = {
  5185. x: x0,
  5186. y: fm * x0 + fb
  5187. };
  5188. }
  5189. }
  5190. }
  5191. edge.a = va;
  5192. edge.b = vb;
  5193. return true;
  5194. }
  5195. function d3_geom_voronoiEdge(lSite, rSite) {
  5196. this.l = lSite;
  5197. this.r = rSite;
  5198. this.a = this.b = null;
  5199. }
  5200. function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
  5201. var edge = new d3_geom_voronoiEdge(lSite, rSite);
  5202. d3_geom_voronoiEdges.push(edge);
  5203. if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
  5204. if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
  5205. d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
  5206. d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
  5207. return edge;
  5208. }
  5209. function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
  5210. var edge = new d3_geom_voronoiEdge(lSite, null);
  5211. edge.a = va;
  5212. edge.b = vb;
  5213. d3_geom_voronoiEdges.push(edge);
  5214. return edge;
  5215. }
  5216. function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
  5217. if (!edge.a && !edge.b) {
  5218. edge.a = vertex;
  5219. edge.l = lSite;
  5220. edge.r = rSite;
  5221. } else if (edge.l === rSite) {
  5222. edge.b = vertex;
  5223. } else {
  5224. edge.a = vertex;
  5225. }
  5226. }
  5227. function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
  5228. var va = edge.a, vb = edge.b;
  5229. this.edge = edge;
  5230. this.site = lSite;
  5231. this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
  5232. }
  5233. d3_geom_voronoiHalfEdge.prototype = {
  5234. start: function() {
  5235. return this.edge.l === this.site ? this.edge.a : this.edge.b;
  5236. },
  5237. end: function() {
  5238. return this.edge.l === this.site ? this.edge.b : this.edge.a;
  5239. }
  5240. };
  5241. function d3_geom_voronoiRedBlackTree() {
  5242. this._ = null;
  5243. }
  5244. function d3_geom_voronoiRedBlackNode(node) {
  5245. node.U = node.C = node.L = node.R = node.P = node.N = null;
  5246. }
  5247. d3_geom_voronoiRedBlackTree.prototype = {
  5248. insert: function(after, node) {
  5249. var parent, grandpa, uncle;
  5250. if (after) {
  5251. node.P = after;
  5252. node.N = after.N;
  5253. if (after.N) after.N.P = node;
  5254. after.N = node;
  5255. if (after.R) {
  5256. after = after.R;
  5257. while (after.L) after = after.L;
  5258. after.L = node;
  5259. } else {
  5260. after.R = node;
  5261. }
  5262. parent = after;
  5263. } else if (this._) {
  5264. after = d3_geom_voronoiRedBlackFirst(this._);
  5265. node.P = null;
  5266. node.N = after;
  5267. after.P = after.L = node;
  5268. parent = after;
  5269. } else {
  5270. node.P = node.N = null;
  5271. this._ = node;
  5272. parent = null;
  5273. }
  5274. node.L = node.R = null;
  5275. node.U = parent;
  5276. node.C = true;
  5277. after = node;
  5278. while (parent && parent.C) {
  5279. grandpa = parent.U;
  5280. if (parent === grandpa.L) {
  5281. uncle = grandpa.R;
  5282. if (uncle && uncle.C) {
  5283. parent.C = uncle.C = false;
  5284. grandpa.C = true;
  5285. after = grandpa;
  5286. } else {
  5287. if (after === parent.R) {
  5288. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5289. after = parent;
  5290. parent = after.U;
  5291. }
  5292. parent.C = false;
  5293. grandpa.C = true;
  5294. d3_geom_voronoiRedBlackRotateRight(this, grandpa);
  5295. }
  5296. } else {
  5297. uncle = grandpa.L;
  5298. if (uncle && uncle.C) {
  5299. parent.C = uncle.C = false;
  5300. grandpa.C = true;
  5301. after = grandpa;
  5302. } else {
  5303. if (after === parent.L) {
  5304. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5305. after = parent;
  5306. parent = after.U;
  5307. }
  5308. parent.C = false;
  5309. grandpa.C = true;
  5310. d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
  5311. }
  5312. }
  5313. parent = after.U;
  5314. }
  5315. this._.C = false;
  5316. },
  5317. remove: function(node) {
  5318. if (node.N) node.N.P = node.P;
  5319. if (node.P) node.P.N = node.N;
  5320. node.N = node.P = null;
  5321. var parent = node.U, sibling, left = node.L, right = node.R, next, red;
  5322. if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
  5323. if (parent) {
  5324. if (parent.L === node) parent.L = next; else parent.R = next;
  5325. } else {
  5326. this._ = next;
  5327. }
  5328. if (left && right) {
  5329. red = next.C;
  5330. next.C = node.C;
  5331. next.L = left;
  5332. left.U = next;
  5333. if (next !== right) {
  5334. parent = next.U;
  5335. next.U = node.U;
  5336. node = next.R;
  5337. parent.L = node;
  5338. next.R = right;
  5339. right.U = next;
  5340. } else {
  5341. next.U = parent;
  5342. parent = next;
  5343. node = next.R;
  5344. }
  5345. } else {
  5346. red = node.C;
  5347. node = next;
  5348. }
  5349. if (node) node.U = parent;
  5350. if (red) return;
  5351. if (node && node.C) {
  5352. node.C = false;
  5353. return;
  5354. }
  5355. do {
  5356. if (node === this._) break;
  5357. if (node === parent.L) {
  5358. sibling = parent.R;
  5359. if (sibling.C) {
  5360. sibling.C = false;
  5361. parent.C = true;
  5362. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5363. sibling = parent.R;
  5364. }
  5365. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5366. if (!sibling.R || !sibling.R.C) {
  5367. sibling.L.C = false;
  5368. sibling.C = true;
  5369. d3_geom_voronoiRedBlackRotateRight(this, sibling);
  5370. sibling = parent.R;
  5371. }
  5372. sibling.C = parent.C;
  5373. parent.C = sibling.R.C = false;
  5374. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5375. node = this._;
  5376. break;
  5377. }
  5378. } else {
  5379. sibling = parent.L;
  5380. if (sibling.C) {
  5381. sibling.C = false;
  5382. parent.C = true;
  5383. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5384. sibling = parent.L;
  5385. }
  5386. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5387. if (!sibling.L || !sibling.L.C) {
  5388. sibling.R.C = false;
  5389. sibling.C = true;
  5390. d3_geom_voronoiRedBlackRotateLeft(this, sibling);
  5391. sibling = parent.L;
  5392. }
  5393. sibling.C = parent.C;
  5394. parent.C = sibling.L.C = false;
  5395. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5396. node = this._;
  5397. break;
  5398. }
  5399. }
  5400. sibling.C = true;
  5401. node = parent;
  5402. parent = parent.U;
  5403. } while (!node.C);
  5404. if (node) node.C = false;
  5405. }
  5406. };
  5407. function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
  5408. var p = node, q = node.R, parent = p.U;
  5409. if (parent) {
  5410. if (parent.L === p) parent.L = q; else parent.R = q;
  5411. } else {
  5412. tree._ = q;
  5413. }
  5414. q.U = parent;
  5415. p.U = q;
  5416. p.R = q.L;
  5417. if (p.R) p.R.U = p;
  5418. q.L = p;
  5419. }
  5420. function d3_geom_voronoiRedBlackRotateRight(tree, node) {
  5421. var p = node, q = node.L, parent = p.U;
  5422. if (parent) {
  5423. if (parent.L === p) parent.L = q; else parent.R = q;
  5424. } else {
  5425. tree._ = q;
  5426. }
  5427. q.U = parent;
  5428. p.U = q;
  5429. p.L = q.R;
  5430. if (p.L) p.L.U = p;
  5431. q.R = p;
  5432. }
  5433. function d3_geom_voronoiRedBlackFirst(node) {
  5434. while (node.L) node = node.L;
  5435. return node;
  5436. }
  5437. function d3_geom_voronoi(sites, bbox) {
  5438. var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
  5439. d3_geom_voronoiEdges = [];
  5440. d3_geom_voronoiCells = new Array(sites.length);
  5441. d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
  5442. d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
  5443. while (true) {
  5444. circle = d3_geom_voronoiFirstCircle;
  5445. if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
  5446. if (site.x !== x0 || site.y !== y0) {
  5447. d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
  5448. d3_geom_voronoiAddBeach(site);
  5449. x0 = site.x, y0 = site.y;
  5450. }
  5451. site = sites.pop();
  5452. } else if (circle) {
  5453. d3_geom_voronoiRemoveBeach(circle.arc);
  5454. } else {
  5455. break;
  5456. }
  5457. }
  5458. if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
  5459. var diagram = {
  5460. cells: d3_geom_voronoiCells,
  5461. edges: d3_geom_voronoiEdges
  5462. };
  5463. d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
  5464. return diagram;
  5465. }
  5466. function d3_geom_voronoiVertexOrder(a, b) {
  5467. return b.y - a.y || b.x - a.x;
  5468. }
  5469. d3.geom.voronoi = function(points) {
  5470. var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
  5471. if (points) return voronoi(points);
  5472. function voronoi(data) {
  5473. var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
  5474. d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
  5475. var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
  5476. var s = e.start();
  5477. return [ s.x, s.y ];
  5478. }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
  5479. polygon.point = data[i];
  5480. });
  5481. return polygons;
  5482. }
  5483. function sites(data) {
  5484. return data.map(function(d, i) {
  5485. return {
  5486. x: Math.round(fx(d, i) / ε) * ε,
  5487. y: Math.round(fy(d, i) / ε) * ε,
  5488. i: i
  5489. };
  5490. });
  5491. }
  5492. voronoi.links = function(data) {
  5493. return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
  5494. return edge.l && edge.r;
  5495. }).map(function(edge) {
  5496. return {
  5497. source: data[edge.l.i],
  5498. target: data[edge.r.i]
  5499. };
  5500. });
  5501. };
  5502. voronoi.triangles = function(data) {
  5503. var triangles = [];
  5504. d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
  5505. var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
  5506. while (++j < m) {
  5507. e0 = e1;
  5508. s0 = s1;
  5509. e1 = edges[j].edge;
  5510. s1 = e1.l === site ? e1.r : e1.l;
  5511. if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
  5512. triangles.push([ data[i], data[s0.i], data[s1.i] ]);
  5513. }
  5514. }
  5515. });
  5516. return triangles;
  5517. };
  5518. voronoi.x = function(_) {
  5519. return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
  5520. };
  5521. voronoi.y = function(_) {
  5522. return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
  5523. };
  5524. voronoi.clipExtent = function(_) {
  5525. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
  5526. clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
  5527. return voronoi;
  5528. };
  5529. voronoi.size = function(_) {
  5530. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
  5531. return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
  5532. };
  5533. return voronoi;
  5534. };
  5535. var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
  5536. function d3_geom_voronoiTriangleArea(a, b, c) {
  5537. return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
  5538. }
  5539. d3.geom.delaunay = function(vertices) {
  5540. return d3.geom.voronoi().triangles(vertices);
  5541. };
  5542. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  5543. var x = d3_geom_pointX, y = d3_geom_pointY, compat;
  5544. if (compat = arguments.length) {
  5545. x = d3_geom_quadtreeCompatX;
  5546. y = d3_geom_quadtreeCompatY;
  5547. if (compat === 3) {
  5548. y2 = y1;
  5549. x2 = x1;
  5550. y1 = x1 = 0;
  5551. }
  5552. return quadtree(points);
  5553. }
  5554. function quadtree(data) {
  5555. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  5556. if (x1 != null) {
  5557. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  5558. } else {
  5559. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  5560. xs = [], ys = [];
  5561. n = data.length;
  5562. if (compat) for (i = 0; i < n; ++i) {
  5563. d = data[i];
  5564. if (d.x < x1_) x1_ = d.x;
  5565. if (d.y < y1_) y1_ = d.y;
  5566. if (d.x > x2_) x2_ = d.x;
  5567. if (d.y > y2_) y2_ = d.y;
  5568. xs.push(d.x);
  5569. ys.push(d.y);
  5570. } else for (i = 0; i < n; ++i) {
  5571. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  5572. if (x_ < x1_) x1_ = x_;
  5573. if (y_ < y1_) y1_ = y_;
  5574. if (x_ > x2_) x2_ = x_;
  5575. if (y_ > y2_) y2_ = y_;
  5576. xs.push(x_);
  5577. ys.push(y_);
  5578. }
  5579. }
  5580. var dx = x2_ - x1_, dy = y2_ - y1_;
  5581. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  5582. function insert(n, d, x, y, x1, y1, x2, y2) {
  5583. if (isNaN(x) || isNaN(y)) return;
  5584. if (n.leaf) {
  5585. var nx = n.x, ny = n.y;
  5586. if (nx != null) {
  5587. if (abs(nx - x) + abs(ny - y) < .01) {
  5588. insertChild(n, d, x, y, x1, y1, x2, y2);
  5589. } else {
  5590. var nPoint = n.point;
  5591. n.x = n.y = n.point = null;
  5592. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  5593. insertChild(n, d, x, y, x1, y1, x2, y2);
  5594. }
  5595. } else {
  5596. n.x = x, n.y = y, n.point = d;
  5597. }
  5598. } else {
  5599. insertChild(n, d, x, y, x1, y1, x2, y2);
  5600. }
  5601. }
  5602. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  5603. var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
  5604. n.leaf = false;
  5605. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  5606. if (right) x1 = xm; else x2 = xm;
  5607. if (below) y1 = ym; else y2 = ym;
  5608. insert(n, d, x, y, x1, y1, x2, y2);
  5609. }
  5610. var root = d3_geom_quadtreeNode();
  5611. root.add = function(d) {
  5612. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  5613. };
  5614. root.visit = function(f) {
  5615. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  5616. };
  5617. root.find = function(point) {
  5618. return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
  5619. };
  5620. i = -1;
  5621. if (x1 == null) {
  5622. while (++i < n) {
  5623. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  5624. }
  5625. --i;
  5626. } else data.forEach(root.add);
  5627. xs = ys = data = d = null;
  5628. return root;
  5629. }
  5630. quadtree.x = function(_) {
  5631. return arguments.length ? (x = _, quadtree) : x;
  5632. };
  5633. quadtree.y = function(_) {
  5634. return arguments.length ? (y = _, quadtree) : y;
  5635. };
  5636. quadtree.extent = function(_) {
  5637. if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
  5638. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
  5639. y2 = +_[1][1];
  5640. return quadtree;
  5641. };
  5642. quadtree.size = function(_) {
  5643. if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
  5644. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
  5645. return quadtree;
  5646. };
  5647. return quadtree;
  5648. };
  5649. function d3_geom_quadtreeCompatX(d) {
  5650. return d.x;
  5651. }
  5652. function d3_geom_quadtreeCompatY(d) {
  5653. return d.y;
  5654. }
  5655. function d3_geom_quadtreeNode() {
  5656. return {
  5657. leaf: true,
  5658. nodes: [],
  5659. point: null,
  5660. x: null,
  5661. y: null
  5662. };
  5663. }
  5664. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  5665. if (!f(node, x1, y1, x2, y2)) {
  5666. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  5667. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  5668. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  5669. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  5670. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  5671. }
  5672. }
  5673. function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
  5674. var minDistance2 = Infinity, closestPoint;
  5675. (function find(node, x1, y1, x2, y2) {
  5676. if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
  5677. if (point = node.point) {
  5678. var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
  5679. if (distance2 < minDistance2) {
  5680. var distance = Math.sqrt(minDistance2 = distance2);
  5681. x0 = x - distance, y0 = y - distance;
  5682. x3 = x + distance, y3 = y + distance;
  5683. closestPoint = point;
  5684. }
  5685. }
  5686. var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
  5687. for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
  5688. if (node = children[i & 3]) switch (i & 3) {
  5689. case 0:
  5690. find(node, x1, y1, xm, ym);
  5691. break;
  5692. case 1:
  5693. find(node, xm, y1, x2, ym);
  5694. break;
  5695. case 2:
  5696. find(node, x1, ym, xm, y2);
  5697. break;
  5698. case 3:
  5699. find(node, xm, ym, x2, y2);
  5700. break;
  5701. }
  5702. }
  5703. })(root, x0, y0, x3, y3);
  5704. return closestPoint;
  5705. }
  5706. d3.interpolateRgb = d3_interpolateRgb;
  5707. function d3_interpolateRgb(a, b) {
  5708. a = d3.rgb(a);
  5709. b = d3.rgb(b);
  5710. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  5711. return function(t) {
  5712. return "#" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t));
  5713. };
  5714. }
  5715. d3.interpolateObject = d3_interpolateObject;
  5716. function d3_interpolateObject(a, b) {
  5717. var i = {}, c = {}, k;
  5718. for (k in a) {
  5719. if (k in b) {
  5720. i[k] = d3_interpolate(a[k], b[k]);
  5721. } else {
  5722. c[k] = a[k];
  5723. }
  5724. }
  5725. for (k in b) {
  5726. if (!(k in a)) {
  5727. c[k] = b[k];
  5728. }
  5729. }
  5730. return function(t) {
  5731. for (k in i) c[k] = i[k](t);
  5732. return c;
  5733. };
  5734. }
  5735. d3.interpolateNumber = d3_interpolateNumber;
  5736. function d3_interpolateNumber(a, b) {
  5737. a = +a, b = +b;
  5738. return function(t) {
  5739. return a * (1 - t) + b * t;
  5740. };
  5741. }
  5742. d3.interpolateString = d3_interpolateString;
  5743. function d3_interpolateString(a, b) {
  5744. var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
  5745. a = a + "", b = b + "";
  5746. while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
  5747. if ((bs = bm.index) > bi) {
  5748. bs = b.slice(bi, bs);
  5749. if (s[i]) s[i] += bs; else s[++i] = bs;
  5750. }
  5751. if ((am = am[0]) === (bm = bm[0])) {
  5752. if (s[i]) s[i] += bm; else s[++i] = bm;
  5753. } else {
  5754. s[++i] = null;
  5755. q.push({
  5756. i: i,
  5757. x: d3_interpolateNumber(am, bm)
  5758. });
  5759. }
  5760. bi = d3_interpolate_numberB.lastIndex;
  5761. }
  5762. if (bi < b.length) {
  5763. bs = b.slice(bi);
  5764. if (s[i]) s[i] += bs; else s[++i] = bs;
  5765. }
  5766. return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
  5767. return b(t) + "";
  5768. }) : function() {
  5769. return b;
  5770. } : (b = q.length, function(t) {
  5771. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  5772. return s.join("");
  5773. });
  5774. }
  5775. var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
  5776. d3.interpolate = d3_interpolate;
  5777. function d3_interpolate(a, b) {
  5778. var i = d3.interpolators.length, f;
  5779. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  5780. return f;
  5781. }
  5782. d3.interpolators = [ function(a, b) {
  5783. var t = typeof b;
  5784. return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
  5785. } ];
  5786. d3.interpolateArray = d3_interpolateArray;
  5787. function d3_interpolateArray(a, b) {
  5788. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  5789. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  5790. for (;i < na; ++i) c[i] = a[i];
  5791. for (;i < nb; ++i) c[i] = b[i];
  5792. return function(t) {
  5793. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  5794. return c;
  5795. };
  5796. }
  5797. var d3_ease_default = function() {
  5798. return d3_identity;
  5799. };
  5800. var d3_ease = d3.map({
  5801. linear: d3_ease_default,
  5802. poly: d3_ease_poly,
  5803. quad: function() {
  5804. return d3_ease_quad;
  5805. },
  5806. cubic: function() {
  5807. return d3_ease_cubic;
  5808. },
  5809. sin: function() {
  5810. return d3_ease_sin;
  5811. },
  5812. exp: function() {
  5813. return d3_ease_exp;
  5814. },
  5815. circle: function() {
  5816. return d3_ease_circle;
  5817. },
  5818. elastic: d3_ease_elastic,
  5819. back: d3_ease_back,
  5820. bounce: function() {
  5821. return d3_ease_bounce;
  5822. }
  5823. });
  5824. var d3_ease_mode = d3.map({
  5825. "in": d3_identity,
  5826. out: d3_ease_reverse,
  5827. "in-out": d3_ease_reflect,
  5828. "out-in": function(f) {
  5829. return d3_ease_reflect(d3_ease_reverse(f));
  5830. }
  5831. });
  5832. d3.ease = function(name) {
  5833. var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
  5834. t = d3_ease.get(t) || d3_ease_default;
  5835. m = d3_ease_mode.get(m) || d3_identity;
  5836. return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
  5837. };
  5838. function d3_ease_clamp(f) {
  5839. return function(t) {
  5840. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  5841. };
  5842. }
  5843. function d3_ease_reverse(f) {
  5844. return function(t) {
  5845. return 1 - f(1 - t);
  5846. };
  5847. }
  5848. function d3_ease_reflect(f) {
  5849. return function(t) {
  5850. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  5851. };
  5852. }
  5853. function d3_ease_quad(t) {
  5854. return t * t;
  5855. }
  5856. function d3_ease_cubic(t) {
  5857. return t * t * t;
  5858. }
  5859. function d3_ease_cubicInOut(t) {
  5860. if (t <= 0) return 0;
  5861. if (t >= 1) return 1;
  5862. var t2 = t * t, t3 = t2 * t;
  5863. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  5864. }
  5865. function d3_ease_poly(e) {
  5866. return function(t) {
  5867. return Math.pow(t, e);
  5868. };
  5869. }
  5870. function d3_ease_sin(t) {
  5871. return 1 - Math.cos(t * halfπ);
  5872. }
  5873. function d3_ease_exp(t) {
  5874. return Math.pow(2, 10 * (t - 1));
  5875. }
  5876. function d3_ease_circle(t) {
  5877. return 1 - Math.sqrt(1 - t * t);
  5878. }
  5879. function d3_ease_elastic(a, p) {
  5880. var s;
  5881. if (arguments.length < 2) p = .45;
  5882. if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
  5883. return function(t) {
  5884. return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
  5885. };
  5886. }
  5887. function d3_ease_back(s) {
  5888. if (!s) s = 1.70158;
  5889. return function(t) {
  5890. return t * t * ((s + 1) * t - s);
  5891. };
  5892. }
  5893. function d3_ease_bounce(t) {
  5894. return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375;
  5895. }
  5896. d3.interpolateHcl = d3_interpolateHcl;
  5897. function d3_interpolateHcl(a, b) {
  5898. a = d3.hcl(a);
  5899. b = d3.hcl(b);
  5900. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  5901. if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
  5902. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5903. return function(t) {
  5904. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  5905. };
  5906. }
  5907. d3.interpolateHsl = d3_interpolateHsl;
  5908. function d3_interpolateHsl(a, b) {
  5909. a = d3.hsl(a);
  5910. b = d3.hsl(b);
  5911. var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
  5912. if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
  5913. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5914. return function(t) {
  5915. return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
  5916. };
  5917. }
  5918. d3.interpolateLab = d3_interpolateLab;
  5919. function d3_interpolateLab(a, b) {
  5920. a = d3.lab(a);
  5921. b = d3.lab(b);
  5922. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  5923. return function(t) {
  5924. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  5925. };
  5926. }
  5927. d3.interpolateRound = d3_interpolateRound;
  5928. function d3_interpolateRound(a, b) {
  5929. b -= a;
  5930. return function(t) {
  5931. return Math.round(a + b * t);
  5932. };
  5933. }
  5934. d3.transform = function(string) {
  5935. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  5936. return (d3.transform = function(string) {
  5937. if (string != null) {
  5938. g.setAttribute("transform", string);
  5939. var t = g.transform.baseVal.consolidate();
  5940. }
  5941. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  5942. })(string);
  5943. };
  5944. function d3_transform(m) {
  5945. var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;
  5946. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  5947. r0[0] *= -1;
  5948. r0[1] *= -1;
  5949. kx *= -1;
  5950. kz *= -1;
  5951. }
  5952. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  5953. this.translate = [ m.e, m.f ];
  5954. this.scale = [ kx, ky ];
  5955. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  5956. }
  5957. d3_transform.prototype.toString = function() {
  5958. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  5959. };
  5960. function d3_transformDot(a, b) {
  5961. return a[0] * b[0] + a[1] * b[1];
  5962. }
  5963. function d3_transformNormalize(a) {
  5964. var k = Math.sqrt(d3_transformDot(a, a));
  5965. if (k) {
  5966. a[0] /= k;
  5967. a[1] /= k;
  5968. }
  5969. return k;
  5970. }
  5971. function d3_transformCombine(a, b, k) {
  5972. a[0] += k * b[0];
  5973. a[1] += k * b[1];
  5974. return a;
  5975. }
  5976. var d3_transformIdentity = {
  5977. a: 1,
  5978. b: 0,
  5979. c: 0,
  5980. d: 1,
  5981. e: 0,
  5982. f: 0
  5983. };
  5984. d3.interpolateTransform = d3_interpolateTransform;
  5985. function d3_interpolateTransformPop(s) {
  5986. return s.length ? s.pop() + "," : "";
  5987. }
  5988. function d3_interpolateTranslate(ta, tb, s, q) {
  5989. if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
  5990. var i = s.push("translate(", null, ",", null, ")");
  5991. q.push({
  5992. i: i - 4,
  5993. x: d3_interpolateNumber(ta[0], tb[0])
  5994. }, {
  5995. i: i - 2,
  5996. x: d3_interpolateNumber(ta[1], tb[1])
  5997. });
  5998. } else if (tb[0] || tb[1]) {
  5999. s.push("translate(" + tb + ")");
  6000. }
  6001. }
  6002. function d3_interpolateRotate(ra, rb, s, q) {
  6003. if (ra !== rb) {
  6004. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  6005. q.push({
  6006. i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
  6007. x: d3_interpolateNumber(ra, rb)
  6008. });
  6009. } else if (rb) {
  6010. s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
  6011. }
  6012. }
  6013. function d3_interpolateSkew(wa, wb, s, q) {
  6014. if (wa !== wb) {
  6015. q.push({
  6016. i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
  6017. x: d3_interpolateNumber(wa, wb)
  6018. });
  6019. } else if (wb) {
  6020. s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
  6021. }
  6022. }
  6023. function d3_interpolateScale(ka, kb, s, q) {
  6024. if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
  6025. var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
  6026. q.push({
  6027. i: i - 4,
  6028. x: d3_interpolateNumber(ka[0], kb[0])
  6029. }, {
  6030. i: i - 2,
  6031. x: d3_interpolateNumber(ka[1], kb[1])
  6032. });
  6033. } else if (kb[0] !== 1 || kb[1] !== 1) {
  6034. s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
  6035. }
  6036. }
  6037. function d3_interpolateTransform(a, b) {
  6038. var s = [], q = [];
  6039. a = d3.transform(a), b = d3.transform(b);
  6040. d3_interpolateTranslate(a.translate, b.translate, s, q);
  6041. d3_interpolateRotate(a.rotate, b.rotate, s, q);
  6042. d3_interpolateSkew(a.skew, b.skew, s, q);
  6043. d3_interpolateScale(a.scale, b.scale, s, q);
  6044. a = b = null;
  6045. return function(t) {
  6046. var i = -1, n = q.length, o;
  6047. while (++i < n) s[(o = q[i]).i] = o.x(t);
  6048. return s.join("");
  6049. };
  6050. }
  6051. function d3_uninterpolateNumber(a, b) {
  6052. b = (b -= a = +a) || 1 / b;
  6053. return function(x) {
  6054. return (x - a) / b;
  6055. };
  6056. }
  6057. function d3_uninterpolateClamp(a, b) {
  6058. b = (b -= a = +a) || 1 / b;
  6059. return function(x) {
  6060. return Math.max(0, Math.min(1, (x - a) / b));
  6061. };
  6062. }
  6063. d3.layout = {};
  6064. d3.layout.bundle = function() {
  6065. return function(links) {
  6066. var paths = [], i = -1, n = links.length;
  6067. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  6068. return paths;
  6069. };
  6070. };
  6071. function d3_layout_bundlePath(link) {
  6072. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  6073. while (start !== lca) {
  6074. start = start.parent;
  6075. points.push(start);
  6076. }
  6077. var k = points.length;
  6078. while (end !== lca) {
  6079. points.splice(k, 0, end);
  6080. end = end.parent;
  6081. }
  6082. return points;
  6083. }
  6084. function d3_layout_bundleAncestors(node) {
  6085. var ancestors = [], parent = node.parent;
  6086. while (parent != null) {
  6087. ancestors.push(node);
  6088. node = parent;
  6089. parent = parent.parent;
  6090. }
  6091. ancestors.push(node);
  6092. return ancestors;
  6093. }
  6094. function d3_layout_bundleLeastCommonAncestor(a, b) {
  6095. if (a === b) return a;
  6096. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  6097. while (aNode === bNode) {
  6098. sharedNode = aNode;
  6099. aNode = aNodes.pop();
  6100. bNode = bNodes.pop();
  6101. }
  6102. return sharedNode;
  6103. }
  6104. d3.layout.chord = function() {
  6105. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  6106. function relayout() {
  6107. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  6108. chords = [];
  6109. groups = [];
  6110. k = 0, i = -1;
  6111. while (++i < n) {
  6112. x = 0, j = -1;
  6113. while (++j < n) {
  6114. x += matrix[i][j];
  6115. }
  6116. groupSums.push(x);
  6117. subgroupIndex.push(d3.range(n));
  6118. k += x;
  6119. }
  6120. if (sortGroups) {
  6121. groupIndex.sort(function(a, b) {
  6122. return sortGroups(groupSums[a], groupSums[b]);
  6123. });
  6124. }
  6125. if (sortSubgroups) {
  6126. subgroupIndex.forEach(function(d, i) {
  6127. d.sort(function(a, b) {
  6128. return sortSubgroups(matrix[i][a], matrix[i][b]);
  6129. });
  6130. });
  6131. }
  6132. k = (τ - padding * n) / k;
  6133. x = 0, i = -1;
  6134. while (++i < n) {
  6135. x0 = x, j = -1;
  6136. while (++j < n) {
  6137. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  6138. subgroups[di + "-" + dj] = {
  6139. index: di,
  6140. subindex: dj,
  6141. startAngle: a0,
  6142. endAngle: a1,
  6143. value: v
  6144. };
  6145. }
  6146. groups[di] = {
  6147. index: di,
  6148. startAngle: x0,
  6149. endAngle: x,
  6150. value: (x - x0) / k
  6151. };
  6152. x += padding;
  6153. }
  6154. i = -1;
  6155. while (++i < n) {
  6156. j = i - 1;
  6157. while (++j < n) {
  6158. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  6159. if (source.value || target.value) {
  6160. chords.push(source.value < target.value ? {
  6161. source: target,
  6162. target: source
  6163. } : {
  6164. source: source,
  6165. target: target
  6166. });
  6167. }
  6168. }
  6169. }
  6170. if (sortChords) resort();
  6171. }
  6172. function resort() {
  6173. chords.sort(function(a, b) {
  6174. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  6175. });
  6176. }
  6177. chord.matrix = function(x) {
  6178. if (!arguments.length) return matrix;
  6179. n = (matrix = x) && matrix.length;
  6180. chords = groups = null;
  6181. return chord;
  6182. };
  6183. chord.padding = function(x) {
  6184. if (!arguments.length) return padding;
  6185. padding = x;
  6186. chords = groups = null;
  6187. return chord;
  6188. };
  6189. chord.sortGroups = function(x) {
  6190. if (!arguments.length) return sortGroups;
  6191. sortGroups = x;
  6192. chords = groups = null;
  6193. return chord;
  6194. };
  6195. chord.sortSubgroups = function(x) {
  6196. if (!arguments.length) return sortSubgroups;
  6197. sortSubgroups = x;
  6198. chords = null;
  6199. return chord;
  6200. };
  6201. chord.sortChords = function(x) {
  6202. if (!arguments.length) return sortChords;
  6203. sortChords = x;
  6204. if (chords) resort();
  6205. return chord;
  6206. };
  6207. chord.chords = function() {
  6208. if (!chords) relayout();
  6209. return chords;
  6210. };
  6211. chord.groups = function() {
  6212. if (!groups) relayout();
  6213. return groups;
  6214. };
  6215. return chord;
  6216. };
  6217. d3.layout.force = function() {
  6218. var force = {}, event = d3.dispatch("start", "tick", "end"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
  6219. function repulse(node) {
  6220. return function(quad, x1, _, x2) {
  6221. if (quad.point !== node) {
  6222. var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
  6223. if (dw * dw / theta2 < dn) {
  6224. if (dn < chargeDistance2) {
  6225. var k = quad.charge / dn;
  6226. node.px -= dx * k;
  6227. node.py -= dy * k;
  6228. }
  6229. return true;
  6230. }
  6231. if (quad.point && dn && dn < chargeDistance2) {
  6232. var k = quad.pointCharge / dn;
  6233. node.px -= dx * k;
  6234. node.py -= dy * k;
  6235. }
  6236. }
  6237. return !quad.charge;
  6238. };
  6239. }
  6240. force.tick = function() {
  6241. if ((alpha *= .99) < .005) {
  6242. timer = null;
  6243. event.end({
  6244. type: "end",
  6245. alpha: alpha = 0
  6246. });
  6247. return true;
  6248. }
  6249. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  6250. for (i = 0; i < m; ++i) {
  6251. o = links[i];
  6252. s = o.source;
  6253. t = o.target;
  6254. x = t.x - s.x;
  6255. y = t.y - s.y;
  6256. if (l = x * x + y * y) {
  6257. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  6258. x *= l;
  6259. y *= l;
  6260. t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
  6261. t.y -= y * k;
  6262. s.x += x * (k = 1 - k);
  6263. s.y += y * k;
  6264. }
  6265. }
  6266. if (k = alpha * gravity) {
  6267. x = size[0] / 2;
  6268. y = size[1] / 2;
  6269. i = -1;
  6270. if (k) while (++i < n) {
  6271. o = nodes[i];
  6272. o.x += (x - o.x) * k;
  6273. o.y += (y - o.y) * k;
  6274. }
  6275. }
  6276. if (charge) {
  6277. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  6278. i = -1;
  6279. while (++i < n) {
  6280. if (!(o = nodes[i]).fixed) {
  6281. q.visit(repulse(o));
  6282. }
  6283. }
  6284. }
  6285. i = -1;
  6286. while (++i < n) {
  6287. o = nodes[i];
  6288. if (o.fixed) {
  6289. o.x = o.px;
  6290. o.y = o.py;
  6291. } else {
  6292. o.x -= (o.px - (o.px = o.x)) * friction;
  6293. o.y -= (o.py - (o.py = o.y)) * friction;
  6294. }
  6295. }
  6296. event.tick({
  6297. type: "tick",
  6298. alpha: alpha
  6299. });
  6300. };
  6301. force.nodes = function(x) {
  6302. if (!arguments.length) return nodes;
  6303. nodes = x;
  6304. return force;
  6305. };
  6306. force.links = function(x) {
  6307. if (!arguments.length) return links;
  6308. links = x;
  6309. return force;
  6310. };
  6311. force.size = function(x) {
  6312. if (!arguments.length) return size;
  6313. size = x;
  6314. return force;
  6315. };
  6316. force.linkDistance = function(x) {
  6317. if (!arguments.length) return linkDistance;
  6318. linkDistance = typeof x === "function" ? x : +x;
  6319. return force;
  6320. };
  6321. force.distance = force.linkDistance;
  6322. force.linkStrength = function(x) {
  6323. if (!arguments.length) return linkStrength;
  6324. linkStrength = typeof x === "function" ? x : +x;
  6325. return force;
  6326. };
  6327. force.friction = function(x) {
  6328. if (!arguments.length) return friction;
  6329. friction = +x;
  6330. return force;
  6331. };
  6332. force.charge = function(x) {
  6333. if (!arguments.length) return charge;
  6334. charge = typeof x === "function" ? x : +x;
  6335. return force;
  6336. };
  6337. force.chargeDistance = function(x) {
  6338. if (!arguments.length) return Math.sqrt(chargeDistance2);
  6339. chargeDistance2 = x * x;
  6340. return force;
  6341. };
  6342. force.gravity = function(x) {
  6343. if (!arguments.length) return gravity;
  6344. gravity = +x;
  6345. return force;
  6346. };
  6347. force.theta = function(x) {
  6348. if (!arguments.length) return Math.sqrt(theta2);
  6349. theta2 = x * x;
  6350. return force;
  6351. };
  6352. force.alpha = function(x) {
  6353. if (!arguments.length) return alpha;
  6354. x = +x;
  6355. if (alpha) {
  6356. if (x > 0) {
  6357. alpha = x;
  6358. } else {
  6359. timer.c = null, timer.t = NaN, timer = null;
  6360. event.start({
  6361. type: "end",
  6362. alpha: alpha = 0
  6363. });
  6364. }
  6365. } else if (x > 0) {
  6366. event.start({
  6367. type: "start",
  6368. alpha: alpha = x
  6369. });
  6370. timer = d3_timer(force.tick);
  6371. }
  6372. return force;
  6373. };
  6374. force.start = function() {
  6375. var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  6376. for (i = 0; i < n; ++i) {
  6377. (o = nodes[i]).index = i;
  6378. o.weight = 0;
  6379. }
  6380. for (i = 0; i < m; ++i) {
  6381. o = links[i];
  6382. if (typeof o.source == "number") o.source = nodes[o.source];
  6383. if (typeof o.target == "number") o.target = nodes[o.target];
  6384. ++o.source.weight;
  6385. ++o.target.weight;
  6386. }
  6387. for (i = 0; i < n; ++i) {
  6388. o = nodes[i];
  6389. if (isNaN(o.x)) o.x = position("x", w);
  6390. if (isNaN(o.y)) o.y = position("y", h);
  6391. if (isNaN(o.px)) o.px = o.x;
  6392. if (isNaN(o.py)) o.py = o.y;
  6393. }
  6394. distances = [];
  6395. if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance;
  6396. strengths = [];
  6397. if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength;
  6398. charges = [];
  6399. if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;
  6400. function position(dimension, size) {
  6401. if (!neighbors) {
  6402. neighbors = new Array(n);
  6403. for (j = 0; j < n; ++j) {
  6404. neighbors[j] = [];
  6405. }
  6406. for (j = 0; j < m; ++j) {
  6407. var o = links[j];
  6408. neighbors[o.source.index].push(o.target);
  6409. neighbors[o.target.index].push(o.source);
  6410. }
  6411. }
  6412. var candidates = neighbors[i], j = -1, l = candidates.length, x;
  6413. while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
  6414. return Math.random() * size;
  6415. }
  6416. return force.resume();
  6417. };
  6418. force.resume = function() {
  6419. return force.alpha(.1);
  6420. };
  6421. force.stop = function() {
  6422. return force.alpha(0);
  6423. };
  6424. force.drag = function() {
  6425. if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart.force", d3_layout_forceDragstart).on("drag.force", dragmove).on("dragend.force", d3_layout_forceDragend);
  6426. if (!arguments.length) return drag;
  6427. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  6428. };
  6429. function dragmove(d) {
  6430. d.px = d3.event.x, d.py = d3.event.y;
  6431. force.resume();
  6432. }
  6433. return d3.rebind(force, event, "on");
  6434. };
  6435. function d3_layout_forceDragstart(d) {
  6436. d.fixed |= 2;
  6437. }
  6438. function d3_layout_forceDragend(d) {
  6439. d.fixed &= ~6;
  6440. }
  6441. function d3_layout_forceMouseover(d) {
  6442. d.fixed |= 4;
  6443. d.px = d.x, d.py = d.y;
  6444. }
  6445. function d3_layout_forceMouseout(d) {
  6446. d.fixed &= ~4;
  6447. }
  6448. function d3_layout_forceAccumulate(quad, alpha, charges) {
  6449. var cx = 0, cy = 0;
  6450. quad.charge = 0;
  6451. if (!quad.leaf) {
  6452. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  6453. while (++i < n) {
  6454. c = nodes[i];
  6455. if (c == null) continue;
  6456. d3_layout_forceAccumulate(c, alpha, charges);
  6457. quad.charge += c.charge;
  6458. cx += c.charge * c.cx;
  6459. cy += c.charge * c.cy;
  6460. }
  6461. }
  6462. if (quad.point) {
  6463. if (!quad.leaf) {
  6464. quad.point.x += Math.random() - .5;
  6465. quad.point.y += Math.random() - .5;
  6466. }
  6467. var k = alpha * charges[quad.point.index];
  6468. quad.charge += quad.pointCharge = k;
  6469. cx += k * quad.point.x;
  6470. cy += k * quad.point.y;
  6471. }
  6472. quad.cx = cx / quad.charge;
  6473. quad.cy = cy / quad.charge;
  6474. }
  6475. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
  6476. d3.layout.hierarchy = function() {
  6477. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  6478. function hierarchy(root) {
  6479. var stack = [ root ], nodes = [], node;
  6480. root.depth = 0;
  6481. while ((node = stack.pop()) != null) {
  6482. nodes.push(node);
  6483. if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
  6484. var n, childs, child;
  6485. while (--n >= 0) {
  6486. stack.push(child = childs[n]);
  6487. child.parent = node;
  6488. child.depth = node.depth + 1;
  6489. }
  6490. if (value) node.value = 0;
  6491. node.children = childs;
  6492. } else {
  6493. if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6494. delete node.children;
  6495. }
  6496. }
  6497. d3_layout_hierarchyVisitAfter(root, function(node) {
  6498. var childs, parent;
  6499. if (sort && (childs = node.children)) childs.sort(sort);
  6500. if (value && (parent = node.parent)) parent.value += node.value;
  6501. });
  6502. return nodes;
  6503. }
  6504. hierarchy.sort = function(x) {
  6505. if (!arguments.length) return sort;
  6506. sort = x;
  6507. return hierarchy;
  6508. };
  6509. hierarchy.children = function(x) {
  6510. if (!arguments.length) return children;
  6511. children = x;
  6512. return hierarchy;
  6513. };
  6514. hierarchy.value = function(x) {
  6515. if (!arguments.length) return value;
  6516. value = x;
  6517. return hierarchy;
  6518. };
  6519. hierarchy.revalue = function(root) {
  6520. if (value) {
  6521. d3_layout_hierarchyVisitBefore(root, function(node) {
  6522. if (node.children) node.value = 0;
  6523. });
  6524. d3_layout_hierarchyVisitAfter(root, function(node) {
  6525. var parent;
  6526. if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6527. if (parent = node.parent) parent.value += node.value;
  6528. });
  6529. }
  6530. return root;
  6531. };
  6532. return hierarchy;
  6533. };
  6534. function d3_layout_hierarchyRebind(object, hierarchy) {
  6535. d3.rebind(object, hierarchy, "sort", "children", "value");
  6536. object.nodes = object;
  6537. object.links = d3_layout_hierarchyLinks;
  6538. return object;
  6539. }
  6540. function d3_layout_hierarchyVisitBefore(node, callback) {
  6541. var nodes = [ node ];
  6542. while ((node = nodes.pop()) != null) {
  6543. callback(node);
  6544. if ((children = node.children) && (n = children.length)) {
  6545. var n, children;
  6546. while (--n >= 0) nodes.push(children[n]);
  6547. }
  6548. }
  6549. }
  6550. function d3_layout_hierarchyVisitAfter(node, callback) {
  6551. var nodes = [ node ], nodes2 = [];
  6552. while ((node = nodes.pop()) != null) {
  6553. nodes2.push(node);
  6554. if ((children = node.children) && (n = children.length)) {
  6555. var i = -1, n, children;
  6556. while (++i < n) nodes.push(children[i]);
  6557. }
  6558. }
  6559. while ((node = nodes2.pop()) != null) {
  6560. callback(node);
  6561. }
  6562. }
  6563. function d3_layout_hierarchyChildren(d) {
  6564. return d.children;
  6565. }
  6566. function d3_layout_hierarchyValue(d) {
  6567. return d.value;
  6568. }
  6569. function d3_layout_hierarchySort(a, b) {
  6570. return b.value - a.value;
  6571. }
  6572. function d3_layout_hierarchyLinks(nodes) {
  6573. return d3.merge(nodes.map(function(parent) {
  6574. return (parent.children || []).map(function(child) {
  6575. return {
  6576. source: parent,
  6577. target: child
  6578. };
  6579. });
  6580. }));
  6581. }
  6582. d3.layout.partition = function() {
  6583. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  6584. function position(node, x, dx, dy) {
  6585. var children = node.children;
  6586. node.x = x;
  6587. node.y = node.depth * dy;
  6588. node.dx = dx;
  6589. node.dy = dy;
  6590. if (children && (n = children.length)) {
  6591. var i = -1, n, c, d;
  6592. dx = node.value ? dx / node.value : 0;
  6593. while (++i < n) {
  6594. position(c = children[i], x, d = c.value * dx, dy);
  6595. x += d;
  6596. }
  6597. }
  6598. }
  6599. function depth(node) {
  6600. var children = node.children, d = 0;
  6601. if (children && (n = children.length)) {
  6602. var i = -1, n;
  6603. while (++i < n) d = Math.max(d, depth(children[i]));
  6604. }
  6605. return 1 + d;
  6606. }
  6607. function partition(d, i) {
  6608. var nodes = hierarchy.call(this, d, i);
  6609. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  6610. return nodes;
  6611. }
  6612. partition.size = function(x) {
  6613. if (!arguments.length) return size;
  6614. size = x;
  6615. return partition;
  6616. };
  6617. return d3_layout_hierarchyRebind(partition, hierarchy);
  6618. };
  6619. d3.layout.pie = function() {
  6620. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
  6621. function pie(data) {
  6622. var n = data.length, values = data.map(function(d, i) {
  6623. return +value.call(pie, d, i);
  6624. }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;
  6625. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  6626. return values[j] - values[i];
  6627. } : function(i, j) {
  6628. return sort(data[i], data[j]);
  6629. });
  6630. index.forEach(function(i) {
  6631. arcs[i] = {
  6632. data: data[i],
  6633. value: v = values[i],
  6634. startAngle: a,
  6635. endAngle: a += v * k + pa,
  6636. padAngle: p
  6637. };
  6638. });
  6639. return arcs;
  6640. }
  6641. pie.value = function(_) {
  6642. if (!arguments.length) return value;
  6643. value = _;
  6644. return pie;
  6645. };
  6646. pie.sort = function(_) {
  6647. if (!arguments.length) return sort;
  6648. sort = _;
  6649. return pie;
  6650. };
  6651. pie.startAngle = function(_) {
  6652. if (!arguments.length) return startAngle;
  6653. startAngle = _;
  6654. return pie;
  6655. };
  6656. pie.endAngle = function(_) {
  6657. if (!arguments.length) return endAngle;
  6658. endAngle = _;
  6659. return pie;
  6660. };
  6661. pie.padAngle = function(_) {
  6662. if (!arguments.length) return padAngle;
  6663. padAngle = _;
  6664. return pie;
  6665. };
  6666. return pie;
  6667. };
  6668. var d3_layout_pieSortByValue = {};
  6669. d3.layout.stack = function() {
  6670. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  6671. function stack(data, index) {
  6672. if (!(n = data.length)) return data;
  6673. var series = data.map(function(d, i) {
  6674. return values.call(stack, d, i);
  6675. });
  6676. var points = series.map(function(d) {
  6677. return d.map(function(v, i) {
  6678. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  6679. });
  6680. });
  6681. var orders = order.call(stack, points, index);
  6682. series = d3.permute(series, orders);
  6683. points = d3.permute(points, orders);
  6684. var offsets = offset.call(stack, points, index);
  6685. var m = series[0].length, n, i, j, o;
  6686. for (j = 0; j < m; ++j) {
  6687. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  6688. for (i = 1; i < n; ++i) {
  6689. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  6690. }
  6691. }
  6692. return data;
  6693. }
  6694. stack.values = function(x) {
  6695. if (!arguments.length) return values;
  6696. values = x;
  6697. return stack;
  6698. };
  6699. stack.order = function(x) {
  6700. if (!arguments.length) return order;
  6701. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  6702. return stack;
  6703. };
  6704. stack.offset = function(x) {
  6705. if (!arguments.length) return offset;
  6706. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  6707. return stack;
  6708. };
  6709. stack.x = function(z) {
  6710. if (!arguments.length) return x;
  6711. x = z;
  6712. return stack;
  6713. };
  6714. stack.y = function(z) {
  6715. if (!arguments.length) return y;
  6716. y = z;
  6717. return stack;
  6718. };
  6719. stack.out = function(z) {
  6720. if (!arguments.length) return out;
  6721. out = z;
  6722. return stack;
  6723. };
  6724. return stack;
  6725. };
  6726. function d3_layout_stackX(d) {
  6727. return d.x;
  6728. }
  6729. function d3_layout_stackY(d) {
  6730. return d.y;
  6731. }
  6732. function d3_layout_stackOut(d, y0, y) {
  6733. d.y0 = y0;
  6734. d.y = y;
  6735. }
  6736. var d3_layout_stackOrders = d3.map({
  6737. "inside-out": function(data) {
  6738. var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) {
  6739. return max[a] - max[b];
  6740. }), top = 0, bottom = 0, tops = [], bottoms = [];
  6741. for (i = 0; i < n; ++i) {
  6742. j = index[i];
  6743. if (top < bottom) {
  6744. top += sums[j];
  6745. tops.push(j);
  6746. } else {
  6747. bottom += sums[j];
  6748. bottoms.push(j);
  6749. }
  6750. }
  6751. return bottoms.reverse().concat(tops);
  6752. },
  6753. reverse: function(data) {
  6754. return d3.range(data.length).reverse();
  6755. },
  6756. "default": d3_layout_stackOrderDefault
  6757. });
  6758. var d3_layout_stackOffsets = d3.map({
  6759. silhouette: function(data) {
  6760. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  6761. for (j = 0; j < m; ++j) {
  6762. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6763. if (o > max) max = o;
  6764. sums.push(o);
  6765. }
  6766. for (j = 0; j < m; ++j) {
  6767. y0[j] = (max - sums[j]) / 2;
  6768. }
  6769. return y0;
  6770. },
  6771. wiggle: function(data) {
  6772. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  6773. y0[0] = o = o0 = 0;
  6774. for (j = 1; j < m; ++j) {
  6775. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  6776. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  6777. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  6778. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  6779. }
  6780. s2 += s3 * data[i][j][1];
  6781. }
  6782. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  6783. if (o < o0) o0 = o;
  6784. }
  6785. for (j = 0; j < m; ++j) y0[j] -= o0;
  6786. return y0;
  6787. },
  6788. expand: function(data) {
  6789. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  6790. for (j = 0; j < m; ++j) {
  6791. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6792. if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
  6793. }
  6794. for (j = 0; j < m; ++j) y0[j] = 0;
  6795. return y0;
  6796. },
  6797. zero: d3_layout_stackOffsetZero
  6798. });
  6799. function d3_layout_stackOrderDefault(data) {
  6800. return d3.range(data.length);
  6801. }
  6802. function d3_layout_stackOffsetZero(data) {
  6803. var j = -1, m = data[0].length, y0 = [];
  6804. while (++j < m) y0[j] = 0;
  6805. return y0;
  6806. }
  6807. function d3_layout_stackMaxIndex(array) {
  6808. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  6809. for (;i < n; ++i) {
  6810. if ((k = array[i][1]) > v) {
  6811. j = i;
  6812. v = k;
  6813. }
  6814. }
  6815. return j;
  6816. }
  6817. function d3_layout_stackReduceSum(d) {
  6818. return d.reduce(d3_layout_stackSum, 0);
  6819. }
  6820. function d3_layout_stackSum(p, d) {
  6821. return p + d[1];
  6822. }
  6823. d3.layout.histogram = function() {
  6824. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  6825. function histogram(data, i) {
  6826. var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x;
  6827. while (++i < m) {
  6828. bin = bins[i] = [];
  6829. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  6830. bin.y = 0;
  6831. }
  6832. if (m > 0) {
  6833. i = -1;
  6834. while (++i < n) {
  6835. x = values[i];
  6836. if (x >= range[0] && x <= range[1]) {
  6837. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  6838. bin.y += k;
  6839. bin.push(data[i]);
  6840. }
  6841. }
  6842. }
  6843. return bins;
  6844. }
  6845. histogram.value = function(x) {
  6846. if (!arguments.length) return valuer;
  6847. valuer = x;
  6848. return histogram;
  6849. };
  6850. histogram.range = function(x) {
  6851. if (!arguments.length) return ranger;
  6852. ranger = d3_functor(x);
  6853. return histogram;
  6854. };
  6855. histogram.bins = function(x) {
  6856. if (!arguments.length) return binner;
  6857. binner = typeof x === "number" ? function(range) {
  6858. return d3_layout_histogramBinFixed(range, x);
  6859. } : d3_functor(x);
  6860. return histogram;
  6861. };
  6862. histogram.frequency = function(x) {
  6863. if (!arguments.length) return frequency;
  6864. frequency = !!x;
  6865. return histogram;
  6866. };
  6867. return histogram;
  6868. };
  6869. function d3_layout_histogramBinSturges(range, values) {
  6870. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  6871. }
  6872. function d3_layout_histogramBinFixed(range, n) {
  6873. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  6874. while (++x <= n) f[x] = m * x + b;
  6875. return f;
  6876. }
  6877. function d3_layout_histogramRange(values) {
  6878. return [ d3.min(values), d3.max(values) ];
  6879. }
  6880. d3.layout.pack = function() {
  6881. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
  6882. function pack(d, i) {
  6883. var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() {
  6884. return radius;
  6885. };
  6886. root.x = root.y = 0;
  6887. d3_layout_hierarchyVisitAfter(root, function(d) {
  6888. d.r = +r(d.value);
  6889. });
  6890. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6891. if (padding) {
  6892. var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
  6893. d3_layout_hierarchyVisitAfter(root, function(d) {
  6894. d.r += dr;
  6895. });
  6896. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6897. d3_layout_hierarchyVisitAfter(root, function(d) {
  6898. d.r -= dr;
  6899. });
  6900. }
  6901. d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
  6902. return nodes;
  6903. }
  6904. pack.size = function(_) {
  6905. if (!arguments.length) return size;
  6906. size = _;
  6907. return pack;
  6908. };
  6909. pack.radius = function(_) {
  6910. if (!arguments.length) return radius;
  6911. radius = _ == null || typeof _ === "function" ? _ : +_;
  6912. return pack;
  6913. };
  6914. pack.padding = function(_) {
  6915. if (!arguments.length) return padding;
  6916. padding = +_;
  6917. return pack;
  6918. };
  6919. return d3_layout_hierarchyRebind(pack, hierarchy);
  6920. };
  6921. function d3_layout_packSort(a, b) {
  6922. return a.value - b.value;
  6923. }
  6924. function d3_layout_packInsert(a, b) {
  6925. var c = a._pack_next;
  6926. a._pack_next = b;
  6927. b._pack_prev = a;
  6928. b._pack_next = c;
  6929. c._pack_prev = b;
  6930. }
  6931. function d3_layout_packSplice(a, b) {
  6932. a._pack_next = b;
  6933. b._pack_prev = a;
  6934. }
  6935. function d3_layout_packIntersects(a, b) {
  6936. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  6937. return .999 * dr * dr > dx * dx + dy * dy;
  6938. }
  6939. function d3_layout_packSiblings(node) {
  6940. if (!(nodes = node.children) || !(n = nodes.length)) return;
  6941. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  6942. function bound(node) {
  6943. xMin = Math.min(node.x - node.r, xMin);
  6944. xMax = Math.max(node.x + node.r, xMax);
  6945. yMin = Math.min(node.y - node.r, yMin);
  6946. yMax = Math.max(node.y + node.r, yMax);
  6947. }
  6948. nodes.forEach(d3_layout_packLink);
  6949. a = nodes[0];
  6950. a.x = -a.r;
  6951. a.y = 0;
  6952. bound(a);
  6953. if (n > 1) {
  6954. b = nodes[1];
  6955. b.x = b.r;
  6956. b.y = 0;
  6957. bound(b);
  6958. if (n > 2) {
  6959. c = nodes[2];
  6960. d3_layout_packPlace(a, b, c);
  6961. bound(c);
  6962. d3_layout_packInsert(a, c);
  6963. a._pack_prev = c;
  6964. d3_layout_packInsert(c, b);
  6965. b = a._pack_next;
  6966. for (i = 3; i < n; i++) {
  6967. d3_layout_packPlace(a, b, c = nodes[i]);
  6968. var isect = 0, s1 = 1, s2 = 1;
  6969. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  6970. if (d3_layout_packIntersects(j, c)) {
  6971. isect = 1;
  6972. break;
  6973. }
  6974. }
  6975. if (isect == 1) {
  6976. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  6977. if (d3_layout_packIntersects(k, c)) {
  6978. break;
  6979. }
  6980. }
  6981. }
  6982. if (isect) {
  6983. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  6984. i--;
  6985. } else {
  6986. d3_layout_packInsert(a, c);
  6987. b = c;
  6988. bound(c);
  6989. }
  6990. }
  6991. }
  6992. }
  6993. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  6994. for (i = 0; i < n; i++) {
  6995. c = nodes[i];
  6996. c.x -= cx;
  6997. c.y -= cy;
  6998. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  6999. }
  7000. node.r = cr;
  7001. nodes.forEach(d3_layout_packUnlink);
  7002. }
  7003. function d3_layout_packLink(node) {
  7004. node._pack_next = node._pack_prev = node;
  7005. }
  7006. function d3_layout_packUnlink(node) {
  7007. delete node._pack_next;
  7008. delete node._pack_prev;
  7009. }
  7010. function d3_layout_packTransform(node, x, y, k) {
  7011. var children = node.children;
  7012. node.x = x += k * node.x;
  7013. node.y = y += k * node.y;
  7014. node.r *= k;
  7015. if (children) {
  7016. var i = -1, n = children.length;
  7017. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  7018. }
  7019. }
  7020. function d3_layout_packPlace(a, b, c) {
  7021. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  7022. if (db && (dx || dy)) {
  7023. var da = b.r + c.r, dc = dx * dx + dy * dy;
  7024. da *= da;
  7025. db *= db;
  7026. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  7027. c.x = a.x + x * dx + y * dy;
  7028. c.y = a.y + x * dy - y * dx;
  7029. } else {
  7030. c.x = a.x + db;
  7031. c.y = a.y;
  7032. }
  7033. }
  7034. d3.layout.tree = function() {
  7035. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
  7036. function tree(d, i) {
  7037. var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
  7038. d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
  7039. d3_layout_hierarchyVisitBefore(root1, secondWalk);
  7040. if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
  7041. var left = root0, right = root0, bottom = root0;
  7042. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7043. if (node.x < left.x) left = node;
  7044. if (node.x > right.x) right = node;
  7045. if (node.depth > bottom.depth) bottom = node;
  7046. });
  7047. var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
  7048. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7049. node.x = (node.x + tx) * kx;
  7050. node.y = node.depth * ky;
  7051. });
  7052. }
  7053. return nodes;
  7054. }
  7055. function wrapTree(root0) {
  7056. var root1 = {
  7057. A: null,
  7058. children: [ root0 ]
  7059. }, queue = [ root1 ], node1;
  7060. while ((node1 = queue.pop()) != null) {
  7061. for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
  7062. queue.push((children[i] = child = {
  7063. _: children[i],
  7064. parent: node1,
  7065. children: (child = children[i].children) && child.slice() || [],
  7066. A: null,
  7067. a: null,
  7068. z: 0,
  7069. m: 0,
  7070. c: 0,
  7071. s: 0,
  7072. t: null,
  7073. i: i
  7074. }).a = child);
  7075. }
  7076. }
  7077. return root1.children[0];
  7078. }
  7079. function firstWalk(v) {
  7080. var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
  7081. if (children.length) {
  7082. d3_layout_treeShift(v);
  7083. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  7084. if (w) {
  7085. v.z = w.z + separation(v._, w._);
  7086. v.m = v.z - midpoint;
  7087. } else {
  7088. v.z = midpoint;
  7089. }
  7090. } else if (w) {
  7091. v.z = w.z + separation(v._, w._);
  7092. }
  7093. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  7094. }
  7095. function secondWalk(v) {
  7096. v._.x = v.z + v.parent.m;
  7097. v.m += v.parent.m;
  7098. }
  7099. function apportion(v, w, ancestor) {
  7100. if (w) {
  7101. var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
  7102. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  7103. vom = d3_layout_treeLeft(vom);
  7104. vop = d3_layout_treeRight(vop);
  7105. vop.a = v;
  7106. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  7107. if (shift > 0) {
  7108. d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
  7109. sip += shift;
  7110. sop += shift;
  7111. }
  7112. sim += vim.m;
  7113. sip += vip.m;
  7114. som += vom.m;
  7115. sop += vop.m;
  7116. }
  7117. if (vim && !d3_layout_treeRight(vop)) {
  7118. vop.t = vim;
  7119. vop.m += sim - sop;
  7120. }
  7121. if (vip && !d3_layout_treeLeft(vom)) {
  7122. vom.t = vip;
  7123. vom.m += sip - som;
  7124. ancestor = v;
  7125. }
  7126. }
  7127. return ancestor;
  7128. }
  7129. function sizeNode(node) {
  7130. node.x *= size[0];
  7131. node.y = node.depth * size[1];
  7132. }
  7133. tree.separation = function(x) {
  7134. if (!arguments.length) return separation;
  7135. separation = x;
  7136. return tree;
  7137. };
  7138. tree.size = function(x) {
  7139. if (!arguments.length) return nodeSize ? null : size;
  7140. nodeSize = (size = x) == null ? sizeNode : null;
  7141. return tree;
  7142. };
  7143. tree.nodeSize = function(x) {
  7144. if (!arguments.length) return nodeSize ? size : null;
  7145. nodeSize = (size = x) == null ? null : sizeNode;
  7146. return tree;
  7147. };
  7148. return d3_layout_hierarchyRebind(tree, hierarchy);
  7149. };
  7150. function d3_layout_treeSeparation(a, b) {
  7151. return a.parent == b.parent ? 1 : 2;
  7152. }
  7153. function d3_layout_treeLeft(v) {
  7154. var children = v.children;
  7155. return children.length ? children[0] : v.t;
  7156. }
  7157. function d3_layout_treeRight(v) {
  7158. var children = v.children, n;
  7159. return (n = children.length) ? children[n - 1] : v.t;
  7160. }
  7161. function d3_layout_treeMove(wm, wp, shift) {
  7162. var change = shift / (wp.i - wm.i);
  7163. wp.c -= change;
  7164. wp.s += shift;
  7165. wm.c += change;
  7166. wp.z += shift;
  7167. wp.m += shift;
  7168. }
  7169. function d3_layout_treeShift(v) {
  7170. var shift = 0, change = 0, children = v.children, i = children.length, w;
  7171. while (--i >= 0) {
  7172. w = children[i];
  7173. w.z += shift;
  7174. w.m += shift;
  7175. shift += w.s + (change += w.c);
  7176. }
  7177. }
  7178. function d3_layout_treeAncestor(vim, v, ancestor) {
  7179. return vim.a.parent === v.parent ? vim.a : ancestor;
  7180. }
  7181. d3.layout.cluster = function() {
  7182. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  7183. function cluster(d, i) {
  7184. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  7185. d3_layout_hierarchyVisitAfter(root, function(node) {
  7186. var children = node.children;
  7187. if (children && children.length) {
  7188. node.x = d3_layout_clusterX(children);
  7189. node.y = d3_layout_clusterY(children);
  7190. } else {
  7191. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7192. node.y = 0;
  7193. previousNode = node;
  7194. }
  7195. });
  7196. var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2;
  7197. d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
  7198. node.x = (node.x - root.x) * size[0];
  7199. node.y = (root.y - node.y) * size[1];
  7200. } : function(node) {
  7201. node.x = (node.x - x0) / (x1 - x0) * size[0];
  7202. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  7203. });
  7204. return nodes;
  7205. }
  7206. cluster.separation = function(x) {
  7207. if (!arguments.length) return separation;
  7208. separation = x;
  7209. return cluster;
  7210. };
  7211. cluster.size = function(x) {
  7212. if (!arguments.length) return nodeSize ? null : size;
  7213. nodeSize = (size = x) == null;
  7214. return cluster;
  7215. };
  7216. cluster.nodeSize = function(x) {
  7217. if (!arguments.length) return nodeSize ? size : null;
  7218. nodeSize = (size = x) != null;
  7219. return cluster;
  7220. };
  7221. return d3_layout_hierarchyRebind(cluster, hierarchy);
  7222. };
  7223. function d3_layout_clusterY(children) {
  7224. return 1 + d3.max(children, function(child) {
  7225. return child.y;
  7226. });
  7227. }
  7228. function d3_layout_clusterX(children) {
  7229. return children.reduce(function(x, child) {
  7230. return x + child.x;
  7231. }, 0) / children.length;
  7232. }
  7233. function d3_layout_clusterLeft(node) {
  7234. var children = node.children;
  7235. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  7236. }
  7237. function d3_layout_clusterRight(node) {
  7238. var children = node.children, n;
  7239. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  7240. }
  7241. d3.layout.treemap = function() {
  7242. var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5));
  7243. function scale(children, k) {
  7244. var i = -1, n = children.length, child, area;
  7245. while (++i < n) {
  7246. area = (child = children[i]).value * (k < 0 ? 0 : k);
  7247. child.area = isNaN(area) || area <= 0 ? 0 : area;
  7248. }
  7249. }
  7250. function squarify(node) {
  7251. var children = node.children;
  7252. if (children && children.length) {
  7253. var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n;
  7254. scale(remaining, rect.dx * rect.dy / node.value);
  7255. row.area = 0;
  7256. while ((n = remaining.length) > 0) {
  7257. row.push(child = remaining[n - 1]);
  7258. row.area += child.area;
  7259. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  7260. remaining.pop();
  7261. best = score;
  7262. } else {
  7263. row.area -= row.pop().area;
  7264. position(row, u, rect, false);
  7265. u = Math.min(rect.dx, rect.dy);
  7266. row.length = row.area = 0;
  7267. best = Infinity;
  7268. }
  7269. }
  7270. if (row.length) {
  7271. position(row, u, rect, true);
  7272. row.length = row.area = 0;
  7273. }
  7274. children.forEach(squarify);
  7275. }
  7276. }
  7277. function stickify(node) {
  7278. var children = node.children;
  7279. if (children && children.length) {
  7280. var rect = pad(node), remaining = children.slice(), child, row = [];
  7281. scale(remaining, rect.dx * rect.dy / node.value);
  7282. row.area = 0;
  7283. while (child = remaining.pop()) {
  7284. row.push(child);
  7285. row.area += child.area;
  7286. if (child.z != null) {
  7287. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  7288. row.length = row.area = 0;
  7289. }
  7290. }
  7291. children.forEach(stickify);
  7292. }
  7293. }
  7294. function worst(row, u) {
  7295. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  7296. while (++i < n) {
  7297. if (!(r = row[i].area)) continue;
  7298. if (r < rmin) rmin = r;
  7299. if (r > rmax) rmax = r;
  7300. }
  7301. s *= s;
  7302. u *= u;
  7303. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  7304. }
  7305. function position(row, u, rect, flush) {
  7306. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  7307. if (u == rect.dx) {
  7308. if (flush || v > rect.dy) v = rect.dy;
  7309. while (++i < n) {
  7310. o = row[i];
  7311. o.x = x;
  7312. o.y = y;
  7313. o.dy = v;
  7314. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  7315. }
  7316. o.z = true;
  7317. o.dx += rect.x + rect.dx - x;
  7318. rect.y += v;
  7319. rect.dy -= v;
  7320. } else {
  7321. if (flush || v > rect.dx) v = rect.dx;
  7322. while (++i < n) {
  7323. o = row[i];
  7324. o.x = x;
  7325. o.y = y;
  7326. o.dx = v;
  7327. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  7328. }
  7329. o.z = false;
  7330. o.dy += rect.y + rect.dy - y;
  7331. rect.x += v;
  7332. rect.dx -= v;
  7333. }
  7334. }
  7335. function treemap(d) {
  7336. var nodes = stickies || hierarchy(d), root = nodes[0];
  7337. root.x = root.y = 0;
  7338. if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
  7339. if (stickies) hierarchy.revalue(root);
  7340. scale([ root ], root.dx * root.dy / root.value);
  7341. (stickies ? stickify : squarify)(root);
  7342. if (sticky) stickies = nodes;
  7343. return nodes;
  7344. }
  7345. treemap.size = function(x) {
  7346. if (!arguments.length) return size;
  7347. size = x;
  7348. return treemap;
  7349. };
  7350. treemap.padding = function(x) {
  7351. if (!arguments.length) return padding;
  7352. function padFunction(node) {
  7353. var p = x.call(treemap, node, node.depth);
  7354. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  7355. }
  7356. function padConstant(node) {
  7357. return d3_layout_treemapPad(node, x);
  7358. }
  7359. var type;
  7360. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  7361. padConstant) : padConstant;
  7362. return treemap;
  7363. };
  7364. treemap.round = function(x) {
  7365. if (!arguments.length) return round != Number;
  7366. round = x ? Math.round : Number;
  7367. return treemap;
  7368. };
  7369. treemap.sticky = function(x) {
  7370. if (!arguments.length) return sticky;
  7371. sticky = x;
  7372. stickies = null;
  7373. return treemap;
  7374. };
  7375. treemap.ratio = function(x) {
  7376. if (!arguments.length) return ratio;
  7377. ratio = x;
  7378. return treemap;
  7379. };
  7380. treemap.mode = function(x) {
  7381. if (!arguments.length) return mode;
  7382. mode = x + "";
  7383. return treemap;
  7384. };
  7385. return d3_layout_hierarchyRebind(treemap, hierarchy);
  7386. };
  7387. function d3_layout_treemapPadNull(node) {
  7388. return {
  7389. x: node.x,
  7390. y: node.y,
  7391. dx: node.dx,
  7392. dy: node.dy
  7393. };
  7394. }
  7395. function d3_layout_treemapPad(node, padding) {
  7396. var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2];
  7397. if (dx < 0) {
  7398. x += dx / 2;
  7399. dx = 0;
  7400. }
  7401. if (dy < 0) {
  7402. y += dy / 2;
  7403. dy = 0;
  7404. }
  7405. return {
  7406. x: x,
  7407. y: y,
  7408. dx: dx,
  7409. dy: dy
  7410. };
  7411. }
  7412. d3.random = {
  7413. normal: function(µ, σ) {
  7414. var n = arguments.length;
  7415. if (n < 2) σ = 1;
  7416. if (n < 1) µ = 0;
  7417. return function() {
  7418. var x, y, r;
  7419. do {
  7420. x = Math.random() * 2 - 1;
  7421. y = Math.random() * 2 - 1;
  7422. r = x * x + y * y;
  7423. } while (!r || r > 1);
  7424. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  7425. };
  7426. },
  7427. logNormal: function() {
  7428. var random = d3.random.normal.apply(d3, arguments);
  7429. return function() {
  7430. return Math.exp(random());
  7431. };
  7432. },
  7433. bates: function(m) {
  7434. var random = d3.random.irwinHall(m);
  7435. return function() {
  7436. return random() / m;
  7437. };
  7438. },
  7439. irwinHall: function(m) {
  7440. return function() {
  7441. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  7442. return s;
  7443. };
  7444. }
  7445. };
  7446. d3.scale = {};
  7447. function d3_scaleExtent(domain) {
  7448. var start = domain[0], stop = domain[domain.length - 1];
  7449. return start < stop ? [ start, stop ] : [ stop, start ];
  7450. }
  7451. function d3_scaleRange(scale) {
  7452. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  7453. }
  7454. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  7455. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  7456. return function(x) {
  7457. return i(u(x));
  7458. };
  7459. }
  7460. function d3_scale_nice(domain, nice) {
  7461. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  7462. if (x1 < x0) {
  7463. dx = i0, i0 = i1, i1 = dx;
  7464. dx = x0, x0 = x1, x1 = dx;
  7465. }
  7466. domain[i0] = nice.floor(x0);
  7467. domain[i1] = nice.ceil(x1);
  7468. return domain;
  7469. }
  7470. function d3_scale_niceStep(step) {
  7471. return step ? {
  7472. floor: function(x) {
  7473. return Math.floor(x / step) * step;
  7474. },
  7475. ceil: function(x) {
  7476. return Math.ceil(x / step) * step;
  7477. }
  7478. } : d3_scale_niceIdentity;
  7479. }
  7480. var d3_scale_niceIdentity = {
  7481. floor: d3_identity,
  7482. ceil: d3_identity
  7483. };
  7484. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  7485. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  7486. if (domain[k] < domain[0]) {
  7487. domain = domain.slice().reverse();
  7488. range = range.slice().reverse();
  7489. }
  7490. while (++j <= k) {
  7491. u.push(uninterpolate(domain[j - 1], domain[j]));
  7492. i.push(interpolate(range[j - 1], range[j]));
  7493. }
  7494. return function(x) {
  7495. var j = d3.bisect(domain, x, 1, k) - 1;
  7496. return i[j](u[j](x));
  7497. };
  7498. }
  7499. d3.scale.linear = function() {
  7500. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  7501. };
  7502. function d3_scale_linear(domain, range, interpolate, clamp) {
  7503. var output, input;
  7504. function rescale() {
  7505. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  7506. output = linear(domain, range, uninterpolate, interpolate);
  7507. input = linear(range, domain, uninterpolate, d3_interpolate);
  7508. return scale;
  7509. }
  7510. function scale(x) {
  7511. return output(x);
  7512. }
  7513. scale.invert = function(y) {
  7514. return input(y);
  7515. };
  7516. scale.domain = function(x) {
  7517. if (!arguments.length) return domain;
  7518. domain = x.map(Number);
  7519. return rescale();
  7520. };
  7521. scale.range = function(x) {
  7522. if (!arguments.length) return range;
  7523. range = x;
  7524. return rescale();
  7525. };
  7526. scale.rangeRound = function(x) {
  7527. return scale.range(x).interpolate(d3_interpolateRound);
  7528. };
  7529. scale.clamp = function(x) {
  7530. if (!arguments.length) return clamp;
  7531. clamp = x;
  7532. return rescale();
  7533. };
  7534. scale.interpolate = function(x) {
  7535. if (!arguments.length) return interpolate;
  7536. interpolate = x;
  7537. return rescale();
  7538. };
  7539. scale.ticks = function(m) {
  7540. return d3_scale_linearTicks(domain, m);
  7541. };
  7542. scale.tickFormat = function(m, format) {
  7543. return d3_scale_linearTickFormat(domain, m, format);
  7544. };
  7545. scale.nice = function(m) {
  7546. d3_scale_linearNice(domain, m);
  7547. return rescale();
  7548. };
  7549. scale.copy = function() {
  7550. return d3_scale_linear(domain, range, interpolate, clamp);
  7551. };
  7552. return rescale();
  7553. }
  7554. function d3_scale_linearRebind(scale, linear) {
  7555. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  7556. }
  7557. function d3_scale_linearNice(domain, m) {
  7558. return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  7559. }
  7560. function d3_scale_linearTickRange(domain, m) {
  7561. if (m == null) m = 10;
  7562. var extent = d3_scaleExtent(domain), span = extent[1] - extent[0], step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), err = m / span * step;
  7563. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  7564. extent[0] = Math.ceil(extent[0] / step) * step;
  7565. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  7566. extent[2] = step;
  7567. return extent;
  7568. }
  7569. function d3_scale_linearTicks(domain, m) {
  7570. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  7571. }
  7572. function d3_scale_linearTickFormat(domain, m, format) {
  7573. var range = d3_scale_linearTickRange(domain, m);
  7574. if (format) {
  7575. var match = d3_format_re.exec(format);
  7576. match.shift();
  7577. if (match[8] === "s") {
  7578. var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
  7579. if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
  7580. match[8] = "f";
  7581. format = d3.format(match.join(""));
  7582. return function(d) {
  7583. return format(prefix.scale(d)) + prefix.symbol;
  7584. };
  7585. }
  7586. if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
  7587. format = match.join("");
  7588. } else {
  7589. format = ",." + d3_scale_linearPrecision(range[2]) + "f";
  7590. }
  7591. return d3.format(format);
  7592. }
  7593. var d3_scale_linearFormatSignificant = {
  7594. s: 1,
  7595. g: 1,
  7596. p: 1,
  7597. r: 1,
  7598. e: 1
  7599. };
  7600. function d3_scale_linearPrecision(value) {
  7601. return -Math.floor(Math.log(value) / Math.LN10 + .01);
  7602. }
  7603. function d3_scale_linearFormatPrecision(type, range) {
  7604. var p = d3_scale_linearPrecision(range[2]);
  7605. return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
  7606. }
  7607. d3.scale.log = function() {
  7608. return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
  7609. };
  7610. function d3_scale_log(linear, base, positive, domain) {
  7611. function log(x) {
  7612. return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
  7613. }
  7614. function pow(x) {
  7615. return positive ? Math.pow(base, x) : -Math.pow(base, -x);
  7616. }
  7617. function scale(x) {
  7618. return linear(log(x));
  7619. }
  7620. scale.invert = function(x) {
  7621. return pow(linear.invert(x));
  7622. };
  7623. scale.domain = function(x) {
  7624. if (!arguments.length) return domain;
  7625. positive = x[0] >= 0;
  7626. linear.domain((domain = x.map(Number)).map(log));
  7627. return scale;
  7628. };
  7629. scale.base = function(_) {
  7630. if (!arguments.length) return base;
  7631. base = +_;
  7632. linear.domain(domain.map(log));
  7633. return scale;
  7634. };
  7635. scale.nice = function() {
  7636. var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
  7637. linear.domain(niced);
  7638. domain = niced.map(pow);
  7639. return scale;
  7640. };
  7641. scale.ticks = function() {
  7642. var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
  7643. if (isFinite(j - i)) {
  7644. if (positive) {
  7645. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
  7646. ticks.push(pow(i));
  7647. } else {
  7648. ticks.push(pow(i));
  7649. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
  7650. }
  7651. for (i = 0; ticks[i] < u; i++) {}
  7652. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  7653. ticks = ticks.slice(i, j);
  7654. }
  7655. return ticks;
  7656. };
  7657. scale.tickFormat = function(n, format) {
  7658. if (!arguments.length) return d3_scale_logFormat;
  7659. if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
  7660. var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
  7661. Math.floor), e;
  7662. return function(d) {
  7663. return d / pow(f(log(d) + e)) <= k ? format(d) : "";
  7664. };
  7665. };
  7666. scale.copy = function() {
  7667. return d3_scale_log(linear.copy(), base, positive, domain);
  7668. };
  7669. return d3_scale_linearRebind(scale, linear);
  7670. }
  7671. var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
  7672. floor: function(x) {
  7673. return -Math.ceil(-x);
  7674. },
  7675. ceil: function(x) {
  7676. return -Math.floor(-x);
  7677. }
  7678. };
  7679. d3.scale.pow = function() {
  7680. return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
  7681. };
  7682. function d3_scale_pow(linear, exponent, domain) {
  7683. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  7684. function scale(x) {
  7685. return linear(powp(x));
  7686. }
  7687. scale.invert = function(x) {
  7688. return powb(linear.invert(x));
  7689. };
  7690. scale.domain = function(x) {
  7691. if (!arguments.length) return domain;
  7692. linear.domain((domain = x.map(Number)).map(powp));
  7693. return scale;
  7694. };
  7695. scale.ticks = function(m) {
  7696. return d3_scale_linearTicks(domain, m);
  7697. };
  7698. scale.tickFormat = function(m, format) {
  7699. return d3_scale_linearTickFormat(domain, m, format);
  7700. };
  7701. scale.nice = function(m) {
  7702. return scale.domain(d3_scale_linearNice(domain, m));
  7703. };
  7704. scale.exponent = function(x) {
  7705. if (!arguments.length) return exponent;
  7706. powp = d3_scale_powPow(exponent = x);
  7707. powb = d3_scale_powPow(1 / exponent);
  7708. linear.domain(domain.map(powp));
  7709. return scale;
  7710. };
  7711. scale.copy = function() {
  7712. return d3_scale_pow(linear.copy(), exponent, domain);
  7713. };
  7714. return d3_scale_linearRebind(scale, linear);
  7715. }
  7716. function d3_scale_powPow(e) {
  7717. return function(x) {
  7718. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  7719. };
  7720. }
  7721. d3.scale.sqrt = function() {
  7722. return d3.scale.pow().exponent(.5);
  7723. };
  7724. d3.scale.ordinal = function() {
  7725. return d3_scale_ordinal([], {
  7726. t: "range",
  7727. a: [ [] ]
  7728. });
  7729. };
  7730. function d3_scale_ordinal(domain, ranger) {
  7731. var index, range, rangeBand;
  7732. function scale(x) {
  7733. return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
  7734. }
  7735. function steps(start, step) {
  7736. return d3.range(domain.length).map(function(i) {
  7737. return start + step * i;
  7738. });
  7739. }
  7740. scale.domain = function(x) {
  7741. if (!arguments.length) return domain;
  7742. domain = [];
  7743. index = new d3_Map();
  7744. var i = -1, n = x.length, xi;
  7745. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  7746. return scale[ranger.t].apply(scale, ranger.a);
  7747. };
  7748. scale.range = function(x) {
  7749. if (!arguments.length) return range;
  7750. range = x;
  7751. rangeBand = 0;
  7752. ranger = {
  7753. t: "range",
  7754. a: arguments
  7755. };
  7756. return scale;
  7757. };
  7758. scale.rangePoints = function(x, padding) {
  7759. if (arguments.length < 2) padding = 0;
  7760. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
  7761. 0) : (stop - start) / (domain.length - 1 + padding);
  7762. range = steps(start + step * padding / 2, step);
  7763. rangeBand = 0;
  7764. ranger = {
  7765. t: "rangePoints",
  7766. a: arguments
  7767. };
  7768. return scale;
  7769. };
  7770. scale.rangeRoundPoints = function(x, padding) {
  7771. if (arguments.length < 2) padding = 0;
  7772. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
  7773. 0) : (stop - start) / (domain.length - 1 + padding) | 0;
  7774. range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
  7775. rangeBand = 0;
  7776. ranger = {
  7777. t: "rangeRoundPoints",
  7778. a: arguments
  7779. };
  7780. return scale;
  7781. };
  7782. scale.rangeBands = function(x, padding, outerPadding) {
  7783. if (arguments.length < 2) padding = 0;
  7784. if (arguments.length < 3) outerPadding = padding;
  7785. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  7786. range = steps(start + step * outerPadding, step);
  7787. if (reverse) range.reverse();
  7788. rangeBand = step * (1 - padding);
  7789. ranger = {
  7790. t: "rangeBands",
  7791. a: arguments
  7792. };
  7793. return scale;
  7794. };
  7795. scale.rangeRoundBands = function(x, padding, outerPadding) {
  7796. if (arguments.length < 2) padding = 0;
  7797. if (arguments.length < 3) outerPadding = padding;
  7798. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
  7799. range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
  7800. if (reverse) range.reverse();
  7801. rangeBand = Math.round(step * (1 - padding));
  7802. ranger = {
  7803. t: "rangeRoundBands",
  7804. a: arguments
  7805. };
  7806. return scale;
  7807. };
  7808. scale.rangeBand = function() {
  7809. return rangeBand;
  7810. };
  7811. scale.rangeExtent = function() {
  7812. return d3_scaleExtent(ranger.a[0]);
  7813. };
  7814. scale.copy = function() {
  7815. return d3_scale_ordinal(domain, ranger);
  7816. };
  7817. return scale.domain(domain);
  7818. }
  7819. d3.scale.category10 = function() {
  7820. return d3.scale.ordinal().range(d3_category10);
  7821. };
  7822. d3.scale.category20 = function() {
  7823. return d3.scale.ordinal().range(d3_category20);
  7824. };
  7825. d3.scale.category20b = function() {
  7826. return d3.scale.ordinal().range(d3_category20b);
  7827. };
  7828. d3.scale.category20c = function() {
  7829. return d3.scale.ordinal().range(d3_category20c);
  7830. };
  7831. var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
  7832. var d3_category20 = [ 2062260, 11454440, 16744206, 16759672, 2924588, 10018698, 14034728, 16750742, 9725885, 12955861, 9197131, 12885140, 14907330, 16234194, 8355711, 13092807, 12369186, 14408589, 1556175, 10410725 ].map(d3_rgbString);
  7833. var d3_category20b = [ 3750777, 5395619, 7040719, 10264286, 6519097, 9216594, 11915115, 13556636, 9202993, 12426809, 15186514, 15190932, 8666169, 11356490, 14049643, 15177372, 8077683, 10834324, 13528509, 14589654 ].map(d3_rgbString);
  7834. var d3_category20c = [ 3244733, 7057110, 10406625, 13032431, 15095053, 16616764, 16625259, 16634018, 3253076, 7652470, 10607003, 13101504, 7695281, 10394312, 12369372, 14342891, 6513507, 9868950, 12434877, 14277081 ].map(d3_rgbString);
  7835. d3.scale.quantile = function() {
  7836. return d3_scale_quantile([], []);
  7837. };
  7838. function d3_scale_quantile(domain, range) {
  7839. var thresholds;
  7840. function rescale() {
  7841. var k = 0, q = range.length;
  7842. thresholds = [];
  7843. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  7844. return scale;
  7845. }
  7846. function scale(x) {
  7847. if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
  7848. }
  7849. scale.domain = function(x) {
  7850. if (!arguments.length) return domain;
  7851. domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
  7852. return rescale();
  7853. };
  7854. scale.range = function(x) {
  7855. if (!arguments.length) return range;
  7856. range = x;
  7857. return rescale();
  7858. };
  7859. scale.quantiles = function() {
  7860. return thresholds;
  7861. };
  7862. scale.invertExtent = function(y) {
  7863. y = range.indexOf(y);
  7864. return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
  7865. };
  7866. scale.copy = function() {
  7867. return d3_scale_quantile(domain, range);
  7868. };
  7869. return rescale();
  7870. }
  7871. d3.scale.quantize = function() {
  7872. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  7873. };
  7874. function d3_scale_quantize(x0, x1, range) {
  7875. var kx, i;
  7876. function scale(x) {
  7877. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  7878. }
  7879. function rescale() {
  7880. kx = range.length / (x1 - x0);
  7881. i = range.length - 1;
  7882. return scale;
  7883. }
  7884. scale.domain = function(x) {
  7885. if (!arguments.length) return [ x0, x1 ];
  7886. x0 = +x[0];
  7887. x1 = +x[x.length - 1];
  7888. return rescale();
  7889. };
  7890. scale.range = function(x) {
  7891. if (!arguments.length) return range;
  7892. range = x;
  7893. return rescale();
  7894. };
  7895. scale.invertExtent = function(y) {
  7896. y = range.indexOf(y);
  7897. y = y < 0 ? NaN : y / kx + x0;
  7898. return [ y, y + 1 / kx ];
  7899. };
  7900. scale.copy = function() {
  7901. return d3_scale_quantize(x0, x1, range);
  7902. };
  7903. return rescale();
  7904. }
  7905. d3.scale.threshold = function() {
  7906. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  7907. };
  7908. function d3_scale_threshold(domain, range) {
  7909. function scale(x) {
  7910. if (x <= x) return range[d3.bisect(domain, x)];
  7911. }
  7912. scale.domain = function(_) {
  7913. if (!arguments.length) return domain;
  7914. domain = _;
  7915. return scale;
  7916. };
  7917. scale.range = function(_) {
  7918. if (!arguments.length) return range;
  7919. range = _;
  7920. return scale;
  7921. };
  7922. scale.invertExtent = function(y) {
  7923. y = range.indexOf(y);
  7924. return [ domain[y - 1], domain[y] ];
  7925. };
  7926. scale.copy = function() {
  7927. return d3_scale_threshold(domain, range);
  7928. };
  7929. return scale;
  7930. }
  7931. d3.scale.identity = function() {
  7932. return d3_scale_identity([ 0, 1 ]);
  7933. };
  7934. function d3_scale_identity(domain) {
  7935. function identity(x) {
  7936. return +x;
  7937. }
  7938. identity.invert = identity;
  7939. identity.domain = identity.range = function(x) {
  7940. if (!arguments.length) return domain;
  7941. domain = x.map(identity);
  7942. return identity;
  7943. };
  7944. identity.ticks = function(m) {
  7945. return d3_scale_linearTicks(domain, m);
  7946. };
  7947. identity.tickFormat = function(m, format) {
  7948. return d3_scale_linearTickFormat(domain, m, format);
  7949. };
  7950. identity.copy = function() {
  7951. return d3_scale_identity(domain);
  7952. };
  7953. return identity;
  7954. }
  7955. d3.svg = {};
  7956. function d3_zero() {
  7957. return 0;
  7958. }
  7959. d3.svg.arc = function() {
  7960. var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
  7961. function arc() {
  7962. var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
  7963. if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
  7964. if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
  7965. var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
  7966. if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
  7967. rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
  7968. if (!cw) p1 *= -1;
  7969. if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
  7970. if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
  7971. }
  7972. if (r1) {
  7973. x0 = r1 * Math.cos(a0 + p1);
  7974. y0 = r1 * Math.sin(a0 + p1);
  7975. x1 = r1 * Math.cos(a1 - p1);
  7976. y1 = r1 * Math.sin(a1 - p1);
  7977. var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
  7978. if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
  7979. var h1 = (a0 + a1) / 2;
  7980. x0 = r1 * Math.cos(h1);
  7981. y0 = r1 * Math.sin(h1);
  7982. x1 = y1 = null;
  7983. }
  7984. } else {
  7985. x0 = y0 = 0;
  7986. }
  7987. if (r0) {
  7988. x2 = r0 * Math.cos(a1 - p0);
  7989. y2 = r0 * Math.sin(a1 - p0);
  7990. x3 = r0 * Math.cos(a0 + p0);
  7991. y3 = r0 * Math.sin(a0 + p0);
  7992. var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
  7993. if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
  7994. var h0 = (a0 + a1) / 2;
  7995. x2 = r0 * Math.cos(h0);
  7996. y2 = r0 * Math.sin(h0);
  7997. x3 = y3 = null;
  7998. }
  7999. } else {
  8000. x2 = y2 = 0;
  8001. }
  8002. if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
  8003. cr = r0 < r1 ^ cw ? 0 : 1;
  8004. var rc1 = rc, rc0 = rc;
  8005. if (da < π) {
  8006. var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  8007. rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
  8008. rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
  8009. }
  8010. if (x1 != null) {
  8011. var t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
  8012. if (rc === rc1) {
  8013. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
  8014. } else {
  8015. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
  8016. }
  8017. } else {
  8018. path.push("M", x0, ",", y0);
  8019. }
  8020. if (x3 != null) {
  8021. var t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
  8022. if (rc === rc0) {
  8023. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  8024. } else {
  8025. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  8026. }
  8027. } else {
  8028. path.push("L", x2, ",", y2);
  8029. }
  8030. } else {
  8031. path.push("M", x0, ",", y0);
  8032. if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
  8033. path.push("L", x2, ",", y2);
  8034. if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
  8035. }
  8036. path.push("Z");
  8037. return path.join("");
  8038. }
  8039. function circleSegment(r1, cw) {
  8040. return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
  8041. }
  8042. arc.innerRadius = function(v) {
  8043. if (!arguments.length) return innerRadius;
  8044. innerRadius = d3_functor(v);
  8045. return arc;
  8046. };
  8047. arc.outerRadius = function(v) {
  8048. if (!arguments.length) return outerRadius;
  8049. outerRadius = d3_functor(v);
  8050. return arc;
  8051. };
  8052. arc.cornerRadius = function(v) {
  8053. if (!arguments.length) return cornerRadius;
  8054. cornerRadius = d3_functor(v);
  8055. return arc;
  8056. };
  8057. arc.padRadius = function(v) {
  8058. if (!arguments.length) return padRadius;
  8059. padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
  8060. return arc;
  8061. };
  8062. arc.startAngle = function(v) {
  8063. if (!arguments.length) return startAngle;
  8064. startAngle = d3_functor(v);
  8065. return arc;
  8066. };
  8067. arc.endAngle = function(v) {
  8068. if (!arguments.length) return endAngle;
  8069. endAngle = d3_functor(v);
  8070. return arc;
  8071. };
  8072. arc.padAngle = function(v) {
  8073. if (!arguments.length) return padAngle;
  8074. padAngle = d3_functor(v);
  8075. return arc;
  8076. };
  8077. arc.centroid = function() {
  8078. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
  8079. return [ Math.cos(a) * r, Math.sin(a) * r ];
  8080. };
  8081. return arc;
  8082. };
  8083. var d3_svg_arcAuto = "auto";
  8084. function d3_svg_arcInnerRadius(d) {
  8085. return d.innerRadius;
  8086. }
  8087. function d3_svg_arcOuterRadius(d) {
  8088. return d.outerRadius;
  8089. }
  8090. function d3_svg_arcStartAngle(d) {
  8091. return d.startAngle;
  8092. }
  8093. function d3_svg_arcEndAngle(d) {
  8094. return d.endAngle;
  8095. }
  8096. function d3_svg_arcPadAngle(d) {
  8097. return d && d.padAngle;
  8098. }
  8099. function d3_svg_arcSweep(x0, y0, x1, y1) {
  8100. return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
  8101. }
  8102. function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
  8103. var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
  8104. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  8105. return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
  8106. }
  8107. function d3_svg_line(projection) {
  8108. var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  8109. function line(data) {
  8110. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  8111. function segment() {
  8112. segments.push("M", interpolate(projection(points), tension));
  8113. }
  8114. while (++i < n) {
  8115. if (defined.call(this, d = data[i], i)) {
  8116. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  8117. } else if (points.length) {
  8118. segment();
  8119. points = [];
  8120. }
  8121. }
  8122. if (points.length) segment();
  8123. return segments.length ? segments.join("") : null;
  8124. }
  8125. line.x = function(_) {
  8126. if (!arguments.length) return x;
  8127. x = _;
  8128. return line;
  8129. };
  8130. line.y = function(_) {
  8131. if (!arguments.length) return y;
  8132. y = _;
  8133. return line;
  8134. };
  8135. line.defined = function(_) {
  8136. if (!arguments.length) return defined;
  8137. defined = _;
  8138. return line;
  8139. };
  8140. line.interpolate = function(_) {
  8141. if (!arguments.length) return interpolateKey;
  8142. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8143. return line;
  8144. };
  8145. line.tension = function(_) {
  8146. if (!arguments.length) return tension;
  8147. tension = _;
  8148. return line;
  8149. };
  8150. return line;
  8151. }
  8152. d3.svg.line = function() {
  8153. return d3_svg_line(d3_identity);
  8154. };
  8155. var d3_svg_lineInterpolators = d3.map({
  8156. linear: d3_svg_lineLinear,
  8157. "linear-closed": d3_svg_lineLinearClosed,
  8158. step: d3_svg_lineStep,
  8159. "step-before": d3_svg_lineStepBefore,
  8160. "step-after": d3_svg_lineStepAfter,
  8161. basis: d3_svg_lineBasis,
  8162. "basis-open": d3_svg_lineBasisOpen,
  8163. "basis-closed": d3_svg_lineBasisClosed,
  8164. bundle: d3_svg_lineBundle,
  8165. cardinal: d3_svg_lineCardinal,
  8166. "cardinal-open": d3_svg_lineCardinalOpen,
  8167. "cardinal-closed": d3_svg_lineCardinalClosed,
  8168. monotone: d3_svg_lineMonotone
  8169. });
  8170. d3_svg_lineInterpolators.forEach(function(key, value) {
  8171. value.key = key;
  8172. value.closed = /-closed$/.test(key);
  8173. });
  8174. function d3_svg_lineLinear(points) {
  8175. return points.length > 1 ? points.join("L") : points + "Z";
  8176. }
  8177. function d3_svg_lineLinearClosed(points) {
  8178. return points.join("L") + "Z";
  8179. }
  8180. function d3_svg_lineStep(points) {
  8181. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8182. while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
  8183. if (n > 1) path.push("H", p[0]);
  8184. return path.join("");
  8185. }
  8186. function d3_svg_lineStepBefore(points) {
  8187. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8188. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  8189. return path.join("");
  8190. }
  8191. function d3_svg_lineStepAfter(points) {
  8192. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8193. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  8194. return path.join("");
  8195. }
  8196. function d3_svg_lineCardinalOpen(points, tension) {
  8197. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
  8198. }
  8199. function d3_svg_lineCardinalClosed(points, tension) {
  8200. return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  8201. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  8202. }
  8203. function d3_svg_lineCardinal(points, tension) {
  8204. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  8205. }
  8206. function d3_svg_lineHermite(points, tangents) {
  8207. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  8208. return d3_svg_lineLinear(points);
  8209. }
  8210. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  8211. if (quad) {
  8212. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  8213. p0 = points[1];
  8214. pi = 2;
  8215. }
  8216. if (tangents.length > 1) {
  8217. t = tangents[1];
  8218. p = points[pi];
  8219. pi++;
  8220. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8221. for (var i = 2; i < tangents.length; i++, pi++) {
  8222. p = points[pi];
  8223. t = tangents[i];
  8224. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8225. }
  8226. }
  8227. if (quad) {
  8228. var lp = points[pi];
  8229. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  8230. }
  8231. return path;
  8232. }
  8233. function d3_svg_lineCardinalTangents(points, tension) {
  8234. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  8235. while (++i < n) {
  8236. p0 = p1;
  8237. p1 = p2;
  8238. p2 = points[i];
  8239. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  8240. }
  8241. return tangents;
  8242. }
  8243. function d3_svg_lineBasis(points) {
  8244. if (points.length < 3) return d3_svg_lineLinear(points);
  8245. var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8246. points.push(points[n - 1]);
  8247. while (++i <= n) {
  8248. pi = points[i];
  8249. px.shift();
  8250. px.push(pi[0]);
  8251. py.shift();
  8252. py.push(pi[1]);
  8253. d3_svg_lineBasisBezier(path, px, py);
  8254. }
  8255. points.pop();
  8256. path.push("L", pi);
  8257. return path.join("");
  8258. }
  8259. function d3_svg_lineBasisOpen(points) {
  8260. if (points.length < 4) return d3_svg_lineLinear(points);
  8261. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  8262. while (++i < 3) {
  8263. pi = points[i];
  8264. px.push(pi[0]);
  8265. py.push(pi[1]);
  8266. }
  8267. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  8268. --i;
  8269. while (++i < n) {
  8270. pi = points[i];
  8271. px.shift();
  8272. px.push(pi[0]);
  8273. py.shift();
  8274. py.push(pi[1]);
  8275. d3_svg_lineBasisBezier(path, px, py);
  8276. }
  8277. return path.join("");
  8278. }
  8279. function d3_svg_lineBasisClosed(points) {
  8280. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  8281. while (++i < 4) {
  8282. pi = points[i % n];
  8283. px.push(pi[0]);
  8284. py.push(pi[1]);
  8285. }
  8286. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8287. --i;
  8288. while (++i < m) {
  8289. pi = points[i % n];
  8290. px.shift();
  8291. px.push(pi[0]);
  8292. py.shift();
  8293. py.push(pi[1]);
  8294. d3_svg_lineBasisBezier(path, px, py);
  8295. }
  8296. return path.join("");
  8297. }
  8298. function d3_svg_lineBundle(points, tension) {
  8299. var n = points.length - 1;
  8300. if (n) {
  8301. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  8302. while (++i <= n) {
  8303. p = points[i];
  8304. t = i / n;
  8305. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  8306. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  8307. }
  8308. }
  8309. return d3_svg_lineBasis(points);
  8310. }
  8311. function d3_svg_lineDot4(a, b) {
  8312. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  8313. }
  8314. var d3_svg_lineBasisBezier1 = [ 0, 2 / 3, 1 / 3, 0 ], d3_svg_lineBasisBezier2 = [ 0, 1 / 3, 2 / 3, 0 ], d3_svg_lineBasisBezier3 = [ 0, 1 / 6, 2 / 3, 1 / 6 ];
  8315. function d3_svg_lineBasisBezier(path, x, y) {
  8316. path.push("C", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y));
  8317. }
  8318. function d3_svg_lineSlope(p0, p1) {
  8319. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  8320. }
  8321. function d3_svg_lineFiniteDifferences(points) {
  8322. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  8323. while (++i < j) {
  8324. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  8325. }
  8326. m[i] = d;
  8327. return m;
  8328. }
  8329. function d3_svg_lineMonotoneTangents(points) {
  8330. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  8331. while (++i < j) {
  8332. d = d3_svg_lineSlope(points[i], points[i + 1]);
  8333. if (abs(d) < ε) {
  8334. m[i] = m[i + 1] = 0;
  8335. } else {
  8336. a = m[i] / d;
  8337. b = m[i + 1] / d;
  8338. s = a * a + b * b;
  8339. if (s > 9) {
  8340. s = d * 3 / Math.sqrt(s);
  8341. m[i] = s * a;
  8342. m[i + 1] = s * b;
  8343. }
  8344. }
  8345. }
  8346. i = -1;
  8347. while (++i <= j) {
  8348. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  8349. tangents.push([ s || 0, m[i] * s || 0 ]);
  8350. }
  8351. return tangents;
  8352. }
  8353. function d3_svg_lineMonotone(points) {
  8354. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  8355. }
  8356. d3.svg.line.radial = function() {
  8357. var line = d3_svg_line(d3_svg_lineRadial);
  8358. line.radius = line.x, delete line.x;
  8359. line.angle = line.y, delete line.y;
  8360. return line;
  8361. };
  8362. function d3_svg_lineRadial(points) {
  8363. var point, i = -1, n = points.length, r, a;
  8364. while (++i < n) {
  8365. point = points[i];
  8366. r = point[0];
  8367. a = point[1] - halfπ;
  8368. point[0] = r * Math.cos(a);
  8369. point[1] = r * Math.sin(a);
  8370. }
  8371. return points;
  8372. }
  8373. function d3_svg_area(projection) {
  8374. var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
  8375. function area(data) {
  8376. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  8377. return x;
  8378. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  8379. return y;
  8380. } : d3_functor(y1), x, y;
  8381. function segment() {
  8382. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  8383. }
  8384. while (++i < n) {
  8385. if (defined.call(this, d = data[i], i)) {
  8386. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  8387. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  8388. } else if (points0.length) {
  8389. segment();
  8390. points0 = [];
  8391. points1 = [];
  8392. }
  8393. }
  8394. if (points0.length) segment();
  8395. return segments.length ? segments.join("") : null;
  8396. }
  8397. area.x = function(_) {
  8398. if (!arguments.length) return x1;
  8399. x0 = x1 = _;
  8400. return area;
  8401. };
  8402. area.x0 = function(_) {
  8403. if (!arguments.length) return x0;
  8404. x0 = _;
  8405. return area;
  8406. };
  8407. area.x1 = function(_) {
  8408. if (!arguments.length) return x1;
  8409. x1 = _;
  8410. return area;
  8411. };
  8412. area.y = function(_) {
  8413. if (!arguments.length) return y1;
  8414. y0 = y1 = _;
  8415. return area;
  8416. };
  8417. area.y0 = function(_) {
  8418. if (!arguments.length) return y0;
  8419. y0 = _;
  8420. return area;
  8421. };
  8422. area.y1 = function(_) {
  8423. if (!arguments.length) return y1;
  8424. y1 = _;
  8425. return area;
  8426. };
  8427. area.defined = function(_) {
  8428. if (!arguments.length) return defined;
  8429. defined = _;
  8430. return area;
  8431. };
  8432. area.interpolate = function(_) {
  8433. if (!arguments.length) return interpolateKey;
  8434. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8435. interpolateReverse = interpolate.reverse || interpolate;
  8436. L = interpolate.closed ? "M" : "L";
  8437. return area;
  8438. };
  8439. area.tension = function(_) {
  8440. if (!arguments.length) return tension;
  8441. tension = _;
  8442. return area;
  8443. };
  8444. return area;
  8445. }
  8446. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  8447. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  8448. d3.svg.area = function() {
  8449. return d3_svg_area(d3_identity);
  8450. };
  8451. d3.svg.area.radial = function() {
  8452. var area = d3_svg_area(d3_svg_lineRadial);
  8453. area.radius = area.x, delete area.x;
  8454. area.innerRadius = area.x0, delete area.x0;
  8455. area.outerRadius = area.x1, delete area.x1;
  8456. area.angle = area.y, delete area.y;
  8457. area.startAngle = area.y0, delete area.y0;
  8458. area.endAngle = area.y1, delete area.y1;
  8459. return area;
  8460. };
  8461. d3.svg.chord = function() {
  8462. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  8463. function chord(d, i) {
  8464. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  8465. return "M" + s.p0 + arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t) ? curve(s.r, s.p1, s.r, s.p0) : curve(s.r, s.p1, t.r, t.p0) + arc(t.r, t.p1, t.a1 - t.a0) + curve(t.r, t.p1, s.r, s.p0)) + "Z";
  8466. }
  8467. function subgroup(self, f, d, i) {
  8468. var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
  8469. return {
  8470. r: r,
  8471. a0: a0,
  8472. a1: a1,
  8473. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  8474. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  8475. };
  8476. }
  8477. function equals(a, b) {
  8478. return a.a0 == b.a0 && a.a1 == b.a1;
  8479. }
  8480. function arc(r, p, a) {
  8481. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  8482. }
  8483. function curve(r0, p0, r1, p1) {
  8484. return "Q 0,0 " + p1;
  8485. }
  8486. chord.radius = function(v) {
  8487. if (!arguments.length) return radius;
  8488. radius = d3_functor(v);
  8489. return chord;
  8490. };
  8491. chord.source = function(v) {
  8492. if (!arguments.length) return source;
  8493. source = d3_functor(v);
  8494. return chord;
  8495. };
  8496. chord.target = function(v) {
  8497. if (!arguments.length) return target;
  8498. target = d3_functor(v);
  8499. return chord;
  8500. };
  8501. chord.startAngle = function(v) {
  8502. if (!arguments.length) return startAngle;
  8503. startAngle = d3_functor(v);
  8504. return chord;
  8505. };
  8506. chord.endAngle = function(v) {
  8507. if (!arguments.length) return endAngle;
  8508. endAngle = d3_functor(v);
  8509. return chord;
  8510. };
  8511. return chord;
  8512. };
  8513. function d3_svg_chordRadius(d) {
  8514. return d.radius;
  8515. }
  8516. d3.svg.diagonal = function() {
  8517. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  8518. function diagonal(d, i) {
  8519. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  8520. x: p0.x,
  8521. y: m
  8522. }, {
  8523. x: p3.x,
  8524. y: m
  8525. }, p3 ];
  8526. p = p.map(projection);
  8527. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  8528. }
  8529. diagonal.source = function(x) {
  8530. if (!arguments.length) return source;
  8531. source = d3_functor(x);
  8532. return diagonal;
  8533. };
  8534. diagonal.target = function(x) {
  8535. if (!arguments.length) return target;
  8536. target = d3_functor(x);
  8537. return diagonal;
  8538. };
  8539. diagonal.projection = function(x) {
  8540. if (!arguments.length) return projection;
  8541. projection = x;
  8542. return diagonal;
  8543. };
  8544. return diagonal;
  8545. };
  8546. function d3_svg_diagonalProjection(d) {
  8547. return [ d.x, d.y ];
  8548. }
  8549. d3.svg.diagonal.radial = function() {
  8550. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  8551. diagonal.projection = function(x) {
  8552. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  8553. };
  8554. return diagonal;
  8555. };
  8556. function d3_svg_diagonalRadialProjection(projection) {
  8557. return function() {
  8558. var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
  8559. return [ r * Math.cos(a), r * Math.sin(a) ];
  8560. };
  8561. }
  8562. d3.svg.symbol = function() {
  8563. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  8564. function symbol(d, i) {
  8565. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  8566. }
  8567. symbol.type = function(x) {
  8568. if (!arguments.length) return type;
  8569. type = d3_functor(x);
  8570. return symbol;
  8571. };
  8572. symbol.size = function(x) {
  8573. if (!arguments.length) return size;
  8574. size = d3_functor(x);
  8575. return symbol;
  8576. };
  8577. return symbol;
  8578. };
  8579. function d3_svg_symbolSize() {
  8580. return 64;
  8581. }
  8582. function d3_svg_symbolType() {
  8583. return "circle";
  8584. }
  8585. function d3_svg_symbolCircle(size) {
  8586. var r = Math.sqrt(size / π);
  8587. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  8588. }
  8589. var d3_svg_symbols = d3.map({
  8590. circle: d3_svg_symbolCircle,
  8591. cross: function(size) {
  8592. var r = Math.sqrt(size / 5) / 2;
  8593. return "M" + -3 * r + "," + -r + "H" + -r + "V" + -3 * r + "H" + r + "V" + -r + "H" + 3 * r + "V" + r + "H" + r + "V" + 3 * r + "H" + -r + "V" + r + "H" + -3 * r + "Z";
  8594. },
  8595. diamond: function(size) {
  8596. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  8597. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  8598. },
  8599. square: function(size) {
  8600. var r = Math.sqrt(size) / 2;
  8601. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  8602. },
  8603. "triangle-down": function(size) {
  8604. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8605. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  8606. },
  8607. "triangle-up": function(size) {
  8608. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8609. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  8610. }
  8611. });
  8612. d3.svg.symbolTypes = d3_svg_symbols.keys();
  8613. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  8614. d3_selectionPrototype.transition = function(name) {
  8615. var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
  8616. time: Date.now(),
  8617. ease: d3_ease_cubicInOut,
  8618. delay: 0,
  8619. duration: 250
  8620. };
  8621. for (var j = -1, m = this.length; ++j < m; ) {
  8622. subgroups.push(subgroup = []);
  8623. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8624. if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
  8625. subgroup.push(node);
  8626. }
  8627. }
  8628. return d3_transition(subgroups, ns, id);
  8629. };
  8630. d3_selectionPrototype.interrupt = function(name) {
  8631. return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
  8632. };
  8633. var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
  8634. function d3_selection_interruptNS(ns) {
  8635. return function() {
  8636. var lock, activeId, active;
  8637. if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
  8638. active.timer.c = null;
  8639. active.timer.t = NaN;
  8640. if (--lock.count) delete lock[activeId]; else delete this[ns];
  8641. lock.active += .5;
  8642. active.event && active.event.interrupt.call(this, this.__data__, active.index);
  8643. }
  8644. };
  8645. }
  8646. function d3_transition(groups, ns, id) {
  8647. d3_subclass(groups, d3_transitionPrototype);
  8648. groups.namespace = ns;
  8649. groups.id = id;
  8650. return groups;
  8651. }
  8652. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
  8653. d3_transitionPrototype.call = d3_selectionPrototype.call;
  8654. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  8655. d3_transitionPrototype.node = d3_selectionPrototype.node;
  8656. d3_transitionPrototype.size = d3_selectionPrototype.size;
  8657. d3.transition = function(selection, name) {
  8658. return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
  8659. };
  8660. d3.transition.prototype = d3_transitionPrototype;
  8661. d3_transitionPrototype.select = function(selector) {
  8662. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
  8663. selector = d3_selection_selector(selector);
  8664. for (var j = -1, m = this.length; ++j < m; ) {
  8665. subgroups.push(subgroup = []);
  8666. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8667. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
  8668. if ("__data__" in node) subnode.__data__ = node.__data__;
  8669. d3_transitionNode(subnode, i, ns, id, node[ns][id]);
  8670. subgroup.push(subnode);
  8671. } else {
  8672. subgroup.push(null);
  8673. }
  8674. }
  8675. }
  8676. return d3_transition(subgroups, ns, id);
  8677. };
  8678. d3_transitionPrototype.selectAll = function(selector) {
  8679. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
  8680. selector = d3_selection_selectorAll(selector);
  8681. for (var j = -1, m = this.length; ++j < m; ) {
  8682. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8683. if (node = group[i]) {
  8684. transition = node[ns][id];
  8685. subnodes = selector.call(node, node.__data__, i, j);
  8686. subgroups.push(subgroup = []);
  8687. for (var k = -1, o = subnodes.length; ++k < o; ) {
  8688. if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
  8689. subgroup.push(subnode);
  8690. }
  8691. }
  8692. }
  8693. }
  8694. return d3_transition(subgroups, ns, id);
  8695. };
  8696. d3_transitionPrototype.filter = function(filter) {
  8697. var subgroups = [], subgroup, group, node;
  8698. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  8699. for (var j = 0, m = this.length; j < m; j++) {
  8700. subgroups.push(subgroup = []);
  8701. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8702. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  8703. subgroup.push(node);
  8704. }
  8705. }
  8706. }
  8707. return d3_transition(subgroups, this.namespace, this.id);
  8708. };
  8709. d3_transitionPrototype.tween = function(name, tween) {
  8710. var id = this.id, ns = this.namespace;
  8711. if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
  8712. return d3_selection_each(this, tween == null ? function(node) {
  8713. node[ns][id].tween.remove(name);
  8714. } : function(node) {
  8715. node[ns][id].tween.set(name, tween);
  8716. });
  8717. };
  8718. function d3_transition_tween(groups, name, value, tween) {
  8719. var id = groups.id, ns = groups.namespace;
  8720. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  8721. node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  8722. } : (value = tween(value), function(node) {
  8723. node[ns][id].tween.set(name, value);
  8724. }));
  8725. }
  8726. d3_transitionPrototype.attr = function(nameNS, value) {
  8727. if (arguments.length < 2) {
  8728. for (value in nameNS) this.attr(value, nameNS[value]);
  8729. return this;
  8730. }
  8731. var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
  8732. function attrNull() {
  8733. this.removeAttribute(name);
  8734. }
  8735. function attrNullNS() {
  8736. this.removeAttributeNS(name.space, name.local);
  8737. }
  8738. function attrTween(b) {
  8739. return b == null ? attrNull : (b += "", function() {
  8740. var a = this.getAttribute(name), i;
  8741. return a !== b && (i = interpolate(a, b), function(t) {
  8742. this.setAttribute(name, i(t));
  8743. });
  8744. });
  8745. }
  8746. function attrTweenNS(b) {
  8747. return b == null ? attrNullNS : (b += "", function() {
  8748. var a = this.getAttributeNS(name.space, name.local), i;
  8749. return a !== b && (i = interpolate(a, b), function(t) {
  8750. this.setAttributeNS(name.space, name.local, i(t));
  8751. });
  8752. });
  8753. }
  8754. return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
  8755. };
  8756. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  8757. var name = d3.ns.qualify(nameNS);
  8758. function attrTween(d, i) {
  8759. var f = tween.call(this, d, i, this.getAttribute(name));
  8760. return f && function(t) {
  8761. this.setAttribute(name, f(t));
  8762. };
  8763. }
  8764. function attrTweenNS(d, i) {
  8765. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  8766. return f && function(t) {
  8767. this.setAttributeNS(name.space, name.local, f(t));
  8768. };
  8769. }
  8770. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  8771. };
  8772. d3_transitionPrototype.style = function(name, value, priority) {
  8773. var n = arguments.length;
  8774. if (n < 3) {
  8775. if (typeof name !== "string") {
  8776. if (n < 2) value = "";
  8777. for (priority in name) this.style(priority, name[priority], value);
  8778. return this;
  8779. }
  8780. priority = "";
  8781. }
  8782. function styleNull() {
  8783. this.style.removeProperty(name);
  8784. }
  8785. function styleString(b) {
  8786. return b == null ? styleNull : (b += "", function() {
  8787. var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
  8788. return a !== b && (i = d3_interpolate(a, b), function(t) {
  8789. this.style.setProperty(name, i(t), priority);
  8790. });
  8791. });
  8792. }
  8793. return d3_transition_tween(this, "style." + name, value, styleString);
  8794. };
  8795. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  8796. if (arguments.length < 3) priority = "";
  8797. function styleTween(d, i) {
  8798. var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
  8799. return f && function(t) {
  8800. this.style.setProperty(name, f(t), priority);
  8801. };
  8802. }
  8803. return this.tween("style." + name, styleTween);
  8804. };
  8805. d3_transitionPrototype.text = function(value) {
  8806. return d3_transition_tween(this, "text", value, d3_transition_text);
  8807. };
  8808. function d3_transition_text(b) {
  8809. if (b == null) b = "";
  8810. return function() {
  8811. this.textContent = b;
  8812. };
  8813. }
  8814. d3_transitionPrototype.remove = function() {
  8815. var ns = this.namespace;
  8816. return this.each("end.transition", function() {
  8817. var p;
  8818. if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
  8819. });
  8820. };
  8821. d3_transitionPrototype.ease = function(value) {
  8822. var id = this.id, ns = this.namespace;
  8823. if (arguments.length < 1) return this.node()[ns][id].ease;
  8824. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  8825. return d3_selection_each(this, function(node) {
  8826. node[ns][id].ease = value;
  8827. });
  8828. };
  8829. d3_transitionPrototype.delay = function(value) {
  8830. var id = this.id, ns = this.namespace;
  8831. if (arguments.length < 1) return this.node()[ns][id].delay;
  8832. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8833. node[ns][id].delay = +value.call(node, node.__data__, i, j);
  8834. } : (value = +value, function(node) {
  8835. node[ns][id].delay = value;
  8836. }));
  8837. };
  8838. d3_transitionPrototype.duration = function(value) {
  8839. var id = this.id, ns = this.namespace;
  8840. if (arguments.length < 1) return this.node()[ns][id].duration;
  8841. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8842. node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
  8843. } : (value = Math.max(1, value), function(node) {
  8844. node[ns][id].duration = value;
  8845. }));
  8846. };
  8847. d3_transitionPrototype.each = function(type, listener) {
  8848. var id = this.id, ns = this.namespace;
  8849. if (arguments.length < 2) {
  8850. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  8851. try {
  8852. d3_transitionInheritId = id;
  8853. d3_selection_each(this, function(node, i, j) {
  8854. d3_transitionInherit = node[ns][id];
  8855. type.call(node, node.__data__, i, j);
  8856. });
  8857. } finally {
  8858. d3_transitionInherit = inherit;
  8859. d3_transitionInheritId = inheritId;
  8860. }
  8861. } else {
  8862. d3_selection_each(this, function(node) {
  8863. var transition = node[ns][id];
  8864. (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
  8865. });
  8866. }
  8867. return this;
  8868. };
  8869. d3_transitionPrototype.transition = function() {
  8870. var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
  8871. for (var j = 0, m = this.length; j < m; j++) {
  8872. subgroups.push(subgroup = []);
  8873. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8874. if (node = group[i]) {
  8875. transition = node[ns][id0];
  8876. d3_transitionNode(node, i, ns, id1, {
  8877. time: transition.time,
  8878. ease: transition.ease,
  8879. delay: transition.delay + transition.duration,
  8880. duration: transition.duration
  8881. });
  8882. }
  8883. subgroup.push(node);
  8884. }
  8885. }
  8886. return d3_transition(subgroups, ns, id1);
  8887. };
  8888. function d3_transitionNamespace(name) {
  8889. return name == null ? "__transition__" : "__transition_" + name + "__";
  8890. }
  8891. function d3_transitionNode(node, i, ns, id, inherit) {
  8892. var lock = node[ns] || (node[ns] = {
  8893. active: 0,
  8894. count: 0
  8895. }), transition = lock[id], time, timer, duration, ease, tweens;
  8896. function schedule(elapsed) {
  8897. var delay = transition.delay;
  8898. timer.t = delay + time;
  8899. if (delay <= elapsed) return start(elapsed - delay);
  8900. timer.c = start;
  8901. }
  8902. function start(elapsed) {
  8903. var activeId = lock.active, active = lock[activeId];
  8904. if (active) {
  8905. active.timer.c = null;
  8906. active.timer.t = NaN;
  8907. --lock.count;
  8908. delete lock[activeId];
  8909. active.event && active.event.interrupt.call(node, node.__data__, active.index);
  8910. }
  8911. for (var cancelId in lock) {
  8912. if (+cancelId < id) {
  8913. var cancel = lock[cancelId];
  8914. cancel.timer.c = null;
  8915. cancel.timer.t = NaN;
  8916. --lock.count;
  8917. delete lock[cancelId];
  8918. }
  8919. }
  8920. lock.active = id;
  8921. transition.event && transition.event.start.call(node, node.__data__, i);
  8922. tweens = [];
  8923. transition.tween.forEach(function(key, value) {
  8924. if (value = value.call(node, node.__data__, i)) {
  8925. tweens.push(value);
  8926. }
  8927. });
  8928. ease = transition.ease;
  8929. duration = transition.duration;
  8930. timer.c = tick;
  8931. d3_timer(function() {
  8932. if (timer.c && tick(elapsed || 1)) {
  8933. timer.c = null;
  8934. timer.t = NaN;
  8935. }
  8936. return 1;
  8937. }, 0, time);
  8938. }
  8939. function tick(elapsed) {
  8940. var t = elapsed / duration, e = ease(t), n = tweens.length;
  8941. while (n > 0) {
  8942. tweens[--n].call(node, e);
  8943. }
  8944. if (t >= 1) {
  8945. transition.event && transition.event.end.call(node, node.__data__, i);
  8946. if (--lock.count) delete lock[id]; else delete node[ns];
  8947. return 1;
  8948. }
  8949. }
  8950. if (!transition) {
  8951. time = inherit.time;
  8952. timer = d3_timer(schedule, 0, time);
  8953. transition = lock[id] = {
  8954. tween: new d3_Map(),
  8955. time: time,
  8956. timer: timer,
  8957. delay: inherit.delay,
  8958. duration: inherit.duration,
  8959. ease: inherit.ease,
  8960. index: i
  8961. };
  8962. inherit = null;
  8963. ++lock.count;
  8964. }
  8965. }
  8966. d3.svg.axis = function() {
  8967. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
  8968. function axis(g) {
  8969. g.each(function() {
  8970. var g = d3.select(this);
  8971. var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
  8972. var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
  8973. var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  8974. d3.transition(path));
  8975. tickEnter.append("line");
  8976. tickEnter.append("text");
  8977. var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
  8978. if (orient === "bottom" || orient === "top") {
  8979. tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
  8980. text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
  8981. pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
  8982. } else {
  8983. tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
  8984. text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
  8985. pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
  8986. }
  8987. lineEnter.attr(y2, sign * innerTickSize);
  8988. textEnter.attr(y1, sign * tickSpacing);
  8989. lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
  8990. textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
  8991. if (scale1.rangeBand) {
  8992. var x = scale1, dx = x.rangeBand() / 2;
  8993. scale0 = scale1 = function(d) {
  8994. return x(d) + dx;
  8995. };
  8996. } else if (scale0.rangeBand) {
  8997. scale0 = scale1;
  8998. } else {
  8999. tickExit.call(tickTransform, scale1, scale0);
  9000. }
  9001. tickEnter.call(tickTransform, scale0, scale1);
  9002. tickUpdate.call(tickTransform, scale1, scale1);
  9003. });
  9004. }
  9005. axis.scale = function(x) {
  9006. if (!arguments.length) return scale;
  9007. scale = x;
  9008. return axis;
  9009. };
  9010. axis.orient = function(x) {
  9011. if (!arguments.length) return orient;
  9012. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  9013. return axis;
  9014. };
  9015. axis.ticks = function() {
  9016. if (!arguments.length) return tickArguments_;
  9017. tickArguments_ = d3_array(arguments);
  9018. return axis;
  9019. };
  9020. axis.tickValues = function(x) {
  9021. if (!arguments.length) return tickValues;
  9022. tickValues = x;
  9023. return axis;
  9024. };
  9025. axis.tickFormat = function(x) {
  9026. if (!arguments.length) return tickFormat_;
  9027. tickFormat_ = x;
  9028. return axis;
  9029. };
  9030. axis.tickSize = function(x) {
  9031. var n = arguments.length;
  9032. if (!n) return innerTickSize;
  9033. innerTickSize = +x;
  9034. outerTickSize = +arguments[n - 1];
  9035. return axis;
  9036. };
  9037. axis.innerTickSize = function(x) {
  9038. if (!arguments.length) return innerTickSize;
  9039. innerTickSize = +x;
  9040. return axis;
  9041. };
  9042. axis.outerTickSize = function(x) {
  9043. if (!arguments.length) return outerTickSize;
  9044. outerTickSize = +x;
  9045. return axis;
  9046. };
  9047. axis.tickPadding = function(x) {
  9048. if (!arguments.length) return tickPadding;
  9049. tickPadding = +x;
  9050. return axis;
  9051. };
  9052. axis.tickSubdivide = function() {
  9053. return arguments.length && axis;
  9054. };
  9055. return axis;
  9056. };
  9057. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  9058. top: 1,
  9059. right: 1,
  9060. bottom: 1,
  9061. left: 1
  9062. };
  9063. function d3_svg_axisX(selection, x0, x1) {
  9064. selection.attr("transform", function(d) {
  9065. var v0 = x0(d);
  9066. return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
  9067. });
  9068. }
  9069. function d3_svg_axisY(selection, y0, y1) {
  9070. selection.attr("transform", function(d) {
  9071. var v0 = y0(d);
  9072. return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
  9073. });
  9074. }
  9075. d3.svg.brush = function() {
  9076. var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0];
  9077. function brush(g) {
  9078. g.each(function() {
  9079. var g = d3.select(this).style("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
  9080. var background = g.selectAll(".background").data([ 0 ]);
  9081. background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  9082. g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
  9083. var resize = g.selectAll(".resize").data(resizes, d3_identity);
  9084. resize.exit().remove();
  9085. resize.enter().append("g").attr("class", function(d) {
  9086. return "resize " + d;
  9087. }).style("cursor", function(d) {
  9088. return d3_svg_brushCursor[d];
  9089. }).append("rect").attr("x", function(d) {
  9090. return /[ew]$/.test(d) ? -3 : null;
  9091. }).attr("y", function(d) {
  9092. return /^[ns]/.test(d) ? -3 : null;
  9093. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  9094. resize.style("display", brush.empty() ? "none" : null);
  9095. var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
  9096. if (x) {
  9097. range = d3_scaleRange(x);
  9098. backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
  9099. redrawX(gUpdate);
  9100. }
  9101. if (y) {
  9102. range = d3_scaleRange(y);
  9103. backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
  9104. redrawY(gUpdate);
  9105. }
  9106. redraw(gUpdate);
  9107. });
  9108. }
  9109. brush.event = function(g) {
  9110. g.each(function() {
  9111. var event_ = event.of(this, arguments), extent1 = {
  9112. x: xExtent,
  9113. y: yExtent,
  9114. i: xExtentDomain,
  9115. j: yExtentDomain
  9116. }, extent0 = this.__chart__ || extent1;
  9117. this.__chart__ = extent1;
  9118. if (d3_transitionInheritId) {
  9119. d3.select(this).transition().each("start.brush", function() {
  9120. xExtentDomain = extent0.i;
  9121. yExtentDomain = extent0.j;
  9122. xExtent = extent0.x;
  9123. yExtent = extent0.y;
  9124. event_({
  9125. type: "brushstart"
  9126. });
  9127. }).tween("brush:brush", function() {
  9128. var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
  9129. xExtentDomain = yExtentDomain = null;
  9130. return function(t) {
  9131. xExtent = extent1.x = xi(t);
  9132. yExtent = extent1.y = yi(t);
  9133. event_({
  9134. type: "brush",
  9135. mode: "resize"
  9136. });
  9137. };
  9138. }).each("end.brush", function() {
  9139. xExtentDomain = extent1.i;
  9140. yExtentDomain = extent1.j;
  9141. event_({
  9142. type: "brush",
  9143. mode: "resize"
  9144. });
  9145. event_({
  9146. type: "brushend"
  9147. });
  9148. });
  9149. } else {
  9150. event_({
  9151. type: "brushstart"
  9152. });
  9153. event_({
  9154. type: "brush",
  9155. mode: "resize"
  9156. });
  9157. event_({
  9158. type: "brushend"
  9159. });
  9160. }
  9161. });
  9162. };
  9163. function redraw(g) {
  9164. g.selectAll(".resize").attr("transform", function(d) {
  9165. return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
  9166. });
  9167. }
  9168. function redrawX(g) {
  9169. g.select(".extent").attr("x", xExtent[0]);
  9170. g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
  9171. }
  9172. function redrawY(g) {
  9173. g.select(".extent").attr("y", yExtent[0]);
  9174. g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
  9175. }
  9176. function brushstart() {
  9177. var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;
  9178. var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
  9179. if (d3.event.changedTouches) {
  9180. w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
  9181. } else {
  9182. w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
  9183. }
  9184. g.interrupt().selectAll("*").interrupt();
  9185. if (dragging) {
  9186. origin[0] = xExtent[0] - origin[0];
  9187. origin[1] = yExtent[0] - origin[1];
  9188. } else if (resizing) {
  9189. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  9190. offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
  9191. origin[0] = xExtent[ex];
  9192. origin[1] = yExtent[ey];
  9193. } else if (d3.event.altKey) center = origin.slice();
  9194. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  9195. d3.select("body").style("cursor", eventTarget.style("cursor"));
  9196. event_({
  9197. type: "brushstart"
  9198. });
  9199. brushmove();
  9200. function keydown() {
  9201. if (d3.event.keyCode == 32) {
  9202. if (!dragging) {
  9203. center = null;
  9204. origin[0] -= xExtent[1];
  9205. origin[1] -= yExtent[1];
  9206. dragging = 2;
  9207. }
  9208. d3_eventPreventDefault();
  9209. }
  9210. }
  9211. function keyup() {
  9212. if (d3.event.keyCode == 32 && dragging == 2) {
  9213. origin[0] += xExtent[1];
  9214. origin[1] += yExtent[1];
  9215. dragging = 0;
  9216. d3_eventPreventDefault();
  9217. }
  9218. }
  9219. function brushmove() {
  9220. var point = d3.mouse(target), moved = false;
  9221. if (offset) {
  9222. point[0] += offset[0];
  9223. point[1] += offset[1];
  9224. }
  9225. if (!dragging) {
  9226. if (d3.event.altKey) {
  9227. if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
  9228. origin[0] = xExtent[+(point[0] < center[0])];
  9229. origin[1] = yExtent[+(point[1] < center[1])];
  9230. } else center = null;
  9231. }
  9232. if (resizingX && move1(point, x, 0)) {
  9233. redrawX(g);
  9234. moved = true;
  9235. }
  9236. if (resizingY && move1(point, y, 1)) {
  9237. redrawY(g);
  9238. moved = true;
  9239. }
  9240. if (moved) {
  9241. redraw(g);
  9242. event_({
  9243. type: "brush",
  9244. mode: dragging ? "move" : "resize"
  9245. });
  9246. }
  9247. }
  9248. function move1(point, scale, i) {
  9249. var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max;
  9250. if (dragging) {
  9251. r0 -= position;
  9252. r1 -= size + position;
  9253. }
  9254. min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
  9255. if (dragging) {
  9256. max = (min += position) + size;
  9257. } else {
  9258. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  9259. if (position < min) {
  9260. max = min;
  9261. min = position;
  9262. } else {
  9263. max = position;
  9264. }
  9265. }
  9266. if (extent[0] != min || extent[1] != max) {
  9267. if (i) yExtentDomain = null; else xExtentDomain = null;
  9268. extent[0] = min;
  9269. extent[1] = max;
  9270. return true;
  9271. }
  9272. }
  9273. function brushend() {
  9274. brushmove();
  9275. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  9276. d3.select("body").style("cursor", null);
  9277. w.on("mousemove.brush", null).on("mouseup.brush", null).on("touchmove.brush", null).on("touchend.brush", null).on("keydown.brush", null).on("keyup.brush", null);
  9278. dragRestore();
  9279. event_({
  9280. type: "brushend"
  9281. });
  9282. }
  9283. }
  9284. brush.x = function(z) {
  9285. if (!arguments.length) return x;
  9286. x = z;
  9287. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9288. return brush;
  9289. };
  9290. brush.y = function(z) {
  9291. if (!arguments.length) return y;
  9292. y = z;
  9293. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9294. return brush;
  9295. };
  9296. brush.clamp = function(z) {
  9297. if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
  9298. if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
  9299. return brush;
  9300. };
  9301. brush.extent = function(z) {
  9302. var x0, x1, y0, y1, t;
  9303. if (!arguments.length) {
  9304. if (x) {
  9305. if (xExtentDomain) {
  9306. x0 = xExtentDomain[0], x1 = xExtentDomain[1];
  9307. } else {
  9308. x0 = xExtent[0], x1 = xExtent[1];
  9309. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  9310. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9311. }
  9312. }
  9313. if (y) {
  9314. if (yExtentDomain) {
  9315. y0 = yExtentDomain[0], y1 = yExtentDomain[1];
  9316. } else {
  9317. y0 = yExtent[0], y1 = yExtent[1];
  9318. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  9319. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9320. }
  9321. }
  9322. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  9323. }
  9324. if (x) {
  9325. x0 = z[0], x1 = z[1];
  9326. if (y) x0 = x0[0], x1 = x1[0];
  9327. xExtentDomain = [ x0, x1 ];
  9328. if (x.invert) x0 = x(x0), x1 = x(x1);
  9329. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9330. if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
  9331. }
  9332. if (y) {
  9333. y0 = z[0], y1 = z[1];
  9334. if (x) y0 = y0[1], y1 = y1[1];
  9335. yExtentDomain = [ y0, y1 ];
  9336. if (y.invert) y0 = y(y0), y1 = y(y1);
  9337. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9338. if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
  9339. }
  9340. return brush;
  9341. };
  9342. brush.clear = function() {
  9343. if (!brush.empty()) {
  9344. xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
  9345. xExtentDomain = yExtentDomain = null;
  9346. }
  9347. return brush;
  9348. };
  9349. brush.empty = function() {
  9350. return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
  9351. };
  9352. return d3.rebind(brush, event, "on");
  9353. };
  9354. var d3_svg_brushCursor = {
  9355. n: "ns-resize",
  9356. e: "ew-resize",
  9357. s: "ns-resize",
  9358. w: "ew-resize",
  9359. nw: "nwse-resize",
  9360. ne: "nesw-resize",
  9361. se: "nwse-resize",
  9362. sw: "nesw-resize"
  9363. };
  9364. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  9365. var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
  9366. var d3_time_formatUtc = d3_time_format.utc;
  9367. var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
  9368. d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  9369. function d3_time_formatIsoNative(date) {
  9370. return date.toISOString();
  9371. }
  9372. d3_time_formatIsoNative.parse = function(string) {
  9373. var date = new Date(string);
  9374. return isNaN(date) ? null : date;
  9375. };
  9376. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  9377. d3_time.second = d3_time_interval(function(date) {
  9378. return new d3_date(Math.floor(date / 1e3) * 1e3);
  9379. }, function(date, offset) {
  9380. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  9381. }, function(date) {
  9382. return date.getSeconds();
  9383. });
  9384. d3_time.seconds = d3_time.second.range;
  9385. d3_time.seconds.utc = d3_time.second.utc.range;
  9386. d3_time.minute = d3_time_interval(function(date) {
  9387. return new d3_date(Math.floor(date / 6e4) * 6e4);
  9388. }, function(date, offset) {
  9389. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  9390. }, function(date) {
  9391. return date.getMinutes();
  9392. });
  9393. d3_time.minutes = d3_time.minute.range;
  9394. d3_time.minutes.utc = d3_time.minute.utc.range;
  9395. d3_time.hour = d3_time_interval(function(date) {
  9396. var timezone = date.getTimezoneOffset() / 60;
  9397. return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  9398. }, function(date, offset) {
  9399. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  9400. }, function(date) {
  9401. return date.getHours();
  9402. });
  9403. d3_time.hours = d3_time.hour.range;
  9404. d3_time.hours.utc = d3_time.hour.utc.range;
  9405. d3_time.month = d3_time_interval(function(date) {
  9406. date = d3_time.day(date);
  9407. date.setDate(1);
  9408. return date;
  9409. }, function(date, offset) {
  9410. date.setMonth(date.getMonth() + offset);
  9411. }, function(date) {
  9412. return date.getMonth();
  9413. });
  9414. d3_time.months = d3_time.month.range;
  9415. d3_time.months.utc = d3_time.month.utc.range;
  9416. function d3_time_scale(linear, methods, format) {
  9417. function scale(x) {
  9418. return linear(x);
  9419. }
  9420. scale.invert = function(x) {
  9421. return d3_time_scaleDate(linear.invert(x));
  9422. };
  9423. scale.domain = function(x) {
  9424. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  9425. linear.domain(x);
  9426. return scale;
  9427. };
  9428. function tickMethod(extent, count) {
  9429. var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
  9430. return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
  9431. return d / 31536e6;
  9432. }), count)[2] ] : !i ? [ d3_time_scaleMilliseconds, d3_scale_linearTickRange(extent, count)[2] ] : methods[target / d3_time_scaleSteps[i - 1] < d3_time_scaleSteps[i] / target ? i - 1 : i];
  9433. }
  9434. scale.nice = function(interval, skip) {
  9435. var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
  9436. if (method) interval = method[0], skip = method[1];
  9437. function skipped(date) {
  9438. return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
  9439. }
  9440. return scale.domain(d3_scale_nice(domain, skip > 1 ? {
  9441. floor: function(date) {
  9442. while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
  9443. return date;
  9444. },
  9445. ceil: function(date) {
  9446. while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
  9447. return date;
  9448. }
  9449. } : interval));
  9450. };
  9451. scale.ticks = function(interval, skip) {
  9452. var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
  9453. range: interval
  9454. }, skip ];
  9455. if (method) interval = method[0], skip = method[1];
  9456. return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
  9457. };
  9458. scale.tickFormat = function() {
  9459. return format;
  9460. };
  9461. scale.copy = function() {
  9462. return d3_time_scale(linear.copy(), methods, format);
  9463. };
  9464. return d3_scale_linearRebind(scale, linear);
  9465. }
  9466. function d3_time_scaleDate(t) {
  9467. return new Date(t);
  9468. }
  9469. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  9470. var d3_time_scaleLocalMethods = [ [ d3_time.second, 1 ], [ d3_time.second, 5 ], [ d3_time.second, 15 ], [ d3_time.second, 30 ], [ d3_time.minute, 1 ], [ d3_time.minute, 5 ], [ d3_time.minute, 15 ], [ d3_time.minute, 30 ], [ d3_time.hour, 1 ], [ d3_time.hour, 3 ], [ d3_time.hour, 6 ], [ d3_time.hour, 12 ], [ d3_time.day, 1 ], [ d3_time.day, 2 ], [ d3_time.week, 1 ], [ d3_time.month, 1 ], [ d3_time.month, 3 ], [ d3_time.year, 1 ] ];
  9471. var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
  9472. return d.getMilliseconds();
  9473. } ], [ ":%S", function(d) {
  9474. return d.getSeconds();
  9475. } ], [ "%I:%M", function(d) {
  9476. return d.getMinutes();
  9477. } ], [ "%I %p", function(d) {
  9478. return d.getHours();
  9479. } ], [ "%a %d", function(d) {
  9480. return d.getDay() && d.getDate() != 1;
  9481. } ], [ "%b %d", function(d) {
  9482. return d.getDate() != 1;
  9483. } ], [ "%B", function(d) {
  9484. return d.getMonth();
  9485. } ], [ "%Y", d3_true ] ]);
  9486. var d3_time_scaleMilliseconds = {
  9487. range: function(start, stop, step) {
  9488. return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
  9489. },
  9490. floor: d3_identity,
  9491. ceil: d3_identity
  9492. };
  9493. d3_time_scaleLocalMethods.year = d3_time.year;
  9494. d3_time.scale = function() {
  9495. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  9496. };
  9497. var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
  9498. return [ m[0].utc, m[1] ];
  9499. });
  9500. var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
  9501. return d.getUTCMilliseconds();
  9502. } ], [ ":%S", function(d) {
  9503. return d.getUTCSeconds();
  9504. } ], [ "%I:%M", function(d) {
  9505. return d.getUTCMinutes();
  9506. } ], [ "%I %p", function(d) {
  9507. return d.getUTCHours();
  9508. } ], [ "%a %d", function(d) {
  9509. return d.getUTCDay() && d.getUTCDate() != 1;
  9510. } ], [ "%b %d", function(d) {
  9511. return d.getUTCDate() != 1;
  9512. } ], [ "%B", function(d) {
  9513. return d.getUTCMonth();
  9514. } ], [ "%Y", d3_true ] ]);
  9515. d3_time_scaleUtcMethods.year = d3_time.year.utc;
  9516. d3_time.scale.utc = function() {
  9517. return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
  9518. };
  9519. d3.text = d3_xhrType(function(request) {
  9520. return request.responseText;
  9521. });
  9522. d3.json = function(url, callback) {
  9523. return d3_xhr(url, "application/json", d3_json, callback);
  9524. };
  9525. function d3_json(request) {
  9526. return JSON.parse(request.responseText);
  9527. }
  9528. d3.html = function(url, callback) {
  9529. return d3_xhr(url, "text/html", d3_html, callback);
  9530. };
  9531. function d3_html(request) {
  9532. var range = d3_document.createRange();
  9533. range.selectNode(d3_document.body);
  9534. return range.createContextualFragment(request.responseText);
  9535. }
  9536. d3.xml = d3_xhrType(function(request) {
  9537. return request.responseXML;
  9538. });
  9539. if (typeof define === "function" && define.amd) define(this.d3 = d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
  9540. }();