d3.v3.js 332 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585
  1. // Downloaded from http://d3js.org/d3.v3.js
  2. //
  3. // Copyright 2010-2016 Mike Bostock
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without modification,
  7. // are permitted provided that the following conditions are met:
  8. //
  9. // * Redistributions of source code must retain the above copyright notice, this
  10. // list of conditions and the following disclaimer.
  11. //
  12. // * Redistributions in binary form must reproduce the above copyright notice,
  13. // this list of conditions and the following disclaimer in the documentation
  14. // and/or other materials provided with the distribution.
  15. //
  16. // * Neither the name of the author nor the names of contributors may be used to
  17. // endorse or promote products derived from this software without specific prior
  18. // written permission.
  19. //
  20. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  21. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  24. // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  27. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. !function() {
  31. var d3 = {
  32. version: "3.5.17"
  33. };
  34. var d3_arraySlice = [].slice, d3_array = function(list) {
  35. return d3_arraySlice.call(list);
  36. };
  37. var d3_document = this.document;
  38. function d3_documentElement(node) {
  39. return node && (node.ownerDocument || node.document || node).documentElement;
  40. }
  41. function d3_window(node) {
  42. return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
  43. }
  44. if (d3_document) {
  45. try {
  46. d3_array(d3_document.documentElement.childNodes)[0].nodeType;
  47. } catch (e) {
  48. d3_array = function(list) {
  49. var i = list.length, array = new Array(i);
  50. while (i--) array[i] = list[i];
  51. return array;
  52. };
  53. }
  54. }
  55. if (!Date.now) Date.now = function() {
  56. return +new Date();
  57. };
  58. if (d3_document) {
  59. try {
  60. d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
  61. } catch (error) {
  62. var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
  63. d3_element_prototype.setAttribute = function(name, value) {
  64. d3_element_setAttribute.call(this, name, value + "");
  65. };
  66. d3_element_prototype.setAttributeNS = function(space, local, value) {
  67. d3_element_setAttributeNS.call(this, space, local, value + "");
  68. };
  69. d3_style_prototype.setProperty = function(name, value, priority) {
  70. d3_style_setProperty.call(this, name, value + "", priority);
  71. };
  72. }
  73. }
  74. d3.ascending = d3_ascending;
  75. function d3_ascending(a, b) {
  76. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  77. }
  78. d3.descending = function(a, b) {
  79. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  80. };
  81. d3.min = function(array, f) {
  82. var i = -1, n = array.length, a, b;
  83. if (arguments.length === 1) {
  84. while (++i < n) if ((b = array[i]) != null && b >= b) {
  85. a = b;
  86. break;
  87. }
  88. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  89. } else {
  90. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  91. a = b;
  92. break;
  93. }
  94. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  95. }
  96. return a;
  97. };
  98. d3.max = function(array, f) {
  99. var i = -1, n = array.length, a, b;
  100. if (arguments.length === 1) {
  101. while (++i < n) if ((b = array[i]) != null && b >= b) {
  102. a = b;
  103. break;
  104. }
  105. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  106. } else {
  107. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  108. a = b;
  109. break;
  110. }
  111. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  112. }
  113. return a;
  114. };
  115. d3.extent = function(array, f) {
  116. var i = -1, n = array.length, a, b, c;
  117. if (arguments.length === 1) {
  118. while (++i < n) if ((b = array[i]) != null && b >= b) {
  119. a = c = b;
  120. break;
  121. }
  122. while (++i < n) if ((b = array[i]) != null) {
  123. if (a > b) a = b;
  124. if (c < b) c = b;
  125. }
  126. } else {
  127. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  128. a = c = b;
  129. break;
  130. }
  131. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  132. if (a > b) a = b;
  133. if (c < b) c = b;
  134. }
  135. }
  136. return [ a, c ];
  137. };
  138. function d3_number(x) {
  139. return x === null ? NaN : +x;
  140. }
  141. function d3_numeric(x) {
  142. return !isNaN(x);
  143. }
  144. d3.sum = function(array, f) {
  145. var s = 0, n = array.length, a, i = -1;
  146. if (arguments.length === 1) {
  147. while (++i < n) if (d3_numeric(a = +array[i])) s += a;
  148. } else {
  149. while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
  150. }
  151. return s;
  152. };
  153. d3.mean = function(array, f) {
  154. var s = 0, n = array.length, a, i = -1, j = n;
  155. if (arguments.length === 1) {
  156. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
  157. } else {
  158. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
  159. }
  160. if (j) return s / j;
  161. };
  162. d3.quantile = function(values, p) {
  163. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  164. return e ? v + e * (values[h] - v) : v;
  165. };
  166. d3.median = function(array, f) {
  167. var numbers = [], n = array.length, a, i = -1;
  168. if (arguments.length === 1) {
  169. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
  170. } else {
  171. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
  172. }
  173. if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
  174. };
  175. d3.variance = function(array, f) {
  176. var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
  177. if (arguments.length === 1) {
  178. while (++i < n) {
  179. if (d3_numeric(a = d3_number(array[i]))) {
  180. d = a - m;
  181. m += d / ++j;
  182. s += d * (a - m);
  183. }
  184. }
  185. } else {
  186. while (++i < n) {
  187. if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
  188. d = a - m;
  189. m += d / ++j;
  190. s += d * (a - m);
  191. }
  192. }
  193. }
  194. if (j > 1) return s / (j - 1);
  195. };
  196. d3.deviation = function() {
  197. var v = d3.variance.apply(this, arguments);
  198. return v ? Math.sqrt(v) : v;
  199. };
  200. function d3_bisector(compare) {
  201. return {
  202. left: function(a, x, lo, hi) {
  203. if (arguments.length < 3) lo = 0;
  204. if (arguments.length < 4) hi = a.length;
  205. while (lo < hi) {
  206. var mid = lo + hi >>> 1;
  207. if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
  208. }
  209. return lo;
  210. },
  211. right: function(a, x, lo, hi) {
  212. if (arguments.length < 3) lo = 0;
  213. if (arguments.length < 4) hi = a.length;
  214. while (lo < hi) {
  215. var mid = lo + hi >>> 1;
  216. if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
  217. }
  218. return lo;
  219. }
  220. };
  221. }
  222. var d3_bisect = d3_bisector(d3_ascending);
  223. d3.bisectLeft = d3_bisect.left;
  224. d3.bisect = d3.bisectRight = d3_bisect.right;
  225. d3.bisector = function(f) {
  226. return d3_bisector(f.length === 1 ? function(d, x) {
  227. return d3_ascending(f(d), x);
  228. } : f);
  229. };
  230. d3.shuffle = function(array, i0, i1) {
  231. if ((m = arguments.length) < 3) {
  232. i1 = array.length;
  233. if (m < 2) i0 = 0;
  234. }
  235. var m = i1 - i0, t, i;
  236. while (m) {
  237. i = Math.random() * m-- | 0;
  238. t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
  239. }
  240. return array;
  241. };
  242. d3.permute = function(array, indexes) {
  243. var i = indexes.length, permutes = new Array(i);
  244. while (i--) permutes[i] = array[indexes[i]];
  245. return permutes;
  246. };
  247. d3.pairs = function(array) {
  248. var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
  249. while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
  250. return pairs;
  251. };
  252. d3.transpose = function(matrix) {
  253. if (!(n = matrix.length)) return [];
  254. for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m; ) {
  255. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n; ) {
  256. row[j] = matrix[j][i];
  257. }
  258. }
  259. return transpose;
  260. };
  261. function d3_transposeLength(d) {
  262. return d.length;
  263. }
  264. d3.zip = function() {
  265. return d3.transpose(arguments);
  266. };
  267. d3.keys = function(map) {
  268. var keys = [];
  269. for (var key in map) keys.push(key);
  270. return keys;
  271. };
  272. d3.values = function(map) {
  273. var values = [];
  274. for (var key in map) values.push(map[key]);
  275. return values;
  276. };
  277. d3.entries = function(map) {
  278. var entries = [];
  279. for (var key in map) entries.push({
  280. key: key,
  281. value: map[key]
  282. });
  283. return entries;
  284. };
  285. d3.merge = function(arrays) {
  286. var n = arrays.length, m, i = -1, j = 0, merged, array;
  287. while (++i < n) j += arrays[i].length;
  288. merged = new Array(j);
  289. while (--n >= 0) {
  290. array = arrays[n];
  291. m = array.length;
  292. while (--m >= 0) {
  293. merged[--j] = array[m];
  294. }
  295. }
  296. return merged;
  297. };
  298. var abs = Math.abs;
  299. d3.range = function(start, stop, step) {
  300. if (arguments.length < 3) {
  301. step = 1;
  302. if (arguments.length < 2) {
  303. stop = start;
  304. start = 0;
  305. }
  306. }
  307. if ((stop - start) / step === Infinity) throw new Error("infinite range");
  308. var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
  309. start *= k, stop *= k, step *= k;
  310. if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
  311. return range;
  312. };
  313. function d3_range_integerScale(x) {
  314. var k = 1;
  315. while (x * k % 1) k *= 10;
  316. return k;
  317. }
  318. function d3_class(ctor, properties) {
  319. for (var key in properties) {
  320. Object.defineProperty(ctor.prototype, key, {
  321. value: properties[key],
  322. enumerable: false
  323. });
  324. }
  325. }
  326. d3.map = function(object, f) {
  327. var map = new d3_Map();
  328. if (object instanceof d3_Map) {
  329. object.forEach(function(key, value) {
  330. map.set(key, value);
  331. });
  332. } else if (Array.isArray(object)) {
  333. var i = -1, n = object.length, o;
  334. if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
  335. } else {
  336. for (var key in object) map.set(key, object[key]);
  337. }
  338. return map;
  339. };
  340. function d3_Map() {
  341. this._ = Object.create(null);
  342. }
  343. var d3_map_proto = "__proto__", d3_map_zero = "\x00";
  344. d3_class(d3_Map, {
  345. has: d3_map_has,
  346. get: function(key) {
  347. return this._[d3_map_escape(key)];
  348. },
  349. set: function(key, value) {
  350. return this._[d3_map_escape(key)] = value;
  351. },
  352. remove: d3_map_remove,
  353. keys: d3_map_keys,
  354. values: function() {
  355. var values = [];
  356. for (var key in this._) values.push(this._[key]);
  357. return values;
  358. },
  359. entries: function() {
  360. var entries = [];
  361. for (var key in this._) entries.push({
  362. key: d3_map_unescape(key),
  363. value: this._[key]
  364. });
  365. return entries;
  366. },
  367. size: d3_map_size,
  368. empty: d3_map_empty,
  369. forEach: function(f) {
  370. for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
  371. }
  372. });
  373. function d3_map_escape(key) {
  374. return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
  375. }
  376. function d3_map_unescape(key) {
  377. return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
  378. }
  379. function d3_map_has(key) {
  380. return d3_map_escape(key) in this._;
  381. }
  382. function d3_map_remove(key) {
  383. return (key = d3_map_escape(key)) in this._ && delete this._[key];
  384. }
  385. function d3_map_keys() {
  386. var keys = [];
  387. for (var key in this._) keys.push(d3_map_unescape(key));
  388. return keys;
  389. }
  390. function d3_map_size() {
  391. var size = 0;
  392. for (var key in this._) ++size;
  393. return size;
  394. }
  395. function d3_map_empty() {
  396. for (var key in this._) return false;
  397. return true;
  398. }
  399. d3.nest = function() {
  400. var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
  401. function map(mapType, array, depth) {
  402. if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
  403. var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
  404. while (++i < n) {
  405. if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
  406. values.push(object);
  407. } else {
  408. valuesByKey.set(keyValue, [ object ]);
  409. }
  410. }
  411. if (mapType) {
  412. object = mapType();
  413. setter = function(keyValue, values) {
  414. object.set(keyValue, map(mapType, values, depth));
  415. };
  416. } else {
  417. object = {};
  418. setter = function(keyValue, values) {
  419. object[keyValue] = map(mapType, values, depth);
  420. };
  421. }
  422. valuesByKey.forEach(setter);
  423. return object;
  424. }
  425. function entries(map, depth) {
  426. if (depth >= keys.length) return map;
  427. var array = [], sortKey = sortKeys[depth++];
  428. map.forEach(function(key, keyMap) {
  429. array.push({
  430. key: key,
  431. values: entries(keyMap, depth)
  432. });
  433. });
  434. return sortKey ? array.sort(function(a, b) {
  435. return sortKey(a.key, b.key);
  436. }) : array;
  437. }
  438. nest.map = function(array, mapType) {
  439. return map(mapType, array, 0);
  440. };
  441. nest.entries = function(array) {
  442. return entries(map(d3.map, array, 0), 0);
  443. };
  444. nest.key = function(d) {
  445. keys.push(d);
  446. return nest;
  447. };
  448. nest.sortKeys = function(order) {
  449. sortKeys[keys.length - 1] = order;
  450. return nest;
  451. };
  452. nest.sortValues = function(order) {
  453. sortValues = order;
  454. return nest;
  455. };
  456. nest.rollup = function(f) {
  457. rollup = f;
  458. return nest;
  459. };
  460. return nest;
  461. };
  462. d3.set = function(array) {
  463. var set = new d3_Set();
  464. if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
  465. return set;
  466. };
  467. function d3_Set() {
  468. this._ = Object.create(null);
  469. }
  470. d3_class(d3_Set, {
  471. has: d3_map_has,
  472. add: function(key) {
  473. this._[d3_map_escape(key += "")] = true;
  474. return key;
  475. },
  476. remove: d3_map_remove,
  477. values: d3_map_keys,
  478. size: d3_map_size,
  479. empty: d3_map_empty,
  480. forEach: function(f) {
  481. for (var key in this._) f.call(this, d3_map_unescape(key));
  482. }
  483. });
  484. d3.behavior = {};
  485. function d3_identity(d) {
  486. return d;
  487. }
  488. d3.rebind = function(target, source) {
  489. var i = 1, n = arguments.length, method;
  490. while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
  491. return target;
  492. };
  493. function d3_rebind(target, source, method) {
  494. return function() {
  495. var value = method.apply(source, arguments);
  496. return value === source ? target : value;
  497. };
  498. }
  499. function d3_vendorSymbol(object, name) {
  500. if (name in object) return name;
  501. name = name.charAt(0).toUpperCase() + name.slice(1);
  502. for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
  503. var prefixName = d3_vendorPrefixes[i] + name;
  504. if (prefixName in object) return prefixName;
  505. }
  506. }
  507. var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
  508. function d3_noop() {}
  509. d3.dispatch = function() {
  510. var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
  511. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  512. return dispatch;
  513. };
  514. function d3_dispatch() {}
  515. d3_dispatch.prototype.on = function(type, listener) {
  516. var i = type.indexOf("."), name = "";
  517. if (i >= 0) {
  518. name = type.slice(i + 1);
  519. type = type.slice(0, i);
  520. }
  521. if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
  522. if (arguments.length === 2) {
  523. if (listener == null) for (type in this) {
  524. if (this.hasOwnProperty(type)) this[type].on(name, null);
  525. }
  526. return this;
  527. }
  528. };
  529. function d3_dispatch_event(dispatch) {
  530. var listeners = [], listenerByName = new d3_Map();
  531. function event() {
  532. var z = listeners, i = -1, n = z.length, l;
  533. while (++i < n) if (l = z[i].on) l.apply(this, arguments);
  534. return dispatch;
  535. }
  536. event.on = function(name, listener) {
  537. var l = listenerByName.get(name), i;
  538. if (arguments.length < 2) return l && l.on;
  539. if (l) {
  540. l.on = null;
  541. listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
  542. listenerByName.remove(name);
  543. }
  544. if (listener) listeners.push(listenerByName.set(name, {
  545. on: listener
  546. }));
  547. return dispatch;
  548. };
  549. return event;
  550. }
  551. d3.event = null;
  552. function d3_eventPreventDefault() {
  553. d3.event.preventDefault();
  554. }
  555. function d3_eventSource() {
  556. var e = d3.event, s;
  557. while (s = e.sourceEvent) e = s;
  558. return e;
  559. }
  560. function d3_eventDispatch(target) {
  561. var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
  562. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  563. dispatch.of = function(thiz, argumentz) {
  564. return function(e1) {
  565. try {
  566. var e0 = e1.sourceEvent = d3.event;
  567. e1.target = target;
  568. d3.event = e1;
  569. dispatch[e1.type].apply(thiz, argumentz);
  570. } finally {
  571. d3.event = e0;
  572. }
  573. };
  574. };
  575. return dispatch;
  576. }
  577. d3.requote = function(s) {
  578. return s.replace(d3_requote_re, "\\$&");
  579. };
  580. var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  581. var d3_subclass = {}.__proto__ ? function(object, prototype) {
  582. object.__proto__ = prototype;
  583. } : function(object, prototype) {
  584. for (var property in prototype) object[property] = prototype[property];
  585. };
  586. function d3_selection(groups) {
  587. d3_subclass(groups, d3_selectionPrototype);
  588. return groups;
  589. }
  590. var d3_select = function(s, n) {
  591. return n.querySelector(s);
  592. }, d3_selectAll = function(s, n) {
  593. return n.querySelectorAll(s);
  594. }, d3_selectMatches = function(n, s) {
  595. var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
  596. d3_selectMatches = function(n, s) {
  597. return d3_selectMatcher.call(n, s);
  598. };
  599. return d3_selectMatches(n, s);
  600. };
  601. if (typeof Sizzle === "function") {
  602. d3_select = function(s, n) {
  603. return Sizzle(s, n)[0] || null;
  604. };
  605. d3_selectAll = Sizzle;
  606. d3_selectMatches = Sizzle.matchesSelector;
  607. }
  608. d3.selection = function() {
  609. return d3.select(d3_document.documentElement);
  610. };
  611. var d3_selectionPrototype = d3.selection.prototype = [];
  612. d3_selectionPrototype.select = function(selector) {
  613. var subgroups = [], subgroup, subnode, group, node;
  614. selector = d3_selection_selector(selector);
  615. for (var j = -1, m = this.length; ++j < m; ) {
  616. subgroups.push(subgroup = []);
  617. subgroup.parentNode = (group = this[j]).parentNode;
  618. for (var i = -1, n = group.length; ++i < n; ) {
  619. if (node = group[i]) {
  620. subgroup.push(subnode = selector.call(node, node.__data__, i, j));
  621. if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
  622. } else {
  623. subgroup.push(null);
  624. }
  625. }
  626. }
  627. return d3_selection(subgroups);
  628. };
  629. function d3_selection_selector(selector) {
  630. return typeof selector === "function" ? selector : function() {
  631. return d3_select(selector, this);
  632. };
  633. }
  634. d3_selectionPrototype.selectAll = function(selector) {
  635. var subgroups = [], subgroup, node;
  636. selector = d3_selection_selectorAll(selector);
  637. for (var j = -1, m = this.length; ++j < m; ) {
  638. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  639. if (node = group[i]) {
  640. subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
  641. subgroup.parentNode = node;
  642. }
  643. }
  644. }
  645. return d3_selection(subgroups);
  646. };
  647. function d3_selection_selectorAll(selector) {
  648. return typeof selector === "function" ? selector : function() {
  649. return d3_selectAll(selector, this);
  650. };
  651. }
  652. var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
  653. var d3_nsPrefix = {
  654. svg: "http://www.w3.org/2000/svg",
  655. xhtml: d3_nsXhtml,
  656. xlink: "http://www.w3.org/1999/xlink",
  657. xml: "http://www.w3.org/XML/1998/namespace",
  658. xmlns: "http://www.w3.org/2000/xmlns/"
  659. };
  660. d3.ns = {
  661. prefix: d3_nsPrefix,
  662. qualify: function(name) {
  663. var i = name.indexOf(":"), prefix = name;
  664. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  665. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  666. space: d3_nsPrefix[prefix],
  667. local: name
  668. } : name;
  669. }
  670. };
  671. d3_selectionPrototype.attr = function(name, value) {
  672. if (arguments.length < 2) {
  673. if (typeof name === "string") {
  674. var node = this.node();
  675. name = d3.ns.qualify(name);
  676. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  677. }
  678. for (value in name) this.each(d3_selection_attr(value, name[value]));
  679. return this;
  680. }
  681. return this.each(d3_selection_attr(name, value));
  682. };
  683. function d3_selection_attr(name, value) {
  684. name = d3.ns.qualify(name);
  685. function attrNull() {
  686. this.removeAttribute(name);
  687. }
  688. function attrNullNS() {
  689. this.removeAttributeNS(name.space, name.local);
  690. }
  691. function attrConstant() {
  692. this.setAttribute(name, value);
  693. }
  694. function attrConstantNS() {
  695. this.setAttributeNS(name.space, name.local, value);
  696. }
  697. function attrFunction() {
  698. var x = value.apply(this, arguments);
  699. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  700. }
  701. function attrFunctionNS() {
  702. var x = value.apply(this, arguments);
  703. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  704. }
  705. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  706. }
  707. function d3_collapse(s) {
  708. return s.trim().replace(/\s+/g, " ");
  709. }
  710. d3_selectionPrototype.classed = function(name, value) {
  711. if (arguments.length < 2) {
  712. if (typeof name === "string") {
  713. var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
  714. if (value = node.classList) {
  715. while (++i < n) if (!value.contains(name[i])) return false;
  716. } else {
  717. value = node.getAttribute("class");
  718. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  719. }
  720. return true;
  721. }
  722. for (value in name) this.each(d3_selection_classed(value, name[value]));
  723. return this;
  724. }
  725. return this.each(d3_selection_classed(name, value));
  726. };
  727. function d3_selection_classedRe(name) {
  728. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  729. }
  730. function d3_selection_classes(name) {
  731. return (name + "").trim().split(/^|\s+/);
  732. }
  733. function d3_selection_classed(name, value) {
  734. name = d3_selection_classes(name).map(d3_selection_classedName);
  735. var n = name.length;
  736. function classedConstant() {
  737. var i = -1;
  738. while (++i < n) name[i](this, value);
  739. }
  740. function classedFunction() {
  741. var i = -1, x = value.apply(this, arguments);
  742. while (++i < n) name[i](this, x);
  743. }
  744. return typeof value === "function" ? classedFunction : classedConstant;
  745. }
  746. function d3_selection_classedName(name) {
  747. var re = d3_selection_classedRe(name);
  748. return function(node, value) {
  749. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  750. var c = node.getAttribute("class") || "";
  751. if (value) {
  752. re.lastIndex = 0;
  753. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  754. } else {
  755. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  756. }
  757. };
  758. }
  759. d3_selectionPrototype.style = function(name, value, priority) {
  760. var n = arguments.length;
  761. if (n < 3) {
  762. if (typeof name !== "string") {
  763. if (n < 2) value = "";
  764. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  765. return this;
  766. }
  767. if (n < 2) {
  768. var node = this.node();
  769. return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
  770. }
  771. priority = "";
  772. }
  773. return this.each(d3_selection_style(name, value, priority));
  774. };
  775. function d3_selection_style(name, value, priority) {
  776. function styleNull() {
  777. this.style.removeProperty(name);
  778. }
  779. function styleConstant() {
  780. this.style.setProperty(name, value, priority);
  781. }
  782. function styleFunction() {
  783. var x = value.apply(this, arguments);
  784. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  785. }
  786. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  787. }
  788. d3_selectionPrototype.property = function(name, value) {
  789. if (arguments.length < 2) {
  790. if (typeof name === "string") return this.node()[name];
  791. for (value in name) this.each(d3_selection_property(value, name[value]));
  792. return this;
  793. }
  794. return this.each(d3_selection_property(name, value));
  795. };
  796. function d3_selection_property(name, value) {
  797. function propertyNull() {
  798. delete this[name];
  799. }
  800. function propertyConstant() {
  801. this[name] = value;
  802. }
  803. function propertyFunction() {
  804. var x = value.apply(this, arguments);
  805. if (x == null) delete this[name]; else this[name] = x;
  806. }
  807. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  808. }
  809. d3_selectionPrototype.text = function(value) {
  810. return arguments.length ? this.each(typeof value === "function" ? function() {
  811. var v = value.apply(this, arguments);
  812. this.textContent = v == null ? "" : v;
  813. } : value == null ? function() {
  814. this.textContent = "";
  815. } : function() {
  816. this.textContent = value;
  817. }) : this.node().textContent;
  818. };
  819. d3_selectionPrototype.html = function(value) {
  820. return arguments.length ? this.each(typeof value === "function" ? function() {
  821. var v = value.apply(this, arguments);
  822. this.innerHTML = v == null ? "" : v;
  823. } : value == null ? function() {
  824. this.innerHTML = "";
  825. } : function() {
  826. this.innerHTML = value;
  827. }) : this.node().innerHTML;
  828. };
  829. d3_selectionPrototype.append = function(name) {
  830. name = d3_selection_creator(name);
  831. return this.select(function() {
  832. return this.appendChild(name.apply(this, arguments));
  833. });
  834. };
  835. function d3_selection_creator(name) {
  836. function create() {
  837. var document = this.ownerDocument, namespace = this.namespaceURI;
  838. return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
  839. }
  840. function createNS() {
  841. return this.ownerDocument.createElementNS(name.space, name.local);
  842. }
  843. return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
  844. }
  845. d3_selectionPrototype.insert = function(name, before) {
  846. name = d3_selection_creator(name);
  847. before = d3_selection_selector(before);
  848. return this.select(function() {
  849. return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
  850. });
  851. };
  852. d3_selectionPrototype.remove = function() {
  853. return this.each(d3_selectionRemove);
  854. };
  855. function d3_selectionRemove() {
  856. var parent = this.parentNode;
  857. if (parent) parent.removeChild(this);
  858. }
  859. d3_selectionPrototype.data = function(value, key) {
  860. var i = -1, n = this.length, group, node;
  861. if (!arguments.length) {
  862. value = new Array(n = (group = this[0]).length);
  863. while (++i < n) {
  864. if (node = group[i]) {
  865. value[i] = node.__data__;
  866. }
  867. }
  868. return value;
  869. }
  870. function bind(group, groupData) {
  871. 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;
  872. if (key) {
  873. var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
  874. for (i = -1; ++i < n; ) {
  875. if (node = group[i]) {
  876. if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
  877. exitNodes[i] = node;
  878. } else {
  879. nodeByKeyValue.set(keyValue, node);
  880. }
  881. keyValues[i] = keyValue;
  882. }
  883. }
  884. for (i = -1; ++i < m; ) {
  885. if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
  886. enterNodes[i] = d3_selection_dataNode(nodeData);
  887. } else if (node !== true) {
  888. updateNodes[i] = node;
  889. node.__data__ = nodeData;
  890. }
  891. nodeByKeyValue.set(keyValue, true);
  892. }
  893. for (i = -1; ++i < n; ) {
  894. if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {
  895. exitNodes[i] = group[i];
  896. }
  897. }
  898. } else {
  899. for (i = -1; ++i < n0; ) {
  900. node = group[i];
  901. nodeData = groupData[i];
  902. if (node) {
  903. node.__data__ = nodeData;
  904. updateNodes[i] = node;
  905. } else {
  906. enterNodes[i] = d3_selection_dataNode(nodeData);
  907. }
  908. }
  909. for (;i < m; ++i) {
  910. enterNodes[i] = d3_selection_dataNode(groupData[i]);
  911. }
  912. for (;i < n; ++i) {
  913. exitNodes[i] = group[i];
  914. }
  915. }
  916. enterNodes.update = updateNodes;
  917. enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
  918. enter.push(enterNodes);
  919. update.push(updateNodes);
  920. exit.push(exitNodes);
  921. }
  922. var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
  923. if (typeof value === "function") {
  924. while (++i < n) {
  925. bind(group = this[i], value.call(group, group.parentNode.__data__, i));
  926. }
  927. } else {
  928. while (++i < n) {
  929. bind(group = this[i], value);
  930. }
  931. }
  932. update.enter = function() {
  933. return enter;
  934. };
  935. update.exit = function() {
  936. return exit;
  937. };
  938. return update;
  939. };
  940. function d3_selection_dataNode(data) {
  941. return {
  942. __data__: data
  943. };
  944. }
  945. d3_selectionPrototype.datum = function(value) {
  946. return arguments.length ? this.property("__data__", value) : this.property("__data__");
  947. };
  948. d3_selectionPrototype.filter = function(filter) {
  949. var subgroups = [], subgroup, group, node;
  950. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  951. for (var j = 0, m = this.length; j < m; j++) {
  952. subgroups.push(subgroup = []);
  953. subgroup.parentNode = (group = this[j]).parentNode;
  954. for (var i = 0, n = group.length; i < n; i++) {
  955. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  956. subgroup.push(node);
  957. }
  958. }
  959. }
  960. return d3_selection(subgroups);
  961. };
  962. function d3_selection_filter(selector) {
  963. return function() {
  964. return d3_selectMatches(this, selector);
  965. };
  966. }
  967. d3_selectionPrototype.order = function() {
  968. for (var j = -1, m = this.length; ++j < m; ) {
  969. for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
  970. if (node = group[i]) {
  971. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  972. next = node;
  973. }
  974. }
  975. }
  976. return this;
  977. };
  978. d3_selectionPrototype.sort = function(comparator) {
  979. comparator = d3_selection_sortComparator.apply(this, arguments);
  980. for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
  981. return this.order();
  982. };
  983. function d3_selection_sortComparator(comparator) {
  984. if (!arguments.length) comparator = d3_ascending;
  985. return function(a, b) {
  986. return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
  987. };
  988. }
  989. d3_selectionPrototype.each = function(callback) {
  990. return d3_selection_each(this, function(node, i, j) {
  991. callback.call(node, node.__data__, i, j);
  992. });
  993. };
  994. function d3_selection_each(groups, callback) {
  995. for (var j = 0, m = groups.length; j < m; j++) {
  996. for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
  997. if (node = group[i]) callback(node, i, j);
  998. }
  999. }
  1000. return groups;
  1001. }
  1002. d3_selectionPrototype.call = function(callback) {
  1003. var args = d3_array(arguments);
  1004. callback.apply(args[0] = this, args);
  1005. return this;
  1006. };
  1007. d3_selectionPrototype.empty = function() {
  1008. return !this.node();
  1009. };
  1010. d3_selectionPrototype.node = function() {
  1011. for (var j = 0, m = this.length; j < m; j++) {
  1012. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  1013. var node = group[i];
  1014. if (node) return node;
  1015. }
  1016. }
  1017. return null;
  1018. };
  1019. d3_selectionPrototype.size = function() {
  1020. var n = 0;
  1021. d3_selection_each(this, function() {
  1022. ++n;
  1023. });
  1024. return n;
  1025. };
  1026. function d3_selection_enter(selection) {
  1027. d3_subclass(selection, d3_selection_enterPrototype);
  1028. return selection;
  1029. }
  1030. var d3_selection_enterPrototype = [];
  1031. d3.selection.enter = d3_selection_enter;
  1032. d3.selection.enter.prototype = d3_selection_enterPrototype;
  1033. d3_selection_enterPrototype.append = d3_selectionPrototype.append;
  1034. d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
  1035. d3_selection_enterPrototype.node = d3_selectionPrototype.node;
  1036. d3_selection_enterPrototype.call = d3_selectionPrototype.call;
  1037. d3_selection_enterPrototype.size = d3_selectionPrototype.size;
  1038. d3_selection_enterPrototype.select = function(selector) {
  1039. var subgroups = [], subgroup, subnode, upgroup, group, node;
  1040. for (var j = -1, m = this.length; ++j < m; ) {
  1041. upgroup = (group = this[j]).update;
  1042. subgroups.push(subgroup = []);
  1043. subgroup.parentNode = group.parentNode;
  1044. for (var i = -1, n = group.length; ++i < n; ) {
  1045. if (node = group[i]) {
  1046. subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
  1047. subnode.__data__ = node.__data__;
  1048. } else {
  1049. subgroup.push(null);
  1050. }
  1051. }
  1052. }
  1053. return d3_selection(subgroups);
  1054. };
  1055. d3_selection_enterPrototype.insert = function(name, before) {
  1056. if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
  1057. return d3_selectionPrototype.insert.call(this, name, before);
  1058. };
  1059. function d3_selection_enterInsertBefore(enter) {
  1060. var i0, j0;
  1061. return function(d, i, j) {
  1062. var group = enter[j].update, n = group.length, node;
  1063. if (j != j0) j0 = j, i0 = 0;
  1064. if (i >= i0) i0 = i + 1;
  1065. while (!(node = group[i0]) && ++i0 < n) ;
  1066. return node;
  1067. };
  1068. }
  1069. d3.select = function(node) {
  1070. var group;
  1071. if (typeof node === "string") {
  1072. group = [ d3_select(node, d3_document) ];
  1073. group.parentNode = d3_document.documentElement;
  1074. } else {
  1075. group = [ node ];
  1076. group.parentNode = d3_documentElement(node);
  1077. }
  1078. return d3_selection([ group ]);
  1079. };
  1080. d3.selectAll = function(nodes) {
  1081. var group;
  1082. if (typeof nodes === "string") {
  1083. group = d3_array(d3_selectAll(nodes, d3_document));
  1084. group.parentNode = d3_document.documentElement;
  1085. } else {
  1086. group = d3_array(nodes);
  1087. group.parentNode = null;
  1088. }
  1089. return d3_selection([ group ]);
  1090. };
  1091. d3_selectionPrototype.on = function(type, listener, capture) {
  1092. var n = arguments.length;
  1093. if (n < 3) {
  1094. if (typeof type !== "string") {
  1095. if (n < 2) listener = false;
  1096. for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
  1097. return this;
  1098. }
  1099. if (n < 2) return (n = this.node()["__on" + type]) && n._;
  1100. capture = false;
  1101. }
  1102. return this.each(d3_selection_on(type, listener, capture));
  1103. };
  1104. function d3_selection_on(type, listener, capture) {
  1105. var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
  1106. if (i > 0) type = type.slice(0, i);
  1107. var filter = d3_selection_onFilters.get(type);
  1108. if (filter) type = filter, wrap = d3_selection_onFilter;
  1109. function onRemove() {
  1110. var l = this[name];
  1111. if (l) {
  1112. this.removeEventListener(type, l, l.$);
  1113. delete this[name];
  1114. }
  1115. }
  1116. function onAdd() {
  1117. var l = wrap(listener, d3_array(arguments));
  1118. onRemove.call(this);
  1119. this.addEventListener(type, this[name] = l, l.$ = capture);
  1120. l._ = listener;
  1121. }
  1122. function removeAll() {
  1123. var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
  1124. for (var name in this) {
  1125. if (match = name.match(re)) {
  1126. var l = this[name];
  1127. this.removeEventListener(match[1], l, l.$);
  1128. delete this[name];
  1129. }
  1130. }
  1131. }
  1132. return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
  1133. }
  1134. var d3_selection_onFilters = d3.map({
  1135. mouseenter: "mouseover",
  1136. mouseleave: "mouseout"
  1137. });
  1138. if (d3_document) {
  1139. d3_selection_onFilters.forEach(function(k) {
  1140. if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
  1141. });
  1142. }
  1143. function d3_selection_onListener(listener, argumentz) {
  1144. return function(e) {
  1145. var o = d3.event;
  1146. d3.event = e;
  1147. argumentz[0] = this.__data__;
  1148. try {
  1149. listener.apply(this, argumentz);
  1150. } finally {
  1151. d3.event = o;
  1152. }
  1153. };
  1154. }
  1155. function d3_selection_onFilter(listener, argumentz) {
  1156. var l = d3_selection_onListener(listener, argumentz);
  1157. return function(e) {
  1158. var target = this, related = e.relatedTarget;
  1159. if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
  1160. l.call(target, e);
  1161. }
  1162. };
  1163. }
  1164. var d3_event_dragSelect, d3_event_dragId = 0;
  1165. function d3_event_dragSuppress(node) {
  1166. var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window(node)).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
  1167. if (d3_event_dragSelect == null) {
  1168. d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
  1169. }
  1170. if (d3_event_dragSelect) {
  1171. var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
  1172. style[d3_event_dragSelect] = "none";
  1173. }
  1174. return function(suppressClick) {
  1175. w.on(name, null);
  1176. if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
  1177. if (suppressClick) {
  1178. var off = function() {
  1179. w.on(click, null);
  1180. };
  1181. w.on(click, function() {
  1182. d3_eventPreventDefault();
  1183. off();
  1184. }, true);
  1185. setTimeout(off, 0);
  1186. }
  1187. };
  1188. }
  1189. d3.mouse = function(container) {
  1190. return d3_mousePoint(container, d3_eventSource());
  1191. };
  1192. var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
  1193. function d3_mousePoint(container, e) {
  1194. if (e.changedTouches) e = e.changedTouches[0];
  1195. var svg = container.ownerSVGElement || container;
  1196. if (svg.createSVGPoint) {
  1197. var point = svg.createSVGPoint();
  1198. if (d3_mouse_bug44083 < 0) {
  1199. var window = d3_window(container);
  1200. if (window.scrollX || window.scrollY) {
  1201. svg = d3.select("body").append("svg").style({
  1202. position: "absolute",
  1203. top: 0,
  1204. left: 0,
  1205. margin: 0,
  1206. padding: 0,
  1207. border: "none"
  1208. }, "important");
  1209. var ctm = svg[0][0].getScreenCTM();
  1210. d3_mouse_bug44083 = !(ctm.f || ctm.e);
  1211. svg.remove();
  1212. }
  1213. }
  1214. if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
  1215. point.y = e.clientY;
  1216. point = point.matrixTransform(container.getScreenCTM().inverse());
  1217. return [ point.x, point.y ];
  1218. }
  1219. var rect = container.getBoundingClientRect();
  1220. return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
  1221. }
  1222. d3.touch = function(container, touches, identifier) {
  1223. if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
  1224. if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
  1225. if ((touch = touches[i]).identifier === identifier) {
  1226. return d3_mousePoint(container, touch);
  1227. }
  1228. }
  1229. };
  1230. d3.behavior.drag = function() {
  1231. var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend");
  1232. function drag() {
  1233. this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
  1234. }
  1235. function dragstart(id, position, subject, move, end) {
  1236. return function() {
  1237. var that = this, target = d3.event.target.correspondingElement || d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
  1238. if (origin) {
  1239. dragOffset = origin.apply(that, arguments);
  1240. dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
  1241. } else {
  1242. dragOffset = [ 0, 0 ];
  1243. }
  1244. dispatch({
  1245. type: "dragstart"
  1246. });
  1247. function moved() {
  1248. var position1 = position(parent, dragId), dx, dy;
  1249. if (!position1) return;
  1250. dx = position1[0] - position0[0];
  1251. dy = position1[1] - position0[1];
  1252. dragged |= dx | dy;
  1253. position0 = position1;
  1254. dispatch({
  1255. type: "drag",
  1256. x: position1[0] + dragOffset[0],
  1257. y: position1[1] + dragOffset[1],
  1258. dx: dx,
  1259. dy: dy
  1260. });
  1261. }
  1262. function ended() {
  1263. if (!position(parent, dragId)) return;
  1264. dragSubject.on(move + dragName, null).on(end + dragName, null);
  1265. dragRestore(dragged);
  1266. dispatch({
  1267. type: "dragend"
  1268. });
  1269. }
  1270. };
  1271. }
  1272. drag.origin = function(x) {
  1273. if (!arguments.length) return origin;
  1274. origin = x;
  1275. return drag;
  1276. };
  1277. return d3.rebind(drag, event, "on");
  1278. };
  1279. function d3_behavior_dragTouchId() {
  1280. return d3.event.changedTouches[0].identifier;
  1281. }
  1282. d3.touches = function(container, touches) {
  1283. if (arguments.length < 2) touches = d3_eventSource().touches;
  1284. return touches ? d3_array(touches).map(function(touch) {
  1285. var point = d3_mousePoint(container, touch);
  1286. point.identifier = touch.identifier;
  1287. return point;
  1288. }) : [];
  1289. };
  1290. var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
  1291. function d3_sgn(x) {
  1292. return x > 0 ? 1 : x < 0 ? -1 : 0;
  1293. }
  1294. function d3_cross2d(a, b, c) {
  1295. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  1296. }
  1297. function d3_acos(x) {
  1298. return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
  1299. }
  1300. function d3_asin(x) {
  1301. return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
  1302. }
  1303. function d3_sinh(x) {
  1304. return ((x = Math.exp(x)) - 1 / x) / 2;
  1305. }
  1306. function d3_cosh(x) {
  1307. return ((x = Math.exp(x)) + 1 / x) / 2;
  1308. }
  1309. function d3_tanh(x) {
  1310. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  1311. }
  1312. function d3_haversin(x) {
  1313. return (x = Math.sin(x / 2)) * x;
  1314. }
  1315. var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
  1316. d3.interpolateZoom = function(p0, p1) {
  1317. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;
  1318. if (d2 < ε2) {
  1319. S = Math.log(w1 / w0) / ρ;
  1320. i = function(t) {
  1321. return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];
  1322. };
  1323. } else {
  1324. var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  1325. S = (r1 - r0) / ρ;
  1326. i = function(t) {
  1327. var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
  1328. return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
  1329. };
  1330. }
  1331. i.duration = S * 1e3;
  1332. return i;
  1333. };
  1334. d3.behavior.zoom = function() {
  1335. var view = {
  1336. x: 0,
  1337. y: 0,
  1338. k: 1
  1339. }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
  1340. if (!d3_behavior_zoomWheel) {
  1341. d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1342. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  1343. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1344. return d3.event.wheelDelta;
  1345. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  1346. return -d3.event.detail;
  1347. }, "MozMousePixelScroll");
  1348. }
  1349. function zoom(g) {
  1350. g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
  1351. }
  1352. zoom.event = function(g) {
  1353. g.each(function() {
  1354. var dispatch = event.of(this, arguments), view1 = view;
  1355. if (d3_transitionInheritId) {
  1356. d3.select(this).transition().each("start.zoom", function() {
  1357. view = this.__chart__ || {
  1358. x: 0,
  1359. y: 0,
  1360. k: 1
  1361. };
  1362. zoomstarted(dispatch);
  1363. }).tween("zoom:zoom", function() {
  1364. var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
  1365. return function(t) {
  1366. var l = i(t), k = dx / l[2];
  1367. this.__chart__ = view = {
  1368. x: cx - l[0] * k,
  1369. y: cy - l[1] * k,
  1370. k: k
  1371. };
  1372. zoomed(dispatch);
  1373. };
  1374. }).each("interrupt.zoom", function() {
  1375. zoomended(dispatch);
  1376. }).each("end.zoom", function() {
  1377. zoomended(dispatch);
  1378. });
  1379. } else {
  1380. this.__chart__ = view;
  1381. zoomstarted(dispatch);
  1382. zoomed(dispatch);
  1383. zoomended(dispatch);
  1384. }
  1385. });
  1386. };
  1387. zoom.translate = function(_) {
  1388. if (!arguments.length) return [ view.x, view.y ];
  1389. view = {
  1390. x: +_[0],
  1391. y: +_[1],
  1392. k: view.k
  1393. };
  1394. rescale();
  1395. return zoom;
  1396. };
  1397. zoom.scale = function(_) {
  1398. if (!arguments.length) return view.k;
  1399. view = {
  1400. x: view.x,
  1401. y: view.y,
  1402. k: null
  1403. };
  1404. scaleTo(+_);
  1405. rescale();
  1406. return zoom;
  1407. };
  1408. zoom.scaleExtent = function(_) {
  1409. if (!arguments.length) return scaleExtent;
  1410. scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
  1411. return zoom;
  1412. };
  1413. zoom.center = function(_) {
  1414. if (!arguments.length) return center;
  1415. center = _ && [ +_[0], +_[1] ];
  1416. return zoom;
  1417. };
  1418. zoom.size = function(_) {
  1419. if (!arguments.length) return size;
  1420. size = _ && [ +_[0], +_[1] ];
  1421. return zoom;
  1422. };
  1423. zoom.duration = function(_) {
  1424. if (!arguments.length) return duration;
  1425. duration = +_;
  1426. return zoom;
  1427. };
  1428. zoom.x = function(z) {
  1429. if (!arguments.length) return x1;
  1430. x1 = z;
  1431. x0 = z.copy();
  1432. view = {
  1433. x: 0,
  1434. y: 0,
  1435. k: 1
  1436. };
  1437. return zoom;
  1438. };
  1439. zoom.y = function(z) {
  1440. if (!arguments.length) return y1;
  1441. y1 = z;
  1442. y0 = z.copy();
  1443. view = {
  1444. x: 0,
  1445. y: 0,
  1446. k: 1
  1447. };
  1448. return zoom;
  1449. };
  1450. function location(p) {
  1451. return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
  1452. }
  1453. function point(l) {
  1454. return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
  1455. }
  1456. function scaleTo(s) {
  1457. view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  1458. }
  1459. function translateTo(p, l) {
  1460. l = point(l);
  1461. view.x += p[0] - l[0];
  1462. view.y += p[1] - l[1];
  1463. }
  1464. function zoomTo(that, p, l, k) {
  1465. that.__chart__ = {
  1466. x: view.x,
  1467. y: view.y,
  1468. k: view.k
  1469. };
  1470. scaleTo(Math.pow(2, k));
  1471. translateTo(center0 = p, l);
  1472. that = d3.select(that);
  1473. if (duration > 0) that = that.transition().duration(duration);
  1474. that.call(zoom.event);
  1475. }
  1476. function rescale() {
  1477. if (x1) x1.domain(x0.range().map(function(x) {
  1478. return (x - view.x) / view.k;
  1479. }).map(x0.invert));
  1480. if (y1) y1.domain(y0.range().map(function(y) {
  1481. return (y - view.y) / view.k;
  1482. }).map(y0.invert));
  1483. }
  1484. function zoomstarted(dispatch) {
  1485. if (!zooming++) dispatch({
  1486. type: "zoomstart"
  1487. });
  1488. }
  1489. function zoomed(dispatch) {
  1490. rescale();
  1491. dispatch({
  1492. type: "zoom",
  1493. scale: view.k,
  1494. translate: [ view.x, view.y ]
  1495. });
  1496. }
  1497. function zoomended(dispatch) {
  1498. if (!--zooming) dispatch({
  1499. type: "zoomend"
  1500. }), center0 = null;
  1501. }
  1502. function mousedowned() {
  1503. var that = this, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
  1504. d3_selection_interrupt.call(that);
  1505. zoomstarted(dispatch);
  1506. function moved() {
  1507. dragged = 1;
  1508. translateTo(d3.mouse(that), location0);
  1509. zoomed(dispatch);
  1510. }
  1511. function ended() {
  1512. subject.on(mousemove, null).on(mouseup, null);
  1513. dragRestore(dragged);
  1514. zoomended(dispatch);
  1515. }
  1516. }
  1517. function touchstarted() {
  1518. var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);
  1519. started();
  1520. zoomstarted(dispatch);
  1521. subject.on(mousedown, null).on(touchstart, started);
  1522. function relocate() {
  1523. var touches = d3.touches(that);
  1524. scale0 = view.k;
  1525. touches.forEach(function(t) {
  1526. if (t.identifier in locations0) locations0[t.identifier] = location(t);
  1527. });
  1528. return touches;
  1529. }
  1530. function started() {
  1531. var target = d3.event.target;
  1532. d3.select(target).on(touchmove, moved).on(touchend, ended);
  1533. targets.push(target);
  1534. var changed = d3.event.changedTouches;
  1535. for (var i = 0, n = changed.length; i < n; ++i) {
  1536. locations0[changed[i].identifier] = null;
  1537. }
  1538. var touches = relocate(), now = Date.now();
  1539. if (touches.length === 1) {
  1540. if (now - touchtime < 500) {
  1541. var p = touches[0];
  1542. zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
  1543. d3_eventPreventDefault();
  1544. }
  1545. touchtime = now;
  1546. } else if (touches.length > 1) {
  1547. var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
  1548. distance0 = dx * dx + dy * dy;
  1549. }
  1550. }
  1551. function moved() {
  1552. var touches = d3.touches(that), p0, l0, p1, l1;
  1553. d3_selection_interrupt.call(that);
  1554. for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
  1555. p1 = touches[i];
  1556. if (l1 = locations0[p1.identifier]) {
  1557. if (l0) break;
  1558. p0 = p1, l0 = l1;
  1559. }
  1560. }
  1561. if (l1) {
  1562. var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
  1563. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  1564. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  1565. scaleTo(scale1 * scale0);
  1566. }
  1567. touchtime = null;
  1568. translateTo(p0, l0);
  1569. zoomed(dispatch);
  1570. }
  1571. function ended() {
  1572. if (d3.event.touches.length) {
  1573. var changed = d3.event.changedTouches;
  1574. for (var i = 0, n = changed.length; i < n; ++i) {
  1575. delete locations0[changed[i].identifier];
  1576. }
  1577. for (var identifier in locations0) {
  1578. return void relocate();
  1579. }
  1580. }
  1581. d3.selectAll(targets).on(zoomName, null);
  1582. subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
  1583. dragRestore();
  1584. zoomended(dispatch);
  1585. }
  1586. }
  1587. function mousewheeled() {
  1588. var dispatch = event.of(this, arguments);
  1589. if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
  1590. translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
  1591. mousewheelTimer = setTimeout(function() {
  1592. mousewheelTimer = null;
  1593. zoomended(dispatch);
  1594. }, 50);
  1595. d3_eventPreventDefault();
  1596. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
  1597. translateTo(center0, translate0);
  1598. zoomed(dispatch);
  1599. }
  1600. function dblclicked() {
  1601. var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
  1602. zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
  1603. }
  1604. return d3.rebind(zoom, event, "on");
  1605. };
  1606. var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
  1607. d3.color = d3_color;
  1608. function d3_color() {}
  1609. d3_color.prototype.toString = function() {
  1610. return this.rgb() + "";
  1611. };
  1612. d3.hsl = d3_hsl;
  1613. function d3_hsl(h, s, l) {
  1614. return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
  1615. }
  1616. var d3_hslPrototype = d3_hsl.prototype = new d3_color();
  1617. d3_hslPrototype.brighter = function(k) {
  1618. k = Math.pow(.7, arguments.length ? k : 1);
  1619. return new d3_hsl(this.h, this.s, this.l / k);
  1620. };
  1621. d3_hslPrototype.darker = function(k) {
  1622. k = Math.pow(.7, arguments.length ? k : 1);
  1623. return new d3_hsl(this.h, this.s, k * this.l);
  1624. };
  1625. d3_hslPrototype.rgb = function() {
  1626. return d3_hsl_rgb(this.h, this.s, this.l);
  1627. };
  1628. function d3_hsl_rgb(h, s, l) {
  1629. var m1, m2;
  1630. h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
  1631. s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
  1632. l = l < 0 ? 0 : l > 1 ? 1 : l;
  1633. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  1634. m1 = 2 * l - m2;
  1635. function v(h) {
  1636. if (h > 360) h -= 360; else if (h < 0) h += 360;
  1637. if (h < 60) return m1 + (m2 - m1) * h / 60;
  1638. if (h < 180) return m2;
  1639. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  1640. return m1;
  1641. }
  1642. function vv(h) {
  1643. return Math.round(v(h) * 255);
  1644. }
  1645. return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  1646. }
  1647. d3.hcl = d3_hcl;
  1648. function d3_hcl(h, c, l) {
  1649. return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);
  1650. }
  1651. var d3_hclPrototype = d3_hcl.prototype = new d3_color();
  1652. d3_hclPrototype.brighter = function(k) {
  1653. return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  1654. };
  1655. d3_hclPrototype.darker = function(k) {
  1656. return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  1657. };
  1658. d3_hclPrototype.rgb = function() {
  1659. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  1660. };
  1661. function d3_hcl_lab(h, c, l) {
  1662. if (isNaN(h)) h = 0;
  1663. if (isNaN(c)) c = 0;
  1664. return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  1665. }
  1666. d3.lab = d3_lab;
  1667. function d3_lab(l, a, b) {
  1668. return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
  1669. }
  1670. var d3_lab_K = 18;
  1671. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  1672. var d3_labPrototype = d3_lab.prototype = new d3_color();
  1673. d3_labPrototype.brighter = function(k) {
  1674. return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1675. };
  1676. d3_labPrototype.darker = function(k) {
  1677. return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1678. };
  1679. d3_labPrototype.rgb = function() {
  1680. return d3_lab_rgb(this.l, this.a, this.b);
  1681. };
  1682. function d3_lab_rgb(l, a, b) {
  1683. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  1684. x = d3_lab_xyz(x) * d3_lab_X;
  1685. y = d3_lab_xyz(y) * d3_lab_Y;
  1686. z = d3_lab_xyz(z) * d3_lab_Z;
  1687. return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
  1688. }
  1689. function d3_lab_hcl(l, a, b) {
  1690. return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
  1691. }
  1692. function d3_lab_xyz(x) {
  1693. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  1694. }
  1695. function d3_xyz_lab(x) {
  1696. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  1697. }
  1698. function d3_xyz_rgb(r) {
  1699. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  1700. }
  1701. d3.rgb = d3_rgb;
  1702. function d3_rgb(r, g, b) {
  1703. return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
  1704. }
  1705. function d3_rgbNumber(value) {
  1706. return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
  1707. }
  1708. function d3_rgbString(value) {
  1709. return d3_rgbNumber(value) + "";
  1710. }
  1711. var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
  1712. d3_rgbPrototype.brighter = function(k) {
  1713. k = Math.pow(.7, arguments.length ? k : 1);
  1714. var r = this.r, g = this.g, b = this.b, i = 30;
  1715. if (!r && !g && !b) return new d3_rgb(i, i, i);
  1716. if (r && r < i) r = i;
  1717. if (g && g < i) g = i;
  1718. if (b && b < i) b = i;
  1719. return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
  1720. };
  1721. d3_rgbPrototype.darker = function(k) {
  1722. k = Math.pow(.7, arguments.length ? k : 1);
  1723. return new d3_rgb(k * this.r, k * this.g, k * this.b);
  1724. };
  1725. d3_rgbPrototype.hsl = function() {
  1726. return d3_rgb_hsl(this.r, this.g, this.b);
  1727. };
  1728. d3_rgbPrototype.toString = function() {
  1729. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  1730. };
  1731. function d3_rgb_hex(v) {
  1732. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  1733. }
  1734. function d3_rgb_parse(format, rgb, hsl) {
  1735. var r = 0, g = 0, b = 0, m1, m2, color;
  1736. m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
  1737. if (m1) {
  1738. m2 = m1[2].split(",");
  1739. switch (m1[1]) {
  1740. case "hsl":
  1741. {
  1742. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  1743. }
  1744. case "rgb":
  1745. {
  1746. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  1747. }
  1748. }
  1749. }
  1750. if (color = d3_rgb_names.get(format)) {
  1751. return rgb(color.r, color.g, color.b);
  1752. }
  1753. if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
  1754. if (format.length === 4) {
  1755. r = (color & 3840) >> 4;
  1756. r = r >> 4 | r;
  1757. g = color & 240;
  1758. g = g >> 4 | g;
  1759. b = color & 15;
  1760. b = b << 4 | b;
  1761. } else if (format.length === 7) {
  1762. r = (color & 16711680) >> 16;
  1763. g = (color & 65280) >> 8;
  1764. b = color & 255;
  1765. }
  1766. }
  1767. return rgb(r, g, b);
  1768. }
  1769. function d3_rgb_hsl(r, g, b) {
  1770. 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;
  1771. if (d) {
  1772. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  1773. 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;
  1774. h *= 60;
  1775. } else {
  1776. h = NaN;
  1777. s = l > 0 && l < 1 ? 0 : h;
  1778. }
  1779. return new d3_hsl(h, s, l);
  1780. }
  1781. function d3_rgb_lab(r, g, b) {
  1782. r = d3_rgb_xyz(r);
  1783. g = d3_rgb_xyz(g);
  1784. b = d3_rgb_xyz(b);
  1785. 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);
  1786. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  1787. }
  1788. function d3_rgb_xyz(r) {
  1789. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  1790. }
  1791. function d3_rgb_parseNumber(c) {
  1792. var f = parseFloat(c);
  1793. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  1794. }
  1795. var d3_rgb_names = d3.map({
  1796. aliceblue: 15792383,
  1797. antiquewhite: 16444375,
  1798. aqua: 65535,
  1799. aquamarine: 8388564,
  1800. azure: 15794175,
  1801. beige: 16119260,
  1802. bisque: 16770244,
  1803. black: 0,
  1804. blanchedalmond: 16772045,
  1805. blue: 255,
  1806. blueviolet: 9055202,
  1807. brown: 10824234,
  1808. burlywood: 14596231,
  1809. cadetblue: 6266528,
  1810. chartreuse: 8388352,
  1811. chocolate: 13789470,
  1812. coral: 16744272,
  1813. cornflowerblue: 6591981,
  1814. cornsilk: 16775388,
  1815. crimson: 14423100,
  1816. cyan: 65535,
  1817. darkblue: 139,
  1818. darkcyan: 35723,
  1819. darkgoldenrod: 12092939,
  1820. darkgray: 11119017,
  1821. darkgreen: 25600,
  1822. darkgrey: 11119017,
  1823. darkkhaki: 12433259,
  1824. darkmagenta: 9109643,
  1825. darkolivegreen: 5597999,
  1826. darkorange: 16747520,
  1827. darkorchid: 10040012,
  1828. darkred: 9109504,
  1829. darksalmon: 15308410,
  1830. darkseagreen: 9419919,
  1831. darkslateblue: 4734347,
  1832. darkslategray: 3100495,
  1833. darkslategrey: 3100495,
  1834. darkturquoise: 52945,
  1835. darkviolet: 9699539,
  1836. deeppink: 16716947,
  1837. deepskyblue: 49151,
  1838. dimgray: 6908265,
  1839. dimgrey: 6908265,
  1840. dodgerblue: 2003199,
  1841. firebrick: 11674146,
  1842. floralwhite: 16775920,
  1843. forestgreen: 2263842,
  1844. fuchsia: 16711935,
  1845. gainsboro: 14474460,
  1846. ghostwhite: 16316671,
  1847. gold: 16766720,
  1848. goldenrod: 14329120,
  1849. gray: 8421504,
  1850. green: 32768,
  1851. greenyellow: 11403055,
  1852. grey: 8421504,
  1853. honeydew: 15794160,
  1854. hotpink: 16738740,
  1855. indianred: 13458524,
  1856. indigo: 4915330,
  1857. ivory: 16777200,
  1858. khaki: 15787660,
  1859. lavender: 15132410,
  1860. lavenderblush: 16773365,
  1861. lawngreen: 8190976,
  1862. lemonchiffon: 16775885,
  1863. lightblue: 11393254,
  1864. lightcoral: 15761536,
  1865. lightcyan: 14745599,
  1866. lightgoldenrodyellow: 16448210,
  1867. lightgray: 13882323,
  1868. lightgreen: 9498256,
  1869. lightgrey: 13882323,
  1870. lightpink: 16758465,
  1871. lightsalmon: 16752762,
  1872. lightseagreen: 2142890,
  1873. lightskyblue: 8900346,
  1874. lightslategray: 7833753,
  1875. lightslategrey: 7833753,
  1876. lightsteelblue: 11584734,
  1877. lightyellow: 16777184,
  1878. lime: 65280,
  1879. limegreen: 3329330,
  1880. linen: 16445670,
  1881. magenta: 16711935,
  1882. maroon: 8388608,
  1883. mediumaquamarine: 6737322,
  1884. mediumblue: 205,
  1885. mediumorchid: 12211667,
  1886. mediumpurple: 9662683,
  1887. mediumseagreen: 3978097,
  1888. mediumslateblue: 8087790,
  1889. mediumspringgreen: 64154,
  1890. mediumturquoise: 4772300,
  1891. mediumvioletred: 13047173,
  1892. midnightblue: 1644912,
  1893. mintcream: 16121850,
  1894. mistyrose: 16770273,
  1895. moccasin: 16770229,
  1896. navajowhite: 16768685,
  1897. navy: 128,
  1898. oldlace: 16643558,
  1899. olive: 8421376,
  1900. olivedrab: 7048739,
  1901. orange: 16753920,
  1902. orangered: 16729344,
  1903. orchid: 14315734,
  1904. palegoldenrod: 15657130,
  1905. palegreen: 10025880,
  1906. paleturquoise: 11529966,
  1907. palevioletred: 14381203,
  1908. papayawhip: 16773077,
  1909. peachpuff: 16767673,
  1910. peru: 13468991,
  1911. pink: 16761035,
  1912. plum: 14524637,
  1913. powderblue: 11591910,
  1914. purple: 8388736,
  1915. rebeccapurple: 6697881,
  1916. red: 16711680,
  1917. rosybrown: 12357519,
  1918. royalblue: 4286945,
  1919. saddlebrown: 9127187,
  1920. salmon: 16416882,
  1921. sandybrown: 16032864,
  1922. seagreen: 3050327,
  1923. seashell: 16774638,
  1924. sienna: 10506797,
  1925. silver: 12632256,
  1926. skyblue: 8900331,
  1927. slateblue: 6970061,
  1928. slategray: 7372944,
  1929. slategrey: 7372944,
  1930. snow: 16775930,
  1931. springgreen: 65407,
  1932. steelblue: 4620980,
  1933. tan: 13808780,
  1934. teal: 32896,
  1935. thistle: 14204888,
  1936. tomato: 16737095,
  1937. turquoise: 4251856,
  1938. violet: 15631086,
  1939. wheat: 16113331,
  1940. white: 16777215,
  1941. whitesmoke: 16119285,
  1942. yellow: 16776960,
  1943. yellowgreen: 10145074
  1944. });
  1945. d3_rgb_names.forEach(function(key, value) {
  1946. d3_rgb_names.set(key, d3_rgbNumber(value));
  1947. });
  1948. function d3_functor(v) {
  1949. return typeof v === "function" ? v : function() {
  1950. return v;
  1951. };
  1952. }
  1953. d3.functor = d3_functor;
  1954. d3.xhr = d3_xhrType(d3_identity);
  1955. function d3_xhrType(response) {
  1956. return function(url, mimeType, callback) {
  1957. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  1958. mimeType = null;
  1959. return d3_xhr(url, mimeType, response, callback);
  1960. };
  1961. }
  1962. function d3_xhr(url, mimeType, response, callback) {
  1963. var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
  1964. if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
  1965. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  1966. request.readyState > 3 && respond();
  1967. };
  1968. function respond() {
  1969. var status = request.status, result;
  1970. if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
  1971. try {
  1972. result = response.call(xhr, request);
  1973. } catch (e) {
  1974. dispatch.error.call(xhr, e);
  1975. return;
  1976. }
  1977. dispatch.load.call(xhr, result);
  1978. } else {
  1979. dispatch.error.call(xhr, request);
  1980. }
  1981. }
  1982. request.onprogress = function(event) {
  1983. var o = d3.event;
  1984. d3.event = event;
  1985. try {
  1986. dispatch.progress.call(xhr, request);
  1987. } finally {
  1988. d3.event = o;
  1989. }
  1990. };
  1991. xhr.header = function(name, value) {
  1992. name = (name + "").toLowerCase();
  1993. if (arguments.length < 2) return headers[name];
  1994. if (value == null) delete headers[name]; else headers[name] = value + "";
  1995. return xhr;
  1996. };
  1997. xhr.mimeType = function(value) {
  1998. if (!arguments.length) return mimeType;
  1999. mimeType = value == null ? null : value + "";
  2000. return xhr;
  2001. };
  2002. xhr.responseType = function(value) {
  2003. if (!arguments.length) return responseType;
  2004. responseType = value;
  2005. return xhr;
  2006. };
  2007. xhr.response = function(value) {
  2008. response = value;
  2009. return xhr;
  2010. };
  2011. [ "get", "post" ].forEach(function(method) {
  2012. xhr[method] = function() {
  2013. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  2014. };
  2015. });
  2016. xhr.send = function(method, data, callback) {
  2017. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  2018. request.open(method, url, true);
  2019. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  2020. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  2021. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  2022. if (responseType != null) request.responseType = responseType;
  2023. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  2024. callback(null, request);
  2025. });
  2026. dispatch.beforesend.call(xhr, request);
  2027. request.send(data == null ? null : data);
  2028. return xhr;
  2029. };
  2030. xhr.abort = function() {
  2031. request.abort();
  2032. return xhr;
  2033. };
  2034. d3.rebind(xhr, dispatch, "on");
  2035. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  2036. }
  2037. function d3_xhr_fixCallback(callback) {
  2038. return callback.length === 1 ? function(error, request) {
  2039. callback(error == null ? request : null);
  2040. } : callback;
  2041. }
  2042. function d3_xhrHasResponse(request) {
  2043. var type = request.responseType;
  2044. return type && type !== "text" ? request.response : request.responseText;
  2045. }
  2046. d3.dsv = function(delimiter, mimeType) {
  2047. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  2048. function dsv(url, row, callback) {
  2049. if (arguments.length < 3) callback = row, row = null;
  2050. var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
  2051. xhr.row = function(_) {
  2052. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  2053. };
  2054. return xhr;
  2055. }
  2056. function response(request) {
  2057. return dsv.parse(request.responseText);
  2058. }
  2059. function typedResponse(f) {
  2060. return function(request) {
  2061. return dsv.parse(request.responseText, f);
  2062. };
  2063. }
  2064. dsv.parse = function(text, f) {
  2065. var o;
  2066. return dsv.parseRows(text, function(row, i) {
  2067. if (o) return o(row, i - 1);
  2068. var a = new Function("d", "return {" + row.map(function(name, i) {
  2069. return JSON.stringify(name) + ": d[" + i + "]";
  2070. }).join(",") + "}");
  2071. o = f ? function(row, i) {
  2072. return f(a(row), i);
  2073. } : a;
  2074. });
  2075. };
  2076. dsv.parseRows = function(text, f) {
  2077. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  2078. function token() {
  2079. if (I >= N) return EOF;
  2080. if (eol) return eol = false, EOL;
  2081. var j = I;
  2082. if (text.charCodeAt(j) === 34) {
  2083. var i = j;
  2084. while (i++ < N) {
  2085. if (text.charCodeAt(i) === 34) {
  2086. if (text.charCodeAt(i + 1) !== 34) break;
  2087. ++i;
  2088. }
  2089. }
  2090. I = i + 2;
  2091. var c = text.charCodeAt(i + 1);
  2092. if (c === 13) {
  2093. eol = true;
  2094. if (text.charCodeAt(i + 2) === 10) ++I;
  2095. } else if (c === 10) {
  2096. eol = true;
  2097. }
  2098. return text.slice(j + 1, i).replace(/""/g, '"');
  2099. }
  2100. while (I < N) {
  2101. var c = text.charCodeAt(I++), k = 1;
  2102. if (c === 10) eol = true; else if (c === 13) {
  2103. eol = true;
  2104. if (text.charCodeAt(I) === 10) ++I, ++k;
  2105. } else if (c !== delimiterCode) continue;
  2106. return text.slice(j, I - k);
  2107. }
  2108. return text.slice(j);
  2109. }
  2110. while ((t = token()) !== EOF) {
  2111. var a = [];
  2112. while (t !== EOL && t !== EOF) {
  2113. a.push(t);
  2114. t = token();
  2115. }
  2116. if (f && (a = f(a, n++)) == null) continue;
  2117. rows.push(a);
  2118. }
  2119. return rows;
  2120. };
  2121. dsv.format = function(rows) {
  2122. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  2123. var fieldSet = new d3_Set(), fields = [];
  2124. rows.forEach(function(row) {
  2125. for (var field in row) {
  2126. if (!fieldSet.has(field)) {
  2127. fields.push(fieldSet.add(field));
  2128. }
  2129. }
  2130. });
  2131. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  2132. return fields.map(function(field) {
  2133. return formatValue(row[field]);
  2134. }).join(delimiter);
  2135. })).join("\n");
  2136. };
  2137. dsv.formatRows = function(rows) {
  2138. return rows.map(formatRow).join("\n");
  2139. };
  2140. function formatRow(row) {
  2141. return row.map(formatValue).join(delimiter);
  2142. }
  2143. function formatValue(text) {
  2144. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  2145. }
  2146. return dsv;
  2147. };
  2148. d3.csv = d3.dsv(",", "text/csv");
  2149. d3.tsv = d3.dsv(" ", "text/tab-separated-values");
  2150. var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
  2151. setTimeout(callback, 17);
  2152. };
  2153. d3.timer = function() {
  2154. d3_timer.apply(this, arguments);
  2155. };
  2156. function d3_timer(callback, delay, then) {
  2157. var n = arguments.length;
  2158. if (n < 2) delay = 0;
  2159. if (n < 3) then = Date.now();
  2160. var time = then + delay, timer = {
  2161. c: callback,
  2162. t: time,
  2163. n: null
  2164. };
  2165. if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
  2166. d3_timer_queueTail = timer;
  2167. if (!d3_timer_interval) {
  2168. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  2169. d3_timer_interval = 1;
  2170. d3_timer_frame(d3_timer_step);
  2171. }
  2172. return timer;
  2173. }
  2174. function d3_timer_step() {
  2175. var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
  2176. if (delay > 24) {
  2177. if (isFinite(delay)) {
  2178. clearTimeout(d3_timer_timeout);
  2179. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  2180. }
  2181. d3_timer_interval = 0;
  2182. } else {
  2183. d3_timer_interval = 1;
  2184. d3_timer_frame(d3_timer_step);
  2185. }
  2186. }
  2187. d3.timer.flush = function() {
  2188. d3_timer_mark();
  2189. d3_timer_sweep();
  2190. };
  2191. function d3_timer_mark() {
  2192. var now = Date.now(), timer = d3_timer_queueHead;
  2193. while (timer) {
  2194. if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
  2195. timer = timer.n;
  2196. }
  2197. return now;
  2198. }
  2199. function d3_timer_sweep() {
  2200. var t0, t1 = d3_timer_queueHead, time = Infinity;
  2201. while (t1) {
  2202. if (t1.c) {
  2203. if (t1.t < time) time = t1.t;
  2204. t1 = (t0 = t1).n;
  2205. } else {
  2206. t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
  2207. }
  2208. }
  2209. d3_timer_queueTail = t0;
  2210. return time;
  2211. }
  2212. function d3_format_precision(x, p) {
  2213. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  2214. }
  2215. d3.round = function(x, n) {
  2216. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  2217. };
  2218. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  2219. d3.formatPrefix = function(value, precision) {
  2220. var i = 0;
  2221. if (value = +value) {
  2222. if (value < 0) value *= -1;
  2223. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  2224. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  2225. i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
  2226. }
  2227. return d3_formatPrefixes[8 + i / 3];
  2228. };
  2229. function d3_formatPrefix(d, i) {
  2230. var k = Math.pow(10, abs(8 - i) * 3);
  2231. return {
  2232. scale: i > 8 ? function(d) {
  2233. return d / k;
  2234. } : function(d) {
  2235. return d * k;
  2236. },
  2237. symbol: d
  2238. };
  2239. }
  2240. function d3_locale_numberFormat(locale) {
  2241. var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {
  2242. var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
  2243. while (i > 0 && g > 0) {
  2244. if (length + g + 1 > width) g = Math.max(1, width - length);
  2245. t.push(value.substring(i -= g, i + g));
  2246. if ((length += g + 1) > width) break;
  2247. g = locale_grouping[j = (j + 1) % locale_grouping.length];
  2248. }
  2249. return t.reverse().join(locale_thousands);
  2250. } : d3_identity;
  2251. return function(specifier) {
  2252. var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true;
  2253. if (precision) precision = +precision.substring(1);
  2254. if (zfill || fill === "0" && align === "=") {
  2255. zfill = fill = "0";
  2256. align = "=";
  2257. }
  2258. switch (type) {
  2259. case "n":
  2260. comma = true;
  2261. type = "g";
  2262. break;
  2263. case "%":
  2264. scale = 100;
  2265. suffix = "%";
  2266. type = "f";
  2267. break;
  2268. case "p":
  2269. scale = 100;
  2270. suffix = "%";
  2271. type = "r";
  2272. break;
  2273. case "b":
  2274. case "o":
  2275. case "x":
  2276. case "X":
  2277. if (symbol === "#") prefix = "0" + type.toLowerCase();
  2278. case "c":
  2279. exponent = false;
  2280. case "d":
  2281. integer = true;
  2282. precision = 0;
  2283. break;
  2284. case "s":
  2285. scale = -1;
  2286. type = "r";
  2287. break;
  2288. }
  2289. if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
  2290. if (type == "r" && !precision) type = "g";
  2291. if (precision != null) {
  2292. 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));
  2293. }
  2294. type = d3_format_types.get(type) || d3_format_typeDefault;
  2295. var zcomma = zfill && comma;
  2296. return function(value) {
  2297. var fullSuffix = suffix;
  2298. if (integer && value % 1) return "";
  2299. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
  2300. if (scale < 0) {
  2301. var unit = d3.formatPrefix(value, precision);
  2302. value = unit.scale(value);
  2303. fullSuffix = unit.symbol + suffix;
  2304. } else {
  2305. value *= scale;
  2306. }
  2307. value = type(value, precision);
  2308. var i = value.lastIndexOf("."), before, after;
  2309. if (i < 0) {
  2310. var j = exponent ? value.lastIndexOf("e") : -1;
  2311. if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
  2312. } else {
  2313. before = value.substring(0, i);
  2314. after = locale_decimal + value.substring(i + 1);
  2315. }
  2316. if (!zfill && comma) before = formatGroup(before, Infinity);
  2317. var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  2318. if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
  2319. negative += prefix;
  2320. value = before + after;
  2321. return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix;
  2322. };
  2323. };
  2324. }
  2325. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  2326. var d3_format_types = d3.map({
  2327. b: function(x) {
  2328. return x.toString(2);
  2329. },
  2330. c: function(x) {
  2331. return String.fromCharCode(x);
  2332. },
  2333. o: function(x) {
  2334. return x.toString(8);
  2335. },
  2336. x: function(x) {
  2337. return x.toString(16);
  2338. },
  2339. X: function(x) {
  2340. return x.toString(16).toUpperCase();
  2341. },
  2342. g: function(x, p) {
  2343. return x.toPrecision(p);
  2344. },
  2345. e: function(x, p) {
  2346. return x.toExponential(p);
  2347. },
  2348. f: function(x, p) {
  2349. return x.toFixed(p);
  2350. },
  2351. r: function(x, p) {
  2352. 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))));
  2353. }
  2354. });
  2355. function d3_format_typeDefault(x) {
  2356. return x + "";
  2357. }
  2358. var d3_time = d3.time = {}, d3_date = Date;
  2359. function d3_date_utc() {
  2360. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  2361. }
  2362. d3_date_utc.prototype = {
  2363. getDate: function() {
  2364. return this._.getUTCDate();
  2365. },
  2366. getDay: function() {
  2367. return this._.getUTCDay();
  2368. },
  2369. getFullYear: function() {
  2370. return this._.getUTCFullYear();
  2371. },
  2372. getHours: function() {
  2373. return this._.getUTCHours();
  2374. },
  2375. getMilliseconds: function() {
  2376. return this._.getUTCMilliseconds();
  2377. },
  2378. getMinutes: function() {
  2379. return this._.getUTCMinutes();
  2380. },
  2381. getMonth: function() {
  2382. return this._.getUTCMonth();
  2383. },
  2384. getSeconds: function() {
  2385. return this._.getUTCSeconds();
  2386. },
  2387. getTime: function() {
  2388. return this._.getTime();
  2389. },
  2390. getTimezoneOffset: function() {
  2391. return 0;
  2392. },
  2393. valueOf: function() {
  2394. return this._.valueOf();
  2395. },
  2396. setDate: function() {
  2397. d3_time_prototype.setUTCDate.apply(this._, arguments);
  2398. },
  2399. setDay: function() {
  2400. d3_time_prototype.setUTCDay.apply(this._, arguments);
  2401. },
  2402. setFullYear: function() {
  2403. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  2404. },
  2405. setHours: function() {
  2406. d3_time_prototype.setUTCHours.apply(this._, arguments);
  2407. },
  2408. setMilliseconds: function() {
  2409. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  2410. },
  2411. setMinutes: function() {
  2412. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  2413. },
  2414. setMonth: function() {
  2415. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  2416. },
  2417. setSeconds: function() {
  2418. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  2419. },
  2420. setTime: function() {
  2421. d3_time_prototype.setTime.apply(this._, arguments);
  2422. }
  2423. };
  2424. var d3_time_prototype = Date.prototype;
  2425. function d3_time_interval(local, step, number) {
  2426. function round(date) {
  2427. var d0 = local(date), d1 = offset(d0, 1);
  2428. return date - d0 < d1 - date ? d0 : d1;
  2429. }
  2430. function ceil(date) {
  2431. step(date = local(new d3_date(date - 1)), 1);
  2432. return date;
  2433. }
  2434. function offset(date, k) {
  2435. step(date = new d3_date(+date), k);
  2436. return date;
  2437. }
  2438. function range(t0, t1, dt) {
  2439. var time = ceil(t0), times = [];
  2440. if (dt > 1) {
  2441. while (time < t1) {
  2442. if (!(number(time) % dt)) times.push(new Date(+time));
  2443. step(time, 1);
  2444. }
  2445. } else {
  2446. while (time < t1) times.push(new Date(+time)), step(time, 1);
  2447. }
  2448. return times;
  2449. }
  2450. function range_utc(t0, t1, dt) {
  2451. try {
  2452. d3_date = d3_date_utc;
  2453. var utc = new d3_date_utc();
  2454. utc._ = t0;
  2455. return range(utc, t1, dt);
  2456. } finally {
  2457. d3_date = Date;
  2458. }
  2459. }
  2460. local.floor = local;
  2461. local.round = round;
  2462. local.ceil = ceil;
  2463. local.offset = offset;
  2464. local.range = range;
  2465. var utc = local.utc = d3_time_interval_utc(local);
  2466. utc.floor = utc;
  2467. utc.round = d3_time_interval_utc(round);
  2468. utc.ceil = d3_time_interval_utc(ceil);
  2469. utc.offset = d3_time_interval_utc(offset);
  2470. utc.range = range_utc;
  2471. return local;
  2472. }
  2473. function d3_time_interval_utc(method) {
  2474. return function(date, k) {
  2475. try {
  2476. d3_date = d3_date_utc;
  2477. var utc = new d3_date_utc();
  2478. utc._ = date;
  2479. return method(utc, k)._;
  2480. } finally {
  2481. d3_date = Date;
  2482. }
  2483. };
  2484. }
  2485. d3_time.year = d3_time_interval(function(date) {
  2486. date = d3_time.day(date);
  2487. date.setMonth(0, 1);
  2488. return date;
  2489. }, function(date, offset) {
  2490. date.setFullYear(date.getFullYear() + offset);
  2491. }, function(date) {
  2492. return date.getFullYear();
  2493. });
  2494. d3_time.years = d3_time.year.range;
  2495. d3_time.years.utc = d3_time.year.utc.range;
  2496. d3_time.day = d3_time_interval(function(date) {
  2497. var day = new d3_date(2e3, 0);
  2498. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  2499. return day;
  2500. }, function(date, offset) {
  2501. date.setDate(date.getDate() + offset);
  2502. }, function(date) {
  2503. return date.getDate() - 1;
  2504. });
  2505. d3_time.days = d3_time.day.range;
  2506. d3_time.days.utc = d3_time.day.utc.range;
  2507. d3_time.dayOfYear = function(date) {
  2508. var year = d3_time.year(date);
  2509. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  2510. };
  2511. [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
  2512. i = 7 - i;
  2513. var interval = d3_time[day] = d3_time_interval(function(date) {
  2514. (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  2515. return date;
  2516. }, function(date, offset) {
  2517. date.setDate(date.getDate() + Math.floor(offset) * 7);
  2518. }, function(date) {
  2519. var day = d3_time.year(date).getDay();
  2520. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  2521. });
  2522. d3_time[day + "s"] = interval.range;
  2523. d3_time[day + "s"].utc = interval.utc.range;
  2524. d3_time[day + "OfYear"] = function(date) {
  2525. var day = d3_time.year(date).getDay();
  2526. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
  2527. };
  2528. });
  2529. d3_time.week = d3_time.sunday;
  2530. d3_time.weeks = d3_time.sunday.range;
  2531. d3_time.weeks.utc = d3_time.sunday.utc.range;
  2532. d3_time.weekOfYear = d3_time.sundayOfYear;
  2533. function d3_locale_timeFormat(locale) {
  2534. var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;
  2535. function d3_time_format(template) {
  2536. var n = template.length;
  2537. function format(date) {
  2538. var string = [], i = -1, j = 0, c, p, f;
  2539. while (++i < n) {
  2540. if (template.charCodeAt(i) === 37) {
  2541. string.push(template.slice(j, i));
  2542. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  2543. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  2544. string.push(c);
  2545. j = i + 1;
  2546. }
  2547. }
  2548. string.push(template.slice(j, i));
  2549. return string.join("");
  2550. }
  2551. format.parse = function(string) {
  2552. var d = {
  2553. y: 1900,
  2554. m: 0,
  2555. d: 1,
  2556. H: 0,
  2557. M: 0,
  2558. S: 0,
  2559. L: 0,
  2560. Z: null
  2561. }, i = d3_time_parse(d, template, string, 0);
  2562. if (i != string.length) return null;
  2563. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  2564. var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
  2565. if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) {
  2566. if (!("w" in d)) d.w = "W" in d ? 1 : 0;
  2567. date.setFullYear(d.y, 0, 1);
  2568. date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);
  2569. } else date.setFullYear(d.y, d.m, d.d);
  2570. date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
  2571. return localZ ? date._ : date;
  2572. };
  2573. format.toString = function() {
  2574. return template;
  2575. };
  2576. return format;
  2577. }
  2578. function d3_time_parse(date, template, string, j) {
  2579. var c, p, t, i = 0, n = template.length, m = string.length;
  2580. while (i < n) {
  2581. if (j >= m) return -1;
  2582. c = template.charCodeAt(i++);
  2583. if (c === 37) {
  2584. t = template.charAt(i++);
  2585. p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
  2586. if (!p || (j = p(date, string, j)) < 0) return -1;
  2587. } else if (c != string.charCodeAt(j++)) {
  2588. return -1;
  2589. }
  2590. }
  2591. return j;
  2592. }
  2593. d3_time_format.utc = function(template) {
  2594. var local = d3_time_format(template);
  2595. function format(date) {
  2596. try {
  2597. d3_date = d3_date_utc;
  2598. var utc = new d3_date();
  2599. utc._ = date;
  2600. return local(utc);
  2601. } finally {
  2602. d3_date = Date;
  2603. }
  2604. }
  2605. format.parse = function(string) {
  2606. try {
  2607. d3_date = d3_date_utc;
  2608. var date = local.parse(string);
  2609. return date && date._;
  2610. } finally {
  2611. d3_date = Date;
  2612. }
  2613. };
  2614. format.toString = local.toString;
  2615. return format;
  2616. };
  2617. d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
  2618. var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths);
  2619. locale_periods.forEach(function(p, i) {
  2620. d3_time_periodLookup.set(p.toLowerCase(), i);
  2621. });
  2622. var d3_time_formats = {
  2623. a: function(d) {
  2624. return locale_shortDays[d.getDay()];
  2625. },
  2626. A: function(d) {
  2627. return locale_days[d.getDay()];
  2628. },
  2629. b: function(d) {
  2630. return locale_shortMonths[d.getMonth()];
  2631. },
  2632. B: function(d) {
  2633. return locale_months[d.getMonth()];
  2634. },
  2635. c: d3_time_format(locale_dateTime),
  2636. d: function(d, p) {
  2637. return d3_time_formatPad(d.getDate(), p, 2);
  2638. },
  2639. e: function(d, p) {
  2640. return d3_time_formatPad(d.getDate(), p, 2);
  2641. },
  2642. H: function(d, p) {
  2643. return d3_time_formatPad(d.getHours(), p, 2);
  2644. },
  2645. I: function(d, p) {
  2646. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  2647. },
  2648. j: function(d, p) {
  2649. return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
  2650. },
  2651. L: function(d, p) {
  2652. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  2653. },
  2654. m: function(d, p) {
  2655. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  2656. },
  2657. M: function(d, p) {
  2658. return d3_time_formatPad(d.getMinutes(), p, 2);
  2659. },
  2660. p: function(d) {
  2661. return locale_periods[+(d.getHours() >= 12)];
  2662. },
  2663. S: function(d, p) {
  2664. return d3_time_formatPad(d.getSeconds(), p, 2);
  2665. },
  2666. U: function(d, p) {
  2667. return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
  2668. },
  2669. w: function(d) {
  2670. return d.getDay();
  2671. },
  2672. W: function(d, p) {
  2673. return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
  2674. },
  2675. x: d3_time_format(locale_date),
  2676. X: d3_time_format(locale_time),
  2677. y: function(d, p) {
  2678. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  2679. },
  2680. Y: function(d, p) {
  2681. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  2682. },
  2683. Z: d3_time_zone,
  2684. "%": function() {
  2685. return "%";
  2686. }
  2687. };
  2688. var d3_time_parsers = {
  2689. a: d3_time_parseWeekdayAbbrev,
  2690. A: d3_time_parseWeekday,
  2691. b: d3_time_parseMonthAbbrev,
  2692. B: d3_time_parseMonth,
  2693. c: d3_time_parseLocaleFull,
  2694. d: d3_time_parseDay,
  2695. e: d3_time_parseDay,
  2696. H: d3_time_parseHour24,
  2697. I: d3_time_parseHour24,
  2698. j: d3_time_parseDayOfYear,
  2699. L: d3_time_parseMilliseconds,
  2700. m: d3_time_parseMonthNumber,
  2701. M: d3_time_parseMinutes,
  2702. p: d3_time_parseAmPm,
  2703. S: d3_time_parseSeconds,
  2704. U: d3_time_parseWeekNumberSunday,
  2705. w: d3_time_parseWeekdayNumber,
  2706. W: d3_time_parseWeekNumberMonday,
  2707. x: d3_time_parseLocaleDate,
  2708. X: d3_time_parseLocaleTime,
  2709. y: d3_time_parseYear,
  2710. Y: d3_time_parseFullYear,
  2711. Z: d3_time_parseZone,
  2712. "%": d3_time_parseLiteralPercent
  2713. };
  2714. function d3_time_parseWeekdayAbbrev(date, string, i) {
  2715. d3_time_dayAbbrevRe.lastIndex = 0;
  2716. var n = d3_time_dayAbbrevRe.exec(string.slice(i));
  2717. return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2718. }
  2719. function d3_time_parseWeekday(date, string, i) {
  2720. d3_time_dayRe.lastIndex = 0;
  2721. var n = d3_time_dayRe.exec(string.slice(i));
  2722. return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2723. }
  2724. function d3_time_parseMonthAbbrev(date, string, i) {
  2725. d3_time_monthAbbrevRe.lastIndex = 0;
  2726. var n = d3_time_monthAbbrevRe.exec(string.slice(i));
  2727. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2728. }
  2729. function d3_time_parseMonth(date, string, i) {
  2730. d3_time_monthRe.lastIndex = 0;
  2731. var n = d3_time_monthRe.exec(string.slice(i));
  2732. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2733. }
  2734. function d3_time_parseLocaleFull(date, string, i) {
  2735. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  2736. }
  2737. function d3_time_parseLocaleDate(date, string, i) {
  2738. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  2739. }
  2740. function d3_time_parseLocaleTime(date, string, i) {
  2741. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  2742. }
  2743. function d3_time_parseAmPm(date, string, i) {
  2744. var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
  2745. return n == null ? -1 : (date.p = n, i);
  2746. }
  2747. return d3_time_format;
  2748. }
  2749. var d3_time_formatPads = {
  2750. "-": "",
  2751. _: " ",
  2752. "0": "0"
  2753. }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
  2754. function d3_time_formatPad(value, fill, width) {
  2755. var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
  2756. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  2757. }
  2758. function d3_time_formatRe(names) {
  2759. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  2760. }
  2761. function d3_time_formatLookup(names) {
  2762. var map = new d3_Map(), i = -1, n = names.length;
  2763. while (++i < n) map.set(names[i].toLowerCase(), i);
  2764. return map;
  2765. }
  2766. function d3_time_parseWeekdayNumber(date, string, i) {
  2767. d3_time_numberRe.lastIndex = 0;
  2768. var n = d3_time_numberRe.exec(string.slice(i, i + 1));
  2769. return n ? (date.w = +n[0], i + n[0].length) : -1;
  2770. }
  2771. function d3_time_parseWeekNumberSunday(date, string, i) {
  2772. d3_time_numberRe.lastIndex = 0;
  2773. var n = d3_time_numberRe.exec(string.slice(i));
  2774. return n ? (date.U = +n[0], i + n[0].length) : -1;
  2775. }
  2776. function d3_time_parseWeekNumberMonday(date, string, i) {
  2777. d3_time_numberRe.lastIndex = 0;
  2778. var n = d3_time_numberRe.exec(string.slice(i));
  2779. return n ? (date.W = +n[0], i + n[0].length) : -1;
  2780. }
  2781. function d3_time_parseFullYear(date, string, i) {
  2782. d3_time_numberRe.lastIndex = 0;
  2783. var n = d3_time_numberRe.exec(string.slice(i, i + 4));
  2784. return n ? (date.y = +n[0], i + n[0].length) : -1;
  2785. }
  2786. function d3_time_parseYear(date, string, i) {
  2787. d3_time_numberRe.lastIndex = 0;
  2788. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2789. return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
  2790. }
  2791. function d3_time_parseZone(date, string, i) {
  2792. return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
  2793. i + 5) : -1;
  2794. }
  2795. function d3_time_expandYear(d) {
  2796. return d + (d > 68 ? 1900 : 2e3);
  2797. }
  2798. function d3_time_parseMonthNumber(date, string, i) {
  2799. d3_time_numberRe.lastIndex = 0;
  2800. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2801. return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
  2802. }
  2803. function d3_time_parseDay(date, string, i) {
  2804. d3_time_numberRe.lastIndex = 0;
  2805. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2806. return n ? (date.d = +n[0], i + n[0].length) : -1;
  2807. }
  2808. function d3_time_parseDayOfYear(date, string, i) {
  2809. d3_time_numberRe.lastIndex = 0;
  2810. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2811. return n ? (date.j = +n[0], i + n[0].length) : -1;
  2812. }
  2813. function d3_time_parseHour24(date, string, i) {
  2814. d3_time_numberRe.lastIndex = 0;
  2815. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2816. return n ? (date.H = +n[0], i + n[0].length) : -1;
  2817. }
  2818. function d3_time_parseMinutes(date, string, i) {
  2819. d3_time_numberRe.lastIndex = 0;
  2820. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2821. return n ? (date.M = +n[0], i + n[0].length) : -1;
  2822. }
  2823. function d3_time_parseSeconds(date, string, i) {
  2824. d3_time_numberRe.lastIndex = 0;
  2825. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2826. return n ? (date.S = +n[0], i + n[0].length) : -1;
  2827. }
  2828. function d3_time_parseMilliseconds(date, string, i) {
  2829. d3_time_numberRe.lastIndex = 0;
  2830. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2831. return n ? (date.L = +n[0], i + n[0].length) : -1;
  2832. }
  2833. function d3_time_zone(d) {
  2834. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
  2835. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  2836. }
  2837. function d3_time_parseLiteralPercent(date, string, i) {
  2838. d3_time_percentRe.lastIndex = 0;
  2839. var n = d3_time_percentRe.exec(string.slice(i, i + 1));
  2840. return n ? i + n[0].length : -1;
  2841. }
  2842. function d3_time_formatMulti(formats) {
  2843. var n = formats.length, i = -1;
  2844. while (++i < n) formats[i][0] = this(formats[i][0]);
  2845. return function(date) {
  2846. var i = 0, f = formats[i];
  2847. while (!f[1](date)) f = formats[++i];
  2848. return f[0](date);
  2849. };
  2850. }
  2851. d3.locale = function(locale) {
  2852. return {
  2853. numberFormat: d3_locale_numberFormat(locale),
  2854. timeFormat: d3_locale_timeFormat(locale)
  2855. };
  2856. };
  2857. var d3_locale_enUS = d3.locale({
  2858. decimal: ".",
  2859. thousands: ",",
  2860. grouping: [ 3 ],
  2861. currency: [ "$", "" ],
  2862. dateTime: "%a %b %e %X %Y",
  2863. date: "%m/%d/%Y",
  2864. time: "%H:%M:%S",
  2865. periods: [ "AM", "PM" ],
  2866. days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
  2867. shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
  2868. months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  2869. shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
  2870. });
  2871. d3.format = d3_locale_enUS.numberFormat;
  2872. d3.geo = {};
  2873. function d3_adder() {}
  2874. d3_adder.prototype = {
  2875. s: 0,
  2876. t: 0,
  2877. add: function(y) {
  2878. d3_adderSum(y, this.t, d3_adderTemp);
  2879. d3_adderSum(d3_adderTemp.s, this.s, this);
  2880. if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
  2881. },
  2882. reset: function() {
  2883. this.s = this.t = 0;
  2884. },
  2885. valueOf: function() {
  2886. return this.s;
  2887. }
  2888. };
  2889. var d3_adderTemp = new d3_adder();
  2890. function d3_adderSum(a, b, o) {
  2891. var x = o.s = a + b, bv = x - a, av = x - bv;
  2892. o.t = a - av + (b - bv);
  2893. }
  2894. d3.geo.stream = function(object, listener) {
  2895. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  2896. d3_geo_streamObjectType[object.type](object, listener);
  2897. } else {
  2898. d3_geo_streamGeometry(object, listener);
  2899. }
  2900. };
  2901. function d3_geo_streamGeometry(geometry, listener) {
  2902. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  2903. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  2904. }
  2905. }
  2906. var d3_geo_streamObjectType = {
  2907. Feature: function(feature, listener) {
  2908. d3_geo_streamGeometry(feature.geometry, listener);
  2909. },
  2910. FeatureCollection: function(object, listener) {
  2911. var features = object.features, i = -1, n = features.length;
  2912. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  2913. }
  2914. };
  2915. var d3_geo_streamGeometryType = {
  2916. Sphere: function(object, listener) {
  2917. listener.sphere();
  2918. },
  2919. Point: function(object, listener) {
  2920. object = object.coordinates;
  2921. listener.point(object[0], object[1], object[2]);
  2922. },
  2923. MultiPoint: function(object, listener) {
  2924. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2925. while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
  2926. },
  2927. LineString: function(object, listener) {
  2928. d3_geo_streamLine(object.coordinates, listener, 0);
  2929. },
  2930. MultiLineString: function(object, listener) {
  2931. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2932. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  2933. },
  2934. Polygon: function(object, listener) {
  2935. d3_geo_streamPolygon(object.coordinates, listener);
  2936. },
  2937. MultiPolygon: function(object, listener) {
  2938. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2939. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  2940. },
  2941. GeometryCollection: function(object, listener) {
  2942. var geometries = object.geometries, i = -1, n = geometries.length;
  2943. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  2944. }
  2945. };
  2946. function d3_geo_streamLine(coordinates, listener, closed) {
  2947. var i = -1, n = coordinates.length - closed, coordinate;
  2948. listener.lineStart();
  2949. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
  2950. listener.lineEnd();
  2951. }
  2952. function d3_geo_streamPolygon(coordinates, listener) {
  2953. var i = -1, n = coordinates.length;
  2954. listener.polygonStart();
  2955. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  2956. listener.polygonEnd();
  2957. }
  2958. d3.geo.area = function(object) {
  2959. d3_geo_areaSum = 0;
  2960. d3.geo.stream(object, d3_geo_area);
  2961. return d3_geo_areaSum;
  2962. };
  2963. var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
  2964. var d3_geo_area = {
  2965. sphere: function() {
  2966. d3_geo_areaSum += 4 * π;
  2967. },
  2968. point: d3_noop,
  2969. lineStart: d3_noop,
  2970. lineEnd: d3_noop,
  2971. polygonStart: function() {
  2972. d3_geo_areaRingSum.reset();
  2973. d3_geo_area.lineStart = d3_geo_areaRingStart;
  2974. },
  2975. polygonEnd: function() {
  2976. var area = 2 * d3_geo_areaRingSum;
  2977. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  2978. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  2979. }
  2980. };
  2981. function d3_geo_areaRingStart() {
  2982. var λ00, φ00, λ0, cosφ0, sinφ0;
  2983. d3_geo_area.point = function(λ, φ) {
  2984. d3_geo_area.point = nextPoint;
  2985. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  2986. sinφ0 = Math.sin(φ);
  2987. };
  2988. function nextPoint(λ, φ) {
  2989. λ *= d3_radians;
  2990. φ = φ * d3_radians / 2 + π / 4;
  2991. var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
  2992. d3_geo_areaRingSum.add(Math.atan2(v, u));
  2993. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  2994. }
  2995. d3_geo_area.lineEnd = function() {
  2996. nextPoint(λ00, φ00);
  2997. };
  2998. }
  2999. function d3_geo_cartesian(spherical) {
  3000. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  3001. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  3002. }
  3003. function d3_geo_cartesianDot(a, b) {
  3004. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  3005. }
  3006. function d3_geo_cartesianCross(a, b) {
  3007. 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] ];
  3008. }
  3009. function d3_geo_cartesianAdd(a, b) {
  3010. a[0] += b[0];
  3011. a[1] += b[1];
  3012. a[2] += b[2];
  3013. }
  3014. function d3_geo_cartesianScale(vector, k) {
  3015. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  3016. }
  3017. function d3_geo_cartesianNormalize(d) {
  3018. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  3019. d[0] /= l;
  3020. d[1] /= l;
  3021. d[2] /= l;
  3022. }
  3023. function d3_geo_spherical(cartesian) {
  3024. return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
  3025. }
  3026. function d3_geo_sphericalEqual(a, b) {
  3027. return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
  3028. }
  3029. d3.geo.bounds = function() {
  3030. var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
  3031. var bound = {
  3032. point: point,
  3033. lineStart: lineStart,
  3034. lineEnd: lineEnd,
  3035. polygonStart: function() {
  3036. bound.point = ringPoint;
  3037. bound.lineStart = ringStart;
  3038. bound.lineEnd = ringEnd;
  3039. dλSum = 0;
  3040. d3_geo_area.polygonStart();
  3041. },
  3042. polygonEnd: function() {
  3043. d3_geo_area.polygonEnd();
  3044. bound.point = point;
  3045. bound.lineStart = lineStart;
  3046. bound.lineEnd = lineEnd;
  3047. if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
  3048. range[0] = λ0, range[1] = λ1;
  3049. }
  3050. };
  3051. function point(λ, φ) {
  3052. ranges.push(range = [ λ0 = λ, λ1 = λ ]);
  3053. if (φ < φ0) φ0 = φ;
  3054. if (φ > φ1) φ1 = φ;
  3055. }
  3056. function linePoint(λ, φ) {
  3057. var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
  3058. if (p0) {
  3059. var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
  3060. d3_geo_cartesianNormalize(inflection);
  3061. inflection = d3_geo_spherical(inflection);
  3062. var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
  3063. if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3064. var φi = inflection[1] * d3_degrees;
  3065. if (φi > φ1) φ1 = φi;
  3066. } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3067. var φi = -inflection[1] * d3_degrees;
  3068. if (φi < φ0) φ0 = φi;
  3069. } else {
  3070. if (φ < φ0) φ0 = φ;
  3071. if (φ > φ1) φ1 = φ;
  3072. }
  3073. if (antimeridian) {
  3074. if (λ < λ_) {
  3075. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3076. } else {
  3077. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3078. }
  3079. } else {
  3080. if (λ1 >= λ0) {
  3081. if (λ < λ0) λ0 = λ;
  3082. if (λ > λ1) λ1 = λ;
  3083. } else {
  3084. if (λ > λ_) {
  3085. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3086. } else {
  3087. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3088. }
  3089. }
  3090. }
  3091. } else {
  3092. point(λ, φ);
  3093. }
  3094. p0 = p, λ_ = λ;
  3095. }
  3096. function lineStart() {
  3097. bound.point = linePoint;
  3098. }
  3099. function lineEnd() {
  3100. range[0] = λ0, range[1] = λ1;
  3101. bound.point = point;
  3102. p0 = null;
  3103. }
  3104. function ringPoint(λ, φ) {
  3105. if (p0) {
  3106. var dλ = λ - λ_;
  3107. dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
  3108. } else λ__ = λ, φ__ = φ;
  3109. d3_geo_area.point(λ, φ);
  3110. linePoint(λ, φ);
  3111. }
  3112. function ringStart() {
  3113. d3_geo_area.lineStart();
  3114. }
  3115. function ringEnd() {
  3116. ringPoint(λ__, φ__);
  3117. d3_geo_area.lineEnd();
  3118. if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
  3119. range[0] = λ0, range[1] = λ1;
  3120. p0 = null;
  3121. }
  3122. function angle(λ0, λ1) {
  3123. return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
  3124. }
  3125. function compareRanges(a, b) {
  3126. return a[0] - b[0];
  3127. }
  3128. function withinRange(x, range) {
  3129. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  3130. }
  3131. return function(feature) {
  3132. φ1 = λ1 = -(λ0 = φ0 = Infinity);
  3133. ranges = [];
  3134. d3.geo.stream(feature, bound);
  3135. var n = ranges.length;
  3136. if (n) {
  3137. ranges.sort(compareRanges);
  3138. for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
  3139. b = ranges[i];
  3140. if (withinRange(b[0], a) || withinRange(b[1], a)) {
  3141. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  3142. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  3143. } else {
  3144. merged.push(a = b);
  3145. }
  3146. }
  3147. var best = -Infinity, dλ;
  3148. for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
  3149. b = merged[i];
  3150. if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
  3151. }
  3152. }
  3153. ranges = range = null;
  3154. return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
  3155. };
  3156. }();
  3157. d3.geo.centroid = function(object) {
  3158. d3_geo_centroidW0 = d3_geo_centroidW1 = d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
  3159. d3.geo.stream(object, d3_geo_centroid);
  3160. var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
  3161. if (m < ε2) {
  3162. x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
  3163. if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
  3164. m = x * x + y * y + z * z;
  3165. if (m < ε2) return [ NaN, NaN ];
  3166. }
  3167. return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
  3168. };
  3169. var d3_geo_centroidW0, d3_geo_centroidW1, d3_geo_centroidX0, d3_geo_centroidY0, d3_geo_centroidZ0, d3_geo_centroidX1, d3_geo_centroidY1, d3_geo_centroidZ1, d3_geo_centroidX2, d3_geo_centroidY2, d3_geo_centroidZ2;
  3170. var d3_geo_centroid = {
  3171. sphere: d3_noop,
  3172. point: d3_geo_centroidPoint,
  3173. lineStart: d3_geo_centroidLineStart,
  3174. lineEnd: d3_geo_centroidLineEnd,
  3175. polygonStart: function() {
  3176. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  3177. },
  3178. polygonEnd: function() {
  3179. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  3180. }
  3181. };
  3182. function d3_geo_centroidPoint(λ, φ) {
  3183. λ *= d3_radians;
  3184. var cosφ = Math.cos(φ *= d3_radians);
  3185. d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
  3186. }
  3187. function d3_geo_centroidPointXYZ(x, y, z) {
  3188. ++d3_geo_centroidW0;
  3189. d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
  3190. d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
  3191. d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
  3192. }
  3193. function d3_geo_centroidLineStart() {
  3194. var x0, y0, z0;
  3195. d3_geo_centroid.point = function(λ, φ) {
  3196. λ *= d3_radians;
  3197. var cosφ = Math.cos(φ *= d3_radians);
  3198. x0 = cosφ * Math.cos(λ);
  3199. y0 = cosφ * Math.sin(λ);
  3200. z0 = Math.sin(φ);
  3201. d3_geo_centroid.point = nextPoint;
  3202. d3_geo_centroidPointXYZ(x0, y0, z0);
  3203. };
  3204. function nextPoint(λ, φ) {
  3205. λ *= d3_radians;
  3206. var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), 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);
  3207. d3_geo_centroidW1 += w;
  3208. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3209. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3210. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3211. d3_geo_centroidPointXYZ(x0, y0, z0);
  3212. }
  3213. }
  3214. function d3_geo_centroidLineEnd() {
  3215. d3_geo_centroid.point = d3_geo_centroidPoint;
  3216. }
  3217. function d3_geo_centroidRingStart() {
  3218. var λ00, φ00, x0, y0, z0;
  3219. d3_geo_centroid.point = function(λ, φ) {
  3220. λ00 = λ, φ00 = φ;
  3221. d3_geo_centroid.point = nextPoint;
  3222. λ *= d3_radians;
  3223. var cosφ = Math.cos(φ *= d3_radians);
  3224. x0 = cosφ * Math.cos(λ);
  3225. y0 = cosφ * Math.sin(λ);
  3226. z0 = Math.sin(φ);
  3227. d3_geo_centroidPointXYZ(x0, y0, z0);
  3228. };
  3229. d3_geo_centroid.lineEnd = function() {
  3230. nextPoint(λ00, φ00);
  3231. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  3232. d3_geo_centroid.point = d3_geo_centroidPoint;
  3233. };
  3234. function nextPoint(λ, φ) {
  3235. λ *= d3_radians;
  3236. var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), cx = y0 * z - z0 * y, cy = z0 * x - x0 * z, cz = x0 * y - y0 * x, m = Math.sqrt(cx * cx + cy * cy + cz * cz), u = x0 * x + y0 * y + z0 * z, v = m && -d3_acos(u) / m, w = Math.atan2(m, u);
  3237. d3_geo_centroidX2 += v * cx;
  3238. d3_geo_centroidY2 += v * cy;
  3239. d3_geo_centroidZ2 += v * cz;
  3240. d3_geo_centroidW1 += w;
  3241. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3242. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3243. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3244. d3_geo_centroidPointXYZ(x0, y0, z0);
  3245. }
  3246. }
  3247. function d3_geo_compose(a, b) {
  3248. function compose(x, y) {
  3249. return x = a(x, y), b(x[0], x[1]);
  3250. }
  3251. if (a.invert && b.invert) compose.invert = function(x, y) {
  3252. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  3253. };
  3254. return compose;
  3255. }
  3256. function d3_true() {
  3257. return true;
  3258. }
  3259. function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
  3260. var subject = [], clip = [];
  3261. segments.forEach(function(segment) {
  3262. if ((n = segment.length - 1) <= 0) return;
  3263. var n, p0 = segment[0], p1 = segment[n];
  3264. if (d3_geo_sphericalEqual(p0, p1)) {
  3265. listener.lineStart();
  3266. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  3267. listener.lineEnd();
  3268. return;
  3269. }
  3270. var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
  3271. a.o = b;
  3272. subject.push(a);
  3273. clip.push(b);
  3274. a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
  3275. b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
  3276. a.o = b;
  3277. subject.push(a);
  3278. clip.push(b);
  3279. });
  3280. clip.sort(compare);
  3281. d3_geo_clipPolygonLinkCircular(subject);
  3282. d3_geo_clipPolygonLinkCircular(clip);
  3283. if (!subject.length) return;
  3284. for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
  3285. clip[i].e = entry = !entry;
  3286. }
  3287. var start = subject[0], points, point;
  3288. while (1) {
  3289. var current = start, isSubject = true;
  3290. while (current.v) if ((current = current.n) === start) return;
  3291. points = current.z;
  3292. listener.lineStart();
  3293. do {
  3294. current.v = current.o.v = true;
  3295. if (current.e) {
  3296. if (isSubject) {
  3297. for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
  3298. } else {
  3299. interpolate(current.x, current.n.x, 1, listener);
  3300. }
  3301. current = current.n;
  3302. } else {
  3303. if (isSubject) {
  3304. points = current.p.z;
  3305. for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
  3306. } else {
  3307. interpolate(current.x, current.p.x, -1, listener);
  3308. }
  3309. current = current.p;
  3310. }
  3311. current = current.o;
  3312. points = current.z;
  3313. isSubject = !isSubject;
  3314. } while (!current.v);
  3315. listener.lineEnd();
  3316. }
  3317. }
  3318. function d3_geo_clipPolygonLinkCircular(array) {
  3319. if (!(n = array.length)) return;
  3320. var n, i = 0, a = array[0], b;
  3321. while (++i < n) {
  3322. a.n = b = array[i];
  3323. b.p = a;
  3324. a = b;
  3325. }
  3326. a.n = b = array[0];
  3327. b.p = a;
  3328. }
  3329. function d3_geo_clipPolygonIntersection(point, points, other, entry) {
  3330. this.x = point;
  3331. this.z = points;
  3332. this.o = other;
  3333. this.e = entry;
  3334. this.v = false;
  3335. this.n = this.p = null;
  3336. }
  3337. function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
  3338. return function(rotate, listener) {
  3339. var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
  3340. var clip = {
  3341. point: point,
  3342. lineStart: lineStart,
  3343. lineEnd: lineEnd,
  3344. polygonStart: function() {
  3345. clip.point = pointRing;
  3346. clip.lineStart = ringStart;
  3347. clip.lineEnd = ringEnd;
  3348. segments = [];
  3349. polygon = [];
  3350. },
  3351. polygonEnd: function() {
  3352. clip.point = point;
  3353. clip.lineStart = lineStart;
  3354. clip.lineEnd = lineEnd;
  3355. segments = d3.merge(segments);
  3356. var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
  3357. if (segments.length) {
  3358. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3359. d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
  3360. } else if (clipStartInside) {
  3361. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3362. listener.lineStart();
  3363. interpolate(null, null, 1, listener);
  3364. listener.lineEnd();
  3365. }
  3366. if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
  3367. segments = polygon = null;
  3368. },
  3369. sphere: function() {
  3370. listener.polygonStart();
  3371. listener.lineStart();
  3372. interpolate(null, null, 1, listener);
  3373. listener.lineEnd();
  3374. listener.polygonEnd();
  3375. }
  3376. };
  3377. function point(λ, φ) {
  3378. var point = rotate(λ, φ);
  3379. if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
  3380. }
  3381. function pointLine(λ, φ) {
  3382. var point = rotate(λ, φ);
  3383. line.point(point[0], point[1]);
  3384. }
  3385. function lineStart() {
  3386. clip.point = pointLine;
  3387. line.lineStart();
  3388. }
  3389. function lineEnd() {
  3390. clip.point = point;
  3391. line.lineEnd();
  3392. }
  3393. var segments;
  3394. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
  3395. function pointRing(λ, φ) {
  3396. ring.push([ λ, φ ]);
  3397. var point = rotate(λ, φ);
  3398. ringListener.point(point[0], point[1]);
  3399. }
  3400. function ringStart() {
  3401. ringListener.lineStart();
  3402. ring = [];
  3403. }
  3404. function ringEnd() {
  3405. pointRing(ring[0][0], ring[0][1]);
  3406. ringListener.lineEnd();
  3407. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  3408. ring.pop();
  3409. polygon.push(ring);
  3410. ring = null;
  3411. if (!n) return;
  3412. if (clean & 1) {
  3413. segment = ringSegments[0];
  3414. var n = segment.length - 1, i = -1, point;
  3415. if (n > 0) {
  3416. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3417. listener.lineStart();
  3418. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  3419. listener.lineEnd();
  3420. }
  3421. return;
  3422. }
  3423. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  3424. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  3425. }
  3426. return clip;
  3427. };
  3428. }
  3429. function d3_geo_clipSegmentLength1(segment) {
  3430. return segment.length > 1;
  3431. }
  3432. function d3_geo_clipBufferListener() {
  3433. var lines = [], line;
  3434. return {
  3435. lineStart: function() {
  3436. lines.push(line = []);
  3437. },
  3438. point: function(λ, φ) {
  3439. line.push([ λ, φ ]);
  3440. },
  3441. lineEnd: d3_noop,
  3442. buffer: function() {
  3443. var buffer = lines;
  3444. lines = [];
  3445. line = null;
  3446. return buffer;
  3447. },
  3448. rejoin: function() {
  3449. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  3450. }
  3451. };
  3452. }
  3453. function d3_geo_clipSort(a, b) {
  3454. return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
  3455. }
  3456. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
  3457. function d3_geo_clipAntimeridianLine(listener) {
  3458. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  3459. return {
  3460. lineStart: function() {
  3461. listener.lineStart();
  3462. clean = 1;
  3463. },
  3464. point: function(λ1, φ1) {
  3465. var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
  3466. if (abs(dλ - π) < ε) {
  3467. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
  3468. listener.point(sλ0, φ0);
  3469. listener.lineEnd();
  3470. listener.lineStart();
  3471. listener.point(sλ1, φ0);
  3472. listener.point(λ1, φ0);
  3473. clean = 0;
  3474. } else if (sλ0 !== sλ1 && dλ >= π) {
  3475. if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  3476. if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  3477. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  3478. listener.point(sλ0, φ0);
  3479. listener.lineEnd();
  3480. listener.lineStart();
  3481. listener.point(sλ1, φ0);
  3482. clean = 0;
  3483. }
  3484. listener.point(λ0 = λ1, φ0 = φ1);
  3485. sλ0 = sλ1;
  3486. },
  3487. lineEnd: function() {
  3488. listener.lineEnd();
  3489. λ0 = φ0 = NaN;
  3490. },
  3491. clean: function() {
  3492. return 2 - clean;
  3493. }
  3494. };
  3495. }
  3496. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  3497. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  3498. return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
  3499. }
  3500. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  3501. var φ;
  3502. if (from == null) {
  3503. φ = direction * halfπ;
  3504. listener.point(-π, φ);
  3505. listener.point(0, φ);
  3506. listener.point(π, φ);
  3507. listener.point(π, 0);
  3508. listener.point(π, -φ);
  3509. listener.point(0, -φ);
  3510. listener.point(-π, -φ);
  3511. listener.point(-π, 0);
  3512. listener.point(-π, φ);
  3513. } else if (abs(from[0] - to[0]) > ε) {
  3514. var s = from[0] < to[0] ? π : -π;
  3515. φ = direction * s / 2;
  3516. listener.point(-s, φ);
  3517. listener.point(0, φ);
  3518. listener.point(s, φ);
  3519. } else {
  3520. listener.point(to[0], to[1]);
  3521. }
  3522. }
  3523. function d3_geo_pointInPolygon(point, polygon) {
  3524. var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
  3525. d3_geo_areaRingSum.reset();
  3526. for (var i = 0, n = polygon.length; i < n; ++i) {
  3527. var ring = polygon[i], m = ring.length;
  3528. if (!m) continue;
  3529. var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
  3530. while (true) {
  3531. if (j === m) j = 0;
  3532. point = ring[j];
  3533. var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;
  3534. d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
  3535. polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
  3536. if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
  3537. var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
  3538. d3_geo_cartesianNormalize(arc);
  3539. var intersection = d3_geo_cartesianCross(meridianNormal, arc);
  3540. d3_geo_cartesianNormalize(intersection);
  3541. var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
  3542. if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
  3543. winding += antimeridian ^ dλ >= 0 ? 1 : -1;
  3544. }
  3545. }
  3546. if (!j++) break;
  3547. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
  3548. }
  3549. }
  3550. return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < -ε) ^ winding & 1;
  3551. }
  3552. function d3_geo_clipCircle(radius) {
  3553. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  3554. return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
  3555. function visible(λ, φ) {
  3556. return Math.cos(λ) * Math.cos(φ) > cr;
  3557. }
  3558. function clipLine(listener) {
  3559. var point0, c0, v0, v00, clean;
  3560. return {
  3561. lineStart: function() {
  3562. v00 = v0 = false;
  3563. clean = 1;
  3564. },
  3565. point: function(λ, φ) {
  3566. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  3567. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  3568. if (v !== v0) {
  3569. point2 = intersect(point0, point1);
  3570. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  3571. point1[0] += ε;
  3572. point1[1] += ε;
  3573. v = visible(point1[0], point1[1]);
  3574. }
  3575. }
  3576. if (v !== v0) {
  3577. clean = 0;
  3578. if (v) {
  3579. listener.lineStart();
  3580. point2 = intersect(point1, point0);
  3581. listener.point(point2[0], point2[1]);
  3582. } else {
  3583. point2 = intersect(point0, point1);
  3584. listener.point(point2[0], point2[1]);
  3585. listener.lineEnd();
  3586. }
  3587. point0 = point2;
  3588. } else if (notHemisphere && point0 && smallRadius ^ v) {
  3589. var t;
  3590. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  3591. clean = 0;
  3592. if (smallRadius) {
  3593. listener.lineStart();
  3594. listener.point(t[0][0], t[0][1]);
  3595. listener.point(t[1][0], t[1][1]);
  3596. listener.lineEnd();
  3597. } else {
  3598. listener.point(t[1][0], t[1][1]);
  3599. listener.lineEnd();
  3600. listener.lineStart();
  3601. listener.point(t[0][0], t[0][1]);
  3602. }
  3603. }
  3604. }
  3605. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  3606. listener.point(point1[0], point1[1]);
  3607. }
  3608. point0 = point1, v0 = v, c0 = c;
  3609. },
  3610. lineEnd: function() {
  3611. if (v0) listener.lineEnd();
  3612. point0 = null;
  3613. },
  3614. clean: function() {
  3615. return clean | (v00 && v0) << 1;
  3616. }
  3617. };
  3618. }
  3619. function intersect(a, b, two) {
  3620. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  3621. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  3622. if (!determinant) return !two && a;
  3623. 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);
  3624. d3_geo_cartesianAdd(A, B);
  3625. 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);
  3626. if (t2 < 0) return;
  3627. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  3628. d3_geo_cartesianAdd(q, A);
  3629. q = d3_geo_spherical(q);
  3630. if (!two) return q;
  3631. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  3632. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  3633. var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
  3634. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  3635. if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
  3636. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  3637. d3_geo_cartesianAdd(q1, A);
  3638. return [ q, d3_geo_spherical(q1) ];
  3639. }
  3640. }
  3641. function code(λ, φ) {
  3642. var r = smallRadius ? radius : π - radius, code = 0;
  3643. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  3644. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  3645. return code;
  3646. }
  3647. }
  3648. function d3_geom_clipLine(x0, y0, x1, y1) {
  3649. return function(line) {
  3650. var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
  3651. r = x0 - ax;
  3652. if (!dx && r > 0) return;
  3653. r /= dx;
  3654. if (dx < 0) {
  3655. if (r < t0) return;
  3656. if (r < t1) t1 = r;
  3657. } else if (dx > 0) {
  3658. if (r > t1) return;
  3659. if (r > t0) t0 = r;
  3660. }
  3661. r = x1 - ax;
  3662. if (!dx && r < 0) return;
  3663. r /= dx;
  3664. if (dx < 0) {
  3665. if (r > t1) return;
  3666. if (r > t0) t0 = r;
  3667. } else if (dx > 0) {
  3668. if (r < t0) return;
  3669. if (r < t1) t1 = r;
  3670. }
  3671. r = y0 - ay;
  3672. if (!dy && r > 0) return;
  3673. r /= dy;
  3674. if (dy < 0) {
  3675. if (r < t0) return;
  3676. if (r < t1) t1 = r;
  3677. } else if (dy > 0) {
  3678. if (r > t1) return;
  3679. if (r > t0) t0 = r;
  3680. }
  3681. r = y1 - ay;
  3682. if (!dy && r < 0) return;
  3683. r /= dy;
  3684. if (dy < 0) {
  3685. if (r > t1) return;
  3686. if (r > t0) t0 = r;
  3687. } else if (dy > 0) {
  3688. if (r < t0) return;
  3689. if (r < t1) t1 = r;
  3690. }
  3691. if (t0 > 0) line.a = {
  3692. x: ax + t0 * dx,
  3693. y: ay + t0 * dy
  3694. };
  3695. if (t1 < 1) line.b = {
  3696. x: ax + t1 * dx,
  3697. y: ay + t1 * dy
  3698. };
  3699. return line;
  3700. };
  3701. }
  3702. var d3_geo_clipExtentMAX = 1e9;
  3703. d3.geo.clipExtent = function() {
  3704. var x0, y0, x1, y1, stream, clip, clipExtent = {
  3705. stream: function(output) {
  3706. if (stream) stream.valid = false;
  3707. stream = clip(output);
  3708. stream.valid = true;
  3709. return stream;
  3710. },
  3711. extent: function(_) {
  3712. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3713. clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
  3714. if (stream) stream.valid = false, stream = null;
  3715. return clipExtent;
  3716. }
  3717. };
  3718. return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
  3719. };
  3720. function d3_geo_clipExtent(x0, y0, x1, y1) {
  3721. return function(listener) {
  3722. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
  3723. var clip = {
  3724. point: point,
  3725. lineStart: lineStart,
  3726. lineEnd: lineEnd,
  3727. polygonStart: function() {
  3728. listener = bufferListener;
  3729. segments = [];
  3730. polygon = [];
  3731. clean = true;
  3732. },
  3733. polygonEnd: function() {
  3734. listener = listener_;
  3735. segments = d3.merge(segments);
  3736. var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
  3737. if (inside || visible) {
  3738. listener.polygonStart();
  3739. if (inside) {
  3740. listener.lineStart();
  3741. interpolate(null, null, 1, listener);
  3742. listener.lineEnd();
  3743. }
  3744. if (visible) {
  3745. d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
  3746. }
  3747. listener.polygonEnd();
  3748. }
  3749. segments = polygon = ring = null;
  3750. }
  3751. };
  3752. function insidePolygon(p) {
  3753. var wn = 0, n = polygon.length, y = p[1];
  3754. for (var i = 0; i < n; ++i) {
  3755. for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
  3756. b = v[j];
  3757. if (a[1] <= y) {
  3758. if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
  3759. } else {
  3760. if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
  3761. }
  3762. a = b;
  3763. }
  3764. }
  3765. return wn !== 0;
  3766. }
  3767. function interpolate(from, to, direction, listener) {
  3768. var a = 0, a1 = 0;
  3769. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  3770. do {
  3771. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  3772. } while ((a = (a + direction + 4) % 4) !== a1);
  3773. } else {
  3774. listener.point(to[0], to[1]);
  3775. }
  3776. }
  3777. function pointVisible(x, y) {
  3778. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  3779. }
  3780. function point(x, y) {
  3781. if (pointVisible(x, y)) listener.point(x, y);
  3782. }
  3783. var x__, y__, v__, x_, y_, v_, first, clean;
  3784. function lineStart() {
  3785. clip.point = linePoint;
  3786. if (polygon) polygon.push(ring = []);
  3787. first = true;
  3788. v_ = false;
  3789. x_ = y_ = NaN;
  3790. }
  3791. function lineEnd() {
  3792. if (segments) {
  3793. linePoint(x__, y__);
  3794. if (v__ && v_) bufferListener.rejoin();
  3795. segments.push(bufferListener.buffer());
  3796. }
  3797. clip.point = point;
  3798. if (v_) listener.lineEnd();
  3799. }
  3800. function linePoint(x, y) {
  3801. x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
  3802. y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
  3803. var v = pointVisible(x, y);
  3804. if (polygon) ring.push([ x, y ]);
  3805. if (first) {
  3806. x__ = x, y__ = y, v__ = v;
  3807. first = false;
  3808. if (v) {
  3809. listener.lineStart();
  3810. listener.point(x, y);
  3811. }
  3812. } else {
  3813. if (v && v_) listener.point(x, y); else {
  3814. var l = {
  3815. a: {
  3816. x: x_,
  3817. y: y_
  3818. },
  3819. b: {
  3820. x: x,
  3821. y: y
  3822. }
  3823. };
  3824. if (clipLine(l)) {
  3825. if (!v_) {
  3826. listener.lineStart();
  3827. listener.point(l.a.x, l.a.y);
  3828. }
  3829. listener.point(l.b.x, l.b.y);
  3830. if (!v) listener.lineEnd();
  3831. clean = false;
  3832. } else if (v) {
  3833. listener.lineStart();
  3834. listener.point(x, y);
  3835. clean = false;
  3836. }
  3837. }
  3838. }
  3839. x_ = x, y_ = y, v_ = v;
  3840. }
  3841. return clip;
  3842. };
  3843. function corner(p, direction) {
  3844. return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
  3845. }
  3846. function compare(a, b) {
  3847. return comparePoints(a.x, b.x);
  3848. }
  3849. function comparePoints(a, b) {
  3850. var ca = corner(a, 1), cb = corner(b, 1);
  3851. 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];
  3852. }
  3853. }
  3854. function d3_geo_conic(projectAt) {
  3855. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  3856. p.parallels = function(_) {
  3857. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  3858. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  3859. };
  3860. return p;
  3861. }
  3862. function d3_geo_conicEqualArea(φ0, φ1) {
  3863. 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;
  3864. function forward(λ, φ) {
  3865. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  3866. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  3867. }
  3868. forward.invert = function(x, y) {
  3869. var ρ0_y = ρ0 - y;
  3870. return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  3871. };
  3872. return forward;
  3873. }
  3874. (d3.geo.conicEqualArea = function() {
  3875. return d3_geo_conic(d3_geo_conicEqualArea);
  3876. }).raw = d3_geo_conicEqualArea;
  3877. d3.geo.albers = function() {
  3878. return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
  3879. };
  3880. d3.geo.albersUsa = function() {
  3881. var lower48 = d3.geo.albers();
  3882. var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
  3883. var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
  3884. var point, pointStream = {
  3885. point: function(x, y) {
  3886. point = [ x, y ];
  3887. }
  3888. }, lower48Point, alaskaPoint, hawaiiPoint;
  3889. function albersUsa(coordinates) {
  3890. var x = coordinates[0], y = coordinates[1];
  3891. point = null;
  3892. (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
  3893. return point;
  3894. }
  3895. albersUsa.invert = function(coordinates) {
  3896. var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
  3897. return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
  3898. };
  3899. albersUsa.stream = function(stream) {
  3900. var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
  3901. return {
  3902. point: function(x, y) {
  3903. lower48Stream.point(x, y);
  3904. alaskaStream.point(x, y);
  3905. hawaiiStream.point(x, y);
  3906. },
  3907. sphere: function() {
  3908. lower48Stream.sphere();
  3909. alaskaStream.sphere();
  3910. hawaiiStream.sphere();
  3911. },
  3912. lineStart: function() {
  3913. lower48Stream.lineStart();
  3914. alaskaStream.lineStart();
  3915. hawaiiStream.lineStart();
  3916. },
  3917. lineEnd: function() {
  3918. lower48Stream.lineEnd();
  3919. alaskaStream.lineEnd();
  3920. hawaiiStream.lineEnd();
  3921. },
  3922. polygonStart: function() {
  3923. lower48Stream.polygonStart();
  3924. alaskaStream.polygonStart();
  3925. hawaiiStream.polygonStart();
  3926. },
  3927. polygonEnd: function() {
  3928. lower48Stream.polygonEnd();
  3929. alaskaStream.polygonEnd();
  3930. hawaiiStream.polygonEnd();
  3931. }
  3932. };
  3933. };
  3934. albersUsa.precision = function(_) {
  3935. if (!arguments.length) return lower48.precision();
  3936. lower48.precision(_);
  3937. alaska.precision(_);
  3938. hawaii.precision(_);
  3939. return albersUsa;
  3940. };
  3941. albersUsa.scale = function(_) {
  3942. if (!arguments.length) return lower48.scale();
  3943. lower48.scale(_);
  3944. alaska.scale(_ * .35);
  3945. hawaii.scale(_);
  3946. return albersUsa.translate(lower48.translate());
  3947. };
  3948. albersUsa.translate = function(_) {
  3949. if (!arguments.length) return lower48.translate();
  3950. var k = lower48.scale(), x = +_[0], y = +_[1];
  3951. lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
  3952. alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
  3953. hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
  3954. return albersUsa;
  3955. };
  3956. return albersUsa.scale(1070);
  3957. };
  3958. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  3959. point: d3_noop,
  3960. lineStart: d3_noop,
  3961. lineEnd: d3_noop,
  3962. polygonStart: function() {
  3963. d3_geo_pathAreaPolygon = 0;
  3964. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  3965. },
  3966. polygonEnd: function() {
  3967. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  3968. d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
  3969. }
  3970. };
  3971. function d3_geo_pathAreaRingStart() {
  3972. var x00, y00, x0, y0;
  3973. d3_geo_pathArea.point = function(x, y) {
  3974. d3_geo_pathArea.point = nextPoint;
  3975. x00 = x0 = x, y00 = y0 = y;
  3976. };
  3977. function nextPoint(x, y) {
  3978. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  3979. x0 = x, y0 = y;
  3980. }
  3981. d3_geo_pathArea.lineEnd = function() {
  3982. nextPoint(x00, y00);
  3983. };
  3984. }
  3985. var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
  3986. var d3_geo_pathBounds = {
  3987. point: d3_geo_pathBoundsPoint,
  3988. lineStart: d3_noop,
  3989. lineEnd: d3_noop,
  3990. polygonStart: d3_noop,
  3991. polygonEnd: d3_noop
  3992. };
  3993. function d3_geo_pathBoundsPoint(x, y) {
  3994. if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
  3995. if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
  3996. if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
  3997. if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
  3998. }
  3999. function d3_geo_pathBuffer() {
  4000. var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
  4001. var stream = {
  4002. point: point,
  4003. lineStart: function() {
  4004. stream.point = pointLineStart;
  4005. },
  4006. lineEnd: lineEnd,
  4007. polygonStart: function() {
  4008. stream.lineEnd = lineEndPolygon;
  4009. },
  4010. polygonEnd: function() {
  4011. stream.lineEnd = lineEnd;
  4012. stream.point = point;
  4013. },
  4014. pointRadius: function(_) {
  4015. pointCircle = d3_geo_pathBufferCircle(_);
  4016. return stream;
  4017. },
  4018. result: function() {
  4019. if (buffer.length) {
  4020. var result = buffer.join("");
  4021. buffer = [];
  4022. return result;
  4023. }
  4024. }
  4025. };
  4026. function point(x, y) {
  4027. buffer.push("M", x, ",", y, pointCircle);
  4028. }
  4029. function pointLineStart(x, y) {
  4030. buffer.push("M", x, ",", y);
  4031. stream.point = pointLine;
  4032. }
  4033. function pointLine(x, y) {
  4034. buffer.push("L", x, ",", y);
  4035. }
  4036. function lineEnd() {
  4037. stream.point = point;
  4038. }
  4039. function lineEndPolygon() {
  4040. buffer.push("Z");
  4041. }
  4042. return stream;
  4043. }
  4044. function d3_geo_pathBufferCircle(radius) {
  4045. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
  4046. }
  4047. var d3_geo_pathCentroid = {
  4048. point: d3_geo_pathCentroidPoint,
  4049. lineStart: d3_geo_pathCentroidLineStart,
  4050. lineEnd: d3_geo_pathCentroidLineEnd,
  4051. polygonStart: function() {
  4052. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  4053. },
  4054. polygonEnd: function() {
  4055. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4056. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  4057. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  4058. }
  4059. };
  4060. function d3_geo_pathCentroidPoint(x, y) {
  4061. d3_geo_centroidX0 += x;
  4062. d3_geo_centroidY0 += y;
  4063. ++d3_geo_centroidZ0;
  4064. }
  4065. function d3_geo_pathCentroidLineStart() {
  4066. var x0, y0;
  4067. d3_geo_pathCentroid.point = function(x, y) {
  4068. d3_geo_pathCentroid.point = nextPoint;
  4069. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4070. };
  4071. function nextPoint(x, y) {
  4072. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4073. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4074. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4075. d3_geo_centroidZ1 += z;
  4076. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4077. }
  4078. }
  4079. function d3_geo_pathCentroidLineEnd() {
  4080. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4081. }
  4082. function d3_geo_pathCentroidRingStart() {
  4083. var x00, y00, x0, y0;
  4084. d3_geo_pathCentroid.point = function(x, y) {
  4085. d3_geo_pathCentroid.point = nextPoint;
  4086. d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
  4087. };
  4088. function nextPoint(x, y) {
  4089. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4090. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4091. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4092. d3_geo_centroidZ1 += z;
  4093. z = y0 * x - x0 * y;
  4094. d3_geo_centroidX2 += z * (x0 + x);
  4095. d3_geo_centroidY2 += z * (y0 + y);
  4096. d3_geo_centroidZ2 += z * 3;
  4097. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4098. }
  4099. d3_geo_pathCentroid.lineEnd = function() {
  4100. nextPoint(x00, y00);
  4101. };
  4102. }
  4103. function d3_geo_pathContext(context) {
  4104. var pointRadius = 4.5;
  4105. var stream = {
  4106. point: point,
  4107. lineStart: function() {
  4108. stream.point = pointLineStart;
  4109. },
  4110. lineEnd: lineEnd,
  4111. polygonStart: function() {
  4112. stream.lineEnd = lineEndPolygon;
  4113. },
  4114. polygonEnd: function() {
  4115. stream.lineEnd = lineEnd;
  4116. stream.point = point;
  4117. },
  4118. pointRadius: function(_) {
  4119. pointRadius = _;
  4120. return stream;
  4121. },
  4122. result: d3_noop
  4123. };
  4124. function point(x, y) {
  4125. context.moveTo(x + pointRadius, y);
  4126. context.arc(x, y, pointRadius, 0, τ);
  4127. }
  4128. function pointLineStart(x, y) {
  4129. context.moveTo(x, y);
  4130. stream.point = pointLine;
  4131. }
  4132. function pointLine(x, y) {
  4133. context.lineTo(x, y);
  4134. }
  4135. function lineEnd() {
  4136. stream.point = point;
  4137. }
  4138. function lineEndPolygon() {
  4139. context.closePath();
  4140. }
  4141. return stream;
  4142. }
  4143. function d3_geo_resample(project) {
  4144. var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
  4145. function resample(stream) {
  4146. return (maxDepth ? resampleRecursive : resampleNone)(stream);
  4147. }
  4148. function resampleNone(stream) {
  4149. return d3_geo_transformPoint(stream, function(x, y) {
  4150. x = project(x, y);
  4151. stream.point(x[0], x[1]);
  4152. });
  4153. }
  4154. function resampleRecursive(stream) {
  4155. var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
  4156. var resample = {
  4157. point: point,
  4158. lineStart: lineStart,
  4159. lineEnd: lineEnd,
  4160. polygonStart: function() {
  4161. stream.polygonStart();
  4162. resample.lineStart = ringStart;
  4163. },
  4164. polygonEnd: function() {
  4165. stream.polygonEnd();
  4166. resample.lineStart = lineStart;
  4167. }
  4168. };
  4169. function point(x, y) {
  4170. x = project(x, y);
  4171. stream.point(x[0], x[1]);
  4172. }
  4173. function lineStart() {
  4174. x0 = NaN;
  4175. resample.point = linePoint;
  4176. stream.lineStart();
  4177. }
  4178. function linePoint(λ, φ) {
  4179. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  4180. 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);
  4181. stream.point(x0, y0);
  4182. }
  4183. function lineEnd() {
  4184. resample.point = point;
  4185. stream.lineEnd();
  4186. }
  4187. function ringStart() {
  4188. lineStart();
  4189. resample.point = ringPoint;
  4190. resample.lineEnd = ringEnd;
  4191. }
  4192. function ringPoint(λ, φ) {
  4193. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  4194. resample.point = linePoint;
  4195. }
  4196. function ringEnd() {
  4197. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  4198. resample.lineEnd = lineEnd;
  4199. lineEnd();
  4200. }
  4201. return resample;
  4202. }
  4203. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  4204. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  4205. if (d2 > 4 * δ2 && depth--) {
  4206. var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = abs(abs(c) - 1) < ε || abs(λ0 - λ1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
  4207. if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
  4208. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  4209. stream.point(x2, y2);
  4210. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  4211. }
  4212. }
  4213. }
  4214. resample.precision = function(_) {
  4215. if (!arguments.length) return Math.sqrt(δ2);
  4216. maxDepth = (δ2 = _ * _) > 0 && 16;
  4217. return resample;
  4218. };
  4219. return resample;
  4220. }
  4221. d3.geo.path = function() {
  4222. var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
  4223. function path(object) {
  4224. if (object) {
  4225. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  4226. if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
  4227. d3.geo.stream(object, cacheStream);
  4228. }
  4229. return contextStream.result();
  4230. }
  4231. path.area = function(object) {
  4232. d3_geo_pathAreaSum = 0;
  4233. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  4234. return d3_geo_pathAreaSum;
  4235. };
  4236. path.centroid = function(object) {
  4237. d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
  4238. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  4239. return d3_geo_centroidZ2 ? [ d3_geo_centroidX2 / d3_geo_centroidZ2, d3_geo_centroidY2 / d3_geo_centroidZ2 ] : d3_geo_centroidZ1 ? [ d3_geo_centroidX1 / d3_geo_centroidZ1, d3_geo_centroidY1 / d3_geo_centroidZ1 ] : d3_geo_centroidZ0 ? [ d3_geo_centroidX0 / d3_geo_centroidZ0, d3_geo_centroidY0 / d3_geo_centroidZ0 ] : [ NaN, NaN ];
  4240. };
  4241. path.bounds = function(object) {
  4242. d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
  4243. d3.geo.stream(object, projectStream(d3_geo_pathBounds));
  4244. return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
  4245. };
  4246. path.projection = function(_) {
  4247. if (!arguments.length) return projection;
  4248. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  4249. return reset();
  4250. };
  4251. path.context = function(_) {
  4252. if (!arguments.length) return context;
  4253. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  4254. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  4255. return reset();
  4256. };
  4257. path.pointRadius = function(_) {
  4258. if (!arguments.length) return pointRadius;
  4259. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  4260. return path;
  4261. };
  4262. function reset() {
  4263. cacheStream = null;
  4264. return path;
  4265. }
  4266. return path.projection(d3.geo.albersUsa()).context(null);
  4267. };
  4268. function d3_geo_pathProjectStream(project) {
  4269. var resample = d3_geo_resample(function(x, y) {
  4270. return project([ x * d3_degrees, y * d3_degrees ]);
  4271. });
  4272. return function(stream) {
  4273. return d3_geo_projectionRadians(resample(stream));
  4274. };
  4275. }
  4276. d3.geo.transform = function(methods) {
  4277. return {
  4278. stream: function(stream) {
  4279. var transform = new d3_geo_transform(stream);
  4280. for (var k in methods) transform[k] = methods[k];
  4281. return transform;
  4282. }
  4283. };
  4284. };
  4285. function d3_geo_transform(stream) {
  4286. this.stream = stream;
  4287. }
  4288. d3_geo_transform.prototype = {
  4289. point: function(x, y) {
  4290. this.stream.point(x, y);
  4291. },
  4292. sphere: function() {
  4293. this.stream.sphere();
  4294. },
  4295. lineStart: function() {
  4296. this.stream.lineStart();
  4297. },
  4298. lineEnd: function() {
  4299. this.stream.lineEnd();
  4300. },
  4301. polygonStart: function() {
  4302. this.stream.polygonStart();
  4303. },
  4304. polygonEnd: function() {
  4305. this.stream.polygonEnd();
  4306. }
  4307. };
  4308. function d3_geo_transformPoint(stream, point) {
  4309. return {
  4310. point: point,
  4311. sphere: function() {
  4312. stream.sphere();
  4313. },
  4314. lineStart: function() {
  4315. stream.lineStart();
  4316. },
  4317. lineEnd: function() {
  4318. stream.lineEnd();
  4319. },
  4320. polygonStart: function() {
  4321. stream.polygonStart();
  4322. },
  4323. polygonEnd: function() {
  4324. stream.polygonEnd();
  4325. }
  4326. };
  4327. }
  4328. d3.geo.projection = d3_geo_projection;
  4329. d3.geo.projectionMutator = d3_geo_projectionMutator;
  4330. function d3_geo_projection(project) {
  4331. return d3_geo_projectionMutator(function() {
  4332. return project;
  4333. })();
  4334. }
  4335. function d3_geo_projectionMutator(projectAt) {
  4336. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  4337. x = project(x, y);
  4338. return [ x[0] * k + δx, δy - x[1] * k ];
  4339. }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null, stream;
  4340. function projection(point) {
  4341. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  4342. return [ point[0] * k + δx, δy - point[1] * k ];
  4343. }
  4344. function invert(point) {
  4345. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  4346. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  4347. }
  4348. projection.stream = function(output) {
  4349. if (stream) stream.valid = false;
  4350. stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
  4351. stream.valid = true;
  4352. return stream;
  4353. };
  4354. projection.clipAngle = function(_) {
  4355. if (!arguments.length) return clipAngle;
  4356. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  4357. return invalidate();
  4358. };
  4359. projection.clipExtent = function(_) {
  4360. if (!arguments.length) return clipExtent;
  4361. clipExtent = _;
  4362. postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
  4363. return invalidate();
  4364. };
  4365. projection.scale = function(_) {
  4366. if (!arguments.length) return k;
  4367. k = +_;
  4368. return reset();
  4369. };
  4370. projection.translate = function(_) {
  4371. if (!arguments.length) return [ x, y ];
  4372. x = +_[0];
  4373. y = +_[1];
  4374. return reset();
  4375. };
  4376. projection.center = function(_) {
  4377. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  4378. λ = _[0] % 360 * d3_radians;
  4379. φ = _[1] % 360 * d3_radians;
  4380. return reset();
  4381. };
  4382. projection.rotate = function(_) {
  4383. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  4384. δλ = _[0] % 360 * d3_radians;
  4385. δφ = _[1] % 360 * d3_radians;
  4386. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  4387. return reset();
  4388. };
  4389. d3.rebind(projection, projectResample, "precision");
  4390. function reset() {
  4391. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  4392. var center = project(λ, φ);
  4393. δx = x - center[0] * k;
  4394. δy = y + center[1] * k;
  4395. return invalidate();
  4396. }
  4397. function invalidate() {
  4398. if (stream) stream.valid = false, stream = null;
  4399. return projection;
  4400. }
  4401. return function() {
  4402. project = projectAt.apply(this, arguments);
  4403. projection.invert = project.invert && invert;
  4404. return reset();
  4405. };
  4406. }
  4407. function d3_geo_projectionRadians(stream) {
  4408. return d3_geo_transformPoint(stream, function(x, y) {
  4409. stream.point(x * d3_radians, y * d3_radians);
  4410. });
  4411. }
  4412. function d3_geo_equirectangular(λ, φ) {
  4413. return [ λ, φ ];
  4414. }
  4415. (d3.geo.equirectangular = function() {
  4416. return d3_geo_projection(d3_geo_equirectangular);
  4417. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  4418. d3.geo.rotation = function(rotate) {
  4419. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  4420. function forward(coordinates) {
  4421. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4422. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4423. }
  4424. forward.invert = function(coordinates) {
  4425. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4426. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4427. };
  4428. return forward;
  4429. };
  4430. function d3_geo_identityRotation(λ, φ) {
  4431. return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4432. }
  4433. d3_geo_identityRotation.invert = d3_geo_equirectangular;
  4434. function d3_geo_rotation(δλ, δφ, δγ) {
  4435. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
  4436. }
  4437. function d3_geo_forwardRotationλ(δλ) {
  4438. return function(λ, φ) {
  4439. return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4440. };
  4441. }
  4442. function d3_geo_rotationλ(δλ) {
  4443. var rotation = d3_geo_forwardRotationλ(δλ);
  4444. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  4445. return rotation;
  4446. }
  4447. function d3_geo_rotationφγ(δφ, δγ) {
  4448. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  4449. function rotation(λ, φ) {
  4450. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  4451. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
  4452. }
  4453. rotation.invert = function(λ, φ) {
  4454. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  4455. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
  4456. };
  4457. return rotation;
  4458. }
  4459. d3.geo.circle = function() {
  4460. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  4461. function circle() {
  4462. 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 = [];
  4463. interpolate(null, null, 1, {
  4464. point: function(x, y) {
  4465. ring.push(x = rotate(x, y));
  4466. x[0] *= d3_degrees, x[1] *= d3_degrees;
  4467. }
  4468. });
  4469. return {
  4470. type: "Polygon",
  4471. coordinates: [ ring ]
  4472. };
  4473. }
  4474. circle.origin = function(x) {
  4475. if (!arguments.length) return origin;
  4476. origin = x;
  4477. return circle;
  4478. };
  4479. circle.angle = function(x) {
  4480. if (!arguments.length) return angle;
  4481. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  4482. return circle;
  4483. };
  4484. circle.precision = function(_) {
  4485. if (!arguments.length) return precision;
  4486. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  4487. return circle;
  4488. };
  4489. return circle.angle(90);
  4490. };
  4491. function d3_geo_circleInterpolate(radius, precision) {
  4492. var cr = Math.cos(radius), sr = Math.sin(radius);
  4493. return function(from, to, direction, listener) {
  4494. var step = direction * precision;
  4495. if (from != null) {
  4496. from = d3_geo_circleAngle(cr, from);
  4497. to = d3_geo_circleAngle(cr, to);
  4498. if (direction > 0 ? from < to : from > to) from += direction * τ;
  4499. } else {
  4500. from = radius + direction * τ;
  4501. to = radius - .5 * step;
  4502. }
  4503. for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
  4504. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  4505. }
  4506. };
  4507. }
  4508. function d3_geo_circleAngle(cr, point) {
  4509. var a = d3_geo_cartesian(point);
  4510. a[0] -= cr;
  4511. d3_geo_cartesianNormalize(a);
  4512. var angle = d3_acos(-a[1]);
  4513. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  4514. }
  4515. d3.geo.distance = function(a, b) {
  4516. 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;
  4517. 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Δλ);
  4518. };
  4519. d3.geo.graticule = function() {
  4520. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  4521. function graticule() {
  4522. return {
  4523. type: "MultiLineString",
  4524. coordinates: lines()
  4525. };
  4526. }
  4527. function lines() {
  4528. 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) {
  4529. return abs(x % DX) > ε;
  4530. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  4531. return abs(y % DY) > ε;
  4532. }).map(y));
  4533. }
  4534. graticule.lines = function() {
  4535. return lines().map(function(coordinates) {
  4536. return {
  4537. type: "LineString",
  4538. coordinates: coordinates
  4539. };
  4540. });
  4541. };
  4542. graticule.outline = function() {
  4543. return {
  4544. type: "Polygon",
  4545. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  4546. };
  4547. };
  4548. graticule.extent = function(_) {
  4549. if (!arguments.length) return graticule.minorExtent();
  4550. return graticule.majorExtent(_).minorExtent(_);
  4551. };
  4552. graticule.majorExtent = function(_) {
  4553. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  4554. X0 = +_[0][0], X1 = +_[1][0];
  4555. Y0 = +_[0][1], Y1 = +_[1][1];
  4556. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  4557. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  4558. return graticule.precision(precision);
  4559. };
  4560. graticule.minorExtent = function(_) {
  4561. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  4562. x0 = +_[0][0], x1 = +_[1][0];
  4563. y0 = +_[0][1], y1 = +_[1][1];
  4564. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  4565. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  4566. return graticule.precision(precision);
  4567. };
  4568. graticule.step = function(_) {
  4569. if (!arguments.length) return graticule.minorStep();
  4570. return graticule.majorStep(_).minorStep(_);
  4571. };
  4572. graticule.majorStep = function(_) {
  4573. if (!arguments.length) return [ DX, DY ];
  4574. DX = +_[0], DY = +_[1];
  4575. return graticule;
  4576. };
  4577. graticule.minorStep = function(_) {
  4578. if (!arguments.length) return [ dx, dy ];
  4579. dx = +_[0], dy = +_[1];
  4580. return graticule;
  4581. };
  4582. graticule.precision = function(_) {
  4583. if (!arguments.length) return precision;
  4584. precision = +_;
  4585. x = d3_geo_graticuleX(y0, y1, 90);
  4586. y = d3_geo_graticuleY(x0, x1, precision);
  4587. X = d3_geo_graticuleX(Y0, Y1, 90);
  4588. Y = d3_geo_graticuleY(X0, X1, precision);
  4589. return graticule;
  4590. };
  4591. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  4592. };
  4593. function d3_geo_graticuleX(y0, y1, dy) {
  4594. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  4595. return function(x) {
  4596. return y.map(function(y) {
  4597. return [ x, y ];
  4598. });
  4599. };
  4600. }
  4601. function d3_geo_graticuleY(x0, x1, dx) {
  4602. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  4603. return function(y) {
  4604. return x.map(function(x) {
  4605. return [ x, y ];
  4606. });
  4607. };
  4608. }
  4609. function d3_source(d) {
  4610. return d.source;
  4611. }
  4612. function d3_target(d) {
  4613. return d.target;
  4614. }
  4615. d3.geo.greatArc = function() {
  4616. var source = d3_source, source_, target = d3_target, target_;
  4617. function greatArc() {
  4618. return {
  4619. type: "LineString",
  4620. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  4621. };
  4622. }
  4623. greatArc.distance = function() {
  4624. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  4625. };
  4626. greatArc.source = function(_) {
  4627. if (!arguments.length) return source;
  4628. source = _, source_ = typeof _ === "function" ? null : _;
  4629. return greatArc;
  4630. };
  4631. greatArc.target = function(_) {
  4632. if (!arguments.length) return target;
  4633. target = _, target_ = typeof _ === "function" ? null : _;
  4634. return greatArc;
  4635. };
  4636. greatArc.precision = function() {
  4637. return arguments.length ? greatArc : 0;
  4638. };
  4639. return greatArc;
  4640. };
  4641. d3.geo.interpolate = function(source, target) {
  4642. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  4643. };
  4644. function d3_geo_interpolate(x0, y0, x1, y1) {
  4645. 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);
  4646. var interpolate = d ? function(t) {
  4647. 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;
  4648. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  4649. } : function() {
  4650. return [ x0 * d3_degrees, y0 * d3_degrees ];
  4651. };
  4652. interpolate.distance = d;
  4653. return interpolate;
  4654. }
  4655. d3.geo.length = function(object) {
  4656. d3_geo_lengthSum = 0;
  4657. d3.geo.stream(object, d3_geo_length);
  4658. return d3_geo_lengthSum;
  4659. };
  4660. var d3_geo_lengthSum;
  4661. var d3_geo_length = {
  4662. sphere: d3_noop,
  4663. point: d3_noop,
  4664. lineStart: d3_geo_lengthLineStart,
  4665. lineEnd: d3_noop,
  4666. polygonStart: d3_noop,
  4667. polygonEnd: d3_noop
  4668. };
  4669. function d3_geo_lengthLineStart() {
  4670. var λ0, sinφ0, cosφ0;
  4671. d3_geo_length.point = function(λ, φ) {
  4672. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  4673. d3_geo_length.point = nextPoint;
  4674. };
  4675. d3_geo_length.lineEnd = function() {
  4676. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  4677. };
  4678. function nextPoint(λ, φ) {
  4679. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  4680. 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Δλ);
  4681. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  4682. }
  4683. }
  4684. function d3_geo_azimuthal(scale, angle) {
  4685. function azimuthal(λ, φ) {
  4686. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  4687. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  4688. }
  4689. azimuthal.invert = function(x, y) {
  4690. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  4691. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  4692. };
  4693. return azimuthal;
  4694. }
  4695. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  4696. return Math.sqrt(2 / (1 + cosλcosφ));
  4697. }, function(ρ) {
  4698. return 2 * Math.asin(ρ / 2);
  4699. });
  4700. (d3.geo.azimuthalEqualArea = function() {
  4701. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  4702. }).raw = d3_geo_azimuthalEqualArea;
  4703. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  4704. var c = Math.acos(cosλcosφ);
  4705. return c && c / Math.sin(c);
  4706. }, d3_identity);
  4707. (d3.geo.azimuthalEquidistant = function() {
  4708. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  4709. }).raw = d3_geo_azimuthalEquidistant;
  4710. function d3_geo_conicConformal(φ0, φ1) {
  4711. var cosφ0 = Math.cos(φ0), t = function(φ) {
  4712. return Math.tan(π / 4 + φ / 2);
  4713. }, 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;
  4714. if (!n) return d3_geo_mercator;
  4715. function forward(λ, φ) {
  4716. if (F > 0) {
  4717. if (φ < -halfπ + ε) φ = -halfπ + ε;
  4718. } else {
  4719. if (φ > halfπ - ε) φ = halfπ - ε;
  4720. }
  4721. var ρ = F / Math.pow(t(φ), n);
  4722. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  4723. }
  4724. forward.invert = function(x, y) {
  4725. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  4726. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
  4727. };
  4728. return forward;
  4729. }
  4730. (d3.geo.conicConformal = function() {
  4731. return d3_geo_conic(d3_geo_conicConformal);
  4732. }).raw = d3_geo_conicConformal;
  4733. function d3_geo_conicEquidistant(φ0, φ1) {
  4734. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  4735. if (abs(n) < ε) return d3_geo_equirectangular;
  4736. function forward(λ, φ) {
  4737. var ρ = G - φ;
  4738. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  4739. }
  4740. forward.invert = function(x, y) {
  4741. var ρ0_y = G - y;
  4742. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  4743. };
  4744. return forward;
  4745. }
  4746. (d3.geo.conicEquidistant = function() {
  4747. return d3_geo_conic(d3_geo_conicEquidistant);
  4748. }).raw = d3_geo_conicEquidistant;
  4749. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  4750. return 1 / cosλcosφ;
  4751. }, Math.atan);
  4752. (d3.geo.gnomonic = function() {
  4753. return d3_geo_projection(d3_geo_gnomonic);
  4754. }).raw = d3_geo_gnomonic;
  4755. function d3_geo_mercator(λ, φ) {
  4756. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  4757. }
  4758. d3_geo_mercator.invert = function(x, y) {
  4759. return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
  4760. };
  4761. function d3_geo_mercatorProjection(project) {
  4762. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  4763. m.scale = function() {
  4764. var v = scale.apply(m, arguments);
  4765. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4766. };
  4767. m.translate = function() {
  4768. var v = translate.apply(m, arguments);
  4769. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4770. };
  4771. m.clipExtent = function(_) {
  4772. var v = clipExtent.apply(m, arguments);
  4773. if (v === m) {
  4774. if (clipAuto = _ == null) {
  4775. var k = π * scale(), t = translate();
  4776. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  4777. }
  4778. } else if (clipAuto) {
  4779. v = null;
  4780. }
  4781. return v;
  4782. };
  4783. return m.clipExtent(null);
  4784. }
  4785. (d3.geo.mercator = function() {
  4786. return d3_geo_mercatorProjection(d3_geo_mercator);
  4787. }).raw = d3_geo_mercator;
  4788. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  4789. return 1;
  4790. }, Math.asin);
  4791. (d3.geo.orthographic = function() {
  4792. return d3_geo_projection(d3_geo_orthographic);
  4793. }).raw = d3_geo_orthographic;
  4794. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  4795. return 1 / (1 + cosλcosφ);
  4796. }, function(ρ) {
  4797. return 2 * Math.atan(ρ);
  4798. });
  4799. (d3.geo.stereographic = function() {
  4800. return d3_geo_projection(d3_geo_stereographic);
  4801. }).raw = d3_geo_stereographic;
  4802. function d3_geo_transverseMercator(λ, φ) {
  4803. return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
  4804. }
  4805. d3_geo_transverseMercator.invert = function(x, y) {
  4806. return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
  4807. };
  4808. (d3.geo.transverseMercator = function() {
  4809. var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
  4810. projection.center = function(_) {
  4811. return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
  4812. };
  4813. projection.rotate = function(_) {
  4814. return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
  4815. [ _[0], _[1], _[2] - 90 ]);
  4816. };
  4817. return rotate([ 0, 0, 90 ]);
  4818. }).raw = d3_geo_transverseMercator;
  4819. d3.geom = {};
  4820. function d3_geom_pointX(d) {
  4821. return d[0];
  4822. }
  4823. function d3_geom_pointY(d) {
  4824. return d[1];
  4825. }
  4826. d3.geom.hull = function(vertices) {
  4827. var x = d3_geom_pointX, y = d3_geom_pointY;
  4828. if (arguments.length) return hull(vertices);
  4829. function hull(data) {
  4830. if (data.length < 3) return [];
  4831. var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
  4832. for (i = 0; i < n; i++) {
  4833. points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
  4834. }
  4835. points.sort(d3_geom_hullOrder);
  4836. for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
  4837. var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
  4838. var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
  4839. for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
  4840. for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
  4841. return polygon;
  4842. }
  4843. hull.x = function(_) {
  4844. return arguments.length ? (x = _, hull) : x;
  4845. };
  4846. hull.y = function(_) {
  4847. return arguments.length ? (y = _, hull) : y;
  4848. };
  4849. return hull;
  4850. };
  4851. function d3_geom_hullUpper(points) {
  4852. var n = points.length, hull = [ 0, 1 ], hs = 2;
  4853. for (var i = 2; i < n; i++) {
  4854. while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
  4855. hull[hs++] = i;
  4856. }
  4857. return hull.slice(0, hs);
  4858. }
  4859. function d3_geom_hullOrder(a, b) {
  4860. return a[0] - b[0] || a[1] - b[1];
  4861. }
  4862. d3.geom.polygon = function(coordinates) {
  4863. d3_subclass(coordinates, d3_geom_polygonPrototype);
  4864. return coordinates;
  4865. };
  4866. var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
  4867. d3_geom_polygonPrototype.area = function() {
  4868. var i = -1, n = this.length, a, b = this[n - 1], area = 0;
  4869. while (++i < n) {
  4870. a = b;
  4871. b = this[i];
  4872. area += a[1] * b[0] - a[0] * b[1];
  4873. }
  4874. return area * .5;
  4875. };
  4876. d3_geom_polygonPrototype.centroid = function(k) {
  4877. var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
  4878. if (!arguments.length) k = -1 / (6 * this.area());
  4879. while (++i < n) {
  4880. a = b;
  4881. b = this[i];
  4882. c = a[0] * b[1] - b[0] * a[1];
  4883. x += (a[0] + b[0]) * c;
  4884. y += (a[1] + b[1]) * c;
  4885. }
  4886. return [ x * k, y * k ];
  4887. };
  4888. d3_geom_polygonPrototype.clip = function(subject) {
  4889. var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d;
  4890. while (++i < n) {
  4891. input = subject.slice();
  4892. subject.length = 0;
  4893. b = this[i];
  4894. c = input[(m = input.length - closed) - 1];
  4895. j = -1;
  4896. while (++j < m) {
  4897. d = input[j];
  4898. if (d3_geom_polygonInside(d, a, b)) {
  4899. if (!d3_geom_polygonInside(c, a, b)) {
  4900. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4901. }
  4902. subject.push(d);
  4903. } else if (d3_geom_polygonInside(c, a, b)) {
  4904. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4905. }
  4906. c = d;
  4907. }
  4908. if (closed) subject.push(subject[0]);
  4909. a = b;
  4910. }
  4911. return subject;
  4912. };
  4913. function d3_geom_polygonInside(p, a, b) {
  4914. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  4915. }
  4916. function d3_geom_polygonIntersect(c, d, a, b) {
  4917. 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);
  4918. return [ x1 + ua * x21, y1 + ua * y21 ];
  4919. }
  4920. function d3_geom_polygonClosed(coordinates) {
  4921. var a = coordinates[0], b = coordinates[coordinates.length - 1];
  4922. return !(a[0] - b[0] || a[1] - b[1]);
  4923. }
  4924. var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
  4925. function d3_geom_voronoiBeach() {
  4926. d3_geom_voronoiRedBlackNode(this);
  4927. this.edge = this.site = this.circle = null;
  4928. }
  4929. function d3_geom_voronoiCreateBeach(site) {
  4930. var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
  4931. beach.site = site;
  4932. return beach;
  4933. }
  4934. function d3_geom_voronoiDetachBeach(beach) {
  4935. d3_geom_voronoiDetachCircle(beach);
  4936. d3_geom_voronoiBeaches.remove(beach);
  4937. d3_geom_voronoiBeachPool.push(beach);
  4938. d3_geom_voronoiRedBlackNode(beach);
  4939. }
  4940. function d3_geom_voronoiRemoveBeach(beach) {
  4941. var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
  4942. x: x,
  4943. y: y
  4944. }, previous = beach.P, next = beach.N, disappearing = [ beach ];
  4945. d3_geom_voronoiDetachBeach(beach);
  4946. var lArc = previous;
  4947. while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
  4948. previous = lArc.P;
  4949. disappearing.unshift(lArc);
  4950. d3_geom_voronoiDetachBeach(lArc);
  4951. lArc = previous;
  4952. }
  4953. disappearing.unshift(lArc);
  4954. d3_geom_voronoiDetachCircle(lArc);
  4955. var rArc = next;
  4956. while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
  4957. next = rArc.N;
  4958. disappearing.push(rArc);
  4959. d3_geom_voronoiDetachBeach(rArc);
  4960. rArc = next;
  4961. }
  4962. disappearing.push(rArc);
  4963. d3_geom_voronoiDetachCircle(rArc);
  4964. var nArcs = disappearing.length, iArc;
  4965. for (iArc = 1; iArc < nArcs; ++iArc) {
  4966. rArc = disappearing[iArc];
  4967. lArc = disappearing[iArc - 1];
  4968. d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  4969. }
  4970. lArc = disappearing[0];
  4971. rArc = disappearing[nArcs - 1];
  4972. rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
  4973. d3_geom_voronoiAttachCircle(lArc);
  4974. d3_geom_voronoiAttachCircle(rArc);
  4975. }
  4976. function d3_geom_voronoiAddBeach(site) {
  4977. var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
  4978. while (node) {
  4979. dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
  4980. if (dxl > ε) node = node.L; else {
  4981. dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
  4982. if (dxr > ε) {
  4983. if (!node.R) {
  4984. lArc = node;
  4985. break;
  4986. }
  4987. node = node.R;
  4988. } else {
  4989. if (dxl > -ε) {
  4990. lArc = node.P;
  4991. rArc = node;
  4992. } else if (dxr > -ε) {
  4993. lArc = node;
  4994. rArc = node.N;
  4995. } else {
  4996. lArc = rArc = node;
  4997. }
  4998. break;
  4999. }
  5000. }
  5001. }
  5002. var newArc = d3_geom_voronoiCreateBeach(site);
  5003. d3_geom_voronoiBeaches.insert(lArc, newArc);
  5004. if (!lArc && !rArc) return;
  5005. if (lArc === rArc) {
  5006. d3_geom_voronoiDetachCircle(lArc);
  5007. rArc = d3_geom_voronoiCreateBeach(lArc.site);
  5008. d3_geom_voronoiBeaches.insert(newArc, rArc);
  5009. newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  5010. d3_geom_voronoiAttachCircle(lArc);
  5011. d3_geom_voronoiAttachCircle(rArc);
  5012. return;
  5013. }
  5014. if (!rArc) {
  5015. newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  5016. return;
  5017. }
  5018. d3_geom_voronoiDetachCircle(lArc);
  5019. d3_geom_voronoiDetachCircle(rArc);
  5020. var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
  5021. x: (cy * hb - by * hc) / d + ax,
  5022. y: (bx * hc - cx * hb) / d + ay
  5023. };
  5024. d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
  5025. newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
  5026. rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
  5027. d3_geom_voronoiAttachCircle(lArc);
  5028. d3_geom_voronoiAttachCircle(rArc);
  5029. }
  5030. function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
  5031. var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
  5032. if (!pby2) return rfocx;
  5033. var lArc = arc.P;
  5034. if (!lArc) return -Infinity;
  5035. site = lArc.site;
  5036. var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
  5037. if (!plby2) return lfocx;
  5038. var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
  5039. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  5040. return (rfocx + lfocx) / 2;
  5041. }
  5042. function d3_geom_voronoiRightBreakPoint(arc, directrix) {
  5043. var rArc = arc.N;
  5044. if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
  5045. var site = arc.site;
  5046. return site.y === directrix ? site.x : Infinity;
  5047. }
  5048. function d3_geom_voronoiCell(site) {
  5049. this.site = site;
  5050. this.edges = [];
  5051. }
  5052. d3_geom_voronoiCell.prototype.prepare = function() {
  5053. var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
  5054. while (iHalfEdge--) {
  5055. edge = halfEdges[iHalfEdge].edge;
  5056. if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
  5057. }
  5058. halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
  5059. return halfEdges.length;
  5060. };
  5061. function d3_geom_voronoiCloseCells(extent) {
  5062. var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
  5063. while (iCell--) {
  5064. cell = cells[iCell];
  5065. if (!cell || !cell.prepare()) continue;
  5066. halfEdges = cell.edges;
  5067. nHalfEdges = halfEdges.length;
  5068. iHalfEdge = 0;
  5069. while (iHalfEdge < nHalfEdges) {
  5070. end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
  5071. start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
  5072. if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
  5073. halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
  5074. x: x0,
  5075. y: abs(x2 - x0) < ε ? y2 : y1
  5076. } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
  5077. x: abs(y2 - y1) < ε ? x2 : x1,
  5078. y: y1
  5079. } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
  5080. x: x1,
  5081. y: abs(x2 - x1) < ε ? y2 : y0
  5082. } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
  5083. x: abs(y2 - y0) < ε ? x2 : x0,
  5084. y: y0
  5085. } : null), cell.site, null));
  5086. ++nHalfEdges;
  5087. }
  5088. }
  5089. }
  5090. }
  5091. function d3_geom_voronoiHalfEdgeOrder(a, b) {
  5092. return b.angle - a.angle;
  5093. }
  5094. function d3_geom_voronoiCircle() {
  5095. d3_geom_voronoiRedBlackNode(this);
  5096. this.x = this.y = this.arc = this.site = this.cy = null;
  5097. }
  5098. function d3_geom_voronoiAttachCircle(arc) {
  5099. var lArc = arc.P, rArc = arc.N;
  5100. if (!lArc || !rArc) return;
  5101. var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
  5102. if (lSite === rSite) return;
  5103. var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
  5104. var d = 2 * (ax * cy - ay * cx);
  5105. if (d >= -ε2) return;
  5106. var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
  5107. var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
  5108. circle.arc = arc;
  5109. circle.site = cSite;
  5110. circle.x = x + bx;
  5111. circle.y = cy + Math.sqrt(x * x + y * y);
  5112. circle.cy = cy;
  5113. arc.circle = circle;
  5114. var before = null, node = d3_geom_voronoiCircles._;
  5115. while (node) {
  5116. if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
  5117. if (node.L) node = node.L; else {
  5118. before = node.P;
  5119. break;
  5120. }
  5121. } else {
  5122. if (node.R) node = node.R; else {
  5123. before = node;
  5124. break;
  5125. }
  5126. }
  5127. }
  5128. d3_geom_voronoiCircles.insert(before, circle);
  5129. if (!before) d3_geom_voronoiFirstCircle = circle;
  5130. }
  5131. function d3_geom_voronoiDetachCircle(arc) {
  5132. var circle = arc.circle;
  5133. if (circle) {
  5134. if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
  5135. d3_geom_voronoiCircles.remove(circle);
  5136. d3_geom_voronoiCirclePool.push(circle);
  5137. d3_geom_voronoiRedBlackNode(circle);
  5138. arc.circle = null;
  5139. }
  5140. }
  5141. function d3_geom_voronoiClipEdges(extent) {
  5142. var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
  5143. while (i--) {
  5144. e = edges[i];
  5145. if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
  5146. e.a = e.b = null;
  5147. edges.splice(i, 1);
  5148. }
  5149. }
  5150. }
  5151. function d3_geom_voronoiConnectEdge(edge, extent) {
  5152. var vb = edge.b;
  5153. if (vb) return true;
  5154. var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
  5155. if (ry === ly) {
  5156. if (fx < x0 || fx >= x1) return;
  5157. if (lx > rx) {
  5158. if (!va) va = {
  5159. x: fx,
  5160. y: y0
  5161. }; else if (va.y >= y1) return;
  5162. vb = {
  5163. x: fx,
  5164. y: y1
  5165. };
  5166. } else {
  5167. if (!va) va = {
  5168. x: fx,
  5169. y: y1
  5170. }; else if (va.y < y0) return;
  5171. vb = {
  5172. x: fx,
  5173. y: y0
  5174. };
  5175. }
  5176. } else {
  5177. fm = (lx - rx) / (ry - ly);
  5178. fb = fy - fm * fx;
  5179. if (fm < -1 || fm > 1) {
  5180. if (lx > rx) {
  5181. if (!va) va = {
  5182. x: (y0 - fb) / fm,
  5183. y: y0
  5184. }; else if (va.y >= y1) return;
  5185. vb = {
  5186. x: (y1 - fb) / fm,
  5187. y: y1
  5188. };
  5189. } else {
  5190. if (!va) va = {
  5191. x: (y1 - fb) / fm,
  5192. y: y1
  5193. }; else if (va.y < y0) return;
  5194. vb = {
  5195. x: (y0 - fb) / fm,
  5196. y: y0
  5197. };
  5198. }
  5199. } else {
  5200. if (ly < ry) {
  5201. if (!va) va = {
  5202. x: x0,
  5203. y: fm * x0 + fb
  5204. }; else if (va.x >= x1) return;
  5205. vb = {
  5206. x: x1,
  5207. y: fm * x1 + fb
  5208. };
  5209. } else {
  5210. if (!va) va = {
  5211. x: x1,
  5212. y: fm * x1 + fb
  5213. }; else if (va.x < x0) return;
  5214. vb = {
  5215. x: x0,
  5216. y: fm * x0 + fb
  5217. };
  5218. }
  5219. }
  5220. }
  5221. edge.a = va;
  5222. edge.b = vb;
  5223. return true;
  5224. }
  5225. function d3_geom_voronoiEdge(lSite, rSite) {
  5226. this.l = lSite;
  5227. this.r = rSite;
  5228. this.a = this.b = null;
  5229. }
  5230. function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
  5231. var edge = new d3_geom_voronoiEdge(lSite, rSite);
  5232. d3_geom_voronoiEdges.push(edge);
  5233. if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
  5234. if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
  5235. d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
  5236. d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
  5237. return edge;
  5238. }
  5239. function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
  5240. var edge = new d3_geom_voronoiEdge(lSite, null);
  5241. edge.a = va;
  5242. edge.b = vb;
  5243. d3_geom_voronoiEdges.push(edge);
  5244. return edge;
  5245. }
  5246. function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
  5247. if (!edge.a && !edge.b) {
  5248. edge.a = vertex;
  5249. edge.l = lSite;
  5250. edge.r = rSite;
  5251. } else if (edge.l === rSite) {
  5252. edge.b = vertex;
  5253. } else {
  5254. edge.a = vertex;
  5255. }
  5256. }
  5257. function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
  5258. var va = edge.a, vb = edge.b;
  5259. this.edge = edge;
  5260. this.site = lSite;
  5261. this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
  5262. }
  5263. d3_geom_voronoiHalfEdge.prototype = {
  5264. start: function() {
  5265. return this.edge.l === this.site ? this.edge.a : this.edge.b;
  5266. },
  5267. end: function() {
  5268. return this.edge.l === this.site ? this.edge.b : this.edge.a;
  5269. }
  5270. };
  5271. function d3_geom_voronoiRedBlackTree() {
  5272. this._ = null;
  5273. }
  5274. function d3_geom_voronoiRedBlackNode(node) {
  5275. node.U = node.C = node.L = node.R = node.P = node.N = null;
  5276. }
  5277. d3_geom_voronoiRedBlackTree.prototype = {
  5278. insert: function(after, node) {
  5279. var parent, grandpa, uncle;
  5280. if (after) {
  5281. node.P = after;
  5282. node.N = after.N;
  5283. if (after.N) after.N.P = node;
  5284. after.N = node;
  5285. if (after.R) {
  5286. after = after.R;
  5287. while (after.L) after = after.L;
  5288. after.L = node;
  5289. } else {
  5290. after.R = node;
  5291. }
  5292. parent = after;
  5293. } else if (this._) {
  5294. after = d3_geom_voronoiRedBlackFirst(this._);
  5295. node.P = null;
  5296. node.N = after;
  5297. after.P = after.L = node;
  5298. parent = after;
  5299. } else {
  5300. node.P = node.N = null;
  5301. this._ = node;
  5302. parent = null;
  5303. }
  5304. node.L = node.R = null;
  5305. node.U = parent;
  5306. node.C = true;
  5307. after = node;
  5308. while (parent && parent.C) {
  5309. grandpa = parent.U;
  5310. if (parent === grandpa.L) {
  5311. uncle = grandpa.R;
  5312. if (uncle && uncle.C) {
  5313. parent.C = uncle.C = false;
  5314. grandpa.C = true;
  5315. after = grandpa;
  5316. } else {
  5317. if (after === parent.R) {
  5318. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5319. after = parent;
  5320. parent = after.U;
  5321. }
  5322. parent.C = false;
  5323. grandpa.C = true;
  5324. d3_geom_voronoiRedBlackRotateRight(this, grandpa);
  5325. }
  5326. } else {
  5327. uncle = grandpa.L;
  5328. if (uncle && uncle.C) {
  5329. parent.C = uncle.C = false;
  5330. grandpa.C = true;
  5331. after = grandpa;
  5332. } else {
  5333. if (after === parent.L) {
  5334. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5335. after = parent;
  5336. parent = after.U;
  5337. }
  5338. parent.C = false;
  5339. grandpa.C = true;
  5340. d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
  5341. }
  5342. }
  5343. parent = after.U;
  5344. }
  5345. this._.C = false;
  5346. },
  5347. remove: function(node) {
  5348. if (node.N) node.N.P = node.P;
  5349. if (node.P) node.P.N = node.N;
  5350. node.N = node.P = null;
  5351. var parent = node.U, sibling, left = node.L, right = node.R, next, red;
  5352. if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
  5353. if (parent) {
  5354. if (parent.L === node) parent.L = next; else parent.R = next;
  5355. } else {
  5356. this._ = next;
  5357. }
  5358. if (left && right) {
  5359. red = next.C;
  5360. next.C = node.C;
  5361. next.L = left;
  5362. left.U = next;
  5363. if (next !== right) {
  5364. parent = next.U;
  5365. next.U = node.U;
  5366. node = next.R;
  5367. parent.L = node;
  5368. next.R = right;
  5369. right.U = next;
  5370. } else {
  5371. next.U = parent;
  5372. parent = next;
  5373. node = next.R;
  5374. }
  5375. } else {
  5376. red = node.C;
  5377. node = next;
  5378. }
  5379. if (node) node.U = parent;
  5380. if (red) return;
  5381. if (node && node.C) {
  5382. node.C = false;
  5383. return;
  5384. }
  5385. do {
  5386. if (node === this._) break;
  5387. if (node === parent.L) {
  5388. sibling = parent.R;
  5389. if (sibling.C) {
  5390. sibling.C = false;
  5391. parent.C = true;
  5392. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5393. sibling = parent.R;
  5394. }
  5395. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5396. if (!sibling.R || !sibling.R.C) {
  5397. sibling.L.C = false;
  5398. sibling.C = true;
  5399. d3_geom_voronoiRedBlackRotateRight(this, sibling);
  5400. sibling = parent.R;
  5401. }
  5402. sibling.C = parent.C;
  5403. parent.C = sibling.R.C = false;
  5404. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5405. node = this._;
  5406. break;
  5407. }
  5408. } else {
  5409. sibling = parent.L;
  5410. if (sibling.C) {
  5411. sibling.C = false;
  5412. parent.C = true;
  5413. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5414. sibling = parent.L;
  5415. }
  5416. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5417. if (!sibling.L || !sibling.L.C) {
  5418. sibling.R.C = false;
  5419. sibling.C = true;
  5420. d3_geom_voronoiRedBlackRotateLeft(this, sibling);
  5421. sibling = parent.L;
  5422. }
  5423. sibling.C = parent.C;
  5424. parent.C = sibling.L.C = false;
  5425. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5426. node = this._;
  5427. break;
  5428. }
  5429. }
  5430. sibling.C = true;
  5431. node = parent;
  5432. parent = parent.U;
  5433. } while (!node.C);
  5434. if (node) node.C = false;
  5435. }
  5436. };
  5437. function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
  5438. var p = node, q = node.R, parent = p.U;
  5439. if (parent) {
  5440. if (parent.L === p) parent.L = q; else parent.R = q;
  5441. } else {
  5442. tree._ = q;
  5443. }
  5444. q.U = parent;
  5445. p.U = q;
  5446. p.R = q.L;
  5447. if (p.R) p.R.U = p;
  5448. q.L = p;
  5449. }
  5450. function d3_geom_voronoiRedBlackRotateRight(tree, node) {
  5451. var p = node, q = node.L, parent = p.U;
  5452. if (parent) {
  5453. if (parent.L === p) parent.L = q; else parent.R = q;
  5454. } else {
  5455. tree._ = q;
  5456. }
  5457. q.U = parent;
  5458. p.U = q;
  5459. p.L = q.R;
  5460. if (p.L) p.L.U = p;
  5461. q.R = p;
  5462. }
  5463. function d3_geom_voronoiRedBlackFirst(node) {
  5464. while (node.L) node = node.L;
  5465. return node;
  5466. }
  5467. function d3_geom_voronoi(sites, bbox) {
  5468. var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
  5469. d3_geom_voronoiEdges = [];
  5470. d3_geom_voronoiCells = new Array(sites.length);
  5471. d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
  5472. d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
  5473. while (true) {
  5474. circle = d3_geom_voronoiFirstCircle;
  5475. if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
  5476. if (site.x !== x0 || site.y !== y0) {
  5477. d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
  5478. d3_geom_voronoiAddBeach(site);
  5479. x0 = site.x, y0 = site.y;
  5480. }
  5481. site = sites.pop();
  5482. } else if (circle) {
  5483. d3_geom_voronoiRemoveBeach(circle.arc);
  5484. } else {
  5485. break;
  5486. }
  5487. }
  5488. if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
  5489. var diagram = {
  5490. cells: d3_geom_voronoiCells,
  5491. edges: d3_geom_voronoiEdges
  5492. };
  5493. d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
  5494. return diagram;
  5495. }
  5496. function d3_geom_voronoiVertexOrder(a, b) {
  5497. return b.y - a.y || b.x - a.x;
  5498. }
  5499. d3.geom.voronoi = function(points) {
  5500. var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
  5501. if (points) return voronoi(points);
  5502. function voronoi(data) {
  5503. var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
  5504. d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
  5505. var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
  5506. var s = e.start();
  5507. return [ s.x, s.y ];
  5508. }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
  5509. polygon.point = data[i];
  5510. });
  5511. return polygons;
  5512. }
  5513. function sites(data) {
  5514. return data.map(function(d, i) {
  5515. return {
  5516. x: Math.round(fx(d, i) / ε) * ε,
  5517. y: Math.round(fy(d, i) / ε) * ε,
  5518. i: i
  5519. };
  5520. });
  5521. }
  5522. voronoi.links = function(data) {
  5523. return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
  5524. return edge.l && edge.r;
  5525. }).map(function(edge) {
  5526. return {
  5527. source: data[edge.l.i],
  5528. target: data[edge.r.i]
  5529. };
  5530. });
  5531. };
  5532. voronoi.triangles = function(data) {
  5533. var triangles = [];
  5534. d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
  5535. var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
  5536. while (++j < m) {
  5537. e0 = e1;
  5538. s0 = s1;
  5539. e1 = edges[j].edge;
  5540. s1 = e1.l === site ? e1.r : e1.l;
  5541. if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
  5542. triangles.push([ data[i], data[s0.i], data[s1.i] ]);
  5543. }
  5544. }
  5545. });
  5546. return triangles;
  5547. };
  5548. voronoi.x = function(_) {
  5549. return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
  5550. };
  5551. voronoi.y = function(_) {
  5552. return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
  5553. };
  5554. voronoi.clipExtent = function(_) {
  5555. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
  5556. clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
  5557. return voronoi;
  5558. };
  5559. voronoi.size = function(_) {
  5560. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
  5561. return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
  5562. };
  5563. return voronoi;
  5564. };
  5565. var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
  5566. function d3_geom_voronoiTriangleArea(a, b, c) {
  5567. return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
  5568. }
  5569. d3.geom.delaunay = function(vertices) {
  5570. return d3.geom.voronoi().triangles(vertices);
  5571. };
  5572. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  5573. var x = d3_geom_pointX, y = d3_geom_pointY, compat;
  5574. if (compat = arguments.length) {
  5575. x = d3_geom_quadtreeCompatX;
  5576. y = d3_geom_quadtreeCompatY;
  5577. if (compat === 3) {
  5578. y2 = y1;
  5579. x2 = x1;
  5580. y1 = x1 = 0;
  5581. }
  5582. return quadtree(points);
  5583. }
  5584. function quadtree(data) {
  5585. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  5586. if (x1 != null) {
  5587. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  5588. } else {
  5589. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  5590. xs = [], ys = [];
  5591. n = data.length;
  5592. if (compat) for (i = 0; i < n; ++i) {
  5593. d = data[i];
  5594. if (d.x < x1_) x1_ = d.x;
  5595. if (d.y < y1_) y1_ = d.y;
  5596. if (d.x > x2_) x2_ = d.x;
  5597. if (d.y > y2_) y2_ = d.y;
  5598. xs.push(d.x);
  5599. ys.push(d.y);
  5600. } else for (i = 0; i < n; ++i) {
  5601. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  5602. if (x_ < x1_) x1_ = x_;
  5603. if (y_ < y1_) y1_ = y_;
  5604. if (x_ > x2_) x2_ = x_;
  5605. if (y_ > y2_) y2_ = y_;
  5606. xs.push(x_);
  5607. ys.push(y_);
  5608. }
  5609. }
  5610. var dx = x2_ - x1_, dy = y2_ - y1_;
  5611. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  5612. function insert(n, d, x, y, x1, y1, x2, y2) {
  5613. if (isNaN(x) || isNaN(y)) return;
  5614. if (n.leaf) {
  5615. var nx = n.x, ny = n.y;
  5616. if (nx != null) {
  5617. if (abs(nx - x) + abs(ny - y) < .01) {
  5618. insertChild(n, d, x, y, x1, y1, x2, y2);
  5619. } else {
  5620. var nPoint = n.point;
  5621. n.x = n.y = n.point = null;
  5622. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  5623. insertChild(n, d, x, y, x1, y1, x2, y2);
  5624. }
  5625. } else {
  5626. n.x = x, n.y = y, n.point = d;
  5627. }
  5628. } else {
  5629. insertChild(n, d, x, y, x1, y1, x2, y2);
  5630. }
  5631. }
  5632. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  5633. var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
  5634. n.leaf = false;
  5635. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  5636. if (right) x1 = xm; else x2 = xm;
  5637. if (below) y1 = ym; else y2 = ym;
  5638. insert(n, d, x, y, x1, y1, x2, y2);
  5639. }
  5640. var root = d3_geom_quadtreeNode();
  5641. root.add = function(d) {
  5642. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  5643. };
  5644. root.visit = function(f) {
  5645. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  5646. };
  5647. root.find = function(point) {
  5648. return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
  5649. };
  5650. i = -1;
  5651. if (x1 == null) {
  5652. while (++i < n) {
  5653. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  5654. }
  5655. --i;
  5656. } else data.forEach(root.add);
  5657. xs = ys = data = d = null;
  5658. return root;
  5659. }
  5660. quadtree.x = function(_) {
  5661. return arguments.length ? (x = _, quadtree) : x;
  5662. };
  5663. quadtree.y = function(_) {
  5664. return arguments.length ? (y = _, quadtree) : y;
  5665. };
  5666. quadtree.extent = function(_) {
  5667. if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
  5668. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
  5669. y2 = +_[1][1];
  5670. return quadtree;
  5671. };
  5672. quadtree.size = function(_) {
  5673. if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
  5674. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
  5675. return quadtree;
  5676. };
  5677. return quadtree;
  5678. };
  5679. function d3_geom_quadtreeCompatX(d) {
  5680. return d.x;
  5681. }
  5682. function d3_geom_quadtreeCompatY(d) {
  5683. return d.y;
  5684. }
  5685. function d3_geom_quadtreeNode() {
  5686. return {
  5687. leaf: true,
  5688. nodes: [],
  5689. point: null,
  5690. x: null,
  5691. y: null
  5692. };
  5693. }
  5694. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  5695. if (!f(node, x1, y1, x2, y2)) {
  5696. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  5697. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  5698. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  5699. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  5700. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  5701. }
  5702. }
  5703. function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
  5704. var minDistance2 = Infinity, closestPoint;
  5705. (function find(node, x1, y1, x2, y2) {
  5706. if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
  5707. if (point = node.point) {
  5708. var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
  5709. if (distance2 < minDistance2) {
  5710. var distance = Math.sqrt(minDistance2 = distance2);
  5711. x0 = x - distance, y0 = y - distance;
  5712. x3 = x + distance, y3 = y + distance;
  5713. closestPoint = point;
  5714. }
  5715. }
  5716. var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
  5717. for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
  5718. if (node = children[i & 3]) switch (i & 3) {
  5719. case 0:
  5720. find(node, x1, y1, xm, ym);
  5721. break;
  5722. case 1:
  5723. find(node, xm, y1, x2, ym);
  5724. break;
  5725. case 2:
  5726. find(node, x1, ym, xm, y2);
  5727. break;
  5728. case 3:
  5729. find(node, xm, ym, x2, y2);
  5730. break;
  5731. }
  5732. }
  5733. })(root, x0, y0, x3, y3);
  5734. return closestPoint;
  5735. }
  5736. d3.interpolateRgb = d3_interpolateRgb;
  5737. function d3_interpolateRgb(a, b) {
  5738. a = d3.rgb(a);
  5739. b = d3.rgb(b);
  5740. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  5741. return function(t) {
  5742. 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));
  5743. };
  5744. }
  5745. d3.interpolateObject = d3_interpolateObject;
  5746. function d3_interpolateObject(a, b) {
  5747. var i = {}, c = {}, k;
  5748. for (k in a) {
  5749. if (k in b) {
  5750. i[k] = d3_interpolate(a[k], b[k]);
  5751. } else {
  5752. c[k] = a[k];
  5753. }
  5754. }
  5755. for (k in b) {
  5756. if (!(k in a)) {
  5757. c[k] = b[k];
  5758. }
  5759. }
  5760. return function(t) {
  5761. for (k in i) c[k] = i[k](t);
  5762. return c;
  5763. };
  5764. }
  5765. d3.interpolateNumber = d3_interpolateNumber;
  5766. function d3_interpolateNumber(a, b) {
  5767. a = +a, b = +b;
  5768. return function(t) {
  5769. return a * (1 - t) + b * t;
  5770. };
  5771. }
  5772. d3.interpolateString = d3_interpolateString;
  5773. function d3_interpolateString(a, b) {
  5774. var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
  5775. a = a + "", b = b + "";
  5776. while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
  5777. if ((bs = bm.index) > bi) {
  5778. bs = b.slice(bi, bs);
  5779. if (s[i]) s[i] += bs; else s[++i] = bs;
  5780. }
  5781. if ((am = am[0]) === (bm = bm[0])) {
  5782. if (s[i]) s[i] += bm; else s[++i] = bm;
  5783. } else {
  5784. s[++i] = null;
  5785. q.push({
  5786. i: i,
  5787. x: d3_interpolateNumber(am, bm)
  5788. });
  5789. }
  5790. bi = d3_interpolate_numberB.lastIndex;
  5791. }
  5792. if (bi < b.length) {
  5793. bs = b.slice(bi);
  5794. if (s[i]) s[i] += bs; else s[++i] = bs;
  5795. }
  5796. return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
  5797. return b(t) + "";
  5798. }) : function() {
  5799. return b;
  5800. } : (b = q.length, function(t) {
  5801. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  5802. return s.join("");
  5803. });
  5804. }
  5805. var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
  5806. d3.interpolate = d3_interpolate;
  5807. function d3_interpolate(a, b) {
  5808. var i = d3.interpolators.length, f;
  5809. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  5810. return f;
  5811. }
  5812. d3.interpolators = [ function(a, b) {
  5813. var t = typeof b;
  5814. return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
  5815. } ];
  5816. d3.interpolateArray = d3_interpolateArray;
  5817. function d3_interpolateArray(a, b) {
  5818. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  5819. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  5820. for (;i < na; ++i) c[i] = a[i];
  5821. for (;i < nb; ++i) c[i] = b[i];
  5822. return function(t) {
  5823. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  5824. return c;
  5825. };
  5826. }
  5827. var d3_ease_default = function() {
  5828. return d3_identity;
  5829. };
  5830. var d3_ease = d3.map({
  5831. linear: d3_ease_default,
  5832. poly: d3_ease_poly,
  5833. quad: function() {
  5834. return d3_ease_quad;
  5835. },
  5836. cubic: function() {
  5837. return d3_ease_cubic;
  5838. },
  5839. sin: function() {
  5840. return d3_ease_sin;
  5841. },
  5842. exp: function() {
  5843. return d3_ease_exp;
  5844. },
  5845. circle: function() {
  5846. return d3_ease_circle;
  5847. },
  5848. elastic: d3_ease_elastic,
  5849. back: d3_ease_back,
  5850. bounce: function() {
  5851. return d3_ease_bounce;
  5852. }
  5853. });
  5854. var d3_ease_mode = d3.map({
  5855. "in": d3_identity,
  5856. out: d3_ease_reverse,
  5857. "in-out": d3_ease_reflect,
  5858. "out-in": function(f) {
  5859. return d3_ease_reflect(d3_ease_reverse(f));
  5860. }
  5861. });
  5862. d3.ease = function(name) {
  5863. var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
  5864. t = d3_ease.get(t) || d3_ease_default;
  5865. m = d3_ease_mode.get(m) || d3_identity;
  5866. return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
  5867. };
  5868. function d3_ease_clamp(f) {
  5869. return function(t) {
  5870. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  5871. };
  5872. }
  5873. function d3_ease_reverse(f) {
  5874. return function(t) {
  5875. return 1 - f(1 - t);
  5876. };
  5877. }
  5878. function d3_ease_reflect(f) {
  5879. return function(t) {
  5880. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  5881. };
  5882. }
  5883. function d3_ease_quad(t) {
  5884. return t * t;
  5885. }
  5886. function d3_ease_cubic(t) {
  5887. return t * t * t;
  5888. }
  5889. function d3_ease_cubicInOut(t) {
  5890. if (t <= 0) return 0;
  5891. if (t >= 1) return 1;
  5892. var t2 = t * t, t3 = t2 * t;
  5893. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  5894. }
  5895. function d3_ease_poly(e) {
  5896. return function(t) {
  5897. return Math.pow(t, e);
  5898. };
  5899. }
  5900. function d3_ease_sin(t) {
  5901. return 1 - Math.cos(t * halfπ);
  5902. }
  5903. function d3_ease_exp(t) {
  5904. return Math.pow(2, 10 * (t - 1));
  5905. }
  5906. function d3_ease_circle(t) {
  5907. return 1 - Math.sqrt(1 - t * t);
  5908. }
  5909. function d3_ease_elastic(a, p) {
  5910. var s;
  5911. if (arguments.length < 2) p = .45;
  5912. if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
  5913. return function(t) {
  5914. return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
  5915. };
  5916. }
  5917. function d3_ease_back(s) {
  5918. if (!s) s = 1.70158;
  5919. return function(t) {
  5920. return t * t * ((s + 1) * t - s);
  5921. };
  5922. }
  5923. function d3_ease_bounce(t) {
  5924. 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;
  5925. }
  5926. d3.interpolateHcl = d3_interpolateHcl;
  5927. function d3_interpolateHcl(a, b) {
  5928. a = d3.hcl(a);
  5929. b = d3.hcl(b);
  5930. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  5931. if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
  5932. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5933. return function(t) {
  5934. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  5935. };
  5936. }
  5937. d3.interpolateHsl = d3_interpolateHsl;
  5938. function d3_interpolateHsl(a, b) {
  5939. a = d3.hsl(a);
  5940. b = d3.hsl(b);
  5941. var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
  5942. if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
  5943. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5944. return function(t) {
  5945. return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
  5946. };
  5947. }
  5948. d3.interpolateLab = d3_interpolateLab;
  5949. function d3_interpolateLab(a, b) {
  5950. a = d3.lab(a);
  5951. b = d3.lab(b);
  5952. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  5953. return function(t) {
  5954. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  5955. };
  5956. }
  5957. d3.interpolateRound = d3_interpolateRound;
  5958. function d3_interpolateRound(a, b) {
  5959. b -= a;
  5960. return function(t) {
  5961. return Math.round(a + b * t);
  5962. };
  5963. }
  5964. d3.transform = function(string) {
  5965. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  5966. return (d3.transform = function(string) {
  5967. if (string != null) {
  5968. g.setAttribute("transform", string);
  5969. var t = g.transform.baseVal.consolidate();
  5970. }
  5971. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  5972. })(string);
  5973. };
  5974. function d3_transform(m) {
  5975. 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;
  5976. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  5977. r0[0] *= -1;
  5978. r0[1] *= -1;
  5979. kx *= -1;
  5980. kz *= -1;
  5981. }
  5982. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  5983. this.translate = [ m.e, m.f ];
  5984. this.scale = [ kx, ky ];
  5985. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  5986. }
  5987. d3_transform.prototype.toString = function() {
  5988. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  5989. };
  5990. function d3_transformDot(a, b) {
  5991. return a[0] * b[0] + a[1] * b[1];
  5992. }
  5993. function d3_transformNormalize(a) {
  5994. var k = Math.sqrt(d3_transformDot(a, a));
  5995. if (k) {
  5996. a[0] /= k;
  5997. a[1] /= k;
  5998. }
  5999. return k;
  6000. }
  6001. function d3_transformCombine(a, b, k) {
  6002. a[0] += k * b[0];
  6003. a[1] += k * b[1];
  6004. return a;
  6005. }
  6006. var d3_transformIdentity = {
  6007. a: 1,
  6008. b: 0,
  6009. c: 0,
  6010. d: 1,
  6011. e: 0,
  6012. f: 0
  6013. };
  6014. d3.interpolateTransform = d3_interpolateTransform;
  6015. function d3_interpolateTransformPop(s) {
  6016. return s.length ? s.pop() + "," : "";
  6017. }
  6018. function d3_interpolateTranslate(ta, tb, s, q) {
  6019. if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
  6020. var i = s.push("translate(", null, ",", null, ")");
  6021. q.push({
  6022. i: i - 4,
  6023. x: d3_interpolateNumber(ta[0], tb[0])
  6024. }, {
  6025. i: i - 2,
  6026. x: d3_interpolateNumber(ta[1], tb[1])
  6027. });
  6028. } else if (tb[0] || tb[1]) {
  6029. s.push("translate(" + tb + ")");
  6030. }
  6031. }
  6032. function d3_interpolateRotate(ra, rb, s, q) {
  6033. if (ra !== rb) {
  6034. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  6035. q.push({
  6036. i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
  6037. x: d3_interpolateNumber(ra, rb)
  6038. });
  6039. } else if (rb) {
  6040. s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
  6041. }
  6042. }
  6043. function d3_interpolateSkew(wa, wb, s, q) {
  6044. if (wa !== wb) {
  6045. q.push({
  6046. i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
  6047. x: d3_interpolateNumber(wa, wb)
  6048. });
  6049. } else if (wb) {
  6050. s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
  6051. }
  6052. }
  6053. function d3_interpolateScale(ka, kb, s, q) {
  6054. if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
  6055. var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
  6056. q.push({
  6057. i: i - 4,
  6058. x: d3_interpolateNumber(ka[0], kb[0])
  6059. }, {
  6060. i: i - 2,
  6061. x: d3_interpolateNumber(ka[1], kb[1])
  6062. });
  6063. } else if (kb[0] !== 1 || kb[1] !== 1) {
  6064. s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
  6065. }
  6066. }
  6067. function d3_interpolateTransform(a, b) {
  6068. var s = [], q = [];
  6069. a = d3.transform(a), b = d3.transform(b);
  6070. d3_interpolateTranslate(a.translate, b.translate, s, q);
  6071. d3_interpolateRotate(a.rotate, b.rotate, s, q);
  6072. d3_interpolateSkew(a.skew, b.skew, s, q);
  6073. d3_interpolateScale(a.scale, b.scale, s, q);
  6074. a = b = null;
  6075. return function(t) {
  6076. var i = -1, n = q.length, o;
  6077. while (++i < n) s[(o = q[i]).i] = o.x(t);
  6078. return s.join("");
  6079. };
  6080. }
  6081. function d3_uninterpolateNumber(a, b) {
  6082. b = (b -= a = +a) || 1 / b;
  6083. return function(x) {
  6084. return (x - a) / b;
  6085. };
  6086. }
  6087. function d3_uninterpolateClamp(a, b) {
  6088. b = (b -= a = +a) || 1 / b;
  6089. return function(x) {
  6090. return Math.max(0, Math.min(1, (x - a) / b));
  6091. };
  6092. }
  6093. d3.layout = {};
  6094. d3.layout.bundle = function() {
  6095. return function(links) {
  6096. var paths = [], i = -1, n = links.length;
  6097. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  6098. return paths;
  6099. };
  6100. };
  6101. function d3_layout_bundlePath(link) {
  6102. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  6103. while (start !== lca) {
  6104. start = start.parent;
  6105. points.push(start);
  6106. }
  6107. var k = points.length;
  6108. while (end !== lca) {
  6109. points.splice(k, 0, end);
  6110. end = end.parent;
  6111. }
  6112. return points;
  6113. }
  6114. function d3_layout_bundleAncestors(node) {
  6115. var ancestors = [], parent = node.parent;
  6116. while (parent != null) {
  6117. ancestors.push(node);
  6118. node = parent;
  6119. parent = parent.parent;
  6120. }
  6121. ancestors.push(node);
  6122. return ancestors;
  6123. }
  6124. function d3_layout_bundleLeastCommonAncestor(a, b) {
  6125. if (a === b) return a;
  6126. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  6127. while (aNode === bNode) {
  6128. sharedNode = aNode;
  6129. aNode = aNodes.pop();
  6130. bNode = bNodes.pop();
  6131. }
  6132. return sharedNode;
  6133. }
  6134. d3.layout.chord = function() {
  6135. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  6136. function relayout() {
  6137. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  6138. chords = [];
  6139. groups = [];
  6140. k = 0, i = -1;
  6141. while (++i < n) {
  6142. x = 0, j = -1;
  6143. while (++j < n) {
  6144. x += matrix[i][j];
  6145. }
  6146. groupSums.push(x);
  6147. subgroupIndex.push(d3.range(n));
  6148. k += x;
  6149. }
  6150. if (sortGroups) {
  6151. groupIndex.sort(function(a, b) {
  6152. return sortGroups(groupSums[a], groupSums[b]);
  6153. });
  6154. }
  6155. if (sortSubgroups) {
  6156. subgroupIndex.forEach(function(d, i) {
  6157. d.sort(function(a, b) {
  6158. return sortSubgroups(matrix[i][a], matrix[i][b]);
  6159. });
  6160. });
  6161. }
  6162. k = (τ - padding * n) / k;
  6163. x = 0, i = -1;
  6164. while (++i < n) {
  6165. x0 = x, j = -1;
  6166. while (++j < n) {
  6167. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  6168. subgroups[di + "-" + dj] = {
  6169. index: di,
  6170. subindex: dj,
  6171. startAngle: a0,
  6172. endAngle: a1,
  6173. value: v
  6174. };
  6175. }
  6176. groups[di] = {
  6177. index: di,
  6178. startAngle: x0,
  6179. endAngle: x,
  6180. value: groupSums[di]
  6181. };
  6182. x += padding;
  6183. }
  6184. i = -1;
  6185. while (++i < n) {
  6186. j = i - 1;
  6187. while (++j < n) {
  6188. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  6189. if (source.value || target.value) {
  6190. chords.push(source.value < target.value ? {
  6191. source: target,
  6192. target: source
  6193. } : {
  6194. source: source,
  6195. target: target
  6196. });
  6197. }
  6198. }
  6199. }
  6200. if (sortChords) resort();
  6201. }
  6202. function resort() {
  6203. chords.sort(function(a, b) {
  6204. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  6205. });
  6206. }
  6207. chord.matrix = function(x) {
  6208. if (!arguments.length) return matrix;
  6209. n = (matrix = x) && matrix.length;
  6210. chords = groups = null;
  6211. return chord;
  6212. };
  6213. chord.padding = function(x) {
  6214. if (!arguments.length) return padding;
  6215. padding = x;
  6216. chords = groups = null;
  6217. return chord;
  6218. };
  6219. chord.sortGroups = function(x) {
  6220. if (!arguments.length) return sortGroups;
  6221. sortGroups = x;
  6222. chords = groups = null;
  6223. return chord;
  6224. };
  6225. chord.sortSubgroups = function(x) {
  6226. if (!arguments.length) return sortSubgroups;
  6227. sortSubgroups = x;
  6228. chords = null;
  6229. return chord;
  6230. };
  6231. chord.sortChords = function(x) {
  6232. if (!arguments.length) return sortChords;
  6233. sortChords = x;
  6234. if (chords) resort();
  6235. return chord;
  6236. };
  6237. chord.chords = function() {
  6238. if (!chords) relayout();
  6239. return chords;
  6240. };
  6241. chord.groups = function() {
  6242. if (!groups) relayout();
  6243. return groups;
  6244. };
  6245. return chord;
  6246. };
  6247. d3.layout.force = function() {
  6248. var force = {}, event = d3.dispatch("start", "tick", "end"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
  6249. function repulse(node) {
  6250. return function(quad, x1, _, x2) {
  6251. if (quad.point !== node) {
  6252. var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
  6253. if (dw * dw / theta2 < dn) {
  6254. if (dn < chargeDistance2) {
  6255. var k = quad.charge / dn;
  6256. node.px -= dx * k;
  6257. node.py -= dy * k;
  6258. }
  6259. return true;
  6260. }
  6261. if (quad.point && dn && dn < chargeDistance2) {
  6262. var k = quad.pointCharge / dn;
  6263. node.px -= dx * k;
  6264. node.py -= dy * k;
  6265. }
  6266. }
  6267. return !quad.charge;
  6268. };
  6269. }
  6270. force.tick = function() {
  6271. if ((alpha *= .99) < .005) {
  6272. timer = null;
  6273. event.end({
  6274. type: "end",
  6275. alpha: alpha = 0
  6276. });
  6277. return true;
  6278. }
  6279. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  6280. for (i = 0; i < m; ++i) {
  6281. o = links[i];
  6282. s = o.source;
  6283. t = o.target;
  6284. x = t.x - s.x;
  6285. y = t.y - s.y;
  6286. if (l = x * x + y * y) {
  6287. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  6288. x *= l;
  6289. y *= l;
  6290. t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
  6291. t.y -= y * k;
  6292. s.x += x * (k = 1 - k);
  6293. s.y += y * k;
  6294. }
  6295. }
  6296. if (k = alpha * gravity) {
  6297. x = size[0] / 2;
  6298. y = size[1] / 2;
  6299. i = -1;
  6300. if (k) while (++i < n) {
  6301. o = nodes[i];
  6302. o.x += (x - o.x) * k;
  6303. o.y += (y - o.y) * k;
  6304. }
  6305. }
  6306. if (charge) {
  6307. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  6308. i = -1;
  6309. while (++i < n) {
  6310. if (!(o = nodes[i]).fixed) {
  6311. q.visit(repulse(o));
  6312. }
  6313. }
  6314. }
  6315. i = -1;
  6316. while (++i < n) {
  6317. o = nodes[i];
  6318. if (o.fixed) {
  6319. o.x = o.px;
  6320. o.y = o.py;
  6321. } else {
  6322. o.x -= (o.px - (o.px = o.x)) * friction;
  6323. o.y -= (o.py - (o.py = o.y)) * friction;
  6324. }
  6325. }
  6326. event.tick({
  6327. type: "tick",
  6328. alpha: alpha
  6329. });
  6330. };
  6331. force.nodes = function(x) {
  6332. if (!arguments.length) return nodes;
  6333. nodes = x;
  6334. return force;
  6335. };
  6336. force.links = function(x) {
  6337. if (!arguments.length) return links;
  6338. links = x;
  6339. return force;
  6340. };
  6341. force.size = function(x) {
  6342. if (!arguments.length) return size;
  6343. size = x;
  6344. return force;
  6345. };
  6346. force.linkDistance = function(x) {
  6347. if (!arguments.length) return linkDistance;
  6348. linkDistance = typeof x === "function" ? x : +x;
  6349. return force;
  6350. };
  6351. force.distance = force.linkDistance;
  6352. force.linkStrength = function(x) {
  6353. if (!arguments.length) return linkStrength;
  6354. linkStrength = typeof x === "function" ? x : +x;
  6355. return force;
  6356. };
  6357. force.friction = function(x) {
  6358. if (!arguments.length) return friction;
  6359. friction = +x;
  6360. return force;
  6361. };
  6362. force.charge = function(x) {
  6363. if (!arguments.length) return charge;
  6364. charge = typeof x === "function" ? x : +x;
  6365. return force;
  6366. };
  6367. force.chargeDistance = function(x) {
  6368. if (!arguments.length) return Math.sqrt(chargeDistance2);
  6369. chargeDistance2 = x * x;
  6370. return force;
  6371. };
  6372. force.gravity = function(x) {
  6373. if (!arguments.length) return gravity;
  6374. gravity = +x;
  6375. return force;
  6376. };
  6377. force.theta = function(x) {
  6378. if (!arguments.length) return Math.sqrt(theta2);
  6379. theta2 = x * x;
  6380. return force;
  6381. };
  6382. force.alpha = function(x) {
  6383. if (!arguments.length) return alpha;
  6384. x = +x;
  6385. if (alpha) {
  6386. if (x > 0) {
  6387. alpha = x;
  6388. } else {
  6389. timer.c = null, timer.t = NaN, timer = null;
  6390. event.end({
  6391. type: "end",
  6392. alpha: alpha = 0
  6393. });
  6394. }
  6395. } else if (x > 0) {
  6396. event.start({
  6397. type: "start",
  6398. alpha: alpha = x
  6399. });
  6400. timer = d3_timer(force.tick);
  6401. }
  6402. return force;
  6403. };
  6404. force.start = function() {
  6405. var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  6406. for (i = 0; i < n; ++i) {
  6407. (o = nodes[i]).index = i;
  6408. o.weight = 0;
  6409. }
  6410. for (i = 0; i < m; ++i) {
  6411. o = links[i];
  6412. if (typeof o.source == "number") o.source = nodes[o.source];
  6413. if (typeof o.target == "number") o.target = nodes[o.target];
  6414. ++o.source.weight;
  6415. ++o.target.weight;
  6416. }
  6417. for (i = 0; i < n; ++i) {
  6418. o = nodes[i];
  6419. if (isNaN(o.x)) o.x = position("x", w);
  6420. if (isNaN(o.y)) o.y = position("y", h);
  6421. if (isNaN(o.px)) o.px = o.x;
  6422. if (isNaN(o.py)) o.py = o.y;
  6423. }
  6424. distances = [];
  6425. 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;
  6426. strengths = [];
  6427. 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;
  6428. charges = [];
  6429. 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;
  6430. function position(dimension, size) {
  6431. if (!neighbors) {
  6432. neighbors = new Array(n);
  6433. for (j = 0; j < n; ++j) {
  6434. neighbors[j] = [];
  6435. }
  6436. for (j = 0; j < m; ++j) {
  6437. var o = links[j];
  6438. neighbors[o.source.index].push(o.target);
  6439. neighbors[o.target.index].push(o.source);
  6440. }
  6441. }
  6442. var candidates = neighbors[i], j = -1, l = candidates.length, x;
  6443. while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
  6444. return Math.random() * size;
  6445. }
  6446. return force.resume();
  6447. };
  6448. force.resume = function() {
  6449. return force.alpha(.1);
  6450. };
  6451. force.stop = function() {
  6452. return force.alpha(0);
  6453. };
  6454. force.drag = function() {
  6455. 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);
  6456. if (!arguments.length) return drag;
  6457. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  6458. };
  6459. function dragmove(d) {
  6460. d.px = d3.event.x, d.py = d3.event.y;
  6461. force.resume();
  6462. }
  6463. return d3.rebind(force, event, "on");
  6464. };
  6465. function d3_layout_forceDragstart(d) {
  6466. d.fixed |= 2;
  6467. }
  6468. function d3_layout_forceDragend(d) {
  6469. d.fixed &= ~6;
  6470. }
  6471. function d3_layout_forceMouseover(d) {
  6472. d.fixed |= 4;
  6473. d.px = d.x, d.py = d.y;
  6474. }
  6475. function d3_layout_forceMouseout(d) {
  6476. d.fixed &= ~4;
  6477. }
  6478. function d3_layout_forceAccumulate(quad, alpha, charges) {
  6479. var cx = 0, cy = 0;
  6480. quad.charge = 0;
  6481. if (!quad.leaf) {
  6482. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  6483. while (++i < n) {
  6484. c = nodes[i];
  6485. if (c == null) continue;
  6486. d3_layout_forceAccumulate(c, alpha, charges);
  6487. quad.charge += c.charge;
  6488. cx += c.charge * c.cx;
  6489. cy += c.charge * c.cy;
  6490. }
  6491. }
  6492. if (quad.point) {
  6493. if (!quad.leaf) {
  6494. quad.point.x += Math.random() - .5;
  6495. quad.point.y += Math.random() - .5;
  6496. }
  6497. var k = alpha * charges[quad.point.index];
  6498. quad.charge += quad.pointCharge = k;
  6499. cx += k * quad.point.x;
  6500. cy += k * quad.point.y;
  6501. }
  6502. quad.cx = cx / quad.charge;
  6503. quad.cy = cy / quad.charge;
  6504. }
  6505. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
  6506. d3.layout.hierarchy = function() {
  6507. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  6508. function hierarchy(root) {
  6509. var stack = [ root ], nodes = [], node;
  6510. root.depth = 0;
  6511. while ((node = stack.pop()) != null) {
  6512. nodes.push(node);
  6513. if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
  6514. var n, childs, child;
  6515. while (--n >= 0) {
  6516. stack.push(child = childs[n]);
  6517. child.parent = node;
  6518. child.depth = node.depth + 1;
  6519. }
  6520. if (value) node.value = 0;
  6521. node.children = childs;
  6522. } else {
  6523. if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6524. delete node.children;
  6525. }
  6526. }
  6527. d3_layout_hierarchyVisitAfter(root, function(node) {
  6528. var childs, parent;
  6529. if (sort && (childs = node.children)) childs.sort(sort);
  6530. if (value && (parent = node.parent)) parent.value += node.value;
  6531. });
  6532. return nodes;
  6533. }
  6534. hierarchy.sort = function(x) {
  6535. if (!arguments.length) return sort;
  6536. sort = x;
  6537. return hierarchy;
  6538. };
  6539. hierarchy.children = function(x) {
  6540. if (!arguments.length) return children;
  6541. children = x;
  6542. return hierarchy;
  6543. };
  6544. hierarchy.value = function(x) {
  6545. if (!arguments.length) return value;
  6546. value = x;
  6547. return hierarchy;
  6548. };
  6549. hierarchy.revalue = function(root) {
  6550. if (value) {
  6551. d3_layout_hierarchyVisitBefore(root, function(node) {
  6552. if (node.children) node.value = 0;
  6553. });
  6554. d3_layout_hierarchyVisitAfter(root, function(node) {
  6555. var parent;
  6556. if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6557. if (parent = node.parent) parent.value += node.value;
  6558. });
  6559. }
  6560. return root;
  6561. };
  6562. return hierarchy;
  6563. };
  6564. function d3_layout_hierarchyRebind(object, hierarchy) {
  6565. d3.rebind(object, hierarchy, "sort", "children", "value");
  6566. object.nodes = object;
  6567. object.links = d3_layout_hierarchyLinks;
  6568. return object;
  6569. }
  6570. function d3_layout_hierarchyVisitBefore(node, callback) {
  6571. var nodes = [ node ];
  6572. while ((node = nodes.pop()) != null) {
  6573. callback(node);
  6574. if ((children = node.children) && (n = children.length)) {
  6575. var n, children;
  6576. while (--n >= 0) nodes.push(children[n]);
  6577. }
  6578. }
  6579. }
  6580. function d3_layout_hierarchyVisitAfter(node, callback) {
  6581. var nodes = [ node ], nodes2 = [];
  6582. while ((node = nodes.pop()) != null) {
  6583. nodes2.push(node);
  6584. if ((children = node.children) && (n = children.length)) {
  6585. var i = -1, n, children;
  6586. while (++i < n) nodes.push(children[i]);
  6587. }
  6588. }
  6589. while ((node = nodes2.pop()) != null) {
  6590. callback(node);
  6591. }
  6592. }
  6593. function d3_layout_hierarchyChildren(d) {
  6594. return d.children;
  6595. }
  6596. function d3_layout_hierarchyValue(d) {
  6597. return d.value;
  6598. }
  6599. function d3_layout_hierarchySort(a, b) {
  6600. return b.value - a.value;
  6601. }
  6602. function d3_layout_hierarchyLinks(nodes) {
  6603. return d3.merge(nodes.map(function(parent) {
  6604. return (parent.children || []).map(function(child) {
  6605. return {
  6606. source: parent,
  6607. target: child
  6608. };
  6609. });
  6610. }));
  6611. }
  6612. d3.layout.partition = function() {
  6613. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  6614. function position(node, x, dx, dy) {
  6615. var children = node.children;
  6616. node.x = x;
  6617. node.y = node.depth * dy;
  6618. node.dx = dx;
  6619. node.dy = dy;
  6620. if (children && (n = children.length)) {
  6621. var i = -1, n, c, d;
  6622. dx = node.value ? dx / node.value : 0;
  6623. while (++i < n) {
  6624. position(c = children[i], x, d = c.value * dx, dy);
  6625. x += d;
  6626. }
  6627. }
  6628. }
  6629. function depth(node) {
  6630. var children = node.children, d = 0;
  6631. if (children && (n = children.length)) {
  6632. var i = -1, n;
  6633. while (++i < n) d = Math.max(d, depth(children[i]));
  6634. }
  6635. return 1 + d;
  6636. }
  6637. function partition(d, i) {
  6638. var nodes = hierarchy.call(this, d, i);
  6639. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  6640. return nodes;
  6641. }
  6642. partition.size = function(x) {
  6643. if (!arguments.length) return size;
  6644. size = x;
  6645. return partition;
  6646. };
  6647. return d3_layout_hierarchyRebind(partition, hierarchy);
  6648. };
  6649. d3.layout.pie = function() {
  6650. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
  6651. function pie(data) {
  6652. var n = data.length, values = data.map(function(d, i) {
  6653. return +value.call(pie, d, i);
  6654. }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;
  6655. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  6656. return values[j] - values[i];
  6657. } : function(i, j) {
  6658. return sort(data[i], data[j]);
  6659. });
  6660. index.forEach(function(i) {
  6661. arcs[i] = {
  6662. data: data[i],
  6663. value: v = values[i],
  6664. startAngle: a,
  6665. endAngle: a += v * k + pa,
  6666. padAngle: p
  6667. };
  6668. });
  6669. return arcs;
  6670. }
  6671. pie.value = function(_) {
  6672. if (!arguments.length) return value;
  6673. value = _;
  6674. return pie;
  6675. };
  6676. pie.sort = function(_) {
  6677. if (!arguments.length) return sort;
  6678. sort = _;
  6679. return pie;
  6680. };
  6681. pie.startAngle = function(_) {
  6682. if (!arguments.length) return startAngle;
  6683. startAngle = _;
  6684. return pie;
  6685. };
  6686. pie.endAngle = function(_) {
  6687. if (!arguments.length) return endAngle;
  6688. endAngle = _;
  6689. return pie;
  6690. };
  6691. pie.padAngle = function(_) {
  6692. if (!arguments.length) return padAngle;
  6693. padAngle = _;
  6694. return pie;
  6695. };
  6696. return pie;
  6697. };
  6698. var d3_layout_pieSortByValue = {};
  6699. d3.layout.stack = function() {
  6700. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  6701. function stack(data, index) {
  6702. if (!(n = data.length)) return data;
  6703. var series = data.map(function(d, i) {
  6704. return values.call(stack, d, i);
  6705. });
  6706. var points = series.map(function(d) {
  6707. return d.map(function(v, i) {
  6708. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  6709. });
  6710. });
  6711. var orders = order.call(stack, points, index);
  6712. series = d3.permute(series, orders);
  6713. points = d3.permute(points, orders);
  6714. var offsets = offset.call(stack, points, index);
  6715. var m = series[0].length, n, i, j, o;
  6716. for (j = 0; j < m; ++j) {
  6717. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  6718. for (i = 1; i < n; ++i) {
  6719. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  6720. }
  6721. }
  6722. return data;
  6723. }
  6724. stack.values = function(x) {
  6725. if (!arguments.length) return values;
  6726. values = x;
  6727. return stack;
  6728. };
  6729. stack.order = function(x) {
  6730. if (!arguments.length) return order;
  6731. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  6732. return stack;
  6733. };
  6734. stack.offset = function(x) {
  6735. if (!arguments.length) return offset;
  6736. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  6737. return stack;
  6738. };
  6739. stack.x = function(z) {
  6740. if (!arguments.length) return x;
  6741. x = z;
  6742. return stack;
  6743. };
  6744. stack.y = function(z) {
  6745. if (!arguments.length) return y;
  6746. y = z;
  6747. return stack;
  6748. };
  6749. stack.out = function(z) {
  6750. if (!arguments.length) return out;
  6751. out = z;
  6752. return stack;
  6753. };
  6754. return stack;
  6755. };
  6756. function d3_layout_stackX(d) {
  6757. return d.x;
  6758. }
  6759. function d3_layout_stackY(d) {
  6760. return d.y;
  6761. }
  6762. function d3_layout_stackOut(d, y0, y) {
  6763. d.y0 = y0;
  6764. d.y = y;
  6765. }
  6766. var d3_layout_stackOrders = d3.map({
  6767. "inside-out": function(data) {
  6768. 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) {
  6769. return max[a] - max[b];
  6770. }), top = 0, bottom = 0, tops = [], bottoms = [];
  6771. for (i = 0; i < n; ++i) {
  6772. j = index[i];
  6773. if (top < bottom) {
  6774. top += sums[j];
  6775. tops.push(j);
  6776. } else {
  6777. bottom += sums[j];
  6778. bottoms.push(j);
  6779. }
  6780. }
  6781. return bottoms.reverse().concat(tops);
  6782. },
  6783. reverse: function(data) {
  6784. return d3.range(data.length).reverse();
  6785. },
  6786. "default": d3_layout_stackOrderDefault
  6787. });
  6788. var d3_layout_stackOffsets = d3.map({
  6789. silhouette: function(data) {
  6790. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  6791. for (j = 0; j < m; ++j) {
  6792. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6793. if (o > max) max = o;
  6794. sums.push(o);
  6795. }
  6796. for (j = 0; j < m; ++j) {
  6797. y0[j] = (max - sums[j]) / 2;
  6798. }
  6799. return y0;
  6800. },
  6801. wiggle: function(data) {
  6802. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  6803. y0[0] = o = o0 = 0;
  6804. for (j = 1; j < m; ++j) {
  6805. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  6806. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  6807. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  6808. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  6809. }
  6810. s2 += s3 * data[i][j][1];
  6811. }
  6812. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  6813. if (o < o0) o0 = o;
  6814. }
  6815. for (j = 0; j < m; ++j) y0[j] -= o0;
  6816. return y0;
  6817. },
  6818. expand: function(data) {
  6819. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  6820. for (j = 0; j < m; ++j) {
  6821. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6822. 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;
  6823. }
  6824. for (j = 0; j < m; ++j) y0[j] = 0;
  6825. return y0;
  6826. },
  6827. zero: d3_layout_stackOffsetZero
  6828. });
  6829. function d3_layout_stackOrderDefault(data) {
  6830. return d3.range(data.length);
  6831. }
  6832. function d3_layout_stackOffsetZero(data) {
  6833. var j = -1, m = data[0].length, y0 = [];
  6834. while (++j < m) y0[j] = 0;
  6835. return y0;
  6836. }
  6837. function d3_layout_stackMaxIndex(array) {
  6838. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  6839. for (;i < n; ++i) {
  6840. if ((k = array[i][1]) > v) {
  6841. j = i;
  6842. v = k;
  6843. }
  6844. }
  6845. return j;
  6846. }
  6847. function d3_layout_stackReduceSum(d) {
  6848. return d.reduce(d3_layout_stackSum, 0);
  6849. }
  6850. function d3_layout_stackSum(p, d) {
  6851. return p + d[1];
  6852. }
  6853. d3.layout.histogram = function() {
  6854. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  6855. function histogram(data, i) {
  6856. 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;
  6857. while (++i < m) {
  6858. bin = bins[i] = [];
  6859. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  6860. bin.y = 0;
  6861. }
  6862. if (m > 0) {
  6863. i = -1;
  6864. while (++i < n) {
  6865. x = values[i];
  6866. if (x >= range[0] && x <= range[1]) {
  6867. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  6868. bin.y += k;
  6869. bin.push(data[i]);
  6870. }
  6871. }
  6872. }
  6873. return bins;
  6874. }
  6875. histogram.value = function(x) {
  6876. if (!arguments.length) return valuer;
  6877. valuer = x;
  6878. return histogram;
  6879. };
  6880. histogram.range = function(x) {
  6881. if (!arguments.length) return ranger;
  6882. ranger = d3_functor(x);
  6883. return histogram;
  6884. };
  6885. histogram.bins = function(x) {
  6886. if (!arguments.length) return binner;
  6887. binner = typeof x === "number" ? function(range) {
  6888. return d3_layout_histogramBinFixed(range, x);
  6889. } : d3_functor(x);
  6890. return histogram;
  6891. };
  6892. histogram.frequency = function(x) {
  6893. if (!arguments.length) return frequency;
  6894. frequency = !!x;
  6895. return histogram;
  6896. };
  6897. return histogram;
  6898. };
  6899. function d3_layout_histogramBinSturges(range, values) {
  6900. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  6901. }
  6902. function d3_layout_histogramBinFixed(range, n) {
  6903. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  6904. while (++x <= n) f[x] = m * x + b;
  6905. return f;
  6906. }
  6907. function d3_layout_histogramRange(values) {
  6908. return [ d3.min(values), d3.max(values) ];
  6909. }
  6910. d3.layout.pack = function() {
  6911. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
  6912. function pack(d, i) {
  6913. var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() {
  6914. return radius;
  6915. };
  6916. root.x = root.y = 0;
  6917. d3_layout_hierarchyVisitAfter(root, function(d) {
  6918. d.r = +r(d.value);
  6919. });
  6920. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6921. if (padding) {
  6922. var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
  6923. d3_layout_hierarchyVisitAfter(root, function(d) {
  6924. d.r += dr;
  6925. });
  6926. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6927. d3_layout_hierarchyVisitAfter(root, function(d) {
  6928. d.r -= dr;
  6929. });
  6930. }
  6931. d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
  6932. return nodes;
  6933. }
  6934. pack.size = function(_) {
  6935. if (!arguments.length) return size;
  6936. size = _;
  6937. return pack;
  6938. };
  6939. pack.radius = function(_) {
  6940. if (!arguments.length) return radius;
  6941. radius = _ == null || typeof _ === "function" ? _ : +_;
  6942. return pack;
  6943. };
  6944. pack.padding = function(_) {
  6945. if (!arguments.length) return padding;
  6946. padding = +_;
  6947. return pack;
  6948. };
  6949. return d3_layout_hierarchyRebind(pack, hierarchy);
  6950. };
  6951. function d3_layout_packSort(a, b) {
  6952. return a.value - b.value;
  6953. }
  6954. function d3_layout_packInsert(a, b) {
  6955. var c = a._pack_next;
  6956. a._pack_next = b;
  6957. b._pack_prev = a;
  6958. b._pack_next = c;
  6959. c._pack_prev = b;
  6960. }
  6961. function d3_layout_packSplice(a, b) {
  6962. a._pack_next = b;
  6963. b._pack_prev = a;
  6964. }
  6965. function d3_layout_packIntersects(a, b) {
  6966. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  6967. return .999 * dr * dr > dx * dx + dy * dy;
  6968. }
  6969. function d3_layout_packSiblings(node) {
  6970. if (!(nodes = node.children) || !(n = nodes.length)) return;
  6971. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  6972. function bound(node) {
  6973. xMin = Math.min(node.x - node.r, xMin);
  6974. xMax = Math.max(node.x + node.r, xMax);
  6975. yMin = Math.min(node.y - node.r, yMin);
  6976. yMax = Math.max(node.y + node.r, yMax);
  6977. }
  6978. nodes.forEach(d3_layout_packLink);
  6979. a = nodes[0];
  6980. a.x = -a.r;
  6981. a.y = 0;
  6982. bound(a);
  6983. if (n > 1) {
  6984. b = nodes[1];
  6985. b.x = b.r;
  6986. b.y = 0;
  6987. bound(b);
  6988. if (n > 2) {
  6989. c = nodes[2];
  6990. d3_layout_packPlace(a, b, c);
  6991. bound(c);
  6992. d3_layout_packInsert(a, c);
  6993. a._pack_prev = c;
  6994. d3_layout_packInsert(c, b);
  6995. b = a._pack_next;
  6996. for (i = 3; i < n; i++) {
  6997. d3_layout_packPlace(a, b, c = nodes[i]);
  6998. var isect = 0, s1 = 1, s2 = 1;
  6999. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  7000. if (d3_layout_packIntersects(j, c)) {
  7001. isect = 1;
  7002. break;
  7003. }
  7004. }
  7005. if (isect == 1) {
  7006. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  7007. if (d3_layout_packIntersects(k, c)) {
  7008. break;
  7009. }
  7010. }
  7011. }
  7012. if (isect) {
  7013. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  7014. i--;
  7015. } else {
  7016. d3_layout_packInsert(a, c);
  7017. b = c;
  7018. bound(c);
  7019. }
  7020. }
  7021. }
  7022. }
  7023. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  7024. for (i = 0; i < n; i++) {
  7025. c = nodes[i];
  7026. c.x -= cx;
  7027. c.y -= cy;
  7028. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  7029. }
  7030. node.r = cr;
  7031. nodes.forEach(d3_layout_packUnlink);
  7032. }
  7033. function d3_layout_packLink(node) {
  7034. node._pack_next = node._pack_prev = node;
  7035. }
  7036. function d3_layout_packUnlink(node) {
  7037. delete node._pack_next;
  7038. delete node._pack_prev;
  7039. }
  7040. function d3_layout_packTransform(node, x, y, k) {
  7041. var children = node.children;
  7042. node.x = x += k * node.x;
  7043. node.y = y += k * node.y;
  7044. node.r *= k;
  7045. if (children) {
  7046. var i = -1, n = children.length;
  7047. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  7048. }
  7049. }
  7050. function d3_layout_packPlace(a, b, c) {
  7051. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  7052. if (db && (dx || dy)) {
  7053. var da = b.r + c.r, dc = dx * dx + dy * dy;
  7054. da *= da;
  7055. db *= db;
  7056. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  7057. c.x = a.x + x * dx + y * dy;
  7058. c.y = a.y + x * dy - y * dx;
  7059. } else {
  7060. c.x = a.x + db;
  7061. c.y = a.y;
  7062. }
  7063. }
  7064. d3.layout.tree = function() {
  7065. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
  7066. function tree(d, i) {
  7067. var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
  7068. d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
  7069. d3_layout_hierarchyVisitBefore(root1, secondWalk);
  7070. if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
  7071. var left = root0, right = root0, bottom = root0;
  7072. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7073. if (node.x < left.x) left = node;
  7074. if (node.x > right.x) right = node;
  7075. if (node.depth > bottom.depth) bottom = node;
  7076. });
  7077. var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
  7078. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7079. node.x = (node.x + tx) * kx;
  7080. node.y = node.depth * ky;
  7081. });
  7082. }
  7083. return nodes;
  7084. }
  7085. function wrapTree(root0) {
  7086. var root1 = {
  7087. A: null,
  7088. children: [ root0 ]
  7089. }, queue = [ root1 ], node1;
  7090. while ((node1 = queue.pop()) != null) {
  7091. for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
  7092. queue.push((children[i] = child = {
  7093. _: children[i],
  7094. parent: node1,
  7095. children: (child = children[i].children) && child.slice() || [],
  7096. A: null,
  7097. a: null,
  7098. z: 0,
  7099. m: 0,
  7100. c: 0,
  7101. s: 0,
  7102. t: null,
  7103. i: i
  7104. }).a = child);
  7105. }
  7106. }
  7107. return root1.children[0];
  7108. }
  7109. function firstWalk(v) {
  7110. var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
  7111. if (children.length) {
  7112. d3_layout_treeShift(v);
  7113. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  7114. if (w) {
  7115. v.z = w.z + separation(v._, w._);
  7116. v.m = v.z - midpoint;
  7117. } else {
  7118. v.z = midpoint;
  7119. }
  7120. } else if (w) {
  7121. v.z = w.z + separation(v._, w._);
  7122. }
  7123. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  7124. }
  7125. function secondWalk(v) {
  7126. v._.x = v.z + v.parent.m;
  7127. v.m += v.parent.m;
  7128. }
  7129. function apportion(v, w, ancestor) {
  7130. if (w) {
  7131. var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
  7132. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  7133. vom = d3_layout_treeLeft(vom);
  7134. vop = d3_layout_treeRight(vop);
  7135. vop.a = v;
  7136. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  7137. if (shift > 0) {
  7138. d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
  7139. sip += shift;
  7140. sop += shift;
  7141. }
  7142. sim += vim.m;
  7143. sip += vip.m;
  7144. som += vom.m;
  7145. sop += vop.m;
  7146. }
  7147. if (vim && !d3_layout_treeRight(vop)) {
  7148. vop.t = vim;
  7149. vop.m += sim - sop;
  7150. }
  7151. if (vip && !d3_layout_treeLeft(vom)) {
  7152. vom.t = vip;
  7153. vom.m += sip - som;
  7154. ancestor = v;
  7155. }
  7156. }
  7157. return ancestor;
  7158. }
  7159. function sizeNode(node) {
  7160. node.x *= size[0];
  7161. node.y = node.depth * size[1];
  7162. }
  7163. tree.separation = function(x) {
  7164. if (!arguments.length) return separation;
  7165. separation = x;
  7166. return tree;
  7167. };
  7168. tree.size = function(x) {
  7169. if (!arguments.length) return nodeSize ? null : size;
  7170. nodeSize = (size = x) == null ? sizeNode : null;
  7171. return tree;
  7172. };
  7173. tree.nodeSize = function(x) {
  7174. if (!arguments.length) return nodeSize ? size : null;
  7175. nodeSize = (size = x) == null ? null : sizeNode;
  7176. return tree;
  7177. };
  7178. return d3_layout_hierarchyRebind(tree, hierarchy);
  7179. };
  7180. function d3_layout_treeSeparation(a, b) {
  7181. return a.parent == b.parent ? 1 : 2;
  7182. }
  7183. function d3_layout_treeLeft(v) {
  7184. var children = v.children;
  7185. return children.length ? children[0] : v.t;
  7186. }
  7187. function d3_layout_treeRight(v) {
  7188. var children = v.children, n;
  7189. return (n = children.length) ? children[n - 1] : v.t;
  7190. }
  7191. function d3_layout_treeMove(wm, wp, shift) {
  7192. var change = shift / (wp.i - wm.i);
  7193. wp.c -= change;
  7194. wp.s += shift;
  7195. wm.c += change;
  7196. wp.z += shift;
  7197. wp.m += shift;
  7198. }
  7199. function d3_layout_treeShift(v) {
  7200. var shift = 0, change = 0, children = v.children, i = children.length, w;
  7201. while (--i >= 0) {
  7202. w = children[i];
  7203. w.z += shift;
  7204. w.m += shift;
  7205. shift += w.s + (change += w.c);
  7206. }
  7207. }
  7208. function d3_layout_treeAncestor(vim, v, ancestor) {
  7209. return vim.a.parent === v.parent ? vim.a : ancestor;
  7210. }
  7211. d3.layout.cluster = function() {
  7212. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  7213. function cluster(d, i) {
  7214. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  7215. d3_layout_hierarchyVisitAfter(root, function(node) {
  7216. var children = node.children;
  7217. if (children && children.length) {
  7218. node.x = d3_layout_clusterX(children);
  7219. node.y = d3_layout_clusterY(children);
  7220. } else {
  7221. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7222. node.y = 0;
  7223. previousNode = node;
  7224. }
  7225. });
  7226. 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;
  7227. d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
  7228. node.x = (node.x - root.x) * size[0];
  7229. node.y = (root.y - node.y) * size[1];
  7230. } : function(node) {
  7231. node.x = (node.x - x0) / (x1 - x0) * size[0];
  7232. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  7233. });
  7234. return nodes;
  7235. }
  7236. cluster.separation = function(x) {
  7237. if (!arguments.length) return separation;
  7238. separation = x;
  7239. return cluster;
  7240. };
  7241. cluster.size = function(x) {
  7242. if (!arguments.length) return nodeSize ? null : size;
  7243. nodeSize = (size = x) == null;
  7244. return cluster;
  7245. };
  7246. cluster.nodeSize = function(x) {
  7247. if (!arguments.length) return nodeSize ? size : null;
  7248. nodeSize = (size = x) != null;
  7249. return cluster;
  7250. };
  7251. return d3_layout_hierarchyRebind(cluster, hierarchy);
  7252. };
  7253. function d3_layout_clusterY(children) {
  7254. return 1 + d3.max(children, function(child) {
  7255. return child.y;
  7256. });
  7257. }
  7258. function d3_layout_clusterX(children) {
  7259. return children.reduce(function(x, child) {
  7260. return x + child.x;
  7261. }, 0) / children.length;
  7262. }
  7263. function d3_layout_clusterLeft(node) {
  7264. var children = node.children;
  7265. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  7266. }
  7267. function d3_layout_clusterRight(node) {
  7268. var children = node.children, n;
  7269. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  7270. }
  7271. d3.layout.treemap = function() {
  7272. 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));
  7273. function scale(children, k) {
  7274. var i = -1, n = children.length, child, area;
  7275. while (++i < n) {
  7276. area = (child = children[i]).value * (k < 0 ? 0 : k);
  7277. child.area = isNaN(area) || area <= 0 ? 0 : area;
  7278. }
  7279. }
  7280. function squarify(node) {
  7281. var children = node.children;
  7282. if (children && children.length) {
  7283. 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;
  7284. scale(remaining, rect.dx * rect.dy / node.value);
  7285. row.area = 0;
  7286. while ((n = remaining.length) > 0) {
  7287. row.push(child = remaining[n - 1]);
  7288. row.area += child.area;
  7289. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  7290. remaining.pop();
  7291. best = score;
  7292. } else {
  7293. row.area -= row.pop().area;
  7294. position(row, u, rect, false);
  7295. u = Math.min(rect.dx, rect.dy);
  7296. row.length = row.area = 0;
  7297. best = Infinity;
  7298. }
  7299. }
  7300. if (row.length) {
  7301. position(row, u, rect, true);
  7302. row.length = row.area = 0;
  7303. }
  7304. children.forEach(squarify);
  7305. }
  7306. }
  7307. function stickify(node) {
  7308. var children = node.children;
  7309. if (children && children.length) {
  7310. var rect = pad(node), remaining = children.slice(), child, row = [];
  7311. scale(remaining, rect.dx * rect.dy / node.value);
  7312. row.area = 0;
  7313. while (child = remaining.pop()) {
  7314. row.push(child);
  7315. row.area += child.area;
  7316. if (child.z != null) {
  7317. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  7318. row.length = row.area = 0;
  7319. }
  7320. }
  7321. children.forEach(stickify);
  7322. }
  7323. }
  7324. function worst(row, u) {
  7325. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  7326. while (++i < n) {
  7327. if (!(r = row[i].area)) continue;
  7328. if (r < rmin) rmin = r;
  7329. if (r > rmax) rmax = r;
  7330. }
  7331. s *= s;
  7332. u *= u;
  7333. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  7334. }
  7335. function position(row, u, rect, flush) {
  7336. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  7337. if (u == rect.dx) {
  7338. if (flush || v > rect.dy) v = rect.dy;
  7339. while (++i < n) {
  7340. o = row[i];
  7341. o.x = x;
  7342. o.y = y;
  7343. o.dy = v;
  7344. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  7345. }
  7346. o.z = true;
  7347. o.dx += rect.x + rect.dx - x;
  7348. rect.y += v;
  7349. rect.dy -= v;
  7350. } else {
  7351. if (flush || v > rect.dx) v = rect.dx;
  7352. while (++i < n) {
  7353. o = row[i];
  7354. o.x = x;
  7355. o.y = y;
  7356. o.dx = v;
  7357. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  7358. }
  7359. o.z = false;
  7360. o.dy += rect.y + rect.dy - y;
  7361. rect.x += v;
  7362. rect.dx -= v;
  7363. }
  7364. }
  7365. function treemap(d) {
  7366. var nodes = stickies || hierarchy(d), root = nodes[0];
  7367. root.x = root.y = 0;
  7368. if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
  7369. if (stickies) hierarchy.revalue(root);
  7370. scale([ root ], root.dx * root.dy / root.value);
  7371. (stickies ? stickify : squarify)(root);
  7372. if (sticky) stickies = nodes;
  7373. return nodes;
  7374. }
  7375. treemap.size = function(x) {
  7376. if (!arguments.length) return size;
  7377. size = x;
  7378. return treemap;
  7379. };
  7380. treemap.padding = function(x) {
  7381. if (!arguments.length) return padding;
  7382. function padFunction(node) {
  7383. var p = x.call(treemap, node, node.depth);
  7384. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  7385. }
  7386. function padConstant(node) {
  7387. return d3_layout_treemapPad(node, x);
  7388. }
  7389. var type;
  7390. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  7391. padConstant) : padConstant;
  7392. return treemap;
  7393. };
  7394. treemap.round = function(x) {
  7395. if (!arguments.length) return round != Number;
  7396. round = x ? Math.round : Number;
  7397. return treemap;
  7398. };
  7399. treemap.sticky = function(x) {
  7400. if (!arguments.length) return sticky;
  7401. sticky = x;
  7402. stickies = null;
  7403. return treemap;
  7404. };
  7405. treemap.ratio = function(x) {
  7406. if (!arguments.length) return ratio;
  7407. ratio = x;
  7408. return treemap;
  7409. };
  7410. treemap.mode = function(x) {
  7411. if (!arguments.length) return mode;
  7412. mode = x + "";
  7413. return treemap;
  7414. };
  7415. return d3_layout_hierarchyRebind(treemap, hierarchy);
  7416. };
  7417. function d3_layout_treemapPadNull(node) {
  7418. return {
  7419. x: node.x,
  7420. y: node.y,
  7421. dx: node.dx,
  7422. dy: node.dy
  7423. };
  7424. }
  7425. function d3_layout_treemapPad(node, padding) {
  7426. 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];
  7427. if (dx < 0) {
  7428. x += dx / 2;
  7429. dx = 0;
  7430. }
  7431. if (dy < 0) {
  7432. y += dy / 2;
  7433. dy = 0;
  7434. }
  7435. return {
  7436. x: x,
  7437. y: y,
  7438. dx: dx,
  7439. dy: dy
  7440. };
  7441. }
  7442. d3.random = {
  7443. normal: function(µ, σ) {
  7444. var n = arguments.length;
  7445. if (n < 2) σ = 1;
  7446. if (n < 1) µ = 0;
  7447. return function() {
  7448. var x, y, r;
  7449. do {
  7450. x = Math.random() * 2 - 1;
  7451. y = Math.random() * 2 - 1;
  7452. r = x * x + y * y;
  7453. } while (!r || r > 1);
  7454. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  7455. };
  7456. },
  7457. logNormal: function() {
  7458. var random = d3.random.normal.apply(d3, arguments);
  7459. return function() {
  7460. return Math.exp(random());
  7461. };
  7462. },
  7463. bates: function(m) {
  7464. var random = d3.random.irwinHall(m);
  7465. return function() {
  7466. return random() / m;
  7467. };
  7468. },
  7469. irwinHall: function(m) {
  7470. return function() {
  7471. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  7472. return s;
  7473. };
  7474. }
  7475. };
  7476. d3.scale = {};
  7477. function d3_scaleExtent(domain) {
  7478. var start = domain[0], stop = domain[domain.length - 1];
  7479. return start < stop ? [ start, stop ] : [ stop, start ];
  7480. }
  7481. function d3_scaleRange(scale) {
  7482. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  7483. }
  7484. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  7485. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  7486. return function(x) {
  7487. return i(u(x));
  7488. };
  7489. }
  7490. function d3_scale_nice(domain, nice) {
  7491. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  7492. if (x1 < x0) {
  7493. dx = i0, i0 = i1, i1 = dx;
  7494. dx = x0, x0 = x1, x1 = dx;
  7495. }
  7496. domain[i0] = nice.floor(x0);
  7497. domain[i1] = nice.ceil(x1);
  7498. return domain;
  7499. }
  7500. function d3_scale_niceStep(step) {
  7501. return step ? {
  7502. floor: function(x) {
  7503. return Math.floor(x / step) * step;
  7504. },
  7505. ceil: function(x) {
  7506. return Math.ceil(x / step) * step;
  7507. }
  7508. } : d3_scale_niceIdentity;
  7509. }
  7510. var d3_scale_niceIdentity = {
  7511. floor: d3_identity,
  7512. ceil: d3_identity
  7513. };
  7514. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  7515. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  7516. if (domain[k] < domain[0]) {
  7517. domain = domain.slice().reverse();
  7518. range = range.slice().reverse();
  7519. }
  7520. while (++j <= k) {
  7521. u.push(uninterpolate(domain[j - 1], domain[j]));
  7522. i.push(interpolate(range[j - 1], range[j]));
  7523. }
  7524. return function(x) {
  7525. var j = d3.bisect(domain, x, 1, k) - 1;
  7526. return i[j](u[j](x));
  7527. };
  7528. }
  7529. d3.scale.linear = function() {
  7530. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  7531. };
  7532. function d3_scale_linear(domain, range, interpolate, clamp) {
  7533. var output, input;
  7534. function rescale() {
  7535. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  7536. output = linear(domain, range, uninterpolate, interpolate);
  7537. input = linear(range, domain, uninterpolate, d3_interpolate);
  7538. return scale;
  7539. }
  7540. function scale(x) {
  7541. return output(x);
  7542. }
  7543. scale.invert = function(y) {
  7544. return input(y);
  7545. };
  7546. scale.domain = function(x) {
  7547. if (!arguments.length) return domain;
  7548. domain = x.map(Number);
  7549. return rescale();
  7550. };
  7551. scale.range = function(x) {
  7552. if (!arguments.length) return range;
  7553. range = x;
  7554. return rescale();
  7555. };
  7556. scale.rangeRound = function(x) {
  7557. return scale.range(x).interpolate(d3_interpolateRound);
  7558. };
  7559. scale.clamp = function(x) {
  7560. if (!arguments.length) return clamp;
  7561. clamp = x;
  7562. return rescale();
  7563. };
  7564. scale.interpolate = function(x) {
  7565. if (!arguments.length) return interpolate;
  7566. interpolate = x;
  7567. return rescale();
  7568. };
  7569. scale.ticks = function(m) {
  7570. return d3_scale_linearTicks(domain, m);
  7571. };
  7572. scale.tickFormat = function(m, format) {
  7573. return d3_scale_linearTickFormat(domain, m, format);
  7574. };
  7575. scale.nice = function(m) {
  7576. d3_scale_linearNice(domain, m);
  7577. return rescale();
  7578. };
  7579. scale.copy = function() {
  7580. return d3_scale_linear(domain, range, interpolate, clamp);
  7581. };
  7582. return rescale();
  7583. }
  7584. function d3_scale_linearRebind(scale, linear) {
  7585. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  7586. }
  7587. function d3_scale_linearNice(domain, m) {
  7588. d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  7589. d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  7590. return domain;
  7591. }
  7592. function d3_scale_linearTickRange(domain, m) {
  7593. if (m == null) m = 10;
  7594. 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;
  7595. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  7596. extent[0] = Math.ceil(extent[0] / step) * step;
  7597. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  7598. extent[2] = step;
  7599. return extent;
  7600. }
  7601. function d3_scale_linearTicks(domain, m) {
  7602. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  7603. }
  7604. function d3_scale_linearTickFormat(domain, m, format) {
  7605. var range = d3_scale_linearTickRange(domain, m);
  7606. if (format) {
  7607. var match = d3_format_re.exec(format);
  7608. match.shift();
  7609. if (match[8] === "s") {
  7610. var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
  7611. if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
  7612. match[8] = "f";
  7613. format = d3.format(match.join(""));
  7614. return function(d) {
  7615. return format(prefix.scale(d)) + prefix.symbol;
  7616. };
  7617. }
  7618. if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
  7619. format = match.join("");
  7620. } else {
  7621. format = ",." + d3_scale_linearPrecision(range[2]) + "f";
  7622. }
  7623. return d3.format(format);
  7624. }
  7625. var d3_scale_linearFormatSignificant = {
  7626. s: 1,
  7627. g: 1,
  7628. p: 1,
  7629. r: 1,
  7630. e: 1
  7631. };
  7632. function d3_scale_linearPrecision(value) {
  7633. return -Math.floor(Math.log(value) / Math.LN10 + .01);
  7634. }
  7635. function d3_scale_linearFormatPrecision(type, range) {
  7636. var p = d3_scale_linearPrecision(range[2]);
  7637. return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
  7638. }
  7639. d3.scale.log = function() {
  7640. return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
  7641. };
  7642. function d3_scale_log(linear, base, positive, domain) {
  7643. function log(x) {
  7644. return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
  7645. }
  7646. function pow(x) {
  7647. return positive ? Math.pow(base, x) : -Math.pow(base, -x);
  7648. }
  7649. function scale(x) {
  7650. return linear(log(x));
  7651. }
  7652. scale.invert = function(x) {
  7653. return pow(linear.invert(x));
  7654. };
  7655. scale.domain = function(x) {
  7656. if (!arguments.length) return domain;
  7657. positive = x[0] >= 0;
  7658. linear.domain((domain = x.map(Number)).map(log));
  7659. return scale;
  7660. };
  7661. scale.base = function(_) {
  7662. if (!arguments.length) return base;
  7663. base = +_;
  7664. linear.domain(domain.map(log));
  7665. return scale;
  7666. };
  7667. scale.nice = function() {
  7668. var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
  7669. linear.domain(niced);
  7670. domain = niced.map(pow);
  7671. return scale;
  7672. };
  7673. scale.ticks = function() {
  7674. var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
  7675. if (isFinite(j - i)) {
  7676. if (positive) {
  7677. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
  7678. ticks.push(pow(i));
  7679. } else {
  7680. ticks.push(pow(i));
  7681. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
  7682. }
  7683. for (i = 0; ticks[i] < u; i++) {}
  7684. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  7685. ticks = ticks.slice(i, j);
  7686. }
  7687. return ticks;
  7688. };
  7689. scale.tickFormat = function(n, format) {
  7690. if (!arguments.length) return d3_scale_logFormat;
  7691. if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
  7692. var k = Math.max(1, base * n / scale.ticks().length);
  7693. return function(d) {
  7694. var i = d / pow(Math.round(log(d)));
  7695. if (i * base < base - .5) i *= base;
  7696. return i <= k ? format(d) : "";
  7697. };
  7698. };
  7699. scale.copy = function() {
  7700. return d3_scale_log(linear.copy(), base, positive, domain);
  7701. };
  7702. return d3_scale_linearRebind(scale, linear);
  7703. }
  7704. var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
  7705. floor: function(x) {
  7706. return -Math.ceil(-x);
  7707. },
  7708. ceil: function(x) {
  7709. return -Math.floor(-x);
  7710. }
  7711. };
  7712. d3.scale.pow = function() {
  7713. return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
  7714. };
  7715. function d3_scale_pow(linear, exponent, domain) {
  7716. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  7717. function scale(x) {
  7718. return linear(powp(x));
  7719. }
  7720. scale.invert = function(x) {
  7721. return powb(linear.invert(x));
  7722. };
  7723. scale.domain = function(x) {
  7724. if (!arguments.length) return domain;
  7725. linear.domain((domain = x.map(Number)).map(powp));
  7726. return scale;
  7727. };
  7728. scale.ticks = function(m) {
  7729. return d3_scale_linearTicks(domain, m);
  7730. };
  7731. scale.tickFormat = function(m, format) {
  7732. return d3_scale_linearTickFormat(domain, m, format);
  7733. };
  7734. scale.nice = function(m) {
  7735. return scale.domain(d3_scale_linearNice(domain, m));
  7736. };
  7737. scale.exponent = function(x) {
  7738. if (!arguments.length) return exponent;
  7739. powp = d3_scale_powPow(exponent = x);
  7740. powb = d3_scale_powPow(1 / exponent);
  7741. linear.domain(domain.map(powp));
  7742. return scale;
  7743. };
  7744. scale.copy = function() {
  7745. return d3_scale_pow(linear.copy(), exponent, domain);
  7746. };
  7747. return d3_scale_linearRebind(scale, linear);
  7748. }
  7749. function d3_scale_powPow(e) {
  7750. return function(x) {
  7751. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  7752. };
  7753. }
  7754. d3.scale.sqrt = function() {
  7755. return d3.scale.pow().exponent(.5);
  7756. };
  7757. d3.scale.ordinal = function() {
  7758. return d3_scale_ordinal([], {
  7759. t: "range",
  7760. a: [ [] ]
  7761. });
  7762. };
  7763. function d3_scale_ordinal(domain, ranger) {
  7764. var index, range, rangeBand;
  7765. function scale(x) {
  7766. return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
  7767. }
  7768. function steps(start, step) {
  7769. return d3.range(domain.length).map(function(i) {
  7770. return start + step * i;
  7771. });
  7772. }
  7773. scale.domain = function(x) {
  7774. if (!arguments.length) return domain;
  7775. domain = [];
  7776. index = new d3_Map();
  7777. var i = -1, n = x.length, xi;
  7778. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  7779. return scale[ranger.t].apply(scale, ranger.a);
  7780. };
  7781. scale.range = function(x) {
  7782. if (!arguments.length) return range;
  7783. range = x;
  7784. rangeBand = 0;
  7785. ranger = {
  7786. t: "range",
  7787. a: arguments
  7788. };
  7789. return scale;
  7790. };
  7791. scale.rangePoints = function(x, padding) {
  7792. if (arguments.length < 2) padding = 0;
  7793. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
  7794. 0) : (stop - start) / (domain.length - 1 + padding);
  7795. range = steps(start + step * padding / 2, step);
  7796. rangeBand = 0;
  7797. ranger = {
  7798. t: "rangePoints",
  7799. a: arguments
  7800. };
  7801. return scale;
  7802. };
  7803. scale.rangeRoundPoints = function(x, padding) {
  7804. if (arguments.length < 2) padding = 0;
  7805. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
  7806. 0) : (stop - start) / (domain.length - 1 + padding) | 0;
  7807. range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
  7808. rangeBand = 0;
  7809. ranger = {
  7810. t: "rangeRoundPoints",
  7811. a: arguments
  7812. };
  7813. return scale;
  7814. };
  7815. scale.rangeBands = function(x, padding, outerPadding) {
  7816. if (arguments.length < 2) padding = 0;
  7817. if (arguments.length < 3) outerPadding = padding;
  7818. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  7819. range = steps(start + step * outerPadding, step);
  7820. if (reverse) range.reverse();
  7821. rangeBand = step * (1 - padding);
  7822. ranger = {
  7823. t: "rangeBands",
  7824. a: arguments
  7825. };
  7826. return scale;
  7827. };
  7828. scale.rangeRoundBands = function(x, padding, outerPadding) {
  7829. if (arguments.length < 2) padding = 0;
  7830. if (arguments.length < 3) outerPadding = padding;
  7831. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
  7832. range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
  7833. if (reverse) range.reverse();
  7834. rangeBand = Math.round(step * (1 - padding));
  7835. ranger = {
  7836. t: "rangeRoundBands",
  7837. a: arguments
  7838. };
  7839. return scale;
  7840. };
  7841. scale.rangeBand = function() {
  7842. return rangeBand;
  7843. };
  7844. scale.rangeExtent = function() {
  7845. return d3_scaleExtent(ranger.a[0]);
  7846. };
  7847. scale.copy = function() {
  7848. return d3_scale_ordinal(domain, ranger);
  7849. };
  7850. return scale.domain(domain);
  7851. }
  7852. d3.scale.category10 = function() {
  7853. return d3.scale.ordinal().range(d3_category10);
  7854. };
  7855. d3.scale.category20 = function() {
  7856. return d3.scale.ordinal().range(d3_category20);
  7857. };
  7858. d3.scale.category20b = function() {
  7859. return d3.scale.ordinal().range(d3_category20b);
  7860. };
  7861. d3.scale.category20c = function() {
  7862. return d3.scale.ordinal().range(d3_category20c);
  7863. };
  7864. var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
  7865. var d3_category20 = [ 2062260, 11454440, 16744206, 16759672, 2924588, 10018698, 14034728, 16750742, 9725885, 12955861, 9197131, 12885140, 14907330, 16234194, 8355711, 13092807, 12369186, 14408589, 1556175, 10410725 ].map(d3_rgbString);
  7866. var d3_category20b = [ 3750777, 5395619, 7040719, 10264286, 6519097, 9216594, 11915115, 13556636, 9202993, 12426809, 15186514, 15190932, 8666169, 11356490, 14049643, 15177372, 8077683, 10834324, 13528509, 14589654 ].map(d3_rgbString);
  7867. var d3_category20c = [ 3244733, 7057110, 10406625, 13032431, 15095053, 16616764, 16625259, 16634018, 3253076, 7652470, 10607003, 13101504, 7695281, 10394312, 12369372, 14342891, 6513507, 9868950, 12434877, 14277081 ].map(d3_rgbString);
  7868. d3.scale.quantile = function() {
  7869. return d3_scale_quantile([], []);
  7870. };
  7871. function d3_scale_quantile(domain, range) {
  7872. var thresholds;
  7873. function rescale() {
  7874. var k = 0, q = range.length;
  7875. thresholds = [];
  7876. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  7877. return scale;
  7878. }
  7879. function scale(x) {
  7880. if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
  7881. }
  7882. scale.domain = function(x) {
  7883. if (!arguments.length) return domain;
  7884. domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
  7885. return rescale();
  7886. };
  7887. scale.range = function(x) {
  7888. if (!arguments.length) return range;
  7889. range = x;
  7890. return rescale();
  7891. };
  7892. scale.quantiles = function() {
  7893. return thresholds;
  7894. };
  7895. scale.invertExtent = function(y) {
  7896. y = range.indexOf(y);
  7897. return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
  7898. };
  7899. scale.copy = function() {
  7900. return d3_scale_quantile(domain, range);
  7901. };
  7902. return rescale();
  7903. }
  7904. d3.scale.quantize = function() {
  7905. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  7906. };
  7907. function d3_scale_quantize(x0, x1, range) {
  7908. var kx, i;
  7909. function scale(x) {
  7910. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  7911. }
  7912. function rescale() {
  7913. kx = range.length / (x1 - x0);
  7914. i = range.length - 1;
  7915. return scale;
  7916. }
  7917. scale.domain = function(x) {
  7918. if (!arguments.length) return [ x0, x1 ];
  7919. x0 = +x[0];
  7920. x1 = +x[x.length - 1];
  7921. return rescale();
  7922. };
  7923. scale.range = function(x) {
  7924. if (!arguments.length) return range;
  7925. range = x;
  7926. return rescale();
  7927. };
  7928. scale.invertExtent = function(y) {
  7929. y = range.indexOf(y);
  7930. y = y < 0 ? NaN : y / kx + x0;
  7931. return [ y, y + 1 / kx ];
  7932. };
  7933. scale.copy = function() {
  7934. return d3_scale_quantize(x0, x1, range);
  7935. };
  7936. return rescale();
  7937. }
  7938. d3.scale.threshold = function() {
  7939. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  7940. };
  7941. function d3_scale_threshold(domain, range) {
  7942. function scale(x) {
  7943. if (x <= x) return range[d3.bisect(domain, x)];
  7944. }
  7945. scale.domain = function(_) {
  7946. if (!arguments.length) return domain;
  7947. domain = _;
  7948. return scale;
  7949. };
  7950. scale.range = function(_) {
  7951. if (!arguments.length) return range;
  7952. range = _;
  7953. return scale;
  7954. };
  7955. scale.invertExtent = function(y) {
  7956. y = range.indexOf(y);
  7957. return [ domain[y - 1], domain[y] ];
  7958. };
  7959. scale.copy = function() {
  7960. return d3_scale_threshold(domain, range);
  7961. };
  7962. return scale;
  7963. }
  7964. d3.scale.identity = function() {
  7965. return d3_scale_identity([ 0, 1 ]);
  7966. };
  7967. function d3_scale_identity(domain) {
  7968. function identity(x) {
  7969. return +x;
  7970. }
  7971. identity.invert = identity;
  7972. identity.domain = identity.range = function(x) {
  7973. if (!arguments.length) return domain;
  7974. domain = x.map(identity);
  7975. return identity;
  7976. };
  7977. identity.ticks = function(m) {
  7978. return d3_scale_linearTicks(domain, m);
  7979. };
  7980. identity.tickFormat = function(m, format) {
  7981. return d3_scale_linearTickFormat(domain, m, format);
  7982. };
  7983. identity.copy = function() {
  7984. return d3_scale_identity(domain);
  7985. };
  7986. return identity;
  7987. }
  7988. d3.svg = {};
  7989. function d3_zero() {
  7990. return 0;
  7991. }
  7992. d3.svg.arc = function() {
  7993. var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
  7994. function arc() {
  7995. var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
  7996. if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
  7997. if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
  7998. var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
  7999. if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
  8000. rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
  8001. if (!cw) p1 *= -1;
  8002. if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
  8003. if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
  8004. }
  8005. if (r1) {
  8006. x0 = r1 * Math.cos(a0 + p1);
  8007. y0 = r1 * Math.sin(a0 + p1);
  8008. x1 = r1 * Math.cos(a1 - p1);
  8009. y1 = r1 * Math.sin(a1 - p1);
  8010. var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
  8011. if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
  8012. var h1 = (a0 + a1) / 2;
  8013. x0 = r1 * Math.cos(h1);
  8014. y0 = r1 * Math.sin(h1);
  8015. x1 = y1 = null;
  8016. }
  8017. } else {
  8018. x0 = y0 = 0;
  8019. }
  8020. if (r0) {
  8021. x2 = r0 * Math.cos(a1 - p0);
  8022. y2 = r0 * Math.sin(a1 - p0);
  8023. x3 = r0 * Math.cos(a0 + p0);
  8024. y3 = r0 * Math.sin(a0 + p0);
  8025. var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
  8026. if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
  8027. var h0 = (a0 + a1) / 2;
  8028. x2 = r0 * Math.cos(h0);
  8029. y2 = r0 * Math.sin(h0);
  8030. x3 = y3 = null;
  8031. }
  8032. } else {
  8033. x2 = y2 = 0;
  8034. }
  8035. if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
  8036. cr = r0 < r1 ^ cw ? 0 : 1;
  8037. var rc1 = rc, rc0 = rc;
  8038. if (da < π) {
  8039. var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  8040. rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
  8041. rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
  8042. }
  8043. if (x1 != null) {
  8044. var t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
  8045. if (rc === rc1) {
  8046. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
  8047. } else {
  8048. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
  8049. }
  8050. } else {
  8051. path.push("M", x0, ",", y0);
  8052. }
  8053. if (x3 != null) {
  8054. var t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
  8055. if (rc === rc0) {
  8056. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  8057. } else {
  8058. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  8059. }
  8060. } else {
  8061. path.push("L", x2, ",", y2);
  8062. }
  8063. } else {
  8064. path.push("M", x0, ",", y0);
  8065. if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
  8066. path.push("L", x2, ",", y2);
  8067. if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
  8068. }
  8069. path.push("Z");
  8070. return path.join("");
  8071. }
  8072. function circleSegment(r1, cw) {
  8073. return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
  8074. }
  8075. arc.innerRadius = function(v) {
  8076. if (!arguments.length) return innerRadius;
  8077. innerRadius = d3_functor(v);
  8078. return arc;
  8079. };
  8080. arc.outerRadius = function(v) {
  8081. if (!arguments.length) return outerRadius;
  8082. outerRadius = d3_functor(v);
  8083. return arc;
  8084. };
  8085. arc.cornerRadius = function(v) {
  8086. if (!arguments.length) return cornerRadius;
  8087. cornerRadius = d3_functor(v);
  8088. return arc;
  8089. };
  8090. arc.padRadius = function(v) {
  8091. if (!arguments.length) return padRadius;
  8092. padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
  8093. return arc;
  8094. };
  8095. arc.startAngle = function(v) {
  8096. if (!arguments.length) return startAngle;
  8097. startAngle = d3_functor(v);
  8098. return arc;
  8099. };
  8100. arc.endAngle = function(v) {
  8101. if (!arguments.length) return endAngle;
  8102. endAngle = d3_functor(v);
  8103. return arc;
  8104. };
  8105. arc.padAngle = function(v) {
  8106. if (!arguments.length) return padAngle;
  8107. padAngle = d3_functor(v);
  8108. return arc;
  8109. };
  8110. arc.centroid = function() {
  8111. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
  8112. return [ Math.cos(a) * r, Math.sin(a) * r ];
  8113. };
  8114. return arc;
  8115. };
  8116. var d3_svg_arcAuto = "auto";
  8117. function d3_svg_arcInnerRadius(d) {
  8118. return d.innerRadius;
  8119. }
  8120. function d3_svg_arcOuterRadius(d) {
  8121. return d.outerRadius;
  8122. }
  8123. function d3_svg_arcStartAngle(d) {
  8124. return d.startAngle;
  8125. }
  8126. function d3_svg_arcEndAngle(d) {
  8127. return d.endAngle;
  8128. }
  8129. function d3_svg_arcPadAngle(d) {
  8130. return d && d.padAngle;
  8131. }
  8132. function d3_svg_arcSweep(x0, y0, x1, y1) {
  8133. return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
  8134. }
  8135. function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
  8136. var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
  8137. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  8138. return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
  8139. }
  8140. function d3_svg_line(projection) {
  8141. var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  8142. function line(data) {
  8143. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  8144. function segment() {
  8145. segments.push("M", interpolate(projection(points), tension));
  8146. }
  8147. while (++i < n) {
  8148. if (defined.call(this, d = data[i], i)) {
  8149. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  8150. } else if (points.length) {
  8151. segment();
  8152. points = [];
  8153. }
  8154. }
  8155. if (points.length) segment();
  8156. return segments.length ? segments.join("") : null;
  8157. }
  8158. line.x = function(_) {
  8159. if (!arguments.length) return x;
  8160. x = _;
  8161. return line;
  8162. };
  8163. line.y = function(_) {
  8164. if (!arguments.length) return y;
  8165. y = _;
  8166. return line;
  8167. };
  8168. line.defined = function(_) {
  8169. if (!arguments.length) return defined;
  8170. defined = _;
  8171. return line;
  8172. };
  8173. line.interpolate = function(_) {
  8174. if (!arguments.length) return interpolateKey;
  8175. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8176. return line;
  8177. };
  8178. line.tension = function(_) {
  8179. if (!arguments.length) return tension;
  8180. tension = _;
  8181. return line;
  8182. };
  8183. return line;
  8184. }
  8185. d3.svg.line = function() {
  8186. return d3_svg_line(d3_identity);
  8187. };
  8188. var d3_svg_lineInterpolators = d3.map({
  8189. linear: d3_svg_lineLinear,
  8190. "linear-closed": d3_svg_lineLinearClosed,
  8191. step: d3_svg_lineStep,
  8192. "step-before": d3_svg_lineStepBefore,
  8193. "step-after": d3_svg_lineStepAfter,
  8194. basis: d3_svg_lineBasis,
  8195. "basis-open": d3_svg_lineBasisOpen,
  8196. "basis-closed": d3_svg_lineBasisClosed,
  8197. bundle: d3_svg_lineBundle,
  8198. cardinal: d3_svg_lineCardinal,
  8199. "cardinal-open": d3_svg_lineCardinalOpen,
  8200. "cardinal-closed": d3_svg_lineCardinalClosed,
  8201. monotone: d3_svg_lineMonotone
  8202. });
  8203. d3_svg_lineInterpolators.forEach(function(key, value) {
  8204. value.key = key;
  8205. value.closed = /-closed$/.test(key);
  8206. });
  8207. function d3_svg_lineLinear(points) {
  8208. return points.length > 1 ? points.join("L") : points + "Z";
  8209. }
  8210. function d3_svg_lineLinearClosed(points) {
  8211. return points.join("L") + "Z";
  8212. }
  8213. function d3_svg_lineStep(points) {
  8214. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8215. while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
  8216. if (n > 1) path.push("H", p[0]);
  8217. return path.join("");
  8218. }
  8219. function d3_svg_lineStepBefore(points) {
  8220. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8221. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  8222. return path.join("");
  8223. }
  8224. function d3_svg_lineStepAfter(points) {
  8225. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8226. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  8227. return path.join("");
  8228. }
  8229. function d3_svg_lineCardinalOpen(points, tension) {
  8230. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
  8231. }
  8232. function d3_svg_lineCardinalClosed(points, tension) {
  8233. return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  8234. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  8235. }
  8236. function d3_svg_lineCardinal(points, tension) {
  8237. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  8238. }
  8239. function d3_svg_lineHermite(points, tangents) {
  8240. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  8241. return d3_svg_lineLinear(points);
  8242. }
  8243. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  8244. if (quad) {
  8245. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  8246. p0 = points[1];
  8247. pi = 2;
  8248. }
  8249. if (tangents.length > 1) {
  8250. t = tangents[1];
  8251. p = points[pi];
  8252. pi++;
  8253. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8254. for (var i = 2; i < tangents.length; i++, pi++) {
  8255. p = points[pi];
  8256. t = tangents[i];
  8257. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8258. }
  8259. }
  8260. if (quad) {
  8261. var lp = points[pi];
  8262. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  8263. }
  8264. return path;
  8265. }
  8266. function d3_svg_lineCardinalTangents(points, tension) {
  8267. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  8268. while (++i < n) {
  8269. p0 = p1;
  8270. p1 = p2;
  8271. p2 = points[i];
  8272. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  8273. }
  8274. return tangents;
  8275. }
  8276. function d3_svg_lineBasis(points) {
  8277. if (points.length < 3) return d3_svg_lineLinear(points);
  8278. var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8279. points.push(points[n - 1]);
  8280. while (++i <= n) {
  8281. pi = points[i];
  8282. px.shift();
  8283. px.push(pi[0]);
  8284. py.shift();
  8285. py.push(pi[1]);
  8286. d3_svg_lineBasisBezier(path, px, py);
  8287. }
  8288. points.pop();
  8289. path.push("L", pi);
  8290. return path.join("");
  8291. }
  8292. function d3_svg_lineBasisOpen(points) {
  8293. if (points.length < 4) return d3_svg_lineLinear(points);
  8294. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  8295. while (++i < 3) {
  8296. pi = points[i];
  8297. px.push(pi[0]);
  8298. py.push(pi[1]);
  8299. }
  8300. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  8301. --i;
  8302. while (++i < n) {
  8303. pi = points[i];
  8304. px.shift();
  8305. px.push(pi[0]);
  8306. py.shift();
  8307. py.push(pi[1]);
  8308. d3_svg_lineBasisBezier(path, px, py);
  8309. }
  8310. return path.join("");
  8311. }
  8312. function d3_svg_lineBasisClosed(points) {
  8313. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  8314. while (++i < 4) {
  8315. pi = points[i % n];
  8316. px.push(pi[0]);
  8317. py.push(pi[1]);
  8318. }
  8319. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8320. --i;
  8321. while (++i < m) {
  8322. pi = points[i % n];
  8323. px.shift();
  8324. px.push(pi[0]);
  8325. py.shift();
  8326. py.push(pi[1]);
  8327. d3_svg_lineBasisBezier(path, px, py);
  8328. }
  8329. return path.join("");
  8330. }
  8331. function d3_svg_lineBundle(points, tension) {
  8332. var n = points.length - 1;
  8333. if (n) {
  8334. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  8335. while (++i <= n) {
  8336. p = points[i];
  8337. t = i / n;
  8338. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  8339. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  8340. }
  8341. }
  8342. return d3_svg_lineBasis(points);
  8343. }
  8344. function d3_svg_lineDot4(a, b) {
  8345. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  8346. }
  8347. 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 ];
  8348. function d3_svg_lineBasisBezier(path, x, y) {
  8349. 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));
  8350. }
  8351. function d3_svg_lineSlope(p0, p1) {
  8352. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  8353. }
  8354. function d3_svg_lineFiniteDifferences(points) {
  8355. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  8356. while (++i < j) {
  8357. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  8358. }
  8359. m[i] = d;
  8360. return m;
  8361. }
  8362. function d3_svg_lineMonotoneTangents(points) {
  8363. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  8364. while (++i < j) {
  8365. d = d3_svg_lineSlope(points[i], points[i + 1]);
  8366. if (abs(d) < ε) {
  8367. m[i] = m[i + 1] = 0;
  8368. } else {
  8369. a = m[i] / d;
  8370. b = m[i + 1] / d;
  8371. s = a * a + b * b;
  8372. if (s > 9) {
  8373. s = d * 3 / Math.sqrt(s);
  8374. m[i] = s * a;
  8375. m[i + 1] = s * b;
  8376. }
  8377. }
  8378. }
  8379. i = -1;
  8380. while (++i <= j) {
  8381. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  8382. tangents.push([ s || 0, m[i] * s || 0 ]);
  8383. }
  8384. return tangents;
  8385. }
  8386. function d3_svg_lineMonotone(points) {
  8387. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  8388. }
  8389. d3.svg.line.radial = function() {
  8390. var line = d3_svg_line(d3_svg_lineRadial);
  8391. line.radius = line.x, delete line.x;
  8392. line.angle = line.y, delete line.y;
  8393. return line;
  8394. };
  8395. function d3_svg_lineRadial(points) {
  8396. var point, i = -1, n = points.length, r, a;
  8397. while (++i < n) {
  8398. point = points[i];
  8399. r = point[0];
  8400. a = point[1] - halfπ;
  8401. point[0] = r * Math.cos(a);
  8402. point[1] = r * Math.sin(a);
  8403. }
  8404. return points;
  8405. }
  8406. function d3_svg_area(projection) {
  8407. var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
  8408. function area(data) {
  8409. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  8410. return x;
  8411. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  8412. return y;
  8413. } : d3_functor(y1), x, y;
  8414. function segment() {
  8415. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  8416. }
  8417. while (++i < n) {
  8418. if (defined.call(this, d = data[i], i)) {
  8419. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  8420. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  8421. } else if (points0.length) {
  8422. segment();
  8423. points0 = [];
  8424. points1 = [];
  8425. }
  8426. }
  8427. if (points0.length) segment();
  8428. return segments.length ? segments.join("") : null;
  8429. }
  8430. area.x = function(_) {
  8431. if (!arguments.length) return x1;
  8432. x0 = x1 = _;
  8433. return area;
  8434. };
  8435. area.x0 = function(_) {
  8436. if (!arguments.length) return x0;
  8437. x0 = _;
  8438. return area;
  8439. };
  8440. area.x1 = function(_) {
  8441. if (!arguments.length) return x1;
  8442. x1 = _;
  8443. return area;
  8444. };
  8445. area.y = function(_) {
  8446. if (!arguments.length) return y1;
  8447. y0 = y1 = _;
  8448. return area;
  8449. };
  8450. area.y0 = function(_) {
  8451. if (!arguments.length) return y0;
  8452. y0 = _;
  8453. return area;
  8454. };
  8455. area.y1 = function(_) {
  8456. if (!arguments.length) return y1;
  8457. y1 = _;
  8458. return area;
  8459. };
  8460. area.defined = function(_) {
  8461. if (!arguments.length) return defined;
  8462. defined = _;
  8463. return area;
  8464. };
  8465. area.interpolate = function(_) {
  8466. if (!arguments.length) return interpolateKey;
  8467. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8468. interpolateReverse = interpolate.reverse || interpolate;
  8469. L = interpolate.closed ? "M" : "L";
  8470. return area;
  8471. };
  8472. area.tension = function(_) {
  8473. if (!arguments.length) return tension;
  8474. tension = _;
  8475. return area;
  8476. };
  8477. return area;
  8478. }
  8479. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  8480. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  8481. d3.svg.area = function() {
  8482. return d3_svg_area(d3_identity);
  8483. };
  8484. d3.svg.area.radial = function() {
  8485. var area = d3_svg_area(d3_svg_lineRadial);
  8486. area.radius = area.x, delete area.x;
  8487. area.innerRadius = area.x0, delete area.x0;
  8488. area.outerRadius = area.x1, delete area.x1;
  8489. area.angle = area.y, delete area.y;
  8490. area.startAngle = area.y0, delete area.y0;
  8491. area.endAngle = area.y1, delete area.y1;
  8492. return area;
  8493. };
  8494. d3.svg.chord = function() {
  8495. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  8496. function chord(d, i) {
  8497. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  8498. 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";
  8499. }
  8500. function subgroup(self, f, d, i) {
  8501. var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
  8502. return {
  8503. r: r,
  8504. a0: a0,
  8505. a1: a1,
  8506. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  8507. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  8508. };
  8509. }
  8510. function equals(a, b) {
  8511. return a.a0 == b.a0 && a.a1 == b.a1;
  8512. }
  8513. function arc(r, p, a) {
  8514. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  8515. }
  8516. function curve(r0, p0, r1, p1) {
  8517. return "Q 0,0 " + p1;
  8518. }
  8519. chord.radius = function(v) {
  8520. if (!arguments.length) return radius;
  8521. radius = d3_functor(v);
  8522. return chord;
  8523. };
  8524. chord.source = function(v) {
  8525. if (!arguments.length) return source;
  8526. source = d3_functor(v);
  8527. return chord;
  8528. };
  8529. chord.target = function(v) {
  8530. if (!arguments.length) return target;
  8531. target = d3_functor(v);
  8532. return chord;
  8533. };
  8534. chord.startAngle = function(v) {
  8535. if (!arguments.length) return startAngle;
  8536. startAngle = d3_functor(v);
  8537. return chord;
  8538. };
  8539. chord.endAngle = function(v) {
  8540. if (!arguments.length) return endAngle;
  8541. endAngle = d3_functor(v);
  8542. return chord;
  8543. };
  8544. return chord;
  8545. };
  8546. function d3_svg_chordRadius(d) {
  8547. return d.radius;
  8548. }
  8549. d3.svg.diagonal = function() {
  8550. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  8551. function diagonal(d, i) {
  8552. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  8553. x: p0.x,
  8554. y: m
  8555. }, {
  8556. x: p3.x,
  8557. y: m
  8558. }, p3 ];
  8559. p = p.map(projection);
  8560. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  8561. }
  8562. diagonal.source = function(x) {
  8563. if (!arguments.length) return source;
  8564. source = d3_functor(x);
  8565. return diagonal;
  8566. };
  8567. diagonal.target = function(x) {
  8568. if (!arguments.length) return target;
  8569. target = d3_functor(x);
  8570. return diagonal;
  8571. };
  8572. diagonal.projection = function(x) {
  8573. if (!arguments.length) return projection;
  8574. projection = x;
  8575. return diagonal;
  8576. };
  8577. return diagonal;
  8578. };
  8579. function d3_svg_diagonalProjection(d) {
  8580. return [ d.x, d.y ];
  8581. }
  8582. d3.svg.diagonal.radial = function() {
  8583. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  8584. diagonal.projection = function(x) {
  8585. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  8586. };
  8587. return diagonal;
  8588. };
  8589. function d3_svg_diagonalRadialProjection(projection) {
  8590. return function() {
  8591. var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
  8592. return [ r * Math.cos(a), r * Math.sin(a) ];
  8593. };
  8594. }
  8595. d3.svg.symbol = function() {
  8596. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  8597. function symbol(d, i) {
  8598. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  8599. }
  8600. symbol.type = function(x) {
  8601. if (!arguments.length) return type;
  8602. type = d3_functor(x);
  8603. return symbol;
  8604. };
  8605. symbol.size = function(x) {
  8606. if (!arguments.length) return size;
  8607. size = d3_functor(x);
  8608. return symbol;
  8609. };
  8610. return symbol;
  8611. };
  8612. function d3_svg_symbolSize() {
  8613. return 64;
  8614. }
  8615. function d3_svg_symbolType() {
  8616. return "circle";
  8617. }
  8618. function d3_svg_symbolCircle(size) {
  8619. var r = Math.sqrt(size / π);
  8620. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  8621. }
  8622. var d3_svg_symbols = d3.map({
  8623. circle: d3_svg_symbolCircle,
  8624. cross: function(size) {
  8625. var r = Math.sqrt(size / 5) / 2;
  8626. 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";
  8627. },
  8628. diamond: function(size) {
  8629. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  8630. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  8631. },
  8632. square: function(size) {
  8633. var r = Math.sqrt(size) / 2;
  8634. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  8635. },
  8636. "triangle-down": function(size) {
  8637. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8638. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  8639. },
  8640. "triangle-up": function(size) {
  8641. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8642. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  8643. }
  8644. });
  8645. d3.svg.symbolTypes = d3_svg_symbols.keys();
  8646. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  8647. d3_selectionPrototype.transition = function(name) {
  8648. var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
  8649. time: Date.now(),
  8650. ease: d3_ease_cubicInOut,
  8651. delay: 0,
  8652. duration: 250
  8653. };
  8654. for (var j = -1, m = this.length; ++j < m; ) {
  8655. subgroups.push(subgroup = []);
  8656. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8657. if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
  8658. subgroup.push(node);
  8659. }
  8660. }
  8661. return d3_transition(subgroups, ns, id);
  8662. };
  8663. d3_selectionPrototype.interrupt = function(name) {
  8664. return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
  8665. };
  8666. var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
  8667. function d3_selection_interruptNS(ns) {
  8668. return function() {
  8669. var lock, activeId, active;
  8670. if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
  8671. active.timer.c = null;
  8672. active.timer.t = NaN;
  8673. if (--lock.count) delete lock[activeId]; else delete this[ns];
  8674. lock.active += .5;
  8675. active.event && active.event.interrupt.call(this, this.__data__, active.index);
  8676. }
  8677. };
  8678. }
  8679. function d3_transition(groups, ns, id) {
  8680. d3_subclass(groups, d3_transitionPrototype);
  8681. groups.namespace = ns;
  8682. groups.id = id;
  8683. return groups;
  8684. }
  8685. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
  8686. d3_transitionPrototype.call = d3_selectionPrototype.call;
  8687. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  8688. d3_transitionPrototype.node = d3_selectionPrototype.node;
  8689. d3_transitionPrototype.size = d3_selectionPrototype.size;
  8690. d3.transition = function(selection, name) {
  8691. return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
  8692. };
  8693. d3.transition.prototype = d3_transitionPrototype;
  8694. d3_transitionPrototype.select = function(selector) {
  8695. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
  8696. selector = d3_selection_selector(selector);
  8697. for (var j = -1, m = this.length; ++j < m; ) {
  8698. subgroups.push(subgroup = []);
  8699. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8700. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
  8701. if ("__data__" in node) subnode.__data__ = node.__data__;
  8702. d3_transitionNode(subnode, i, ns, id, node[ns][id]);
  8703. subgroup.push(subnode);
  8704. } else {
  8705. subgroup.push(null);
  8706. }
  8707. }
  8708. }
  8709. return d3_transition(subgroups, ns, id);
  8710. };
  8711. d3_transitionPrototype.selectAll = function(selector) {
  8712. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
  8713. selector = d3_selection_selectorAll(selector);
  8714. for (var j = -1, m = this.length; ++j < m; ) {
  8715. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8716. if (node = group[i]) {
  8717. transition = node[ns][id];
  8718. subnodes = selector.call(node, node.__data__, i, j);
  8719. subgroups.push(subgroup = []);
  8720. for (var k = -1, o = subnodes.length; ++k < o; ) {
  8721. if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
  8722. subgroup.push(subnode);
  8723. }
  8724. }
  8725. }
  8726. }
  8727. return d3_transition(subgroups, ns, id);
  8728. };
  8729. d3_transitionPrototype.filter = function(filter) {
  8730. var subgroups = [], subgroup, group, node;
  8731. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  8732. for (var j = 0, m = this.length; j < m; j++) {
  8733. subgroups.push(subgroup = []);
  8734. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8735. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  8736. subgroup.push(node);
  8737. }
  8738. }
  8739. }
  8740. return d3_transition(subgroups, this.namespace, this.id);
  8741. };
  8742. d3_transitionPrototype.tween = function(name, tween) {
  8743. var id = this.id, ns = this.namespace;
  8744. if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
  8745. return d3_selection_each(this, tween == null ? function(node) {
  8746. node[ns][id].tween.remove(name);
  8747. } : function(node) {
  8748. node[ns][id].tween.set(name, tween);
  8749. });
  8750. };
  8751. function d3_transition_tween(groups, name, value, tween) {
  8752. var id = groups.id, ns = groups.namespace;
  8753. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  8754. node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  8755. } : (value = tween(value), function(node) {
  8756. node[ns][id].tween.set(name, value);
  8757. }));
  8758. }
  8759. d3_transitionPrototype.attr = function(nameNS, value) {
  8760. if (arguments.length < 2) {
  8761. for (value in nameNS) this.attr(value, nameNS[value]);
  8762. return this;
  8763. }
  8764. var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
  8765. function attrNull() {
  8766. this.removeAttribute(name);
  8767. }
  8768. function attrNullNS() {
  8769. this.removeAttributeNS(name.space, name.local);
  8770. }
  8771. function attrTween(b) {
  8772. return b == null ? attrNull : (b += "", function() {
  8773. var a = this.getAttribute(name), i;
  8774. return a !== b && (i = interpolate(a, b), function(t) {
  8775. this.setAttribute(name, i(t));
  8776. });
  8777. });
  8778. }
  8779. function attrTweenNS(b) {
  8780. return b == null ? attrNullNS : (b += "", function() {
  8781. var a = this.getAttributeNS(name.space, name.local), i;
  8782. return a !== b && (i = interpolate(a, b), function(t) {
  8783. this.setAttributeNS(name.space, name.local, i(t));
  8784. });
  8785. });
  8786. }
  8787. return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
  8788. };
  8789. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  8790. var name = d3.ns.qualify(nameNS);
  8791. function attrTween(d, i) {
  8792. var f = tween.call(this, d, i, this.getAttribute(name));
  8793. return f && function(t) {
  8794. this.setAttribute(name, f(t));
  8795. };
  8796. }
  8797. function attrTweenNS(d, i) {
  8798. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  8799. return f && function(t) {
  8800. this.setAttributeNS(name.space, name.local, f(t));
  8801. };
  8802. }
  8803. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  8804. };
  8805. d3_transitionPrototype.style = function(name, value, priority) {
  8806. var n = arguments.length;
  8807. if (n < 3) {
  8808. if (typeof name !== "string") {
  8809. if (n < 2) value = "";
  8810. for (priority in name) this.style(priority, name[priority], value);
  8811. return this;
  8812. }
  8813. priority = "";
  8814. }
  8815. function styleNull() {
  8816. this.style.removeProperty(name);
  8817. }
  8818. function styleString(b) {
  8819. return b == null ? styleNull : (b += "", function() {
  8820. var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
  8821. return a !== b && (i = d3_interpolate(a, b), function(t) {
  8822. this.style.setProperty(name, i(t), priority);
  8823. });
  8824. });
  8825. }
  8826. return d3_transition_tween(this, "style." + name, value, styleString);
  8827. };
  8828. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  8829. if (arguments.length < 3) priority = "";
  8830. function styleTween(d, i) {
  8831. var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
  8832. return f && function(t) {
  8833. this.style.setProperty(name, f(t), priority);
  8834. };
  8835. }
  8836. return this.tween("style." + name, styleTween);
  8837. };
  8838. d3_transitionPrototype.text = function(value) {
  8839. return d3_transition_tween(this, "text", value, d3_transition_text);
  8840. };
  8841. function d3_transition_text(b) {
  8842. if (b == null) b = "";
  8843. return function() {
  8844. this.textContent = b;
  8845. };
  8846. }
  8847. d3_transitionPrototype.remove = function() {
  8848. var ns = this.namespace;
  8849. return this.each("end.transition", function() {
  8850. var p;
  8851. if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
  8852. });
  8853. };
  8854. d3_transitionPrototype.ease = function(value) {
  8855. var id = this.id, ns = this.namespace;
  8856. if (arguments.length < 1) return this.node()[ns][id].ease;
  8857. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  8858. return d3_selection_each(this, function(node) {
  8859. node[ns][id].ease = value;
  8860. });
  8861. };
  8862. d3_transitionPrototype.delay = function(value) {
  8863. var id = this.id, ns = this.namespace;
  8864. if (arguments.length < 1) return this.node()[ns][id].delay;
  8865. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8866. node[ns][id].delay = +value.call(node, node.__data__, i, j);
  8867. } : (value = +value, function(node) {
  8868. node[ns][id].delay = value;
  8869. }));
  8870. };
  8871. d3_transitionPrototype.duration = function(value) {
  8872. var id = this.id, ns = this.namespace;
  8873. if (arguments.length < 1) return this.node()[ns][id].duration;
  8874. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8875. node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
  8876. } : (value = Math.max(1, value), function(node) {
  8877. node[ns][id].duration = value;
  8878. }));
  8879. };
  8880. d3_transitionPrototype.each = function(type, listener) {
  8881. var id = this.id, ns = this.namespace;
  8882. if (arguments.length < 2) {
  8883. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  8884. try {
  8885. d3_transitionInheritId = id;
  8886. d3_selection_each(this, function(node, i, j) {
  8887. d3_transitionInherit = node[ns][id];
  8888. type.call(node, node.__data__, i, j);
  8889. });
  8890. } finally {
  8891. d3_transitionInherit = inherit;
  8892. d3_transitionInheritId = inheritId;
  8893. }
  8894. } else {
  8895. d3_selection_each(this, function(node) {
  8896. var transition = node[ns][id];
  8897. (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
  8898. });
  8899. }
  8900. return this;
  8901. };
  8902. d3_transitionPrototype.transition = function() {
  8903. var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
  8904. for (var j = 0, m = this.length; j < m; j++) {
  8905. subgroups.push(subgroup = []);
  8906. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8907. if (node = group[i]) {
  8908. transition = node[ns][id0];
  8909. d3_transitionNode(node, i, ns, id1, {
  8910. time: transition.time,
  8911. ease: transition.ease,
  8912. delay: transition.delay + transition.duration,
  8913. duration: transition.duration
  8914. });
  8915. }
  8916. subgroup.push(node);
  8917. }
  8918. }
  8919. return d3_transition(subgroups, ns, id1);
  8920. };
  8921. function d3_transitionNamespace(name) {
  8922. return name == null ? "__transition__" : "__transition_" + name + "__";
  8923. }
  8924. function d3_transitionNode(node, i, ns, id, inherit) {
  8925. var lock = node[ns] || (node[ns] = {
  8926. active: 0,
  8927. count: 0
  8928. }), transition = lock[id], time, timer, duration, ease, tweens;
  8929. function schedule(elapsed) {
  8930. var delay = transition.delay;
  8931. timer.t = delay + time;
  8932. if (delay <= elapsed) return start(elapsed - delay);
  8933. timer.c = start;
  8934. }
  8935. function start(elapsed) {
  8936. var activeId = lock.active, active = lock[activeId];
  8937. if (active) {
  8938. active.timer.c = null;
  8939. active.timer.t = NaN;
  8940. --lock.count;
  8941. delete lock[activeId];
  8942. active.event && active.event.interrupt.call(node, node.__data__, active.index);
  8943. }
  8944. for (var cancelId in lock) {
  8945. if (+cancelId < id) {
  8946. var cancel = lock[cancelId];
  8947. cancel.timer.c = null;
  8948. cancel.timer.t = NaN;
  8949. --lock.count;
  8950. delete lock[cancelId];
  8951. }
  8952. }
  8953. timer.c = tick;
  8954. d3_timer(function() {
  8955. if (timer.c && tick(elapsed || 1)) {
  8956. timer.c = null;
  8957. timer.t = NaN;
  8958. }
  8959. return 1;
  8960. }, 0, time);
  8961. lock.active = id;
  8962. transition.event && transition.event.start.call(node, node.__data__, i);
  8963. tweens = [];
  8964. transition.tween.forEach(function(key, value) {
  8965. if (value = value.call(node, node.__data__, i)) {
  8966. tweens.push(value);
  8967. }
  8968. });
  8969. ease = transition.ease;
  8970. duration = transition.duration;
  8971. }
  8972. function tick(elapsed) {
  8973. var t = elapsed / duration, e = ease(t), n = tweens.length;
  8974. while (n > 0) {
  8975. tweens[--n].call(node, e);
  8976. }
  8977. if (t >= 1) {
  8978. transition.event && transition.event.end.call(node, node.__data__, i);
  8979. if (--lock.count) delete lock[id]; else delete node[ns];
  8980. return 1;
  8981. }
  8982. }
  8983. if (!transition) {
  8984. time = inherit.time;
  8985. timer = d3_timer(schedule, 0, time);
  8986. transition = lock[id] = {
  8987. tween: new d3_Map(),
  8988. time: time,
  8989. timer: timer,
  8990. delay: inherit.delay,
  8991. duration: inherit.duration,
  8992. ease: inherit.ease,
  8993. index: i
  8994. };
  8995. inherit = null;
  8996. ++lock.count;
  8997. }
  8998. }
  8999. d3.svg.axis = function() {
  9000. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
  9001. function axis(g) {
  9002. g.each(function() {
  9003. var g = d3.select(this);
  9004. var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
  9005. var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
  9006. var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  9007. d3.transition(path));
  9008. tickEnter.append("line");
  9009. tickEnter.append("text");
  9010. var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
  9011. if (orient === "bottom" || orient === "top") {
  9012. tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
  9013. text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
  9014. pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
  9015. } else {
  9016. tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
  9017. text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
  9018. pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
  9019. }
  9020. lineEnter.attr(y2, sign * innerTickSize);
  9021. textEnter.attr(y1, sign * tickSpacing);
  9022. lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
  9023. textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
  9024. if (scale1.rangeBand) {
  9025. var x = scale1, dx = x.rangeBand() / 2;
  9026. scale0 = scale1 = function(d) {
  9027. return x(d) + dx;
  9028. };
  9029. } else if (scale0.rangeBand) {
  9030. scale0 = scale1;
  9031. } else {
  9032. tickExit.call(tickTransform, scale1, scale0);
  9033. }
  9034. tickEnter.call(tickTransform, scale0, scale1);
  9035. tickUpdate.call(tickTransform, scale1, scale1);
  9036. });
  9037. }
  9038. axis.scale = function(x) {
  9039. if (!arguments.length) return scale;
  9040. scale = x;
  9041. return axis;
  9042. };
  9043. axis.orient = function(x) {
  9044. if (!arguments.length) return orient;
  9045. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  9046. return axis;
  9047. };
  9048. axis.ticks = function() {
  9049. if (!arguments.length) return tickArguments_;
  9050. tickArguments_ = d3_array(arguments);
  9051. return axis;
  9052. };
  9053. axis.tickValues = function(x) {
  9054. if (!arguments.length) return tickValues;
  9055. tickValues = x;
  9056. return axis;
  9057. };
  9058. axis.tickFormat = function(x) {
  9059. if (!arguments.length) return tickFormat_;
  9060. tickFormat_ = x;
  9061. return axis;
  9062. };
  9063. axis.tickSize = function(x) {
  9064. var n = arguments.length;
  9065. if (!n) return innerTickSize;
  9066. innerTickSize = +x;
  9067. outerTickSize = +arguments[n - 1];
  9068. return axis;
  9069. };
  9070. axis.innerTickSize = function(x) {
  9071. if (!arguments.length) return innerTickSize;
  9072. innerTickSize = +x;
  9073. return axis;
  9074. };
  9075. axis.outerTickSize = function(x) {
  9076. if (!arguments.length) return outerTickSize;
  9077. outerTickSize = +x;
  9078. return axis;
  9079. };
  9080. axis.tickPadding = function(x) {
  9081. if (!arguments.length) return tickPadding;
  9082. tickPadding = +x;
  9083. return axis;
  9084. };
  9085. axis.tickSubdivide = function() {
  9086. return arguments.length && axis;
  9087. };
  9088. return axis;
  9089. };
  9090. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  9091. top: 1,
  9092. right: 1,
  9093. bottom: 1,
  9094. left: 1
  9095. };
  9096. function d3_svg_axisX(selection, x0, x1) {
  9097. selection.attr("transform", function(d) {
  9098. var v0 = x0(d);
  9099. return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
  9100. });
  9101. }
  9102. function d3_svg_axisY(selection, y0, y1) {
  9103. selection.attr("transform", function(d) {
  9104. var v0 = y0(d);
  9105. return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
  9106. });
  9107. }
  9108. d3.svg.brush = function() {
  9109. var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0];
  9110. function brush(g) {
  9111. g.each(function() {
  9112. var g = d3.select(this).style("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
  9113. var background = g.selectAll(".background").data([ 0 ]);
  9114. background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  9115. g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
  9116. var resize = g.selectAll(".resize").data(resizes, d3_identity);
  9117. resize.exit().remove();
  9118. resize.enter().append("g").attr("class", function(d) {
  9119. return "resize " + d;
  9120. }).style("cursor", function(d) {
  9121. return d3_svg_brushCursor[d];
  9122. }).append("rect").attr("x", function(d) {
  9123. return /[ew]$/.test(d) ? -3 : null;
  9124. }).attr("y", function(d) {
  9125. return /^[ns]/.test(d) ? -3 : null;
  9126. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  9127. resize.style("display", brush.empty() ? "none" : null);
  9128. var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
  9129. if (x) {
  9130. range = d3_scaleRange(x);
  9131. backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
  9132. redrawX(gUpdate);
  9133. }
  9134. if (y) {
  9135. range = d3_scaleRange(y);
  9136. backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
  9137. redrawY(gUpdate);
  9138. }
  9139. redraw(gUpdate);
  9140. });
  9141. }
  9142. brush.event = function(g) {
  9143. g.each(function() {
  9144. var event_ = event.of(this, arguments), extent1 = {
  9145. x: xExtent,
  9146. y: yExtent,
  9147. i: xExtentDomain,
  9148. j: yExtentDomain
  9149. }, extent0 = this.__chart__ || extent1;
  9150. this.__chart__ = extent1;
  9151. if (d3_transitionInheritId) {
  9152. d3.select(this).transition().each("start.brush", function() {
  9153. xExtentDomain = extent0.i;
  9154. yExtentDomain = extent0.j;
  9155. xExtent = extent0.x;
  9156. yExtent = extent0.y;
  9157. event_({
  9158. type: "brushstart"
  9159. });
  9160. }).tween("brush:brush", function() {
  9161. var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
  9162. xExtentDomain = yExtentDomain = null;
  9163. return function(t) {
  9164. xExtent = extent1.x = xi(t);
  9165. yExtent = extent1.y = yi(t);
  9166. event_({
  9167. type: "brush",
  9168. mode: "resize"
  9169. });
  9170. };
  9171. }).each("end.brush", function() {
  9172. xExtentDomain = extent1.i;
  9173. yExtentDomain = extent1.j;
  9174. event_({
  9175. type: "brush",
  9176. mode: "resize"
  9177. });
  9178. event_({
  9179. type: "brushend"
  9180. });
  9181. });
  9182. } else {
  9183. event_({
  9184. type: "brushstart"
  9185. });
  9186. event_({
  9187. type: "brush",
  9188. mode: "resize"
  9189. });
  9190. event_({
  9191. type: "brushend"
  9192. });
  9193. }
  9194. });
  9195. };
  9196. function redraw(g) {
  9197. g.selectAll(".resize").attr("transform", function(d) {
  9198. return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
  9199. });
  9200. }
  9201. function redrawX(g) {
  9202. g.select(".extent").attr("x", xExtent[0]);
  9203. g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
  9204. }
  9205. function redrawY(g) {
  9206. g.select(".extent").attr("y", yExtent[0]);
  9207. g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
  9208. }
  9209. function brushstart() {
  9210. var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;
  9211. var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
  9212. if (d3.event.changedTouches) {
  9213. w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
  9214. } else {
  9215. w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
  9216. }
  9217. g.interrupt().selectAll("*").interrupt();
  9218. if (dragging) {
  9219. origin[0] = xExtent[0] - origin[0];
  9220. origin[1] = yExtent[0] - origin[1];
  9221. } else if (resizing) {
  9222. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  9223. offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
  9224. origin[0] = xExtent[ex];
  9225. origin[1] = yExtent[ey];
  9226. } else if (d3.event.altKey) center = origin.slice();
  9227. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  9228. d3.select("body").style("cursor", eventTarget.style("cursor"));
  9229. event_({
  9230. type: "brushstart"
  9231. });
  9232. brushmove();
  9233. function keydown() {
  9234. if (d3.event.keyCode == 32) {
  9235. if (!dragging) {
  9236. center = null;
  9237. origin[0] -= xExtent[1];
  9238. origin[1] -= yExtent[1];
  9239. dragging = 2;
  9240. }
  9241. d3_eventPreventDefault();
  9242. }
  9243. }
  9244. function keyup() {
  9245. if (d3.event.keyCode == 32 && dragging == 2) {
  9246. origin[0] += xExtent[1];
  9247. origin[1] += yExtent[1];
  9248. dragging = 0;
  9249. d3_eventPreventDefault();
  9250. }
  9251. }
  9252. function brushmove() {
  9253. var point = d3.mouse(target), moved = false;
  9254. if (offset) {
  9255. point[0] += offset[0];
  9256. point[1] += offset[1];
  9257. }
  9258. if (!dragging) {
  9259. if (d3.event.altKey) {
  9260. if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
  9261. origin[0] = xExtent[+(point[0] < center[0])];
  9262. origin[1] = yExtent[+(point[1] < center[1])];
  9263. } else center = null;
  9264. }
  9265. if (resizingX && move1(point, x, 0)) {
  9266. redrawX(g);
  9267. moved = true;
  9268. }
  9269. if (resizingY && move1(point, y, 1)) {
  9270. redrawY(g);
  9271. moved = true;
  9272. }
  9273. if (moved) {
  9274. redraw(g);
  9275. event_({
  9276. type: "brush",
  9277. mode: dragging ? "move" : "resize"
  9278. });
  9279. }
  9280. }
  9281. function move1(point, scale, i) {
  9282. var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max;
  9283. if (dragging) {
  9284. r0 -= position;
  9285. r1 -= size + position;
  9286. }
  9287. min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
  9288. if (dragging) {
  9289. max = (min += position) + size;
  9290. } else {
  9291. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  9292. if (position < min) {
  9293. max = min;
  9294. min = position;
  9295. } else {
  9296. max = position;
  9297. }
  9298. }
  9299. if (extent[0] != min || extent[1] != max) {
  9300. if (i) yExtentDomain = null; else xExtentDomain = null;
  9301. extent[0] = min;
  9302. extent[1] = max;
  9303. return true;
  9304. }
  9305. }
  9306. function brushend() {
  9307. brushmove();
  9308. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  9309. d3.select("body").style("cursor", null);
  9310. 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);
  9311. dragRestore();
  9312. event_({
  9313. type: "brushend"
  9314. });
  9315. }
  9316. }
  9317. brush.x = function(z) {
  9318. if (!arguments.length) return x;
  9319. x = z;
  9320. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9321. return brush;
  9322. };
  9323. brush.y = function(z) {
  9324. if (!arguments.length) return y;
  9325. y = z;
  9326. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9327. return brush;
  9328. };
  9329. brush.clamp = function(z) {
  9330. if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
  9331. if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
  9332. return brush;
  9333. };
  9334. brush.extent = function(z) {
  9335. var x0, x1, y0, y1, t;
  9336. if (!arguments.length) {
  9337. if (x) {
  9338. if (xExtentDomain) {
  9339. x0 = xExtentDomain[0], x1 = xExtentDomain[1];
  9340. } else {
  9341. x0 = xExtent[0], x1 = xExtent[1];
  9342. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  9343. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9344. }
  9345. }
  9346. if (y) {
  9347. if (yExtentDomain) {
  9348. y0 = yExtentDomain[0], y1 = yExtentDomain[1];
  9349. } else {
  9350. y0 = yExtent[0], y1 = yExtent[1];
  9351. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  9352. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9353. }
  9354. }
  9355. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  9356. }
  9357. if (x) {
  9358. x0 = z[0], x1 = z[1];
  9359. if (y) x0 = x0[0], x1 = x1[0];
  9360. xExtentDomain = [ x0, x1 ];
  9361. if (x.invert) x0 = x(x0), x1 = x(x1);
  9362. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9363. if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
  9364. }
  9365. if (y) {
  9366. y0 = z[0], y1 = z[1];
  9367. if (x) y0 = y0[1], y1 = y1[1];
  9368. yExtentDomain = [ y0, y1 ];
  9369. if (y.invert) y0 = y(y0), y1 = y(y1);
  9370. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9371. if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
  9372. }
  9373. return brush;
  9374. };
  9375. brush.clear = function() {
  9376. if (!brush.empty()) {
  9377. xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
  9378. xExtentDomain = yExtentDomain = null;
  9379. }
  9380. return brush;
  9381. };
  9382. brush.empty = function() {
  9383. return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
  9384. };
  9385. return d3.rebind(brush, event, "on");
  9386. };
  9387. var d3_svg_brushCursor = {
  9388. n: "ns-resize",
  9389. e: "ew-resize",
  9390. s: "ns-resize",
  9391. w: "ew-resize",
  9392. nw: "nwse-resize",
  9393. ne: "nesw-resize",
  9394. se: "nwse-resize",
  9395. sw: "nesw-resize"
  9396. };
  9397. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  9398. var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
  9399. var d3_time_formatUtc = d3_time_format.utc;
  9400. var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
  9401. d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  9402. function d3_time_formatIsoNative(date) {
  9403. return date.toISOString();
  9404. }
  9405. d3_time_formatIsoNative.parse = function(string) {
  9406. var date = new Date(string);
  9407. return isNaN(date) ? null : date;
  9408. };
  9409. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  9410. d3_time.second = d3_time_interval(function(date) {
  9411. return new d3_date(Math.floor(date / 1e3) * 1e3);
  9412. }, function(date, offset) {
  9413. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  9414. }, function(date) {
  9415. return date.getSeconds();
  9416. });
  9417. d3_time.seconds = d3_time.second.range;
  9418. d3_time.seconds.utc = d3_time.second.utc.range;
  9419. d3_time.minute = d3_time_interval(function(date) {
  9420. return new d3_date(Math.floor(date / 6e4) * 6e4);
  9421. }, function(date, offset) {
  9422. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  9423. }, function(date) {
  9424. return date.getMinutes();
  9425. });
  9426. d3_time.minutes = d3_time.minute.range;
  9427. d3_time.minutes.utc = d3_time.minute.utc.range;
  9428. d3_time.hour = d3_time_interval(function(date) {
  9429. var timezone = date.getTimezoneOffset() / 60;
  9430. return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  9431. }, function(date, offset) {
  9432. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  9433. }, function(date) {
  9434. return date.getHours();
  9435. });
  9436. d3_time.hours = d3_time.hour.range;
  9437. d3_time.hours.utc = d3_time.hour.utc.range;
  9438. d3_time.month = d3_time_interval(function(date) {
  9439. date = d3_time.day(date);
  9440. date.setDate(1);
  9441. return date;
  9442. }, function(date, offset) {
  9443. date.setMonth(date.getMonth() + offset);
  9444. }, function(date) {
  9445. return date.getMonth();
  9446. });
  9447. d3_time.months = d3_time.month.range;
  9448. d3_time.months.utc = d3_time.month.utc.range;
  9449. function d3_time_scale(linear, methods, format) {
  9450. function scale(x) {
  9451. return linear(x);
  9452. }
  9453. scale.invert = function(x) {
  9454. return d3_time_scaleDate(linear.invert(x));
  9455. };
  9456. scale.domain = function(x) {
  9457. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  9458. linear.domain(x);
  9459. return scale;
  9460. };
  9461. function tickMethod(extent, count) {
  9462. var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
  9463. return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
  9464. return d / 31536e6;
  9465. }), count)[2] ] : !i ? [ d3_time_scaleMilliseconds, d3_scale_linearTickRange(extent, count)[2] ] : methods[target / d3_time_scaleSteps[i - 1] < d3_time_scaleSteps[i] / target ? i - 1 : i];
  9466. }
  9467. scale.nice = function(interval, skip) {
  9468. var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
  9469. if (method) interval = method[0], skip = method[1];
  9470. function skipped(date) {
  9471. return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
  9472. }
  9473. return scale.domain(d3_scale_nice(domain, skip > 1 ? {
  9474. floor: function(date) {
  9475. while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
  9476. return date;
  9477. },
  9478. ceil: function(date) {
  9479. while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
  9480. return date;
  9481. }
  9482. } : interval));
  9483. };
  9484. scale.ticks = function(interval, skip) {
  9485. var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
  9486. range: interval
  9487. }, skip ];
  9488. if (method) interval = method[0], skip = method[1];
  9489. return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
  9490. };
  9491. scale.tickFormat = function() {
  9492. return format;
  9493. };
  9494. scale.copy = function() {
  9495. return d3_time_scale(linear.copy(), methods, format);
  9496. };
  9497. return d3_scale_linearRebind(scale, linear);
  9498. }
  9499. function d3_time_scaleDate(t) {
  9500. return new Date(t);
  9501. }
  9502. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  9503. 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 ] ];
  9504. var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
  9505. return d.getMilliseconds();
  9506. } ], [ ":%S", function(d) {
  9507. return d.getSeconds();
  9508. } ], [ "%I:%M", function(d) {
  9509. return d.getMinutes();
  9510. } ], [ "%I %p", function(d) {
  9511. return d.getHours();
  9512. } ], [ "%a %d", function(d) {
  9513. return d.getDay() && d.getDate() != 1;
  9514. } ], [ "%b %d", function(d) {
  9515. return d.getDate() != 1;
  9516. } ], [ "%B", function(d) {
  9517. return d.getMonth();
  9518. } ], [ "%Y", d3_true ] ]);
  9519. var d3_time_scaleMilliseconds = {
  9520. range: function(start, stop, step) {
  9521. return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
  9522. },
  9523. floor: d3_identity,
  9524. ceil: d3_identity
  9525. };
  9526. d3_time_scaleLocalMethods.year = d3_time.year;
  9527. d3_time.scale = function() {
  9528. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  9529. };
  9530. var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
  9531. return [ m[0].utc, m[1] ];
  9532. });
  9533. var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
  9534. return d.getUTCMilliseconds();
  9535. } ], [ ":%S", function(d) {
  9536. return d.getUTCSeconds();
  9537. } ], [ "%I:%M", function(d) {
  9538. return d.getUTCMinutes();
  9539. } ], [ "%I %p", function(d) {
  9540. return d.getUTCHours();
  9541. } ], [ "%a %d", function(d) {
  9542. return d.getUTCDay() && d.getUTCDate() != 1;
  9543. } ], [ "%b %d", function(d) {
  9544. return d.getUTCDate() != 1;
  9545. } ], [ "%B", function(d) {
  9546. return d.getUTCMonth();
  9547. } ], [ "%Y", d3_true ] ]);
  9548. d3_time_scaleUtcMethods.year = d3_time.year.utc;
  9549. d3_time.scale.utc = function() {
  9550. return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
  9551. };
  9552. d3.text = d3_xhrType(function(request) {
  9553. return request.responseText;
  9554. });
  9555. d3.json = function(url, callback) {
  9556. return d3_xhr(url, "application/json", d3_json, callback);
  9557. };
  9558. function d3_json(request) {
  9559. return JSON.parse(request.responseText);
  9560. }
  9561. d3.html = function(url, callback) {
  9562. return d3_xhr(url, "text/html", d3_html, callback);
  9563. };
  9564. function d3_html(request) {
  9565. var range = d3_document.createRange();
  9566. range.selectNode(d3_document.body);
  9567. return range.createContextualFragment(request.responseText);
  9568. }
  9569. d3.xml = d3_xhrType(function(request) {
  9570. return request.responseXML;
  9571. });
  9572. if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
  9573. }();