d3.v3.js 330 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554
  1. !function() {
  2. var d3 = {
  3. version: "3.5.17"
  4. };
  5. var d3_arraySlice = [].slice, d3_array = function(list) {
  6. return d3_arraySlice.call(list);
  7. };
  8. var d3_document = this.document;
  9. function d3_documentElement(node) {
  10. return node && (node.ownerDocument || node.document || node).documentElement;
  11. }
  12. function d3_window(node) {
  13. return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
  14. }
  15. if (d3_document) {
  16. try {
  17. d3_array(d3_document.documentElement.childNodes)[0].nodeType;
  18. } catch (e) {
  19. d3_array = function(list) {
  20. var i = list.length, array = new Array(i);
  21. while (i--) array[i] = list[i];
  22. return array;
  23. };
  24. }
  25. }
  26. if (!Date.now) Date.now = function() {
  27. return +new Date();
  28. };
  29. if (d3_document) {
  30. try {
  31. d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
  32. } catch (error) {
  33. var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
  34. d3_element_prototype.setAttribute = function(name, value) {
  35. d3_element_setAttribute.call(this, name, value + "");
  36. };
  37. d3_element_prototype.setAttributeNS = function(space, local, value) {
  38. d3_element_setAttributeNS.call(this, space, local, value + "");
  39. };
  40. d3_style_prototype.setProperty = function(name, value, priority) {
  41. d3_style_setProperty.call(this, name, value + "", priority);
  42. };
  43. }
  44. }
  45. d3.ascending = d3_ascending;
  46. function d3_ascending(a, b) {
  47. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  48. }
  49. d3.descending = function(a, b) {
  50. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  51. };
  52. d3.min = function(array, f) {
  53. var i = -1, n = array.length, a, b;
  54. if (arguments.length === 1) {
  55. while (++i < n) if ((b = array[i]) != null && b >= b) {
  56. a = b;
  57. break;
  58. }
  59. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  60. } else {
  61. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  62. a = b;
  63. break;
  64. }
  65. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  66. }
  67. return a;
  68. };
  69. d3.max = function(array, f) {
  70. var i = -1, n = array.length, a, b;
  71. if (arguments.length === 1) {
  72. while (++i < n) if ((b = array[i]) != null && b >= b) {
  73. a = b;
  74. break;
  75. }
  76. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  77. } else {
  78. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  79. a = b;
  80. break;
  81. }
  82. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  83. }
  84. return a;
  85. };
  86. d3.extent = function(array, f) {
  87. var i = -1, n = array.length, a, b, c;
  88. if (arguments.length === 1) {
  89. while (++i < n) if ((b = array[i]) != null && b >= b) {
  90. a = c = b;
  91. break;
  92. }
  93. while (++i < n) if ((b = array[i]) != null) {
  94. if (a > b) a = b;
  95. if (c < b) c = b;
  96. }
  97. } else {
  98. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  99. a = c = b;
  100. break;
  101. }
  102. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  103. if (a > b) a = b;
  104. if (c < b) c = b;
  105. }
  106. }
  107. return [ a, c ];
  108. };
  109. function d3_number(x) {
  110. return x === null ? NaN : +x;
  111. }
  112. function d3_numeric(x) {
  113. return !isNaN(x);
  114. }
  115. d3.sum = function(array, f) {
  116. var s = 0, n = array.length, a, i = -1;
  117. if (arguments.length === 1) {
  118. while (++i < n) if (d3_numeric(a = +array[i])) s += a;
  119. } else {
  120. while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
  121. }
  122. return s;
  123. };
  124. d3.mean = function(array, f) {
  125. var s = 0, n = array.length, a, i = -1, j = n;
  126. if (arguments.length === 1) {
  127. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
  128. } else {
  129. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
  130. }
  131. if (j) return s / j;
  132. };
  133. d3.quantile = function(values, p) {
  134. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  135. return e ? v + e * (values[h] - v) : v;
  136. };
  137. d3.median = function(array, f) {
  138. var numbers = [], n = array.length, a, i = -1;
  139. if (arguments.length === 1) {
  140. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
  141. } else {
  142. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
  143. }
  144. if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
  145. };
  146. d3.variance = function(array, f) {
  147. var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
  148. if (arguments.length === 1) {
  149. while (++i < n) {
  150. if (d3_numeric(a = d3_number(array[i]))) {
  151. d = a - m;
  152. m += d / ++j;
  153. s += d * (a - m);
  154. }
  155. }
  156. } else {
  157. while (++i < n) {
  158. if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
  159. d = a - m;
  160. m += d / ++j;
  161. s += d * (a - m);
  162. }
  163. }
  164. }
  165. if (j > 1) return s / (j - 1);
  166. };
  167. d3.deviation = function() {
  168. var v = d3.variance.apply(this, arguments);
  169. return v ? Math.sqrt(v) : v;
  170. };
  171. function d3_bisector(compare) {
  172. return {
  173. left: function(a, x, lo, hi) {
  174. if (arguments.length < 3) lo = 0;
  175. if (arguments.length < 4) hi = a.length;
  176. while (lo < hi) {
  177. var mid = lo + hi >>> 1;
  178. if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
  179. }
  180. return lo;
  181. },
  182. right: function(a, x, lo, hi) {
  183. if (arguments.length < 3) lo = 0;
  184. if (arguments.length < 4) hi = a.length;
  185. while (lo < hi) {
  186. var mid = lo + hi >>> 1;
  187. if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
  188. }
  189. return lo;
  190. }
  191. };
  192. }
  193. var d3_bisect = d3_bisector(d3_ascending);
  194. d3.bisectLeft = d3_bisect.left;
  195. d3.bisect = d3.bisectRight = d3_bisect.right;
  196. d3.bisector = function(f) {
  197. return d3_bisector(f.length === 1 ? function(d, x) {
  198. return d3_ascending(f(d), x);
  199. } : f);
  200. };
  201. d3.shuffle = function(array, i0, i1) {
  202. if ((m = arguments.length) < 3) {
  203. i1 = array.length;
  204. if (m < 2) i0 = 0;
  205. }
  206. var m = i1 - i0, t, i;
  207. while (m) {
  208. i = Math.random() * m-- | 0;
  209. t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
  210. }
  211. return array;
  212. };
  213. d3.permute = function(array, indexes) {
  214. var i = indexes.length, permutes = new Array(i);
  215. while (i--) permutes[i] = array[indexes[i]];
  216. return permutes;
  217. };
  218. d3.pairs = function(array) {
  219. var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
  220. while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
  221. return pairs;
  222. };
  223. d3.transpose = function(matrix) {
  224. if (!(n = matrix.length)) return [];
  225. for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m; ) {
  226. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n; ) {
  227. row[j] = matrix[j][i];
  228. }
  229. }
  230. return transpose;
  231. };
  232. function d3_transposeLength(d) {
  233. return d.length;
  234. }
  235. d3.zip = function() {
  236. return d3.transpose(arguments);
  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_nsXhtml = "http://www.w3.org/1999/xhtml";
  624. var d3_nsPrefix = {
  625. svg: "http://www.w3.org/2000/svg",
  626. xhtml: d3_nsXhtml,
  627. xlink: "http://www.w3.org/1999/xlink",
  628. xml: "http://www.w3.org/XML/1998/namespace",
  629. xmlns: "http://www.w3.org/2000/xmlns/"
  630. };
  631. d3.ns = {
  632. prefix: d3_nsPrefix,
  633. qualify: function(name) {
  634. var i = name.indexOf(":"), prefix = name;
  635. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  636. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  637. space: d3_nsPrefix[prefix],
  638. local: name
  639. } : name;
  640. }
  641. };
  642. d3_selectionPrototype.attr = function(name, value) {
  643. if (arguments.length < 2) {
  644. if (typeof name === "string") {
  645. var node = this.node();
  646. name = d3.ns.qualify(name);
  647. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  648. }
  649. for (value in name) this.each(d3_selection_attr(value, name[value]));
  650. return this;
  651. }
  652. return this.each(d3_selection_attr(name, value));
  653. };
  654. function d3_selection_attr(name, value) {
  655. name = d3.ns.qualify(name);
  656. function attrNull() {
  657. this.removeAttribute(name);
  658. }
  659. function attrNullNS() {
  660. this.removeAttributeNS(name.space, name.local);
  661. }
  662. function attrConstant() {
  663. this.setAttribute(name, value);
  664. }
  665. function attrConstantNS() {
  666. this.setAttributeNS(name.space, name.local, value);
  667. }
  668. function attrFunction() {
  669. var x = value.apply(this, arguments);
  670. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  671. }
  672. function attrFunctionNS() {
  673. var x = value.apply(this, arguments);
  674. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  675. }
  676. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  677. }
  678. function d3_collapse(s) {
  679. return s.trim().replace(/\s+/g, " ");
  680. }
  681. d3_selectionPrototype.classed = function(name, value) {
  682. if (arguments.length < 2) {
  683. if (typeof name === "string") {
  684. var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
  685. if (value = node.classList) {
  686. while (++i < n) if (!value.contains(name[i])) return false;
  687. } else {
  688. value = node.getAttribute("class");
  689. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  690. }
  691. return true;
  692. }
  693. for (value in name) this.each(d3_selection_classed(value, name[value]));
  694. return this;
  695. }
  696. return this.each(d3_selection_classed(name, value));
  697. };
  698. function d3_selection_classedRe(name) {
  699. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  700. }
  701. function d3_selection_classes(name) {
  702. return (name + "").trim().split(/^|\s+/);
  703. }
  704. function d3_selection_classed(name, value) {
  705. name = d3_selection_classes(name).map(d3_selection_classedName);
  706. var n = name.length;
  707. function classedConstant() {
  708. var i = -1;
  709. while (++i < n) name[i](this, value);
  710. }
  711. function classedFunction() {
  712. var i = -1, x = value.apply(this, arguments);
  713. while (++i < n) name[i](this, x);
  714. }
  715. return typeof value === "function" ? classedFunction : classedConstant;
  716. }
  717. function d3_selection_classedName(name) {
  718. var re = d3_selection_classedRe(name);
  719. return function(node, value) {
  720. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  721. var c = node.getAttribute("class") || "";
  722. if (value) {
  723. re.lastIndex = 0;
  724. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  725. } else {
  726. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  727. }
  728. };
  729. }
  730. d3_selectionPrototype.style = function(name, value, priority) {
  731. var n = arguments.length;
  732. if (n < 3) {
  733. if (typeof name !== "string") {
  734. if (n < 2) value = "";
  735. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  736. return this;
  737. }
  738. if (n < 2) {
  739. var node = this.node();
  740. return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
  741. }
  742. priority = "";
  743. }
  744. return this.each(d3_selection_style(name, value, priority));
  745. };
  746. function d3_selection_style(name, value, priority) {
  747. function styleNull() {
  748. this.style.removeProperty(name);
  749. }
  750. function styleConstant() {
  751. this.style.setProperty(name, value, priority);
  752. }
  753. function styleFunction() {
  754. var x = value.apply(this, arguments);
  755. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  756. }
  757. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  758. }
  759. d3_selectionPrototype.property = function(name, value) {
  760. if (arguments.length < 2) {
  761. if (typeof name === "string") return this.node()[name];
  762. for (value in name) this.each(d3_selection_property(value, name[value]));
  763. return this;
  764. }
  765. return this.each(d3_selection_property(name, value));
  766. };
  767. function d3_selection_property(name, value) {
  768. function propertyNull() {
  769. delete this[name];
  770. }
  771. function propertyConstant() {
  772. this[name] = value;
  773. }
  774. function propertyFunction() {
  775. var x = value.apply(this, arguments);
  776. if (x == null) delete this[name]; else this[name] = x;
  777. }
  778. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  779. }
  780. d3_selectionPrototype.text = function(value) {
  781. return arguments.length ? this.each(typeof value === "function" ? function() {
  782. var v = value.apply(this, arguments);
  783. this.textContent = v == null ? "" : v;
  784. } : value == null ? function() {
  785. this.textContent = "";
  786. } : function() {
  787. this.textContent = value;
  788. }) : this.node().textContent;
  789. };
  790. d3_selectionPrototype.html = function(value) {
  791. return arguments.length ? this.each(typeof value === "function" ? function() {
  792. var v = value.apply(this, arguments);
  793. this.innerHTML = v == null ? "" : v;
  794. } : value == null ? function() {
  795. this.innerHTML = "";
  796. } : function() {
  797. this.innerHTML = value;
  798. }) : this.node().innerHTML;
  799. };
  800. d3_selectionPrototype.append = function(name) {
  801. name = d3_selection_creator(name);
  802. return this.select(function() {
  803. return this.appendChild(name.apply(this, arguments));
  804. });
  805. };
  806. function d3_selection_creator(name) {
  807. function create() {
  808. var document = this.ownerDocument, namespace = this.namespaceURI;
  809. return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
  810. }
  811. function createNS() {
  812. return this.ownerDocument.createElementNS(name.space, name.local);
  813. }
  814. return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
  815. }
  816. d3_selectionPrototype.insert = function(name, before) {
  817. name = d3_selection_creator(name);
  818. before = d3_selection_selector(before);
  819. return this.select(function() {
  820. return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
  821. });
  822. };
  823. d3_selectionPrototype.remove = function() {
  824. return this.each(d3_selectionRemove);
  825. };
  826. function d3_selectionRemove() {
  827. var parent = this.parentNode;
  828. if (parent) parent.removeChild(this);
  829. }
  830. d3_selectionPrototype.data = function(value, key) {
  831. var i = -1, n = this.length, group, node;
  832. if (!arguments.length) {
  833. value = new Array(n = (group = this[0]).length);
  834. while (++i < n) {
  835. if (node = group[i]) {
  836. value[i] = node.__data__;
  837. }
  838. }
  839. return value;
  840. }
  841. function bind(group, groupData) {
  842. 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;
  843. if (key) {
  844. var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
  845. for (i = -1; ++i < n; ) {
  846. if (node = group[i]) {
  847. if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
  848. exitNodes[i] = node;
  849. } else {
  850. nodeByKeyValue.set(keyValue, node);
  851. }
  852. keyValues[i] = keyValue;
  853. }
  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 (i in keyValues && 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 = d3_array(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.correspondingElement || d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
  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);
  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], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;
  1289. if (d2 < ε2) {
  1290. S = Math.log(w1 / w0) / ρ;
  1291. i = function(t) {
  1292. return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];
  1293. };
  1294. } else {
  1295. var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  1296. S = (r1 - r0) / ρ;
  1297. i = function(t) {
  1298. var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
  1299. return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
  1300. };
  1301. }
  1302. i.duration = S * 1e3;
  1303. return i;
  1304. };
  1305. d3.behavior.zoom = function() {
  1306. var view = {
  1307. x: 0,
  1308. y: 0,
  1309. k: 1
  1310. }, 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;
  1311. if (!d3_behavior_zoomWheel) {
  1312. d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1313. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  1314. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1315. return d3.event.wheelDelta;
  1316. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  1317. return -d3.event.detail;
  1318. }, "MozMousePixelScroll");
  1319. }
  1320. function zoom(g) {
  1321. g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
  1322. }
  1323. zoom.event = function(g) {
  1324. g.each(function() {
  1325. var dispatch = event.of(this, arguments), view1 = view;
  1326. if (d3_transitionInheritId) {
  1327. d3.select(this).transition().each("start.zoom", function() {
  1328. view = this.__chart__ || {
  1329. x: 0,
  1330. y: 0,
  1331. k: 1
  1332. };
  1333. zoomstarted(dispatch);
  1334. }).tween("zoom:zoom", function() {
  1335. 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 ]);
  1336. return function(t) {
  1337. var l = i(t), k = dx / l[2];
  1338. this.__chart__ = view = {
  1339. x: cx - l[0] * k,
  1340. y: cy - l[1] * k,
  1341. k: k
  1342. };
  1343. zoomed(dispatch);
  1344. };
  1345. }).each("interrupt.zoom", function() {
  1346. zoomended(dispatch);
  1347. }).each("end.zoom", function() {
  1348. zoomended(dispatch);
  1349. });
  1350. } else {
  1351. this.__chart__ = view;
  1352. zoomstarted(dispatch);
  1353. zoomed(dispatch);
  1354. zoomended(dispatch);
  1355. }
  1356. });
  1357. };
  1358. zoom.translate = function(_) {
  1359. if (!arguments.length) return [ view.x, view.y ];
  1360. view = {
  1361. x: +_[0],
  1362. y: +_[1],
  1363. k: view.k
  1364. };
  1365. rescale();
  1366. return zoom;
  1367. };
  1368. zoom.scale = function(_) {
  1369. if (!arguments.length) return view.k;
  1370. view = {
  1371. x: view.x,
  1372. y: view.y,
  1373. k: null
  1374. };
  1375. scaleTo(+_);
  1376. rescale();
  1377. return zoom;
  1378. };
  1379. zoom.scaleExtent = function(_) {
  1380. if (!arguments.length) return scaleExtent;
  1381. scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
  1382. return zoom;
  1383. };
  1384. zoom.center = function(_) {
  1385. if (!arguments.length) return center;
  1386. center = _ && [ +_[0], +_[1] ];
  1387. return zoom;
  1388. };
  1389. zoom.size = function(_) {
  1390. if (!arguments.length) return size;
  1391. size = _ && [ +_[0], +_[1] ];
  1392. return zoom;
  1393. };
  1394. zoom.duration = function(_) {
  1395. if (!arguments.length) return duration;
  1396. duration = +_;
  1397. return zoom;
  1398. };
  1399. zoom.x = function(z) {
  1400. if (!arguments.length) return x1;
  1401. x1 = z;
  1402. x0 = z.copy();
  1403. view = {
  1404. x: 0,
  1405. y: 0,
  1406. k: 1
  1407. };
  1408. return zoom;
  1409. };
  1410. zoom.y = function(z) {
  1411. if (!arguments.length) return y1;
  1412. y1 = z;
  1413. y0 = z.copy();
  1414. view = {
  1415. x: 0,
  1416. y: 0,
  1417. k: 1
  1418. };
  1419. return zoom;
  1420. };
  1421. function location(p) {
  1422. return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
  1423. }
  1424. function point(l) {
  1425. return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
  1426. }
  1427. function scaleTo(s) {
  1428. view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  1429. }
  1430. function translateTo(p, l) {
  1431. l = point(l);
  1432. view.x += p[0] - l[0];
  1433. view.y += p[1] - l[1];
  1434. }
  1435. function zoomTo(that, p, l, k) {
  1436. that.__chart__ = {
  1437. x: view.x,
  1438. y: view.y,
  1439. k: view.k
  1440. };
  1441. scaleTo(Math.pow(2, k));
  1442. translateTo(center0 = p, l);
  1443. that = d3.select(that);
  1444. if (duration > 0) that = that.transition().duration(duration);
  1445. that.call(zoom.event);
  1446. }
  1447. function rescale() {
  1448. if (x1) x1.domain(x0.range().map(function(x) {
  1449. return (x - view.x) / view.k;
  1450. }).map(x0.invert));
  1451. if (y1) y1.domain(y0.range().map(function(y) {
  1452. return (y - view.y) / view.k;
  1453. }).map(y0.invert));
  1454. }
  1455. function zoomstarted(dispatch) {
  1456. if (!zooming++) dispatch({
  1457. type: "zoomstart"
  1458. });
  1459. }
  1460. function zoomed(dispatch) {
  1461. rescale();
  1462. dispatch({
  1463. type: "zoom",
  1464. scale: view.k,
  1465. translate: [ view.x, view.y ]
  1466. });
  1467. }
  1468. function zoomended(dispatch) {
  1469. if (!--zooming) dispatch({
  1470. type: "zoomend"
  1471. }), center0 = null;
  1472. }
  1473. function mousedowned() {
  1474. var that = this, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
  1475. d3_selection_interrupt.call(that);
  1476. zoomstarted(dispatch);
  1477. function moved() {
  1478. dragged = 1;
  1479. translateTo(d3.mouse(that), location0);
  1480. zoomed(dispatch);
  1481. }
  1482. function ended() {
  1483. subject.on(mousemove, null).on(mouseup, null);
  1484. dragRestore(dragged);
  1485. zoomended(dispatch);
  1486. }
  1487. }
  1488. function touchstarted() {
  1489. 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);
  1490. started();
  1491. zoomstarted(dispatch);
  1492. subject.on(mousedown, null).on(touchstart, started);
  1493. function relocate() {
  1494. var touches = d3.touches(that);
  1495. scale0 = view.k;
  1496. touches.forEach(function(t) {
  1497. if (t.identifier in locations0) locations0[t.identifier] = location(t);
  1498. });
  1499. return touches;
  1500. }
  1501. function started() {
  1502. var target = d3.event.target;
  1503. d3.select(target).on(touchmove, moved).on(touchend, ended);
  1504. targets.push(target);
  1505. var changed = d3.event.changedTouches;
  1506. for (var i = 0, n = changed.length; i < n; ++i) {
  1507. locations0[changed[i].identifier] = null;
  1508. }
  1509. var touches = relocate(), now = Date.now();
  1510. if (touches.length === 1) {
  1511. if (now - touchtime < 500) {
  1512. var p = touches[0];
  1513. zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
  1514. d3_eventPreventDefault();
  1515. }
  1516. touchtime = now;
  1517. } else if (touches.length > 1) {
  1518. var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
  1519. distance0 = dx * dx + dy * dy;
  1520. }
  1521. }
  1522. function moved() {
  1523. var touches = d3.touches(that), p0, l0, p1, l1;
  1524. d3_selection_interrupt.call(that);
  1525. for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
  1526. p1 = touches[i];
  1527. if (l1 = locations0[p1.identifier]) {
  1528. if (l0) break;
  1529. p0 = p1, l0 = l1;
  1530. }
  1531. }
  1532. if (l1) {
  1533. var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
  1534. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  1535. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  1536. scaleTo(scale1 * scale0);
  1537. }
  1538. touchtime = null;
  1539. translateTo(p0, l0);
  1540. zoomed(dispatch);
  1541. }
  1542. function ended() {
  1543. if (d3.event.touches.length) {
  1544. var changed = d3.event.changedTouches;
  1545. for (var i = 0, n = changed.length; i < n; ++i) {
  1546. delete locations0[changed[i].identifier];
  1547. }
  1548. for (var identifier in locations0) {
  1549. return void relocate();
  1550. }
  1551. }
  1552. d3.selectAll(targets).on(zoomName, null);
  1553. subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
  1554. dragRestore();
  1555. zoomended(dispatch);
  1556. }
  1557. }
  1558. function mousewheeled() {
  1559. var dispatch = event.of(this, arguments);
  1560. if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
  1561. translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
  1562. mousewheelTimer = setTimeout(function() {
  1563. mousewheelTimer = null;
  1564. zoomended(dispatch);
  1565. }, 50);
  1566. d3_eventPreventDefault();
  1567. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
  1568. translateTo(center0, translate0);
  1569. zoomed(dispatch);
  1570. }
  1571. function dblclicked() {
  1572. var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
  1573. zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
  1574. }
  1575. return d3.rebind(zoom, event, "on");
  1576. };
  1577. var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
  1578. d3.color = d3_color;
  1579. function d3_color() {}
  1580. d3_color.prototype.toString = function() {
  1581. return this.rgb() + "";
  1582. };
  1583. d3.hsl = d3_hsl;
  1584. function d3_hsl(h, s, l) {
  1585. 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);
  1586. }
  1587. var d3_hslPrototype = d3_hsl.prototype = new d3_color();
  1588. d3_hslPrototype.brighter = function(k) {
  1589. k = Math.pow(.7, arguments.length ? k : 1);
  1590. return new d3_hsl(this.h, this.s, this.l / k);
  1591. };
  1592. d3_hslPrototype.darker = function(k) {
  1593. k = Math.pow(.7, arguments.length ? k : 1);
  1594. return new d3_hsl(this.h, this.s, k * this.l);
  1595. };
  1596. d3_hslPrototype.rgb = function() {
  1597. return d3_hsl_rgb(this.h, this.s, this.l);
  1598. };
  1599. function d3_hsl_rgb(h, s, l) {
  1600. var m1, m2;
  1601. h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
  1602. s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
  1603. l = l < 0 ? 0 : l > 1 ? 1 : l;
  1604. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  1605. m1 = 2 * l - m2;
  1606. function v(h) {
  1607. if (h > 360) h -= 360; else if (h < 0) h += 360;
  1608. if (h < 60) return m1 + (m2 - m1) * h / 60;
  1609. if (h < 180) return m2;
  1610. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  1611. return m1;
  1612. }
  1613. function vv(h) {
  1614. return Math.round(v(h) * 255);
  1615. }
  1616. return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  1617. }
  1618. d3.hcl = d3_hcl;
  1619. function d3_hcl(h, c, l) {
  1620. 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);
  1621. }
  1622. var d3_hclPrototype = d3_hcl.prototype = new d3_color();
  1623. d3_hclPrototype.brighter = function(k) {
  1624. return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  1625. };
  1626. d3_hclPrototype.darker = function(k) {
  1627. return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  1628. };
  1629. d3_hclPrototype.rgb = function() {
  1630. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  1631. };
  1632. function d3_hcl_lab(h, c, l) {
  1633. if (isNaN(h)) h = 0;
  1634. if (isNaN(c)) c = 0;
  1635. return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  1636. }
  1637. d3.lab = d3_lab;
  1638. function d3_lab(l, a, b) {
  1639. 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);
  1640. }
  1641. var d3_lab_K = 18;
  1642. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  1643. var d3_labPrototype = d3_lab.prototype = new d3_color();
  1644. d3_labPrototype.brighter = function(k) {
  1645. return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1646. };
  1647. d3_labPrototype.darker = function(k) {
  1648. return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1649. };
  1650. d3_labPrototype.rgb = function() {
  1651. return d3_lab_rgb(this.l, this.a, this.b);
  1652. };
  1653. function d3_lab_rgb(l, a, b) {
  1654. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  1655. x = d3_lab_xyz(x) * d3_lab_X;
  1656. y = d3_lab_xyz(y) * d3_lab_Y;
  1657. z = d3_lab_xyz(z) * d3_lab_Z;
  1658. 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));
  1659. }
  1660. function d3_lab_hcl(l, a, b) {
  1661. 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);
  1662. }
  1663. function d3_lab_xyz(x) {
  1664. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  1665. }
  1666. function d3_xyz_lab(x) {
  1667. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  1668. }
  1669. function d3_xyz_rgb(r) {
  1670. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  1671. }
  1672. d3.rgb = d3_rgb;
  1673. function d3_rgb(r, g, b) {
  1674. 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);
  1675. }
  1676. function d3_rgbNumber(value) {
  1677. return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
  1678. }
  1679. function d3_rgbString(value) {
  1680. return d3_rgbNumber(value) + "";
  1681. }
  1682. var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
  1683. d3_rgbPrototype.brighter = function(k) {
  1684. k = Math.pow(.7, arguments.length ? k : 1);
  1685. var r = this.r, g = this.g, b = this.b, i = 30;
  1686. if (!r && !g && !b) return new d3_rgb(i, i, i);
  1687. if (r && r < i) r = i;
  1688. if (g && g < i) g = i;
  1689. if (b && b < i) b = i;
  1690. return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
  1691. };
  1692. d3_rgbPrototype.darker = function(k) {
  1693. k = Math.pow(.7, arguments.length ? k : 1);
  1694. return new d3_rgb(k * this.r, k * this.g, k * this.b);
  1695. };
  1696. d3_rgbPrototype.hsl = function() {
  1697. return d3_rgb_hsl(this.r, this.g, this.b);
  1698. };
  1699. d3_rgbPrototype.toString = function() {
  1700. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  1701. };
  1702. function d3_rgb_hex(v) {
  1703. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  1704. }
  1705. function d3_rgb_parse(format, rgb, hsl) {
  1706. var r = 0, g = 0, b = 0, m1, m2, color;
  1707. m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
  1708. if (m1) {
  1709. m2 = m1[2].split(",");
  1710. switch (m1[1]) {
  1711. case "hsl":
  1712. {
  1713. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  1714. }
  1715. case "rgb":
  1716. {
  1717. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  1718. }
  1719. }
  1720. }
  1721. if (color = d3_rgb_names.get(format)) {
  1722. return rgb(color.r, color.g, color.b);
  1723. }
  1724. if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
  1725. if (format.length === 4) {
  1726. r = (color & 3840) >> 4;
  1727. r = r >> 4 | r;
  1728. g = color & 240;
  1729. g = g >> 4 | g;
  1730. b = color & 15;
  1731. b = b << 4 | b;
  1732. } else if (format.length === 7) {
  1733. r = (color & 16711680) >> 16;
  1734. g = (color & 65280) >> 8;
  1735. b = color & 255;
  1736. }
  1737. }
  1738. return rgb(r, g, b);
  1739. }
  1740. function d3_rgb_hsl(r, g, b) {
  1741. 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;
  1742. if (d) {
  1743. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  1744. 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;
  1745. h *= 60;
  1746. } else {
  1747. h = NaN;
  1748. s = l > 0 && l < 1 ? 0 : h;
  1749. }
  1750. return new d3_hsl(h, s, l);
  1751. }
  1752. function d3_rgb_lab(r, g, b) {
  1753. r = d3_rgb_xyz(r);
  1754. g = d3_rgb_xyz(g);
  1755. b = d3_rgb_xyz(b);
  1756. 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);
  1757. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  1758. }
  1759. function d3_rgb_xyz(r) {
  1760. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  1761. }
  1762. function d3_rgb_parseNumber(c) {
  1763. var f = parseFloat(c);
  1764. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  1765. }
  1766. var d3_rgb_names = d3.map({
  1767. aliceblue: 15792383,
  1768. antiquewhite: 16444375,
  1769. aqua: 65535,
  1770. aquamarine: 8388564,
  1771. azure: 15794175,
  1772. beige: 16119260,
  1773. bisque: 16770244,
  1774. black: 0,
  1775. blanchedalmond: 16772045,
  1776. blue: 255,
  1777. blueviolet: 9055202,
  1778. brown: 10824234,
  1779. burlywood: 14596231,
  1780. cadetblue: 6266528,
  1781. chartreuse: 8388352,
  1782. chocolate: 13789470,
  1783. coral: 16744272,
  1784. cornflowerblue: 6591981,
  1785. cornsilk: 16775388,
  1786. crimson: 14423100,
  1787. cyan: 65535,
  1788. darkblue: 139,
  1789. darkcyan: 35723,
  1790. darkgoldenrod: 12092939,
  1791. darkgray: 11119017,
  1792. darkgreen: 25600,
  1793. darkgrey: 11119017,
  1794. darkkhaki: 12433259,
  1795. darkmagenta: 9109643,
  1796. darkolivegreen: 5597999,
  1797. darkorange: 16747520,
  1798. darkorchid: 10040012,
  1799. darkred: 9109504,
  1800. darksalmon: 15308410,
  1801. darkseagreen: 9419919,
  1802. darkslateblue: 4734347,
  1803. darkslategray: 3100495,
  1804. darkslategrey: 3100495,
  1805. darkturquoise: 52945,
  1806. darkviolet: 9699539,
  1807. deeppink: 16716947,
  1808. deepskyblue: 49151,
  1809. dimgray: 6908265,
  1810. dimgrey: 6908265,
  1811. dodgerblue: 2003199,
  1812. firebrick: 11674146,
  1813. floralwhite: 16775920,
  1814. forestgreen: 2263842,
  1815. fuchsia: 16711935,
  1816. gainsboro: 14474460,
  1817. ghostwhite: 16316671,
  1818. gold: 16766720,
  1819. goldenrod: 14329120,
  1820. gray: 8421504,
  1821. green: 32768,
  1822. greenyellow: 11403055,
  1823. grey: 8421504,
  1824. honeydew: 15794160,
  1825. hotpink: 16738740,
  1826. indianred: 13458524,
  1827. indigo: 4915330,
  1828. ivory: 16777200,
  1829. khaki: 15787660,
  1830. lavender: 15132410,
  1831. lavenderblush: 16773365,
  1832. lawngreen: 8190976,
  1833. lemonchiffon: 16775885,
  1834. lightblue: 11393254,
  1835. lightcoral: 15761536,
  1836. lightcyan: 14745599,
  1837. lightgoldenrodyellow: 16448210,
  1838. lightgray: 13882323,
  1839. lightgreen: 9498256,
  1840. lightgrey: 13882323,
  1841. lightpink: 16758465,
  1842. lightsalmon: 16752762,
  1843. lightseagreen: 2142890,
  1844. lightskyblue: 8900346,
  1845. lightslategray: 7833753,
  1846. lightslategrey: 7833753,
  1847. lightsteelblue: 11584734,
  1848. lightyellow: 16777184,
  1849. lime: 65280,
  1850. limegreen: 3329330,
  1851. linen: 16445670,
  1852. magenta: 16711935,
  1853. maroon: 8388608,
  1854. mediumaquamarine: 6737322,
  1855. mediumblue: 205,
  1856. mediumorchid: 12211667,
  1857. mediumpurple: 9662683,
  1858. mediumseagreen: 3978097,
  1859. mediumslateblue: 8087790,
  1860. mediumspringgreen: 64154,
  1861. mediumturquoise: 4772300,
  1862. mediumvioletred: 13047173,
  1863. midnightblue: 1644912,
  1864. mintcream: 16121850,
  1865. mistyrose: 16770273,
  1866. moccasin: 16770229,
  1867. navajowhite: 16768685,
  1868. navy: 128,
  1869. oldlace: 16643558,
  1870. olive: 8421376,
  1871. olivedrab: 7048739,
  1872. orange: 16753920,
  1873. orangered: 16729344,
  1874. orchid: 14315734,
  1875. palegoldenrod: 15657130,
  1876. palegreen: 10025880,
  1877. paleturquoise: 11529966,
  1878. palevioletred: 14381203,
  1879. papayawhip: 16773077,
  1880. peachpuff: 16767673,
  1881. peru: 13468991,
  1882. pink: 16761035,
  1883. plum: 14524637,
  1884. powderblue: 11591910,
  1885. purple: 8388736,
  1886. rebeccapurple: 6697881,
  1887. red: 16711680,
  1888. rosybrown: 12357519,
  1889. royalblue: 4286945,
  1890. saddlebrown: 9127187,
  1891. salmon: 16416882,
  1892. sandybrown: 16032864,
  1893. seagreen: 3050327,
  1894. seashell: 16774638,
  1895. sienna: 10506797,
  1896. silver: 12632256,
  1897. skyblue: 8900331,
  1898. slateblue: 6970061,
  1899. slategray: 7372944,
  1900. slategrey: 7372944,
  1901. snow: 16775930,
  1902. springgreen: 65407,
  1903. steelblue: 4620980,
  1904. tan: 13808780,
  1905. teal: 32896,
  1906. thistle: 14204888,
  1907. tomato: 16737095,
  1908. turquoise: 4251856,
  1909. violet: 15631086,
  1910. wheat: 16113331,
  1911. white: 16777215,
  1912. whitesmoke: 16119285,
  1913. yellow: 16776960,
  1914. yellowgreen: 10145074
  1915. });
  1916. d3_rgb_names.forEach(function(key, value) {
  1917. d3_rgb_names.set(key, d3_rgbNumber(value));
  1918. });
  1919. function d3_functor(v) {
  1920. return typeof v === "function" ? v : function() {
  1921. return v;
  1922. };
  1923. }
  1924. d3.functor = d3_functor;
  1925. d3.xhr = d3_xhrType(d3_identity);
  1926. function d3_xhrType(response) {
  1927. return function(url, mimeType, callback) {
  1928. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  1929. mimeType = null;
  1930. return d3_xhr(url, mimeType, response, callback);
  1931. };
  1932. }
  1933. function d3_xhr(url, mimeType, response, callback) {
  1934. var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
  1935. if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
  1936. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  1937. request.readyState > 3 && respond();
  1938. };
  1939. function respond() {
  1940. var status = request.status, result;
  1941. if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
  1942. try {
  1943. result = response.call(xhr, request);
  1944. } catch (e) {
  1945. dispatch.error.call(xhr, e);
  1946. return;
  1947. }
  1948. dispatch.load.call(xhr, result);
  1949. } else {
  1950. dispatch.error.call(xhr, request);
  1951. }
  1952. }
  1953. request.onprogress = function(event) {
  1954. var o = d3.event;
  1955. d3.event = event;
  1956. try {
  1957. dispatch.progress.call(xhr, request);
  1958. } finally {
  1959. d3.event = o;
  1960. }
  1961. };
  1962. xhr.header = function(name, value) {
  1963. name = (name + "").toLowerCase();
  1964. if (arguments.length < 2) return headers[name];
  1965. if (value == null) delete headers[name]; else headers[name] = value + "";
  1966. return xhr;
  1967. };
  1968. xhr.mimeType = function(value) {
  1969. if (!arguments.length) return mimeType;
  1970. mimeType = value == null ? null : value + "";
  1971. return xhr;
  1972. };
  1973. xhr.responseType = function(value) {
  1974. if (!arguments.length) return responseType;
  1975. responseType = value;
  1976. return xhr;
  1977. };
  1978. xhr.response = function(value) {
  1979. response = value;
  1980. return xhr;
  1981. };
  1982. [ "get", "post" ].forEach(function(method) {
  1983. xhr[method] = function() {
  1984. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  1985. };
  1986. });
  1987. xhr.send = function(method, data, callback) {
  1988. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  1989. request.open(method, url, true);
  1990. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  1991. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  1992. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  1993. if (responseType != null) request.responseType = responseType;
  1994. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  1995. callback(null, request);
  1996. });
  1997. dispatch.beforesend.call(xhr, request);
  1998. request.send(data == null ? null : data);
  1999. return xhr;
  2000. };
  2001. xhr.abort = function() {
  2002. request.abort();
  2003. return xhr;
  2004. };
  2005. d3.rebind(xhr, dispatch, "on");
  2006. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  2007. }
  2008. function d3_xhr_fixCallback(callback) {
  2009. return callback.length === 1 ? function(error, request) {
  2010. callback(error == null ? request : null);
  2011. } : callback;
  2012. }
  2013. function d3_xhrHasResponse(request) {
  2014. var type = request.responseType;
  2015. return type && type !== "text" ? request.response : request.responseText;
  2016. }
  2017. d3.dsv = function(delimiter, mimeType) {
  2018. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  2019. function dsv(url, row, callback) {
  2020. if (arguments.length < 3) callback = row, row = null;
  2021. var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
  2022. xhr.row = function(_) {
  2023. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  2024. };
  2025. return xhr;
  2026. }
  2027. function response(request) {
  2028. return dsv.parse(request.responseText);
  2029. }
  2030. function typedResponse(f) {
  2031. return function(request) {
  2032. return dsv.parse(request.responseText, f);
  2033. };
  2034. }
  2035. dsv.parse = function(text, f) {
  2036. var o;
  2037. return dsv.parseRows(text, function(row, i) {
  2038. if (o) return o(row, i - 1);
  2039. var a = new Function("d", "return {" + row.map(function(name, i) {
  2040. return JSON.stringify(name) + ": d[" + i + "]";
  2041. }).join(",") + "}");
  2042. o = f ? function(row, i) {
  2043. return f(a(row), i);
  2044. } : a;
  2045. });
  2046. };
  2047. dsv.parseRows = function(text, f) {
  2048. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  2049. function token() {
  2050. if (I >= N) return EOF;
  2051. if (eol) return eol = false, EOL;
  2052. var j = I;
  2053. if (text.charCodeAt(j) === 34) {
  2054. var i = j;
  2055. while (i++ < N) {
  2056. if (text.charCodeAt(i) === 34) {
  2057. if (text.charCodeAt(i + 1) !== 34) break;
  2058. ++i;
  2059. }
  2060. }
  2061. I = i + 2;
  2062. var c = text.charCodeAt(i + 1);
  2063. if (c === 13) {
  2064. eol = true;
  2065. if (text.charCodeAt(i + 2) === 10) ++I;
  2066. } else if (c === 10) {
  2067. eol = true;
  2068. }
  2069. return text.slice(j + 1, i).replace(/""/g, '"');
  2070. }
  2071. while (I < N) {
  2072. var c = text.charCodeAt(I++), k = 1;
  2073. if (c === 10) eol = true; else if (c === 13) {
  2074. eol = true;
  2075. if (text.charCodeAt(I) === 10) ++I, ++k;
  2076. } else if (c !== delimiterCode) continue;
  2077. return text.slice(j, I - k);
  2078. }
  2079. return text.slice(j);
  2080. }
  2081. while ((t = token()) !== EOF) {
  2082. var a = [];
  2083. while (t !== EOL && t !== EOF) {
  2084. a.push(t);
  2085. t = token();
  2086. }
  2087. if (f && (a = f(a, n++)) == null) continue;
  2088. rows.push(a);
  2089. }
  2090. return rows;
  2091. };
  2092. dsv.format = function(rows) {
  2093. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  2094. var fieldSet = new d3_Set(), fields = [];
  2095. rows.forEach(function(row) {
  2096. for (var field in row) {
  2097. if (!fieldSet.has(field)) {
  2098. fields.push(fieldSet.add(field));
  2099. }
  2100. }
  2101. });
  2102. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  2103. return fields.map(function(field) {
  2104. return formatValue(row[field]);
  2105. }).join(delimiter);
  2106. })).join("\n");
  2107. };
  2108. dsv.formatRows = function(rows) {
  2109. return rows.map(formatRow).join("\n");
  2110. };
  2111. function formatRow(row) {
  2112. return row.map(formatValue).join(delimiter);
  2113. }
  2114. function formatValue(text) {
  2115. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  2116. }
  2117. return dsv;
  2118. };
  2119. d3.csv = d3.dsv(",", "text/csv");
  2120. d3.tsv = d3.dsv(" ", "text/tab-separated-values");
  2121. var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
  2122. setTimeout(callback, 17);
  2123. };
  2124. d3.timer = function() {
  2125. d3_timer.apply(this, arguments);
  2126. };
  2127. function d3_timer(callback, delay, then) {
  2128. var n = arguments.length;
  2129. if (n < 2) delay = 0;
  2130. if (n < 3) then = Date.now();
  2131. var time = then + delay, timer = {
  2132. c: callback,
  2133. t: time,
  2134. n: null
  2135. };
  2136. if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
  2137. d3_timer_queueTail = timer;
  2138. if (!d3_timer_interval) {
  2139. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  2140. d3_timer_interval = 1;
  2141. d3_timer_frame(d3_timer_step);
  2142. }
  2143. return timer;
  2144. }
  2145. function d3_timer_step() {
  2146. var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
  2147. if (delay > 24) {
  2148. if (isFinite(delay)) {
  2149. clearTimeout(d3_timer_timeout);
  2150. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  2151. }
  2152. d3_timer_interval = 0;
  2153. } else {
  2154. d3_timer_interval = 1;
  2155. d3_timer_frame(d3_timer_step);
  2156. }
  2157. }
  2158. d3.timer.flush = function() {
  2159. d3_timer_mark();
  2160. d3_timer_sweep();
  2161. };
  2162. function d3_timer_mark() {
  2163. var now = Date.now(), timer = d3_timer_queueHead;
  2164. while (timer) {
  2165. if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
  2166. timer = timer.n;
  2167. }
  2168. return now;
  2169. }
  2170. function d3_timer_sweep() {
  2171. var t0, t1 = d3_timer_queueHead, time = Infinity;
  2172. while (t1) {
  2173. if (t1.c) {
  2174. if (t1.t < time) time = t1.t;
  2175. t1 = (t0 = t1).n;
  2176. } else {
  2177. t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
  2178. }
  2179. }
  2180. d3_timer_queueTail = t0;
  2181. return time;
  2182. }
  2183. function d3_format_precision(x, p) {
  2184. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  2185. }
  2186. d3.round = function(x, n) {
  2187. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  2188. };
  2189. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  2190. d3.formatPrefix = function(value, precision) {
  2191. var i = 0;
  2192. if (value = +value) {
  2193. if (value < 0) value *= -1;
  2194. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  2195. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  2196. i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
  2197. }
  2198. return d3_formatPrefixes[8 + i / 3];
  2199. };
  2200. function d3_formatPrefix(d, i) {
  2201. var k = Math.pow(10, abs(8 - i) * 3);
  2202. return {
  2203. scale: i > 8 ? function(d) {
  2204. return d / k;
  2205. } : function(d) {
  2206. return d * k;
  2207. },
  2208. symbol: d
  2209. };
  2210. }
  2211. function d3_locale_numberFormat(locale) {
  2212. 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) {
  2213. var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
  2214. while (i > 0 && g > 0) {
  2215. if (length + g + 1 > width) g = Math.max(1, width - length);
  2216. t.push(value.substring(i -= g, i + g));
  2217. if ((length += g + 1) > width) break;
  2218. g = locale_grouping[j = (j + 1) % locale_grouping.length];
  2219. }
  2220. return t.reverse().join(locale_thousands);
  2221. } : d3_identity;
  2222. return function(specifier) {
  2223. 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;
  2224. if (precision) precision = +precision.substring(1);
  2225. if (zfill || fill === "0" && align === "=") {
  2226. zfill = fill = "0";
  2227. align = "=";
  2228. }
  2229. switch (type) {
  2230. case "n":
  2231. comma = true;
  2232. type = "g";
  2233. break;
  2234. case "%":
  2235. scale = 100;
  2236. suffix = "%";
  2237. type = "f";
  2238. break;
  2239. case "p":
  2240. scale = 100;
  2241. suffix = "%";
  2242. type = "r";
  2243. break;
  2244. case "b":
  2245. case "o":
  2246. case "x":
  2247. case "X":
  2248. if (symbol === "#") prefix = "0" + type.toLowerCase();
  2249. case "c":
  2250. exponent = false;
  2251. case "d":
  2252. integer = true;
  2253. precision = 0;
  2254. break;
  2255. case "s":
  2256. scale = -1;
  2257. type = "r";
  2258. break;
  2259. }
  2260. if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
  2261. if (type == "r" && !precision) type = "g";
  2262. if (precision != null) {
  2263. 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));
  2264. }
  2265. type = d3_format_types.get(type) || d3_format_typeDefault;
  2266. var zcomma = zfill && comma;
  2267. return function(value) {
  2268. var fullSuffix = suffix;
  2269. if (integer && value % 1) return "";
  2270. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
  2271. if (scale < 0) {
  2272. var unit = d3.formatPrefix(value, precision);
  2273. value = unit.scale(value);
  2274. fullSuffix = unit.symbol + suffix;
  2275. } else {
  2276. value *= scale;
  2277. }
  2278. value = type(value, precision);
  2279. var i = value.lastIndexOf("."), before, after;
  2280. if (i < 0) {
  2281. var j = exponent ? value.lastIndexOf("e") : -1;
  2282. if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
  2283. } else {
  2284. before = value.substring(0, i);
  2285. after = locale_decimal + value.substring(i + 1);
  2286. }
  2287. if (!zfill && comma) before = formatGroup(before, Infinity);
  2288. var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  2289. if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
  2290. negative += prefix;
  2291. value = before + after;
  2292. 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;
  2293. };
  2294. };
  2295. }
  2296. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  2297. var d3_format_types = d3.map({
  2298. b: function(x) {
  2299. return x.toString(2);
  2300. },
  2301. c: function(x) {
  2302. return String.fromCharCode(x);
  2303. },
  2304. o: function(x) {
  2305. return x.toString(8);
  2306. },
  2307. x: function(x) {
  2308. return x.toString(16);
  2309. },
  2310. X: function(x) {
  2311. return x.toString(16).toUpperCase();
  2312. },
  2313. g: function(x, p) {
  2314. return x.toPrecision(p);
  2315. },
  2316. e: function(x, p) {
  2317. return x.toExponential(p);
  2318. },
  2319. f: function(x, p) {
  2320. return x.toFixed(p);
  2321. },
  2322. r: function(x, p) {
  2323. 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))));
  2324. }
  2325. });
  2326. function d3_format_typeDefault(x) {
  2327. return x + "";
  2328. }
  2329. var d3_time = d3.time = {}, d3_date = Date;
  2330. function d3_date_utc() {
  2331. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  2332. }
  2333. d3_date_utc.prototype = {
  2334. getDate: function() {
  2335. return this._.getUTCDate();
  2336. },
  2337. getDay: function() {
  2338. return this._.getUTCDay();
  2339. },
  2340. getFullYear: function() {
  2341. return this._.getUTCFullYear();
  2342. },
  2343. getHours: function() {
  2344. return this._.getUTCHours();
  2345. },
  2346. getMilliseconds: function() {
  2347. return this._.getUTCMilliseconds();
  2348. },
  2349. getMinutes: function() {
  2350. return this._.getUTCMinutes();
  2351. },
  2352. getMonth: function() {
  2353. return this._.getUTCMonth();
  2354. },
  2355. getSeconds: function() {
  2356. return this._.getUTCSeconds();
  2357. },
  2358. getTime: function() {
  2359. return this._.getTime();
  2360. },
  2361. getTimezoneOffset: function() {
  2362. return 0;
  2363. },
  2364. valueOf: function() {
  2365. return this._.valueOf();
  2366. },
  2367. setDate: function() {
  2368. d3_time_prototype.setUTCDate.apply(this._, arguments);
  2369. },
  2370. setDay: function() {
  2371. d3_time_prototype.setUTCDay.apply(this._, arguments);
  2372. },
  2373. setFullYear: function() {
  2374. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  2375. },
  2376. setHours: function() {
  2377. d3_time_prototype.setUTCHours.apply(this._, arguments);
  2378. },
  2379. setMilliseconds: function() {
  2380. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  2381. },
  2382. setMinutes: function() {
  2383. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  2384. },
  2385. setMonth: function() {
  2386. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  2387. },
  2388. setSeconds: function() {
  2389. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  2390. },
  2391. setTime: function() {
  2392. d3_time_prototype.setTime.apply(this._, arguments);
  2393. }
  2394. };
  2395. var d3_time_prototype = Date.prototype;
  2396. function d3_time_interval(local, step, number) {
  2397. function round(date) {
  2398. var d0 = local(date), d1 = offset(d0, 1);
  2399. return date - d0 < d1 - date ? d0 : d1;
  2400. }
  2401. function ceil(date) {
  2402. step(date = local(new d3_date(date - 1)), 1);
  2403. return date;
  2404. }
  2405. function offset(date, k) {
  2406. step(date = new d3_date(+date), k);
  2407. return date;
  2408. }
  2409. function range(t0, t1, dt) {
  2410. var time = ceil(t0), times = [];
  2411. if (dt > 1) {
  2412. while (time < t1) {
  2413. if (!(number(time) % dt)) times.push(new Date(+time));
  2414. step(time, 1);
  2415. }
  2416. } else {
  2417. while (time < t1) times.push(new Date(+time)), step(time, 1);
  2418. }
  2419. return times;
  2420. }
  2421. function range_utc(t0, t1, dt) {
  2422. try {
  2423. d3_date = d3_date_utc;
  2424. var utc = new d3_date_utc();
  2425. utc._ = t0;
  2426. return range(utc, t1, dt);
  2427. } finally {
  2428. d3_date = Date;
  2429. }
  2430. }
  2431. local.floor = local;
  2432. local.round = round;
  2433. local.ceil = ceil;
  2434. local.offset = offset;
  2435. local.range = range;
  2436. var utc = local.utc = d3_time_interval_utc(local);
  2437. utc.floor = utc;
  2438. utc.round = d3_time_interval_utc(round);
  2439. utc.ceil = d3_time_interval_utc(ceil);
  2440. utc.offset = d3_time_interval_utc(offset);
  2441. utc.range = range_utc;
  2442. return local;
  2443. }
  2444. function d3_time_interval_utc(method) {
  2445. return function(date, k) {
  2446. try {
  2447. d3_date = d3_date_utc;
  2448. var utc = new d3_date_utc();
  2449. utc._ = date;
  2450. return method(utc, k)._;
  2451. } finally {
  2452. d3_date = Date;
  2453. }
  2454. };
  2455. }
  2456. d3_time.year = d3_time_interval(function(date) {
  2457. date = d3_time.day(date);
  2458. date.setMonth(0, 1);
  2459. return date;
  2460. }, function(date, offset) {
  2461. date.setFullYear(date.getFullYear() + offset);
  2462. }, function(date) {
  2463. return date.getFullYear();
  2464. });
  2465. d3_time.years = d3_time.year.range;
  2466. d3_time.years.utc = d3_time.year.utc.range;
  2467. d3_time.day = d3_time_interval(function(date) {
  2468. var day = new d3_date(2e3, 0);
  2469. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  2470. return day;
  2471. }, function(date, offset) {
  2472. date.setDate(date.getDate() + offset);
  2473. }, function(date) {
  2474. return date.getDate() - 1;
  2475. });
  2476. d3_time.days = d3_time.day.range;
  2477. d3_time.days.utc = d3_time.day.utc.range;
  2478. d3_time.dayOfYear = function(date) {
  2479. var year = d3_time.year(date);
  2480. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  2481. };
  2482. [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
  2483. i = 7 - i;
  2484. var interval = d3_time[day] = d3_time_interval(function(date) {
  2485. (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  2486. return date;
  2487. }, function(date, offset) {
  2488. date.setDate(date.getDate() + Math.floor(offset) * 7);
  2489. }, function(date) {
  2490. var day = d3_time.year(date).getDay();
  2491. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  2492. });
  2493. d3_time[day + "s"] = interval.range;
  2494. d3_time[day + "s"].utc = interval.utc.range;
  2495. d3_time[day + "OfYear"] = function(date) {
  2496. var day = d3_time.year(date).getDay();
  2497. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
  2498. };
  2499. });
  2500. d3_time.week = d3_time.sunday;
  2501. d3_time.weeks = d3_time.sunday.range;
  2502. d3_time.weeks.utc = d3_time.sunday.utc.range;
  2503. d3_time.weekOfYear = d3_time.sundayOfYear;
  2504. function d3_locale_timeFormat(locale) {
  2505. 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;
  2506. function d3_time_format(template) {
  2507. var n = template.length;
  2508. function format(date) {
  2509. var string = [], i = -1, j = 0, c, p, f;
  2510. while (++i < n) {
  2511. if (template.charCodeAt(i) === 37) {
  2512. string.push(template.slice(j, i));
  2513. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  2514. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  2515. string.push(c);
  2516. j = i + 1;
  2517. }
  2518. }
  2519. string.push(template.slice(j, i));
  2520. return string.join("");
  2521. }
  2522. format.parse = function(string) {
  2523. var d = {
  2524. y: 1900,
  2525. m: 0,
  2526. d: 1,
  2527. H: 0,
  2528. M: 0,
  2529. S: 0,
  2530. L: 0,
  2531. Z: null
  2532. }, i = d3_time_parse(d, template, string, 0);
  2533. if (i != string.length) return null;
  2534. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  2535. var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
  2536. if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) {
  2537. if (!("w" in d)) d.w = "W" in d ? 1 : 0;
  2538. date.setFullYear(d.y, 0, 1);
  2539. 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);
  2540. } else date.setFullYear(d.y, d.m, d.d);
  2541. date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
  2542. return localZ ? date._ : date;
  2543. };
  2544. format.toString = function() {
  2545. return template;
  2546. };
  2547. return format;
  2548. }
  2549. function d3_time_parse(date, template, string, j) {
  2550. var c, p, t, i = 0, n = template.length, m = string.length;
  2551. while (i < n) {
  2552. if (j >= m) return -1;
  2553. c = template.charCodeAt(i++);
  2554. if (c === 37) {
  2555. t = template.charAt(i++);
  2556. p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
  2557. if (!p || (j = p(date, string, j)) < 0) return -1;
  2558. } else if (c != string.charCodeAt(j++)) {
  2559. return -1;
  2560. }
  2561. }
  2562. return j;
  2563. }
  2564. d3_time_format.utc = function(template) {
  2565. var local = d3_time_format(template);
  2566. function format(date) {
  2567. try {
  2568. d3_date = d3_date_utc;
  2569. var utc = new d3_date();
  2570. utc._ = date;
  2571. return local(utc);
  2572. } finally {
  2573. d3_date = Date;
  2574. }
  2575. }
  2576. format.parse = function(string) {
  2577. try {
  2578. d3_date = d3_date_utc;
  2579. var date = local.parse(string);
  2580. return date && date._;
  2581. } finally {
  2582. d3_date = Date;
  2583. }
  2584. };
  2585. format.toString = local.toString;
  2586. return format;
  2587. };
  2588. d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
  2589. 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);
  2590. locale_periods.forEach(function(p, i) {
  2591. d3_time_periodLookup.set(p.toLowerCase(), i);
  2592. });
  2593. var d3_time_formats = {
  2594. a: function(d) {
  2595. return locale_shortDays[d.getDay()];
  2596. },
  2597. A: function(d) {
  2598. return locale_days[d.getDay()];
  2599. },
  2600. b: function(d) {
  2601. return locale_shortMonths[d.getMonth()];
  2602. },
  2603. B: function(d) {
  2604. return locale_months[d.getMonth()];
  2605. },
  2606. c: d3_time_format(locale_dateTime),
  2607. d: function(d, p) {
  2608. return d3_time_formatPad(d.getDate(), p, 2);
  2609. },
  2610. e: function(d, p) {
  2611. return d3_time_formatPad(d.getDate(), p, 2);
  2612. },
  2613. H: function(d, p) {
  2614. return d3_time_formatPad(d.getHours(), p, 2);
  2615. },
  2616. I: function(d, p) {
  2617. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  2618. },
  2619. j: function(d, p) {
  2620. return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
  2621. },
  2622. L: function(d, p) {
  2623. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  2624. },
  2625. m: function(d, p) {
  2626. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  2627. },
  2628. M: function(d, p) {
  2629. return d3_time_formatPad(d.getMinutes(), p, 2);
  2630. },
  2631. p: function(d) {
  2632. return locale_periods[+(d.getHours() >= 12)];
  2633. },
  2634. S: function(d, p) {
  2635. return d3_time_formatPad(d.getSeconds(), p, 2);
  2636. },
  2637. U: function(d, p) {
  2638. return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
  2639. },
  2640. w: function(d) {
  2641. return d.getDay();
  2642. },
  2643. W: function(d, p) {
  2644. return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
  2645. },
  2646. x: d3_time_format(locale_date),
  2647. X: d3_time_format(locale_time),
  2648. y: function(d, p) {
  2649. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  2650. },
  2651. Y: function(d, p) {
  2652. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  2653. },
  2654. Z: d3_time_zone,
  2655. "%": function() {
  2656. return "%";
  2657. }
  2658. };
  2659. var d3_time_parsers = {
  2660. a: d3_time_parseWeekdayAbbrev,
  2661. A: d3_time_parseWeekday,
  2662. b: d3_time_parseMonthAbbrev,
  2663. B: d3_time_parseMonth,
  2664. c: d3_time_parseLocaleFull,
  2665. d: d3_time_parseDay,
  2666. e: d3_time_parseDay,
  2667. H: d3_time_parseHour24,
  2668. I: d3_time_parseHour24,
  2669. j: d3_time_parseDayOfYear,
  2670. L: d3_time_parseMilliseconds,
  2671. m: d3_time_parseMonthNumber,
  2672. M: d3_time_parseMinutes,
  2673. p: d3_time_parseAmPm,
  2674. S: d3_time_parseSeconds,
  2675. U: d3_time_parseWeekNumberSunday,
  2676. w: d3_time_parseWeekdayNumber,
  2677. W: d3_time_parseWeekNumberMonday,
  2678. x: d3_time_parseLocaleDate,
  2679. X: d3_time_parseLocaleTime,
  2680. y: d3_time_parseYear,
  2681. Y: d3_time_parseFullYear,
  2682. Z: d3_time_parseZone,
  2683. "%": d3_time_parseLiteralPercent
  2684. };
  2685. function d3_time_parseWeekdayAbbrev(date, string, i) {
  2686. d3_time_dayAbbrevRe.lastIndex = 0;
  2687. var n = d3_time_dayAbbrevRe.exec(string.slice(i));
  2688. return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2689. }
  2690. function d3_time_parseWeekday(date, string, i) {
  2691. d3_time_dayRe.lastIndex = 0;
  2692. var n = d3_time_dayRe.exec(string.slice(i));
  2693. return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2694. }
  2695. function d3_time_parseMonthAbbrev(date, string, i) {
  2696. d3_time_monthAbbrevRe.lastIndex = 0;
  2697. var n = d3_time_monthAbbrevRe.exec(string.slice(i));
  2698. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2699. }
  2700. function d3_time_parseMonth(date, string, i) {
  2701. d3_time_monthRe.lastIndex = 0;
  2702. var n = d3_time_monthRe.exec(string.slice(i));
  2703. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2704. }
  2705. function d3_time_parseLocaleFull(date, string, i) {
  2706. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  2707. }
  2708. function d3_time_parseLocaleDate(date, string, i) {
  2709. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  2710. }
  2711. function d3_time_parseLocaleTime(date, string, i) {
  2712. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  2713. }
  2714. function d3_time_parseAmPm(date, string, i) {
  2715. var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
  2716. return n == null ? -1 : (date.p = n, i);
  2717. }
  2718. return d3_time_format;
  2719. }
  2720. var d3_time_formatPads = {
  2721. "-": "",
  2722. _: " ",
  2723. "0": "0"
  2724. }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
  2725. function d3_time_formatPad(value, fill, width) {
  2726. var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
  2727. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  2728. }
  2729. function d3_time_formatRe(names) {
  2730. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  2731. }
  2732. function d3_time_formatLookup(names) {
  2733. var map = new d3_Map(), i = -1, n = names.length;
  2734. while (++i < n) map.set(names[i].toLowerCase(), i);
  2735. return map;
  2736. }
  2737. function d3_time_parseWeekdayNumber(date, string, i) {
  2738. d3_time_numberRe.lastIndex = 0;
  2739. var n = d3_time_numberRe.exec(string.slice(i, i + 1));
  2740. return n ? (date.w = +n[0], i + n[0].length) : -1;
  2741. }
  2742. function d3_time_parseWeekNumberSunday(date, string, i) {
  2743. d3_time_numberRe.lastIndex = 0;
  2744. var n = d3_time_numberRe.exec(string.slice(i));
  2745. return n ? (date.U = +n[0], i + n[0].length) : -1;
  2746. }
  2747. function d3_time_parseWeekNumberMonday(date, string, i) {
  2748. d3_time_numberRe.lastIndex = 0;
  2749. var n = d3_time_numberRe.exec(string.slice(i));
  2750. return n ? (date.W = +n[0], i + n[0].length) : -1;
  2751. }
  2752. function d3_time_parseFullYear(date, string, i) {
  2753. d3_time_numberRe.lastIndex = 0;
  2754. var n = d3_time_numberRe.exec(string.slice(i, i + 4));
  2755. return n ? (date.y = +n[0], i + n[0].length) : -1;
  2756. }
  2757. function d3_time_parseYear(date, string, i) {
  2758. d3_time_numberRe.lastIndex = 0;
  2759. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2760. return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
  2761. }
  2762. function d3_time_parseZone(date, string, i) {
  2763. return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
  2764. i + 5) : -1;
  2765. }
  2766. function d3_time_expandYear(d) {
  2767. return d + (d > 68 ? 1900 : 2e3);
  2768. }
  2769. function d3_time_parseMonthNumber(date, string, i) {
  2770. d3_time_numberRe.lastIndex = 0;
  2771. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2772. return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
  2773. }
  2774. function d3_time_parseDay(date, string, i) {
  2775. d3_time_numberRe.lastIndex = 0;
  2776. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2777. return n ? (date.d = +n[0], i + n[0].length) : -1;
  2778. }
  2779. function d3_time_parseDayOfYear(date, string, i) {
  2780. d3_time_numberRe.lastIndex = 0;
  2781. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2782. return n ? (date.j = +n[0], i + n[0].length) : -1;
  2783. }
  2784. function d3_time_parseHour24(date, string, i) {
  2785. d3_time_numberRe.lastIndex = 0;
  2786. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2787. return n ? (date.H = +n[0], i + n[0].length) : -1;
  2788. }
  2789. function d3_time_parseMinutes(date, string, i) {
  2790. d3_time_numberRe.lastIndex = 0;
  2791. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2792. return n ? (date.M = +n[0], i + n[0].length) : -1;
  2793. }
  2794. function d3_time_parseSeconds(date, string, i) {
  2795. d3_time_numberRe.lastIndex = 0;
  2796. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2797. return n ? (date.S = +n[0], i + n[0].length) : -1;
  2798. }
  2799. function d3_time_parseMilliseconds(date, string, i) {
  2800. d3_time_numberRe.lastIndex = 0;
  2801. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2802. return n ? (date.L = +n[0], i + n[0].length) : -1;
  2803. }
  2804. function d3_time_zone(d) {
  2805. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
  2806. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  2807. }
  2808. function d3_time_parseLiteralPercent(date, string, i) {
  2809. d3_time_percentRe.lastIndex = 0;
  2810. var n = d3_time_percentRe.exec(string.slice(i, i + 1));
  2811. return n ? i + n[0].length : -1;
  2812. }
  2813. function d3_time_formatMulti(formats) {
  2814. var n = formats.length, i = -1;
  2815. while (++i < n) formats[i][0] = this(formats[i][0]);
  2816. return function(date) {
  2817. var i = 0, f = formats[i];
  2818. while (!f[1](date)) f = formats[++i];
  2819. return f[0](date);
  2820. };
  2821. }
  2822. d3.locale = function(locale) {
  2823. return {
  2824. numberFormat: d3_locale_numberFormat(locale),
  2825. timeFormat: d3_locale_timeFormat(locale)
  2826. };
  2827. };
  2828. var d3_locale_enUS = d3.locale({
  2829. decimal: ".",
  2830. thousands: ",",
  2831. grouping: [ 3 ],
  2832. currency: [ "$", "" ],
  2833. dateTime: "%a %b %e %X %Y",
  2834. date: "%m/%d/%Y",
  2835. time: "%H:%M:%S",
  2836. periods: [ "AM", "PM" ],
  2837. days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
  2838. shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
  2839. months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  2840. shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
  2841. });
  2842. d3.format = d3_locale_enUS.numberFormat;
  2843. d3.geo = {};
  2844. function d3_adder() {}
  2845. d3_adder.prototype = {
  2846. s: 0,
  2847. t: 0,
  2848. add: function(y) {
  2849. d3_adderSum(y, this.t, d3_adderTemp);
  2850. d3_adderSum(d3_adderTemp.s, this.s, this);
  2851. if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
  2852. },
  2853. reset: function() {
  2854. this.s = this.t = 0;
  2855. },
  2856. valueOf: function() {
  2857. return this.s;
  2858. }
  2859. };
  2860. var d3_adderTemp = new d3_adder();
  2861. function d3_adderSum(a, b, o) {
  2862. var x = o.s = a + b, bv = x - a, av = x - bv;
  2863. o.t = a - av + (b - bv);
  2864. }
  2865. d3.geo.stream = function(object, listener) {
  2866. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  2867. d3_geo_streamObjectType[object.type](object, listener);
  2868. } else {
  2869. d3_geo_streamGeometry(object, listener);
  2870. }
  2871. };
  2872. function d3_geo_streamGeometry(geometry, listener) {
  2873. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  2874. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  2875. }
  2876. }
  2877. var d3_geo_streamObjectType = {
  2878. Feature: function(feature, listener) {
  2879. d3_geo_streamGeometry(feature.geometry, listener);
  2880. },
  2881. FeatureCollection: function(object, listener) {
  2882. var features = object.features, i = -1, n = features.length;
  2883. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  2884. }
  2885. };
  2886. var d3_geo_streamGeometryType = {
  2887. Sphere: function(object, listener) {
  2888. listener.sphere();
  2889. },
  2890. Point: function(object, listener) {
  2891. object = object.coordinates;
  2892. listener.point(object[0], object[1], object[2]);
  2893. },
  2894. MultiPoint: function(object, listener) {
  2895. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2896. while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
  2897. },
  2898. LineString: function(object, listener) {
  2899. d3_geo_streamLine(object.coordinates, listener, 0);
  2900. },
  2901. MultiLineString: function(object, listener) {
  2902. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2903. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  2904. },
  2905. Polygon: function(object, listener) {
  2906. d3_geo_streamPolygon(object.coordinates, listener);
  2907. },
  2908. MultiPolygon: function(object, listener) {
  2909. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2910. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  2911. },
  2912. GeometryCollection: function(object, listener) {
  2913. var geometries = object.geometries, i = -1, n = geometries.length;
  2914. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  2915. }
  2916. };
  2917. function d3_geo_streamLine(coordinates, listener, closed) {
  2918. var i = -1, n = coordinates.length - closed, coordinate;
  2919. listener.lineStart();
  2920. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
  2921. listener.lineEnd();
  2922. }
  2923. function d3_geo_streamPolygon(coordinates, listener) {
  2924. var i = -1, n = coordinates.length;
  2925. listener.polygonStart();
  2926. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  2927. listener.polygonEnd();
  2928. }
  2929. d3.geo.area = function(object) {
  2930. d3_geo_areaSum = 0;
  2931. d3.geo.stream(object, d3_geo_area);
  2932. return d3_geo_areaSum;
  2933. };
  2934. var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
  2935. var d3_geo_area = {
  2936. sphere: function() {
  2937. d3_geo_areaSum += 4 * π;
  2938. },
  2939. point: d3_noop,
  2940. lineStart: d3_noop,
  2941. lineEnd: d3_noop,
  2942. polygonStart: function() {
  2943. d3_geo_areaRingSum.reset();
  2944. d3_geo_area.lineStart = d3_geo_areaRingStart;
  2945. },
  2946. polygonEnd: function() {
  2947. var area = 2 * d3_geo_areaRingSum;
  2948. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  2949. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  2950. }
  2951. };
  2952. function d3_geo_areaRingStart() {
  2953. var λ00, φ00, λ0, cosφ0, sinφ0;
  2954. d3_geo_area.point = function(λ, φ) {
  2955. d3_geo_area.point = nextPoint;
  2956. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  2957. sinφ0 = Math.sin(φ);
  2958. };
  2959. function nextPoint(λ, φ) {
  2960. λ *= d3_radians;
  2961. φ = φ * d3_radians / 2 + π / 4;
  2962. 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λ);
  2963. d3_geo_areaRingSum.add(Math.atan2(v, u));
  2964. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  2965. }
  2966. d3_geo_area.lineEnd = function() {
  2967. nextPoint(λ00, φ00);
  2968. };
  2969. }
  2970. function d3_geo_cartesian(spherical) {
  2971. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  2972. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  2973. }
  2974. function d3_geo_cartesianDot(a, b) {
  2975. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  2976. }
  2977. function d3_geo_cartesianCross(a, b) {
  2978. 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] ];
  2979. }
  2980. function d3_geo_cartesianAdd(a, b) {
  2981. a[0] += b[0];
  2982. a[1] += b[1];
  2983. a[2] += b[2];
  2984. }
  2985. function d3_geo_cartesianScale(vector, k) {
  2986. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  2987. }
  2988. function d3_geo_cartesianNormalize(d) {
  2989. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  2990. d[0] /= l;
  2991. d[1] /= l;
  2992. d[2] /= l;
  2993. }
  2994. function d3_geo_spherical(cartesian) {
  2995. return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
  2996. }
  2997. function d3_geo_sphericalEqual(a, b) {
  2998. return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
  2999. }
  3000. d3.geo.bounds = function() {
  3001. var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
  3002. var bound = {
  3003. point: point,
  3004. lineStart: lineStart,
  3005. lineEnd: lineEnd,
  3006. polygonStart: function() {
  3007. bound.point = ringPoint;
  3008. bound.lineStart = ringStart;
  3009. bound.lineEnd = ringEnd;
  3010. dλSum = 0;
  3011. d3_geo_area.polygonStart();
  3012. },
  3013. polygonEnd: function() {
  3014. d3_geo_area.polygonEnd();
  3015. bound.point = point;
  3016. bound.lineStart = lineStart;
  3017. bound.lineEnd = lineEnd;
  3018. if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
  3019. range[0] = λ0, range[1] = λ1;
  3020. }
  3021. };
  3022. function point(λ, φ) {
  3023. ranges.push(range = [ λ0 = λ, λ1 = λ ]);
  3024. if (φ < φ0) φ0 = φ;
  3025. if (φ > φ1) φ1 = φ;
  3026. }
  3027. function linePoint(λ, φ) {
  3028. var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
  3029. if (p0) {
  3030. var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
  3031. d3_geo_cartesianNormalize(inflection);
  3032. inflection = d3_geo_spherical(inflection);
  3033. var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
  3034. if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3035. var φi = inflection[1] * d3_degrees;
  3036. if (φi > φ1) φ1 = φi;
  3037. } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3038. var φi = -inflection[1] * d3_degrees;
  3039. if (φi < φ0) φ0 = φi;
  3040. } else {
  3041. if (φ < φ0) φ0 = φ;
  3042. if (φ > φ1) φ1 = φ;
  3043. }
  3044. if (antimeridian) {
  3045. if (λ < λ_) {
  3046. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3047. } else {
  3048. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3049. }
  3050. } else {
  3051. if (λ1 >= λ0) {
  3052. if (λ < λ0) λ0 = λ;
  3053. if (λ > λ1) λ1 = λ;
  3054. } else {
  3055. if (λ > λ_) {
  3056. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3057. } else {
  3058. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3059. }
  3060. }
  3061. }
  3062. } else {
  3063. point(λ, φ);
  3064. }
  3065. p0 = p, λ_ = λ;
  3066. }
  3067. function lineStart() {
  3068. bound.point = linePoint;
  3069. }
  3070. function lineEnd() {
  3071. range[0] = λ0, range[1] = λ1;
  3072. bound.point = point;
  3073. p0 = null;
  3074. }
  3075. function ringPoint(λ, φ) {
  3076. if (p0) {
  3077. var dλ = λ - λ_;
  3078. dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
  3079. } else λ__ = λ, φ__ = φ;
  3080. d3_geo_area.point(λ, φ);
  3081. linePoint(λ, φ);
  3082. }
  3083. function ringStart() {
  3084. d3_geo_area.lineStart();
  3085. }
  3086. function ringEnd() {
  3087. ringPoint(λ__, φ__);
  3088. d3_geo_area.lineEnd();
  3089. if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
  3090. range[0] = λ0, range[1] = λ1;
  3091. p0 = null;
  3092. }
  3093. function angle(λ0, λ1) {
  3094. return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
  3095. }
  3096. function compareRanges(a, b) {
  3097. return a[0] - b[0];
  3098. }
  3099. function withinRange(x, range) {
  3100. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  3101. }
  3102. return function(feature) {
  3103. φ1 = λ1 = -(λ0 = φ0 = Infinity);
  3104. ranges = [];
  3105. d3.geo.stream(feature, bound);
  3106. var n = ranges.length;
  3107. if (n) {
  3108. ranges.sort(compareRanges);
  3109. for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
  3110. b = ranges[i];
  3111. if (withinRange(b[0], a) || withinRange(b[1], a)) {
  3112. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  3113. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  3114. } else {
  3115. merged.push(a = b);
  3116. }
  3117. }
  3118. var best = -Infinity, dλ;
  3119. for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
  3120. b = merged[i];
  3121. if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
  3122. }
  3123. }
  3124. ranges = range = null;
  3125. return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
  3126. };
  3127. }();
  3128. d3.geo.centroid = function(object) {
  3129. 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;
  3130. d3.geo.stream(object, d3_geo_centroid);
  3131. var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
  3132. if (m < ε2) {
  3133. x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
  3134. if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
  3135. m = x * x + y * y + z * z;
  3136. if (m < ε2) return [ NaN, NaN ];
  3137. }
  3138. return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
  3139. };
  3140. 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;
  3141. var d3_geo_centroid = {
  3142. sphere: d3_noop,
  3143. point: d3_geo_centroidPoint,
  3144. lineStart: d3_geo_centroidLineStart,
  3145. lineEnd: d3_geo_centroidLineEnd,
  3146. polygonStart: function() {
  3147. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  3148. },
  3149. polygonEnd: function() {
  3150. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  3151. }
  3152. };
  3153. function d3_geo_centroidPoint(λ, φ) {
  3154. λ *= d3_radians;
  3155. var cosφ = Math.cos(φ *= d3_radians);
  3156. d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
  3157. }
  3158. function d3_geo_centroidPointXYZ(x, y, z) {
  3159. ++d3_geo_centroidW0;
  3160. d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
  3161. d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
  3162. d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
  3163. }
  3164. function d3_geo_centroidLineStart() {
  3165. var x0, y0, z0;
  3166. d3_geo_centroid.point = function(λ, φ) {
  3167. λ *= d3_radians;
  3168. var cosφ = Math.cos(φ *= d3_radians);
  3169. x0 = cosφ * Math.cos(λ);
  3170. y0 = cosφ * Math.sin(λ);
  3171. z0 = Math.sin(φ);
  3172. d3_geo_centroid.point = nextPoint;
  3173. d3_geo_centroidPointXYZ(x0, y0, z0);
  3174. };
  3175. function nextPoint(λ, φ) {
  3176. λ *= d3_radians;
  3177. 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);
  3178. d3_geo_centroidW1 += w;
  3179. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3180. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3181. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3182. d3_geo_centroidPointXYZ(x0, y0, z0);
  3183. }
  3184. }
  3185. function d3_geo_centroidLineEnd() {
  3186. d3_geo_centroid.point = d3_geo_centroidPoint;
  3187. }
  3188. function d3_geo_centroidRingStart() {
  3189. var λ00, φ00, x0, y0, z0;
  3190. d3_geo_centroid.point = function(λ, φ) {
  3191. λ00 = λ, φ00 = φ;
  3192. d3_geo_centroid.point = nextPoint;
  3193. λ *= d3_radians;
  3194. var cosφ = Math.cos(φ *= d3_radians);
  3195. x0 = cosφ * Math.cos(λ);
  3196. y0 = cosφ * Math.sin(λ);
  3197. z0 = Math.sin(φ);
  3198. d3_geo_centroidPointXYZ(x0, y0, z0);
  3199. };
  3200. d3_geo_centroid.lineEnd = function() {
  3201. nextPoint(λ00, φ00);
  3202. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  3203. d3_geo_centroid.point = d3_geo_centroidPoint;
  3204. };
  3205. function nextPoint(λ, φ) {
  3206. λ *= d3_radians;
  3207. 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);
  3208. d3_geo_centroidX2 += v * cx;
  3209. d3_geo_centroidY2 += v * cy;
  3210. d3_geo_centroidZ2 += v * cz;
  3211. d3_geo_centroidW1 += w;
  3212. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3213. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3214. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3215. d3_geo_centroidPointXYZ(x0, y0, z0);
  3216. }
  3217. }
  3218. function d3_geo_compose(a, b) {
  3219. function compose(x, y) {
  3220. return x = a(x, y), b(x[0], x[1]);
  3221. }
  3222. if (a.invert && b.invert) compose.invert = function(x, y) {
  3223. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  3224. };
  3225. return compose;
  3226. }
  3227. function d3_true() {
  3228. return true;
  3229. }
  3230. function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
  3231. var subject = [], clip = [];
  3232. segments.forEach(function(segment) {
  3233. if ((n = segment.length - 1) <= 0) return;
  3234. var n, p0 = segment[0], p1 = segment[n];
  3235. if (d3_geo_sphericalEqual(p0, p1)) {
  3236. listener.lineStart();
  3237. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  3238. listener.lineEnd();
  3239. return;
  3240. }
  3241. var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
  3242. a.o = b;
  3243. subject.push(a);
  3244. clip.push(b);
  3245. a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
  3246. b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
  3247. a.o = b;
  3248. subject.push(a);
  3249. clip.push(b);
  3250. });
  3251. clip.sort(compare);
  3252. d3_geo_clipPolygonLinkCircular(subject);
  3253. d3_geo_clipPolygonLinkCircular(clip);
  3254. if (!subject.length) return;
  3255. for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
  3256. clip[i].e = entry = !entry;
  3257. }
  3258. var start = subject[0], points, point;
  3259. while (1) {
  3260. var current = start, isSubject = true;
  3261. while (current.v) if ((current = current.n) === start) return;
  3262. points = current.z;
  3263. listener.lineStart();
  3264. do {
  3265. current.v = current.o.v = true;
  3266. if (current.e) {
  3267. if (isSubject) {
  3268. for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
  3269. } else {
  3270. interpolate(current.x, current.n.x, 1, listener);
  3271. }
  3272. current = current.n;
  3273. } else {
  3274. if (isSubject) {
  3275. points = current.p.z;
  3276. for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
  3277. } else {
  3278. interpolate(current.x, current.p.x, -1, listener);
  3279. }
  3280. current = current.p;
  3281. }
  3282. current = current.o;
  3283. points = current.z;
  3284. isSubject = !isSubject;
  3285. } while (!current.v);
  3286. listener.lineEnd();
  3287. }
  3288. }
  3289. function d3_geo_clipPolygonLinkCircular(array) {
  3290. if (!(n = array.length)) return;
  3291. var n, i = 0, a = array[0], b;
  3292. while (++i < n) {
  3293. a.n = b = array[i];
  3294. b.p = a;
  3295. a = b;
  3296. }
  3297. a.n = b = array[0];
  3298. b.p = a;
  3299. }
  3300. function d3_geo_clipPolygonIntersection(point, points, other, entry) {
  3301. this.x = point;
  3302. this.z = points;
  3303. this.o = other;
  3304. this.e = entry;
  3305. this.v = false;
  3306. this.n = this.p = null;
  3307. }
  3308. function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
  3309. return function(rotate, listener) {
  3310. var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
  3311. var clip = {
  3312. point: point,
  3313. lineStart: lineStart,
  3314. lineEnd: lineEnd,
  3315. polygonStart: function() {
  3316. clip.point = pointRing;
  3317. clip.lineStart = ringStart;
  3318. clip.lineEnd = ringEnd;
  3319. segments = [];
  3320. polygon = [];
  3321. },
  3322. polygonEnd: function() {
  3323. clip.point = point;
  3324. clip.lineStart = lineStart;
  3325. clip.lineEnd = lineEnd;
  3326. segments = d3.merge(segments);
  3327. var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
  3328. if (segments.length) {
  3329. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3330. d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
  3331. } else if (clipStartInside) {
  3332. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3333. listener.lineStart();
  3334. interpolate(null, null, 1, listener);
  3335. listener.lineEnd();
  3336. }
  3337. if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
  3338. segments = polygon = null;
  3339. },
  3340. sphere: function() {
  3341. listener.polygonStart();
  3342. listener.lineStart();
  3343. interpolate(null, null, 1, listener);
  3344. listener.lineEnd();
  3345. listener.polygonEnd();
  3346. }
  3347. };
  3348. function point(λ, φ) {
  3349. var point = rotate(λ, φ);
  3350. if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
  3351. }
  3352. function pointLine(λ, φ) {
  3353. var point = rotate(λ, φ);
  3354. line.point(point[0], point[1]);
  3355. }
  3356. function lineStart() {
  3357. clip.point = pointLine;
  3358. line.lineStart();
  3359. }
  3360. function lineEnd() {
  3361. clip.point = point;
  3362. line.lineEnd();
  3363. }
  3364. var segments;
  3365. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
  3366. function pointRing(λ, φ) {
  3367. ring.push([ λ, φ ]);
  3368. var point = rotate(λ, φ);
  3369. ringListener.point(point[0], point[1]);
  3370. }
  3371. function ringStart() {
  3372. ringListener.lineStart();
  3373. ring = [];
  3374. }
  3375. function ringEnd() {
  3376. pointRing(ring[0][0], ring[0][1]);
  3377. ringListener.lineEnd();
  3378. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  3379. ring.pop();
  3380. polygon.push(ring);
  3381. ring = null;
  3382. if (!n) return;
  3383. if (clean & 1) {
  3384. segment = ringSegments[0];
  3385. var n = segment.length - 1, i = -1, point;
  3386. if (n > 0) {
  3387. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3388. listener.lineStart();
  3389. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  3390. listener.lineEnd();
  3391. }
  3392. return;
  3393. }
  3394. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  3395. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  3396. }
  3397. return clip;
  3398. };
  3399. }
  3400. function d3_geo_clipSegmentLength1(segment) {
  3401. return segment.length > 1;
  3402. }
  3403. function d3_geo_clipBufferListener() {
  3404. var lines = [], line;
  3405. return {
  3406. lineStart: function() {
  3407. lines.push(line = []);
  3408. },
  3409. point: function(λ, φ) {
  3410. line.push([ λ, φ ]);
  3411. },
  3412. lineEnd: d3_noop,
  3413. buffer: function() {
  3414. var buffer = lines;
  3415. lines = [];
  3416. line = null;
  3417. return buffer;
  3418. },
  3419. rejoin: function() {
  3420. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  3421. }
  3422. };
  3423. }
  3424. function d3_geo_clipSort(a, b) {
  3425. return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
  3426. }
  3427. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
  3428. function d3_geo_clipAntimeridianLine(listener) {
  3429. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  3430. return {
  3431. lineStart: function() {
  3432. listener.lineStart();
  3433. clean = 1;
  3434. },
  3435. point: function(λ1, φ1) {
  3436. var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
  3437. if (abs(dλ - π) < ε) {
  3438. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
  3439. listener.point(sλ0, φ0);
  3440. listener.lineEnd();
  3441. listener.lineStart();
  3442. listener.point(sλ1, φ0);
  3443. listener.point(λ1, φ0);
  3444. clean = 0;
  3445. } else if (sλ0 !== sλ1 && dλ >= π) {
  3446. if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  3447. if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  3448. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  3449. listener.point(sλ0, φ0);
  3450. listener.lineEnd();
  3451. listener.lineStart();
  3452. listener.point(sλ1, φ0);
  3453. clean = 0;
  3454. }
  3455. listener.point(λ0 = λ1, φ0 = φ1);
  3456. sλ0 = sλ1;
  3457. },
  3458. lineEnd: function() {
  3459. listener.lineEnd();
  3460. λ0 = φ0 = NaN;
  3461. },
  3462. clean: function() {
  3463. return 2 - clean;
  3464. }
  3465. };
  3466. }
  3467. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  3468. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  3469. 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;
  3470. }
  3471. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  3472. var φ;
  3473. if (from == null) {
  3474. φ = direction * halfπ;
  3475. listener.point(-π, φ);
  3476. listener.point(0, φ);
  3477. listener.point(π, φ);
  3478. listener.point(π, 0);
  3479. listener.point(π, -φ);
  3480. listener.point(0, -φ);
  3481. listener.point(-π, -φ);
  3482. listener.point(-π, 0);
  3483. listener.point(-π, φ);
  3484. } else if (abs(from[0] - to[0]) > ε) {
  3485. var s = from[0] < to[0] ? π : -π;
  3486. φ = direction * s / 2;
  3487. listener.point(-s, φ);
  3488. listener.point(0, φ);
  3489. listener.point(s, φ);
  3490. } else {
  3491. listener.point(to[0], to[1]);
  3492. }
  3493. }
  3494. function d3_geo_pointInPolygon(point, polygon) {
  3495. var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
  3496. d3_geo_areaRingSum.reset();
  3497. for (var i = 0, n = polygon.length; i < n; ++i) {
  3498. var ring = polygon[i], m = ring.length;
  3499. if (!m) continue;
  3500. var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
  3501. while (true) {
  3502. if (j === m) j = 0;
  3503. point = ring[j];
  3504. 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φ;
  3505. d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
  3506. polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
  3507. if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
  3508. var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
  3509. d3_geo_cartesianNormalize(arc);
  3510. var intersection = d3_geo_cartesianCross(meridianNormal, arc);
  3511. d3_geo_cartesianNormalize(intersection);
  3512. var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
  3513. if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
  3514. winding += antimeridian ^ dλ >= 0 ? 1 : -1;
  3515. }
  3516. }
  3517. if (!j++) break;
  3518. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
  3519. }
  3520. }
  3521. return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < -ε) ^ winding & 1;
  3522. }
  3523. function d3_geo_clipCircle(radius) {
  3524. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  3525. return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
  3526. function visible(λ, φ) {
  3527. return Math.cos(λ) * Math.cos(φ) > cr;
  3528. }
  3529. function clipLine(listener) {
  3530. var point0, c0, v0, v00, clean;
  3531. return {
  3532. lineStart: function() {
  3533. v00 = v0 = false;
  3534. clean = 1;
  3535. },
  3536. point: function(λ, φ) {
  3537. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  3538. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  3539. if (v !== v0) {
  3540. point2 = intersect(point0, point1);
  3541. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  3542. point1[0] += ε;
  3543. point1[1] += ε;
  3544. v = visible(point1[0], point1[1]);
  3545. }
  3546. }
  3547. if (v !== v0) {
  3548. clean = 0;
  3549. if (v) {
  3550. listener.lineStart();
  3551. point2 = intersect(point1, point0);
  3552. listener.point(point2[0], point2[1]);
  3553. } else {
  3554. point2 = intersect(point0, point1);
  3555. listener.point(point2[0], point2[1]);
  3556. listener.lineEnd();
  3557. }
  3558. point0 = point2;
  3559. } else if (notHemisphere && point0 && smallRadius ^ v) {
  3560. var t;
  3561. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  3562. clean = 0;
  3563. if (smallRadius) {
  3564. listener.lineStart();
  3565. listener.point(t[0][0], t[0][1]);
  3566. listener.point(t[1][0], t[1][1]);
  3567. listener.lineEnd();
  3568. } else {
  3569. listener.point(t[1][0], t[1][1]);
  3570. listener.lineEnd();
  3571. listener.lineStart();
  3572. listener.point(t[0][0], t[0][1]);
  3573. }
  3574. }
  3575. }
  3576. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  3577. listener.point(point1[0], point1[1]);
  3578. }
  3579. point0 = point1, v0 = v, c0 = c;
  3580. },
  3581. lineEnd: function() {
  3582. if (v0) listener.lineEnd();
  3583. point0 = null;
  3584. },
  3585. clean: function() {
  3586. return clean | (v00 && v0) << 1;
  3587. }
  3588. };
  3589. }
  3590. function intersect(a, b, two) {
  3591. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  3592. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  3593. if (!determinant) return !two && a;
  3594. 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);
  3595. d3_geo_cartesianAdd(A, B);
  3596. 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);
  3597. if (t2 < 0) return;
  3598. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  3599. d3_geo_cartesianAdd(q, A);
  3600. q = d3_geo_spherical(q);
  3601. if (!two) return q;
  3602. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  3603. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  3604. var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
  3605. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  3606. 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)) {
  3607. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  3608. d3_geo_cartesianAdd(q1, A);
  3609. return [ q, d3_geo_spherical(q1) ];
  3610. }
  3611. }
  3612. function code(λ, φ) {
  3613. var r = smallRadius ? radius : π - radius, code = 0;
  3614. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  3615. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  3616. return code;
  3617. }
  3618. }
  3619. function d3_geom_clipLine(x0, y0, x1, y1) {
  3620. return function(line) {
  3621. 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;
  3622. r = x0 - ax;
  3623. if (!dx && r > 0) return;
  3624. r /= dx;
  3625. if (dx < 0) {
  3626. if (r < t0) return;
  3627. if (r < t1) t1 = r;
  3628. } else if (dx > 0) {
  3629. if (r > t1) return;
  3630. if (r > t0) t0 = r;
  3631. }
  3632. r = x1 - ax;
  3633. if (!dx && r < 0) return;
  3634. r /= dx;
  3635. if (dx < 0) {
  3636. if (r > t1) return;
  3637. if (r > t0) t0 = r;
  3638. } else if (dx > 0) {
  3639. if (r < t0) return;
  3640. if (r < t1) t1 = r;
  3641. }
  3642. r = y0 - ay;
  3643. if (!dy && r > 0) return;
  3644. r /= dy;
  3645. if (dy < 0) {
  3646. if (r < t0) return;
  3647. if (r < t1) t1 = r;
  3648. } else if (dy > 0) {
  3649. if (r > t1) return;
  3650. if (r > t0) t0 = r;
  3651. }
  3652. r = y1 - ay;
  3653. if (!dy && r < 0) return;
  3654. r /= dy;
  3655. if (dy < 0) {
  3656. if (r > t1) return;
  3657. if (r > t0) t0 = r;
  3658. } else if (dy > 0) {
  3659. if (r < t0) return;
  3660. if (r < t1) t1 = r;
  3661. }
  3662. if (t0 > 0) line.a = {
  3663. x: ax + t0 * dx,
  3664. y: ay + t0 * dy
  3665. };
  3666. if (t1 < 1) line.b = {
  3667. x: ax + t1 * dx,
  3668. y: ay + t1 * dy
  3669. };
  3670. return line;
  3671. };
  3672. }
  3673. var d3_geo_clipExtentMAX = 1e9;
  3674. d3.geo.clipExtent = function() {
  3675. var x0, y0, x1, y1, stream, clip, clipExtent = {
  3676. stream: function(output) {
  3677. if (stream) stream.valid = false;
  3678. stream = clip(output);
  3679. stream.valid = true;
  3680. return stream;
  3681. },
  3682. extent: function(_) {
  3683. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3684. clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
  3685. if (stream) stream.valid = false, stream = null;
  3686. return clipExtent;
  3687. }
  3688. };
  3689. return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
  3690. };
  3691. function d3_geo_clipExtent(x0, y0, x1, y1) {
  3692. return function(listener) {
  3693. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
  3694. var clip = {
  3695. point: point,
  3696. lineStart: lineStart,
  3697. lineEnd: lineEnd,
  3698. polygonStart: function() {
  3699. listener = bufferListener;
  3700. segments = [];
  3701. polygon = [];
  3702. clean = true;
  3703. },
  3704. polygonEnd: function() {
  3705. listener = listener_;
  3706. segments = d3.merge(segments);
  3707. var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
  3708. if (inside || visible) {
  3709. listener.polygonStart();
  3710. if (inside) {
  3711. listener.lineStart();
  3712. interpolate(null, null, 1, listener);
  3713. listener.lineEnd();
  3714. }
  3715. if (visible) {
  3716. d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
  3717. }
  3718. listener.polygonEnd();
  3719. }
  3720. segments = polygon = ring = null;
  3721. }
  3722. };
  3723. function insidePolygon(p) {
  3724. var wn = 0, n = polygon.length, y = p[1];
  3725. for (var i = 0; i < n; ++i) {
  3726. for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
  3727. b = v[j];
  3728. if (a[1] <= y) {
  3729. if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
  3730. } else {
  3731. if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
  3732. }
  3733. a = b;
  3734. }
  3735. }
  3736. return wn !== 0;
  3737. }
  3738. function interpolate(from, to, direction, listener) {
  3739. var a = 0, a1 = 0;
  3740. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  3741. do {
  3742. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  3743. } while ((a = (a + direction + 4) % 4) !== a1);
  3744. } else {
  3745. listener.point(to[0], to[1]);
  3746. }
  3747. }
  3748. function pointVisible(x, y) {
  3749. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  3750. }
  3751. function point(x, y) {
  3752. if (pointVisible(x, y)) listener.point(x, y);
  3753. }
  3754. var x__, y__, v__, x_, y_, v_, first, clean;
  3755. function lineStart() {
  3756. clip.point = linePoint;
  3757. if (polygon) polygon.push(ring = []);
  3758. first = true;
  3759. v_ = false;
  3760. x_ = y_ = NaN;
  3761. }
  3762. function lineEnd() {
  3763. if (segments) {
  3764. linePoint(x__, y__);
  3765. if (v__ && v_) bufferListener.rejoin();
  3766. segments.push(bufferListener.buffer());
  3767. }
  3768. clip.point = point;
  3769. if (v_) listener.lineEnd();
  3770. }
  3771. function linePoint(x, y) {
  3772. x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
  3773. y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
  3774. var v = pointVisible(x, y);
  3775. if (polygon) ring.push([ x, y ]);
  3776. if (first) {
  3777. x__ = x, y__ = y, v__ = v;
  3778. first = false;
  3779. if (v) {
  3780. listener.lineStart();
  3781. listener.point(x, y);
  3782. }
  3783. } else {
  3784. if (v && v_) listener.point(x, y); else {
  3785. var l = {
  3786. a: {
  3787. x: x_,
  3788. y: y_
  3789. },
  3790. b: {
  3791. x: x,
  3792. y: y
  3793. }
  3794. };
  3795. if (clipLine(l)) {
  3796. if (!v_) {
  3797. listener.lineStart();
  3798. listener.point(l.a.x, l.a.y);
  3799. }
  3800. listener.point(l.b.x, l.b.y);
  3801. if (!v) listener.lineEnd();
  3802. clean = false;
  3803. } else if (v) {
  3804. listener.lineStart();
  3805. listener.point(x, y);
  3806. clean = false;
  3807. }
  3808. }
  3809. }
  3810. x_ = x, y_ = y, v_ = v;
  3811. }
  3812. return clip;
  3813. };
  3814. function corner(p, direction) {
  3815. 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;
  3816. }
  3817. function compare(a, b) {
  3818. return comparePoints(a.x, b.x);
  3819. }
  3820. function comparePoints(a, b) {
  3821. var ca = corner(a, 1), cb = corner(b, 1);
  3822. 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];
  3823. }
  3824. }
  3825. function d3_geo_conic(projectAt) {
  3826. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  3827. p.parallels = function(_) {
  3828. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  3829. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  3830. };
  3831. return p;
  3832. }
  3833. function d3_geo_conicEqualArea(φ0, φ1) {
  3834. 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;
  3835. function forward(λ, φ) {
  3836. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  3837. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  3838. }
  3839. forward.invert = function(x, y) {
  3840. var ρ0_y = ρ0 - y;
  3841. return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  3842. };
  3843. return forward;
  3844. }
  3845. (d3.geo.conicEqualArea = function() {
  3846. return d3_geo_conic(d3_geo_conicEqualArea);
  3847. }).raw = d3_geo_conicEqualArea;
  3848. d3.geo.albers = function() {
  3849. return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
  3850. };
  3851. d3.geo.albersUsa = function() {
  3852. var lower48 = d3.geo.albers();
  3853. var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
  3854. var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
  3855. var point, pointStream = {
  3856. point: function(x, y) {
  3857. point = [ x, y ];
  3858. }
  3859. }, lower48Point, alaskaPoint, hawaiiPoint;
  3860. function albersUsa(coordinates) {
  3861. var x = coordinates[0], y = coordinates[1];
  3862. point = null;
  3863. (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
  3864. return point;
  3865. }
  3866. albersUsa.invert = function(coordinates) {
  3867. var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
  3868. return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
  3869. };
  3870. albersUsa.stream = function(stream) {
  3871. var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
  3872. return {
  3873. point: function(x, y) {
  3874. lower48Stream.point(x, y);
  3875. alaskaStream.point(x, y);
  3876. hawaiiStream.point(x, y);
  3877. },
  3878. sphere: function() {
  3879. lower48Stream.sphere();
  3880. alaskaStream.sphere();
  3881. hawaiiStream.sphere();
  3882. },
  3883. lineStart: function() {
  3884. lower48Stream.lineStart();
  3885. alaskaStream.lineStart();
  3886. hawaiiStream.lineStart();
  3887. },
  3888. lineEnd: function() {
  3889. lower48Stream.lineEnd();
  3890. alaskaStream.lineEnd();
  3891. hawaiiStream.lineEnd();
  3892. },
  3893. polygonStart: function() {
  3894. lower48Stream.polygonStart();
  3895. alaskaStream.polygonStart();
  3896. hawaiiStream.polygonStart();
  3897. },
  3898. polygonEnd: function() {
  3899. lower48Stream.polygonEnd();
  3900. alaskaStream.polygonEnd();
  3901. hawaiiStream.polygonEnd();
  3902. }
  3903. };
  3904. };
  3905. albersUsa.precision = function(_) {
  3906. if (!arguments.length) return lower48.precision();
  3907. lower48.precision(_);
  3908. alaska.precision(_);
  3909. hawaii.precision(_);
  3910. return albersUsa;
  3911. };
  3912. albersUsa.scale = function(_) {
  3913. if (!arguments.length) return lower48.scale();
  3914. lower48.scale(_);
  3915. alaska.scale(_ * .35);
  3916. hawaii.scale(_);
  3917. return albersUsa.translate(lower48.translate());
  3918. };
  3919. albersUsa.translate = function(_) {
  3920. if (!arguments.length) return lower48.translate();
  3921. var k = lower48.scale(), x = +_[0], y = +_[1];
  3922. lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
  3923. 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;
  3924. 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;
  3925. return albersUsa;
  3926. };
  3927. return albersUsa.scale(1070);
  3928. };
  3929. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  3930. point: d3_noop,
  3931. lineStart: d3_noop,
  3932. lineEnd: d3_noop,
  3933. polygonStart: function() {
  3934. d3_geo_pathAreaPolygon = 0;
  3935. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  3936. },
  3937. polygonEnd: function() {
  3938. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  3939. d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
  3940. }
  3941. };
  3942. function d3_geo_pathAreaRingStart() {
  3943. var x00, y00, x0, y0;
  3944. d3_geo_pathArea.point = function(x, y) {
  3945. d3_geo_pathArea.point = nextPoint;
  3946. x00 = x0 = x, y00 = y0 = y;
  3947. };
  3948. function nextPoint(x, y) {
  3949. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  3950. x0 = x, y0 = y;
  3951. }
  3952. d3_geo_pathArea.lineEnd = function() {
  3953. nextPoint(x00, y00);
  3954. };
  3955. }
  3956. var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
  3957. var d3_geo_pathBounds = {
  3958. point: d3_geo_pathBoundsPoint,
  3959. lineStart: d3_noop,
  3960. lineEnd: d3_noop,
  3961. polygonStart: d3_noop,
  3962. polygonEnd: d3_noop
  3963. };
  3964. function d3_geo_pathBoundsPoint(x, y) {
  3965. if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
  3966. if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
  3967. if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
  3968. if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
  3969. }
  3970. function d3_geo_pathBuffer() {
  3971. var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
  3972. var stream = {
  3973. point: point,
  3974. lineStart: function() {
  3975. stream.point = pointLineStart;
  3976. },
  3977. lineEnd: lineEnd,
  3978. polygonStart: function() {
  3979. stream.lineEnd = lineEndPolygon;
  3980. },
  3981. polygonEnd: function() {
  3982. stream.lineEnd = lineEnd;
  3983. stream.point = point;
  3984. },
  3985. pointRadius: function(_) {
  3986. pointCircle = d3_geo_pathBufferCircle(_);
  3987. return stream;
  3988. },
  3989. result: function() {
  3990. if (buffer.length) {
  3991. var result = buffer.join("");
  3992. buffer = [];
  3993. return result;
  3994. }
  3995. }
  3996. };
  3997. function point(x, y) {
  3998. buffer.push("M", x, ",", y, pointCircle);
  3999. }
  4000. function pointLineStart(x, y) {
  4001. buffer.push("M", x, ",", y);
  4002. stream.point = pointLine;
  4003. }
  4004. function pointLine(x, y) {
  4005. buffer.push("L", x, ",", y);
  4006. }
  4007. function lineEnd() {
  4008. stream.point = point;
  4009. }
  4010. function lineEndPolygon() {
  4011. buffer.push("Z");
  4012. }
  4013. return stream;
  4014. }
  4015. function d3_geo_pathBufferCircle(radius) {
  4016. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
  4017. }
  4018. var d3_geo_pathCentroid = {
  4019. point: d3_geo_pathCentroidPoint,
  4020. lineStart: d3_geo_pathCentroidLineStart,
  4021. lineEnd: d3_geo_pathCentroidLineEnd,
  4022. polygonStart: function() {
  4023. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  4024. },
  4025. polygonEnd: function() {
  4026. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4027. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  4028. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  4029. }
  4030. };
  4031. function d3_geo_pathCentroidPoint(x, y) {
  4032. d3_geo_centroidX0 += x;
  4033. d3_geo_centroidY0 += y;
  4034. ++d3_geo_centroidZ0;
  4035. }
  4036. function d3_geo_pathCentroidLineStart() {
  4037. var x0, y0;
  4038. d3_geo_pathCentroid.point = function(x, y) {
  4039. d3_geo_pathCentroid.point = nextPoint;
  4040. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4041. };
  4042. function nextPoint(x, y) {
  4043. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4044. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4045. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4046. d3_geo_centroidZ1 += z;
  4047. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4048. }
  4049. }
  4050. function d3_geo_pathCentroidLineEnd() {
  4051. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4052. }
  4053. function d3_geo_pathCentroidRingStart() {
  4054. var x00, y00, x0, y0;
  4055. d3_geo_pathCentroid.point = function(x, y) {
  4056. d3_geo_pathCentroid.point = nextPoint;
  4057. d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
  4058. };
  4059. function nextPoint(x, y) {
  4060. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4061. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4062. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4063. d3_geo_centroidZ1 += z;
  4064. z = y0 * x - x0 * y;
  4065. d3_geo_centroidX2 += z * (x0 + x);
  4066. d3_geo_centroidY2 += z * (y0 + y);
  4067. d3_geo_centroidZ2 += z * 3;
  4068. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4069. }
  4070. d3_geo_pathCentroid.lineEnd = function() {
  4071. nextPoint(x00, y00);
  4072. };
  4073. }
  4074. function d3_geo_pathContext(context) {
  4075. var pointRadius = 4.5;
  4076. var stream = {
  4077. point: point,
  4078. lineStart: function() {
  4079. stream.point = pointLineStart;
  4080. },
  4081. lineEnd: lineEnd,
  4082. polygonStart: function() {
  4083. stream.lineEnd = lineEndPolygon;
  4084. },
  4085. polygonEnd: function() {
  4086. stream.lineEnd = lineEnd;
  4087. stream.point = point;
  4088. },
  4089. pointRadius: function(_) {
  4090. pointRadius = _;
  4091. return stream;
  4092. },
  4093. result: d3_noop
  4094. };
  4095. function point(x, y) {
  4096. context.moveTo(x + pointRadius, y);
  4097. context.arc(x, y, pointRadius, 0, τ);
  4098. }
  4099. function pointLineStart(x, y) {
  4100. context.moveTo(x, y);
  4101. stream.point = pointLine;
  4102. }
  4103. function pointLine(x, y) {
  4104. context.lineTo(x, y);
  4105. }
  4106. function lineEnd() {
  4107. stream.point = point;
  4108. }
  4109. function lineEndPolygon() {
  4110. context.closePath();
  4111. }
  4112. return stream;
  4113. }
  4114. function d3_geo_resample(project) {
  4115. var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
  4116. function resample(stream) {
  4117. return (maxDepth ? resampleRecursive : resampleNone)(stream);
  4118. }
  4119. function resampleNone(stream) {
  4120. return d3_geo_transformPoint(stream, function(x, y) {
  4121. x = project(x, y);
  4122. stream.point(x[0], x[1]);
  4123. });
  4124. }
  4125. function resampleRecursive(stream) {
  4126. var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
  4127. var resample = {
  4128. point: point,
  4129. lineStart: lineStart,
  4130. lineEnd: lineEnd,
  4131. polygonStart: function() {
  4132. stream.polygonStart();
  4133. resample.lineStart = ringStart;
  4134. },
  4135. polygonEnd: function() {
  4136. stream.polygonEnd();
  4137. resample.lineStart = lineStart;
  4138. }
  4139. };
  4140. function point(x, y) {
  4141. x = project(x, y);
  4142. stream.point(x[0], x[1]);
  4143. }
  4144. function lineStart() {
  4145. x0 = NaN;
  4146. resample.point = linePoint;
  4147. stream.lineStart();
  4148. }
  4149. function linePoint(λ, φ) {
  4150. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  4151. 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);
  4152. stream.point(x0, y0);
  4153. }
  4154. function lineEnd() {
  4155. resample.point = point;
  4156. stream.lineEnd();
  4157. }
  4158. function ringStart() {
  4159. lineStart();
  4160. resample.point = ringPoint;
  4161. resample.lineEnd = ringEnd;
  4162. }
  4163. function ringPoint(λ, φ) {
  4164. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  4165. resample.point = linePoint;
  4166. }
  4167. function ringEnd() {
  4168. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  4169. resample.lineEnd = lineEnd;
  4170. lineEnd();
  4171. }
  4172. return resample;
  4173. }
  4174. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  4175. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  4176. if (d2 > 4 * δ2 && depth--) {
  4177. 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;
  4178. if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
  4179. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  4180. stream.point(x2, y2);
  4181. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  4182. }
  4183. }
  4184. }
  4185. resample.precision = function(_) {
  4186. if (!arguments.length) return Math.sqrt(δ2);
  4187. maxDepth = (δ2 = _ * _) > 0 && 16;
  4188. return resample;
  4189. };
  4190. return resample;
  4191. }
  4192. d3.geo.path = function() {
  4193. var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
  4194. function path(object) {
  4195. if (object) {
  4196. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  4197. if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
  4198. d3.geo.stream(object, cacheStream);
  4199. }
  4200. return contextStream.result();
  4201. }
  4202. path.area = function(object) {
  4203. d3_geo_pathAreaSum = 0;
  4204. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  4205. return d3_geo_pathAreaSum;
  4206. };
  4207. path.centroid = function(object) {
  4208. 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;
  4209. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  4210. 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 ];
  4211. };
  4212. path.bounds = function(object) {
  4213. d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
  4214. d3.geo.stream(object, projectStream(d3_geo_pathBounds));
  4215. return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
  4216. };
  4217. path.projection = function(_) {
  4218. if (!arguments.length) return projection;
  4219. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  4220. return reset();
  4221. };
  4222. path.context = function(_) {
  4223. if (!arguments.length) return context;
  4224. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  4225. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  4226. return reset();
  4227. };
  4228. path.pointRadius = function(_) {
  4229. if (!arguments.length) return pointRadius;
  4230. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  4231. return path;
  4232. };
  4233. function reset() {
  4234. cacheStream = null;
  4235. return path;
  4236. }
  4237. return path.projection(d3.geo.albersUsa()).context(null);
  4238. };
  4239. function d3_geo_pathProjectStream(project) {
  4240. var resample = d3_geo_resample(function(x, y) {
  4241. return project([ x * d3_degrees, y * d3_degrees ]);
  4242. });
  4243. return function(stream) {
  4244. return d3_geo_projectionRadians(resample(stream));
  4245. };
  4246. }
  4247. d3.geo.transform = function(methods) {
  4248. return {
  4249. stream: function(stream) {
  4250. var transform = new d3_geo_transform(stream);
  4251. for (var k in methods) transform[k] = methods[k];
  4252. return transform;
  4253. }
  4254. };
  4255. };
  4256. function d3_geo_transform(stream) {
  4257. this.stream = stream;
  4258. }
  4259. d3_geo_transform.prototype = {
  4260. point: function(x, y) {
  4261. this.stream.point(x, y);
  4262. },
  4263. sphere: function() {
  4264. this.stream.sphere();
  4265. },
  4266. lineStart: function() {
  4267. this.stream.lineStart();
  4268. },
  4269. lineEnd: function() {
  4270. this.stream.lineEnd();
  4271. },
  4272. polygonStart: function() {
  4273. this.stream.polygonStart();
  4274. },
  4275. polygonEnd: function() {
  4276. this.stream.polygonEnd();
  4277. }
  4278. };
  4279. function d3_geo_transformPoint(stream, point) {
  4280. return {
  4281. point: point,
  4282. sphere: function() {
  4283. stream.sphere();
  4284. },
  4285. lineStart: function() {
  4286. stream.lineStart();
  4287. },
  4288. lineEnd: function() {
  4289. stream.lineEnd();
  4290. },
  4291. polygonStart: function() {
  4292. stream.polygonStart();
  4293. },
  4294. polygonEnd: function() {
  4295. stream.polygonEnd();
  4296. }
  4297. };
  4298. }
  4299. d3.geo.projection = d3_geo_projection;
  4300. d3.geo.projectionMutator = d3_geo_projectionMutator;
  4301. function d3_geo_projection(project) {
  4302. return d3_geo_projectionMutator(function() {
  4303. return project;
  4304. })();
  4305. }
  4306. function d3_geo_projectionMutator(projectAt) {
  4307. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  4308. x = project(x, y);
  4309. return [ x[0] * k + δx, δy - x[1] * k ];
  4310. }), 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;
  4311. function projection(point) {
  4312. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  4313. return [ point[0] * k + δx, δy - point[1] * k ];
  4314. }
  4315. function invert(point) {
  4316. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  4317. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  4318. }
  4319. projection.stream = function(output) {
  4320. if (stream) stream.valid = false;
  4321. stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
  4322. stream.valid = true;
  4323. return stream;
  4324. };
  4325. projection.clipAngle = function(_) {
  4326. if (!arguments.length) return clipAngle;
  4327. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  4328. return invalidate();
  4329. };
  4330. projection.clipExtent = function(_) {
  4331. if (!arguments.length) return clipExtent;
  4332. clipExtent = _;
  4333. postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
  4334. return invalidate();
  4335. };
  4336. projection.scale = function(_) {
  4337. if (!arguments.length) return k;
  4338. k = +_;
  4339. return reset();
  4340. };
  4341. projection.translate = function(_) {
  4342. if (!arguments.length) return [ x, y ];
  4343. x = +_[0];
  4344. y = +_[1];
  4345. return reset();
  4346. };
  4347. projection.center = function(_) {
  4348. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  4349. λ = _[0] % 360 * d3_radians;
  4350. φ = _[1] % 360 * d3_radians;
  4351. return reset();
  4352. };
  4353. projection.rotate = function(_) {
  4354. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  4355. δλ = _[0] % 360 * d3_radians;
  4356. δφ = _[1] % 360 * d3_radians;
  4357. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  4358. return reset();
  4359. };
  4360. d3.rebind(projection, projectResample, "precision");
  4361. function reset() {
  4362. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  4363. var center = project(λ, φ);
  4364. δx = x - center[0] * k;
  4365. δy = y + center[1] * k;
  4366. return invalidate();
  4367. }
  4368. function invalidate() {
  4369. if (stream) stream.valid = false, stream = null;
  4370. return projection;
  4371. }
  4372. return function() {
  4373. project = projectAt.apply(this, arguments);
  4374. projection.invert = project.invert && invert;
  4375. return reset();
  4376. };
  4377. }
  4378. function d3_geo_projectionRadians(stream) {
  4379. return d3_geo_transformPoint(stream, function(x, y) {
  4380. stream.point(x * d3_radians, y * d3_radians);
  4381. });
  4382. }
  4383. function d3_geo_equirectangular(λ, φ) {
  4384. return [ λ, φ ];
  4385. }
  4386. (d3.geo.equirectangular = function() {
  4387. return d3_geo_projection(d3_geo_equirectangular);
  4388. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  4389. d3.geo.rotation = function(rotate) {
  4390. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  4391. function forward(coordinates) {
  4392. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4393. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4394. }
  4395. forward.invert = function(coordinates) {
  4396. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4397. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4398. };
  4399. return forward;
  4400. };
  4401. function d3_geo_identityRotation(λ, φ) {
  4402. return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4403. }
  4404. d3_geo_identityRotation.invert = d3_geo_equirectangular;
  4405. function d3_geo_rotation(δλ, δφ, δγ) {
  4406. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
  4407. }
  4408. function d3_geo_forwardRotationλ(δλ) {
  4409. return function(λ, φ) {
  4410. return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4411. };
  4412. }
  4413. function d3_geo_rotationλ(δλ) {
  4414. var rotation = d3_geo_forwardRotationλ(δλ);
  4415. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  4416. return rotation;
  4417. }
  4418. function d3_geo_rotationφγ(δφ, δγ) {
  4419. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  4420. function rotation(λ, φ) {
  4421. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  4422. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
  4423. }
  4424. rotation.invert = function(λ, φ) {
  4425. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  4426. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
  4427. };
  4428. return rotation;
  4429. }
  4430. d3.geo.circle = function() {
  4431. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  4432. function circle() {
  4433. 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 = [];
  4434. interpolate(null, null, 1, {
  4435. point: function(x, y) {
  4436. ring.push(x = rotate(x, y));
  4437. x[0] *= d3_degrees, x[1] *= d3_degrees;
  4438. }
  4439. });
  4440. return {
  4441. type: "Polygon",
  4442. coordinates: [ ring ]
  4443. };
  4444. }
  4445. circle.origin = function(x) {
  4446. if (!arguments.length) return origin;
  4447. origin = x;
  4448. return circle;
  4449. };
  4450. circle.angle = function(x) {
  4451. if (!arguments.length) return angle;
  4452. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  4453. return circle;
  4454. };
  4455. circle.precision = function(_) {
  4456. if (!arguments.length) return precision;
  4457. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  4458. return circle;
  4459. };
  4460. return circle.angle(90);
  4461. };
  4462. function d3_geo_circleInterpolate(radius, precision) {
  4463. var cr = Math.cos(radius), sr = Math.sin(radius);
  4464. return function(from, to, direction, listener) {
  4465. var step = direction * precision;
  4466. if (from != null) {
  4467. from = d3_geo_circleAngle(cr, from);
  4468. to = d3_geo_circleAngle(cr, to);
  4469. if (direction > 0 ? from < to : from > to) from += direction * τ;
  4470. } else {
  4471. from = radius + direction * τ;
  4472. to = radius - .5 * step;
  4473. }
  4474. for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
  4475. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  4476. }
  4477. };
  4478. }
  4479. function d3_geo_circleAngle(cr, point) {
  4480. var a = d3_geo_cartesian(point);
  4481. a[0] -= cr;
  4482. d3_geo_cartesianNormalize(a);
  4483. var angle = d3_acos(-a[1]);
  4484. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  4485. }
  4486. d3.geo.distance = function(a, b) {
  4487. 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;
  4488. 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Δλ);
  4489. };
  4490. d3.geo.graticule = function() {
  4491. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  4492. function graticule() {
  4493. return {
  4494. type: "MultiLineString",
  4495. coordinates: lines()
  4496. };
  4497. }
  4498. function lines() {
  4499. 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) {
  4500. return abs(x % DX) > ε;
  4501. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  4502. return abs(y % DY) > ε;
  4503. }).map(y));
  4504. }
  4505. graticule.lines = function() {
  4506. return lines().map(function(coordinates) {
  4507. return {
  4508. type: "LineString",
  4509. coordinates: coordinates
  4510. };
  4511. });
  4512. };
  4513. graticule.outline = function() {
  4514. return {
  4515. type: "Polygon",
  4516. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  4517. };
  4518. };
  4519. graticule.extent = function(_) {
  4520. if (!arguments.length) return graticule.minorExtent();
  4521. return graticule.majorExtent(_).minorExtent(_);
  4522. };
  4523. graticule.majorExtent = function(_) {
  4524. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  4525. X0 = +_[0][0], X1 = +_[1][0];
  4526. Y0 = +_[0][1], Y1 = +_[1][1];
  4527. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  4528. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  4529. return graticule.precision(precision);
  4530. };
  4531. graticule.minorExtent = function(_) {
  4532. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  4533. x0 = +_[0][0], x1 = +_[1][0];
  4534. y0 = +_[0][1], y1 = +_[1][1];
  4535. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  4536. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  4537. return graticule.precision(precision);
  4538. };
  4539. graticule.step = function(_) {
  4540. if (!arguments.length) return graticule.minorStep();
  4541. return graticule.majorStep(_).minorStep(_);
  4542. };
  4543. graticule.majorStep = function(_) {
  4544. if (!arguments.length) return [ DX, DY ];
  4545. DX = +_[0], DY = +_[1];
  4546. return graticule;
  4547. };
  4548. graticule.minorStep = function(_) {
  4549. if (!arguments.length) return [ dx, dy ];
  4550. dx = +_[0], dy = +_[1];
  4551. return graticule;
  4552. };
  4553. graticule.precision = function(_) {
  4554. if (!arguments.length) return precision;
  4555. precision = +_;
  4556. x = d3_geo_graticuleX(y0, y1, 90);
  4557. y = d3_geo_graticuleY(x0, x1, precision);
  4558. X = d3_geo_graticuleX(Y0, Y1, 90);
  4559. Y = d3_geo_graticuleY(X0, X1, precision);
  4560. return graticule;
  4561. };
  4562. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  4563. };
  4564. function d3_geo_graticuleX(y0, y1, dy) {
  4565. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  4566. return function(x) {
  4567. return y.map(function(y) {
  4568. return [ x, y ];
  4569. });
  4570. };
  4571. }
  4572. function d3_geo_graticuleY(x0, x1, dx) {
  4573. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  4574. return function(y) {
  4575. return x.map(function(x) {
  4576. return [ x, y ];
  4577. });
  4578. };
  4579. }
  4580. function d3_source(d) {
  4581. return d.source;
  4582. }
  4583. function d3_target(d) {
  4584. return d.target;
  4585. }
  4586. d3.geo.greatArc = function() {
  4587. var source = d3_source, source_, target = d3_target, target_;
  4588. function greatArc() {
  4589. return {
  4590. type: "LineString",
  4591. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  4592. };
  4593. }
  4594. greatArc.distance = function() {
  4595. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  4596. };
  4597. greatArc.source = function(_) {
  4598. if (!arguments.length) return source;
  4599. source = _, source_ = typeof _ === "function" ? null : _;
  4600. return greatArc;
  4601. };
  4602. greatArc.target = function(_) {
  4603. if (!arguments.length) return target;
  4604. target = _, target_ = typeof _ === "function" ? null : _;
  4605. return greatArc;
  4606. };
  4607. greatArc.precision = function() {
  4608. return arguments.length ? greatArc : 0;
  4609. };
  4610. return greatArc;
  4611. };
  4612. d3.geo.interpolate = function(source, target) {
  4613. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  4614. };
  4615. function d3_geo_interpolate(x0, y0, x1, y1) {
  4616. 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);
  4617. var interpolate = d ? function(t) {
  4618. 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;
  4619. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  4620. } : function() {
  4621. return [ x0 * d3_degrees, y0 * d3_degrees ];
  4622. };
  4623. interpolate.distance = d;
  4624. return interpolate;
  4625. }
  4626. d3.geo.length = function(object) {
  4627. d3_geo_lengthSum = 0;
  4628. d3.geo.stream(object, d3_geo_length);
  4629. return d3_geo_lengthSum;
  4630. };
  4631. var d3_geo_lengthSum;
  4632. var d3_geo_length = {
  4633. sphere: d3_noop,
  4634. point: d3_noop,
  4635. lineStart: d3_geo_lengthLineStart,
  4636. lineEnd: d3_noop,
  4637. polygonStart: d3_noop,
  4638. polygonEnd: d3_noop
  4639. };
  4640. function d3_geo_lengthLineStart() {
  4641. var λ0, sinφ0, cosφ0;
  4642. d3_geo_length.point = function(λ, φ) {
  4643. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  4644. d3_geo_length.point = nextPoint;
  4645. };
  4646. d3_geo_length.lineEnd = function() {
  4647. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  4648. };
  4649. function nextPoint(λ, φ) {
  4650. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  4651. 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Δλ);
  4652. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  4653. }
  4654. }
  4655. function d3_geo_azimuthal(scale, angle) {
  4656. function azimuthal(λ, φ) {
  4657. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  4658. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  4659. }
  4660. azimuthal.invert = function(x, y) {
  4661. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  4662. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  4663. };
  4664. return azimuthal;
  4665. }
  4666. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  4667. return Math.sqrt(2 / (1 + cosλcosφ));
  4668. }, function(ρ) {
  4669. return 2 * Math.asin(ρ / 2);
  4670. });
  4671. (d3.geo.azimuthalEqualArea = function() {
  4672. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  4673. }).raw = d3_geo_azimuthalEqualArea;
  4674. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  4675. var c = Math.acos(cosλcosφ);
  4676. return c && c / Math.sin(c);
  4677. }, d3_identity);
  4678. (d3.geo.azimuthalEquidistant = function() {
  4679. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  4680. }).raw = d3_geo_azimuthalEquidistant;
  4681. function d3_geo_conicConformal(φ0, φ1) {
  4682. var cosφ0 = Math.cos(φ0), t = function(φ) {
  4683. return Math.tan(π / 4 + φ / 2);
  4684. }, 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;
  4685. if (!n) return d3_geo_mercator;
  4686. function forward(λ, φ) {
  4687. if (F > 0) {
  4688. if (φ < -halfπ + ε) φ = -halfπ + ε;
  4689. } else {
  4690. if (φ > halfπ - ε) φ = halfπ - ε;
  4691. }
  4692. var ρ = F / Math.pow(t(φ), n);
  4693. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  4694. }
  4695. forward.invert = function(x, y) {
  4696. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  4697. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
  4698. };
  4699. return forward;
  4700. }
  4701. (d3.geo.conicConformal = function() {
  4702. return d3_geo_conic(d3_geo_conicConformal);
  4703. }).raw = d3_geo_conicConformal;
  4704. function d3_geo_conicEquidistant(φ0, φ1) {
  4705. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  4706. if (abs(n) < ε) return d3_geo_equirectangular;
  4707. function forward(λ, φ) {
  4708. var ρ = G - φ;
  4709. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  4710. }
  4711. forward.invert = function(x, y) {
  4712. var ρ0_y = G - y;
  4713. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  4714. };
  4715. return forward;
  4716. }
  4717. (d3.geo.conicEquidistant = function() {
  4718. return d3_geo_conic(d3_geo_conicEquidistant);
  4719. }).raw = d3_geo_conicEquidistant;
  4720. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  4721. return 1 / cosλcosφ;
  4722. }, Math.atan);
  4723. (d3.geo.gnomonic = function() {
  4724. return d3_geo_projection(d3_geo_gnomonic);
  4725. }).raw = d3_geo_gnomonic;
  4726. function d3_geo_mercator(λ, φ) {
  4727. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  4728. }
  4729. d3_geo_mercator.invert = function(x, y) {
  4730. return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
  4731. };
  4732. function d3_geo_mercatorProjection(project) {
  4733. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  4734. m.scale = function() {
  4735. var v = scale.apply(m, arguments);
  4736. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4737. };
  4738. m.translate = function() {
  4739. var v = translate.apply(m, arguments);
  4740. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4741. };
  4742. m.clipExtent = function(_) {
  4743. var v = clipExtent.apply(m, arguments);
  4744. if (v === m) {
  4745. if (clipAuto = _ == null) {
  4746. var k = π * scale(), t = translate();
  4747. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  4748. }
  4749. } else if (clipAuto) {
  4750. v = null;
  4751. }
  4752. return v;
  4753. };
  4754. return m.clipExtent(null);
  4755. }
  4756. (d3.geo.mercator = function() {
  4757. return d3_geo_mercatorProjection(d3_geo_mercator);
  4758. }).raw = d3_geo_mercator;
  4759. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  4760. return 1;
  4761. }, Math.asin);
  4762. (d3.geo.orthographic = function() {
  4763. return d3_geo_projection(d3_geo_orthographic);
  4764. }).raw = d3_geo_orthographic;
  4765. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  4766. return 1 / (1 + cosλcosφ);
  4767. }, function(ρ) {
  4768. return 2 * Math.atan(ρ);
  4769. });
  4770. (d3.geo.stereographic = function() {
  4771. return d3_geo_projection(d3_geo_stereographic);
  4772. }).raw = d3_geo_stereographic;
  4773. function d3_geo_transverseMercator(λ, φ) {
  4774. return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
  4775. }
  4776. d3_geo_transverseMercator.invert = function(x, y) {
  4777. return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
  4778. };
  4779. (d3.geo.transverseMercator = function() {
  4780. var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
  4781. projection.center = function(_) {
  4782. return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
  4783. };
  4784. projection.rotate = function(_) {
  4785. return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
  4786. [ _[0], _[1], _[2] - 90 ]);
  4787. };
  4788. return rotate([ 0, 0, 90 ]);
  4789. }).raw = d3_geo_transverseMercator;
  4790. d3.geom = {};
  4791. function d3_geom_pointX(d) {
  4792. return d[0];
  4793. }
  4794. function d3_geom_pointY(d) {
  4795. return d[1];
  4796. }
  4797. d3.geom.hull = function(vertices) {
  4798. var x = d3_geom_pointX, y = d3_geom_pointY;
  4799. if (arguments.length) return hull(vertices);
  4800. function hull(data) {
  4801. if (data.length < 3) return [];
  4802. var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
  4803. for (i = 0; i < n; i++) {
  4804. points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
  4805. }
  4806. points.sort(d3_geom_hullOrder);
  4807. for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
  4808. var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
  4809. var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
  4810. for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
  4811. for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
  4812. return polygon;
  4813. }
  4814. hull.x = function(_) {
  4815. return arguments.length ? (x = _, hull) : x;
  4816. };
  4817. hull.y = function(_) {
  4818. return arguments.length ? (y = _, hull) : y;
  4819. };
  4820. return hull;
  4821. };
  4822. function d3_geom_hullUpper(points) {
  4823. var n = points.length, hull = [ 0, 1 ], hs = 2;
  4824. for (var i = 2; i < n; i++) {
  4825. while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
  4826. hull[hs++] = i;
  4827. }
  4828. return hull.slice(0, hs);
  4829. }
  4830. function d3_geom_hullOrder(a, b) {
  4831. return a[0] - b[0] || a[1] - b[1];
  4832. }
  4833. d3.geom.polygon = function(coordinates) {
  4834. d3_subclass(coordinates, d3_geom_polygonPrototype);
  4835. return coordinates;
  4836. };
  4837. var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
  4838. d3_geom_polygonPrototype.area = function() {
  4839. var i = -1, n = this.length, a, b = this[n - 1], area = 0;
  4840. while (++i < n) {
  4841. a = b;
  4842. b = this[i];
  4843. area += a[1] * b[0] - a[0] * b[1];
  4844. }
  4845. return area * .5;
  4846. };
  4847. d3_geom_polygonPrototype.centroid = function(k) {
  4848. var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
  4849. if (!arguments.length) k = -1 / (6 * this.area());
  4850. while (++i < n) {
  4851. a = b;
  4852. b = this[i];
  4853. c = a[0] * b[1] - b[0] * a[1];
  4854. x += (a[0] + b[0]) * c;
  4855. y += (a[1] + b[1]) * c;
  4856. }
  4857. return [ x * k, y * k ];
  4858. };
  4859. d3_geom_polygonPrototype.clip = function(subject) {
  4860. 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;
  4861. while (++i < n) {
  4862. input = subject.slice();
  4863. subject.length = 0;
  4864. b = this[i];
  4865. c = input[(m = input.length - closed) - 1];
  4866. j = -1;
  4867. while (++j < m) {
  4868. d = input[j];
  4869. if (d3_geom_polygonInside(d, a, b)) {
  4870. if (!d3_geom_polygonInside(c, a, b)) {
  4871. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4872. }
  4873. subject.push(d);
  4874. } else if (d3_geom_polygonInside(c, a, b)) {
  4875. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4876. }
  4877. c = d;
  4878. }
  4879. if (closed) subject.push(subject[0]);
  4880. a = b;
  4881. }
  4882. return subject;
  4883. };
  4884. function d3_geom_polygonInside(p, a, b) {
  4885. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  4886. }
  4887. function d3_geom_polygonIntersect(c, d, a, b) {
  4888. 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);
  4889. return [ x1 + ua * x21, y1 + ua * y21 ];
  4890. }
  4891. function d3_geom_polygonClosed(coordinates) {
  4892. var a = coordinates[0], b = coordinates[coordinates.length - 1];
  4893. return !(a[0] - b[0] || a[1] - b[1]);
  4894. }
  4895. var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
  4896. function d3_geom_voronoiBeach() {
  4897. d3_geom_voronoiRedBlackNode(this);
  4898. this.edge = this.site = this.circle = null;
  4899. }
  4900. function d3_geom_voronoiCreateBeach(site) {
  4901. var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
  4902. beach.site = site;
  4903. return beach;
  4904. }
  4905. function d3_geom_voronoiDetachBeach(beach) {
  4906. d3_geom_voronoiDetachCircle(beach);
  4907. d3_geom_voronoiBeaches.remove(beach);
  4908. d3_geom_voronoiBeachPool.push(beach);
  4909. d3_geom_voronoiRedBlackNode(beach);
  4910. }
  4911. function d3_geom_voronoiRemoveBeach(beach) {
  4912. var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
  4913. x: x,
  4914. y: y
  4915. }, previous = beach.P, next = beach.N, disappearing = [ beach ];
  4916. d3_geom_voronoiDetachBeach(beach);
  4917. var lArc = previous;
  4918. while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
  4919. previous = lArc.P;
  4920. disappearing.unshift(lArc);
  4921. d3_geom_voronoiDetachBeach(lArc);
  4922. lArc = previous;
  4923. }
  4924. disappearing.unshift(lArc);
  4925. d3_geom_voronoiDetachCircle(lArc);
  4926. var rArc = next;
  4927. while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
  4928. next = rArc.N;
  4929. disappearing.push(rArc);
  4930. d3_geom_voronoiDetachBeach(rArc);
  4931. rArc = next;
  4932. }
  4933. disappearing.push(rArc);
  4934. d3_geom_voronoiDetachCircle(rArc);
  4935. var nArcs = disappearing.length, iArc;
  4936. for (iArc = 1; iArc < nArcs; ++iArc) {
  4937. rArc = disappearing[iArc];
  4938. lArc = disappearing[iArc - 1];
  4939. d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  4940. }
  4941. lArc = disappearing[0];
  4942. rArc = disappearing[nArcs - 1];
  4943. rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
  4944. d3_geom_voronoiAttachCircle(lArc);
  4945. d3_geom_voronoiAttachCircle(rArc);
  4946. }
  4947. function d3_geom_voronoiAddBeach(site) {
  4948. var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
  4949. while (node) {
  4950. dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
  4951. if (dxl > ε) node = node.L; else {
  4952. dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
  4953. if (dxr > ε) {
  4954. if (!node.R) {
  4955. lArc = node;
  4956. break;
  4957. }
  4958. node = node.R;
  4959. } else {
  4960. if (dxl > -ε) {
  4961. lArc = node.P;
  4962. rArc = node;
  4963. } else if (dxr > -ε) {
  4964. lArc = node;
  4965. rArc = node.N;
  4966. } else {
  4967. lArc = rArc = node;
  4968. }
  4969. break;
  4970. }
  4971. }
  4972. }
  4973. var newArc = d3_geom_voronoiCreateBeach(site);
  4974. d3_geom_voronoiBeaches.insert(lArc, newArc);
  4975. if (!lArc && !rArc) return;
  4976. if (lArc === rArc) {
  4977. d3_geom_voronoiDetachCircle(lArc);
  4978. rArc = d3_geom_voronoiCreateBeach(lArc.site);
  4979. d3_geom_voronoiBeaches.insert(newArc, rArc);
  4980. newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4981. d3_geom_voronoiAttachCircle(lArc);
  4982. d3_geom_voronoiAttachCircle(rArc);
  4983. return;
  4984. }
  4985. if (!rArc) {
  4986. newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4987. return;
  4988. }
  4989. d3_geom_voronoiDetachCircle(lArc);
  4990. d3_geom_voronoiDetachCircle(rArc);
  4991. 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 = {
  4992. x: (cy * hb - by * hc) / d + ax,
  4993. y: (bx * hc - cx * hb) / d + ay
  4994. };
  4995. d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
  4996. newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
  4997. rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
  4998. d3_geom_voronoiAttachCircle(lArc);
  4999. d3_geom_voronoiAttachCircle(rArc);
  5000. }
  5001. function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
  5002. var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
  5003. if (!pby2) return rfocx;
  5004. var lArc = arc.P;
  5005. if (!lArc) return -Infinity;
  5006. site = lArc.site;
  5007. var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
  5008. if (!plby2) return lfocx;
  5009. var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
  5010. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  5011. return (rfocx + lfocx) / 2;
  5012. }
  5013. function d3_geom_voronoiRightBreakPoint(arc, directrix) {
  5014. var rArc = arc.N;
  5015. if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
  5016. var site = arc.site;
  5017. return site.y === directrix ? site.x : Infinity;
  5018. }
  5019. function d3_geom_voronoiCell(site) {
  5020. this.site = site;
  5021. this.edges = [];
  5022. }
  5023. d3_geom_voronoiCell.prototype.prepare = function() {
  5024. var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
  5025. while (iHalfEdge--) {
  5026. edge = halfEdges[iHalfEdge].edge;
  5027. if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
  5028. }
  5029. halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
  5030. return halfEdges.length;
  5031. };
  5032. function d3_geom_voronoiCloseCells(extent) {
  5033. 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;
  5034. while (iCell--) {
  5035. cell = cells[iCell];
  5036. if (!cell || !cell.prepare()) continue;
  5037. halfEdges = cell.edges;
  5038. nHalfEdges = halfEdges.length;
  5039. iHalfEdge = 0;
  5040. while (iHalfEdge < nHalfEdges) {
  5041. end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
  5042. start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
  5043. if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
  5044. halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
  5045. x: x0,
  5046. y: abs(x2 - x0) < ε ? y2 : y1
  5047. } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
  5048. x: abs(y2 - y1) < ε ? x2 : x1,
  5049. y: y1
  5050. } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
  5051. x: x1,
  5052. y: abs(x2 - x1) < ε ? y2 : y0
  5053. } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
  5054. x: abs(y2 - y0) < ε ? x2 : x0,
  5055. y: y0
  5056. } : null), cell.site, null));
  5057. ++nHalfEdges;
  5058. }
  5059. }
  5060. }
  5061. }
  5062. function d3_geom_voronoiHalfEdgeOrder(a, b) {
  5063. return b.angle - a.angle;
  5064. }
  5065. function d3_geom_voronoiCircle() {
  5066. d3_geom_voronoiRedBlackNode(this);
  5067. this.x = this.y = this.arc = this.site = this.cy = null;
  5068. }
  5069. function d3_geom_voronoiAttachCircle(arc) {
  5070. var lArc = arc.P, rArc = arc.N;
  5071. if (!lArc || !rArc) return;
  5072. var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
  5073. if (lSite === rSite) return;
  5074. var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
  5075. var d = 2 * (ax * cy - ay * cx);
  5076. if (d >= -ε2) return;
  5077. 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;
  5078. var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
  5079. circle.arc = arc;
  5080. circle.site = cSite;
  5081. circle.x = x + bx;
  5082. circle.y = cy + Math.sqrt(x * x + y * y);
  5083. circle.cy = cy;
  5084. arc.circle = circle;
  5085. var before = null, node = d3_geom_voronoiCircles._;
  5086. while (node) {
  5087. if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
  5088. if (node.L) node = node.L; else {
  5089. before = node.P;
  5090. break;
  5091. }
  5092. } else {
  5093. if (node.R) node = node.R; else {
  5094. before = node;
  5095. break;
  5096. }
  5097. }
  5098. }
  5099. d3_geom_voronoiCircles.insert(before, circle);
  5100. if (!before) d3_geom_voronoiFirstCircle = circle;
  5101. }
  5102. function d3_geom_voronoiDetachCircle(arc) {
  5103. var circle = arc.circle;
  5104. if (circle) {
  5105. if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
  5106. d3_geom_voronoiCircles.remove(circle);
  5107. d3_geom_voronoiCirclePool.push(circle);
  5108. d3_geom_voronoiRedBlackNode(circle);
  5109. arc.circle = null;
  5110. }
  5111. }
  5112. function d3_geom_voronoiClipEdges(extent) {
  5113. 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;
  5114. while (i--) {
  5115. e = edges[i];
  5116. if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
  5117. e.a = e.b = null;
  5118. edges.splice(i, 1);
  5119. }
  5120. }
  5121. }
  5122. function d3_geom_voronoiConnectEdge(edge, extent) {
  5123. var vb = edge.b;
  5124. if (vb) return true;
  5125. 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;
  5126. if (ry === ly) {
  5127. if (fx < x0 || fx >= x1) return;
  5128. if (lx > rx) {
  5129. if (!va) va = {
  5130. x: fx,
  5131. y: y0
  5132. }; else if (va.y >= y1) return;
  5133. vb = {
  5134. x: fx,
  5135. y: y1
  5136. };
  5137. } else {
  5138. if (!va) va = {
  5139. x: fx,
  5140. y: y1
  5141. }; else if (va.y < y0) return;
  5142. vb = {
  5143. x: fx,
  5144. y: y0
  5145. };
  5146. }
  5147. } else {
  5148. fm = (lx - rx) / (ry - ly);
  5149. fb = fy - fm * fx;
  5150. if (fm < -1 || fm > 1) {
  5151. if (lx > rx) {
  5152. if (!va) va = {
  5153. x: (y0 - fb) / fm,
  5154. y: y0
  5155. }; else if (va.y >= y1) return;
  5156. vb = {
  5157. x: (y1 - fb) / fm,
  5158. y: y1
  5159. };
  5160. } else {
  5161. if (!va) va = {
  5162. x: (y1 - fb) / fm,
  5163. y: y1
  5164. }; else if (va.y < y0) return;
  5165. vb = {
  5166. x: (y0 - fb) / fm,
  5167. y: y0
  5168. };
  5169. }
  5170. } else {
  5171. if (ly < ry) {
  5172. if (!va) va = {
  5173. x: x0,
  5174. y: fm * x0 + fb
  5175. }; else if (va.x >= x1) return;
  5176. vb = {
  5177. x: x1,
  5178. y: fm * x1 + fb
  5179. };
  5180. } else {
  5181. if (!va) va = {
  5182. x: x1,
  5183. y: fm * x1 + fb
  5184. }; else if (va.x < x0) return;
  5185. vb = {
  5186. x: x0,
  5187. y: fm * x0 + fb
  5188. };
  5189. }
  5190. }
  5191. }
  5192. edge.a = va;
  5193. edge.b = vb;
  5194. return true;
  5195. }
  5196. function d3_geom_voronoiEdge(lSite, rSite) {
  5197. this.l = lSite;
  5198. this.r = rSite;
  5199. this.a = this.b = null;
  5200. }
  5201. function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
  5202. var edge = new d3_geom_voronoiEdge(lSite, rSite);
  5203. d3_geom_voronoiEdges.push(edge);
  5204. if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
  5205. if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
  5206. d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
  5207. d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
  5208. return edge;
  5209. }
  5210. function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
  5211. var edge = new d3_geom_voronoiEdge(lSite, null);
  5212. edge.a = va;
  5213. edge.b = vb;
  5214. d3_geom_voronoiEdges.push(edge);
  5215. return edge;
  5216. }
  5217. function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
  5218. if (!edge.a && !edge.b) {
  5219. edge.a = vertex;
  5220. edge.l = lSite;
  5221. edge.r = rSite;
  5222. } else if (edge.l === rSite) {
  5223. edge.b = vertex;
  5224. } else {
  5225. edge.a = vertex;
  5226. }
  5227. }
  5228. function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
  5229. var va = edge.a, vb = edge.b;
  5230. this.edge = edge;
  5231. this.site = lSite;
  5232. 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);
  5233. }
  5234. d3_geom_voronoiHalfEdge.prototype = {
  5235. start: function() {
  5236. return this.edge.l === this.site ? this.edge.a : this.edge.b;
  5237. },
  5238. end: function() {
  5239. return this.edge.l === this.site ? this.edge.b : this.edge.a;
  5240. }
  5241. };
  5242. function d3_geom_voronoiRedBlackTree() {
  5243. this._ = null;
  5244. }
  5245. function d3_geom_voronoiRedBlackNode(node) {
  5246. node.U = node.C = node.L = node.R = node.P = node.N = null;
  5247. }
  5248. d3_geom_voronoiRedBlackTree.prototype = {
  5249. insert: function(after, node) {
  5250. var parent, grandpa, uncle;
  5251. if (after) {
  5252. node.P = after;
  5253. node.N = after.N;
  5254. if (after.N) after.N.P = node;
  5255. after.N = node;
  5256. if (after.R) {
  5257. after = after.R;
  5258. while (after.L) after = after.L;
  5259. after.L = node;
  5260. } else {
  5261. after.R = node;
  5262. }
  5263. parent = after;
  5264. } else if (this._) {
  5265. after = d3_geom_voronoiRedBlackFirst(this._);
  5266. node.P = null;
  5267. node.N = after;
  5268. after.P = after.L = node;
  5269. parent = after;
  5270. } else {
  5271. node.P = node.N = null;
  5272. this._ = node;
  5273. parent = null;
  5274. }
  5275. node.L = node.R = null;
  5276. node.U = parent;
  5277. node.C = true;
  5278. after = node;
  5279. while (parent && parent.C) {
  5280. grandpa = parent.U;
  5281. if (parent === grandpa.L) {
  5282. uncle = grandpa.R;
  5283. if (uncle && uncle.C) {
  5284. parent.C = uncle.C = false;
  5285. grandpa.C = true;
  5286. after = grandpa;
  5287. } else {
  5288. if (after === parent.R) {
  5289. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5290. after = parent;
  5291. parent = after.U;
  5292. }
  5293. parent.C = false;
  5294. grandpa.C = true;
  5295. d3_geom_voronoiRedBlackRotateRight(this, grandpa);
  5296. }
  5297. } else {
  5298. uncle = grandpa.L;
  5299. if (uncle && uncle.C) {
  5300. parent.C = uncle.C = false;
  5301. grandpa.C = true;
  5302. after = grandpa;
  5303. } else {
  5304. if (after === parent.L) {
  5305. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5306. after = parent;
  5307. parent = after.U;
  5308. }
  5309. parent.C = false;
  5310. grandpa.C = true;
  5311. d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
  5312. }
  5313. }
  5314. parent = after.U;
  5315. }
  5316. this._.C = false;
  5317. },
  5318. remove: function(node) {
  5319. if (node.N) node.N.P = node.P;
  5320. if (node.P) node.P.N = node.N;
  5321. node.N = node.P = null;
  5322. var parent = node.U, sibling, left = node.L, right = node.R, next, red;
  5323. if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
  5324. if (parent) {
  5325. if (parent.L === node) parent.L = next; else parent.R = next;
  5326. } else {
  5327. this._ = next;
  5328. }
  5329. if (left && right) {
  5330. red = next.C;
  5331. next.C = node.C;
  5332. next.L = left;
  5333. left.U = next;
  5334. if (next !== right) {
  5335. parent = next.U;
  5336. next.U = node.U;
  5337. node = next.R;
  5338. parent.L = node;
  5339. next.R = right;
  5340. right.U = next;
  5341. } else {
  5342. next.U = parent;
  5343. parent = next;
  5344. node = next.R;
  5345. }
  5346. } else {
  5347. red = node.C;
  5348. node = next;
  5349. }
  5350. if (node) node.U = parent;
  5351. if (red) return;
  5352. if (node && node.C) {
  5353. node.C = false;
  5354. return;
  5355. }
  5356. do {
  5357. if (node === this._) break;
  5358. if (node === parent.L) {
  5359. sibling = parent.R;
  5360. if (sibling.C) {
  5361. sibling.C = false;
  5362. parent.C = true;
  5363. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5364. sibling = parent.R;
  5365. }
  5366. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5367. if (!sibling.R || !sibling.R.C) {
  5368. sibling.L.C = false;
  5369. sibling.C = true;
  5370. d3_geom_voronoiRedBlackRotateRight(this, sibling);
  5371. sibling = parent.R;
  5372. }
  5373. sibling.C = parent.C;
  5374. parent.C = sibling.R.C = false;
  5375. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5376. node = this._;
  5377. break;
  5378. }
  5379. } else {
  5380. sibling = parent.L;
  5381. if (sibling.C) {
  5382. sibling.C = false;
  5383. parent.C = true;
  5384. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5385. sibling = parent.L;
  5386. }
  5387. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5388. if (!sibling.L || !sibling.L.C) {
  5389. sibling.R.C = false;
  5390. sibling.C = true;
  5391. d3_geom_voronoiRedBlackRotateLeft(this, sibling);
  5392. sibling = parent.L;
  5393. }
  5394. sibling.C = parent.C;
  5395. parent.C = sibling.L.C = false;
  5396. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5397. node = this._;
  5398. break;
  5399. }
  5400. }
  5401. sibling.C = true;
  5402. node = parent;
  5403. parent = parent.U;
  5404. } while (!node.C);
  5405. if (node) node.C = false;
  5406. }
  5407. };
  5408. function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
  5409. var p = node, q = node.R, parent = p.U;
  5410. if (parent) {
  5411. if (parent.L === p) parent.L = q; else parent.R = q;
  5412. } else {
  5413. tree._ = q;
  5414. }
  5415. q.U = parent;
  5416. p.U = q;
  5417. p.R = q.L;
  5418. if (p.R) p.R.U = p;
  5419. q.L = p;
  5420. }
  5421. function d3_geom_voronoiRedBlackRotateRight(tree, node) {
  5422. var p = node, q = node.L, parent = p.U;
  5423. if (parent) {
  5424. if (parent.L === p) parent.L = q; else parent.R = q;
  5425. } else {
  5426. tree._ = q;
  5427. }
  5428. q.U = parent;
  5429. p.U = q;
  5430. p.L = q.R;
  5431. if (p.L) p.L.U = p;
  5432. q.R = p;
  5433. }
  5434. function d3_geom_voronoiRedBlackFirst(node) {
  5435. while (node.L) node = node.L;
  5436. return node;
  5437. }
  5438. function d3_geom_voronoi(sites, bbox) {
  5439. var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
  5440. d3_geom_voronoiEdges = [];
  5441. d3_geom_voronoiCells = new Array(sites.length);
  5442. d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
  5443. d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
  5444. while (true) {
  5445. circle = d3_geom_voronoiFirstCircle;
  5446. if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
  5447. if (site.x !== x0 || site.y !== y0) {
  5448. d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
  5449. d3_geom_voronoiAddBeach(site);
  5450. x0 = site.x, y0 = site.y;
  5451. }
  5452. site = sites.pop();
  5453. } else if (circle) {
  5454. d3_geom_voronoiRemoveBeach(circle.arc);
  5455. } else {
  5456. break;
  5457. }
  5458. }
  5459. if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
  5460. var diagram = {
  5461. cells: d3_geom_voronoiCells,
  5462. edges: d3_geom_voronoiEdges
  5463. };
  5464. d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
  5465. return diagram;
  5466. }
  5467. function d3_geom_voronoiVertexOrder(a, b) {
  5468. return b.y - a.y || b.x - a.x;
  5469. }
  5470. d3.geom.voronoi = function(points) {
  5471. var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
  5472. if (points) return voronoi(points);
  5473. function voronoi(data) {
  5474. var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
  5475. d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
  5476. var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
  5477. var s = e.start();
  5478. return [ s.x, s.y ];
  5479. }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
  5480. polygon.point = data[i];
  5481. });
  5482. return polygons;
  5483. }
  5484. function sites(data) {
  5485. return data.map(function(d, i) {
  5486. return {
  5487. x: Math.round(fx(d, i) / ε) * ε,
  5488. y: Math.round(fy(d, i) / ε) * ε,
  5489. i: i
  5490. };
  5491. });
  5492. }
  5493. voronoi.links = function(data) {
  5494. return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
  5495. return edge.l && edge.r;
  5496. }).map(function(edge) {
  5497. return {
  5498. source: data[edge.l.i],
  5499. target: data[edge.r.i]
  5500. };
  5501. });
  5502. };
  5503. voronoi.triangles = function(data) {
  5504. var triangles = [];
  5505. d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
  5506. 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;
  5507. while (++j < m) {
  5508. e0 = e1;
  5509. s0 = s1;
  5510. e1 = edges[j].edge;
  5511. s1 = e1.l === site ? e1.r : e1.l;
  5512. if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
  5513. triangles.push([ data[i], data[s0.i], data[s1.i] ]);
  5514. }
  5515. }
  5516. });
  5517. return triangles;
  5518. };
  5519. voronoi.x = function(_) {
  5520. return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
  5521. };
  5522. voronoi.y = function(_) {
  5523. return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
  5524. };
  5525. voronoi.clipExtent = function(_) {
  5526. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
  5527. clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
  5528. return voronoi;
  5529. };
  5530. voronoi.size = function(_) {
  5531. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
  5532. return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
  5533. };
  5534. return voronoi;
  5535. };
  5536. var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
  5537. function d3_geom_voronoiTriangleArea(a, b, c) {
  5538. return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
  5539. }
  5540. d3.geom.delaunay = function(vertices) {
  5541. return d3.geom.voronoi().triangles(vertices);
  5542. };
  5543. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  5544. var x = d3_geom_pointX, y = d3_geom_pointY, compat;
  5545. if (compat = arguments.length) {
  5546. x = d3_geom_quadtreeCompatX;
  5547. y = d3_geom_quadtreeCompatY;
  5548. if (compat === 3) {
  5549. y2 = y1;
  5550. x2 = x1;
  5551. y1 = x1 = 0;
  5552. }
  5553. return quadtree(points);
  5554. }
  5555. function quadtree(data) {
  5556. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  5557. if (x1 != null) {
  5558. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  5559. } else {
  5560. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  5561. xs = [], ys = [];
  5562. n = data.length;
  5563. if (compat) for (i = 0; i < n; ++i) {
  5564. d = data[i];
  5565. if (d.x < x1_) x1_ = d.x;
  5566. if (d.y < y1_) y1_ = d.y;
  5567. if (d.x > x2_) x2_ = d.x;
  5568. if (d.y > y2_) y2_ = d.y;
  5569. xs.push(d.x);
  5570. ys.push(d.y);
  5571. } else for (i = 0; i < n; ++i) {
  5572. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  5573. if (x_ < x1_) x1_ = x_;
  5574. if (y_ < y1_) y1_ = y_;
  5575. if (x_ > x2_) x2_ = x_;
  5576. if (y_ > y2_) y2_ = y_;
  5577. xs.push(x_);
  5578. ys.push(y_);
  5579. }
  5580. }
  5581. var dx = x2_ - x1_, dy = y2_ - y1_;
  5582. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  5583. function insert(n, d, x, y, x1, y1, x2, y2) {
  5584. if (isNaN(x) || isNaN(y)) return;
  5585. if (n.leaf) {
  5586. var nx = n.x, ny = n.y;
  5587. if (nx != null) {
  5588. if (abs(nx - x) + abs(ny - y) < .01) {
  5589. insertChild(n, d, x, y, x1, y1, x2, y2);
  5590. } else {
  5591. var nPoint = n.point;
  5592. n.x = n.y = n.point = null;
  5593. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  5594. insertChild(n, d, x, y, x1, y1, x2, y2);
  5595. }
  5596. } else {
  5597. n.x = x, n.y = y, n.point = d;
  5598. }
  5599. } else {
  5600. insertChild(n, d, x, y, x1, y1, x2, y2);
  5601. }
  5602. }
  5603. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  5604. var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
  5605. n.leaf = false;
  5606. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  5607. if (right) x1 = xm; else x2 = xm;
  5608. if (below) y1 = ym; else y2 = ym;
  5609. insert(n, d, x, y, x1, y1, x2, y2);
  5610. }
  5611. var root = d3_geom_quadtreeNode();
  5612. root.add = function(d) {
  5613. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  5614. };
  5615. root.visit = function(f) {
  5616. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  5617. };
  5618. root.find = function(point) {
  5619. return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
  5620. };
  5621. i = -1;
  5622. if (x1 == null) {
  5623. while (++i < n) {
  5624. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  5625. }
  5626. --i;
  5627. } else data.forEach(root.add);
  5628. xs = ys = data = d = null;
  5629. return root;
  5630. }
  5631. quadtree.x = function(_) {
  5632. return arguments.length ? (x = _, quadtree) : x;
  5633. };
  5634. quadtree.y = function(_) {
  5635. return arguments.length ? (y = _, quadtree) : y;
  5636. };
  5637. quadtree.extent = function(_) {
  5638. if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
  5639. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
  5640. y2 = +_[1][1];
  5641. return quadtree;
  5642. };
  5643. quadtree.size = function(_) {
  5644. if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
  5645. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
  5646. return quadtree;
  5647. };
  5648. return quadtree;
  5649. };
  5650. function d3_geom_quadtreeCompatX(d) {
  5651. return d.x;
  5652. }
  5653. function d3_geom_quadtreeCompatY(d) {
  5654. return d.y;
  5655. }
  5656. function d3_geom_quadtreeNode() {
  5657. return {
  5658. leaf: true,
  5659. nodes: [],
  5660. point: null,
  5661. x: null,
  5662. y: null
  5663. };
  5664. }
  5665. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  5666. if (!f(node, x1, y1, x2, y2)) {
  5667. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  5668. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  5669. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  5670. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  5671. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  5672. }
  5673. }
  5674. function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
  5675. var minDistance2 = Infinity, closestPoint;
  5676. (function find(node, x1, y1, x2, y2) {
  5677. if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
  5678. if (point = node.point) {
  5679. var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
  5680. if (distance2 < minDistance2) {
  5681. var distance = Math.sqrt(minDistance2 = distance2);
  5682. x0 = x - distance, y0 = y - distance;
  5683. x3 = x + distance, y3 = y + distance;
  5684. closestPoint = point;
  5685. }
  5686. }
  5687. var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
  5688. for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
  5689. if (node = children[i & 3]) switch (i & 3) {
  5690. case 0:
  5691. find(node, x1, y1, xm, ym);
  5692. break;
  5693. case 1:
  5694. find(node, xm, y1, x2, ym);
  5695. break;
  5696. case 2:
  5697. find(node, x1, ym, xm, y2);
  5698. break;
  5699. case 3:
  5700. find(node, xm, ym, x2, y2);
  5701. break;
  5702. }
  5703. }
  5704. })(root, x0, y0, x3, y3);
  5705. return closestPoint;
  5706. }
  5707. d3.interpolateRgb = d3_interpolateRgb;
  5708. function d3_interpolateRgb(a, b) {
  5709. a = d3.rgb(a);
  5710. b = d3.rgb(b);
  5711. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  5712. return function(t) {
  5713. 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));
  5714. };
  5715. }
  5716. d3.interpolateObject = d3_interpolateObject;
  5717. function d3_interpolateObject(a, b) {
  5718. var i = {}, c = {}, k;
  5719. for (k in a) {
  5720. if (k in b) {
  5721. i[k] = d3_interpolate(a[k], b[k]);
  5722. } else {
  5723. c[k] = a[k];
  5724. }
  5725. }
  5726. for (k in b) {
  5727. if (!(k in a)) {
  5728. c[k] = b[k];
  5729. }
  5730. }
  5731. return function(t) {
  5732. for (k in i) c[k] = i[k](t);
  5733. return c;
  5734. };
  5735. }
  5736. d3.interpolateNumber = d3_interpolateNumber;
  5737. function d3_interpolateNumber(a, b) {
  5738. a = +a, b = +b;
  5739. return function(t) {
  5740. return a * (1 - t) + b * t;
  5741. };
  5742. }
  5743. d3.interpolateString = d3_interpolateString;
  5744. function d3_interpolateString(a, b) {
  5745. var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
  5746. a = a + "", b = b + "";
  5747. while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
  5748. if ((bs = bm.index) > bi) {
  5749. bs = b.slice(bi, bs);
  5750. if (s[i]) s[i] += bs; else s[++i] = bs;
  5751. }
  5752. if ((am = am[0]) === (bm = bm[0])) {
  5753. if (s[i]) s[i] += bm; else s[++i] = bm;
  5754. } else {
  5755. s[++i] = null;
  5756. q.push({
  5757. i: i,
  5758. x: d3_interpolateNumber(am, bm)
  5759. });
  5760. }
  5761. bi = d3_interpolate_numberB.lastIndex;
  5762. }
  5763. if (bi < b.length) {
  5764. bs = b.slice(bi);
  5765. if (s[i]) s[i] += bs; else s[++i] = bs;
  5766. }
  5767. return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
  5768. return b(t) + "";
  5769. }) : function() {
  5770. return b;
  5771. } : (b = q.length, function(t) {
  5772. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  5773. return s.join("");
  5774. });
  5775. }
  5776. var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
  5777. d3.interpolate = d3_interpolate;
  5778. function d3_interpolate(a, b) {
  5779. var i = d3.interpolators.length, f;
  5780. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  5781. return f;
  5782. }
  5783. d3.interpolators = [ function(a, b) {
  5784. var t = typeof b;
  5785. return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
  5786. } ];
  5787. d3.interpolateArray = d3_interpolateArray;
  5788. function d3_interpolateArray(a, b) {
  5789. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  5790. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  5791. for (;i < na; ++i) c[i] = a[i];
  5792. for (;i < nb; ++i) c[i] = b[i];
  5793. return function(t) {
  5794. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  5795. return c;
  5796. };
  5797. }
  5798. var d3_ease_default = function() {
  5799. return d3_identity;
  5800. };
  5801. var d3_ease = d3.map({
  5802. linear: d3_ease_default,
  5803. poly: d3_ease_poly,
  5804. quad: function() {
  5805. return d3_ease_quad;
  5806. },
  5807. cubic: function() {
  5808. return d3_ease_cubic;
  5809. },
  5810. sin: function() {
  5811. return d3_ease_sin;
  5812. },
  5813. exp: function() {
  5814. return d3_ease_exp;
  5815. },
  5816. circle: function() {
  5817. return d3_ease_circle;
  5818. },
  5819. elastic: d3_ease_elastic,
  5820. back: d3_ease_back,
  5821. bounce: function() {
  5822. return d3_ease_bounce;
  5823. }
  5824. });
  5825. var d3_ease_mode = d3.map({
  5826. "in": d3_identity,
  5827. out: d3_ease_reverse,
  5828. "in-out": d3_ease_reflect,
  5829. "out-in": function(f) {
  5830. return d3_ease_reflect(d3_ease_reverse(f));
  5831. }
  5832. });
  5833. d3.ease = function(name) {
  5834. var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
  5835. t = d3_ease.get(t) || d3_ease_default;
  5836. m = d3_ease_mode.get(m) || d3_identity;
  5837. return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
  5838. };
  5839. function d3_ease_clamp(f) {
  5840. return function(t) {
  5841. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  5842. };
  5843. }
  5844. function d3_ease_reverse(f) {
  5845. return function(t) {
  5846. return 1 - f(1 - t);
  5847. };
  5848. }
  5849. function d3_ease_reflect(f) {
  5850. return function(t) {
  5851. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  5852. };
  5853. }
  5854. function d3_ease_quad(t) {
  5855. return t * t;
  5856. }
  5857. function d3_ease_cubic(t) {
  5858. return t * t * t;
  5859. }
  5860. function d3_ease_cubicInOut(t) {
  5861. if (t <= 0) return 0;
  5862. if (t >= 1) return 1;
  5863. var t2 = t * t, t3 = t2 * t;
  5864. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  5865. }
  5866. function d3_ease_poly(e) {
  5867. return function(t) {
  5868. return Math.pow(t, e);
  5869. };
  5870. }
  5871. function d3_ease_sin(t) {
  5872. return 1 - Math.cos(t * halfπ);
  5873. }
  5874. function d3_ease_exp(t) {
  5875. return Math.pow(2, 10 * (t - 1));
  5876. }
  5877. function d3_ease_circle(t) {
  5878. return 1 - Math.sqrt(1 - t * t);
  5879. }
  5880. function d3_ease_elastic(a, p) {
  5881. var s;
  5882. if (arguments.length < 2) p = .45;
  5883. if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
  5884. return function(t) {
  5885. return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
  5886. };
  5887. }
  5888. function d3_ease_back(s) {
  5889. if (!s) s = 1.70158;
  5890. return function(t) {
  5891. return t * t * ((s + 1) * t - s);
  5892. };
  5893. }
  5894. function d3_ease_bounce(t) {
  5895. 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;
  5896. }
  5897. d3.interpolateHcl = d3_interpolateHcl;
  5898. function d3_interpolateHcl(a, b) {
  5899. a = d3.hcl(a);
  5900. b = d3.hcl(b);
  5901. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  5902. if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
  5903. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5904. return function(t) {
  5905. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  5906. };
  5907. }
  5908. d3.interpolateHsl = d3_interpolateHsl;
  5909. function d3_interpolateHsl(a, b) {
  5910. a = d3.hsl(a);
  5911. b = d3.hsl(b);
  5912. var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
  5913. if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
  5914. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5915. return function(t) {
  5916. return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
  5917. };
  5918. }
  5919. d3.interpolateLab = d3_interpolateLab;
  5920. function d3_interpolateLab(a, b) {
  5921. a = d3.lab(a);
  5922. b = d3.lab(b);
  5923. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  5924. return function(t) {
  5925. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  5926. };
  5927. }
  5928. d3.interpolateRound = d3_interpolateRound;
  5929. function d3_interpolateRound(a, b) {
  5930. b -= a;
  5931. return function(t) {
  5932. return Math.round(a + b * t);
  5933. };
  5934. }
  5935. d3.transform = function(string) {
  5936. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  5937. return (d3.transform = function(string) {
  5938. if (string != null) {
  5939. g.setAttribute("transform", string);
  5940. var t = g.transform.baseVal.consolidate();
  5941. }
  5942. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  5943. })(string);
  5944. };
  5945. function d3_transform(m) {
  5946. 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;
  5947. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  5948. r0[0] *= -1;
  5949. r0[1] *= -1;
  5950. kx *= -1;
  5951. kz *= -1;
  5952. }
  5953. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  5954. this.translate = [ m.e, m.f ];
  5955. this.scale = [ kx, ky ];
  5956. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  5957. }
  5958. d3_transform.prototype.toString = function() {
  5959. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  5960. };
  5961. function d3_transformDot(a, b) {
  5962. return a[0] * b[0] + a[1] * b[1];
  5963. }
  5964. function d3_transformNormalize(a) {
  5965. var k = Math.sqrt(d3_transformDot(a, a));
  5966. if (k) {
  5967. a[0] /= k;
  5968. a[1] /= k;
  5969. }
  5970. return k;
  5971. }
  5972. function d3_transformCombine(a, b, k) {
  5973. a[0] += k * b[0];
  5974. a[1] += k * b[1];
  5975. return a;
  5976. }
  5977. var d3_transformIdentity = {
  5978. a: 1,
  5979. b: 0,
  5980. c: 0,
  5981. d: 1,
  5982. e: 0,
  5983. f: 0
  5984. };
  5985. d3.interpolateTransform = d3_interpolateTransform;
  5986. function d3_interpolateTransformPop(s) {
  5987. return s.length ? s.pop() + "," : "";
  5988. }
  5989. function d3_interpolateTranslate(ta, tb, s, q) {
  5990. if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
  5991. var i = s.push("translate(", null, ",", null, ")");
  5992. q.push({
  5993. i: i - 4,
  5994. x: d3_interpolateNumber(ta[0], tb[0])
  5995. }, {
  5996. i: i - 2,
  5997. x: d3_interpolateNumber(ta[1], tb[1])
  5998. });
  5999. } else if (tb[0] || tb[1]) {
  6000. s.push("translate(" + tb + ")");
  6001. }
  6002. }
  6003. function d3_interpolateRotate(ra, rb, s, q) {
  6004. if (ra !== rb) {
  6005. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  6006. q.push({
  6007. i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
  6008. x: d3_interpolateNumber(ra, rb)
  6009. });
  6010. } else if (rb) {
  6011. s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
  6012. }
  6013. }
  6014. function d3_interpolateSkew(wa, wb, s, q) {
  6015. if (wa !== wb) {
  6016. q.push({
  6017. i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
  6018. x: d3_interpolateNumber(wa, wb)
  6019. });
  6020. } else if (wb) {
  6021. s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
  6022. }
  6023. }
  6024. function d3_interpolateScale(ka, kb, s, q) {
  6025. if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
  6026. var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
  6027. q.push({
  6028. i: i - 4,
  6029. x: d3_interpolateNumber(ka[0], kb[0])
  6030. }, {
  6031. i: i - 2,
  6032. x: d3_interpolateNumber(ka[1], kb[1])
  6033. });
  6034. } else if (kb[0] !== 1 || kb[1] !== 1) {
  6035. s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
  6036. }
  6037. }
  6038. function d3_interpolateTransform(a, b) {
  6039. var s = [], q = [];
  6040. a = d3.transform(a), b = d3.transform(b);
  6041. d3_interpolateTranslate(a.translate, b.translate, s, q);
  6042. d3_interpolateRotate(a.rotate, b.rotate, s, q);
  6043. d3_interpolateSkew(a.skew, b.skew, s, q);
  6044. d3_interpolateScale(a.scale, b.scale, s, q);
  6045. a = b = null;
  6046. return function(t) {
  6047. var i = -1, n = q.length, o;
  6048. while (++i < n) s[(o = q[i]).i] = o.x(t);
  6049. return s.join("");
  6050. };
  6051. }
  6052. function d3_uninterpolateNumber(a, b) {
  6053. b = (b -= a = +a) || 1 / b;
  6054. return function(x) {
  6055. return (x - a) / b;
  6056. };
  6057. }
  6058. function d3_uninterpolateClamp(a, b) {
  6059. b = (b -= a = +a) || 1 / b;
  6060. return function(x) {
  6061. return Math.max(0, Math.min(1, (x - a) / b));
  6062. };
  6063. }
  6064. d3.layout = {};
  6065. d3.layout.bundle = function() {
  6066. return function(links) {
  6067. var paths = [], i = -1, n = links.length;
  6068. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  6069. return paths;
  6070. };
  6071. };
  6072. function d3_layout_bundlePath(link) {
  6073. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  6074. while (start !== lca) {
  6075. start = start.parent;
  6076. points.push(start);
  6077. }
  6078. var k = points.length;
  6079. while (end !== lca) {
  6080. points.splice(k, 0, end);
  6081. end = end.parent;
  6082. }
  6083. return points;
  6084. }
  6085. function d3_layout_bundleAncestors(node) {
  6086. var ancestors = [], parent = node.parent;
  6087. while (parent != null) {
  6088. ancestors.push(node);
  6089. node = parent;
  6090. parent = parent.parent;
  6091. }
  6092. ancestors.push(node);
  6093. return ancestors;
  6094. }
  6095. function d3_layout_bundleLeastCommonAncestor(a, b) {
  6096. if (a === b) return a;
  6097. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  6098. while (aNode === bNode) {
  6099. sharedNode = aNode;
  6100. aNode = aNodes.pop();
  6101. bNode = bNodes.pop();
  6102. }
  6103. return sharedNode;
  6104. }
  6105. d3.layout.chord = function() {
  6106. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  6107. function relayout() {
  6108. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  6109. chords = [];
  6110. groups = [];
  6111. k = 0, i = -1;
  6112. while (++i < n) {
  6113. x = 0, j = -1;
  6114. while (++j < n) {
  6115. x += matrix[i][j];
  6116. }
  6117. groupSums.push(x);
  6118. subgroupIndex.push(d3.range(n));
  6119. k += x;
  6120. }
  6121. if (sortGroups) {
  6122. groupIndex.sort(function(a, b) {
  6123. return sortGroups(groupSums[a], groupSums[b]);
  6124. });
  6125. }
  6126. if (sortSubgroups) {
  6127. subgroupIndex.forEach(function(d, i) {
  6128. d.sort(function(a, b) {
  6129. return sortSubgroups(matrix[i][a], matrix[i][b]);
  6130. });
  6131. });
  6132. }
  6133. k = (τ - padding * n) / k;
  6134. x = 0, i = -1;
  6135. while (++i < n) {
  6136. x0 = x, j = -1;
  6137. while (++j < n) {
  6138. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  6139. subgroups[di + "-" + dj] = {
  6140. index: di,
  6141. subindex: dj,
  6142. startAngle: a0,
  6143. endAngle: a1,
  6144. value: v
  6145. };
  6146. }
  6147. groups[di] = {
  6148. index: di,
  6149. startAngle: x0,
  6150. endAngle: x,
  6151. value: groupSums[di]
  6152. };
  6153. x += padding;
  6154. }
  6155. i = -1;
  6156. while (++i < n) {
  6157. j = i - 1;
  6158. while (++j < n) {
  6159. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  6160. if (source.value || target.value) {
  6161. chords.push(source.value < target.value ? {
  6162. source: target,
  6163. target: source
  6164. } : {
  6165. source: source,
  6166. target: target
  6167. });
  6168. }
  6169. }
  6170. }
  6171. if (sortChords) resort();
  6172. }
  6173. function resort() {
  6174. chords.sort(function(a, b) {
  6175. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  6176. });
  6177. }
  6178. chord.matrix = function(x) {
  6179. if (!arguments.length) return matrix;
  6180. n = (matrix = x) && matrix.length;
  6181. chords = groups = null;
  6182. return chord;
  6183. };
  6184. chord.padding = function(x) {
  6185. if (!arguments.length) return padding;
  6186. padding = x;
  6187. chords = groups = null;
  6188. return chord;
  6189. };
  6190. chord.sortGroups = function(x) {
  6191. if (!arguments.length) return sortGroups;
  6192. sortGroups = x;
  6193. chords = groups = null;
  6194. return chord;
  6195. };
  6196. chord.sortSubgroups = function(x) {
  6197. if (!arguments.length) return sortSubgroups;
  6198. sortSubgroups = x;
  6199. chords = null;
  6200. return chord;
  6201. };
  6202. chord.sortChords = function(x) {
  6203. if (!arguments.length) return sortChords;
  6204. sortChords = x;
  6205. if (chords) resort();
  6206. return chord;
  6207. };
  6208. chord.chords = function() {
  6209. if (!chords) relayout();
  6210. return chords;
  6211. };
  6212. chord.groups = function() {
  6213. if (!groups) relayout();
  6214. return groups;
  6215. };
  6216. return chord;
  6217. };
  6218. d3.layout.force = function() {
  6219. var force = {}, event = d3.dispatch("start", "tick", "end"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
  6220. function repulse(node) {
  6221. return function(quad, x1, _, x2) {
  6222. if (quad.point !== node) {
  6223. var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
  6224. if (dw * dw / theta2 < dn) {
  6225. if (dn < chargeDistance2) {
  6226. var k = quad.charge / dn;
  6227. node.px -= dx * k;
  6228. node.py -= dy * k;
  6229. }
  6230. return true;
  6231. }
  6232. if (quad.point && dn && dn < chargeDistance2) {
  6233. var k = quad.pointCharge / dn;
  6234. node.px -= dx * k;
  6235. node.py -= dy * k;
  6236. }
  6237. }
  6238. return !quad.charge;
  6239. };
  6240. }
  6241. force.tick = function() {
  6242. if ((alpha *= .99) < .005) {
  6243. timer = null;
  6244. event.end({
  6245. type: "end",
  6246. alpha: alpha = 0
  6247. });
  6248. return true;
  6249. }
  6250. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  6251. for (i = 0; i < m; ++i) {
  6252. o = links[i];
  6253. s = o.source;
  6254. t = o.target;
  6255. x = t.x - s.x;
  6256. y = t.y - s.y;
  6257. if (l = x * x + y * y) {
  6258. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  6259. x *= l;
  6260. y *= l;
  6261. t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
  6262. t.y -= y * k;
  6263. s.x += x * (k = 1 - k);
  6264. s.y += y * k;
  6265. }
  6266. }
  6267. if (k = alpha * gravity) {
  6268. x = size[0] / 2;
  6269. y = size[1] / 2;
  6270. i = -1;
  6271. if (k) while (++i < n) {
  6272. o = nodes[i];
  6273. o.x += (x - o.x) * k;
  6274. o.y += (y - o.y) * k;
  6275. }
  6276. }
  6277. if (charge) {
  6278. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  6279. i = -1;
  6280. while (++i < n) {
  6281. if (!(o = nodes[i]).fixed) {
  6282. q.visit(repulse(o));
  6283. }
  6284. }
  6285. }
  6286. i = -1;
  6287. while (++i < n) {
  6288. o = nodes[i];
  6289. if (o.fixed) {
  6290. o.x = o.px;
  6291. o.y = o.py;
  6292. } else {
  6293. o.x -= (o.px - (o.px = o.x)) * friction;
  6294. o.y -= (o.py - (o.py = o.y)) * friction;
  6295. }
  6296. }
  6297. event.tick({
  6298. type: "tick",
  6299. alpha: alpha
  6300. });
  6301. };
  6302. force.nodes = function(x) {
  6303. if (!arguments.length) return nodes;
  6304. nodes = x;
  6305. return force;
  6306. };
  6307. force.links = function(x) {
  6308. if (!arguments.length) return links;
  6309. links = x;
  6310. return force;
  6311. };
  6312. force.size = function(x) {
  6313. if (!arguments.length) return size;
  6314. size = x;
  6315. return force;
  6316. };
  6317. force.linkDistance = function(x) {
  6318. if (!arguments.length) return linkDistance;
  6319. linkDistance = typeof x === "function" ? x : +x;
  6320. return force;
  6321. };
  6322. force.distance = force.linkDistance;
  6323. force.linkStrength = function(x) {
  6324. if (!arguments.length) return linkStrength;
  6325. linkStrength = typeof x === "function" ? x : +x;
  6326. return force;
  6327. };
  6328. force.friction = function(x) {
  6329. if (!arguments.length) return friction;
  6330. friction = +x;
  6331. return force;
  6332. };
  6333. force.charge = function(x) {
  6334. if (!arguments.length) return charge;
  6335. charge = typeof x === "function" ? x : +x;
  6336. return force;
  6337. };
  6338. force.chargeDistance = function(x) {
  6339. if (!arguments.length) return Math.sqrt(chargeDistance2);
  6340. chargeDistance2 = x * x;
  6341. return force;
  6342. };
  6343. force.gravity = function(x) {
  6344. if (!arguments.length) return gravity;
  6345. gravity = +x;
  6346. return force;
  6347. };
  6348. force.theta = function(x) {
  6349. if (!arguments.length) return Math.sqrt(theta2);
  6350. theta2 = x * x;
  6351. return force;
  6352. };
  6353. force.alpha = function(x) {
  6354. if (!arguments.length) return alpha;
  6355. x = +x;
  6356. if (alpha) {
  6357. if (x > 0) {
  6358. alpha = x;
  6359. } else {
  6360. timer.c = null, timer.t = NaN, timer = null;
  6361. event.end({
  6362. type: "end",
  6363. alpha: alpha = 0
  6364. });
  6365. }
  6366. } else if (x > 0) {
  6367. event.start({
  6368. type: "start",
  6369. alpha: alpha = x
  6370. });
  6371. timer = d3_timer(force.tick);
  6372. }
  6373. return force;
  6374. };
  6375. force.start = function() {
  6376. var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  6377. for (i = 0; i < n; ++i) {
  6378. (o = nodes[i]).index = i;
  6379. o.weight = 0;
  6380. }
  6381. for (i = 0; i < m; ++i) {
  6382. o = links[i];
  6383. if (typeof o.source == "number") o.source = nodes[o.source];
  6384. if (typeof o.target == "number") o.target = nodes[o.target];
  6385. ++o.source.weight;
  6386. ++o.target.weight;
  6387. }
  6388. for (i = 0; i < n; ++i) {
  6389. o = nodes[i];
  6390. if (isNaN(o.x)) o.x = position("x", w);
  6391. if (isNaN(o.y)) o.y = position("y", h);
  6392. if (isNaN(o.px)) o.px = o.x;
  6393. if (isNaN(o.py)) o.py = o.y;
  6394. }
  6395. distances = [];
  6396. 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;
  6397. strengths = [];
  6398. 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;
  6399. charges = [];
  6400. 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;
  6401. function position(dimension, size) {
  6402. if (!neighbors) {
  6403. neighbors = new Array(n);
  6404. for (j = 0; j < n; ++j) {
  6405. neighbors[j] = [];
  6406. }
  6407. for (j = 0; j < m; ++j) {
  6408. var o = links[j];
  6409. neighbors[o.source.index].push(o.target);
  6410. neighbors[o.target.index].push(o.source);
  6411. }
  6412. }
  6413. var candidates = neighbors[i], j = -1, l = candidates.length, x;
  6414. while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
  6415. return Math.random() * size;
  6416. }
  6417. return force.resume();
  6418. };
  6419. force.resume = function() {
  6420. return force.alpha(.1);
  6421. };
  6422. force.stop = function() {
  6423. return force.alpha(0);
  6424. };
  6425. force.drag = function() {
  6426. 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);
  6427. if (!arguments.length) return drag;
  6428. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  6429. };
  6430. function dragmove(d) {
  6431. d.px = d3.event.x, d.py = d3.event.y;
  6432. force.resume();
  6433. }
  6434. return d3.rebind(force, event, "on");
  6435. };
  6436. function d3_layout_forceDragstart(d) {
  6437. d.fixed |= 2;
  6438. }
  6439. function d3_layout_forceDragend(d) {
  6440. d.fixed &= ~6;
  6441. }
  6442. function d3_layout_forceMouseover(d) {
  6443. d.fixed |= 4;
  6444. d.px = d.x, d.py = d.y;
  6445. }
  6446. function d3_layout_forceMouseout(d) {
  6447. d.fixed &= ~4;
  6448. }
  6449. function d3_layout_forceAccumulate(quad, alpha, charges) {
  6450. var cx = 0, cy = 0;
  6451. quad.charge = 0;
  6452. if (!quad.leaf) {
  6453. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  6454. while (++i < n) {
  6455. c = nodes[i];
  6456. if (c == null) continue;
  6457. d3_layout_forceAccumulate(c, alpha, charges);
  6458. quad.charge += c.charge;
  6459. cx += c.charge * c.cx;
  6460. cy += c.charge * c.cy;
  6461. }
  6462. }
  6463. if (quad.point) {
  6464. if (!quad.leaf) {
  6465. quad.point.x += Math.random() - .5;
  6466. quad.point.y += Math.random() - .5;
  6467. }
  6468. var k = alpha * charges[quad.point.index];
  6469. quad.charge += quad.pointCharge = k;
  6470. cx += k * quad.point.x;
  6471. cy += k * quad.point.y;
  6472. }
  6473. quad.cx = cx / quad.charge;
  6474. quad.cy = cy / quad.charge;
  6475. }
  6476. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
  6477. d3.layout.hierarchy = function() {
  6478. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  6479. function hierarchy(root) {
  6480. var stack = [ root ], nodes = [], node;
  6481. root.depth = 0;
  6482. while ((node = stack.pop()) != null) {
  6483. nodes.push(node);
  6484. if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
  6485. var n, childs, child;
  6486. while (--n >= 0) {
  6487. stack.push(child = childs[n]);
  6488. child.parent = node;
  6489. child.depth = node.depth + 1;
  6490. }
  6491. if (value) node.value = 0;
  6492. node.children = childs;
  6493. } else {
  6494. if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6495. delete node.children;
  6496. }
  6497. }
  6498. d3_layout_hierarchyVisitAfter(root, function(node) {
  6499. var childs, parent;
  6500. if (sort && (childs = node.children)) childs.sort(sort);
  6501. if (value && (parent = node.parent)) parent.value += node.value;
  6502. });
  6503. return nodes;
  6504. }
  6505. hierarchy.sort = function(x) {
  6506. if (!arguments.length) return sort;
  6507. sort = x;
  6508. return hierarchy;
  6509. };
  6510. hierarchy.children = function(x) {
  6511. if (!arguments.length) return children;
  6512. children = x;
  6513. return hierarchy;
  6514. };
  6515. hierarchy.value = function(x) {
  6516. if (!arguments.length) return value;
  6517. value = x;
  6518. return hierarchy;
  6519. };
  6520. hierarchy.revalue = function(root) {
  6521. if (value) {
  6522. d3_layout_hierarchyVisitBefore(root, function(node) {
  6523. if (node.children) node.value = 0;
  6524. });
  6525. d3_layout_hierarchyVisitAfter(root, function(node) {
  6526. var parent;
  6527. if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6528. if (parent = node.parent) parent.value += node.value;
  6529. });
  6530. }
  6531. return root;
  6532. };
  6533. return hierarchy;
  6534. };
  6535. function d3_layout_hierarchyRebind(object, hierarchy) {
  6536. d3.rebind(object, hierarchy, "sort", "children", "value");
  6537. object.nodes = object;
  6538. object.links = d3_layout_hierarchyLinks;
  6539. return object;
  6540. }
  6541. function d3_layout_hierarchyVisitBefore(node, callback) {
  6542. var nodes = [ node ];
  6543. while ((node = nodes.pop()) != null) {
  6544. callback(node);
  6545. if ((children = node.children) && (n = children.length)) {
  6546. var n, children;
  6547. while (--n >= 0) nodes.push(children[n]);
  6548. }
  6549. }
  6550. }
  6551. function d3_layout_hierarchyVisitAfter(node, callback) {
  6552. var nodes = [ node ], nodes2 = [];
  6553. while ((node = nodes.pop()) != null) {
  6554. nodes2.push(node);
  6555. if ((children = node.children) && (n = children.length)) {
  6556. var i = -1, n, children;
  6557. while (++i < n) nodes.push(children[i]);
  6558. }
  6559. }
  6560. while ((node = nodes2.pop()) != null) {
  6561. callback(node);
  6562. }
  6563. }
  6564. function d3_layout_hierarchyChildren(d) {
  6565. return d.children;
  6566. }
  6567. function d3_layout_hierarchyValue(d) {
  6568. return d.value;
  6569. }
  6570. function d3_layout_hierarchySort(a, b) {
  6571. return b.value - a.value;
  6572. }
  6573. function d3_layout_hierarchyLinks(nodes) {
  6574. return d3.merge(nodes.map(function(parent) {
  6575. return (parent.children || []).map(function(child) {
  6576. return {
  6577. source: parent,
  6578. target: child
  6579. };
  6580. });
  6581. }));
  6582. }
  6583. d3.layout.partition = function() {
  6584. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  6585. function position(node, x, dx, dy) {
  6586. var children = node.children;
  6587. node.x = x;
  6588. node.y = node.depth * dy;
  6589. node.dx = dx;
  6590. node.dy = dy;
  6591. if (children && (n = children.length)) {
  6592. var i = -1, n, c, d;
  6593. dx = node.value ? dx / node.value : 0;
  6594. while (++i < n) {
  6595. position(c = children[i], x, d = c.value * dx, dy);
  6596. x += d;
  6597. }
  6598. }
  6599. }
  6600. function depth(node) {
  6601. var children = node.children, d = 0;
  6602. if (children && (n = children.length)) {
  6603. var i = -1, n;
  6604. while (++i < n) d = Math.max(d, depth(children[i]));
  6605. }
  6606. return 1 + d;
  6607. }
  6608. function partition(d, i) {
  6609. var nodes = hierarchy.call(this, d, i);
  6610. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  6611. return nodes;
  6612. }
  6613. partition.size = function(x) {
  6614. if (!arguments.length) return size;
  6615. size = x;
  6616. return partition;
  6617. };
  6618. return d3_layout_hierarchyRebind(partition, hierarchy);
  6619. };
  6620. d3.layout.pie = function() {
  6621. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
  6622. function pie(data) {
  6623. var n = data.length, values = data.map(function(d, i) {
  6624. return +value.call(pie, d, i);
  6625. }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;
  6626. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  6627. return values[j] - values[i];
  6628. } : function(i, j) {
  6629. return sort(data[i], data[j]);
  6630. });
  6631. index.forEach(function(i) {
  6632. arcs[i] = {
  6633. data: data[i],
  6634. value: v = values[i],
  6635. startAngle: a,
  6636. endAngle: a += v * k + pa,
  6637. padAngle: p
  6638. };
  6639. });
  6640. return arcs;
  6641. }
  6642. pie.value = function(_) {
  6643. if (!arguments.length) return value;
  6644. value = _;
  6645. return pie;
  6646. };
  6647. pie.sort = function(_) {
  6648. if (!arguments.length) return sort;
  6649. sort = _;
  6650. return pie;
  6651. };
  6652. pie.startAngle = function(_) {
  6653. if (!arguments.length) return startAngle;
  6654. startAngle = _;
  6655. return pie;
  6656. };
  6657. pie.endAngle = function(_) {
  6658. if (!arguments.length) return endAngle;
  6659. endAngle = _;
  6660. return pie;
  6661. };
  6662. pie.padAngle = function(_) {
  6663. if (!arguments.length) return padAngle;
  6664. padAngle = _;
  6665. return pie;
  6666. };
  6667. return pie;
  6668. };
  6669. var d3_layout_pieSortByValue = {};
  6670. d3.layout.stack = function() {
  6671. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  6672. function stack(data, index) {
  6673. if (!(n = data.length)) return data;
  6674. var series = data.map(function(d, i) {
  6675. return values.call(stack, d, i);
  6676. });
  6677. var points = series.map(function(d) {
  6678. return d.map(function(v, i) {
  6679. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  6680. });
  6681. });
  6682. var orders = order.call(stack, points, index);
  6683. series = d3.permute(series, orders);
  6684. points = d3.permute(points, orders);
  6685. var offsets = offset.call(stack, points, index);
  6686. var m = series[0].length, n, i, j, o;
  6687. for (j = 0; j < m; ++j) {
  6688. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  6689. for (i = 1; i < n; ++i) {
  6690. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  6691. }
  6692. }
  6693. return data;
  6694. }
  6695. stack.values = function(x) {
  6696. if (!arguments.length) return values;
  6697. values = x;
  6698. return stack;
  6699. };
  6700. stack.order = function(x) {
  6701. if (!arguments.length) return order;
  6702. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  6703. return stack;
  6704. };
  6705. stack.offset = function(x) {
  6706. if (!arguments.length) return offset;
  6707. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  6708. return stack;
  6709. };
  6710. stack.x = function(z) {
  6711. if (!arguments.length) return x;
  6712. x = z;
  6713. return stack;
  6714. };
  6715. stack.y = function(z) {
  6716. if (!arguments.length) return y;
  6717. y = z;
  6718. return stack;
  6719. };
  6720. stack.out = function(z) {
  6721. if (!arguments.length) return out;
  6722. out = z;
  6723. return stack;
  6724. };
  6725. return stack;
  6726. };
  6727. function d3_layout_stackX(d) {
  6728. return d.x;
  6729. }
  6730. function d3_layout_stackY(d) {
  6731. return d.y;
  6732. }
  6733. function d3_layout_stackOut(d, y0, y) {
  6734. d.y0 = y0;
  6735. d.y = y;
  6736. }
  6737. var d3_layout_stackOrders = d3.map({
  6738. "inside-out": function(data) {
  6739. 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) {
  6740. return max[a] - max[b];
  6741. }), top = 0, bottom = 0, tops = [], bottoms = [];
  6742. for (i = 0; i < n; ++i) {
  6743. j = index[i];
  6744. if (top < bottom) {
  6745. top += sums[j];
  6746. tops.push(j);
  6747. } else {
  6748. bottom += sums[j];
  6749. bottoms.push(j);
  6750. }
  6751. }
  6752. return bottoms.reverse().concat(tops);
  6753. },
  6754. reverse: function(data) {
  6755. return d3.range(data.length).reverse();
  6756. },
  6757. "default": d3_layout_stackOrderDefault
  6758. });
  6759. var d3_layout_stackOffsets = d3.map({
  6760. silhouette: function(data) {
  6761. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  6762. for (j = 0; j < m; ++j) {
  6763. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6764. if (o > max) max = o;
  6765. sums.push(o);
  6766. }
  6767. for (j = 0; j < m; ++j) {
  6768. y0[j] = (max - sums[j]) / 2;
  6769. }
  6770. return y0;
  6771. },
  6772. wiggle: function(data) {
  6773. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  6774. y0[0] = o = o0 = 0;
  6775. for (j = 1; j < m; ++j) {
  6776. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  6777. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  6778. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  6779. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  6780. }
  6781. s2 += s3 * data[i][j][1];
  6782. }
  6783. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  6784. if (o < o0) o0 = o;
  6785. }
  6786. for (j = 0; j < m; ++j) y0[j] -= o0;
  6787. return y0;
  6788. },
  6789. expand: function(data) {
  6790. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  6791. for (j = 0; j < m; ++j) {
  6792. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6793. if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
  6794. }
  6795. for (j = 0; j < m; ++j) y0[j] = 0;
  6796. return y0;
  6797. },
  6798. zero: d3_layout_stackOffsetZero
  6799. });
  6800. function d3_layout_stackOrderDefault(data) {
  6801. return d3.range(data.length);
  6802. }
  6803. function d3_layout_stackOffsetZero(data) {
  6804. var j = -1, m = data[0].length, y0 = [];
  6805. while (++j < m) y0[j] = 0;
  6806. return y0;
  6807. }
  6808. function d3_layout_stackMaxIndex(array) {
  6809. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  6810. for (;i < n; ++i) {
  6811. if ((k = array[i][1]) > v) {
  6812. j = i;
  6813. v = k;
  6814. }
  6815. }
  6816. return j;
  6817. }
  6818. function d3_layout_stackReduceSum(d) {
  6819. return d.reduce(d3_layout_stackSum, 0);
  6820. }
  6821. function d3_layout_stackSum(p, d) {
  6822. return p + d[1];
  6823. }
  6824. d3.layout.histogram = function() {
  6825. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  6826. function histogram(data, i) {
  6827. 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;
  6828. while (++i < m) {
  6829. bin = bins[i] = [];
  6830. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  6831. bin.y = 0;
  6832. }
  6833. if (m > 0) {
  6834. i = -1;
  6835. while (++i < n) {
  6836. x = values[i];
  6837. if (x >= range[0] && x <= range[1]) {
  6838. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  6839. bin.y += k;
  6840. bin.push(data[i]);
  6841. }
  6842. }
  6843. }
  6844. return bins;
  6845. }
  6846. histogram.value = function(x) {
  6847. if (!arguments.length) return valuer;
  6848. valuer = x;
  6849. return histogram;
  6850. };
  6851. histogram.range = function(x) {
  6852. if (!arguments.length) return ranger;
  6853. ranger = d3_functor(x);
  6854. return histogram;
  6855. };
  6856. histogram.bins = function(x) {
  6857. if (!arguments.length) return binner;
  6858. binner = typeof x === "number" ? function(range) {
  6859. return d3_layout_histogramBinFixed(range, x);
  6860. } : d3_functor(x);
  6861. return histogram;
  6862. };
  6863. histogram.frequency = function(x) {
  6864. if (!arguments.length) return frequency;
  6865. frequency = !!x;
  6866. return histogram;
  6867. };
  6868. return histogram;
  6869. };
  6870. function d3_layout_histogramBinSturges(range, values) {
  6871. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  6872. }
  6873. function d3_layout_histogramBinFixed(range, n) {
  6874. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  6875. while (++x <= n) f[x] = m * x + b;
  6876. return f;
  6877. }
  6878. function d3_layout_histogramRange(values) {
  6879. return [ d3.min(values), d3.max(values) ];
  6880. }
  6881. d3.layout.pack = function() {
  6882. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
  6883. function pack(d, i) {
  6884. 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() {
  6885. return radius;
  6886. };
  6887. root.x = root.y = 0;
  6888. d3_layout_hierarchyVisitAfter(root, function(d) {
  6889. d.r = +r(d.value);
  6890. });
  6891. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6892. if (padding) {
  6893. var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
  6894. d3_layout_hierarchyVisitAfter(root, function(d) {
  6895. d.r += dr;
  6896. });
  6897. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6898. d3_layout_hierarchyVisitAfter(root, function(d) {
  6899. d.r -= dr;
  6900. });
  6901. }
  6902. d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
  6903. return nodes;
  6904. }
  6905. pack.size = function(_) {
  6906. if (!arguments.length) return size;
  6907. size = _;
  6908. return pack;
  6909. };
  6910. pack.radius = function(_) {
  6911. if (!arguments.length) return radius;
  6912. radius = _ == null || typeof _ === "function" ? _ : +_;
  6913. return pack;
  6914. };
  6915. pack.padding = function(_) {
  6916. if (!arguments.length) return padding;
  6917. padding = +_;
  6918. return pack;
  6919. };
  6920. return d3_layout_hierarchyRebind(pack, hierarchy);
  6921. };
  6922. function d3_layout_packSort(a, b) {
  6923. return a.value - b.value;
  6924. }
  6925. function d3_layout_packInsert(a, b) {
  6926. var c = a._pack_next;
  6927. a._pack_next = b;
  6928. b._pack_prev = a;
  6929. b._pack_next = c;
  6930. c._pack_prev = b;
  6931. }
  6932. function d3_layout_packSplice(a, b) {
  6933. a._pack_next = b;
  6934. b._pack_prev = a;
  6935. }
  6936. function d3_layout_packIntersects(a, b) {
  6937. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  6938. return .999 * dr * dr > dx * dx + dy * dy;
  6939. }
  6940. function d3_layout_packSiblings(node) {
  6941. if (!(nodes = node.children) || !(n = nodes.length)) return;
  6942. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  6943. function bound(node) {
  6944. xMin = Math.min(node.x - node.r, xMin);
  6945. xMax = Math.max(node.x + node.r, xMax);
  6946. yMin = Math.min(node.y - node.r, yMin);
  6947. yMax = Math.max(node.y + node.r, yMax);
  6948. }
  6949. nodes.forEach(d3_layout_packLink);
  6950. a = nodes[0];
  6951. a.x = -a.r;
  6952. a.y = 0;
  6953. bound(a);
  6954. if (n > 1) {
  6955. b = nodes[1];
  6956. b.x = b.r;
  6957. b.y = 0;
  6958. bound(b);
  6959. if (n > 2) {
  6960. c = nodes[2];
  6961. d3_layout_packPlace(a, b, c);
  6962. bound(c);
  6963. d3_layout_packInsert(a, c);
  6964. a._pack_prev = c;
  6965. d3_layout_packInsert(c, b);
  6966. b = a._pack_next;
  6967. for (i = 3; i < n; i++) {
  6968. d3_layout_packPlace(a, b, c = nodes[i]);
  6969. var isect = 0, s1 = 1, s2 = 1;
  6970. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  6971. if (d3_layout_packIntersects(j, c)) {
  6972. isect = 1;
  6973. break;
  6974. }
  6975. }
  6976. if (isect == 1) {
  6977. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  6978. if (d3_layout_packIntersects(k, c)) {
  6979. break;
  6980. }
  6981. }
  6982. }
  6983. if (isect) {
  6984. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  6985. i--;
  6986. } else {
  6987. d3_layout_packInsert(a, c);
  6988. b = c;
  6989. bound(c);
  6990. }
  6991. }
  6992. }
  6993. }
  6994. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  6995. for (i = 0; i < n; i++) {
  6996. c = nodes[i];
  6997. c.x -= cx;
  6998. c.y -= cy;
  6999. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  7000. }
  7001. node.r = cr;
  7002. nodes.forEach(d3_layout_packUnlink);
  7003. }
  7004. function d3_layout_packLink(node) {
  7005. node._pack_next = node._pack_prev = node;
  7006. }
  7007. function d3_layout_packUnlink(node) {
  7008. delete node._pack_next;
  7009. delete node._pack_prev;
  7010. }
  7011. function d3_layout_packTransform(node, x, y, k) {
  7012. var children = node.children;
  7013. node.x = x += k * node.x;
  7014. node.y = y += k * node.y;
  7015. node.r *= k;
  7016. if (children) {
  7017. var i = -1, n = children.length;
  7018. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  7019. }
  7020. }
  7021. function d3_layout_packPlace(a, b, c) {
  7022. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  7023. if (db && (dx || dy)) {
  7024. var da = b.r + c.r, dc = dx * dx + dy * dy;
  7025. da *= da;
  7026. db *= db;
  7027. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  7028. c.x = a.x + x * dx + y * dy;
  7029. c.y = a.y + x * dy - y * dx;
  7030. } else {
  7031. c.x = a.x + db;
  7032. c.y = a.y;
  7033. }
  7034. }
  7035. d3.layout.tree = function() {
  7036. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
  7037. function tree(d, i) {
  7038. var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
  7039. d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
  7040. d3_layout_hierarchyVisitBefore(root1, secondWalk);
  7041. if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
  7042. var left = root0, right = root0, bottom = root0;
  7043. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7044. if (node.x < left.x) left = node;
  7045. if (node.x > right.x) right = node;
  7046. if (node.depth > bottom.depth) bottom = node;
  7047. });
  7048. var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
  7049. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7050. node.x = (node.x + tx) * kx;
  7051. node.y = node.depth * ky;
  7052. });
  7053. }
  7054. return nodes;
  7055. }
  7056. function wrapTree(root0) {
  7057. var root1 = {
  7058. A: null,
  7059. children: [ root0 ]
  7060. }, queue = [ root1 ], node1;
  7061. while ((node1 = queue.pop()) != null) {
  7062. for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
  7063. queue.push((children[i] = child = {
  7064. _: children[i],
  7065. parent: node1,
  7066. children: (child = children[i].children) && child.slice() || [],
  7067. A: null,
  7068. a: null,
  7069. z: 0,
  7070. m: 0,
  7071. c: 0,
  7072. s: 0,
  7073. t: null,
  7074. i: i
  7075. }).a = child);
  7076. }
  7077. }
  7078. return root1.children[0];
  7079. }
  7080. function firstWalk(v) {
  7081. var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
  7082. if (children.length) {
  7083. d3_layout_treeShift(v);
  7084. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  7085. if (w) {
  7086. v.z = w.z + separation(v._, w._);
  7087. v.m = v.z - midpoint;
  7088. } else {
  7089. v.z = midpoint;
  7090. }
  7091. } else if (w) {
  7092. v.z = w.z + separation(v._, w._);
  7093. }
  7094. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  7095. }
  7096. function secondWalk(v) {
  7097. v._.x = v.z + v.parent.m;
  7098. v.m += v.parent.m;
  7099. }
  7100. function apportion(v, w, ancestor) {
  7101. if (w) {
  7102. 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;
  7103. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  7104. vom = d3_layout_treeLeft(vom);
  7105. vop = d3_layout_treeRight(vop);
  7106. vop.a = v;
  7107. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  7108. if (shift > 0) {
  7109. d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
  7110. sip += shift;
  7111. sop += shift;
  7112. }
  7113. sim += vim.m;
  7114. sip += vip.m;
  7115. som += vom.m;
  7116. sop += vop.m;
  7117. }
  7118. if (vim && !d3_layout_treeRight(vop)) {
  7119. vop.t = vim;
  7120. vop.m += sim - sop;
  7121. }
  7122. if (vip && !d3_layout_treeLeft(vom)) {
  7123. vom.t = vip;
  7124. vom.m += sip - som;
  7125. ancestor = v;
  7126. }
  7127. }
  7128. return ancestor;
  7129. }
  7130. function sizeNode(node) {
  7131. node.x *= size[0];
  7132. node.y = node.depth * size[1];
  7133. }
  7134. tree.separation = function(x) {
  7135. if (!arguments.length) return separation;
  7136. separation = x;
  7137. return tree;
  7138. };
  7139. tree.size = function(x) {
  7140. if (!arguments.length) return nodeSize ? null : size;
  7141. nodeSize = (size = x) == null ? sizeNode : null;
  7142. return tree;
  7143. };
  7144. tree.nodeSize = function(x) {
  7145. if (!arguments.length) return nodeSize ? size : null;
  7146. nodeSize = (size = x) == null ? null : sizeNode;
  7147. return tree;
  7148. };
  7149. return d3_layout_hierarchyRebind(tree, hierarchy);
  7150. };
  7151. function d3_layout_treeSeparation(a, b) {
  7152. return a.parent == b.parent ? 1 : 2;
  7153. }
  7154. function d3_layout_treeLeft(v) {
  7155. var children = v.children;
  7156. return children.length ? children[0] : v.t;
  7157. }
  7158. function d3_layout_treeRight(v) {
  7159. var children = v.children, n;
  7160. return (n = children.length) ? children[n - 1] : v.t;
  7161. }
  7162. function d3_layout_treeMove(wm, wp, shift) {
  7163. var change = shift / (wp.i - wm.i);
  7164. wp.c -= change;
  7165. wp.s += shift;
  7166. wm.c += change;
  7167. wp.z += shift;
  7168. wp.m += shift;
  7169. }
  7170. function d3_layout_treeShift(v) {
  7171. var shift = 0, change = 0, children = v.children, i = children.length, w;
  7172. while (--i >= 0) {
  7173. w = children[i];
  7174. w.z += shift;
  7175. w.m += shift;
  7176. shift += w.s + (change += w.c);
  7177. }
  7178. }
  7179. function d3_layout_treeAncestor(vim, v, ancestor) {
  7180. return vim.a.parent === v.parent ? vim.a : ancestor;
  7181. }
  7182. d3.layout.cluster = function() {
  7183. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  7184. function cluster(d, i) {
  7185. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  7186. d3_layout_hierarchyVisitAfter(root, function(node) {
  7187. var children = node.children;
  7188. if (children && children.length) {
  7189. node.x = d3_layout_clusterX(children);
  7190. node.y = d3_layout_clusterY(children);
  7191. } else {
  7192. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7193. node.y = 0;
  7194. previousNode = node;
  7195. }
  7196. });
  7197. 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;
  7198. d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
  7199. node.x = (node.x - root.x) * size[0];
  7200. node.y = (root.y - node.y) * size[1];
  7201. } : function(node) {
  7202. node.x = (node.x - x0) / (x1 - x0) * size[0];
  7203. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  7204. });
  7205. return nodes;
  7206. }
  7207. cluster.separation = function(x) {
  7208. if (!arguments.length) return separation;
  7209. separation = x;
  7210. return cluster;
  7211. };
  7212. cluster.size = function(x) {
  7213. if (!arguments.length) return nodeSize ? null : size;
  7214. nodeSize = (size = x) == null;
  7215. return cluster;
  7216. };
  7217. cluster.nodeSize = function(x) {
  7218. if (!arguments.length) return nodeSize ? size : null;
  7219. nodeSize = (size = x) != null;
  7220. return cluster;
  7221. };
  7222. return d3_layout_hierarchyRebind(cluster, hierarchy);
  7223. };
  7224. function d3_layout_clusterY(children) {
  7225. return 1 + d3.max(children, function(child) {
  7226. return child.y;
  7227. });
  7228. }
  7229. function d3_layout_clusterX(children) {
  7230. return children.reduce(function(x, child) {
  7231. return x + child.x;
  7232. }, 0) / children.length;
  7233. }
  7234. function d3_layout_clusterLeft(node) {
  7235. var children = node.children;
  7236. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  7237. }
  7238. function d3_layout_clusterRight(node) {
  7239. var children = node.children, n;
  7240. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  7241. }
  7242. d3.layout.treemap = function() {
  7243. 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));
  7244. function scale(children, k) {
  7245. var i = -1, n = children.length, child, area;
  7246. while (++i < n) {
  7247. area = (child = children[i]).value * (k < 0 ? 0 : k);
  7248. child.area = isNaN(area) || area <= 0 ? 0 : area;
  7249. }
  7250. }
  7251. function squarify(node) {
  7252. var children = node.children;
  7253. if (children && children.length) {
  7254. 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;
  7255. scale(remaining, rect.dx * rect.dy / node.value);
  7256. row.area = 0;
  7257. while ((n = remaining.length) > 0) {
  7258. row.push(child = remaining[n - 1]);
  7259. row.area += child.area;
  7260. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  7261. remaining.pop();
  7262. best = score;
  7263. } else {
  7264. row.area -= row.pop().area;
  7265. position(row, u, rect, false);
  7266. u = Math.min(rect.dx, rect.dy);
  7267. row.length = row.area = 0;
  7268. best = Infinity;
  7269. }
  7270. }
  7271. if (row.length) {
  7272. position(row, u, rect, true);
  7273. row.length = row.area = 0;
  7274. }
  7275. children.forEach(squarify);
  7276. }
  7277. }
  7278. function stickify(node) {
  7279. var children = node.children;
  7280. if (children && children.length) {
  7281. var rect = pad(node), remaining = children.slice(), child, row = [];
  7282. scale(remaining, rect.dx * rect.dy / node.value);
  7283. row.area = 0;
  7284. while (child = remaining.pop()) {
  7285. row.push(child);
  7286. row.area += child.area;
  7287. if (child.z != null) {
  7288. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  7289. row.length = row.area = 0;
  7290. }
  7291. }
  7292. children.forEach(stickify);
  7293. }
  7294. }
  7295. function worst(row, u) {
  7296. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  7297. while (++i < n) {
  7298. if (!(r = row[i].area)) continue;
  7299. if (r < rmin) rmin = r;
  7300. if (r > rmax) rmax = r;
  7301. }
  7302. s *= s;
  7303. u *= u;
  7304. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  7305. }
  7306. function position(row, u, rect, flush) {
  7307. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  7308. if (u == rect.dx) {
  7309. if (flush || v > rect.dy) v = rect.dy;
  7310. while (++i < n) {
  7311. o = row[i];
  7312. o.x = x;
  7313. o.y = y;
  7314. o.dy = v;
  7315. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  7316. }
  7317. o.z = true;
  7318. o.dx += rect.x + rect.dx - x;
  7319. rect.y += v;
  7320. rect.dy -= v;
  7321. } else {
  7322. if (flush || v > rect.dx) v = rect.dx;
  7323. while (++i < n) {
  7324. o = row[i];
  7325. o.x = x;
  7326. o.y = y;
  7327. o.dx = v;
  7328. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  7329. }
  7330. o.z = false;
  7331. o.dy += rect.y + rect.dy - y;
  7332. rect.x += v;
  7333. rect.dx -= v;
  7334. }
  7335. }
  7336. function treemap(d) {
  7337. var nodes = stickies || hierarchy(d), root = nodes[0];
  7338. root.x = root.y = 0;
  7339. if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
  7340. if (stickies) hierarchy.revalue(root);
  7341. scale([ root ], root.dx * root.dy / root.value);
  7342. (stickies ? stickify : squarify)(root);
  7343. if (sticky) stickies = nodes;
  7344. return nodes;
  7345. }
  7346. treemap.size = function(x) {
  7347. if (!arguments.length) return size;
  7348. size = x;
  7349. return treemap;
  7350. };
  7351. treemap.padding = function(x) {
  7352. if (!arguments.length) return padding;
  7353. function padFunction(node) {
  7354. var p = x.call(treemap, node, node.depth);
  7355. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  7356. }
  7357. function padConstant(node) {
  7358. return d3_layout_treemapPad(node, x);
  7359. }
  7360. var type;
  7361. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  7362. padConstant) : padConstant;
  7363. return treemap;
  7364. };
  7365. treemap.round = function(x) {
  7366. if (!arguments.length) return round != Number;
  7367. round = x ? Math.round : Number;
  7368. return treemap;
  7369. };
  7370. treemap.sticky = function(x) {
  7371. if (!arguments.length) return sticky;
  7372. sticky = x;
  7373. stickies = null;
  7374. return treemap;
  7375. };
  7376. treemap.ratio = function(x) {
  7377. if (!arguments.length) return ratio;
  7378. ratio = x;
  7379. return treemap;
  7380. };
  7381. treemap.mode = function(x) {
  7382. if (!arguments.length) return mode;
  7383. mode = x + "";
  7384. return treemap;
  7385. };
  7386. return d3_layout_hierarchyRebind(treemap, hierarchy);
  7387. };
  7388. function d3_layout_treemapPadNull(node) {
  7389. return {
  7390. x: node.x,
  7391. y: node.y,
  7392. dx: node.dx,
  7393. dy: node.dy
  7394. };
  7395. }
  7396. function d3_layout_treemapPad(node, padding) {
  7397. 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];
  7398. if (dx < 0) {
  7399. x += dx / 2;
  7400. dx = 0;
  7401. }
  7402. if (dy < 0) {
  7403. y += dy / 2;
  7404. dy = 0;
  7405. }
  7406. return {
  7407. x: x,
  7408. y: y,
  7409. dx: dx,
  7410. dy: dy
  7411. };
  7412. }
  7413. d3.random = {
  7414. normal: function(µ, σ) {
  7415. var n = arguments.length;
  7416. if (n < 2) σ = 1;
  7417. if (n < 1) µ = 0;
  7418. return function() {
  7419. var x, y, r;
  7420. do {
  7421. x = Math.random() * 2 - 1;
  7422. y = Math.random() * 2 - 1;
  7423. r = x * x + y * y;
  7424. } while (!r || r > 1);
  7425. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  7426. };
  7427. },
  7428. logNormal: function() {
  7429. var random = d3.random.normal.apply(d3, arguments);
  7430. return function() {
  7431. return Math.exp(random());
  7432. };
  7433. },
  7434. bates: function(m) {
  7435. var random = d3.random.irwinHall(m);
  7436. return function() {
  7437. return random() / m;
  7438. };
  7439. },
  7440. irwinHall: function(m) {
  7441. return function() {
  7442. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  7443. return s;
  7444. };
  7445. }
  7446. };
  7447. d3.scale = {};
  7448. function d3_scaleExtent(domain) {
  7449. var start = domain[0], stop = domain[domain.length - 1];
  7450. return start < stop ? [ start, stop ] : [ stop, start ];
  7451. }
  7452. function d3_scaleRange(scale) {
  7453. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  7454. }
  7455. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  7456. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  7457. return function(x) {
  7458. return i(u(x));
  7459. };
  7460. }
  7461. function d3_scale_nice(domain, nice) {
  7462. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  7463. if (x1 < x0) {
  7464. dx = i0, i0 = i1, i1 = dx;
  7465. dx = x0, x0 = x1, x1 = dx;
  7466. }
  7467. domain[i0] = nice.floor(x0);
  7468. domain[i1] = nice.ceil(x1);
  7469. return domain;
  7470. }
  7471. function d3_scale_niceStep(step) {
  7472. return step ? {
  7473. floor: function(x) {
  7474. return Math.floor(x / step) * step;
  7475. },
  7476. ceil: function(x) {
  7477. return Math.ceil(x / step) * step;
  7478. }
  7479. } : d3_scale_niceIdentity;
  7480. }
  7481. var d3_scale_niceIdentity = {
  7482. floor: d3_identity,
  7483. ceil: d3_identity
  7484. };
  7485. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  7486. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  7487. if (domain[k] < domain[0]) {
  7488. domain = domain.slice().reverse();
  7489. range = range.slice().reverse();
  7490. }
  7491. while (++j <= k) {
  7492. u.push(uninterpolate(domain[j - 1], domain[j]));
  7493. i.push(interpolate(range[j - 1], range[j]));
  7494. }
  7495. return function(x) {
  7496. var j = d3.bisect(domain, x, 1, k) - 1;
  7497. return i[j](u[j](x));
  7498. };
  7499. }
  7500. d3.scale.linear = function() {
  7501. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  7502. };
  7503. function d3_scale_linear(domain, range, interpolate, clamp) {
  7504. var output, input;
  7505. function rescale() {
  7506. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  7507. output = linear(domain, range, uninterpolate, interpolate);
  7508. input = linear(range, domain, uninterpolate, d3_interpolate);
  7509. return scale;
  7510. }
  7511. function scale(x) {
  7512. return output(x);
  7513. }
  7514. scale.invert = function(y) {
  7515. return input(y);
  7516. };
  7517. scale.domain = function(x) {
  7518. if (!arguments.length) return domain;
  7519. domain = x.map(Number);
  7520. return rescale();
  7521. };
  7522. scale.range = function(x) {
  7523. if (!arguments.length) return range;
  7524. range = x;
  7525. return rescale();
  7526. };
  7527. scale.rangeRound = function(x) {
  7528. return scale.range(x).interpolate(d3_interpolateRound);
  7529. };
  7530. scale.clamp = function(x) {
  7531. if (!arguments.length) return clamp;
  7532. clamp = x;
  7533. return rescale();
  7534. };
  7535. scale.interpolate = function(x) {
  7536. if (!arguments.length) return interpolate;
  7537. interpolate = x;
  7538. return rescale();
  7539. };
  7540. scale.ticks = function(m) {
  7541. return d3_scale_linearTicks(domain, m);
  7542. };
  7543. scale.tickFormat = function(m, format) {
  7544. return d3_scale_linearTickFormat(domain, m, format);
  7545. };
  7546. scale.nice = function(m) {
  7547. d3_scale_linearNice(domain, m);
  7548. return rescale();
  7549. };
  7550. scale.copy = function() {
  7551. return d3_scale_linear(domain, range, interpolate, clamp);
  7552. };
  7553. return rescale();
  7554. }
  7555. function d3_scale_linearRebind(scale, linear) {
  7556. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  7557. }
  7558. function d3_scale_linearNice(domain, m) {
  7559. d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  7560. d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  7561. return domain;
  7562. }
  7563. function d3_scale_linearTickRange(domain, m) {
  7564. if (m == null) m = 10;
  7565. 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;
  7566. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  7567. extent[0] = Math.ceil(extent[0] / step) * step;
  7568. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  7569. extent[2] = step;
  7570. return extent;
  7571. }
  7572. function d3_scale_linearTicks(domain, m) {
  7573. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  7574. }
  7575. function d3_scale_linearTickFormat(domain, m, format) {
  7576. var range = d3_scale_linearTickRange(domain, m);
  7577. if (format) {
  7578. var match = d3_format_re.exec(format);
  7579. match.shift();
  7580. if (match[8] === "s") {
  7581. var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
  7582. if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
  7583. match[8] = "f";
  7584. format = d3.format(match.join(""));
  7585. return function(d) {
  7586. return format(prefix.scale(d)) + prefix.symbol;
  7587. };
  7588. }
  7589. if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
  7590. format = match.join("");
  7591. } else {
  7592. format = ",." + d3_scale_linearPrecision(range[2]) + "f";
  7593. }
  7594. return d3.format(format);
  7595. }
  7596. var d3_scale_linearFormatSignificant = {
  7597. s: 1,
  7598. g: 1,
  7599. p: 1,
  7600. r: 1,
  7601. e: 1
  7602. };
  7603. function d3_scale_linearPrecision(value) {
  7604. return -Math.floor(Math.log(value) / Math.LN10 + .01);
  7605. }
  7606. function d3_scale_linearFormatPrecision(type, range) {
  7607. var p = d3_scale_linearPrecision(range[2]);
  7608. 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;
  7609. }
  7610. d3.scale.log = function() {
  7611. return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
  7612. };
  7613. function d3_scale_log(linear, base, positive, domain) {
  7614. function log(x) {
  7615. return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
  7616. }
  7617. function pow(x) {
  7618. return positive ? Math.pow(base, x) : -Math.pow(base, -x);
  7619. }
  7620. function scale(x) {
  7621. return linear(log(x));
  7622. }
  7623. scale.invert = function(x) {
  7624. return pow(linear.invert(x));
  7625. };
  7626. scale.domain = function(x) {
  7627. if (!arguments.length) return domain;
  7628. positive = x[0] >= 0;
  7629. linear.domain((domain = x.map(Number)).map(log));
  7630. return scale;
  7631. };
  7632. scale.base = function(_) {
  7633. if (!arguments.length) return base;
  7634. base = +_;
  7635. linear.domain(domain.map(log));
  7636. return scale;
  7637. };
  7638. scale.nice = function() {
  7639. var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
  7640. linear.domain(niced);
  7641. domain = niced.map(pow);
  7642. return scale;
  7643. };
  7644. scale.ticks = function() {
  7645. 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;
  7646. if (isFinite(j - i)) {
  7647. if (positive) {
  7648. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
  7649. ticks.push(pow(i));
  7650. } else {
  7651. ticks.push(pow(i));
  7652. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
  7653. }
  7654. for (i = 0; ticks[i] < u; i++) {}
  7655. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  7656. ticks = ticks.slice(i, j);
  7657. }
  7658. return ticks;
  7659. };
  7660. scale.tickFormat = function(n, format) {
  7661. if (!arguments.length) return d3_scale_logFormat;
  7662. if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
  7663. var k = Math.max(1, base * n / scale.ticks().length);
  7664. return function(d) {
  7665. var i = d / pow(Math.round(log(d)));
  7666. if (i * base < base - .5) i *= base;
  7667. return i <= k ? format(d) : "";
  7668. };
  7669. };
  7670. scale.copy = function() {
  7671. return d3_scale_log(linear.copy(), base, positive, domain);
  7672. };
  7673. return d3_scale_linearRebind(scale, linear);
  7674. }
  7675. var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
  7676. floor: function(x) {
  7677. return -Math.ceil(-x);
  7678. },
  7679. ceil: function(x) {
  7680. return -Math.floor(-x);
  7681. }
  7682. };
  7683. d3.scale.pow = function() {
  7684. return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
  7685. };
  7686. function d3_scale_pow(linear, exponent, domain) {
  7687. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  7688. function scale(x) {
  7689. return linear(powp(x));
  7690. }
  7691. scale.invert = function(x) {
  7692. return powb(linear.invert(x));
  7693. };
  7694. scale.domain = function(x) {
  7695. if (!arguments.length) return domain;
  7696. linear.domain((domain = x.map(Number)).map(powp));
  7697. return scale;
  7698. };
  7699. scale.ticks = function(m) {
  7700. return d3_scale_linearTicks(domain, m);
  7701. };
  7702. scale.tickFormat = function(m, format) {
  7703. return d3_scale_linearTickFormat(domain, m, format);
  7704. };
  7705. scale.nice = function(m) {
  7706. return scale.domain(d3_scale_linearNice(domain, m));
  7707. };
  7708. scale.exponent = function(x) {
  7709. if (!arguments.length) return exponent;
  7710. powp = d3_scale_powPow(exponent = x);
  7711. powb = d3_scale_powPow(1 / exponent);
  7712. linear.domain(domain.map(powp));
  7713. return scale;
  7714. };
  7715. scale.copy = function() {
  7716. return d3_scale_pow(linear.copy(), exponent, domain);
  7717. };
  7718. return d3_scale_linearRebind(scale, linear);
  7719. }
  7720. function d3_scale_powPow(e) {
  7721. return function(x) {
  7722. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  7723. };
  7724. }
  7725. d3.scale.sqrt = function() {
  7726. return d3.scale.pow().exponent(.5);
  7727. };
  7728. d3.scale.ordinal = function() {
  7729. return d3_scale_ordinal([], {
  7730. t: "range",
  7731. a: [ [] ]
  7732. });
  7733. };
  7734. function d3_scale_ordinal(domain, ranger) {
  7735. var index, range, rangeBand;
  7736. function scale(x) {
  7737. return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
  7738. }
  7739. function steps(start, step) {
  7740. return d3.range(domain.length).map(function(i) {
  7741. return start + step * i;
  7742. });
  7743. }
  7744. scale.domain = function(x) {
  7745. if (!arguments.length) return domain;
  7746. domain = [];
  7747. index = new d3_Map();
  7748. var i = -1, n = x.length, xi;
  7749. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  7750. return scale[ranger.t].apply(scale, ranger.a);
  7751. };
  7752. scale.range = function(x) {
  7753. if (!arguments.length) return range;
  7754. range = x;
  7755. rangeBand = 0;
  7756. ranger = {
  7757. t: "range",
  7758. a: arguments
  7759. };
  7760. return scale;
  7761. };
  7762. scale.rangePoints = function(x, padding) {
  7763. if (arguments.length < 2) padding = 0;
  7764. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
  7765. 0) : (stop - start) / (domain.length - 1 + padding);
  7766. range = steps(start + step * padding / 2, step);
  7767. rangeBand = 0;
  7768. ranger = {
  7769. t: "rangePoints",
  7770. a: arguments
  7771. };
  7772. return scale;
  7773. };
  7774. scale.rangeRoundPoints = function(x, padding) {
  7775. if (arguments.length < 2) padding = 0;
  7776. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
  7777. 0) : (stop - start) / (domain.length - 1 + padding) | 0;
  7778. range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
  7779. rangeBand = 0;
  7780. ranger = {
  7781. t: "rangeRoundPoints",
  7782. a: arguments
  7783. };
  7784. return scale;
  7785. };
  7786. scale.rangeBands = function(x, padding, outerPadding) {
  7787. if (arguments.length < 2) padding = 0;
  7788. if (arguments.length < 3) outerPadding = padding;
  7789. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  7790. range = steps(start + step * outerPadding, step);
  7791. if (reverse) range.reverse();
  7792. rangeBand = step * (1 - padding);
  7793. ranger = {
  7794. t: "rangeBands",
  7795. a: arguments
  7796. };
  7797. return scale;
  7798. };
  7799. scale.rangeRoundBands = function(x, padding, outerPadding) {
  7800. if (arguments.length < 2) padding = 0;
  7801. if (arguments.length < 3) outerPadding = padding;
  7802. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
  7803. range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
  7804. if (reverse) range.reverse();
  7805. rangeBand = Math.round(step * (1 - padding));
  7806. ranger = {
  7807. t: "rangeRoundBands",
  7808. a: arguments
  7809. };
  7810. return scale;
  7811. };
  7812. scale.rangeBand = function() {
  7813. return rangeBand;
  7814. };
  7815. scale.rangeExtent = function() {
  7816. return d3_scaleExtent(ranger.a[0]);
  7817. };
  7818. scale.copy = function() {
  7819. return d3_scale_ordinal(domain, ranger);
  7820. };
  7821. return scale.domain(domain);
  7822. }
  7823. d3.scale.category10 = function() {
  7824. return d3.scale.ordinal().range(d3_category10);
  7825. };
  7826. d3.scale.category20 = function() {
  7827. return d3.scale.ordinal().range(d3_category20);
  7828. };
  7829. d3.scale.category20b = function() {
  7830. return d3.scale.ordinal().range(d3_category20b);
  7831. };
  7832. d3.scale.category20c = function() {
  7833. return d3.scale.ordinal().range(d3_category20c);
  7834. };
  7835. var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
  7836. 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);
  7837. 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);
  7838. 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);
  7839. d3.scale.quantile = function() {
  7840. return d3_scale_quantile([], []);
  7841. };
  7842. function d3_scale_quantile(domain, range) {
  7843. var thresholds;
  7844. function rescale() {
  7845. var k = 0, q = range.length;
  7846. thresholds = [];
  7847. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  7848. return scale;
  7849. }
  7850. function scale(x) {
  7851. if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
  7852. }
  7853. scale.domain = function(x) {
  7854. if (!arguments.length) return domain;
  7855. domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
  7856. return rescale();
  7857. };
  7858. scale.range = function(x) {
  7859. if (!arguments.length) return range;
  7860. range = x;
  7861. return rescale();
  7862. };
  7863. scale.quantiles = function() {
  7864. return thresholds;
  7865. };
  7866. scale.invertExtent = function(y) {
  7867. y = range.indexOf(y);
  7868. return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
  7869. };
  7870. scale.copy = function() {
  7871. return d3_scale_quantile(domain, range);
  7872. };
  7873. return rescale();
  7874. }
  7875. d3.scale.quantize = function() {
  7876. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  7877. };
  7878. function d3_scale_quantize(x0, x1, range) {
  7879. var kx, i;
  7880. function scale(x) {
  7881. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  7882. }
  7883. function rescale() {
  7884. kx = range.length / (x1 - x0);
  7885. i = range.length - 1;
  7886. return scale;
  7887. }
  7888. scale.domain = function(x) {
  7889. if (!arguments.length) return [ x0, x1 ];
  7890. x0 = +x[0];
  7891. x1 = +x[x.length - 1];
  7892. return rescale();
  7893. };
  7894. scale.range = function(x) {
  7895. if (!arguments.length) return range;
  7896. range = x;
  7897. return rescale();
  7898. };
  7899. scale.invertExtent = function(y) {
  7900. y = range.indexOf(y);
  7901. y = y < 0 ? NaN : y / kx + x0;
  7902. return [ y, y + 1 / kx ];
  7903. };
  7904. scale.copy = function() {
  7905. return d3_scale_quantize(x0, x1, range);
  7906. };
  7907. return rescale();
  7908. }
  7909. d3.scale.threshold = function() {
  7910. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  7911. };
  7912. function d3_scale_threshold(domain, range) {
  7913. function scale(x) {
  7914. if (x <= x) return range[d3.bisect(domain, x)];
  7915. }
  7916. scale.domain = function(_) {
  7917. if (!arguments.length) return domain;
  7918. domain = _;
  7919. return scale;
  7920. };
  7921. scale.range = function(_) {
  7922. if (!arguments.length) return range;
  7923. range = _;
  7924. return scale;
  7925. };
  7926. scale.invertExtent = function(y) {
  7927. y = range.indexOf(y);
  7928. return [ domain[y - 1], domain[y] ];
  7929. };
  7930. scale.copy = function() {
  7931. return d3_scale_threshold(domain, range);
  7932. };
  7933. return scale;
  7934. }
  7935. d3.scale.identity = function() {
  7936. return d3_scale_identity([ 0, 1 ]);
  7937. };
  7938. function d3_scale_identity(domain) {
  7939. function identity(x) {
  7940. return +x;
  7941. }
  7942. identity.invert = identity;
  7943. identity.domain = identity.range = function(x) {
  7944. if (!arguments.length) return domain;
  7945. domain = x.map(identity);
  7946. return identity;
  7947. };
  7948. identity.ticks = function(m) {
  7949. return d3_scale_linearTicks(domain, m);
  7950. };
  7951. identity.tickFormat = function(m, format) {
  7952. return d3_scale_linearTickFormat(domain, m, format);
  7953. };
  7954. identity.copy = function() {
  7955. return d3_scale_identity(domain);
  7956. };
  7957. return identity;
  7958. }
  7959. d3.svg = {};
  7960. function d3_zero() {
  7961. return 0;
  7962. }
  7963. d3.svg.arc = function() {
  7964. 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;
  7965. function arc() {
  7966. 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;
  7967. if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
  7968. if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
  7969. var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
  7970. if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
  7971. rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
  7972. if (!cw) p1 *= -1;
  7973. if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
  7974. if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
  7975. }
  7976. if (r1) {
  7977. x0 = r1 * Math.cos(a0 + p1);
  7978. y0 = r1 * Math.sin(a0 + p1);
  7979. x1 = r1 * Math.cos(a1 - p1);
  7980. y1 = r1 * Math.sin(a1 - p1);
  7981. var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
  7982. if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
  7983. var h1 = (a0 + a1) / 2;
  7984. x0 = r1 * Math.cos(h1);
  7985. y0 = r1 * Math.sin(h1);
  7986. x1 = y1 = null;
  7987. }
  7988. } else {
  7989. x0 = y0 = 0;
  7990. }
  7991. if (r0) {
  7992. x2 = r0 * Math.cos(a1 - p0);
  7993. y2 = r0 * Math.sin(a1 - p0);
  7994. x3 = r0 * Math.cos(a0 + p0);
  7995. y3 = r0 * Math.sin(a0 + p0);
  7996. var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
  7997. if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
  7998. var h0 = (a0 + a1) / 2;
  7999. x2 = r0 * Math.cos(h0);
  8000. y2 = r0 * Math.sin(h0);
  8001. x3 = y3 = null;
  8002. }
  8003. } else {
  8004. x2 = y2 = 0;
  8005. }
  8006. if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
  8007. cr = r0 < r1 ^ cw ? 0 : 1;
  8008. var rc1 = rc, rc0 = rc;
  8009. if (da < π) {
  8010. 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]);
  8011. rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
  8012. rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
  8013. }
  8014. if (x1 != null) {
  8015. var t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
  8016. if (rc === rc1) {
  8017. 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]);
  8018. } else {
  8019. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
  8020. }
  8021. } else {
  8022. path.push("M", x0, ",", y0);
  8023. }
  8024. if (x3 != null) {
  8025. var t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
  8026. if (rc === rc0) {
  8027. 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]);
  8028. } else {
  8029. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  8030. }
  8031. } else {
  8032. path.push("L", x2, ",", y2);
  8033. }
  8034. } else {
  8035. path.push("M", x0, ",", y0);
  8036. if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
  8037. path.push("L", x2, ",", y2);
  8038. if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
  8039. }
  8040. path.push("Z");
  8041. return path.join("");
  8042. }
  8043. function circleSegment(r1, cw) {
  8044. return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
  8045. }
  8046. arc.innerRadius = function(v) {
  8047. if (!arguments.length) return innerRadius;
  8048. innerRadius = d3_functor(v);
  8049. return arc;
  8050. };
  8051. arc.outerRadius = function(v) {
  8052. if (!arguments.length) return outerRadius;
  8053. outerRadius = d3_functor(v);
  8054. return arc;
  8055. };
  8056. arc.cornerRadius = function(v) {
  8057. if (!arguments.length) return cornerRadius;
  8058. cornerRadius = d3_functor(v);
  8059. return arc;
  8060. };
  8061. arc.padRadius = function(v) {
  8062. if (!arguments.length) return padRadius;
  8063. padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
  8064. return arc;
  8065. };
  8066. arc.startAngle = function(v) {
  8067. if (!arguments.length) return startAngle;
  8068. startAngle = d3_functor(v);
  8069. return arc;
  8070. };
  8071. arc.endAngle = function(v) {
  8072. if (!arguments.length) return endAngle;
  8073. endAngle = d3_functor(v);
  8074. return arc;
  8075. };
  8076. arc.padAngle = function(v) {
  8077. if (!arguments.length) return padAngle;
  8078. padAngle = d3_functor(v);
  8079. return arc;
  8080. };
  8081. arc.centroid = function() {
  8082. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
  8083. return [ Math.cos(a) * r, Math.sin(a) * r ];
  8084. };
  8085. return arc;
  8086. };
  8087. var d3_svg_arcAuto = "auto";
  8088. function d3_svg_arcInnerRadius(d) {
  8089. return d.innerRadius;
  8090. }
  8091. function d3_svg_arcOuterRadius(d) {
  8092. return d.outerRadius;
  8093. }
  8094. function d3_svg_arcStartAngle(d) {
  8095. return d.startAngle;
  8096. }
  8097. function d3_svg_arcEndAngle(d) {
  8098. return d.endAngle;
  8099. }
  8100. function d3_svg_arcPadAngle(d) {
  8101. return d && d.padAngle;
  8102. }
  8103. function d3_svg_arcSweep(x0, y0, x1, y1) {
  8104. return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
  8105. }
  8106. function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
  8107. var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
  8108. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  8109. return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
  8110. }
  8111. function d3_svg_line(projection) {
  8112. var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  8113. function line(data) {
  8114. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  8115. function segment() {
  8116. segments.push("M", interpolate(projection(points), tension));
  8117. }
  8118. while (++i < n) {
  8119. if (defined.call(this, d = data[i], i)) {
  8120. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  8121. } else if (points.length) {
  8122. segment();
  8123. points = [];
  8124. }
  8125. }
  8126. if (points.length) segment();
  8127. return segments.length ? segments.join("") : null;
  8128. }
  8129. line.x = function(_) {
  8130. if (!arguments.length) return x;
  8131. x = _;
  8132. return line;
  8133. };
  8134. line.y = function(_) {
  8135. if (!arguments.length) return y;
  8136. y = _;
  8137. return line;
  8138. };
  8139. line.defined = function(_) {
  8140. if (!arguments.length) return defined;
  8141. defined = _;
  8142. return line;
  8143. };
  8144. line.interpolate = function(_) {
  8145. if (!arguments.length) return interpolateKey;
  8146. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8147. return line;
  8148. };
  8149. line.tension = function(_) {
  8150. if (!arguments.length) return tension;
  8151. tension = _;
  8152. return line;
  8153. };
  8154. return line;
  8155. }
  8156. d3.svg.line = function() {
  8157. return d3_svg_line(d3_identity);
  8158. };
  8159. var d3_svg_lineInterpolators = d3.map({
  8160. linear: d3_svg_lineLinear,
  8161. "linear-closed": d3_svg_lineLinearClosed,
  8162. step: d3_svg_lineStep,
  8163. "step-before": d3_svg_lineStepBefore,
  8164. "step-after": d3_svg_lineStepAfter,
  8165. basis: d3_svg_lineBasis,
  8166. "basis-open": d3_svg_lineBasisOpen,
  8167. "basis-closed": d3_svg_lineBasisClosed,
  8168. bundle: d3_svg_lineBundle,
  8169. cardinal: d3_svg_lineCardinal,
  8170. "cardinal-open": d3_svg_lineCardinalOpen,
  8171. "cardinal-closed": d3_svg_lineCardinalClosed,
  8172. monotone: d3_svg_lineMonotone
  8173. });
  8174. d3_svg_lineInterpolators.forEach(function(key, value) {
  8175. value.key = key;
  8176. value.closed = /-closed$/.test(key);
  8177. });
  8178. function d3_svg_lineLinear(points) {
  8179. return points.length > 1 ? points.join("L") : points + "Z";
  8180. }
  8181. function d3_svg_lineLinearClosed(points) {
  8182. return points.join("L") + "Z";
  8183. }
  8184. function d3_svg_lineStep(points) {
  8185. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8186. while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
  8187. if (n > 1) path.push("H", p[0]);
  8188. return path.join("");
  8189. }
  8190. function d3_svg_lineStepBefore(points) {
  8191. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8192. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  8193. return path.join("");
  8194. }
  8195. function d3_svg_lineStepAfter(points) {
  8196. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8197. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  8198. return path.join("");
  8199. }
  8200. function d3_svg_lineCardinalOpen(points, tension) {
  8201. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
  8202. }
  8203. function d3_svg_lineCardinalClosed(points, tension) {
  8204. return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  8205. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  8206. }
  8207. function d3_svg_lineCardinal(points, tension) {
  8208. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  8209. }
  8210. function d3_svg_lineHermite(points, tangents) {
  8211. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  8212. return d3_svg_lineLinear(points);
  8213. }
  8214. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  8215. if (quad) {
  8216. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  8217. p0 = points[1];
  8218. pi = 2;
  8219. }
  8220. if (tangents.length > 1) {
  8221. t = tangents[1];
  8222. p = points[pi];
  8223. pi++;
  8224. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8225. for (var i = 2; i < tangents.length; i++, pi++) {
  8226. p = points[pi];
  8227. t = tangents[i];
  8228. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8229. }
  8230. }
  8231. if (quad) {
  8232. var lp = points[pi];
  8233. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  8234. }
  8235. return path;
  8236. }
  8237. function d3_svg_lineCardinalTangents(points, tension) {
  8238. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  8239. while (++i < n) {
  8240. p0 = p1;
  8241. p1 = p2;
  8242. p2 = points[i];
  8243. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  8244. }
  8245. return tangents;
  8246. }
  8247. function d3_svg_lineBasis(points) {
  8248. if (points.length < 3) return d3_svg_lineLinear(points);
  8249. 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) ];
  8250. points.push(points[n - 1]);
  8251. while (++i <= n) {
  8252. pi = points[i];
  8253. px.shift();
  8254. px.push(pi[0]);
  8255. py.shift();
  8256. py.push(pi[1]);
  8257. d3_svg_lineBasisBezier(path, px, py);
  8258. }
  8259. points.pop();
  8260. path.push("L", pi);
  8261. return path.join("");
  8262. }
  8263. function d3_svg_lineBasisOpen(points) {
  8264. if (points.length < 4) return d3_svg_lineLinear(points);
  8265. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  8266. while (++i < 3) {
  8267. pi = points[i];
  8268. px.push(pi[0]);
  8269. py.push(pi[1]);
  8270. }
  8271. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  8272. --i;
  8273. while (++i < n) {
  8274. pi = points[i];
  8275. px.shift();
  8276. px.push(pi[0]);
  8277. py.shift();
  8278. py.push(pi[1]);
  8279. d3_svg_lineBasisBezier(path, px, py);
  8280. }
  8281. return path.join("");
  8282. }
  8283. function d3_svg_lineBasisClosed(points) {
  8284. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  8285. while (++i < 4) {
  8286. pi = points[i % n];
  8287. px.push(pi[0]);
  8288. py.push(pi[1]);
  8289. }
  8290. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8291. --i;
  8292. while (++i < m) {
  8293. pi = points[i % n];
  8294. px.shift();
  8295. px.push(pi[0]);
  8296. py.shift();
  8297. py.push(pi[1]);
  8298. d3_svg_lineBasisBezier(path, px, py);
  8299. }
  8300. return path.join("");
  8301. }
  8302. function d3_svg_lineBundle(points, tension) {
  8303. var n = points.length - 1;
  8304. if (n) {
  8305. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  8306. while (++i <= n) {
  8307. p = points[i];
  8308. t = i / n;
  8309. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  8310. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  8311. }
  8312. }
  8313. return d3_svg_lineBasis(points);
  8314. }
  8315. function d3_svg_lineDot4(a, b) {
  8316. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  8317. }
  8318. 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 ];
  8319. function d3_svg_lineBasisBezier(path, x, y) {
  8320. 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));
  8321. }
  8322. function d3_svg_lineSlope(p0, p1) {
  8323. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  8324. }
  8325. function d3_svg_lineFiniteDifferences(points) {
  8326. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  8327. while (++i < j) {
  8328. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  8329. }
  8330. m[i] = d;
  8331. return m;
  8332. }
  8333. function d3_svg_lineMonotoneTangents(points) {
  8334. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  8335. while (++i < j) {
  8336. d = d3_svg_lineSlope(points[i], points[i + 1]);
  8337. if (abs(d) < ε) {
  8338. m[i] = m[i + 1] = 0;
  8339. } else {
  8340. a = m[i] / d;
  8341. b = m[i + 1] / d;
  8342. s = a * a + b * b;
  8343. if (s > 9) {
  8344. s = d * 3 / Math.sqrt(s);
  8345. m[i] = s * a;
  8346. m[i + 1] = s * b;
  8347. }
  8348. }
  8349. }
  8350. i = -1;
  8351. while (++i <= j) {
  8352. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  8353. tangents.push([ s || 0, m[i] * s || 0 ]);
  8354. }
  8355. return tangents;
  8356. }
  8357. function d3_svg_lineMonotone(points) {
  8358. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  8359. }
  8360. d3.svg.line.radial = function() {
  8361. var line = d3_svg_line(d3_svg_lineRadial);
  8362. line.radius = line.x, delete line.x;
  8363. line.angle = line.y, delete line.y;
  8364. return line;
  8365. };
  8366. function d3_svg_lineRadial(points) {
  8367. var point, i = -1, n = points.length, r, a;
  8368. while (++i < n) {
  8369. point = points[i];
  8370. r = point[0];
  8371. a = point[1] - halfπ;
  8372. point[0] = r * Math.cos(a);
  8373. point[1] = r * Math.sin(a);
  8374. }
  8375. return points;
  8376. }
  8377. function d3_svg_area(projection) {
  8378. 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;
  8379. function area(data) {
  8380. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  8381. return x;
  8382. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  8383. return y;
  8384. } : d3_functor(y1), x, y;
  8385. function segment() {
  8386. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  8387. }
  8388. while (++i < n) {
  8389. if (defined.call(this, d = data[i], i)) {
  8390. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  8391. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  8392. } else if (points0.length) {
  8393. segment();
  8394. points0 = [];
  8395. points1 = [];
  8396. }
  8397. }
  8398. if (points0.length) segment();
  8399. return segments.length ? segments.join("") : null;
  8400. }
  8401. area.x = function(_) {
  8402. if (!arguments.length) return x1;
  8403. x0 = x1 = _;
  8404. return area;
  8405. };
  8406. area.x0 = function(_) {
  8407. if (!arguments.length) return x0;
  8408. x0 = _;
  8409. return area;
  8410. };
  8411. area.x1 = function(_) {
  8412. if (!arguments.length) return x1;
  8413. x1 = _;
  8414. return area;
  8415. };
  8416. area.y = function(_) {
  8417. if (!arguments.length) return y1;
  8418. y0 = y1 = _;
  8419. return area;
  8420. };
  8421. area.y0 = function(_) {
  8422. if (!arguments.length) return y0;
  8423. y0 = _;
  8424. return area;
  8425. };
  8426. area.y1 = function(_) {
  8427. if (!arguments.length) return y1;
  8428. y1 = _;
  8429. return area;
  8430. };
  8431. area.defined = function(_) {
  8432. if (!arguments.length) return defined;
  8433. defined = _;
  8434. return area;
  8435. };
  8436. area.interpolate = function(_) {
  8437. if (!arguments.length) return interpolateKey;
  8438. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8439. interpolateReverse = interpolate.reverse || interpolate;
  8440. L = interpolate.closed ? "M" : "L";
  8441. return area;
  8442. };
  8443. area.tension = function(_) {
  8444. if (!arguments.length) return tension;
  8445. tension = _;
  8446. return area;
  8447. };
  8448. return area;
  8449. }
  8450. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  8451. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  8452. d3.svg.area = function() {
  8453. return d3_svg_area(d3_identity);
  8454. };
  8455. d3.svg.area.radial = function() {
  8456. var area = d3_svg_area(d3_svg_lineRadial);
  8457. area.radius = area.x, delete area.x;
  8458. area.innerRadius = area.x0, delete area.x0;
  8459. area.outerRadius = area.x1, delete area.x1;
  8460. area.angle = area.y, delete area.y;
  8461. area.startAngle = area.y0, delete area.y0;
  8462. area.endAngle = area.y1, delete area.y1;
  8463. return area;
  8464. };
  8465. d3.svg.chord = function() {
  8466. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  8467. function chord(d, i) {
  8468. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  8469. 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";
  8470. }
  8471. function subgroup(self, f, d, i) {
  8472. 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π;
  8473. return {
  8474. r: r,
  8475. a0: a0,
  8476. a1: a1,
  8477. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  8478. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  8479. };
  8480. }
  8481. function equals(a, b) {
  8482. return a.a0 == b.a0 && a.a1 == b.a1;
  8483. }
  8484. function arc(r, p, a) {
  8485. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  8486. }
  8487. function curve(r0, p0, r1, p1) {
  8488. return "Q 0,0 " + p1;
  8489. }
  8490. chord.radius = function(v) {
  8491. if (!arguments.length) return radius;
  8492. radius = d3_functor(v);
  8493. return chord;
  8494. };
  8495. chord.source = function(v) {
  8496. if (!arguments.length) return source;
  8497. source = d3_functor(v);
  8498. return chord;
  8499. };
  8500. chord.target = function(v) {
  8501. if (!arguments.length) return target;
  8502. target = d3_functor(v);
  8503. return chord;
  8504. };
  8505. chord.startAngle = function(v) {
  8506. if (!arguments.length) return startAngle;
  8507. startAngle = d3_functor(v);
  8508. return chord;
  8509. };
  8510. chord.endAngle = function(v) {
  8511. if (!arguments.length) return endAngle;
  8512. endAngle = d3_functor(v);
  8513. return chord;
  8514. };
  8515. return chord;
  8516. };
  8517. function d3_svg_chordRadius(d) {
  8518. return d.radius;
  8519. }
  8520. d3.svg.diagonal = function() {
  8521. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  8522. function diagonal(d, i) {
  8523. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  8524. x: p0.x,
  8525. y: m
  8526. }, {
  8527. x: p3.x,
  8528. y: m
  8529. }, p3 ];
  8530. p = p.map(projection);
  8531. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  8532. }
  8533. diagonal.source = function(x) {
  8534. if (!arguments.length) return source;
  8535. source = d3_functor(x);
  8536. return diagonal;
  8537. };
  8538. diagonal.target = function(x) {
  8539. if (!arguments.length) return target;
  8540. target = d3_functor(x);
  8541. return diagonal;
  8542. };
  8543. diagonal.projection = function(x) {
  8544. if (!arguments.length) return projection;
  8545. projection = x;
  8546. return diagonal;
  8547. };
  8548. return diagonal;
  8549. };
  8550. function d3_svg_diagonalProjection(d) {
  8551. return [ d.x, d.y ];
  8552. }
  8553. d3.svg.diagonal.radial = function() {
  8554. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  8555. diagonal.projection = function(x) {
  8556. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  8557. };
  8558. return diagonal;
  8559. };
  8560. function d3_svg_diagonalRadialProjection(projection) {
  8561. return function() {
  8562. var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
  8563. return [ r * Math.cos(a), r * Math.sin(a) ];
  8564. };
  8565. }
  8566. d3.svg.symbol = function() {
  8567. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  8568. function symbol(d, i) {
  8569. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  8570. }
  8571. symbol.type = function(x) {
  8572. if (!arguments.length) return type;
  8573. type = d3_functor(x);
  8574. return symbol;
  8575. };
  8576. symbol.size = function(x) {
  8577. if (!arguments.length) return size;
  8578. size = d3_functor(x);
  8579. return symbol;
  8580. };
  8581. return symbol;
  8582. };
  8583. function d3_svg_symbolSize() {
  8584. return 64;
  8585. }
  8586. function d3_svg_symbolType() {
  8587. return "circle";
  8588. }
  8589. function d3_svg_symbolCircle(size) {
  8590. var r = Math.sqrt(size / π);
  8591. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  8592. }
  8593. var d3_svg_symbols = d3.map({
  8594. circle: d3_svg_symbolCircle,
  8595. cross: function(size) {
  8596. var r = Math.sqrt(size / 5) / 2;
  8597. 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";
  8598. },
  8599. diamond: function(size) {
  8600. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  8601. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  8602. },
  8603. square: function(size) {
  8604. var r = Math.sqrt(size) / 2;
  8605. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  8606. },
  8607. "triangle-down": function(size) {
  8608. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8609. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  8610. },
  8611. "triangle-up": function(size) {
  8612. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8613. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  8614. }
  8615. });
  8616. d3.svg.symbolTypes = d3_svg_symbols.keys();
  8617. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  8618. d3_selectionPrototype.transition = function(name) {
  8619. var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
  8620. time: Date.now(),
  8621. ease: d3_ease_cubicInOut,
  8622. delay: 0,
  8623. duration: 250
  8624. };
  8625. for (var j = -1, m = this.length; ++j < m; ) {
  8626. subgroups.push(subgroup = []);
  8627. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8628. if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
  8629. subgroup.push(node);
  8630. }
  8631. }
  8632. return d3_transition(subgroups, ns, id);
  8633. };
  8634. d3_selectionPrototype.interrupt = function(name) {
  8635. return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
  8636. };
  8637. var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
  8638. function d3_selection_interruptNS(ns) {
  8639. return function() {
  8640. var lock, activeId, active;
  8641. if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
  8642. active.timer.c = null;
  8643. active.timer.t = NaN;
  8644. if (--lock.count) delete lock[activeId]; else delete this[ns];
  8645. lock.active += .5;
  8646. active.event && active.event.interrupt.call(this, this.__data__, active.index);
  8647. }
  8648. };
  8649. }
  8650. function d3_transition(groups, ns, id) {
  8651. d3_subclass(groups, d3_transitionPrototype);
  8652. groups.namespace = ns;
  8653. groups.id = id;
  8654. return groups;
  8655. }
  8656. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
  8657. d3_transitionPrototype.call = d3_selectionPrototype.call;
  8658. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  8659. d3_transitionPrototype.node = d3_selectionPrototype.node;
  8660. d3_transitionPrototype.size = d3_selectionPrototype.size;
  8661. d3.transition = function(selection, name) {
  8662. return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
  8663. };
  8664. d3.transition.prototype = d3_transitionPrototype;
  8665. d3_transitionPrototype.select = function(selector) {
  8666. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
  8667. selector = d3_selection_selector(selector);
  8668. for (var j = -1, m = this.length; ++j < m; ) {
  8669. subgroups.push(subgroup = []);
  8670. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8671. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
  8672. if ("__data__" in node) subnode.__data__ = node.__data__;
  8673. d3_transitionNode(subnode, i, ns, id, node[ns][id]);
  8674. subgroup.push(subnode);
  8675. } else {
  8676. subgroup.push(null);
  8677. }
  8678. }
  8679. }
  8680. return d3_transition(subgroups, ns, id);
  8681. };
  8682. d3_transitionPrototype.selectAll = function(selector) {
  8683. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
  8684. selector = d3_selection_selectorAll(selector);
  8685. for (var j = -1, m = this.length; ++j < m; ) {
  8686. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8687. if (node = group[i]) {
  8688. transition = node[ns][id];
  8689. subnodes = selector.call(node, node.__data__, i, j);
  8690. subgroups.push(subgroup = []);
  8691. for (var k = -1, o = subnodes.length; ++k < o; ) {
  8692. if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
  8693. subgroup.push(subnode);
  8694. }
  8695. }
  8696. }
  8697. }
  8698. return d3_transition(subgroups, ns, id);
  8699. };
  8700. d3_transitionPrototype.filter = function(filter) {
  8701. var subgroups = [], subgroup, group, node;
  8702. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  8703. for (var j = 0, m = this.length; j < m; j++) {
  8704. subgroups.push(subgroup = []);
  8705. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8706. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  8707. subgroup.push(node);
  8708. }
  8709. }
  8710. }
  8711. return d3_transition(subgroups, this.namespace, this.id);
  8712. };
  8713. d3_transitionPrototype.tween = function(name, tween) {
  8714. var id = this.id, ns = this.namespace;
  8715. if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
  8716. return d3_selection_each(this, tween == null ? function(node) {
  8717. node[ns][id].tween.remove(name);
  8718. } : function(node) {
  8719. node[ns][id].tween.set(name, tween);
  8720. });
  8721. };
  8722. function d3_transition_tween(groups, name, value, tween) {
  8723. var id = groups.id, ns = groups.namespace;
  8724. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  8725. node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  8726. } : (value = tween(value), function(node) {
  8727. node[ns][id].tween.set(name, value);
  8728. }));
  8729. }
  8730. d3_transitionPrototype.attr = function(nameNS, value) {
  8731. if (arguments.length < 2) {
  8732. for (value in nameNS) this.attr(value, nameNS[value]);
  8733. return this;
  8734. }
  8735. var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
  8736. function attrNull() {
  8737. this.removeAttribute(name);
  8738. }
  8739. function attrNullNS() {
  8740. this.removeAttributeNS(name.space, name.local);
  8741. }
  8742. function attrTween(b) {
  8743. return b == null ? attrNull : (b += "", function() {
  8744. var a = this.getAttribute(name), i;
  8745. return a !== b && (i = interpolate(a, b), function(t) {
  8746. this.setAttribute(name, i(t));
  8747. });
  8748. });
  8749. }
  8750. function attrTweenNS(b) {
  8751. return b == null ? attrNullNS : (b += "", function() {
  8752. var a = this.getAttributeNS(name.space, name.local), i;
  8753. return a !== b && (i = interpolate(a, b), function(t) {
  8754. this.setAttributeNS(name.space, name.local, i(t));
  8755. });
  8756. });
  8757. }
  8758. return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
  8759. };
  8760. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  8761. var name = d3.ns.qualify(nameNS);
  8762. function attrTween(d, i) {
  8763. var f = tween.call(this, d, i, this.getAttribute(name));
  8764. return f && function(t) {
  8765. this.setAttribute(name, f(t));
  8766. };
  8767. }
  8768. function attrTweenNS(d, i) {
  8769. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  8770. return f && function(t) {
  8771. this.setAttributeNS(name.space, name.local, f(t));
  8772. };
  8773. }
  8774. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  8775. };
  8776. d3_transitionPrototype.style = function(name, value, priority) {
  8777. var n = arguments.length;
  8778. if (n < 3) {
  8779. if (typeof name !== "string") {
  8780. if (n < 2) value = "";
  8781. for (priority in name) this.style(priority, name[priority], value);
  8782. return this;
  8783. }
  8784. priority = "";
  8785. }
  8786. function styleNull() {
  8787. this.style.removeProperty(name);
  8788. }
  8789. function styleString(b) {
  8790. return b == null ? styleNull : (b += "", function() {
  8791. var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
  8792. return a !== b && (i = d3_interpolate(a, b), function(t) {
  8793. this.style.setProperty(name, i(t), priority);
  8794. });
  8795. });
  8796. }
  8797. return d3_transition_tween(this, "style." + name, value, styleString);
  8798. };
  8799. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  8800. if (arguments.length < 3) priority = "";
  8801. function styleTween(d, i) {
  8802. var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
  8803. return f && function(t) {
  8804. this.style.setProperty(name, f(t), priority);
  8805. };
  8806. }
  8807. return this.tween("style." + name, styleTween);
  8808. };
  8809. d3_transitionPrototype.text = function(value) {
  8810. return d3_transition_tween(this, "text", value, d3_transition_text);
  8811. };
  8812. function d3_transition_text(b) {
  8813. if (b == null) b = "";
  8814. return function() {
  8815. this.textContent = b;
  8816. };
  8817. }
  8818. d3_transitionPrototype.remove = function() {
  8819. var ns = this.namespace;
  8820. return this.each("end.transition", function() {
  8821. var p;
  8822. if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
  8823. });
  8824. };
  8825. d3_transitionPrototype.ease = function(value) {
  8826. var id = this.id, ns = this.namespace;
  8827. if (arguments.length < 1) return this.node()[ns][id].ease;
  8828. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  8829. return d3_selection_each(this, function(node) {
  8830. node[ns][id].ease = value;
  8831. });
  8832. };
  8833. d3_transitionPrototype.delay = function(value) {
  8834. var id = this.id, ns = this.namespace;
  8835. if (arguments.length < 1) return this.node()[ns][id].delay;
  8836. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8837. node[ns][id].delay = +value.call(node, node.__data__, i, j);
  8838. } : (value = +value, function(node) {
  8839. node[ns][id].delay = value;
  8840. }));
  8841. };
  8842. d3_transitionPrototype.duration = function(value) {
  8843. var id = this.id, ns = this.namespace;
  8844. if (arguments.length < 1) return this.node()[ns][id].duration;
  8845. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8846. node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
  8847. } : (value = Math.max(1, value), function(node) {
  8848. node[ns][id].duration = value;
  8849. }));
  8850. };
  8851. d3_transitionPrototype.each = function(type, listener) {
  8852. var id = this.id, ns = this.namespace;
  8853. if (arguments.length < 2) {
  8854. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  8855. try {
  8856. d3_transitionInheritId = id;
  8857. d3_selection_each(this, function(node, i, j) {
  8858. d3_transitionInherit = node[ns][id];
  8859. type.call(node, node.__data__, i, j);
  8860. });
  8861. } finally {
  8862. d3_transitionInherit = inherit;
  8863. d3_transitionInheritId = inheritId;
  8864. }
  8865. } else {
  8866. d3_selection_each(this, function(node) {
  8867. var transition = node[ns][id];
  8868. (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
  8869. });
  8870. }
  8871. return this;
  8872. };
  8873. d3_transitionPrototype.transition = function() {
  8874. var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
  8875. for (var j = 0, m = this.length; j < m; j++) {
  8876. subgroups.push(subgroup = []);
  8877. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8878. if (node = group[i]) {
  8879. transition = node[ns][id0];
  8880. d3_transitionNode(node, i, ns, id1, {
  8881. time: transition.time,
  8882. ease: transition.ease,
  8883. delay: transition.delay + transition.duration,
  8884. duration: transition.duration
  8885. });
  8886. }
  8887. subgroup.push(node);
  8888. }
  8889. }
  8890. return d3_transition(subgroups, ns, id1);
  8891. };
  8892. function d3_transitionNamespace(name) {
  8893. return name == null ? "__transition__" : "__transition_" + name + "__";
  8894. }
  8895. function d3_transitionNode(node, i, ns, id, inherit) {
  8896. var lock = node[ns] || (node[ns] = {
  8897. active: 0,
  8898. count: 0
  8899. }), transition = lock[id], time, timer, duration, ease, tweens;
  8900. function schedule(elapsed) {
  8901. var delay = transition.delay;
  8902. timer.t = delay + time;
  8903. if (delay <= elapsed) return start(elapsed - delay);
  8904. timer.c = start;
  8905. }
  8906. function start(elapsed) {
  8907. var activeId = lock.active, active = lock[activeId];
  8908. if (active) {
  8909. active.timer.c = null;
  8910. active.timer.t = NaN;
  8911. --lock.count;
  8912. delete lock[activeId];
  8913. active.event && active.event.interrupt.call(node, node.__data__, active.index);
  8914. }
  8915. for (var cancelId in lock) {
  8916. if (+cancelId < id) {
  8917. var cancel = lock[cancelId];
  8918. cancel.timer.c = null;
  8919. cancel.timer.t = NaN;
  8920. --lock.count;
  8921. delete lock[cancelId];
  8922. }
  8923. }
  8924. timer.c = tick;
  8925. d3_timer(function() {
  8926. if (timer.c && tick(elapsed || 1)) {
  8927. timer.c = null;
  8928. timer.t = NaN;
  8929. }
  8930. return 1;
  8931. }, 0, time);
  8932. lock.active = id;
  8933. transition.event && transition.event.start.call(node, node.__data__, i);
  8934. tweens = [];
  8935. transition.tween.forEach(function(key, value) {
  8936. if (value = value.call(node, node.__data__, i)) {
  8937. tweens.push(value);
  8938. }
  8939. });
  8940. ease = transition.ease;
  8941. duration = transition.duration;
  8942. }
  8943. function tick(elapsed) {
  8944. var t = elapsed / duration, e = ease(t), n = tweens.length;
  8945. while (n > 0) {
  8946. tweens[--n].call(node, e);
  8947. }
  8948. if (t >= 1) {
  8949. transition.event && transition.event.end.call(node, node.__data__, i);
  8950. if (--lock.count) delete lock[id]; else delete node[ns];
  8951. return 1;
  8952. }
  8953. }
  8954. if (!transition) {
  8955. time = inherit.time;
  8956. timer = d3_timer(schedule, 0, time);
  8957. transition = lock[id] = {
  8958. tween: new d3_Map(),
  8959. time: time,
  8960. timer: timer,
  8961. delay: inherit.delay,
  8962. duration: inherit.duration,
  8963. ease: inherit.ease,
  8964. index: i
  8965. };
  8966. inherit = null;
  8967. ++lock.count;
  8968. }
  8969. }
  8970. d3.svg.axis = function() {
  8971. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
  8972. function axis(g) {
  8973. g.each(function() {
  8974. var g = d3.select(this);
  8975. var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
  8976. 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;
  8977. var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  8978. d3.transition(path));
  8979. tickEnter.append("line");
  8980. tickEnter.append("text");
  8981. 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;
  8982. if (orient === "bottom" || orient === "top") {
  8983. tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
  8984. text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
  8985. pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
  8986. } else {
  8987. tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
  8988. text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
  8989. pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
  8990. }
  8991. lineEnter.attr(y2, sign * innerTickSize);
  8992. textEnter.attr(y1, sign * tickSpacing);
  8993. lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
  8994. textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
  8995. if (scale1.rangeBand) {
  8996. var x = scale1, dx = x.rangeBand() / 2;
  8997. scale0 = scale1 = function(d) {
  8998. return x(d) + dx;
  8999. };
  9000. } else if (scale0.rangeBand) {
  9001. scale0 = scale1;
  9002. } else {
  9003. tickExit.call(tickTransform, scale1, scale0);
  9004. }
  9005. tickEnter.call(tickTransform, scale0, scale1);
  9006. tickUpdate.call(tickTransform, scale1, scale1);
  9007. });
  9008. }
  9009. axis.scale = function(x) {
  9010. if (!arguments.length) return scale;
  9011. scale = x;
  9012. return axis;
  9013. };
  9014. axis.orient = function(x) {
  9015. if (!arguments.length) return orient;
  9016. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  9017. return axis;
  9018. };
  9019. axis.ticks = function() {
  9020. if (!arguments.length) return tickArguments_;
  9021. tickArguments_ = d3_array(arguments);
  9022. return axis;
  9023. };
  9024. axis.tickValues = function(x) {
  9025. if (!arguments.length) return tickValues;
  9026. tickValues = x;
  9027. return axis;
  9028. };
  9029. axis.tickFormat = function(x) {
  9030. if (!arguments.length) return tickFormat_;
  9031. tickFormat_ = x;
  9032. return axis;
  9033. };
  9034. axis.tickSize = function(x) {
  9035. var n = arguments.length;
  9036. if (!n) return innerTickSize;
  9037. innerTickSize = +x;
  9038. outerTickSize = +arguments[n - 1];
  9039. return axis;
  9040. };
  9041. axis.innerTickSize = function(x) {
  9042. if (!arguments.length) return innerTickSize;
  9043. innerTickSize = +x;
  9044. return axis;
  9045. };
  9046. axis.outerTickSize = function(x) {
  9047. if (!arguments.length) return outerTickSize;
  9048. outerTickSize = +x;
  9049. return axis;
  9050. };
  9051. axis.tickPadding = function(x) {
  9052. if (!arguments.length) return tickPadding;
  9053. tickPadding = +x;
  9054. return axis;
  9055. };
  9056. axis.tickSubdivide = function() {
  9057. return arguments.length && axis;
  9058. };
  9059. return axis;
  9060. };
  9061. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  9062. top: 1,
  9063. right: 1,
  9064. bottom: 1,
  9065. left: 1
  9066. };
  9067. function d3_svg_axisX(selection, x0, x1) {
  9068. selection.attr("transform", function(d) {
  9069. var v0 = x0(d);
  9070. return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
  9071. });
  9072. }
  9073. function d3_svg_axisY(selection, y0, y1) {
  9074. selection.attr("transform", function(d) {
  9075. var v0 = y0(d);
  9076. return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
  9077. });
  9078. }
  9079. d3.svg.brush = function() {
  9080. 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];
  9081. function brush(g) {
  9082. g.each(function() {
  9083. 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);
  9084. var background = g.selectAll(".background").data([ 0 ]);
  9085. background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  9086. g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
  9087. var resize = g.selectAll(".resize").data(resizes, d3_identity);
  9088. resize.exit().remove();
  9089. resize.enter().append("g").attr("class", function(d) {
  9090. return "resize " + d;
  9091. }).style("cursor", function(d) {
  9092. return d3_svg_brushCursor[d];
  9093. }).append("rect").attr("x", function(d) {
  9094. return /[ew]$/.test(d) ? -3 : null;
  9095. }).attr("y", function(d) {
  9096. return /^[ns]/.test(d) ? -3 : null;
  9097. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  9098. resize.style("display", brush.empty() ? "none" : null);
  9099. var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
  9100. if (x) {
  9101. range = d3_scaleRange(x);
  9102. backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
  9103. redrawX(gUpdate);
  9104. }
  9105. if (y) {
  9106. range = d3_scaleRange(y);
  9107. backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
  9108. redrawY(gUpdate);
  9109. }
  9110. redraw(gUpdate);
  9111. });
  9112. }
  9113. brush.event = function(g) {
  9114. g.each(function() {
  9115. var event_ = event.of(this, arguments), extent1 = {
  9116. x: xExtent,
  9117. y: yExtent,
  9118. i: xExtentDomain,
  9119. j: yExtentDomain
  9120. }, extent0 = this.__chart__ || extent1;
  9121. this.__chart__ = extent1;
  9122. if (d3_transitionInheritId) {
  9123. d3.select(this).transition().each("start.brush", function() {
  9124. xExtentDomain = extent0.i;
  9125. yExtentDomain = extent0.j;
  9126. xExtent = extent0.x;
  9127. yExtent = extent0.y;
  9128. event_({
  9129. type: "brushstart"
  9130. });
  9131. }).tween("brush:brush", function() {
  9132. var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
  9133. xExtentDomain = yExtentDomain = null;
  9134. return function(t) {
  9135. xExtent = extent1.x = xi(t);
  9136. yExtent = extent1.y = yi(t);
  9137. event_({
  9138. type: "brush",
  9139. mode: "resize"
  9140. });
  9141. };
  9142. }).each("end.brush", function() {
  9143. xExtentDomain = extent1.i;
  9144. yExtentDomain = extent1.j;
  9145. event_({
  9146. type: "brush",
  9147. mode: "resize"
  9148. });
  9149. event_({
  9150. type: "brushend"
  9151. });
  9152. });
  9153. } else {
  9154. event_({
  9155. type: "brushstart"
  9156. });
  9157. event_({
  9158. type: "brush",
  9159. mode: "resize"
  9160. });
  9161. event_({
  9162. type: "brushend"
  9163. });
  9164. }
  9165. });
  9166. };
  9167. function redraw(g) {
  9168. g.selectAll(".resize").attr("transform", function(d) {
  9169. return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
  9170. });
  9171. }
  9172. function redrawX(g) {
  9173. g.select(".extent").attr("x", xExtent[0]);
  9174. g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
  9175. }
  9176. function redrawY(g) {
  9177. g.select(".extent").attr("y", yExtent[0]);
  9178. g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
  9179. }
  9180. function brushstart() {
  9181. 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;
  9182. var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
  9183. if (d3.event.changedTouches) {
  9184. w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
  9185. } else {
  9186. w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
  9187. }
  9188. g.interrupt().selectAll("*").interrupt();
  9189. if (dragging) {
  9190. origin[0] = xExtent[0] - origin[0];
  9191. origin[1] = yExtent[0] - origin[1];
  9192. } else if (resizing) {
  9193. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  9194. offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
  9195. origin[0] = xExtent[ex];
  9196. origin[1] = yExtent[ey];
  9197. } else if (d3.event.altKey) center = origin.slice();
  9198. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  9199. d3.select("body").style("cursor", eventTarget.style("cursor"));
  9200. event_({
  9201. type: "brushstart"
  9202. });
  9203. brushmove();
  9204. function keydown() {
  9205. if (d3.event.keyCode == 32) {
  9206. if (!dragging) {
  9207. center = null;
  9208. origin[0] -= xExtent[1];
  9209. origin[1] -= yExtent[1];
  9210. dragging = 2;
  9211. }
  9212. d3_eventPreventDefault();
  9213. }
  9214. }
  9215. function keyup() {
  9216. if (d3.event.keyCode == 32 && dragging == 2) {
  9217. origin[0] += xExtent[1];
  9218. origin[1] += yExtent[1];
  9219. dragging = 0;
  9220. d3_eventPreventDefault();
  9221. }
  9222. }
  9223. function brushmove() {
  9224. var point = d3.mouse(target), moved = false;
  9225. if (offset) {
  9226. point[0] += offset[0];
  9227. point[1] += offset[1];
  9228. }
  9229. if (!dragging) {
  9230. if (d3.event.altKey) {
  9231. if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
  9232. origin[0] = xExtent[+(point[0] < center[0])];
  9233. origin[1] = yExtent[+(point[1] < center[1])];
  9234. } else center = null;
  9235. }
  9236. if (resizingX && move1(point, x, 0)) {
  9237. redrawX(g);
  9238. moved = true;
  9239. }
  9240. if (resizingY && move1(point, y, 1)) {
  9241. redrawY(g);
  9242. moved = true;
  9243. }
  9244. if (moved) {
  9245. redraw(g);
  9246. event_({
  9247. type: "brush",
  9248. mode: dragging ? "move" : "resize"
  9249. });
  9250. }
  9251. }
  9252. function move1(point, scale, i) {
  9253. 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;
  9254. if (dragging) {
  9255. r0 -= position;
  9256. r1 -= size + position;
  9257. }
  9258. min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
  9259. if (dragging) {
  9260. max = (min += position) + size;
  9261. } else {
  9262. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  9263. if (position < min) {
  9264. max = min;
  9265. min = position;
  9266. } else {
  9267. max = position;
  9268. }
  9269. }
  9270. if (extent[0] != min || extent[1] != max) {
  9271. if (i) yExtentDomain = null; else xExtentDomain = null;
  9272. extent[0] = min;
  9273. extent[1] = max;
  9274. return true;
  9275. }
  9276. }
  9277. function brushend() {
  9278. brushmove();
  9279. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  9280. d3.select("body").style("cursor", null);
  9281. 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);
  9282. dragRestore();
  9283. event_({
  9284. type: "brushend"
  9285. });
  9286. }
  9287. }
  9288. brush.x = function(z) {
  9289. if (!arguments.length) return x;
  9290. x = z;
  9291. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9292. return brush;
  9293. };
  9294. brush.y = function(z) {
  9295. if (!arguments.length) return y;
  9296. y = z;
  9297. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9298. return brush;
  9299. };
  9300. brush.clamp = function(z) {
  9301. if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
  9302. if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
  9303. return brush;
  9304. };
  9305. brush.extent = function(z) {
  9306. var x0, x1, y0, y1, t;
  9307. if (!arguments.length) {
  9308. if (x) {
  9309. if (xExtentDomain) {
  9310. x0 = xExtentDomain[0], x1 = xExtentDomain[1];
  9311. } else {
  9312. x0 = xExtent[0], x1 = xExtent[1];
  9313. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  9314. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9315. }
  9316. }
  9317. if (y) {
  9318. if (yExtentDomain) {
  9319. y0 = yExtentDomain[0], y1 = yExtentDomain[1];
  9320. } else {
  9321. y0 = yExtent[0], y1 = yExtent[1];
  9322. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  9323. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9324. }
  9325. }
  9326. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  9327. }
  9328. if (x) {
  9329. x0 = z[0], x1 = z[1];
  9330. if (y) x0 = x0[0], x1 = x1[0];
  9331. xExtentDomain = [ x0, x1 ];
  9332. if (x.invert) x0 = x(x0), x1 = x(x1);
  9333. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9334. if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
  9335. }
  9336. if (y) {
  9337. y0 = z[0], y1 = z[1];
  9338. if (x) y0 = y0[1], y1 = y1[1];
  9339. yExtentDomain = [ y0, y1 ];
  9340. if (y.invert) y0 = y(y0), y1 = y(y1);
  9341. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9342. if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
  9343. }
  9344. return brush;
  9345. };
  9346. brush.clear = function() {
  9347. if (!brush.empty()) {
  9348. xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
  9349. xExtentDomain = yExtentDomain = null;
  9350. }
  9351. return brush;
  9352. };
  9353. brush.empty = function() {
  9354. return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
  9355. };
  9356. return d3.rebind(brush, event, "on");
  9357. };
  9358. var d3_svg_brushCursor = {
  9359. n: "ns-resize",
  9360. e: "ew-resize",
  9361. s: "ns-resize",
  9362. w: "ew-resize",
  9363. nw: "nwse-resize",
  9364. ne: "nesw-resize",
  9365. se: "nwse-resize",
  9366. sw: "nesw-resize"
  9367. };
  9368. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  9369. var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
  9370. var d3_time_formatUtc = d3_time_format.utc;
  9371. var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
  9372. d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  9373. function d3_time_formatIsoNative(date) {
  9374. return date.toISOString();
  9375. }
  9376. d3_time_formatIsoNative.parse = function(string) {
  9377. var date = new Date(string);
  9378. return isNaN(date) ? null : date;
  9379. };
  9380. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  9381. d3_time.second = d3_time_interval(function(date) {
  9382. return new d3_date(Math.floor(date / 1e3) * 1e3);
  9383. }, function(date, offset) {
  9384. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  9385. }, function(date) {
  9386. return date.getSeconds();
  9387. });
  9388. d3_time.seconds = d3_time.second.range;
  9389. d3_time.seconds.utc = d3_time.second.utc.range;
  9390. d3_time.minute = d3_time_interval(function(date) {
  9391. return new d3_date(Math.floor(date / 6e4) * 6e4);
  9392. }, function(date, offset) {
  9393. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  9394. }, function(date) {
  9395. return date.getMinutes();
  9396. });
  9397. d3_time.minutes = d3_time.minute.range;
  9398. d3_time.minutes.utc = d3_time.minute.utc.range;
  9399. d3_time.hour = d3_time_interval(function(date) {
  9400. var timezone = date.getTimezoneOffset() / 60;
  9401. return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  9402. }, function(date, offset) {
  9403. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  9404. }, function(date) {
  9405. return date.getHours();
  9406. });
  9407. d3_time.hours = d3_time.hour.range;
  9408. d3_time.hours.utc = d3_time.hour.utc.range;
  9409. d3_time.month = d3_time_interval(function(date) {
  9410. date = d3_time.day(date);
  9411. date.setDate(1);
  9412. return date;
  9413. }, function(date, offset) {
  9414. date.setMonth(date.getMonth() + offset);
  9415. }, function(date) {
  9416. return date.getMonth();
  9417. });
  9418. d3_time.months = d3_time.month.range;
  9419. d3_time.months.utc = d3_time.month.utc.range;
  9420. function d3_time_scale(linear, methods, format) {
  9421. function scale(x) {
  9422. return linear(x);
  9423. }
  9424. scale.invert = function(x) {
  9425. return d3_time_scaleDate(linear.invert(x));
  9426. };
  9427. scale.domain = function(x) {
  9428. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  9429. linear.domain(x);
  9430. return scale;
  9431. };
  9432. function tickMethod(extent, count) {
  9433. var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
  9434. return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
  9435. return d / 31536e6;
  9436. }), 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];
  9437. }
  9438. scale.nice = function(interval, skip) {
  9439. var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
  9440. if (method) interval = method[0], skip = method[1];
  9441. function skipped(date) {
  9442. return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
  9443. }
  9444. return scale.domain(d3_scale_nice(domain, skip > 1 ? {
  9445. floor: function(date) {
  9446. while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
  9447. return date;
  9448. },
  9449. ceil: function(date) {
  9450. while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
  9451. return date;
  9452. }
  9453. } : interval));
  9454. };
  9455. scale.ticks = function(interval, skip) {
  9456. var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
  9457. range: interval
  9458. }, skip ];
  9459. if (method) interval = method[0], skip = method[1];
  9460. return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
  9461. };
  9462. scale.tickFormat = function() {
  9463. return format;
  9464. };
  9465. scale.copy = function() {
  9466. return d3_time_scale(linear.copy(), methods, format);
  9467. };
  9468. return d3_scale_linearRebind(scale, linear);
  9469. }
  9470. function d3_time_scaleDate(t) {
  9471. return new Date(t);
  9472. }
  9473. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  9474. 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 ] ];
  9475. var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
  9476. return d.getMilliseconds();
  9477. } ], [ ":%S", function(d) {
  9478. return d.getSeconds();
  9479. } ], [ "%I:%M", function(d) {
  9480. return d.getMinutes();
  9481. } ], [ "%I %p", function(d) {
  9482. return d.getHours();
  9483. } ], [ "%a %d", function(d) {
  9484. return d.getDay() && d.getDate() != 1;
  9485. } ], [ "%b %d", function(d) {
  9486. return d.getDate() != 1;
  9487. } ], [ "%B", function(d) {
  9488. return d.getMonth();
  9489. } ], [ "%Y", d3_true ] ]);
  9490. var d3_time_scaleMilliseconds = {
  9491. range: function(start, stop, step) {
  9492. return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
  9493. },
  9494. floor: d3_identity,
  9495. ceil: d3_identity
  9496. };
  9497. d3_time_scaleLocalMethods.year = d3_time.year;
  9498. d3_time.scale = function() {
  9499. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  9500. };
  9501. var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
  9502. return [ m[0].utc, m[1] ];
  9503. });
  9504. var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
  9505. return d.getUTCMilliseconds();
  9506. } ], [ ":%S", function(d) {
  9507. return d.getUTCSeconds();
  9508. } ], [ "%I:%M", function(d) {
  9509. return d.getUTCMinutes();
  9510. } ], [ "%I %p", function(d) {
  9511. return d.getUTCHours();
  9512. } ], [ "%a %d", function(d) {
  9513. return d.getUTCDay() && d.getUTCDate() != 1;
  9514. } ], [ "%b %d", function(d) {
  9515. return d.getUTCDate() != 1;
  9516. } ], [ "%B", function(d) {
  9517. return d.getUTCMonth();
  9518. } ], [ "%Y", d3_true ] ]);
  9519. d3_time_scaleUtcMethods.year = d3_time.year.utc;
  9520. d3_time.scale.utc = function() {
  9521. return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
  9522. };
  9523. d3.text = d3_xhrType(function(request) {
  9524. return request.responseText;
  9525. });
  9526. d3.json = function(url, callback) {
  9527. return d3_xhr(url, "application/json", d3_json, callback);
  9528. };
  9529. function d3_json(request) {
  9530. return JSON.parse(request.responseText);
  9531. }
  9532. d3.html = function(url, callback) {
  9533. return d3_xhr(url, "text/html", d3_html, callback);
  9534. };
  9535. function d3_html(request) {
  9536. var range = d3_document.createRange();
  9537. range.selectNode(d3_document.body);
  9538. return range.createContextualFragment(request.responseText);
  9539. }
  9540. d3.xml = d3_xhrType(function(request) {
  9541. return request.responseXML;
  9542. });
  9543. if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
  9544. }();