d3.js 328 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504
  1. !function() {
  2. var d3 = {
  3. version: "3.5.4"
  4. };
  5. var d3_arraySlice = [].slice, d3_array = function(list) {
  6. return d3_arraySlice.call(list);
  7. };
  8. var d3_document = this.document;
  9. function d3_documentElement(node) {
  10. return node && (node.ownerDocument || node.document).documentElement;
  11. }
  12. function d3_window(node) {
  13. return node && node.ownerDocument ? node.ownerDocument.defaultView : node;
  14. }
  15. if (d3_document) {
  16. try {
  17. d3_array(d3_document.documentElement.childNodes)[0].nodeType;
  18. } catch (e) {
  19. d3_array = function(list) {
  20. var i = list.length, array = new Array(i);
  21. while (i--) array[i] = list[i];
  22. return array;
  23. };
  24. }
  25. }
  26. if (!Date.now) Date.now = function() {
  27. return +new Date();
  28. };
  29. if (d3_document) {
  30. try {
  31. d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
  32. } catch (error) {
  33. var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
  34. d3_element_prototype.setAttribute = function(name, value) {
  35. d3_element_setAttribute.call(this, name, value + "");
  36. };
  37. d3_element_prototype.setAttributeNS = function(space, local, value) {
  38. d3_element_setAttributeNS.call(this, space, local, value + "");
  39. };
  40. d3_style_prototype.setProperty = function(name, value, priority) {
  41. d3_style_setProperty.call(this, name, value + "", priority);
  42. };
  43. }
  44. }
  45. d3.ascending = d3_ascending;
  46. function d3_ascending(a, b) {
  47. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  48. }
  49. d3.descending = function(a, b) {
  50. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  51. };
  52. d3.min = function(array, f) {
  53. var i = -1, n = array.length, a, b;
  54. if (arguments.length === 1) {
  55. while (++i < n) if ((b = array[i]) != null && b >= b) {
  56. a = b;
  57. break;
  58. }
  59. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  60. } else {
  61. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  62. a = b;
  63. break;
  64. }
  65. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  66. }
  67. return a;
  68. };
  69. d3.max = function(array, f) {
  70. var i = -1, n = array.length, a, b;
  71. if (arguments.length === 1) {
  72. while (++i < n) if ((b = array[i]) != null && b >= b) {
  73. a = b;
  74. break;
  75. }
  76. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  77. } else {
  78. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  79. a = b;
  80. break;
  81. }
  82. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  83. }
  84. return a;
  85. };
  86. d3.extent = function(array, f) {
  87. var i = -1, n = array.length, a, b, c;
  88. if (arguments.length === 1) {
  89. while (++i < n) if ((b = array[i]) != null && b >= b) {
  90. a = c = b;
  91. break;
  92. }
  93. while (++i < n) if ((b = array[i]) != null) {
  94. if (a > b) a = b;
  95. if (c < b) c = b;
  96. }
  97. } else {
  98. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  99. a = c = b;
  100. break;
  101. }
  102. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  103. if (a > b) a = b;
  104. if (c < b) c = b;
  105. }
  106. }
  107. return [ a, c ];
  108. };
  109. function d3_number(x) {
  110. return x === null ? NaN : +x;
  111. }
  112. function d3_numeric(x) {
  113. return !isNaN(x);
  114. }
  115. d3.sum = function(array, f) {
  116. var s = 0, n = array.length, a, i = -1;
  117. if (arguments.length === 1) {
  118. while (++i < n) if (d3_numeric(a = +array[i])) s += a;
  119. } else {
  120. while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
  121. }
  122. return s;
  123. };
  124. d3.mean = function(array, f) {
  125. var s = 0, n = array.length, a, i = -1, j = n;
  126. if (arguments.length === 1) {
  127. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
  128. } else {
  129. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
  130. }
  131. if (j) return s / j;
  132. };
  133. d3.quantile = function(values, p) {
  134. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  135. return e ? v + e * (values[h] - v) : v;
  136. };
  137. d3.median = function(array, f) {
  138. var numbers = [], n = array.length, a, i = -1;
  139. if (arguments.length === 1) {
  140. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
  141. } else {
  142. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
  143. }
  144. if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
  145. };
  146. d3.variance = function(array, f) {
  147. var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
  148. if (arguments.length === 1) {
  149. while (++i < n) {
  150. if (d3_numeric(a = d3_number(array[i]))) {
  151. d = a - m;
  152. m += d / ++j;
  153. s += d * (a - m);
  154. }
  155. }
  156. } else {
  157. while (++i < n) {
  158. if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
  159. d = a - m;
  160. m += d / ++j;
  161. s += d * (a - m);
  162. }
  163. }
  164. }
  165. if (j > 1) return s / (j - 1);
  166. };
  167. d3.deviation = function() {
  168. var v = d3.variance.apply(this, arguments);
  169. return v ? Math.sqrt(v) : v;
  170. };
  171. function d3_bisector(compare) {
  172. return {
  173. left: function(a, x, lo, hi) {
  174. if (arguments.length < 3) lo = 0;
  175. if (arguments.length < 4) hi = a.length;
  176. while (lo < hi) {
  177. var mid = lo + hi >>> 1;
  178. if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
  179. }
  180. return lo;
  181. },
  182. right: function(a, x, lo, hi) {
  183. if (arguments.length < 3) lo = 0;
  184. if (arguments.length < 4) hi = a.length;
  185. while (lo < hi) {
  186. var mid = lo + hi >>> 1;
  187. if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
  188. }
  189. return lo;
  190. }
  191. };
  192. }
  193. var d3_bisect = d3_bisector(d3_ascending);
  194. d3.bisectLeft = d3_bisect.left;
  195. d3.bisect = d3.bisectRight = d3_bisect.right;
  196. d3.bisector = function(f) {
  197. return d3_bisector(f.length === 1 ? function(d, x) {
  198. return d3_ascending(f(d), x);
  199. } : f);
  200. };
  201. d3.shuffle = function(array, i0, i1) {
  202. if ((m = arguments.length) < 3) {
  203. i1 = array.length;
  204. if (m < 2) i0 = 0;
  205. }
  206. var m = i1 - i0, t, i;
  207. while (m) {
  208. i = Math.random() * m-- | 0;
  209. t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
  210. }
  211. return array;
  212. };
  213. d3.permute = function(array, indexes) {
  214. var i = indexes.length, permutes = new Array(i);
  215. while (i--) permutes[i] = array[indexes[i]];
  216. return permutes;
  217. };
  218. d3.pairs = function(array) {
  219. var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
  220. while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
  221. return pairs;
  222. };
  223. d3.zip = function() {
  224. if (!(n = arguments.length)) return [];
  225. for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
  226. for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
  227. zip[j] = arguments[j][i];
  228. }
  229. }
  230. return zips;
  231. };
  232. function d3_zipLength(d) {
  233. return d.length;
  234. }
  235. d3.transpose = function(matrix) {
  236. return d3.zip.apply(d3, matrix);
  237. };
  238. d3.keys = function(map) {
  239. var keys = [];
  240. for (var key in map) keys.push(key);
  241. return keys;
  242. };
  243. d3.values = function(map) {
  244. var values = [];
  245. for (var key in map) values.push(map[key]);
  246. return values;
  247. };
  248. d3.entries = function(map) {
  249. var entries = [];
  250. for (var key in map) entries.push({
  251. key: key,
  252. value: map[key]
  253. });
  254. return entries;
  255. };
  256. d3.merge = function(arrays) {
  257. var n = arrays.length, m, i = -1, j = 0, merged, array;
  258. while (++i < n) j += arrays[i].length;
  259. merged = new Array(j);
  260. while (--n >= 0) {
  261. array = arrays[n];
  262. m = array.length;
  263. while (--m >= 0) {
  264. merged[--j] = array[m];
  265. }
  266. }
  267. return merged;
  268. };
  269. var abs = Math.abs;
  270. d3.range = function(start, stop, step) {
  271. if (arguments.length < 3) {
  272. step = 1;
  273. if (arguments.length < 2) {
  274. stop = start;
  275. start = 0;
  276. }
  277. }
  278. if ((stop - start) / step === Infinity) throw new Error("infinite range");
  279. var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
  280. start *= k, stop *= k, step *= k;
  281. if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
  282. return range;
  283. };
  284. function d3_range_integerScale(x) {
  285. var k = 1;
  286. while (x * k % 1) k *= 10;
  287. return k;
  288. }
  289. function d3_class(ctor, properties) {
  290. for (var key in properties) {
  291. Object.defineProperty(ctor.prototype, key, {
  292. value: properties[key],
  293. enumerable: false
  294. });
  295. }
  296. }
  297. d3.map = function(object, f) {
  298. var map = new d3_Map();
  299. if (object instanceof d3_Map) {
  300. object.forEach(function(key, value) {
  301. map.set(key, value);
  302. });
  303. } else if (Array.isArray(object)) {
  304. var i = -1, n = object.length, o;
  305. if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
  306. } else {
  307. for (var key in object) map.set(key, object[key]);
  308. }
  309. return map;
  310. };
  311. function d3_Map() {
  312. this._ = Object.create(null);
  313. }
  314. var d3_map_proto = "__proto__", d3_map_zero = "\x00";
  315. d3_class(d3_Map, {
  316. has: d3_map_has,
  317. get: function(key) {
  318. return this._[d3_map_escape(key)];
  319. },
  320. set: function(key, value) {
  321. return this._[d3_map_escape(key)] = value;
  322. },
  323. remove: d3_map_remove,
  324. keys: d3_map_keys,
  325. values: function() {
  326. var values = [];
  327. for (var key in this._) values.push(this._[key]);
  328. return values;
  329. },
  330. entries: function() {
  331. var entries = [];
  332. for (var key in this._) entries.push({
  333. key: d3_map_unescape(key),
  334. value: this._[key]
  335. });
  336. return entries;
  337. },
  338. size: d3_map_size,
  339. empty: d3_map_empty,
  340. forEach: function(f) {
  341. for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
  342. }
  343. });
  344. function d3_map_escape(key) {
  345. return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
  346. }
  347. function d3_map_unescape(key) {
  348. return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
  349. }
  350. function d3_map_has(key) {
  351. return d3_map_escape(key) in this._;
  352. }
  353. function d3_map_remove(key) {
  354. return (key = d3_map_escape(key)) in this._ && delete this._[key];
  355. }
  356. function d3_map_keys() {
  357. var keys = [];
  358. for (var key in this._) keys.push(d3_map_unescape(key));
  359. return keys;
  360. }
  361. function d3_map_size() {
  362. var size = 0;
  363. for (var key in this._) ++size;
  364. return size;
  365. }
  366. function d3_map_empty() {
  367. for (var key in this._) return false;
  368. return true;
  369. }
  370. d3.nest = function() {
  371. var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
  372. function map(mapType, array, depth) {
  373. if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
  374. var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
  375. while (++i < n) {
  376. if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
  377. values.push(object);
  378. } else {
  379. valuesByKey.set(keyValue, [ object ]);
  380. }
  381. }
  382. if (mapType) {
  383. object = mapType();
  384. setter = function(keyValue, values) {
  385. object.set(keyValue, map(mapType, values, depth));
  386. };
  387. } else {
  388. object = {};
  389. setter = function(keyValue, values) {
  390. object[keyValue] = map(mapType, values, depth);
  391. };
  392. }
  393. valuesByKey.forEach(setter);
  394. return object;
  395. }
  396. function entries(map, depth) {
  397. if (depth >= keys.length) return map;
  398. var array = [], sortKey = sortKeys[depth++];
  399. map.forEach(function(key, keyMap) {
  400. array.push({
  401. key: key,
  402. values: entries(keyMap, depth)
  403. });
  404. });
  405. return sortKey ? array.sort(function(a, b) {
  406. return sortKey(a.key, b.key);
  407. }) : array;
  408. }
  409. nest.map = function(array, mapType) {
  410. return map(mapType, array, 0);
  411. };
  412. nest.entries = function(array) {
  413. return entries(map(d3.map, array, 0), 0);
  414. };
  415. nest.key = function(d) {
  416. keys.push(d);
  417. return nest;
  418. };
  419. nest.sortKeys = function(order) {
  420. sortKeys[keys.length - 1] = order;
  421. return nest;
  422. };
  423. nest.sortValues = function(order) {
  424. sortValues = order;
  425. return nest;
  426. };
  427. nest.rollup = function(f) {
  428. rollup = f;
  429. return nest;
  430. };
  431. return nest;
  432. };
  433. d3.set = function(array) {
  434. var set = new d3_Set();
  435. if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
  436. return set;
  437. };
  438. function d3_Set() {
  439. this._ = Object.create(null);
  440. }
  441. d3_class(d3_Set, {
  442. has: d3_map_has,
  443. add: function(key) {
  444. this._[d3_map_escape(key += "")] = true;
  445. return key;
  446. },
  447. remove: d3_map_remove,
  448. values: d3_map_keys,
  449. size: d3_map_size,
  450. empty: d3_map_empty,
  451. forEach: function(f) {
  452. for (var key in this._) f.call(this, d3_map_unescape(key));
  453. }
  454. });
  455. d3.behavior = {};
  456. function d3_identity(d) {
  457. return d;
  458. }
  459. d3.rebind = function(target, source) {
  460. var i = 1, n = arguments.length, method;
  461. while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
  462. return target;
  463. };
  464. function d3_rebind(target, source, method) {
  465. return function() {
  466. var value = method.apply(source, arguments);
  467. return value === source ? target : value;
  468. };
  469. }
  470. function d3_vendorSymbol(object, name) {
  471. if (name in object) return name;
  472. name = name.charAt(0).toUpperCase() + name.slice(1);
  473. for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
  474. var prefixName = d3_vendorPrefixes[i] + name;
  475. if (prefixName in object) return prefixName;
  476. }
  477. }
  478. var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
  479. function d3_noop() {}
  480. d3.dispatch = function() {
  481. var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
  482. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  483. return dispatch;
  484. };
  485. function d3_dispatch() {}
  486. d3_dispatch.prototype.on = function(type, listener) {
  487. var i = type.indexOf("."), name = "";
  488. if (i >= 0) {
  489. name = type.slice(i + 1);
  490. type = type.slice(0, i);
  491. }
  492. if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
  493. if (arguments.length === 2) {
  494. if (listener == null) for (type in this) {
  495. if (this.hasOwnProperty(type)) this[type].on(name, null);
  496. }
  497. return this;
  498. }
  499. };
  500. function d3_dispatch_event(dispatch) {
  501. var listeners = [], listenerByName = new d3_Map();
  502. function event() {
  503. var z = listeners, i = -1, n = z.length, l;
  504. while (++i < n) if (l = z[i].on) l.apply(this, arguments);
  505. return dispatch;
  506. }
  507. event.on = function(name, listener) {
  508. var l = listenerByName.get(name), i;
  509. if (arguments.length < 2) return l && l.on;
  510. if (l) {
  511. l.on = null;
  512. listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
  513. listenerByName.remove(name);
  514. }
  515. if (listener) listeners.push(listenerByName.set(name, {
  516. on: listener
  517. }));
  518. return dispatch;
  519. };
  520. return event;
  521. }
  522. d3.event = null;
  523. function d3_eventPreventDefault() {
  524. d3.event.preventDefault();
  525. }
  526. function d3_eventSource() {
  527. var e = d3.event, s;
  528. while (s = e.sourceEvent) e = s;
  529. return e;
  530. }
  531. function d3_eventDispatch(target) {
  532. var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
  533. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  534. dispatch.of = function(thiz, argumentz) {
  535. return function(e1) {
  536. try {
  537. var e0 = e1.sourceEvent = d3.event;
  538. e1.target = target;
  539. d3.event = e1;
  540. dispatch[e1.type].apply(thiz, argumentz);
  541. } finally {
  542. d3.event = e0;
  543. }
  544. };
  545. };
  546. return dispatch;
  547. }
  548. d3.requote = function(s) {
  549. return s.replace(d3_requote_re, "\\$&");
  550. };
  551. var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  552. var d3_subclass = {}.__proto__ ? function(object, prototype) {
  553. object.__proto__ = prototype;
  554. } : function(object, prototype) {
  555. for (var property in prototype) object[property] = prototype[property];
  556. };
  557. function d3_selection(groups) {
  558. d3_subclass(groups, d3_selectionPrototype);
  559. return groups;
  560. }
  561. var d3_select = function(s, n) {
  562. return n.querySelector(s);
  563. }, d3_selectAll = function(s, n) {
  564. return n.querySelectorAll(s);
  565. }, d3_selectMatches = function(n, s) {
  566. var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
  567. d3_selectMatches = function(n, s) {
  568. return d3_selectMatcher.call(n, s);
  569. };
  570. return d3_selectMatches(n, s);
  571. };
  572. if (typeof Sizzle === "function") {
  573. d3_select = function(s, n) {
  574. return Sizzle(s, n)[0] || null;
  575. };
  576. d3_selectAll = Sizzle;
  577. d3_selectMatches = Sizzle.matchesSelector;
  578. }
  579. d3.selection = function() {
  580. return d3.select(d3_document.documentElement);
  581. };
  582. var d3_selectionPrototype = d3.selection.prototype = [];
  583. d3_selectionPrototype.select = function(selector) {
  584. var subgroups = [], subgroup, subnode, group, node;
  585. selector = d3_selection_selector(selector);
  586. for (var j = -1, m = this.length; ++j < m; ) {
  587. subgroups.push(subgroup = []);
  588. subgroup.parentNode = (group = this[j]).parentNode;
  589. for (var i = -1, n = group.length; ++i < n; ) {
  590. if (node = group[i]) {
  591. subgroup.push(subnode = selector.call(node, node.__data__, i, j));
  592. if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
  593. } else {
  594. subgroup.push(null);
  595. }
  596. }
  597. }
  598. return d3_selection(subgroups);
  599. };
  600. function d3_selection_selector(selector) {
  601. return typeof selector === "function" ? selector : function() {
  602. return d3_select(selector, this);
  603. };
  604. }
  605. d3_selectionPrototype.selectAll = function(selector) {
  606. var subgroups = [], subgroup, node;
  607. selector = d3_selection_selectorAll(selector);
  608. for (var j = -1, m = this.length; ++j < m; ) {
  609. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  610. if (node = group[i]) {
  611. subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
  612. subgroup.parentNode = node;
  613. }
  614. }
  615. }
  616. return d3_selection(subgroups);
  617. };
  618. function d3_selection_selectorAll(selector) {
  619. return typeof selector === "function" ? selector : function() {
  620. return d3_selectAll(selector, this);
  621. };
  622. }
  623. var d3_nsPrefix = {
  624. svg: "http://www.w3.org/2000/svg",
  625. xhtml: "http://www.w3.org/1999/xhtml",
  626. xlink: "http://www.w3.org/1999/xlink",
  627. xml: "http://www.w3.org/XML/1998/namespace",
  628. xmlns: "http://www.w3.org/2000/xmlns/"
  629. };
  630. d3.ns = {
  631. prefix: d3_nsPrefix,
  632. qualify: function(name) {
  633. var i = name.indexOf(":"), prefix = name;
  634. if (i >= 0) {
  635. prefix = name.slice(0, i);
  636. name = name.slice(i + 1);
  637. }
  638. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  639. space: d3_nsPrefix[prefix],
  640. local: name
  641. } : name;
  642. }
  643. };
  644. d3_selectionPrototype.attr = function(name, value) {
  645. if (arguments.length < 2) {
  646. if (typeof name === "string") {
  647. var node = this.node();
  648. name = d3.ns.qualify(name);
  649. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  650. }
  651. for (value in name) this.each(d3_selection_attr(value, name[value]));
  652. return this;
  653. }
  654. return this.each(d3_selection_attr(name, value));
  655. };
  656. function d3_selection_attr(name, value) {
  657. name = d3.ns.qualify(name);
  658. function attrNull() {
  659. this.removeAttribute(name);
  660. }
  661. function attrNullNS() {
  662. this.removeAttributeNS(name.space, name.local);
  663. }
  664. function attrConstant() {
  665. this.setAttribute(name, value);
  666. }
  667. function attrConstantNS() {
  668. this.setAttributeNS(name.space, name.local, value);
  669. }
  670. function attrFunction() {
  671. var x = value.apply(this, arguments);
  672. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  673. }
  674. function attrFunctionNS() {
  675. var x = value.apply(this, arguments);
  676. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  677. }
  678. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  679. }
  680. function d3_collapse(s) {
  681. return s.trim().replace(/\s+/g, " ");
  682. }
  683. d3_selectionPrototype.classed = function(name, value) {
  684. if (arguments.length < 2) {
  685. if (typeof name === "string") {
  686. var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
  687. if (value = node.classList) {
  688. while (++i < n) if (!value.contains(name[i])) return false;
  689. } else {
  690. value = node.getAttribute("class");
  691. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  692. }
  693. return true;
  694. }
  695. for (value in name) this.each(d3_selection_classed(value, name[value]));
  696. return this;
  697. }
  698. return this.each(d3_selection_classed(name, value));
  699. };
  700. function d3_selection_classedRe(name) {
  701. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  702. }
  703. function d3_selection_classes(name) {
  704. return (name + "").trim().split(/^|\s+/);
  705. }
  706. function d3_selection_classed(name, value) {
  707. name = d3_selection_classes(name).map(d3_selection_classedName);
  708. var n = name.length;
  709. function classedConstant() {
  710. var i = -1;
  711. while (++i < n) name[i](this, value);
  712. }
  713. function classedFunction() {
  714. var i = -1, x = value.apply(this, arguments);
  715. while (++i < n) name[i](this, x);
  716. }
  717. return typeof value === "function" ? classedFunction : classedConstant;
  718. }
  719. function d3_selection_classedName(name) {
  720. var re = d3_selection_classedRe(name);
  721. return function(node, value) {
  722. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  723. var c = node.getAttribute("class") || "";
  724. if (value) {
  725. re.lastIndex = 0;
  726. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  727. } else {
  728. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  729. }
  730. };
  731. }
  732. d3_selectionPrototype.style = function(name, value, priority) {
  733. var n = arguments.length;
  734. if (n < 3) {
  735. if (typeof name !== "string") {
  736. if (n < 2) value = "";
  737. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  738. return this;
  739. }
  740. if (n < 2) {
  741. var node = this.node();
  742. return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
  743. }
  744. priority = "";
  745. }
  746. return this.each(d3_selection_style(name, value, priority));
  747. };
  748. function d3_selection_style(name, value, priority) {
  749. function styleNull() {
  750. this.style.removeProperty(name);
  751. }
  752. function styleConstant() {
  753. this.style.setProperty(name, value, priority);
  754. }
  755. function styleFunction() {
  756. var x = value.apply(this, arguments);
  757. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  758. }
  759. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  760. }
  761. d3_selectionPrototype.property = function(name, value) {
  762. if (arguments.length < 2) {
  763. if (typeof name === "string") return this.node()[name];
  764. for (value in name) this.each(d3_selection_property(value, name[value]));
  765. return this;
  766. }
  767. return this.each(d3_selection_property(name, value));
  768. };
  769. function d3_selection_property(name, value) {
  770. function propertyNull() {
  771. delete this[name];
  772. }
  773. function propertyConstant() {
  774. this[name] = value;
  775. }
  776. function propertyFunction() {
  777. var x = value.apply(this, arguments);
  778. if (x == null) delete this[name]; else this[name] = x;
  779. }
  780. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  781. }
  782. d3_selectionPrototype.text = function(value) {
  783. return arguments.length ? this.each(typeof value === "function" ? function() {
  784. var v = value.apply(this, arguments);
  785. this.textContent = v == null ? "" : v;
  786. } : value == null ? function() {
  787. this.textContent = "";
  788. } : function() {
  789. this.textContent = value;
  790. }) : this.node().textContent;
  791. };
  792. d3_selectionPrototype.html = function(value) {
  793. return arguments.length ? this.each(typeof value === "function" ? function() {
  794. var v = value.apply(this, arguments);
  795. this.innerHTML = v == null ? "" : v;
  796. } : value == null ? function() {
  797. this.innerHTML = "";
  798. } : function() {
  799. this.innerHTML = value;
  800. }) : this.node().innerHTML;
  801. };
  802. d3_selectionPrototype.append = function(name) {
  803. name = d3_selection_creator(name);
  804. return this.select(function() {
  805. return this.appendChild(name.apply(this, arguments));
  806. });
  807. };
  808. function d3_selection_creator(name) {
  809. function create() {
  810. var document = this.ownerDocument, namespace = this.namespaceURI;
  811. return namespace ? document.createElementNS(namespace, name) : document.createElement(name);
  812. }
  813. function createNS() {
  814. return this.ownerDocument.createElementNS(name.space, name.local);
  815. }
  816. return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
  817. }
  818. d3_selectionPrototype.insert = function(name, before) {
  819. name = d3_selection_creator(name);
  820. before = d3_selection_selector(before);
  821. return this.select(function() {
  822. return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
  823. });
  824. };
  825. d3_selectionPrototype.remove = function() {
  826. return this.each(d3_selectionRemove);
  827. };
  828. function d3_selectionRemove() {
  829. var parent = this.parentNode;
  830. if (parent) parent.removeChild(this);
  831. }
  832. d3_selectionPrototype.data = function(value, key) {
  833. var i = -1, n = this.length, group, node;
  834. if (!arguments.length) {
  835. value = new Array(n = (group = this[0]).length);
  836. while (++i < n) {
  837. if (node = group[i]) {
  838. value[i] = node.__data__;
  839. }
  840. }
  841. return value;
  842. }
  843. function bind(group, groupData) {
  844. 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;
  845. if (key) {
  846. var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
  847. for (i = -1; ++i < n; ) {
  848. if (nodeByKeyValue.has(keyValue = key.call(node = group[i], node.__data__, i))) {
  849. exitNodes[i] = node;
  850. } else {
  851. nodeByKeyValue.set(keyValue, node);
  852. }
  853. keyValues[i] = keyValue;
  854. }
  855. for (i = -1; ++i < m; ) {
  856. if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
  857. enterNodes[i] = d3_selection_dataNode(nodeData);
  858. } else if (node !== true) {
  859. updateNodes[i] = node;
  860. node.__data__ = nodeData;
  861. }
  862. nodeByKeyValue.set(keyValue, true);
  863. }
  864. for (i = -1; ++i < n; ) {
  865. if (nodeByKeyValue.get(keyValues[i]) !== true) {
  866. exitNodes[i] = group[i];
  867. }
  868. }
  869. } else {
  870. for (i = -1; ++i < n0; ) {
  871. node = group[i];
  872. nodeData = groupData[i];
  873. if (node) {
  874. node.__data__ = nodeData;
  875. updateNodes[i] = node;
  876. } else {
  877. enterNodes[i] = d3_selection_dataNode(nodeData);
  878. }
  879. }
  880. for (;i < m; ++i) {
  881. enterNodes[i] = d3_selection_dataNode(groupData[i]);
  882. }
  883. for (;i < n; ++i) {
  884. exitNodes[i] = group[i];
  885. }
  886. }
  887. enterNodes.update = updateNodes;
  888. enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
  889. enter.push(enterNodes);
  890. update.push(updateNodes);
  891. exit.push(exitNodes);
  892. }
  893. var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
  894. if (typeof value === "function") {
  895. while (++i < n) {
  896. bind(group = this[i], value.call(group, group.parentNode.__data__, i));
  897. }
  898. } else {
  899. while (++i < n) {
  900. bind(group = this[i], value);
  901. }
  902. }
  903. update.enter = function() {
  904. return enter;
  905. };
  906. update.exit = function() {
  907. return exit;
  908. };
  909. return update;
  910. };
  911. function d3_selection_dataNode(data) {
  912. return {
  913. __data__: data
  914. };
  915. }
  916. d3_selectionPrototype.datum = function(value) {
  917. return arguments.length ? this.property("__data__", value) : this.property("__data__");
  918. };
  919. d3_selectionPrototype.filter = function(filter) {
  920. var subgroups = [], subgroup, group, node;
  921. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  922. for (var j = 0, m = this.length; j < m; j++) {
  923. subgroups.push(subgroup = []);
  924. subgroup.parentNode = (group = this[j]).parentNode;
  925. for (var i = 0, n = group.length; i < n; i++) {
  926. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  927. subgroup.push(node);
  928. }
  929. }
  930. }
  931. return d3_selection(subgroups);
  932. };
  933. function d3_selection_filter(selector) {
  934. return function() {
  935. return d3_selectMatches(this, selector);
  936. };
  937. }
  938. d3_selectionPrototype.order = function() {
  939. for (var j = -1, m = this.length; ++j < m; ) {
  940. for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
  941. if (node = group[i]) {
  942. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  943. next = node;
  944. }
  945. }
  946. }
  947. return this;
  948. };
  949. d3_selectionPrototype.sort = function(comparator) {
  950. comparator = d3_selection_sortComparator.apply(this, arguments);
  951. for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
  952. return this.order();
  953. };
  954. function d3_selection_sortComparator(comparator) {
  955. if (!arguments.length) comparator = d3_ascending;
  956. return function(a, b) {
  957. return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
  958. };
  959. }
  960. d3_selectionPrototype.each = function(callback) {
  961. return d3_selection_each(this, function(node, i, j) {
  962. callback.call(node, node.__data__, i, j);
  963. });
  964. };
  965. function d3_selection_each(groups, callback) {
  966. for (var j = 0, m = groups.length; j < m; j++) {
  967. for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
  968. if (node = group[i]) callback(node, i, j);
  969. }
  970. }
  971. return groups;
  972. }
  973. d3_selectionPrototype.call = function(callback) {
  974. var args = d3_array(arguments);
  975. callback.apply(args[0] = this, args);
  976. return this;
  977. };
  978. d3_selectionPrototype.empty = function() {
  979. return !this.node();
  980. };
  981. d3_selectionPrototype.node = function() {
  982. for (var j = 0, m = this.length; j < m; j++) {
  983. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  984. var node = group[i];
  985. if (node) return node;
  986. }
  987. }
  988. return null;
  989. };
  990. d3_selectionPrototype.size = function() {
  991. var n = 0;
  992. d3_selection_each(this, function() {
  993. ++n;
  994. });
  995. return n;
  996. };
  997. function d3_selection_enter(selection) {
  998. d3_subclass(selection, d3_selection_enterPrototype);
  999. return selection;
  1000. }
  1001. var d3_selection_enterPrototype = [];
  1002. d3.selection.enter = d3_selection_enter;
  1003. d3.selection.enter.prototype = d3_selection_enterPrototype;
  1004. d3_selection_enterPrototype.append = d3_selectionPrototype.append;
  1005. d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
  1006. d3_selection_enterPrototype.node = d3_selectionPrototype.node;
  1007. d3_selection_enterPrototype.call = d3_selectionPrototype.call;
  1008. d3_selection_enterPrototype.size = d3_selectionPrototype.size;
  1009. d3_selection_enterPrototype.select = function(selector) {
  1010. var subgroups = [], subgroup, subnode, upgroup, group, node;
  1011. for (var j = -1, m = this.length; ++j < m; ) {
  1012. upgroup = (group = this[j]).update;
  1013. subgroups.push(subgroup = []);
  1014. subgroup.parentNode = group.parentNode;
  1015. for (var i = -1, n = group.length; ++i < n; ) {
  1016. if (node = group[i]) {
  1017. subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
  1018. subnode.__data__ = node.__data__;
  1019. } else {
  1020. subgroup.push(null);
  1021. }
  1022. }
  1023. }
  1024. return d3_selection(subgroups);
  1025. };
  1026. d3_selection_enterPrototype.insert = function(name, before) {
  1027. if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
  1028. return d3_selectionPrototype.insert.call(this, name, before);
  1029. };
  1030. function d3_selection_enterInsertBefore(enter) {
  1031. var i0, j0;
  1032. return function(d, i, j) {
  1033. var group = enter[j].update, n = group.length, node;
  1034. if (j != j0) j0 = j, i0 = 0;
  1035. if (i >= i0) i0 = i + 1;
  1036. while (!(node = group[i0]) && ++i0 < n) ;
  1037. return node;
  1038. };
  1039. }
  1040. d3.select = function(node) {
  1041. var group;
  1042. if (typeof node === "string") {
  1043. group = [ d3_select(node, d3_document) ];
  1044. group.parentNode = d3_document.documentElement;
  1045. } else {
  1046. group = [ node ];
  1047. group.parentNode = d3_documentElement(node);
  1048. }
  1049. return d3_selection([ group ]);
  1050. };
  1051. d3.selectAll = function(nodes) {
  1052. var group;
  1053. if (typeof nodes === "string") {
  1054. group = d3_array(d3_selectAll(nodes, d3_document));
  1055. group.parentNode = d3_document.documentElement;
  1056. } else {
  1057. group = nodes;
  1058. group.parentNode = null;
  1059. }
  1060. return d3_selection([ group ]);
  1061. };
  1062. d3_selectionPrototype.on = function(type, listener, capture) {
  1063. var n = arguments.length;
  1064. if (n < 3) {
  1065. if (typeof type !== "string") {
  1066. if (n < 2) listener = false;
  1067. for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
  1068. return this;
  1069. }
  1070. if (n < 2) return (n = this.node()["__on" + type]) && n._;
  1071. capture = false;
  1072. }
  1073. return this.each(d3_selection_on(type, listener, capture));
  1074. };
  1075. function d3_selection_on(type, listener, capture) {
  1076. var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
  1077. if (i > 0) type = type.slice(0, i);
  1078. var filter = d3_selection_onFilters.get(type);
  1079. if (filter) type = filter, wrap = d3_selection_onFilter;
  1080. function onRemove() {
  1081. var l = this[name];
  1082. if (l) {
  1083. this.removeEventListener(type, l, l.$);
  1084. delete this[name];
  1085. }
  1086. }
  1087. function onAdd() {
  1088. var l = wrap(listener, d3_array(arguments));
  1089. onRemove.call(this);
  1090. this.addEventListener(type, this[name] = l, l.$ = capture);
  1091. l._ = listener;
  1092. }
  1093. function removeAll() {
  1094. var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
  1095. for (var name in this) {
  1096. if (match = name.match(re)) {
  1097. var l = this[name];
  1098. this.removeEventListener(match[1], l, l.$);
  1099. delete this[name];
  1100. }
  1101. }
  1102. }
  1103. return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
  1104. }
  1105. var d3_selection_onFilters = d3.map({
  1106. mouseenter: "mouseover",
  1107. mouseleave: "mouseout"
  1108. });
  1109. if (d3_document) {
  1110. d3_selection_onFilters.forEach(function(k) {
  1111. if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
  1112. });
  1113. }
  1114. function d3_selection_onListener(listener, argumentz) {
  1115. return function(e) {
  1116. var o = d3.event;
  1117. d3.event = e;
  1118. argumentz[0] = this.__data__;
  1119. try {
  1120. listener.apply(this, argumentz);
  1121. } finally {
  1122. d3.event = o;
  1123. }
  1124. };
  1125. }
  1126. function d3_selection_onFilter(listener, argumentz) {
  1127. var l = d3_selection_onListener(listener, argumentz);
  1128. return function(e) {
  1129. var target = this, related = e.relatedTarget;
  1130. if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
  1131. l.call(target, e);
  1132. }
  1133. };
  1134. }
  1135. var d3_event_dragSelect, d3_event_dragId = 0;
  1136. function d3_event_dragSuppress(node) {
  1137. 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);
  1138. if (d3_event_dragSelect == null) {
  1139. d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
  1140. }
  1141. if (d3_event_dragSelect) {
  1142. var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
  1143. style[d3_event_dragSelect] = "none";
  1144. }
  1145. return function(suppressClick) {
  1146. w.on(name, null);
  1147. if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
  1148. if (suppressClick) {
  1149. var off = function() {
  1150. w.on(click, null);
  1151. };
  1152. w.on(click, function() {
  1153. d3_eventPreventDefault();
  1154. off();
  1155. }, true);
  1156. setTimeout(off, 0);
  1157. }
  1158. };
  1159. }
  1160. d3.mouse = function(container) {
  1161. return d3_mousePoint(container, d3_eventSource());
  1162. };
  1163. var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
  1164. function d3_mousePoint(container, e) {
  1165. if (e.changedTouches) e = e.changedTouches[0];
  1166. var svg = container.ownerSVGElement || container;
  1167. if (svg.createSVGPoint) {
  1168. var point = svg.createSVGPoint();
  1169. if (d3_mouse_bug44083 < 0) {
  1170. var window = d3_window(container);
  1171. if (window.scrollX || window.scrollY) {
  1172. svg = d3.select("body").append("svg").style({
  1173. position: "absolute",
  1174. top: 0,
  1175. left: 0,
  1176. margin: 0,
  1177. padding: 0,
  1178. border: "none"
  1179. }, "important");
  1180. var ctm = svg[0][0].getScreenCTM();
  1181. d3_mouse_bug44083 = !(ctm.f || ctm.e);
  1182. svg.remove();
  1183. }
  1184. }
  1185. if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
  1186. point.y = e.clientY;
  1187. point = point.matrixTransform(container.getScreenCTM().inverse());
  1188. return [ point.x, point.y ];
  1189. }
  1190. var rect = container.getBoundingClientRect();
  1191. return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
  1192. }
  1193. d3.touch = function(container, touches, identifier) {
  1194. if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
  1195. if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
  1196. if ((touch = touches[i]).identifier === identifier) {
  1197. return d3_mousePoint(container, touch);
  1198. }
  1199. }
  1200. };
  1201. d3.behavior.drag = function() {
  1202. 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");
  1203. function drag() {
  1204. this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
  1205. }
  1206. function dragstart(id, position, subject, move, end) {
  1207. return function() {
  1208. var that = this, target = d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
  1209. if (origin) {
  1210. dragOffset = origin.apply(that, arguments);
  1211. dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
  1212. } else {
  1213. dragOffset = [ 0, 0 ];
  1214. }
  1215. dispatch({
  1216. type: "dragstart"
  1217. });
  1218. function moved() {
  1219. var position1 = position(parent, dragId), dx, dy;
  1220. if (!position1) return;
  1221. dx = position1[0] - position0[0];
  1222. dy = position1[1] - position0[1];
  1223. dragged |= dx | dy;
  1224. position0 = position1;
  1225. dispatch({
  1226. type: "drag",
  1227. x: position1[0] + dragOffset[0],
  1228. y: position1[1] + dragOffset[1],
  1229. dx: dx,
  1230. dy: dy
  1231. });
  1232. }
  1233. function ended() {
  1234. if (!position(parent, dragId)) return;
  1235. dragSubject.on(move + dragName, null).on(end + dragName, null);
  1236. dragRestore(dragged && d3.event.target === target);
  1237. dispatch({
  1238. type: "dragend"
  1239. });
  1240. }
  1241. };
  1242. }
  1243. drag.origin = function(x) {
  1244. if (!arguments.length) return origin;
  1245. origin = x;
  1246. return drag;
  1247. };
  1248. return d3.rebind(drag, event, "on");
  1249. };
  1250. function d3_behavior_dragTouchId() {
  1251. return d3.event.changedTouches[0].identifier;
  1252. }
  1253. d3.touches = function(container, touches) {
  1254. if (arguments.length < 2) touches = d3_eventSource().touches;
  1255. return touches ? d3_array(touches).map(function(touch) {
  1256. var point = d3_mousePoint(container, touch);
  1257. point.identifier = touch.identifier;
  1258. return point;
  1259. }) : [];
  1260. };
  1261. var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
  1262. function d3_sgn(x) {
  1263. return x > 0 ? 1 : x < 0 ? -1 : 0;
  1264. }
  1265. function d3_cross2d(a, b, c) {
  1266. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  1267. }
  1268. function d3_acos(x) {
  1269. return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
  1270. }
  1271. function d3_asin(x) {
  1272. return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
  1273. }
  1274. function d3_sinh(x) {
  1275. return ((x = Math.exp(x)) - 1 / x) / 2;
  1276. }
  1277. function d3_cosh(x) {
  1278. return ((x = Math.exp(x)) + 1 / x) / 2;
  1279. }
  1280. function d3_tanh(x) {
  1281. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  1282. }
  1283. function d3_haversin(x) {
  1284. return (x = Math.sin(x / 2)) * x;
  1285. }
  1286. var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
  1287. d3.interpolateZoom = function(p0, p1) {
  1288. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
  1289. var dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, 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), dr = r1 - r0, S = (dr || Math.log(w1 / w0)) / ρ;
  1290. function interpolate(t) {
  1291. var s = t * S;
  1292. if (dr) {
  1293. var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
  1294. return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
  1295. }
  1296. return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
  1297. }
  1298. interpolate.duration = S * 1e3;
  1299. return interpolate;
  1300. };
  1301. d3.behavior.zoom = function() {
  1302. var view = {
  1303. x: 0,
  1304. y: 0,
  1305. k: 1
  1306. }, 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;
  1307. if (!d3_behavior_zoomWheel) {
  1308. d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1309. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  1310. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1311. return d3.event.wheelDelta;
  1312. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  1313. return -d3.event.detail;
  1314. }, "MozMousePixelScroll");
  1315. }
  1316. function zoom(g) {
  1317. g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
  1318. }
  1319. zoom.event = function(g) {
  1320. g.each(function() {
  1321. var dispatch = event.of(this, arguments), view1 = view;
  1322. if (d3_transitionInheritId) {
  1323. d3.select(this).transition().each("start.zoom", function() {
  1324. view = this.__chart__ || {
  1325. x: 0,
  1326. y: 0,
  1327. k: 1
  1328. };
  1329. zoomstarted(dispatch);
  1330. }).tween("zoom:zoom", function() {
  1331. 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 ]);
  1332. return function(t) {
  1333. var l = i(t), k = dx / l[2];
  1334. this.__chart__ = view = {
  1335. x: cx - l[0] * k,
  1336. y: cy - l[1] * k,
  1337. k: k
  1338. };
  1339. zoomed(dispatch);
  1340. };
  1341. }).each("interrupt.zoom", function() {
  1342. zoomended(dispatch);
  1343. }).each("end.zoom", function() {
  1344. zoomended(dispatch);
  1345. });
  1346. } else {
  1347. this.__chart__ = view;
  1348. zoomstarted(dispatch);
  1349. zoomed(dispatch);
  1350. zoomended(dispatch);
  1351. }
  1352. });
  1353. };
  1354. zoom.translate = function(_) {
  1355. if (!arguments.length) return [ view.x, view.y ];
  1356. view = {
  1357. x: +_[0],
  1358. y: +_[1],
  1359. k: view.k
  1360. };
  1361. rescale();
  1362. return zoom;
  1363. };
  1364. zoom.scale = function(_) {
  1365. if (!arguments.length) return view.k;
  1366. view = {
  1367. x: view.x,
  1368. y: view.y,
  1369. k: +_
  1370. };
  1371. rescale();
  1372. return zoom;
  1373. };
  1374. zoom.scaleExtent = function(_) {
  1375. if (!arguments.length) return scaleExtent;
  1376. scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
  1377. return zoom;
  1378. };
  1379. zoom.center = function(_) {
  1380. if (!arguments.length) return center;
  1381. center = _ && [ +_[0], +_[1] ];
  1382. return zoom;
  1383. };
  1384. zoom.size = function(_) {
  1385. if (!arguments.length) return size;
  1386. size = _ && [ +_[0], +_[1] ];
  1387. return zoom;
  1388. };
  1389. zoom.duration = function(_) {
  1390. if (!arguments.length) return duration;
  1391. duration = +_;
  1392. return zoom;
  1393. };
  1394. zoom.x = function(z) {
  1395. if (!arguments.length) return x1;
  1396. x1 = z;
  1397. x0 = z.copy();
  1398. view = {
  1399. x: 0,
  1400. y: 0,
  1401. k: 1
  1402. };
  1403. return zoom;
  1404. };
  1405. zoom.y = function(z) {
  1406. if (!arguments.length) return y1;
  1407. y1 = z;
  1408. y0 = z.copy();
  1409. view = {
  1410. x: 0,
  1411. y: 0,
  1412. k: 1
  1413. };
  1414. return zoom;
  1415. };
  1416. function location(p) {
  1417. return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
  1418. }
  1419. function point(l) {
  1420. return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
  1421. }
  1422. function scaleTo(s) {
  1423. view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  1424. }
  1425. function translateTo(p, l) {
  1426. l = point(l);
  1427. view.x += p[0] - l[0];
  1428. view.y += p[1] - l[1];
  1429. }
  1430. function zoomTo(that, p, l, k) {
  1431. that.__chart__ = {
  1432. x: view.x,
  1433. y: view.y,
  1434. k: view.k
  1435. };
  1436. scaleTo(Math.pow(2, k));
  1437. translateTo(center0 = p, l);
  1438. that = d3.select(that);
  1439. if (duration > 0) that = that.transition().duration(duration);
  1440. that.call(zoom.event);
  1441. }
  1442. function rescale() {
  1443. if (x1) x1.domain(x0.range().map(function(x) {
  1444. return (x - view.x) / view.k;
  1445. }).map(x0.invert));
  1446. if (y1) y1.domain(y0.range().map(function(y) {
  1447. return (y - view.y) / view.k;
  1448. }).map(y0.invert));
  1449. }
  1450. function zoomstarted(dispatch) {
  1451. if (!zooming++) dispatch({
  1452. type: "zoomstart"
  1453. });
  1454. }
  1455. function zoomed(dispatch) {
  1456. rescale();
  1457. dispatch({
  1458. type: "zoom",
  1459. scale: view.k,
  1460. translate: [ view.x, view.y ]
  1461. });
  1462. }
  1463. function zoomended(dispatch) {
  1464. if (!--zooming) dispatch({
  1465. type: "zoomend"
  1466. });
  1467. center0 = null;
  1468. }
  1469. function mousedowned() {
  1470. var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
  1471. d3_selection_interrupt.call(that);
  1472. zoomstarted(dispatch);
  1473. function moved() {
  1474. dragged = 1;
  1475. translateTo(d3.mouse(that), location0);
  1476. zoomed(dispatch);
  1477. }
  1478. function ended() {
  1479. subject.on(mousemove, null).on(mouseup, null);
  1480. dragRestore(dragged && d3.event.target === target);
  1481. zoomended(dispatch);
  1482. }
  1483. }
  1484. function touchstarted() {
  1485. 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);
  1486. started();
  1487. zoomstarted(dispatch);
  1488. subject.on(mousedown, null).on(touchstart, started);
  1489. function relocate() {
  1490. var touches = d3.touches(that);
  1491. scale0 = view.k;
  1492. touches.forEach(function(t) {
  1493. if (t.identifier in locations0) locations0[t.identifier] = location(t);
  1494. });
  1495. return touches;
  1496. }
  1497. function started() {
  1498. var target = d3.event.target;
  1499. d3.select(target).on(touchmove, moved).on(touchend, ended);
  1500. targets.push(target);
  1501. var changed = d3.event.changedTouches;
  1502. for (var i = 0, n = changed.length; i < n; ++i) {
  1503. locations0[changed[i].identifier] = null;
  1504. }
  1505. var touches = relocate(), now = Date.now();
  1506. if (touches.length === 1) {
  1507. if (now - touchtime < 500) {
  1508. var p = touches[0];
  1509. zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
  1510. d3_eventPreventDefault();
  1511. }
  1512. touchtime = now;
  1513. } else if (touches.length > 1) {
  1514. var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
  1515. distance0 = dx * dx + dy * dy;
  1516. }
  1517. }
  1518. function moved() {
  1519. var touches = d3.touches(that), p0, l0, p1, l1;
  1520. d3_selection_interrupt.call(that);
  1521. for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
  1522. p1 = touches[i];
  1523. if (l1 = locations0[p1.identifier]) {
  1524. if (l0) break;
  1525. p0 = p1, l0 = l1;
  1526. }
  1527. }
  1528. if (l1) {
  1529. var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
  1530. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  1531. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  1532. scaleTo(scale1 * scale0);
  1533. }
  1534. touchtime = null;
  1535. translateTo(p0, l0);
  1536. zoomed(dispatch);
  1537. }
  1538. function ended() {
  1539. if (d3.event.touches.length) {
  1540. var changed = d3.event.changedTouches;
  1541. for (var i = 0, n = changed.length; i < n; ++i) {
  1542. delete locations0[changed[i].identifier];
  1543. }
  1544. for (var identifier in locations0) {
  1545. return void relocate();
  1546. }
  1547. }
  1548. d3.selectAll(targets).on(zoomName, null);
  1549. subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
  1550. dragRestore();
  1551. zoomended(dispatch);
  1552. }
  1553. }
  1554. function mousewheeled() {
  1555. var dispatch = event.of(this, arguments);
  1556. if (mousewheelTimer) clearTimeout(mousewheelTimer); else translate0 = location(center0 = center || d3.mouse(this)),
  1557. d3_selection_interrupt.call(this), zoomstarted(dispatch);
  1558. mousewheelTimer = setTimeout(function() {
  1559. mousewheelTimer = null;
  1560. zoomended(dispatch);
  1561. }, 50);
  1562. d3_eventPreventDefault();
  1563. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
  1564. translateTo(center0, translate0);
  1565. zoomed(dispatch);
  1566. }
  1567. function dblclicked() {
  1568. var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
  1569. zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
  1570. }
  1571. return d3.rebind(zoom, event, "on");
  1572. };
  1573. var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
  1574. d3.color = d3_color;
  1575. function d3_color() {}
  1576. d3_color.prototype.toString = function() {
  1577. return this.rgb() + "";
  1578. };
  1579. d3.hsl = d3_hsl;
  1580. function d3_hsl(h, s, l) {
  1581. 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);
  1582. }
  1583. var d3_hslPrototype = d3_hsl.prototype = new d3_color();
  1584. d3_hslPrototype.brighter = function(k) {
  1585. k = Math.pow(.7, arguments.length ? k : 1);
  1586. return new d3_hsl(this.h, this.s, this.l / k);
  1587. };
  1588. d3_hslPrototype.darker = function(k) {
  1589. k = Math.pow(.7, arguments.length ? k : 1);
  1590. return new d3_hsl(this.h, this.s, k * this.l);
  1591. };
  1592. d3_hslPrototype.rgb = function() {
  1593. return d3_hsl_rgb(this.h, this.s, this.l);
  1594. };
  1595. function d3_hsl_rgb(h, s, l) {
  1596. var m1, m2;
  1597. h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
  1598. s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
  1599. l = l < 0 ? 0 : l > 1 ? 1 : l;
  1600. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  1601. m1 = 2 * l - m2;
  1602. function v(h) {
  1603. if (h > 360) h -= 360; else if (h < 0) h += 360;
  1604. if (h < 60) return m1 + (m2 - m1) * h / 60;
  1605. if (h < 180) return m2;
  1606. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  1607. return m1;
  1608. }
  1609. function vv(h) {
  1610. return Math.round(v(h) * 255);
  1611. }
  1612. return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  1613. }
  1614. d3.hcl = d3_hcl;
  1615. function d3_hcl(h, c, l) {
  1616. 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);
  1617. }
  1618. var d3_hclPrototype = d3_hcl.prototype = new d3_color();
  1619. d3_hclPrototype.brighter = function(k) {
  1620. return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  1621. };
  1622. d3_hclPrototype.darker = function(k) {
  1623. return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  1624. };
  1625. d3_hclPrototype.rgb = function() {
  1626. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  1627. };
  1628. function d3_hcl_lab(h, c, l) {
  1629. if (isNaN(h)) h = 0;
  1630. if (isNaN(c)) c = 0;
  1631. return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  1632. }
  1633. d3.lab = d3_lab;
  1634. function d3_lab(l, a, b) {
  1635. 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);
  1636. }
  1637. var d3_lab_K = 18;
  1638. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  1639. var d3_labPrototype = d3_lab.prototype = new d3_color();
  1640. d3_labPrototype.brighter = function(k) {
  1641. return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1642. };
  1643. d3_labPrototype.darker = function(k) {
  1644. return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1645. };
  1646. d3_labPrototype.rgb = function() {
  1647. return d3_lab_rgb(this.l, this.a, this.b);
  1648. };
  1649. function d3_lab_rgb(l, a, b) {
  1650. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  1651. x = d3_lab_xyz(x) * d3_lab_X;
  1652. y = d3_lab_xyz(y) * d3_lab_Y;
  1653. z = d3_lab_xyz(z) * d3_lab_Z;
  1654. 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));
  1655. }
  1656. function d3_lab_hcl(l, a, b) {
  1657. 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);
  1658. }
  1659. function d3_lab_xyz(x) {
  1660. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  1661. }
  1662. function d3_xyz_lab(x) {
  1663. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  1664. }
  1665. function d3_xyz_rgb(r) {
  1666. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  1667. }
  1668. d3.rgb = d3_rgb;
  1669. function d3_rgb(r, g, b) {
  1670. 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);
  1671. }
  1672. function d3_rgbNumber(value) {
  1673. return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
  1674. }
  1675. function d3_rgbString(value) {
  1676. return d3_rgbNumber(value) + "";
  1677. }
  1678. var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
  1679. d3_rgbPrototype.brighter = function(k) {
  1680. k = Math.pow(.7, arguments.length ? k : 1);
  1681. var r = this.r, g = this.g, b = this.b, i = 30;
  1682. if (!r && !g && !b) return new d3_rgb(i, i, i);
  1683. if (r && r < i) r = i;
  1684. if (g && g < i) g = i;
  1685. if (b && b < i) b = i;
  1686. return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
  1687. };
  1688. d3_rgbPrototype.darker = function(k) {
  1689. k = Math.pow(.7, arguments.length ? k : 1);
  1690. return new d3_rgb(k * this.r, k * this.g, k * this.b);
  1691. };
  1692. d3_rgbPrototype.hsl = function() {
  1693. return d3_rgb_hsl(this.r, this.g, this.b);
  1694. };
  1695. d3_rgbPrototype.toString = function() {
  1696. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  1697. };
  1698. function d3_rgb_hex(v) {
  1699. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  1700. }
  1701. function d3_rgb_parse(format, rgb, hsl) {
  1702. var r = 0, g = 0, b = 0, m1, m2, color;
  1703. m1 = /([a-z]+)\((.*)\)/i.exec(format);
  1704. if (m1) {
  1705. m2 = m1[2].split(",");
  1706. switch (m1[1]) {
  1707. case "hsl":
  1708. {
  1709. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  1710. }
  1711. case "rgb":
  1712. {
  1713. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  1714. }
  1715. }
  1716. }
  1717. if (color = d3_rgb_names.get(format.toLowerCase())) {
  1718. return rgb(color.r, color.g, color.b);
  1719. }
  1720. if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
  1721. if (format.length === 4) {
  1722. r = (color & 3840) >> 4;
  1723. r = r >> 4 | r;
  1724. g = color & 240;
  1725. g = g >> 4 | g;
  1726. b = color & 15;
  1727. b = b << 4 | b;
  1728. } else if (format.length === 7) {
  1729. r = (color & 16711680) >> 16;
  1730. g = (color & 65280) >> 8;
  1731. b = color & 255;
  1732. }
  1733. }
  1734. return rgb(r, g, b);
  1735. }
  1736. function d3_rgb_hsl(r, g, b) {
  1737. 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;
  1738. if (d) {
  1739. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  1740. 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;
  1741. h *= 60;
  1742. } else {
  1743. h = NaN;
  1744. s = l > 0 && l < 1 ? 0 : h;
  1745. }
  1746. return new d3_hsl(h, s, l);
  1747. }
  1748. function d3_rgb_lab(r, g, b) {
  1749. r = d3_rgb_xyz(r);
  1750. g = d3_rgb_xyz(g);
  1751. b = d3_rgb_xyz(b);
  1752. 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);
  1753. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  1754. }
  1755. function d3_rgb_xyz(r) {
  1756. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  1757. }
  1758. function d3_rgb_parseNumber(c) {
  1759. var f = parseFloat(c);
  1760. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  1761. }
  1762. var d3_rgb_names = d3.map({
  1763. aliceblue: 15792383,
  1764. antiquewhite: 16444375,
  1765. aqua: 65535,
  1766. aquamarine: 8388564,
  1767. azure: 15794175,
  1768. beige: 16119260,
  1769. bisque: 16770244,
  1770. black: 0,
  1771. blanchedalmond: 16772045,
  1772. blue: 255,
  1773. blueviolet: 9055202,
  1774. brown: 10824234,
  1775. burlywood: 14596231,
  1776. cadetblue: 6266528,
  1777. chartreuse: 8388352,
  1778. chocolate: 13789470,
  1779. coral: 16744272,
  1780. cornflowerblue: 6591981,
  1781. cornsilk: 16775388,
  1782. crimson: 14423100,
  1783. cyan: 65535,
  1784. darkblue: 139,
  1785. darkcyan: 35723,
  1786. darkgoldenrod: 12092939,
  1787. darkgray: 11119017,
  1788. darkgreen: 25600,
  1789. darkgrey: 11119017,
  1790. darkkhaki: 12433259,
  1791. darkmagenta: 9109643,
  1792. darkolivegreen: 5597999,
  1793. darkorange: 16747520,
  1794. darkorchid: 10040012,
  1795. darkred: 9109504,
  1796. darksalmon: 15308410,
  1797. darkseagreen: 9419919,
  1798. darkslateblue: 4734347,
  1799. darkslategray: 3100495,
  1800. darkslategrey: 3100495,
  1801. darkturquoise: 52945,
  1802. darkviolet: 9699539,
  1803. deeppink: 16716947,
  1804. deepskyblue: 49151,
  1805. dimgray: 6908265,
  1806. dimgrey: 6908265,
  1807. dodgerblue: 2003199,
  1808. firebrick: 11674146,
  1809. floralwhite: 16775920,
  1810. forestgreen: 2263842,
  1811. fuchsia: 16711935,
  1812. gainsboro: 14474460,
  1813. ghostwhite: 16316671,
  1814. gold: 16766720,
  1815. goldenrod: 14329120,
  1816. gray: 8421504,
  1817. green: 32768,
  1818. greenyellow: 11403055,
  1819. grey: 8421504,
  1820. honeydew: 15794160,
  1821. hotpink: 16738740,
  1822. indianred: 13458524,
  1823. indigo: 4915330,
  1824. ivory: 16777200,
  1825. khaki: 15787660,
  1826. lavender: 15132410,
  1827. lavenderblush: 16773365,
  1828. lawngreen: 8190976,
  1829. lemonchiffon: 16775885,
  1830. lightblue: 11393254,
  1831. lightcoral: 15761536,
  1832. lightcyan: 14745599,
  1833. lightgoldenrodyellow: 16448210,
  1834. lightgray: 13882323,
  1835. lightgreen: 9498256,
  1836. lightgrey: 13882323,
  1837. lightpink: 16758465,
  1838. lightsalmon: 16752762,
  1839. lightseagreen: 2142890,
  1840. lightskyblue: 8900346,
  1841. lightslategray: 7833753,
  1842. lightslategrey: 7833753,
  1843. lightsteelblue: 11584734,
  1844. lightyellow: 16777184,
  1845. lime: 65280,
  1846. limegreen: 3329330,
  1847. linen: 16445670,
  1848. magenta: 16711935,
  1849. maroon: 8388608,
  1850. mediumaquamarine: 6737322,
  1851. mediumblue: 205,
  1852. mediumorchid: 12211667,
  1853. mediumpurple: 9662683,
  1854. mediumseagreen: 3978097,
  1855. mediumslateblue: 8087790,
  1856. mediumspringgreen: 64154,
  1857. mediumturquoise: 4772300,
  1858. mediumvioletred: 13047173,
  1859. midnightblue: 1644912,
  1860. mintcream: 16121850,
  1861. mistyrose: 16770273,
  1862. moccasin: 16770229,
  1863. navajowhite: 16768685,
  1864. navy: 128,
  1865. oldlace: 16643558,
  1866. olive: 8421376,
  1867. olivedrab: 7048739,
  1868. orange: 16753920,
  1869. orangered: 16729344,
  1870. orchid: 14315734,
  1871. palegoldenrod: 15657130,
  1872. palegreen: 10025880,
  1873. paleturquoise: 11529966,
  1874. palevioletred: 14381203,
  1875. papayawhip: 16773077,
  1876. peachpuff: 16767673,
  1877. peru: 13468991,
  1878. pink: 16761035,
  1879. plum: 14524637,
  1880. powderblue: 11591910,
  1881. purple: 8388736,
  1882. rebeccapurple: 6697881,
  1883. red: 16711680,
  1884. rosybrown: 12357519,
  1885. royalblue: 4286945,
  1886. saddlebrown: 9127187,
  1887. salmon: 16416882,
  1888. sandybrown: 16032864,
  1889. seagreen: 3050327,
  1890. seashell: 16774638,
  1891. sienna: 10506797,
  1892. silver: 12632256,
  1893. skyblue: 8900331,
  1894. slateblue: 6970061,
  1895. slategray: 7372944,
  1896. slategrey: 7372944,
  1897. snow: 16775930,
  1898. springgreen: 65407,
  1899. steelblue: 4620980,
  1900. tan: 13808780,
  1901. teal: 32896,
  1902. thistle: 14204888,
  1903. tomato: 16737095,
  1904. turquoise: 4251856,
  1905. violet: 15631086,
  1906. wheat: 16113331,
  1907. white: 16777215,
  1908. whitesmoke: 16119285,
  1909. yellow: 16776960,
  1910. yellowgreen: 10145074
  1911. });
  1912. d3_rgb_names.forEach(function(key, value) {
  1913. d3_rgb_names.set(key, d3_rgbNumber(value));
  1914. });
  1915. function d3_functor(v) {
  1916. return typeof v === "function" ? v : function() {
  1917. return v;
  1918. };
  1919. }
  1920. d3.functor = d3_functor;
  1921. d3.xhr = d3_xhrType(d3_identity);
  1922. function d3_xhrType(response) {
  1923. return function(url, mimeType, callback) {
  1924. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  1925. mimeType = null;
  1926. return d3_xhr(url, mimeType, response, callback);
  1927. };
  1928. }
  1929. function d3_xhr(url, mimeType, response, callback) {
  1930. var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
  1931. if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
  1932. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  1933. request.readyState > 3 && respond();
  1934. };
  1935. function respond() {
  1936. var status = request.status, result;
  1937. if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
  1938. try {
  1939. result = response.call(xhr, request);
  1940. } catch (e) {
  1941. dispatch.error.call(xhr, e);
  1942. return;
  1943. }
  1944. dispatch.load.call(xhr, result);
  1945. } else {
  1946. dispatch.error.call(xhr, request);
  1947. }
  1948. }
  1949. request.onprogress = function(event) {
  1950. var o = d3.event;
  1951. d3.event = event;
  1952. try {
  1953. dispatch.progress.call(xhr, request);
  1954. } finally {
  1955. d3.event = o;
  1956. }
  1957. };
  1958. xhr.header = function(name, value) {
  1959. name = (name + "").toLowerCase();
  1960. if (arguments.length < 2) return headers[name];
  1961. if (value == null) delete headers[name]; else headers[name] = value + "";
  1962. return xhr;
  1963. };
  1964. xhr.mimeType = function(value) {
  1965. if (!arguments.length) return mimeType;
  1966. mimeType = value == null ? null : value + "";
  1967. return xhr;
  1968. };
  1969. xhr.responseType = function(value) {
  1970. if (!arguments.length) return responseType;
  1971. responseType = value;
  1972. return xhr;
  1973. };
  1974. xhr.response = function(value) {
  1975. response = value;
  1976. return xhr;
  1977. };
  1978. [ "get", "post" ].forEach(function(method) {
  1979. xhr[method] = function() {
  1980. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  1981. };
  1982. });
  1983. xhr.send = function(method, data, callback) {
  1984. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  1985. request.open(method, url, true);
  1986. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  1987. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  1988. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  1989. if (responseType != null) request.responseType = responseType;
  1990. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  1991. callback(null, request);
  1992. });
  1993. dispatch.beforesend.call(xhr, request);
  1994. request.send(data == null ? null : data);
  1995. return xhr;
  1996. };
  1997. xhr.abort = function() {
  1998. request.abort();
  1999. return xhr;
  2000. };
  2001. d3.rebind(xhr, dispatch, "on");
  2002. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  2003. }
  2004. function d3_xhr_fixCallback(callback) {
  2005. return callback.length === 1 ? function(error, request) {
  2006. callback(error == null ? request : null);
  2007. } : callback;
  2008. }
  2009. function d3_xhrHasResponse(request) {
  2010. var type = request.responseType;
  2011. return type && type !== "text" ? request.response : request.responseText;
  2012. }
  2013. d3.dsv = function(delimiter, mimeType) {
  2014. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  2015. function dsv(url, row, callback) {
  2016. if (arguments.length < 3) callback = row, row = null;
  2017. var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
  2018. xhr.row = function(_) {
  2019. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  2020. };
  2021. return xhr;
  2022. }
  2023. function response(request) {
  2024. return dsv.parse(request.responseText);
  2025. }
  2026. function typedResponse(f) {
  2027. return function(request) {
  2028. return dsv.parse(request.responseText, f);
  2029. };
  2030. }
  2031. dsv.parse = function(text, f) {
  2032. var o;
  2033. return dsv.parseRows(text, function(row, i) {
  2034. if (o) return o(row, i - 1);
  2035. var a = new Function("d", "return {" + row.map(function(name, i) {
  2036. return JSON.stringify(name) + ": d[" + i + "]";
  2037. }).join(",") + "}");
  2038. o = f ? function(row, i) {
  2039. return f(a(row), i);
  2040. } : a;
  2041. });
  2042. };
  2043. dsv.parseRows = function(text, f) {
  2044. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  2045. function token() {
  2046. if (I >= N) return EOF;
  2047. if (eol) return eol = false, EOL;
  2048. var j = I;
  2049. if (text.charCodeAt(j) === 34) {
  2050. var i = j;
  2051. while (i++ < N) {
  2052. if (text.charCodeAt(i) === 34) {
  2053. if (text.charCodeAt(i + 1) !== 34) break;
  2054. ++i;
  2055. }
  2056. }
  2057. I = i + 2;
  2058. var c = text.charCodeAt(i + 1);
  2059. if (c === 13) {
  2060. eol = true;
  2061. if (text.charCodeAt(i + 2) === 10) ++I;
  2062. } else if (c === 10) {
  2063. eol = true;
  2064. }
  2065. return text.slice(j + 1, i).replace(/""/g, '"');
  2066. }
  2067. while (I < N) {
  2068. var c = text.charCodeAt(I++), k = 1;
  2069. if (c === 10) eol = true; else if (c === 13) {
  2070. eol = true;
  2071. if (text.charCodeAt(I) === 10) ++I, ++k;
  2072. } else if (c !== delimiterCode) continue;
  2073. return text.slice(j, I - k);
  2074. }
  2075. return text.slice(j);
  2076. }
  2077. while ((t = token()) !== EOF) {
  2078. var a = [];
  2079. while (t !== EOL && t !== EOF) {
  2080. a.push(t);
  2081. t = token();
  2082. }
  2083. if (f && (a = f(a, n++)) == null) continue;
  2084. rows.push(a);
  2085. }
  2086. return rows;
  2087. };
  2088. dsv.format = function(rows) {
  2089. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  2090. var fieldSet = new d3_Set(), fields = [];
  2091. rows.forEach(function(row) {
  2092. for (var field in row) {
  2093. if (!fieldSet.has(field)) {
  2094. fields.push(fieldSet.add(field));
  2095. }
  2096. }
  2097. });
  2098. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  2099. return fields.map(function(field) {
  2100. return formatValue(row[field]);
  2101. }).join(delimiter);
  2102. })).join("\n");
  2103. };
  2104. dsv.formatRows = function(rows) {
  2105. return rows.map(formatRow).join("\n");
  2106. };
  2107. function formatRow(row) {
  2108. return row.map(formatValue).join(delimiter);
  2109. }
  2110. function formatValue(text) {
  2111. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  2112. }
  2113. return dsv;
  2114. };
  2115. d3.csv = d3.dsv(",", "text/csv");
  2116. d3.tsv = d3.dsv(" ", "text/tab-separated-values");
  2117. var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_active, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
  2118. setTimeout(callback, 17);
  2119. };
  2120. d3.timer = function(callback, delay, then) {
  2121. var n = arguments.length;
  2122. if (n < 2) delay = 0;
  2123. if (n < 3) then = Date.now();
  2124. var time = then + delay, timer = {
  2125. c: callback,
  2126. t: time,
  2127. f: false,
  2128. n: null
  2129. };
  2130. if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
  2131. d3_timer_queueTail = timer;
  2132. if (!d3_timer_interval) {
  2133. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  2134. d3_timer_interval = 1;
  2135. d3_timer_frame(d3_timer_step);
  2136. }
  2137. };
  2138. function d3_timer_step() {
  2139. var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
  2140. if (delay > 24) {
  2141. if (isFinite(delay)) {
  2142. clearTimeout(d3_timer_timeout);
  2143. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  2144. }
  2145. d3_timer_interval = 0;
  2146. } else {
  2147. d3_timer_interval = 1;
  2148. d3_timer_frame(d3_timer_step);
  2149. }
  2150. }
  2151. d3.timer.flush = function() {
  2152. d3_timer_mark();
  2153. d3_timer_sweep();
  2154. };
  2155. function d3_timer_mark() {
  2156. var now = Date.now();
  2157. d3_timer_active = d3_timer_queueHead;
  2158. while (d3_timer_active) {
  2159. if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
  2160. d3_timer_active = d3_timer_active.n;
  2161. }
  2162. return now;
  2163. }
  2164. function d3_timer_sweep() {
  2165. var t0, t1 = d3_timer_queueHead, time = Infinity;
  2166. while (t1) {
  2167. if (t1.f) {
  2168. t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
  2169. } else {
  2170. if (t1.t < time) time = t1.t;
  2171. t1 = (t0 = t1).n;
  2172. }
  2173. }
  2174. d3_timer_queueTail = t0;
  2175. return time;
  2176. }
  2177. function d3_format_precision(x, p) {
  2178. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  2179. }
  2180. d3.round = function(x, n) {
  2181. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  2182. };
  2183. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  2184. d3.formatPrefix = function(value, precision) {
  2185. var i = 0;
  2186. if (value) {
  2187. if (value < 0) value *= -1;
  2188. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  2189. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  2190. i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
  2191. }
  2192. return d3_formatPrefixes[8 + i / 3];
  2193. };
  2194. function d3_formatPrefix(d, i) {
  2195. var k = Math.pow(10, abs(8 - i) * 3);
  2196. return {
  2197. scale: i > 8 ? function(d) {
  2198. return d / k;
  2199. } : function(d) {
  2200. return d * k;
  2201. },
  2202. symbol: d
  2203. };
  2204. }
  2205. function d3_locale_numberFormat(locale) {
  2206. 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) {
  2207. var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
  2208. while (i > 0 && g > 0) {
  2209. if (length + g + 1 > width) g = Math.max(1, width - length);
  2210. t.push(value.substring(i -= g, i + g));
  2211. if ((length += g + 1) > width) break;
  2212. g = locale_grouping[j = (j + 1) % locale_grouping.length];
  2213. }
  2214. return t.reverse().join(locale_thousands);
  2215. } : d3_identity;
  2216. return function(specifier) {
  2217. 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;
  2218. if (precision) precision = +precision.substring(1);
  2219. if (zfill || fill === "0" && align === "=") {
  2220. zfill = fill = "0";
  2221. align = "=";
  2222. }
  2223. switch (type) {
  2224. case "n":
  2225. comma = true;
  2226. type = "g";
  2227. break;
  2228. case "%":
  2229. scale = 100;
  2230. suffix = "%";
  2231. type = "f";
  2232. break;
  2233. case "p":
  2234. scale = 100;
  2235. suffix = "%";
  2236. type = "r";
  2237. break;
  2238. case "b":
  2239. case "o":
  2240. case "x":
  2241. case "X":
  2242. if (symbol === "#") prefix = "0" + type.toLowerCase();
  2243. case "c":
  2244. exponent = false;
  2245. case "d":
  2246. integer = true;
  2247. precision = 0;
  2248. break;
  2249. case "s":
  2250. scale = -1;
  2251. type = "r";
  2252. break;
  2253. }
  2254. if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
  2255. if (type == "r" && !precision) type = "g";
  2256. if (precision != null) {
  2257. 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));
  2258. }
  2259. type = d3_format_types.get(type) || d3_format_typeDefault;
  2260. var zcomma = zfill && comma;
  2261. return function(value) {
  2262. var fullSuffix = suffix;
  2263. if (integer && value % 1) return "";
  2264. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
  2265. if (scale < 0) {
  2266. var unit = d3.formatPrefix(value, precision);
  2267. value = unit.scale(value);
  2268. fullSuffix = unit.symbol + suffix;
  2269. } else {
  2270. value *= scale;
  2271. }
  2272. value = type(value, precision);
  2273. var i = value.lastIndexOf("."), before, after;
  2274. if (i < 0) {
  2275. var j = exponent ? value.lastIndexOf("e") : -1;
  2276. if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
  2277. } else {
  2278. before = value.substring(0, i);
  2279. after = locale_decimal + value.substring(i + 1);
  2280. }
  2281. if (!zfill && comma) before = formatGroup(before, Infinity);
  2282. var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  2283. if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
  2284. negative += prefix;
  2285. value = before + after;
  2286. 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;
  2287. };
  2288. };
  2289. }
  2290. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  2291. var d3_format_types = d3.map({
  2292. b: function(x) {
  2293. return x.toString(2);
  2294. },
  2295. c: function(x) {
  2296. return String.fromCharCode(x);
  2297. },
  2298. o: function(x) {
  2299. return x.toString(8);
  2300. },
  2301. x: function(x) {
  2302. return x.toString(16);
  2303. },
  2304. X: function(x) {
  2305. return x.toString(16).toUpperCase();
  2306. },
  2307. g: function(x, p) {
  2308. return x.toPrecision(p);
  2309. },
  2310. e: function(x, p) {
  2311. return x.toExponential(p);
  2312. },
  2313. f: function(x, p) {
  2314. return x.toFixed(p);
  2315. },
  2316. r: function(x, p) {
  2317. 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))));
  2318. }
  2319. });
  2320. function d3_format_typeDefault(x) {
  2321. return x + "";
  2322. }
  2323. var d3_time = d3.time = {}, d3_date = Date;
  2324. function d3_date_utc() {
  2325. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  2326. }
  2327. d3_date_utc.prototype = {
  2328. getDate: function() {
  2329. return this._.getUTCDate();
  2330. },
  2331. getDay: function() {
  2332. return this._.getUTCDay();
  2333. },
  2334. getFullYear: function() {
  2335. return this._.getUTCFullYear();
  2336. },
  2337. getHours: function() {
  2338. return this._.getUTCHours();
  2339. },
  2340. getMilliseconds: function() {
  2341. return this._.getUTCMilliseconds();
  2342. },
  2343. getMinutes: function() {
  2344. return this._.getUTCMinutes();
  2345. },
  2346. getMonth: function() {
  2347. return this._.getUTCMonth();
  2348. },
  2349. getSeconds: function() {
  2350. return this._.getUTCSeconds();
  2351. },
  2352. getTime: function() {
  2353. return this._.getTime();
  2354. },
  2355. getTimezoneOffset: function() {
  2356. return 0;
  2357. },
  2358. valueOf: function() {
  2359. return this._.valueOf();
  2360. },
  2361. setDate: function() {
  2362. d3_time_prototype.setUTCDate.apply(this._, arguments);
  2363. },
  2364. setDay: function() {
  2365. d3_time_prototype.setUTCDay.apply(this._, arguments);
  2366. },
  2367. setFullYear: function() {
  2368. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  2369. },
  2370. setHours: function() {
  2371. d3_time_prototype.setUTCHours.apply(this._, arguments);
  2372. },
  2373. setMilliseconds: function() {
  2374. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  2375. },
  2376. setMinutes: function() {
  2377. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  2378. },
  2379. setMonth: function() {
  2380. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  2381. },
  2382. setSeconds: function() {
  2383. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  2384. },
  2385. setTime: function() {
  2386. d3_time_prototype.setTime.apply(this._, arguments);
  2387. }
  2388. };
  2389. var d3_time_prototype = Date.prototype;
  2390. function d3_time_interval(local, step, number) {
  2391. function round(date) {
  2392. var d0 = local(date), d1 = offset(d0, 1);
  2393. return date - d0 < d1 - date ? d0 : d1;
  2394. }
  2395. function ceil(date) {
  2396. step(date = local(new d3_date(date - 1)), 1);
  2397. return date;
  2398. }
  2399. function offset(date, k) {
  2400. step(date = new d3_date(+date), k);
  2401. return date;
  2402. }
  2403. function range(t0, t1, dt) {
  2404. var time = ceil(t0), times = [];
  2405. if (dt > 1) {
  2406. while (time < t1) {
  2407. if (!(number(time) % dt)) times.push(new Date(+time));
  2408. step(time, 1);
  2409. }
  2410. } else {
  2411. while (time < t1) times.push(new Date(+time)), step(time, 1);
  2412. }
  2413. return times;
  2414. }
  2415. function range_utc(t0, t1, dt) {
  2416. try {
  2417. d3_date = d3_date_utc;
  2418. var utc = new d3_date_utc();
  2419. utc._ = t0;
  2420. return range(utc, t1, dt);
  2421. } finally {
  2422. d3_date = Date;
  2423. }
  2424. }
  2425. local.floor = local;
  2426. local.round = round;
  2427. local.ceil = ceil;
  2428. local.offset = offset;
  2429. local.range = range;
  2430. var utc = local.utc = d3_time_interval_utc(local);
  2431. utc.floor = utc;
  2432. utc.round = d3_time_interval_utc(round);
  2433. utc.ceil = d3_time_interval_utc(ceil);
  2434. utc.offset = d3_time_interval_utc(offset);
  2435. utc.range = range_utc;
  2436. return local;
  2437. }
  2438. function d3_time_interval_utc(method) {
  2439. return function(date, k) {
  2440. try {
  2441. d3_date = d3_date_utc;
  2442. var utc = new d3_date_utc();
  2443. utc._ = date;
  2444. return method(utc, k)._;
  2445. } finally {
  2446. d3_date = Date;
  2447. }
  2448. };
  2449. }
  2450. d3_time.year = d3_time_interval(function(date) {
  2451. date = d3_time.day(date);
  2452. date.setMonth(0, 1);
  2453. return date;
  2454. }, function(date, offset) {
  2455. date.setFullYear(date.getFullYear() + offset);
  2456. }, function(date) {
  2457. return date.getFullYear();
  2458. });
  2459. d3_time.years = d3_time.year.range;
  2460. d3_time.years.utc = d3_time.year.utc.range;
  2461. d3_time.day = d3_time_interval(function(date) {
  2462. var day = new d3_date(2e3, 0);
  2463. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  2464. return day;
  2465. }, function(date, offset) {
  2466. date.setDate(date.getDate() + offset);
  2467. }, function(date) {
  2468. return date.getDate() - 1;
  2469. });
  2470. d3_time.days = d3_time.day.range;
  2471. d3_time.days.utc = d3_time.day.utc.range;
  2472. d3_time.dayOfYear = function(date) {
  2473. var year = d3_time.year(date);
  2474. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  2475. };
  2476. [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
  2477. i = 7 - i;
  2478. var interval = d3_time[day] = d3_time_interval(function(date) {
  2479. (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  2480. return date;
  2481. }, function(date, offset) {
  2482. date.setDate(date.getDate() + Math.floor(offset) * 7);
  2483. }, function(date) {
  2484. var day = d3_time.year(date).getDay();
  2485. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  2486. });
  2487. d3_time[day + "s"] = interval.range;
  2488. d3_time[day + "s"].utc = interval.utc.range;
  2489. d3_time[day + "OfYear"] = function(date) {
  2490. var day = d3_time.year(date).getDay();
  2491. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
  2492. };
  2493. });
  2494. d3_time.week = d3_time.sunday;
  2495. d3_time.weeks = d3_time.sunday.range;
  2496. d3_time.weeks.utc = d3_time.sunday.utc.range;
  2497. d3_time.weekOfYear = d3_time.sundayOfYear;
  2498. function d3_locale_timeFormat(locale) {
  2499. 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;
  2500. function d3_time_format(template) {
  2501. var n = template.length;
  2502. function format(date) {
  2503. var string = [], i = -1, j = 0, c, p, f;
  2504. while (++i < n) {
  2505. if (template.charCodeAt(i) === 37) {
  2506. string.push(template.slice(j, i));
  2507. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  2508. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  2509. string.push(c);
  2510. j = i + 1;
  2511. }
  2512. }
  2513. string.push(template.slice(j, i));
  2514. return string.join("");
  2515. }
  2516. format.parse = function(string) {
  2517. var d = {
  2518. y: 1900,
  2519. m: 0,
  2520. d: 1,
  2521. H: 0,
  2522. M: 0,
  2523. S: 0,
  2524. L: 0,
  2525. Z: null
  2526. }, i = d3_time_parse(d, template, string, 0);
  2527. if (i != string.length) return null;
  2528. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  2529. var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
  2530. if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
  2531. date.setFullYear(d.y, 0, 1);
  2532. 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);
  2533. } else date.setFullYear(d.y, d.m, d.d);
  2534. date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
  2535. return localZ ? date._ : date;
  2536. };
  2537. format.toString = function() {
  2538. return template;
  2539. };
  2540. return format;
  2541. }
  2542. function d3_time_parse(date, template, string, j) {
  2543. var c, p, t, i = 0, n = template.length, m = string.length;
  2544. while (i < n) {
  2545. if (j >= m) return -1;
  2546. c = template.charCodeAt(i++);
  2547. if (c === 37) {
  2548. t = template.charAt(i++);
  2549. p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
  2550. if (!p || (j = p(date, string, j)) < 0) return -1;
  2551. } else if (c != string.charCodeAt(j++)) {
  2552. return -1;
  2553. }
  2554. }
  2555. return j;
  2556. }
  2557. d3_time_format.utc = function(template) {
  2558. var local = d3_time_format(template);
  2559. function format(date) {
  2560. try {
  2561. d3_date = d3_date_utc;
  2562. var utc = new d3_date();
  2563. utc._ = date;
  2564. return local(utc);
  2565. } finally {
  2566. d3_date = Date;
  2567. }
  2568. }
  2569. format.parse = function(string) {
  2570. try {
  2571. d3_date = d3_date_utc;
  2572. var date = local.parse(string);
  2573. return date && date._;
  2574. } finally {
  2575. d3_date = Date;
  2576. }
  2577. };
  2578. format.toString = local.toString;
  2579. return format;
  2580. };
  2581. d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
  2582. 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);
  2583. locale_periods.forEach(function(p, i) {
  2584. d3_time_periodLookup.set(p.toLowerCase(), i);
  2585. });
  2586. var d3_time_formats = {
  2587. a: function(d) {
  2588. return locale_shortDays[d.getDay()];
  2589. },
  2590. A: function(d) {
  2591. return locale_days[d.getDay()];
  2592. },
  2593. b: function(d) {
  2594. return locale_shortMonths[d.getMonth()];
  2595. },
  2596. B: function(d) {
  2597. return locale_months[d.getMonth()];
  2598. },
  2599. c: d3_time_format(locale_dateTime),
  2600. d: function(d, p) {
  2601. return d3_time_formatPad(d.getDate(), p, 2);
  2602. },
  2603. e: function(d, p) {
  2604. return d3_time_formatPad(d.getDate(), p, 2);
  2605. },
  2606. H: function(d, p) {
  2607. return d3_time_formatPad(d.getHours(), p, 2);
  2608. },
  2609. I: function(d, p) {
  2610. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  2611. },
  2612. j: function(d, p) {
  2613. return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
  2614. },
  2615. L: function(d, p) {
  2616. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  2617. },
  2618. m: function(d, p) {
  2619. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  2620. },
  2621. M: function(d, p) {
  2622. return d3_time_formatPad(d.getMinutes(), p, 2);
  2623. },
  2624. p: function(d) {
  2625. return locale_periods[+(d.getHours() >= 12)];
  2626. },
  2627. S: function(d, p) {
  2628. return d3_time_formatPad(d.getSeconds(), p, 2);
  2629. },
  2630. U: function(d, p) {
  2631. return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
  2632. },
  2633. w: function(d) {
  2634. return d.getDay();
  2635. },
  2636. W: function(d, p) {
  2637. return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
  2638. },
  2639. x: d3_time_format(locale_date),
  2640. X: d3_time_format(locale_time),
  2641. y: function(d, p) {
  2642. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  2643. },
  2644. Y: function(d, p) {
  2645. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  2646. },
  2647. Z: d3_time_zone,
  2648. "%": function() {
  2649. return "%";
  2650. }
  2651. };
  2652. var d3_time_parsers = {
  2653. a: d3_time_parseWeekdayAbbrev,
  2654. A: d3_time_parseWeekday,
  2655. b: d3_time_parseMonthAbbrev,
  2656. B: d3_time_parseMonth,
  2657. c: d3_time_parseLocaleFull,
  2658. d: d3_time_parseDay,
  2659. e: d3_time_parseDay,
  2660. H: d3_time_parseHour24,
  2661. I: d3_time_parseHour24,
  2662. j: d3_time_parseDayOfYear,
  2663. L: d3_time_parseMilliseconds,
  2664. m: d3_time_parseMonthNumber,
  2665. M: d3_time_parseMinutes,
  2666. p: d3_time_parseAmPm,
  2667. S: d3_time_parseSeconds,
  2668. U: d3_time_parseWeekNumberSunday,
  2669. w: d3_time_parseWeekdayNumber,
  2670. W: d3_time_parseWeekNumberMonday,
  2671. x: d3_time_parseLocaleDate,
  2672. X: d3_time_parseLocaleTime,
  2673. y: d3_time_parseYear,
  2674. Y: d3_time_parseFullYear,
  2675. Z: d3_time_parseZone,
  2676. "%": d3_time_parseLiteralPercent
  2677. };
  2678. function d3_time_parseWeekdayAbbrev(date, string, i) {
  2679. d3_time_dayAbbrevRe.lastIndex = 0;
  2680. var n = d3_time_dayAbbrevRe.exec(string.slice(i));
  2681. return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2682. }
  2683. function d3_time_parseWeekday(date, string, i) {
  2684. d3_time_dayRe.lastIndex = 0;
  2685. var n = d3_time_dayRe.exec(string.slice(i));
  2686. return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2687. }
  2688. function d3_time_parseMonthAbbrev(date, string, i) {
  2689. d3_time_monthAbbrevRe.lastIndex = 0;
  2690. var n = d3_time_monthAbbrevRe.exec(string.slice(i));
  2691. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2692. }
  2693. function d3_time_parseMonth(date, string, i) {
  2694. d3_time_monthRe.lastIndex = 0;
  2695. var n = d3_time_monthRe.exec(string.slice(i));
  2696. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2697. }
  2698. function d3_time_parseLocaleFull(date, string, i) {
  2699. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  2700. }
  2701. function d3_time_parseLocaleDate(date, string, i) {
  2702. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  2703. }
  2704. function d3_time_parseLocaleTime(date, string, i) {
  2705. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  2706. }
  2707. function d3_time_parseAmPm(date, string, i) {
  2708. var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
  2709. return n == null ? -1 : (date.p = n, i);
  2710. }
  2711. return d3_time_format;
  2712. }
  2713. var d3_time_formatPads = {
  2714. "-": "",
  2715. _: " ",
  2716. "0": "0"
  2717. }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
  2718. function d3_time_formatPad(value, fill, width) {
  2719. var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
  2720. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  2721. }
  2722. function d3_time_formatRe(names) {
  2723. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  2724. }
  2725. function d3_time_formatLookup(names) {
  2726. var map = new d3_Map(), i = -1, n = names.length;
  2727. while (++i < n) map.set(names[i].toLowerCase(), i);
  2728. return map;
  2729. }
  2730. function d3_time_parseWeekdayNumber(date, string, i) {
  2731. d3_time_numberRe.lastIndex = 0;
  2732. var n = d3_time_numberRe.exec(string.slice(i, i + 1));
  2733. return n ? (date.w = +n[0], i + n[0].length) : -1;
  2734. }
  2735. function d3_time_parseWeekNumberSunday(date, string, i) {
  2736. d3_time_numberRe.lastIndex = 0;
  2737. var n = d3_time_numberRe.exec(string.slice(i));
  2738. return n ? (date.U = +n[0], i + n[0].length) : -1;
  2739. }
  2740. function d3_time_parseWeekNumberMonday(date, string, i) {
  2741. d3_time_numberRe.lastIndex = 0;
  2742. var n = d3_time_numberRe.exec(string.slice(i));
  2743. return n ? (date.W = +n[0], i + n[0].length) : -1;
  2744. }
  2745. function d3_time_parseFullYear(date, string, i) {
  2746. d3_time_numberRe.lastIndex = 0;
  2747. var n = d3_time_numberRe.exec(string.slice(i, i + 4));
  2748. return n ? (date.y = +n[0], i + n[0].length) : -1;
  2749. }
  2750. function d3_time_parseYear(date, string, i) {
  2751. d3_time_numberRe.lastIndex = 0;
  2752. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2753. return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
  2754. }
  2755. function d3_time_parseZone(date, string, i) {
  2756. return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
  2757. i + 5) : -1;
  2758. }
  2759. function d3_time_expandYear(d) {
  2760. return d + (d > 68 ? 1900 : 2e3);
  2761. }
  2762. function d3_time_parseMonthNumber(date, string, i) {
  2763. d3_time_numberRe.lastIndex = 0;
  2764. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2765. return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
  2766. }
  2767. function d3_time_parseDay(date, string, i) {
  2768. d3_time_numberRe.lastIndex = 0;
  2769. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2770. return n ? (date.d = +n[0], i + n[0].length) : -1;
  2771. }
  2772. function d3_time_parseDayOfYear(date, string, i) {
  2773. d3_time_numberRe.lastIndex = 0;
  2774. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2775. return n ? (date.j = +n[0], i + n[0].length) : -1;
  2776. }
  2777. function d3_time_parseHour24(date, string, i) {
  2778. d3_time_numberRe.lastIndex = 0;
  2779. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2780. return n ? (date.H = +n[0], i + n[0].length) : -1;
  2781. }
  2782. function d3_time_parseMinutes(date, string, i) {
  2783. d3_time_numberRe.lastIndex = 0;
  2784. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2785. return n ? (date.M = +n[0], i + n[0].length) : -1;
  2786. }
  2787. function d3_time_parseSeconds(date, string, i) {
  2788. d3_time_numberRe.lastIndex = 0;
  2789. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2790. return n ? (date.S = +n[0], i + n[0].length) : -1;
  2791. }
  2792. function d3_time_parseMilliseconds(date, string, i) {
  2793. d3_time_numberRe.lastIndex = 0;
  2794. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2795. return n ? (date.L = +n[0], i + n[0].length) : -1;
  2796. }
  2797. function d3_time_zone(d) {
  2798. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
  2799. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  2800. }
  2801. function d3_time_parseLiteralPercent(date, string, i) {
  2802. d3_time_percentRe.lastIndex = 0;
  2803. var n = d3_time_percentRe.exec(string.slice(i, i + 1));
  2804. return n ? i + n[0].length : -1;
  2805. }
  2806. function d3_time_formatMulti(formats) {
  2807. var n = formats.length, i = -1;
  2808. while (++i < n) formats[i][0] = this(formats[i][0]);
  2809. return function(date) {
  2810. var i = 0, f = formats[i];
  2811. while (!f[1](date)) f = formats[++i];
  2812. return f[0](date);
  2813. };
  2814. }
  2815. d3.locale = function(locale) {
  2816. return {
  2817. numberFormat: d3_locale_numberFormat(locale),
  2818. timeFormat: d3_locale_timeFormat(locale)
  2819. };
  2820. };
  2821. var d3_locale_enUS = d3.locale({
  2822. decimal: ".",
  2823. thousands: ",",
  2824. grouping: [ 3 ],
  2825. currency: [ "$", "" ],
  2826. dateTime: "%a %b %e %X %Y",
  2827. date: "%m/%d/%Y",
  2828. time: "%H:%M:%S",
  2829. periods: [ "AM", "PM" ],
  2830. days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
  2831. shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
  2832. months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  2833. shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
  2834. });
  2835. d3.format = d3_locale_enUS.numberFormat;
  2836. d3.geo = {};
  2837. function d3_adder() {}
  2838. d3_adder.prototype = {
  2839. s: 0,
  2840. t: 0,
  2841. add: function(y) {
  2842. d3_adderSum(y, this.t, d3_adderTemp);
  2843. d3_adderSum(d3_adderTemp.s, this.s, this);
  2844. if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
  2845. },
  2846. reset: function() {
  2847. this.s = this.t = 0;
  2848. },
  2849. valueOf: function() {
  2850. return this.s;
  2851. }
  2852. };
  2853. var d3_adderTemp = new d3_adder();
  2854. function d3_adderSum(a, b, o) {
  2855. var x = o.s = a + b, bv = x - a, av = x - bv;
  2856. o.t = a - av + (b - bv);
  2857. }
  2858. d3.geo.stream = function(object, listener) {
  2859. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  2860. d3_geo_streamObjectType[object.type](object, listener);
  2861. } else {
  2862. d3_geo_streamGeometry(object, listener);
  2863. }
  2864. };
  2865. function d3_geo_streamGeometry(geometry, listener) {
  2866. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  2867. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  2868. }
  2869. }
  2870. var d3_geo_streamObjectType = {
  2871. Feature: function(feature, listener) {
  2872. d3_geo_streamGeometry(feature.geometry, listener);
  2873. },
  2874. FeatureCollection: function(object, listener) {
  2875. var features = object.features, i = -1, n = features.length;
  2876. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  2877. }
  2878. };
  2879. var d3_geo_streamGeometryType = {
  2880. Sphere: function(object, listener) {
  2881. listener.sphere();
  2882. },
  2883. Point: function(object, listener) {
  2884. object = object.coordinates;
  2885. listener.point(object[0], object[1], object[2]);
  2886. },
  2887. MultiPoint: function(object, listener) {
  2888. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2889. while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
  2890. },
  2891. LineString: function(object, listener) {
  2892. d3_geo_streamLine(object.coordinates, listener, 0);
  2893. },
  2894. MultiLineString: function(object, listener) {
  2895. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2896. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  2897. },
  2898. Polygon: function(object, listener) {
  2899. d3_geo_streamPolygon(object.coordinates, listener);
  2900. },
  2901. MultiPolygon: function(object, listener) {
  2902. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2903. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  2904. },
  2905. GeometryCollection: function(object, listener) {
  2906. var geometries = object.geometries, i = -1, n = geometries.length;
  2907. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  2908. }
  2909. };
  2910. function d3_geo_streamLine(coordinates, listener, closed) {
  2911. var i = -1, n = coordinates.length - closed, coordinate;
  2912. listener.lineStart();
  2913. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
  2914. listener.lineEnd();
  2915. }
  2916. function d3_geo_streamPolygon(coordinates, listener) {
  2917. var i = -1, n = coordinates.length;
  2918. listener.polygonStart();
  2919. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  2920. listener.polygonEnd();
  2921. }
  2922. d3.geo.area = function(object) {
  2923. d3_geo_areaSum = 0;
  2924. d3.geo.stream(object, d3_geo_area);
  2925. return d3_geo_areaSum;
  2926. };
  2927. var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
  2928. var d3_geo_area = {
  2929. sphere: function() {
  2930. d3_geo_areaSum += 4 * π;
  2931. },
  2932. point: d3_noop,
  2933. lineStart: d3_noop,
  2934. lineEnd: d3_noop,
  2935. polygonStart: function() {
  2936. d3_geo_areaRingSum.reset();
  2937. d3_geo_area.lineStart = d3_geo_areaRingStart;
  2938. },
  2939. polygonEnd: function() {
  2940. var area = 2 * d3_geo_areaRingSum;
  2941. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  2942. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  2943. }
  2944. };
  2945. function d3_geo_areaRingStart() {
  2946. var λ00, φ00, λ0, cosφ0, sinφ0;
  2947. d3_geo_area.point = function(λ, φ) {
  2948. d3_geo_area.point = nextPoint;
  2949. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  2950. sinφ0 = Math.sin(φ);
  2951. };
  2952. function nextPoint(λ, φ) {
  2953. λ *= d3_radians;
  2954. φ = φ * d3_radians / 2 + π / 4;
  2955. 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λ);
  2956. d3_geo_areaRingSum.add(Math.atan2(v, u));
  2957. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  2958. }
  2959. d3_geo_area.lineEnd = function() {
  2960. nextPoint(λ00, φ00);
  2961. };
  2962. }
  2963. function d3_geo_cartesian(spherical) {
  2964. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  2965. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  2966. }
  2967. function d3_geo_cartesianDot(a, b) {
  2968. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  2969. }
  2970. function d3_geo_cartesianCross(a, b) {
  2971. 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] ];
  2972. }
  2973. function d3_geo_cartesianAdd(a, b) {
  2974. a[0] += b[0];
  2975. a[1] += b[1];
  2976. a[2] += b[2];
  2977. }
  2978. function d3_geo_cartesianScale(vector, k) {
  2979. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  2980. }
  2981. function d3_geo_cartesianNormalize(d) {
  2982. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  2983. d[0] /= l;
  2984. d[1] /= l;
  2985. d[2] /= l;
  2986. }
  2987. function d3_geo_spherical(cartesian) {
  2988. return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
  2989. }
  2990. function d3_geo_sphericalEqual(a, b) {
  2991. return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
  2992. }
  2993. d3.geo.bounds = function() {
  2994. var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
  2995. var bound = {
  2996. point: point,
  2997. lineStart: lineStart,
  2998. lineEnd: lineEnd,
  2999. polygonStart: function() {
  3000. bound.point = ringPoint;
  3001. bound.lineStart = ringStart;
  3002. bound.lineEnd = ringEnd;
  3003. dλSum = 0;
  3004. d3_geo_area.polygonStart();
  3005. },
  3006. polygonEnd: function() {
  3007. d3_geo_area.polygonEnd();
  3008. bound.point = point;
  3009. bound.lineStart = lineStart;
  3010. bound.lineEnd = lineEnd;
  3011. if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
  3012. range[0] = λ0, range[1] = λ1;
  3013. }
  3014. };
  3015. function point(λ, φ) {
  3016. ranges.push(range = [ λ0 = λ, λ1 = λ ]);
  3017. if (φ < φ0) φ0 = φ;
  3018. if (φ > φ1) φ1 = φ;
  3019. }
  3020. function linePoint(λ, φ) {
  3021. var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
  3022. if (p0) {
  3023. var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
  3024. d3_geo_cartesianNormalize(inflection);
  3025. inflection = d3_geo_spherical(inflection);
  3026. var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
  3027. if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3028. var φi = inflection[1] * d3_degrees;
  3029. if (φi > φ1) φ1 = φi;
  3030. } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3031. var φi = -inflection[1] * d3_degrees;
  3032. if (φi < φ0) φ0 = φi;
  3033. } else {
  3034. if (φ < φ0) φ0 = φ;
  3035. if (φ > φ1) φ1 = φ;
  3036. }
  3037. if (antimeridian) {
  3038. if (λ < λ_) {
  3039. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3040. } else {
  3041. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3042. }
  3043. } else {
  3044. if (λ1 >= λ0) {
  3045. if (λ < λ0) λ0 = λ;
  3046. if (λ > λ1) λ1 = λ;
  3047. } else {
  3048. if (λ > λ_) {
  3049. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3050. } else {
  3051. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3052. }
  3053. }
  3054. }
  3055. } else {
  3056. point(λ, φ);
  3057. }
  3058. p0 = p, λ_ = λ;
  3059. }
  3060. function lineStart() {
  3061. bound.point = linePoint;
  3062. }
  3063. function lineEnd() {
  3064. range[0] = λ0, range[1] = λ1;
  3065. bound.point = point;
  3066. p0 = null;
  3067. }
  3068. function ringPoint(λ, φ) {
  3069. if (p0) {
  3070. var dλ = λ - λ_;
  3071. dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
  3072. } else λ__ = λ, φ__ = φ;
  3073. d3_geo_area.point(λ, φ);
  3074. linePoint(λ, φ);
  3075. }
  3076. function ringStart() {
  3077. d3_geo_area.lineStart();
  3078. }
  3079. function ringEnd() {
  3080. ringPoint(λ__, φ__);
  3081. d3_geo_area.lineEnd();
  3082. if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
  3083. range[0] = λ0, range[1] = λ1;
  3084. p0 = null;
  3085. }
  3086. function angle(λ0, λ1) {
  3087. return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
  3088. }
  3089. function compareRanges(a, b) {
  3090. return a[0] - b[0];
  3091. }
  3092. function withinRange(x, range) {
  3093. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  3094. }
  3095. return function(feature) {
  3096. φ1 = λ1 = -(λ0 = φ0 = Infinity);
  3097. ranges = [];
  3098. d3.geo.stream(feature, bound);
  3099. var n = ranges.length;
  3100. if (n) {
  3101. ranges.sort(compareRanges);
  3102. for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
  3103. b = ranges[i];
  3104. if (withinRange(b[0], a) || withinRange(b[1], a)) {
  3105. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  3106. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  3107. } else {
  3108. merged.push(a = b);
  3109. }
  3110. }
  3111. var best = -Infinity, dλ;
  3112. for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
  3113. b = merged[i];
  3114. if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
  3115. }
  3116. }
  3117. ranges = range = null;
  3118. return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
  3119. };
  3120. }();
  3121. d3.geo.centroid = function(object) {
  3122. 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;
  3123. d3.geo.stream(object, d3_geo_centroid);
  3124. var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
  3125. if (m < ε2) {
  3126. x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
  3127. if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
  3128. m = x * x + y * y + z * z;
  3129. if (m < ε2) return [ NaN, NaN ];
  3130. }
  3131. return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
  3132. };
  3133. 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;
  3134. var d3_geo_centroid = {
  3135. sphere: d3_noop,
  3136. point: d3_geo_centroidPoint,
  3137. lineStart: d3_geo_centroidLineStart,
  3138. lineEnd: d3_geo_centroidLineEnd,
  3139. polygonStart: function() {
  3140. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  3141. },
  3142. polygonEnd: function() {
  3143. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  3144. }
  3145. };
  3146. function d3_geo_centroidPoint(λ, φ) {
  3147. λ *= d3_radians;
  3148. var cosφ = Math.cos(φ *= d3_radians);
  3149. d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
  3150. }
  3151. function d3_geo_centroidPointXYZ(x, y, z) {
  3152. ++d3_geo_centroidW0;
  3153. d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
  3154. d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
  3155. d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
  3156. }
  3157. function d3_geo_centroidLineStart() {
  3158. var x0, y0, z0;
  3159. d3_geo_centroid.point = function(λ, φ) {
  3160. λ *= d3_radians;
  3161. var cosφ = Math.cos(φ *= d3_radians);
  3162. x0 = cosφ * Math.cos(λ);
  3163. y0 = cosφ * Math.sin(λ);
  3164. z0 = Math.sin(φ);
  3165. d3_geo_centroid.point = nextPoint;
  3166. d3_geo_centroidPointXYZ(x0, y0, z0);
  3167. };
  3168. function nextPoint(λ, φ) {
  3169. λ *= d3_radians;
  3170. 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);
  3171. d3_geo_centroidW1 += w;
  3172. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3173. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3174. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3175. d3_geo_centroidPointXYZ(x0, y0, z0);
  3176. }
  3177. }
  3178. function d3_geo_centroidLineEnd() {
  3179. d3_geo_centroid.point = d3_geo_centroidPoint;
  3180. }
  3181. function d3_geo_centroidRingStart() {
  3182. var λ00, φ00, x0, y0, z0;
  3183. d3_geo_centroid.point = function(λ, φ) {
  3184. λ00 = λ, φ00 = φ;
  3185. d3_geo_centroid.point = nextPoint;
  3186. λ *= d3_radians;
  3187. var cosφ = Math.cos(φ *= d3_radians);
  3188. x0 = cosφ * Math.cos(λ);
  3189. y0 = cosφ * Math.sin(λ);
  3190. z0 = Math.sin(φ);
  3191. d3_geo_centroidPointXYZ(x0, y0, z0);
  3192. };
  3193. d3_geo_centroid.lineEnd = function() {
  3194. nextPoint(λ00, φ00);
  3195. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  3196. d3_geo_centroid.point = d3_geo_centroidPoint;
  3197. };
  3198. function nextPoint(λ, φ) {
  3199. λ *= d3_radians;
  3200. 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);
  3201. d3_geo_centroidX2 += v * cx;
  3202. d3_geo_centroidY2 += v * cy;
  3203. d3_geo_centroidZ2 += v * cz;
  3204. d3_geo_centroidW1 += w;
  3205. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3206. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3207. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3208. d3_geo_centroidPointXYZ(x0, y0, z0);
  3209. }
  3210. }
  3211. function d3_geo_compose(a, b) {
  3212. function compose(x, y) {
  3213. return x = a(x, y), b(x[0], x[1]);
  3214. }
  3215. if (a.invert && b.invert) compose.invert = function(x, y) {
  3216. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  3217. };
  3218. return compose;
  3219. }
  3220. function d3_true() {
  3221. return true;
  3222. }
  3223. function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
  3224. var subject = [], clip = [];
  3225. segments.forEach(function(segment) {
  3226. if ((n = segment.length - 1) <= 0) return;
  3227. var n, p0 = segment[0], p1 = segment[n];
  3228. if (d3_geo_sphericalEqual(p0, p1)) {
  3229. listener.lineStart();
  3230. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  3231. listener.lineEnd();
  3232. return;
  3233. }
  3234. var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
  3235. a.o = b;
  3236. subject.push(a);
  3237. clip.push(b);
  3238. a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
  3239. b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
  3240. a.o = b;
  3241. subject.push(a);
  3242. clip.push(b);
  3243. });
  3244. clip.sort(compare);
  3245. d3_geo_clipPolygonLinkCircular(subject);
  3246. d3_geo_clipPolygonLinkCircular(clip);
  3247. if (!subject.length) return;
  3248. for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
  3249. clip[i].e = entry = !entry;
  3250. }
  3251. var start = subject[0], points, point;
  3252. while (1) {
  3253. var current = start, isSubject = true;
  3254. while (current.v) if ((current = current.n) === start) return;
  3255. points = current.z;
  3256. listener.lineStart();
  3257. do {
  3258. current.v = current.o.v = true;
  3259. if (current.e) {
  3260. if (isSubject) {
  3261. for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
  3262. } else {
  3263. interpolate(current.x, current.n.x, 1, listener);
  3264. }
  3265. current = current.n;
  3266. } else {
  3267. if (isSubject) {
  3268. points = current.p.z;
  3269. for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
  3270. } else {
  3271. interpolate(current.x, current.p.x, -1, listener);
  3272. }
  3273. current = current.p;
  3274. }
  3275. current = current.o;
  3276. points = current.z;
  3277. isSubject = !isSubject;
  3278. } while (!current.v);
  3279. listener.lineEnd();
  3280. }
  3281. }
  3282. function d3_geo_clipPolygonLinkCircular(array) {
  3283. if (!(n = array.length)) return;
  3284. var n, i = 0, a = array[0], b;
  3285. while (++i < n) {
  3286. a.n = b = array[i];
  3287. b.p = a;
  3288. a = b;
  3289. }
  3290. a.n = b = array[0];
  3291. b.p = a;
  3292. }
  3293. function d3_geo_clipPolygonIntersection(point, points, other, entry) {
  3294. this.x = point;
  3295. this.z = points;
  3296. this.o = other;
  3297. this.e = entry;
  3298. this.v = false;
  3299. this.n = this.p = null;
  3300. }
  3301. function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
  3302. return function(rotate, listener) {
  3303. var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
  3304. var clip = {
  3305. point: point,
  3306. lineStart: lineStart,
  3307. lineEnd: lineEnd,
  3308. polygonStart: function() {
  3309. clip.point = pointRing;
  3310. clip.lineStart = ringStart;
  3311. clip.lineEnd = ringEnd;
  3312. segments = [];
  3313. polygon = [];
  3314. },
  3315. polygonEnd: function() {
  3316. clip.point = point;
  3317. clip.lineStart = lineStart;
  3318. clip.lineEnd = lineEnd;
  3319. segments = d3.merge(segments);
  3320. var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
  3321. if (segments.length) {
  3322. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3323. d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
  3324. } else if (clipStartInside) {
  3325. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3326. listener.lineStart();
  3327. interpolate(null, null, 1, listener);
  3328. listener.lineEnd();
  3329. }
  3330. if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
  3331. segments = polygon = null;
  3332. },
  3333. sphere: function() {
  3334. listener.polygonStart();
  3335. listener.lineStart();
  3336. interpolate(null, null, 1, listener);
  3337. listener.lineEnd();
  3338. listener.polygonEnd();
  3339. }
  3340. };
  3341. function point(λ, φ) {
  3342. var point = rotate(λ, φ);
  3343. if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
  3344. }
  3345. function pointLine(λ, φ) {
  3346. var point = rotate(λ, φ);
  3347. line.point(point[0], point[1]);
  3348. }
  3349. function lineStart() {
  3350. clip.point = pointLine;
  3351. line.lineStart();
  3352. }
  3353. function lineEnd() {
  3354. clip.point = point;
  3355. line.lineEnd();
  3356. }
  3357. var segments;
  3358. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
  3359. function pointRing(λ, φ) {
  3360. ring.push([ λ, φ ]);
  3361. var point = rotate(λ, φ);
  3362. ringListener.point(point[0], point[1]);
  3363. }
  3364. function ringStart() {
  3365. ringListener.lineStart();
  3366. ring = [];
  3367. }
  3368. function ringEnd() {
  3369. pointRing(ring[0][0], ring[0][1]);
  3370. ringListener.lineEnd();
  3371. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  3372. ring.pop();
  3373. polygon.push(ring);
  3374. ring = null;
  3375. if (!n) return;
  3376. if (clean & 1) {
  3377. segment = ringSegments[0];
  3378. var n = segment.length - 1, i = -1, point;
  3379. if (n > 0) {
  3380. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3381. listener.lineStart();
  3382. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  3383. listener.lineEnd();
  3384. }
  3385. return;
  3386. }
  3387. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  3388. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  3389. }
  3390. return clip;
  3391. };
  3392. }
  3393. function d3_geo_clipSegmentLength1(segment) {
  3394. return segment.length > 1;
  3395. }
  3396. function d3_geo_clipBufferListener() {
  3397. var lines = [], line;
  3398. return {
  3399. lineStart: function() {
  3400. lines.push(line = []);
  3401. },
  3402. point: function(λ, φ) {
  3403. line.push([ λ, φ ]);
  3404. },
  3405. lineEnd: d3_noop,
  3406. buffer: function() {
  3407. var buffer = lines;
  3408. lines = [];
  3409. line = null;
  3410. return buffer;
  3411. },
  3412. rejoin: function() {
  3413. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  3414. }
  3415. };
  3416. }
  3417. function d3_geo_clipSort(a, b) {
  3418. return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
  3419. }
  3420. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
  3421. function d3_geo_clipAntimeridianLine(listener) {
  3422. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  3423. return {
  3424. lineStart: function() {
  3425. listener.lineStart();
  3426. clean = 1;
  3427. },
  3428. point: function(λ1, φ1) {
  3429. var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
  3430. if (abs(dλ - π) < ε) {
  3431. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
  3432. listener.point(sλ0, φ0);
  3433. listener.lineEnd();
  3434. listener.lineStart();
  3435. listener.point(sλ1, φ0);
  3436. listener.point(λ1, φ0);
  3437. clean = 0;
  3438. } else if (sλ0 !== sλ1 && dλ >= π) {
  3439. if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  3440. if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  3441. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  3442. listener.point(sλ0, φ0);
  3443. listener.lineEnd();
  3444. listener.lineStart();
  3445. listener.point(sλ1, φ0);
  3446. clean = 0;
  3447. }
  3448. listener.point(λ0 = λ1, φ0 = φ1);
  3449. sλ0 = sλ1;
  3450. },
  3451. lineEnd: function() {
  3452. listener.lineEnd();
  3453. λ0 = φ0 = NaN;
  3454. },
  3455. clean: function() {
  3456. return 2 - clean;
  3457. }
  3458. };
  3459. }
  3460. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  3461. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  3462. 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;
  3463. }
  3464. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  3465. var φ;
  3466. if (from == null) {
  3467. φ = direction * halfπ;
  3468. listener.point(-π, φ);
  3469. listener.point(0, φ);
  3470. listener.point(π, φ);
  3471. listener.point(π, 0);
  3472. listener.point(π, -φ);
  3473. listener.point(0, -φ);
  3474. listener.point(-π, -φ);
  3475. listener.point(-π, 0);
  3476. listener.point(-π, φ);
  3477. } else if (abs(from[0] - to[0]) > ε) {
  3478. var s = from[0] < to[0] ? π : -π;
  3479. φ = direction * s / 2;
  3480. listener.point(-s, φ);
  3481. listener.point(0, φ);
  3482. listener.point(s, φ);
  3483. } else {
  3484. listener.point(to[0], to[1]);
  3485. }
  3486. }
  3487. function d3_geo_pointInPolygon(point, polygon) {
  3488. var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
  3489. d3_geo_areaRingSum.reset();
  3490. for (var i = 0, n = polygon.length; i < n; ++i) {
  3491. var ring = polygon[i], m = ring.length;
  3492. if (!m) continue;
  3493. var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
  3494. while (true) {
  3495. if (j === m) j = 0;
  3496. point = ring[j];
  3497. 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φ;
  3498. d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
  3499. polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
  3500. if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
  3501. var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
  3502. d3_geo_cartesianNormalize(arc);
  3503. var intersection = d3_geo_cartesianCross(meridianNormal, arc);
  3504. d3_geo_cartesianNormalize(intersection);
  3505. var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
  3506. if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
  3507. winding += antimeridian ^ dλ >= 0 ? 1 : -1;
  3508. }
  3509. }
  3510. if (!j++) break;
  3511. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
  3512. }
  3513. }
  3514. return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
  3515. }
  3516. function d3_geo_clipCircle(radius) {
  3517. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  3518. return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
  3519. function visible(λ, φ) {
  3520. return Math.cos(λ) * Math.cos(φ) > cr;
  3521. }
  3522. function clipLine(listener) {
  3523. var point0, c0, v0, v00, clean;
  3524. return {
  3525. lineStart: function() {
  3526. v00 = v0 = false;
  3527. clean = 1;
  3528. },
  3529. point: function(λ, φ) {
  3530. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  3531. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  3532. if (v !== v0) {
  3533. point2 = intersect(point0, point1);
  3534. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  3535. point1[0] += ε;
  3536. point1[1] += ε;
  3537. v = visible(point1[0], point1[1]);
  3538. }
  3539. }
  3540. if (v !== v0) {
  3541. clean = 0;
  3542. if (v) {
  3543. listener.lineStart();
  3544. point2 = intersect(point1, point0);
  3545. listener.point(point2[0], point2[1]);
  3546. } else {
  3547. point2 = intersect(point0, point1);
  3548. listener.point(point2[0], point2[1]);
  3549. listener.lineEnd();
  3550. }
  3551. point0 = point2;
  3552. } else if (notHemisphere && point0 && smallRadius ^ v) {
  3553. var t;
  3554. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  3555. clean = 0;
  3556. if (smallRadius) {
  3557. listener.lineStart();
  3558. listener.point(t[0][0], t[0][1]);
  3559. listener.point(t[1][0], t[1][1]);
  3560. listener.lineEnd();
  3561. } else {
  3562. listener.point(t[1][0], t[1][1]);
  3563. listener.lineEnd();
  3564. listener.lineStart();
  3565. listener.point(t[0][0], t[0][1]);
  3566. }
  3567. }
  3568. }
  3569. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  3570. listener.point(point1[0], point1[1]);
  3571. }
  3572. point0 = point1, v0 = v, c0 = c;
  3573. },
  3574. lineEnd: function() {
  3575. if (v0) listener.lineEnd();
  3576. point0 = null;
  3577. },
  3578. clean: function() {
  3579. return clean | (v00 && v0) << 1;
  3580. }
  3581. };
  3582. }
  3583. function intersect(a, b, two) {
  3584. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  3585. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  3586. if (!determinant) return !two && a;
  3587. 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);
  3588. d3_geo_cartesianAdd(A, B);
  3589. 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);
  3590. if (t2 < 0) return;
  3591. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  3592. d3_geo_cartesianAdd(q, A);
  3593. q = d3_geo_spherical(q);
  3594. if (!two) return q;
  3595. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  3596. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  3597. var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
  3598. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  3599. 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)) {
  3600. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  3601. d3_geo_cartesianAdd(q1, A);
  3602. return [ q, d3_geo_spherical(q1) ];
  3603. }
  3604. }
  3605. function code(λ, φ) {
  3606. var r = smallRadius ? radius : π - radius, code = 0;
  3607. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  3608. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  3609. return code;
  3610. }
  3611. }
  3612. function d3_geom_clipLine(x0, y0, x1, y1) {
  3613. return function(line) {
  3614. 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;
  3615. r = x0 - ax;
  3616. if (!dx && r > 0) return;
  3617. r /= dx;
  3618. if (dx < 0) {
  3619. if (r < t0) return;
  3620. if (r < t1) t1 = r;
  3621. } else if (dx > 0) {
  3622. if (r > t1) return;
  3623. if (r > t0) t0 = r;
  3624. }
  3625. r = x1 - ax;
  3626. if (!dx && r < 0) return;
  3627. r /= dx;
  3628. if (dx < 0) {
  3629. if (r > t1) return;
  3630. if (r > t0) t0 = r;
  3631. } else if (dx > 0) {
  3632. if (r < t0) return;
  3633. if (r < t1) t1 = r;
  3634. }
  3635. r = y0 - ay;
  3636. if (!dy && r > 0) return;
  3637. r /= dy;
  3638. if (dy < 0) {
  3639. if (r < t0) return;
  3640. if (r < t1) t1 = r;
  3641. } else if (dy > 0) {
  3642. if (r > t1) return;
  3643. if (r > t0) t0 = r;
  3644. }
  3645. r = y1 - ay;
  3646. if (!dy && r < 0) return;
  3647. r /= dy;
  3648. if (dy < 0) {
  3649. if (r > t1) return;
  3650. if (r > t0) t0 = r;
  3651. } else if (dy > 0) {
  3652. if (r < t0) return;
  3653. if (r < t1) t1 = r;
  3654. }
  3655. if (t0 > 0) line.a = {
  3656. x: ax + t0 * dx,
  3657. y: ay + t0 * dy
  3658. };
  3659. if (t1 < 1) line.b = {
  3660. x: ax + t1 * dx,
  3661. y: ay + t1 * dy
  3662. };
  3663. return line;
  3664. };
  3665. }
  3666. var d3_geo_clipExtentMAX = 1e9;
  3667. d3.geo.clipExtent = function() {
  3668. var x0, y0, x1, y1, stream, clip, clipExtent = {
  3669. stream: function(output) {
  3670. if (stream) stream.valid = false;
  3671. stream = clip(output);
  3672. stream.valid = true;
  3673. return stream;
  3674. },
  3675. extent: function(_) {
  3676. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3677. clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
  3678. if (stream) stream.valid = false, stream = null;
  3679. return clipExtent;
  3680. }
  3681. };
  3682. return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
  3683. };
  3684. function d3_geo_clipExtent(x0, y0, x1, y1) {
  3685. return function(listener) {
  3686. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
  3687. var clip = {
  3688. point: point,
  3689. lineStart: lineStart,
  3690. lineEnd: lineEnd,
  3691. polygonStart: function() {
  3692. listener = bufferListener;
  3693. segments = [];
  3694. polygon = [];
  3695. clean = true;
  3696. },
  3697. polygonEnd: function() {
  3698. listener = listener_;
  3699. segments = d3.merge(segments);
  3700. var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
  3701. if (inside || visible) {
  3702. listener.polygonStart();
  3703. if (inside) {
  3704. listener.lineStart();
  3705. interpolate(null, null, 1, listener);
  3706. listener.lineEnd();
  3707. }
  3708. if (visible) {
  3709. d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
  3710. }
  3711. listener.polygonEnd();
  3712. }
  3713. segments = polygon = ring = null;
  3714. }
  3715. };
  3716. function insidePolygon(p) {
  3717. var wn = 0, n = polygon.length, y = p[1];
  3718. for (var i = 0; i < n; ++i) {
  3719. for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
  3720. b = v[j];
  3721. if (a[1] <= y) {
  3722. if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
  3723. } else {
  3724. if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
  3725. }
  3726. a = b;
  3727. }
  3728. }
  3729. return wn !== 0;
  3730. }
  3731. function interpolate(from, to, direction, listener) {
  3732. var a = 0, a1 = 0;
  3733. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  3734. do {
  3735. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  3736. } while ((a = (a + direction + 4) % 4) !== a1);
  3737. } else {
  3738. listener.point(to[0], to[1]);
  3739. }
  3740. }
  3741. function pointVisible(x, y) {
  3742. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  3743. }
  3744. function point(x, y) {
  3745. if (pointVisible(x, y)) listener.point(x, y);
  3746. }
  3747. var x__, y__, v__, x_, y_, v_, first, clean;
  3748. function lineStart() {
  3749. clip.point = linePoint;
  3750. if (polygon) polygon.push(ring = []);
  3751. first = true;
  3752. v_ = false;
  3753. x_ = y_ = NaN;
  3754. }
  3755. function lineEnd() {
  3756. if (segments) {
  3757. linePoint(x__, y__);
  3758. if (v__ && v_) bufferListener.rejoin();
  3759. segments.push(bufferListener.buffer());
  3760. }
  3761. clip.point = point;
  3762. if (v_) listener.lineEnd();
  3763. }
  3764. function linePoint(x, y) {
  3765. x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
  3766. y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
  3767. var v = pointVisible(x, y);
  3768. if (polygon) ring.push([ x, y ]);
  3769. if (first) {
  3770. x__ = x, y__ = y, v__ = v;
  3771. first = false;
  3772. if (v) {
  3773. listener.lineStart();
  3774. listener.point(x, y);
  3775. }
  3776. } else {
  3777. if (v && v_) listener.point(x, y); else {
  3778. var l = {
  3779. a: {
  3780. x: x_,
  3781. y: y_
  3782. },
  3783. b: {
  3784. x: x,
  3785. y: y
  3786. }
  3787. };
  3788. if (clipLine(l)) {
  3789. if (!v_) {
  3790. listener.lineStart();
  3791. listener.point(l.a.x, l.a.y);
  3792. }
  3793. listener.point(l.b.x, l.b.y);
  3794. if (!v) listener.lineEnd();
  3795. clean = false;
  3796. } else if (v) {
  3797. listener.lineStart();
  3798. listener.point(x, y);
  3799. clean = false;
  3800. }
  3801. }
  3802. }
  3803. x_ = x, y_ = y, v_ = v;
  3804. }
  3805. return clip;
  3806. };
  3807. function corner(p, direction) {
  3808. 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;
  3809. }
  3810. function compare(a, b) {
  3811. return comparePoints(a.x, b.x);
  3812. }
  3813. function comparePoints(a, b) {
  3814. var ca = corner(a, 1), cb = corner(b, 1);
  3815. 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];
  3816. }
  3817. }
  3818. function d3_geo_conic(projectAt) {
  3819. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  3820. p.parallels = function(_) {
  3821. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  3822. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  3823. };
  3824. return p;
  3825. }
  3826. function d3_geo_conicEqualArea(φ0, φ1) {
  3827. 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;
  3828. function forward(λ, φ) {
  3829. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  3830. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  3831. }
  3832. forward.invert = function(x, y) {
  3833. var ρ0_y = ρ0 - y;
  3834. return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  3835. };
  3836. return forward;
  3837. }
  3838. (d3.geo.conicEqualArea = function() {
  3839. return d3_geo_conic(d3_geo_conicEqualArea);
  3840. }).raw = d3_geo_conicEqualArea;
  3841. d3.geo.albers = function() {
  3842. return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
  3843. };
  3844. d3.geo.albersUsa = function() {
  3845. var lower48 = d3.geo.albers();
  3846. var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
  3847. var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
  3848. var point, pointStream = {
  3849. point: function(x, y) {
  3850. point = [ x, y ];
  3851. }
  3852. }, lower48Point, alaskaPoint, hawaiiPoint;
  3853. function albersUsa(coordinates) {
  3854. var x = coordinates[0], y = coordinates[1];
  3855. point = null;
  3856. (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
  3857. return point;
  3858. }
  3859. albersUsa.invert = function(coordinates) {
  3860. var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
  3861. return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
  3862. };
  3863. albersUsa.stream = function(stream) {
  3864. var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
  3865. return {
  3866. point: function(x, y) {
  3867. lower48Stream.point(x, y);
  3868. alaskaStream.point(x, y);
  3869. hawaiiStream.point(x, y);
  3870. },
  3871. sphere: function() {
  3872. lower48Stream.sphere();
  3873. alaskaStream.sphere();
  3874. hawaiiStream.sphere();
  3875. },
  3876. lineStart: function() {
  3877. lower48Stream.lineStart();
  3878. alaskaStream.lineStart();
  3879. hawaiiStream.lineStart();
  3880. },
  3881. lineEnd: function() {
  3882. lower48Stream.lineEnd();
  3883. alaskaStream.lineEnd();
  3884. hawaiiStream.lineEnd();
  3885. },
  3886. polygonStart: function() {
  3887. lower48Stream.polygonStart();
  3888. alaskaStream.polygonStart();
  3889. hawaiiStream.polygonStart();
  3890. },
  3891. polygonEnd: function() {
  3892. lower48Stream.polygonEnd();
  3893. alaskaStream.polygonEnd();
  3894. hawaiiStream.polygonEnd();
  3895. }
  3896. };
  3897. };
  3898. albersUsa.precision = function(_) {
  3899. if (!arguments.length) return lower48.precision();
  3900. lower48.precision(_);
  3901. alaska.precision(_);
  3902. hawaii.precision(_);
  3903. return albersUsa;
  3904. };
  3905. albersUsa.scale = function(_) {
  3906. if (!arguments.length) return lower48.scale();
  3907. lower48.scale(_);
  3908. alaska.scale(_ * .35);
  3909. hawaii.scale(_);
  3910. return albersUsa.translate(lower48.translate());
  3911. };
  3912. albersUsa.translate = function(_) {
  3913. if (!arguments.length) return lower48.translate();
  3914. var k = lower48.scale(), x = +_[0], y = +_[1];
  3915. lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
  3916. 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;
  3917. 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;
  3918. return albersUsa;
  3919. };
  3920. return albersUsa.scale(1070);
  3921. };
  3922. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  3923. point: d3_noop,
  3924. lineStart: d3_noop,
  3925. lineEnd: d3_noop,
  3926. polygonStart: function() {
  3927. d3_geo_pathAreaPolygon = 0;
  3928. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  3929. },
  3930. polygonEnd: function() {
  3931. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  3932. d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
  3933. }
  3934. };
  3935. function d3_geo_pathAreaRingStart() {
  3936. var x00, y00, x0, y0;
  3937. d3_geo_pathArea.point = function(x, y) {
  3938. d3_geo_pathArea.point = nextPoint;
  3939. x00 = x0 = x, y00 = y0 = y;
  3940. };
  3941. function nextPoint(x, y) {
  3942. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  3943. x0 = x, y0 = y;
  3944. }
  3945. d3_geo_pathArea.lineEnd = function() {
  3946. nextPoint(x00, y00);
  3947. };
  3948. }
  3949. var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
  3950. var d3_geo_pathBounds = {
  3951. point: d3_geo_pathBoundsPoint,
  3952. lineStart: d3_noop,
  3953. lineEnd: d3_noop,
  3954. polygonStart: d3_noop,
  3955. polygonEnd: d3_noop
  3956. };
  3957. function d3_geo_pathBoundsPoint(x, y) {
  3958. if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
  3959. if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
  3960. if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
  3961. if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
  3962. }
  3963. function d3_geo_pathBuffer() {
  3964. var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
  3965. var stream = {
  3966. point: point,
  3967. lineStart: function() {
  3968. stream.point = pointLineStart;
  3969. },
  3970. lineEnd: lineEnd,
  3971. polygonStart: function() {
  3972. stream.lineEnd = lineEndPolygon;
  3973. },
  3974. polygonEnd: function() {
  3975. stream.lineEnd = lineEnd;
  3976. stream.point = point;
  3977. },
  3978. pointRadius: function(_) {
  3979. pointCircle = d3_geo_pathBufferCircle(_);
  3980. return stream;
  3981. },
  3982. result: function() {
  3983. if (buffer.length) {
  3984. var result = buffer.join("");
  3985. buffer = [];
  3986. return result;
  3987. }
  3988. }
  3989. };
  3990. function point(x, y) {
  3991. buffer.push("M", x, ",", y, pointCircle);
  3992. }
  3993. function pointLineStart(x, y) {
  3994. buffer.push("M", x, ",", y);
  3995. stream.point = pointLine;
  3996. }
  3997. function pointLine(x, y) {
  3998. buffer.push("L", x, ",", y);
  3999. }
  4000. function lineEnd() {
  4001. stream.point = point;
  4002. }
  4003. function lineEndPolygon() {
  4004. buffer.push("Z");
  4005. }
  4006. return stream;
  4007. }
  4008. function d3_geo_pathBufferCircle(radius) {
  4009. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
  4010. }
  4011. var d3_geo_pathCentroid = {
  4012. point: d3_geo_pathCentroidPoint,
  4013. lineStart: d3_geo_pathCentroidLineStart,
  4014. lineEnd: d3_geo_pathCentroidLineEnd,
  4015. polygonStart: function() {
  4016. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  4017. },
  4018. polygonEnd: function() {
  4019. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4020. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  4021. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  4022. }
  4023. };
  4024. function d3_geo_pathCentroidPoint(x, y) {
  4025. d3_geo_centroidX0 += x;
  4026. d3_geo_centroidY0 += y;
  4027. ++d3_geo_centroidZ0;
  4028. }
  4029. function d3_geo_pathCentroidLineStart() {
  4030. var x0, y0;
  4031. d3_geo_pathCentroid.point = function(x, y) {
  4032. d3_geo_pathCentroid.point = nextPoint;
  4033. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4034. };
  4035. function nextPoint(x, y) {
  4036. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4037. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4038. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4039. d3_geo_centroidZ1 += z;
  4040. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4041. }
  4042. }
  4043. function d3_geo_pathCentroidLineEnd() {
  4044. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4045. }
  4046. function d3_geo_pathCentroidRingStart() {
  4047. var x00, y00, x0, y0;
  4048. d3_geo_pathCentroid.point = function(x, y) {
  4049. d3_geo_pathCentroid.point = nextPoint;
  4050. d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
  4051. };
  4052. function nextPoint(x, y) {
  4053. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4054. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4055. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4056. d3_geo_centroidZ1 += z;
  4057. z = y0 * x - x0 * y;
  4058. d3_geo_centroidX2 += z * (x0 + x);
  4059. d3_geo_centroidY2 += z * (y0 + y);
  4060. d3_geo_centroidZ2 += z * 3;
  4061. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4062. }
  4063. d3_geo_pathCentroid.lineEnd = function() {
  4064. nextPoint(x00, y00);
  4065. };
  4066. }
  4067. function d3_geo_pathContext(context) {
  4068. var pointRadius = 4.5;
  4069. var stream = {
  4070. point: point,
  4071. lineStart: function() {
  4072. stream.point = pointLineStart;
  4073. },
  4074. lineEnd: lineEnd,
  4075. polygonStart: function() {
  4076. stream.lineEnd = lineEndPolygon;
  4077. },
  4078. polygonEnd: function() {
  4079. stream.lineEnd = lineEnd;
  4080. stream.point = point;
  4081. },
  4082. pointRadius: function(_) {
  4083. pointRadius = _;
  4084. return stream;
  4085. },
  4086. result: d3_noop
  4087. };
  4088. function point(x, y) {
  4089. context.moveTo(x + pointRadius, y);
  4090. context.arc(x, y, pointRadius, 0, τ);
  4091. }
  4092. function pointLineStart(x, y) {
  4093. context.moveTo(x, y);
  4094. stream.point = pointLine;
  4095. }
  4096. function pointLine(x, y) {
  4097. context.lineTo(x, y);
  4098. }
  4099. function lineEnd() {
  4100. stream.point = point;
  4101. }
  4102. function lineEndPolygon() {
  4103. context.closePath();
  4104. }
  4105. return stream;
  4106. }
  4107. function d3_geo_resample(project) {
  4108. var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
  4109. function resample(stream) {
  4110. return (maxDepth ? resampleRecursive : resampleNone)(stream);
  4111. }
  4112. function resampleNone(stream) {
  4113. return d3_geo_transformPoint(stream, function(x, y) {
  4114. x = project(x, y);
  4115. stream.point(x[0], x[1]);
  4116. });
  4117. }
  4118. function resampleRecursive(stream) {
  4119. var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
  4120. var resample = {
  4121. point: point,
  4122. lineStart: lineStart,
  4123. lineEnd: lineEnd,
  4124. polygonStart: function() {
  4125. stream.polygonStart();
  4126. resample.lineStart = ringStart;
  4127. },
  4128. polygonEnd: function() {
  4129. stream.polygonEnd();
  4130. resample.lineStart = lineStart;
  4131. }
  4132. };
  4133. function point(x, y) {
  4134. x = project(x, y);
  4135. stream.point(x[0], x[1]);
  4136. }
  4137. function lineStart() {
  4138. x0 = NaN;
  4139. resample.point = linePoint;
  4140. stream.lineStart();
  4141. }
  4142. function linePoint(λ, φ) {
  4143. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  4144. 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);
  4145. stream.point(x0, y0);
  4146. }
  4147. function lineEnd() {
  4148. resample.point = point;
  4149. stream.lineEnd();
  4150. }
  4151. function ringStart() {
  4152. lineStart();
  4153. resample.point = ringPoint;
  4154. resample.lineEnd = ringEnd;
  4155. }
  4156. function ringPoint(λ, φ) {
  4157. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  4158. resample.point = linePoint;
  4159. }
  4160. function ringEnd() {
  4161. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  4162. resample.lineEnd = lineEnd;
  4163. lineEnd();
  4164. }
  4165. return resample;
  4166. }
  4167. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  4168. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  4169. if (d2 > 4 * δ2 && depth--) {
  4170. 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;
  4171. if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
  4172. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  4173. stream.point(x2, y2);
  4174. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  4175. }
  4176. }
  4177. }
  4178. resample.precision = function(_) {
  4179. if (!arguments.length) return Math.sqrt(δ2);
  4180. maxDepth = (δ2 = _ * _) > 0 && 16;
  4181. return resample;
  4182. };
  4183. return resample;
  4184. }
  4185. d3.geo.path = function() {
  4186. var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
  4187. function path(object) {
  4188. if (object) {
  4189. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  4190. if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
  4191. d3.geo.stream(object, cacheStream);
  4192. }
  4193. return contextStream.result();
  4194. }
  4195. path.area = function(object) {
  4196. d3_geo_pathAreaSum = 0;
  4197. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  4198. return d3_geo_pathAreaSum;
  4199. };
  4200. path.centroid = function(object) {
  4201. 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;
  4202. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  4203. 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 ];
  4204. };
  4205. path.bounds = function(object) {
  4206. d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
  4207. d3.geo.stream(object, projectStream(d3_geo_pathBounds));
  4208. return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
  4209. };
  4210. path.projection = function(_) {
  4211. if (!arguments.length) return projection;
  4212. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  4213. return reset();
  4214. };
  4215. path.context = function(_) {
  4216. if (!arguments.length) return context;
  4217. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  4218. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  4219. return reset();
  4220. };
  4221. path.pointRadius = function(_) {
  4222. if (!arguments.length) return pointRadius;
  4223. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  4224. return path;
  4225. };
  4226. function reset() {
  4227. cacheStream = null;
  4228. return path;
  4229. }
  4230. return path.projection(d3.geo.albersUsa()).context(null);
  4231. };
  4232. function d3_geo_pathProjectStream(project) {
  4233. var resample = d3_geo_resample(function(x, y) {
  4234. return project([ x * d3_degrees, y * d3_degrees ]);
  4235. });
  4236. return function(stream) {
  4237. return d3_geo_projectionRadians(resample(stream));
  4238. };
  4239. }
  4240. d3.geo.transform = function(methods) {
  4241. return {
  4242. stream: function(stream) {
  4243. var transform = new d3_geo_transform(stream);
  4244. for (var k in methods) transform[k] = methods[k];
  4245. return transform;
  4246. }
  4247. };
  4248. };
  4249. function d3_geo_transform(stream) {
  4250. this.stream = stream;
  4251. }
  4252. d3_geo_transform.prototype = {
  4253. point: function(x, y) {
  4254. this.stream.point(x, y);
  4255. },
  4256. sphere: function() {
  4257. this.stream.sphere();
  4258. },
  4259. lineStart: function() {
  4260. this.stream.lineStart();
  4261. },
  4262. lineEnd: function() {
  4263. this.stream.lineEnd();
  4264. },
  4265. polygonStart: function() {
  4266. this.stream.polygonStart();
  4267. },
  4268. polygonEnd: function() {
  4269. this.stream.polygonEnd();
  4270. }
  4271. };
  4272. function d3_geo_transformPoint(stream, point) {
  4273. return {
  4274. point: point,
  4275. sphere: function() {
  4276. stream.sphere();
  4277. },
  4278. lineStart: function() {
  4279. stream.lineStart();
  4280. },
  4281. lineEnd: function() {
  4282. stream.lineEnd();
  4283. },
  4284. polygonStart: function() {
  4285. stream.polygonStart();
  4286. },
  4287. polygonEnd: function() {
  4288. stream.polygonEnd();
  4289. }
  4290. };
  4291. }
  4292. d3.geo.projection = d3_geo_projection;
  4293. d3.geo.projectionMutator = d3_geo_projectionMutator;
  4294. function d3_geo_projection(project) {
  4295. return d3_geo_projectionMutator(function() {
  4296. return project;
  4297. })();
  4298. }
  4299. function d3_geo_projectionMutator(projectAt) {
  4300. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  4301. x = project(x, y);
  4302. return [ x[0] * k + δx, δy - x[1] * k ];
  4303. }), 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;
  4304. function projection(point) {
  4305. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  4306. return [ point[0] * k + δx, δy - point[1] * k ];
  4307. }
  4308. function invert(point) {
  4309. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  4310. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  4311. }
  4312. projection.stream = function(output) {
  4313. if (stream) stream.valid = false;
  4314. stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
  4315. stream.valid = true;
  4316. return stream;
  4317. };
  4318. projection.clipAngle = function(_) {
  4319. if (!arguments.length) return clipAngle;
  4320. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  4321. return invalidate();
  4322. };
  4323. projection.clipExtent = function(_) {
  4324. if (!arguments.length) return clipExtent;
  4325. clipExtent = _;
  4326. postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
  4327. return invalidate();
  4328. };
  4329. projection.scale = function(_) {
  4330. if (!arguments.length) return k;
  4331. k = +_;
  4332. return reset();
  4333. };
  4334. projection.translate = function(_) {
  4335. if (!arguments.length) return [ x, y ];
  4336. x = +_[0];
  4337. y = +_[1];
  4338. return reset();
  4339. };
  4340. projection.center = function(_) {
  4341. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  4342. λ = _[0] % 360 * d3_radians;
  4343. φ = _[1] % 360 * d3_radians;
  4344. return reset();
  4345. };
  4346. projection.rotate = function(_) {
  4347. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  4348. δλ = _[0] % 360 * d3_radians;
  4349. δφ = _[1] % 360 * d3_radians;
  4350. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  4351. return reset();
  4352. };
  4353. d3.rebind(projection, projectResample, "precision");
  4354. function reset() {
  4355. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  4356. var center = project(λ, φ);
  4357. δx = x - center[0] * k;
  4358. δy = y + center[1] * k;
  4359. return invalidate();
  4360. }
  4361. function invalidate() {
  4362. if (stream) stream.valid = false, stream = null;
  4363. return projection;
  4364. }
  4365. return function() {
  4366. project = projectAt.apply(this, arguments);
  4367. projection.invert = project.invert && invert;
  4368. return reset();
  4369. };
  4370. }
  4371. function d3_geo_projectionRadians(stream) {
  4372. return d3_geo_transformPoint(stream, function(x, y) {
  4373. stream.point(x * d3_radians, y * d3_radians);
  4374. });
  4375. }
  4376. function d3_geo_equirectangular(λ, φ) {
  4377. return [ λ, φ ];
  4378. }
  4379. (d3.geo.equirectangular = function() {
  4380. return d3_geo_projection(d3_geo_equirectangular);
  4381. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  4382. d3.geo.rotation = function(rotate) {
  4383. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  4384. function forward(coordinates) {
  4385. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4386. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4387. }
  4388. forward.invert = function(coordinates) {
  4389. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4390. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4391. };
  4392. return forward;
  4393. };
  4394. function d3_geo_identityRotation(λ, φ) {
  4395. return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4396. }
  4397. d3_geo_identityRotation.invert = d3_geo_equirectangular;
  4398. function d3_geo_rotation(δλ, δφ, δγ) {
  4399. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
  4400. }
  4401. function d3_geo_forwardRotationλ(δλ) {
  4402. return function(λ, φ) {
  4403. return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4404. };
  4405. }
  4406. function d3_geo_rotationλ(δλ) {
  4407. var rotation = d3_geo_forwardRotationλ(δλ);
  4408. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  4409. return rotation;
  4410. }
  4411. function d3_geo_rotationφγ(δφ, δγ) {
  4412. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  4413. function rotation(λ, φ) {
  4414. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  4415. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
  4416. }
  4417. rotation.invert = function(λ, φ) {
  4418. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  4419. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
  4420. };
  4421. return rotation;
  4422. }
  4423. d3.geo.circle = function() {
  4424. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  4425. function circle() {
  4426. 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 = [];
  4427. interpolate(null, null, 1, {
  4428. point: function(x, y) {
  4429. ring.push(x = rotate(x, y));
  4430. x[0] *= d3_degrees, x[1] *= d3_degrees;
  4431. }
  4432. });
  4433. return {
  4434. type: "Polygon",
  4435. coordinates: [ ring ]
  4436. };
  4437. }
  4438. circle.origin = function(x) {
  4439. if (!arguments.length) return origin;
  4440. origin = x;
  4441. return circle;
  4442. };
  4443. circle.angle = function(x) {
  4444. if (!arguments.length) return angle;
  4445. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  4446. return circle;
  4447. };
  4448. circle.precision = function(_) {
  4449. if (!arguments.length) return precision;
  4450. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  4451. return circle;
  4452. };
  4453. return circle.angle(90);
  4454. };
  4455. function d3_geo_circleInterpolate(radius, precision) {
  4456. var cr = Math.cos(radius), sr = Math.sin(radius);
  4457. return function(from, to, direction, listener) {
  4458. var step = direction * precision;
  4459. if (from != null) {
  4460. from = d3_geo_circleAngle(cr, from);
  4461. to = d3_geo_circleAngle(cr, to);
  4462. if (direction > 0 ? from < to : from > to) from += direction * τ;
  4463. } else {
  4464. from = radius + direction * τ;
  4465. to = radius - .5 * step;
  4466. }
  4467. for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
  4468. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  4469. }
  4470. };
  4471. }
  4472. function d3_geo_circleAngle(cr, point) {
  4473. var a = d3_geo_cartesian(point);
  4474. a[0] -= cr;
  4475. d3_geo_cartesianNormalize(a);
  4476. var angle = d3_acos(-a[1]);
  4477. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  4478. }
  4479. d3.geo.distance = function(a, b) {
  4480. 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;
  4481. 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Δλ);
  4482. };
  4483. d3.geo.graticule = function() {
  4484. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  4485. function graticule() {
  4486. return {
  4487. type: "MultiLineString",
  4488. coordinates: lines()
  4489. };
  4490. }
  4491. function lines() {
  4492. 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) {
  4493. return abs(x % DX) > ε;
  4494. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  4495. return abs(y % DY) > ε;
  4496. }).map(y));
  4497. }
  4498. graticule.lines = function() {
  4499. return lines().map(function(coordinates) {
  4500. return {
  4501. type: "LineString",
  4502. coordinates: coordinates
  4503. };
  4504. });
  4505. };
  4506. graticule.outline = function() {
  4507. return {
  4508. type: "Polygon",
  4509. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  4510. };
  4511. };
  4512. graticule.extent = function(_) {
  4513. if (!arguments.length) return graticule.minorExtent();
  4514. return graticule.majorExtent(_).minorExtent(_);
  4515. };
  4516. graticule.majorExtent = function(_) {
  4517. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  4518. X0 = +_[0][0], X1 = +_[1][0];
  4519. Y0 = +_[0][1], Y1 = +_[1][1];
  4520. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  4521. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  4522. return graticule.precision(precision);
  4523. };
  4524. graticule.minorExtent = function(_) {
  4525. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  4526. x0 = +_[0][0], x1 = +_[1][0];
  4527. y0 = +_[0][1], y1 = +_[1][1];
  4528. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  4529. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  4530. return graticule.precision(precision);
  4531. };
  4532. graticule.step = function(_) {
  4533. if (!arguments.length) return graticule.minorStep();
  4534. return graticule.majorStep(_).minorStep(_);
  4535. };
  4536. graticule.majorStep = function(_) {
  4537. if (!arguments.length) return [ DX, DY ];
  4538. DX = +_[0], DY = +_[1];
  4539. return graticule;
  4540. };
  4541. graticule.minorStep = function(_) {
  4542. if (!arguments.length) return [ dx, dy ];
  4543. dx = +_[0], dy = +_[1];
  4544. return graticule;
  4545. };
  4546. graticule.precision = function(_) {
  4547. if (!arguments.length) return precision;
  4548. precision = +_;
  4549. x = d3_geo_graticuleX(y0, y1, 90);
  4550. y = d3_geo_graticuleY(x0, x1, precision);
  4551. X = d3_geo_graticuleX(Y0, Y1, 90);
  4552. Y = d3_geo_graticuleY(X0, X1, precision);
  4553. return graticule;
  4554. };
  4555. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  4556. };
  4557. function d3_geo_graticuleX(y0, y1, dy) {
  4558. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  4559. return function(x) {
  4560. return y.map(function(y) {
  4561. return [ x, y ];
  4562. });
  4563. };
  4564. }
  4565. function d3_geo_graticuleY(x0, x1, dx) {
  4566. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  4567. return function(y) {
  4568. return x.map(function(x) {
  4569. return [ x, y ];
  4570. });
  4571. };
  4572. }
  4573. function d3_source(d) {
  4574. return d.source;
  4575. }
  4576. function d3_target(d) {
  4577. return d.target;
  4578. }
  4579. d3.geo.greatArc = function() {
  4580. var source = d3_source, source_, target = d3_target, target_;
  4581. function greatArc() {
  4582. return {
  4583. type: "LineString",
  4584. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  4585. };
  4586. }
  4587. greatArc.distance = function() {
  4588. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  4589. };
  4590. greatArc.source = function(_) {
  4591. if (!arguments.length) return source;
  4592. source = _, source_ = typeof _ === "function" ? null : _;
  4593. return greatArc;
  4594. };
  4595. greatArc.target = function(_) {
  4596. if (!arguments.length) return target;
  4597. target = _, target_ = typeof _ === "function" ? null : _;
  4598. return greatArc;
  4599. };
  4600. greatArc.precision = function() {
  4601. return arguments.length ? greatArc : 0;
  4602. };
  4603. return greatArc;
  4604. };
  4605. d3.geo.interpolate = function(source, target) {
  4606. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  4607. };
  4608. function d3_geo_interpolate(x0, y0, x1, y1) {
  4609. 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);
  4610. var interpolate = d ? function(t) {
  4611. 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;
  4612. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  4613. } : function() {
  4614. return [ x0 * d3_degrees, y0 * d3_degrees ];
  4615. };
  4616. interpolate.distance = d;
  4617. return interpolate;
  4618. }
  4619. d3.geo.length = function(object) {
  4620. d3_geo_lengthSum = 0;
  4621. d3.geo.stream(object, d3_geo_length);
  4622. return d3_geo_lengthSum;
  4623. };
  4624. var d3_geo_lengthSum;
  4625. var d3_geo_length = {
  4626. sphere: d3_noop,
  4627. point: d3_noop,
  4628. lineStart: d3_geo_lengthLineStart,
  4629. lineEnd: d3_noop,
  4630. polygonStart: d3_noop,
  4631. polygonEnd: d3_noop
  4632. };
  4633. function d3_geo_lengthLineStart() {
  4634. var λ0, sinφ0, cosφ0;
  4635. d3_geo_length.point = function(λ, φ) {
  4636. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  4637. d3_geo_length.point = nextPoint;
  4638. };
  4639. d3_geo_length.lineEnd = function() {
  4640. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  4641. };
  4642. function nextPoint(λ, φ) {
  4643. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  4644. 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Δλ);
  4645. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  4646. }
  4647. }
  4648. function d3_geo_azimuthal(scale, angle) {
  4649. function azimuthal(λ, φ) {
  4650. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  4651. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  4652. }
  4653. azimuthal.invert = function(x, y) {
  4654. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  4655. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  4656. };
  4657. return azimuthal;
  4658. }
  4659. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  4660. return Math.sqrt(2 / (1 + cosλcosφ));
  4661. }, function(ρ) {
  4662. return 2 * Math.asin(ρ / 2);
  4663. });
  4664. (d3.geo.azimuthalEqualArea = function() {
  4665. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  4666. }).raw = d3_geo_azimuthalEqualArea;
  4667. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  4668. var c = Math.acos(cosλcosφ);
  4669. return c && c / Math.sin(c);
  4670. }, d3_identity);
  4671. (d3.geo.azimuthalEquidistant = function() {
  4672. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  4673. }).raw = d3_geo_azimuthalEquidistant;
  4674. function d3_geo_conicConformal(φ0, φ1) {
  4675. var cosφ0 = Math.cos(φ0), t = function(φ) {
  4676. return Math.tan(π / 4 + φ / 2);
  4677. }, 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;
  4678. if (!n) return d3_geo_mercator;
  4679. function forward(λ, φ) {
  4680. if (F > 0) {
  4681. if (φ < -halfπ + ε) φ = -halfπ + ε;
  4682. } else {
  4683. if (φ > halfπ - ε) φ = halfπ - ε;
  4684. }
  4685. var ρ = F / Math.pow(t(φ), n);
  4686. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  4687. }
  4688. forward.invert = function(x, y) {
  4689. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  4690. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
  4691. };
  4692. return forward;
  4693. }
  4694. (d3.geo.conicConformal = function() {
  4695. return d3_geo_conic(d3_geo_conicConformal);
  4696. }).raw = d3_geo_conicConformal;
  4697. function d3_geo_conicEquidistant(φ0, φ1) {
  4698. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  4699. if (abs(n) < ε) return d3_geo_equirectangular;
  4700. function forward(λ, φ) {
  4701. var ρ = G - φ;
  4702. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  4703. }
  4704. forward.invert = function(x, y) {
  4705. var ρ0_y = G - y;
  4706. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  4707. };
  4708. return forward;
  4709. }
  4710. (d3.geo.conicEquidistant = function() {
  4711. return d3_geo_conic(d3_geo_conicEquidistant);
  4712. }).raw = d3_geo_conicEquidistant;
  4713. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  4714. return 1 / cosλcosφ;
  4715. }, Math.atan);
  4716. (d3.geo.gnomonic = function() {
  4717. return d3_geo_projection(d3_geo_gnomonic);
  4718. }).raw = d3_geo_gnomonic;
  4719. function d3_geo_mercator(λ, φ) {
  4720. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  4721. }
  4722. d3_geo_mercator.invert = function(x, y) {
  4723. return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
  4724. };
  4725. function d3_geo_mercatorProjection(project) {
  4726. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  4727. m.scale = function() {
  4728. var v = scale.apply(m, arguments);
  4729. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4730. };
  4731. m.translate = function() {
  4732. var v = translate.apply(m, arguments);
  4733. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4734. };
  4735. m.clipExtent = function(_) {
  4736. var v = clipExtent.apply(m, arguments);
  4737. if (v === m) {
  4738. if (clipAuto = _ == null) {
  4739. var k = π * scale(), t = translate();
  4740. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  4741. }
  4742. } else if (clipAuto) {
  4743. v = null;
  4744. }
  4745. return v;
  4746. };
  4747. return m.clipExtent(null);
  4748. }
  4749. (d3.geo.mercator = function() {
  4750. return d3_geo_mercatorProjection(d3_geo_mercator);
  4751. }).raw = d3_geo_mercator;
  4752. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  4753. return 1;
  4754. }, Math.asin);
  4755. (d3.geo.orthographic = function() {
  4756. return d3_geo_projection(d3_geo_orthographic);
  4757. }).raw = d3_geo_orthographic;
  4758. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  4759. return 1 / (1 + cosλcosφ);
  4760. }, function(ρ) {
  4761. return 2 * Math.atan(ρ);
  4762. });
  4763. (d3.geo.stereographic = function() {
  4764. return d3_geo_projection(d3_geo_stereographic);
  4765. }).raw = d3_geo_stereographic;
  4766. function d3_geo_transverseMercator(λ, φ) {
  4767. return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
  4768. }
  4769. d3_geo_transverseMercator.invert = function(x, y) {
  4770. return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
  4771. };
  4772. (d3.geo.transverseMercator = function() {
  4773. var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
  4774. projection.center = function(_) {
  4775. return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
  4776. };
  4777. projection.rotate = function(_) {
  4778. return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
  4779. [ _[0], _[1], _[2] - 90 ]);
  4780. };
  4781. return rotate([ 0, 0, 90 ]);
  4782. }).raw = d3_geo_transverseMercator;
  4783. d3.geom = {};
  4784. function d3_geom_pointX(d) {
  4785. return d[0];
  4786. }
  4787. function d3_geom_pointY(d) {
  4788. return d[1];
  4789. }
  4790. d3.geom.hull = function(vertices) {
  4791. var x = d3_geom_pointX, y = d3_geom_pointY;
  4792. if (arguments.length) return hull(vertices);
  4793. function hull(data) {
  4794. if (data.length < 3) return [];
  4795. var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
  4796. for (i = 0; i < n; i++) {
  4797. points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
  4798. }
  4799. points.sort(d3_geom_hullOrder);
  4800. for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
  4801. var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
  4802. var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
  4803. for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
  4804. for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
  4805. return polygon;
  4806. }
  4807. hull.x = function(_) {
  4808. return arguments.length ? (x = _, hull) : x;
  4809. };
  4810. hull.y = function(_) {
  4811. return arguments.length ? (y = _, hull) : y;
  4812. };
  4813. return hull;
  4814. };
  4815. function d3_geom_hullUpper(points) {
  4816. var n = points.length, hull = [ 0, 1 ], hs = 2;
  4817. for (var i = 2; i < n; i++) {
  4818. while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
  4819. hull[hs++] = i;
  4820. }
  4821. return hull.slice(0, hs);
  4822. }
  4823. function d3_geom_hullOrder(a, b) {
  4824. return a[0] - b[0] || a[1] - b[1];
  4825. }
  4826. d3.geom.polygon = function(coordinates) {
  4827. d3_subclass(coordinates, d3_geom_polygonPrototype);
  4828. return coordinates;
  4829. };
  4830. var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
  4831. d3_geom_polygonPrototype.area = function() {
  4832. var i = -1, n = this.length, a, b = this[n - 1], area = 0;
  4833. while (++i < n) {
  4834. a = b;
  4835. b = this[i];
  4836. area += a[1] * b[0] - a[0] * b[1];
  4837. }
  4838. return area * .5;
  4839. };
  4840. d3_geom_polygonPrototype.centroid = function(k) {
  4841. var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
  4842. if (!arguments.length) k = -1 / (6 * this.area());
  4843. while (++i < n) {
  4844. a = b;
  4845. b = this[i];
  4846. c = a[0] * b[1] - b[0] * a[1];
  4847. x += (a[0] + b[0]) * c;
  4848. y += (a[1] + b[1]) * c;
  4849. }
  4850. return [ x * k, y * k ];
  4851. };
  4852. d3_geom_polygonPrototype.clip = function(subject) {
  4853. 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;
  4854. while (++i < n) {
  4855. input = subject.slice();
  4856. subject.length = 0;
  4857. b = this[i];
  4858. c = input[(m = input.length - closed) - 1];
  4859. j = -1;
  4860. while (++j < m) {
  4861. d = input[j];
  4862. if (d3_geom_polygonInside(d, a, b)) {
  4863. if (!d3_geom_polygonInside(c, a, b)) {
  4864. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4865. }
  4866. subject.push(d);
  4867. } else if (d3_geom_polygonInside(c, a, b)) {
  4868. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4869. }
  4870. c = d;
  4871. }
  4872. if (closed) subject.push(subject[0]);
  4873. a = b;
  4874. }
  4875. return subject;
  4876. };
  4877. function d3_geom_polygonInside(p, a, b) {
  4878. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  4879. }
  4880. function d3_geom_polygonIntersect(c, d, a, b) {
  4881. 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);
  4882. return [ x1 + ua * x21, y1 + ua * y21 ];
  4883. }
  4884. function d3_geom_polygonClosed(coordinates) {
  4885. var a = coordinates[0], b = coordinates[coordinates.length - 1];
  4886. return !(a[0] - b[0] || a[1] - b[1]);
  4887. }
  4888. var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
  4889. function d3_geom_voronoiBeach() {
  4890. d3_geom_voronoiRedBlackNode(this);
  4891. this.edge = this.site = this.circle = null;
  4892. }
  4893. function d3_geom_voronoiCreateBeach(site) {
  4894. var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
  4895. beach.site = site;
  4896. return beach;
  4897. }
  4898. function d3_geom_voronoiDetachBeach(beach) {
  4899. d3_geom_voronoiDetachCircle(beach);
  4900. d3_geom_voronoiBeaches.remove(beach);
  4901. d3_geom_voronoiBeachPool.push(beach);
  4902. d3_geom_voronoiRedBlackNode(beach);
  4903. }
  4904. function d3_geom_voronoiRemoveBeach(beach) {
  4905. var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
  4906. x: x,
  4907. y: y
  4908. }, previous = beach.P, next = beach.N, disappearing = [ beach ];
  4909. d3_geom_voronoiDetachBeach(beach);
  4910. var lArc = previous;
  4911. while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
  4912. previous = lArc.P;
  4913. disappearing.unshift(lArc);
  4914. d3_geom_voronoiDetachBeach(lArc);
  4915. lArc = previous;
  4916. }
  4917. disappearing.unshift(lArc);
  4918. d3_geom_voronoiDetachCircle(lArc);
  4919. var rArc = next;
  4920. while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
  4921. next = rArc.N;
  4922. disappearing.push(rArc);
  4923. d3_geom_voronoiDetachBeach(rArc);
  4924. rArc = next;
  4925. }
  4926. disappearing.push(rArc);
  4927. d3_geom_voronoiDetachCircle(rArc);
  4928. var nArcs = disappearing.length, iArc;
  4929. for (iArc = 1; iArc < nArcs; ++iArc) {
  4930. rArc = disappearing[iArc];
  4931. lArc = disappearing[iArc - 1];
  4932. d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  4933. }
  4934. lArc = disappearing[0];
  4935. rArc = disappearing[nArcs - 1];
  4936. rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
  4937. d3_geom_voronoiAttachCircle(lArc);
  4938. d3_geom_voronoiAttachCircle(rArc);
  4939. }
  4940. function d3_geom_voronoiAddBeach(site) {
  4941. var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
  4942. while (node) {
  4943. dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
  4944. if (dxl > ε) node = node.L; else {
  4945. dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
  4946. if (dxr > ε) {
  4947. if (!node.R) {
  4948. lArc = node;
  4949. break;
  4950. }
  4951. node = node.R;
  4952. } else {
  4953. if (dxl > -ε) {
  4954. lArc = node.P;
  4955. rArc = node;
  4956. } else if (dxr > -ε) {
  4957. lArc = node;
  4958. rArc = node.N;
  4959. } else {
  4960. lArc = rArc = node;
  4961. }
  4962. break;
  4963. }
  4964. }
  4965. }
  4966. var newArc = d3_geom_voronoiCreateBeach(site);
  4967. d3_geom_voronoiBeaches.insert(lArc, newArc);
  4968. if (!lArc && !rArc) return;
  4969. if (lArc === rArc) {
  4970. d3_geom_voronoiDetachCircle(lArc);
  4971. rArc = d3_geom_voronoiCreateBeach(lArc.site);
  4972. d3_geom_voronoiBeaches.insert(newArc, rArc);
  4973. newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4974. d3_geom_voronoiAttachCircle(lArc);
  4975. d3_geom_voronoiAttachCircle(rArc);
  4976. return;
  4977. }
  4978. if (!rArc) {
  4979. newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4980. return;
  4981. }
  4982. d3_geom_voronoiDetachCircle(lArc);
  4983. d3_geom_voronoiDetachCircle(rArc);
  4984. 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 = {
  4985. x: (cy * hb - by * hc) / d + ax,
  4986. y: (bx * hc - cx * hb) / d + ay
  4987. };
  4988. d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
  4989. newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
  4990. rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
  4991. d3_geom_voronoiAttachCircle(lArc);
  4992. d3_geom_voronoiAttachCircle(rArc);
  4993. }
  4994. function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
  4995. var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
  4996. if (!pby2) return rfocx;
  4997. var lArc = arc.P;
  4998. if (!lArc) return -Infinity;
  4999. site = lArc.site;
  5000. var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
  5001. if (!plby2) return lfocx;
  5002. var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
  5003. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  5004. return (rfocx + lfocx) / 2;
  5005. }
  5006. function d3_geom_voronoiRightBreakPoint(arc, directrix) {
  5007. var rArc = arc.N;
  5008. if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
  5009. var site = arc.site;
  5010. return site.y === directrix ? site.x : Infinity;
  5011. }
  5012. function d3_geom_voronoiCell(site) {
  5013. this.site = site;
  5014. this.edges = [];
  5015. }
  5016. d3_geom_voronoiCell.prototype.prepare = function() {
  5017. var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
  5018. while (iHalfEdge--) {
  5019. edge = halfEdges[iHalfEdge].edge;
  5020. if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
  5021. }
  5022. halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
  5023. return halfEdges.length;
  5024. };
  5025. function d3_geom_voronoiCloseCells(extent) {
  5026. 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;
  5027. while (iCell--) {
  5028. cell = cells[iCell];
  5029. if (!cell || !cell.prepare()) continue;
  5030. halfEdges = cell.edges;
  5031. nHalfEdges = halfEdges.length;
  5032. iHalfEdge = 0;
  5033. while (iHalfEdge < nHalfEdges) {
  5034. end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
  5035. start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
  5036. if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
  5037. halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
  5038. x: x0,
  5039. y: abs(x2 - x0) < ε ? y2 : y1
  5040. } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
  5041. x: abs(y2 - y1) < ε ? x2 : x1,
  5042. y: y1
  5043. } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
  5044. x: x1,
  5045. y: abs(x2 - x1) < ε ? y2 : y0
  5046. } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
  5047. x: abs(y2 - y0) < ε ? x2 : x0,
  5048. y: y0
  5049. } : null), cell.site, null));
  5050. ++nHalfEdges;
  5051. }
  5052. }
  5053. }
  5054. }
  5055. function d3_geom_voronoiHalfEdgeOrder(a, b) {
  5056. return b.angle - a.angle;
  5057. }
  5058. function d3_geom_voronoiCircle() {
  5059. d3_geom_voronoiRedBlackNode(this);
  5060. this.x = this.y = this.arc = this.site = this.cy = null;
  5061. }
  5062. function d3_geom_voronoiAttachCircle(arc) {
  5063. var lArc = arc.P, rArc = arc.N;
  5064. if (!lArc || !rArc) return;
  5065. var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
  5066. if (lSite === rSite) return;
  5067. var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
  5068. var d = 2 * (ax * cy - ay * cx);
  5069. if (d >= -ε2) return;
  5070. 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;
  5071. var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
  5072. circle.arc = arc;
  5073. circle.site = cSite;
  5074. circle.x = x + bx;
  5075. circle.y = cy + Math.sqrt(x * x + y * y);
  5076. circle.cy = cy;
  5077. arc.circle = circle;
  5078. var before = null, node = d3_geom_voronoiCircles._;
  5079. while (node) {
  5080. if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
  5081. if (node.L) node = node.L; else {
  5082. before = node.P;
  5083. break;
  5084. }
  5085. } else {
  5086. if (node.R) node = node.R; else {
  5087. before = node;
  5088. break;
  5089. }
  5090. }
  5091. }
  5092. d3_geom_voronoiCircles.insert(before, circle);
  5093. if (!before) d3_geom_voronoiFirstCircle = circle;
  5094. }
  5095. function d3_geom_voronoiDetachCircle(arc) {
  5096. var circle = arc.circle;
  5097. if (circle) {
  5098. if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
  5099. d3_geom_voronoiCircles.remove(circle);
  5100. d3_geom_voronoiCirclePool.push(circle);
  5101. d3_geom_voronoiRedBlackNode(circle);
  5102. arc.circle = null;
  5103. }
  5104. }
  5105. function d3_geom_voronoiClipEdges(extent) {
  5106. 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;
  5107. while (i--) {
  5108. e = edges[i];
  5109. if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
  5110. e.a = e.b = null;
  5111. edges.splice(i, 1);
  5112. }
  5113. }
  5114. }
  5115. function d3_geom_voronoiConnectEdge(edge, extent) {
  5116. var vb = edge.b;
  5117. if (vb) return true;
  5118. 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;
  5119. if (ry === ly) {
  5120. if (fx < x0 || fx >= x1) return;
  5121. if (lx > rx) {
  5122. if (!va) va = {
  5123. x: fx,
  5124. y: y0
  5125. }; else if (va.y >= y1) return;
  5126. vb = {
  5127. x: fx,
  5128. y: y1
  5129. };
  5130. } else {
  5131. if (!va) va = {
  5132. x: fx,
  5133. y: y1
  5134. }; else if (va.y < y0) return;
  5135. vb = {
  5136. x: fx,
  5137. y: y0
  5138. };
  5139. }
  5140. } else {
  5141. fm = (lx - rx) / (ry - ly);
  5142. fb = fy - fm * fx;
  5143. if (fm < -1 || fm > 1) {
  5144. if (lx > rx) {
  5145. if (!va) va = {
  5146. x: (y0 - fb) / fm,
  5147. y: y0
  5148. }; else if (va.y >= y1) return;
  5149. vb = {
  5150. x: (y1 - fb) / fm,
  5151. y: y1
  5152. };
  5153. } else {
  5154. if (!va) va = {
  5155. x: (y1 - fb) / fm,
  5156. y: y1
  5157. }; else if (va.y < y0) return;
  5158. vb = {
  5159. x: (y0 - fb) / fm,
  5160. y: y0
  5161. };
  5162. }
  5163. } else {
  5164. if (ly < ry) {
  5165. if (!va) va = {
  5166. x: x0,
  5167. y: fm * x0 + fb
  5168. }; else if (va.x >= x1) return;
  5169. vb = {
  5170. x: x1,
  5171. y: fm * x1 + fb
  5172. };
  5173. } else {
  5174. if (!va) va = {
  5175. x: x1,
  5176. y: fm * x1 + fb
  5177. }; else if (va.x < x0) return;
  5178. vb = {
  5179. x: x0,
  5180. y: fm * x0 + fb
  5181. };
  5182. }
  5183. }
  5184. }
  5185. edge.a = va;
  5186. edge.b = vb;
  5187. return true;
  5188. }
  5189. function d3_geom_voronoiEdge(lSite, rSite) {
  5190. this.l = lSite;
  5191. this.r = rSite;
  5192. this.a = this.b = null;
  5193. }
  5194. function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
  5195. var edge = new d3_geom_voronoiEdge(lSite, rSite);
  5196. d3_geom_voronoiEdges.push(edge);
  5197. if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
  5198. if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
  5199. d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
  5200. d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
  5201. return edge;
  5202. }
  5203. function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
  5204. var edge = new d3_geom_voronoiEdge(lSite, null);
  5205. edge.a = va;
  5206. edge.b = vb;
  5207. d3_geom_voronoiEdges.push(edge);
  5208. return edge;
  5209. }
  5210. function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
  5211. if (!edge.a && !edge.b) {
  5212. edge.a = vertex;
  5213. edge.l = lSite;
  5214. edge.r = rSite;
  5215. } else if (edge.l === rSite) {
  5216. edge.b = vertex;
  5217. } else {
  5218. edge.a = vertex;
  5219. }
  5220. }
  5221. function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
  5222. var va = edge.a, vb = edge.b;
  5223. this.edge = edge;
  5224. this.site = lSite;
  5225. 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);
  5226. }
  5227. d3_geom_voronoiHalfEdge.prototype = {
  5228. start: function() {
  5229. return this.edge.l === this.site ? this.edge.a : this.edge.b;
  5230. },
  5231. end: function() {
  5232. return this.edge.l === this.site ? this.edge.b : this.edge.a;
  5233. }
  5234. };
  5235. function d3_geom_voronoiRedBlackTree() {
  5236. this._ = null;
  5237. }
  5238. function d3_geom_voronoiRedBlackNode(node) {
  5239. node.U = node.C = node.L = node.R = node.P = node.N = null;
  5240. }
  5241. d3_geom_voronoiRedBlackTree.prototype = {
  5242. insert: function(after, node) {
  5243. var parent, grandpa, uncle;
  5244. if (after) {
  5245. node.P = after;
  5246. node.N = after.N;
  5247. if (after.N) after.N.P = node;
  5248. after.N = node;
  5249. if (after.R) {
  5250. after = after.R;
  5251. while (after.L) after = after.L;
  5252. after.L = node;
  5253. } else {
  5254. after.R = node;
  5255. }
  5256. parent = after;
  5257. } else if (this._) {
  5258. after = d3_geom_voronoiRedBlackFirst(this._);
  5259. node.P = null;
  5260. node.N = after;
  5261. after.P = after.L = node;
  5262. parent = after;
  5263. } else {
  5264. node.P = node.N = null;
  5265. this._ = node;
  5266. parent = null;
  5267. }
  5268. node.L = node.R = null;
  5269. node.U = parent;
  5270. node.C = true;
  5271. after = node;
  5272. while (parent && parent.C) {
  5273. grandpa = parent.U;
  5274. if (parent === grandpa.L) {
  5275. uncle = grandpa.R;
  5276. if (uncle && uncle.C) {
  5277. parent.C = uncle.C = false;
  5278. grandpa.C = true;
  5279. after = grandpa;
  5280. } else {
  5281. if (after === parent.R) {
  5282. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5283. after = parent;
  5284. parent = after.U;
  5285. }
  5286. parent.C = false;
  5287. grandpa.C = true;
  5288. d3_geom_voronoiRedBlackRotateRight(this, grandpa);
  5289. }
  5290. } else {
  5291. uncle = grandpa.L;
  5292. if (uncle && uncle.C) {
  5293. parent.C = uncle.C = false;
  5294. grandpa.C = true;
  5295. after = grandpa;
  5296. } else {
  5297. if (after === parent.L) {
  5298. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5299. after = parent;
  5300. parent = after.U;
  5301. }
  5302. parent.C = false;
  5303. grandpa.C = true;
  5304. d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
  5305. }
  5306. }
  5307. parent = after.U;
  5308. }
  5309. this._.C = false;
  5310. },
  5311. remove: function(node) {
  5312. if (node.N) node.N.P = node.P;
  5313. if (node.P) node.P.N = node.N;
  5314. node.N = node.P = null;
  5315. var parent = node.U, sibling, left = node.L, right = node.R, next, red;
  5316. if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
  5317. if (parent) {
  5318. if (parent.L === node) parent.L = next; else parent.R = next;
  5319. } else {
  5320. this._ = next;
  5321. }
  5322. if (left && right) {
  5323. red = next.C;
  5324. next.C = node.C;
  5325. next.L = left;
  5326. left.U = next;
  5327. if (next !== right) {
  5328. parent = next.U;
  5329. next.U = node.U;
  5330. node = next.R;
  5331. parent.L = node;
  5332. next.R = right;
  5333. right.U = next;
  5334. } else {
  5335. next.U = parent;
  5336. parent = next;
  5337. node = next.R;
  5338. }
  5339. } else {
  5340. red = node.C;
  5341. node = next;
  5342. }
  5343. if (node) node.U = parent;
  5344. if (red) return;
  5345. if (node && node.C) {
  5346. node.C = false;
  5347. return;
  5348. }
  5349. do {
  5350. if (node === this._) break;
  5351. if (node === parent.L) {
  5352. sibling = parent.R;
  5353. if (sibling.C) {
  5354. sibling.C = false;
  5355. parent.C = true;
  5356. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5357. sibling = parent.R;
  5358. }
  5359. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5360. if (!sibling.R || !sibling.R.C) {
  5361. sibling.L.C = false;
  5362. sibling.C = true;
  5363. d3_geom_voronoiRedBlackRotateRight(this, sibling);
  5364. sibling = parent.R;
  5365. }
  5366. sibling.C = parent.C;
  5367. parent.C = sibling.R.C = false;
  5368. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5369. node = this._;
  5370. break;
  5371. }
  5372. } else {
  5373. sibling = parent.L;
  5374. if (sibling.C) {
  5375. sibling.C = false;
  5376. parent.C = true;
  5377. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5378. sibling = parent.L;
  5379. }
  5380. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5381. if (!sibling.L || !sibling.L.C) {
  5382. sibling.R.C = false;
  5383. sibling.C = true;
  5384. d3_geom_voronoiRedBlackRotateLeft(this, sibling);
  5385. sibling = parent.L;
  5386. }
  5387. sibling.C = parent.C;
  5388. parent.C = sibling.L.C = false;
  5389. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5390. node = this._;
  5391. break;
  5392. }
  5393. }
  5394. sibling.C = true;
  5395. node = parent;
  5396. parent = parent.U;
  5397. } while (!node.C);
  5398. if (node) node.C = false;
  5399. }
  5400. };
  5401. function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
  5402. var p = node, q = node.R, parent = p.U;
  5403. if (parent) {
  5404. if (parent.L === p) parent.L = q; else parent.R = q;
  5405. } else {
  5406. tree._ = q;
  5407. }
  5408. q.U = parent;
  5409. p.U = q;
  5410. p.R = q.L;
  5411. if (p.R) p.R.U = p;
  5412. q.L = p;
  5413. }
  5414. function d3_geom_voronoiRedBlackRotateRight(tree, node) {
  5415. var p = node, q = node.L, parent = p.U;
  5416. if (parent) {
  5417. if (parent.L === p) parent.L = q; else parent.R = q;
  5418. } else {
  5419. tree._ = q;
  5420. }
  5421. q.U = parent;
  5422. p.U = q;
  5423. p.L = q.R;
  5424. if (p.L) p.L.U = p;
  5425. q.R = p;
  5426. }
  5427. function d3_geom_voronoiRedBlackFirst(node) {
  5428. while (node.L) node = node.L;
  5429. return node;
  5430. }
  5431. function d3_geom_voronoi(sites, bbox) {
  5432. var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
  5433. d3_geom_voronoiEdges = [];
  5434. d3_geom_voronoiCells = new Array(sites.length);
  5435. d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
  5436. d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
  5437. while (true) {
  5438. circle = d3_geom_voronoiFirstCircle;
  5439. if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
  5440. if (site.x !== x0 || site.y !== y0) {
  5441. d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
  5442. d3_geom_voronoiAddBeach(site);
  5443. x0 = site.x, y0 = site.y;
  5444. }
  5445. site = sites.pop();
  5446. } else if (circle) {
  5447. d3_geom_voronoiRemoveBeach(circle.arc);
  5448. } else {
  5449. break;
  5450. }
  5451. }
  5452. if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
  5453. var diagram = {
  5454. cells: d3_geom_voronoiCells,
  5455. edges: d3_geom_voronoiEdges
  5456. };
  5457. d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
  5458. return diagram;
  5459. }
  5460. function d3_geom_voronoiVertexOrder(a, b) {
  5461. return b.y - a.y || b.x - a.x;
  5462. }
  5463. d3.geom.voronoi = function(points) {
  5464. var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
  5465. if (points) return voronoi(points);
  5466. function voronoi(data) {
  5467. var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
  5468. d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
  5469. var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
  5470. var s = e.start();
  5471. return [ s.x, s.y ];
  5472. }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
  5473. polygon.point = data[i];
  5474. });
  5475. return polygons;
  5476. }
  5477. function sites(data) {
  5478. return data.map(function(d, i) {
  5479. return {
  5480. x: Math.round(fx(d, i) / ε) * ε,
  5481. y: Math.round(fy(d, i) / ε) * ε,
  5482. i: i
  5483. };
  5484. });
  5485. }
  5486. voronoi.links = function(data) {
  5487. return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
  5488. return edge.l && edge.r;
  5489. }).map(function(edge) {
  5490. return {
  5491. source: data[edge.l.i],
  5492. target: data[edge.r.i]
  5493. };
  5494. });
  5495. };
  5496. voronoi.triangles = function(data) {
  5497. var triangles = [];
  5498. d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
  5499. 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;
  5500. while (++j < m) {
  5501. e0 = e1;
  5502. s0 = s1;
  5503. e1 = edges[j].edge;
  5504. s1 = e1.l === site ? e1.r : e1.l;
  5505. if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
  5506. triangles.push([ data[i], data[s0.i], data[s1.i] ]);
  5507. }
  5508. }
  5509. });
  5510. return triangles;
  5511. };
  5512. voronoi.x = function(_) {
  5513. return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
  5514. };
  5515. voronoi.y = function(_) {
  5516. return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
  5517. };
  5518. voronoi.clipExtent = function(_) {
  5519. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
  5520. clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
  5521. return voronoi;
  5522. };
  5523. voronoi.size = function(_) {
  5524. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
  5525. return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
  5526. };
  5527. return voronoi;
  5528. };
  5529. var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
  5530. function d3_geom_voronoiTriangleArea(a, b, c) {
  5531. return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
  5532. }
  5533. d3.geom.delaunay = function(vertices) {
  5534. return d3.geom.voronoi().triangles(vertices);
  5535. };
  5536. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  5537. var x = d3_geom_pointX, y = d3_geom_pointY, compat;
  5538. if (compat = arguments.length) {
  5539. x = d3_geom_quadtreeCompatX;
  5540. y = d3_geom_quadtreeCompatY;
  5541. if (compat === 3) {
  5542. y2 = y1;
  5543. x2 = x1;
  5544. y1 = x1 = 0;
  5545. }
  5546. return quadtree(points);
  5547. }
  5548. function quadtree(data) {
  5549. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  5550. if (x1 != null) {
  5551. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  5552. } else {
  5553. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  5554. xs = [], ys = [];
  5555. n = data.length;
  5556. if (compat) for (i = 0; i < n; ++i) {
  5557. d = data[i];
  5558. if (d.x < x1_) x1_ = d.x;
  5559. if (d.y < y1_) y1_ = d.y;
  5560. if (d.x > x2_) x2_ = d.x;
  5561. if (d.y > y2_) y2_ = d.y;
  5562. xs.push(d.x);
  5563. ys.push(d.y);
  5564. } else for (i = 0; i < n; ++i) {
  5565. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  5566. if (x_ < x1_) x1_ = x_;
  5567. if (y_ < y1_) y1_ = y_;
  5568. if (x_ > x2_) x2_ = x_;
  5569. if (y_ > y2_) y2_ = y_;
  5570. xs.push(x_);
  5571. ys.push(y_);
  5572. }
  5573. }
  5574. var dx = x2_ - x1_, dy = y2_ - y1_;
  5575. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  5576. function insert(n, d, x, y, x1, y1, x2, y2) {
  5577. if (isNaN(x) || isNaN(y)) return;
  5578. if (n.leaf) {
  5579. var nx = n.x, ny = n.y;
  5580. if (nx != null) {
  5581. if (abs(nx - x) + abs(ny - y) < .01) {
  5582. insertChild(n, d, x, y, x1, y1, x2, y2);
  5583. } else {
  5584. var nPoint = n.point;
  5585. n.x = n.y = n.point = null;
  5586. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  5587. insertChild(n, d, x, y, x1, y1, x2, y2);
  5588. }
  5589. } else {
  5590. n.x = x, n.y = y, n.point = d;
  5591. }
  5592. } else {
  5593. insertChild(n, d, x, y, x1, y1, x2, y2);
  5594. }
  5595. }
  5596. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  5597. var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
  5598. n.leaf = false;
  5599. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  5600. if (right) x1 = xm; else x2 = xm;
  5601. if (below) y1 = ym; else y2 = ym;
  5602. insert(n, d, x, y, x1, y1, x2, y2);
  5603. }
  5604. var root = d3_geom_quadtreeNode();
  5605. root.add = function(d) {
  5606. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  5607. };
  5608. root.visit = function(f) {
  5609. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  5610. };
  5611. root.find = function(point) {
  5612. return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
  5613. };
  5614. i = -1;
  5615. if (x1 == null) {
  5616. while (++i < n) {
  5617. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  5618. }
  5619. --i;
  5620. } else data.forEach(root.add);
  5621. xs = ys = data = d = null;
  5622. return root;
  5623. }
  5624. quadtree.x = function(_) {
  5625. return arguments.length ? (x = _, quadtree) : x;
  5626. };
  5627. quadtree.y = function(_) {
  5628. return arguments.length ? (y = _, quadtree) : y;
  5629. };
  5630. quadtree.extent = function(_) {
  5631. if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
  5632. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
  5633. y2 = +_[1][1];
  5634. return quadtree;
  5635. };
  5636. quadtree.size = function(_) {
  5637. if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
  5638. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
  5639. return quadtree;
  5640. };
  5641. return quadtree;
  5642. };
  5643. function d3_geom_quadtreeCompatX(d) {
  5644. return d.x;
  5645. }
  5646. function d3_geom_quadtreeCompatY(d) {
  5647. return d.y;
  5648. }
  5649. function d3_geom_quadtreeNode() {
  5650. return {
  5651. leaf: true,
  5652. nodes: [],
  5653. point: null,
  5654. x: null,
  5655. y: null
  5656. };
  5657. }
  5658. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  5659. if (!f(node, x1, y1, x2, y2)) {
  5660. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  5661. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  5662. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  5663. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  5664. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  5665. }
  5666. }
  5667. function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
  5668. var minDistance2 = Infinity, closestPoint;
  5669. (function find(node, x1, y1, x2, y2) {
  5670. if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
  5671. if (point = node.point) {
  5672. var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
  5673. if (distance2 < minDistance2) {
  5674. var distance = Math.sqrt(minDistance2 = distance2);
  5675. x0 = x - distance, y0 = y - distance;
  5676. x3 = x + distance, y3 = y + distance;
  5677. closestPoint = point;
  5678. }
  5679. }
  5680. var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
  5681. for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
  5682. if (node = children[i & 3]) switch (i & 3) {
  5683. case 0:
  5684. find(node, x1, y1, xm, ym);
  5685. break;
  5686. case 1:
  5687. find(node, xm, y1, x2, ym);
  5688. break;
  5689. case 2:
  5690. find(node, x1, ym, xm, y2);
  5691. break;
  5692. case 3:
  5693. find(node, xm, ym, x2, y2);
  5694. break;
  5695. }
  5696. }
  5697. })(root, x0, y0, x3, y3);
  5698. return closestPoint;
  5699. }
  5700. d3.interpolateRgb = d3_interpolateRgb;
  5701. function d3_interpolateRgb(a, b) {
  5702. a = d3.rgb(a);
  5703. b = d3.rgb(b);
  5704. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  5705. return function(t) {
  5706. 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));
  5707. };
  5708. }
  5709. d3.interpolateObject = d3_interpolateObject;
  5710. function d3_interpolateObject(a, b) {
  5711. var i = {}, c = {}, k;
  5712. for (k in a) {
  5713. if (k in b) {
  5714. i[k] = d3_interpolate(a[k], b[k]);
  5715. } else {
  5716. c[k] = a[k];
  5717. }
  5718. }
  5719. for (k in b) {
  5720. if (!(k in a)) {
  5721. c[k] = b[k];
  5722. }
  5723. }
  5724. return function(t) {
  5725. for (k in i) c[k] = i[k](t);
  5726. return c;
  5727. };
  5728. }
  5729. d3.interpolateNumber = d3_interpolateNumber;
  5730. function d3_interpolateNumber(a, b) {
  5731. a = +a, b = +b;
  5732. return function(t) {
  5733. return a * (1 - t) + b * t;
  5734. };
  5735. }
  5736. d3.interpolateString = d3_interpolateString;
  5737. function d3_interpolateString(a, b) {
  5738. var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
  5739. a = a + "", b = b + "";
  5740. while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
  5741. if ((bs = bm.index) > bi) {
  5742. bs = b.slice(bi, bs);
  5743. if (s[i]) s[i] += bs; else s[++i] = bs;
  5744. }
  5745. if ((am = am[0]) === (bm = bm[0])) {
  5746. if (s[i]) s[i] += bm; else s[++i] = bm;
  5747. } else {
  5748. s[++i] = null;
  5749. q.push({
  5750. i: i,
  5751. x: d3_interpolateNumber(am, bm)
  5752. });
  5753. }
  5754. bi = d3_interpolate_numberB.lastIndex;
  5755. }
  5756. if (bi < b.length) {
  5757. bs = b.slice(bi);
  5758. if (s[i]) s[i] += bs; else s[++i] = bs;
  5759. }
  5760. return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
  5761. return b(t) + "";
  5762. }) : function() {
  5763. return b;
  5764. } : (b = q.length, function(t) {
  5765. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  5766. return s.join("");
  5767. });
  5768. }
  5769. var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
  5770. d3.interpolate = d3_interpolate;
  5771. function d3_interpolate(a, b) {
  5772. var i = d3.interpolators.length, f;
  5773. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  5774. return f;
  5775. }
  5776. d3.interpolators = [ function(a, b) {
  5777. var t = typeof b;
  5778. return (t === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.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);
  5779. } ];
  5780. d3.interpolateArray = d3_interpolateArray;
  5781. function d3_interpolateArray(a, b) {
  5782. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  5783. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  5784. for (;i < na; ++i) c[i] = a[i];
  5785. for (;i < nb; ++i) c[i] = b[i];
  5786. return function(t) {
  5787. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  5788. return c;
  5789. };
  5790. }
  5791. var d3_ease_default = function() {
  5792. return d3_identity;
  5793. };
  5794. var d3_ease = d3.map({
  5795. linear: d3_ease_default,
  5796. poly: d3_ease_poly,
  5797. quad: function() {
  5798. return d3_ease_quad;
  5799. },
  5800. cubic: function() {
  5801. return d3_ease_cubic;
  5802. },
  5803. sin: function() {
  5804. return d3_ease_sin;
  5805. },
  5806. exp: function() {
  5807. return d3_ease_exp;
  5808. },
  5809. circle: function() {
  5810. return d3_ease_circle;
  5811. },
  5812. elastic: d3_ease_elastic,
  5813. back: d3_ease_back,
  5814. bounce: function() {
  5815. return d3_ease_bounce;
  5816. }
  5817. });
  5818. var d3_ease_mode = d3.map({
  5819. "in": d3_identity,
  5820. out: d3_ease_reverse,
  5821. "in-out": d3_ease_reflect,
  5822. "out-in": function(f) {
  5823. return d3_ease_reflect(d3_ease_reverse(f));
  5824. }
  5825. });
  5826. d3.ease = function(name) {
  5827. var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
  5828. t = d3_ease.get(t) || d3_ease_default;
  5829. m = d3_ease_mode.get(m) || d3_identity;
  5830. return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
  5831. };
  5832. function d3_ease_clamp(f) {
  5833. return function(t) {
  5834. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  5835. };
  5836. }
  5837. function d3_ease_reverse(f) {
  5838. return function(t) {
  5839. return 1 - f(1 - t);
  5840. };
  5841. }
  5842. function d3_ease_reflect(f) {
  5843. return function(t) {
  5844. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  5845. };
  5846. }
  5847. function d3_ease_quad(t) {
  5848. return t * t;
  5849. }
  5850. function d3_ease_cubic(t) {
  5851. return t * t * t;
  5852. }
  5853. function d3_ease_cubicInOut(t) {
  5854. if (t <= 0) return 0;
  5855. if (t >= 1) return 1;
  5856. var t2 = t * t, t3 = t2 * t;
  5857. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  5858. }
  5859. function d3_ease_poly(e) {
  5860. return function(t) {
  5861. return Math.pow(t, e);
  5862. };
  5863. }
  5864. function d3_ease_sin(t) {
  5865. return 1 - Math.cos(t * halfπ);
  5866. }
  5867. function d3_ease_exp(t) {
  5868. return Math.pow(2, 10 * (t - 1));
  5869. }
  5870. function d3_ease_circle(t) {
  5871. return 1 - Math.sqrt(1 - t * t);
  5872. }
  5873. function d3_ease_elastic(a, p) {
  5874. var s;
  5875. if (arguments.length < 2) p = .45;
  5876. if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
  5877. return function(t) {
  5878. return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
  5879. };
  5880. }
  5881. function d3_ease_back(s) {
  5882. if (!s) s = 1.70158;
  5883. return function(t) {
  5884. return t * t * ((s + 1) * t - s);
  5885. };
  5886. }
  5887. function d3_ease_bounce(t) {
  5888. 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;
  5889. }
  5890. d3.interpolateHcl = d3_interpolateHcl;
  5891. function d3_interpolateHcl(a, b) {
  5892. a = d3.hcl(a);
  5893. b = d3.hcl(b);
  5894. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  5895. if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
  5896. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5897. return function(t) {
  5898. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  5899. };
  5900. }
  5901. d3.interpolateHsl = d3_interpolateHsl;
  5902. function d3_interpolateHsl(a, b) {
  5903. a = d3.hsl(a);
  5904. b = d3.hsl(b);
  5905. var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
  5906. if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
  5907. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5908. return function(t) {
  5909. return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
  5910. };
  5911. }
  5912. d3.interpolateLab = d3_interpolateLab;
  5913. function d3_interpolateLab(a, b) {
  5914. a = d3.lab(a);
  5915. b = d3.lab(b);
  5916. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  5917. return function(t) {
  5918. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  5919. };
  5920. }
  5921. d3.interpolateRound = d3_interpolateRound;
  5922. function d3_interpolateRound(a, b) {
  5923. b -= a;
  5924. return function(t) {
  5925. return Math.round(a + b * t);
  5926. };
  5927. }
  5928. d3.transform = function(string) {
  5929. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  5930. return (d3.transform = function(string) {
  5931. if (string != null) {
  5932. g.setAttribute("transform", string);
  5933. var t = g.transform.baseVal.consolidate();
  5934. }
  5935. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  5936. })(string);
  5937. };
  5938. function d3_transform(m) {
  5939. 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;
  5940. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  5941. r0[0] *= -1;
  5942. r0[1] *= -1;
  5943. kx *= -1;
  5944. kz *= -1;
  5945. }
  5946. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  5947. this.translate = [ m.e, m.f ];
  5948. this.scale = [ kx, ky ];
  5949. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  5950. }
  5951. d3_transform.prototype.toString = function() {
  5952. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  5953. };
  5954. function d3_transformDot(a, b) {
  5955. return a[0] * b[0] + a[1] * b[1];
  5956. }
  5957. function d3_transformNormalize(a) {
  5958. var k = Math.sqrt(d3_transformDot(a, a));
  5959. if (k) {
  5960. a[0] /= k;
  5961. a[1] /= k;
  5962. }
  5963. return k;
  5964. }
  5965. function d3_transformCombine(a, b, k) {
  5966. a[0] += k * b[0];
  5967. a[1] += k * b[1];
  5968. return a;
  5969. }
  5970. var d3_transformIdentity = {
  5971. a: 1,
  5972. b: 0,
  5973. c: 0,
  5974. d: 1,
  5975. e: 0,
  5976. f: 0
  5977. };
  5978. d3.interpolateTransform = d3_interpolateTransform;
  5979. function d3_interpolateTransform(a, b) {
  5980. var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
  5981. if (ta[0] != tb[0] || ta[1] != tb[1]) {
  5982. s.push("translate(", null, ",", null, ")");
  5983. q.push({
  5984. i: 1,
  5985. x: d3_interpolateNumber(ta[0], tb[0])
  5986. }, {
  5987. i: 3,
  5988. x: d3_interpolateNumber(ta[1], tb[1])
  5989. });
  5990. } else if (tb[0] || tb[1]) {
  5991. s.push("translate(" + tb + ")");
  5992. } else {
  5993. s.push("");
  5994. }
  5995. if (ra != rb) {
  5996. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  5997. q.push({
  5998. i: s.push(s.pop() + "rotate(", null, ")") - 2,
  5999. x: d3_interpolateNumber(ra, rb)
  6000. });
  6001. } else if (rb) {
  6002. s.push(s.pop() + "rotate(" + rb + ")");
  6003. }
  6004. if (wa != wb) {
  6005. q.push({
  6006. i: s.push(s.pop() + "skewX(", null, ")") - 2,
  6007. x: d3_interpolateNumber(wa, wb)
  6008. });
  6009. } else if (wb) {
  6010. s.push(s.pop() + "skewX(" + wb + ")");
  6011. }
  6012. if (ka[0] != kb[0] || ka[1] != kb[1]) {
  6013. n = s.push(s.pop() + "scale(", null, ",", null, ")");
  6014. q.push({
  6015. i: n - 4,
  6016. x: d3_interpolateNumber(ka[0], kb[0])
  6017. }, {
  6018. i: n - 2,
  6019. x: d3_interpolateNumber(ka[1], kb[1])
  6020. });
  6021. } else if (kb[0] != 1 || kb[1] != 1) {
  6022. s.push(s.pop() + "scale(" + kb + ")");
  6023. }
  6024. n = q.length;
  6025. return function(t) {
  6026. var i = -1, o;
  6027. while (++i < n) s[(o = q[i]).i] = o.x(t);
  6028. return s.join("");
  6029. };
  6030. }
  6031. function d3_uninterpolateNumber(a, b) {
  6032. b = (b -= a = +a) || 1 / b;
  6033. return function(x) {
  6034. return (x - a) / b;
  6035. };
  6036. }
  6037. function d3_uninterpolateClamp(a, b) {
  6038. b = (b -= a = +a) || 1 / b;
  6039. return function(x) {
  6040. return Math.max(0, Math.min(1, (x - a) / b));
  6041. };
  6042. }
  6043. d3.layout = {};
  6044. d3.layout.bundle = function() {
  6045. return function(links) {
  6046. var paths = [], i = -1, n = links.length;
  6047. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  6048. return paths;
  6049. };
  6050. };
  6051. function d3_layout_bundlePath(link) {
  6052. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  6053. while (start !== lca) {
  6054. start = start.parent;
  6055. points.push(start);
  6056. }
  6057. var k = points.length;
  6058. while (end !== lca) {
  6059. points.splice(k, 0, end);
  6060. end = end.parent;
  6061. }
  6062. return points;
  6063. }
  6064. function d3_layout_bundleAncestors(node) {
  6065. var ancestors = [], parent = node.parent;
  6066. while (parent != null) {
  6067. ancestors.push(node);
  6068. node = parent;
  6069. parent = parent.parent;
  6070. }
  6071. ancestors.push(node);
  6072. return ancestors;
  6073. }
  6074. function d3_layout_bundleLeastCommonAncestor(a, b) {
  6075. if (a === b) return a;
  6076. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  6077. while (aNode === bNode) {
  6078. sharedNode = aNode;
  6079. aNode = aNodes.pop();
  6080. bNode = bNodes.pop();
  6081. }
  6082. return sharedNode;
  6083. }
  6084. d3.layout.chord = function() {
  6085. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  6086. function relayout() {
  6087. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  6088. chords = [];
  6089. groups = [];
  6090. k = 0, i = -1;
  6091. while (++i < n) {
  6092. x = 0, j = -1;
  6093. while (++j < n) {
  6094. x += matrix[i][j];
  6095. }
  6096. groupSums.push(x);
  6097. subgroupIndex.push(d3.range(n));
  6098. k += x;
  6099. }
  6100. if (sortGroups) {
  6101. groupIndex.sort(function(a, b) {
  6102. return sortGroups(groupSums[a], groupSums[b]);
  6103. });
  6104. }
  6105. if (sortSubgroups) {
  6106. subgroupIndex.forEach(function(d, i) {
  6107. d.sort(function(a, b) {
  6108. return sortSubgroups(matrix[i][a], matrix[i][b]);
  6109. });
  6110. });
  6111. }
  6112. k = (τ - padding * n) / k;
  6113. x = 0, i = -1;
  6114. while (++i < n) {
  6115. x0 = x, j = -1;
  6116. while (++j < n) {
  6117. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  6118. subgroups[di + "-" + dj] = {
  6119. index: di,
  6120. subindex: dj,
  6121. startAngle: a0,
  6122. endAngle: a1,
  6123. value: v
  6124. };
  6125. }
  6126. groups[di] = {
  6127. index: di,
  6128. startAngle: x0,
  6129. endAngle: x,
  6130. value: (x - x0) / k
  6131. };
  6132. x += padding;
  6133. }
  6134. i = -1;
  6135. while (++i < n) {
  6136. j = i - 1;
  6137. while (++j < n) {
  6138. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  6139. if (source.value || target.value) {
  6140. chords.push(source.value < target.value ? {
  6141. source: target,
  6142. target: source
  6143. } : {
  6144. source: source,
  6145. target: target
  6146. });
  6147. }
  6148. }
  6149. }
  6150. if (sortChords) resort();
  6151. }
  6152. function resort() {
  6153. chords.sort(function(a, b) {
  6154. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  6155. });
  6156. }
  6157. chord.matrix = function(x) {
  6158. if (!arguments.length) return matrix;
  6159. n = (matrix = x) && matrix.length;
  6160. chords = groups = null;
  6161. return chord;
  6162. };
  6163. chord.padding = function(x) {
  6164. if (!arguments.length) return padding;
  6165. padding = x;
  6166. chords = groups = null;
  6167. return chord;
  6168. };
  6169. chord.sortGroups = function(x) {
  6170. if (!arguments.length) return sortGroups;
  6171. sortGroups = x;
  6172. chords = groups = null;
  6173. return chord;
  6174. };
  6175. chord.sortSubgroups = function(x) {
  6176. if (!arguments.length) return sortSubgroups;
  6177. sortSubgroups = x;
  6178. chords = null;
  6179. return chord;
  6180. };
  6181. chord.sortChords = function(x) {
  6182. if (!arguments.length) return sortChords;
  6183. sortChords = x;
  6184. if (chords) resort();
  6185. return chord;
  6186. };
  6187. chord.chords = function() {
  6188. if (!chords) relayout();
  6189. return chords;
  6190. };
  6191. chord.groups = function() {
  6192. if (!groups) relayout();
  6193. return groups;
  6194. };
  6195. return chord;
  6196. };
  6197. d3.layout.force = function() {
  6198. var force = {}, event = d3.dispatch("start", "tick", "end"), size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
  6199. function repulse(node) {
  6200. return function(quad, x1, _, x2) {
  6201. if (quad.point !== node) {
  6202. var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
  6203. if (dw * dw / theta2 < dn) {
  6204. if (dn < chargeDistance2) {
  6205. var k = quad.charge / dn;
  6206. node.px -= dx * k;
  6207. node.py -= dy * k;
  6208. }
  6209. return true;
  6210. }
  6211. if (quad.point && dn && dn < chargeDistance2) {
  6212. var k = quad.pointCharge / dn;
  6213. node.px -= dx * k;
  6214. node.py -= dy * k;
  6215. }
  6216. }
  6217. return !quad.charge;
  6218. };
  6219. }
  6220. force.tick = function() {
  6221. if ((alpha *= .99) < .005) {
  6222. event.end({
  6223. type: "end",
  6224. alpha: alpha = 0
  6225. });
  6226. return true;
  6227. }
  6228. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  6229. for (i = 0; i < m; ++i) {
  6230. o = links[i];
  6231. s = o.source;
  6232. t = o.target;
  6233. x = t.x - s.x;
  6234. y = t.y - s.y;
  6235. if (l = x * x + y * y) {
  6236. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  6237. x *= l;
  6238. y *= l;
  6239. t.x -= x * (k = s.weight / (t.weight + s.weight));
  6240. t.y -= y * k;
  6241. s.x += x * (k = 1 - k);
  6242. s.y += y * k;
  6243. }
  6244. }
  6245. if (k = alpha * gravity) {
  6246. x = size[0] / 2;
  6247. y = size[1] / 2;
  6248. i = -1;
  6249. if (k) while (++i < n) {
  6250. o = nodes[i];
  6251. o.x += (x - o.x) * k;
  6252. o.y += (y - o.y) * k;
  6253. }
  6254. }
  6255. if (charge) {
  6256. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  6257. i = -1;
  6258. while (++i < n) {
  6259. if (!(o = nodes[i]).fixed) {
  6260. q.visit(repulse(o));
  6261. }
  6262. }
  6263. }
  6264. i = -1;
  6265. while (++i < n) {
  6266. o = nodes[i];
  6267. if (o.fixed) {
  6268. o.x = o.px;
  6269. o.y = o.py;
  6270. } else {
  6271. o.x -= (o.px - (o.px = o.x)) * friction;
  6272. o.y -= (o.py - (o.py = o.y)) * friction;
  6273. }
  6274. }
  6275. event.tick({
  6276. type: "tick",
  6277. alpha: alpha
  6278. });
  6279. };
  6280. force.nodes = function(x) {
  6281. if (!arguments.length) return nodes;
  6282. nodes = x;
  6283. return force;
  6284. };
  6285. force.links = function(x) {
  6286. if (!arguments.length) return links;
  6287. links = x;
  6288. return force;
  6289. };
  6290. force.size = function(x) {
  6291. if (!arguments.length) return size;
  6292. size = x;
  6293. return force;
  6294. };
  6295. force.linkDistance = function(x) {
  6296. if (!arguments.length) return linkDistance;
  6297. linkDistance = typeof x === "function" ? x : +x;
  6298. return force;
  6299. };
  6300. force.distance = force.linkDistance;
  6301. force.linkStrength = function(x) {
  6302. if (!arguments.length) return linkStrength;
  6303. linkStrength = typeof x === "function" ? x : +x;
  6304. return force;
  6305. };
  6306. force.friction = function(x) {
  6307. if (!arguments.length) return friction;
  6308. friction = +x;
  6309. return force;
  6310. };
  6311. force.charge = function(x) {
  6312. if (!arguments.length) return charge;
  6313. charge = typeof x === "function" ? x : +x;
  6314. return force;
  6315. };
  6316. force.chargeDistance = function(x) {
  6317. if (!arguments.length) return Math.sqrt(chargeDistance2);
  6318. chargeDistance2 = x * x;
  6319. return force;
  6320. };
  6321. force.gravity = function(x) {
  6322. if (!arguments.length) return gravity;
  6323. gravity = +x;
  6324. return force;
  6325. };
  6326. force.theta = function(x) {
  6327. if (!arguments.length) return Math.sqrt(theta2);
  6328. theta2 = x * x;
  6329. return force;
  6330. };
  6331. force.alpha = function(x) {
  6332. if (!arguments.length) return alpha;
  6333. x = +x;
  6334. if (alpha) {
  6335. if (x > 0) alpha = x; else alpha = 0;
  6336. } else if (x > 0) {
  6337. event.start({
  6338. type: "start",
  6339. alpha: alpha = x
  6340. });
  6341. d3.timer(force.tick);
  6342. }
  6343. return force;
  6344. };
  6345. force.start = function() {
  6346. var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  6347. for (i = 0; i < n; ++i) {
  6348. (o = nodes[i]).index = i;
  6349. o.weight = 0;
  6350. }
  6351. for (i = 0; i < m; ++i) {
  6352. o = links[i];
  6353. if (typeof o.source == "number") o.source = nodes[o.source];
  6354. if (typeof o.target == "number") o.target = nodes[o.target];
  6355. ++o.source.weight;
  6356. ++o.target.weight;
  6357. }
  6358. for (i = 0; i < n; ++i) {
  6359. o = nodes[i];
  6360. if (isNaN(o.x)) o.x = position("x", w);
  6361. if (isNaN(o.y)) o.y = position("y", h);
  6362. if (isNaN(o.px)) o.px = o.x;
  6363. if (isNaN(o.py)) o.py = o.y;
  6364. }
  6365. distances = [];
  6366. 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;
  6367. strengths = [];
  6368. 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;
  6369. charges = [];
  6370. 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;
  6371. function position(dimension, size) {
  6372. if (!neighbors) {
  6373. neighbors = new Array(n);
  6374. for (j = 0; j < n; ++j) {
  6375. neighbors[j] = [];
  6376. }
  6377. for (j = 0; j < m; ++j) {
  6378. var o = links[j];
  6379. neighbors[o.source.index].push(o.target);
  6380. neighbors[o.target.index].push(o.source);
  6381. }
  6382. }
  6383. var candidates = neighbors[i], j = -1, l = candidates.length, x;
  6384. while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
  6385. return Math.random() * size;
  6386. }
  6387. return force.resume();
  6388. };
  6389. force.resume = function() {
  6390. return force.alpha(.1);
  6391. };
  6392. force.stop = function() {
  6393. return force.alpha(0);
  6394. };
  6395. force.drag = function() {
  6396. 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);
  6397. if (!arguments.length) return drag;
  6398. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  6399. };
  6400. function dragmove(d) {
  6401. d.px = d3.event.x, d.py = d3.event.y;
  6402. force.resume();
  6403. }
  6404. return d3.rebind(force, event, "on");
  6405. };
  6406. function d3_layout_forceDragstart(d) {
  6407. d.fixed |= 2;
  6408. }
  6409. function d3_layout_forceDragend(d) {
  6410. d.fixed &= ~6;
  6411. }
  6412. function d3_layout_forceMouseover(d) {
  6413. d.fixed |= 4;
  6414. d.px = d.x, d.py = d.y;
  6415. }
  6416. function d3_layout_forceMouseout(d) {
  6417. d.fixed &= ~4;
  6418. }
  6419. function d3_layout_forceAccumulate(quad, alpha, charges) {
  6420. var cx = 0, cy = 0;
  6421. quad.charge = 0;
  6422. if (!quad.leaf) {
  6423. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  6424. while (++i < n) {
  6425. c = nodes[i];
  6426. if (c == null) continue;
  6427. d3_layout_forceAccumulate(c, alpha, charges);
  6428. quad.charge += c.charge;
  6429. cx += c.charge * c.cx;
  6430. cy += c.charge * c.cy;
  6431. }
  6432. }
  6433. if (quad.point) {
  6434. if (!quad.leaf) {
  6435. quad.point.x += Math.random() - .5;
  6436. quad.point.y += Math.random() - .5;
  6437. }
  6438. var k = alpha * charges[quad.point.index];
  6439. quad.charge += quad.pointCharge = k;
  6440. cx += k * quad.point.x;
  6441. cy += k * quad.point.y;
  6442. }
  6443. quad.cx = cx / quad.charge;
  6444. quad.cy = cy / quad.charge;
  6445. }
  6446. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
  6447. d3.layout.hierarchy = function() {
  6448. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  6449. function hierarchy(root) {
  6450. var stack = [ root ], nodes = [], node;
  6451. root.depth = 0;
  6452. while ((node = stack.pop()) != null) {
  6453. nodes.push(node);
  6454. if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
  6455. var n, childs, child;
  6456. while (--n >= 0) {
  6457. stack.push(child = childs[n]);
  6458. child.parent = node;
  6459. child.depth = node.depth + 1;
  6460. }
  6461. if (value) node.value = 0;
  6462. node.children = childs;
  6463. } else {
  6464. if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6465. delete node.children;
  6466. }
  6467. }
  6468. d3_layout_hierarchyVisitAfter(root, function(node) {
  6469. var childs, parent;
  6470. if (sort && (childs = node.children)) childs.sort(sort);
  6471. if (value && (parent = node.parent)) parent.value += node.value;
  6472. });
  6473. return nodes;
  6474. }
  6475. hierarchy.sort = function(x) {
  6476. if (!arguments.length) return sort;
  6477. sort = x;
  6478. return hierarchy;
  6479. };
  6480. hierarchy.children = function(x) {
  6481. if (!arguments.length) return children;
  6482. children = x;
  6483. return hierarchy;
  6484. };
  6485. hierarchy.value = function(x) {
  6486. if (!arguments.length) return value;
  6487. value = x;
  6488. return hierarchy;
  6489. };
  6490. hierarchy.revalue = function(root) {
  6491. if (value) {
  6492. d3_layout_hierarchyVisitBefore(root, function(node) {
  6493. if (node.children) node.value = 0;
  6494. });
  6495. d3_layout_hierarchyVisitAfter(root, function(node) {
  6496. var parent;
  6497. if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6498. if (parent = node.parent) parent.value += node.value;
  6499. });
  6500. }
  6501. return root;
  6502. };
  6503. return hierarchy;
  6504. };
  6505. function d3_layout_hierarchyRebind(object, hierarchy) {
  6506. d3.rebind(object, hierarchy, "sort", "children", "value");
  6507. object.nodes = object;
  6508. object.links = d3_layout_hierarchyLinks;
  6509. return object;
  6510. }
  6511. function d3_layout_hierarchyVisitBefore(node, callback) {
  6512. var nodes = [ node ];
  6513. while ((node = nodes.pop()) != null) {
  6514. callback(node);
  6515. if ((children = node.children) && (n = children.length)) {
  6516. var n, children;
  6517. while (--n >= 0) nodes.push(children[n]);
  6518. }
  6519. }
  6520. }
  6521. function d3_layout_hierarchyVisitAfter(node, callback) {
  6522. var nodes = [ node ], nodes2 = [];
  6523. while ((node = nodes.pop()) != null) {
  6524. nodes2.push(node);
  6525. if ((children = node.children) && (n = children.length)) {
  6526. var i = -1, n, children;
  6527. while (++i < n) nodes.push(children[i]);
  6528. }
  6529. }
  6530. while ((node = nodes2.pop()) != null) {
  6531. callback(node);
  6532. }
  6533. }
  6534. function d3_layout_hierarchyChildren(d) {
  6535. return d.children;
  6536. }
  6537. function d3_layout_hierarchyValue(d) {
  6538. return d.value;
  6539. }
  6540. function d3_layout_hierarchySort(a, b) {
  6541. return b.value - a.value;
  6542. }
  6543. function d3_layout_hierarchyLinks(nodes) {
  6544. return d3.merge(nodes.map(function(parent) {
  6545. return (parent.children || []).map(function(child) {
  6546. return {
  6547. source: parent,
  6548. target: child
  6549. };
  6550. });
  6551. }));
  6552. }
  6553. d3.layout.partition = function() {
  6554. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  6555. function position(node, x, dx, dy) {
  6556. var children = node.children;
  6557. node.x = x;
  6558. node.y = node.depth * dy;
  6559. node.dx = dx;
  6560. node.dy = dy;
  6561. if (children && (n = children.length)) {
  6562. var i = -1, n, c, d;
  6563. dx = node.value ? dx / node.value : 0;
  6564. while (++i < n) {
  6565. position(c = children[i], x, d = c.value * dx, dy);
  6566. x += d;
  6567. }
  6568. }
  6569. }
  6570. function depth(node) {
  6571. var children = node.children, d = 0;
  6572. if (children && (n = children.length)) {
  6573. var i = -1, n;
  6574. while (++i < n) d = Math.max(d, depth(children[i]));
  6575. }
  6576. return 1 + d;
  6577. }
  6578. function partition(d, i) {
  6579. var nodes = hierarchy.call(this, d, i);
  6580. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  6581. return nodes;
  6582. }
  6583. partition.size = function(x) {
  6584. if (!arguments.length) return size;
  6585. size = x;
  6586. return partition;
  6587. };
  6588. return d3_layout_hierarchyRebind(partition, hierarchy);
  6589. };
  6590. d3.layout.pie = function() {
  6591. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
  6592. function pie(data) {
  6593. var n = data.length, values = data.map(function(d, i) {
  6594. return +value.call(pie, d, i);
  6595. }), 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), k = (da - n * pa) / d3.sum(values), index = d3.range(n), arcs = [], v;
  6596. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  6597. return values[j] - values[i];
  6598. } : function(i, j) {
  6599. return sort(data[i], data[j]);
  6600. });
  6601. index.forEach(function(i) {
  6602. arcs[i] = {
  6603. data: data[i],
  6604. value: v = values[i],
  6605. startAngle: a,
  6606. endAngle: a += v * k + pa,
  6607. padAngle: p
  6608. };
  6609. });
  6610. return arcs;
  6611. }
  6612. pie.value = function(_) {
  6613. if (!arguments.length) return value;
  6614. value = _;
  6615. return pie;
  6616. };
  6617. pie.sort = function(_) {
  6618. if (!arguments.length) return sort;
  6619. sort = _;
  6620. return pie;
  6621. };
  6622. pie.startAngle = function(_) {
  6623. if (!arguments.length) return startAngle;
  6624. startAngle = _;
  6625. return pie;
  6626. };
  6627. pie.endAngle = function(_) {
  6628. if (!arguments.length) return endAngle;
  6629. endAngle = _;
  6630. return pie;
  6631. };
  6632. pie.padAngle = function(_) {
  6633. if (!arguments.length) return padAngle;
  6634. padAngle = _;
  6635. return pie;
  6636. };
  6637. return pie;
  6638. };
  6639. var d3_layout_pieSortByValue = {};
  6640. d3.layout.stack = function() {
  6641. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  6642. function stack(data, index) {
  6643. if (!(n = data.length)) return data;
  6644. var series = data.map(function(d, i) {
  6645. return values.call(stack, d, i);
  6646. });
  6647. var points = series.map(function(d) {
  6648. return d.map(function(v, i) {
  6649. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  6650. });
  6651. });
  6652. var orders = order.call(stack, points, index);
  6653. series = d3.permute(series, orders);
  6654. points = d3.permute(points, orders);
  6655. var offsets = offset.call(stack, points, index);
  6656. var m = series[0].length, n, i, j, o;
  6657. for (j = 0; j < m; ++j) {
  6658. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  6659. for (i = 1; i < n; ++i) {
  6660. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  6661. }
  6662. }
  6663. return data;
  6664. }
  6665. stack.values = function(x) {
  6666. if (!arguments.length) return values;
  6667. values = x;
  6668. return stack;
  6669. };
  6670. stack.order = function(x) {
  6671. if (!arguments.length) return order;
  6672. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  6673. return stack;
  6674. };
  6675. stack.offset = function(x) {
  6676. if (!arguments.length) return offset;
  6677. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  6678. return stack;
  6679. };
  6680. stack.x = function(z) {
  6681. if (!arguments.length) return x;
  6682. x = z;
  6683. return stack;
  6684. };
  6685. stack.y = function(z) {
  6686. if (!arguments.length) return y;
  6687. y = z;
  6688. return stack;
  6689. };
  6690. stack.out = function(z) {
  6691. if (!arguments.length) return out;
  6692. out = z;
  6693. return stack;
  6694. };
  6695. return stack;
  6696. };
  6697. function d3_layout_stackX(d) {
  6698. return d.x;
  6699. }
  6700. function d3_layout_stackY(d) {
  6701. return d.y;
  6702. }
  6703. function d3_layout_stackOut(d, y0, y) {
  6704. d.y0 = y0;
  6705. d.y = y;
  6706. }
  6707. var d3_layout_stackOrders = d3.map({
  6708. "inside-out": function(data) {
  6709. 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) {
  6710. return max[a] - max[b];
  6711. }), top = 0, bottom = 0, tops = [], bottoms = [];
  6712. for (i = 0; i < n; ++i) {
  6713. j = index[i];
  6714. if (top < bottom) {
  6715. top += sums[j];
  6716. tops.push(j);
  6717. } else {
  6718. bottom += sums[j];
  6719. bottoms.push(j);
  6720. }
  6721. }
  6722. return bottoms.reverse().concat(tops);
  6723. },
  6724. reverse: function(data) {
  6725. return d3.range(data.length).reverse();
  6726. },
  6727. "default": d3_layout_stackOrderDefault
  6728. });
  6729. var d3_layout_stackOffsets = d3.map({
  6730. silhouette: function(data) {
  6731. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  6732. for (j = 0; j < m; ++j) {
  6733. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6734. if (o > max) max = o;
  6735. sums.push(o);
  6736. }
  6737. for (j = 0; j < m; ++j) {
  6738. y0[j] = (max - sums[j]) / 2;
  6739. }
  6740. return y0;
  6741. },
  6742. wiggle: function(data) {
  6743. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  6744. y0[0] = o = o0 = 0;
  6745. for (j = 1; j < m; ++j) {
  6746. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  6747. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  6748. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  6749. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  6750. }
  6751. s2 += s3 * data[i][j][1];
  6752. }
  6753. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  6754. if (o < o0) o0 = o;
  6755. }
  6756. for (j = 0; j < m; ++j) y0[j] -= o0;
  6757. return y0;
  6758. },
  6759. expand: function(data) {
  6760. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  6761. for (j = 0; j < m; ++j) {
  6762. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6763. if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
  6764. }
  6765. for (j = 0; j < m; ++j) y0[j] = 0;
  6766. return y0;
  6767. },
  6768. zero: d3_layout_stackOffsetZero
  6769. });
  6770. function d3_layout_stackOrderDefault(data) {
  6771. return d3.range(data.length);
  6772. }
  6773. function d3_layout_stackOffsetZero(data) {
  6774. var j = -1, m = data[0].length, y0 = [];
  6775. while (++j < m) y0[j] = 0;
  6776. return y0;
  6777. }
  6778. function d3_layout_stackMaxIndex(array) {
  6779. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  6780. for (;i < n; ++i) {
  6781. if ((k = array[i][1]) > v) {
  6782. j = i;
  6783. v = k;
  6784. }
  6785. }
  6786. return j;
  6787. }
  6788. function d3_layout_stackReduceSum(d) {
  6789. return d.reduce(d3_layout_stackSum, 0);
  6790. }
  6791. function d3_layout_stackSum(p, d) {
  6792. return p + d[1];
  6793. }
  6794. d3.layout.histogram = function() {
  6795. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  6796. function histogram(data, i) {
  6797. 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;
  6798. while (++i < m) {
  6799. bin = bins[i] = [];
  6800. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  6801. bin.y = 0;
  6802. }
  6803. if (m > 0) {
  6804. i = -1;
  6805. while (++i < n) {
  6806. x = values[i];
  6807. if (x >= range[0] && x <= range[1]) {
  6808. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  6809. bin.y += k;
  6810. bin.push(data[i]);
  6811. }
  6812. }
  6813. }
  6814. return bins;
  6815. }
  6816. histogram.value = function(x) {
  6817. if (!arguments.length) return valuer;
  6818. valuer = x;
  6819. return histogram;
  6820. };
  6821. histogram.range = function(x) {
  6822. if (!arguments.length) return ranger;
  6823. ranger = d3_functor(x);
  6824. return histogram;
  6825. };
  6826. histogram.bins = function(x) {
  6827. if (!arguments.length) return binner;
  6828. binner = typeof x === "number" ? function(range) {
  6829. return d3_layout_histogramBinFixed(range, x);
  6830. } : d3_functor(x);
  6831. return histogram;
  6832. };
  6833. histogram.frequency = function(x) {
  6834. if (!arguments.length) return frequency;
  6835. frequency = !!x;
  6836. return histogram;
  6837. };
  6838. return histogram;
  6839. };
  6840. function d3_layout_histogramBinSturges(range, values) {
  6841. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  6842. }
  6843. function d3_layout_histogramBinFixed(range, n) {
  6844. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  6845. while (++x <= n) f[x] = m * x + b;
  6846. return f;
  6847. }
  6848. function d3_layout_histogramRange(values) {
  6849. return [ d3.min(values), d3.max(values) ];
  6850. }
  6851. d3.layout.pack = function() {
  6852. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
  6853. function pack(d, i) {
  6854. 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() {
  6855. return radius;
  6856. };
  6857. root.x = root.y = 0;
  6858. d3_layout_hierarchyVisitAfter(root, function(d) {
  6859. d.r = +r(d.value);
  6860. });
  6861. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6862. if (padding) {
  6863. var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
  6864. d3_layout_hierarchyVisitAfter(root, function(d) {
  6865. d.r += dr;
  6866. });
  6867. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6868. d3_layout_hierarchyVisitAfter(root, function(d) {
  6869. d.r -= dr;
  6870. });
  6871. }
  6872. d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
  6873. return nodes;
  6874. }
  6875. pack.size = function(_) {
  6876. if (!arguments.length) return size;
  6877. size = _;
  6878. return pack;
  6879. };
  6880. pack.radius = function(_) {
  6881. if (!arguments.length) return radius;
  6882. radius = _ == null || typeof _ === "function" ? _ : +_;
  6883. return pack;
  6884. };
  6885. pack.padding = function(_) {
  6886. if (!arguments.length) return padding;
  6887. padding = +_;
  6888. return pack;
  6889. };
  6890. return d3_layout_hierarchyRebind(pack, hierarchy);
  6891. };
  6892. function d3_layout_packSort(a, b) {
  6893. return a.value - b.value;
  6894. }
  6895. function d3_layout_packInsert(a, b) {
  6896. var c = a._pack_next;
  6897. a._pack_next = b;
  6898. b._pack_prev = a;
  6899. b._pack_next = c;
  6900. c._pack_prev = b;
  6901. }
  6902. function d3_layout_packSplice(a, b) {
  6903. a._pack_next = b;
  6904. b._pack_prev = a;
  6905. }
  6906. function d3_layout_packIntersects(a, b) {
  6907. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  6908. return .999 * dr * dr > dx * dx + dy * dy;
  6909. }
  6910. function d3_layout_packSiblings(node) {
  6911. if (!(nodes = node.children) || !(n = nodes.length)) return;
  6912. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  6913. function bound(node) {
  6914. xMin = Math.min(node.x - node.r, xMin);
  6915. xMax = Math.max(node.x + node.r, xMax);
  6916. yMin = Math.min(node.y - node.r, yMin);
  6917. yMax = Math.max(node.y + node.r, yMax);
  6918. }
  6919. nodes.forEach(d3_layout_packLink);
  6920. a = nodes[0];
  6921. a.x = -a.r;
  6922. a.y = 0;
  6923. bound(a);
  6924. if (n > 1) {
  6925. b = nodes[1];
  6926. b.x = b.r;
  6927. b.y = 0;
  6928. bound(b);
  6929. if (n > 2) {
  6930. c = nodes[2];
  6931. d3_layout_packPlace(a, b, c);
  6932. bound(c);
  6933. d3_layout_packInsert(a, c);
  6934. a._pack_prev = c;
  6935. d3_layout_packInsert(c, b);
  6936. b = a._pack_next;
  6937. for (i = 3; i < n; i++) {
  6938. d3_layout_packPlace(a, b, c = nodes[i]);
  6939. var isect = 0, s1 = 1, s2 = 1;
  6940. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  6941. if (d3_layout_packIntersects(j, c)) {
  6942. isect = 1;
  6943. break;
  6944. }
  6945. }
  6946. if (isect == 1) {
  6947. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  6948. if (d3_layout_packIntersects(k, c)) {
  6949. break;
  6950. }
  6951. }
  6952. }
  6953. if (isect) {
  6954. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  6955. i--;
  6956. } else {
  6957. d3_layout_packInsert(a, c);
  6958. b = c;
  6959. bound(c);
  6960. }
  6961. }
  6962. }
  6963. }
  6964. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  6965. for (i = 0; i < n; i++) {
  6966. c = nodes[i];
  6967. c.x -= cx;
  6968. c.y -= cy;
  6969. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  6970. }
  6971. node.r = cr;
  6972. nodes.forEach(d3_layout_packUnlink);
  6973. }
  6974. function d3_layout_packLink(node) {
  6975. node._pack_next = node._pack_prev = node;
  6976. }
  6977. function d3_layout_packUnlink(node) {
  6978. delete node._pack_next;
  6979. delete node._pack_prev;
  6980. }
  6981. function d3_layout_packTransform(node, x, y, k) {
  6982. var children = node.children;
  6983. node.x = x += k * node.x;
  6984. node.y = y += k * node.y;
  6985. node.r *= k;
  6986. if (children) {
  6987. var i = -1, n = children.length;
  6988. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  6989. }
  6990. }
  6991. function d3_layout_packPlace(a, b, c) {
  6992. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  6993. if (db && (dx || dy)) {
  6994. var da = b.r + c.r, dc = dx * dx + dy * dy;
  6995. da *= da;
  6996. db *= db;
  6997. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  6998. c.x = a.x + x * dx + y * dy;
  6999. c.y = a.y + x * dy - y * dx;
  7000. } else {
  7001. c.x = a.x + db;
  7002. c.y = a.y;
  7003. }
  7004. }
  7005. d3.layout.tree = function() {
  7006. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
  7007. function tree(d, i) {
  7008. var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
  7009. d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
  7010. d3_layout_hierarchyVisitBefore(root1, secondWalk);
  7011. if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
  7012. var left = root0, right = root0, bottom = root0;
  7013. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7014. if (node.x < left.x) left = node;
  7015. if (node.x > right.x) right = node;
  7016. if (node.depth > bottom.depth) bottom = node;
  7017. });
  7018. var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
  7019. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7020. node.x = (node.x + tx) * kx;
  7021. node.y = node.depth * ky;
  7022. });
  7023. }
  7024. return nodes;
  7025. }
  7026. function wrapTree(root0) {
  7027. var root1 = {
  7028. A: null,
  7029. children: [ root0 ]
  7030. }, queue = [ root1 ], node1;
  7031. while ((node1 = queue.pop()) != null) {
  7032. for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
  7033. queue.push((children[i] = child = {
  7034. _: children[i],
  7035. parent: node1,
  7036. children: (child = children[i].children) && child.slice() || [],
  7037. A: null,
  7038. a: null,
  7039. z: 0,
  7040. m: 0,
  7041. c: 0,
  7042. s: 0,
  7043. t: null,
  7044. i: i
  7045. }).a = child);
  7046. }
  7047. }
  7048. return root1.children[0];
  7049. }
  7050. function firstWalk(v) {
  7051. var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
  7052. if (children.length) {
  7053. d3_layout_treeShift(v);
  7054. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  7055. if (w) {
  7056. v.z = w.z + separation(v._, w._);
  7057. v.m = v.z - midpoint;
  7058. } else {
  7059. v.z = midpoint;
  7060. }
  7061. } else if (w) {
  7062. v.z = w.z + separation(v._, w._);
  7063. }
  7064. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  7065. }
  7066. function secondWalk(v) {
  7067. v._.x = v.z + v.parent.m;
  7068. v.m += v.parent.m;
  7069. }
  7070. function apportion(v, w, ancestor) {
  7071. if (w) {
  7072. 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;
  7073. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  7074. vom = d3_layout_treeLeft(vom);
  7075. vop = d3_layout_treeRight(vop);
  7076. vop.a = v;
  7077. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  7078. if (shift > 0) {
  7079. d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
  7080. sip += shift;
  7081. sop += shift;
  7082. }
  7083. sim += vim.m;
  7084. sip += vip.m;
  7085. som += vom.m;
  7086. sop += vop.m;
  7087. }
  7088. if (vim && !d3_layout_treeRight(vop)) {
  7089. vop.t = vim;
  7090. vop.m += sim - sop;
  7091. }
  7092. if (vip && !d3_layout_treeLeft(vom)) {
  7093. vom.t = vip;
  7094. vom.m += sip - som;
  7095. ancestor = v;
  7096. }
  7097. }
  7098. return ancestor;
  7099. }
  7100. function sizeNode(node) {
  7101. node.x *= size[0];
  7102. node.y = node.depth * size[1];
  7103. }
  7104. tree.separation = function(x) {
  7105. if (!arguments.length) return separation;
  7106. separation = x;
  7107. return tree;
  7108. };
  7109. tree.size = function(x) {
  7110. if (!arguments.length) return nodeSize ? null : size;
  7111. nodeSize = (size = x) == null ? sizeNode : null;
  7112. return tree;
  7113. };
  7114. tree.nodeSize = function(x) {
  7115. if (!arguments.length) return nodeSize ? size : null;
  7116. nodeSize = (size = x) == null ? null : sizeNode;
  7117. return tree;
  7118. };
  7119. return d3_layout_hierarchyRebind(tree, hierarchy);
  7120. };
  7121. function d3_layout_treeSeparation(a, b) {
  7122. return a.parent == b.parent ? 1 : 2;
  7123. }
  7124. function d3_layout_treeLeft(v) {
  7125. var children = v.children;
  7126. return children.length ? children[0] : v.t;
  7127. }
  7128. function d3_layout_treeRight(v) {
  7129. var children = v.children, n;
  7130. return (n = children.length) ? children[n - 1] : v.t;
  7131. }
  7132. function d3_layout_treeMove(wm, wp, shift) {
  7133. var change = shift / (wp.i - wm.i);
  7134. wp.c -= change;
  7135. wp.s += shift;
  7136. wm.c += change;
  7137. wp.z += shift;
  7138. wp.m += shift;
  7139. }
  7140. function d3_layout_treeShift(v) {
  7141. var shift = 0, change = 0, children = v.children, i = children.length, w;
  7142. while (--i >= 0) {
  7143. w = children[i];
  7144. w.z += shift;
  7145. w.m += shift;
  7146. shift += w.s + (change += w.c);
  7147. }
  7148. }
  7149. function d3_layout_treeAncestor(vim, v, ancestor) {
  7150. return vim.a.parent === v.parent ? vim.a : ancestor;
  7151. }
  7152. d3.layout.cluster = function() {
  7153. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  7154. function cluster(d, i) {
  7155. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  7156. d3_layout_hierarchyVisitAfter(root, function(node) {
  7157. var children = node.children;
  7158. if (children && children.length) {
  7159. node.x = d3_layout_clusterX(children);
  7160. node.y = d3_layout_clusterY(children);
  7161. } else {
  7162. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7163. node.y = 0;
  7164. previousNode = node;
  7165. }
  7166. });
  7167. 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;
  7168. d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
  7169. node.x = (node.x - root.x) * size[0];
  7170. node.y = (root.y - node.y) * size[1];
  7171. } : function(node) {
  7172. node.x = (node.x - x0) / (x1 - x0) * size[0];
  7173. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  7174. });
  7175. return nodes;
  7176. }
  7177. cluster.separation = function(x) {
  7178. if (!arguments.length) return separation;
  7179. separation = x;
  7180. return cluster;
  7181. };
  7182. cluster.size = function(x) {
  7183. if (!arguments.length) return nodeSize ? null : size;
  7184. nodeSize = (size = x) == null;
  7185. return cluster;
  7186. };
  7187. cluster.nodeSize = function(x) {
  7188. if (!arguments.length) return nodeSize ? size : null;
  7189. nodeSize = (size = x) != null;
  7190. return cluster;
  7191. };
  7192. return d3_layout_hierarchyRebind(cluster, hierarchy);
  7193. };
  7194. function d3_layout_clusterY(children) {
  7195. return 1 + d3.max(children, function(child) {
  7196. return child.y;
  7197. });
  7198. }
  7199. function d3_layout_clusterX(children) {
  7200. return children.reduce(function(x, child) {
  7201. return x + child.x;
  7202. }, 0) / children.length;
  7203. }
  7204. function d3_layout_clusterLeft(node) {
  7205. var children = node.children;
  7206. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  7207. }
  7208. function d3_layout_clusterRight(node) {
  7209. var children = node.children, n;
  7210. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  7211. }
  7212. d3.layout.treemap = function() {
  7213. 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));
  7214. function scale(children, k) {
  7215. var i = -1, n = children.length, child, area;
  7216. while (++i < n) {
  7217. area = (child = children[i]).value * (k < 0 ? 0 : k);
  7218. child.area = isNaN(area) || area <= 0 ? 0 : area;
  7219. }
  7220. }
  7221. function squarify(node) {
  7222. var children = node.children;
  7223. if (children && children.length) {
  7224. 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;
  7225. scale(remaining, rect.dx * rect.dy / node.value);
  7226. row.area = 0;
  7227. while ((n = remaining.length) > 0) {
  7228. row.push(child = remaining[n - 1]);
  7229. row.area += child.area;
  7230. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  7231. remaining.pop();
  7232. best = score;
  7233. } else {
  7234. row.area -= row.pop().area;
  7235. position(row, u, rect, false);
  7236. u = Math.min(rect.dx, rect.dy);
  7237. row.length = row.area = 0;
  7238. best = Infinity;
  7239. }
  7240. }
  7241. if (row.length) {
  7242. position(row, u, rect, true);
  7243. row.length = row.area = 0;
  7244. }
  7245. children.forEach(squarify);
  7246. }
  7247. }
  7248. function stickify(node) {
  7249. var children = node.children;
  7250. if (children && children.length) {
  7251. var rect = pad(node), remaining = children.slice(), child, row = [];
  7252. scale(remaining, rect.dx * rect.dy / node.value);
  7253. row.area = 0;
  7254. while (child = remaining.pop()) {
  7255. row.push(child);
  7256. row.area += child.area;
  7257. if (child.z != null) {
  7258. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  7259. row.length = row.area = 0;
  7260. }
  7261. }
  7262. children.forEach(stickify);
  7263. }
  7264. }
  7265. function worst(row, u) {
  7266. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  7267. while (++i < n) {
  7268. if (!(r = row[i].area)) continue;
  7269. if (r < rmin) rmin = r;
  7270. if (r > rmax) rmax = r;
  7271. }
  7272. s *= s;
  7273. u *= u;
  7274. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  7275. }
  7276. function position(row, u, rect, flush) {
  7277. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  7278. if (u == rect.dx) {
  7279. if (flush || v > rect.dy) v = rect.dy;
  7280. while (++i < n) {
  7281. o = row[i];
  7282. o.x = x;
  7283. o.y = y;
  7284. o.dy = v;
  7285. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  7286. }
  7287. o.z = true;
  7288. o.dx += rect.x + rect.dx - x;
  7289. rect.y += v;
  7290. rect.dy -= v;
  7291. } else {
  7292. if (flush || v > rect.dx) v = rect.dx;
  7293. while (++i < n) {
  7294. o = row[i];
  7295. o.x = x;
  7296. o.y = y;
  7297. o.dx = v;
  7298. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  7299. }
  7300. o.z = false;
  7301. o.dy += rect.y + rect.dy - y;
  7302. rect.x += v;
  7303. rect.dx -= v;
  7304. }
  7305. }
  7306. function treemap(d) {
  7307. var nodes = stickies || hierarchy(d), root = nodes[0];
  7308. root.x = 0;
  7309. root.y = 0;
  7310. root.dx = size[0];
  7311. root.dy = size[1];
  7312. if (stickies) hierarchy.revalue(root);
  7313. scale([ root ], root.dx * root.dy / root.value);
  7314. (stickies ? stickify : squarify)(root);
  7315. if (sticky) stickies = nodes;
  7316. return nodes;
  7317. }
  7318. treemap.size = function(x) {
  7319. if (!arguments.length) return size;
  7320. size = x;
  7321. return treemap;
  7322. };
  7323. treemap.padding = function(x) {
  7324. if (!arguments.length) return padding;
  7325. function padFunction(node) {
  7326. var p = x.call(treemap, node, node.depth);
  7327. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  7328. }
  7329. function padConstant(node) {
  7330. return d3_layout_treemapPad(node, x);
  7331. }
  7332. var type;
  7333. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  7334. padConstant) : padConstant;
  7335. return treemap;
  7336. };
  7337. treemap.round = function(x) {
  7338. if (!arguments.length) return round != Number;
  7339. round = x ? Math.round : Number;
  7340. return treemap;
  7341. };
  7342. treemap.sticky = function(x) {
  7343. if (!arguments.length) return sticky;
  7344. sticky = x;
  7345. stickies = null;
  7346. return treemap;
  7347. };
  7348. treemap.ratio = function(x) {
  7349. if (!arguments.length) return ratio;
  7350. ratio = x;
  7351. return treemap;
  7352. };
  7353. treemap.mode = function(x) {
  7354. if (!arguments.length) return mode;
  7355. mode = x + "";
  7356. return treemap;
  7357. };
  7358. return d3_layout_hierarchyRebind(treemap, hierarchy);
  7359. };
  7360. function d3_layout_treemapPadNull(node) {
  7361. return {
  7362. x: node.x,
  7363. y: node.y,
  7364. dx: node.dx,
  7365. dy: node.dy
  7366. };
  7367. }
  7368. function d3_layout_treemapPad(node, padding) {
  7369. 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];
  7370. if (dx < 0) {
  7371. x += dx / 2;
  7372. dx = 0;
  7373. }
  7374. if (dy < 0) {
  7375. y += dy / 2;
  7376. dy = 0;
  7377. }
  7378. return {
  7379. x: x,
  7380. y: y,
  7381. dx: dx,
  7382. dy: dy
  7383. };
  7384. }
  7385. d3.random = {
  7386. normal: function(µ, σ) {
  7387. var n = arguments.length;
  7388. if (n < 2) σ = 1;
  7389. if (n < 1) µ = 0;
  7390. return function() {
  7391. var x, y, r;
  7392. do {
  7393. x = Math.random() * 2 - 1;
  7394. y = Math.random() * 2 - 1;
  7395. r = x * x + y * y;
  7396. } while (!r || r > 1);
  7397. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  7398. };
  7399. },
  7400. logNormal: function() {
  7401. var random = d3.random.normal.apply(d3, arguments);
  7402. return function() {
  7403. return Math.exp(random());
  7404. };
  7405. },
  7406. bates: function(m) {
  7407. var random = d3.random.irwinHall(m);
  7408. return function() {
  7409. return random() / m;
  7410. };
  7411. },
  7412. irwinHall: function(m) {
  7413. return function() {
  7414. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  7415. return s;
  7416. };
  7417. }
  7418. };
  7419. d3.scale = {};
  7420. function d3_scaleExtent(domain) {
  7421. var start = domain[0], stop = domain[domain.length - 1];
  7422. return start < stop ? [ start, stop ] : [ stop, start ];
  7423. }
  7424. function d3_scaleRange(scale) {
  7425. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  7426. }
  7427. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  7428. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  7429. return function(x) {
  7430. return i(u(x));
  7431. };
  7432. }
  7433. function d3_scale_nice(domain, nice) {
  7434. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  7435. if (x1 < x0) {
  7436. dx = i0, i0 = i1, i1 = dx;
  7437. dx = x0, x0 = x1, x1 = dx;
  7438. }
  7439. domain[i0] = nice.floor(x0);
  7440. domain[i1] = nice.ceil(x1);
  7441. return domain;
  7442. }
  7443. function d3_scale_niceStep(step) {
  7444. return step ? {
  7445. floor: function(x) {
  7446. return Math.floor(x / step) * step;
  7447. },
  7448. ceil: function(x) {
  7449. return Math.ceil(x / step) * step;
  7450. }
  7451. } : d3_scale_niceIdentity;
  7452. }
  7453. var d3_scale_niceIdentity = {
  7454. floor: d3_identity,
  7455. ceil: d3_identity
  7456. };
  7457. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  7458. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  7459. if (domain[k] < domain[0]) {
  7460. domain = domain.slice().reverse();
  7461. range = range.slice().reverse();
  7462. }
  7463. while (++j <= k) {
  7464. u.push(uninterpolate(domain[j - 1], domain[j]));
  7465. i.push(interpolate(range[j - 1], range[j]));
  7466. }
  7467. return function(x) {
  7468. var j = d3.bisect(domain, x, 1, k) - 1;
  7469. return i[j](u[j](x));
  7470. };
  7471. }
  7472. d3.scale.linear = function() {
  7473. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  7474. };
  7475. function d3_scale_linear(domain, range, interpolate, clamp) {
  7476. var output, input;
  7477. function rescale() {
  7478. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  7479. output = linear(domain, range, uninterpolate, interpolate);
  7480. input = linear(range, domain, uninterpolate, d3_interpolate);
  7481. return scale;
  7482. }
  7483. function scale(x) {
  7484. return output(x);
  7485. }
  7486. scale.invert = function(y) {
  7487. return input(y);
  7488. };
  7489. scale.domain = function(x) {
  7490. if (!arguments.length) return domain;
  7491. domain = x.map(Number);
  7492. return rescale();
  7493. };
  7494. scale.range = function(x) {
  7495. if (!arguments.length) return range;
  7496. range = x;
  7497. return rescale();
  7498. };
  7499. scale.rangeRound = function(x) {
  7500. return scale.range(x).interpolate(d3_interpolateRound);
  7501. };
  7502. scale.clamp = function(x) {
  7503. if (!arguments.length) return clamp;
  7504. clamp = x;
  7505. return rescale();
  7506. };
  7507. scale.interpolate = function(x) {
  7508. if (!arguments.length) return interpolate;
  7509. interpolate = x;
  7510. return rescale();
  7511. };
  7512. scale.ticks = function(m) {
  7513. return d3_scale_linearTicks(domain, m);
  7514. };
  7515. scale.tickFormat = function(m, format) {
  7516. return d3_scale_linearTickFormat(domain, m, format);
  7517. };
  7518. scale.nice = function(m) {
  7519. d3_scale_linearNice(domain, m);
  7520. return rescale();
  7521. };
  7522. scale.copy = function() {
  7523. return d3_scale_linear(domain, range, interpolate, clamp);
  7524. };
  7525. return rescale();
  7526. }
  7527. function d3_scale_linearRebind(scale, linear) {
  7528. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  7529. }
  7530. function d3_scale_linearNice(domain, m) {
  7531. return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  7532. }
  7533. function d3_scale_linearTickRange(domain, m) {
  7534. if (m == null) m = 10;
  7535. 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;
  7536. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  7537. extent[0] = Math.ceil(extent[0] / step) * step;
  7538. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  7539. extent[2] = step;
  7540. return extent;
  7541. }
  7542. function d3_scale_linearTicks(domain, m) {
  7543. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  7544. }
  7545. function d3_scale_linearTickFormat(domain, m, format) {
  7546. var range = d3_scale_linearTickRange(domain, m);
  7547. if (format) {
  7548. var match = d3_format_re.exec(format);
  7549. match.shift();
  7550. if (match[8] === "s") {
  7551. var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
  7552. if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
  7553. match[8] = "f";
  7554. format = d3.format(match.join(""));
  7555. return function(d) {
  7556. return format(prefix.scale(d)) + prefix.symbol;
  7557. };
  7558. }
  7559. if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
  7560. format = match.join("");
  7561. } else {
  7562. format = ",." + d3_scale_linearPrecision(range[2]) + "f";
  7563. }
  7564. return d3.format(format);
  7565. }
  7566. var d3_scale_linearFormatSignificant = {
  7567. s: 1,
  7568. g: 1,
  7569. p: 1,
  7570. r: 1,
  7571. e: 1
  7572. };
  7573. function d3_scale_linearPrecision(value) {
  7574. return -Math.floor(Math.log(value) / Math.LN10 + .01);
  7575. }
  7576. function d3_scale_linearFormatPrecision(type, range) {
  7577. var p = d3_scale_linearPrecision(range[2]);
  7578. 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;
  7579. }
  7580. d3.scale.log = function() {
  7581. return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
  7582. };
  7583. function d3_scale_log(linear, base, positive, domain) {
  7584. function log(x) {
  7585. return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
  7586. }
  7587. function pow(x) {
  7588. return positive ? Math.pow(base, x) : -Math.pow(base, -x);
  7589. }
  7590. function scale(x) {
  7591. return linear(log(x));
  7592. }
  7593. scale.invert = function(x) {
  7594. return pow(linear.invert(x));
  7595. };
  7596. scale.domain = function(x) {
  7597. if (!arguments.length) return domain;
  7598. positive = x[0] >= 0;
  7599. linear.domain((domain = x.map(Number)).map(log));
  7600. return scale;
  7601. };
  7602. scale.base = function(_) {
  7603. if (!arguments.length) return base;
  7604. base = +_;
  7605. linear.domain(domain.map(log));
  7606. return scale;
  7607. };
  7608. scale.nice = function() {
  7609. var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
  7610. linear.domain(niced);
  7611. domain = niced.map(pow);
  7612. return scale;
  7613. };
  7614. scale.ticks = function() {
  7615. 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;
  7616. if (isFinite(j - i)) {
  7617. if (positive) {
  7618. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
  7619. ticks.push(pow(i));
  7620. } else {
  7621. ticks.push(pow(i));
  7622. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
  7623. }
  7624. for (i = 0; ticks[i] < u; i++) {}
  7625. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  7626. ticks = ticks.slice(i, j);
  7627. }
  7628. return ticks;
  7629. };
  7630. scale.tickFormat = function(n, format) {
  7631. if (!arguments.length) return d3_scale_logFormat;
  7632. if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
  7633. var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
  7634. Math.floor), e;
  7635. return function(d) {
  7636. return d / pow(f(log(d) + e)) <= k ? format(d) : "";
  7637. };
  7638. };
  7639. scale.copy = function() {
  7640. return d3_scale_log(linear.copy(), base, positive, domain);
  7641. };
  7642. return d3_scale_linearRebind(scale, linear);
  7643. }
  7644. var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
  7645. floor: function(x) {
  7646. return -Math.ceil(-x);
  7647. },
  7648. ceil: function(x) {
  7649. return -Math.floor(-x);
  7650. }
  7651. };
  7652. d3.scale.pow = function() {
  7653. return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
  7654. };
  7655. function d3_scale_pow(linear, exponent, domain) {
  7656. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  7657. function scale(x) {
  7658. return linear(powp(x));
  7659. }
  7660. scale.invert = function(x) {
  7661. return powb(linear.invert(x));
  7662. };
  7663. scale.domain = function(x) {
  7664. if (!arguments.length) return domain;
  7665. linear.domain((domain = x.map(Number)).map(powp));
  7666. return scale;
  7667. };
  7668. scale.ticks = function(m) {
  7669. return d3_scale_linearTicks(domain, m);
  7670. };
  7671. scale.tickFormat = function(m, format) {
  7672. return d3_scale_linearTickFormat(domain, m, format);
  7673. };
  7674. scale.nice = function(m) {
  7675. return scale.domain(d3_scale_linearNice(domain, m));
  7676. };
  7677. scale.exponent = function(x) {
  7678. if (!arguments.length) return exponent;
  7679. powp = d3_scale_powPow(exponent = x);
  7680. powb = d3_scale_powPow(1 / exponent);
  7681. linear.domain(domain.map(powp));
  7682. return scale;
  7683. };
  7684. scale.copy = function() {
  7685. return d3_scale_pow(linear.copy(), exponent, domain);
  7686. };
  7687. return d3_scale_linearRebind(scale, linear);
  7688. }
  7689. function d3_scale_powPow(e) {
  7690. return function(x) {
  7691. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  7692. };
  7693. }
  7694. d3.scale.sqrt = function() {
  7695. return d3.scale.pow().exponent(.5);
  7696. };
  7697. d3.scale.ordinal = function() {
  7698. return d3_scale_ordinal([], {
  7699. t: "range",
  7700. a: [ [] ]
  7701. });
  7702. };
  7703. function d3_scale_ordinal(domain, ranger) {
  7704. var index, range, rangeBand;
  7705. function scale(x) {
  7706. return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
  7707. }
  7708. function steps(start, step) {
  7709. return d3.range(domain.length).map(function(i) {
  7710. return start + step * i;
  7711. });
  7712. }
  7713. scale.domain = function(x) {
  7714. if (!arguments.length) return domain;
  7715. domain = [];
  7716. index = new d3_Map();
  7717. var i = -1, n = x.length, xi;
  7718. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  7719. return scale[ranger.t].apply(scale, ranger.a);
  7720. };
  7721. scale.range = function(x) {
  7722. if (!arguments.length) return range;
  7723. range = x;
  7724. rangeBand = 0;
  7725. ranger = {
  7726. t: "range",
  7727. a: arguments
  7728. };
  7729. return scale;
  7730. };
  7731. scale.rangePoints = function(x, padding) {
  7732. if (arguments.length < 2) padding = 0;
  7733. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
  7734. 0) : (stop - start) / (domain.length - 1 + padding);
  7735. range = steps(start + step * padding / 2, step);
  7736. rangeBand = 0;
  7737. ranger = {
  7738. t: "rangePoints",
  7739. a: arguments
  7740. };
  7741. return scale;
  7742. };
  7743. scale.rangeRoundPoints = function(x, padding) {
  7744. if (arguments.length < 2) padding = 0;
  7745. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
  7746. 0) : (stop - start) / (domain.length - 1 + padding) | 0;
  7747. range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
  7748. rangeBand = 0;
  7749. ranger = {
  7750. t: "rangeRoundPoints",
  7751. a: arguments
  7752. };
  7753. return scale;
  7754. };
  7755. scale.rangeBands = function(x, padding, outerPadding) {
  7756. if (arguments.length < 2) padding = 0;
  7757. if (arguments.length < 3) outerPadding = padding;
  7758. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  7759. range = steps(start + step * outerPadding, step);
  7760. if (reverse) range.reverse();
  7761. rangeBand = step * (1 - padding);
  7762. ranger = {
  7763. t: "rangeBands",
  7764. a: arguments
  7765. };
  7766. return scale;
  7767. };
  7768. scale.rangeRoundBands = function(x, padding, outerPadding) {
  7769. if (arguments.length < 2) padding = 0;
  7770. if (arguments.length < 3) outerPadding = padding;
  7771. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
  7772. range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
  7773. if (reverse) range.reverse();
  7774. rangeBand = Math.round(step * (1 - padding));
  7775. ranger = {
  7776. t: "rangeRoundBands",
  7777. a: arguments
  7778. };
  7779. return scale;
  7780. };
  7781. scale.rangeBand = function() {
  7782. return rangeBand;
  7783. };
  7784. scale.rangeExtent = function() {
  7785. return d3_scaleExtent(ranger.a[0]);
  7786. };
  7787. scale.copy = function() {
  7788. return d3_scale_ordinal(domain, ranger);
  7789. };
  7790. return scale.domain(domain);
  7791. }
  7792. d3.scale.category10 = function() {
  7793. return d3.scale.ordinal().range(d3_category10);
  7794. };
  7795. d3.scale.category20 = function() {
  7796. return d3.scale.ordinal().range(d3_category20);
  7797. };
  7798. d3.scale.category20b = function() {
  7799. return d3.scale.ordinal().range(d3_category20b);
  7800. };
  7801. d3.scale.category20c = function() {
  7802. return d3.scale.ordinal().range(d3_category20c);
  7803. };
  7804. var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
  7805. 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);
  7806. 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);
  7807. 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);
  7808. d3.scale.quantile = function() {
  7809. return d3_scale_quantile([], []);
  7810. };
  7811. function d3_scale_quantile(domain, range) {
  7812. var thresholds;
  7813. function rescale() {
  7814. var k = 0, q = range.length;
  7815. thresholds = [];
  7816. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  7817. return scale;
  7818. }
  7819. function scale(x) {
  7820. if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
  7821. }
  7822. scale.domain = function(x) {
  7823. if (!arguments.length) return domain;
  7824. domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
  7825. return rescale();
  7826. };
  7827. scale.range = function(x) {
  7828. if (!arguments.length) return range;
  7829. range = x;
  7830. return rescale();
  7831. };
  7832. scale.quantiles = function() {
  7833. return thresholds;
  7834. };
  7835. scale.invertExtent = function(y) {
  7836. y = range.indexOf(y);
  7837. return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
  7838. };
  7839. scale.copy = function() {
  7840. return d3_scale_quantile(domain, range);
  7841. };
  7842. return rescale();
  7843. }
  7844. d3.scale.quantize = function() {
  7845. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  7846. };
  7847. function d3_scale_quantize(x0, x1, range) {
  7848. var kx, i;
  7849. function scale(x) {
  7850. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  7851. }
  7852. function rescale() {
  7853. kx = range.length / (x1 - x0);
  7854. i = range.length - 1;
  7855. return scale;
  7856. }
  7857. scale.domain = function(x) {
  7858. if (!arguments.length) return [ x0, x1 ];
  7859. x0 = +x[0];
  7860. x1 = +x[x.length - 1];
  7861. return rescale();
  7862. };
  7863. scale.range = function(x) {
  7864. if (!arguments.length) return range;
  7865. range = x;
  7866. return rescale();
  7867. };
  7868. scale.invertExtent = function(y) {
  7869. y = range.indexOf(y);
  7870. y = y < 0 ? NaN : y / kx + x0;
  7871. return [ y, y + 1 / kx ];
  7872. };
  7873. scale.copy = function() {
  7874. return d3_scale_quantize(x0, x1, range);
  7875. };
  7876. return rescale();
  7877. }
  7878. d3.scale.threshold = function() {
  7879. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  7880. };
  7881. function d3_scale_threshold(domain, range) {
  7882. function scale(x) {
  7883. if (x <= x) return range[d3.bisect(domain, x)];
  7884. }
  7885. scale.domain = function(_) {
  7886. if (!arguments.length) return domain;
  7887. domain = _;
  7888. return scale;
  7889. };
  7890. scale.range = function(_) {
  7891. if (!arguments.length) return range;
  7892. range = _;
  7893. return scale;
  7894. };
  7895. scale.invertExtent = function(y) {
  7896. y = range.indexOf(y);
  7897. return [ domain[y - 1], domain[y] ];
  7898. };
  7899. scale.copy = function() {
  7900. return d3_scale_threshold(domain, range);
  7901. };
  7902. return scale;
  7903. }
  7904. d3.scale.identity = function() {
  7905. return d3_scale_identity([ 0, 1 ]);
  7906. };
  7907. function d3_scale_identity(domain) {
  7908. function identity(x) {
  7909. return +x;
  7910. }
  7911. identity.invert = identity;
  7912. identity.domain = identity.range = function(x) {
  7913. if (!arguments.length) return domain;
  7914. domain = x.map(identity);
  7915. return identity;
  7916. };
  7917. identity.ticks = function(m) {
  7918. return d3_scale_linearTicks(domain, m);
  7919. };
  7920. identity.tickFormat = function(m, format) {
  7921. return d3_scale_linearTickFormat(domain, m, format);
  7922. };
  7923. identity.copy = function() {
  7924. return d3_scale_identity(domain);
  7925. };
  7926. return identity;
  7927. }
  7928. d3.svg = {};
  7929. function d3_zero() {
  7930. return 0;
  7931. }
  7932. d3.svg.arc = function() {
  7933. 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;
  7934. function arc() {
  7935. 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;
  7936. if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
  7937. if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
  7938. var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
  7939. if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
  7940. rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
  7941. if (!cw) p1 *= -1;
  7942. if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
  7943. if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
  7944. }
  7945. if (r1) {
  7946. x0 = r1 * Math.cos(a0 + p1);
  7947. y0 = r1 * Math.sin(a0 + p1);
  7948. x1 = r1 * Math.cos(a1 - p1);
  7949. y1 = r1 * Math.sin(a1 - p1);
  7950. var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
  7951. if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
  7952. var h1 = (a0 + a1) / 2;
  7953. x0 = r1 * Math.cos(h1);
  7954. y0 = r1 * Math.sin(h1);
  7955. x1 = y1 = null;
  7956. }
  7957. } else {
  7958. x0 = y0 = 0;
  7959. }
  7960. if (r0) {
  7961. x2 = r0 * Math.cos(a1 - p0);
  7962. y2 = r0 * Math.sin(a1 - p0);
  7963. x3 = r0 * Math.cos(a0 + p0);
  7964. y3 = r0 * Math.sin(a0 + p0);
  7965. var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
  7966. if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
  7967. var h0 = (a0 + a1) / 2;
  7968. x2 = r0 * Math.cos(h0);
  7969. y2 = r0 * Math.sin(h0);
  7970. x3 = y3 = null;
  7971. }
  7972. } else {
  7973. x2 = y2 = 0;
  7974. }
  7975. if ((rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
  7976. cr = r0 < r1 ^ cw ? 0 : 1;
  7977. 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]);
  7978. if (x1 != null) {
  7979. var rc1 = Math.min(rc, (r1 - lc) / (kc + 1)), 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);
  7980. if (rc === rc1) {
  7981. 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]);
  7982. } else {
  7983. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
  7984. }
  7985. } else {
  7986. path.push("M", x0, ",", y0);
  7987. }
  7988. if (x3 != null) {
  7989. var rc0 = Math.min(rc, (r0 - lc) / (kc - 1)), 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);
  7990. if (rc === rc0) {
  7991. 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]);
  7992. } else {
  7993. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  7994. }
  7995. } else {
  7996. path.push("L", x2, ",", y2);
  7997. }
  7998. } else {
  7999. path.push("M", x0, ",", y0);
  8000. if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
  8001. path.push("L", x2, ",", y2);
  8002. if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
  8003. }
  8004. path.push("Z");
  8005. return path.join("");
  8006. }
  8007. function circleSegment(r1, cw) {
  8008. return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
  8009. }
  8010. arc.innerRadius = function(v) {
  8011. if (!arguments.length) return innerRadius;
  8012. innerRadius = d3_functor(v);
  8013. return arc;
  8014. };
  8015. arc.outerRadius = function(v) {
  8016. if (!arguments.length) return outerRadius;
  8017. outerRadius = d3_functor(v);
  8018. return arc;
  8019. };
  8020. arc.cornerRadius = function(v) {
  8021. if (!arguments.length) return cornerRadius;
  8022. cornerRadius = d3_functor(v);
  8023. return arc;
  8024. };
  8025. arc.padRadius = function(v) {
  8026. if (!arguments.length) return padRadius;
  8027. padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
  8028. return arc;
  8029. };
  8030. arc.startAngle = function(v) {
  8031. if (!arguments.length) return startAngle;
  8032. startAngle = d3_functor(v);
  8033. return arc;
  8034. };
  8035. arc.endAngle = function(v) {
  8036. if (!arguments.length) return endAngle;
  8037. endAngle = d3_functor(v);
  8038. return arc;
  8039. };
  8040. arc.padAngle = function(v) {
  8041. if (!arguments.length) return padAngle;
  8042. padAngle = d3_functor(v);
  8043. return arc;
  8044. };
  8045. arc.centroid = function() {
  8046. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
  8047. return [ Math.cos(a) * r, Math.sin(a) * r ];
  8048. };
  8049. return arc;
  8050. };
  8051. var d3_svg_arcAuto = "auto";
  8052. function d3_svg_arcInnerRadius(d) {
  8053. return d.innerRadius;
  8054. }
  8055. function d3_svg_arcOuterRadius(d) {
  8056. return d.outerRadius;
  8057. }
  8058. function d3_svg_arcStartAngle(d) {
  8059. return d.startAngle;
  8060. }
  8061. function d3_svg_arcEndAngle(d) {
  8062. return d.endAngle;
  8063. }
  8064. function d3_svg_arcPadAngle(d) {
  8065. return d && d.padAngle;
  8066. }
  8067. function d3_svg_arcSweep(x0, y0, x1, y1) {
  8068. return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
  8069. }
  8070. function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
  8071. 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(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;
  8072. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  8073. return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
  8074. }
  8075. function d3_svg_line(projection) {
  8076. var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  8077. function line(data) {
  8078. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  8079. function segment() {
  8080. segments.push("M", interpolate(projection(points), tension));
  8081. }
  8082. while (++i < n) {
  8083. if (defined.call(this, d = data[i], i)) {
  8084. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  8085. } else if (points.length) {
  8086. segment();
  8087. points = [];
  8088. }
  8089. }
  8090. if (points.length) segment();
  8091. return segments.length ? segments.join("") : null;
  8092. }
  8093. line.x = function(_) {
  8094. if (!arguments.length) return x;
  8095. x = _;
  8096. return line;
  8097. };
  8098. line.y = function(_) {
  8099. if (!arguments.length) return y;
  8100. y = _;
  8101. return line;
  8102. };
  8103. line.defined = function(_) {
  8104. if (!arguments.length) return defined;
  8105. defined = _;
  8106. return line;
  8107. };
  8108. line.interpolate = function(_) {
  8109. if (!arguments.length) return interpolateKey;
  8110. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8111. return line;
  8112. };
  8113. line.tension = function(_) {
  8114. if (!arguments.length) return tension;
  8115. tension = _;
  8116. return line;
  8117. };
  8118. return line;
  8119. }
  8120. d3.svg.line = function() {
  8121. return d3_svg_line(d3_identity);
  8122. };
  8123. var d3_svg_lineInterpolators = d3.map({
  8124. linear: d3_svg_lineLinear,
  8125. "linear-closed": d3_svg_lineLinearClosed,
  8126. step: d3_svg_lineStep,
  8127. "step-before": d3_svg_lineStepBefore,
  8128. "step-after": d3_svg_lineStepAfter,
  8129. basis: d3_svg_lineBasis,
  8130. "basis-open": d3_svg_lineBasisOpen,
  8131. "basis-closed": d3_svg_lineBasisClosed,
  8132. bundle: d3_svg_lineBundle,
  8133. cardinal: d3_svg_lineCardinal,
  8134. "cardinal-open": d3_svg_lineCardinalOpen,
  8135. "cardinal-closed": d3_svg_lineCardinalClosed,
  8136. monotone: d3_svg_lineMonotone
  8137. });
  8138. d3_svg_lineInterpolators.forEach(function(key, value) {
  8139. value.key = key;
  8140. value.closed = /-closed$/.test(key);
  8141. });
  8142. function d3_svg_lineLinear(points) {
  8143. return points.join("L");
  8144. }
  8145. function d3_svg_lineLinearClosed(points) {
  8146. return d3_svg_lineLinear(points) + "Z";
  8147. }
  8148. function d3_svg_lineStep(points) {
  8149. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8150. while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
  8151. if (n > 1) path.push("H", p[0]);
  8152. return path.join("");
  8153. }
  8154. function d3_svg_lineStepBefore(points) {
  8155. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8156. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  8157. return path.join("");
  8158. }
  8159. function d3_svg_lineStepAfter(points) {
  8160. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8161. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  8162. return path.join("");
  8163. }
  8164. function d3_svg_lineCardinalOpen(points, tension) {
  8165. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
  8166. }
  8167. function d3_svg_lineCardinalClosed(points, tension) {
  8168. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  8169. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  8170. }
  8171. function d3_svg_lineCardinal(points, tension) {
  8172. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  8173. }
  8174. function d3_svg_lineHermite(points, tangents) {
  8175. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  8176. return d3_svg_lineLinear(points);
  8177. }
  8178. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  8179. if (quad) {
  8180. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  8181. p0 = points[1];
  8182. pi = 2;
  8183. }
  8184. if (tangents.length > 1) {
  8185. t = tangents[1];
  8186. p = points[pi];
  8187. pi++;
  8188. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8189. for (var i = 2; i < tangents.length; i++, pi++) {
  8190. p = points[pi];
  8191. t = tangents[i];
  8192. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8193. }
  8194. }
  8195. if (quad) {
  8196. var lp = points[pi];
  8197. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  8198. }
  8199. return path;
  8200. }
  8201. function d3_svg_lineCardinalTangents(points, tension) {
  8202. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  8203. while (++i < n) {
  8204. p0 = p1;
  8205. p1 = p2;
  8206. p2 = points[i];
  8207. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  8208. }
  8209. return tangents;
  8210. }
  8211. function d3_svg_lineBasis(points) {
  8212. if (points.length < 3) return d3_svg_lineLinear(points);
  8213. 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) ];
  8214. points.push(points[n - 1]);
  8215. while (++i <= n) {
  8216. pi = points[i];
  8217. px.shift();
  8218. px.push(pi[0]);
  8219. py.shift();
  8220. py.push(pi[1]);
  8221. d3_svg_lineBasisBezier(path, px, py);
  8222. }
  8223. points.pop();
  8224. path.push("L", pi);
  8225. return path.join("");
  8226. }
  8227. function d3_svg_lineBasisOpen(points) {
  8228. if (points.length < 4) return d3_svg_lineLinear(points);
  8229. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  8230. while (++i < 3) {
  8231. pi = points[i];
  8232. px.push(pi[0]);
  8233. py.push(pi[1]);
  8234. }
  8235. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  8236. --i;
  8237. while (++i < n) {
  8238. pi = points[i];
  8239. px.shift();
  8240. px.push(pi[0]);
  8241. py.shift();
  8242. py.push(pi[1]);
  8243. d3_svg_lineBasisBezier(path, px, py);
  8244. }
  8245. return path.join("");
  8246. }
  8247. function d3_svg_lineBasisClosed(points) {
  8248. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  8249. while (++i < 4) {
  8250. pi = points[i % n];
  8251. px.push(pi[0]);
  8252. py.push(pi[1]);
  8253. }
  8254. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8255. --i;
  8256. while (++i < m) {
  8257. pi = points[i % n];
  8258. px.shift();
  8259. px.push(pi[0]);
  8260. py.shift();
  8261. py.push(pi[1]);
  8262. d3_svg_lineBasisBezier(path, px, py);
  8263. }
  8264. return path.join("");
  8265. }
  8266. function d3_svg_lineBundle(points, tension) {
  8267. var n = points.length - 1;
  8268. if (n) {
  8269. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  8270. while (++i <= n) {
  8271. p = points[i];
  8272. t = i / n;
  8273. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  8274. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  8275. }
  8276. }
  8277. return d3_svg_lineBasis(points);
  8278. }
  8279. function d3_svg_lineDot4(a, b) {
  8280. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  8281. }
  8282. 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 ];
  8283. function d3_svg_lineBasisBezier(path, x, y) {
  8284. 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));
  8285. }
  8286. function d3_svg_lineSlope(p0, p1) {
  8287. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  8288. }
  8289. function d3_svg_lineFiniteDifferences(points) {
  8290. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  8291. while (++i < j) {
  8292. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  8293. }
  8294. m[i] = d;
  8295. return m;
  8296. }
  8297. function d3_svg_lineMonotoneTangents(points) {
  8298. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  8299. while (++i < j) {
  8300. d = d3_svg_lineSlope(points[i], points[i + 1]);
  8301. if (abs(d) < ε) {
  8302. m[i] = m[i + 1] = 0;
  8303. } else {
  8304. a = m[i] / d;
  8305. b = m[i + 1] / d;
  8306. s = a * a + b * b;
  8307. if (s > 9) {
  8308. s = d * 3 / Math.sqrt(s);
  8309. m[i] = s * a;
  8310. m[i + 1] = s * b;
  8311. }
  8312. }
  8313. }
  8314. i = -1;
  8315. while (++i <= j) {
  8316. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  8317. tangents.push([ s || 0, m[i] * s || 0 ]);
  8318. }
  8319. return tangents;
  8320. }
  8321. function d3_svg_lineMonotone(points) {
  8322. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  8323. }
  8324. d3.svg.line.radial = function() {
  8325. var line = d3_svg_line(d3_svg_lineRadial);
  8326. line.radius = line.x, delete line.x;
  8327. line.angle = line.y, delete line.y;
  8328. return line;
  8329. };
  8330. function d3_svg_lineRadial(points) {
  8331. var point, i = -1, n = points.length, r, a;
  8332. while (++i < n) {
  8333. point = points[i];
  8334. r = point[0];
  8335. a = point[1] - halfπ;
  8336. point[0] = r * Math.cos(a);
  8337. point[1] = r * Math.sin(a);
  8338. }
  8339. return points;
  8340. }
  8341. function d3_svg_area(projection) {
  8342. 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;
  8343. function area(data) {
  8344. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  8345. return x;
  8346. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  8347. return y;
  8348. } : d3_functor(y1), x, y;
  8349. function segment() {
  8350. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  8351. }
  8352. while (++i < n) {
  8353. if (defined.call(this, d = data[i], i)) {
  8354. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  8355. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  8356. } else if (points0.length) {
  8357. segment();
  8358. points0 = [];
  8359. points1 = [];
  8360. }
  8361. }
  8362. if (points0.length) segment();
  8363. return segments.length ? segments.join("") : null;
  8364. }
  8365. area.x = function(_) {
  8366. if (!arguments.length) return x1;
  8367. x0 = x1 = _;
  8368. return area;
  8369. };
  8370. area.x0 = function(_) {
  8371. if (!arguments.length) return x0;
  8372. x0 = _;
  8373. return area;
  8374. };
  8375. area.x1 = function(_) {
  8376. if (!arguments.length) return x1;
  8377. x1 = _;
  8378. return area;
  8379. };
  8380. area.y = function(_) {
  8381. if (!arguments.length) return y1;
  8382. y0 = y1 = _;
  8383. return area;
  8384. };
  8385. area.y0 = function(_) {
  8386. if (!arguments.length) return y0;
  8387. y0 = _;
  8388. return area;
  8389. };
  8390. area.y1 = function(_) {
  8391. if (!arguments.length) return y1;
  8392. y1 = _;
  8393. return area;
  8394. };
  8395. area.defined = function(_) {
  8396. if (!arguments.length) return defined;
  8397. defined = _;
  8398. return area;
  8399. };
  8400. area.interpolate = function(_) {
  8401. if (!arguments.length) return interpolateKey;
  8402. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8403. interpolateReverse = interpolate.reverse || interpolate;
  8404. L = interpolate.closed ? "M" : "L";
  8405. return area;
  8406. };
  8407. area.tension = function(_) {
  8408. if (!arguments.length) return tension;
  8409. tension = _;
  8410. return area;
  8411. };
  8412. return area;
  8413. }
  8414. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  8415. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  8416. d3.svg.area = function() {
  8417. return d3_svg_area(d3_identity);
  8418. };
  8419. d3.svg.area.radial = function() {
  8420. var area = d3_svg_area(d3_svg_lineRadial);
  8421. area.radius = area.x, delete area.x;
  8422. area.innerRadius = area.x0, delete area.x0;
  8423. area.outerRadius = area.x1, delete area.x1;
  8424. area.angle = area.y, delete area.y;
  8425. area.startAngle = area.y0, delete area.y0;
  8426. area.endAngle = area.y1, delete area.y1;
  8427. return area;
  8428. };
  8429. d3.svg.chord = function() {
  8430. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  8431. function chord(d, i) {
  8432. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  8433. 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";
  8434. }
  8435. function subgroup(self, f, d, i) {
  8436. 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π;
  8437. return {
  8438. r: r,
  8439. a0: a0,
  8440. a1: a1,
  8441. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  8442. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  8443. };
  8444. }
  8445. function equals(a, b) {
  8446. return a.a0 == b.a0 && a.a1 == b.a1;
  8447. }
  8448. function arc(r, p, a) {
  8449. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  8450. }
  8451. function curve(r0, p0, r1, p1) {
  8452. return "Q 0,0 " + p1;
  8453. }
  8454. chord.radius = function(v) {
  8455. if (!arguments.length) return radius;
  8456. radius = d3_functor(v);
  8457. return chord;
  8458. };
  8459. chord.source = function(v) {
  8460. if (!arguments.length) return source;
  8461. source = d3_functor(v);
  8462. return chord;
  8463. };
  8464. chord.target = function(v) {
  8465. if (!arguments.length) return target;
  8466. target = d3_functor(v);
  8467. return chord;
  8468. };
  8469. chord.startAngle = function(v) {
  8470. if (!arguments.length) return startAngle;
  8471. startAngle = d3_functor(v);
  8472. return chord;
  8473. };
  8474. chord.endAngle = function(v) {
  8475. if (!arguments.length) return endAngle;
  8476. endAngle = d3_functor(v);
  8477. return chord;
  8478. };
  8479. return chord;
  8480. };
  8481. function d3_svg_chordRadius(d) {
  8482. return d.radius;
  8483. }
  8484. d3.svg.diagonal = function() {
  8485. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  8486. function diagonal(d, i) {
  8487. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  8488. x: p0.x,
  8489. y: m
  8490. }, {
  8491. x: p3.x,
  8492. y: m
  8493. }, p3 ];
  8494. p = p.map(projection);
  8495. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  8496. }
  8497. diagonal.source = function(x) {
  8498. if (!arguments.length) return source;
  8499. source = d3_functor(x);
  8500. return diagonal;
  8501. };
  8502. diagonal.target = function(x) {
  8503. if (!arguments.length) return target;
  8504. target = d3_functor(x);
  8505. return diagonal;
  8506. };
  8507. diagonal.projection = function(x) {
  8508. if (!arguments.length) return projection;
  8509. projection = x;
  8510. return diagonal;
  8511. };
  8512. return diagonal;
  8513. };
  8514. function d3_svg_diagonalProjection(d) {
  8515. return [ d.x, d.y ];
  8516. }
  8517. d3.svg.diagonal.radial = function() {
  8518. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  8519. diagonal.projection = function(x) {
  8520. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  8521. };
  8522. return diagonal;
  8523. };
  8524. function d3_svg_diagonalRadialProjection(projection) {
  8525. return function() {
  8526. var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
  8527. return [ r * Math.cos(a), r * Math.sin(a) ];
  8528. };
  8529. }
  8530. d3.svg.symbol = function() {
  8531. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  8532. function symbol(d, i) {
  8533. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  8534. }
  8535. symbol.type = function(x) {
  8536. if (!arguments.length) return type;
  8537. type = d3_functor(x);
  8538. return symbol;
  8539. };
  8540. symbol.size = function(x) {
  8541. if (!arguments.length) return size;
  8542. size = d3_functor(x);
  8543. return symbol;
  8544. };
  8545. return symbol;
  8546. };
  8547. function d3_svg_symbolSize() {
  8548. return 64;
  8549. }
  8550. function d3_svg_symbolType() {
  8551. return "circle";
  8552. }
  8553. function d3_svg_symbolCircle(size) {
  8554. var r = Math.sqrt(size / π);
  8555. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  8556. }
  8557. var d3_svg_symbols = d3.map({
  8558. circle: d3_svg_symbolCircle,
  8559. cross: function(size) {
  8560. var r = Math.sqrt(size / 5) / 2;
  8561. 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";
  8562. },
  8563. diamond: function(size) {
  8564. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  8565. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  8566. },
  8567. square: function(size) {
  8568. var r = Math.sqrt(size) / 2;
  8569. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  8570. },
  8571. "triangle-down": function(size) {
  8572. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8573. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  8574. },
  8575. "triangle-up": function(size) {
  8576. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8577. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  8578. }
  8579. });
  8580. d3.svg.symbolTypes = d3_svg_symbols.keys();
  8581. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  8582. d3_selectionPrototype.transition = function(name) {
  8583. var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
  8584. time: Date.now(),
  8585. ease: d3_ease_cubicInOut,
  8586. delay: 0,
  8587. duration: 250
  8588. };
  8589. for (var j = -1, m = this.length; ++j < m; ) {
  8590. subgroups.push(subgroup = []);
  8591. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8592. if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
  8593. subgroup.push(node);
  8594. }
  8595. }
  8596. return d3_transition(subgroups, ns, id);
  8597. };
  8598. d3_selectionPrototype.interrupt = function(name) {
  8599. return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
  8600. };
  8601. var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
  8602. function d3_selection_interruptNS(ns) {
  8603. return function() {
  8604. var lock, active;
  8605. if ((lock = this[ns]) && (active = lock[lock.active])) {
  8606. if (--lock.count) delete lock[lock.active]; else delete this[ns];
  8607. lock.active += .5;
  8608. active.event && active.event.interrupt.call(this, this.__data__, active.index);
  8609. }
  8610. };
  8611. }
  8612. function d3_transition(groups, ns, id) {
  8613. d3_subclass(groups, d3_transitionPrototype);
  8614. groups.namespace = ns;
  8615. groups.id = id;
  8616. return groups;
  8617. }
  8618. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
  8619. d3_transitionPrototype.call = d3_selectionPrototype.call;
  8620. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  8621. d3_transitionPrototype.node = d3_selectionPrototype.node;
  8622. d3_transitionPrototype.size = d3_selectionPrototype.size;
  8623. d3.transition = function(selection, name) {
  8624. return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
  8625. };
  8626. d3.transition.prototype = d3_transitionPrototype;
  8627. d3_transitionPrototype.select = function(selector) {
  8628. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
  8629. selector = d3_selection_selector(selector);
  8630. for (var j = -1, m = this.length; ++j < m; ) {
  8631. subgroups.push(subgroup = []);
  8632. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8633. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
  8634. if ("__data__" in node) subnode.__data__ = node.__data__;
  8635. d3_transitionNode(subnode, i, ns, id, node[ns][id]);
  8636. subgroup.push(subnode);
  8637. } else {
  8638. subgroup.push(null);
  8639. }
  8640. }
  8641. }
  8642. return d3_transition(subgroups, ns, id);
  8643. };
  8644. d3_transitionPrototype.selectAll = function(selector) {
  8645. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
  8646. selector = d3_selection_selectorAll(selector);
  8647. for (var j = -1, m = this.length; ++j < m; ) {
  8648. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8649. if (node = group[i]) {
  8650. transition = node[ns][id];
  8651. subnodes = selector.call(node, node.__data__, i, j);
  8652. subgroups.push(subgroup = []);
  8653. for (var k = -1, o = subnodes.length; ++k < o; ) {
  8654. if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
  8655. subgroup.push(subnode);
  8656. }
  8657. }
  8658. }
  8659. }
  8660. return d3_transition(subgroups, ns, id);
  8661. };
  8662. d3_transitionPrototype.filter = function(filter) {
  8663. var subgroups = [], subgroup, group, node;
  8664. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  8665. for (var j = 0, m = this.length; j < m; j++) {
  8666. subgroups.push(subgroup = []);
  8667. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8668. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  8669. subgroup.push(node);
  8670. }
  8671. }
  8672. }
  8673. return d3_transition(subgroups, this.namespace, this.id);
  8674. };
  8675. d3_transitionPrototype.tween = function(name, tween) {
  8676. var id = this.id, ns = this.namespace;
  8677. if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
  8678. return d3_selection_each(this, tween == null ? function(node) {
  8679. node[ns][id].tween.remove(name);
  8680. } : function(node) {
  8681. node[ns][id].tween.set(name, tween);
  8682. });
  8683. };
  8684. function d3_transition_tween(groups, name, value, tween) {
  8685. var id = groups.id, ns = groups.namespace;
  8686. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  8687. node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  8688. } : (value = tween(value), function(node) {
  8689. node[ns][id].tween.set(name, value);
  8690. }));
  8691. }
  8692. d3_transitionPrototype.attr = function(nameNS, value) {
  8693. if (arguments.length < 2) {
  8694. for (value in nameNS) this.attr(value, nameNS[value]);
  8695. return this;
  8696. }
  8697. var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
  8698. function attrNull() {
  8699. this.removeAttribute(name);
  8700. }
  8701. function attrNullNS() {
  8702. this.removeAttributeNS(name.space, name.local);
  8703. }
  8704. function attrTween(b) {
  8705. return b == null ? attrNull : (b += "", function() {
  8706. var a = this.getAttribute(name), i;
  8707. return a !== b && (i = interpolate(a, b), function(t) {
  8708. this.setAttribute(name, i(t));
  8709. });
  8710. });
  8711. }
  8712. function attrTweenNS(b) {
  8713. return b == null ? attrNullNS : (b += "", function() {
  8714. var a = this.getAttributeNS(name.space, name.local), i;
  8715. return a !== b && (i = interpolate(a, b), function(t) {
  8716. this.setAttributeNS(name.space, name.local, i(t));
  8717. });
  8718. });
  8719. }
  8720. return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
  8721. };
  8722. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  8723. var name = d3.ns.qualify(nameNS);
  8724. function attrTween(d, i) {
  8725. var f = tween.call(this, d, i, this.getAttribute(name));
  8726. return f && function(t) {
  8727. this.setAttribute(name, f(t));
  8728. };
  8729. }
  8730. function attrTweenNS(d, i) {
  8731. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  8732. return f && function(t) {
  8733. this.setAttributeNS(name.space, name.local, f(t));
  8734. };
  8735. }
  8736. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  8737. };
  8738. d3_transitionPrototype.style = function(name, value, priority) {
  8739. var n = arguments.length;
  8740. if (n < 3) {
  8741. if (typeof name !== "string") {
  8742. if (n < 2) value = "";
  8743. for (priority in name) this.style(priority, name[priority], value);
  8744. return this;
  8745. }
  8746. priority = "";
  8747. }
  8748. function styleNull() {
  8749. this.style.removeProperty(name);
  8750. }
  8751. function styleString(b) {
  8752. return b == null ? styleNull : (b += "", function() {
  8753. var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
  8754. return a !== b && (i = d3_interpolate(a, b), function(t) {
  8755. this.style.setProperty(name, i(t), priority);
  8756. });
  8757. });
  8758. }
  8759. return d3_transition_tween(this, "style." + name, value, styleString);
  8760. };
  8761. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  8762. if (arguments.length < 3) priority = "";
  8763. function styleTween(d, i) {
  8764. var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
  8765. return f && function(t) {
  8766. this.style.setProperty(name, f(t), priority);
  8767. };
  8768. }
  8769. return this.tween("style." + name, styleTween);
  8770. };
  8771. d3_transitionPrototype.text = function(value) {
  8772. return d3_transition_tween(this, "text", value, d3_transition_text);
  8773. };
  8774. function d3_transition_text(b) {
  8775. if (b == null) b = "";
  8776. return function() {
  8777. this.textContent = b;
  8778. };
  8779. }
  8780. d3_transitionPrototype.remove = function() {
  8781. var ns = this.namespace;
  8782. return this.each("end.transition", function() {
  8783. var p;
  8784. if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
  8785. });
  8786. };
  8787. d3_transitionPrototype.ease = function(value) {
  8788. var id = this.id, ns = this.namespace;
  8789. if (arguments.length < 1) return this.node()[ns][id].ease;
  8790. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  8791. return d3_selection_each(this, function(node) {
  8792. node[ns][id].ease = value;
  8793. });
  8794. };
  8795. d3_transitionPrototype.delay = function(value) {
  8796. var id = this.id, ns = this.namespace;
  8797. if (arguments.length < 1) return this.node()[ns][id].delay;
  8798. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8799. node[ns][id].delay = +value.call(node, node.__data__, i, j);
  8800. } : (value = +value, function(node) {
  8801. node[ns][id].delay = value;
  8802. }));
  8803. };
  8804. d3_transitionPrototype.duration = function(value) {
  8805. var id = this.id, ns = this.namespace;
  8806. if (arguments.length < 1) return this.node()[ns][id].duration;
  8807. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8808. node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
  8809. } : (value = Math.max(1, value), function(node) {
  8810. node[ns][id].duration = value;
  8811. }));
  8812. };
  8813. d3_transitionPrototype.each = function(type, listener) {
  8814. var id = this.id, ns = this.namespace;
  8815. if (arguments.length < 2) {
  8816. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  8817. try {
  8818. d3_transitionInheritId = id;
  8819. d3_selection_each(this, function(node, i, j) {
  8820. d3_transitionInherit = node[ns][id];
  8821. type.call(node, node.__data__, i, j);
  8822. });
  8823. } finally {
  8824. d3_transitionInherit = inherit;
  8825. d3_transitionInheritId = inheritId;
  8826. }
  8827. } else {
  8828. d3_selection_each(this, function(node) {
  8829. var transition = node[ns][id];
  8830. (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
  8831. });
  8832. }
  8833. return this;
  8834. };
  8835. d3_transitionPrototype.transition = function() {
  8836. var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
  8837. for (var j = 0, m = this.length; j < m; j++) {
  8838. subgroups.push(subgroup = []);
  8839. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8840. if (node = group[i]) {
  8841. transition = node[ns][id0];
  8842. d3_transitionNode(node, i, ns, id1, {
  8843. time: transition.time,
  8844. ease: transition.ease,
  8845. delay: transition.delay + transition.duration,
  8846. duration: transition.duration
  8847. });
  8848. }
  8849. subgroup.push(node);
  8850. }
  8851. }
  8852. return d3_transition(subgroups, ns, id1);
  8853. };
  8854. function d3_transitionNamespace(name) {
  8855. return name == null ? "__transition__" : "__transition_" + name + "__";
  8856. }
  8857. function d3_transitionNode(node, i, ns, id, inherit) {
  8858. var lock = node[ns] || (node[ns] = {
  8859. active: 0,
  8860. count: 0
  8861. }), transition = lock[id];
  8862. if (!transition) {
  8863. var time = inherit.time;
  8864. transition = lock[id] = {
  8865. tween: new d3_Map(),
  8866. time: time,
  8867. delay: inherit.delay,
  8868. duration: inherit.duration,
  8869. ease: inherit.ease,
  8870. index: i
  8871. };
  8872. inherit = null;
  8873. ++lock.count;
  8874. d3.timer(function(elapsed) {
  8875. var delay = transition.delay, duration, ease, timer = d3_timer_active, tweened = [];
  8876. timer.t = delay + time;
  8877. if (delay <= elapsed) return start(elapsed - delay);
  8878. timer.c = start;
  8879. function start(elapsed) {
  8880. if (lock.active > id) return stop();
  8881. var active = lock[lock.active];
  8882. if (active) {
  8883. --lock.count;
  8884. delete lock[lock.active];
  8885. active.event && active.event.interrupt.call(node, node.__data__, active.index);
  8886. }
  8887. lock.active = id;
  8888. transition.event && transition.event.start.call(node, node.__data__, i);
  8889. transition.tween.forEach(function(key, value) {
  8890. if (value = value.call(node, node.__data__, i)) {
  8891. tweened.push(value);
  8892. }
  8893. });
  8894. ease = transition.ease;
  8895. duration = transition.duration;
  8896. d3.timer(function() {
  8897. timer.c = tick(elapsed || 1) ? d3_true : tick;
  8898. return 1;
  8899. }, 0, time);
  8900. }
  8901. function tick(elapsed) {
  8902. if (lock.active !== id) return 1;
  8903. var t = elapsed / duration, e = ease(t), n = tweened.length;
  8904. while (n > 0) {
  8905. tweened[--n].call(node, e);
  8906. }
  8907. if (t >= 1) {
  8908. transition.event && transition.event.end.call(node, node.__data__, i);
  8909. return stop();
  8910. }
  8911. }
  8912. function stop() {
  8913. if (--lock.count) delete lock[id]; else delete node[ns];
  8914. return 1;
  8915. }
  8916. }, 0, time);
  8917. }
  8918. }
  8919. d3.svg.axis = function() {
  8920. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
  8921. function axis(g) {
  8922. g.each(function() {
  8923. var g = d3.select(this);
  8924. var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
  8925. 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;
  8926. var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  8927. d3.transition(path));
  8928. tickEnter.append("line");
  8929. tickEnter.append("text");
  8930. 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;
  8931. if (orient === "bottom" || orient === "top") {
  8932. tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
  8933. text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
  8934. pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
  8935. } else {
  8936. tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
  8937. text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
  8938. pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
  8939. }
  8940. lineEnter.attr(y2, sign * innerTickSize);
  8941. textEnter.attr(y1, sign * tickSpacing);
  8942. lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
  8943. textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
  8944. if (scale1.rangeBand) {
  8945. var x = scale1, dx = x.rangeBand() / 2;
  8946. scale0 = scale1 = function(d) {
  8947. return x(d) + dx;
  8948. };
  8949. } else if (scale0.rangeBand) {
  8950. scale0 = scale1;
  8951. } else {
  8952. tickExit.call(tickTransform, scale1, scale0);
  8953. }
  8954. tickEnter.call(tickTransform, scale0, scale1);
  8955. tickUpdate.call(tickTransform, scale1, scale1);
  8956. });
  8957. }
  8958. axis.scale = function(x) {
  8959. if (!arguments.length) return scale;
  8960. scale = x;
  8961. return axis;
  8962. };
  8963. axis.orient = function(x) {
  8964. if (!arguments.length) return orient;
  8965. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  8966. return axis;
  8967. };
  8968. axis.ticks = function() {
  8969. if (!arguments.length) return tickArguments_;
  8970. tickArguments_ = arguments;
  8971. return axis;
  8972. };
  8973. axis.tickValues = function(x) {
  8974. if (!arguments.length) return tickValues;
  8975. tickValues = x;
  8976. return axis;
  8977. };
  8978. axis.tickFormat = function(x) {
  8979. if (!arguments.length) return tickFormat_;
  8980. tickFormat_ = x;
  8981. return axis;
  8982. };
  8983. axis.tickSize = function(x) {
  8984. var n = arguments.length;
  8985. if (!n) return innerTickSize;
  8986. innerTickSize = +x;
  8987. outerTickSize = +arguments[n - 1];
  8988. return axis;
  8989. };
  8990. axis.innerTickSize = function(x) {
  8991. if (!arguments.length) return innerTickSize;
  8992. innerTickSize = +x;
  8993. return axis;
  8994. };
  8995. axis.outerTickSize = function(x) {
  8996. if (!arguments.length) return outerTickSize;
  8997. outerTickSize = +x;
  8998. return axis;
  8999. };
  9000. axis.tickPadding = function(x) {
  9001. if (!arguments.length) return tickPadding;
  9002. tickPadding = +x;
  9003. return axis;
  9004. };
  9005. axis.tickSubdivide = function() {
  9006. return arguments.length && axis;
  9007. };
  9008. return axis;
  9009. };
  9010. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  9011. top: 1,
  9012. right: 1,
  9013. bottom: 1,
  9014. left: 1
  9015. };
  9016. function d3_svg_axisX(selection, x0, x1) {
  9017. selection.attr("transform", function(d) {
  9018. var v0 = x0(d);
  9019. return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
  9020. });
  9021. }
  9022. function d3_svg_axisY(selection, y0, y1) {
  9023. selection.attr("transform", function(d) {
  9024. var v0 = y0(d);
  9025. return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
  9026. });
  9027. }
  9028. d3.svg.brush = function() {
  9029. 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];
  9030. function brush(g) {
  9031. g.each(function() {
  9032. 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);
  9033. var background = g.selectAll(".background").data([ 0 ]);
  9034. background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  9035. g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
  9036. var resize = g.selectAll(".resize").data(resizes, d3_identity);
  9037. resize.exit().remove();
  9038. resize.enter().append("g").attr("class", function(d) {
  9039. return "resize " + d;
  9040. }).style("cursor", function(d) {
  9041. return d3_svg_brushCursor[d];
  9042. }).append("rect").attr("x", function(d) {
  9043. return /[ew]$/.test(d) ? -3 : null;
  9044. }).attr("y", function(d) {
  9045. return /^[ns]/.test(d) ? -3 : null;
  9046. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  9047. resize.style("display", brush.empty() ? "none" : null);
  9048. var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
  9049. if (x) {
  9050. range = d3_scaleRange(x);
  9051. backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
  9052. redrawX(gUpdate);
  9053. }
  9054. if (y) {
  9055. range = d3_scaleRange(y);
  9056. backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
  9057. redrawY(gUpdate);
  9058. }
  9059. redraw(gUpdate);
  9060. });
  9061. }
  9062. brush.event = function(g) {
  9063. g.each(function() {
  9064. var event_ = event.of(this, arguments), extent1 = {
  9065. x: xExtent,
  9066. y: yExtent,
  9067. i: xExtentDomain,
  9068. j: yExtentDomain
  9069. }, extent0 = this.__chart__ || extent1;
  9070. this.__chart__ = extent1;
  9071. if (d3_transitionInheritId) {
  9072. d3.select(this).transition().each("start.brush", function() {
  9073. xExtentDomain = extent0.i;
  9074. yExtentDomain = extent0.j;
  9075. xExtent = extent0.x;
  9076. yExtent = extent0.y;
  9077. event_({
  9078. type: "brushstart"
  9079. });
  9080. }).tween("brush:brush", function() {
  9081. var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
  9082. xExtentDomain = yExtentDomain = null;
  9083. return function(t) {
  9084. xExtent = extent1.x = xi(t);
  9085. yExtent = extent1.y = yi(t);
  9086. event_({
  9087. type: "brush",
  9088. mode: "resize"
  9089. });
  9090. };
  9091. }).each("end.brush", function() {
  9092. xExtentDomain = extent1.i;
  9093. yExtentDomain = extent1.j;
  9094. event_({
  9095. type: "brush",
  9096. mode: "resize"
  9097. });
  9098. event_({
  9099. type: "brushend"
  9100. });
  9101. });
  9102. } else {
  9103. event_({
  9104. type: "brushstart"
  9105. });
  9106. event_({
  9107. type: "brush",
  9108. mode: "resize"
  9109. });
  9110. event_({
  9111. type: "brushend"
  9112. });
  9113. }
  9114. });
  9115. };
  9116. function redraw(g) {
  9117. g.selectAll(".resize").attr("transform", function(d) {
  9118. return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
  9119. });
  9120. }
  9121. function redrawX(g) {
  9122. g.select(".extent").attr("x", xExtent[0]);
  9123. g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
  9124. }
  9125. function redrawY(g) {
  9126. g.select(".extent").attr("y", yExtent[0]);
  9127. g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
  9128. }
  9129. function brushstart() {
  9130. 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;
  9131. var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
  9132. if (d3.event.changedTouches) {
  9133. w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
  9134. } else {
  9135. w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
  9136. }
  9137. g.interrupt().selectAll("*").interrupt();
  9138. if (dragging) {
  9139. origin[0] = xExtent[0] - origin[0];
  9140. origin[1] = yExtent[0] - origin[1];
  9141. } else if (resizing) {
  9142. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  9143. offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
  9144. origin[0] = xExtent[ex];
  9145. origin[1] = yExtent[ey];
  9146. } else if (d3.event.altKey) center = origin.slice();
  9147. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  9148. d3.select("body").style("cursor", eventTarget.style("cursor"));
  9149. event_({
  9150. type: "brushstart"
  9151. });
  9152. brushmove();
  9153. function keydown() {
  9154. if (d3.event.keyCode == 32) {
  9155. if (!dragging) {
  9156. center = null;
  9157. origin[0] -= xExtent[1];
  9158. origin[1] -= yExtent[1];
  9159. dragging = 2;
  9160. }
  9161. d3_eventPreventDefault();
  9162. }
  9163. }
  9164. function keyup() {
  9165. if (d3.event.keyCode == 32 && dragging == 2) {
  9166. origin[0] += xExtent[1];
  9167. origin[1] += yExtent[1];
  9168. dragging = 0;
  9169. d3_eventPreventDefault();
  9170. }
  9171. }
  9172. function brushmove() {
  9173. var point = d3.mouse(target), moved = false;
  9174. if (offset) {
  9175. point[0] += offset[0];
  9176. point[1] += offset[1];
  9177. }
  9178. if (!dragging) {
  9179. if (d3.event.altKey) {
  9180. if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
  9181. origin[0] = xExtent[+(point[0] < center[0])];
  9182. origin[1] = yExtent[+(point[1] < center[1])];
  9183. } else center = null;
  9184. }
  9185. if (resizingX && move1(point, x, 0)) {
  9186. redrawX(g);
  9187. moved = true;
  9188. }
  9189. if (resizingY && move1(point, y, 1)) {
  9190. redrawY(g);
  9191. moved = true;
  9192. }
  9193. if (moved) {
  9194. redraw(g);
  9195. event_({
  9196. type: "brush",
  9197. mode: dragging ? "move" : "resize"
  9198. });
  9199. }
  9200. }
  9201. function move1(point, scale, i) {
  9202. 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;
  9203. if (dragging) {
  9204. r0 -= position;
  9205. r1 -= size + position;
  9206. }
  9207. min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
  9208. if (dragging) {
  9209. max = (min += position) + size;
  9210. } else {
  9211. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  9212. if (position < min) {
  9213. max = min;
  9214. min = position;
  9215. } else {
  9216. max = position;
  9217. }
  9218. }
  9219. if (extent[0] != min || extent[1] != max) {
  9220. if (i) yExtentDomain = null; else xExtentDomain = null;
  9221. extent[0] = min;
  9222. extent[1] = max;
  9223. return true;
  9224. }
  9225. }
  9226. function brushend() {
  9227. brushmove();
  9228. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  9229. d3.select("body").style("cursor", null);
  9230. 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);
  9231. dragRestore();
  9232. event_({
  9233. type: "brushend"
  9234. });
  9235. }
  9236. }
  9237. brush.x = function(z) {
  9238. if (!arguments.length) return x;
  9239. x = z;
  9240. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9241. return brush;
  9242. };
  9243. brush.y = function(z) {
  9244. if (!arguments.length) return y;
  9245. y = z;
  9246. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9247. return brush;
  9248. };
  9249. brush.clamp = function(z) {
  9250. if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
  9251. if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
  9252. return brush;
  9253. };
  9254. brush.extent = function(z) {
  9255. var x0, x1, y0, y1, t;
  9256. if (!arguments.length) {
  9257. if (x) {
  9258. if (xExtentDomain) {
  9259. x0 = xExtentDomain[0], x1 = xExtentDomain[1];
  9260. } else {
  9261. x0 = xExtent[0], x1 = xExtent[1];
  9262. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  9263. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9264. }
  9265. }
  9266. if (y) {
  9267. if (yExtentDomain) {
  9268. y0 = yExtentDomain[0], y1 = yExtentDomain[1];
  9269. } else {
  9270. y0 = yExtent[0], y1 = yExtent[1];
  9271. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  9272. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9273. }
  9274. }
  9275. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  9276. }
  9277. if (x) {
  9278. x0 = z[0], x1 = z[1];
  9279. if (y) x0 = x0[0], x1 = x1[0];
  9280. xExtentDomain = [ x0, x1 ];
  9281. if (x.invert) x0 = x(x0), x1 = x(x1);
  9282. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9283. if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
  9284. }
  9285. if (y) {
  9286. y0 = z[0], y1 = z[1];
  9287. if (x) y0 = y0[1], y1 = y1[1];
  9288. yExtentDomain = [ y0, y1 ];
  9289. if (y.invert) y0 = y(y0), y1 = y(y1);
  9290. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9291. if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
  9292. }
  9293. return brush;
  9294. };
  9295. brush.clear = function() {
  9296. if (!brush.empty()) {
  9297. xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
  9298. xExtentDomain = yExtentDomain = null;
  9299. }
  9300. return brush;
  9301. };
  9302. brush.empty = function() {
  9303. return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
  9304. };
  9305. return d3.rebind(brush, event, "on");
  9306. };
  9307. var d3_svg_brushCursor = {
  9308. n: "ns-resize",
  9309. e: "ew-resize",
  9310. s: "ns-resize",
  9311. w: "ew-resize",
  9312. nw: "nwse-resize",
  9313. ne: "nesw-resize",
  9314. se: "nwse-resize",
  9315. sw: "nesw-resize"
  9316. };
  9317. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  9318. var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
  9319. var d3_time_formatUtc = d3_time_format.utc;
  9320. var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
  9321. d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  9322. function d3_time_formatIsoNative(date) {
  9323. return date.toISOString();
  9324. }
  9325. d3_time_formatIsoNative.parse = function(string) {
  9326. var date = new Date(string);
  9327. return isNaN(date) ? null : date;
  9328. };
  9329. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  9330. d3_time.second = d3_time_interval(function(date) {
  9331. return new d3_date(Math.floor(date / 1e3) * 1e3);
  9332. }, function(date, offset) {
  9333. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  9334. }, function(date) {
  9335. return date.getSeconds();
  9336. });
  9337. d3_time.seconds = d3_time.second.range;
  9338. d3_time.seconds.utc = d3_time.second.utc.range;
  9339. d3_time.minute = d3_time_interval(function(date) {
  9340. return new d3_date(Math.floor(date / 6e4) * 6e4);
  9341. }, function(date, offset) {
  9342. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  9343. }, function(date) {
  9344. return date.getMinutes();
  9345. });
  9346. d3_time.minutes = d3_time.minute.range;
  9347. d3_time.minutes.utc = d3_time.minute.utc.range;
  9348. d3_time.hour = d3_time_interval(function(date) {
  9349. var timezone = date.getTimezoneOffset() / 60;
  9350. return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  9351. }, function(date, offset) {
  9352. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  9353. }, function(date) {
  9354. return date.getHours();
  9355. });
  9356. d3_time.hours = d3_time.hour.range;
  9357. d3_time.hours.utc = d3_time.hour.utc.range;
  9358. d3_time.month = d3_time_interval(function(date) {
  9359. date = d3_time.day(date);
  9360. date.setDate(1);
  9361. return date;
  9362. }, function(date, offset) {
  9363. date.setMonth(date.getMonth() + offset);
  9364. }, function(date) {
  9365. return date.getMonth();
  9366. });
  9367. d3_time.months = d3_time.month.range;
  9368. d3_time.months.utc = d3_time.month.utc.range;
  9369. function d3_time_scale(linear, methods, format) {
  9370. function scale(x) {
  9371. return linear(x);
  9372. }
  9373. scale.invert = function(x) {
  9374. return d3_time_scaleDate(linear.invert(x));
  9375. };
  9376. scale.domain = function(x) {
  9377. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  9378. linear.domain(x);
  9379. return scale;
  9380. };
  9381. function tickMethod(extent, count) {
  9382. var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
  9383. return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
  9384. return d / 31536e6;
  9385. }), 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];
  9386. }
  9387. scale.nice = function(interval, skip) {
  9388. var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
  9389. if (method) interval = method[0], skip = method[1];
  9390. function skipped(date) {
  9391. return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
  9392. }
  9393. return scale.domain(d3_scale_nice(domain, skip > 1 ? {
  9394. floor: function(date) {
  9395. while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
  9396. return date;
  9397. },
  9398. ceil: function(date) {
  9399. while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
  9400. return date;
  9401. }
  9402. } : interval));
  9403. };
  9404. scale.ticks = function(interval, skip) {
  9405. var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
  9406. range: interval
  9407. }, skip ];
  9408. if (method) interval = method[0], skip = method[1];
  9409. return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
  9410. };
  9411. scale.tickFormat = function() {
  9412. return format;
  9413. };
  9414. scale.copy = function() {
  9415. return d3_time_scale(linear.copy(), methods, format);
  9416. };
  9417. return d3_scale_linearRebind(scale, linear);
  9418. }
  9419. function d3_time_scaleDate(t) {
  9420. return new Date(t);
  9421. }
  9422. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  9423. 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 ] ];
  9424. var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
  9425. return d.getMilliseconds();
  9426. } ], [ ":%S", function(d) {
  9427. return d.getSeconds();
  9428. } ], [ "%I:%M", function(d) {
  9429. return d.getMinutes();
  9430. } ], [ "%I %p", function(d) {
  9431. return d.getHours();
  9432. } ], [ "%a %d", function(d) {
  9433. return d.getDay() && d.getDate() != 1;
  9434. } ], [ "%b %d", function(d) {
  9435. return d.getDate() != 1;
  9436. } ], [ "%B", function(d) {
  9437. return d.getMonth();
  9438. } ], [ "%Y", d3_true ] ]);
  9439. var d3_time_scaleMilliseconds = {
  9440. range: function(start, stop, step) {
  9441. return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
  9442. },
  9443. floor: d3_identity,
  9444. ceil: d3_identity
  9445. };
  9446. d3_time_scaleLocalMethods.year = d3_time.year;
  9447. d3_time.scale = function() {
  9448. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  9449. };
  9450. var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
  9451. return [ m[0].utc, m[1] ];
  9452. });
  9453. var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
  9454. return d.getUTCMilliseconds();
  9455. } ], [ ":%S", function(d) {
  9456. return d.getUTCSeconds();
  9457. } ], [ "%I:%M", function(d) {
  9458. return d.getUTCMinutes();
  9459. } ], [ "%I %p", function(d) {
  9460. return d.getUTCHours();
  9461. } ], [ "%a %d", function(d) {
  9462. return d.getUTCDay() && d.getUTCDate() != 1;
  9463. } ], [ "%b %d", function(d) {
  9464. return d.getUTCDate() != 1;
  9465. } ], [ "%B", function(d) {
  9466. return d.getUTCMonth();
  9467. } ], [ "%Y", d3_true ] ]);
  9468. d3_time_scaleUtcMethods.year = d3_time.year.utc;
  9469. d3_time.scale.utc = function() {
  9470. return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
  9471. };
  9472. d3.text = d3_xhrType(function(request) {
  9473. return request.responseText;
  9474. });
  9475. d3.json = function(url, callback) {
  9476. return d3_xhr(url, "application/json", d3_json, callback);
  9477. };
  9478. function d3_json(request) {
  9479. return JSON.parse(request.responseText);
  9480. }
  9481. d3.html = function(url, callback) {
  9482. return d3_xhr(url, "text/html", d3_html, callback);
  9483. };
  9484. function d3_html(request) {
  9485. var range = d3_document.createRange();
  9486. range.selectNode(d3_document.body);
  9487. return range.createContextualFragment(request.responseText);
  9488. }
  9489. d3.xml = d3_xhrType(function(request) {
  9490. return request.responseXML;
  9491. });
  9492. if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3;
  9493. this.d3 = d3;
  9494. }();