d3.v3.js 286 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436
  1. d3 = function() {
  2. var d3 = {
  3. version: "3.1.5"
  4. };
  5. if (!Date.now) Date.now = function() {
  6. return +new Date();
  7. };
  8. var d3_document = document, d3_window = window;
  9. try {
  10. d3_document.createElement("div").style.setProperty("opacity", 0, "");
  11. } catch (error) {
  12. var d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
  13. d3_style_prototype.setProperty = function(name, value, priority) {
  14. d3_style_setProperty.call(this, name, value + "", priority);
  15. };
  16. }
  17. d3.ascending = function(a, b) {
  18. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  19. };
  20. d3.descending = function(a, b) {
  21. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  22. };
  23. d3.min = function(array, f) {
  24. var i = -1, n = array.length, a, b;
  25. if (arguments.length === 1) {
  26. while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
  27. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  28. } else {
  29. while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
  30. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  31. }
  32. return a;
  33. };
  34. d3.max = function(array, f) {
  35. var i = -1, n = array.length, a, b;
  36. if (arguments.length === 1) {
  37. while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
  38. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  39. } else {
  40. while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
  41. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  42. }
  43. return a;
  44. };
  45. d3.extent = function(array, f) {
  46. var i = -1, n = array.length, a, b, c;
  47. if (arguments.length === 1) {
  48. while (++i < n && ((a = c = array[i]) == null || a != a)) a = c = undefined;
  49. while (++i < n) if ((b = array[i]) != null) {
  50. if (a > b) a = b;
  51. if (c < b) c = b;
  52. }
  53. } else {
  54. while (++i < n && ((a = c = f.call(array, array[i], i)) == null || a != a)) a = undefined;
  55. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  56. if (a > b) a = b;
  57. if (c < b) c = b;
  58. }
  59. }
  60. return [ a, c ];
  61. };
  62. d3.sum = function(array, f) {
  63. var s = 0, n = array.length, a, i = -1;
  64. if (arguments.length === 1) {
  65. while (++i < n) if (!isNaN(a = +array[i])) s += a;
  66. } else {
  67. while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
  68. }
  69. return s;
  70. };
  71. function d3_number(x) {
  72. return x != null && !isNaN(x);
  73. }
  74. d3.mean = function(array, f) {
  75. var n = array.length, a, m = 0, i = -1, j = 0;
  76. if (arguments.length === 1) {
  77. while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j;
  78. } else {
  79. while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j;
  80. }
  81. return j ? m : undefined;
  82. };
  83. d3.quantile = function(values, p) {
  84. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  85. return e ? v + e * (values[h] - v) : v;
  86. };
  87. d3.median = function(array, f) {
  88. if (arguments.length > 1) array = array.map(f);
  89. array = array.filter(d3_number);
  90. return array.length ? d3.quantile(array.sort(d3.ascending), .5) : undefined;
  91. };
  92. d3.bisector = function(f) {
  93. return {
  94. left: function(a, x, lo, hi) {
  95. if (arguments.length < 3) lo = 0;
  96. if (arguments.length < 4) hi = a.length;
  97. while (lo < hi) {
  98. var mid = lo + hi >>> 1;
  99. if (f.call(a, a[mid], mid) < x) lo = mid + 1; else hi = mid;
  100. }
  101. return lo;
  102. },
  103. right: function(a, x, lo, hi) {
  104. if (arguments.length < 3) lo = 0;
  105. if (arguments.length < 4) hi = a.length;
  106. while (lo < hi) {
  107. var mid = lo + hi >>> 1;
  108. if (x < f.call(a, a[mid], mid)) hi = mid; else lo = mid + 1;
  109. }
  110. return lo;
  111. }
  112. };
  113. };
  114. var d3_bisector = d3.bisector(function(d) {
  115. return d;
  116. });
  117. d3.bisectLeft = d3_bisector.left;
  118. d3.bisect = d3.bisectRight = d3_bisector.right;
  119. d3.shuffle = function(array) {
  120. var m = array.length, t, i;
  121. while (m) {
  122. i = Math.random() * m-- | 0;
  123. t = array[m], array[m] = array[i], array[i] = t;
  124. }
  125. return array;
  126. };
  127. d3.permute = function(array, indexes) {
  128. var permutes = [], i = -1, n = indexes.length;
  129. while (++i < n) permutes[i] = array[indexes[i]];
  130. return permutes;
  131. };
  132. d3.zip = function() {
  133. if (!(n = arguments.length)) return [];
  134. for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
  135. for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
  136. zip[j] = arguments[j][i];
  137. }
  138. }
  139. return zips;
  140. };
  141. function d3_zipLength(d) {
  142. return d.length;
  143. }
  144. d3.transpose = function(matrix) {
  145. return d3.zip.apply(d3, matrix);
  146. };
  147. d3.keys = function(map) {
  148. var keys = [];
  149. for (var key in map) keys.push(key);
  150. return keys;
  151. };
  152. d3.values = function(map) {
  153. var values = [];
  154. for (var key in map) values.push(map[key]);
  155. return values;
  156. };
  157. d3.entries = function(map) {
  158. var entries = [];
  159. for (var key in map) entries.push({
  160. key: key,
  161. value: map[key]
  162. });
  163. return entries;
  164. };
  165. d3.merge = function(arrays) {
  166. return Array.prototype.concat.apply([], arrays);
  167. };
  168. d3.range = function(start, stop, step) {
  169. if (arguments.length < 3) {
  170. step = 1;
  171. if (arguments.length < 2) {
  172. stop = start;
  173. start = 0;
  174. }
  175. }
  176. if ((stop - start) / step === Infinity) throw new Error("infinite range");
  177. var range = [], k = d3_range_integerScale(Math.abs(step)), i = -1, j;
  178. start *= k, stop *= k, step *= k;
  179. if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
  180. return range;
  181. };
  182. function d3_range_integerScale(x) {
  183. var k = 1;
  184. while (x * k % 1) k *= 10;
  185. return k;
  186. }
  187. function d3_class(ctor, properties) {
  188. try {
  189. for (var key in properties) {
  190. Object.defineProperty(ctor.prototype, key, {
  191. value: properties[key],
  192. enumerable: false
  193. });
  194. }
  195. } catch (e) {
  196. ctor.prototype = properties;
  197. }
  198. }
  199. d3.map = function(object) {
  200. var map = new d3_Map();
  201. for (var key in object) map.set(key, object[key]);
  202. return map;
  203. };
  204. function d3_Map() {}
  205. d3_class(d3_Map, {
  206. has: function(key) {
  207. return d3_map_prefix + key in this;
  208. },
  209. get: function(key) {
  210. return this[d3_map_prefix + key];
  211. },
  212. set: function(key, value) {
  213. return this[d3_map_prefix + key] = value;
  214. },
  215. remove: function(key) {
  216. key = d3_map_prefix + key;
  217. return key in this && delete this[key];
  218. },
  219. keys: function() {
  220. var keys = [];
  221. this.forEach(function(key) {
  222. keys.push(key);
  223. });
  224. return keys;
  225. },
  226. values: function() {
  227. var values = [];
  228. this.forEach(function(key, value) {
  229. values.push(value);
  230. });
  231. return values;
  232. },
  233. entries: function() {
  234. var entries = [];
  235. this.forEach(function(key, value) {
  236. entries.push({
  237. key: key,
  238. value: value
  239. });
  240. });
  241. return entries;
  242. },
  243. forEach: function(f) {
  244. for (var key in this) {
  245. if (key.charCodeAt(0) === d3_map_prefixCode) {
  246. f.call(this, key.substring(1), this[key]);
  247. }
  248. }
  249. }
  250. });
  251. var d3_map_prefix = "\0", d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
  252. d3.nest = function() {
  253. var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
  254. function map(mapType, array, depth) {
  255. if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
  256. var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
  257. while (++i < n) {
  258. if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
  259. values.push(object);
  260. } else {
  261. valuesByKey.set(keyValue, [ object ]);
  262. }
  263. }
  264. if (mapType) {
  265. object = mapType();
  266. setter = function(keyValue, values) {
  267. object.set(keyValue, map(mapType, values, depth));
  268. };
  269. } else {
  270. object = {};
  271. setter = function(keyValue, values) {
  272. object[keyValue] = map(mapType, values, depth);
  273. };
  274. }
  275. valuesByKey.forEach(setter);
  276. return object;
  277. }
  278. function entries(map, depth) {
  279. if (depth >= keys.length) return map;
  280. var array = [], sortKey = sortKeys[depth++];
  281. map.forEach(function(key, keyMap) {
  282. array.push({
  283. key: key,
  284. values: entries(keyMap, depth)
  285. });
  286. });
  287. return sortKey ? array.sort(function(a, b) {
  288. return sortKey(a.key, b.key);
  289. }) : array;
  290. }
  291. nest.map = function(array, mapType) {
  292. return map(mapType, array, 0);
  293. };
  294. nest.entries = function(array) {
  295. return entries(map(d3.map, array, 0), 0);
  296. };
  297. nest.key = function(d) {
  298. keys.push(d);
  299. return nest;
  300. };
  301. nest.sortKeys = function(order) {
  302. sortKeys[keys.length - 1] = order;
  303. return nest;
  304. };
  305. nest.sortValues = function(order) {
  306. sortValues = order;
  307. return nest;
  308. };
  309. nest.rollup = function(f) {
  310. rollup = f;
  311. return nest;
  312. };
  313. return nest;
  314. };
  315. d3.set = function(array) {
  316. var set = new d3_Set();
  317. if (array) for (var i = 0; i < array.length; i++) set.add(array[i]);
  318. return set;
  319. };
  320. function d3_Set() {}
  321. d3_class(d3_Set, {
  322. has: function(value) {
  323. return d3_map_prefix + value in this;
  324. },
  325. add: function(value) {
  326. this[d3_map_prefix + value] = true;
  327. return value;
  328. },
  329. remove: function(value) {
  330. value = d3_map_prefix + value;
  331. return value in this && delete this[value];
  332. },
  333. values: function() {
  334. var values = [];
  335. this.forEach(function(value) {
  336. values.push(value);
  337. });
  338. return values;
  339. },
  340. forEach: function(f) {
  341. for (var value in this) {
  342. if (value.charCodeAt(0) === d3_map_prefixCode) {
  343. f.call(this, value.substring(1));
  344. }
  345. }
  346. }
  347. });
  348. d3.behavior = {};
  349. d3.rebind = function(target, source) {
  350. var i = 1, n = arguments.length, method;
  351. while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
  352. return target;
  353. };
  354. function d3_rebind(target, source, method) {
  355. return function() {
  356. var value = method.apply(source, arguments);
  357. return value === source ? target : value;
  358. };
  359. }
  360. d3.dispatch = function() {
  361. var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
  362. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  363. return dispatch;
  364. };
  365. function d3_dispatch() {}
  366. d3_dispatch.prototype.on = function(type, listener) {
  367. var i = type.indexOf("."), name = "";
  368. if (i >= 0) {
  369. name = type.substring(i + 1);
  370. type = type.substring(0, i);
  371. }
  372. if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
  373. if (arguments.length === 2) {
  374. if (listener == null) for (type in this) {
  375. if (this.hasOwnProperty(type)) this[type].on(name, null);
  376. }
  377. return this;
  378. }
  379. };
  380. function d3_dispatch_event(dispatch) {
  381. var listeners = [], listenerByName = new d3_Map();
  382. function event() {
  383. var z = listeners, i = -1, n = z.length, l;
  384. while (++i < n) if (l = z[i].on) l.apply(this, arguments);
  385. return dispatch;
  386. }
  387. event.on = function(name, listener) {
  388. var l = listenerByName.get(name), i;
  389. if (arguments.length < 2) return l && l.on;
  390. if (l) {
  391. l.on = null;
  392. listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
  393. listenerByName.remove(name);
  394. }
  395. if (listener) listeners.push(listenerByName.set(name, {
  396. on: listener
  397. }));
  398. return dispatch;
  399. };
  400. return event;
  401. }
  402. d3.event = null;
  403. function d3_eventCancel() {
  404. d3.event.stopPropagation();
  405. d3.event.preventDefault();
  406. }
  407. function d3_eventSource() {
  408. var e = d3.event, s;
  409. while (s = e.sourceEvent) e = s;
  410. return e;
  411. }
  412. function d3_eventSuppress(target, type) {
  413. function off() {
  414. target.on(type, null);
  415. }
  416. target.on(type, function() {
  417. d3_eventCancel();
  418. off();
  419. }, true);
  420. setTimeout(off, 0);
  421. }
  422. function d3_eventDispatch(target) {
  423. var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
  424. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  425. dispatch.of = function(thiz, argumentz) {
  426. return function(e1) {
  427. try {
  428. var e0 = e1.sourceEvent = d3.event;
  429. e1.target = target;
  430. d3.event = e1;
  431. dispatch[e1.type].apply(thiz, argumentz);
  432. } finally {
  433. d3.event = e0;
  434. }
  435. };
  436. };
  437. return dispatch;
  438. }
  439. d3.mouse = function(container) {
  440. return d3_mousePoint(container, d3_eventSource());
  441. };
  442. var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
  443. function d3_mousePoint(container, e) {
  444. var svg = container.ownerSVGElement || container;
  445. if (svg.createSVGPoint) {
  446. var point = svg.createSVGPoint();
  447. if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
  448. svg = d3.select(d3_document.body).append("svg").style("position", "absolute").style("top", 0).style("left", 0);
  449. var ctm = svg[0][0].getScreenCTM();
  450. d3_mouse_bug44083 = !(ctm.f || ctm.e);
  451. svg.remove();
  452. }
  453. if (d3_mouse_bug44083) {
  454. point.x = e.pageX;
  455. point.y = e.pageY;
  456. } else {
  457. point.x = e.clientX;
  458. point.y = e.clientY;
  459. }
  460. point = point.matrixTransform(container.getScreenCTM().inverse());
  461. return [ point.x, point.y ];
  462. }
  463. var rect = container.getBoundingClientRect();
  464. return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
  465. }
  466. var d3_array = d3_arraySlice;
  467. function d3_arrayCopy(pseudoarray) {
  468. var i = -1, n = pseudoarray.length, array = [];
  469. while (++i < n) array.push(pseudoarray[i]);
  470. return array;
  471. }
  472. function d3_arraySlice(pseudoarray) {
  473. return Array.prototype.slice.call(pseudoarray);
  474. }
  475. try {
  476. d3_array(d3_document.documentElement.childNodes)[0].nodeType;
  477. } catch (e) {
  478. d3_array = d3_arrayCopy;
  479. }
  480. var d3_arraySubclass = [].__proto__ ? function(array, prototype) {
  481. array.__proto__ = prototype;
  482. } : function(array, prototype) {
  483. for (var property in prototype) array[property] = prototype[property];
  484. };
  485. d3.touches = function(container, touches) {
  486. if (arguments.length < 2) touches = d3_eventSource().touches;
  487. return touches ? d3_array(touches).map(function(touch) {
  488. var point = d3_mousePoint(container, touch);
  489. point.identifier = touch.identifier;
  490. return point;
  491. }) : [];
  492. };
  493. d3.behavior.drag = function() {
  494. var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null;
  495. function drag() {
  496. this.on("mousedown.drag", mousedown).on("touchstart.drag", mousedown);
  497. }
  498. function mousedown() {
  499. var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, touchId = d3.event.touches ? d3.event.changedTouches[0].identifier : null, offset, origin_ = point(), moved = 0;
  500. var w = d3.select(d3_window).on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);
  501. if (origin) {
  502. offset = origin.apply(target, arguments);
  503. offset = [ offset.x - origin_[0], offset.y - origin_[1] ];
  504. } else {
  505. offset = [ 0, 0 ];
  506. }
  507. if (touchId == null) d3_eventCancel();
  508. event_({
  509. type: "dragstart"
  510. });
  511. function point() {
  512. var p = target.parentNode;
  513. return touchId != null ? d3.touches(p).filter(function(p) {
  514. return p.identifier === touchId;
  515. })[0] : d3.mouse(p);
  516. }
  517. function dragmove() {
  518. if (!target.parentNode) return dragend();
  519. var p = point(), dx = p[0] - origin_[0], dy = p[1] - origin_[1];
  520. moved |= dx | dy;
  521. origin_ = p;
  522. d3_eventCancel();
  523. event_({
  524. type: "drag",
  525. x: p[0] + offset[0],
  526. y: p[1] + offset[1],
  527. dx: dx,
  528. dy: dy
  529. });
  530. }
  531. function dragend() {
  532. event_({
  533. type: "dragend"
  534. });
  535. if (moved) {
  536. d3_eventCancel();
  537. if (d3.event.target === eventTarget) d3_eventSuppress(w, "click");
  538. }
  539. w.on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", null).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", null);
  540. }
  541. }
  542. drag.origin = function(x) {
  543. if (!arguments.length) return origin;
  544. origin = x;
  545. return drag;
  546. };
  547. return d3.rebind(drag, event, "on");
  548. };
  549. function d3_selection(groups) {
  550. d3_arraySubclass(groups, d3_selectionPrototype);
  551. return groups;
  552. }
  553. var d3_select = function(s, n) {
  554. return n.querySelector(s);
  555. }, d3_selectAll = function(s, n) {
  556. return n.querySelectorAll(s);
  557. }, d3_selectRoot = d3_document.documentElement, d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector || d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector, d3_selectMatches = function(n, s) {
  558. return d3_selectMatcher.call(n, s);
  559. };
  560. if (typeof Sizzle === "function") {
  561. d3_select = function(s, n) {
  562. return Sizzle(s, n)[0] || null;
  563. };
  564. d3_selectAll = function(s, n) {
  565. return Sizzle.uniqueSort(Sizzle(s, n));
  566. };
  567. d3_selectMatches = Sizzle.matchesSelector;
  568. }
  569. var d3_selectionPrototype = [];
  570. d3.selection = function() {
  571. return d3_selectionRoot;
  572. };
  573. d3.selection.prototype = d3_selectionPrototype;
  574. d3_selectionPrototype.select = function(selector) {
  575. var subgroups = [], subgroup, subnode, group, node;
  576. if (typeof selector !== "function") selector = d3_selection_selector(selector);
  577. for (var j = -1, m = this.length; ++j < m; ) {
  578. subgroups.push(subgroup = []);
  579. subgroup.parentNode = (group = this[j]).parentNode;
  580. for (var i = -1, n = group.length; ++i < n; ) {
  581. if (node = group[i]) {
  582. subgroup.push(subnode = selector.call(node, node.__data__, i));
  583. if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
  584. } else {
  585. subgroup.push(null);
  586. }
  587. }
  588. }
  589. return d3_selection(subgroups);
  590. };
  591. function d3_selection_selector(selector) {
  592. return function() {
  593. return d3_select(selector, this);
  594. };
  595. }
  596. d3_selectionPrototype.selectAll = function(selector) {
  597. var subgroups = [], subgroup, node;
  598. if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
  599. for (var j = -1, m = this.length; ++j < m; ) {
  600. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  601. if (node = group[i]) {
  602. subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i)));
  603. subgroup.parentNode = node;
  604. }
  605. }
  606. }
  607. return d3_selection(subgroups);
  608. };
  609. function d3_selection_selectorAll(selector) {
  610. return function() {
  611. return d3_selectAll(selector, this);
  612. };
  613. }
  614. var d3_nsPrefix = {
  615. svg: "http://www.w3.org/2000/svg",
  616. xhtml: "http://www.w3.org/1999/xhtml",
  617. xlink: "http://www.w3.org/1999/xlink",
  618. xml: "http://www.w3.org/XML/1998/namespace",
  619. xmlns: "http://www.w3.org/2000/xmlns/"
  620. };
  621. d3.ns = {
  622. prefix: d3_nsPrefix,
  623. qualify: function(name) {
  624. var i = name.indexOf(":"), prefix = name;
  625. if (i >= 0) {
  626. prefix = name.substring(0, i);
  627. name = name.substring(i + 1);
  628. }
  629. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  630. space: d3_nsPrefix[prefix],
  631. local: name
  632. } : name;
  633. }
  634. };
  635. d3_selectionPrototype.attr = function(name, value) {
  636. if (arguments.length < 2) {
  637. if (typeof name === "string") {
  638. var node = this.node();
  639. name = d3.ns.qualify(name);
  640. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  641. }
  642. for (value in name) this.each(d3_selection_attr(value, name[value]));
  643. return this;
  644. }
  645. return this.each(d3_selection_attr(name, value));
  646. };
  647. function d3_selection_attr(name, value) {
  648. name = d3.ns.qualify(name);
  649. function attrNull() {
  650. this.removeAttribute(name);
  651. }
  652. function attrNullNS() {
  653. this.removeAttributeNS(name.space, name.local);
  654. }
  655. function attrConstant() {
  656. this.setAttribute(name, value);
  657. }
  658. function attrConstantNS() {
  659. this.setAttributeNS(name.space, name.local, value);
  660. }
  661. function attrFunction() {
  662. var x = value.apply(this, arguments);
  663. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  664. }
  665. function attrFunctionNS() {
  666. var x = value.apply(this, arguments);
  667. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  668. }
  669. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  670. }
  671. function d3_collapse(s) {
  672. return s.trim().replace(/\s+/g, " ");
  673. }
  674. d3.requote = function(s) {
  675. return s.replace(d3_requote_re, "\\$&");
  676. };
  677. var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  678. d3_selectionPrototype.classed = function(name, value) {
  679. if (arguments.length < 2) {
  680. if (typeof name === "string") {
  681. var node = this.node(), n = (name = name.trim().split(/^|\s+/g)).length, i = -1;
  682. if (value = node.classList) {
  683. while (++i < n) if (!value.contains(name[i])) return false;
  684. } else {
  685. value = node.getAttribute("class");
  686. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  687. }
  688. return true;
  689. }
  690. for (value in name) this.each(d3_selection_classed(value, name[value]));
  691. return this;
  692. }
  693. return this.each(d3_selection_classed(name, value));
  694. };
  695. function d3_selection_classedRe(name) {
  696. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  697. }
  698. function d3_selection_classed(name, value) {
  699. name = name.trim().split(/\s+/).map(d3_selection_classedName);
  700. var n = name.length;
  701. function classedConstant() {
  702. var i = -1;
  703. while (++i < n) name[i](this, value);
  704. }
  705. function classedFunction() {
  706. var i = -1, x = value.apply(this, arguments);
  707. while (++i < n) name[i](this, x);
  708. }
  709. return typeof value === "function" ? classedFunction : classedConstant;
  710. }
  711. function d3_selection_classedName(name) {
  712. var re = d3_selection_classedRe(name);
  713. return function(node, value) {
  714. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  715. var c = node.getAttribute("class") || "";
  716. if (value) {
  717. re.lastIndex = 0;
  718. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  719. } else {
  720. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  721. }
  722. };
  723. }
  724. d3_selectionPrototype.style = function(name, value, priority) {
  725. var n = arguments.length;
  726. if (n < 3) {
  727. if (typeof name !== "string") {
  728. if (n < 2) value = "";
  729. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  730. return this;
  731. }
  732. if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
  733. priority = "";
  734. }
  735. return this.each(d3_selection_style(name, value, priority));
  736. };
  737. function d3_selection_style(name, value, priority) {
  738. function styleNull() {
  739. this.style.removeProperty(name);
  740. }
  741. function styleConstant() {
  742. this.style.setProperty(name, value, priority);
  743. }
  744. function styleFunction() {
  745. var x = value.apply(this, arguments);
  746. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  747. }
  748. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  749. }
  750. d3_selectionPrototype.property = function(name, value) {
  751. if (arguments.length < 2) {
  752. if (typeof name === "string") return this.node()[name];
  753. for (value in name) this.each(d3_selection_property(value, name[value]));
  754. return this;
  755. }
  756. return this.each(d3_selection_property(name, value));
  757. };
  758. function d3_selection_property(name, value) {
  759. function propertyNull() {
  760. delete this[name];
  761. }
  762. function propertyConstant() {
  763. this[name] = value;
  764. }
  765. function propertyFunction() {
  766. var x = value.apply(this, arguments);
  767. if (x == null) delete this[name]; else this[name] = x;
  768. }
  769. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  770. }
  771. d3_selectionPrototype.text = function(value) {
  772. return arguments.length ? this.each(typeof value === "function" ? function() {
  773. var v = value.apply(this, arguments);
  774. this.textContent = v == null ? "" : v;
  775. } : value == null ? function() {
  776. this.textContent = "";
  777. } : function() {
  778. this.textContent = value;
  779. }) : this.node().textContent;
  780. };
  781. d3_selectionPrototype.html = function(value) {
  782. return arguments.length ? this.each(typeof value === "function" ? function() {
  783. var v = value.apply(this, arguments);
  784. this.innerHTML = v == null ? "" : v;
  785. } : value == null ? function() {
  786. this.innerHTML = "";
  787. } : function() {
  788. this.innerHTML = value;
  789. }) : this.node().innerHTML;
  790. };
  791. d3_selectionPrototype.append = function(name) {
  792. name = d3.ns.qualify(name);
  793. function append() {
  794. return this.appendChild(d3_document.createElementNS(this.namespaceURI, name));
  795. }
  796. function appendNS() {
  797. return this.appendChild(d3_document.createElementNS(name.space, name.local));
  798. }
  799. return this.select(name.local ? appendNS : append);
  800. };
  801. d3_selectionPrototype.insert = function(name, before) {
  802. name = d3.ns.qualify(name);
  803. if (typeof before !== "function") before = d3_selection_selector(before);
  804. function insert(d, i) {
  805. return this.insertBefore(d3_document.createElementNS(this.namespaceURI, name), before.call(this, d, i));
  806. }
  807. function insertNS(d, i) {
  808. return this.insertBefore(d3_document.createElementNS(name.space, name.local), before.call(this, d, i));
  809. }
  810. return this.select(name.local ? insertNS : insert);
  811. };
  812. d3_selectionPrototype.remove = function() {
  813. return this.each(function() {
  814. var parent = this.parentNode;
  815. if (parent) parent.removeChild(this);
  816. });
  817. };
  818. d3_selectionPrototype.data = function(value, key) {
  819. var i = -1, n = this.length, group, node;
  820. if (!arguments.length) {
  821. value = new Array(n = (group = this[0]).length);
  822. while (++i < n) {
  823. if (node = group[i]) {
  824. value[i] = node.__data__;
  825. }
  826. }
  827. return value;
  828. }
  829. function bind(group, groupData) {
  830. 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;
  831. if (key) {
  832. var nodeByKeyValue = new d3_Map(), dataByKeyValue = new d3_Map(), keyValues = [], keyValue;
  833. for (i = -1; ++i < n; ) {
  834. keyValue = key.call(node = group[i], node.__data__, i);
  835. if (nodeByKeyValue.has(keyValue)) {
  836. exitNodes[i] = node;
  837. } else {
  838. nodeByKeyValue.set(keyValue, node);
  839. }
  840. keyValues.push(keyValue);
  841. }
  842. for (i = -1; ++i < m; ) {
  843. keyValue = key.call(groupData, nodeData = groupData[i], i);
  844. if (node = nodeByKeyValue.get(keyValue)) {
  845. updateNodes[i] = node;
  846. node.__data__ = nodeData;
  847. } else if (!dataByKeyValue.has(keyValue)) {
  848. enterNodes[i] = d3_selection_dataNode(nodeData);
  849. }
  850. dataByKeyValue.set(keyValue, nodeData);
  851. nodeByKeyValue.remove(keyValue);
  852. }
  853. for (i = -1; ++i < n; ) {
  854. if (nodeByKeyValue.has(keyValues[i])) {
  855. exitNodes[i] = group[i];
  856. }
  857. }
  858. } else {
  859. for (i = -1; ++i < n0; ) {
  860. node = group[i];
  861. nodeData = groupData[i];
  862. if (node) {
  863. node.__data__ = nodeData;
  864. updateNodes[i] = node;
  865. } else {
  866. enterNodes[i] = d3_selection_dataNode(nodeData);
  867. }
  868. }
  869. for (;i < m; ++i) {
  870. enterNodes[i] = d3_selection_dataNode(groupData[i]);
  871. }
  872. for (;i < n; ++i) {
  873. exitNodes[i] = group[i];
  874. }
  875. }
  876. enterNodes.update = updateNodes;
  877. enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
  878. enter.push(enterNodes);
  879. update.push(updateNodes);
  880. exit.push(exitNodes);
  881. }
  882. var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
  883. if (typeof value === "function") {
  884. while (++i < n) {
  885. bind(group = this[i], value.call(group, group.parentNode.__data__, i));
  886. }
  887. } else {
  888. while (++i < n) {
  889. bind(group = this[i], value);
  890. }
  891. }
  892. update.enter = function() {
  893. return enter;
  894. };
  895. update.exit = function() {
  896. return exit;
  897. };
  898. return update;
  899. };
  900. function d3_selection_dataNode(data) {
  901. return {
  902. __data__: data
  903. };
  904. }
  905. d3_selectionPrototype.datum = function(value) {
  906. return arguments.length ? this.property("__data__", value) : this.property("__data__");
  907. };
  908. d3_selectionPrototype.filter = function(filter) {
  909. var subgroups = [], subgroup, group, node;
  910. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  911. for (var j = 0, m = this.length; j < m; j++) {
  912. subgroups.push(subgroup = []);
  913. subgroup.parentNode = (group = this[j]).parentNode;
  914. for (var i = 0, n = group.length; i < n; i++) {
  915. if ((node = group[i]) && filter.call(node, node.__data__, i)) {
  916. subgroup.push(node);
  917. }
  918. }
  919. }
  920. return d3_selection(subgroups);
  921. };
  922. function d3_selection_filter(selector) {
  923. return function() {
  924. return d3_selectMatches(this, selector);
  925. };
  926. }
  927. d3_selectionPrototype.order = function() {
  928. for (var j = -1, m = this.length; ++j < m; ) {
  929. for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
  930. if (node = group[i]) {
  931. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  932. next = node;
  933. }
  934. }
  935. }
  936. return this;
  937. };
  938. d3_selectionPrototype.sort = function(comparator) {
  939. comparator = d3_selection_sortComparator.apply(this, arguments);
  940. for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
  941. return this.order();
  942. };
  943. function d3_selection_sortComparator(comparator) {
  944. if (!arguments.length) comparator = d3.ascending;
  945. return function(a, b) {
  946. return !a - !b || comparator(a.__data__, b.__data__);
  947. };
  948. }
  949. function d3_noop() {}
  950. d3_selectionPrototype.on = function(type, listener, capture) {
  951. var n = arguments.length;
  952. if (n < 3) {
  953. if (typeof type !== "string") {
  954. if (n < 2) listener = false;
  955. for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
  956. return this;
  957. }
  958. if (n < 2) return (n = this.node()["__on" + type]) && n._;
  959. capture = false;
  960. }
  961. return this.each(d3_selection_on(type, listener, capture));
  962. };
  963. function d3_selection_on(type, listener, capture) {
  964. var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
  965. if (i > 0) type = type.substring(0, i);
  966. var filter = d3_selection_onFilters.get(type);
  967. if (filter) type = filter, wrap = d3_selection_onFilter;
  968. function onRemove() {
  969. var l = this[name];
  970. if (l) {
  971. this.removeEventListener(type, l, l.$);
  972. delete this[name];
  973. }
  974. }
  975. function onAdd() {
  976. var l = wrap(listener, d3_array(arguments));
  977. onRemove.call(this);
  978. this.addEventListener(type, this[name] = l, l.$ = capture);
  979. l._ = listener;
  980. }
  981. function removeAll() {
  982. var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
  983. for (var name in this) {
  984. if (match = name.match(re)) {
  985. var l = this[name];
  986. this.removeEventListener(match[1], l, l.$);
  987. delete this[name];
  988. }
  989. }
  990. }
  991. return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
  992. }
  993. var d3_selection_onFilters = d3.map({
  994. mouseenter: "mouseover",
  995. mouseleave: "mouseout"
  996. });
  997. d3_selection_onFilters.forEach(function(k) {
  998. if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
  999. });
  1000. function d3_selection_onListener(listener, argumentz) {
  1001. return function(e) {
  1002. var o = d3.event;
  1003. d3.event = e;
  1004. argumentz[0] = this.__data__;
  1005. try {
  1006. listener.apply(this, argumentz);
  1007. } finally {
  1008. d3.event = o;
  1009. }
  1010. };
  1011. }
  1012. function d3_selection_onFilter(listener, argumentz) {
  1013. var l = d3_selection_onListener(listener, argumentz);
  1014. return function(e) {
  1015. var target = this, related = e.relatedTarget;
  1016. if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
  1017. l.call(target, e);
  1018. }
  1019. };
  1020. }
  1021. d3_selectionPrototype.each = function(callback) {
  1022. return d3_selection_each(this, function(node, i, j) {
  1023. callback.call(node, node.__data__, i, j);
  1024. });
  1025. };
  1026. function d3_selection_each(groups, callback) {
  1027. for (var j = 0, m = groups.length; j < m; j++) {
  1028. for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
  1029. if (node = group[i]) callback(node, i, j);
  1030. }
  1031. }
  1032. return groups;
  1033. }
  1034. d3_selectionPrototype.call = function(callback) {
  1035. var args = d3_array(arguments);
  1036. callback.apply(args[0] = this, args);
  1037. return this;
  1038. };
  1039. d3_selectionPrototype.empty = function() {
  1040. return !this.node();
  1041. };
  1042. d3_selectionPrototype.node = function() {
  1043. for (var j = 0, m = this.length; j < m; j++) {
  1044. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  1045. var node = group[i];
  1046. if (node) return node;
  1047. }
  1048. }
  1049. return null;
  1050. };
  1051. function d3_selection_enter(selection) {
  1052. d3_arraySubclass(selection, d3_selection_enterPrototype);
  1053. return selection;
  1054. }
  1055. var d3_selection_enterPrototype = [];
  1056. d3.selection.enter = d3_selection_enter;
  1057. d3.selection.enter.prototype = d3_selection_enterPrototype;
  1058. d3_selection_enterPrototype.append = d3_selectionPrototype.append;
  1059. d3_selection_enterPrototype.insert = d3_selectionPrototype.insert;
  1060. d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
  1061. d3_selection_enterPrototype.node = d3_selectionPrototype.node;
  1062. d3_selection_enterPrototype.select = function(selector) {
  1063. var subgroups = [], subgroup, subnode, upgroup, group, node;
  1064. for (var j = -1, m = this.length; ++j < m; ) {
  1065. upgroup = (group = this[j]).update;
  1066. subgroups.push(subgroup = []);
  1067. subgroup.parentNode = group.parentNode;
  1068. for (var i = -1, n = group.length; ++i < n; ) {
  1069. if (node = group[i]) {
  1070. subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i));
  1071. subnode.__data__ = node.__data__;
  1072. } else {
  1073. subgroup.push(null);
  1074. }
  1075. }
  1076. }
  1077. return d3_selection(subgroups);
  1078. };
  1079. d3_selectionPrototype.transition = function() {
  1080. var id = d3_transitionInheritId || ++d3_transitionId, subgroups = [], subgroup, node, transition = Object.create(d3_transitionInherit);
  1081. transition.time = Date.now();
  1082. for (var j = -1, m = this.length; ++j < m; ) {
  1083. subgroups.push(subgroup = []);
  1084. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  1085. if (node = group[i]) d3_transitionNode(node, i, id, transition);
  1086. subgroup.push(node);
  1087. }
  1088. }
  1089. return d3_transition(subgroups, id);
  1090. };
  1091. var d3_selectionRoot = d3_selection([ [ d3_document ] ]);
  1092. d3_selectionRoot[0].parentNode = d3_selectRoot;
  1093. d3.select = function(selector) {
  1094. return typeof selector === "string" ? d3_selectionRoot.select(selector) : d3_selection([ [ selector ] ]);
  1095. };
  1096. d3.selectAll = function(selector) {
  1097. return typeof selector === "string" ? d3_selectionRoot.selectAll(selector) : d3_selection([ d3_array(selector) ]);
  1098. };
  1099. d3.behavior.zoom = function() {
  1100. var translate = [ 0, 0 ], translate0, scale = 1, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime;
  1101. function zoom() {
  1102. this.on("mousedown.zoom", mousedown).on("mousemove.zoom", mousemove).on(d3_behavior_zoomWheel + ".zoom", mousewheel).on("dblclick.zoom", dblclick).on("touchstart.zoom", touchstart).on("touchmove.zoom", touchmove).on("touchend.zoom", touchstart);
  1103. }
  1104. zoom.translate = function(x) {
  1105. if (!arguments.length) return translate;
  1106. translate = x.map(Number);
  1107. rescale();
  1108. return zoom;
  1109. };
  1110. zoom.scale = function(x) {
  1111. if (!arguments.length) return scale;
  1112. scale = +x;
  1113. rescale();
  1114. return zoom;
  1115. };
  1116. zoom.scaleExtent = function(x) {
  1117. if (!arguments.length) return scaleExtent;
  1118. scaleExtent = x == null ? d3_behavior_zoomInfinity : x.map(Number);
  1119. return zoom;
  1120. };
  1121. zoom.x = function(z) {
  1122. if (!arguments.length) return x1;
  1123. x1 = z;
  1124. x0 = z.copy();
  1125. translate = [ 0, 0 ];
  1126. scale = 1;
  1127. return zoom;
  1128. };
  1129. zoom.y = function(z) {
  1130. if (!arguments.length) return y1;
  1131. y1 = z;
  1132. y0 = z.copy();
  1133. translate = [ 0, 0 ];
  1134. scale = 1;
  1135. return zoom;
  1136. };
  1137. function location(p) {
  1138. return [ (p[0] - translate[0]) / scale, (p[1] - translate[1]) / scale ];
  1139. }
  1140. function point(l) {
  1141. return [ l[0] * scale + translate[0], l[1] * scale + translate[1] ];
  1142. }
  1143. function scaleTo(s) {
  1144. scale = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  1145. }
  1146. function translateTo(p, l) {
  1147. l = point(l);
  1148. translate[0] += p[0] - l[0];
  1149. translate[1] += p[1] - l[1];
  1150. }
  1151. function rescale() {
  1152. if (x1) x1.domain(x0.range().map(function(x) {
  1153. return (x - translate[0]) / scale;
  1154. }).map(x0.invert));
  1155. if (y1) y1.domain(y0.range().map(function(y) {
  1156. return (y - translate[1]) / scale;
  1157. }).map(y0.invert));
  1158. }
  1159. function dispatch(event) {
  1160. rescale();
  1161. d3.event.preventDefault();
  1162. event({
  1163. type: "zoom",
  1164. scale: scale,
  1165. translate: translate
  1166. });
  1167. }
  1168. function mousedown() {
  1169. var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, moved = 0, w = d3.select(d3_window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup), l = location(d3.mouse(target));
  1170. d3_window.focus();
  1171. d3_eventCancel();
  1172. function mousemove() {
  1173. moved = 1;
  1174. translateTo(d3.mouse(target), l);
  1175. dispatch(event_);
  1176. }
  1177. function mouseup() {
  1178. if (moved) d3_eventCancel();
  1179. w.on("mousemove.zoom", null).on("mouseup.zoom", null);
  1180. if (moved && d3.event.target === eventTarget) d3_eventSuppress(w, "click.zoom");
  1181. }
  1182. }
  1183. function mousewheel() {
  1184. if (!translate0) translate0 = location(d3.mouse(this));
  1185. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * scale);
  1186. translateTo(d3.mouse(this), translate0);
  1187. dispatch(event.of(this, arguments));
  1188. }
  1189. function mousemove() {
  1190. translate0 = null;
  1191. }
  1192. function dblclick() {
  1193. var p = d3.mouse(this), l = location(p), k = Math.log(scale) / Math.LN2;
  1194. scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
  1195. translateTo(p, l);
  1196. dispatch(event.of(this, arguments));
  1197. }
  1198. function touchstart() {
  1199. var touches = d3.touches(this), now = Date.now();
  1200. scale0 = scale;
  1201. translate0 = {};
  1202. touches.forEach(function(t) {
  1203. translate0[t.identifier] = location(t);
  1204. });
  1205. d3_eventCancel();
  1206. if (touches.length === 1) {
  1207. if (now - touchtime < 500) {
  1208. var p = touches[0], l = location(touches[0]);
  1209. scaleTo(scale * 2);
  1210. translateTo(p, l);
  1211. dispatch(event.of(this, arguments));
  1212. }
  1213. touchtime = now;
  1214. }
  1215. }
  1216. function touchmove() {
  1217. var touches = d3.touches(this), p0 = touches[0], l0 = translate0[p0.identifier];
  1218. if (p1 = touches[1]) {
  1219. var p1, l1 = translate0[p1.identifier];
  1220. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  1221. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  1222. scaleTo(d3.event.scale * scale0);
  1223. }
  1224. translateTo(p0, l0);
  1225. touchtime = null;
  1226. dispatch(event.of(this, arguments));
  1227. }
  1228. return d3.rebind(zoom, event, "on");
  1229. };
  1230. var d3_behavior_zoomInfinity = [ 0, Infinity ];
  1231. var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1232. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  1233. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1234. return d3.event.wheelDelta;
  1235. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  1236. return -d3.event.detail;
  1237. }, "MozMousePixelScroll");
  1238. function d3_Color() {}
  1239. d3_Color.prototype.toString = function() {
  1240. return this.rgb() + "";
  1241. };
  1242. d3.hsl = function(h, s, l) {
  1243. return arguments.length === 1 ? h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : d3_hsl(+h, +s, +l);
  1244. };
  1245. function d3_hsl(h, s, l) {
  1246. return new d3_Hsl(h, s, l);
  1247. }
  1248. function d3_Hsl(h, s, l) {
  1249. this.h = h;
  1250. this.s = s;
  1251. this.l = l;
  1252. }
  1253. var d3_hslPrototype = d3_Hsl.prototype = new d3_Color();
  1254. d3_hslPrototype.brighter = function(k) {
  1255. k = Math.pow(.7, arguments.length ? k : 1);
  1256. return d3_hsl(this.h, this.s, this.l / k);
  1257. };
  1258. d3_hslPrototype.darker = function(k) {
  1259. k = Math.pow(.7, arguments.length ? k : 1);
  1260. return d3_hsl(this.h, this.s, k * this.l);
  1261. };
  1262. d3_hslPrototype.rgb = function() {
  1263. return d3_hsl_rgb(this.h, this.s, this.l);
  1264. };
  1265. function d3_hsl_rgb(h, s, l) {
  1266. var m1, m2;
  1267. h = h % 360;
  1268. if (h < 0) h += 360;
  1269. s = s < 0 ? 0 : s > 1 ? 1 : s;
  1270. l = l < 0 ? 0 : l > 1 ? 1 : l;
  1271. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  1272. m1 = 2 * l - m2;
  1273. function v(h) {
  1274. if (h > 360) h -= 360; else if (h < 0) h += 360;
  1275. if (h < 60) return m1 + (m2 - m1) * h / 60;
  1276. if (h < 180) return m2;
  1277. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  1278. return m1;
  1279. }
  1280. function vv(h) {
  1281. return Math.round(v(h) * 255);
  1282. }
  1283. return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  1284. }
  1285. var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π;
  1286. function d3_sgn(x) {
  1287. return x > 0 ? 1 : x < 0 ? -1 : 0;
  1288. }
  1289. function d3_acos(x) {
  1290. return Math.acos(Math.max(-1, Math.min(1, x)));
  1291. }
  1292. function d3_asin(x) {
  1293. return x > 1 ? π / 2 : x < -1 ? -π / 2 : Math.asin(x);
  1294. }
  1295. function d3_sinh(x) {
  1296. return (Math.exp(x) - Math.exp(-x)) / 2;
  1297. }
  1298. function d3_cosh(x) {
  1299. return (Math.exp(x) + Math.exp(-x)) / 2;
  1300. }
  1301. function d3_haversin(x) {
  1302. return (x = Math.sin(x / 2)) * x;
  1303. }
  1304. d3.hcl = function(h, c, l) {
  1305. return arguments.length === 1 ? h instanceof d3_Hcl ? 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) : d3_hcl(+h, +c, +l);
  1306. };
  1307. function d3_hcl(h, c, l) {
  1308. return new d3_Hcl(h, c, l);
  1309. }
  1310. function d3_Hcl(h, c, l) {
  1311. this.h = h;
  1312. this.c = c;
  1313. this.l = l;
  1314. }
  1315. var d3_hclPrototype = d3_Hcl.prototype = new d3_Color();
  1316. d3_hclPrototype.brighter = function(k) {
  1317. return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  1318. };
  1319. d3_hclPrototype.darker = function(k) {
  1320. return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  1321. };
  1322. d3_hclPrototype.rgb = function() {
  1323. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  1324. };
  1325. function d3_hcl_lab(h, c, l) {
  1326. return d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  1327. }
  1328. d3.lab = function(l, a, b) {
  1329. return arguments.length === 1 ? l instanceof d3_Lab ? d3_lab(l.l, l.a, l.b) : l instanceof d3_Hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3.rgb(l)).r, l.g, l.b) : d3_lab(+l, +a, +b);
  1330. };
  1331. function d3_lab(l, a, b) {
  1332. return new d3_Lab(l, a, b);
  1333. }
  1334. function d3_Lab(l, a, b) {
  1335. this.l = l;
  1336. this.a = a;
  1337. this.b = b;
  1338. }
  1339. var d3_lab_K = 18;
  1340. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  1341. var d3_labPrototype = d3_Lab.prototype = new d3_Color();
  1342. d3_labPrototype.brighter = function(k) {
  1343. return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1344. };
  1345. d3_labPrototype.darker = function(k) {
  1346. return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1347. };
  1348. d3_labPrototype.rgb = function() {
  1349. return d3_lab_rgb(this.l, this.a, this.b);
  1350. };
  1351. function d3_lab_rgb(l, a, b) {
  1352. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  1353. x = d3_lab_xyz(x) * d3_lab_X;
  1354. y = d3_lab_xyz(y) * d3_lab_Y;
  1355. z = d3_lab_xyz(z) * d3_lab_Z;
  1356. return 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));
  1357. }
  1358. function d3_lab_hcl(l, a, b) {
  1359. return d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l);
  1360. }
  1361. function d3_lab_xyz(x) {
  1362. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  1363. }
  1364. function d3_xyz_lab(x) {
  1365. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  1366. }
  1367. function d3_xyz_rgb(r) {
  1368. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  1369. }
  1370. d3.rgb = function(r, g, b) {
  1371. return arguments.length === 1 ? r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : d3_rgb(~~r, ~~g, ~~b);
  1372. };
  1373. function d3_rgb(r, g, b) {
  1374. return new d3_Rgb(r, g, b);
  1375. }
  1376. function d3_Rgb(r, g, b) {
  1377. this.r = r;
  1378. this.g = g;
  1379. this.b = b;
  1380. }
  1381. var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color();
  1382. d3_rgbPrototype.brighter = function(k) {
  1383. k = Math.pow(.7, arguments.length ? k : 1);
  1384. var r = this.r, g = this.g, b = this.b, i = 30;
  1385. if (!r && !g && !b) return d3_rgb(i, i, i);
  1386. if (r && r < i) r = i;
  1387. if (g && g < i) g = i;
  1388. if (b && b < i) b = i;
  1389. return d3_rgb(Math.min(255, Math.floor(r / k)), Math.min(255, Math.floor(g / k)), Math.min(255, Math.floor(b / k)));
  1390. };
  1391. d3_rgbPrototype.darker = function(k) {
  1392. k = Math.pow(.7, arguments.length ? k : 1);
  1393. return d3_rgb(Math.floor(k * this.r), Math.floor(k * this.g), Math.floor(k * this.b));
  1394. };
  1395. d3_rgbPrototype.hsl = function() {
  1396. return d3_rgb_hsl(this.r, this.g, this.b);
  1397. };
  1398. d3_rgbPrototype.toString = function() {
  1399. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  1400. };
  1401. function d3_rgb_hex(v) {
  1402. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  1403. }
  1404. function d3_rgb_parse(format, rgb, hsl) {
  1405. var r = 0, g = 0, b = 0, m1, m2, name;
  1406. m1 = /([a-z]+)\((.*)\)/i.exec(format);
  1407. if (m1) {
  1408. m2 = m1[2].split(",");
  1409. switch (m1[1]) {
  1410. case "hsl":
  1411. {
  1412. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  1413. }
  1414. case "rgb":
  1415. {
  1416. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  1417. }
  1418. }
  1419. }
  1420. if (name = d3_rgb_names.get(format)) return rgb(name.r, name.g, name.b);
  1421. if (format != null && format.charAt(0) === "#") {
  1422. if (format.length === 4) {
  1423. r = format.charAt(1);
  1424. r += r;
  1425. g = format.charAt(2);
  1426. g += g;
  1427. b = format.charAt(3);
  1428. b += b;
  1429. } else if (format.length === 7) {
  1430. r = format.substring(1, 3);
  1431. g = format.substring(3, 5);
  1432. b = format.substring(5, 7);
  1433. }
  1434. r = parseInt(r, 16);
  1435. g = parseInt(g, 16);
  1436. b = parseInt(b, 16);
  1437. }
  1438. return rgb(r, g, b);
  1439. }
  1440. function d3_rgb_hsl(r, g, b) {
  1441. 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;
  1442. if (d) {
  1443. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  1444. 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;
  1445. h *= 60;
  1446. } else {
  1447. s = h = 0;
  1448. }
  1449. return d3_hsl(h, s, l);
  1450. }
  1451. function d3_rgb_lab(r, g, b) {
  1452. r = d3_rgb_xyz(r);
  1453. g = d3_rgb_xyz(g);
  1454. b = d3_rgb_xyz(b);
  1455. 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);
  1456. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  1457. }
  1458. function d3_rgb_xyz(r) {
  1459. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  1460. }
  1461. function d3_rgb_parseNumber(c) {
  1462. var f = parseFloat(c);
  1463. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  1464. }
  1465. var d3_rgb_names = d3.map({
  1466. aliceblue: "#f0f8ff",
  1467. antiquewhite: "#faebd7",
  1468. aqua: "#00ffff",
  1469. aquamarine: "#7fffd4",
  1470. azure: "#f0ffff",
  1471. beige: "#f5f5dc",
  1472. bisque: "#ffe4c4",
  1473. black: "#000000",
  1474. blanchedalmond: "#ffebcd",
  1475. blue: "#0000ff",
  1476. blueviolet: "#8a2be2",
  1477. brown: "#a52a2a",
  1478. burlywood: "#deb887",
  1479. cadetblue: "#5f9ea0",
  1480. chartreuse: "#7fff00",
  1481. chocolate: "#d2691e",
  1482. coral: "#ff7f50",
  1483. cornflowerblue: "#6495ed",
  1484. cornsilk: "#fff8dc",
  1485. crimson: "#dc143c",
  1486. cyan: "#00ffff",
  1487. darkblue: "#00008b",
  1488. darkcyan: "#008b8b",
  1489. darkgoldenrod: "#b8860b",
  1490. darkgray: "#a9a9a9",
  1491. darkgreen: "#006400",
  1492. darkgrey: "#a9a9a9",
  1493. darkkhaki: "#bdb76b",
  1494. darkmagenta: "#8b008b",
  1495. darkolivegreen: "#556b2f",
  1496. darkorange: "#ff8c00",
  1497. darkorchid: "#9932cc",
  1498. darkred: "#8b0000",
  1499. darksalmon: "#e9967a",
  1500. darkseagreen: "#8fbc8f",
  1501. darkslateblue: "#483d8b",
  1502. darkslategray: "#2f4f4f",
  1503. darkslategrey: "#2f4f4f",
  1504. darkturquoise: "#00ced1",
  1505. darkviolet: "#9400d3",
  1506. deeppink: "#ff1493",
  1507. deepskyblue: "#00bfff",
  1508. dimgray: "#696969",
  1509. dimgrey: "#696969",
  1510. dodgerblue: "#1e90ff",
  1511. firebrick: "#b22222",
  1512. floralwhite: "#fffaf0",
  1513. forestgreen: "#228b22",
  1514. fuchsia: "#ff00ff",
  1515. gainsboro: "#dcdcdc",
  1516. ghostwhite: "#f8f8ff",
  1517. gold: "#ffd700",
  1518. goldenrod: "#daa520",
  1519. gray: "#808080",
  1520. green: "#008000",
  1521. greenyellow: "#adff2f",
  1522. grey: "#808080",
  1523. honeydew: "#f0fff0",
  1524. hotpink: "#ff69b4",
  1525. indianred: "#cd5c5c",
  1526. indigo: "#4b0082",
  1527. ivory: "#fffff0",
  1528. khaki: "#f0e68c",
  1529. lavender: "#e6e6fa",
  1530. lavenderblush: "#fff0f5",
  1531. lawngreen: "#7cfc00",
  1532. lemonchiffon: "#fffacd",
  1533. lightblue: "#add8e6",
  1534. lightcoral: "#f08080",
  1535. lightcyan: "#e0ffff",
  1536. lightgoldenrodyellow: "#fafad2",
  1537. lightgray: "#d3d3d3",
  1538. lightgreen: "#90ee90",
  1539. lightgrey: "#d3d3d3",
  1540. lightpink: "#ffb6c1",
  1541. lightsalmon: "#ffa07a",
  1542. lightseagreen: "#20b2aa",
  1543. lightskyblue: "#87cefa",
  1544. lightslategray: "#778899",
  1545. lightslategrey: "#778899",
  1546. lightsteelblue: "#b0c4de",
  1547. lightyellow: "#ffffe0",
  1548. lime: "#00ff00",
  1549. limegreen: "#32cd32",
  1550. linen: "#faf0e6",
  1551. magenta: "#ff00ff",
  1552. maroon: "#800000",
  1553. mediumaquamarine: "#66cdaa",
  1554. mediumblue: "#0000cd",
  1555. mediumorchid: "#ba55d3",
  1556. mediumpurple: "#9370db",
  1557. mediumseagreen: "#3cb371",
  1558. mediumslateblue: "#7b68ee",
  1559. mediumspringgreen: "#00fa9a",
  1560. mediumturquoise: "#48d1cc",
  1561. mediumvioletred: "#c71585",
  1562. midnightblue: "#191970",
  1563. mintcream: "#f5fffa",
  1564. mistyrose: "#ffe4e1",
  1565. moccasin: "#ffe4b5",
  1566. navajowhite: "#ffdead",
  1567. navy: "#000080",
  1568. oldlace: "#fdf5e6",
  1569. olive: "#808000",
  1570. olivedrab: "#6b8e23",
  1571. orange: "#ffa500",
  1572. orangered: "#ff4500",
  1573. orchid: "#da70d6",
  1574. palegoldenrod: "#eee8aa",
  1575. palegreen: "#98fb98",
  1576. paleturquoise: "#afeeee",
  1577. palevioletred: "#db7093",
  1578. papayawhip: "#ffefd5",
  1579. peachpuff: "#ffdab9",
  1580. peru: "#cd853f",
  1581. pink: "#ffc0cb",
  1582. plum: "#dda0dd",
  1583. powderblue: "#b0e0e6",
  1584. purple: "#800080",
  1585. red: "#ff0000",
  1586. rosybrown: "#bc8f8f",
  1587. royalblue: "#4169e1",
  1588. saddlebrown: "#8b4513",
  1589. salmon: "#fa8072",
  1590. sandybrown: "#f4a460",
  1591. seagreen: "#2e8b57",
  1592. seashell: "#fff5ee",
  1593. sienna: "#a0522d",
  1594. silver: "#c0c0c0",
  1595. skyblue: "#87ceeb",
  1596. slateblue: "#6a5acd",
  1597. slategray: "#708090",
  1598. slategrey: "#708090",
  1599. snow: "#fffafa",
  1600. springgreen: "#00ff7f",
  1601. steelblue: "#4682b4",
  1602. tan: "#d2b48c",
  1603. teal: "#008080",
  1604. thistle: "#d8bfd8",
  1605. tomato: "#ff6347",
  1606. turquoise: "#40e0d0",
  1607. violet: "#ee82ee",
  1608. wheat: "#f5deb3",
  1609. white: "#ffffff",
  1610. whitesmoke: "#f5f5f5",
  1611. yellow: "#ffff00",
  1612. yellowgreen: "#9acd32"
  1613. });
  1614. d3_rgb_names.forEach(function(key, value) {
  1615. d3_rgb_names.set(key, d3_rgb_parse(value, d3_rgb, d3_hsl_rgb));
  1616. });
  1617. function d3_functor(v) {
  1618. return typeof v === "function" ? v : function() {
  1619. return v;
  1620. };
  1621. }
  1622. d3.functor = d3_functor;
  1623. function d3_identity(d) {
  1624. return d;
  1625. }
  1626. d3.xhr = function(url, mimeType, callback) {
  1627. var xhr = {}, dispatch = d3.dispatch("progress", "load", "error"), headers = {}, response = d3_identity, request = new (d3_window.XDomainRequest && /^(http(s)?:)?\/\//.test(url) ? XDomainRequest : XMLHttpRequest)();
  1628. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  1629. request.readyState > 3 && respond();
  1630. };
  1631. function respond() {
  1632. var s = request.status;
  1633. !s && request.responseText || s >= 200 && s < 300 || s === 304 ? dispatch.load.call(xhr, response.call(xhr, request)) : dispatch.error.call(xhr, request);
  1634. }
  1635. request.onprogress = function(event) {
  1636. var o = d3.event;
  1637. d3.event = event;
  1638. try {
  1639. dispatch.progress.call(xhr, request);
  1640. } finally {
  1641. d3.event = o;
  1642. }
  1643. };
  1644. xhr.header = function(name, value) {
  1645. name = (name + "").toLowerCase();
  1646. if (arguments.length < 2) return headers[name];
  1647. if (value == null) delete headers[name]; else headers[name] = value + "";
  1648. return xhr;
  1649. };
  1650. xhr.mimeType = function(value) {
  1651. if (!arguments.length) return mimeType;
  1652. mimeType = value == null ? null : value + "";
  1653. return xhr;
  1654. };
  1655. xhr.response = function(value) {
  1656. response = value;
  1657. return xhr;
  1658. };
  1659. [ "get", "post" ].forEach(function(method) {
  1660. xhr[method] = function() {
  1661. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  1662. };
  1663. });
  1664. xhr.send = function(method, data, callback) {
  1665. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  1666. request.open(method, url, true);
  1667. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  1668. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  1669. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  1670. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  1671. callback(null, request);
  1672. });
  1673. request.send(data == null ? null : data);
  1674. return xhr;
  1675. };
  1676. xhr.abort = function() {
  1677. request.abort();
  1678. return xhr;
  1679. };
  1680. d3.rebind(xhr, dispatch, "on");
  1681. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  1682. mimeType = null;
  1683. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  1684. };
  1685. function d3_xhr_fixCallback(callback) {
  1686. return callback.length === 1 ? function(error, request) {
  1687. callback(error == null ? request : null);
  1688. } : callback;
  1689. }
  1690. function d3_dsv(delimiter, mimeType) {
  1691. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  1692. function dsv(url, row, callback) {
  1693. if (arguments.length < 3) callback = row, row = null;
  1694. var xhr = d3.xhr(url, mimeType, callback);
  1695. xhr.row = function(_) {
  1696. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  1697. };
  1698. return xhr.row(row);
  1699. }
  1700. function response(request) {
  1701. return dsv.parse(request.responseText);
  1702. }
  1703. function typedResponse(f) {
  1704. return function(request) {
  1705. return dsv.parse(request.responseText, f);
  1706. };
  1707. }
  1708. dsv.parse = function(text, f) {
  1709. var o;
  1710. return dsv.parseRows(text, function(row, i) {
  1711. if (o) return o(row, i - 1);
  1712. var a = new Function("d", "return {" + row.map(function(name, i) {
  1713. return JSON.stringify(name) + ": d[" + i + "]";
  1714. }).join(",") + "}");
  1715. o = f ? function(row, i) {
  1716. return f(a(row), i);
  1717. } : a;
  1718. });
  1719. };
  1720. dsv.parseRows = function(text, f) {
  1721. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  1722. function token() {
  1723. if (I >= N) return EOF;
  1724. if (eol) return eol = false, EOL;
  1725. var j = I;
  1726. if (text.charCodeAt(j) === 34) {
  1727. var i = j;
  1728. while (i++ < N) {
  1729. if (text.charCodeAt(i) === 34) {
  1730. if (text.charCodeAt(i + 1) !== 34) break;
  1731. ++i;
  1732. }
  1733. }
  1734. I = i + 2;
  1735. var c = text.charCodeAt(i + 1);
  1736. if (c === 13) {
  1737. eol = true;
  1738. if (text.charCodeAt(i + 2) === 10) ++I;
  1739. } else if (c === 10) {
  1740. eol = true;
  1741. }
  1742. return text.substring(j + 1, i).replace(/""/g, '"');
  1743. }
  1744. while (I < N) {
  1745. var c = text.charCodeAt(I++), k = 1;
  1746. if (c === 10) eol = true; else if (c === 13) {
  1747. eol = true;
  1748. if (text.charCodeAt(I) === 10) ++I, ++k;
  1749. } else if (c !== delimiterCode) continue;
  1750. return text.substring(j, I - k);
  1751. }
  1752. return text.substring(j);
  1753. }
  1754. while ((t = token()) !== EOF) {
  1755. var a = [];
  1756. while (t !== EOL && t !== EOF) {
  1757. a.push(t);
  1758. t = token();
  1759. }
  1760. if (f && !(a = f(a, n++))) continue;
  1761. rows.push(a);
  1762. }
  1763. return rows;
  1764. };
  1765. dsv.format = function(rows) {
  1766. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  1767. var fieldSet = new d3_Set(), fields = [];
  1768. rows.forEach(function(row) {
  1769. for (var field in row) {
  1770. if (!fieldSet.has(field)) {
  1771. fields.push(fieldSet.add(field));
  1772. }
  1773. }
  1774. });
  1775. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  1776. return fields.map(function(field) {
  1777. return formatValue(row[field]);
  1778. }).join(delimiter);
  1779. })).join("\n");
  1780. };
  1781. dsv.formatRows = function(rows) {
  1782. return rows.map(formatRow).join("\n");
  1783. };
  1784. function formatRow(row) {
  1785. return row.map(formatValue).join(delimiter);
  1786. }
  1787. function formatValue(text) {
  1788. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  1789. }
  1790. return dsv;
  1791. }
  1792. d3.csv = d3_dsv(",", "text/csv");
  1793. d3.tsv = d3_dsv(" ", "text/tab-separated-values");
  1794. var d3_timer_id = 0, d3_timer_byId = {}, d3_timer_queue = null, d3_timer_interval, d3_timer_timeout;
  1795. d3.timer = function(callback, delay, then) {
  1796. if (arguments.length < 3) {
  1797. if (arguments.length < 2) delay = 0; else if (!isFinite(delay)) return;
  1798. then = Date.now();
  1799. }
  1800. var timer = d3_timer_byId[callback.id];
  1801. if (timer && timer.callback === callback) {
  1802. timer.then = then;
  1803. timer.delay = delay;
  1804. } else d3_timer_byId[callback.id = ++d3_timer_id] = d3_timer_queue = {
  1805. callback: callback,
  1806. then: then,
  1807. delay: delay,
  1808. next: d3_timer_queue
  1809. };
  1810. if (!d3_timer_interval) {
  1811. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  1812. d3_timer_interval = 1;
  1813. d3_timer_frame(d3_timer_step);
  1814. }
  1815. };
  1816. function d3_timer_step() {
  1817. var elapsed, now = Date.now(), t1 = d3_timer_queue;
  1818. while (t1) {
  1819. elapsed = now - t1.then;
  1820. if (elapsed >= t1.delay) t1.flush = t1.callback(elapsed);
  1821. t1 = t1.next;
  1822. }
  1823. var delay = d3_timer_flush() - now;
  1824. if (delay > 24) {
  1825. if (isFinite(delay)) {
  1826. clearTimeout(d3_timer_timeout);
  1827. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  1828. }
  1829. d3_timer_interval = 0;
  1830. } else {
  1831. d3_timer_interval = 1;
  1832. d3_timer_frame(d3_timer_step);
  1833. }
  1834. }
  1835. d3.timer.flush = function() {
  1836. var elapsed, now = Date.now(), t1 = d3_timer_queue;
  1837. while (t1) {
  1838. elapsed = now - t1.then;
  1839. if (!t1.delay) t1.flush = t1.callback(elapsed);
  1840. t1 = t1.next;
  1841. }
  1842. d3_timer_flush();
  1843. };
  1844. function d3_timer_flush() {
  1845. var t0 = null, t1 = d3_timer_queue, then = Infinity;
  1846. while (t1) {
  1847. if (t1.flush) {
  1848. delete d3_timer_byId[t1.callback.id];
  1849. t1 = t0 ? t0.next = t1.next : d3_timer_queue = t1.next;
  1850. } else {
  1851. then = Math.min(then, t1.then + t1.delay);
  1852. t1 = (t0 = t1).next;
  1853. }
  1854. }
  1855. return then;
  1856. }
  1857. var d3_timer_frame = d3_window.requestAnimationFrame || d3_window.webkitRequestAnimationFrame || d3_window.mozRequestAnimationFrame || d3_window.oRequestAnimationFrame || d3_window.msRequestAnimationFrame || function(callback) {
  1858. setTimeout(callback, 17);
  1859. };
  1860. var d3_format_decimalPoint = ".", d3_format_thousandsSeparator = ",", d3_format_grouping = [ 3, 3 ];
  1861. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  1862. d3.formatPrefix = function(value, precision) {
  1863. var i = 0;
  1864. if (value) {
  1865. if (value < 0) value *= -1;
  1866. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  1867. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  1868. i = Math.max(-24, Math.min(24, Math.floor((i <= 0 ? i + 1 : i - 1) / 3) * 3));
  1869. }
  1870. return d3_formatPrefixes[8 + i / 3];
  1871. };
  1872. function d3_formatPrefix(d, i) {
  1873. var k = Math.pow(10, Math.abs(8 - i) * 3);
  1874. return {
  1875. scale: i > 8 ? function(d) {
  1876. return d / k;
  1877. } : function(d) {
  1878. return d * k;
  1879. },
  1880. symbol: d
  1881. };
  1882. }
  1883. d3.round = function(x, n) {
  1884. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  1885. };
  1886. d3.format = function(specifier) {
  1887. var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "", basePrefix = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, suffix = "", integer = false;
  1888. if (precision) precision = +precision.substring(1);
  1889. if (zfill || fill === "0" && align === "=") {
  1890. zfill = fill = "0";
  1891. align = "=";
  1892. if (comma) width -= Math.floor((width - 1) / 4);
  1893. }
  1894. switch (type) {
  1895. case "n":
  1896. comma = true;
  1897. type = "g";
  1898. break;
  1899. case "%":
  1900. scale = 100;
  1901. suffix = "%";
  1902. type = "f";
  1903. break;
  1904. case "p":
  1905. scale = 100;
  1906. suffix = "%";
  1907. type = "r";
  1908. break;
  1909. case "b":
  1910. case "o":
  1911. case "x":
  1912. case "X":
  1913. if (basePrefix) basePrefix = "0" + type.toLowerCase();
  1914. case "c":
  1915. case "d":
  1916. integer = true;
  1917. precision = 0;
  1918. break;
  1919. case "s":
  1920. scale = -1;
  1921. type = "r";
  1922. break;
  1923. }
  1924. if (basePrefix === "#") basePrefix = "";
  1925. if (type == "r" && !precision) type = "g";
  1926. if (precision != null) {
  1927. 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));
  1928. }
  1929. type = d3_format_types.get(type) || d3_format_typeDefault;
  1930. var zcomma = zfill && comma;
  1931. return function(value) {
  1932. if (integer && value % 1) return "";
  1933. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign;
  1934. if (scale < 0) {
  1935. var prefix = d3.formatPrefix(value, precision);
  1936. value = prefix.scale(value);
  1937. suffix = prefix.symbol;
  1938. } else {
  1939. value *= scale;
  1940. }
  1941. value = type(value, precision);
  1942. if (!zfill && comma) value = d3_format_group(value);
  1943. var length = basePrefix.length + value.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  1944. if (zcomma) value = d3_format_group(padding + value);
  1945. if (d3_format_decimalPoint) value.replace(".", d3_format_decimalPoint);
  1946. negative += basePrefix;
  1947. 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)) + suffix;
  1948. };
  1949. };
  1950. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  1951. var d3_format_types = d3.map({
  1952. b: function(x) {
  1953. return x.toString(2);
  1954. },
  1955. c: function(x) {
  1956. return String.fromCharCode(x);
  1957. },
  1958. o: function(x) {
  1959. return x.toString(8);
  1960. },
  1961. x: function(x) {
  1962. return x.toString(16);
  1963. },
  1964. X: function(x) {
  1965. return x.toString(16).toUpperCase();
  1966. },
  1967. g: function(x, p) {
  1968. return x.toPrecision(p);
  1969. },
  1970. e: function(x, p) {
  1971. return x.toExponential(p);
  1972. },
  1973. f: function(x, p) {
  1974. return x.toFixed(p);
  1975. },
  1976. r: function(x, p) {
  1977. 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))));
  1978. }
  1979. });
  1980. function d3_format_precision(x, p) {
  1981. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  1982. }
  1983. function d3_format_typeDefault(x) {
  1984. return x + "";
  1985. }
  1986. var d3_format_group = d3_identity;
  1987. if (d3_format_grouping) {
  1988. var d3_format_groupingLength = d3_format_grouping.length;
  1989. d3_format_group = function(value) {
  1990. var i = value.lastIndexOf("."), f = i >= 0 ? "." + value.substring(i + 1) : (i = value.length,
  1991. ""), t = [], j = 0, g = d3_format_grouping[0];
  1992. while (i > 0 && g > 0) {
  1993. t.push(value.substring(i -= g, i + g));
  1994. g = d3_format_grouping[j = (j + 1) % d3_format_groupingLength];
  1995. }
  1996. return t.reverse().join(d3_format_thousandsSeparator || "") + f;
  1997. };
  1998. }
  1999. d3.geo = {};
  2000. d3.geo.stream = function(object, listener) {
  2001. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  2002. d3_geo_streamObjectType[object.type](object, listener);
  2003. } else {
  2004. d3_geo_streamGeometry(object, listener);
  2005. }
  2006. };
  2007. function d3_geo_streamGeometry(geometry, listener) {
  2008. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  2009. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  2010. }
  2011. }
  2012. var d3_geo_streamObjectType = {
  2013. Feature: function(feature, listener) {
  2014. d3_geo_streamGeometry(feature.geometry, listener);
  2015. },
  2016. FeatureCollection: function(object, listener) {
  2017. var features = object.features, i = -1, n = features.length;
  2018. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  2019. }
  2020. };
  2021. var d3_geo_streamGeometryType = {
  2022. Sphere: function(object, listener) {
  2023. listener.sphere();
  2024. },
  2025. Point: function(object, listener) {
  2026. var coordinate = object.coordinates;
  2027. listener.point(coordinate[0], coordinate[1]);
  2028. },
  2029. MultiPoint: function(object, listener) {
  2030. var coordinates = object.coordinates, i = -1, n = coordinates.length, coordinate;
  2031. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1]);
  2032. },
  2033. LineString: function(object, listener) {
  2034. d3_geo_streamLine(object.coordinates, listener, 0);
  2035. },
  2036. MultiLineString: function(object, listener) {
  2037. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2038. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  2039. },
  2040. Polygon: function(object, listener) {
  2041. d3_geo_streamPolygon(object.coordinates, listener);
  2042. },
  2043. MultiPolygon: function(object, listener) {
  2044. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2045. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  2046. },
  2047. GeometryCollection: function(object, listener) {
  2048. var geometries = object.geometries, i = -1, n = geometries.length;
  2049. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  2050. }
  2051. };
  2052. function d3_geo_streamLine(coordinates, listener, closed) {
  2053. var i = -1, n = coordinates.length - closed, coordinate;
  2054. listener.lineStart();
  2055. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1]);
  2056. listener.lineEnd();
  2057. }
  2058. function d3_geo_streamPolygon(coordinates, listener) {
  2059. var i = -1, n = coordinates.length;
  2060. listener.polygonStart();
  2061. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  2062. listener.polygonEnd();
  2063. }
  2064. d3.geo.area = function(object) {
  2065. d3_geo_areaSum = 0;
  2066. d3.geo.stream(object, d3_geo_area);
  2067. return d3_geo_areaSum;
  2068. };
  2069. var d3_geo_areaSum, d3_geo_areaRingU, d3_geo_areaRingV;
  2070. var d3_geo_area = {
  2071. sphere: function() {
  2072. d3_geo_areaSum += 4 * π;
  2073. },
  2074. point: d3_noop,
  2075. lineStart: d3_noop,
  2076. lineEnd: d3_noop,
  2077. polygonStart: function() {
  2078. d3_geo_areaRingU = 1, d3_geo_areaRingV = 0;
  2079. d3_geo_area.lineStart = d3_geo_areaRingStart;
  2080. },
  2081. polygonEnd: function() {
  2082. var area = 2 * Math.atan2(d3_geo_areaRingV, d3_geo_areaRingU);
  2083. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  2084. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  2085. }
  2086. };
  2087. function d3_geo_areaRingStart() {
  2088. var λ00, φ00, λ0, cosφ0, sinφ0;
  2089. d3_geo_area.point = function(λ, φ) {
  2090. d3_geo_area.point = nextPoint;
  2091. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  2092. sinφ0 = Math.sin(φ);
  2093. };
  2094. function nextPoint(λ, φ) {
  2095. λ *= d3_radians;
  2096. φ = φ * d3_radians / 2 + π / 4;
  2097. var dλ = λ - λ0, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u0 = d3_geo_areaRingU, v0 = d3_geo_areaRingV, u = cosφ0 * cosφ + k * Math.cos(dλ), v = k * Math.sin(dλ);
  2098. d3_geo_areaRingU = u0 * u - v0 * v;
  2099. d3_geo_areaRingV = v0 * u + u0 * v;
  2100. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  2101. }
  2102. d3_geo_area.lineEnd = function() {
  2103. nextPoint(λ00, φ00);
  2104. };
  2105. }
  2106. d3.geo.bounds = d3_geo_bounds(d3_identity);
  2107. function d3_geo_bounds(projectStream) {
  2108. var x0, y0, x1, y1;
  2109. var bound = {
  2110. point: boundPoint,
  2111. lineStart: d3_noop,
  2112. lineEnd: d3_noop,
  2113. polygonStart: function() {
  2114. bound.lineEnd = boundPolygonLineEnd;
  2115. },
  2116. polygonEnd: function() {
  2117. bound.point = boundPoint;
  2118. }
  2119. };
  2120. function boundPoint(x, y) {
  2121. if (x < x0) x0 = x;
  2122. if (x > x1) x1 = x;
  2123. if (y < y0) y0 = y;
  2124. if (y > y1) y1 = y;
  2125. }
  2126. function boundPolygonLineEnd() {
  2127. bound.point = bound.lineEnd = d3_noop;
  2128. }
  2129. return function(feature) {
  2130. y1 = x1 = -(x0 = y0 = Infinity);
  2131. d3.geo.stream(feature, projectStream(bound));
  2132. return [ [ x0, y0 ], [ x1, y1 ] ];
  2133. };
  2134. }
  2135. d3.geo.centroid = function(object) {
  2136. d3_geo_centroidDimension = d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
  2137. d3.geo.stream(object, d3_geo_centroid);
  2138. var m;
  2139. if (d3_geo_centroidW && Math.abs(m = Math.sqrt(d3_geo_centroidX * d3_geo_centroidX + d3_geo_centroidY * d3_geo_centroidY + d3_geo_centroidZ * d3_geo_centroidZ)) > ε) {
  2140. return [ Math.atan2(d3_geo_centroidY, d3_geo_centroidX) * d3_degrees, Math.asin(Math.max(-1, Math.min(1, d3_geo_centroidZ / m))) * d3_degrees ];
  2141. }
  2142. };
  2143. var d3_geo_centroidDimension, d3_geo_centroidW, d3_geo_centroidX, d3_geo_centroidY, d3_geo_centroidZ;
  2144. var d3_geo_centroid = {
  2145. sphere: function() {
  2146. if (d3_geo_centroidDimension < 2) {
  2147. d3_geo_centroidDimension = 2;
  2148. d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
  2149. }
  2150. },
  2151. point: d3_geo_centroidPoint,
  2152. lineStart: d3_geo_centroidLineStart,
  2153. lineEnd: d3_geo_centroidLineEnd,
  2154. polygonStart: function() {
  2155. if (d3_geo_centroidDimension < 2) {
  2156. d3_geo_centroidDimension = 2;
  2157. d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
  2158. }
  2159. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  2160. },
  2161. polygonEnd: function() {
  2162. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  2163. }
  2164. };
  2165. function d3_geo_centroidPoint(λ, φ) {
  2166. if (d3_geo_centroidDimension) return;
  2167. ++d3_geo_centroidW;
  2168. λ *= d3_radians;
  2169. var cosφ = Math.cos(φ *= d3_radians);
  2170. d3_geo_centroidX += (cosφ * Math.cos(λ) - d3_geo_centroidX) / d3_geo_centroidW;
  2171. d3_geo_centroidY += (cosφ * Math.sin(λ) - d3_geo_centroidY) / d3_geo_centroidW;
  2172. d3_geo_centroidZ += (Math.sin(φ) - d3_geo_centroidZ) / d3_geo_centroidW;
  2173. }
  2174. function d3_geo_centroidRingStart() {
  2175. var λ00, φ00;
  2176. d3_geo_centroidDimension = 1;
  2177. d3_geo_centroidLineStart();
  2178. d3_geo_centroidDimension = 2;
  2179. var linePoint = d3_geo_centroid.point;
  2180. d3_geo_centroid.point = function(λ, φ) {
  2181. linePoint(λ00 = λ, φ00 = φ);
  2182. };
  2183. d3_geo_centroid.lineEnd = function() {
  2184. d3_geo_centroid.point(λ00, φ00);
  2185. d3_geo_centroidLineEnd();
  2186. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  2187. };
  2188. }
  2189. function d3_geo_centroidLineStart() {
  2190. var x0, y0, z0;
  2191. if (d3_geo_centroidDimension > 1) return;
  2192. if (d3_geo_centroidDimension < 1) {
  2193. d3_geo_centroidDimension = 1;
  2194. d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
  2195. }
  2196. d3_geo_centroid.point = function(λ, φ) {
  2197. λ *= d3_radians;
  2198. var cosφ = Math.cos(φ *= d3_radians);
  2199. x0 = cosφ * Math.cos(λ);
  2200. y0 = cosφ * Math.sin(λ);
  2201. z0 = Math.sin(φ);
  2202. d3_geo_centroid.point = nextPoint;
  2203. };
  2204. function nextPoint(λ, φ) {
  2205. λ *= d3_radians;
  2206. 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);
  2207. d3_geo_centroidW += w;
  2208. d3_geo_centroidX += w * (x0 + (x0 = x));
  2209. d3_geo_centroidY += w * (y0 + (y0 = y));
  2210. d3_geo_centroidZ += w * (z0 + (z0 = z));
  2211. }
  2212. }
  2213. function d3_geo_centroidLineEnd() {
  2214. d3_geo_centroid.point = d3_geo_centroidPoint;
  2215. }
  2216. function d3_geo_cartesian(spherical) {
  2217. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  2218. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  2219. }
  2220. function d3_geo_cartesianDot(a, b) {
  2221. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  2222. }
  2223. function d3_geo_cartesianCross(a, b) {
  2224. 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] ];
  2225. }
  2226. function d3_geo_cartesianAdd(a, b) {
  2227. a[0] += b[0];
  2228. a[1] += b[1];
  2229. a[2] += b[2];
  2230. }
  2231. function d3_geo_cartesianScale(vector, k) {
  2232. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  2233. }
  2234. function d3_geo_cartesianNormalize(d) {
  2235. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  2236. d[0] /= l;
  2237. d[1] /= l;
  2238. d[2] /= l;
  2239. }
  2240. function d3_true() {
  2241. return true;
  2242. }
  2243. function d3_geo_spherical(cartesian) {
  2244. return [ Math.atan2(cartesian[1], cartesian[0]), Math.asin(Math.max(-1, Math.min(1, cartesian[2]))) ];
  2245. }
  2246. function d3_geo_sphericalEqual(a, b) {
  2247. return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;
  2248. }
  2249. function d3_geo_clipPolygon(segments, compare, inside, interpolate, listener) {
  2250. var subject = [], clip = [];
  2251. segments.forEach(function(segment) {
  2252. if ((n = segment.length - 1) <= 0) return;
  2253. var n, p0 = segment[0], p1 = segment[n];
  2254. if (d3_geo_sphericalEqual(p0, p1)) {
  2255. listener.lineStart();
  2256. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  2257. listener.lineEnd();
  2258. return;
  2259. }
  2260. var a = {
  2261. point: p0,
  2262. points: segment,
  2263. other: null,
  2264. visited: false,
  2265. entry: true,
  2266. subject: true
  2267. }, b = {
  2268. point: p0,
  2269. points: [ p0 ],
  2270. other: a,
  2271. visited: false,
  2272. entry: false,
  2273. subject: false
  2274. };
  2275. a.other = b;
  2276. subject.push(a);
  2277. clip.push(b);
  2278. a = {
  2279. point: p1,
  2280. points: [ p1 ],
  2281. other: null,
  2282. visited: false,
  2283. entry: false,
  2284. subject: true
  2285. };
  2286. b = {
  2287. point: p1,
  2288. points: [ p1 ],
  2289. other: a,
  2290. visited: false,
  2291. entry: true,
  2292. subject: false
  2293. };
  2294. a.other = b;
  2295. subject.push(a);
  2296. clip.push(b);
  2297. });
  2298. clip.sort(compare);
  2299. d3_geo_clipPolygonLinkCircular(subject);
  2300. d3_geo_clipPolygonLinkCircular(clip);
  2301. if (!subject.length) return;
  2302. if (inside) for (var i = 1, e = !inside(clip[0].point), n = clip.length; i < n; ++i) {
  2303. clip[i].entry = e = !e;
  2304. }
  2305. var start = subject[0], current, points, point;
  2306. while (1) {
  2307. current = start;
  2308. while (current.visited) if ((current = current.next) === start) return;
  2309. points = current.points;
  2310. listener.lineStart();
  2311. do {
  2312. current.visited = current.other.visited = true;
  2313. if (current.entry) {
  2314. if (current.subject) {
  2315. for (var i = 0; i < points.length; i++) listener.point((point = points[i])[0], point[1]);
  2316. } else {
  2317. interpolate(current.point, current.next.point, 1, listener);
  2318. }
  2319. current = current.next;
  2320. } else {
  2321. if (current.subject) {
  2322. points = current.prev.points;
  2323. for (var i = points.length; --i >= 0; ) listener.point((point = points[i])[0], point[1]);
  2324. } else {
  2325. interpolate(current.point, current.prev.point, -1, listener);
  2326. }
  2327. current = current.prev;
  2328. }
  2329. current = current.other;
  2330. points = current.points;
  2331. } while (!current.visited);
  2332. listener.lineEnd();
  2333. }
  2334. }
  2335. function d3_geo_clipPolygonLinkCircular(array) {
  2336. if (!(n = array.length)) return;
  2337. var n, i = 0, a = array[0], b;
  2338. while (++i < n) {
  2339. a.next = b = array[i];
  2340. b.prev = a;
  2341. a = b;
  2342. }
  2343. a.next = b = array[0];
  2344. b.prev = a;
  2345. }
  2346. function d3_geo_clip(pointVisible, clipLine, interpolate) {
  2347. return function(listener) {
  2348. var line = clipLine(listener);
  2349. var clip = {
  2350. point: point,
  2351. lineStart: lineStart,
  2352. lineEnd: lineEnd,
  2353. polygonStart: function() {
  2354. clip.point = pointRing;
  2355. clip.lineStart = ringStart;
  2356. clip.lineEnd = ringEnd;
  2357. invisible = false;
  2358. invisibleArea = visibleArea = 0;
  2359. segments = [];
  2360. listener.polygonStart();
  2361. },
  2362. polygonEnd: function() {
  2363. clip.point = point;
  2364. clip.lineStart = lineStart;
  2365. clip.lineEnd = lineEnd;
  2366. segments = d3.merge(segments);
  2367. if (segments.length) {
  2368. d3_geo_clipPolygon(segments, d3_geo_clipSort, null, interpolate, listener);
  2369. } else if (visibleArea < -ε || invisible && invisibleArea < -ε) {
  2370. listener.lineStart();
  2371. interpolate(null, null, 1, listener);
  2372. listener.lineEnd();
  2373. }
  2374. listener.polygonEnd();
  2375. segments = null;
  2376. },
  2377. sphere: function() {
  2378. listener.polygonStart();
  2379. listener.lineStart();
  2380. interpolate(null, null, 1, listener);
  2381. listener.lineEnd();
  2382. listener.polygonEnd();
  2383. }
  2384. };
  2385. function point(λ, φ) {
  2386. if (pointVisible(λ, φ)) listener.point(λ, φ);
  2387. }
  2388. function pointLine(λ, φ) {
  2389. line.point(λ, φ);
  2390. }
  2391. function lineStart() {
  2392. clip.point = pointLine;
  2393. line.lineStart();
  2394. }
  2395. function lineEnd() {
  2396. clip.point = point;
  2397. line.lineEnd();
  2398. }
  2399. var segments, visibleArea, invisibleArea, invisible;
  2400. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), ring;
  2401. function pointRing(λ, φ) {
  2402. ringListener.point(λ, φ);
  2403. ring.push([ λ, φ ]);
  2404. }
  2405. function ringStart() {
  2406. ringListener.lineStart();
  2407. ring = [];
  2408. }
  2409. function ringEnd() {
  2410. pointRing(ring[0][0], ring[0][1]);
  2411. ringListener.lineEnd();
  2412. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  2413. if (!n) {
  2414. invisible = true;
  2415. invisibleArea += d3_geo_clipAreaRing(ring, -1);
  2416. ring = null;
  2417. return;
  2418. }
  2419. ring = null;
  2420. if (clean & 1) {
  2421. segment = ringSegments[0];
  2422. visibleArea += d3_geo_clipAreaRing(segment, 1);
  2423. var n = segment.length - 1, i = -1, point;
  2424. listener.lineStart();
  2425. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  2426. listener.lineEnd();
  2427. return;
  2428. }
  2429. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  2430. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  2431. }
  2432. return clip;
  2433. };
  2434. }
  2435. function d3_geo_clipSegmentLength1(segment) {
  2436. return segment.length > 1;
  2437. }
  2438. function d3_geo_clipBufferListener() {
  2439. var lines = [], line;
  2440. return {
  2441. lineStart: function() {
  2442. lines.push(line = []);
  2443. },
  2444. point: function(λ, φ) {
  2445. line.push([ λ, φ ]);
  2446. },
  2447. lineEnd: d3_noop,
  2448. buffer: function() {
  2449. var buffer = lines;
  2450. lines = [];
  2451. line = null;
  2452. return buffer;
  2453. },
  2454. rejoin: function() {
  2455. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  2456. }
  2457. };
  2458. }
  2459. function d3_geo_clipAreaRing(ring, invisible) {
  2460. if (!(n = ring.length)) return 0;
  2461. var n, i = 0, area = 0, p = ring[0], λ = p[0], φ = p[1], cosφ = Math.cos(φ), x0 = Math.atan2(invisible * Math.sin(λ) * cosφ, Math.sin(φ)), y0 = 1 - invisible * Math.cos(λ) * cosφ, x1 = x0, x, y;
  2462. while (++i < n) {
  2463. p = ring[i];
  2464. cosφ = Math.cos(φ = p[1]);
  2465. x = Math.atan2(invisible * Math.sin(λ = p[0]) * cosφ, Math.sin(φ));
  2466. y = 1 - invisible * Math.cos(λ) * cosφ;
  2467. if (Math.abs(y0 - 2) < ε && Math.abs(y - 2) < ε) continue;
  2468. if (Math.abs(y) < ε || Math.abs(y0) < ε) {} else if (Math.abs(Math.abs(x - x0) - π) < ε) {
  2469. if (y + y0 > 2) area += 4 * (x - x0);
  2470. } else if (Math.abs(y0 - 2) < ε) area += 4 * (x - x1); else area += ((3 * π + x - x0) % (2 * π) - π) * (y0 + y);
  2471. x1 = x0, x0 = x, y0 = y;
  2472. }
  2473. return area;
  2474. }
  2475. function d3_geo_clipSort(a, b) {
  2476. return ((a = a.point)[0] < 0 ? a[1] - π / 2 - ε : π / 2 - a[1]) - ((b = b.point)[0] < 0 ? b[1] - π / 2 - ε : π / 2 - b[1]);
  2477. }
  2478. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate);
  2479. function d3_geo_clipAntimeridianLine(listener) {
  2480. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  2481. return {
  2482. lineStart: function() {
  2483. listener.lineStart();
  2484. clean = 1;
  2485. },
  2486. point: function(λ1, φ1) {
  2487. var sλ1 = λ1 > 0 ? π : -π, dλ = Math.abs(λ1 - λ0);
  2488. if (Math.abs(dλ - π) < ε) {
  2489. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? π / 2 : -π / 2);
  2490. listener.point(sλ0, φ0);
  2491. listener.lineEnd();
  2492. listener.lineStart();
  2493. listener.point(sλ1, φ0);
  2494. listener.point(λ1, φ0);
  2495. clean = 0;
  2496. } else if (sλ0 !== sλ1 && dλ >= π) {
  2497. if (Math.abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  2498. if (Math.abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  2499. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  2500. listener.point(sλ0, φ0);
  2501. listener.lineEnd();
  2502. listener.lineStart();
  2503. listener.point(sλ1, φ0);
  2504. clean = 0;
  2505. }
  2506. listener.point(λ0 = λ1, φ0 = φ1);
  2507. sλ0 = sλ1;
  2508. },
  2509. lineEnd: function() {
  2510. listener.lineEnd();
  2511. λ0 = φ0 = NaN;
  2512. },
  2513. clean: function() {
  2514. return 2 - clean;
  2515. }
  2516. };
  2517. }
  2518. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  2519. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  2520. return Math.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;
  2521. }
  2522. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  2523. var φ;
  2524. if (from == null) {
  2525. φ = direction * π / 2;
  2526. listener.point(-π, φ);
  2527. listener.point(0, φ);
  2528. listener.point(π, φ);
  2529. listener.point(π, 0);
  2530. listener.point(π, -φ);
  2531. listener.point(0, -φ);
  2532. listener.point(-π, -φ);
  2533. listener.point(-π, 0);
  2534. listener.point(-π, φ);
  2535. } else if (Math.abs(from[0] - to[0]) > ε) {
  2536. var s = (from[0] < to[0] ? 1 : -1) * π;
  2537. φ = direction * s / 2;
  2538. listener.point(-s, φ);
  2539. listener.point(0, φ);
  2540. listener.point(s, φ);
  2541. } else {
  2542. listener.point(to[0], to[1]);
  2543. }
  2544. }
  2545. function d3_geo_clipCircle(radius) {
  2546. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = Math.abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  2547. return d3_geo_clip(visible, clipLine, interpolate);
  2548. function visible(λ, φ) {
  2549. return Math.cos(λ) * Math.cos(φ) > cr;
  2550. }
  2551. function clipLine(listener) {
  2552. var point0, c0, v0, v00, clean;
  2553. return {
  2554. lineStart: function() {
  2555. v00 = v0 = false;
  2556. clean = 1;
  2557. },
  2558. point: function(λ, φ) {
  2559. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  2560. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  2561. if (v !== v0) {
  2562. point2 = intersect(point0, point1);
  2563. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  2564. point1[0] += ε;
  2565. point1[1] += ε;
  2566. v = visible(point1[0], point1[1]);
  2567. }
  2568. }
  2569. if (v !== v0) {
  2570. clean = 0;
  2571. if (v) {
  2572. listener.lineStart();
  2573. point2 = intersect(point1, point0);
  2574. listener.point(point2[0], point2[1]);
  2575. } else {
  2576. point2 = intersect(point0, point1);
  2577. listener.point(point2[0], point2[1]);
  2578. listener.lineEnd();
  2579. }
  2580. point0 = point2;
  2581. } else if (notHemisphere && point0 && smallRadius ^ v) {
  2582. var t;
  2583. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  2584. clean = 0;
  2585. if (smallRadius) {
  2586. listener.lineStart();
  2587. listener.point(t[0][0], t[0][1]);
  2588. listener.point(t[1][0], t[1][1]);
  2589. listener.lineEnd();
  2590. } else {
  2591. listener.point(t[1][0], t[1][1]);
  2592. listener.lineEnd();
  2593. listener.lineStart();
  2594. listener.point(t[0][0], t[0][1]);
  2595. }
  2596. }
  2597. }
  2598. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  2599. listener.point(point1[0], point1[1]);
  2600. }
  2601. point0 = point1, v0 = v, c0 = c;
  2602. },
  2603. lineEnd: function() {
  2604. if (v0) listener.lineEnd();
  2605. point0 = null;
  2606. },
  2607. clean: function() {
  2608. return clean | (v00 && v0) << 1;
  2609. }
  2610. };
  2611. }
  2612. function intersect(a, b, two) {
  2613. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  2614. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  2615. if (!determinant) return !two && a;
  2616. 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);
  2617. d3_geo_cartesianAdd(A, B);
  2618. 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);
  2619. if (t2 < 0) return;
  2620. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  2621. d3_geo_cartesianAdd(q, A);
  2622. q = d3_geo_spherical(q);
  2623. if (!two) return q;
  2624. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  2625. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  2626. var δλ = λ1 - λ0, polar = Math.abs(δλ - π) < ε, meridian = polar || δλ < ε;
  2627. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  2628. if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (Math.abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
  2629. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  2630. d3_geo_cartesianAdd(q1, A);
  2631. return [ q, d3_geo_spherical(q1) ];
  2632. }
  2633. }
  2634. function code(λ, φ) {
  2635. var r = smallRadius ? radius : π - radius, code = 0;
  2636. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  2637. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  2638. return code;
  2639. }
  2640. }
  2641. var d3_geo_clipViewMAX = 1e9;
  2642. function d3_geo_clipView(x0, y0, x1, y1) {
  2643. return function(listener) {
  2644. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), segments, polygon, ring;
  2645. var clip = {
  2646. point: point,
  2647. lineStart: lineStart,
  2648. lineEnd: lineEnd,
  2649. polygonStart: function() {
  2650. listener = bufferListener;
  2651. segments = [];
  2652. polygon = [];
  2653. },
  2654. polygonEnd: function() {
  2655. listener = listener_;
  2656. if ((segments = d3.merge(segments)).length) {
  2657. listener.polygonStart();
  2658. d3_geo_clipPolygon(segments, compare, inside, interpolate, listener);
  2659. listener.polygonEnd();
  2660. } else if (insidePolygon([ x0, y0 ])) {
  2661. listener.polygonStart(), listener.lineStart();
  2662. interpolate(null, null, 1, listener);
  2663. listener.lineEnd(), listener.polygonEnd();
  2664. }
  2665. segments = polygon = ring = null;
  2666. }
  2667. };
  2668. function inside(point) {
  2669. var a = corner(point, -1), i = insidePolygon([ a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0 ]);
  2670. return i;
  2671. }
  2672. function insidePolygon(p) {
  2673. var wn = 0, n = polygon.length, y = p[1];
  2674. for (var i = 0; i < n; ++i) {
  2675. for (var j = 1, v = polygon[i], m = v.length, a = v[0]; j < m; ++j) {
  2676. b = v[j];
  2677. if (a[1] <= y) {
  2678. if (b[1] > y && isLeft(a, b, p) > 0) ++wn;
  2679. } else {
  2680. if (b[1] <= y && isLeft(a, b, p) < 0) --wn;
  2681. }
  2682. a = b;
  2683. }
  2684. }
  2685. return wn !== 0;
  2686. }
  2687. function isLeft(a, b, c) {
  2688. return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]);
  2689. }
  2690. function interpolate(from, to, direction, listener) {
  2691. var a = 0, a1 = 0;
  2692. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  2693. do {
  2694. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  2695. } while ((a = (a + direction + 4) % 4) !== a1);
  2696. } else {
  2697. listener.point(to[0], to[1]);
  2698. }
  2699. }
  2700. function visible(x, y) {
  2701. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  2702. }
  2703. function point(x, y) {
  2704. if (visible(x, y)) listener.point(x, y);
  2705. }
  2706. var x__, y__, v__, x_, y_, v_, first;
  2707. function lineStart() {
  2708. clip.point = linePoint;
  2709. if (polygon) polygon.push(ring = []);
  2710. first = true;
  2711. v_ = false;
  2712. x_ = y_ = NaN;
  2713. }
  2714. function lineEnd() {
  2715. if (segments) {
  2716. linePoint(x__, y__);
  2717. if (v__ && v_) bufferListener.rejoin();
  2718. segments.push(bufferListener.buffer());
  2719. }
  2720. clip.point = point;
  2721. if (v_) listener.lineEnd();
  2722. }
  2723. function linePoint(x, y) {
  2724. x = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, x));
  2725. y = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, y));
  2726. var v = visible(x, y);
  2727. if (polygon) ring.push([ x, y ]);
  2728. if (first) {
  2729. x__ = x, y__ = y, v__ = v;
  2730. first = false;
  2731. if (v) {
  2732. listener.lineStart();
  2733. listener.point(x, y);
  2734. }
  2735. } else {
  2736. if (v && v_) listener.point(x, y); else {
  2737. var a = [ x_, y_ ], b = [ x, y ];
  2738. if (clipLine(a, b)) {
  2739. if (!v_) {
  2740. listener.lineStart();
  2741. listener.point(a[0], a[1]);
  2742. }
  2743. listener.point(b[0], b[1]);
  2744. if (!v) listener.lineEnd();
  2745. } else {
  2746. listener.lineStart();
  2747. listener.point(x, y);
  2748. }
  2749. }
  2750. }
  2751. x_ = x, y_ = y, v_ = v;
  2752. }
  2753. return clip;
  2754. };
  2755. function corner(p, direction) {
  2756. return Math.abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : Math.abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : Math.abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
  2757. }
  2758. function compare(a, b) {
  2759. return comparePoints(a.point, b.point);
  2760. }
  2761. function comparePoints(a, b) {
  2762. var ca = corner(a, 1), cb = corner(b, 1);
  2763. 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];
  2764. }
  2765. function clipLine(a, b) {
  2766. var dx = b[0] - a[0], dy = b[1] - a[1], t = [ 0, 1 ];
  2767. if (Math.abs(dx) < ε && Math.abs(dy) < ε) return x0 <= a[0] && a[0] <= x1 && y0 <= a[1] && a[1] <= y1;
  2768. if (d3_geo_clipViewT(x0 - a[0], dx, t) && d3_geo_clipViewT(a[0] - x1, -dx, t) && d3_geo_clipViewT(y0 - a[1], dy, t) && d3_geo_clipViewT(a[1] - y1, -dy, t)) {
  2769. if (t[1] < 1) {
  2770. b[0] = a[0] + t[1] * dx;
  2771. b[1] = a[1] + t[1] * dy;
  2772. }
  2773. if (t[0] > 0) {
  2774. a[0] += t[0] * dx;
  2775. a[1] += t[0] * dy;
  2776. }
  2777. return true;
  2778. }
  2779. return false;
  2780. }
  2781. }
  2782. function d3_geo_clipViewT(num, denominator, t) {
  2783. if (Math.abs(denominator) < ε) return num <= 0;
  2784. var u = num / denominator;
  2785. if (denominator > 0) {
  2786. if (u > t[1]) return false;
  2787. if (u > t[0]) t[0] = u;
  2788. } else {
  2789. if (u < t[0]) return false;
  2790. if (u < t[1]) t[1] = u;
  2791. }
  2792. return true;
  2793. }
  2794. function d3_geo_compose(a, b) {
  2795. function compose(x, y) {
  2796. return x = a(x, y), b(x[0], x[1]);
  2797. }
  2798. if (a.invert && b.invert) compose.invert = function(x, y) {
  2799. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  2800. };
  2801. return compose;
  2802. }
  2803. function d3_geo_resample(project) {
  2804. var δ2 = .5, maxDepth = 16;
  2805. function resample(stream) {
  2806. var λ0, x0, y0, a0, b0, c0;
  2807. var resample = {
  2808. point: point,
  2809. lineStart: lineStart,
  2810. lineEnd: lineEnd,
  2811. polygonStart: function() {
  2812. stream.polygonStart();
  2813. resample.lineStart = polygonLineStart;
  2814. },
  2815. polygonEnd: function() {
  2816. stream.polygonEnd();
  2817. resample.lineStart = lineStart;
  2818. }
  2819. };
  2820. function point(x, y) {
  2821. x = project(x, y);
  2822. stream.point(x[0], x[1]);
  2823. }
  2824. function lineStart() {
  2825. x0 = NaN;
  2826. resample.point = linePoint;
  2827. stream.lineStart();
  2828. }
  2829. function linePoint(λ, φ) {
  2830. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  2831. 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);
  2832. stream.point(x0, y0);
  2833. }
  2834. function lineEnd() {
  2835. resample.point = point;
  2836. stream.lineEnd();
  2837. }
  2838. function polygonLineStart() {
  2839. var λ00, φ00, x00, y00, a00, b00, c00;
  2840. lineStart();
  2841. resample.point = function(λ, φ) {
  2842. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  2843. resample.point = linePoint;
  2844. };
  2845. resample.lineEnd = function() {
  2846. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  2847. resample.lineEnd = lineEnd;
  2848. lineEnd();
  2849. };
  2850. }
  2851. return resample;
  2852. }
  2853. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  2854. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  2855. if (d2 > 4 * δ2 && depth--) {
  2856. 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 = Math.abs(Math.abs(c) - 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;
  2857. if (dz * dz / d2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / d2 - .5) > .3) {
  2858. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  2859. stream.point(x2, y2);
  2860. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  2861. }
  2862. }
  2863. }
  2864. resample.precision = function(_) {
  2865. if (!arguments.length) return Math.sqrt(δ2);
  2866. maxDepth = (δ2 = _ * _) > 0 && 16;
  2867. return resample;
  2868. };
  2869. return resample;
  2870. }
  2871. d3.geo.projection = d3_geo_projection;
  2872. d3.geo.projectionMutator = d3_geo_projectionMutator;
  2873. function d3_geo_projection(project) {
  2874. return d3_geo_projectionMutator(function() {
  2875. return project;
  2876. })();
  2877. }
  2878. function d3_geo_projectionMutator(projectAt) {
  2879. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  2880. x = project(x, y);
  2881. return [ x[0] * k + δx, δy - x[1] * k ];
  2882. }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null;
  2883. function projection(point) {
  2884. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  2885. return [ point[0] * k + δx, δy - point[1] * k ];
  2886. }
  2887. function invert(point) {
  2888. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  2889. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  2890. }
  2891. projection.stream = function(stream) {
  2892. return d3_geo_projectionRadiansRotate(rotate, preclip(projectResample(postclip(stream))));
  2893. };
  2894. projection.clipAngle = function(_) {
  2895. if (!arguments.length) return clipAngle;
  2896. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  2897. return projection;
  2898. };
  2899. projection.clipExtent = function(_) {
  2900. if (!arguments.length) return clipExtent;
  2901. clipExtent = _;
  2902. postclip = _ == null ? d3_identity : d3_geo_clipView(_[0][0], _[0][1], _[1][0], _[1][1]);
  2903. return projection;
  2904. };
  2905. projection.scale = function(_) {
  2906. if (!arguments.length) return k;
  2907. k = +_;
  2908. return reset();
  2909. };
  2910. projection.translate = function(_) {
  2911. if (!arguments.length) return [ x, y ];
  2912. x = +_[0];
  2913. y = +_[1];
  2914. return reset();
  2915. };
  2916. projection.center = function(_) {
  2917. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  2918. λ = _[0] % 360 * d3_radians;
  2919. φ = _[1] % 360 * d3_radians;
  2920. return reset();
  2921. };
  2922. projection.rotate = function(_) {
  2923. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  2924. δλ = _[0] % 360 * d3_radians;
  2925. δφ = _[1] % 360 * d3_radians;
  2926. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  2927. return reset();
  2928. };
  2929. d3.rebind(projection, projectResample, "precision");
  2930. function reset() {
  2931. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  2932. var center = project(λ, φ);
  2933. δx = x - center[0] * k;
  2934. δy = y + center[1] * k;
  2935. return projection;
  2936. }
  2937. return function() {
  2938. project = projectAt.apply(this, arguments);
  2939. projection.invert = project.invert && invert;
  2940. return reset();
  2941. };
  2942. }
  2943. function d3_geo_projectionRadiansRotate(rotate, stream) {
  2944. return {
  2945. point: function(x, y) {
  2946. y = rotate(x * d3_radians, y * d3_radians), x = y[0];
  2947. stream.point(x > π ? x - 2 * π : x < -π ? x + 2 * π : x, y[1]);
  2948. },
  2949. sphere: function() {
  2950. stream.sphere();
  2951. },
  2952. lineStart: function() {
  2953. stream.lineStart();
  2954. },
  2955. lineEnd: function() {
  2956. stream.lineEnd();
  2957. },
  2958. polygonStart: function() {
  2959. stream.polygonStart();
  2960. },
  2961. polygonEnd: function() {
  2962. stream.polygonEnd();
  2963. }
  2964. };
  2965. }
  2966. function d3_geo_equirectangular(λ, φ) {
  2967. return [ λ, φ ];
  2968. }
  2969. (d3.geo.equirectangular = function() {
  2970. return d3_geo_projection(d3_geo_equirectangular);
  2971. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  2972. d3.geo.rotation = function(rotate) {
  2973. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  2974. function forward(coordinates) {
  2975. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  2976. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  2977. }
  2978. forward.invert = function(coordinates) {
  2979. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  2980. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  2981. };
  2982. return forward;
  2983. };
  2984. function d3_geo_rotation(δλ, δφ, δγ) {
  2985. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_equirectangular;
  2986. }
  2987. function d3_geo_forwardRotationλ(δλ) {
  2988. return function(λ, φ) {
  2989. return λ += δλ, [ λ > π ? λ - 2 * π : λ < -π ? λ + 2 * π : λ, φ ];
  2990. };
  2991. }
  2992. function d3_geo_rotationλ(δλ) {
  2993. var rotation = d3_geo_forwardRotationλ(δλ);
  2994. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  2995. return rotation;
  2996. }
  2997. function d3_geo_rotationφγ(δφ, δγ) {
  2998. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  2999. function rotation(λ, φ) {
  3000. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  3001. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), Math.asin(Math.max(-1, Math.min(1, k * cosδγ + y * sinδγ))) ];
  3002. }
  3003. rotation.invert = function(λ, φ) {
  3004. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  3005. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), Math.asin(Math.max(-1, Math.min(1, k * cosδφ - x * sinδφ))) ];
  3006. };
  3007. return rotation;
  3008. }
  3009. d3.geo.circle = function() {
  3010. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  3011. function circle() {
  3012. 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 = [];
  3013. interpolate(null, null, 1, {
  3014. point: function(x, y) {
  3015. ring.push(x = rotate(x, y));
  3016. x[0] *= d3_degrees, x[1] *= d3_degrees;
  3017. }
  3018. });
  3019. return {
  3020. type: "Polygon",
  3021. coordinates: [ ring ]
  3022. };
  3023. }
  3024. circle.origin = function(x) {
  3025. if (!arguments.length) return origin;
  3026. origin = x;
  3027. return circle;
  3028. };
  3029. circle.angle = function(x) {
  3030. if (!arguments.length) return angle;
  3031. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  3032. return circle;
  3033. };
  3034. circle.precision = function(_) {
  3035. if (!arguments.length) return precision;
  3036. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  3037. return circle;
  3038. };
  3039. return circle.angle(90);
  3040. };
  3041. function d3_geo_circleInterpolate(radius, precision) {
  3042. var cr = Math.cos(radius), sr = Math.sin(radius);
  3043. return function(from, to, direction, listener) {
  3044. if (from != null) {
  3045. from = d3_geo_circleAngle(cr, from);
  3046. to = d3_geo_circleAngle(cr, to);
  3047. if (direction > 0 ? from < to : from > to) from += direction * 2 * π;
  3048. } else {
  3049. from = radius + direction * 2 * π;
  3050. to = radius;
  3051. }
  3052. var point;
  3053. for (var step = direction * precision, t = from; direction > 0 ? t > to : t < to; t -= step) {
  3054. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  3055. }
  3056. };
  3057. }
  3058. function d3_geo_circleAngle(cr, point) {
  3059. var a = d3_geo_cartesian(point);
  3060. a[0] -= cr;
  3061. d3_geo_cartesianNormalize(a);
  3062. var angle = d3_acos(-a[1]);
  3063. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  3064. }
  3065. d3.geo.distance = function(a, b) {
  3066. 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;
  3067. 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Δλ);
  3068. };
  3069. d3.geo.graticule = function() {
  3070. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  3071. function graticule() {
  3072. return {
  3073. type: "MultiLineString",
  3074. coordinates: lines()
  3075. };
  3076. }
  3077. function lines() {
  3078. 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) {
  3079. return Math.abs(x % DX) > ε;
  3080. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  3081. return Math.abs(y % DY) > ε;
  3082. }).map(y));
  3083. }
  3084. graticule.lines = function() {
  3085. return lines().map(function(coordinates) {
  3086. return {
  3087. type: "LineString",
  3088. coordinates: coordinates
  3089. };
  3090. });
  3091. };
  3092. graticule.outline = function() {
  3093. return {
  3094. type: "Polygon",
  3095. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  3096. };
  3097. };
  3098. graticule.extent = function(_) {
  3099. if (!arguments.length) return graticule.minorExtent();
  3100. return graticule.majorExtent(_).minorExtent(_);
  3101. };
  3102. graticule.majorExtent = function(_) {
  3103. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  3104. X0 = +_[0][0], X1 = +_[1][0];
  3105. Y0 = +_[0][1], Y1 = +_[1][1];
  3106. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  3107. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  3108. return graticule.precision(precision);
  3109. };
  3110. graticule.minorExtent = function(_) {
  3111. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3112. x0 = +_[0][0], x1 = +_[1][0];
  3113. y0 = +_[0][1], y1 = +_[1][1];
  3114. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  3115. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  3116. return graticule.precision(precision);
  3117. };
  3118. graticule.step = function(_) {
  3119. if (!arguments.length) return graticule.minorStep();
  3120. return graticule.majorStep(_).minorStep(_);
  3121. };
  3122. graticule.majorStep = function(_) {
  3123. if (!arguments.length) return [ DX, DY ];
  3124. DX = +_[0], DY = +_[1];
  3125. return graticule;
  3126. };
  3127. graticule.minorStep = function(_) {
  3128. if (!arguments.length) return [ dx, dy ];
  3129. dx = +_[0], dy = +_[1];
  3130. return graticule;
  3131. };
  3132. graticule.precision = function(_) {
  3133. if (!arguments.length) return precision;
  3134. precision = +_;
  3135. x = d3_geo_graticuleX(y0, y1, 90);
  3136. y = d3_geo_graticuleY(x0, x1, precision);
  3137. X = d3_geo_graticuleX(Y0, Y1, 90);
  3138. Y = d3_geo_graticuleY(X0, X1, precision);
  3139. return graticule;
  3140. };
  3141. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  3142. };
  3143. function d3_geo_graticuleX(y0, y1, dy) {
  3144. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  3145. return function(x) {
  3146. return y.map(function(y) {
  3147. return [ x, y ];
  3148. });
  3149. };
  3150. }
  3151. function d3_geo_graticuleY(x0, x1, dx) {
  3152. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  3153. return function(y) {
  3154. return x.map(function(x) {
  3155. return [ x, y ];
  3156. });
  3157. };
  3158. }
  3159. function d3_source(d) {
  3160. return d.source;
  3161. }
  3162. function d3_target(d) {
  3163. return d.target;
  3164. }
  3165. d3.geo.greatArc = function() {
  3166. var source = d3_source, source_, target = d3_target, target_;
  3167. function greatArc() {
  3168. return {
  3169. type: "LineString",
  3170. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  3171. };
  3172. }
  3173. greatArc.distance = function() {
  3174. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  3175. };
  3176. greatArc.source = function(_) {
  3177. if (!arguments.length) return source;
  3178. source = _, source_ = typeof _ === "function" ? null : _;
  3179. return greatArc;
  3180. };
  3181. greatArc.target = function(_) {
  3182. if (!arguments.length) return target;
  3183. target = _, target_ = typeof _ === "function" ? null : _;
  3184. return greatArc;
  3185. };
  3186. greatArc.precision = function() {
  3187. return arguments.length ? greatArc : 0;
  3188. };
  3189. return greatArc;
  3190. };
  3191. d3.geo.interpolate = function(source, target) {
  3192. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  3193. };
  3194. function d3_geo_interpolate(x0, y0, x1, y1) {
  3195. 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);
  3196. var interpolate = d ? function(t) {
  3197. 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;
  3198. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  3199. } : function() {
  3200. return [ x0 * d3_degrees, y0 * d3_degrees ];
  3201. };
  3202. interpolate.distance = d;
  3203. return interpolate;
  3204. }
  3205. d3.geo.length = function(object) {
  3206. d3_geo_lengthSum = 0;
  3207. d3.geo.stream(object, d3_geo_length);
  3208. return d3_geo_lengthSum;
  3209. };
  3210. var d3_geo_lengthSum;
  3211. var d3_geo_length = {
  3212. sphere: d3_noop,
  3213. point: d3_noop,
  3214. lineStart: d3_geo_lengthLineStart,
  3215. lineEnd: d3_noop,
  3216. polygonStart: d3_noop,
  3217. polygonEnd: d3_noop
  3218. };
  3219. function d3_geo_lengthLineStart() {
  3220. var λ0, sinφ0, cosφ0;
  3221. d3_geo_length.point = function(λ, φ) {
  3222. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  3223. d3_geo_length.point = nextPoint;
  3224. };
  3225. d3_geo_length.lineEnd = function() {
  3226. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  3227. };
  3228. function nextPoint(λ, φ) {
  3229. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = Math.abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  3230. 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Δλ);
  3231. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  3232. }
  3233. }
  3234. function d3_geo_conic(projectAt) {
  3235. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  3236. p.parallels = function(_) {
  3237. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  3238. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  3239. };
  3240. return p;
  3241. }
  3242. function d3_geo_conicEqualArea(φ0, φ1) {
  3243. 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;
  3244. function forward(λ, φ) {
  3245. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  3246. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  3247. }
  3248. forward.invert = function(x, y) {
  3249. var ρ0_y = ρ0 - y;
  3250. return [ Math.atan2(x, ρ0_y) / n, Math.asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  3251. };
  3252. return forward;
  3253. }
  3254. (d3.geo.conicEqualArea = function() {
  3255. return d3_geo_conic(d3_geo_conicEqualArea);
  3256. }).raw = d3_geo_conicEqualArea;
  3257. d3.geo.albersUsa = function() {
  3258. var lower48 = d3.geo.conicEqualArea().rotate([ 98, 0 ]).center([ 0, 38 ]).parallels([ 29.5, 45.5 ]);
  3259. var alaska = d3.geo.conicEqualArea().rotate([ 160, 0 ]).center([ 0, 60 ]).parallels([ 55, 65 ]);
  3260. var hawaii = d3.geo.conicEqualArea().rotate([ 160, 0 ]).center([ 0, 20 ]).parallels([ 8, 18 ]);
  3261. var puertoRico = d3.geo.conicEqualArea().rotate([ 60, 0 ]).center([ 0, 10 ]).parallels([ 8, 18 ]);
  3262. var alaskaInvert, hawaiiInvert, puertoRicoInvert;
  3263. function albersUsa(coordinates) {
  3264. return projection(coordinates)(coordinates);
  3265. }
  3266. function projection(point) {
  3267. var lon = point[0], lat = point[1];
  3268. return lat > 50 ? alaska : lon < -140 ? hawaii : lat < 21 ? puertoRico : lower48;
  3269. }
  3270. albersUsa.invert = function(coordinates) {
  3271. return alaskaInvert(coordinates) || hawaiiInvert(coordinates) || puertoRicoInvert(coordinates) || lower48.invert(coordinates);
  3272. };
  3273. albersUsa.scale = function(x) {
  3274. if (!arguments.length) return lower48.scale();
  3275. lower48.scale(x);
  3276. alaska.scale(x * .6);
  3277. hawaii.scale(x);
  3278. puertoRico.scale(x * 1.5);
  3279. return albersUsa.translate(lower48.translate());
  3280. };
  3281. albersUsa.translate = function(x) {
  3282. if (!arguments.length) return lower48.translate();
  3283. var dz = lower48.scale(), dx = x[0], dy = x[1];
  3284. lower48.translate(x);
  3285. alaska.translate([ dx - .4 * dz, dy + .17 * dz ]);
  3286. hawaii.translate([ dx - .19 * dz, dy + .2 * dz ]);
  3287. puertoRico.translate([ dx + .58 * dz, dy + .43 * dz ]);
  3288. alaskaInvert = d3_geo_albersUsaInvert(alaska, [ [ -180, 50 ], [ -130, 72 ] ]);
  3289. hawaiiInvert = d3_geo_albersUsaInvert(hawaii, [ [ -164, 18 ], [ -154, 24 ] ]);
  3290. puertoRicoInvert = d3_geo_albersUsaInvert(puertoRico, [ [ -67.5, 17.5 ], [ -65, 19 ] ]);
  3291. return albersUsa;
  3292. };
  3293. return albersUsa.scale(1e3);
  3294. };
  3295. function d3_geo_albersUsaInvert(projection, extent) {
  3296. var a = projection(extent[0]), b = projection([ .5 * (extent[0][0] + extent[1][0]), extent[0][1] ]), c = projection([ extent[1][0], extent[0][1] ]), d = projection(extent[1]);
  3297. var dya = b[1] - a[1], dxa = b[0] - a[0], dyb = c[1] - b[1], dxb = c[0] - b[0];
  3298. var ma = dya / dxa, mb = dyb / dxb;
  3299. var cx = .5 * (ma * mb * (a[1] - c[1]) + mb * (a[0] + b[0]) - ma * (b[0] + c[0])) / (mb - ma), cy = (.5 * (a[0] + b[0]) - cx) / ma + .5 * (a[1] + b[1]);
  3300. var dx0 = d[0] - cx, dy0 = d[1] - cy, dx1 = a[0] - cx, dy1 = a[1] - cy, r0 = dx0 * dx0 + dy0 * dy0, r1 = dx1 * dx1 + dy1 * dy1;
  3301. var a0 = Math.atan2(dy0, dx0), a1 = Math.atan2(dy1, dx1);
  3302. return function(coordinates) {
  3303. var dx = coordinates[0] - cx, dy = coordinates[1] - cy, r = dx * dx + dy * dy, a = Math.atan2(dy, dx);
  3304. if (r0 < r && r < r1 && a0 < a && a < a1) return projection.invert(coordinates);
  3305. };
  3306. }
  3307. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  3308. point: d3_noop,
  3309. lineStart: d3_noop,
  3310. lineEnd: d3_noop,
  3311. polygonStart: function() {
  3312. d3_geo_pathAreaPolygon = 0;
  3313. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  3314. },
  3315. polygonEnd: function() {
  3316. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  3317. d3_geo_pathAreaSum += Math.abs(d3_geo_pathAreaPolygon / 2);
  3318. }
  3319. };
  3320. function d3_geo_pathAreaRingStart() {
  3321. var x00, y00, x0, y0;
  3322. d3_geo_pathArea.point = function(x, y) {
  3323. d3_geo_pathArea.point = nextPoint;
  3324. x00 = x0 = x, y00 = y0 = y;
  3325. };
  3326. function nextPoint(x, y) {
  3327. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  3328. x0 = x, y0 = y;
  3329. }
  3330. d3_geo_pathArea.lineEnd = function() {
  3331. nextPoint(x00, y00);
  3332. };
  3333. }
  3334. function d3_geo_pathBuffer() {
  3335. var pointCircle = d3_geo_pathCircle(4.5), buffer = [];
  3336. var stream = {
  3337. point: point,
  3338. lineStart: function() {
  3339. stream.point = pointLineStart;
  3340. },
  3341. lineEnd: lineEnd,
  3342. polygonStart: function() {
  3343. stream.lineEnd = lineEndPolygon;
  3344. },
  3345. polygonEnd: function() {
  3346. stream.lineEnd = lineEnd;
  3347. stream.point = point;
  3348. },
  3349. pointRadius: function(_) {
  3350. pointCircle = d3_geo_pathCircle(_);
  3351. return stream;
  3352. },
  3353. result: function() {
  3354. if (buffer.length) {
  3355. var result = buffer.join("");
  3356. buffer = [];
  3357. return result;
  3358. }
  3359. }
  3360. };
  3361. function point(x, y) {
  3362. buffer.push("M", x, ",", y, pointCircle);
  3363. }
  3364. function pointLineStart(x, y) {
  3365. buffer.push("M", x, ",", y);
  3366. stream.point = pointLine;
  3367. }
  3368. function pointLine(x, y) {
  3369. buffer.push("L", x, ",", y);
  3370. }
  3371. function lineEnd() {
  3372. stream.point = point;
  3373. }
  3374. function lineEndPolygon() {
  3375. buffer.push("Z");
  3376. }
  3377. return stream;
  3378. }
  3379. var d3_geo_pathCentroid = {
  3380. point: d3_geo_pathCentroidPoint,
  3381. lineStart: d3_geo_pathCentroidLineStart,
  3382. lineEnd: d3_geo_pathCentroidLineEnd,
  3383. polygonStart: function() {
  3384. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  3385. },
  3386. polygonEnd: function() {
  3387. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  3388. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  3389. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  3390. }
  3391. };
  3392. function d3_geo_pathCentroidPoint(x, y) {
  3393. if (d3_geo_centroidDimension) return;
  3394. d3_geo_centroidX += x;
  3395. d3_geo_centroidY += y;
  3396. ++d3_geo_centroidZ;
  3397. }
  3398. function d3_geo_pathCentroidLineStart() {
  3399. var x0, y0;
  3400. if (d3_geo_centroidDimension !== 1) {
  3401. if (d3_geo_centroidDimension < 1) {
  3402. d3_geo_centroidDimension = 1;
  3403. d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
  3404. } else return;
  3405. }
  3406. d3_geo_pathCentroid.point = function(x, y) {
  3407. d3_geo_pathCentroid.point = nextPoint;
  3408. x0 = x, y0 = y;
  3409. };
  3410. function nextPoint(x, y) {
  3411. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  3412. d3_geo_centroidX += z * (x0 + x) / 2;
  3413. d3_geo_centroidY += z * (y0 + y) / 2;
  3414. d3_geo_centroidZ += z;
  3415. x0 = x, y0 = y;
  3416. }
  3417. }
  3418. function d3_geo_pathCentroidLineEnd() {
  3419. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  3420. }
  3421. function d3_geo_pathCentroidRingStart() {
  3422. var x00, y00, x0, y0;
  3423. if (d3_geo_centroidDimension < 2) {
  3424. d3_geo_centroidDimension = 2;
  3425. d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
  3426. }
  3427. d3_geo_pathCentroid.point = function(x, y) {
  3428. d3_geo_pathCentroid.point = nextPoint;
  3429. x00 = x0 = x, y00 = y0 = y;
  3430. };
  3431. function nextPoint(x, y) {
  3432. var z = y0 * x - x0 * y;
  3433. d3_geo_centroidX += z * (x0 + x);
  3434. d3_geo_centroidY += z * (y0 + y);
  3435. d3_geo_centroidZ += z * 3;
  3436. x0 = x, y0 = y;
  3437. }
  3438. d3_geo_pathCentroid.lineEnd = function() {
  3439. nextPoint(x00, y00);
  3440. };
  3441. }
  3442. function d3_geo_pathContext(context) {
  3443. var pointRadius = 4.5;
  3444. var stream = {
  3445. point: point,
  3446. lineStart: function() {
  3447. stream.point = pointLineStart;
  3448. },
  3449. lineEnd: lineEnd,
  3450. polygonStart: function() {
  3451. stream.lineEnd = lineEndPolygon;
  3452. },
  3453. polygonEnd: function() {
  3454. stream.lineEnd = lineEnd;
  3455. stream.point = point;
  3456. },
  3457. pointRadius: function(_) {
  3458. pointRadius = _;
  3459. return stream;
  3460. },
  3461. result: d3_noop
  3462. };
  3463. function point(x, y) {
  3464. context.moveTo(x, y);
  3465. context.arc(x, y, pointRadius, 0, 2 * π);
  3466. }
  3467. function pointLineStart(x, y) {
  3468. context.moveTo(x, y);
  3469. stream.point = pointLine;
  3470. }
  3471. function pointLine(x, y) {
  3472. context.lineTo(x, y);
  3473. }
  3474. function lineEnd() {
  3475. stream.point = point;
  3476. }
  3477. function lineEndPolygon() {
  3478. context.closePath();
  3479. }
  3480. return stream;
  3481. }
  3482. d3.geo.path = function() {
  3483. var pointRadius = 4.5, projection, context, projectStream, contextStream;
  3484. function path(object) {
  3485. if (object) d3.geo.stream(object, projectStream(contextStream.pointRadius(typeof pointRadius === "function" ? +pointRadius.apply(this, arguments) : pointRadius)));
  3486. return contextStream.result();
  3487. }
  3488. path.area = function(object) {
  3489. d3_geo_pathAreaSum = 0;
  3490. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  3491. return d3_geo_pathAreaSum;
  3492. };
  3493. path.centroid = function(object) {
  3494. d3_geo_centroidDimension = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
  3495. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  3496. return d3_geo_centroidZ ? [ d3_geo_centroidX / d3_geo_centroidZ, d3_geo_centroidY / d3_geo_centroidZ ] : undefined;
  3497. };
  3498. path.bounds = function(object) {
  3499. return d3_geo_bounds(projectStream)(object);
  3500. };
  3501. path.projection = function(_) {
  3502. if (!arguments.length) return projection;
  3503. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  3504. return path;
  3505. };
  3506. path.context = function(_) {
  3507. if (!arguments.length) return context;
  3508. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  3509. return path;
  3510. };
  3511. path.pointRadius = function(_) {
  3512. if (!arguments.length) return pointRadius;
  3513. pointRadius = typeof _ === "function" ? _ : +_;
  3514. return path;
  3515. };
  3516. return path.projection(d3.geo.albersUsa()).context(null);
  3517. };
  3518. function d3_geo_pathCircle(radius) {
  3519. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
  3520. }
  3521. function d3_geo_pathProjectStream(project) {
  3522. var resample = d3_geo_resample(function(λ, φ) {
  3523. return project([ λ * d3_degrees, φ * d3_degrees ]);
  3524. });
  3525. return function(stream) {
  3526. stream = resample(stream);
  3527. return {
  3528. point: function(λ, φ) {
  3529. stream.point(λ * d3_radians, φ * d3_radians);
  3530. },
  3531. sphere: function() {
  3532. stream.sphere();
  3533. },
  3534. lineStart: function() {
  3535. stream.lineStart();
  3536. },
  3537. lineEnd: function() {
  3538. stream.lineEnd();
  3539. },
  3540. polygonStart: function() {
  3541. stream.polygonStart();
  3542. },
  3543. polygonEnd: function() {
  3544. stream.polygonEnd();
  3545. }
  3546. };
  3547. };
  3548. }
  3549. d3.geo.albers = function() {
  3550. return d3.geo.conicEqualArea().parallels([ 29.5, 45.5 ]).rotate([ 98, 0 ]).center([ 0, 38 ]).scale(1e3);
  3551. };
  3552. function d3_geo_azimuthal(scale, angle) {
  3553. function azimuthal(λ, φ) {
  3554. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  3555. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  3556. }
  3557. azimuthal.invert = function(x, y) {
  3558. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  3559. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  3560. };
  3561. return azimuthal;
  3562. }
  3563. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  3564. return Math.sqrt(2 / (1 + cosλcosφ));
  3565. }, function(ρ) {
  3566. return 2 * Math.asin(ρ / 2);
  3567. });
  3568. (d3.geo.azimuthalEqualArea = function() {
  3569. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  3570. }).raw = d3_geo_azimuthalEqualArea;
  3571. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  3572. var c = Math.acos(cosλcosφ);
  3573. return c && c / Math.sin(c);
  3574. }, d3_identity);
  3575. (d3.geo.azimuthalEquidistant = function() {
  3576. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  3577. }).raw = d3_geo_azimuthalEquidistant;
  3578. function d3_geo_conicConformal(φ0, φ1) {
  3579. var cosφ0 = Math.cos(φ0), t = function(φ) {
  3580. return Math.tan(π / 4 + φ / 2);
  3581. }, 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;
  3582. if (!n) return d3_geo_mercator;
  3583. function forward(λ, φ) {
  3584. var ρ = Math.abs(Math.abs(φ) - π / 2) < ε ? 0 : F / Math.pow(t(φ), n);
  3585. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  3586. }
  3587. forward.invert = function(x, y) {
  3588. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  3589. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - π / 2 ];
  3590. };
  3591. return forward;
  3592. }
  3593. (d3.geo.conicConformal = function() {
  3594. return d3_geo_conic(d3_geo_conicConformal);
  3595. }).raw = d3_geo_conicConformal;
  3596. function d3_geo_conicEquidistant(φ0, φ1) {
  3597. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  3598. if (Math.abs(n) < ε) return d3_geo_equirectangular;
  3599. function forward(λ, φ) {
  3600. var ρ = G - φ;
  3601. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  3602. }
  3603. forward.invert = function(x, y) {
  3604. var ρ0_y = G - y;
  3605. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  3606. };
  3607. return forward;
  3608. }
  3609. (d3.geo.conicEquidistant = function() {
  3610. return d3_geo_conic(d3_geo_conicEquidistant);
  3611. }).raw = d3_geo_conicEquidistant;
  3612. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  3613. return 1 / cosλcosφ;
  3614. }, Math.atan);
  3615. (d3.geo.gnomonic = function() {
  3616. return d3_geo_projection(d3_geo_gnomonic);
  3617. }).raw = d3_geo_gnomonic;
  3618. function d3_geo_mercator(λ, φ) {
  3619. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  3620. }
  3621. d3_geo_mercator.invert = function(x, y) {
  3622. return [ x, 2 * Math.atan(Math.exp(y)) - π / 2 ];
  3623. };
  3624. function d3_geo_mercatorProjection(project) {
  3625. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  3626. m.scale = function() {
  3627. var v = scale.apply(m, arguments);
  3628. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  3629. };
  3630. m.translate = function() {
  3631. var v = translate.apply(m, arguments);
  3632. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  3633. };
  3634. m.clipExtent = function(_) {
  3635. var v = clipExtent.apply(m, arguments);
  3636. if (v === m) {
  3637. if (clipAuto = _ == null) {
  3638. var k = π * scale(), t = translate();
  3639. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  3640. }
  3641. } else if (clipAuto) {
  3642. v = null;
  3643. }
  3644. return v;
  3645. };
  3646. return m.clipExtent(null);
  3647. }
  3648. (d3.geo.mercator = function() {
  3649. return d3_geo_mercatorProjection(d3_geo_mercator);
  3650. }).raw = d3_geo_mercator;
  3651. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  3652. return 1;
  3653. }, Math.asin);
  3654. (d3.geo.orthographic = function() {
  3655. return d3_geo_projection(d3_geo_orthographic);
  3656. }).raw = d3_geo_orthographic;
  3657. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  3658. return 1 / (1 + cosλcosφ);
  3659. }, function(ρ) {
  3660. return 2 * Math.atan(ρ);
  3661. });
  3662. (d3.geo.stereographic = function() {
  3663. return d3_geo_projection(d3_geo_stereographic);
  3664. }).raw = d3_geo_stereographic;
  3665. function d3_geo_transverseMercator(λ, φ) {
  3666. var B = Math.cos(φ) * Math.sin(λ);
  3667. return [ Math.log((1 + B) / (1 - B)) / 2, Math.atan2(Math.tan(φ), Math.cos(λ)) ];
  3668. }
  3669. d3_geo_transverseMercator.invert = function(x, y) {
  3670. return [ Math.atan2(d3_sinh(x), Math.cos(y)), d3_asin(Math.sin(y) / d3_cosh(x)) ];
  3671. };
  3672. (d3.geo.transverseMercator = function() {
  3673. return d3_geo_mercatorProjection(d3_geo_transverseMercator);
  3674. }).raw = d3_geo_transverseMercator;
  3675. d3.geom = {};
  3676. d3.svg = {};
  3677. function d3_svg_line(projection) {
  3678. var x = d3_svg_lineX, y = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  3679. function line(data) {
  3680. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  3681. function segment() {
  3682. segments.push("M", interpolate(projection(points), tension));
  3683. }
  3684. while (++i < n) {
  3685. if (defined.call(this, d = data[i], i)) {
  3686. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  3687. } else if (points.length) {
  3688. segment();
  3689. points = [];
  3690. }
  3691. }
  3692. if (points.length) segment();
  3693. return segments.length ? segments.join("") : null;
  3694. }
  3695. line.x = function(_) {
  3696. if (!arguments.length) return x;
  3697. x = _;
  3698. return line;
  3699. };
  3700. line.y = function(_) {
  3701. if (!arguments.length) return y;
  3702. y = _;
  3703. return line;
  3704. };
  3705. line.defined = function(_) {
  3706. if (!arguments.length) return defined;
  3707. defined = _;
  3708. return line;
  3709. };
  3710. line.interpolate = function(_) {
  3711. if (!arguments.length) return interpolateKey;
  3712. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  3713. return line;
  3714. };
  3715. line.tension = function(_) {
  3716. if (!arguments.length) return tension;
  3717. tension = _;
  3718. return line;
  3719. };
  3720. return line;
  3721. }
  3722. d3.svg.line = function() {
  3723. return d3_svg_line(d3_identity);
  3724. };
  3725. function d3_svg_lineX(d) {
  3726. return d[0];
  3727. }
  3728. function d3_svg_lineY(d) {
  3729. return d[1];
  3730. }
  3731. var d3_svg_lineInterpolators = d3.map({
  3732. linear: d3_svg_lineLinear,
  3733. "linear-closed": d3_svg_lineLinearClosed,
  3734. "step-before": d3_svg_lineStepBefore,
  3735. "step-after": d3_svg_lineStepAfter,
  3736. basis: d3_svg_lineBasis,
  3737. "basis-open": d3_svg_lineBasisOpen,
  3738. "basis-closed": d3_svg_lineBasisClosed,
  3739. bundle: d3_svg_lineBundle,
  3740. cardinal: d3_svg_lineCardinal,
  3741. "cardinal-open": d3_svg_lineCardinalOpen,
  3742. "cardinal-closed": d3_svg_lineCardinalClosed,
  3743. monotone: d3_svg_lineMonotone
  3744. });
  3745. d3_svg_lineInterpolators.forEach(function(key, value) {
  3746. value.key = key;
  3747. value.closed = /-closed$/.test(key);
  3748. });
  3749. function d3_svg_lineLinear(points) {
  3750. return points.join("L");
  3751. }
  3752. function d3_svg_lineLinearClosed(points) {
  3753. return d3_svg_lineLinear(points) + "Z";
  3754. }
  3755. function d3_svg_lineStepBefore(points) {
  3756. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  3757. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  3758. return path.join("");
  3759. }
  3760. function d3_svg_lineStepAfter(points) {
  3761. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  3762. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  3763. return path.join("");
  3764. }
  3765. function d3_svg_lineCardinalOpen(points, tension) {
  3766. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
  3767. }
  3768. function d3_svg_lineCardinalClosed(points, tension) {
  3769. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  3770. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  3771. }
  3772. function d3_svg_lineCardinal(points, tension) {
  3773. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  3774. }
  3775. function d3_svg_lineHermite(points, tangents) {
  3776. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  3777. return d3_svg_lineLinear(points);
  3778. }
  3779. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  3780. if (quad) {
  3781. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  3782. p0 = points[1];
  3783. pi = 2;
  3784. }
  3785. if (tangents.length > 1) {
  3786. t = tangents[1];
  3787. p = points[pi];
  3788. pi++;
  3789. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  3790. for (var i = 2; i < tangents.length; i++, pi++) {
  3791. p = points[pi];
  3792. t = tangents[i];
  3793. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  3794. }
  3795. }
  3796. if (quad) {
  3797. var lp = points[pi];
  3798. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  3799. }
  3800. return path;
  3801. }
  3802. function d3_svg_lineCardinalTangents(points, tension) {
  3803. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  3804. while (++i < n) {
  3805. p0 = p1;
  3806. p1 = p2;
  3807. p2 = points[i];
  3808. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  3809. }
  3810. return tangents;
  3811. }
  3812. function d3_svg_lineBasis(points) {
  3813. if (points.length < 3) return d3_svg_lineLinear(points);
  3814. 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 ];
  3815. d3_svg_lineBasisBezier(path, px, py);
  3816. while (++i < n) {
  3817. pi = points[i];
  3818. px.shift();
  3819. px.push(pi[0]);
  3820. py.shift();
  3821. py.push(pi[1]);
  3822. d3_svg_lineBasisBezier(path, px, py);
  3823. }
  3824. i = -1;
  3825. while (++i < 2) {
  3826. px.shift();
  3827. px.push(pi[0]);
  3828. py.shift();
  3829. py.push(pi[1]);
  3830. d3_svg_lineBasisBezier(path, px, py);
  3831. }
  3832. return path.join("");
  3833. }
  3834. function d3_svg_lineBasisOpen(points) {
  3835. if (points.length < 4) return d3_svg_lineLinear(points);
  3836. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  3837. while (++i < 3) {
  3838. pi = points[i];
  3839. px.push(pi[0]);
  3840. py.push(pi[1]);
  3841. }
  3842. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  3843. --i;
  3844. while (++i < n) {
  3845. pi = points[i];
  3846. px.shift();
  3847. px.push(pi[0]);
  3848. py.shift();
  3849. py.push(pi[1]);
  3850. d3_svg_lineBasisBezier(path, px, py);
  3851. }
  3852. return path.join("");
  3853. }
  3854. function d3_svg_lineBasisClosed(points) {
  3855. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  3856. while (++i < 4) {
  3857. pi = points[i % n];
  3858. px.push(pi[0]);
  3859. py.push(pi[1]);
  3860. }
  3861. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  3862. --i;
  3863. while (++i < m) {
  3864. pi = points[i % n];
  3865. px.shift();
  3866. px.push(pi[0]);
  3867. py.shift();
  3868. py.push(pi[1]);
  3869. d3_svg_lineBasisBezier(path, px, py);
  3870. }
  3871. return path.join("");
  3872. }
  3873. function d3_svg_lineBundle(points, tension) {
  3874. var n = points.length - 1;
  3875. if (n) {
  3876. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  3877. while (++i <= n) {
  3878. p = points[i];
  3879. t = i / n;
  3880. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  3881. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  3882. }
  3883. }
  3884. return d3_svg_lineBasis(points);
  3885. }
  3886. function d3_svg_lineDot4(a, b) {
  3887. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  3888. }
  3889. 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 ];
  3890. function d3_svg_lineBasisBezier(path, x, y) {
  3891. 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));
  3892. }
  3893. function d3_svg_lineSlope(p0, p1) {
  3894. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  3895. }
  3896. function d3_svg_lineFiniteDifferences(points) {
  3897. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  3898. while (++i < j) {
  3899. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  3900. }
  3901. m[i] = d;
  3902. return m;
  3903. }
  3904. function d3_svg_lineMonotoneTangents(points) {
  3905. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  3906. while (++i < j) {
  3907. d = d3_svg_lineSlope(points[i], points[i + 1]);
  3908. if (Math.abs(d) < 1e-6) {
  3909. m[i] = m[i + 1] = 0;
  3910. } else {
  3911. a = m[i] / d;
  3912. b = m[i + 1] / d;
  3913. s = a * a + b * b;
  3914. if (s > 9) {
  3915. s = d * 3 / Math.sqrt(s);
  3916. m[i] = s * a;
  3917. m[i + 1] = s * b;
  3918. }
  3919. }
  3920. }
  3921. i = -1;
  3922. while (++i <= j) {
  3923. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  3924. tangents.push([ s || 0, m[i] * s || 0 ]);
  3925. }
  3926. return tangents;
  3927. }
  3928. function d3_svg_lineMonotone(points) {
  3929. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  3930. }
  3931. d3.geom.hull = function(vertices) {
  3932. var x = d3_svg_lineX, y = d3_svg_lineY;
  3933. if (arguments.length) return hull(vertices);
  3934. function hull(data) {
  3935. if (data.length < 3) return [];
  3936. var fx = d3_functor(x), fy = d3_functor(y), n = data.length, vertices, plen = n - 1, points = [], stack = [], d, i, j, h = 0, x1, y1, x2, y2, u, v, a, sp;
  3937. if (fx === d3_svg_lineX && y === d3_svg_lineY) vertices = data; else for (i = 0,
  3938. vertices = []; i < n; ++i) {
  3939. vertices.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
  3940. }
  3941. for (i = 1; i < n; ++i) {
  3942. if (vertices[i][1] < vertices[h][1]) {
  3943. h = i;
  3944. } else if (vertices[i][1] == vertices[h][1]) {
  3945. h = vertices[i][0] < vertices[h][0] ? i : h;
  3946. }
  3947. }
  3948. for (i = 0; i < n; ++i) {
  3949. if (i === h) continue;
  3950. y1 = vertices[i][1] - vertices[h][1];
  3951. x1 = vertices[i][0] - vertices[h][0];
  3952. points.push({
  3953. angle: Math.atan2(y1, x1),
  3954. index: i
  3955. });
  3956. }
  3957. points.sort(function(a, b) {
  3958. return a.angle - b.angle;
  3959. });
  3960. a = points[0].angle;
  3961. v = points[0].index;
  3962. u = 0;
  3963. for (i = 1; i < plen; ++i) {
  3964. j = points[i].index;
  3965. if (a == points[i].angle) {
  3966. x1 = vertices[v][0] - vertices[h][0];
  3967. y1 = vertices[v][1] - vertices[h][1];
  3968. x2 = vertices[j][0] - vertices[h][0];
  3969. y2 = vertices[j][1] - vertices[h][1];
  3970. if (x1 * x1 + y1 * y1 >= x2 * x2 + y2 * y2) {
  3971. points[i].index = -1;
  3972. } else {
  3973. points[u].index = -1;
  3974. a = points[i].angle;
  3975. u = i;
  3976. v = j;
  3977. }
  3978. } else {
  3979. a = points[i].angle;
  3980. u = i;
  3981. v = j;
  3982. }
  3983. }
  3984. stack.push(h);
  3985. for (i = 0, j = 0; i < 2; ++j) {
  3986. if (points[j].index !== -1) {
  3987. stack.push(points[j].index);
  3988. i++;
  3989. }
  3990. }
  3991. sp = stack.length;
  3992. for (;j < plen; ++j) {
  3993. if (points[j].index === -1) continue;
  3994. while (!d3_geom_hullCCW(stack[sp - 2], stack[sp - 1], points[j].index, vertices)) {
  3995. --sp;
  3996. }
  3997. stack[sp++] = points[j].index;
  3998. }
  3999. var poly = [];
  4000. for (i = 0; i < sp; ++i) {
  4001. poly.push(data[stack[i]]);
  4002. }
  4003. return poly;
  4004. }
  4005. hull.x = function(_) {
  4006. return arguments.length ? (x = _, hull) : x;
  4007. };
  4008. hull.y = function(_) {
  4009. return arguments.length ? (y = _, hull) : y;
  4010. };
  4011. return hull;
  4012. };
  4013. function d3_geom_hullCCW(i1, i2, i3, v) {
  4014. var t, a, b, c, d, e, f;
  4015. t = v[i1];
  4016. a = t[0];
  4017. b = t[1];
  4018. t = v[i2];
  4019. c = t[0];
  4020. d = t[1];
  4021. t = v[i3];
  4022. e = t[0];
  4023. f = t[1];
  4024. return (f - b) * (c - a) - (d - b) * (e - a) > 0;
  4025. }
  4026. d3.geom.polygon = function(coordinates) {
  4027. coordinates.area = function() {
  4028. var i = 0, n = coordinates.length, area = coordinates[n - 1][1] * coordinates[0][0] - coordinates[n - 1][0] * coordinates[0][1];
  4029. while (++i < n) {
  4030. area += coordinates[i - 1][1] * coordinates[i][0] - coordinates[i - 1][0] * coordinates[i][1];
  4031. }
  4032. return area * .5;
  4033. };
  4034. coordinates.centroid = function(k) {
  4035. var i = -1, n = coordinates.length, x = 0, y = 0, a, b = coordinates[n - 1], c;
  4036. if (!arguments.length) k = -1 / (6 * coordinates.area());
  4037. while (++i < n) {
  4038. a = b;
  4039. b = coordinates[i];
  4040. c = a[0] * b[1] - b[0] * a[1];
  4041. x += (a[0] + b[0]) * c;
  4042. y += (a[1] + b[1]) * c;
  4043. }
  4044. return [ x * k, y * k ];
  4045. };
  4046. coordinates.clip = function(subject) {
  4047. var input, i = -1, n = coordinates.length, j, m, a = coordinates[n - 1], b, c, d;
  4048. while (++i < n) {
  4049. input = subject.slice();
  4050. subject.length = 0;
  4051. b = coordinates[i];
  4052. c = input[(m = input.length) - 1];
  4053. j = -1;
  4054. while (++j < m) {
  4055. d = input[j];
  4056. if (d3_geom_polygonInside(d, a, b)) {
  4057. if (!d3_geom_polygonInside(c, a, b)) {
  4058. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4059. }
  4060. subject.push(d);
  4061. } else if (d3_geom_polygonInside(c, a, b)) {
  4062. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4063. }
  4064. c = d;
  4065. }
  4066. a = b;
  4067. }
  4068. return subject;
  4069. };
  4070. return coordinates;
  4071. };
  4072. function d3_geom_polygonInside(p, a, b) {
  4073. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  4074. }
  4075. function d3_geom_polygonIntersect(c, d, a, b) {
  4076. 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);
  4077. return [ x1 + ua * x21, y1 + ua * y21 ];
  4078. }
  4079. d3.geom.delaunay = function(vertices) {
  4080. var edges = vertices.map(function() {
  4081. return [];
  4082. }), triangles = [];
  4083. d3_geom_voronoiTessellate(vertices, function(e) {
  4084. edges[e.region.l.index].push(vertices[e.region.r.index]);
  4085. });
  4086. edges.forEach(function(edge, i) {
  4087. var v = vertices[i], cx = v[0], cy = v[1];
  4088. edge.forEach(function(v) {
  4089. v.angle = Math.atan2(v[0] - cx, v[1] - cy);
  4090. });
  4091. edge.sort(function(a, b) {
  4092. return a.angle - b.angle;
  4093. });
  4094. for (var j = 0, m = edge.length - 1; j < m; j++) {
  4095. triangles.push([ v, edge[j], edge[j + 1] ]);
  4096. }
  4097. });
  4098. return triangles;
  4099. };
  4100. d3.geom.voronoi = function(points) {
  4101. var size = null, x = d3_svg_lineX, y = d3_svg_lineY, clip;
  4102. if (arguments.length) return voronoi(points);
  4103. function voronoi(data) {
  4104. var points, polygons = data.map(function() {
  4105. return [];
  4106. }), fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length, Z = 1e6;
  4107. if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (points = [],
  4108. i = 0; i < n; ++i) {
  4109. points.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
  4110. }
  4111. d3_geom_voronoiTessellate(points, function(e) {
  4112. var s1, s2, x1, x2, y1, y2;
  4113. if (e.a === 1 && e.b >= 0) {
  4114. s1 = e.ep.r;
  4115. s2 = e.ep.l;
  4116. } else {
  4117. s1 = e.ep.l;
  4118. s2 = e.ep.r;
  4119. }
  4120. if (e.a === 1) {
  4121. y1 = s1 ? s1.y : -Z;
  4122. x1 = e.c - e.b * y1;
  4123. y2 = s2 ? s2.y : Z;
  4124. x2 = e.c - e.b * y2;
  4125. } else {
  4126. x1 = s1 ? s1.x : -Z;
  4127. y1 = e.c - e.a * x1;
  4128. x2 = s2 ? s2.x : Z;
  4129. y2 = e.c - e.a * x2;
  4130. }
  4131. var v1 = [ x1, y1 ], v2 = [ x2, y2 ];
  4132. polygons[e.region.l.index].push(v1, v2);
  4133. polygons[e.region.r.index].push(v1, v2);
  4134. });
  4135. polygons = polygons.map(function(polygon, i) {
  4136. var cx = points[i][0], cy = points[i][1], angle = polygon.map(function(v) {
  4137. return Math.atan2(v[0] - cx, v[1] - cy);
  4138. }), order = d3.range(polygon.length).sort(function(a, b) {
  4139. return angle[a] - angle[b];
  4140. });
  4141. return order.filter(function(d, i) {
  4142. return !i || angle[d] - angle[order[i - 1]] > ε;
  4143. }).map(function(d) {
  4144. return polygon[d];
  4145. });
  4146. });
  4147. polygons.forEach(function(polygon, i) {
  4148. var n = polygon.length;
  4149. if (!n) return polygon.push([ -Z, -Z ], [ -Z, Z ], [ Z, Z ], [ Z, -Z ]);
  4150. if (n > 2) return;
  4151. var p0 = points[i], p1 = polygon[0], p2 = polygon[1], x0 = p0[0], y0 = p0[1], x1 = p1[0], y1 = p1[1], x2 = p2[0], y2 = p2[1], dx = Math.abs(x2 - x1), dy = y2 - y1;
  4152. if (Math.abs(dy) < ε) {
  4153. var y = y0 < y1 ? -Z : Z;
  4154. polygon.push([ -Z, y ], [ Z, y ]);
  4155. } else if (dx < ε) {
  4156. var x = x0 < x1 ? -Z : Z;
  4157. polygon.push([ x, -Z ], [ x, Z ]);
  4158. } else {
  4159. var y = (x2 - x1) * (y1 - y0) < (x1 - x0) * (y2 - y1) ? Z : -Z, z = Math.abs(dy) - dx;
  4160. if (Math.abs(z) < ε) {
  4161. polygon.push([ dy < 0 ? y : -y, y ]);
  4162. } else {
  4163. if (z > 0) y *= -1;
  4164. polygon.push([ -Z, y ], [ Z, y ]);
  4165. }
  4166. }
  4167. });
  4168. if (clip) for (i = 0; i < n; ++i) clip(polygons[i]);
  4169. for (i = 0; i < n; ++i) polygons[i].point = data[i];
  4170. return polygons;
  4171. }
  4172. voronoi.x = function(_) {
  4173. return arguments.length ? (x = _, voronoi) : x;
  4174. };
  4175. voronoi.y = function(_) {
  4176. return arguments.length ? (y = _, voronoi) : y;
  4177. };
  4178. voronoi.size = function(_) {
  4179. if (!arguments.length) return size;
  4180. if (_ == null) {
  4181. clip = null;
  4182. } else {
  4183. size = [ +_[0], +_[1] ];
  4184. clip = d3.geom.polygon([ [ 0, 0 ], [ 0, size[1] ], size, [ size[0], 0 ] ]).clip;
  4185. }
  4186. return voronoi;
  4187. };
  4188. voronoi.links = function(data) {
  4189. var points, graph = data.map(function() {
  4190. return [];
  4191. }), links = [], fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length;
  4192. if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (i = 0; i < n; ++i) {
  4193. points.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
  4194. }
  4195. d3_geom_voronoiTessellate(points, function(e) {
  4196. var l = e.region.l.index, r = e.region.r.index;
  4197. if (graph[l][r]) return;
  4198. graph[l][r] = graph[r][l] = true;
  4199. links.push({
  4200. source: data[l],
  4201. target: data[r]
  4202. });
  4203. });
  4204. return links;
  4205. };
  4206. voronoi.triangles = function(data) {
  4207. if (x === d3_svg_lineX && y === d3_svg_lineY) return d3.geom.delaunay(data);
  4208. var points, point, fx = d3_functor(x), fy = d3_functor(y), d, i, n;
  4209. for (i = 0, points = [], n = data.length; i < n; ++i) {
  4210. point = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ];
  4211. point.data = d;
  4212. points.push(point);
  4213. }
  4214. return d3.geom.delaunay(points).map(function(triangle) {
  4215. return triangle.map(function(point) {
  4216. return point.data;
  4217. });
  4218. });
  4219. };
  4220. return voronoi;
  4221. };
  4222. var d3_geom_voronoiOpposite = {
  4223. l: "r",
  4224. r: "l"
  4225. };
  4226. function d3_geom_voronoiTessellate(points, callback) {
  4227. var Sites = {
  4228. list: points.map(function(v, i) {
  4229. return {
  4230. index: i,
  4231. x: v[0],
  4232. y: v[1]
  4233. };
  4234. }).sort(function(a, b) {
  4235. return a.y < b.y ? -1 : a.y > b.y ? 1 : a.x < b.x ? -1 : a.x > b.x ? 1 : 0;
  4236. }),
  4237. bottomSite: null
  4238. };
  4239. var EdgeList = {
  4240. list: [],
  4241. leftEnd: null,
  4242. rightEnd: null,
  4243. init: function() {
  4244. EdgeList.leftEnd = EdgeList.createHalfEdge(null, "l");
  4245. EdgeList.rightEnd = EdgeList.createHalfEdge(null, "l");
  4246. EdgeList.leftEnd.r = EdgeList.rightEnd;
  4247. EdgeList.rightEnd.l = EdgeList.leftEnd;
  4248. EdgeList.list.unshift(EdgeList.leftEnd, EdgeList.rightEnd);
  4249. },
  4250. createHalfEdge: function(edge, side) {
  4251. return {
  4252. edge: edge,
  4253. side: side,
  4254. vertex: null,
  4255. l: null,
  4256. r: null
  4257. };
  4258. },
  4259. insert: function(lb, he) {
  4260. he.l = lb;
  4261. he.r = lb.r;
  4262. lb.r.l = he;
  4263. lb.r = he;
  4264. },
  4265. leftBound: function(p) {
  4266. var he = EdgeList.leftEnd;
  4267. do {
  4268. he = he.r;
  4269. } while (he != EdgeList.rightEnd && Geom.rightOf(he, p));
  4270. he = he.l;
  4271. return he;
  4272. },
  4273. del: function(he) {
  4274. he.l.r = he.r;
  4275. he.r.l = he.l;
  4276. he.edge = null;
  4277. },
  4278. right: function(he) {
  4279. return he.r;
  4280. },
  4281. left: function(he) {
  4282. return he.l;
  4283. },
  4284. leftRegion: function(he) {
  4285. return he.edge == null ? Sites.bottomSite : he.edge.region[he.side];
  4286. },
  4287. rightRegion: function(he) {
  4288. return he.edge == null ? Sites.bottomSite : he.edge.region[d3_geom_voronoiOpposite[he.side]];
  4289. }
  4290. };
  4291. var Geom = {
  4292. bisect: function(s1, s2) {
  4293. var newEdge = {
  4294. region: {
  4295. l: s1,
  4296. r: s2
  4297. },
  4298. ep: {
  4299. l: null,
  4300. r: null
  4301. }
  4302. };
  4303. var dx = s2.x - s1.x, dy = s2.y - s1.y, adx = dx > 0 ? dx : -dx, ady = dy > 0 ? dy : -dy;
  4304. newEdge.c = s1.x * dx + s1.y * dy + (dx * dx + dy * dy) * .5;
  4305. if (adx > ady) {
  4306. newEdge.a = 1;
  4307. newEdge.b = dy / dx;
  4308. newEdge.c /= dx;
  4309. } else {
  4310. newEdge.b = 1;
  4311. newEdge.a = dx / dy;
  4312. newEdge.c /= dy;
  4313. }
  4314. return newEdge;
  4315. },
  4316. intersect: function(el1, el2) {
  4317. var e1 = el1.edge, e2 = el2.edge;
  4318. if (!e1 || !e2 || e1.region.r == e2.region.r) {
  4319. return null;
  4320. }
  4321. var d = e1.a * e2.b - e1.b * e2.a;
  4322. if (Math.abs(d) < 1e-10) {
  4323. return null;
  4324. }
  4325. var xint = (e1.c * e2.b - e2.c * e1.b) / d, yint = (e2.c * e1.a - e1.c * e2.a) / d, e1r = e1.region.r, e2r = e2.region.r, el, e;
  4326. if (e1r.y < e2r.y || e1r.y == e2r.y && e1r.x < e2r.x) {
  4327. el = el1;
  4328. e = e1;
  4329. } else {
  4330. el = el2;
  4331. e = e2;
  4332. }
  4333. var rightOfSite = xint >= e.region.r.x;
  4334. if (rightOfSite && el.side === "l" || !rightOfSite && el.side === "r") {
  4335. return null;
  4336. }
  4337. return {
  4338. x: xint,
  4339. y: yint
  4340. };
  4341. },
  4342. rightOf: function(he, p) {
  4343. var e = he.edge, topsite = e.region.r, rightOfSite = p.x > topsite.x;
  4344. if (rightOfSite && he.side === "l") {
  4345. return 1;
  4346. }
  4347. if (!rightOfSite && he.side === "r") {
  4348. return 0;
  4349. }
  4350. if (e.a === 1) {
  4351. var dyp = p.y - topsite.y, dxp = p.x - topsite.x, fast = 0, above = 0;
  4352. if (!rightOfSite && e.b < 0 || rightOfSite && e.b >= 0) {
  4353. above = fast = dyp >= e.b * dxp;
  4354. } else {
  4355. above = p.x + p.y * e.b > e.c;
  4356. if (e.b < 0) {
  4357. above = !above;
  4358. }
  4359. if (!above) {
  4360. fast = 1;
  4361. }
  4362. }
  4363. if (!fast) {
  4364. var dxs = topsite.x - e.region.l.x;
  4365. above = e.b * (dxp * dxp - dyp * dyp) < dxs * dyp * (1 + 2 * dxp / dxs + e.b * e.b);
  4366. if (e.b < 0) {
  4367. above = !above;
  4368. }
  4369. }
  4370. } else {
  4371. var yl = e.c - e.a * p.x, t1 = p.y - yl, t2 = p.x - topsite.x, t3 = yl - topsite.y;
  4372. above = t1 * t1 > t2 * t2 + t3 * t3;
  4373. }
  4374. return he.side === "l" ? above : !above;
  4375. },
  4376. endPoint: function(edge, side, site) {
  4377. edge.ep[side] = site;
  4378. if (!edge.ep[d3_geom_voronoiOpposite[side]]) return;
  4379. callback(edge);
  4380. },
  4381. distance: function(s, t) {
  4382. var dx = s.x - t.x, dy = s.y - t.y;
  4383. return Math.sqrt(dx * dx + dy * dy);
  4384. }
  4385. };
  4386. var EventQueue = {
  4387. list: [],
  4388. insert: function(he, site, offset) {
  4389. he.vertex = site;
  4390. he.ystar = site.y + offset;
  4391. for (var i = 0, list = EventQueue.list, l = list.length; i < l; i++) {
  4392. var next = list[i];
  4393. if (he.ystar > next.ystar || he.ystar == next.ystar && site.x > next.vertex.x) {
  4394. continue;
  4395. } else {
  4396. break;
  4397. }
  4398. }
  4399. list.splice(i, 0, he);
  4400. },
  4401. del: function(he) {
  4402. for (var i = 0, ls = EventQueue.list, l = ls.length; i < l && ls[i] != he; ++i) {}
  4403. ls.splice(i, 1);
  4404. },
  4405. empty: function() {
  4406. return EventQueue.list.length === 0;
  4407. },
  4408. nextEvent: function(he) {
  4409. for (var i = 0, ls = EventQueue.list, l = ls.length; i < l; ++i) {
  4410. if (ls[i] == he) return ls[i + 1];
  4411. }
  4412. return null;
  4413. },
  4414. min: function() {
  4415. var elem = EventQueue.list[0];
  4416. return {
  4417. x: elem.vertex.x,
  4418. y: elem.ystar
  4419. };
  4420. },
  4421. extractMin: function() {
  4422. return EventQueue.list.shift();
  4423. }
  4424. };
  4425. EdgeList.init();
  4426. Sites.bottomSite = Sites.list.shift();
  4427. var newSite = Sites.list.shift(), newIntStar;
  4428. var lbnd, rbnd, llbnd, rrbnd, bisector;
  4429. var bot, top, temp, p, v;
  4430. var e, pm;
  4431. while (true) {
  4432. if (!EventQueue.empty()) {
  4433. newIntStar = EventQueue.min();
  4434. }
  4435. if (newSite && (EventQueue.empty() || newSite.y < newIntStar.y || newSite.y == newIntStar.y && newSite.x < newIntStar.x)) {
  4436. lbnd = EdgeList.leftBound(newSite);
  4437. rbnd = EdgeList.right(lbnd);
  4438. bot = EdgeList.rightRegion(lbnd);
  4439. e = Geom.bisect(bot, newSite);
  4440. bisector = EdgeList.createHalfEdge(e, "l");
  4441. EdgeList.insert(lbnd, bisector);
  4442. p = Geom.intersect(lbnd, bisector);
  4443. if (p) {
  4444. EventQueue.del(lbnd);
  4445. EventQueue.insert(lbnd, p, Geom.distance(p, newSite));
  4446. }
  4447. lbnd = bisector;
  4448. bisector = EdgeList.createHalfEdge(e, "r");
  4449. EdgeList.insert(lbnd, bisector);
  4450. p = Geom.intersect(bisector, rbnd);
  4451. if (p) {
  4452. EventQueue.insert(bisector, p, Geom.distance(p, newSite));
  4453. }
  4454. newSite = Sites.list.shift();
  4455. } else if (!EventQueue.empty()) {
  4456. lbnd = EventQueue.extractMin();
  4457. llbnd = EdgeList.left(lbnd);
  4458. rbnd = EdgeList.right(lbnd);
  4459. rrbnd = EdgeList.right(rbnd);
  4460. bot = EdgeList.leftRegion(lbnd);
  4461. top = EdgeList.rightRegion(rbnd);
  4462. v = lbnd.vertex;
  4463. Geom.endPoint(lbnd.edge, lbnd.side, v);
  4464. Geom.endPoint(rbnd.edge, rbnd.side, v);
  4465. EdgeList.del(lbnd);
  4466. EventQueue.del(rbnd);
  4467. EdgeList.del(rbnd);
  4468. pm = "l";
  4469. if (bot.y > top.y) {
  4470. temp = bot;
  4471. bot = top;
  4472. top = temp;
  4473. pm = "r";
  4474. }
  4475. e = Geom.bisect(bot, top);
  4476. bisector = EdgeList.createHalfEdge(e, pm);
  4477. EdgeList.insert(llbnd, bisector);
  4478. Geom.endPoint(e, d3_geom_voronoiOpposite[pm], v);
  4479. p = Geom.intersect(llbnd, bisector);
  4480. if (p) {
  4481. EventQueue.del(llbnd);
  4482. EventQueue.insert(llbnd, p, Geom.distance(p, bot));
  4483. }
  4484. p = Geom.intersect(bisector, rrbnd);
  4485. if (p) {
  4486. EventQueue.insert(bisector, p, Geom.distance(p, bot));
  4487. }
  4488. } else {
  4489. break;
  4490. }
  4491. }
  4492. for (lbnd = EdgeList.right(EdgeList.leftEnd); lbnd != EdgeList.rightEnd; lbnd = EdgeList.right(lbnd)) {
  4493. callback(lbnd.edge);
  4494. }
  4495. }
  4496. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  4497. var x = d3_svg_lineX, y = d3_svg_lineY, compat;
  4498. if (compat = arguments.length) {
  4499. x = d3_geom_quadtreeCompatX;
  4500. y = d3_geom_quadtreeCompatY;
  4501. if (compat === 3) {
  4502. y2 = y1;
  4503. x2 = x1;
  4504. y1 = x1 = 0;
  4505. }
  4506. return quadtree(points);
  4507. }
  4508. function quadtree(data) {
  4509. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  4510. if (x1 != null) {
  4511. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  4512. } else {
  4513. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  4514. xs = [], ys = [];
  4515. n = data.length;
  4516. if (compat) for (i = 0; i < n; ++i) {
  4517. d = data[i];
  4518. if (d.x < x1_) x1_ = d.x;
  4519. if (d.y < y1_) y1_ = d.y;
  4520. if (d.x > x2_) x2_ = d.x;
  4521. if (d.y > y2_) y2_ = d.y;
  4522. xs.push(d.x);
  4523. ys.push(d.y);
  4524. } else for (i = 0; i < n; ++i) {
  4525. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  4526. if (x_ < x1_) x1_ = x_;
  4527. if (y_ < y1_) y1_ = y_;
  4528. if (x_ > x2_) x2_ = x_;
  4529. if (y_ > y2_) y2_ = y_;
  4530. xs.push(x_);
  4531. ys.push(y_);
  4532. }
  4533. }
  4534. var dx = x2_ - x1_, dy = y2_ - y1_;
  4535. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  4536. function insert(n, d, x, y, x1, y1, x2, y2) {
  4537. if (isNaN(x) || isNaN(y)) return;
  4538. if (n.leaf) {
  4539. var nx = n.x, ny = n.y;
  4540. if (nx != null) {
  4541. if (Math.abs(nx - x) + Math.abs(ny - y) < .01) {
  4542. insertChild(n, d, x, y, x1, y1, x2, y2);
  4543. } else {
  4544. var nPoint = n.point;
  4545. n.x = n.y = n.point = null;
  4546. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  4547. insertChild(n, d, x, y, x1, y1, x2, y2);
  4548. }
  4549. } else {
  4550. n.x = x, n.y = y, n.point = d;
  4551. }
  4552. } else {
  4553. insertChild(n, d, x, y, x1, y1, x2, y2);
  4554. }
  4555. }
  4556. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  4557. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = x >= sx, bottom = y >= sy, i = (bottom << 1) + right;
  4558. n.leaf = false;
  4559. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  4560. if (right) x1 = sx; else x2 = sx;
  4561. if (bottom) y1 = sy; else y2 = sy;
  4562. insert(n, d, x, y, x1, y1, x2, y2);
  4563. }
  4564. var root = d3_geom_quadtreeNode();
  4565. root.add = function(d) {
  4566. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  4567. };
  4568. root.visit = function(f) {
  4569. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  4570. };
  4571. i = -1;
  4572. if (x1 == null) {
  4573. while (++i < n) {
  4574. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  4575. }
  4576. --i;
  4577. } else data.forEach(root.add);
  4578. xs = ys = data = d = null;
  4579. return root;
  4580. }
  4581. quadtree.x = function(_) {
  4582. return arguments.length ? (x = _, quadtree) : x;
  4583. };
  4584. quadtree.y = function(_) {
  4585. return arguments.length ? (y = _, quadtree) : y;
  4586. };
  4587. quadtree.size = function(_) {
  4588. if (!arguments.length) return x1 == null ? null : [ x2, y2 ];
  4589. if (_ == null) {
  4590. x1 = y1 = x2 = y2 = null;
  4591. } else {
  4592. x1 = y1 = 0;
  4593. x2 = +_[0], y2 = +_[1];
  4594. }
  4595. return quadtree;
  4596. };
  4597. return quadtree;
  4598. };
  4599. function d3_geom_quadtreeCompatX(d) {
  4600. return d.x;
  4601. }
  4602. function d3_geom_quadtreeCompatY(d) {
  4603. return d.y;
  4604. }
  4605. function d3_geom_quadtreeNode() {
  4606. return {
  4607. leaf: true,
  4608. nodes: [],
  4609. point: null,
  4610. x: null,
  4611. y: null
  4612. };
  4613. }
  4614. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  4615. if (!f(node, x1, y1, x2, y2)) {
  4616. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  4617. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  4618. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  4619. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  4620. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  4621. }
  4622. }
  4623. d3.interpolateRgb = d3_interpolateRgb;
  4624. function d3_interpolateRgb(a, b) {
  4625. a = d3.rgb(a);
  4626. b = d3.rgb(b);
  4627. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  4628. return function(t) {
  4629. 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));
  4630. };
  4631. }
  4632. d3.transform = function(string) {
  4633. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  4634. return (d3.transform = function(string) {
  4635. g.setAttribute("transform", string);
  4636. var t = g.transform.baseVal.consolidate();
  4637. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  4638. })(string);
  4639. };
  4640. function d3_transform(m) {
  4641. 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;
  4642. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  4643. r0[0] *= -1;
  4644. r0[1] *= -1;
  4645. kx *= -1;
  4646. kz *= -1;
  4647. }
  4648. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  4649. this.translate = [ m.e, m.f ];
  4650. this.scale = [ kx, ky ];
  4651. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  4652. }
  4653. d3_transform.prototype.toString = function() {
  4654. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  4655. };
  4656. function d3_transformDot(a, b) {
  4657. return a[0] * b[0] + a[1] * b[1];
  4658. }
  4659. function d3_transformNormalize(a) {
  4660. var k = Math.sqrt(d3_transformDot(a, a));
  4661. if (k) {
  4662. a[0] /= k;
  4663. a[1] /= k;
  4664. }
  4665. return k;
  4666. }
  4667. function d3_transformCombine(a, b, k) {
  4668. a[0] += k * b[0];
  4669. a[1] += k * b[1];
  4670. return a;
  4671. }
  4672. var d3_transformIdentity = {
  4673. a: 1,
  4674. b: 0,
  4675. c: 0,
  4676. d: 1,
  4677. e: 0,
  4678. f: 0
  4679. };
  4680. d3.interpolateNumber = d3_interpolateNumber;
  4681. function d3_interpolateNumber(a, b) {
  4682. b -= a = +a;
  4683. return function(t) {
  4684. return a + b * t;
  4685. };
  4686. }
  4687. d3.interpolateTransform = d3_interpolateTransform;
  4688. function d3_interpolateTransform(a, b) {
  4689. var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
  4690. if (ta[0] != tb[0] || ta[1] != tb[1]) {
  4691. s.push("translate(", null, ",", null, ")");
  4692. q.push({
  4693. i: 1,
  4694. x: d3_interpolateNumber(ta[0], tb[0])
  4695. }, {
  4696. i: 3,
  4697. x: d3_interpolateNumber(ta[1], tb[1])
  4698. });
  4699. } else if (tb[0] || tb[1]) {
  4700. s.push("translate(" + tb + ")");
  4701. } else {
  4702. s.push("");
  4703. }
  4704. if (ra != rb) {
  4705. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  4706. q.push({
  4707. i: s.push(s.pop() + "rotate(", null, ")") - 2,
  4708. x: d3_interpolateNumber(ra, rb)
  4709. });
  4710. } else if (rb) {
  4711. s.push(s.pop() + "rotate(" + rb + ")");
  4712. }
  4713. if (wa != wb) {
  4714. q.push({
  4715. i: s.push(s.pop() + "skewX(", null, ")") - 2,
  4716. x: d3_interpolateNumber(wa, wb)
  4717. });
  4718. } else if (wb) {
  4719. s.push(s.pop() + "skewX(" + wb + ")");
  4720. }
  4721. if (ka[0] != kb[0] || ka[1] != kb[1]) {
  4722. n = s.push(s.pop() + "scale(", null, ",", null, ")");
  4723. q.push({
  4724. i: n - 4,
  4725. x: d3_interpolateNumber(ka[0], kb[0])
  4726. }, {
  4727. i: n - 2,
  4728. x: d3_interpolateNumber(ka[1], kb[1])
  4729. });
  4730. } else if (kb[0] != 1 || kb[1] != 1) {
  4731. s.push(s.pop() + "scale(" + kb + ")");
  4732. }
  4733. n = q.length;
  4734. return function(t) {
  4735. var i = -1, o;
  4736. while (++i < n) s[(o = q[i]).i] = o.x(t);
  4737. return s.join("");
  4738. };
  4739. }
  4740. d3.interpolateObject = d3_interpolateObject;
  4741. function d3_interpolateObject(a, b) {
  4742. var i = {}, c = {}, k;
  4743. for (k in a) {
  4744. if (k in b) {
  4745. i[k] = d3_interpolateByName(k)(a[k], b[k]);
  4746. } else {
  4747. c[k] = a[k];
  4748. }
  4749. }
  4750. for (k in b) {
  4751. if (!(k in a)) {
  4752. c[k] = b[k];
  4753. }
  4754. }
  4755. return function(t) {
  4756. for (k in i) c[k] = i[k](t);
  4757. return c;
  4758. };
  4759. }
  4760. d3.interpolateString = d3_interpolateString;
  4761. function d3_interpolateString(a, b) {
  4762. var m, i, j, s0 = 0, s1 = 0, s = [], q = [], n, o;
  4763. a = a + "", b = b + "";
  4764. d3_interpolate_number.lastIndex = 0;
  4765. for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
  4766. if (m.index) s.push(b.substring(s0, s1 = m.index));
  4767. q.push({
  4768. i: s.length,
  4769. x: m[0]
  4770. });
  4771. s.push(null);
  4772. s0 = d3_interpolate_number.lastIndex;
  4773. }
  4774. if (s0 < b.length) s.push(b.substring(s0));
  4775. for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
  4776. o = q[i];
  4777. if (o.x == m[0]) {
  4778. if (o.i) {
  4779. if (s[o.i + 1] == null) {
  4780. s[o.i - 1] += o.x;
  4781. s.splice(o.i, 1);
  4782. for (j = i + 1; j < n; ++j) q[j].i--;
  4783. } else {
  4784. s[o.i - 1] += o.x + s[o.i + 1];
  4785. s.splice(o.i, 2);
  4786. for (j = i + 1; j < n; ++j) q[j].i -= 2;
  4787. }
  4788. } else {
  4789. if (s[o.i + 1] == null) {
  4790. s[o.i] = o.x;
  4791. } else {
  4792. s[o.i] = o.x + s[o.i + 1];
  4793. s.splice(o.i + 1, 1);
  4794. for (j = i + 1; j < n; ++j) q[j].i--;
  4795. }
  4796. }
  4797. q.splice(i, 1);
  4798. n--;
  4799. i--;
  4800. } else {
  4801. o.x = d3_interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
  4802. }
  4803. }
  4804. while (i < n) {
  4805. o = q.pop();
  4806. if (s[o.i + 1] == null) {
  4807. s[o.i] = o.x;
  4808. } else {
  4809. s[o.i] = o.x + s[o.i + 1];
  4810. s.splice(o.i + 1, 1);
  4811. }
  4812. n--;
  4813. }
  4814. if (s.length === 1) {
  4815. return s[0] == null ? q[0].x : function() {
  4816. return b;
  4817. };
  4818. }
  4819. return function(t) {
  4820. for (i = 0; i < n; ++i) s[(o = q[i]).i] = o.x(t);
  4821. return s.join("");
  4822. };
  4823. }
  4824. var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
  4825. d3.interpolate = d3_interpolate;
  4826. function d3_interpolate(a, b) {
  4827. var i = d3.interpolators.length, f;
  4828. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  4829. return f;
  4830. }
  4831. function d3_interpolateByName(name) {
  4832. return name == "transform" ? d3_interpolateTransform : d3_interpolate;
  4833. }
  4834. d3.interpolators = [ function(a, b) {
  4835. var t = typeof b;
  4836. return (t === "string" || t !== typeof a ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_Color ? d3_interpolateRgb : t === "object" ? Array.isArray(b) ? d3_interpolateArray : d3_interpolateObject : d3_interpolateNumber)(a, b);
  4837. } ];
  4838. d3.interpolateArray = d3_interpolateArray;
  4839. function d3_interpolateArray(a, b) {
  4840. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  4841. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  4842. for (;i < na; ++i) c[i] = a[i];
  4843. for (;i < nb; ++i) c[i] = b[i];
  4844. return function(t) {
  4845. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  4846. return c;
  4847. };
  4848. }
  4849. var d3_ease_default = function() {
  4850. return d3_identity;
  4851. };
  4852. var d3_ease = d3.map({
  4853. linear: d3_ease_default,
  4854. poly: d3_ease_poly,
  4855. quad: function() {
  4856. return d3_ease_quad;
  4857. },
  4858. cubic: function() {
  4859. return d3_ease_cubic;
  4860. },
  4861. sin: function() {
  4862. return d3_ease_sin;
  4863. },
  4864. exp: function() {
  4865. return d3_ease_exp;
  4866. },
  4867. circle: function() {
  4868. return d3_ease_circle;
  4869. },
  4870. elastic: d3_ease_elastic,
  4871. back: d3_ease_back,
  4872. bounce: function() {
  4873. return d3_ease_bounce;
  4874. }
  4875. });
  4876. var d3_ease_mode = d3.map({
  4877. "in": d3_identity,
  4878. out: d3_ease_reverse,
  4879. "in-out": d3_ease_reflect,
  4880. "out-in": function(f) {
  4881. return d3_ease_reflect(d3_ease_reverse(f));
  4882. }
  4883. });
  4884. d3.ease = function(name) {
  4885. var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
  4886. t = d3_ease.get(t) || d3_ease_default;
  4887. m = d3_ease_mode.get(m) || d3_identity;
  4888. return d3_ease_clamp(m(t.apply(null, Array.prototype.slice.call(arguments, 1))));
  4889. };
  4890. function d3_ease_clamp(f) {
  4891. return function(t) {
  4892. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  4893. };
  4894. }
  4895. function d3_ease_reverse(f) {
  4896. return function(t) {
  4897. return 1 - f(1 - t);
  4898. };
  4899. }
  4900. function d3_ease_reflect(f) {
  4901. return function(t) {
  4902. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  4903. };
  4904. }
  4905. function d3_ease_quad(t) {
  4906. return t * t;
  4907. }
  4908. function d3_ease_cubic(t) {
  4909. return t * t * t;
  4910. }
  4911. function d3_ease_cubicInOut(t) {
  4912. if (t <= 0) return 0;
  4913. if (t >= 1) return 1;
  4914. var t2 = t * t, t3 = t2 * t;
  4915. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  4916. }
  4917. function d3_ease_poly(e) {
  4918. return function(t) {
  4919. return Math.pow(t, e);
  4920. };
  4921. }
  4922. function d3_ease_sin(t) {
  4923. return 1 - Math.cos(t * π / 2);
  4924. }
  4925. function d3_ease_exp(t) {
  4926. return Math.pow(2, 10 * (t - 1));
  4927. }
  4928. function d3_ease_circle(t) {
  4929. return 1 - Math.sqrt(1 - t * t);
  4930. }
  4931. function d3_ease_elastic(a, p) {
  4932. var s;
  4933. if (arguments.length < 2) p = .45;
  4934. if (arguments.length) s = p / (2 * π) * Math.asin(1 / a); else a = 1, s = p / 4;
  4935. return function(t) {
  4936. return 1 + a * Math.pow(2, 10 * -t) * Math.sin((t - s) * 2 * π / p);
  4937. };
  4938. }
  4939. function d3_ease_back(s) {
  4940. if (!s) s = 1.70158;
  4941. return function(t) {
  4942. return t * t * ((s + 1) * t - s);
  4943. };
  4944. }
  4945. function d3_ease_bounce(t) {
  4946. 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;
  4947. }
  4948. d3.interpolateHcl = d3_interpolateHcl;
  4949. function d3_interpolateHcl(a, b) {
  4950. a = d3.hcl(a);
  4951. b = d3.hcl(b);
  4952. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  4953. if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  4954. return function(t) {
  4955. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  4956. };
  4957. }
  4958. d3.interpolateHsl = d3_interpolateHsl;
  4959. function d3_interpolateHsl(a, b) {
  4960. a = d3.hsl(a);
  4961. b = d3.hsl(b);
  4962. var h0 = a.h, s0 = a.s, l0 = a.l, h1 = b.h - h0, s1 = b.s - s0, l1 = b.l - l0;
  4963. if (h1 > 180) h1 -= 360; else if (h1 < -180) h1 += 360;
  4964. return function(t) {
  4965. return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t) + "";
  4966. };
  4967. }
  4968. d3.interpolateLab = d3_interpolateLab;
  4969. function d3_interpolateLab(a, b) {
  4970. a = d3.lab(a);
  4971. b = d3.lab(b);
  4972. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  4973. return function(t) {
  4974. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  4975. };
  4976. }
  4977. d3.interpolateRound = d3_interpolateRound;
  4978. function d3_interpolateRound(a, b) {
  4979. b -= a;
  4980. return function(t) {
  4981. return Math.round(a + b * t);
  4982. };
  4983. }
  4984. function d3_uninterpolateNumber(a, b) {
  4985. b = b - (a = +a) ? 1 / (b - a) : 0;
  4986. return function(x) {
  4987. return (x - a) * b;
  4988. };
  4989. }
  4990. function d3_uninterpolateClamp(a, b) {
  4991. b = b - (a = +a) ? 1 / (b - a) : 0;
  4992. return function(x) {
  4993. return Math.max(0, Math.min(1, (x - a) * b));
  4994. };
  4995. }
  4996. d3.layout = {};
  4997. d3.layout.bundle = function() {
  4998. return function(links) {
  4999. var paths = [], i = -1, n = links.length;
  5000. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  5001. return paths;
  5002. };
  5003. };
  5004. function d3_layout_bundlePath(link) {
  5005. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  5006. while (start !== lca) {
  5007. start = start.parent;
  5008. points.push(start);
  5009. }
  5010. var k = points.length;
  5011. while (end !== lca) {
  5012. points.splice(k, 0, end);
  5013. end = end.parent;
  5014. }
  5015. return points;
  5016. }
  5017. function d3_layout_bundleAncestors(node) {
  5018. var ancestors = [], parent = node.parent;
  5019. while (parent != null) {
  5020. ancestors.push(node);
  5021. node = parent;
  5022. parent = parent.parent;
  5023. }
  5024. ancestors.push(node);
  5025. return ancestors;
  5026. }
  5027. function d3_layout_bundleLeastCommonAncestor(a, b) {
  5028. if (a === b) return a;
  5029. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  5030. while (aNode === bNode) {
  5031. sharedNode = aNode;
  5032. aNode = aNodes.pop();
  5033. bNode = bNodes.pop();
  5034. }
  5035. return sharedNode;
  5036. }
  5037. d3.layout.chord = function() {
  5038. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  5039. function relayout() {
  5040. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  5041. chords = [];
  5042. groups = [];
  5043. k = 0, i = -1;
  5044. while (++i < n) {
  5045. x = 0, j = -1;
  5046. while (++j < n) {
  5047. x += matrix[i][j];
  5048. }
  5049. groupSums.push(x);
  5050. subgroupIndex.push(d3.range(n));
  5051. k += x;
  5052. }
  5053. if (sortGroups) {
  5054. groupIndex.sort(function(a, b) {
  5055. return sortGroups(groupSums[a], groupSums[b]);
  5056. });
  5057. }
  5058. if (sortSubgroups) {
  5059. subgroupIndex.forEach(function(d, i) {
  5060. d.sort(function(a, b) {
  5061. return sortSubgroups(matrix[i][a], matrix[i][b]);
  5062. });
  5063. });
  5064. }
  5065. k = (2 * π - padding * n) / k;
  5066. x = 0, i = -1;
  5067. while (++i < n) {
  5068. x0 = x, j = -1;
  5069. while (++j < n) {
  5070. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  5071. subgroups[di + "-" + dj] = {
  5072. index: di,
  5073. subindex: dj,
  5074. startAngle: a0,
  5075. endAngle: a1,
  5076. value: v
  5077. };
  5078. }
  5079. groups[di] = {
  5080. index: di,
  5081. startAngle: x0,
  5082. endAngle: x,
  5083. value: (x - x0) / k
  5084. };
  5085. x += padding;
  5086. }
  5087. i = -1;
  5088. while (++i < n) {
  5089. j = i - 1;
  5090. while (++j < n) {
  5091. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  5092. if (source.value || target.value) {
  5093. chords.push(source.value < target.value ? {
  5094. source: target,
  5095. target: source
  5096. } : {
  5097. source: source,
  5098. target: target
  5099. });
  5100. }
  5101. }
  5102. }
  5103. if (sortChords) resort();
  5104. }
  5105. function resort() {
  5106. chords.sort(function(a, b) {
  5107. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  5108. });
  5109. }
  5110. chord.matrix = function(x) {
  5111. if (!arguments.length) return matrix;
  5112. n = (matrix = x) && matrix.length;
  5113. chords = groups = null;
  5114. return chord;
  5115. };
  5116. chord.padding = function(x) {
  5117. if (!arguments.length) return padding;
  5118. padding = x;
  5119. chords = groups = null;
  5120. return chord;
  5121. };
  5122. chord.sortGroups = function(x) {
  5123. if (!arguments.length) return sortGroups;
  5124. sortGroups = x;
  5125. chords = groups = null;
  5126. return chord;
  5127. };
  5128. chord.sortSubgroups = function(x) {
  5129. if (!arguments.length) return sortSubgroups;
  5130. sortSubgroups = x;
  5131. chords = null;
  5132. return chord;
  5133. };
  5134. chord.sortChords = function(x) {
  5135. if (!arguments.length) return sortChords;
  5136. sortChords = x;
  5137. if (chords) resort();
  5138. return chord;
  5139. };
  5140. chord.chords = function() {
  5141. if (!chords) relayout();
  5142. return chords;
  5143. };
  5144. chord.groups = function() {
  5145. if (!groups) relayout();
  5146. return groups;
  5147. };
  5148. return chord;
  5149. };
  5150. d3.layout.force = function() {
  5151. var force = {}, event = d3.dispatch("start", "tick", "end"), size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, gravity = .1, theta = .8, nodes = [], links = [], distances, strengths, charges;
  5152. function repulse(node) {
  5153. return function(quad, x1, _, x2) {
  5154. if (quad.point !== node) {
  5155. var dx = quad.cx - node.x, dy = quad.cy - node.y, dn = 1 / Math.sqrt(dx * dx + dy * dy);
  5156. if ((x2 - x1) * dn < theta) {
  5157. var k = quad.charge * dn * dn;
  5158. node.px -= dx * k;
  5159. node.py -= dy * k;
  5160. return true;
  5161. }
  5162. if (quad.point && isFinite(dn)) {
  5163. var k = quad.pointCharge * dn * dn;
  5164. node.px -= dx * k;
  5165. node.py -= dy * k;
  5166. }
  5167. }
  5168. return !quad.charge;
  5169. };
  5170. }
  5171. force.tick = function() {
  5172. if ((alpha *= .99) < .005) {
  5173. event.end({
  5174. type: "end",
  5175. alpha: alpha = 0
  5176. });
  5177. return true;
  5178. }
  5179. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  5180. for (i = 0; i < m; ++i) {
  5181. o = links[i];
  5182. s = o.source;
  5183. t = o.target;
  5184. x = t.x - s.x;
  5185. y = t.y - s.y;
  5186. if (l = x * x + y * y) {
  5187. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  5188. x *= l;
  5189. y *= l;
  5190. t.x -= x * (k = s.weight / (t.weight + s.weight));
  5191. t.y -= y * k;
  5192. s.x += x * (k = 1 - k);
  5193. s.y += y * k;
  5194. }
  5195. }
  5196. if (k = alpha * gravity) {
  5197. x = size[0] / 2;
  5198. y = size[1] / 2;
  5199. i = -1;
  5200. if (k) while (++i < n) {
  5201. o = nodes[i];
  5202. o.x += (x - o.x) * k;
  5203. o.y += (y - o.y) * k;
  5204. }
  5205. }
  5206. if (charge) {
  5207. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  5208. i = -1;
  5209. while (++i < n) {
  5210. if (!(o = nodes[i]).fixed) {
  5211. q.visit(repulse(o));
  5212. }
  5213. }
  5214. }
  5215. i = -1;
  5216. while (++i < n) {
  5217. o = nodes[i];
  5218. if (o.fixed) {
  5219. o.x = o.px;
  5220. o.y = o.py;
  5221. } else {
  5222. o.x -= (o.px - (o.px = o.x)) * friction;
  5223. o.y -= (o.py - (o.py = o.y)) * friction;
  5224. }
  5225. }
  5226. event.tick({
  5227. type: "tick",
  5228. alpha: alpha
  5229. });
  5230. };
  5231. force.nodes = function(x) {
  5232. if (!arguments.length) return nodes;
  5233. nodes = x;
  5234. return force;
  5235. };
  5236. force.links = function(x) {
  5237. if (!arguments.length) return links;
  5238. links = x;
  5239. return force;
  5240. };
  5241. force.size = function(x) {
  5242. if (!arguments.length) return size;
  5243. size = x;
  5244. return force;
  5245. };
  5246. force.linkDistance = function(x) {
  5247. if (!arguments.length) return linkDistance;
  5248. linkDistance = typeof x === "function" ? x : +x;
  5249. return force;
  5250. };
  5251. force.distance = force.linkDistance;
  5252. force.linkStrength = function(x) {
  5253. if (!arguments.length) return linkStrength;
  5254. linkStrength = typeof x === "function" ? x : +x;
  5255. return force;
  5256. };
  5257. force.friction = function(x) {
  5258. if (!arguments.length) return friction;
  5259. friction = +x;
  5260. return force;
  5261. };
  5262. force.charge = function(x) {
  5263. if (!arguments.length) return charge;
  5264. charge = typeof x === "function" ? x : +x;
  5265. return force;
  5266. };
  5267. force.gravity = function(x) {
  5268. if (!arguments.length) return gravity;
  5269. gravity = +x;
  5270. return force;
  5271. };
  5272. force.theta = function(x) {
  5273. if (!arguments.length) return theta;
  5274. theta = +x;
  5275. return force;
  5276. };
  5277. force.alpha = function(x) {
  5278. if (!arguments.length) return alpha;
  5279. x = +x;
  5280. if (alpha) {
  5281. if (x > 0) alpha = x; else alpha = 0;
  5282. } else if (x > 0) {
  5283. event.start({
  5284. type: "start",
  5285. alpha: alpha = x
  5286. });
  5287. d3.timer(force.tick);
  5288. }
  5289. return force;
  5290. };
  5291. force.start = function() {
  5292. var i, j, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  5293. for (i = 0; i < n; ++i) {
  5294. (o = nodes[i]).index = i;
  5295. o.weight = 0;
  5296. }
  5297. for (i = 0; i < m; ++i) {
  5298. o = links[i];
  5299. if (typeof o.source == "number") o.source = nodes[o.source];
  5300. if (typeof o.target == "number") o.target = nodes[o.target];
  5301. ++o.source.weight;
  5302. ++o.target.weight;
  5303. }
  5304. for (i = 0; i < n; ++i) {
  5305. o = nodes[i];
  5306. if (isNaN(o.x)) o.x = position("x", w);
  5307. if (isNaN(o.y)) o.y = position("y", h);
  5308. if (isNaN(o.px)) o.px = o.x;
  5309. if (isNaN(o.py)) o.py = o.y;
  5310. }
  5311. distances = [];
  5312. 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;
  5313. strengths = [];
  5314. 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;
  5315. charges = [];
  5316. 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;
  5317. function position(dimension, size) {
  5318. var neighbors = neighbor(i), j = -1, m = neighbors.length, x;
  5319. while (++j < m) if (!isNaN(x = neighbors[j][dimension])) return x;
  5320. return Math.random() * size;
  5321. }
  5322. function neighbor() {
  5323. if (!neighbors) {
  5324. neighbors = [];
  5325. for (j = 0; j < n; ++j) {
  5326. neighbors[j] = [];
  5327. }
  5328. for (j = 0; j < m; ++j) {
  5329. var o = links[j];
  5330. neighbors[o.source.index].push(o.target);
  5331. neighbors[o.target.index].push(o.source);
  5332. }
  5333. }
  5334. return neighbors[i];
  5335. }
  5336. return force.resume();
  5337. };
  5338. force.resume = function() {
  5339. return force.alpha(.1);
  5340. };
  5341. force.stop = function() {
  5342. return force.alpha(0);
  5343. };
  5344. force.drag = function() {
  5345. 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);
  5346. if (!arguments.length) return drag;
  5347. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  5348. };
  5349. function dragmove(d) {
  5350. d.px = d3.event.x, d.py = d3.event.y;
  5351. force.resume();
  5352. }
  5353. return d3.rebind(force, event, "on");
  5354. };
  5355. function d3_layout_forceDragstart(d) {
  5356. d.fixed |= 2;
  5357. }
  5358. function d3_layout_forceDragend(d) {
  5359. d.fixed &= ~6;
  5360. }
  5361. function d3_layout_forceMouseover(d) {
  5362. d.fixed |= 4;
  5363. d.px = d.x, d.py = d.y;
  5364. }
  5365. function d3_layout_forceMouseout(d) {
  5366. d.fixed &= ~4;
  5367. }
  5368. function d3_layout_forceAccumulate(quad, alpha, charges) {
  5369. var cx = 0, cy = 0;
  5370. quad.charge = 0;
  5371. if (!quad.leaf) {
  5372. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  5373. while (++i < n) {
  5374. c = nodes[i];
  5375. if (c == null) continue;
  5376. d3_layout_forceAccumulate(c, alpha, charges);
  5377. quad.charge += c.charge;
  5378. cx += c.charge * c.cx;
  5379. cy += c.charge * c.cy;
  5380. }
  5381. }
  5382. if (quad.point) {
  5383. if (!quad.leaf) {
  5384. quad.point.x += Math.random() - .5;
  5385. quad.point.y += Math.random() - .5;
  5386. }
  5387. var k = alpha * charges[quad.point.index];
  5388. quad.charge += quad.pointCharge = k;
  5389. cx += k * quad.point.x;
  5390. cy += k * quad.point.y;
  5391. }
  5392. quad.cx = cx / quad.charge;
  5393. quad.cy = cy / quad.charge;
  5394. }
  5395. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1;
  5396. d3.layout.hierarchy = function() {
  5397. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  5398. function recurse(node, depth, nodes) {
  5399. var childs = children.call(hierarchy, node, depth);
  5400. node.depth = depth;
  5401. nodes.push(node);
  5402. if (childs && (n = childs.length)) {
  5403. var i = -1, n, c = node.children = [], v = 0, j = depth + 1, d;
  5404. while (++i < n) {
  5405. d = recurse(childs[i], j, nodes);
  5406. d.parent = node;
  5407. c.push(d);
  5408. v += d.value;
  5409. }
  5410. if (sort) c.sort(sort);
  5411. if (value) node.value = v;
  5412. } else if (value) {
  5413. node.value = +value.call(hierarchy, node, depth) || 0;
  5414. }
  5415. return node;
  5416. }
  5417. function revalue(node, depth) {
  5418. var children = node.children, v = 0;
  5419. if (children && (n = children.length)) {
  5420. var i = -1, n, j = depth + 1;
  5421. while (++i < n) v += revalue(children[i], j);
  5422. } else if (value) {
  5423. v = +value.call(hierarchy, node, depth) || 0;
  5424. }
  5425. if (value) node.value = v;
  5426. return v;
  5427. }
  5428. function hierarchy(d) {
  5429. var nodes = [];
  5430. recurse(d, 0, nodes);
  5431. return nodes;
  5432. }
  5433. hierarchy.sort = function(x) {
  5434. if (!arguments.length) return sort;
  5435. sort = x;
  5436. return hierarchy;
  5437. };
  5438. hierarchy.children = function(x) {
  5439. if (!arguments.length) return children;
  5440. children = x;
  5441. return hierarchy;
  5442. };
  5443. hierarchy.value = function(x) {
  5444. if (!arguments.length) return value;
  5445. value = x;
  5446. return hierarchy;
  5447. };
  5448. hierarchy.revalue = function(root) {
  5449. revalue(root, 0);
  5450. return root;
  5451. };
  5452. return hierarchy;
  5453. };
  5454. function d3_layout_hierarchyRebind(object, hierarchy) {
  5455. d3.rebind(object, hierarchy, "sort", "children", "value");
  5456. object.nodes = object;
  5457. object.links = d3_layout_hierarchyLinks;
  5458. return object;
  5459. }
  5460. function d3_layout_hierarchyChildren(d) {
  5461. return d.children;
  5462. }
  5463. function d3_layout_hierarchyValue(d) {
  5464. return d.value;
  5465. }
  5466. function d3_layout_hierarchySort(a, b) {
  5467. return b.value - a.value;
  5468. }
  5469. function d3_layout_hierarchyLinks(nodes) {
  5470. return d3.merge(nodes.map(function(parent) {
  5471. return (parent.children || []).map(function(child) {
  5472. return {
  5473. source: parent,
  5474. target: child
  5475. };
  5476. });
  5477. }));
  5478. }
  5479. d3.layout.partition = function() {
  5480. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  5481. function position(node, x, dx, dy) {
  5482. var children = node.children;
  5483. node.x = x;
  5484. node.y = node.depth * dy;
  5485. node.dx = dx;
  5486. node.dy = dy;
  5487. if (children && (n = children.length)) {
  5488. var i = -1, n, c, d;
  5489. dx = node.value ? dx / node.value : 0;
  5490. while (++i < n) {
  5491. position(c = children[i], x, d = c.value * dx, dy);
  5492. x += d;
  5493. }
  5494. }
  5495. }
  5496. function depth(node) {
  5497. var children = node.children, d = 0;
  5498. if (children && (n = children.length)) {
  5499. var i = -1, n;
  5500. while (++i < n) d = Math.max(d, depth(children[i]));
  5501. }
  5502. return 1 + d;
  5503. }
  5504. function partition(d, i) {
  5505. var nodes = hierarchy.call(this, d, i);
  5506. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  5507. return nodes;
  5508. }
  5509. partition.size = function(x) {
  5510. if (!arguments.length) return size;
  5511. size = x;
  5512. return partition;
  5513. };
  5514. return d3_layout_hierarchyRebind(partition, hierarchy);
  5515. };
  5516. d3.layout.pie = function() {
  5517. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = 2 * π;
  5518. function pie(data) {
  5519. var values = data.map(function(d, i) {
  5520. return +value.call(pie, d, i);
  5521. });
  5522. var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
  5523. var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a) / d3.sum(values);
  5524. var index = d3.range(data.length);
  5525. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  5526. return values[j] - values[i];
  5527. } : function(i, j) {
  5528. return sort(data[i], data[j]);
  5529. });
  5530. var arcs = [];
  5531. index.forEach(function(i) {
  5532. var d;
  5533. arcs[i] = {
  5534. data: data[i],
  5535. value: d = values[i],
  5536. startAngle: a,
  5537. endAngle: a += d * k
  5538. };
  5539. });
  5540. return arcs;
  5541. }
  5542. pie.value = function(x) {
  5543. if (!arguments.length) return value;
  5544. value = x;
  5545. return pie;
  5546. };
  5547. pie.sort = function(x) {
  5548. if (!arguments.length) return sort;
  5549. sort = x;
  5550. return pie;
  5551. };
  5552. pie.startAngle = function(x) {
  5553. if (!arguments.length) return startAngle;
  5554. startAngle = x;
  5555. return pie;
  5556. };
  5557. pie.endAngle = function(x) {
  5558. if (!arguments.length) return endAngle;
  5559. endAngle = x;
  5560. return pie;
  5561. };
  5562. return pie;
  5563. };
  5564. var d3_layout_pieSortByValue = {};
  5565. d3.layout.stack = function() {
  5566. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  5567. function stack(data, index) {
  5568. var series = data.map(function(d, i) {
  5569. return values.call(stack, d, i);
  5570. });
  5571. var points = series.map(function(d) {
  5572. return d.map(function(v, i) {
  5573. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  5574. });
  5575. });
  5576. var orders = order.call(stack, points, index);
  5577. series = d3.permute(series, orders);
  5578. points = d3.permute(points, orders);
  5579. var offsets = offset.call(stack, points, index);
  5580. var n = series.length, m = series[0].length, i, j, o;
  5581. for (j = 0; j < m; ++j) {
  5582. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  5583. for (i = 1; i < n; ++i) {
  5584. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  5585. }
  5586. }
  5587. return data;
  5588. }
  5589. stack.values = function(x) {
  5590. if (!arguments.length) return values;
  5591. values = x;
  5592. return stack;
  5593. };
  5594. stack.order = function(x) {
  5595. if (!arguments.length) return order;
  5596. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  5597. return stack;
  5598. };
  5599. stack.offset = function(x) {
  5600. if (!arguments.length) return offset;
  5601. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  5602. return stack;
  5603. };
  5604. stack.x = function(z) {
  5605. if (!arguments.length) return x;
  5606. x = z;
  5607. return stack;
  5608. };
  5609. stack.y = function(z) {
  5610. if (!arguments.length) return y;
  5611. y = z;
  5612. return stack;
  5613. };
  5614. stack.out = function(z) {
  5615. if (!arguments.length) return out;
  5616. out = z;
  5617. return stack;
  5618. };
  5619. return stack;
  5620. };
  5621. function d3_layout_stackX(d) {
  5622. return d.x;
  5623. }
  5624. function d3_layout_stackY(d) {
  5625. return d.y;
  5626. }
  5627. function d3_layout_stackOut(d, y0, y) {
  5628. d.y0 = y0;
  5629. d.y = y;
  5630. }
  5631. var d3_layout_stackOrders = d3.map({
  5632. "inside-out": function(data) {
  5633. 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) {
  5634. return max[a] - max[b];
  5635. }), top = 0, bottom = 0, tops = [], bottoms = [];
  5636. for (i = 0; i < n; ++i) {
  5637. j = index[i];
  5638. if (top < bottom) {
  5639. top += sums[j];
  5640. tops.push(j);
  5641. } else {
  5642. bottom += sums[j];
  5643. bottoms.push(j);
  5644. }
  5645. }
  5646. return bottoms.reverse().concat(tops);
  5647. },
  5648. reverse: function(data) {
  5649. return d3.range(data.length).reverse();
  5650. },
  5651. "default": d3_layout_stackOrderDefault
  5652. });
  5653. var d3_layout_stackOffsets = d3.map({
  5654. silhouette: function(data) {
  5655. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  5656. for (j = 0; j < m; ++j) {
  5657. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  5658. if (o > max) max = o;
  5659. sums.push(o);
  5660. }
  5661. for (j = 0; j < m; ++j) {
  5662. y0[j] = (max - sums[j]) / 2;
  5663. }
  5664. return y0;
  5665. },
  5666. wiggle: function(data) {
  5667. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  5668. y0[0] = o = o0 = 0;
  5669. for (j = 1; j < m; ++j) {
  5670. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  5671. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  5672. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  5673. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  5674. }
  5675. s2 += s3 * data[i][j][1];
  5676. }
  5677. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  5678. if (o < o0) o0 = o;
  5679. }
  5680. for (j = 0; j < m; ++j) y0[j] -= o0;
  5681. return y0;
  5682. },
  5683. expand: function(data) {
  5684. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  5685. for (j = 0; j < m; ++j) {
  5686. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  5687. 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;
  5688. }
  5689. for (j = 0; j < m; ++j) y0[j] = 0;
  5690. return y0;
  5691. },
  5692. zero: d3_layout_stackOffsetZero
  5693. });
  5694. function d3_layout_stackOrderDefault(data) {
  5695. return d3.range(data.length);
  5696. }
  5697. function d3_layout_stackOffsetZero(data) {
  5698. var j = -1, m = data[0].length, y0 = [];
  5699. while (++j < m) y0[j] = 0;
  5700. return y0;
  5701. }
  5702. function d3_layout_stackMaxIndex(array) {
  5703. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  5704. for (;i < n; ++i) {
  5705. if ((k = array[i][1]) > v) {
  5706. j = i;
  5707. v = k;
  5708. }
  5709. }
  5710. return j;
  5711. }
  5712. function d3_layout_stackReduceSum(d) {
  5713. return d.reduce(d3_layout_stackSum, 0);
  5714. }
  5715. function d3_layout_stackSum(p, d) {
  5716. return p + d[1];
  5717. }
  5718. d3.layout.histogram = function() {
  5719. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  5720. function histogram(data, i) {
  5721. 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;
  5722. while (++i < m) {
  5723. bin = bins[i] = [];
  5724. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  5725. bin.y = 0;
  5726. }
  5727. if (m > 0) {
  5728. i = -1;
  5729. while (++i < n) {
  5730. x = values[i];
  5731. if (x >= range[0] && x <= range[1]) {
  5732. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  5733. bin.y += k;
  5734. bin.push(data[i]);
  5735. }
  5736. }
  5737. }
  5738. return bins;
  5739. }
  5740. histogram.value = function(x) {
  5741. if (!arguments.length) return valuer;
  5742. valuer = x;
  5743. return histogram;
  5744. };
  5745. histogram.range = function(x) {
  5746. if (!arguments.length) return ranger;
  5747. ranger = d3_functor(x);
  5748. return histogram;
  5749. };
  5750. histogram.bins = function(x) {
  5751. if (!arguments.length) return binner;
  5752. binner = typeof x === "number" ? function(range) {
  5753. return d3_layout_histogramBinFixed(range, x);
  5754. } : d3_functor(x);
  5755. return histogram;
  5756. };
  5757. histogram.frequency = function(x) {
  5758. if (!arguments.length) return frequency;
  5759. frequency = !!x;
  5760. return histogram;
  5761. };
  5762. return histogram;
  5763. };
  5764. function d3_layout_histogramBinSturges(range, values) {
  5765. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  5766. }
  5767. function d3_layout_histogramBinFixed(range, n) {
  5768. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  5769. while (++x <= n) f[x] = m * x + b;
  5770. return f;
  5771. }
  5772. function d3_layout_histogramRange(values) {
  5773. return [ d3.min(values), d3.max(values) ];
  5774. }
  5775. d3.layout.tree = function() {
  5776. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
  5777. function tree(d, i) {
  5778. var nodes = hierarchy.call(this, d, i), root = nodes[0];
  5779. function firstWalk(node, previousSibling) {
  5780. var children = node.children, layout = node._tree;
  5781. if (children && (n = children.length)) {
  5782. var n, firstChild = children[0], previousChild, ancestor = firstChild, child, i = -1;
  5783. while (++i < n) {
  5784. child = children[i];
  5785. firstWalk(child, previousChild);
  5786. ancestor = apportion(child, previousChild, ancestor);
  5787. previousChild = child;
  5788. }
  5789. d3_layout_treeShift(node);
  5790. var midpoint = .5 * (firstChild._tree.prelim + child._tree.prelim);
  5791. if (previousSibling) {
  5792. layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
  5793. layout.mod = layout.prelim - midpoint;
  5794. } else {
  5795. layout.prelim = midpoint;
  5796. }
  5797. } else {
  5798. if (previousSibling) {
  5799. layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
  5800. }
  5801. }
  5802. }
  5803. function secondWalk(node, x) {
  5804. node.x = node._tree.prelim + x;
  5805. var children = node.children;
  5806. if (children && (n = children.length)) {
  5807. var i = -1, n;
  5808. x += node._tree.mod;
  5809. while (++i < n) {
  5810. secondWalk(children[i], x);
  5811. }
  5812. }
  5813. }
  5814. function apportion(node, previousSibling, ancestor) {
  5815. if (previousSibling) {
  5816. var vip = node, vop = node, vim = previousSibling, vom = node.parent.children[0], sip = vip._tree.mod, sop = vop._tree.mod, sim = vim._tree.mod, som = vom._tree.mod, shift;
  5817. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  5818. vom = d3_layout_treeLeft(vom);
  5819. vop = d3_layout_treeRight(vop);
  5820. vop._tree.ancestor = node;
  5821. shift = vim._tree.prelim + sim - vip._tree.prelim - sip + separation(vim, vip);
  5822. if (shift > 0) {
  5823. d3_layout_treeMove(d3_layout_treeAncestor(vim, node, ancestor), node, shift);
  5824. sip += shift;
  5825. sop += shift;
  5826. }
  5827. sim += vim._tree.mod;
  5828. sip += vip._tree.mod;
  5829. som += vom._tree.mod;
  5830. sop += vop._tree.mod;
  5831. }
  5832. if (vim && !d3_layout_treeRight(vop)) {
  5833. vop._tree.thread = vim;
  5834. vop._tree.mod += sim - sop;
  5835. }
  5836. if (vip && !d3_layout_treeLeft(vom)) {
  5837. vom._tree.thread = vip;
  5838. vom._tree.mod += sip - som;
  5839. ancestor = node;
  5840. }
  5841. }
  5842. return ancestor;
  5843. }
  5844. d3_layout_treeVisitAfter(root, function(node, previousSibling) {
  5845. node._tree = {
  5846. ancestor: node,
  5847. prelim: 0,
  5848. mod: 0,
  5849. change: 0,
  5850. shift: 0,
  5851. number: previousSibling ? previousSibling._tree.number + 1 : 0
  5852. };
  5853. });
  5854. firstWalk(root);
  5855. secondWalk(root, -root._tree.prelim);
  5856. var left = d3_layout_treeSearch(root, d3_layout_treeLeftmost), right = d3_layout_treeSearch(root, d3_layout_treeRightmost), deep = d3_layout_treeSearch(root, d3_layout_treeDeepest), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2, y1 = deep.depth || 1;
  5857. d3_layout_treeVisitAfter(root, function(node) {
  5858. node.x = (node.x - x0) / (x1 - x0) * size[0];
  5859. node.y = node.depth / y1 * size[1];
  5860. delete node._tree;
  5861. });
  5862. return nodes;
  5863. }
  5864. tree.separation = function(x) {
  5865. if (!arguments.length) return separation;
  5866. separation = x;
  5867. return tree;
  5868. };
  5869. tree.size = function(x) {
  5870. if (!arguments.length) return size;
  5871. size = x;
  5872. return tree;
  5873. };
  5874. return d3_layout_hierarchyRebind(tree, hierarchy);
  5875. };
  5876. function d3_layout_treeSeparation(a, b) {
  5877. return a.parent == b.parent ? 1 : 2;
  5878. }
  5879. function d3_layout_treeLeft(node) {
  5880. var children = node.children;
  5881. return children && children.length ? children[0] : node._tree.thread;
  5882. }
  5883. function d3_layout_treeRight(node) {
  5884. var children = node.children, n;
  5885. return children && (n = children.length) ? children[n - 1] : node._tree.thread;
  5886. }
  5887. function d3_layout_treeSearch(node, compare) {
  5888. var children = node.children;
  5889. if (children && (n = children.length)) {
  5890. var child, n, i = -1;
  5891. while (++i < n) {
  5892. if (compare(child = d3_layout_treeSearch(children[i], compare), node) > 0) {
  5893. node = child;
  5894. }
  5895. }
  5896. }
  5897. return node;
  5898. }
  5899. function d3_layout_treeRightmost(a, b) {
  5900. return a.x - b.x;
  5901. }
  5902. function d3_layout_treeLeftmost(a, b) {
  5903. return b.x - a.x;
  5904. }
  5905. function d3_layout_treeDeepest(a, b) {
  5906. return a.depth - b.depth;
  5907. }
  5908. function d3_layout_treeVisitAfter(node, callback) {
  5909. function visit(node, previousSibling) {
  5910. var children = node.children;
  5911. if (children && (n = children.length)) {
  5912. var child, previousChild = null, i = -1, n;
  5913. while (++i < n) {
  5914. child = children[i];
  5915. visit(child, previousChild);
  5916. previousChild = child;
  5917. }
  5918. }
  5919. callback(node, previousSibling);
  5920. }
  5921. visit(node, null);
  5922. }
  5923. function d3_layout_treeShift(node) {
  5924. var shift = 0, change = 0, children = node.children, i = children.length, child;
  5925. while (--i >= 0) {
  5926. child = children[i]._tree;
  5927. child.prelim += shift;
  5928. child.mod += shift;
  5929. shift += child.shift + (change += child.change);
  5930. }
  5931. }
  5932. function d3_layout_treeMove(ancestor, node, shift) {
  5933. ancestor = ancestor._tree;
  5934. node = node._tree;
  5935. var change = shift / (node.number - ancestor.number);
  5936. ancestor.change += change;
  5937. node.change -= change;
  5938. node.shift += shift;
  5939. node.prelim += shift;
  5940. node.mod += shift;
  5941. }
  5942. function d3_layout_treeAncestor(vim, node, ancestor) {
  5943. return vim._tree.ancestor.parent == node.parent ? vim._tree.ancestor : ancestor;
  5944. }
  5945. d3.layout.pack = function() {
  5946. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ];
  5947. function pack(d, i) {
  5948. var nodes = hierarchy.call(this, d, i), root = nodes[0];
  5949. root.x = 0;
  5950. root.y = 0;
  5951. d3_layout_treeVisitAfter(root, function(d) {
  5952. d.r = Math.sqrt(d.value);
  5953. });
  5954. d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
  5955. var w = size[0], h = size[1], k = Math.max(2 * root.r / w, 2 * root.r / h);
  5956. if (padding > 0) {
  5957. var dr = padding * k / 2;
  5958. d3_layout_treeVisitAfter(root, function(d) {
  5959. d.r += dr;
  5960. });
  5961. d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
  5962. d3_layout_treeVisitAfter(root, function(d) {
  5963. d.r -= dr;
  5964. });
  5965. k = Math.max(2 * root.r / w, 2 * root.r / h);
  5966. }
  5967. d3_layout_packTransform(root, w / 2, h / 2, 1 / k);
  5968. return nodes;
  5969. }
  5970. pack.size = function(x) {
  5971. if (!arguments.length) return size;
  5972. size = x;
  5973. return pack;
  5974. };
  5975. pack.padding = function(_) {
  5976. if (!arguments.length) return padding;
  5977. padding = +_;
  5978. return pack;
  5979. };
  5980. return d3_layout_hierarchyRebind(pack, hierarchy);
  5981. };
  5982. function d3_layout_packSort(a, b) {
  5983. return a.value - b.value;
  5984. }
  5985. function d3_layout_packInsert(a, b) {
  5986. var c = a._pack_next;
  5987. a._pack_next = b;
  5988. b._pack_prev = a;
  5989. b._pack_next = c;
  5990. c._pack_prev = b;
  5991. }
  5992. function d3_layout_packSplice(a, b) {
  5993. a._pack_next = b;
  5994. b._pack_prev = a;
  5995. }
  5996. function d3_layout_packIntersects(a, b) {
  5997. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  5998. return dr * dr - dx * dx - dy * dy > .001;
  5999. }
  6000. function d3_layout_packSiblings(node) {
  6001. if (!(nodes = node.children) || !(n = nodes.length)) return;
  6002. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  6003. function bound(node) {
  6004. xMin = Math.min(node.x - node.r, xMin);
  6005. xMax = Math.max(node.x + node.r, xMax);
  6006. yMin = Math.min(node.y - node.r, yMin);
  6007. yMax = Math.max(node.y + node.r, yMax);
  6008. }
  6009. nodes.forEach(d3_layout_packLink);
  6010. a = nodes[0];
  6011. a.x = -a.r;
  6012. a.y = 0;
  6013. bound(a);
  6014. if (n > 1) {
  6015. b = nodes[1];
  6016. b.x = b.r;
  6017. b.y = 0;
  6018. bound(b);
  6019. if (n > 2) {
  6020. c = nodes[2];
  6021. d3_layout_packPlace(a, b, c);
  6022. bound(c);
  6023. d3_layout_packInsert(a, c);
  6024. a._pack_prev = c;
  6025. d3_layout_packInsert(c, b);
  6026. b = a._pack_next;
  6027. for (i = 3; i < n; i++) {
  6028. d3_layout_packPlace(a, b, c = nodes[i]);
  6029. var isect = 0, s1 = 1, s2 = 1;
  6030. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  6031. if (d3_layout_packIntersects(j, c)) {
  6032. isect = 1;
  6033. break;
  6034. }
  6035. }
  6036. if (isect == 1) {
  6037. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  6038. if (d3_layout_packIntersects(k, c)) {
  6039. break;
  6040. }
  6041. }
  6042. }
  6043. if (isect) {
  6044. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  6045. i--;
  6046. } else {
  6047. d3_layout_packInsert(a, c);
  6048. b = c;
  6049. bound(c);
  6050. }
  6051. }
  6052. }
  6053. }
  6054. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  6055. for (i = 0; i < n; i++) {
  6056. c = nodes[i];
  6057. c.x -= cx;
  6058. c.y -= cy;
  6059. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  6060. }
  6061. node.r = cr;
  6062. nodes.forEach(d3_layout_packUnlink);
  6063. }
  6064. function d3_layout_packLink(node) {
  6065. node._pack_next = node._pack_prev = node;
  6066. }
  6067. function d3_layout_packUnlink(node) {
  6068. delete node._pack_next;
  6069. delete node._pack_prev;
  6070. }
  6071. function d3_layout_packTransform(node, x, y, k) {
  6072. var children = node.children;
  6073. node.x = x += k * node.x;
  6074. node.y = y += k * node.y;
  6075. node.r *= k;
  6076. if (children) {
  6077. var i = -1, n = children.length;
  6078. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  6079. }
  6080. }
  6081. function d3_layout_packPlace(a, b, c) {
  6082. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  6083. if (db && (dx || dy)) {
  6084. var da = b.r + c.r, dc = dx * dx + dy * dy;
  6085. da *= da;
  6086. db *= db;
  6087. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  6088. c.x = a.x + x * dx + y * dy;
  6089. c.y = a.y + x * dy - y * dx;
  6090. } else {
  6091. c.x = a.x + db;
  6092. c.y = a.y;
  6093. }
  6094. }
  6095. d3.layout.cluster = function() {
  6096. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
  6097. function cluster(d, i) {
  6098. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  6099. d3_layout_treeVisitAfter(root, function(node) {
  6100. var children = node.children;
  6101. if (children && children.length) {
  6102. node.x = d3_layout_clusterX(children);
  6103. node.y = d3_layout_clusterY(children);
  6104. } else {
  6105. node.x = previousNode ? x += separation(node, previousNode) : 0;
  6106. node.y = 0;
  6107. previousNode = node;
  6108. }
  6109. });
  6110. 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;
  6111. d3_layout_treeVisitAfter(root, function(node) {
  6112. node.x = (node.x - x0) / (x1 - x0) * size[0];
  6113. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  6114. });
  6115. return nodes;
  6116. }
  6117. cluster.separation = function(x) {
  6118. if (!arguments.length) return separation;
  6119. separation = x;
  6120. return cluster;
  6121. };
  6122. cluster.size = function(x) {
  6123. if (!arguments.length) return size;
  6124. size = x;
  6125. return cluster;
  6126. };
  6127. return d3_layout_hierarchyRebind(cluster, hierarchy);
  6128. };
  6129. function d3_layout_clusterY(children) {
  6130. return 1 + d3.max(children, function(child) {
  6131. return child.y;
  6132. });
  6133. }
  6134. function d3_layout_clusterX(children) {
  6135. return children.reduce(function(x, child) {
  6136. return x + child.x;
  6137. }, 0) / children.length;
  6138. }
  6139. function d3_layout_clusterLeft(node) {
  6140. var children = node.children;
  6141. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  6142. }
  6143. function d3_layout_clusterRight(node) {
  6144. var children = node.children, n;
  6145. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  6146. }
  6147. d3.layout.treemap = function() {
  6148. 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));
  6149. function scale(children, k) {
  6150. var i = -1, n = children.length, child, area;
  6151. while (++i < n) {
  6152. area = (child = children[i]).value * (k < 0 ? 0 : k);
  6153. child.area = isNaN(area) || area <= 0 ? 0 : area;
  6154. }
  6155. }
  6156. function squarify(node) {
  6157. var children = node.children;
  6158. if (children && children.length) {
  6159. 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;
  6160. scale(remaining, rect.dx * rect.dy / node.value);
  6161. row.area = 0;
  6162. while ((n = remaining.length) > 0) {
  6163. row.push(child = remaining[n - 1]);
  6164. row.area += child.area;
  6165. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  6166. remaining.pop();
  6167. best = score;
  6168. } else {
  6169. row.area -= row.pop().area;
  6170. position(row, u, rect, false);
  6171. u = Math.min(rect.dx, rect.dy);
  6172. row.length = row.area = 0;
  6173. best = Infinity;
  6174. }
  6175. }
  6176. if (row.length) {
  6177. position(row, u, rect, true);
  6178. row.length = row.area = 0;
  6179. }
  6180. children.forEach(squarify);
  6181. }
  6182. }
  6183. function stickify(node) {
  6184. var children = node.children;
  6185. if (children && children.length) {
  6186. var rect = pad(node), remaining = children.slice(), child, row = [];
  6187. scale(remaining, rect.dx * rect.dy / node.value);
  6188. row.area = 0;
  6189. while (child = remaining.pop()) {
  6190. row.push(child);
  6191. row.area += child.area;
  6192. if (child.z != null) {
  6193. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  6194. row.length = row.area = 0;
  6195. }
  6196. }
  6197. children.forEach(stickify);
  6198. }
  6199. }
  6200. function worst(row, u) {
  6201. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  6202. while (++i < n) {
  6203. if (!(r = row[i].area)) continue;
  6204. if (r < rmin) rmin = r;
  6205. if (r > rmax) rmax = r;
  6206. }
  6207. s *= s;
  6208. u *= u;
  6209. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  6210. }
  6211. function position(row, u, rect, flush) {
  6212. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  6213. if (u == rect.dx) {
  6214. if (flush || v > rect.dy) v = rect.dy;
  6215. while (++i < n) {
  6216. o = row[i];
  6217. o.x = x;
  6218. o.y = y;
  6219. o.dy = v;
  6220. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  6221. }
  6222. o.z = true;
  6223. o.dx += rect.x + rect.dx - x;
  6224. rect.y += v;
  6225. rect.dy -= v;
  6226. } else {
  6227. if (flush || v > rect.dx) v = rect.dx;
  6228. while (++i < n) {
  6229. o = row[i];
  6230. o.x = x;
  6231. o.y = y;
  6232. o.dx = v;
  6233. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  6234. }
  6235. o.z = false;
  6236. o.dy += rect.y + rect.dy - y;
  6237. rect.x += v;
  6238. rect.dx -= v;
  6239. }
  6240. }
  6241. function treemap(d) {
  6242. var nodes = stickies || hierarchy(d), root = nodes[0];
  6243. root.x = 0;
  6244. root.y = 0;
  6245. root.dx = size[0];
  6246. root.dy = size[1];
  6247. if (stickies) hierarchy.revalue(root);
  6248. scale([ root ], root.dx * root.dy / root.value);
  6249. (stickies ? stickify : squarify)(root);
  6250. if (sticky) stickies = nodes;
  6251. return nodes;
  6252. }
  6253. treemap.size = function(x) {
  6254. if (!arguments.length) return size;
  6255. size = x;
  6256. return treemap;
  6257. };
  6258. treemap.padding = function(x) {
  6259. if (!arguments.length) return padding;
  6260. function padFunction(node) {
  6261. var p = x.call(treemap, node, node.depth);
  6262. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  6263. }
  6264. function padConstant(node) {
  6265. return d3_layout_treemapPad(node, x);
  6266. }
  6267. var type;
  6268. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  6269. padConstant) : padConstant;
  6270. return treemap;
  6271. };
  6272. treemap.round = function(x) {
  6273. if (!arguments.length) return round != Number;
  6274. round = x ? Math.round : Number;
  6275. return treemap;
  6276. };
  6277. treemap.sticky = function(x) {
  6278. if (!arguments.length) return sticky;
  6279. sticky = x;
  6280. stickies = null;
  6281. return treemap;
  6282. };
  6283. treemap.ratio = function(x) {
  6284. if (!arguments.length) return ratio;
  6285. ratio = x;
  6286. return treemap;
  6287. };
  6288. treemap.mode = function(x) {
  6289. if (!arguments.length) return mode;
  6290. mode = x + "";
  6291. return treemap;
  6292. };
  6293. return d3_layout_hierarchyRebind(treemap, hierarchy);
  6294. };
  6295. function d3_layout_treemapPadNull(node) {
  6296. return {
  6297. x: node.x,
  6298. y: node.y,
  6299. dx: node.dx,
  6300. dy: node.dy
  6301. };
  6302. }
  6303. function d3_layout_treemapPad(node, padding) {
  6304. 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];
  6305. if (dx < 0) {
  6306. x += dx / 2;
  6307. dx = 0;
  6308. }
  6309. if (dy < 0) {
  6310. y += dy / 2;
  6311. dy = 0;
  6312. }
  6313. return {
  6314. x: x,
  6315. y: y,
  6316. dx: dx,
  6317. dy: dy
  6318. };
  6319. }
  6320. d3.random = {
  6321. normal: function(µ, σ) {
  6322. var n = arguments.length;
  6323. if (n < 2) σ = 1;
  6324. if (n < 1) µ = 0;
  6325. return function() {
  6326. var x, y, r;
  6327. do {
  6328. x = Math.random() * 2 - 1;
  6329. y = Math.random() * 2 - 1;
  6330. r = x * x + y * y;
  6331. } while (!r || r > 1);
  6332. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  6333. };
  6334. },
  6335. logNormal: function() {
  6336. var random = d3.random.normal.apply(d3, arguments);
  6337. return function() {
  6338. return Math.exp(random());
  6339. };
  6340. },
  6341. irwinHall: function(m) {
  6342. return function() {
  6343. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  6344. return s / m;
  6345. };
  6346. }
  6347. };
  6348. d3.scale = {};
  6349. function d3_scaleExtent(domain) {
  6350. var start = domain[0], stop = domain[domain.length - 1];
  6351. return start < stop ? [ start, stop ] : [ stop, start ];
  6352. }
  6353. function d3_scaleRange(scale) {
  6354. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  6355. }
  6356. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  6357. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  6358. return function(x) {
  6359. return i(u(x));
  6360. };
  6361. }
  6362. function d3_scale_nice(domain, nice) {
  6363. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  6364. if (x1 < x0) {
  6365. dx = i0, i0 = i1, i1 = dx;
  6366. dx = x0, x0 = x1, x1 = dx;
  6367. }
  6368. if (nice = nice(x1 - x0)) {
  6369. domain[i0] = nice.floor(x0);
  6370. domain[i1] = nice.ceil(x1);
  6371. }
  6372. return domain;
  6373. }
  6374. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  6375. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  6376. if (domain[k] < domain[0]) {
  6377. domain = domain.slice().reverse();
  6378. range = range.slice().reverse();
  6379. }
  6380. while (++j <= k) {
  6381. u.push(uninterpolate(domain[j - 1], domain[j]));
  6382. i.push(interpolate(range[j - 1], range[j]));
  6383. }
  6384. return function(x) {
  6385. var j = d3.bisect(domain, x, 1, k) - 1;
  6386. return i[j](u[j](x));
  6387. };
  6388. }
  6389. d3.scale.linear = function() {
  6390. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  6391. };
  6392. function d3_scale_linear(domain, range, interpolate, clamp) {
  6393. var output, input;
  6394. function rescale() {
  6395. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  6396. output = linear(domain, range, uninterpolate, interpolate);
  6397. input = linear(range, domain, uninterpolate, d3_interpolate);
  6398. return scale;
  6399. }
  6400. function scale(x) {
  6401. return output(x);
  6402. }
  6403. scale.invert = function(y) {
  6404. return input(y);
  6405. };
  6406. scale.domain = function(x) {
  6407. if (!arguments.length) return domain;
  6408. domain = x.map(Number);
  6409. return rescale();
  6410. };
  6411. scale.range = function(x) {
  6412. if (!arguments.length) return range;
  6413. range = x;
  6414. return rescale();
  6415. };
  6416. scale.rangeRound = function(x) {
  6417. return scale.range(x).interpolate(d3_interpolateRound);
  6418. };
  6419. scale.clamp = function(x) {
  6420. if (!arguments.length) return clamp;
  6421. clamp = x;
  6422. return rescale();
  6423. };
  6424. scale.interpolate = function(x) {
  6425. if (!arguments.length) return interpolate;
  6426. interpolate = x;
  6427. return rescale();
  6428. };
  6429. scale.ticks = function(m) {
  6430. return d3_scale_linearTicks(domain, m);
  6431. };
  6432. scale.tickFormat = function(m, format) {
  6433. return d3_scale_linearTickFormat(domain, m, format);
  6434. };
  6435. scale.nice = function() {
  6436. d3_scale_nice(domain, d3_scale_linearNice);
  6437. return rescale();
  6438. };
  6439. scale.copy = function() {
  6440. return d3_scale_linear(domain, range, interpolate, clamp);
  6441. };
  6442. return rescale();
  6443. }
  6444. function d3_scale_linearRebind(scale, linear) {
  6445. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  6446. }
  6447. function d3_scale_linearNice(dx) {
  6448. dx = Math.pow(10, Math.round(Math.log(dx) / Math.LN10) - 1);
  6449. return dx && {
  6450. floor: function(x) {
  6451. return Math.floor(x / dx) * dx;
  6452. },
  6453. ceil: function(x) {
  6454. return Math.ceil(x / dx) * dx;
  6455. }
  6456. };
  6457. }
  6458. function d3_scale_linearTickRange(domain, m) {
  6459. 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;
  6460. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  6461. extent[0] = Math.ceil(extent[0] / step) * step;
  6462. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  6463. extent[2] = step;
  6464. return extent;
  6465. }
  6466. function d3_scale_linearTicks(domain, m) {
  6467. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  6468. }
  6469. function d3_scale_linearTickFormat(domain, m, format) {
  6470. var precision = -Math.floor(Math.log(d3_scale_linearTickRange(domain, m)[2]) / Math.LN10 + .01);
  6471. return d3.format(format ? format.replace(d3_format_re, function(a, b, c, d, e, f, g, h, i, j) {
  6472. return [ b, c, d, e, f, g, h, i || "." + (precision - (j === "%") * 2), j ].join("");
  6473. }) : ",." + precision + "f");
  6474. }
  6475. d3.scale.log = function() {
  6476. return d3_scale_log(d3.scale.linear().domain([ 0, Math.LN10 ]), 10, d3_scale_logp, d3_scale_powp);
  6477. };
  6478. function d3_scale_log(linear, base, log, pow) {
  6479. function scale(x) {
  6480. return linear(log(x));
  6481. }
  6482. scale.invert = function(x) {
  6483. return pow(linear.invert(x));
  6484. };
  6485. scale.domain = function(x) {
  6486. if (!arguments.length) return linear.domain().map(pow);
  6487. if (x[0] < 0) log = d3_scale_logn, pow = d3_scale_pown; else log = d3_scale_logp,
  6488. pow = d3_scale_powp;
  6489. linear.domain(x.map(log));
  6490. return scale;
  6491. };
  6492. scale.base = function(_) {
  6493. if (!arguments.length) return base;
  6494. base = +_;
  6495. return scale;
  6496. };
  6497. scale.nice = function() {
  6498. linear.domain(d3_scale_nice(linear.domain(), d3_scale_logNice(base)));
  6499. return scale;
  6500. };
  6501. scale.ticks = function() {
  6502. var extent = d3_scaleExtent(linear.domain()), ticks = [];
  6503. if (extent.every(isFinite)) {
  6504. var b = Math.log(base), i = Math.floor(extent[0] / b), j = Math.ceil(extent[1] / b), u = pow(extent[0]), v = pow(extent[1]), n = base % 1 ? 2 : base;
  6505. if (log === d3_scale_logn) {
  6506. ticks.push(-Math.pow(base, -i));
  6507. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(-Math.pow(base, -i) * k);
  6508. } else {
  6509. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(Math.pow(base, i) * k);
  6510. ticks.push(Math.pow(base, i));
  6511. }
  6512. for (i = 0; ticks[i] < u; i++) {}
  6513. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  6514. ticks = ticks.slice(i, j);
  6515. }
  6516. return ticks;
  6517. };
  6518. scale.tickFormat = function(n, format) {
  6519. if (arguments.length < 2) format = d3_scale_logFormat;
  6520. if (!arguments.length) return format;
  6521. var b = Math.log(base), k = Math.max(.1, n / scale.ticks().length), f = log === d3_scale_logn ? (e = -1e-12,
  6522. Math.floor) : (e = 1e-12, Math.ceil), e;
  6523. return function(d) {
  6524. return d / pow(b * f(log(d) / b + e)) <= k ? format(d) : "";
  6525. };
  6526. };
  6527. scale.copy = function() {
  6528. return d3_scale_log(linear.copy(), base, log, pow);
  6529. };
  6530. return d3_scale_linearRebind(scale, linear);
  6531. }
  6532. var d3_scale_logFormat = d3.format(".0e");
  6533. function d3_scale_logp(x) {
  6534. return Math.log(x < 0 ? 0 : x);
  6535. }
  6536. function d3_scale_powp(x) {
  6537. return Math.exp(x);
  6538. }
  6539. function d3_scale_logn(x) {
  6540. return -Math.log(x > 0 ? 0 : -x);
  6541. }
  6542. function d3_scale_pown(x) {
  6543. return -Math.exp(-x);
  6544. }
  6545. function d3_scale_logNice(base) {
  6546. base = Math.log(base);
  6547. var nice = {
  6548. floor: function(x) {
  6549. return Math.floor(x / base) * base;
  6550. },
  6551. ceil: function(x) {
  6552. return Math.ceil(x / base) * base;
  6553. }
  6554. };
  6555. return function() {
  6556. return nice;
  6557. };
  6558. }
  6559. d3.scale.pow = function() {
  6560. return d3_scale_pow(d3.scale.linear(), 1);
  6561. };
  6562. function d3_scale_pow(linear, exponent) {
  6563. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  6564. function scale(x) {
  6565. return linear(powp(x));
  6566. }
  6567. scale.invert = function(x) {
  6568. return powb(linear.invert(x));
  6569. };
  6570. scale.domain = function(x) {
  6571. if (!arguments.length) return linear.domain().map(powb);
  6572. linear.domain(x.map(powp));
  6573. return scale;
  6574. };
  6575. scale.ticks = function(m) {
  6576. return d3_scale_linearTicks(scale.domain(), m);
  6577. };
  6578. scale.tickFormat = function(m, format) {
  6579. return d3_scale_linearTickFormat(scale.domain(), m, format);
  6580. };
  6581. scale.nice = function() {
  6582. return scale.domain(d3_scale_nice(scale.domain(), d3_scale_linearNice));
  6583. };
  6584. scale.exponent = function(x) {
  6585. if (!arguments.length) return exponent;
  6586. var domain = scale.domain();
  6587. powp = d3_scale_powPow(exponent = x);
  6588. powb = d3_scale_powPow(1 / exponent);
  6589. return scale.domain(domain);
  6590. };
  6591. scale.copy = function() {
  6592. return d3_scale_pow(linear.copy(), exponent);
  6593. };
  6594. return d3_scale_linearRebind(scale, linear);
  6595. }
  6596. function d3_scale_powPow(e) {
  6597. return function(x) {
  6598. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  6599. };
  6600. }
  6601. d3.scale.sqrt = function() {
  6602. return d3.scale.pow().exponent(.5);
  6603. };
  6604. d3.scale.ordinal = function() {
  6605. return d3_scale_ordinal([], {
  6606. t: "range",
  6607. a: [ [] ]
  6608. });
  6609. };
  6610. function d3_scale_ordinal(domain, ranger) {
  6611. var index, range, rangeBand;
  6612. function scale(x) {
  6613. return range[((index.get(x) || index.set(x, domain.push(x))) - 1) % range.length];
  6614. }
  6615. function steps(start, step) {
  6616. return d3.range(domain.length).map(function(i) {
  6617. return start + step * i;
  6618. });
  6619. }
  6620. scale.domain = function(x) {
  6621. if (!arguments.length) return domain;
  6622. domain = [];
  6623. index = new d3_Map();
  6624. var i = -1, n = x.length, xi;
  6625. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  6626. return scale[ranger.t].apply(scale, ranger.a);
  6627. };
  6628. scale.range = function(x) {
  6629. if (!arguments.length) return range;
  6630. range = x;
  6631. rangeBand = 0;
  6632. ranger = {
  6633. t: "range",
  6634. a: arguments
  6635. };
  6636. return scale;
  6637. };
  6638. scale.rangePoints = function(x, padding) {
  6639. if (arguments.length < 2) padding = 0;
  6640. var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
  6641. range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
  6642. rangeBand = 0;
  6643. ranger = {
  6644. t: "rangePoints",
  6645. a: arguments
  6646. };
  6647. return scale;
  6648. };
  6649. scale.rangeBands = function(x, padding, outerPadding) {
  6650. if (arguments.length < 2) padding = 0;
  6651. if (arguments.length < 3) outerPadding = padding;
  6652. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  6653. range = steps(start + step * outerPadding, step);
  6654. if (reverse) range.reverse();
  6655. rangeBand = step * (1 - padding);
  6656. ranger = {
  6657. t: "rangeBands",
  6658. a: arguments
  6659. };
  6660. return scale;
  6661. };
  6662. scale.rangeRoundBands = function(x, padding, outerPadding) {
  6663. if (arguments.length < 2) padding = 0;
  6664. if (arguments.length < 3) outerPadding = padding;
  6665. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding)), error = stop - start - (domain.length - padding) * step;
  6666. range = steps(start + Math.round(error / 2), step);
  6667. if (reverse) range.reverse();
  6668. rangeBand = Math.round(step * (1 - padding));
  6669. ranger = {
  6670. t: "rangeRoundBands",
  6671. a: arguments
  6672. };
  6673. return scale;
  6674. };
  6675. scale.rangeBand = function() {
  6676. return rangeBand;
  6677. };
  6678. scale.rangeExtent = function() {
  6679. return d3_scaleExtent(ranger.a[0]);
  6680. };
  6681. scale.copy = function() {
  6682. return d3_scale_ordinal(domain, ranger);
  6683. };
  6684. return scale.domain(domain);
  6685. }
  6686. d3.scale.category10 = function() {
  6687. return d3.scale.ordinal().range(d3_category10);
  6688. };
  6689. d3.scale.category20 = function() {
  6690. return d3.scale.ordinal().range(d3_category20);
  6691. };
  6692. d3.scale.category20b = function() {
  6693. return d3.scale.ordinal().range(d3_category20b);
  6694. };
  6695. d3.scale.category20c = function() {
  6696. return d3.scale.ordinal().range(d3_category20c);
  6697. };
  6698. var d3_category10 = [ "#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf" ];
  6699. var d3_category20 = [ "#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2", "#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5" ];
  6700. var d3_category20b = [ "#393b79", "#5254a3", "#6b6ecf", "#9c9ede", "#637939", "#8ca252", "#b5cf6b", "#cedb9c", "#8c6d31", "#bd9e39", "#e7ba52", "#e7cb94", "#843c39", "#ad494a", "#d6616b", "#e7969c", "#7b4173", "#a55194", "#ce6dbd", "#de9ed6" ];
  6701. var d3_category20c = [ "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d", "#fd8d3c", "#fdae6b", "#fdd0a2", "#31a354", "#74c476", "#a1d99b", "#c7e9c0", "#756bb1", "#9e9ac8", "#bcbddc", "#dadaeb", "#636363", "#969696", "#bdbdbd", "#d9d9d9" ];
  6702. d3.scale.quantile = function() {
  6703. return d3_scale_quantile([], []);
  6704. };
  6705. function d3_scale_quantile(domain, range) {
  6706. var thresholds;
  6707. function rescale() {
  6708. var k = 0, q = range.length;
  6709. thresholds = [];
  6710. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  6711. return scale;
  6712. }
  6713. function scale(x) {
  6714. if (isNaN(x = +x)) return NaN;
  6715. return range[d3.bisect(thresholds, x)];
  6716. }
  6717. scale.domain = function(x) {
  6718. if (!arguments.length) return domain;
  6719. domain = x.filter(function(d) {
  6720. return !isNaN(d);
  6721. }).sort(d3.ascending);
  6722. return rescale();
  6723. };
  6724. scale.range = function(x) {
  6725. if (!arguments.length) return range;
  6726. range = x;
  6727. return rescale();
  6728. };
  6729. scale.quantiles = function() {
  6730. return thresholds;
  6731. };
  6732. scale.copy = function() {
  6733. return d3_scale_quantile(domain, range);
  6734. };
  6735. return rescale();
  6736. }
  6737. d3.scale.quantize = function() {
  6738. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  6739. };
  6740. function d3_scale_quantize(x0, x1, range) {
  6741. var kx, i;
  6742. function scale(x) {
  6743. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  6744. }
  6745. function rescale() {
  6746. kx = range.length / (x1 - x0);
  6747. i = range.length - 1;
  6748. return scale;
  6749. }
  6750. scale.domain = function(x) {
  6751. if (!arguments.length) return [ x0, x1 ];
  6752. x0 = +x[0];
  6753. x1 = +x[x.length - 1];
  6754. return rescale();
  6755. };
  6756. scale.range = function(x) {
  6757. if (!arguments.length) return range;
  6758. range = x;
  6759. return rescale();
  6760. };
  6761. scale.copy = function() {
  6762. return d3_scale_quantize(x0, x1, range);
  6763. };
  6764. return rescale();
  6765. }
  6766. d3.scale.threshold = function() {
  6767. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  6768. };
  6769. function d3_scale_threshold(domain, range) {
  6770. function scale(x) {
  6771. return range[d3.bisect(domain, x)];
  6772. }
  6773. scale.domain = function(_) {
  6774. if (!arguments.length) return domain;
  6775. domain = _;
  6776. return scale;
  6777. };
  6778. scale.range = function(_) {
  6779. if (!arguments.length) return range;
  6780. range = _;
  6781. return scale;
  6782. };
  6783. scale.copy = function() {
  6784. return d3_scale_threshold(domain, range);
  6785. };
  6786. return scale;
  6787. }
  6788. d3.scale.identity = function() {
  6789. return d3_scale_identity([ 0, 1 ]);
  6790. };
  6791. function d3_scale_identity(domain) {
  6792. function identity(x) {
  6793. return +x;
  6794. }
  6795. identity.invert = identity;
  6796. identity.domain = identity.range = function(x) {
  6797. if (!arguments.length) return domain;
  6798. domain = x.map(identity);
  6799. return identity;
  6800. };
  6801. identity.ticks = function(m) {
  6802. return d3_scale_linearTicks(domain, m);
  6803. };
  6804. identity.tickFormat = function(m, format) {
  6805. return d3_scale_linearTickFormat(domain, m, format);
  6806. };
  6807. identity.copy = function() {
  6808. return d3_scale_identity(domain);
  6809. };
  6810. return identity;
  6811. }
  6812. d3.svg.arc = function() {
  6813. var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  6814. function arc() {
  6815. var r0 = innerRadius.apply(this, arguments), r1 = outerRadius.apply(this, arguments), a0 = startAngle.apply(this, arguments) + d3_svg_arcOffset, a1 = endAngle.apply(this, arguments) + d3_svg_arcOffset, da = (a1 < a0 && (da = a0,
  6816. a0 = a1, a1 = da), a1 - a0), df = da < π ? "0" : "1", c0 = Math.cos(a0), s0 = Math.sin(a0), c1 = Math.cos(a1), s1 = Math.sin(a1);
  6817. return da >= d3_svg_arcMax ? r0 ? "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "M0," + r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + -r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + r0 + "Z" : "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "Z" : r0 ? "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L" + r0 * c1 + "," + r0 * s1 + "A" + r0 + "," + r0 + " 0 " + df + ",0 " + r0 * c0 + "," + r0 * s0 + "Z" : "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L0,0" + "Z";
  6818. }
  6819. arc.innerRadius = function(v) {
  6820. if (!arguments.length) return innerRadius;
  6821. innerRadius = d3_functor(v);
  6822. return arc;
  6823. };
  6824. arc.outerRadius = function(v) {
  6825. if (!arguments.length) return outerRadius;
  6826. outerRadius = d3_functor(v);
  6827. return arc;
  6828. };
  6829. arc.startAngle = function(v) {
  6830. if (!arguments.length) return startAngle;
  6831. startAngle = d3_functor(v);
  6832. return arc;
  6833. };
  6834. arc.endAngle = function(v) {
  6835. if (!arguments.length) return endAngle;
  6836. endAngle = d3_functor(v);
  6837. return arc;
  6838. };
  6839. arc.centroid = function() {
  6840. var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
  6841. return [ Math.cos(a) * r, Math.sin(a) * r ];
  6842. };
  6843. return arc;
  6844. };
  6845. var d3_svg_arcOffset = -π / 2, d3_svg_arcMax = 2 * π - 1e-6;
  6846. function d3_svg_arcInnerRadius(d) {
  6847. return d.innerRadius;
  6848. }
  6849. function d3_svg_arcOuterRadius(d) {
  6850. return d.outerRadius;
  6851. }
  6852. function d3_svg_arcStartAngle(d) {
  6853. return d.startAngle;
  6854. }
  6855. function d3_svg_arcEndAngle(d) {
  6856. return d.endAngle;
  6857. }
  6858. d3.svg.line.radial = function() {
  6859. var line = d3_svg_line(d3_svg_lineRadial);
  6860. line.radius = line.x, delete line.x;
  6861. line.angle = line.y, delete line.y;
  6862. return line;
  6863. };
  6864. function d3_svg_lineRadial(points) {
  6865. var point, i = -1, n = points.length, r, a;
  6866. while (++i < n) {
  6867. point = points[i];
  6868. r = point[0];
  6869. a = point[1] + d3_svg_arcOffset;
  6870. point[0] = r * Math.cos(a);
  6871. point[1] = r * Math.sin(a);
  6872. }
  6873. return points;
  6874. }
  6875. function d3_svg_area(projection) {
  6876. var x0 = d3_svg_lineX, x1 = d3_svg_lineX, y0 = 0, y1 = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
  6877. function area(data) {
  6878. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  6879. return x;
  6880. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  6881. return y;
  6882. } : d3_functor(y1), x, y;
  6883. function segment() {
  6884. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  6885. }
  6886. while (++i < n) {
  6887. if (defined.call(this, d = data[i], i)) {
  6888. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  6889. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  6890. } else if (points0.length) {
  6891. segment();
  6892. points0 = [];
  6893. points1 = [];
  6894. }
  6895. }
  6896. if (points0.length) segment();
  6897. return segments.length ? segments.join("") : null;
  6898. }
  6899. area.x = function(_) {
  6900. if (!arguments.length) return x1;
  6901. x0 = x1 = _;
  6902. return area;
  6903. };
  6904. area.x0 = function(_) {
  6905. if (!arguments.length) return x0;
  6906. x0 = _;
  6907. return area;
  6908. };
  6909. area.x1 = function(_) {
  6910. if (!arguments.length) return x1;
  6911. x1 = _;
  6912. return area;
  6913. };
  6914. area.y = function(_) {
  6915. if (!arguments.length) return y1;
  6916. y0 = y1 = _;
  6917. return area;
  6918. };
  6919. area.y0 = function(_) {
  6920. if (!arguments.length) return y0;
  6921. y0 = _;
  6922. return area;
  6923. };
  6924. area.y1 = function(_) {
  6925. if (!arguments.length) return y1;
  6926. y1 = _;
  6927. return area;
  6928. };
  6929. area.defined = function(_) {
  6930. if (!arguments.length) return defined;
  6931. defined = _;
  6932. return area;
  6933. };
  6934. area.interpolate = function(_) {
  6935. if (!arguments.length) return interpolateKey;
  6936. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  6937. interpolateReverse = interpolate.reverse || interpolate;
  6938. L = interpolate.closed ? "M" : "L";
  6939. return area;
  6940. };
  6941. area.tension = function(_) {
  6942. if (!arguments.length) return tension;
  6943. tension = _;
  6944. return area;
  6945. };
  6946. return area;
  6947. }
  6948. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  6949. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  6950. d3.svg.area = function() {
  6951. return d3_svg_area(d3_identity);
  6952. };
  6953. d3.svg.area.radial = function() {
  6954. var area = d3_svg_area(d3_svg_lineRadial);
  6955. area.radius = area.x, delete area.x;
  6956. area.innerRadius = area.x0, delete area.x0;
  6957. area.outerRadius = area.x1, delete area.x1;
  6958. area.angle = area.y, delete area.y;
  6959. area.startAngle = area.y0, delete area.y0;
  6960. area.endAngle = area.y1, delete area.y1;
  6961. return area;
  6962. };
  6963. d3.svg.chord = function() {
  6964. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  6965. function chord(d, i) {
  6966. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  6967. 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";
  6968. }
  6969. function subgroup(self, f, d, i) {
  6970. var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) + d3_svg_arcOffset, a1 = endAngle.call(self, subgroup, i) + d3_svg_arcOffset;
  6971. return {
  6972. r: r,
  6973. a0: a0,
  6974. a1: a1,
  6975. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  6976. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  6977. };
  6978. }
  6979. function equals(a, b) {
  6980. return a.a0 == b.a0 && a.a1 == b.a1;
  6981. }
  6982. function arc(r, p, a) {
  6983. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  6984. }
  6985. function curve(r0, p0, r1, p1) {
  6986. return "Q 0,0 " + p1;
  6987. }
  6988. chord.radius = function(v) {
  6989. if (!arguments.length) return radius;
  6990. radius = d3_functor(v);
  6991. return chord;
  6992. };
  6993. chord.source = function(v) {
  6994. if (!arguments.length) return source;
  6995. source = d3_functor(v);
  6996. return chord;
  6997. };
  6998. chord.target = function(v) {
  6999. if (!arguments.length) return target;
  7000. target = d3_functor(v);
  7001. return chord;
  7002. };
  7003. chord.startAngle = function(v) {
  7004. if (!arguments.length) return startAngle;
  7005. startAngle = d3_functor(v);
  7006. return chord;
  7007. };
  7008. chord.endAngle = function(v) {
  7009. if (!arguments.length) return endAngle;
  7010. endAngle = d3_functor(v);
  7011. return chord;
  7012. };
  7013. return chord;
  7014. };
  7015. function d3_svg_chordRadius(d) {
  7016. return d.radius;
  7017. }
  7018. d3.svg.diagonal = function() {
  7019. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  7020. function diagonal(d, i) {
  7021. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  7022. x: p0.x,
  7023. y: m
  7024. }, {
  7025. x: p3.x,
  7026. y: m
  7027. }, p3 ];
  7028. p = p.map(projection);
  7029. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  7030. }
  7031. diagonal.source = function(x) {
  7032. if (!arguments.length) return source;
  7033. source = d3_functor(x);
  7034. return diagonal;
  7035. };
  7036. diagonal.target = function(x) {
  7037. if (!arguments.length) return target;
  7038. target = d3_functor(x);
  7039. return diagonal;
  7040. };
  7041. diagonal.projection = function(x) {
  7042. if (!arguments.length) return projection;
  7043. projection = x;
  7044. return diagonal;
  7045. };
  7046. return diagonal;
  7047. };
  7048. function d3_svg_diagonalProjection(d) {
  7049. return [ d.x, d.y ];
  7050. }
  7051. d3.svg.diagonal.radial = function() {
  7052. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  7053. diagonal.projection = function(x) {
  7054. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  7055. };
  7056. return diagonal;
  7057. };
  7058. function d3_svg_diagonalRadialProjection(projection) {
  7059. return function() {
  7060. var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
  7061. return [ r * Math.cos(a), r * Math.sin(a) ];
  7062. };
  7063. }
  7064. d3.svg.symbol = function() {
  7065. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  7066. function symbol(d, i) {
  7067. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  7068. }
  7069. symbol.type = function(x) {
  7070. if (!arguments.length) return type;
  7071. type = d3_functor(x);
  7072. return symbol;
  7073. };
  7074. symbol.size = function(x) {
  7075. if (!arguments.length) return size;
  7076. size = d3_functor(x);
  7077. return symbol;
  7078. };
  7079. return symbol;
  7080. };
  7081. function d3_svg_symbolSize() {
  7082. return 64;
  7083. }
  7084. function d3_svg_symbolType() {
  7085. return "circle";
  7086. }
  7087. function d3_svg_symbolCircle(size) {
  7088. var r = Math.sqrt(size / π);
  7089. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  7090. }
  7091. var d3_svg_symbols = d3.map({
  7092. circle: d3_svg_symbolCircle,
  7093. cross: function(size) {
  7094. var r = Math.sqrt(size / 5) / 2;
  7095. 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";
  7096. },
  7097. diamond: function(size) {
  7098. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  7099. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  7100. },
  7101. square: function(size) {
  7102. var r = Math.sqrt(size) / 2;
  7103. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  7104. },
  7105. "triangle-down": function(size) {
  7106. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  7107. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  7108. },
  7109. "triangle-up": function(size) {
  7110. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  7111. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  7112. }
  7113. });
  7114. d3.svg.symbolTypes = d3_svg_symbols.keys();
  7115. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  7116. function d3_transition(groups, id) {
  7117. d3_arraySubclass(groups, d3_transitionPrototype);
  7118. groups.id = id;
  7119. return groups;
  7120. }
  7121. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit = {
  7122. ease: d3_ease_cubicInOut,
  7123. delay: 0,
  7124. duration: 250
  7125. };
  7126. d3_transitionPrototype.call = d3_selectionPrototype.call;
  7127. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  7128. d3_transitionPrototype.node = d3_selectionPrototype.node;
  7129. d3.transition = function(selection) {
  7130. return arguments.length ? d3_transitionInheritId ? selection.transition() : selection : d3_selectionRoot.transition();
  7131. };
  7132. d3.transition.prototype = d3_transitionPrototype;
  7133. d3_transitionPrototype.select = function(selector) {
  7134. var id = this.id, subgroups = [], subgroup, subnode, node;
  7135. if (typeof selector !== "function") selector = d3_selection_selector(selector);
  7136. for (var j = -1, m = this.length; ++j < m; ) {
  7137. subgroups.push(subgroup = []);
  7138. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  7139. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i))) {
  7140. if ("__data__" in node) subnode.__data__ = node.__data__;
  7141. d3_transitionNode(subnode, i, id, node.__transition__[id]);
  7142. subgroup.push(subnode);
  7143. } else {
  7144. subgroup.push(null);
  7145. }
  7146. }
  7147. }
  7148. return d3_transition(subgroups, id);
  7149. };
  7150. d3_transitionPrototype.selectAll = function(selector) {
  7151. var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition;
  7152. if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
  7153. for (var j = -1, m = this.length; ++j < m; ) {
  7154. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  7155. if (node = group[i]) {
  7156. transition = node.__transition__[id];
  7157. subnodes = selector.call(node, node.__data__, i);
  7158. subgroups.push(subgroup = []);
  7159. for (var k = -1, o = subnodes.length; ++k < o; ) {
  7160. d3_transitionNode(subnode = subnodes[k], k, id, transition);
  7161. subgroup.push(subnode);
  7162. }
  7163. }
  7164. }
  7165. }
  7166. return d3_transition(subgroups, id);
  7167. };
  7168. d3_transitionPrototype.filter = function(filter) {
  7169. var subgroups = [], subgroup, group, node;
  7170. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  7171. for (var j = 0, m = this.length; j < m; j++) {
  7172. subgroups.push(subgroup = []);
  7173. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  7174. if ((node = group[i]) && filter.call(node, node.__data__, i)) {
  7175. subgroup.push(node);
  7176. }
  7177. }
  7178. }
  7179. return d3_transition(subgroups, this.id, this.time).ease(this.ease());
  7180. };
  7181. d3_transitionPrototype.tween = function(name, tween) {
  7182. var id = this.id;
  7183. if (arguments.length < 2) return this.node().__transition__[id].tween.get(name);
  7184. return d3_selection_each(this, tween == null ? function(node) {
  7185. node.__transition__[id].tween.remove(name);
  7186. } : function(node) {
  7187. node.__transition__[id].tween.set(name, tween);
  7188. });
  7189. };
  7190. function d3_transition_tween(groups, name, value, tween) {
  7191. var id = groups.id;
  7192. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  7193. node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  7194. } : (value = tween(value), function(node) {
  7195. node.__transition__[id].tween.set(name, value);
  7196. }));
  7197. }
  7198. d3_transitionPrototype.attr = function(nameNS, value) {
  7199. if (arguments.length < 2) {
  7200. for (value in nameNS) this.attr(value, nameNS[value]);
  7201. return this;
  7202. }
  7203. var interpolate = d3_interpolateByName(nameNS), name = d3.ns.qualify(nameNS);
  7204. function attrNull() {
  7205. this.removeAttribute(name);
  7206. }
  7207. function attrNullNS() {
  7208. this.removeAttributeNS(name.space, name.local);
  7209. }
  7210. return d3_transition_tween(this, "attr." + nameNS, value, function(b) {
  7211. function attrString() {
  7212. var a = this.getAttribute(name), i;
  7213. return a !== b && (i = interpolate(a, b), function(t) {
  7214. this.setAttribute(name, i(t));
  7215. });
  7216. }
  7217. function attrStringNS() {
  7218. var a = this.getAttributeNS(name.space, name.local), i;
  7219. return a !== b && (i = interpolate(a, b), function(t) {
  7220. this.setAttributeNS(name.space, name.local, i(t));
  7221. });
  7222. }
  7223. return b == null ? name.local ? attrNullNS : attrNull : (b += "", name.local ? attrStringNS : attrString);
  7224. });
  7225. };
  7226. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  7227. var name = d3.ns.qualify(nameNS);
  7228. function attrTween(d, i) {
  7229. var f = tween.call(this, d, i, this.getAttribute(name));
  7230. return f && function(t) {
  7231. this.setAttribute(name, f(t));
  7232. };
  7233. }
  7234. function attrTweenNS(d, i) {
  7235. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  7236. return f && function(t) {
  7237. this.setAttributeNS(name.space, name.local, f(t));
  7238. };
  7239. }
  7240. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  7241. };
  7242. d3_transitionPrototype.style = function(name, value, priority) {
  7243. var n = arguments.length;
  7244. if (n < 3) {
  7245. if (typeof name !== "string") {
  7246. if (n < 2) value = "";
  7247. for (priority in name) this.style(priority, name[priority], value);
  7248. return this;
  7249. }
  7250. priority = "";
  7251. }
  7252. var interpolate = d3_interpolateByName(name);
  7253. function styleNull() {
  7254. this.style.removeProperty(name);
  7255. }
  7256. return d3_transition_tween(this, "style." + name, value, function(b) {
  7257. function styleString() {
  7258. var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
  7259. return a !== b && (i = interpolate(a, b), function(t) {
  7260. this.style.setProperty(name, i(t), priority);
  7261. });
  7262. }
  7263. return b == null ? styleNull : (b += "", styleString);
  7264. });
  7265. };
  7266. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  7267. if (arguments.length < 3) priority = "";
  7268. return this.tween("style." + name, function(d, i) {
  7269. var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
  7270. return f && function(t) {
  7271. this.style.setProperty(name, f(t), priority);
  7272. };
  7273. });
  7274. };
  7275. d3_transitionPrototype.text = function(value) {
  7276. return d3_transition_tween(this, "text", value, d3_transition_text);
  7277. };
  7278. function d3_transition_text(b) {
  7279. if (b == null) b = "";
  7280. return function() {
  7281. this.textContent = b;
  7282. };
  7283. }
  7284. d3_transitionPrototype.remove = function() {
  7285. return this.each("end.transition", function() {
  7286. var p;
  7287. if (!this.__transition__ && (p = this.parentNode)) p.removeChild(this);
  7288. });
  7289. };
  7290. d3_transitionPrototype.ease = function(value) {
  7291. var id = this.id;
  7292. if (arguments.length < 1) return this.node().__transition__[id].ease;
  7293. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  7294. return d3_selection_each(this, function(node) {
  7295. node.__transition__[id].ease = value;
  7296. });
  7297. };
  7298. d3_transitionPrototype.delay = function(value) {
  7299. var id = this.id;
  7300. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  7301. node.__transition__[id].delay = value.call(node, node.__data__, i, j) | 0;
  7302. } : (value |= 0, function(node) {
  7303. node.__transition__[id].delay = value;
  7304. }));
  7305. };
  7306. d3_transitionPrototype.duration = function(value) {
  7307. var id = this.id;
  7308. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  7309. node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j) | 0);
  7310. } : (value = Math.max(1, value | 0), function(node) {
  7311. node.__transition__[id].duration = value;
  7312. }));
  7313. };
  7314. d3_transitionPrototype.each = function(type, listener) {
  7315. var id = this.id;
  7316. if (arguments.length < 2) {
  7317. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  7318. d3_transitionInheritId = id;
  7319. d3_selection_each(this, function(node, i, j) {
  7320. d3_transitionInherit = node.__transition__[id];
  7321. type.call(node, node.__data__, i, j);
  7322. });
  7323. d3_transitionInherit = inherit;
  7324. d3_transitionInheritId = inheritId;
  7325. } else {
  7326. d3_selection_each(this, function(node) {
  7327. node.__transition__[id].event.on(type, listener);
  7328. });
  7329. }
  7330. return this;
  7331. };
  7332. d3_transitionPrototype.transition = function() {
  7333. var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition;
  7334. for (var j = 0, m = this.length; j < m; j++) {
  7335. subgroups.push(subgroup = []);
  7336. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  7337. if (node = group[i]) {
  7338. transition = Object.create(node.__transition__[id0]);
  7339. transition.delay += transition.duration;
  7340. d3_transitionNode(node, i, id1, transition);
  7341. }
  7342. subgroup.push(node);
  7343. }
  7344. }
  7345. return d3_transition(subgroups, id1);
  7346. };
  7347. function d3_transitionNode(node, i, id, inherit) {
  7348. var lock = node.__transition__ || (node.__transition__ = {
  7349. active: 0,
  7350. count: 0
  7351. }), transition = lock[id];
  7352. if (!transition) {
  7353. var time = inherit.time;
  7354. transition = lock[id] = {
  7355. tween: new d3_Map(),
  7356. event: d3.dispatch("start", "end"),
  7357. time: time,
  7358. ease: inherit.ease,
  7359. delay: inherit.delay,
  7360. duration: inherit.duration
  7361. };
  7362. ++lock.count;
  7363. d3.timer(function(elapsed) {
  7364. var d = node.__data__, ease = transition.ease, event = transition.event, delay = transition.delay, duration = transition.duration, tweened = [];
  7365. return delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time), 1;
  7366. function start(elapsed) {
  7367. if (lock.active > id) return stop();
  7368. lock.active = id;
  7369. event.start.call(node, d, i);
  7370. transition.tween.forEach(function(key, value) {
  7371. if (value = value.call(node, d, i)) {
  7372. tweened.push(value);
  7373. }
  7374. });
  7375. if (!tick(elapsed)) d3.timer(tick, 0, time);
  7376. return 1;
  7377. }
  7378. function tick(elapsed) {
  7379. if (lock.active !== id) return stop();
  7380. var t = (elapsed - delay) / duration, e = ease(t), n = tweened.length;
  7381. while (n > 0) {
  7382. tweened[--n].call(node, e);
  7383. }
  7384. if (t >= 1) {
  7385. stop();
  7386. event.end.call(node, d, i);
  7387. return 1;
  7388. }
  7389. }
  7390. function stop() {
  7391. if (--lock.count) delete lock[id]; else delete node.__transition__;
  7392. return 1;
  7393. }
  7394. }, 0, time);
  7395. return transition;
  7396. }
  7397. }
  7398. d3.svg.axis = function() {
  7399. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, tickMajorSize = 6, tickMinorSize = 6, tickEndSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_, tickSubdivide = 0;
  7400. function axis(g) {
  7401. g.each(function() {
  7402. var g = d3.select(this);
  7403. var ticks = tickValues == null ? scale.ticks ? scale.ticks.apply(scale, tickArguments_) : scale.domain() : tickValues, tickFormat = tickFormat_ == null ? scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments_) : String : tickFormat_;
  7404. var subticks = d3_svg_axisSubdivide(scale, ticks, tickSubdivide), subtick = g.selectAll(".tick.minor").data(subticks, String), subtickEnter = subtick.enter().insert("line", ".tick").attr("class", "tick minor").style("opacity", 1e-6), subtickExit = d3.transition(subtick.exit()).style("opacity", 1e-6).remove(), subtickUpdate = d3.transition(subtick).style("opacity", 1);
  7405. var tick = g.selectAll(".tick.major").data(ticks, String), tickEnter = tick.enter().insert("g", "path").attr("class", "tick major").style("opacity", 1e-6), tickExit = d3.transition(tick.exit()).style("opacity", 1e-6).remove(), tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform;
  7406. var range = d3_scaleRange(scale), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  7407. d3.transition(path));
  7408. var scale1 = scale.copy(), scale0 = this.__chart__ || scale1;
  7409. this.__chart__ = scale1;
  7410. tickEnter.append("line");
  7411. tickEnter.append("text");
  7412. var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
  7413. switch (orient) {
  7414. case "bottom":
  7415. {
  7416. tickTransform = d3_svg_axisX;
  7417. subtickEnter.attr("y2", tickMinorSize);
  7418. subtickUpdate.attr("x2", 0).attr("y2", tickMinorSize);
  7419. lineEnter.attr("y2", tickMajorSize);
  7420. textEnter.attr("y", Math.max(tickMajorSize, 0) + tickPadding);
  7421. lineUpdate.attr("x2", 0).attr("y2", tickMajorSize);
  7422. textUpdate.attr("x", 0).attr("y", Math.max(tickMajorSize, 0) + tickPadding);
  7423. text.attr("dy", ".71em").style("text-anchor", "middle");
  7424. pathUpdate.attr("d", "M" + range[0] + "," + tickEndSize + "V0H" + range[1] + "V" + tickEndSize);
  7425. break;
  7426. }
  7427. case "top":
  7428. {
  7429. tickTransform = d3_svg_axisX;
  7430. subtickEnter.attr("y2", -tickMinorSize);
  7431. subtickUpdate.attr("x2", 0).attr("y2", -tickMinorSize);
  7432. lineEnter.attr("y2", -tickMajorSize);
  7433. textEnter.attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
  7434. lineUpdate.attr("x2", 0).attr("y2", -tickMajorSize);
  7435. textUpdate.attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
  7436. text.attr("dy", "0em").style("text-anchor", "middle");
  7437. pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize);
  7438. break;
  7439. }
  7440. case "left":
  7441. {
  7442. tickTransform = d3_svg_axisY;
  7443. subtickEnter.attr("x2", -tickMinorSize);
  7444. subtickUpdate.attr("x2", -tickMinorSize).attr("y2", 0);
  7445. lineEnter.attr("x2", -tickMajorSize);
  7446. textEnter.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding));
  7447. lineUpdate.attr("x2", -tickMajorSize).attr("y2", 0);
  7448. textUpdate.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("y", 0);
  7449. text.attr("dy", ".32em").style("text-anchor", "end");
  7450. pathUpdate.attr("d", "M" + -tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + -tickEndSize);
  7451. break;
  7452. }
  7453. case "right":
  7454. {
  7455. tickTransform = d3_svg_axisY;
  7456. subtickEnter.attr("x2", tickMinorSize);
  7457. subtickUpdate.attr("x2", tickMinorSize).attr("y2", 0);
  7458. lineEnter.attr("x2", tickMajorSize);
  7459. textEnter.attr("x", Math.max(tickMajorSize, 0) + tickPadding);
  7460. lineUpdate.attr("x2", tickMajorSize).attr("y2", 0);
  7461. textUpdate.attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0);
  7462. text.attr("dy", ".32em").style("text-anchor", "start");
  7463. pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize);
  7464. break;
  7465. }
  7466. }
  7467. if (scale.ticks) {
  7468. tickEnter.call(tickTransform, scale0);
  7469. tickUpdate.call(tickTransform, scale1);
  7470. tickExit.call(tickTransform, scale1);
  7471. subtickEnter.call(tickTransform, scale0);
  7472. subtickUpdate.call(tickTransform, scale1);
  7473. subtickExit.call(tickTransform, scale1);
  7474. } else {
  7475. var dx = scale1.rangeBand() / 2, x = function(d) {
  7476. return scale1(d) + dx;
  7477. };
  7478. tickEnter.call(tickTransform, x);
  7479. tickUpdate.call(tickTransform, x);
  7480. }
  7481. });
  7482. }
  7483. axis.scale = function(x) {
  7484. if (!arguments.length) return scale;
  7485. scale = x;
  7486. return axis;
  7487. };
  7488. axis.orient = function(x) {
  7489. if (!arguments.length) return orient;
  7490. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  7491. return axis;
  7492. };
  7493. axis.ticks = function() {
  7494. if (!arguments.length) return tickArguments_;
  7495. tickArguments_ = arguments;
  7496. return axis;
  7497. };
  7498. axis.tickValues = function(x) {
  7499. if (!arguments.length) return tickValues;
  7500. tickValues = x;
  7501. return axis;
  7502. };
  7503. axis.tickFormat = function(x) {
  7504. if (!arguments.length) return tickFormat_;
  7505. tickFormat_ = x;
  7506. return axis;
  7507. };
  7508. axis.tickSize = function(x, y) {
  7509. if (!arguments.length) return tickMajorSize;
  7510. var n = arguments.length - 1;
  7511. tickMajorSize = +x;
  7512. tickMinorSize = n > 1 ? +y : tickMajorSize;
  7513. tickEndSize = n > 0 ? +arguments[n] : tickMajorSize;
  7514. return axis;
  7515. };
  7516. axis.tickPadding = function(x) {
  7517. if (!arguments.length) return tickPadding;
  7518. tickPadding = +x;
  7519. return axis;
  7520. };
  7521. axis.tickSubdivide = function(x) {
  7522. if (!arguments.length) return tickSubdivide;
  7523. tickSubdivide = +x;
  7524. return axis;
  7525. };
  7526. return axis;
  7527. };
  7528. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  7529. top: 1,
  7530. right: 1,
  7531. bottom: 1,
  7532. left: 1
  7533. };
  7534. function d3_svg_axisX(selection, x) {
  7535. selection.attr("transform", function(d) {
  7536. return "translate(" + x(d) + ",0)";
  7537. });
  7538. }
  7539. function d3_svg_axisY(selection, y) {
  7540. selection.attr("transform", function(d) {
  7541. return "translate(0," + y(d) + ")";
  7542. });
  7543. }
  7544. function d3_svg_axisSubdivide(scale, ticks, m) {
  7545. subticks = [];
  7546. if (m && ticks.length > 1) {
  7547. var extent = d3_scaleExtent(scale.domain()), subticks, i = -1, n = ticks.length, d = (ticks[1] - ticks[0]) / ++m, j, v;
  7548. while (++i < n) {
  7549. for (j = m; --j > 0; ) {
  7550. if ((v = +ticks[i] - j * d) >= extent[0]) {
  7551. subticks.push(v);
  7552. }
  7553. }
  7554. }
  7555. for (--i, j = 0; ++j < m && (v = +ticks[i] + j * d) < extent[1]; ) {
  7556. subticks.push(v);
  7557. }
  7558. }
  7559. return subticks;
  7560. }
  7561. d3.svg.brush = function() {
  7562. var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, resizes = d3_svg_brushResizes[0], extent = [ [ 0, 0 ], [ 0, 0 ] ], extentDomain;
  7563. function brush(g) {
  7564. g.each(function() {
  7565. var g = d3.select(this), bg = g.selectAll(".background").data([ 0 ]), fg = g.selectAll(".extent").data([ 0 ]), tz = g.selectAll(".resize").data(resizes, String), e;
  7566. g.style("pointer-events", "all").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
  7567. bg.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  7568. fg.enter().append("rect").attr("class", "extent").style("cursor", "move");
  7569. tz.enter().append("g").attr("class", function(d) {
  7570. return "resize " + d;
  7571. }).style("cursor", function(d) {
  7572. return d3_svg_brushCursor[d];
  7573. }).append("rect").attr("x", function(d) {
  7574. return /[ew]$/.test(d) ? -3 : null;
  7575. }).attr("y", function(d) {
  7576. return /^[ns]/.test(d) ? -3 : null;
  7577. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  7578. tz.style("display", brush.empty() ? "none" : null);
  7579. tz.exit().remove();
  7580. if (x) {
  7581. e = d3_scaleRange(x);
  7582. bg.attr("x", e[0]).attr("width", e[1] - e[0]);
  7583. redrawX(g);
  7584. }
  7585. if (y) {
  7586. e = d3_scaleRange(y);
  7587. bg.attr("y", e[0]).attr("height", e[1] - e[0]);
  7588. redrawY(g);
  7589. }
  7590. redraw(g);
  7591. });
  7592. }
  7593. function redraw(g) {
  7594. g.selectAll(".resize").attr("transform", function(d) {
  7595. return "translate(" + extent[+/e$/.test(d)][0] + "," + extent[+/^s/.test(d)][1] + ")";
  7596. });
  7597. }
  7598. function redrawX(g) {
  7599. g.select(".extent").attr("x", extent[0][0]);
  7600. g.selectAll(".extent,.n>rect,.s>rect").attr("width", extent[1][0] - extent[0][0]);
  7601. }
  7602. function redrawY(g) {
  7603. g.select(".extent").attr("y", extent[0][1]);
  7604. g.selectAll(".extent,.e>rect,.w>rect").attr("height", extent[1][1] - extent[0][1]);
  7605. }
  7606. function brushstart() {
  7607. 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"), center, origin = mouse(), offset;
  7608. var w = d3.select(d3_window).on("mousemove.brush", brushmove).on("mouseup.brush", brushend).on("touchmove.brush", brushmove).on("touchend.brush", brushend).on("keydown.brush", keydown).on("keyup.brush", keyup);
  7609. if (dragging) {
  7610. origin[0] = extent[0][0] - origin[0];
  7611. origin[1] = extent[0][1] - origin[1];
  7612. } else if (resizing) {
  7613. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  7614. offset = [ extent[1 - ex][0] - origin[0], extent[1 - ey][1] - origin[1] ];
  7615. origin[0] = extent[ex][0];
  7616. origin[1] = extent[ey][1];
  7617. } else if (d3.event.altKey) center = origin.slice();
  7618. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  7619. d3.select("body").style("cursor", eventTarget.style("cursor"));
  7620. event_({
  7621. type: "brushstart"
  7622. });
  7623. brushmove();
  7624. d3_eventCancel();
  7625. function mouse() {
  7626. var touches = d3.event.changedTouches;
  7627. return touches ? d3.touches(target, touches)[0] : d3.mouse(target);
  7628. }
  7629. function keydown() {
  7630. if (d3.event.keyCode == 32) {
  7631. if (!dragging) {
  7632. center = null;
  7633. origin[0] -= extent[1][0];
  7634. origin[1] -= extent[1][1];
  7635. dragging = 2;
  7636. }
  7637. d3_eventCancel();
  7638. }
  7639. }
  7640. function keyup() {
  7641. if (d3.event.keyCode == 32 && dragging == 2) {
  7642. origin[0] += extent[1][0];
  7643. origin[1] += extent[1][1];
  7644. dragging = 0;
  7645. d3_eventCancel();
  7646. }
  7647. }
  7648. function brushmove() {
  7649. var point = mouse(), moved = false;
  7650. if (offset) {
  7651. point[0] += offset[0];
  7652. point[1] += offset[1];
  7653. }
  7654. if (!dragging) {
  7655. if (d3.event.altKey) {
  7656. if (!center) center = [ (extent[0][0] + extent[1][0]) / 2, (extent[0][1] + extent[1][1]) / 2 ];
  7657. origin[0] = extent[+(point[0] < center[0])][0];
  7658. origin[1] = extent[+(point[1] < center[1])][1];
  7659. } else center = null;
  7660. }
  7661. if (resizingX && move1(point, x, 0)) {
  7662. redrawX(g);
  7663. moved = true;
  7664. }
  7665. if (resizingY && move1(point, y, 1)) {
  7666. redrawY(g);
  7667. moved = true;
  7668. }
  7669. if (moved) {
  7670. redraw(g);
  7671. event_({
  7672. type: "brush",
  7673. mode: dragging ? "move" : "resize"
  7674. });
  7675. }
  7676. }
  7677. function move1(point, scale, i) {
  7678. var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], size = extent[1][i] - extent[0][i], min, max;
  7679. if (dragging) {
  7680. r0 -= position;
  7681. r1 -= size + position;
  7682. }
  7683. min = Math.max(r0, Math.min(r1, point[i]));
  7684. if (dragging) {
  7685. max = (min += position) + size;
  7686. } else {
  7687. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  7688. if (position < min) {
  7689. max = min;
  7690. min = position;
  7691. } else {
  7692. max = position;
  7693. }
  7694. }
  7695. if (extent[0][i] !== min || extent[1][i] !== max) {
  7696. extentDomain = null;
  7697. extent[0][i] = min;
  7698. extent[1][i] = max;
  7699. return true;
  7700. }
  7701. }
  7702. function brushend() {
  7703. brushmove();
  7704. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  7705. d3.select("body").style("cursor", null);
  7706. 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);
  7707. event_({
  7708. type: "brushend"
  7709. });
  7710. d3_eventCancel();
  7711. }
  7712. }
  7713. brush.x = function(z) {
  7714. if (!arguments.length) return x;
  7715. x = z;
  7716. resizes = d3_svg_brushResizes[!x << 1 | !y];
  7717. return brush;
  7718. };
  7719. brush.y = function(z) {
  7720. if (!arguments.length) return y;
  7721. y = z;
  7722. resizes = d3_svg_brushResizes[!x << 1 | !y];
  7723. return brush;
  7724. };
  7725. brush.extent = function(z) {
  7726. var x0, x1, y0, y1, t;
  7727. if (!arguments.length) {
  7728. z = extentDomain || extent;
  7729. if (x) {
  7730. x0 = z[0][0], x1 = z[1][0];
  7731. if (!extentDomain) {
  7732. x0 = extent[0][0], x1 = extent[1][0];
  7733. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  7734. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  7735. }
  7736. }
  7737. if (y) {
  7738. y0 = z[0][1], y1 = z[1][1];
  7739. if (!extentDomain) {
  7740. y0 = extent[0][1], y1 = extent[1][1];
  7741. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  7742. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  7743. }
  7744. }
  7745. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  7746. }
  7747. extentDomain = [ [ 0, 0 ], [ 0, 0 ] ];
  7748. if (x) {
  7749. x0 = z[0], x1 = z[1];
  7750. if (y) x0 = x0[0], x1 = x1[0];
  7751. extentDomain[0][0] = x0, extentDomain[1][0] = x1;
  7752. if (x.invert) x0 = x(x0), x1 = x(x1);
  7753. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  7754. extent[0][0] = x0 | 0, extent[1][0] = x1 | 0;
  7755. }
  7756. if (y) {
  7757. y0 = z[0], y1 = z[1];
  7758. if (x) y0 = y0[1], y1 = y1[1];
  7759. extentDomain[0][1] = y0, extentDomain[1][1] = y1;
  7760. if (y.invert) y0 = y(y0), y1 = y(y1);
  7761. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  7762. extent[0][1] = y0 | 0, extent[1][1] = y1 | 0;
  7763. }
  7764. return brush;
  7765. };
  7766. brush.clear = function() {
  7767. extentDomain = null;
  7768. extent[0][0] = extent[0][1] = extent[1][0] = extent[1][1] = 0;
  7769. return brush;
  7770. };
  7771. brush.empty = function() {
  7772. return x && extent[0][0] === extent[1][0] || y && extent[0][1] === extent[1][1];
  7773. };
  7774. return d3.rebind(brush, event, "on");
  7775. };
  7776. var d3_svg_brushCursor = {
  7777. n: "ns-resize",
  7778. e: "ew-resize",
  7779. s: "ns-resize",
  7780. w: "ew-resize",
  7781. nw: "nwse-resize",
  7782. ne: "nesw-resize",
  7783. se: "nwse-resize",
  7784. sw: "nesw-resize"
  7785. };
  7786. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  7787. d3.time = {};
  7788. var d3_time = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
  7789. function d3_time_utc() {
  7790. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  7791. }
  7792. d3_time_utc.prototype = {
  7793. getDate: function() {
  7794. return this._.getUTCDate();
  7795. },
  7796. getDay: function() {
  7797. return this._.getUTCDay();
  7798. },
  7799. getFullYear: function() {
  7800. return this._.getUTCFullYear();
  7801. },
  7802. getHours: function() {
  7803. return this._.getUTCHours();
  7804. },
  7805. getMilliseconds: function() {
  7806. return this._.getUTCMilliseconds();
  7807. },
  7808. getMinutes: function() {
  7809. return this._.getUTCMinutes();
  7810. },
  7811. getMonth: function() {
  7812. return this._.getUTCMonth();
  7813. },
  7814. getSeconds: function() {
  7815. return this._.getUTCSeconds();
  7816. },
  7817. getTime: function() {
  7818. return this._.getTime();
  7819. },
  7820. getTimezoneOffset: function() {
  7821. return 0;
  7822. },
  7823. valueOf: function() {
  7824. return this._.valueOf();
  7825. },
  7826. setDate: function() {
  7827. d3_time_prototype.setUTCDate.apply(this._, arguments);
  7828. },
  7829. setDay: function() {
  7830. d3_time_prototype.setUTCDay.apply(this._, arguments);
  7831. },
  7832. setFullYear: function() {
  7833. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  7834. },
  7835. setHours: function() {
  7836. d3_time_prototype.setUTCHours.apply(this._, arguments);
  7837. },
  7838. setMilliseconds: function() {
  7839. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  7840. },
  7841. setMinutes: function() {
  7842. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  7843. },
  7844. setMonth: function() {
  7845. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  7846. },
  7847. setSeconds: function() {
  7848. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  7849. },
  7850. setTime: function() {
  7851. d3_time_prototype.setTime.apply(this._, arguments);
  7852. }
  7853. };
  7854. var d3_time_prototype = Date.prototype;
  7855. var d3_time_formatDateTime = "%a %b %e %X %Y", d3_time_formatDate = "%m/%d/%Y", d3_time_formatTime = "%H:%M:%S";
  7856. var d3_time_days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], d3_time_dayAbbreviations = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], d3_time_monthAbbreviations = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
  7857. function d3_time_interval(local, step, number) {
  7858. function round(date) {
  7859. var d0 = local(date), d1 = offset(d0, 1);
  7860. return date - d0 < d1 - date ? d0 : d1;
  7861. }
  7862. function ceil(date) {
  7863. step(date = local(new d3_time(date - 1)), 1);
  7864. return date;
  7865. }
  7866. function offset(date, k) {
  7867. step(date = new d3_time(+date), k);
  7868. return date;
  7869. }
  7870. function range(t0, t1, dt) {
  7871. var time = ceil(t0), times = [];
  7872. if (dt > 1) {
  7873. while (time < t1) {
  7874. if (!(number(time) % dt)) times.push(new Date(+time));
  7875. step(time, 1);
  7876. }
  7877. } else {
  7878. while (time < t1) times.push(new Date(+time)), step(time, 1);
  7879. }
  7880. return times;
  7881. }
  7882. function range_utc(t0, t1, dt) {
  7883. try {
  7884. d3_time = d3_time_utc;
  7885. var utc = new d3_time_utc();
  7886. utc._ = t0;
  7887. return range(utc, t1, dt);
  7888. } finally {
  7889. d3_time = Date;
  7890. }
  7891. }
  7892. local.floor = local;
  7893. local.round = round;
  7894. local.ceil = ceil;
  7895. local.offset = offset;
  7896. local.range = range;
  7897. var utc = local.utc = d3_time_interval_utc(local);
  7898. utc.floor = utc;
  7899. utc.round = d3_time_interval_utc(round);
  7900. utc.ceil = d3_time_interval_utc(ceil);
  7901. utc.offset = d3_time_interval_utc(offset);
  7902. utc.range = range_utc;
  7903. return local;
  7904. }
  7905. function d3_time_interval_utc(method) {
  7906. return function(date, k) {
  7907. try {
  7908. d3_time = d3_time_utc;
  7909. var utc = new d3_time_utc();
  7910. utc._ = date;
  7911. return method(utc, k)._;
  7912. } finally {
  7913. d3_time = Date;
  7914. }
  7915. };
  7916. }
  7917. d3.time.year = d3_time_interval(function(date) {
  7918. date = d3.time.day(date);
  7919. date.setMonth(0, 1);
  7920. return date;
  7921. }, function(date, offset) {
  7922. date.setFullYear(date.getFullYear() + offset);
  7923. }, function(date) {
  7924. return date.getFullYear();
  7925. });
  7926. d3.time.years = d3.time.year.range;
  7927. d3.time.years.utc = d3.time.year.utc.range;
  7928. d3.time.day = d3_time_interval(function(date) {
  7929. var day = new d3_time(1970, 0);
  7930. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  7931. return day;
  7932. }, function(date, offset) {
  7933. date.setDate(date.getDate() + offset);
  7934. }, function(date) {
  7935. return date.getDate() - 1;
  7936. });
  7937. d3.time.days = d3.time.day.range;
  7938. d3.time.days.utc = d3.time.day.utc.range;
  7939. d3.time.dayOfYear = function(date) {
  7940. var year = d3.time.year(date);
  7941. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  7942. };
  7943. d3_time_daySymbols.forEach(function(day, i) {
  7944. day = day.toLowerCase();
  7945. i = 7 - i;
  7946. var interval = d3.time[day] = d3_time_interval(function(date) {
  7947. (date = d3.time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  7948. return date;
  7949. }, function(date, offset) {
  7950. date.setDate(date.getDate() + Math.floor(offset) * 7);
  7951. }, function(date) {
  7952. var day = d3.time.year(date).getDay();
  7953. return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  7954. });
  7955. d3.time[day + "s"] = interval.range;
  7956. d3.time[day + "s"].utc = interval.utc.range;
  7957. d3.time[day + "OfYear"] = function(date) {
  7958. var day = d3.time.year(date).getDay();
  7959. return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7);
  7960. };
  7961. });
  7962. d3.time.week = d3.time.sunday;
  7963. d3.time.weeks = d3.time.sunday.range;
  7964. d3.time.weeks.utc = d3.time.sunday.utc.range;
  7965. d3.time.weekOfYear = d3.time.sundayOfYear;
  7966. d3.time.format = function(template) {
  7967. var n = template.length;
  7968. function format(date) {
  7969. var string = [], i = -1, j = 0, c, p, f;
  7970. while (++i < n) {
  7971. if (template.charCodeAt(i) === 37) {
  7972. string.push(template.substring(j, i));
  7973. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  7974. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  7975. string.push(c);
  7976. j = i + 1;
  7977. }
  7978. }
  7979. string.push(template.substring(j, i));
  7980. return string.join("");
  7981. }
  7982. format.parse = function(string) {
  7983. var d = {
  7984. y: 1900,
  7985. m: 0,
  7986. d: 1,
  7987. H: 0,
  7988. M: 0,
  7989. S: 0,
  7990. L: 0
  7991. }, i = d3_time_parse(d, template, string, 0);
  7992. if (i != string.length) return null;
  7993. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  7994. var date = new d3_time();
  7995. date.setFullYear(d.y, d.m, d.d);
  7996. date.setHours(d.H, d.M, d.S, d.L);
  7997. return date;
  7998. };
  7999. format.toString = function() {
  8000. return template;
  8001. };
  8002. return format;
  8003. };
  8004. function d3_time_parse(date, template, string, j) {
  8005. var c, p, i = 0, n = template.length, m = string.length;
  8006. while (i < n) {
  8007. if (j >= m) return -1;
  8008. c = template.charCodeAt(i++);
  8009. if (c === 37) {
  8010. p = d3_time_parsers[template.charAt(i++)];
  8011. if (!p || (j = p(date, string, j)) < 0) return -1;
  8012. } else if (c != string.charCodeAt(j++)) {
  8013. return -1;
  8014. }
  8015. }
  8016. return j;
  8017. }
  8018. function d3_time_formatRe(names) {
  8019. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  8020. }
  8021. function d3_time_formatLookup(names) {
  8022. var map = new d3_Map(), i = -1, n = names.length;
  8023. while (++i < n) map.set(names[i].toLowerCase(), i);
  8024. return map;
  8025. }
  8026. function d3_time_formatPad(value, fill, width) {
  8027. value += "";
  8028. var length = value.length;
  8029. return length < width ? new Array(width - length + 1).join(fill) + value : value;
  8030. }
  8031. var d3_time_dayRe = d3_time_formatRe(d3_time_days), d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations), d3_time_monthRe = d3_time_formatRe(d3_time_months), d3_time_monthLookup = d3_time_formatLookup(d3_time_months), d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations), d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations);
  8032. var d3_time_formatPads = {
  8033. "-": "",
  8034. _: " ",
  8035. "0": "0"
  8036. };
  8037. var d3_time_formats = {
  8038. a: function(d) {
  8039. return d3_time_dayAbbreviations[d.getDay()];
  8040. },
  8041. A: function(d) {
  8042. return d3_time_days[d.getDay()];
  8043. },
  8044. b: function(d) {
  8045. return d3_time_monthAbbreviations[d.getMonth()];
  8046. },
  8047. B: function(d) {
  8048. return d3_time_months[d.getMonth()];
  8049. },
  8050. c: d3.time.format(d3_time_formatDateTime),
  8051. d: function(d, p) {
  8052. return d3_time_formatPad(d.getDate(), p, 2);
  8053. },
  8054. e: function(d, p) {
  8055. return d3_time_formatPad(d.getDate(), p, 2);
  8056. },
  8057. H: function(d, p) {
  8058. return d3_time_formatPad(d.getHours(), p, 2);
  8059. },
  8060. I: function(d, p) {
  8061. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  8062. },
  8063. j: function(d, p) {
  8064. return d3_time_formatPad(1 + d3.time.dayOfYear(d), p, 3);
  8065. },
  8066. L: function(d, p) {
  8067. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  8068. },
  8069. m: function(d, p) {
  8070. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  8071. },
  8072. M: function(d, p) {
  8073. return d3_time_formatPad(d.getMinutes(), p, 2);
  8074. },
  8075. p: function(d) {
  8076. return d.getHours() >= 12 ? "PM" : "AM";
  8077. },
  8078. S: function(d, p) {
  8079. return d3_time_formatPad(d.getSeconds(), p, 2);
  8080. },
  8081. U: function(d, p) {
  8082. return d3_time_formatPad(d3.time.sundayOfYear(d), p, 2);
  8083. },
  8084. w: function(d) {
  8085. return d.getDay();
  8086. },
  8087. W: function(d, p) {
  8088. return d3_time_formatPad(d3.time.mondayOfYear(d), p, 2);
  8089. },
  8090. x: d3.time.format(d3_time_formatDate),
  8091. X: d3.time.format(d3_time_formatTime),
  8092. y: function(d, p) {
  8093. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  8094. },
  8095. Y: function(d, p) {
  8096. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  8097. },
  8098. Z: d3_time_zone,
  8099. "%": function() {
  8100. return "%";
  8101. }
  8102. };
  8103. var d3_time_parsers = {
  8104. a: d3_time_parseWeekdayAbbrev,
  8105. A: d3_time_parseWeekday,
  8106. b: d3_time_parseMonthAbbrev,
  8107. B: d3_time_parseMonth,
  8108. c: d3_time_parseLocaleFull,
  8109. d: d3_time_parseDay,
  8110. e: d3_time_parseDay,
  8111. H: d3_time_parseHour24,
  8112. I: d3_time_parseHour24,
  8113. L: d3_time_parseMilliseconds,
  8114. m: d3_time_parseMonthNumber,
  8115. M: d3_time_parseMinutes,
  8116. p: d3_time_parseAmPm,
  8117. S: d3_time_parseSeconds,
  8118. x: d3_time_parseLocaleDate,
  8119. X: d3_time_parseLocaleTime,
  8120. y: d3_time_parseYear,
  8121. Y: d3_time_parseFullYear
  8122. };
  8123. function d3_time_parseWeekdayAbbrev(date, string, i) {
  8124. d3_time_dayAbbrevRe.lastIndex = 0;
  8125. var n = d3_time_dayAbbrevRe.exec(string.substring(i));
  8126. return n ? i += n[0].length : -1;
  8127. }
  8128. function d3_time_parseWeekday(date, string, i) {
  8129. d3_time_dayRe.lastIndex = 0;
  8130. var n = d3_time_dayRe.exec(string.substring(i));
  8131. return n ? i += n[0].length : -1;
  8132. }
  8133. function d3_time_parseMonthAbbrev(date, string, i) {
  8134. d3_time_monthAbbrevRe.lastIndex = 0;
  8135. var n = d3_time_monthAbbrevRe.exec(string.substring(i));
  8136. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
  8137. }
  8138. function d3_time_parseMonth(date, string, i) {
  8139. d3_time_monthRe.lastIndex = 0;
  8140. var n = d3_time_monthRe.exec(string.substring(i));
  8141. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
  8142. }
  8143. function d3_time_parseLocaleFull(date, string, i) {
  8144. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  8145. }
  8146. function d3_time_parseLocaleDate(date, string, i) {
  8147. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  8148. }
  8149. function d3_time_parseLocaleTime(date, string, i) {
  8150. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  8151. }
  8152. function d3_time_parseFullYear(date, string, i) {
  8153. d3_time_numberRe.lastIndex = 0;
  8154. var n = d3_time_numberRe.exec(string.substring(i, i + 4));
  8155. return n ? (date.y = +n[0], i += n[0].length) : -1;
  8156. }
  8157. function d3_time_parseYear(date, string, i) {
  8158. d3_time_numberRe.lastIndex = 0;
  8159. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8160. return n ? (date.y = d3_time_expandYear(+n[0]), i += n[0].length) : -1;
  8161. }
  8162. function d3_time_expandYear(d) {
  8163. return d + (d > 68 ? 1900 : 2e3);
  8164. }
  8165. function d3_time_parseMonthNumber(date, string, i) {
  8166. d3_time_numberRe.lastIndex = 0;
  8167. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8168. return n ? (date.m = n[0] - 1, i += n[0].length) : -1;
  8169. }
  8170. function d3_time_parseDay(date, string, i) {
  8171. d3_time_numberRe.lastIndex = 0;
  8172. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8173. return n ? (date.d = +n[0], i += n[0].length) : -1;
  8174. }
  8175. function d3_time_parseHour24(date, string, i) {
  8176. d3_time_numberRe.lastIndex = 0;
  8177. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8178. return n ? (date.H = +n[0], i += n[0].length) : -1;
  8179. }
  8180. function d3_time_parseMinutes(date, string, i) {
  8181. d3_time_numberRe.lastIndex = 0;
  8182. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8183. return n ? (date.M = +n[0], i += n[0].length) : -1;
  8184. }
  8185. function d3_time_parseSeconds(date, string, i) {
  8186. d3_time_numberRe.lastIndex = 0;
  8187. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8188. return n ? (date.S = +n[0], i += n[0].length) : -1;
  8189. }
  8190. function d3_time_parseMilliseconds(date, string, i) {
  8191. d3_time_numberRe.lastIndex = 0;
  8192. var n = d3_time_numberRe.exec(string.substring(i, i + 3));
  8193. return n ? (date.L = +n[0], i += n[0].length) : -1;
  8194. }
  8195. var d3_time_numberRe = /^\s*\d+/;
  8196. function d3_time_parseAmPm(date, string, i) {
  8197. var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
  8198. return n == null ? -1 : (date.p = n, i);
  8199. }
  8200. var d3_time_amPmLookup = d3.map({
  8201. am: 0,
  8202. pm: 1
  8203. });
  8204. function d3_time_zone(d) {
  8205. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(Math.abs(z) / 60), zm = Math.abs(z) % 60;
  8206. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  8207. }
  8208. d3.time.format.utc = function(template) {
  8209. var local = d3.time.format(template);
  8210. function format(date) {
  8211. try {
  8212. d3_time = d3_time_utc;
  8213. var utc = new d3_time();
  8214. utc._ = date;
  8215. return local(utc);
  8216. } finally {
  8217. d3_time = Date;
  8218. }
  8219. }
  8220. format.parse = function(string) {
  8221. try {
  8222. d3_time = d3_time_utc;
  8223. var date = local.parse(string);
  8224. return date && date._;
  8225. } finally {
  8226. d3_time = Date;
  8227. }
  8228. };
  8229. format.toString = local.toString;
  8230. return format;
  8231. };
  8232. var d3_time_formatIso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");
  8233. d3.time.format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  8234. function d3_time_formatIsoNative(date) {
  8235. return date.toISOString();
  8236. }
  8237. d3_time_formatIsoNative.parse = function(string) {
  8238. var date = new Date(string);
  8239. return isNaN(date) ? null : date;
  8240. };
  8241. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  8242. d3.time.second = d3_time_interval(function(date) {
  8243. return new d3_time(Math.floor(date / 1e3) * 1e3);
  8244. }, function(date, offset) {
  8245. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  8246. }, function(date) {
  8247. return date.getSeconds();
  8248. });
  8249. d3.time.seconds = d3.time.second.range;
  8250. d3.time.seconds.utc = d3.time.second.utc.range;
  8251. d3.time.minute = d3_time_interval(function(date) {
  8252. return new d3_time(Math.floor(date / 6e4) * 6e4);
  8253. }, function(date, offset) {
  8254. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  8255. }, function(date) {
  8256. return date.getMinutes();
  8257. });
  8258. d3.time.minutes = d3.time.minute.range;
  8259. d3.time.minutes.utc = d3.time.minute.utc.range;
  8260. d3.time.hour = d3_time_interval(function(date) {
  8261. var timezone = date.getTimezoneOffset() / 60;
  8262. return new d3_time((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  8263. }, function(date, offset) {
  8264. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  8265. }, function(date) {
  8266. return date.getHours();
  8267. });
  8268. d3.time.hours = d3.time.hour.range;
  8269. d3.time.hours.utc = d3.time.hour.utc.range;
  8270. d3.time.month = d3_time_interval(function(date) {
  8271. date = d3.time.day(date);
  8272. date.setDate(1);
  8273. return date;
  8274. }, function(date, offset) {
  8275. date.setMonth(date.getMonth() + offset);
  8276. }, function(date) {
  8277. return date.getMonth();
  8278. });
  8279. d3.time.months = d3.time.month.range;
  8280. d3.time.months.utc = d3.time.month.utc.range;
  8281. function d3_time_scale(linear, methods, format) {
  8282. function scale(x) {
  8283. return linear(x);
  8284. }
  8285. scale.invert = function(x) {
  8286. return d3_time_scaleDate(linear.invert(x));
  8287. };
  8288. scale.domain = function(x) {
  8289. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  8290. linear.domain(x);
  8291. return scale;
  8292. };
  8293. scale.nice = function(m) {
  8294. return scale.domain(d3_scale_nice(scale.domain(), function() {
  8295. return m;
  8296. }));
  8297. };
  8298. scale.ticks = function(m, k) {
  8299. var extent = d3_time_scaleExtent(scale.domain());
  8300. if (typeof m !== "function") {
  8301. var span = extent[1] - extent[0], target = span / m, i = d3.bisect(d3_time_scaleSteps, target);
  8302. if (i == d3_time_scaleSteps.length) return methods.year(extent, m);
  8303. if (!i) return linear.ticks(m).map(d3_time_scaleDate);
  8304. if (Math.log(target / d3_time_scaleSteps[i - 1]) < Math.log(d3_time_scaleSteps[i] / target)) --i;
  8305. m = methods[i];
  8306. k = m[1];
  8307. m = m[0].range;
  8308. }
  8309. return m(extent[0], new Date(+extent[1] + 1), k);
  8310. };
  8311. scale.tickFormat = function() {
  8312. return format;
  8313. };
  8314. scale.copy = function() {
  8315. return d3_time_scale(linear.copy(), methods, format);
  8316. };
  8317. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  8318. }
  8319. function d3_time_scaleExtent(domain) {
  8320. var start = domain[0], stop = domain[domain.length - 1];
  8321. return start < stop ? [ start, stop ] : [ stop, start ];
  8322. }
  8323. function d3_time_scaleDate(t) {
  8324. return new Date(t);
  8325. }
  8326. function d3_time_scaleFormat(formats) {
  8327. return function(date) {
  8328. var i = formats.length - 1, f = formats[i];
  8329. while (!f[1](date)) f = formats[--i];
  8330. return f[0](date);
  8331. };
  8332. }
  8333. function d3_time_scaleSetYear(y) {
  8334. var d = new Date(y, 0, 1);
  8335. d.setFullYear(y);
  8336. return d;
  8337. }
  8338. function d3_time_scaleGetYear(d) {
  8339. var y = d.getFullYear(), d0 = d3_time_scaleSetYear(y), d1 = d3_time_scaleSetYear(y + 1);
  8340. return y + (d - d0) / (d1 - d0);
  8341. }
  8342. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  8343. 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 ] ];
  8344. var d3_time_scaleLocalFormats = [ [ d3.time.format("%Y"), d3_true ], [ d3.time.format("%B"), function(d) {
  8345. return d.getMonth();
  8346. } ], [ d3.time.format("%b %d"), function(d) {
  8347. return d.getDate() != 1;
  8348. } ], [ d3.time.format("%a %d"), function(d) {
  8349. return d.getDay() && d.getDate() != 1;
  8350. } ], [ d3.time.format("%I %p"), function(d) {
  8351. return d.getHours();
  8352. } ], [ d3.time.format("%I:%M"), function(d) {
  8353. return d.getMinutes();
  8354. } ], [ d3.time.format(":%S"), function(d) {
  8355. return d.getSeconds();
  8356. } ], [ d3.time.format(".%L"), function(d) {
  8357. return d.getMilliseconds();
  8358. } ] ];
  8359. var d3_time_scaleLinear = d3.scale.linear(), d3_time_scaleLocalFormat = d3_time_scaleFormat(d3_time_scaleLocalFormats);
  8360. d3_time_scaleLocalMethods.year = function(extent, m) {
  8361. return d3_time_scaleLinear.domain(extent.map(d3_time_scaleGetYear)).ticks(m).map(d3_time_scaleSetYear);
  8362. };
  8363. d3.time.scale = function() {
  8364. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  8365. };
  8366. var d3_time_scaleUTCMethods = d3_time_scaleLocalMethods.map(function(m) {
  8367. return [ m[0].utc, m[1] ];
  8368. });
  8369. var d3_time_scaleUTCFormats = [ [ d3.time.format.utc("%Y"), d3_true ], [ d3.time.format.utc("%B"), function(d) {
  8370. return d.getUTCMonth();
  8371. } ], [ d3.time.format.utc("%b %d"), function(d) {
  8372. return d.getUTCDate() != 1;
  8373. } ], [ d3.time.format.utc("%a %d"), function(d) {
  8374. return d.getUTCDay() && d.getUTCDate() != 1;
  8375. } ], [ d3.time.format.utc("%I %p"), function(d) {
  8376. return d.getUTCHours();
  8377. } ], [ d3.time.format.utc("%I:%M"), function(d) {
  8378. return d.getUTCMinutes();
  8379. } ], [ d3.time.format.utc(":%S"), function(d) {
  8380. return d.getUTCSeconds();
  8381. } ], [ d3.time.format.utc(".%L"), function(d) {
  8382. return d.getUTCMilliseconds();
  8383. } ] ];
  8384. var d3_time_scaleUTCFormat = d3_time_scaleFormat(d3_time_scaleUTCFormats);
  8385. function d3_time_scaleUTCSetYear(y) {
  8386. var d = new Date(Date.UTC(y, 0, 1));
  8387. d.setUTCFullYear(y);
  8388. return d;
  8389. }
  8390. function d3_time_scaleUTCGetYear(d) {
  8391. var y = d.getUTCFullYear(), d0 = d3_time_scaleUTCSetYear(y), d1 = d3_time_scaleUTCSetYear(y + 1);
  8392. return y + (d - d0) / (d1 - d0);
  8393. }
  8394. d3_time_scaleUTCMethods.year = function(extent, m) {
  8395. return d3_time_scaleLinear.domain(extent.map(d3_time_scaleUTCGetYear)).ticks(m).map(d3_time_scaleUTCSetYear);
  8396. };
  8397. d3.time.scale.utc = function() {
  8398. return d3_time_scale(d3.scale.linear(), d3_time_scaleUTCMethods, d3_time_scaleUTCFormat);
  8399. };
  8400. d3.text = function() {
  8401. return d3.xhr.apply(d3, arguments).response(d3_text);
  8402. };
  8403. function d3_text(request) {
  8404. return request.responseText;
  8405. }
  8406. d3.json = function(url, callback) {
  8407. return d3.xhr(url, "application/json", callback).response(d3_json);
  8408. };
  8409. function d3_json(request) {
  8410. return JSON.parse(request.responseText);
  8411. }
  8412. d3.html = function(url, callback) {
  8413. return d3.xhr(url, "text/html", callback).response(d3_html);
  8414. };
  8415. function d3_html(request) {
  8416. var range = d3_document.createRange();
  8417. range.selectNode(d3_document.body);
  8418. return range.createContextualFragment(request.responseText);
  8419. }
  8420. d3.xml = function() {
  8421. return d3.xhr.apply(d3, arguments).response(d3_xml);
  8422. };
  8423. function d3_xml(request) {
  8424. return request.responseXML;
  8425. }
  8426. return d3;
  8427. }();