d3.v3.js 308 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981
  1. d3 = function() {
  2. var d3 = {
  3. version: "3.3.6"
  4. };
  5. if (!Date.now) Date.now = function() {
  6. return +new Date();
  7. };
  8. var d3_arraySlice = [].slice, d3_array = function(list) {
  9. return d3_arraySlice.call(list);
  10. };
  11. var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window;
  12. try {
  13. d3_array(d3_documentElement.childNodes)[0].nodeType;
  14. } catch (e) {
  15. d3_array = function(list) {
  16. var i = list.length, array = new Array(i);
  17. while (i--) array[i] = list[i];
  18. return array;
  19. };
  20. }
  21. try {
  22. d3_document.createElement("div").style.setProperty("opacity", 0, "");
  23. } catch (error) {
  24. var d3_element_prototype = d3_window.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
  25. d3_element_prototype.setAttribute = function(name, value) {
  26. d3_element_setAttribute.call(this, name, value + "");
  27. };
  28. d3_element_prototype.setAttributeNS = function(space, local, value) {
  29. d3_element_setAttributeNS.call(this, space, local, value + "");
  30. };
  31. d3_style_prototype.setProperty = function(name, value, priority) {
  32. d3_style_setProperty.call(this, name, value + "", priority);
  33. };
  34. }
  35. d3.ascending = function(a, b) {
  36. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  37. };
  38. d3.descending = function(a, b) {
  39. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  40. };
  41. d3.min = function(array, f) {
  42. var i = -1, n = array.length, a, b;
  43. if (arguments.length === 1) {
  44. while (++i < n && !((a = array[i]) != null && a <= a)) a = undefined;
  45. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  46. } else {
  47. while (++i < n && !((a = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
  48. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  49. }
  50. return a;
  51. };
  52. d3.max = function(array, f) {
  53. var i = -1, n = array.length, a, b;
  54. if (arguments.length === 1) {
  55. while (++i < n && !((a = array[i]) != null && a <= a)) a = undefined;
  56. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  57. } else {
  58. while (++i < n && !((a = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
  59. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  60. }
  61. return a;
  62. };
  63. d3.extent = function(array, f) {
  64. var i = -1, n = array.length, a, b, c;
  65. if (arguments.length === 1) {
  66. while (++i < n && !((a = c = array[i]) != null && a <= a)) a = c = undefined;
  67. while (++i < n) if ((b = array[i]) != null) {
  68. if (a > b) a = b;
  69. if (c < b) c = b;
  70. }
  71. } else {
  72. while (++i < n && !((a = c = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
  73. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  74. if (a > b) a = b;
  75. if (c < b) c = b;
  76. }
  77. }
  78. return [ a, c ];
  79. };
  80. d3.sum = function(array, f) {
  81. var s = 0, n = array.length, a, i = -1;
  82. if (arguments.length === 1) {
  83. while (++i < n) if (!isNaN(a = +array[i])) s += a;
  84. } else {
  85. while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
  86. }
  87. return s;
  88. };
  89. function d3_number(x) {
  90. return x != null && !isNaN(x);
  91. }
  92. d3.mean = function(array, f) {
  93. var n = array.length, a, m = 0, i = -1, j = 0;
  94. if (arguments.length === 1) {
  95. while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j;
  96. } else {
  97. while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j;
  98. }
  99. return j ? m : undefined;
  100. };
  101. d3.quantile = function(values, p) {
  102. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  103. return e ? v + e * (values[h] - v) : v;
  104. };
  105. d3.median = function(array, f) {
  106. if (arguments.length > 1) array = array.map(f);
  107. array = array.filter(d3_number);
  108. return array.length ? d3.quantile(array.sort(d3.ascending), .5) : undefined;
  109. };
  110. d3.bisector = function(f) {
  111. return {
  112. left: function(a, x, lo, hi) {
  113. if (arguments.length < 3) lo = 0;
  114. if (arguments.length < 4) hi = a.length;
  115. while (lo < hi) {
  116. var mid = lo + hi >>> 1;
  117. if (f.call(a, a[mid], mid) < x) lo = mid + 1; else hi = mid;
  118. }
  119. return lo;
  120. },
  121. right: function(a, x, lo, hi) {
  122. if (arguments.length < 3) lo = 0;
  123. if (arguments.length < 4) hi = a.length;
  124. while (lo < hi) {
  125. var mid = lo + hi >>> 1;
  126. if (x < f.call(a, a[mid], mid)) hi = mid; else lo = mid + 1;
  127. }
  128. return lo;
  129. }
  130. };
  131. };
  132. var d3_bisector = d3.bisector(function(d) {
  133. return d;
  134. });
  135. d3.bisectLeft = d3_bisector.left;
  136. d3.bisect = d3.bisectRight = d3_bisector.right;
  137. d3.shuffle = function(array) {
  138. var m = array.length, t, i;
  139. while (m) {
  140. i = Math.random() * m-- | 0;
  141. t = array[m], array[m] = array[i], array[i] = t;
  142. }
  143. return array;
  144. };
  145. d3.permute = function(array, indexes) {
  146. var i = indexes.length, permutes = new Array(i);
  147. while (i--) permutes[i] = array[indexes[i]];
  148. return permutes;
  149. };
  150. d3.pairs = function(array) {
  151. var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
  152. while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
  153. return pairs;
  154. };
  155. d3.zip = function() {
  156. if (!(n = arguments.length)) return [];
  157. for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
  158. for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
  159. zip[j] = arguments[j][i];
  160. }
  161. }
  162. return zips;
  163. };
  164. function d3_zipLength(d) {
  165. return d.length;
  166. }
  167. d3.transpose = function(matrix) {
  168. return d3.zip.apply(d3, matrix);
  169. };
  170. d3.keys = function(map) {
  171. var keys = [];
  172. for (var key in map) keys.push(key);
  173. return keys;
  174. };
  175. d3.values = function(map) {
  176. var values = [];
  177. for (var key in map) values.push(map[key]);
  178. return values;
  179. };
  180. d3.entries = function(map) {
  181. var entries = [];
  182. for (var key in map) entries.push({
  183. key: key,
  184. value: map[key]
  185. });
  186. return entries;
  187. };
  188. d3.merge = function(arrays) {
  189. return Array.prototype.concat.apply([], arrays);
  190. };
  191. d3.range = function(start, stop, step) {
  192. if (arguments.length < 3) {
  193. step = 1;
  194. if (arguments.length < 2) {
  195. stop = start;
  196. start = 0;
  197. }
  198. }
  199. if ((stop - start) / step === Infinity) throw new Error("infinite range");
  200. var range = [], k = d3_range_integerScale(Math.abs(step)), i = -1, j;
  201. start *= k, stop *= k, step *= k;
  202. if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
  203. return range;
  204. };
  205. function d3_range_integerScale(x) {
  206. var k = 1;
  207. while (x * k % 1) k *= 10;
  208. return k;
  209. }
  210. function d3_class(ctor, properties) {
  211. try {
  212. for (var key in properties) {
  213. Object.defineProperty(ctor.prototype, key, {
  214. value: properties[key],
  215. enumerable: false
  216. });
  217. }
  218. } catch (e) {
  219. ctor.prototype = properties;
  220. }
  221. }
  222. d3.map = function(object) {
  223. var map = new d3_Map();
  224. if (object instanceof d3_Map) object.forEach(function(key, value) {
  225. map.set(key, value);
  226. }); else for (var key in object) map.set(key, object[key]);
  227. return map;
  228. };
  229. function d3_Map() {}
  230. d3_class(d3_Map, {
  231. has: function(key) {
  232. return d3_map_prefix + key in this;
  233. },
  234. get: function(key) {
  235. return this[d3_map_prefix + key];
  236. },
  237. set: function(key, value) {
  238. return this[d3_map_prefix + key] = value;
  239. },
  240. remove: function(key) {
  241. key = d3_map_prefix + key;
  242. return key in this && delete this[key];
  243. },
  244. keys: function() {
  245. var keys = [];
  246. this.forEach(function(key) {
  247. keys.push(key);
  248. });
  249. return keys;
  250. },
  251. values: function() {
  252. var values = [];
  253. this.forEach(function(key, value) {
  254. values.push(value);
  255. });
  256. return values;
  257. },
  258. entries: function() {
  259. var entries = [];
  260. this.forEach(function(key, value) {
  261. entries.push({
  262. key: key,
  263. value: value
  264. });
  265. });
  266. return entries;
  267. },
  268. forEach: function(f) {
  269. for (var key in this) {
  270. if (key.charCodeAt(0) === d3_map_prefixCode) {
  271. f.call(this, key.substring(1), this[key]);
  272. }
  273. }
  274. }
  275. });
  276. var d3_map_prefix = "\x00", d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
  277. d3.nest = function() {
  278. var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
  279. function map(mapType, array, depth) {
  280. if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
  281. var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
  282. while (++i < n) {
  283. if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
  284. values.push(object);
  285. } else {
  286. valuesByKey.set(keyValue, [ object ]);
  287. }
  288. }
  289. if (mapType) {
  290. object = mapType();
  291. setter = function(keyValue, values) {
  292. object.set(keyValue, map(mapType, values, depth));
  293. };
  294. } else {
  295. object = {};
  296. setter = function(keyValue, values) {
  297. object[keyValue] = map(mapType, values, depth);
  298. };
  299. }
  300. valuesByKey.forEach(setter);
  301. return object;
  302. }
  303. function entries(map, depth) {
  304. if (depth >= keys.length) return map;
  305. var array = [], sortKey = sortKeys[depth++];
  306. map.forEach(function(key, keyMap) {
  307. array.push({
  308. key: key,
  309. values: entries(keyMap, depth)
  310. });
  311. });
  312. return sortKey ? array.sort(function(a, b) {
  313. return sortKey(a.key, b.key);
  314. }) : array;
  315. }
  316. nest.map = function(array, mapType) {
  317. return map(mapType, array, 0);
  318. };
  319. nest.entries = function(array) {
  320. return entries(map(d3.map, array, 0), 0);
  321. };
  322. nest.key = function(d) {
  323. keys.push(d);
  324. return nest;
  325. };
  326. nest.sortKeys = function(order) {
  327. sortKeys[keys.length - 1] = order;
  328. return nest;
  329. };
  330. nest.sortValues = function(order) {
  331. sortValues = order;
  332. return nest;
  333. };
  334. nest.rollup = function(f) {
  335. rollup = f;
  336. return nest;
  337. };
  338. return nest;
  339. };
  340. d3.set = function(array) {
  341. var set = new d3_Set();
  342. if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
  343. return set;
  344. };
  345. function d3_Set() {}
  346. d3_class(d3_Set, {
  347. has: function(value) {
  348. return d3_map_prefix + value in this;
  349. },
  350. add: function(value) {
  351. this[d3_map_prefix + value] = true;
  352. return value;
  353. },
  354. remove: function(value) {
  355. value = d3_map_prefix + value;
  356. return value in this && delete this[value];
  357. },
  358. values: function() {
  359. var values = [];
  360. this.forEach(function(value) {
  361. values.push(value);
  362. });
  363. return values;
  364. },
  365. forEach: function(f) {
  366. for (var value in this) {
  367. if (value.charCodeAt(0) === d3_map_prefixCode) {
  368. f.call(this, value.substring(1));
  369. }
  370. }
  371. }
  372. });
  373. d3.behavior = {};
  374. d3.rebind = function(target, source) {
  375. var i = 1, n = arguments.length, method;
  376. while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
  377. return target;
  378. };
  379. function d3_rebind(target, source, method) {
  380. return function() {
  381. var value = method.apply(source, arguments);
  382. return value === source ? target : value;
  383. };
  384. }
  385. function d3_vendorSymbol(object, name) {
  386. if (name in object) return name;
  387. name = name.charAt(0).toUpperCase() + name.substring(1);
  388. for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
  389. var prefixName = d3_vendorPrefixes[i] + name;
  390. if (prefixName in object) return prefixName;
  391. }
  392. }
  393. var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
  394. function d3_noop() {}
  395. d3.dispatch = function() {
  396. var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
  397. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  398. return dispatch;
  399. };
  400. function d3_dispatch() {}
  401. d3_dispatch.prototype.on = function(type, listener) {
  402. var i = type.indexOf("."), name = "";
  403. if (i >= 0) {
  404. name = type.substring(i + 1);
  405. type = type.substring(0, i);
  406. }
  407. if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
  408. if (arguments.length === 2) {
  409. if (listener == null) for (type in this) {
  410. if (this.hasOwnProperty(type)) this[type].on(name, null);
  411. }
  412. return this;
  413. }
  414. };
  415. function d3_dispatch_event(dispatch) {
  416. var listeners = [], listenerByName = new d3_Map();
  417. function event() {
  418. var z = listeners, i = -1, n = z.length, l;
  419. while (++i < n) if (l = z[i].on) l.apply(this, arguments);
  420. return dispatch;
  421. }
  422. event.on = function(name, listener) {
  423. var l = listenerByName.get(name), i;
  424. if (arguments.length < 2) return l && l.on;
  425. if (l) {
  426. l.on = null;
  427. listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
  428. listenerByName.remove(name);
  429. }
  430. if (listener) listeners.push(listenerByName.set(name, {
  431. on: listener
  432. }));
  433. return dispatch;
  434. };
  435. return event;
  436. }
  437. d3.event = null;
  438. function d3_eventPreventDefault() {
  439. d3.event.preventDefault();
  440. }
  441. function d3_eventSource() {
  442. var e = d3.event, s;
  443. while (s = e.sourceEvent) e = s;
  444. return e;
  445. }
  446. function d3_eventDispatch(target) {
  447. var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
  448. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  449. dispatch.of = function(thiz, argumentz) {
  450. return function(e1) {
  451. try {
  452. var e0 = e1.sourceEvent = d3.event;
  453. e1.target = target;
  454. d3.event = e1;
  455. dispatch[e1.type].apply(thiz, argumentz);
  456. } finally {
  457. d3.event = e0;
  458. }
  459. };
  460. };
  461. return dispatch;
  462. }
  463. d3.requote = function(s) {
  464. return s.replace(d3_requote_re, "\\$&");
  465. };
  466. var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  467. var d3_subclass = {}.__proto__ ? function(object, prototype) {
  468. object.__proto__ = prototype;
  469. } : function(object, prototype) {
  470. for (var property in prototype) object[property] = prototype[property];
  471. };
  472. function d3_selection(groups) {
  473. d3_subclass(groups, d3_selectionPrototype);
  474. return groups;
  475. }
  476. var d3_select = function(s, n) {
  477. return n.querySelector(s);
  478. }, d3_selectAll = function(s, n) {
  479. return n.querySelectorAll(s);
  480. }, d3_selectMatcher = d3_documentElement[d3_vendorSymbol(d3_documentElement, "matchesSelector")], d3_selectMatches = function(n, s) {
  481. return d3_selectMatcher.call(n, s);
  482. };
  483. if (typeof Sizzle === "function") {
  484. d3_select = function(s, n) {
  485. return Sizzle(s, n)[0] || null;
  486. };
  487. d3_selectAll = function(s, n) {
  488. return Sizzle.uniqueSort(Sizzle(s, n));
  489. };
  490. d3_selectMatches = Sizzle.matchesSelector;
  491. }
  492. d3.selection = function() {
  493. return d3_selectionRoot;
  494. };
  495. var d3_selectionPrototype = d3.selection.prototype = [];
  496. d3_selectionPrototype.select = function(selector) {
  497. var subgroups = [], subgroup, subnode, group, node;
  498. selector = d3_selection_selector(selector);
  499. for (var j = -1, m = this.length; ++j < m; ) {
  500. subgroups.push(subgroup = []);
  501. subgroup.parentNode = (group = this[j]).parentNode;
  502. for (var i = -1, n = group.length; ++i < n; ) {
  503. if (node = group[i]) {
  504. subgroup.push(subnode = selector.call(node, node.__data__, i, j));
  505. if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
  506. } else {
  507. subgroup.push(null);
  508. }
  509. }
  510. }
  511. return d3_selection(subgroups);
  512. };
  513. function d3_selection_selector(selector) {
  514. return typeof selector === "function" ? selector : function() {
  515. return d3_select(selector, this);
  516. };
  517. }
  518. d3_selectionPrototype.selectAll = function(selector) {
  519. var subgroups = [], subgroup, node;
  520. selector = d3_selection_selectorAll(selector);
  521. for (var j = -1, m = this.length; ++j < m; ) {
  522. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  523. if (node = group[i]) {
  524. subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
  525. subgroup.parentNode = node;
  526. }
  527. }
  528. }
  529. return d3_selection(subgroups);
  530. };
  531. function d3_selection_selectorAll(selector) {
  532. return typeof selector === "function" ? selector : function() {
  533. return d3_selectAll(selector, this);
  534. };
  535. }
  536. var d3_nsPrefix = {
  537. svg: "http://www.w3.org/2000/svg",
  538. xhtml: "http://www.w3.org/1999/xhtml",
  539. xlink: "http://www.w3.org/1999/xlink",
  540. xml: "http://www.w3.org/XML/1998/namespace",
  541. xmlns: "http://www.w3.org/2000/xmlns/"
  542. };
  543. d3.ns = {
  544. prefix: d3_nsPrefix,
  545. qualify: function(name) {
  546. var i = name.indexOf(":"), prefix = name;
  547. if (i >= 0) {
  548. prefix = name.substring(0, i);
  549. name = name.substring(i + 1);
  550. }
  551. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  552. space: d3_nsPrefix[prefix],
  553. local: name
  554. } : name;
  555. }
  556. };
  557. d3_selectionPrototype.attr = function(name, value) {
  558. if (arguments.length < 2) {
  559. if (typeof name === "string") {
  560. var node = this.node();
  561. name = d3.ns.qualify(name);
  562. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  563. }
  564. for (value in name) this.each(d3_selection_attr(value, name[value]));
  565. return this;
  566. }
  567. return this.each(d3_selection_attr(name, value));
  568. };
  569. function d3_selection_attr(name, value) {
  570. name = d3.ns.qualify(name);
  571. function attrNull() {
  572. this.removeAttribute(name);
  573. }
  574. function attrNullNS() {
  575. this.removeAttributeNS(name.space, name.local);
  576. }
  577. function attrConstant() {
  578. this.setAttribute(name, value);
  579. }
  580. function attrConstantNS() {
  581. this.setAttributeNS(name.space, name.local, value);
  582. }
  583. function attrFunction() {
  584. var x = value.apply(this, arguments);
  585. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  586. }
  587. function attrFunctionNS() {
  588. var x = value.apply(this, arguments);
  589. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  590. }
  591. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  592. }
  593. function d3_collapse(s) {
  594. return s.trim().replace(/\s+/g, " ");
  595. }
  596. d3_selectionPrototype.classed = function(name, value) {
  597. if (arguments.length < 2) {
  598. if (typeof name === "string") {
  599. var node = this.node(), n = (name = name.trim().split(/^|\s+/g)).length, i = -1;
  600. if (value = node.classList) {
  601. while (++i < n) if (!value.contains(name[i])) return false;
  602. } else {
  603. value = node.getAttribute("class");
  604. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  605. }
  606. return true;
  607. }
  608. for (value in name) this.each(d3_selection_classed(value, name[value]));
  609. return this;
  610. }
  611. return this.each(d3_selection_classed(name, value));
  612. };
  613. function d3_selection_classedRe(name) {
  614. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  615. }
  616. function d3_selection_classed(name, value) {
  617. name = name.trim().split(/\s+/).map(d3_selection_classedName);
  618. var n = name.length;
  619. function classedConstant() {
  620. var i = -1;
  621. while (++i < n) name[i](this, value);
  622. }
  623. function classedFunction() {
  624. var i = -1, x = value.apply(this, arguments);
  625. while (++i < n) name[i](this, x);
  626. }
  627. return typeof value === "function" ? classedFunction : classedConstant;
  628. }
  629. function d3_selection_classedName(name) {
  630. var re = d3_selection_classedRe(name);
  631. return function(node, value) {
  632. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  633. var c = node.getAttribute("class") || "";
  634. if (value) {
  635. re.lastIndex = 0;
  636. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  637. } else {
  638. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  639. }
  640. };
  641. }
  642. d3_selectionPrototype.style = function(name, value, priority) {
  643. var n = arguments.length;
  644. if (n < 3) {
  645. if (typeof name !== "string") {
  646. if (n < 2) value = "";
  647. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  648. return this;
  649. }
  650. if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
  651. priority = "";
  652. }
  653. return this.each(d3_selection_style(name, value, priority));
  654. };
  655. function d3_selection_style(name, value, priority) {
  656. function styleNull() {
  657. this.style.removeProperty(name);
  658. }
  659. function styleConstant() {
  660. this.style.setProperty(name, value, priority);
  661. }
  662. function styleFunction() {
  663. var x = value.apply(this, arguments);
  664. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  665. }
  666. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  667. }
  668. d3_selectionPrototype.property = function(name, value) {
  669. if (arguments.length < 2) {
  670. if (typeof name === "string") return this.node()[name];
  671. for (value in name) this.each(d3_selection_property(value, name[value]));
  672. return this;
  673. }
  674. return this.each(d3_selection_property(name, value));
  675. };
  676. function d3_selection_property(name, value) {
  677. function propertyNull() {
  678. delete this[name];
  679. }
  680. function propertyConstant() {
  681. this[name] = value;
  682. }
  683. function propertyFunction() {
  684. var x = value.apply(this, arguments);
  685. if (x == null) delete this[name]; else this[name] = x;
  686. }
  687. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  688. }
  689. d3_selectionPrototype.text = function(value) {
  690. return arguments.length ? this.each(typeof value === "function" ? function() {
  691. var v = value.apply(this, arguments);
  692. this.textContent = v == null ? "" : v;
  693. } : value == null ? function() {
  694. this.textContent = "";
  695. } : function() {
  696. this.textContent = value;
  697. }) : this.node().textContent;
  698. };
  699. d3_selectionPrototype.html = function(value) {
  700. return arguments.length ? this.each(typeof value === "function" ? function() {
  701. var v = value.apply(this, arguments);
  702. this.innerHTML = v == null ? "" : v;
  703. } : value == null ? function() {
  704. this.innerHTML = "";
  705. } : function() {
  706. this.innerHTML = value;
  707. }) : this.node().innerHTML;
  708. };
  709. d3_selectionPrototype.append = function(name) {
  710. name = d3_selection_creator(name);
  711. return this.select(function() {
  712. return this.appendChild(name.apply(this, arguments));
  713. });
  714. };
  715. function d3_selection_creator(name) {
  716. return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? function() {
  717. return d3_document.createElementNS(name.space, name.local);
  718. } : function() {
  719. return d3_document.createElementNS(this.namespaceURI, name);
  720. };
  721. }
  722. d3_selectionPrototype.insert = function(name, before) {
  723. name = d3_selection_creator(name);
  724. before = d3_selection_selector(before);
  725. return this.select(function() {
  726. return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments));
  727. });
  728. };
  729. d3_selectionPrototype.remove = function() {
  730. return this.each(function() {
  731. var parent = this.parentNode;
  732. if (parent) parent.removeChild(this);
  733. });
  734. };
  735. d3_selectionPrototype.data = function(value, key) {
  736. var i = -1, n = this.length, group, node;
  737. if (!arguments.length) {
  738. value = new Array(n = (group = this[0]).length);
  739. while (++i < n) {
  740. if (node = group[i]) {
  741. value[i] = node.__data__;
  742. }
  743. }
  744. return value;
  745. }
  746. function bind(group, groupData) {
  747. 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;
  748. if (key) {
  749. var nodeByKeyValue = new d3_Map(), dataByKeyValue = new d3_Map(), keyValues = [], keyValue;
  750. for (i = -1; ++i < n; ) {
  751. keyValue = key.call(node = group[i], node.__data__, i);
  752. if (nodeByKeyValue.has(keyValue)) {
  753. exitNodes[i] = node;
  754. } else {
  755. nodeByKeyValue.set(keyValue, node);
  756. }
  757. keyValues.push(keyValue);
  758. }
  759. for (i = -1; ++i < m; ) {
  760. keyValue = key.call(groupData, nodeData = groupData[i], i);
  761. if (node = nodeByKeyValue.get(keyValue)) {
  762. updateNodes[i] = node;
  763. node.__data__ = nodeData;
  764. } else if (!dataByKeyValue.has(keyValue)) {
  765. enterNodes[i] = d3_selection_dataNode(nodeData);
  766. }
  767. dataByKeyValue.set(keyValue, nodeData);
  768. nodeByKeyValue.remove(keyValue);
  769. }
  770. for (i = -1; ++i < n; ) {
  771. if (nodeByKeyValue.has(keyValues[i])) {
  772. exitNodes[i] = group[i];
  773. }
  774. }
  775. } else {
  776. for (i = -1; ++i < n0; ) {
  777. node = group[i];
  778. nodeData = groupData[i];
  779. if (node) {
  780. node.__data__ = nodeData;
  781. updateNodes[i] = node;
  782. } else {
  783. enterNodes[i] = d3_selection_dataNode(nodeData);
  784. }
  785. }
  786. for (;i < m; ++i) {
  787. enterNodes[i] = d3_selection_dataNode(groupData[i]);
  788. }
  789. for (;i < n; ++i) {
  790. exitNodes[i] = group[i];
  791. }
  792. }
  793. enterNodes.update = updateNodes;
  794. enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
  795. enter.push(enterNodes);
  796. update.push(updateNodes);
  797. exit.push(exitNodes);
  798. }
  799. var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
  800. if (typeof value === "function") {
  801. while (++i < n) {
  802. bind(group = this[i], value.call(group, group.parentNode.__data__, i));
  803. }
  804. } else {
  805. while (++i < n) {
  806. bind(group = this[i], value);
  807. }
  808. }
  809. update.enter = function() {
  810. return enter;
  811. };
  812. update.exit = function() {
  813. return exit;
  814. };
  815. return update;
  816. };
  817. function d3_selection_dataNode(data) {
  818. return {
  819. __data__: data
  820. };
  821. }
  822. d3_selectionPrototype.datum = function(value) {
  823. return arguments.length ? this.property("__data__", value) : this.property("__data__");
  824. };
  825. d3_selectionPrototype.filter = function(filter) {
  826. var subgroups = [], subgroup, group, node;
  827. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  828. for (var j = 0, m = this.length; j < m; j++) {
  829. subgroups.push(subgroup = []);
  830. subgroup.parentNode = (group = this[j]).parentNode;
  831. for (var i = 0, n = group.length; i < n; i++) {
  832. if ((node = group[i]) && filter.call(node, node.__data__, i)) {
  833. subgroup.push(node);
  834. }
  835. }
  836. }
  837. return d3_selection(subgroups);
  838. };
  839. function d3_selection_filter(selector) {
  840. return function() {
  841. return d3_selectMatches(this, selector);
  842. };
  843. }
  844. d3_selectionPrototype.order = function() {
  845. for (var j = -1, m = this.length; ++j < m; ) {
  846. for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
  847. if (node = group[i]) {
  848. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  849. next = node;
  850. }
  851. }
  852. }
  853. return this;
  854. };
  855. d3_selectionPrototype.sort = function(comparator) {
  856. comparator = d3_selection_sortComparator.apply(this, arguments);
  857. for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
  858. return this.order();
  859. };
  860. function d3_selection_sortComparator(comparator) {
  861. if (!arguments.length) comparator = d3.ascending;
  862. return function(a, b) {
  863. return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
  864. };
  865. }
  866. d3_selectionPrototype.each = function(callback) {
  867. return d3_selection_each(this, function(node, i, j) {
  868. callback.call(node, node.__data__, i, j);
  869. });
  870. };
  871. function d3_selection_each(groups, callback) {
  872. for (var j = 0, m = groups.length; j < m; j++) {
  873. for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
  874. if (node = group[i]) callback(node, i, j);
  875. }
  876. }
  877. return groups;
  878. }
  879. d3_selectionPrototype.call = function(callback) {
  880. var args = d3_array(arguments);
  881. callback.apply(args[0] = this, args);
  882. return this;
  883. };
  884. d3_selectionPrototype.empty = function() {
  885. return !this.node();
  886. };
  887. d3_selectionPrototype.node = function() {
  888. for (var j = 0, m = this.length; j < m; j++) {
  889. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  890. var node = group[i];
  891. if (node) return node;
  892. }
  893. }
  894. return null;
  895. };
  896. d3_selectionPrototype.size = function() {
  897. var n = 0;
  898. this.each(function() {
  899. ++n;
  900. });
  901. return n;
  902. };
  903. function d3_selection_enter(selection) {
  904. d3_subclass(selection, d3_selection_enterPrototype);
  905. return selection;
  906. }
  907. var d3_selection_enterPrototype = [];
  908. d3.selection.enter = d3_selection_enter;
  909. d3.selection.enter.prototype = d3_selection_enterPrototype;
  910. d3_selection_enterPrototype.append = d3_selectionPrototype.append;
  911. d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
  912. d3_selection_enterPrototype.node = d3_selectionPrototype.node;
  913. d3_selection_enterPrototype.call = d3_selectionPrototype.call;
  914. d3_selection_enterPrototype.size = d3_selectionPrototype.size;
  915. d3_selection_enterPrototype.select = function(selector) {
  916. var subgroups = [], subgroup, subnode, upgroup, group, node;
  917. for (var j = -1, m = this.length; ++j < m; ) {
  918. upgroup = (group = this[j]).update;
  919. subgroups.push(subgroup = []);
  920. subgroup.parentNode = group.parentNode;
  921. for (var i = -1, n = group.length; ++i < n; ) {
  922. if (node = group[i]) {
  923. subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
  924. subnode.__data__ = node.__data__;
  925. } else {
  926. subgroup.push(null);
  927. }
  928. }
  929. }
  930. return d3_selection(subgroups);
  931. };
  932. d3_selection_enterPrototype.insert = function(name, before) {
  933. if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
  934. return d3_selectionPrototype.insert.call(this, name, before);
  935. };
  936. function d3_selection_enterInsertBefore(enter) {
  937. var i0, j0;
  938. return function(d, i, j) {
  939. var group = enter[j].update, n = group.length, node;
  940. if (j != j0) j0 = j, i0 = 0;
  941. if (i >= i0) i0 = i + 1;
  942. while (!(node = group[i0]) && ++i0 < n) ;
  943. return node;
  944. };
  945. }
  946. d3_selectionPrototype.transition = function() {
  947. var id = d3_transitionInheritId || ++d3_transitionId, subgroups = [], subgroup, node, transition = d3_transitionInherit || {
  948. time: Date.now(),
  949. ease: d3_ease_cubicInOut,
  950. delay: 0,
  951. duration: 250
  952. };
  953. for (var j = -1, m = this.length; ++j < m; ) {
  954. subgroups.push(subgroup = []);
  955. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  956. if (node = group[i]) d3_transitionNode(node, i, id, transition);
  957. subgroup.push(node);
  958. }
  959. }
  960. return d3_transition(subgroups, id);
  961. };
  962. d3_selectionPrototype.interrupt = function() {
  963. return this.each(d3_selection_interrupt);
  964. };
  965. function d3_selection_interrupt() {
  966. var lock = this.__transition__;
  967. if (lock) ++lock.active;
  968. }
  969. d3.select = function(node) {
  970. var group = [ typeof node === "string" ? d3_select(node, d3_document) : node ];
  971. group.parentNode = d3_documentElement;
  972. return d3_selection([ group ]);
  973. };
  974. d3.selectAll = function(nodes) {
  975. var group = d3_array(typeof nodes === "string" ? d3_selectAll(nodes, d3_document) : nodes);
  976. group.parentNode = d3_documentElement;
  977. return d3_selection([ group ]);
  978. };
  979. var d3_selectionRoot = d3.select(d3_documentElement);
  980. d3_selectionPrototype.on = function(type, listener, capture) {
  981. var n = arguments.length;
  982. if (n < 3) {
  983. if (typeof type !== "string") {
  984. if (n < 2) listener = false;
  985. for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
  986. return this;
  987. }
  988. if (n < 2) return (n = this.node()["__on" + type]) && n._;
  989. capture = false;
  990. }
  991. return this.each(d3_selection_on(type, listener, capture));
  992. };
  993. function d3_selection_on(type, listener, capture) {
  994. var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
  995. if (i > 0) type = type.substring(0, i);
  996. var filter = d3_selection_onFilters.get(type);
  997. if (filter) type = filter, wrap = d3_selection_onFilter;
  998. function onRemove() {
  999. var l = this[name];
  1000. if (l) {
  1001. this.removeEventListener(type, l, l.$);
  1002. delete this[name];
  1003. }
  1004. }
  1005. function onAdd() {
  1006. var l = wrap(listener, d3_array(arguments));
  1007. onRemove.call(this);
  1008. this.addEventListener(type, this[name] = l, l.$ = capture);
  1009. l._ = listener;
  1010. }
  1011. function removeAll() {
  1012. var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
  1013. for (var name in this) {
  1014. if (match = name.match(re)) {
  1015. var l = this[name];
  1016. this.removeEventListener(match[1], l, l.$);
  1017. delete this[name];
  1018. }
  1019. }
  1020. }
  1021. return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
  1022. }
  1023. var d3_selection_onFilters = d3.map({
  1024. mouseenter: "mouseover",
  1025. mouseleave: "mouseout"
  1026. });
  1027. d3_selection_onFilters.forEach(function(k) {
  1028. if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
  1029. });
  1030. function d3_selection_onListener(listener, argumentz) {
  1031. return function(e) {
  1032. var o = d3.event;
  1033. d3.event = e;
  1034. argumentz[0] = this.__data__;
  1035. try {
  1036. listener.apply(this, argumentz);
  1037. } finally {
  1038. d3.event = o;
  1039. }
  1040. };
  1041. }
  1042. function d3_selection_onFilter(listener, argumentz) {
  1043. var l = d3_selection_onListener(listener, argumentz);
  1044. return function(e) {
  1045. var target = this, related = e.relatedTarget;
  1046. if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
  1047. l.call(target, e);
  1048. }
  1049. };
  1050. }
  1051. var d3_event_dragSelect = d3_vendorSymbol(d3_documentElement.style, "userSelect"), d3_event_dragId = 0;
  1052. function d3_event_dragSuppress() {
  1053. var name = ".dragsuppress-" + ++d3_event_dragId, touchmove = "touchmove" + name, selectstart = "selectstart" + name, dragstart = "dragstart" + name, click = "click" + name, w = d3.select(d3_window).on(touchmove, d3_eventPreventDefault).on(selectstart, d3_eventPreventDefault).on(dragstart, d3_eventPreventDefault), style = d3_documentElement.style, select = style[d3_event_dragSelect];
  1054. style[d3_event_dragSelect] = "none";
  1055. return function(suppressClick) {
  1056. w.on(name, null);
  1057. style[d3_event_dragSelect] = select;
  1058. if (suppressClick) {
  1059. function off() {
  1060. w.on(click, null);
  1061. }
  1062. w.on(click, function() {
  1063. d3_eventPreventDefault();
  1064. off();
  1065. }, true);
  1066. setTimeout(off, 0);
  1067. }
  1068. };
  1069. }
  1070. d3.mouse = function(container) {
  1071. return d3_mousePoint(container, d3_eventSource());
  1072. };
  1073. var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
  1074. function d3_mousePoint(container, e) {
  1075. if (e.changedTouches) e = e.changedTouches[0];
  1076. var svg = container.ownerSVGElement || container;
  1077. if (svg.createSVGPoint) {
  1078. var point = svg.createSVGPoint();
  1079. if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
  1080. svg = d3.select("body").append("svg").style({
  1081. position: "absolute",
  1082. top: 0,
  1083. left: 0,
  1084. margin: 0,
  1085. padding: 0,
  1086. border: "none"
  1087. }, "important");
  1088. var ctm = svg[0][0].getScreenCTM();
  1089. d3_mouse_bug44083 = !(ctm.f || ctm.e);
  1090. svg.remove();
  1091. }
  1092. if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
  1093. point.y = e.clientY;
  1094. point = point.matrixTransform(container.getScreenCTM().inverse());
  1095. return [ point.x, point.y ];
  1096. }
  1097. var rect = container.getBoundingClientRect();
  1098. return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
  1099. }
  1100. d3.touches = function(container, touches) {
  1101. if (arguments.length < 2) touches = d3_eventSource().touches;
  1102. return touches ? d3_array(touches).map(function(touch) {
  1103. var point = d3_mousePoint(container, touch);
  1104. point.identifier = touch.identifier;
  1105. return point;
  1106. }) : [];
  1107. };
  1108. d3.behavior.drag = function() {
  1109. var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, "mousemove", "mouseup"), touchstart = dragstart(touchid, touchposition, "touchmove", "touchend");
  1110. function drag() {
  1111. this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
  1112. }
  1113. function touchid() {
  1114. return d3.event.changedTouches[0].identifier;
  1115. }
  1116. function touchposition(parent, id) {
  1117. return d3.touches(parent).filter(function(p) {
  1118. return p.identifier === id;
  1119. })[0];
  1120. }
  1121. function dragstart(id, position, move, end) {
  1122. return function() {
  1123. var target = this, parent = target.parentNode, event_ = event.of(target, arguments), eventTarget = d3.event.target, eventId = id(), drag = eventId == null ? "drag" : "drag-" + eventId, origin_ = position(parent, eventId), dragged = 0, offset, w = d3.select(d3_window).on(move + "." + drag, moved).on(end + "." + drag, ended), dragRestore = d3_event_dragSuppress();
  1124. if (origin) {
  1125. offset = origin.apply(target, arguments);
  1126. offset = [ offset.x - origin_[0], offset.y - origin_[1] ];
  1127. } else {
  1128. offset = [ 0, 0 ];
  1129. }
  1130. event_({
  1131. type: "dragstart"
  1132. });
  1133. function moved() {
  1134. var p = position(parent, eventId), dx = p[0] - origin_[0], dy = p[1] - origin_[1];
  1135. dragged |= dx | dy;
  1136. origin_ = p;
  1137. event_({
  1138. type: "drag",
  1139. x: p[0] + offset[0],
  1140. y: p[1] + offset[1],
  1141. dx: dx,
  1142. dy: dy
  1143. });
  1144. }
  1145. function ended() {
  1146. w.on(move + "." + drag, null).on(end + "." + drag, null);
  1147. dragRestore(dragged && d3.event.target === eventTarget);
  1148. event_({
  1149. type: "dragend"
  1150. });
  1151. }
  1152. };
  1153. }
  1154. drag.origin = function(x) {
  1155. if (!arguments.length) return origin;
  1156. origin = x;
  1157. return drag;
  1158. };
  1159. return d3.rebind(drag, event, "on");
  1160. };
  1161. var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
  1162. function d3_sgn(x) {
  1163. return x > 0 ? 1 : x < 0 ? -1 : 0;
  1164. }
  1165. function d3_acos(x) {
  1166. return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
  1167. }
  1168. function d3_asin(x) {
  1169. return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
  1170. }
  1171. function d3_sinh(x) {
  1172. return ((x = Math.exp(x)) - 1 / x) / 2;
  1173. }
  1174. function d3_cosh(x) {
  1175. return ((x = Math.exp(x)) + 1 / x) / 2;
  1176. }
  1177. function d3_tanh(x) {
  1178. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  1179. }
  1180. function d3_haversin(x) {
  1181. return (x = Math.sin(x / 2)) * x;
  1182. }
  1183. var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
  1184. d3.interpolateZoom = function(p0, p1) {
  1185. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
  1186. var dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1), dr = r1 - r0, S = (dr || Math.log(w1 / w0)) / ρ;
  1187. function interpolate(t) {
  1188. var s = t * S;
  1189. if (dr) {
  1190. var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
  1191. return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
  1192. }
  1193. return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
  1194. }
  1195. interpolate.duration = S * 1e3;
  1196. return interpolate;
  1197. };
  1198. d3.behavior.zoom = function() {
  1199. var view = {
  1200. x: 0,
  1201. y: 0,
  1202. k: 1
  1203. }, translate0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, 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;
  1204. function zoom(g) {
  1205. g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
  1206. }
  1207. zoom.event = function(g) {
  1208. g.each(function() {
  1209. var event_ = event.of(this, arguments), view1 = view;
  1210. if (d3_transitionInheritId) {
  1211. d3.select(this).transition().each("start.zoom", function() {
  1212. view = this.__chart__ || {
  1213. x: 0,
  1214. y: 0,
  1215. k: 1
  1216. };
  1217. zoomstarted(event_);
  1218. }).tween("zoom:zoom", function() {
  1219. var dx = size[0], dy = size[1], cx = dx / 2, cy = 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 ]);
  1220. return function(t) {
  1221. var l = i(t), k = dx / l[2];
  1222. this.__chart__ = view = {
  1223. x: cx - l[0] * k,
  1224. y: cy - l[1] * k,
  1225. k: k
  1226. };
  1227. zoomed(event_);
  1228. };
  1229. }).each("end.zoom", function() {
  1230. zoomended(event_);
  1231. });
  1232. } else {
  1233. this.__chart__ = view;
  1234. zoomstarted(event_);
  1235. zoomed(event_);
  1236. zoomended(event_);
  1237. }
  1238. });
  1239. };
  1240. zoom.translate = function(_) {
  1241. if (!arguments.length) return [ view.x, view.y ];
  1242. view = {
  1243. x: +_[0],
  1244. y: +_[1],
  1245. k: view.k
  1246. };
  1247. rescale();
  1248. return zoom;
  1249. };
  1250. zoom.scale = function(_) {
  1251. if (!arguments.length) return view.k;
  1252. view = {
  1253. x: view.x,
  1254. y: view.y,
  1255. k: +_
  1256. };
  1257. rescale();
  1258. return zoom;
  1259. };
  1260. zoom.scaleExtent = function(_) {
  1261. if (!arguments.length) return scaleExtent;
  1262. scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
  1263. return zoom;
  1264. };
  1265. zoom.center = function(_) {
  1266. if (!arguments.length) return center;
  1267. center = _ && [ +_[0], +_[1] ];
  1268. return zoom;
  1269. };
  1270. zoom.size = function(_) {
  1271. if (!arguments.length) return size;
  1272. size = _ && [ +_[0], +_[1] ];
  1273. return zoom;
  1274. };
  1275. zoom.x = function(z) {
  1276. if (!arguments.length) return x1;
  1277. x1 = z;
  1278. x0 = z.copy();
  1279. view = {
  1280. x: 0,
  1281. y: 0,
  1282. k: 1
  1283. };
  1284. return zoom;
  1285. };
  1286. zoom.y = function(z) {
  1287. if (!arguments.length) return y1;
  1288. y1 = z;
  1289. y0 = z.copy();
  1290. view = {
  1291. x: 0,
  1292. y: 0,
  1293. k: 1
  1294. };
  1295. return zoom;
  1296. };
  1297. function location(p) {
  1298. return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
  1299. }
  1300. function point(l) {
  1301. return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
  1302. }
  1303. function scaleTo(s) {
  1304. view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  1305. }
  1306. function translateTo(p, l) {
  1307. l = point(l);
  1308. view.x += p[0] - l[0];
  1309. view.y += p[1] - l[1];
  1310. }
  1311. function rescale() {
  1312. if (x1) x1.domain(x0.range().map(function(x) {
  1313. return (x - view.x) / view.k;
  1314. }).map(x0.invert));
  1315. if (y1) y1.domain(y0.range().map(function(y) {
  1316. return (y - view.y) / view.k;
  1317. }).map(y0.invert));
  1318. }
  1319. function zoomstarted(event) {
  1320. event({
  1321. type: "zoomstart"
  1322. });
  1323. }
  1324. function zoomed(event) {
  1325. rescale();
  1326. event({
  1327. type: "zoom",
  1328. scale: view.k,
  1329. translate: [ view.x, view.y ]
  1330. });
  1331. }
  1332. function zoomended(event) {
  1333. event({
  1334. type: "zoomend"
  1335. });
  1336. }
  1337. function mousedowned() {
  1338. var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, dragged = 0, w = d3.select(d3_window).on(mousemove, moved).on(mouseup, ended), l = location(d3.mouse(target)), dragRestore = d3_event_dragSuppress();
  1339. d3_selection_interrupt.call(target);
  1340. zoomstarted(event_);
  1341. function moved() {
  1342. dragged = 1;
  1343. translateTo(d3.mouse(target), l);
  1344. zoomed(event_);
  1345. }
  1346. function ended() {
  1347. w.on(mousemove, d3_window === target ? mousewheelreset : null).on(mouseup, null);
  1348. dragRestore(dragged && d3.event.target === eventTarget);
  1349. zoomended(event_);
  1350. }
  1351. }
  1352. function touchstarted() {
  1353. var target = this, event_ = event.of(target, arguments), locations0 = {}, distance0 = 0, scale0, eventId = d3.event.changedTouches[0].identifier, touchmove = "touchmove.zoom-" + eventId, touchend = "touchend.zoom-" + eventId, w = d3.select(d3_window).on(touchmove, moved).on(touchend, ended), t = d3.select(target).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress();
  1354. d3_selection_interrupt.call(target);
  1355. started();
  1356. zoomstarted(event_);
  1357. function relocate() {
  1358. var touches = d3.touches(target);
  1359. scale0 = view.k;
  1360. touches.forEach(function(t) {
  1361. if (t.identifier in locations0) locations0[t.identifier] = location(t);
  1362. });
  1363. return touches;
  1364. }
  1365. function started() {
  1366. var changed = d3.event.changedTouches;
  1367. for (var i = 0, n = changed.length; i < n; ++i) {
  1368. locations0[changed[i].identifier] = null;
  1369. }
  1370. var touches = relocate(), now = Date.now();
  1371. if (touches.length === 1) {
  1372. if (now - touchtime < 500) {
  1373. var p = touches[0], l = locations0[p.identifier];
  1374. scaleTo(view.k * 2);
  1375. translateTo(p, l);
  1376. d3_eventPreventDefault();
  1377. zoomed(event_);
  1378. }
  1379. touchtime = now;
  1380. } else if (touches.length > 1) {
  1381. var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
  1382. distance0 = dx * dx + dy * dy;
  1383. }
  1384. }
  1385. function moved() {
  1386. var touches = d3.touches(target), p0, l0, p1, l1;
  1387. for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
  1388. p1 = touches[i];
  1389. if (l1 = locations0[p1.identifier]) {
  1390. if (l0) break;
  1391. p0 = p1, l0 = l1;
  1392. }
  1393. }
  1394. if (l1) {
  1395. var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
  1396. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  1397. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  1398. scaleTo(scale1 * scale0);
  1399. }
  1400. touchtime = null;
  1401. translateTo(p0, l0);
  1402. zoomed(event_);
  1403. }
  1404. function ended() {
  1405. if (d3.event.touches.length) {
  1406. var changed = d3.event.changedTouches;
  1407. for (var i = 0, n = changed.length; i < n; ++i) {
  1408. delete locations0[changed[i].identifier];
  1409. }
  1410. for (var identifier in locations0) {
  1411. return void relocate();
  1412. }
  1413. }
  1414. w.on(touchmove, null).on(touchend, null);
  1415. t.on(mousedown, mousedowned).on(touchstart, touchstarted);
  1416. dragRestore();
  1417. zoomended(event_);
  1418. }
  1419. }
  1420. function mousewheeled() {
  1421. var event_ = event.of(this, arguments);
  1422. if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
  1423. zoomstarted(event_);
  1424. mousewheelTimer = setTimeout(function() {
  1425. mousewheelTimer = null;
  1426. zoomended(event_);
  1427. }, 50);
  1428. d3_eventPreventDefault();
  1429. var point = center || d3.mouse(this);
  1430. if (!translate0) translate0 = location(point);
  1431. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
  1432. translateTo(point, translate0);
  1433. zoomed(event_);
  1434. }
  1435. function mousewheelreset() {
  1436. translate0 = null;
  1437. }
  1438. function dblclicked() {
  1439. var event_ = event.of(this, arguments), p = d3.mouse(this), l = location(p), k = Math.log(view.k) / Math.LN2;
  1440. zoomstarted(event_);
  1441. scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
  1442. translateTo(p, l);
  1443. zoomed(event_);
  1444. zoomended(event_);
  1445. }
  1446. return d3.rebind(zoom, event, "on");
  1447. };
  1448. var d3_behavior_zoomInfinity = [ 0, Infinity ];
  1449. var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1450. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  1451. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1452. return d3.event.wheelDelta;
  1453. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  1454. return -d3.event.detail;
  1455. }, "MozMousePixelScroll");
  1456. function d3_Color() {}
  1457. d3_Color.prototype.toString = function() {
  1458. return this.rgb() + "";
  1459. };
  1460. d3.hsl = function(h, s, l) {
  1461. return arguments.length === 1 ? h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : d3_hsl(+h, +s, +l);
  1462. };
  1463. function d3_hsl(h, s, l) {
  1464. return new d3_Hsl(h, s, l);
  1465. }
  1466. function d3_Hsl(h, s, l) {
  1467. this.h = h;
  1468. this.s = s;
  1469. this.l = l;
  1470. }
  1471. var d3_hslPrototype = d3_Hsl.prototype = new d3_Color();
  1472. d3_hslPrototype.brighter = function(k) {
  1473. k = Math.pow(.7, arguments.length ? k : 1);
  1474. return d3_hsl(this.h, this.s, this.l / k);
  1475. };
  1476. d3_hslPrototype.darker = function(k) {
  1477. k = Math.pow(.7, arguments.length ? k : 1);
  1478. return d3_hsl(this.h, this.s, k * this.l);
  1479. };
  1480. d3_hslPrototype.rgb = function() {
  1481. return d3_hsl_rgb(this.h, this.s, this.l);
  1482. };
  1483. function d3_hsl_rgb(h, s, l) {
  1484. var m1, m2;
  1485. h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
  1486. s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
  1487. l = l < 0 ? 0 : l > 1 ? 1 : l;
  1488. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  1489. m1 = 2 * l - m2;
  1490. function v(h) {
  1491. if (h > 360) h -= 360; else if (h < 0) h += 360;
  1492. if (h < 60) return m1 + (m2 - m1) * h / 60;
  1493. if (h < 180) return m2;
  1494. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  1495. return m1;
  1496. }
  1497. function vv(h) {
  1498. return Math.round(v(h) * 255);
  1499. }
  1500. return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  1501. }
  1502. d3.hcl = function(h, c, l) {
  1503. return arguments.length === 1 ? h instanceof d3_Hcl ? d3_hcl(h.h, h.c, h.l) : h instanceof d3_Lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : d3_hcl(+h, +c, +l);
  1504. };
  1505. function d3_hcl(h, c, l) {
  1506. return new d3_Hcl(h, c, l);
  1507. }
  1508. function d3_Hcl(h, c, l) {
  1509. this.h = h;
  1510. this.c = c;
  1511. this.l = l;
  1512. }
  1513. var d3_hclPrototype = d3_Hcl.prototype = new d3_Color();
  1514. d3_hclPrototype.brighter = function(k) {
  1515. return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  1516. };
  1517. d3_hclPrototype.darker = function(k) {
  1518. return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  1519. };
  1520. d3_hclPrototype.rgb = function() {
  1521. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  1522. };
  1523. function d3_hcl_lab(h, c, l) {
  1524. if (isNaN(h)) h = 0;
  1525. if (isNaN(c)) c = 0;
  1526. return d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  1527. }
  1528. d3.lab = function(l, a, b) {
  1529. return arguments.length === 1 ? l instanceof d3_Lab ? d3_lab(l.l, l.a, l.b) : l instanceof d3_Hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3.rgb(l)).r, l.g, l.b) : d3_lab(+l, +a, +b);
  1530. };
  1531. function d3_lab(l, a, b) {
  1532. return new d3_Lab(l, a, b);
  1533. }
  1534. function d3_Lab(l, a, b) {
  1535. this.l = l;
  1536. this.a = a;
  1537. this.b = b;
  1538. }
  1539. var d3_lab_K = 18;
  1540. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  1541. var d3_labPrototype = d3_Lab.prototype = new d3_Color();
  1542. d3_labPrototype.brighter = function(k) {
  1543. return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1544. };
  1545. d3_labPrototype.darker = function(k) {
  1546. return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1547. };
  1548. d3_labPrototype.rgb = function() {
  1549. return d3_lab_rgb(this.l, this.a, this.b);
  1550. };
  1551. function d3_lab_rgb(l, a, b) {
  1552. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  1553. x = d3_lab_xyz(x) * d3_lab_X;
  1554. y = d3_lab_xyz(y) * d3_lab_Y;
  1555. z = d3_lab_xyz(z) * d3_lab_Z;
  1556. return d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
  1557. }
  1558. function d3_lab_hcl(l, a, b) {
  1559. return l > 0 ? d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : d3_hcl(NaN, NaN, l);
  1560. }
  1561. function d3_lab_xyz(x) {
  1562. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  1563. }
  1564. function d3_xyz_lab(x) {
  1565. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  1566. }
  1567. function d3_xyz_rgb(r) {
  1568. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  1569. }
  1570. d3.rgb = function(r, g, b) {
  1571. return arguments.length === 1 ? r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : d3_rgb(~~r, ~~g, ~~b);
  1572. };
  1573. function d3_rgbNumber(value) {
  1574. return d3_rgb(value >> 16, value >> 8 & 255, value & 255);
  1575. }
  1576. function d3_rgbString(value) {
  1577. return d3_rgbNumber(value) + "";
  1578. }
  1579. function d3_rgb(r, g, b) {
  1580. return new d3_Rgb(r, g, b);
  1581. }
  1582. function d3_Rgb(r, g, b) {
  1583. this.r = r;
  1584. this.g = g;
  1585. this.b = b;
  1586. }
  1587. var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color();
  1588. d3_rgbPrototype.brighter = function(k) {
  1589. k = Math.pow(.7, arguments.length ? k : 1);
  1590. var r = this.r, g = this.g, b = this.b, i = 30;
  1591. if (!r && !g && !b) return d3_rgb(i, i, i);
  1592. if (r && r < i) r = i;
  1593. if (g && g < i) g = i;
  1594. if (b && b < i) b = i;
  1595. return d3_rgb(Math.min(255, ~~(r / k)), Math.min(255, ~~(g / k)), Math.min(255, ~~(b / k)));
  1596. };
  1597. d3_rgbPrototype.darker = function(k) {
  1598. k = Math.pow(.7, arguments.length ? k : 1);
  1599. return d3_rgb(~~(k * this.r), ~~(k * this.g), ~~(k * this.b));
  1600. };
  1601. d3_rgbPrototype.hsl = function() {
  1602. return d3_rgb_hsl(this.r, this.g, this.b);
  1603. };
  1604. d3_rgbPrototype.toString = function() {
  1605. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  1606. };
  1607. function d3_rgb_hex(v) {
  1608. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  1609. }
  1610. function d3_rgb_parse(format, rgb, hsl) {
  1611. var r = 0, g = 0, b = 0, m1, m2, name;
  1612. m1 = /([a-z]+)\((.*)\)/i.exec(format);
  1613. if (m1) {
  1614. m2 = m1[2].split(",");
  1615. switch (m1[1]) {
  1616. case "hsl":
  1617. {
  1618. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  1619. }
  1620. case "rgb":
  1621. {
  1622. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  1623. }
  1624. }
  1625. }
  1626. if (name = d3_rgb_names.get(format)) return rgb(name.r, name.g, name.b);
  1627. if (format != null && format.charAt(0) === "#") {
  1628. if (format.length === 4) {
  1629. r = format.charAt(1);
  1630. r += r;
  1631. g = format.charAt(2);
  1632. g += g;
  1633. b = format.charAt(3);
  1634. b += b;
  1635. } else if (format.length === 7) {
  1636. r = format.substring(1, 3);
  1637. g = format.substring(3, 5);
  1638. b = format.substring(5, 7);
  1639. }
  1640. r = parseInt(r, 16);
  1641. g = parseInt(g, 16);
  1642. b = parseInt(b, 16);
  1643. }
  1644. return rgb(r, g, b);
  1645. }
  1646. function d3_rgb_hsl(r, g, b) {
  1647. 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;
  1648. if (d) {
  1649. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  1650. 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;
  1651. h *= 60;
  1652. } else {
  1653. h = NaN;
  1654. s = l > 0 && l < 1 ? 0 : h;
  1655. }
  1656. return d3_hsl(h, s, l);
  1657. }
  1658. function d3_rgb_lab(r, g, b) {
  1659. r = d3_rgb_xyz(r);
  1660. g = d3_rgb_xyz(g);
  1661. b = d3_rgb_xyz(b);
  1662. 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);
  1663. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  1664. }
  1665. function d3_rgb_xyz(r) {
  1666. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  1667. }
  1668. function d3_rgb_parseNumber(c) {
  1669. var f = parseFloat(c);
  1670. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  1671. }
  1672. var d3_rgb_names = d3.map({
  1673. aliceblue: 15792383,
  1674. antiquewhite: 16444375,
  1675. aqua: 65535,
  1676. aquamarine: 8388564,
  1677. azure: 15794175,
  1678. beige: 16119260,
  1679. bisque: 16770244,
  1680. black: 0,
  1681. blanchedalmond: 16772045,
  1682. blue: 255,
  1683. blueviolet: 9055202,
  1684. brown: 10824234,
  1685. burlywood: 14596231,
  1686. cadetblue: 6266528,
  1687. chartreuse: 8388352,
  1688. chocolate: 13789470,
  1689. coral: 16744272,
  1690. cornflowerblue: 6591981,
  1691. cornsilk: 16775388,
  1692. crimson: 14423100,
  1693. cyan: 65535,
  1694. darkblue: 139,
  1695. darkcyan: 35723,
  1696. darkgoldenrod: 12092939,
  1697. darkgray: 11119017,
  1698. darkgreen: 25600,
  1699. darkgrey: 11119017,
  1700. darkkhaki: 12433259,
  1701. darkmagenta: 9109643,
  1702. darkolivegreen: 5597999,
  1703. darkorange: 16747520,
  1704. darkorchid: 10040012,
  1705. darkred: 9109504,
  1706. darksalmon: 15308410,
  1707. darkseagreen: 9419919,
  1708. darkslateblue: 4734347,
  1709. darkslategray: 3100495,
  1710. darkslategrey: 3100495,
  1711. darkturquoise: 52945,
  1712. darkviolet: 9699539,
  1713. deeppink: 16716947,
  1714. deepskyblue: 49151,
  1715. dimgray: 6908265,
  1716. dimgrey: 6908265,
  1717. dodgerblue: 2003199,
  1718. firebrick: 11674146,
  1719. floralwhite: 16775920,
  1720. forestgreen: 2263842,
  1721. fuchsia: 16711935,
  1722. gainsboro: 14474460,
  1723. ghostwhite: 16316671,
  1724. gold: 16766720,
  1725. goldenrod: 14329120,
  1726. gray: 8421504,
  1727. green: 32768,
  1728. greenyellow: 11403055,
  1729. grey: 8421504,
  1730. honeydew: 15794160,
  1731. hotpink: 16738740,
  1732. indianred: 13458524,
  1733. indigo: 4915330,
  1734. ivory: 16777200,
  1735. khaki: 15787660,
  1736. lavender: 15132410,
  1737. lavenderblush: 16773365,
  1738. lawngreen: 8190976,
  1739. lemonchiffon: 16775885,
  1740. lightblue: 11393254,
  1741. lightcoral: 15761536,
  1742. lightcyan: 14745599,
  1743. lightgoldenrodyellow: 16448210,
  1744. lightgray: 13882323,
  1745. lightgreen: 9498256,
  1746. lightgrey: 13882323,
  1747. lightpink: 16758465,
  1748. lightsalmon: 16752762,
  1749. lightseagreen: 2142890,
  1750. lightskyblue: 8900346,
  1751. lightslategray: 7833753,
  1752. lightslategrey: 7833753,
  1753. lightsteelblue: 11584734,
  1754. lightyellow: 16777184,
  1755. lime: 65280,
  1756. limegreen: 3329330,
  1757. linen: 16445670,
  1758. magenta: 16711935,
  1759. maroon: 8388608,
  1760. mediumaquamarine: 6737322,
  1761. mediumblue: 205,
  1762. mediumorchid: 12211667,
  1763. mediumpurple: 9662683,
  1764. mediumseagreen: 3978097,
  1765. mediumslateblue: 8087790,
  1766. mediumspringgreen: 64154,
  1767. mediumturquoise: 4772300,
  1768. mediumvioletred: 13047173,
  1769. midnightblue: 1644912,
  1770. mintcream: 16121850,
  1771. mistyrose: 16770273,
  1772. moccasin: 16770229,
  1773. navajowhite: 16768685,
  1774. navy: 128,
  1775. oldlace: 16643558,
  1776. olive: 8421376,
  1777. olivedrab: 7048739,
  1778. orange: 16753920,
  1779. orangered: 16729344,
  1780. orchid: 14315734,
  1781. palegoldenrod: 15657130,
  1782. palegreen: 10025880,
  1783. paleturquoise: 11529966,
  1784. palevioletred: 14381203,
  1785. papayawhip: 16773077,
  1786. peachpuff: 16767673,
  1787. peru: 13468991,
  1788. pink: 16761035,
  1789. plum: 14524637,
  1790. powderblue: 11591910,
  1791. purple: 8388736,
  1792. red: 16711680,
  1793. rosybrown: 12357519,
  1794. royalblue: 4286945,
  1795. saddlebrown: 9127187,
  1796. salmon: 16416882,
  1797. sandybrown: 16032864,
  1798. seagreen: 3050327,
  1799. seashell: 16774638,
  1800. sienna: 10506797,
  1801. silver: 12632256,
  1802. skyblue: 8900331,
  1803. slateblue: 6970061,
  1804. slategray: 7372944,
  1805. slategrey: 7372944,
  1806. snow: 16775930,
  1807. springgreen: 65407,
  1808. steelblue: 4620980,
  1809. tan: 13808780,
  1810. teal: 32896,
  1811. thistle: 14204888,
  1812. tomato: 16737095,
  1813. turquoise: 4251856,
  1814. violet: 15631086,
  1815. wheat: 16113331,
  1816. white: 16777215,
  1817. whitesmoke: 16119285,
  1818. yellow: 16776960,
  1819. yellowgreen: 10145074
  1820. });
  1821. d3_rgb_names.forEach(function(key, value) {
  1822. d3_rgb_names.set(key, d3_rgbNumber(value));
  1823. });
  1824. function d3_functor(v) {
  1825. return typeof v === "function" ? v : function() {
  1826. return v;
  1827. };
  1828. }
  1829. d3.functor = d3_functor;
  1830. function d3_identity(d) {
  1831. return d;
  1832. }
  1833. d3.xhr = d3_xhrType(d3_identity);
  1834. function d3_xhrType(response) {
  1835. return function(url, mimeType, callback) {
  1836. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  1837. mimeType = null;
  1838. return d3_xhr(url, mimeType, response, callback);
  1839. };
  1840. }
  1841. function d3_xhr(url, mimeType, response, callback) {
  1842. var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
  1843. if (d3_window.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
  1844. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  1845. request.readyState > 3 && respond();
  1846. };
  1847. function respond() {
  1848. var status = request.status, result;
  1849. if (!status && request.responseText || status >= 200 && status < 300 || status === 304) {
  1850. try {
  1851. result = response.call(xhr, request);
  1852. } catch (e) {
  1853. dispatch.error.call(xhr, e);
  1854. return;
  1855. }
  1856. dispatch.load.call(xhr, result);
  1857. } else {
  1858. dispatch.error.call(xhr, request);
  1859. }
  1860. }
  1861. request.onprogress = function(event) {
  1862. var o = d3.event;
  1863. d3.event = event;
  1864. try {
  1865. dispatch.progress.call(xhr, request);
  1866. } finally {
  1867. d3.event = o;
  1868. }
  1869. };
  1870. xhr.header = function(name, value) {
  1871. name = (name + "").toLowerCase();
  1872. if (arguments.length < 2) return headers[name];
  1873. if (value == null) delete headers[name]; else headers[name] = value + "";
  1874. return xhr;
  1875. };
  1876. xhr.mimeType = function(value) {
  1877. if (!arguments.length) return mimeType;
  1878. mimeType = value == null ? null : value + "";
  1879. return xhr;
  1880. };
  1881. xhr.responseType = function(value) {
  1882. if (!arguments.length) return responseType;
  1883. responseType = value;
  1884. return xhr;
  1885. };
  1886. xhr.response = function(value) {
  1887. response = value;
  1888. return xhr;
  1889. };
  1890. [ "get", "post" ].forEach(function(method) {
  1891. xhr[method] = function() {
  1892. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  1893. };
  1894. });
  1895. xhr.send = function(method, data, callback) {
  1896. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  1897. request.open(method, url, true);
  1898. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  1899. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  1900. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  1901. if (responseType != null) request.responseType = responseType;
  1902. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  1903. callback(null, request);
  1904. });
  1905. dispatch.beforesend.call(xhr, request);
  1906. request.send(data == null ? null : data);
  1907. return xhr;
  1908. };
  1909. xhr.abort = function() {
  1910. request.abort();
  1911. return xhr;
  1912. };
  1913. d3.rebind(xhr, dispatch, "on");
  1914. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  1915. }
  1916. function d3_xhr_fixCallback(callback) {
  1917. return callback.length === 1 ? function(error, request) {
  1918. callback(error == null ? request : null);
  1919. } : callback;
  1920. }
  1921. d3.dsv = function(delimiter, mimeType) {
  1922. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  1923. function dsv(url, row, callback) {
  1924. if (arguments.length < 3) callback = row, row = null;
  1925. var xhr = d3.xhr(url, mimeType, callback);
  1926. xhr.row = function(_) {
  1927. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  1928. };
  1929. return xhr.row(row);
  1930. }
  1931. function response(request) {
  1932. return dsv.parse(request.responseText);
  1933. }
  1934. function typedResponse(f) {
  1935. return function(request) {
  1936. return dsv.parse(request.responseText, f);
  1937. };
  1938. }
  1939. dsv.parse = function(text, f) {
  1940. var o;
  1941. return dsv.parseRows(text, function(row, i) {
  1942. if (o) return o(row, i - 1);
  1943. var a = new Function("d", "return {" + row.map(function(name, i) {
  1944. return JSON.stringify(name) + ": d[" + i + "]";
  1945. }).join(",") + "}");
  1946. o = f ? function(row, i) {
  1947. return f(a(row), i);
  1948. } : a;
  1949. });
  1950. };
  1951. dsv.parseRows = function(text, f) {
  1952. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  1953. function token() {
  1954. if (I >= N) return EOF;
  1955. if (eol) return eol = false, EOL;
  1956. var j = I;
  1957. if (text.charCodeAt(j) === 34) {
  1958. var i = j;
  1959. while (i++ < N) {
  1960. if (text.charCodeAt(i) === 34) {
  1961. if (text.charCodeAt(i + 1) !== 34) break;
  1962. ++i;
  1963. }
  1964. }
  1965. I = i + 2;
  1966. var c = text.charCodeAt(i + 1);
  1967. if (c === 13) {
  1968. eol = true;
  1969. if (text.charCodeAt(i + 2) === 10) ++I;
  1970. } else if (c === 10) {
  1971. eol = true;
  1972. }
  1973. return text.substring(j + 1, i).replace(/""/g, '"');
  1974. }
  1975. while (I < N) {
  1976. var c = text.charCodeAt(I++), k = 1;
  1977. if (c === 10) eol = true; else if (c === 13) {
  1978. eol = true;
  1979. if (text.charCodeAt(I) === 10) ++I, ++k;
  1980. } else if (c !== delimiterCode) continue;
  1981. return text.substring(j, I - k);
  1982. }
  1983. return text.substring(j);
  1984. }
  1985. while ((t = token()) !== EOF) {
  1986. var a = [];
  1987. while (t !== EOL && t !== EOF) {
  1988. a.push(t);
  1989. t = token();
  1990. }
  1991. if (f && !(a = f(a, n++))) continue;
  1992. rows.push(a);
  1993. }
  1994. return rows;
  1995. };
  1996. dsv.format = function(rows) {
  1997. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  1998. var fieldSet = new d3_Set(), fields = [];
  1999. rows.forEach(function(row) {
  2000. for (var field in row) {
  2001. if (!fieldSet.has(field)) {
  2002. fields.push(fieldSet.add(field));
  2003. }
  2004. }
  2005. });
  2006. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  2007. return fields.map(function(field) {
  2008. return formatValue(row[field]);
  2009. }).join(delimiter);
  2010. })).join("\n");
  2011. };
  2012. dsv.formatRows = function(rows) {
  2013. return rows.map(formatRow).join("\n");
  2014. };
  2015. function formatRow(row) {
  2016. return row.map(formatValue).join(delimiter);
  2017. }
  2018. function formatValue(text) {
  2019. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  2020. }
  2021. return dsv;
  2022. };
  2023. d3.csv = d3.dsv(",", "text/csv");
  2024. d3.tsv = d3.dsv(" ", "text/tab-separated-values");
  2025. var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_active, d3_timer_frame = d3_window[d3_vendorSymbol(d3_window, "requestAnimationFrame")] || function(callback) {
  2026. setTimeout(callback, 17);
  2027. };
  2028. d3.timer = function(callback, delay, then) {
  2029. var n = arguments.length;
  2030. if (n < 2) delay = 0;
  2031. if (n < 3) then = Date.now();
  2032. var time = then + delay, timer = {
  2033. callback: callback,
  2034. time: time,
  2035. next: null
  2036. };
  2037. if (d3_timer_queueTail) d3_timer_queueTail.next = timer; else d3_timer_queueHead = timer;
  2038. d3_timer_queueTail = timer;
  2039. if (!d3_timer_interval) {
  2040. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  2041. d3_timer_interval = 1;
  2042. d3_timer_frame(d3_timer_step);
  2043. }
  2044. };
  2045. function d3_timer_step() {
  2046. var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
  2047. if (delay > 24) {
  2048. if (isFinite(delay)) {
  2049. clearTimeout(d3_timer_timeout);
  2050. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  2051. }
  2052. d3_timer_interval = 0;
  2053. } else {
  2054. d3_timer_interval = 1;
  2055. d3_timer_frame(d3_timer_step);
  2056. }
  2057. }
  2058. d3.timer.flush = function() {
  2059. d3_timer_mark();
  2060. d3_timer_sweep();
  2061. };
  2062. function d3_timer_replace(callback, delay, then) {
  2063. var n = arguments.length;
  2064. if (n < 2) delay = 0;
  2065. if (n < 3) then = Date.now();
  2066. d3_timer_active.callback = callback;
  2067. d3_timer_active.time = then + delay;
  2068. }
  2069. function d3_timer_mark() {
  2070. var now = Date.now();
  2071. d3_timer_active = d3_timer_queueHead;
  2072. while (d3_timer_active) {
  2073. if (now >= d3_timer_active.time) d3_timer_active.flush = d3_timer_active.callback(now - d3_timer_active.time);
  2074. d3_timer_active = d3_timer_active.next;
  2075. }
  2076. return now;
  2077. }
  2078. function d3_timer_sweep() {
  2079. var t0, t1 = d3_timer_queueHead, time = Infinity;
  2080. while (t1) {
  2081. if (t1.flush) {
  2082. t1 = t0 ? t0.next = t1.next : d3_timer_queueHead = t1.next;
  2083. } else {
  2084. if (t1.time < time) time = t1.time;
  2085. t1 = (t0 = t1).next;
  2086. }
  2087. }
  2088. d3_timer_queueTail = t0;
  2089. return time;
  2090. }
  2091. var d3_format_decimalPoint = ".", d3_format_thousandsSeparator = ",", d3_format_grouping = [ 3, 3 ], d3_format_currencySymbol = "$";
  2092. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  2093. d3.formatPrefix = function(value, precision) {
  2094. var i = 0;
  2095. if (value) {
  2096. if (value < 0) value *= -1;
  2097. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  2098. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  2099. i = Math.max(-24, Math.min(24, Math.floor((i <= 0 ? i + 1 : i - 1) / 3) * 3));
  2100. }
  2101. return d3_formatPrefixes[8 + i / 3];
  2102. };
  2103. function d3_formatPrefix(d, i) {
  2104. var k = Math.pow(10, Math.abs(8 - i) * 3);
  2105. return {
  2106. scale: i > 8 ? function(d) {
  2107. return d / k;
  2108. } : function(d) {
  2109. return d * k;
  2110. },
  2111. symbol: d
  2112. };
  2113. }
  2114. d3.round = function(x, n) {
  2115. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  2116. };
  2117. d3.format = function(specifier) {
  2118. 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, suffix = "", integer = false;
  2119. if (precision) precision = +precision.substring(1);
  2120. if (zfill || fill === "0" && align === "=") {
  2121. zfill = fill = "0";
  2122. align = "=";
  2123. if (comma) width -= Math.floor((width - 1) / 4);
  2124. }
  2125. switch (type) {
  2126. case "n":
  2127. comma = true;
  2128. type = "g";
  2129. break;
  2130. case "%":
  2131. scale = 100;
  2132. suffix = "%";
  2133. type = "f";
  2134. break;
  2135. case "p":
  2136. scale = 100;
  2137. suffix = "%";
  2138. type = "r";
  2139. break;
  2140. case "b":
  2141. case "o":
  2142. case "x":
  2143. case "X":
  2144. if (symbol === "#") symbol = "0" + type.toLowerCase();
  2145. case "c":
  2146. case "d":
  2147. integer = true;
  2148. precision = 0;
  2149. break;
  2150. case "s":
  2151. scale = -1;
  2152. type = "r";
  2153. break;
  2154. }
  2155. if (symbol === "#") symbol = ""; else if (symbol === "$") symbol = d3_format_currencySymbol;
  2156. if (type == "r" && !precision) type = "g";
  2157. if (precision != null) {
  2158. 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));
  2159. }
  2160. type = d3_format_types.get(type) || d3_format_typeDefault;
  2161. var zcomma = zfill && comma;
  2162. return function(value) {
  2163. if (integer && value % 1) return "";
  2164. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign;
  2165. if (scale < 0) {
  2166. var prefix = d3.formatPrefix(value, precision);
  2167. value = prefix.scale(value);
  2168. suffix = prefix.symbol;
  2169. } else {
  2170. value *= scale;
  2171. }
  2172. value = type(value, precision);
  2173. var i = value.lastIndexOf("."), before = i < 0 ? value : value.substring(0, i), after = i < 0 ? "" : d3_format_decimalPoint + value.substring(i + 1);
  2174. if (!zfill && comma) before = d3_format_group(before);
  2175. var length = symbol.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  2176. if (zcomma) before = d3_format_group(padding + before);
  2177. negative += symbol;
  2178. value = before + after;
  2179. return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + suffix;
  2180. };
  2181. };
  2182. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  2183. var d3_format_types = d3.map({
  2184. b: function(x) {
  2185. return x.toString(2);
  2186. },
  2187. c: function(x) {
  2188. return String.fromCharCode(x);
  2189. },
  2190. o: function(x) {
  2191. return x.toString(8);
  2192. },
  2193. x: function(x) {
  2194. return x.toString(16);
  2195. },
  2196. X: function(x) {
  2197. return x.toString(16).toUpperCase();
  2198. },
  2199. g: function(x, p) {
  2200. return x.toPrecision(p);
  2201. },
  2202. e: function(x, p) {
  2203. return x.toExponential(p);
  2204. },
  2205. f: function(x, p) {
  2206. return x.toFixed(p);
  2207. },
  2208. r: function(x, p) {
  2209. 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))));
  2210. }
  2211. });
  2212. function d3_format_precision(x, p) {
  2213. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  2214. }
  2215. function d3_format_typeDefault(x) {
  2216. return x + "";
  2217. }
  2218. var d3_format_group = d3_identity;
  2219. if (d3_format_grouping) {
  2220. var d3_format_groupingLength = d3_format_grouping.length;
  2221. d3_format_group = function(value) {
  2222. var i = value.length, t = [], j = 0, g = d3_format_grouping[0];
  2223. while (i > 0 && g > 0) {
  2224. t.push(value.substring(i -= g, i + g));
  2225. g = d3_format_grouping[j = (j + 1) % d3_format_groupingLength];
  2226. }
  2227. return t.reverse().join(d3_format_thousandsSeparator);
  2228. };
  2229. }
  2230. d3.geo = {};
  2231. function d3_adder() {}
  2232. d3_adder.prototype = {
  2233. s: 0,
  2234. t: 0,
  2235. add: function(y) {
  2236. d3_adderSum(y, this.t, d3_adderTemp);
  2237. d3_adderSum(d3_adderTemp.s, this.s, this);
  2238. if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
  2239. },
  2240. reset: function() {
  2241. this.s = this.t = 0;
  2242. },
  2243. valueOf: function() {
  2244. return this.s;
  2245. }
  2246. };
  2247. var d3_adderTemp = new d3_adder();
  2248. function d3_adderSum(a, b, o) {
  2249. var x = o.s = a + b, bv = x - a, av = x - bv;
  2250. o.t = a - av + (b - bv);
  2251. }
  2252. d3.geo.stream = function(object, listener) {
  2253. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  2254. d3_geo_streamObjectType[object.type](object, listener);
  2255. } else {
  2256. d3_geo_streamGeometry(object, listener);
  2257. }
  2258. };
  2259. function d3_geo_streamGeometry(geometry, listener) {
  2260. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  2261. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  2262. }
  2263. }
  2264. var d3_geo_streamObjectType = {
  2265. Feature: function(feature, listener) {
  2266. d3_geo_streamGeometry(feature.geometry, listener);
  2267. },
  2268. FeatureCollection: function(object, listener) {
  2269. var features = object.features, i = -1, n = features.length;
  2270. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  2271. }
  2272. };
  2273. var d3_geo_streamGeometryType = {
  2274. Sphere: function(object, listener) {
  2275. listener.sphere();
  2276. },
  2277. Point: function(object, listener) {
  2278. object = object.coordinates;
  2279. listener.point(object[0], object[1], object[2]);
  2280. },
  2281. MultiPoint: function(object, listener) {
  2282. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2283. while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
  2284. },
  2285. LineString: function(object, listener) {
  2286. d3_geo_streamLine(object.coordinates, listener, 0);
  2287. },
  2288. MultiLineString: function(object, listener) {
  2289. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2290. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  2291. },
  2292. Polygon: function(object, listener) {
  2293. d3_geo_streamPolygon(object.coordinates, listener);
  2294. },
  2295. MultiPolygon: function(object, listener) {
  2296. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2297. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  2298. },
  2299. GeometryCollection: function(object, listener) {
  2300. var geometries = object.geometries, i = -1, n = geometries.length;
  2301. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  2302. }
  2303. };
  2304. function d3_geo_streamLine(coordinates, listener, closed) {
  2305. var i = -1, n = coordinates.length - closed, coordinate;
  2306. listener.lineStart();
  2307. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
  2308. listener.lineEnd();
  2309. }
  2310. function d3_geo_streamPolygon(coordinates, listener) {
  2311. var i = -1, n = coordinates.length;
  2312. listener.polygonStart();
  2313. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  2314. listener.polygonEnd();
  2315. }
  2316. d3.geo.area = function(object) {
  2317. d3_geo_areaSum = 0;
  2318. d3.geo.stream(object, d3_geo_area);
  2319. return d3_geo_areaSum;
  2320. };
  2321. var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
  2322. var d3_geo_area = {
  2323. sphere: function() {
  2324. d3_geo_areaSum += 4 * π;
  2325. },
  2326. point: d3_noop,
  2327. lineStart: d3_noop,
  2328. lineEnd: d3_noop,
  2329. polygonStart: function() {
  2330. d3_geo_areaRingSum.reset();
  2331. d3_geo_area.lineStart = d3_geo_areaRingStart;
  2332. },
  2333. polygonEnd: function() {
  2334. var area = 2 * d3_geo_areaRingSum;
  2335. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  2336. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  2337. }
  2338. };
  2339. function d3_geo_areaRingStart() {
  2340. var λ00, φ00, λ0, cosφ0, sinφ0;
  2341. d3_geo_area.point = function(λ, φ) {
  2342. d3_geo_area.point = nextPoint;
  2343. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  2344. sinφ0 = Math.sin(φ);
  2345. };
  2346. function nextPoint(λ, φ) {
  2347. λ *= d3_radians;
  2348. φ = φ * d3_radians / 2 + π / 4;
  2349. var dλ = λ - λ0, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(dλ), v = k * Math.sin(dλ);
  2350. d3_geo_areaRingSum.add(Math.atan2(v, u));
  2351. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  2352. }
  2353. d3_geo_area.lineEnd = function() {
  2354. nextPoint(λ00, φ00);
  2355. };
  2356. }
  2357. function d3_geo_cartesian(spherical) {
  2358. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  2359. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  2360. }
  2361. function d3_geo_cartesianDot(a, b) {
  2362. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  2363. }
  2364. function d3_geo_cartesianCross(a, b) {
  2365. 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] ];
  2366. }
  2367. function d3_geo_cartesianAdd(a, b) {
  2368. a[0] += b[0];
  2369. a[1] += b[1];
  2370. a[2] += b[2];
  2371. }
  2372. function d3_geo_cartesianScale(vector, k) {
  2373. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  2374. }
  2375. function d3_geo_cartesianNormalize(d) {
  2376. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  2377. d[0] /= l;
  2378. d[1] /= l;
  2379. d[2] /= l;
  2380. }
  2381. function d3_geo_spherical(cartesian) {
  2382. return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
  2383. }
  2384. function d3_geo_sphericalEqual(a, b) {
  2385. return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;
  2386. }
  2387. d3.geo.bounds = function() {
  2388. var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
  2389. var bound = {
  2390. point: point,
  2391. lineStart: lineStart,
  2392. lineEnd: lineEnd,
  2393. polygonStart: function() {
  2394. bound.point = ringPoint;
  2395. bound.lineStart = ringStart;
  2396. bound.lineEnd = ringEnd;
  2397. dλSum = 0;
  2398. d3_geo_area.polygonStart();
  2399. },
  2400. polygonEnd: function() {
  2401. d3_geo_area.polygonEnd();
  2402. bound.point = point;
  2403. bound.lineStart = lineStart;
  2404. bound.lineEnd = lineEnd;
  2405. if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
  2406. range[0] = λ0, range[1] = λ1;
  2407. }
  2408. };
  2409. function point(λ, φ) {
  2410. ranges.push(range = [ λ0 = λ, λ1 = λ ]);
  2411. if (φ < φ0) φ0 = φ;
  2412. if (φ > φ1) φ1 = φ;
  2413. }
  2414. function linePoint(λ, φ) {
  2415. var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
  2416. if (p0) {
  2417. var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
  2418. d3_geo_cartesianNormalize(inflection);
  2419. inflection = d3_geo_spherical(inflection);
  2420. var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = Math.abs(dλ) > 180;
  2421. if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  2422. var φi = inflection[1] * d3_degrees;
  2423. if (φi > φ1) φ1 = φi;
  2424. } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  2425. var φi = -inflection[1] * d3_degrees;
  2426. if (φi < φ0) φ0 = φi;
  2427. } else {
  2428. if (φ < φ0) φ0 = φ;
  2429. if (φ > φ1) φ1 = φ;
  2430. }
  2431. if (antimeridian) {
  2432. if (λ < λ_) {
  2433. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  2434. } else {
  2435. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  2436. }
  2437. } else {
  2438. if (λ1 >= λ0) {
  2439. if (λ < λ0) λ0 = λ;
  2440. if (λ > λ1) λ1 = λ;
  2441. } else {
  2442. if (λ > λ_) {
  2443. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  2444. } else {
  2445. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  2446. }
  2447. }
  2448. }
  2449. } else {
  2450. point(λ, φ);
  2451. }
  2452. p0 = p, λ_ = λ;
  2453. }
  2454. function lineStart() {
  2455. bound.point = linePoint;
  2456. }
  2457. function lineEnd() {
  2458. range[0] = λ0, range[1] = λ1;
  2459. bound.point = point;
  2460. p0 = null;
  2461. }
  2462. function ringPoint(λ, φ) {
  2463. if (p0) {
  2464. var dλ = λ - λ_;
  2465. dλSum += Math.abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
  2466. } else λ__ = λ, φ__ = φ;
  2467. d3_geo_area.point(λ, φ);
  2468. linePoint(λ, φ);
  2469. }
  2470. function ringStart() {
  2471. d3_geo_area.lineStart();
  2472. }
  2473. function ringEnd() {
  2474. ringPoint(λ__, φ__);
  2475. d3_geo_area.lineEnd();
  2476. if (Math.abs(dλSum) > ε) λ0 = -(λ1 = 180);
  2477. range[0] = λ0, range[1] = λ1;
  2478. p0 = null;
  2479. }
  2480. function angle(λ0, λ1) {
  2481. return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
  2482. }
  2483. function compareRanges(a, b) {
  2484. return a[0] - b[0];
  2485. }
  2486. function withinRange(x, range) {
  2487. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  2488. }
  2489. return function(feature) {
  2490. φ1 = λ1 = -(λ0 = φ0 = Infinity);
  2491. ranges = [];
  2492. d3.geo.stream(feature, bound);
  2493. var n = ranges.length;
  2494. if (n) {
  2495. ranges.sort(compareRanges);
  2496. for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
  2497. b = ranges[i];
  2498. if (withinRange(b[0], a) || withinRange(b[1], a)) {
  2499. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  2500. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  2501. } else {
  2502. merged.push(a = b);
  2503. }
  2504. }
  2505. var best = -Infinity, dλ;
  2506. for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
  2507. b = merged[i];
  2508. if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
  2509. }
  2510. }
  2511. ranges = range = null;
  2512. return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
  2513. };
  2514. }();
  2515. d3.geo.centroid = function(object) {
  2516. 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;
  2517. d3.geo.stream(object, d3_geo_centroid);
  2518. var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
  2519. if (m < ε2) {
  2520. x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
  2521. if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
  2522. m = x * x + y * y + z * z;
  2523. if (m < ε2) return [ NaN, NaN ];
  2524. }
  2525. return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
  2526. };
  2527. 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;
  2528. var d3_geo_centroid = {
  2529. sphere: d3_noop,
  2530. point: d3_geo_centroidPoint,
  2531. lineStart: d3_geo_centroidLineStart,
  2532. lineEnd: d3_geo_centroidLineEnd,
  2533. polygonStart: function() {
  2534. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  2535. },
  2536. polygonEnd: function() {
  2537. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  2538. }
  2539. };
  2540. function d3_geo_centroidPoint(λ, φ) {
  2541. λ *= d3_radians;
  2542. var cosφ = Math.cos(φ *= d3_radians);
  2543. d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
  2544. }
  2545. function d3_geo_centroidPointXYZ(x, y, z) {
  2546. ++d3_geo_centroidW0;
  2547. d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
  2548. d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
  2549. d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
  2550. }
  2551. function d3_geo_centroidLineStart() {
  2552. var x0, y0, z0;
  2553. d3_geo_centroid.point = function(λ, φ) {
  2554. λ *= d3_radians;
  2555. var cosφ = Math.cos(φ *= d3_radians);
  2556. x0 = cosφ * Math.cos(λ);
  2557. y0 = cosφ * Math.sin(λ);
  2558. z0 = Math.sin(φ);
  2559. d3_geo_centroid.point = nextPoint;
  2560. d3_geo_centroidPointXYZ(x0, y0, z0);
  2561. };
  2562. function nextPoint(λ, φ) {
  2563. λ *= d3_radians;
  2564. 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);
  2565. d3_geo_centroidW1 += w;
  2566. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  2567. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  2568. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  2569. d3_geo_centroidPointXYZ(x0, y0, z0);
  2570. }
  2571. }
  2572. function d3_geo_centroidLineEnd() {
  2573. d3_geo_centroid.point = d3_geo_centroidPoint;
  2574. }
  2575. function d3_geo_centroidRingStart() {
  2576. var λ00, φ00, x0, y0, z0;
  2577. d3_geo_centroid.point = function(λ, φ) {
  2578. λ00 = λ, φ00 = φ;
  2579. d3_geo_centroid.point = nextPoint;
  2580. λ *= d3_radians;
  2581. var cosφ = Math.cos(φ *= d3_radians);
  2582. x0 = cosφ * Math.cos(λ);
  2583. y0 = cosφ * Math.sin(λ);
  2584. z0 = Math.sin(φ);
  2585. d3_geo_centroidPointXYZ(x0, y0, z0);
  2586. };
  2587. d3_geo_centroid.lineEnd = function() {
  2588. nextPoint(λ00, φ00);
  2589. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  2590. d3_geo_centroid.point = d3_geo_centroidPoint;
  2591. };
  2592. function nextPoint(λ, φ) {
  2593. λ *= d3_radians;
  2594. 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);
  2595. d3_geo_centroidX2 += v * cx;
  2596. d3_geo_centroidY2 += v * cy;
  2597. d3_geo_centroidZ2 += v * cz;
  2598. d3_geo_centroidW1 += w;
  2599. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  2600. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  2601. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  2602. d3_geo_centroidPointXYZ(x0, y0, z0);
  2603. }
  2604. }
  2605. function d3_true() {
  2606. return true;
  2607. }
  2608. function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
  2609. var subject = [], clip = [];
  2610. segments.forEach(function(segment) {
  2611. if ((n = segment.length - 1) <= 0) return;
  2612. var n, p0 = segment[0], p1 = segment[n];
  2613. if (d3_geo_sphericalEqual(p0, p1)) {
  2614. listener.lineStart();
  2615. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  2616. listener.lineEnd();
  2617. return;
  2618. }
  2619. var a = {
  2620. point: p0,
  2621. points: segment,
  2622. other: null,
  2623. visited: false,
  2624. entry: true,
  2625. subject: true
  2626. }, b = {
  2627. point: p0,
  2628. points: [ p0 ],
  2629. other: a,
  2630. visited: false,
  2631. entry: false,
  2632. subject: false
  2633. };
  2634. a.other = b;
  2635. subject.push(a);
  2636. clip.push(b);
  2637. a = {
  2638. point: p1,
  2639. points: [ p1 ],
  2640. other: null,
  2641. visited: false,
  2642. entry: false,
  2643. subject: true
  2644. };
  2645. b = {
  2646. point: p1,
  2647. points: [ p1 ],
  2648. other: a,
  2649. visited: false,
  2650. entry: true,
  2651. subject: false
  2652. };
  2653. a.other = b;
  2654. subject.push(a);
  2655. clip.push(b);
  2656. });
  2657. clip.sort(compare);
  2658. d3_geo_clipPolygonLinkCircular(subject);
  2659. d3_geo_clipPolygonLinkCircular(clip);
  2660. if (!subject.length) return;
  2661. for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
  2662. clip[i].entry = entry = !entry;
  2663. }
  2664. var start = subject[0], current, points, point;
  2665. while (1) {
  2666. current = start;
  2667. while (current.visited) if ((current = current.next) === start) return;
  2668. points = current.points;
  2669. listener.lineStart();
  2670. do {
  2671. current.visited = current.other.visited = true;
  2672. if (current.entry) {
  2673. if (current.subject) {
  2674. for (var i = 0; i < points.length; i++) listener.point((point = points[i])[0], point[1]);
  2675. } else {
  2676. interpolate(current.point, current.next.point, 1, listener);
  2677. }
  2678. current = current.next;
  2679. } else {
  2680. if (current.subject) {
  2681. points = current.prev.points;
  2682. for (var i = points.length; --i >= 0; ) listener.point((point = points[i])[0], point[1]);
  2683. } else {
  2684. interpolate(current.point, current.prev.point, -1, listener);
  2685. }
  2686. current = current.prev;
  2687. }
  2688. current = current.other;
  2689. points = current.points;
  2690. } while (!current.visited);
  2691. listener.lineEnd();
  2692. }
  2693. }
  2694. function d3_geo_clipPolygonLinkCircular(array) {
  2695. if (!(n = array.length)) return;
  2696. var n, i = 0, a = array[0], b;
  2697. while (++i < n) {
  2698. a.next = b = array[i];
  2699. b.prev = a;
  2700. a = b;
  2701. }
  2702. a.next = b = array[0];
  2703. b.prev = a;
  2704. }
  2705. function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
  2706. return function(rotate, listener) {
  2707. var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
  2708. var clip = {
  2709. point: point,
  2710. lineStart: lineStart,
  2711. lineEnd: lineEnd,
  2712. polygonStart: function() {
  2713. clip.point = pointRing;
  2714. clip.lineStart = ringStart;
  2715. clip.lineEnd = ringEnd;
  2716. segments = [];
  2717. polygon = [];
  2718. listener.polygonStart();
  2719. },
  2720. polygonEnd: function() {
  2721. clip.point = point;
  2722. clip.lineStart = lineStart;
  2723. clip.lineEnd = lineEnd;
  2724. segments = d3.merge(segments);
  2725. var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
  2726. if (segments.length) {
  2727. d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
  2728. } else if (clipStartInside) {
  2729. listener.lineStart();
  2730. interpolate(null, null, 1, listener);
  2731. listener.lineEnd();
  2732. }
  2733. listener.polygonEnd();
  2734. segments = polygon = null;
  2735. },
  2736. sphere: function() {
  2737. listener.polygonStart();
  2738. listener.lineStart();
  2739. interpolate(null, null, 1, listener);
  2740. listener.lineEnd();
  2741. listener.polygonEnd();
  2742. }
  2743. };
  2744. function point(λ, φ) {
  2745. var point = rotate(λ, φ);
  2746. if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
  2747. }
  2748. function pointLine(λ, φ) {
  2749. var point = rotate(λ, φ);
  2750. line.point(point[0], point[1]);
  2751. }
  2752. function lineStart() {
  2753. clip.point = pointLine;
  2754. line.lineStart();
  2755. }
  2756. function lineEnd() {
  2757. clip.point = point;
  2758. line.lineEnd();
  2759. }
  2760. var segments;
  2761. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygon, ring;
  2762. function pointRing(λ, φ) {
  2763. ring.push([ λ, φ ]);
  2764. var point = rotate(λ, φ);
  2765. ringListener.point(point[0], point[1]);
  2766. }
  2767. function ringStart() {
  2768. ringListener.lineStart();
  2769. ring = [];
  2770. }
  2771. function ringEnd() {
  2772. pointRing(ring[0][0], ring[0][1]);
  2773. ringListener.lineEnd();
  2774. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  2775. ring.pop();
  2776. polygon.push(ring);
  2777. ring = null;
  2778. if (!n) return;
  2779. if (clean & 1) {
  2780. segment = ringSegments[0];
  2781. var n = segment.length - 1, i = -1, point;
  2782. listener.lineStart();
  2783. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  2784. listener.lineEnd();
  2785. return;
  2786. }
  2787. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  2788. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  2789. }
  2790. return clip;
  2791. };
  2792. }
  2793. function d3_geo_clipSegmentLength1(segment) {
  2794. return segment.length > 1;
  2795. }
  2796. function d3_geo_clipBufferListener() {
  2797. var lines = [], line;
  2798. return {
  2799. lineStart: function() {
  2800. lines.push(line = []);
  2801. },
  2802. point: function(λ, φ) {
  2803. line.push([ λ, φ ]);
  2804. },
  2805. lineEnd: d3_noop,
  2806. buffer: function() {
  2807. var buffer = lines;
  2808. lines = [];
  2809. line = null;
  2810. return buffer;
  2811. },
  2812. rejoin: function() {
  2813. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  2814. }
  2815. };
  2816. }
  2817. function d3_geo_clipSort(a, b) {
  2818. return ((a = a.point)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.point)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
  2819. }
  2820. function d3_geo_pointInPolygon(point, polygon) {
  2821. var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
  2822. d3_geo_areaRingSum.reset();
  2823. for (var i = 0, n = polygon.length; i < n; ++i) {
  2824. var ring = polygon[i], m = ring.length;
  2825. if (!m) continue;
  2826. var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
  2827. while (true) {
  2828. if (j === m) j = 0;
  2829. point = ring[j];
  2830. var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, antimeridian = Math.abs(dλ) > π, k = sinφ0 * sinφ;
  2831. d3_geo_areaRingSum.add(Math.atan2(k * Math.sin(dλ), cosφ0 * cosφ + k * Math.cos(dλ)));
  2832. polarAngle += antimeridian ? dλ + (dλ >= 0 ? 2 : -2) * π : dλ;
  2833. if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
  2834. var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
  2835. d3_geo_cartesianNormalize(arc);
  2836. var intersection = d3_geo_cartesianCross(meridianNormal, arc);
  2837. d3_geo_cartesianNormalize(intersection);
  2838. var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
  2839. if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
  2840. winding += antimeridian ^ dλ >= 0 ? 1 : -1;
  2841. }
  2842. }
  2843. if (!j++) break;
  2844. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
  2845. }
  2846. }
  2847. return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
  2848. }
  2849. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
  2850. function d3_geo_clipAntimeridianLine(listener) {
  2851. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  2852. return {
  2853. lineStart: function() {
  2854. listener.lineStart();
  2855. clean = 1;
  2856. },
  2857. point: function(λ1, φ1) {
  2858. var sλ1 = λ1 > 0 ? π : -π, dλ = Math.abs(λ1 - λ0);
  2859. if (Math.abs(dλ - π) < ε) {
  2860. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
  2861. listener.point(sλ0, φ0);
  2862. listener.lineEnd();
  2863. listener.lineStart();
  2864. listener.point(sλ1, φ0);
  2865. listener.point(λ1, φ0);
  2866. clean = 0;
  2867. } else if (sλ0 !== sλ1 && dλ >= π) {
  2868. if (Math.abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  2869. if (Math.abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  2870. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  2871. listener.point(sλ0, φ0);
  2872. listener.lineEnd();
  2873. listener.lineStart();
  2874. listener.point(sλ1, φ0);
  2875. clean = 0;
  2876. }
  2877. listener.point(λ0 = λ1, φ0 = φ1);
  2878. sλ0 = sλ1;
  2879. },
  2880. lineEnd: function() {
  2881. listener.lineEnd();
  2882. λ0 = φ0 = NaN;
  2883. },
  2884. clean: function() {
  2885. return 2 - clean;
  2886. }
  2887. };
  2888. }
  2889. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  2890. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  2891. return Math.abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
  2892. }
  2893. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  2894. var φ;
  2895. if (from == null) {
  2896. φ = direction * halfπ;
  2897. listener.point(-π, φ);
  2898. listener.point(0, φ);
  2899. listener.point(π, φ);
  2900. listener.point(π, 0);
  2901. listener.point(π, -φ);
  2902. listener.point(0, -φ);
  2903. listener.point(-π, -φ);
  2904. listener.point(-π, 0);
  2905. listener.point(-π, φ);
  2906. } else if (Math.abs(from[0] - to[0]) > ε) {
  2907. var s = (from[0] < to[0] ? 1 : -1) * π;
  2908. φ = direction * s / 2;
  2909. listener.point(-s, φ);
  2910. listener.point(0, φ);
  2911. listener.point(s, φ);
  2912. } else {
  2913. listener.point(to[0], to[1]);
  2914. }
  2915. }
  2916. function d3_geo_clipCircle(radius) {
  2917. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = Math.abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  2918. return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
  2919. function visible(λ, φ) {
  2920. return Math.cos(λ) * Math.cos(φ) > cr;
  2921. }
  2922. function clipLine(listener) {
  2923. var point0, c0, v0, v00, clean;
  2924. return {
  2925. lineStart: function() {
  2926. v00 = v0 = false;
  2927. clean = 1;
  2928. },
  2929. point: function(λ, φ) {
  2930. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  2931. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  2932. if (v !== v0) {
  2933. point2 = intersect(point0, point1);
  2934. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  2935. point1[0] += ε;
  2936. point1[1] += ε;
  2937. v = visible(point1[0], point1[1]);
  2938. }
  2939. }
  2940. if (v !== v0) {
  2941. clean = 0;
  2942. if (v) {
  2943. listener.lineStart();
  2944. point2 = intersect(point1, point0);
  2945. listener.point(point2[0], point2[1]);
  2946. } else {
  2947. point2 = intersect(point0, point1);
  2948. listener.point(point2[0], point2[1]);
  2949. listener.lineEnd();
  2950. }
  2951. point0 = point2;
  2952. } else if (notHemisphere && point0 && smallRadius ^ v) {
  2953. var t;
  2954. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  2955. clean = 0;
  2956. if (smallRadius) {
  2957. listener.lineStart();
  2958. listener.point(t[0][0], t[0][1]);
  2959. listener.point(t[1][0], t[1][1]);
  2960. listener.lineEnd();
  2961. } else {
  2962. listener.point(t[1][0], t[1][1]);
  2963. listener.lineEnd();
  2964. listener.lineStart();
  2965. listener.point(t[0][0], t[0][1]);
  2966. }
  2967. }
  2968. }
  2969. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  2970. listener.point(point1[0], point1[1]);
  2971. }
  2972. point0 = point1, v0 = v, c0 = c;
  2973. },
  2974. lineEnd: function() {
  2975. if (v0) listener.lineEnd();
  2976. point0 = null;
  2977. },
  2978. clean: function() {
  2979. return clean | (v00 && v0) << 1;
  2980. }
  2981. };
  2982. }
  2983. function intersect(a, b, two) {
  2984. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  2985. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  2986. if (!determinant) return !two && a;
  2987. 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);
  2988. d3_geo_cartesianAdd(A, B);
  2989. 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);
  2990. if (t2 < 0) return;
  2991. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  2992. d3_geo_cartesianAdd(q, A);
  2993. q = d3_geo_spherical(q);
  2994. if (!two) return q;
  2995. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  2996. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  2997. var δλ = λ1 - λ0, polar = Math.abs(δλ - π) < ε, meridian = polar || δλ < ε;
  2998. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  2999. if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (Math.abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
  3000. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  3001. d3_geo_cartesianAdd(q1, A);
  3002. return [ q, d3_geo_spherical(q1) ];
  3003. }
  3004. }
  3005. function code(λ, φ) {
  3006. var r = smallRadius ? radius : π - radius, code = 0;
  3007. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  3008. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  3009. return code;
  3010. }
  3011. }
  3012. var d3_geo_clipExtentMAX = 1e9;
  3013. d3.geo.clipExtent = function() {
  3014. var x0, y0, x1, y1, stream, clip, clipExtent = {
  3015. stream: function(output) {
  3016. if (stream) stream.valid = false;
  3017. stream = clip(output);
  3018. stream.valid = true;
  3019. return stream;
  3020. },
  3021. extent: function(_) {
  3022. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3023. clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
  3024. if (stream) stream.valid = false, stream = null;
  3025. return clipExtent;
  3026. }
  3027. };
  3028. return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
  3029. };
  3030. function d3_geo_clipExtent(x0, y0, x1, y1) {
  3031. return function(listener) {
  3032. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), segments, polygon, ring;
  3033. var clip = {
  3034. point: point,
  3035. lineStart: lineStart,
  3036. lineEnd: lineEnd,
  3037. polygonStart: function() {
  3038. listener = bufferListener;
  3039. segments = [];
  3040. polygon = [];
  3041. clean = true;
  3042. },
  3043. polygonEnd: function() {
  3044. listener = listener_;
  3045. segments = d3.merge(segments);
  3046. var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
  3047. if (inside || visible) {
  3048. listener.polygonStart();
  3049. if (inside) {
  3050. listener.lineStart();
  3051. interpolate(null, null, 1, listener);
  3052. listener.lineEnd();
  3053. }
  3054. if (visible) {
  3055. d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
  3056. }
  3057. listener.polygonEnd();
  3058. }
  3059. segments = polygon = ring = null;
  3060. }
  3061. };
  3062. function insidePolygon(p) {
  3063. var wn = 0, n = polygon.length, y = p[1];
  3064. for (var i = 0; i < n; ++i) {
  3065. for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
  3066. b = v[j];
  3067. if (a[1] <= y) {
  3068. if (b[1] > y && isLeft(a, b, p) > 0) ++wn;
  3069. } else {
  3070. if (b[1] <= y && isLeft(a, b, p) < 0) --wn;
  3071. }
  3072. a = b;
  3073. }
  3074. }
  3075. return wn !== 0;
  3076. }
  3077. function isLeft(a, b, c) {
  3078. return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]);
  3079. }
  3080. function interpolate(from, to, direction, listener) {
  3081. var a = 0, a1 = 0;
  3082. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  3083. do {
  3084. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  3085. } while ((a = (a + direction + 4) % 4) !== a1);
  3086. } else {
  3087. listener.point(to[0], to[1]);
  3088. }
  3089. }
  3090. function pointVisible(x, y) {
  3091. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  3092. }
  3093. function point(x, y) {
  3094. if (pointVisible(x, y)) listener.point(x, y);
  3095. }
  3096. var x__, y__, v__, x_, y_, v_, first, clean;
  3097. function lineStart() {
  3098. clip.point = linePoint;
  3099. if (polygon) polygon.push(ring = []);
  3100. first = true;
  3101. v_ = false;
  3102. x_ = y_ = NaN;
  3103. }
  3104. function lineEnd() {
  3105. if (segments) {
  3106. linePoint(x__, y__);
  3107. if (v__ && v_) bufferListener.rejoin();
  3108. segments.push(bufferListener.buffer());
  3109. }
  3110. clip.point = point;
  3111. if (v_) listener.lineEnd();
  3112. }
  3113. function linePoint(x, y) {
  3114. x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
  3115. y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
  3116. var v = pointVisible(x, y);
  3117. if (polygon) ring.push([ x, y ]);
  3118. if (first) {
  3119. x__ = x, y__ = y, v__ = v;
  3120. first = false;
  3121. if (v) {
  3122. listener.lineStart();
  3123. listener.point(x, y);
  3124. }
  3125. } else {
  3126. if (v && v_) listener.point(x, y); else {
  3127. var a = [ x_, y_ ], b = [ x, y ];
  3128. if (clipLine(a, b)) {
  3129. if (!v_) {
  3130. listener.lineStart();
  3131. listener.point(a[0], a[1]);
  3132. }
  3133. listener.point(b[0], b[1]);
  3134. if (!v) listener.lineEnd();
  3135. clean = false;
  3136. } else if (v) {
  3137. listener.lineStart();
  3138. listener.point(x, y);
  3139. clean = false;
  3140. }
  3141. }
  3142. }
  3143. x_ = x, y_ = y, v_ = v;
  3144. }
  3145. return clip;
  3146. };
  3147. function corner(p, direction) {
  3148. return Math.abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : Math.abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : Math.abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
  3149. }
  3150. function compare(a, b) {
  3151. return comparePoints(a.point, b.point);
  3152. }
  3153. function comparePoints(a, b) {
  3154. var ca = corner(a, 1), cb = corner(b, 1);
  3155. 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];
  3156. }
  3157. function clipLine(a, b) {
  3158. var dx = b[0] - a[0], dy = b[1] - a[1], t = [ 0, 1 ];
  3159. if (Math.abs(dx) < ε && Math.abs(dy) < ε) return x0 <= a[0] && a[0] <= x1 && y0 <= a[1] && a[1] <= y1;
  3160. if (d3_geo_clipExtentT(x0 - a[0], dx, t) && d3_geo_clipExtentT(a[0] - x1, -dx, t) && d3_geo_clipExtentT(y0 - a[1], dy, t) && d3_geo_clipExtentT(a[1] - y1, -dy, t)) {
  3161. if (t[1] < 1) {
  3162. b[0] = a[0] + t[1] * dx;
  3163. b[1] = a[1] + t[1] * dy;
  3164. }
  3165. if (t[0] > 0) {
  3166. a[0] += t[0] * dx;
  3167. a[1] += t[0] * dy;
  3168. }
  3169. return true;
  3170. }
  3171. return false;
  3172. }
  3173. }
  3174. function d3_geo_clipExtentT(num, denominator, t) {
  3175. if (Math.abs(denominator) < ε) return num <= 0;
  3176. var u = num / denominator;
  3177. if (denominator > 0) {
  3178. if (u > t[1]) return false;
  3179. if (u > t[0]) t[0] = u;
  3180. } else {
  3181. if (u < t[0]) return false;
  3182. if (u < t[1]) t[1] = u;
  3183. }
  3184. return true;
  3185. }
  3186. function d3_geo_compose(a, b) {
  3187. function compose(x, y) {
  3188. return x = a(x, y), b(x[0], x[1]);
  3189. }
  3190. if (a.invert && b.invert) compose.invert = function(x, y) {
  3191. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  3192. };
  3193. return compose;
  3194. }
  3195. function d3_geo_conic(projectAt) {
  3196. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  3197. p.parallels = function(_) {
  3198. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  3199. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  3200. };
  3201. return p;
  3202. }
  3203. function d3_geo_conicEqualArea(φ0, φ1) {
  3204. 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;
  3205. function forward(λ, φ) {
  3206. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  3207. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  3208. }
  3209. forward.invert = function(x, y) {
  3210. var ρ0_y = ρ0 - y;
  3211. return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  3212. };
  3213. return forward;
  3214. }
  3215. (d3.geo.conicEqualArea = function() {
  3216. return d3_geo_conic(d3_geo_conicEqualArea);
  3217. }).raw = d3_geo_conicEqualArea;
  3218. d3.geo.albers = function() {
  3219. return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
  3220. };
  3221. d3.geo.albersUsa = function() {
  3222. var lower48 = d3.geo.albers();
  3223. var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
  3224. var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
  3225. var point, pointStream = {
  3226. point: function(x, y) {
  3227. point = [ x, y ];
  3228. }
  3229. }, lower48Point, alaskaPoint, hawaiiPoint;
  3230. function albersUsa(coordinates) {
  3231. var x = coordinates[0], y = coordinates[1];
  3232. point = null;
  3233. (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
  3234. return point;
  3235. }
  3236. albersUsa.invert = function(coordinates) {
  3237. var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
  3238. return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
  3239. };
  3240. albersUsa.stream = function(stream) {
  3241. var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
  3242. return {
  3243. point: function(x, y) {
  3244. lower48Stream.point(x, y);
  3245. alaskaStream.point(x, y);
  3246. hawaiiStream.point(x, y);
  3247. },
  3248. sphere: function() {
  3249. lower48Stream.sphere();
  3250. alaskaStream.sphere();
  3251. hawaiiStream.sphere();
  3252. },
  3253. lineStart: function() {
  3254. lower48Stream.lineStart();
  3255. alaskaStream.lineStart();
  3256. hawaiiStream.lineStart();
  3257. },
  3258. lineEnd: function() {
  3259. lower48Stream.lineEnd();
  3260. alaskaStream.lineEnd();
  3261. hawaiiStream.lineEnd();
  3262. },
  3263. polygonStart: function() {
  3264. lower48Stream.polygonStart();
  3265. alaskaStream.polygonStart();
  3266. hawaiiStream.polygonStart();
  3267. },
  3268. polygonEnd: function() {
  3269. lower48Stream.polygonEnd();
  3270. alaskaStream.polygonEnd();
  3271. hawaiiStream.polygonEnd();
  3272. }
  3273. };
  3274. };
  3275. albersUsa.precision = function(_) {
  3276. if (!arguments.length) return lower48.precision();
  3277. lower48.precision(_);
  3278. alaska.precision(_);
  3279. hawaii.precision(_);
  3280. return albersUsa;
  3281. };
  3282. albersUsa.scale = function(_) {
  3283. if (!arguments.length) return lower48.scale();
  3284. lower48.scale(_);
  3285. alaska.scale(_ * .35);
  3286. hawaii.scale(_);
  3287. return albersUsa.translate(lower48.translate());
  3288. };
  3289. albersUsa.translate = function(_) {
  3290. if (!arguments.length) return lower48.translate();
  3291. var k = lower48.scale(), x = +_[0], y = +_[1];
  3292. lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
  3293. 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;
  3294. 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;
  3295. return albersUsa;
  3296. };
  3297. return albersUsa.scale(1070);
  3298. };
  3299. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  3300. point: d3_noop,
  3301. lineStart: d3_noop,
  3302. lineEnd: d3_noop,
  3303. polygonStart: function() {
  3304. d3_geo_pathAreaPolygon = 0;
  3305. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  3306. },
  3307. polygonEnd: function() {
  3308. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  3309. d3_geo_pathAreaSum += Math.abs(d3_geo_pathAreaPolygon / 2);
  3310. }
  3311. };
  3312. function d3_geo_pathAreaRingStart() {
  3313. var x00, y00, x0, y0;
  3314. d3_geo_pathArea.point = function(x, y) {
  3315. d3_geo_pathArea.point = nextPoint;
  3316. x00 = x0 = x, y00 = y0 = y;
  3317. };
  3318. function nextPoint(x, y) {
  3319. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  3320. x0 = x, y0 = y;
  3321. }
  3322. d3_geo_pathArea.lineEnd = function() {
  3323. nextPoint(x00, y00);
  3324. };
  3325. }
  3326. var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
  3327. var d3_geo_pathBounds = {
  3328. point: d3_geo_pathBoundsPoint,
  3329. lineStart: d3_noop,
  3330. lineEnd: d3_noop,
  3331. polygonStart: d3_noop,
  3332. polygonEnd: d3_noop
  3333. };
  3334. function d3_geo_pathBoundsPoint(x, y) {
  3335. if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
  3336. if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
  3337. if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
  3338. if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
  3339. }
  3340. function d3_geo_pathBuffer() {
  3341. var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
  3342. var stream = {
  3343. point: point,
  3344. lineStart: function() {
  3345. stream.point = pointLineStart;
  3346. },
  3347. lineEnd: lineEnd,
  3348. polygonStart: function() {
  3349. stream.lineEnd = lineEndPolygon;
  3350. },
  3351. polygonEnd: function() {
  3352. stream.lineEnd = lineEnd;
  3353. stream.point = point;
  3354. },
  3355. pointRadius: function(_) {
  3356. pointCircle = d3_geo_pathBufferCircle(_);
  3357. return stream;
  3358. },
  3359. result: function() {
  3360. if (buffer.length) {
  3361. var result = buffer.join("");
  3362. buffer = [];
  3363. return result;
  3364. }
  3365. }
  3366. };
  3367. function point(x, y) {
  3368. buffer.push("M", x, ",", y, pointCircle);
  3369. }
  3370. function pointLineStart(x, y) {
  3371. buffer.push("M", x, ",", y);
  3372. stream.point = pointLine;
  3373. }
  3374. function pointLine(x, y) {
  3375. buffer.push("L", x, ",", y);
  3376. }
  3377. function lineEnd() {
  3378. stream.point = point;
  3379. }
  3380. function lineEndPolygon() {
  3381. buffer.push("Z");
  3382. }
  3383. return stream;
  3384. }
  3385. function d3_geo_pathBufferCircle(radius) {
  3386. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
  3387. }
  3388. var d3_geo_pathCentroid = {
  3389. point: d3_geo_pathCentroidPoint,
  3390. lineStart: d3_geo_pathCentroidLineStart,
  3391. lineEnd: d3_geo_pathCentroidLineEnd,
  3392. polygonStart: function() {
  3393. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  3394. },
  3395. polygonEnd: function() {
  3396. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  3397. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  3398. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  3399. }
  3400. };
  3401. function d3_geo_pathCentroidPoint(x, y) {
  3402. d3_geo_centroidX0 += x;
  3403. d3_geo_centroidY0 += y;
  3404. ++d3_geo_centroidZ0;
  3405. }
  3406. function d3_geo_pathCentroidLineStart() {
  3407. var x0, y0;
  3408. d3_geo_pathCentroid.point = function(x, y) {
  3409. d3_geo_pathCentroid.point = nextPoint;
  3410. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  3411. };
  3412. function nextPoint(x, y) {
  3413. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  3414. d3_geo_centroidX1 += z * (x0 + x) / 2;
  3415. d3_geo_centroidY1 += z * (y0 + y) / 2;
  3416. d3_geo_centroidZ1 += z;
  3417. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  3418. }
  3419. }
  3420. function d3_geo_pathCentroidLineEnd() {
  3421. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  3422. }
  3423. function d3_geo_pathCentroidRingStart() {
  3424. var x00, y00, x0, y0;
  3425. d3_geo_pathCentroid.point = function(x, y) {
  3426. d3_geo_pathCentroid.point = nextPoint;
  3427. d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
  3428. };
  3429. function nextPoint(x, y) {
  3430. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  3431. d3_geo_centroidX1 += z * (x0 + x) / 2;
  3432. d3_geo_centroidY1 += z * (y0 + y) / 2;
  3433. d3_geo_centroidZ1 += z;
  3434. z = y0 * x - x0 * y;
  3435. d3_geo_centroidX2 += z * (x0 + x);
  3436. d3_geo_centroidY2 += z * (y0 + y);
  3437. d3_geo_centroidZ2 += z * 3;
  3438. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  3439. }
  3440. d3_geo_pathCentroid.lineEnd = function() {
  3441. nextPoint(x00, y00);
  3442. };
  3443. }
  3444. function d3_geo_pathContext(context) {
  3445. var pointRadius = 4.5;
  3446. var stream = {
  3447. point: point,
  3448. lineStart: function() {
  3449. stream.point = pointLineStart;
  3450. },
  3451. lineEnd: lineEnd,
  3452. polygonStart: function() {
  3453. stream.lineEnd = lineEndPolygon;
  3454. },
  3455. polygonEnd: function() {
  3456. stream.lineEnd = lineEnd;
  3457. stream.point = point;
  3458. },
  3459. pointRadius: function(_) {
  3460. pointRadius = _;
  3461. return stream;
  3462. },
  3463. result: d3_noop
  3464. };
  3465. function point(x, y) {
  3466. context.moveTo(x, y);
  3467. context.arc(x, y, pointRadius, 0, τ);
  3468. }
  3469. function pointLineStart(x, y) {
  3470. context.moveTo(x, y);
  3471. stream.point = pointLine;
  3472. }
  3473. function pointLine(x, y) {
  3474. context.lineTo(x, y);
  3475. }
  3476. function lineEnd() {
  3477. stream.point = point;
  3478. }
  3479. function lineEndPolygon() {
  3480. context.closePath();
  3481. }
  3482. return stream;
  3483. }
  3484. function d3_geo_resample(project) {
  3485. var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
  3486. function resample(stream) {
  3487. var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
  3488. var resample = {
  3489. point: point,
  3490. lineStart: lineStart,
  3491. lineEnd: lineEnd,
  3492. polygonStart: function() {
  3493. stream.polygonStart();
  3494. resample.lineStart = ringStart;
  3495. },
  3496. polygonEnd: function() {
  3497. stream.polygonEnd();
  3498. resample.lineStart = lineStart;
  3499. }
  3500. };
  3501. function point(x, y) {
  3502. x = project(x, y);
  3503. stream.point(x[0], x[1]);
  3504. }
  3505. function lineStart() {
  3506. x0 = NaN;
  3507. resample.point = linePoint;
  3508. stream.lineStart();
  3509. }
  3510. function linePoint(λ, φ) {
  3511. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  3512. 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);
  3513. stream.point(x0, y0);
  3514. }
  3515. function lineEnd() {
  3516. resample.point = point;
  3517. stream.lineEnd();
  3518. }
  3519. function ringStart() {
  3520. lineStart();
  3521. resample.point = ringPoint;
  3522. resample.lineEnd = ringEnd;
  3523. }
  3524. function ringPoint(λ, φ) {
  3525. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  3526. resample.point = linePoint;
  3527. }
  3528. function ringEnd() {
  3529. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  3530. resample.lineEnd = lineEnd;
  3531. lineEnd();
  3532. }
  3533. return resample;
  3534. }
  3535. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  3536. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  3537. if (d2 > 4 * δ2 && depth--) {
  3538. var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = Math.abs(Math.abs(c) - 1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
  3539. if (dz * dz / d2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
  3540. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  3541. stream.point(x2, y2);
  3542. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  3543. }
  3544. }
  3545. }
  3546. resample.precision = function(_) {
  3547. if (!arguments.length) return Math.sqrt(δ2);
  3548. maxDepth = (δ2 = _ * _) > 0 && 16;
  3549. return resample;
  3550. };
  3551. return resample;
  3552. }
  3553. d3.geo.transform = function(methods) {
  3554. return {
  3555. stream: function(stream) {
  3556. var transform = new d3_geo_transform(stream);
  3557. for (var k in methods) transform[k] = methods[k];
  3558. return transform;
  3559. }
  3560. };
  3561. };
  3562. function d3_geo_transform(stream) {
  3563. this.stream = stream;
  3564. }
  3565. d3_geo_transform.prototype = {
  3566. point: function(x, y) {
  3567. this.stream.point(x, y);
  3568. },
  3569. sphere: function() {
  3570. this.stream.sphere();
  3571. },
  3572. lineStart: function() {
  3573. this.stream.lineStart();
  3574. },
  3575. lineEnd: function() {
  3576. this.stream.lineEnd();
  3577. },
  3578. polygonStart: function() {
  3579. this.stream.polygonStart();
  3580. },
  3581. polygonEnd: function() {
  3582. this.stream.polygonEnd();
  3583. }
  3584. };
  3585. d3.geo.path = function() {
  3586. var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
  3587. function path(object) {
  3588. if (object) {
  3589. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  3590. if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
  3591. d3.geo.stream(object, cacheStream);
  3592. }
  3593. return contextStream.result();
  3594. }
  3595. path.area = function(object) {
  3596. d3_geo_pathAreaSum = 0;
  3597. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  3598. return d3_geo_pathAreaSum;
  3599. };
  3600. path.centroid = function(object) {
  3601. 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;
  3602. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  3603. 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 ];
  3604. };
  3605. path.bounds = function(object) {
  3606. d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
  3607. d3.geo.stream(object, projectStream(d3_geo_pathBounds));
  3608. return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
  3609. };
  3610. path.projection = function(_) {
  3611. if (!arguments.length) return projection;
  3612. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  3613. return reset();
  3614. };
  3615. path.context = function(_) {
  3616. if (!arguments.length) return context;
  3617. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  3618. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  3619. return reset();
  3620. };
  3621. path.pointRadius = function(_) {
  3622. if (!arguments.length) return pointRadius;
  3623. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  3624. return path;
  3625. };
  3626. function reset() {
  3627. cacheStream = null;
  3628. return path;
  3629. }
  3630. return path.projection(d3.geo.albersUsa()).context(null);
  3631. };
  3632. function d3_geo_pathProjectStream(project) {
  3633. var resample = d3_geo_resample(function(x, y) {
  3634. return project([ x * d3_degrees, y * d3_degrees ]);
  3635. });
  3636. return function(stream) {
  3637. var transform = new d3_geo_transform(stream = resample(stream));
  3638. transform.point = function(x, y) {
  3639. stream.point(x * d3_radians, y * d3_radians);
  3640. };
  3641. return transform;
  3642. };
  3643. }
  3644. d3.geo.projection = d3_geo_projection;
  3645. d3.geo.projectionMutator = d3_geo_projectionMutator;
  3646. function d3_geo_projection(project) {
  3647. return d3_geo_projectionMutator(function() {
  3648. return project;
  3649. })();
  3650. }
  3651. function d3_geo_projectionMutator(projectAt) {
  3652. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  3653. x = project(x, y);
  3654. return [ x[0] * k + δx, δy - x[1] * k ];
  3655. }), 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;
  3656. function projection(point) {
  3657. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  3658. return [ point[0] * k + δx, δy - point[1] * k ];
  3659. }
  3660. function invert(point) {
  3661. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  3662. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  3663. }
  3664. projection.stream = function(output) {
  3665. if (stream) stream.valid = false;
  3666. stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
  3667. stream.valid = true;
  3668. return stream;
  3669. };
  3670. projection.clipAngle = function(_) {
  3671. if (!arguments.length) return clipAngle;
  3672. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  3673. return invalidate();
  3674. };
  3675. projection.clipExtent = function(_) {
  3676. if (!arguments.length) return clipExtent;
  3677. clipExtent = _;
  3678. postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
  3679. return invalidate();
  3680. };
  3681. projection.scale = function(_) {
  3682. if (!arguments.length) return k;
  3683. k = +_;
  3684. return reset();
  3685. };
  3686. projection.translate = function(_) {
  3687. if (!arguments.length) return [ x, y ];
  3688. x = +_[0];
  3689. y = +_[1];
  3690. return reset();
  3691. };
  3692. projection.center = function(_) {
  3693. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  3694. λ = _[0] % 360 * d3_radians;
  3695. φ = _[1] % 360 * d3_radians;
  3696. return reset();
  3697. };
  3698. projection.rotate = function(_) {
  3699. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  3700. δλ = _[0] % 360 * d3_radians;
  3701. δφ = _[1] % 360 * d3_radians;
  3702. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  3703. return reset();
  3704. };
  3705. d3.rebind(projection, projectResample, "precision");
  3706. function reset() {
  3707. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  3708. var center = project(λ, φ);
  3709. δx = x - center[0] * k;
  3710. δy = y + center[1] * k;
  3711. return invalidate();
  3712. }
  3713. function invalidate() {
  3714. if (stream) stream.valid = false, stream = null;
  3715. return projection;
  3716. }
  3717. return function() {
  3718. project = projectAt.apply(this, arguments);
  3719. projection.invert = project.invert && invert;
  3720. return reset();
  3721. };
  3722. }
  3723. function d3_geo_projectionRadians(stream) {
  3724. var transform = new d3_geo_transform(stream);
  3725. transform.point = function(λ, φ) {
  3726. stream.point(λ * d3_radians, φ * d3_radians);
  3727. };
  3728. return transform;
  3729. }
  3730. function d3_geo_equirectangular(λ, φ) {
  3731. return [ λ, φ ];
  3732. }
  3733. (d3.geo.equirectangular = function() {
  3734. return d3_geo_projection(d3_geo_equirectangular);
  3735. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  3736. d3.geo.rotation = function(rotate) {
  3737. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  3738. function forward(coordinates) {
  3739. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  3740. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  3741. }
  3742. forward.invert = function(coordinates) {
  3743. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  3744. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  3745. };
  3746. return forward;
  3747. };
  3748. function d3_geo_identityRotation(λ, φ) {
  3749. return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  3750. }
  3751. d3_geo_identityRotation.invert = d3_geo_equirectangular;
  3752. function d3_geo_rotation(δλ, δφ, δγ) {
  3753. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
  3754. }
  3755. function d3_geo_forwardRotationλ(δλ) {
  3756. return function(λ, φ) {
  3757. return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  3758. };
  3759. }
  3760. function d3_geo_rotationλ(δλ) {
  3761. var rotation = d3_geo_forwardRotationλ(δλ);
  3762. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  3763. return rotation;
  3764. }
  3765. function d3_geo_rotationφγ(δφ, δγ) {
  3766. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  3767. function rotation(λ, φ) {
  3768. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  3769. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
  3770. }
  3771. rotation.invert = function(λ, φ) {
  3772. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  3773. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
  3774. };
  3775. return rotation;
  3776. }
  3777. d3.geo.circle = function() {
  3778. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  3779. function circle() {
  3780. 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 = [];
  3781. interpolate(null, null, 1, {
  3782. point: function(x, y) {
  3783. ring.push(x = rotate(x, y));
  3784. x[0] *= d3_degrees, x[1] *= d3_degrees;
  3785. }
  3786. });
  3787. return {
  3788. type: "Polygon",
  3789. coordinates: [ ring ]
  3790. };
  3791. }
  3792. circle.origin = function(x) {
  3793. if (!arguments.length) return origin;
  3794. origin = x;
  3795. return circle;
  3796. };
  3797. circle.angle = function(x) {
  3798. if (!arguments.length) return angle;
  3799. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  3800. return circle;
  3801. };
  3802. circle.precision = function(_) {
  3803. if (!arguments.length) return precision;
  3804. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  3805. return circle;
  3806. };
  3807. return circle.angle(90);
  3808. };
  3809. function d3_geo_circleInterpolate(radius, precision) {
  3810. var cr = Math.cos(radius), sr = Math.sin(radius);
  3811. return function(from, to, direction, listener) {
  3812. var step = direction * precision;
  3813. if (from != null) {
  3814. from = d3_geo_circleAngle(cr, from);
  3815. to = d3_geo_circleAngle(cr, to);
  3816. if (direction > 0 ? from < to : from > to) from += direction * τ;
  3817. } else {
  3818. from = radius + direction * τ;
  3819. to = radius - .5 * step;
  3820. }
  3821. for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
  3822. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  3823. }
  3824. };
  3825. }
  3826. function d3_geo_circleAngle(cr, point) {
  3827. var a = d3_geo_cartesian(point);
  3828. a[0] -= cr;
  3829. d3_geo_cartesianNormalize(a);
  3830. var angle = d3_acos(-a[1]);
  3831. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  3832. }
  3833. d3.geo.distance = function(a, b) {
  3834. 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;
  3835. 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Δλ);
  3836. };
  3837. d3.geo.graticule = function() {
  3838. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  3839. function graticule() {
  3840. return {
  3841. type: "MultiLineString",
  3842. coordinates: lines()
  3843. };
  3844. }
  3845. function lines() {
  3846. 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) {
  3847. return Math.abs(x % DX) > ε;
  3848. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  3849. return Math.abs(y % DY) > ε;
  3850. }).map(y));
  3851. }
  3852. graticule.lines = function() {
  3853. return lines().map(function(coordinates) {
  3854. return {
  3855. type: "LineString",
  3856. coordinates: coordinates
  3857. };
  3858. });
  3859. };
  3860. graticule.outline = function() {
  3861. return {
  3862. type: "Polygon",
  3863. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  3864. };
  3865. };
  3866. graticule.extent = function(_) {
  3867. if (!arguments.length) return graticule.minorExtent();
  3868. return graticule.majorExtent(_).minorExtent(_);
  3869. };
  3870. graticule.majorExtent = function(_) {
  3871. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  3872. X0 = +_[0][0], X1 = +_[1][0];
  3873. Y0 = +_[0][1], Y1 = +_[1][1];
  3874. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  3875. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  3876. return graticule.precision(precision);
  3877. };
  3878. graticule.minorExtent = function(_) {
  3879. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3880. x0 = +_[0][0], x1 = +_[1][0];
  3881. y0 = +_[0][1], y1 = +_[1][1];
  3882. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  3883. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  3884. return graticule.precision(precision);
  3885. };
  3886. graticule.step = function(_) {
  3887. if (!arguments.length) return graticule.minorStep();
  3888. return graticule.majorStep(_).minorStep(_);
  3889. };
  3890. graticule.majorStep = function(_) {
  3891. if (!arguments.length) return [ DX, DY ];
  3892. DX = +_[0], DY = +_[1];
  3893. return graticule;
  3894. };
  3895. graticule.minorStep = function(_) {
  3896. if (!arguments.length) return [ dx, dy ];
  3897. dx = +_[0], dy = +_[1];
  3898. return graticule;
  3899. };
  3900. graticule.precision = function(_) {
  3901. if (!arguments.length) return precision;
  3902. precision = +_;
  3903. x = d3_geo_graticuleX(y0, y1, 90);
  3904. y = d3_geo_graticuleY(x0, x1, precision);
  3905. X = d3_geo_graticuleX(Y0, Y1, 90);
  3906. Y = d3_geo_graticuleY(X0, X1, precision);
  3907. return graticule;
  3908. };
  3909. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  3910. };
  3911. function d3_geo_graticuleX(y0, y1, dy) {
  3912. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  3913. return function(x) {
  3914. return y.map(function(y) {
  3915. return [ x, y ];
  3916. });
  3917. };
  3918. }
  3919. function d3_geo_graticuleY(x0, x1, dx) {
  3920. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  3921. return function(y) {
  3922. return x.map(function(x) {
  3923. return [ x, y ];
  3924. });
  3925. };
  3926. }
  3927. function d3_source(d) {
  3928. return d.source;
  3929. }
  3930. function d3_target(d) {
  3931. return d.target;
  3932. }
  3933. d3.geo.greatArc = function() {
  3934. var source = d3_source, source_, target = d3_target, target_;
  3935. function greatArc() {
  3936. return {
  3937. type: "LineString",
  3938. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  3939. };
  3940. }
  3941. greatArc.distance = function() {
  3942. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  3943. };
  3944. greatArc.source = function(_) {
  3945. if (!arguments.length) return source;
  3946. source = _, source_ = typeof _ === "function" ? null : _;
  3947. return greatArc;
  3948. };
  3949. greatArc.target = function(_) {
  3950. if (!arguments.length) return target;
  3951. target = _, target_ = typeof _ === "function" ? null : _;
  3952. return greatArc;
  3953. };
  3954. greatArc.precision = function() {
  3955. return arguments.length ? greatArc : 0;
  3956. };
  3957. return greatArc;
  3958. };
  3959. d3.geo.interpolate = function(source, target) {
  3960. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  3961. };
  3962. function d3_geo_interpolate(x0, y0, x1, y1) {
  3963. 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);
  3964. var interpolate = d ? function(t) {
  3965. 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;
  3966. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  3967. } : function() {
  3968. return [ x0 * d3_degrees, y0 * d3_degrees ];
  3969. };
  3970. interpolate.distance = d;
  3971. return interpolate;
  3972. }
  3973. d3.geo.length = function(object) {
  3974. d3_geo_lengthSum = 0;
  3975. d3.geo.stream(object, d3_geo_length);
  3976. return d3_geo_lengthSum;
  3977. };
  3978. var d3_geo_lengthSum;
  3979. var d3_geo_length = {
  3980. sphere: d3_noop,
  3981. point: d3_noop,
  3982. lineStart: d3_geo_lengthLineStart,
  3983. lineEnd: d3_noop,
  3984. polygonStart: d3_noop,
  3985. polygonEnd: d3_noop
  3986. };
  3987. function d3_geo_lengthLineStart() {
  3988. var λ0, sinφ0, cosφ0;
  3989. d3_geo_length.point = function(λ, φ) {
  3990. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  3991. d3_geo_length.point = nextPoint;
  3992. };
  3993. d3_geo_length.lineEnd = function() {
  3994. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  3995. };
  3996. function nextPoint(λ, φ) {
  3997. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = Math.abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  3998. 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Δλ);
  3999. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  4000. }
  4001. }
  4002. function d3_geo_azimuthal(scale, angle) {
  4003. function azimuthal(λ, φ) {
  4004. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  4005. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  4006. }
  4007. azimuthal.invert = function(x, y) {
  4008. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  4009. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  4010. };
  4011. return azimuthal;
  4012. }
  4013. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  4014. return Math.sqrt(2 / (1 + cosλcosφ));
  4015. }, function(ρ) {
  4016. return 2 * Math.asin(ρ / 2);
  4017. });
  4018. (d3.geo.azimuthalEqualArea = function() {
  4019. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  4020. }).raw = d3_geo_azimuthalEqualArea;
  4021. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  4022. var c = Math.acos(cosλcosφ);
  4023. return c && c / Math.sin(c);
  4024. }, d3_identity);
  4025. (d3.geo.azimuthalEquidistant = function() {
  4026. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  4027. }).raw = d3_geo_azimuthalEquidistant;
  4028. function d3_geo_conicConformal(φ0, φ1) {
  4029. var cosφ0 = Math.cos(φ0), t = function(φ) {
  4030. return Math.tan(π / 4 + φ / 2);
  4031. }, 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;
  4032. if (!n) return d3_geo_mercator;
  4033. function forward(λ, φ) {
  4034. var ρ = Math.abs(Math.abs(φ) - halfπ) < ε ? 0 : F / Math.pow(t(φ), n);
  4035. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  4036. }
  4037. forward.invert = function(x, y) {
  4038. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  4039. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
  4040. };
  4041. return forward;
  4042. }
  4043. (d3.geo.conicConformal = function() {
  4044. return d3_geo_conic(d3_geo_conicConformal);
  4045. }).raw = d3_geo_conicConformal;
  4046. function d3_geo_conicEquidistant(φ0, φ1) {
  4047. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  4048. if (Math.abs(n) < ε) return d3_geo_equirectangular;
  4049. function forward(λ, φ) {
  4050. var ρ = G - φ;
  4051. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  4052. }
  4053. forward.invert = function(x, y) {
  4054. var ρ0_y = G - y;
  4055. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  4056. };
  4057. return forward;
  4058. }
  4059. (d3.geo.conicEquidistant = function() {
  4060. return d3_geo_conic(d3_geo_conicEquidistant);
  4061. }).raw = d3_geo_conicEquidistant;
  4062. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  4063. return 1 / cosλcosφ;
  4064. }, Math.atan);
  4065. (d3.geo.gnomonic = function() {
  4066. return d3_geo_projection(d3_geo_gnomonic);
  4067. }).raw = d3_geo_gnomonic;
  4068. function d3_geo_mercator(λ, φ) {
  4069. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  4070. }
  4071. d3_geo_mercator.invert = function(x, y) {
  4072. return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
  4073. };
  4074. function d3_geo_mercatorProjection(project) {
  4075. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  4076. m.scale = function() {
  4077. var v = scale.apply(m, arguments);
  4078. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4079. };
  4080. m.translate = function() {
  4081. var v = translate.apply(m, arguments);
  4082. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4083. };
  4084. m.clipExtent = function(_) {
  4085. var v = clipExtent.apply(m, arguments);
  4086. if (v === m) {
  4087. if (clipAuto = _ == null) {
  4088. var k = π * scale(), t = translate();
  4089. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  4090. }
  4091. } else if (clipAuto) {
  4092. v = null;
  4093. }
  4094. return v;
  4095. };
  4096. return m.clipExtent(null);
  4097. }
  4098. (d3.geo.mercator = function() {
  4099. return d3_geo_mercatorProjection(d3_geo_mercator);
  4100. }).raw = d3_geo_mercator;
  4101. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  4102. return 1;
  4103. }, Math.asin);
  4104. (d3.geo.orthographic = function() {
  4105. return d3_geo_projection(d3_geo_orthographic);
  4106. }).raw = d3_geo_orthographic;
  4107. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  4108. return 1 / (1 + cosλcosφ);
  4109. }, function(ρ) {
  4110. return 2 * Math.atan(ρ);
  4111. });
  4112. (d3.geo.stereographic = function() {
  4113. return d3_geo_projection(d3_geo_stereographic);
  4114. }).raw = d3_geo_stereographic;
  4115. function d3_geo_transverseMercator(λ, φ) {
  4116. var B = Math.cos(φ) * Math.sin(λ);
  4117. return [ Math.log((1 + B) / (1 - B)) / 2, Math.atan2(Math.tan(φ), Math.cos(λ)) ];
  4118. }
  4119. d3_geo_transverseMercator.invert = function(x, y) {
  4120. return [ Math.atan2(d3_sinh(x), Math.cos(y)), d3_asin(Math.sin(y) / d3_cosh(x)) ];
  4121. };
  4122. (d3.geo.transverseMercator = function() {
  4123. return d3_geo_mercatorProjection(d3_geo_transverseMercator);
  4124. }).raw = d3_geo_transverseMercator;
  4125. d3.geom = {};
  4126. d3.svg = {};
  4127. function d3_svg_line(projection) {
  4128. var x = d3_svg_lineX, y = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  4129. function line(data) {
  4130. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  4131. function segment() {
  4132. segments.push("M", interpolate(projection(points), tension));
  4133. }
  4134. while (++i < n) {
  4135. if (defined.call(this, d = data[i], i)) {
  4136. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  4137. } else if (points.length) {
  4138. segment();
  4139. points = [];
  4140. }
  4141. }
  4142. if (points.length) segment();
  4143. return segments.length ? segments.join("") : null;
  4144. }
  4145. line.x = function(_) {
  4146. if (!arguments.length) return x;
  4147. x = _;
  4148. return line;
  4149. };
  4150. line.y = function(_) {
  4151. if (!arguments.length) return y;
  4152. y = _;
  4153. return line;
  4154. };
  4155. line.defined = function(_) {
  4156. if (!arguments.length) return defined;
  4157. defined = _;
  4158. return line;
  4159. };
  4160. line.interpolate = function(_) {
  4161. if (!arguments.length) return interpolateKey;
  4162. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  4163. return line;
  4164. };
  4165. line.tension = function(_) {
  4166. if (!arguments.length) return tension;
  4167. tension = _;
  4168. return line;
  4169. };
  4170. return line;
  4171. }
  4172. d3.svg.line = function() {
  4173. return d3_svg_line(d3_identity);
  4174. };
  4175. function d3_svg_lineX(d) {
  4176. return d[0];
  4177. }
  4178. function d3_svg_lineY(d) {
  4179. return d[1];
  4180. }
  4181. var d3_svg_lineInterpolators = d3.map({
  4182. linear: d3_svg_lineLinear,
  4183. "linear-closed": d3_svg_lineLinearClosed,
  4184. step: d3_svg_lineStep,
  4185. "step-before": d3_svg_lineStepBefore,
  4186. "step-after": d3_svg_lineStepAfter,
  4187. basis: d3_svg_lineBasis,
  4188. "basis-open": d3_svg_lineBasisOpen,
  4189. "basis-closed": d3_svg_lineBasisClosed,
  4190. bundle: d3_svg_lineBundle,
  4191. cardinal: d3_svg_lineCardinal,
  4192. "cardinal-open": d3_svg_lineCardinalOpen,
  4193. "cardinal-closed": d3_svg_lineCardinalClosed,
  4194. monotone: d3_svg_lineMonotone
  4195. });
  4196. d3_svg_lineInterpolators.forEach(function(key, value) {
  4197. value.key = key;
  4198. value.closed = /-closed$/.test(key);
  4199. });
  4200. function d3_svg_lineLinear(points) {
  4201. return points.join("L");
  4202. }
  4203. function d3_svg_lineLinearClosed(points) {
  4204. return d3_svg_lineLinear(points) + "Z";
  4205. }
  4206. function d3_svg_lineStep(points) {
  4207. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  4208. while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
  4209. if (n > 1) path.push("H", p[0]);
  4210. return path.join("");
  4211. }
  4212. function d3_svg_lineStepBefore(points) {
  4213. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  4214. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  4215. return path.join("");
  4216. }
  4217. function d3_svg_lineStepAfter(points) {
  4218. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  4219. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  4220. return path.join("");
  4221. }
  4222. function d3_svg_lineCardinalOpen(points, tension) {
  4223. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
  4224. }
  4225. function d3_svg_lineCardinalClosed(points, tension) {
  4226. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  4227. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  4228. }
  4229. function d3_svg_lineCardinal(points, tension) {
  4230. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  4231. }
  4232. function d3_svg_lineHermite(points, tangents) {
  4233. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  4234. return d3_svg_lineLinear(points);
  4235. }
  4236. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  4237. if (quad) {
  4238. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  4239. p0 = points[1];
  4240. pi = 2;
  4241. }
  4242. if (tangents.length > 1) {
  4243. t = tangents[1];
  4244. p = points[pi];
  4245. pi++;
  4246. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  4247. for (var i = 2; i < tangents.length; i++, pi++) {
  4248. p = points[pi];
  4249. t = tangents[i];
  4250. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  4251. }
  4252. }
  4253. if (quad) {
  4254. var lp = points[pi];
  4255. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  4256. }
  4257. return path;
  4258. }
  4259. function d3_svg_lineCardinalTangents(points, tension) {
  4260. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  4261. while (++i < n) {
  4262. p0 = p1;
  4263. p1 = p2;
  4264. p2 = points[i];
  4265. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  4266. }
  4267. return tangents;
  4268. }
  4269. function d3_svg_lineBasis(points) {
  4270. if (points.length < 3) return d3_svg_lineLinear(points);
  4271. 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) ];
  4272. points.push(points[n - 1]);
  4273. while (++i <= n) {
  4274. pi = points[i];
  4275. px.shift();
  4276. px.push(pi[0]);
  4277. py.shift();
  4278. py.push(pi[1]);
  4279. d3_svg_lineBasisBezier(path, px, py);
  4280. }
  4281. points.pop();
  4282. path.push("L", pi);
  4283. return path.join("");
  4284. }
  4285. function d3_svg_lineBasisOpen(points) {
  4286. if (points.length < 4) return d3_svg_lineLinear(points);
  4287. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  4288. while (++i < 3) {
  4289. pi = points[i];
  4290. px.push(pi[0]);
  4291. py.push(pi[1]);
  4292. }
  4293. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  4294. --i;
  4295. while (++i < n) {
  4296. pi = points[i];
  4297. px.shift();
  4298. px.push(pi[0]);
  4299. py.shift();
  4300. py.push(pi[1]);
  4301. d3_svg_lineBasisBezier(path, px, py);
  4302. }
  4303. return path.join("");
  4304. }
  4305. function d3_svg_lineBasisClosed(points) {
  4306. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  4307. while (++i < 4) {
  4308. pi = points[i % n];
  4309. px.push(pi[0]);
  4310. py.push(pi[1]);
  4311. }
  4312. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  4313. --i;
  4314. while (++i < m) {
  4315. pi = points[i % n];
  4316. px.shift();
  4317. px.push(pi[0]);
  4318. py.shift();
  4319. py.push(pi[1]);
  4320. d3_svg_lineBasisBezier(path, px, py);
  4321. }
  4322. return path.join("");
  4323. }
  4324. function d3_svg_lineBundle(points, tension) {
  4325. var n = points.length - 1;
  4326. if (n) {
  4327. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  4328. while (++i <= n) {
  4329. p = points[i];
  4330. t = i / n;
  4331. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  4332. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  4333. }
  4334. }
  4335. return d3_svg_lineBasis(points);
  4336. }
  4337. function d3_svg_lineDot4(a, b) {
  4338. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  4339. }
  4340. 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 ];
  4341. function d3_svg_lineBasisBezier(path, x, y) {
  4342. 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));
  4343. }
  4344. function d3_svg_lineSlope(p0, p1) {
  4345. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  4346. }
  4347. function d3_svg_lineFiniteDifferences(points) {
  4348. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  4349. while (++i < j) {
  4350. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  4351. }
  4352. m[i] = d;
  4353. return m;
  4354. }
  4355. function d3_svg_lineMonotoneTangents(points) {
  4356. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  4357. while (++i < j) {
  4358. d = d3_svg_lineSlope(points[i], points[i + 1]);
  4359. if (Math.abs(d) < ε) {
  4360. m[i] = m[i + 1] = 0;
  4361. } else {
  4362. a = m[i] / d;
  4363. b = m[i + 1] / d;
  4364. s = a * a + b * b;
  4365. if (s > 9) {
  4366. s = d * 3 / Math.sqrt(s);
  4367. m[i] = s * a;
  4368. m[i + 1] = s * b;
  4369. }
  4370. }
  4371. }
  4372. i = -1;
  4373. while (++i <= j) {
  4374. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  4375. tangents.push([ s || 0, m[i] * s || 0 ]);
  4376. }
  4377. return tangents;
  4378. }
  4379. function d3_svg_lineMonotone(points) {
  4380. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  4381. }
  4382. d3.geom.hull = function(vertices) {
  4383. var x = d3_svg_lineX, y = d3_svg_lineY;
  4384. if (arguments.length) return hull(vertices);
  4385. function hull(data) {
  4386. if (data.length < 3) return [];
  4387. var fx = d3_functor(x), fy = d3_functor(y), n = data.length, vertices, plen = n - 1, points = [], stack = [], d, i, j, h = 0, x1, y1, x2, y2, u, v, a, sp;
  4388. if (fx === d3_svg_lineX && y === d3_svg_lineY) vertices = data; else for (i = 0,
  4389. vertices = []; i < n; ++i) {
  4390. vertices.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
  4391. }
  4392. for (i = 1; i < n; ++i) {
  4393. if (vertices[i][1] < vertices[h][1] || vertices[i][1] == vertices[h][1] && vertices[i][0] < vertices[h][0]) h = i;
  4394. }
  4395. for (i = 0; i < n; ++i) {
  4396. if (i === h) continue;
  4397. y1 = vertices[i][1] - vertices[h][1];
  4398. x1 = vertices[i][0] - vertices[h][0];
  4399. points.push({
  4400. angle: Math.atan2(y1, x1),
  4401. index: i
  4402. });
  4403. }
  4404. points.sort(function(a, b) {
  4405. return a.angle - b.angle;
  4406. });
  4407. a = points[0].angle;
  4408. v = points[0].index;
  4409. u = 0;
  4410. for (i = 1; i < plen; ++i) {
  4411. j = points[i].index;
  4412. if (a == points[i].angle) {
  4413. x1 = vertices[v][0] - vertices[h][0];
  4414. y1 = vertices[v][1] - vertices[h][1];
  4415. x2 = vertices[j][0] - vertices[h][0];
  4416. y2 = vertices[j][1] - vertices[h][1];
  4417. if (x1 * x1 + y1 * y1 >= x2 * x2 + y2 * y2) {
  4418. points[i].index = -1;
  4419. continue;
  4420. } else {
  4421. points[u].index = -1;
  4422. }
  4423. }
  4424. a = points[i].angle;
  4425. u = i;
  4426. v = j;
  4427. }
  4428. stack.push(h);
  4429. for (i = 0, j = 0; i < 2; ++j) {
  4430. if (points[j].index > -1) {
  4431. stack.push(points[j].index);
  4432. i++;
  4433. }
  4434. }
  4435. sp = stack.length;
  4436. for (;j < plen; ++j) {
  4437. if (points[j].index < 0) continue;
  4438. while (!d3_geom_hullCCW(stack[sp - 2], stack[sp - 1], points[j].index, vertices)) {
  4439. --sp;
  4440. }
  4441. stack[sp++] = points[j].index;
  4442. }
  4443. var poly = [];
  4444. for (i = sp - 1; i >= 0; --i) poly.push(data[stack[i]]);
  4445. return poly;
  4446. }
  4447. hull.x = function(_) {
  4448. return arguments.length ? (x = _, hull) : x;
  4449. };
  4450. hull.y = function(_) {
  4451. return arguments.length ? (y = _, hull) : y;
  4452. };
  4453. return hull;
  4454. };
  4455. function d3_geom_hullCCW(i1, i2, i3, v) {
  4456. var t, a, b, c, d, e, f;
  4457. t = v[i1];
  4458. a = t[0];
  4459. b = t[1];
  4460. t = v[i2];
  4461. c = t[0];
  4462. d = t[1];
  4463. t = v[i3];
  4464. e = t[0];
  4465. f = t[1];
  4466. return (f - b) * (c - a) - (d - b) * (e - a) > 0;
  4467. }
  4468. d3.geom.polygon = function(coordinates) {
  4469. d3_subclass(coordinates, d3_geom_polygonPrototype);
  4470. return coordinates;
  4471. };
  4472. var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
  4473. d3_geom_polygonPrototype.area = function() {
  4474. var i = -1, n = this.length, a, b = this[n - 1], area = 0;
  4475. while (++i < n) {
  4476. a = b;
  4477. b = this[i];
  4478. area += a[1] * b[0] - a[0] * b[1];
  4479. }
  4480. return area * .5;
  4481. };
  4482. d3_geom_polygonPrototype.centroid = function(k) {
  4483. var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
  4484. if (!arguments.length) k = -1 / (6 * this.area());
  4485. while (++i < n) {
  4486. a = b;
  4487. b = this[i];
  4488. c = a[0] * b[1] - b[0] * a[1];
  4489. x += (a[0] + b[0]) * c;
  4490. y += (a[1] + b[1]) * c;
  4491. }
  4492. return [ x * k, y * k ];
  4493. };
  4494. d3_geom_polygonPrototype.clip = function(subject) {
  4495. 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;
  4496. while (++i < n) {
  4497. input = subject.slice();
  4498. subject.length = 0;
  4499. b = this[i];
  4500. c = input[(m = input.length - closed) - 1];
  4501. j = -1;
  4502. while (++j < m) {
  4503. d = input[j];
  4504. if (d3_geom_polygonInside(d, a, b)) {
  4505. if (!d3_geom_polygonInside(c, a, b)) {
  4506. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4507. }
  4508. subject.push(d);
  4509. } else if (d3_geom_polygonInside(c, a, b)) {
  4510. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4511. }
  4512. c = d;
  4513. }
  4514. if (closed) subject.push(subject[0]);
  4515. a = b;
  4516. }
  4517. return subject;
  4518. };
  4519. function d3_geom_polygonInside(p, a, b) {
  4520. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  4521. }
  4522. function d3_geom_polygonIntersect(c, d, a, b) {
  4523. 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);
  4524. return [ x1 + ua * x21, y1 + ua * y21 ];
  4525. }
  4526. function d3_geom_polygonClosed(coordinates) {
  4527. var a = coordinates[0], b = coordinates[coordinates.length - 1];
  4528. return !(a[0] - b[0] || a[1] - b[1]);
  4529. }
  4530. d3.geom.delaunay = function(vertices) {
  4531. var edges = vertices.map(function() {
  4532. return [];
  4533. }), triangles = [];
  4534. d3_geom_voronoiTessellate(vertices, function(e) {
  4535. edges[e.region.l.index].push(vertices[e.region.r.index]);
  4536. });
  4537. edges.forEach(function(edge, i) {
  4538. var v = vertices[i], cx = v[0], cy = v[1];
  4539. edge.forEach(function(v) {
  4540. v.angle = Math.atan2(v[0] - cx, v[1] - cy);
  4541. });
  4542. edge.sort(function(a, b) {
  4543. return a.angle - b.angle;
  4544. });
  4545. for (var j = 0, m = edge.length - 1; j < m; j++) {
  4546. triangles.push([ v, edge[j], edge[j + 1] ]);
  4547. }
  4548. });
  4549. return triangles;
  4550. };
  4551. d3.geom.voronoi = function(points) {
  4552. var x = d3_svg_lineX, y = d3_svg_lineY, clipPolygon = null;
  4553. if (arguments.length) return voronoi(points);
  4554. function voronoi(data) {
  4555. var points, polygons = data.map(function() {
  4556. return [];
  4557. }), fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length, Z = 1e6;
  4558. if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (points = new Array(n),
  4559. i = 0; i < n; ++i) {
  4560. points[i] = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ];
  4561. }
  4562. d3_geom_voronoiTessellate(points, function(e) {
  4563. var s1, s2, x1, x2, y1, y2;
  4564. if (e.a === 1 && e.b >= 0) {
  4565. s1 = e.ep.r;
  4566. s2 = e.ep.l;
  4567. } else {
  4568. s1 = e.ep.l;
  4569. s2 = e.ep.r;
  4570. }
  4571. if (e.a === 1) {
  4572. y1 = s1 ? s1.y : -Z;
  4573. x1 = e.c - e.b * y1;
  4574. y2 = s2 ? s2.y : Z;
  4575. x2 = e.c - e.b * y2;
  4576. } else {
  4577. x1 = s1 ? s1.x : -Z;
  4578. y1 = e.c - e.a * x1;
  4579. x2 = s2 ? s2.x : Z;
  4580. y2 = e.c - e.a * x2;
  4581. }
  4582. var v1 = [ x1, y1 ], v2 = [ x2, y2 ];
  4583. polygons[e.region.l.index].push(v1, v2);
  4584. polygons[e.region.r.index].push(v1, v2);
  4585. });
  4586. polygons = polygons.map(function(polygon, i) {
  4587. var cx = points[i][0], cy = points[i][1], angle = polygon.map(function(v) {
  4588. return Math.atan2(v[0] - cx, v[1] - cy);
  4589. }), order = d3.range(polygon.length).sort(function(a, b) {
  4590. return angle[a] - angle[b];
  4591. });
  4592. return order.filter(function(d, i) {
  4593. return !i || angle[d] - angle[order[i - 1]] > ε;
  4594. }).map(function(d) {
  4595. return polygon[d];
  4596. });
  4597. });
  4598. polygons.forEach(function(polygon, i) {
  4599. var n = polygon.length;
  4600. if (!n) return polygon.push([ -Z, -Z ], [ -Z, Z ], [ Z, Z ], [ Z, -Z ]);
  4601. if (n > 2) return;
  4602. var p0 = points[i], p1 = polygon[0], p2 = polygon[1], x0 = p0[0], y0 = p0[1], x1 = p1[0], y1 = p1[1], x2 = p2[0], y2 = p2[1], dx = Math.abs(x2 - x1), dy = y2 - y1;
  4603. if (Math.abs(dy) < ε) {
  4604. var y = y0 < y1 ? -Z : Z;
  4605. polygon.push([ -Z, y ], [ Z, y ]);
  4606. } else if (dx < ε) {
  4607. var x = x0 < x1 ? -Z : Z;
  4608. polygon.push([ x, -Z ], [ x, Z ]);
  4609. } else {
  4610. var y = (x2 - x1) * (y1 - y0) < (x1 - x0) * (y2 - y1) ? Z : -Z, z = Math.abs(dy) - dx;
  4611. if (Math.abs(z) < ε) {
  4612. polygon.push([ dy < 0 ? y : -y, y ]);
  4613. } else {
  4614. if (z > 0) y *= -1;
  4615. polygon.push([ -Z, y ], [ Z, y ]);
  4616. }
  4617. }
  4618. });
  4619. if (clipPolygon) for (i = 0; i < n; ++i) clipPolygon.clip(polygons[i]);
  4620. for (i = 0; i < n; ++i) polygons[i].point = data[i];
  4621. return polygons;
  4622. }
  4623. voronoi.x = function(_) {
  4624. return arguments.length ? (x = _, voronoi) : x;
  4625. };
  4626. voronoi.y = function(_) {
  4627. return arguments.length ? (y = _, voronoi) : y;
  4628. };
  4629. voronoi.clipExtent = function(_) {
  4630. if (!arguments.length) return clipPolygon && [ clipPolygon[0], clipPolygon[2] ];
  4631. if (_ == null) clipPolygon = null; else {
  4632. var x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], y2 = +_[1][1];
  4633. clipPolygon = d3.geom.polygon([ [ x1, y1 ], [ x1, y2 ], [ x2, y2 ], [ x2, y1 ] ]);
  4634. }
  4635. return voronoi;
  4636. };
  4637. voronoi.size = function(_) {
  4638. if (!arguments.length) return clipPolygon && clipPolygon[2];
  4639. return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
  4640. };
  4641. voronoi.links = function(data) {
  4642. var points, graph = data.map(function() {
  4643. return [];
  4644. }), links = [], fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length;
  4645. if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (points = new Array(n),
  4646. i = 0; i < n; ++i) {
  4647. points[i] = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ];
  4648. }
  4649. d3_geom_voronoiTessellate(points, function(e) {
  4650. var l = e.region.l.index, r = e.region.r.index;
  4651. if (graph[l][r]) return;
  4652. graph[l][r] = graph[r][l] = true;
  4653. links.push({
  4654. source: data[l],
  4655. target: data[r]
  4656. });
  4657. });
  4658. return links;
  4659. };
  4660. voronoi.triangles = function(data) {
  4661. if (x === d3_svg_lineX && y === d3_svg_lineY) return d3.geom.delaunay(data);
  4662. var points = new Array(n), fx = d3_functor(x), fy = d3_functor(y), d, i = -1, n = data.length;
  4663. while (++i < n) {
  4664. (points[i] = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]).data = d;
  4665. }
  4666. return d3.geom.delaunay(points).map(function(triangle) {
  4667. return triangle.map(function(point) {
  4668. return point.data;
  4669. });
  4670. });
  4671. };
  4672. return voronoi;
  4673. };
  4674. var d3_geom_voronoiOpposite = {
  4675. l: "r",
  4676. r: "l"
  4677. };
  4678. function d3_geom_voronoiTessellate(points, callback) {
  4679. var Sites = {
  4680. list: points.map(function(v, i) {
  4681. return {
  4682. index: i,
  4683. x: v[0],
  4684. y: v[1]
  4685. };
  4686. }).sort(function(a, b) {
  4687. return a.y < b.y ? -1 : a.y > b.y ? 1 : a.x < b.x ? -1 : a.x > b.x ? 1 : 0;
  4688. }),
  4689. bottomSite: null
  4690. };
  4691. var EdgeList = {
  4692. list: [],
  4693. leftEnd: null,
  4694. rightEnd: null,
  4695. init: function() {
  4696. EdgeList.leftEnd = EdgeList.createHalfEdge(null, "l");
  4697. EdgeList.rightEnd = EdgeList.createHalfEdge(null, "l");
  4698. EdgeList.leftEnd.r = EdgeList.rightEnd;
  4699. EdgeList.rightEnd.l = EdgeList.leftEnd;
  4700. EdgeList.list.unshift(EdgeList.leftEnd, EdgeList.rightEnd);
  4701. },
  4702. createHalfEdge: function(edge, side) {
  4703. return {
  4704. edge: edge,
  4705. side: side,
  4706. vertex: null,
  4707. l: null,
  4708. r: null
  4709. };
  4710. },
  4711. insert: function(lb, he) {
  4712. he.l = lb;
  4713. he.r = lb.r;
  4714. lb.r.l = he;
  4715. lb.r = he;
  4716. },
  4717. leftBound: function(p) {
  4718. var he = EdgeList.leftEnd;
  4719. do {
  4720. he = he.r;
  4721. } while (he != EdgeList.rightEnd && Geom.rightOf(he, p));
  4722. he = he.l;
  4723. return he;
  4724. },
  4725. del: function(he) {
  4726. he.l.r = he.r;
  4727. he.r.l = he.l;
  4728. he.edge = null;
  4729. },
  4730. right: function(he) {
  4731. return he.r;
  4732. },
  4733. left: function(he) {
  4734. return he.l;
  4735. },
  4736. leftRegion: function(he) {
  4737. return he.edge == null ? Sites.bottomSite : he.edge.region[he.side];
  4738. },
  4739. rightRegion: function(he) {
  4740. return he.edge == null ? Sites.bottomSite : he.edge.region[d3_geom_voronoiOpposite[he.side]];
  4741. }
  4742. };
  4743. var Geom = {
  4744. bisect: function(s1, s2) {
  4745. var newEdge = {
  4746. region: {
  4747. l: s1,
  4748. r: s2
  4749. },
  4750. ep: {
  4751. l: null,
  4752. r: null
  4753. }
  4754. };
  4755. var dx = s2.x - s1.x, dy = s2.y - s1.y, adx = dx > 0 ? dx : -dx, ady = dy > 0 ? dy : -dy;
  4756. newEdge.c = s1.x * dx + s1.y * dy + (dx * dx + dy * dy) * .5;
  4757. if (adx > ady) {
  4758. newEdge.a = 1;
  4759. newEdge.b = dy / dx;
  4760. newEdge.c /= dx;
  4761. } else {
  4762. newEdge.b = 1;
  4763. newEdge.a = dx / dy;
  4764. newEdge.c /= dy;
  4765. }
  4766. return newEdge;
  4767. },
  4768. intersect: function(el1, el2) {
  4769. var e1 = el1.edge, e2 = el2.edge;
  4770. if (!e1 || !e2 || e1.region.r == e2.region.r) {
  4771. return null;
  4772. }
  4773. var d = e1.a * e2.b - e1.b * e2.a;
  4774. if (Math.abs(d) < 1e-10) {
  4775. return null;
  4776. }
  4777. var xint = (e1.c * e2.b - e2.c * e1.b) / d, yint = (e2.c * e1.a - e1.c * e2.a) / d, e1r = e1.region.r, e2r = e2.region.r, el, e;
  4778. if (e1r.y < e2r.y || e1r.y == e2r.y && e1r.x < e2r.x) {
  4779. el = el1;
  4780. e = e1;
  4781. } else {
  4782. el = el2;
  4783. e = e2;
  4784. }
  4785. var rightOfSite = xint >= e.region.r.x;
  4786. if (rightOfSite && el.side === "l" || !rightOfSite && el.side === "r") {
  4787. return null;
  4788. }
  4789. return {
  4790. x: xint,
  4791. y: yint
  4792. };
  4793. },
  4794. rightOf: function(he, p) {
  4795. var e = he.edge, topsite = e.region.r, rightOfSite = p.x > topsite.x;
  4796. if (rightOfSite && he.side === "l") {
  4797. return 1;
  4798. }
  4799. if (!rightOfSite && he.side === "r") {
  4800. return 0;
  4801. }
  4802. if (e.a === 1) {
  4803. var dyp = p.y - topsite.y, dxp = p.x - topsite.x, fast = 0, above = 0;
  4804. if (!rightOfSite && e.b < 0 || rightOfSite && e.b >= 0) {
  4805. above = fast = dyp >= e.b * dxp;
  4806. } else {
  4807. above = p.x + p.y * e.b > e.c;
  4808. if (e.b < 0) {
  4809. above = !above;
  4810. }
  4811. if (!above) {
  4812. fast = 1;
  4813. }
  4814. }
  4815. if (!fast) {
  4816. var dxs = topsite.x - e.region.l.x;
  4817. above = e.b * (dxp * dxp - dyp * dyp) < dxs * dyp * (1 + 2 * dxp / dxs + e.b * e.b);
  4818. if (e.b < 0) {
  4819. above = !above;
  4820. }
  4821. }
  4822. } else {
  4823. var yl = e.c - e.a * p.x, t1 = p.y - yl, t2 = p.x - topsite.x, t3 = yl - topsite.y;
  4824. above = t1 * t1 > t2 * t2 + t3 * t3;
  4825. }
  4826. return he.side === "l" ? above : !above;
  4827. },
  4828. endPoint: function(edge, side, site) {
  4829. edge.ep[side] = site;
  4830. if (!edge.ep[d3_geom_voronoiOpposite[side]]) return;
  4831. callback(edge);
  4832. },
  4833. distance: function(s, t) {
  4834. var dx = s.x - t.x, dy = s.y - t.y;
  4835. return Math.sqrt(dx * dx + dy * dy);
  4836. }
  4837. };
  4838. var EventQueue = {
  4839. list: [],
  4840. insert: function(he, site, offset) {
  4841. he.vertex = site;
  4842. he.ystar = site.y + offset;
  4843. for (var i = 0, list = EventQueue.list, l = list.length; i < l; i++) {
  4844. var next = list[i];
  4845. if (he.ystar > next.ystar || he.ystar == next.ystar && site.x > next.vertex.x) {
  4846. continue;
  4847. } else {
  4848. break;
  4849. }
  4850. }
  4851. list.splice(i, 0, he);
  4852. },
  4853. del: function(he) {
  4854. for (var i = 0, ls = EventQueue.list, l = ls.length; i < l && ls[i] != he; ++i) {}
  4855. ls.splice(i, 1);
  4856. },
  4857. empty: function() {
  4858. return EventQueue.list.length === 0;
  4859. },
  4860. nextEvent: function(he) {
  4861. for (var i = 0, ls = EventQueue.list, l = ls.length; i < l; ++i) {
  4862. if (ls[i] == he) return ls[i + 1];
  4863. }
  4864. return null;
  4865. },
  4866. min: function() {
  4867. var elem = EventQueue.list[0];
  4868. return {
  4869. x: elem.vertex.x,
  4870. y: elem.ystar
  4871. };
  4872. },
  4873. extractMin: function() {
  4874. return EventQueue.list.shift();
  4875. }
  4876. };
  4877. EdgeList.init();
  4878. Sites.bottomSite = Sites.list.shift();
  4879. var newSite = Sites.list.shift(), newIntStar;
  4880. var lbnd, rbnd, llbnd, rrbnd, bisector;
  4881. var bot, top, temp, p, v;
  4882. var e, pm;
  4883. while (true) {
  4884. if (!EventQueue.empty()) {
  4885. newIntStar = EventQueue.min();
  4886. }
  4887. if (newSite && (EventQueue.empty() || newSite.y < newIntStar.y || newSite.y == newIntStar.y && newSite.x < newIntStar.x)) {
  4888. lbnd = EdgeList.leftBound(newSite);
  4889. rbnd = EdgeList.right(lbnd);
  4890. bot = EdgeList.rightRegion(lbnd);
  4891. e = Geom.bisect(bot, newSite);
  4892. bisector = EdgeList.createHalfEdge(e, "l");
  4893. EdgeList.insert(lbnd, bisector);
  4894. p = Geom.intersect(lbnd, bisector);
  4895. if (p) {
  4896. EventQueue.del(lbnd);
  4897. EventQueue.insert(lbnd, p, Geom.distance(p, newSite));
  4898. }
  4899. lbnd = bisector;
  4900. bisector = EdgeList.createHalfEdge(e, "r");
  4901. EdgeList.insert(lbnd, bisector);
  4902. p = Geom.intersect(bisector, rbnd);
  4903. if (p) {
  4904. EventQueue.insert(bisector, p, Geom.distance(p, newSite));
  4905. }
  4906. newSite = Sites.list.shift();
  4907. } else if (!EventQueue.empty()) {
  4908. lbnd = EventQueue.extractMin();
  4909. llbnd = EdgeList.left(lbnd);
  4910. rbnd = EdgeList.right(lbnd);
  4911. rrbnd = EdgeList.right(rbnd);
  4912. bot = EdgeList.leftRegion(lbnd);
  4913. top = EdgeList.rightRegion(rbnd);
  4914. v = lbnd.vertex;
  4915. Geom.endPoint(lbnd.edge, lbnd.side, v);
  4916. Geom.endPoint(rbnd.edge, rbnd.side, v);
  4917. EdgeList.del(lbnd);
  4918. EventQueue.del(rbnd);
  4919. EdgeList.del(rbnd);
  4920. pm = "l";
  4921. if (bot.y > top.y) {
  4922. temp = bot;
  4923. bot = top;
  4924. top = temp;
  4925. pm = "r";
  4926. }
  4927. e = Geom.bisect(bot, top);
  4928. bisector = EdgeList.createHalfEdge(e, pm);
  4929. EdgeList.insert(llbnd, bisector);
  4930. Geom.endPoint(e, d3_geom_voronoiOpposite[pm], v);
  4931. p = Geom.intersect(llbnd, bisector);
  4932. if (p) {
  4933. EventQueue.del(llbnd);
  4934. EventQueue.insert(llbnd, p, Geom.distance(p, bot));
  4935. }
  4936. p = Geom.intersect(bisector, rrbnd);
  4937. if (p) {
  4938. EventQueue.insert(bisector, p, Geom.distance(p, bot));
  4939. }
  4940. } else {
  4941. break;
  4942. }
  4943. }
  4944. for (lbnd = EdgeList.right(EdgeList.leftEnd); lbnd != EdgeList.rightEnd; lbnd = EdgeList.right(lbnd)) {
  4945. callback(lbnd.edge);
  4946. }
  4947. }
  4948. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  4949. var x = d3_svg_lineX, y = d3_svg_lineY, compat;
  4950. if (compat = arguments.length) {
  4951. x = d3_geom_quadtreeCompatX;
  4952. y = d3_geom_quadtreeCompatY;
  4953. if (compat === 3) {
  4954. y2 = y1;
  4955. x2 = x1;
  4956. y1 = x1 = 0;
  4957. }
  4958. return quadtree(points);
  4959. }
  4960. function quadtree(data) {
  4961. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  4962. if (x1 != null) {
  4963. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  4964. } else {
  4965. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  4966. xs = [], ys = [];
  4967. n = data.length;
  4968. if (compat) for (i = 0; i < n; ++i) {
  4969. d = data[i];
  4970. if (d.x < x1_) x1_ = d.x;
  4971. if (d.y < y1_) y1_ = d.y;
  4972. if (d.x > x2_) x2_ = d.x;
  4973. if (d.y > y2_) y2_ = d.y;
  4974. xs.push(d.x);
  4975. ys.push(d.y);
  4976. } else for (i = 0; i < n; ++i) {
  4977. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  4978. if (x_ < x1_) x1_ = x_;
  4979. if (y_ < y1_) y1_ = y_;
  4980. if (x_ > x2_) x2_ = x_;
  4981. if (y_ > y2_) y2_ = y_;
  4982. xs.push(x_);
  4983. ys.push(y_);
  4984. }
  4985. }
  4986. var dx = x2_ - x1_, dy = y2_ - y1_;
  4987. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  4988. function insert(n, d, x, y, x1, y1, x2, y2) {
  4989. if (isNaN(x) || isNaN(y)) return;
  4990. if (n.leaf) {
  4991. var nx = n.x, ny = n.y;
  4992. if (nx != null) {
  4993. if (Math.abs(nx - x) + Math.abs(ny - y) < .01) {
  4994. insertChild(n, d, x, y, x1, y1, x2, y2);
  4995. } else {
  4996. var nPoint = n.point;
  4997. n.x = n.y = n.point = null;
  4998. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  4999. insertChild(n, d, x, y, x1, y1, x2, y2);
  5000. }
  5001. } else {
  5002. n.x = x, n.y = y, n.point = d;
  5003. }
  5004. } else {
  5005. insertChild(n, d, x, y, x1, y1, x2, y2);
  5006. }
  5007. }
  5008. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  5009. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = x >= sx, bottom = y >= sy, i = (bottom << 1) + right;
  5010. n.leaf = false;
  5011. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  5012. if (right) x1 = sx; else x2 = sx;
  5013. if (bottom) y1 = sy; else y2 = sy;
  5014. insert(n, d, x, y, x1, y1, x2, y2);
  5015. }
  5016. var root = d3_geom_quadtreeNode();
  5017. root.add = function(d) {
  5018. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  5019. };
  5020. root.visit = function(f) {
  5021. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  5022. };
  5023. i = -1;
  5024. if (x1 == null) {
  5025. while (++i < n) {
  5026. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  5027. }
  5028. --i;
  5029. } else data.forEach(root.add);
  5030. xs = ys = data = d = null;
  5031. return root;
  5032. }
  5033. quadtree.x = function(_) {
  5034. return arguments.length ? (x = _, quadtree) : x;
  5035. };
  5036. quadtree.y = function(_) {
  5037. return arguments.length ? (y = _, quadtree) : y;
  5038. };
  5039. quadtree.extent = function(_) {
  5040. if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
  5041. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
  5042. y2 = +_[1][1];
  5043. return quadtree;
  5044. };
  5045. quadtree.size = function(_) {
  5046. if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
  5047. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
  5048. return quadtree;
  5049. };
  5050. return quadtree;
  5051. };
  5052. function d3_geom_quadtreeCompatX(d) {
  5053. return d.x;
  5054. }
  5055. function d3_geom_quadtreeCompatY(d) {
  5056. return d.y;
  5057. }
  5058. function d3_geom_quadtreeNode() {
  5059. return {
  5060. leaf: true,
  5061. nodes: [],
  5062. point: null,
  5063. x: null,
  5064. y: null
  5065. };
  5066. }
  5067. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  5068. if (!f(node, x1, y1, x2, y2)) {
  5069. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  5070. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  5071. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  5072. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  5073. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  5074. }
  5075. }
  5076. d3.interpolateRgb = d3_interpolateRgb;
  5077. function d3_interpolateRgb(a, b) {
  5078. a = d3.rgb(a);
  5079. b = d3.rgb(b);
  5080. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  5081. return function(t) {
  5082. 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));
  5083. };
  5084. }
  5085. d3.interpolateObject = d3_interpolateObject;
  5086. function d3_interpolateObject(a, b) {
  5087. var i = {}, c = {}, k;
  5088. for (k in a) {
  5089. if (k in b) {
  5090. i[k] = d3_interpolate(a[k], b[k]);
  5091. } else {
  5092. c[k] = a[k];
  5093. }
  5094. }
  5095. for (k in b) {
  5096. if (!(k in a)) {
  5097. c[k] = b[k];
  5098. }
  5099. }
  5100. return function(t) {
  5101. for (k in i) c[k] = i[k](t);
  5102. return c;
  5103. };
  5104. }
  5105. d3.interpolateNumber = d3_interpolateNumber;
  5106. function d3_interpolateNumber(a, b) {
  5107. b -= a = +a;
  5108. return function(t) {
  5109. return a + b * t;
  5110. };
  5111. }
  5112. d3.interpolateString = d3_interpolateString;
  5113. function d3_interpolateString(a, b) {
  5114. var m, i, j, s0 = 0, s1 = 0, s = [], q = [], n, o;
  5115. a = a + "", b = b + "";
  5116. d3_interpolate_number.lastIndex = 0;
  5117. for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
  5118. if (m.index) s.push(b.substring(s0, s1 = m.index));
  5119. q.push({
  5120. i: s.length,
  5121. x: m[0]
  5122. });
  5123. s.push(null);
  5124. s0 = d3_interpolate_number.lastIndex;
  5125. }
  5126. if (s0 < b.length) s.push(b.substring(s0));
  5127. for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
  5128. o = q[i];
  5129. if (o.x == m[0]) {
  5130. if (o.i) {
  5131. if (s[o.i + 1] == null) {
  5132. s[o.i - 1] += o.x;
  5133. s.splice(o.i, 1);
  5134. for (j = i + 1; j < n; ++j) q[j].i--;
  5135. } else {
  5136. s[o.i - 1] += o.x + s[o.i + 1];
  5137. s.splice(o.i, 2);
  5138. for (j = i + 1; j < n; ++j) q[j].i -= 2;
  5139. }
  5140. } else {
  5141. if (s[o.i + 1] == null) {
  5142. s[o.i] = o.x;
  5143. } else {
  5144. s[o.i] = o.x + s[o.i + 1];
  5145. s.splice(o.i + 1, 1);
  5146. for (j = i + 1; j < n; ++j) q[j].i--;
  5147. }
  5148. }
  5149. q.splice(i, 1);
  5150. n--;
  5151. i--;
  5152. } else {
  5153. o.x = d3_interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
  5154. }
  5155. }
  5156. while (i < n) {
  5157. o = q.pop();
  5158. if (s[o.i + 1] == null) {
  5159. s[o.i] = o.x;
  5160. } else {
  5161. s[o.i] = o.x + s[o.i + 1];
  5162. s.splice(o.i + 1, 1);
  5163. }
  5164. n--;
  5165. }
  5166. if (s.length === 1) {
  5167. return s[0] == null ? (o = q[0].x, function(t) {
  5168. return o(t) + "";
  5169. }) : function() {
  5170. return b;
  5171. };
  5172. }
  5173. return function(t) {
  5174. for (i = 0; i < n; ++i) s[(o = q[i]).i] = o.x(t);
  5175. return s.join("");
  5176. };
  5177. }
  5178. var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
  5179. d3.interpolate = d3_interpolate;
  5180. function d3_interpolate(a, b) {
  5181. var i = d3.interpolators.length, f;
  5182. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  5183. return f;
  5184. }
  5185. d3.interpolators = [ function(a, b) {
  5186. var t = typeof b;
  5187. return (t === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_Color ? d3_interpolateRgb : t === "object" ? Array.isArray(b) ? d3_interpolateArray : d3_interpolateObject : d3_interpolateNumber)(a, b);
  5188. } ];
  5189. d3.interpolateArray = d3_interpolateArray;
  5190. function d3_interpolateArray(a, b) {
  5191. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  5192. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  5193. for (;i < na; ++i) c[i] = a[i];
  5194. for (;i < nb; ++i) c[i] = b[i];
  5195. return function(t) {
  5196. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  5197. return c;
  5198. };
  5199. }
  5200. var d3_ease_default = function() {
  5201. return d3_identity;
  5202. };
  5203. var d3_ease = d3.map({
  5204. linear: d3_ease_default,
  5205. poly: d3_ease_poly,
  5206. quad: function() {
  5207. return d3_ease_quad;
  5208. },
  5209. cubic: function() {
  5210. return d3_ease_cubic;
  5211. },
  5212. sin: function() {
  5213. return d3_ease_sin;
  5214. },
  5215. exp: function() {
  5216. return d3_ease_exp;
  5217. },
  5218. circle: function() {
  5219. return d3_ease_circle;
  5220. },
  5221. elastic: d3_ease_elastic,
  5222. back: d3_ease_back,
  5223. bounce: function() {
  5224. return d3_ease_bounce;
  5225. }
  5226. });
  5227. var d3_ease_mode = d3.map({
  5228. "in": d3_identity,
  5229. out: d3_ease_reverse,
  5230. "in-out": d3_ease_reflect,
  5231. "out-in": function(f) {
  5232. return d3_ease_reflect(d3_ease_reverse(f));
  5233. }
  5234. });
  5235. d3.ease = function(name) {
  5236. var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
  5237. t = d3_ease.get(t) || d3_ease_default;
  5238. m = d3_ease_mode.get(m) || d3_identity;
  5239. return d3_ease_clamp(m(t.apply(null, Array.prototype.slice.call(arguments, 1))));
  5240. };
  5241. function d3_ease_clamp(f) {
  5242. return function(t) {
  5243. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  5244. };
  5245. }
  5246. function d3_ease_reverse(f) {
  5247. return function(t) {
  5248. return 1 - f(1 - t);
  5249. };
  5250. }
  5251. function d3_ease_reflect(f) {
  5252. return function(t) {
  5253. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  5254. };
  5255. }
  5256. function d3_ease_quad(t) {
  5257. return t * t;
  5258. }
  5259. function d3_ease_cubic(t) {
  5260. return t * t * t;
  5261. }
  5262. function d3_ease_cubicInOut(t) {
  5263. if (t <= 0) return 0;
  5264. if (t >= 1) return 1;
  5265. var t2 = t * t, t3 = t2 * t;
  5266. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  5267. }
  5268. function d3_ease_poly(e) {
  5269. return function(t) {
  5270. return Math.pow(t, e);
  5271. };
  5272. }
  5273. function d3_ease_sin(t) {
  5274. return 1 - Math.cos(t * halfπ);
  5275. }
  5276. function d3_ease_exp(t) {
  5277. return Math.pow(2, 10 * (t - 1));
  5278. }
  5279. function d3_ease_circle(t) {
  5280. return 1 - Math.sqrt(1 - t * t);
  5281. }
  5282. function d3_ease_elastic(a, p) {
  5283. var s;
  5284. if (arguments.length < 2) p = .45;
  5285. if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
  5286. return function(t) {
  5287. return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
  5288. };
  5289. }
  5290. function d3_ease_back(s) {
  5291. if (!s) s = 1.70158;
  5292. return function(t) {
  5293. return t * t * ((s + 1) * t - s);
  5294. };
  5295. }
  5296. function d3_ease_bounce(t) {
  5297. 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;
  5298. }
  5299. d3.interpolateHcl = d3_interpolateHcl;
  5300. function d3_interpolateHcl(a, b) {
  5301. a = d3.hcl(a);
  5302. b = d3.hcl(b);
  5303. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  5304. if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
  5305. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5306. return function(t) {
  5307. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  5308. };
  5309. }
  5310. d3.interpolateHsl = d3_interpolateHsl;
  5311. function d3_interpolateHsl(a, b) {
  5312. a = d3.hsl(a);
  5313. b = d3.hsl(b);
  5314. var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
  5315. if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
  5316. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5317. return function(t) {
  5318. return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
  5319. };
  5320. }
  5321. d3.interpolateLab = d3_interpolateLab;
  5322. function d3_interpolateLab(a, b) {
  5323. a = d3.lab(a);
  5324. b = d3.lab(b);
  5325. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  5326. return function(t) {
  5327. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  5328. };
  5329. }
  5330. d3.interpolateRound = d3_interpolateRound;
  5331. function d3_interpolateRound(a, b) {
  5332. b -= a;
  5333. return function(t) {
  5334. return Math.round(a + b * t);
  5335. };
  5336. }
  5337. d3.transform = function(string) {
  5338. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  5339. return (d3.transform = function(string) {
  5340. if (string != null) {
  5341. g.setAttribute("transform", string);
  5342. var t = g.transform.baseVal.consolidate();
  5343. }
  5344. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  5345. })(string);
  5346. };
  5347. function d3_transform(m) {
  5348. 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;
  5349. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  5350. r0[0] *= -1;
  5351. r0[1] *= -1;
  5352. kx *= -1;
  5353. kz *= -1;
  5354. }
  5355. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  5356. this.translate = [ m.e, m.f ];
  5357. this.scale = [ kx, ky ];
  5358. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  5359. }
  5360. d3_transform.prototype.toString = function() {
  5361. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  5362. };
  5363. function d3_transformDot(a, b) {
  5364. return a[0] * b[0] + a[1] * b[1];
  5365. }
  5366. function d3_transformNormalize(a) {
  5367. var k = Math.sqrt(d3_transformDot(a, a));
  5368. if (k) {
  5369. a[0] /= k;
  5370. a[1] /= k;
  5371. }
  5372. return k;
  5373. }
  5374. function d3_transformCombine(a, b, k) {
  5375. a[0] += k * b[0];
  5376. a[1] += k * b[1];
  5377. return a;
  5378. }
  5379. var d3_transformIdentity = {
  5380. a: 1,
  5381. b: 0,
  5382. c: 0,
  5383. d: 1,
  5384. e: 0,
  5385. f: 0
  5386. };
  5387. d3.interpolateTransform = d3_interpolateTransform;
  5388. function d3_interpolateTransform(a, b) {
  5389. var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
  5390. if (ta[0] != tb[0] || ta[1] != tb[1]) {
  5391. s.push("translate(", null, ",", null, ")");
  5392. q.push({
  5393. i: 1,
  5394. x: d3_interpolateNumber(ta[0], tb[0])
  5395. }, {
  5396. i: 3,
  5397. x: d3_interpolateNumber(ta[1], tb[1])
  5398. });
  5399. } else if (tb[0] || tb[1]) {
  5400. s.push("translate(" + tb + ")");
  5401. } else {
  5402. s.push("");
  5403. }
  5404. if (ra != rb) {
  5405. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  5406. q.push({
  5407. i: s.push(s.pop() + "rotate(", null, ")") - 2,
  5408. x: d3_interpolateNumber(ra, rb)
  5409. });
  5410. } else if (rb) {
  5411. s.push(s.pop() + "rotate(" + rb + ")");
  5412. }
  5413. if (wa != wb) {
  5414. q.push({
  5415. i: s.push(s.pop() + "skewX(", null, ")") - 2,
  5416. x: d3_interpolateNumber(wa, wb)
  5417. });
  5418. } else if (wb) {
  5419. s.push(s.pop() + "skewX(" + wb + ")");
  5420. }
  5421. if (ka[0] != kb[0] || ka[1] != kb[1]) {
  5422. n = s.push(s.pop() + "scale(", null, ",", null, ")");
  5423. q.push({
  5424. i: n - 4,
  5425. x: d3_interpolateNumber(ka[0], kb[0])
  5426. }, {
  5427. i: n - 2,
  5428. x: d3_interpolateNumber(ka[1], kb[1])
  5429. });
  5430. } else if (kb[0] != 1 || kb[1] != 1) {
  5431. s.push(s.pop() + "scale(" + kb + ")");
  5432. }
  5433. n = q.length;
  5434. return function(t) {
  5435. var i = -1, o;
  5436. while (++i < n) s[(o = q[i]).i] = o.x(t);
  5437. return s.join("");
  5438. };
  5439. }
  5440. function d3_uninterpolateNumber(a, b) {
  5441. b = b - (a = +a) ? 1 / (b - a) : 0;
  5442. return function(x) {
  5443. return (x - a) * b;
  5444. };
  5445. }
  5446. function d3_uninterpolateClamp(a, b) {
  5447. b = b - (a = +a) ? 1 / (b - a) : 0;
  5448. return function(x) {
  5449. return Math.max(0, Math.min(1, (x - a) * b));
  5450. };
  5451. }
  5452. d3.layout = {};
  5453. d3.layout.bundle = function() {
  5454. return function(links) {
  5455. var paths = [], i = -1, n = links.length;
  5456. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  5457. return paths;
  5458. };
  5459. };
  5460. function d3_layout_bundlePath(link) {
  5461. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  5462. while (start !== lca) {
  5463. start = start.parent;
  5464. points.push(start);
  5465. }
  5466. var k = points.length;
  5467. while (end !== lca) {
  5468. points.splice(k, 0, end);
  5469. end = end.parent;
  5470. }
  5471. return points;
  5472. }
  5473. function d3_layout_bundleAncestors(node) {
  5474. var ancestors = [], parent = node.parent;
  5475. while (parent != null) {
  5476. ancestors.push(node);
  5477. node = parent;
  5478. parent = parent.parent;
  5479. }
  5480. ancestors.push(node);
  5481. return ancestors;
  5482. }
  5483. function d3_layout_bundleLeastCommonAncestor(a, b) {
  5484. if (a === b) return a;
  5485. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  5486. while (aNode === bNode) {
  5487. sharedNode = aNode;
  5488. aNode = aNodes.pop();
  5489. bNode = bNodes.pop();
  5490. }
  5491. return sharedNode;
  5492. }
  5493. d3.layout.chord = function() {
  5494. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  5495. function relayout() {
  5496. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  5497. chords = [];
  5498. groups = [];
  5499. k = 0, i = -1;
  5500. while (++i < n) {
  5501. x = 0, j = -1;
  5502. while (++j < n) {
  5503. x += matrix[i][j];
  5504. }
  5505. groupSums.push(x);
  5506. subgroupIndex.push(d3.range(n));
  5507. k += x;
  5508. }
  5509. if (sortGroups) {
  5510. groupIndex.sort(function(a, b) {
  5511. return sortGroups(groupSums[a], groupSums[b]);
  5512. });
  5513. }
  5514. if (sortSubgroups) {
  5515. subgroupIndex.forEach(function(d, i) {
  5516. d.sort(function(a, b) {
  5517. return sortSubgroups(matrix[i][a], matrix[i][b]);
  5518. });
  5519. });
  5520. }
  5521. k = (τ - padding * n) / k;
  5522. x = 0, i = -1;
  5523. while (++i < n) {
  5524. x0 = x, j = -1;
  5525. while (++j < n) {
  5526. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  5527. subgroups[di + "-" + dj] = {
  5528. index: di,
  5529. subindex: dj,
  5530. startAngle: a0,
  5531. endAngle: a1,
  5532. value: v
  5533. };
  5534. }
  5535. groups[di] = {
  5536. index: di,
  5537. startAngle: x0,
  5538. endAngle: x,
  5539. value: (x - x0) / k
  5540. };
  5541. x += padding;
  5542. }
  5543. i = -1;
  5544. while (++i < n) {
  5545. j = i - 1;
  5546. while (++j < n) {
  5547. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  5548. if (source.value || target.value) {
  5549. chords.push(source.value < target.value ? {
  5550. source: target,
  5551. target: source
  5552. } : {
  5553. source: source,
  5554. target: target
  5555. });
  5556. }
  5557. }
  5558. }
  5559. if (sortChords) resort();
  5560. }
  5561. function resort() {
  5562. chords.sort(function(a, b) {
  5563. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  5564. });
  5565. }
  5566. chord.matrix = function(x) {
  5567. if (!arguments.length) return matrix;
  5568. n = (matrix = x) && matrix.length;
  5569. chords = groups = null;
  5570. return chord;
  5571. };
  5572. chord.padding = function(x) {
  5573. if (!arguments.length) return padding;
  5574. padding = x;
  5575. chords = groups = null;
  5576. return chord;
  5577. };
  5578. chord.sortGroups = function(x) {
  5579. if (!arguments.length) return sortGroups;
  5580. sortGroups = x;
  5581. chords = groups = null;
  5582. return chord;
  5583. };
  5584. chord.sortSubgroups = function(x) {
  5585. if (!arguments.length) return sortSubgroups;
  5586. sortSubgroups = x;
  5587. chords = null;
  5588. return chord;
  5589. };
  5590. chord.sortChords = function(x) {
  5591. if (!arguments.length) return sortChords;
  5592. sortChords = x;
  5593. if (chords) resort();
  5594. return chord;
  5595. };
  5596. chord.chords = function() {
  5597. if (!chords) relayout();
  5598. return chords;
  5599. };
  5600. chord.groups = function() {
  5601. if (!groups) relayout();
  5602. return groups;
  5603. };
  5604. return chord;
  5605. };
  5606. d3.layout.force = function() {
  5607. var force = {}, event = d3.dispatch("start", "tick", "end"), size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, gravity = .1, theta = .8, nodes = [], links = [], distances, strengths, charges;
  5608. function repulse(node) {
  5609. return function(quad, x1, _, x2) {
  5610. if (quad.point !== node) {
  5611. var dx = quad.cx - node.x, dy = quad.cy - node.y, dn = 1 / Math.sqrt(dx * dx + dy * dy);
  5612. if ((x2 - x1) * dn < theta) {
  5613. var k = quad.charge * dn * dn;
  5614. node.px -= dx * k;
  5615. node.py -= dy * k;
  5616. return true;
  5617. }
  5618. if (quad.point && isFinite(dn)) {
  5619. var k = quad.pointCharge * dn * dn;
  5620. node.px -= dx * k;
  5621. node.py -= dy * k;
  5622. }
  5623. }
  5624. return !quad.charge;
  5625. };
  5626. }
  5627. force.tick = function() {
  5628. if ((alpha *= .99) < .005) {
  5629. event.end({
  5630. type: "end",
  5631. alpha: alpha = 0
  5632. });
  5633. return true;
  5634. }
  5635. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  5636. for (i = 0; i < m; ++i) {
  5637. o = links[i];
  5638. s = o.source;
  5639. t = o.target;
  5640. x = t.x - s.x;
  5641. y = t.y - s.y;
  5642. if (l = x * x + y * y) {
  5643. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  5644. x *= l;
  5645. y *= l;
  5646. t.x -= x * (k = s.weight / (t.weight + s.weight));
  5647. t.y -= y * k;
  5648. s.x += x * (k = 1 - k);
  5649. s.y += y * k;
  5650. }
  5651. }
  5652. if (k = alpha * gravity) {
  5653. x = size[0] / 2;
  5654. y = size[1] / 2;
  5655. i = -1;
  5656. if (k) while (++i < n) {
  5657. o = nodes[i];
  5658. o.x += (x - o.x) * k;
  5659. o.y += (y - o.y) * k;
  5660. }
  5661. }
  5662. if (charge) {
  5663. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  5664. i = -1;
  5665. while (++i < n) {
  5666. if (!(o = nodes[i]).fixed) {
  5667. q.visit(repulse(o));
  5668. }
  5669. }
  5670. }
  5671. i = -1;
  5672. while (++i < n) {
  5673. o = nodes[i];
  5674. if (o.fixed) {
  5675. o.x = o.px;
  5676. o.y = o.py;
  5677. } else {
  5678. o.x -= (o.px - (o.px = o.x)) * friction;
  5679. o.y -= (o.py - (o.py = o.y)) * friction;
  5680. }
  5681. }
  5682. event.tick({
  5683. type: "tick",
  5684. alpha: alpha
  5685. });
  5686. };
  5687. force.nodes = function(x) {
  5688. if (!arguments.length) return nodes;
  5689. nodes = x;
  5690. return force;
  5691. };
  5692. force.links = function(x) {
  5693. if (!arguments.length) return links;
  5694. links = x;
  5695. return force;
  5696. };
  5697. force.size = function(x) {
  5698. if (!arguments.length) return size;
  5699. size = x;
  5700. return force;
  5701. };
  5702. force.linkDistance = function(x) {
  5703. if (!arguments.length) return linkDistance;
  5704. linkDistance = typeof x === "function" ? x : +x;
  5705. return force;
  5706. };
  5707. force.distance = force.linkDistance;
  5708. force.linkStrength = function(x) {
  5709. if (!arguments.length) return linkStrength;
  5710. linkStrength = typeof x === "function" ? x : +x;
  5711. return force;
  5712. };
  5713. force.friction = function(x) {
  5714. if (!arguments.length) return friction;
  5715. friction = +x;
  5716. return force;
  5717. };
  5718. force.charge = function(x) {
  5719. if (!arguments.length) return charge;
  5720. charge = typeof x === "function" ? x : +x;
  5721. return force;
  5722. };
  5723. force.gravity = function(x) {
  5724. if (!arguments.length) return gravity;
  5725. gravity = +x;
  5726. return force;
  5727. };
  5728. force.theta = function(x) {
  5729. if (!arguments.length) return theta;
  5730. theta = +x;
  5731. return force;
  5732. };
  5733. force.alpha = function(x) {
  5734. if (!arguments.length) return alpha;
  5735. x = +x;
  5736. if (alpha) {
  5737. if (x > 0) alpha = x; else alpha = 0;
  5738. } else if (x > 0) {
  5739. event.start({
  5740. type: "start",
  5741. alpha: alpha = x
  5742. });
  5743. d3.timer(force.tick);
  5744. }
  5745. return force;
  5746. };
  5747. force.start = function() {
  5748. var i, j, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  5749. for (i = 0; i < n; ++i) {
  5750. (o = nodes[i]).index = i;
  5751. o.weight = 0;
  5752. }
  5753. for (i = 0; i < m; ++i) {
  5754. o = links[i];
  5755. if (typeof o.source == "number") o.source = nodes[o.source];
  5756. if (typeof o.target == "number") o.target = nodes[o.target];
  5757. ++o.source.weight;
  5758. ++o.target.weight;
  5759. }
  5760. for (i = 0; i < n; ++i) {
  5761. o = nodes[i];
  5762. if (isNaN(o.x)) o.x = position("x", w);
  5763. if (isNaN(o.y)) o.y = position("y", h);
  5764. if (isNaN(o.px)) o.px = o.x;
  5765. if (isNaN(o.py)) o.py = o.y;
  5766. }
  5767. distances = [];
  5768. 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;
  5769. strengths = [];
  5770. 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;
  5771. charges = [];
  5772. 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;
  5773. function position(dimension, size) {
  5774. var neighbors = neighbor(i), j = -1, m = neighbors.length, x;
  5775. while (++j < m) if (!isNaN(x = neighbors[j][dimension])) return x;
  5776. return Math.random() * size;
  5777. }
  5778. function neighbor() {
  5779. if (!neighbors) {
  5780. neighbors = [];
  5781. for (j = 0; j < n; ++j) {
  5782. neighbors[j] = [];
  5783. }
  5784. for (j = 0; j < m; ++j) {
  5785. var o = links[j];
  5786. neighbors[o.source.index].push(o.target);
  5787. neighbors[o.target.index].push(o.source);
  5788. }
  5789. }
  5790. return neighbors[i];
  5791. }
  5792. return force.resume();
  5793. };
  5794. force.resume = function() {
  5795. return force.alpha(.1);
  5796. };
  5797. force.stop = function() {
  5798. return force.alpha(0);
  5799. };
  5800. force.drag = function() {
  5801. 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);
  5802. if (!arguments.length) return drag;
  5803. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  5804. };
  5805. function dragmove(d) {
  5806. d.px = d3.event.x, d.py = d3.event.y;
  5807. force.resume();
  5808. }
  5809. return d3.rebind(force, event, "on");
  5810. };
  5811. function d3_layout_forceDragstart(d) {
  5812. d.fixed |= 2;
  5813. }
  5814. function d3_layout_forceDragend(d) {
  5815. d.fixed &= ~6;
  5816. }
  5817. function d3_layout_forceMouseover(d) {
  5818. d.fixed |= 4;
  5819. d.px = d.x, d.py = d.y;
  5820. }
  5821. function d3_layout_forceMouseout(d) {
  5822. d.fixed &= ~4;
  5823. }
  5824. function d3_layout_forceAccumulate(quad, alpha, charges) {
  5825. var cx = 0, cy = 0;
  5826. quad.charge = 0;
  5827. if (!quad.leaf) {
  5828. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  5829. while (++i < n) {
  5830. c = nodes[i];
  5831. if (c == null) continue;
  5832. d3_layout_forceAccumulate(c, alpha, charges);
  5833. quad.charge += c.charge;
  5834. cx += c.charge * c.cx;
  5835. cy += c.charge * c.cy;
  5836. }
  5837. }
  5838. if (quad.point) {
  5839. if (!quad.leaf) {
  5840. quad.point.x += Math.random() - .5;
  5841. quad.point.y += Math.random() - .5;
  5842. }
  5843. var k = alpha * charges[quad.point.index];
  5844. quad.charge += quad.pointCharge = k;
  5845. cx += k * quad.point.x;
  5846. cy += k * quad.point.y;
  5847. }
  5848. quad.cx = cx / quad.charge;
  5849. quad.cy = cy / quad.charge;
  5850. }
  5851. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1;
  5852. d3.layout.hierarchy = function() {
  5853. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  5854. function recurse(node, depth, nodes) {
  5855. var childs = children.call(hierarchy, node, depth);
  5856. node.depth = depth;
  5857. nodes.push(node);
  5858. if (childs && (n = childs.length)) {
  5859. var i = -1, n, c = node.children = [], v = 0, j = depth + 1, d;
  5860. while (++i < n) {
  5861. d = recurse(childs[i], j, nodes);
  5862. d.parent = node;
  5863. c.push(d);
  5864. v += d.value;
  5865. }
  5866. if (sort) c.sort(sort);
  5867. if (value) node.value = v;
  5868. } else if (value) {
  5869. node.value = +value.call(hierarchy, node, depth) || 0;
  5870. }
  5871. return node;
  5872. }
  5873. function revalue(node, depth) {
  5874. var children = node.children, v = 0;
  5875. if (children && (n = children.length)) {
  5876. var i = -1, n, j = depth + 1;
  5877. while (++i < n) v += revalue(children[i], j);
  5878. } else if (value) {
  5879. v = +value.call(hierarchy, node, depth) || 0;
  5880. }
  5881. if (value) node.value = v;
  5882. return v;
  5883. }
  5884. function hierarchy(d) {
  5885. var nodes = [];
  5886. recurse(d, 0, nodes);
  5887. return nodes;
  5888. }
  5889. hierarchy.sort = function(x) {
  5890. if (!arguments.length) return sort;
  5891. sort = x;
  5892. return hierarchy;
  5893. };
  5894. hierarchy.children = function(x) {
  5895. if (!arguments.length) return children;
  5896. children = x;
  5897. return hierarchy;
  5898. };
  5899. hierarchy.value = function(x) {
  5900. if (!arguments.length) return value;
  5901. value = x;
  5902. return hierarchy;
  5903. };
  5904. hierarchy.revalue = function(root) {
  5905. revalue(root, 0);
  5906. return root;
  5907. };
  5908. return hierarchy;
  5909. };
  5910. function d3_layout_hierarchyRebind(object, hierarchy) {
  5911. d3.rebind(object, hierarchy, "sort", "children", "value");
  5912. object.nodes = object;
  5913. object.links = d3_layout_hierarchyLinks;
  5914. return object;
  5915. }
  5916. function d3_layout_hierarchyChildren(d) {
  5917. return d.children;
  5918. }
  5919. function d3_layout_hierarchyValue(d) {
  5920. return d.value;
  5921. }
  5922. function d3_layout_hierarchySort(a, b) {
  5923. return b.value - a.value;
  5924. }
  5925. function d3_layout_hierarchyLinks(nodes) {
  5926. return d3.merge(nodes.map(function(parent) {
  5927. return (parent.children || []).map(function(child) {
  5928. return {
  5929. source: parent,
  5930. target: child
  5931. };
  5932. });
  5933. }));
  5934. }
  5935. d3.layout.partition = function() {
  5936. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  5937. function position(node, x, dx, dy) {
  5938. var children = node.children;
  5939. node.x = x;
  5940. node.y = node.depth * dy;
  5941. node.dx = dx;
  5942. node.dy = dy;
  5943. if (children && (n = children.length)) {
  5944. var i = -1, n, c, d;
  5945. dx = node.value ? dx / node.value : 0;
  5946. while (++i < n) {
  5947. position(c = children[i], x, d = c.value * dx, dy);
  5948. x += d;
  5949. }
  5950. }
  5951. }
  5952. function depth(node) {
  5953. var children = node.children, d = 0;
  5954. if (children && (n = children.length)) {
  5955. var i = -1, n;
  5956. while (++i < n) d = Math.max(d, depth(children[i]));
  5957. }
  5958. return 1 + d;
  5959. }
  5960. function partition(d, i) {
  5961. var nodes = hierarchy.call(this, d, i);
  5962. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  5963. return nodes;
  5964. }
  5965. partition.size = function(x) {
  5966. if (!arguments.length) return size;
  5967. size = x;
  5968. return partition;
  5969. };
  5970. return d3_layout_hierarchyRebind(partition, hierarchy);
  5971. };
  5972. d3.layout.pie = function() {
  5973. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ;
  5974. function pie(data) {
  5975. var values = data.map(function(d, i) {
  5976. return +value.call(pie, d, i);
  5977. });
  5978. var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
  5979. var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a) / d3.sum(values);
  5980. var index = d3.range(data.length);
  5981. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  5982. return values[j] - values[i];
  5983. } : function(i, j) {
  5984. return sort(data[i], data[j]);
  5985. });
  5986. var arcs = [];
  5987. index.forEach(function(i) {
  5988. var d;
  5989. arcs[i] = {
  5990. data: data[i],
  5991. value: d = values[i],
  5992. startAngle: a,
  5993. endAngle: a += d * k
  5994. };
  5995. });
  5996. return arcs;
  5997. }
  5998. pie.value = function(x) {
  5999. if (!arguments.length) return value;
  6000. value = x;
  6001. return pie;
  6002. };
  6003. pie.sort = function(x) {
  6004. if (!arguments.length) return sort;
  6005. sort = x;
  6006. return pie;
  6007. };
  6008. pie.startAngle = function(x) {
  6009. if (!arguments.length) return startAngle;
  6010. startAngle = x;
  6011. return pie;
  6012. };
  6013. pie.endAngle = function(x) {
  6014. if (!arguments.length) return endAngle;
  6015. endAngle = x;
  6016. return pie;
  6017. };
  6018. return pie;
  6019. };
  6020. var d3_layout_pieSortByValue = {};
  6021. d3.layout.stack = function() {
  6022. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  6023. function stack(data, index) {
  6024. var series = data.map(function(d, i) {
  6025. return values.call(stack, d, i);
  6026. });
  6027. var points = series.map(function(d) {
  6028. return d.map(function(v, i) {
  6029. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  6030. });
  6031. });
  6032. var orders = order.call(stack, points, index);
  6033. series = d3.permute(series, orders);
  6034. points = d3.permute(points, orders);
  6035. var offsets = offset.call(stack, points, index);
  6036. var n = series.length, m = series[0].length, i, j, o;
  6037. for (j = 0; j < m; ++j) {
  6038. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  6039. for (i = 1; i < n; ++i) {
  6040. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  6041. }
  6042. }
  6043. return data;
  6044. }
  6045. stack.values = function(x) {
  6046. if (!arguments.length) return values;
  6047. values = x;
  6048. return stack;
  6049. };
  6050. stack.order = function(x) {
  6051. if (!arguments.length) return order;
  6052. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  6053. return stack;
  6054. };
  6055. stack.offset = function(x) {
  6056. if (!arguments.length) return offset;
  6057. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  6058. return stack;
  6059. };
  6060. stack.x = function(z) {
  6061. if (!arguments.length) return x;
  6062. x = z;
  6063. return stack;
  6064. };
  6065. stack.y = function(z) {
  6066. if (!arguments.length) return y;
  6067. y = z;
  6068. return stack;
  6069. };
  6070. stack.out = function(z) {
  6071. if (!arguments.length) return out;
  6072. out = z;
  6073. return stack;
  6074. };
  6075. return stack;
  6076. };
  6077. function d3_layout_stackX(d) {
  6078. return d.x;
  6079. }
  6080. function d3_layout_stackY(d) {
  6081. return d.y;
  6082. }
  6083. function d3_layout_stackOut(d, y0, y) {
  6084. d.y0 = y0;
  6085. d.y = y;
  6086. }
  6087. var d3_layout_stackOrders = d3.map({
  6088. "inside-out": function(data) {
  6089. 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) {
  6090. return max[a] - max[b];
  6091. }), top = 0, bottom = 0, tops = [], bottoms = [];
  6092. for (i = 0; i < n; ++i) {
  6093. j = index[i];
  6094. if (top < bottom) {
  6095. top += sums[j];
  6096. tops.push(j);
  6097. } else {
  6098. bottom += sums[j];
  6099. bottoms.push(j);
  6100. }
  6101. }
  6102. return bottoms.reverse().concat(tops);
  6103. },
  6104. reverse: function(data) {
  6105. return d3.range(data.length).reverse();
  6106. },
  6107. "default": d3_layout_stackOrderDefault
  6108. });
  6109. var d3_layout_stackOffsets = d3.map({
  6110. silhouette: function(data) {
  6111. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  6112. for (j = 0; j < m; ++j) {
  6113. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6114. if (o > max) max = o;
  6115. sums.push(o);
  6116. }
  6117. for (j = 0; j < m; ++j) {
  6118. y0[j] = (max - sums[j]) / 2;
  6119. }
  6120. return y0;
  6121. },
  6122. wiggle: function(data) {
  6123. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  6124. y0[0] = o = o0 = 0;
  6125. for (j = 1; j < m; ++j) {
  6126. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  6127. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  6128. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  6129. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  6130. }
  6131. s2 += s3 * data[i][j][1];
  6132. }
  6133. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  6134. if (o < o0) o0 = o;
  6135. }
  6136. for (j = 0; j < m; ++j) y0[j] -= o0;
  6137. return y0;
  6138. },
  6139. expand: function(data) {
  6140. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  6141. for (j = 0; j < m; ++j) {
  6142. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6143. 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;
  6144. }
  6145. for (j = 0; j < m; ++j) y0[j] = 0;
  6146. return y0;
  6147. },
  6148. zero: d3_layout_stackOffsetZero
  6149. });
  6150. function d3_layout_stackOrderDefault(data) {
  6151. return d3.range(data.length);
  6152. }
  6153. function d3_layout_stackOffsetZero(data) {
  6154. var j = -1, m = data[0].length, y0 = [];
  6155. while (++j < m) y0[j] = 0;
  6156. return y0;
  6157. }
  6158. function d3_layout_stackMaxIndex(array) {
  6159. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  6160. for (;i < n; ++i) {
  6161. if ((k = array[i][1]) > v) {
  6162. j = i;
  6163. v = k;
  6164. }
  6165. }
  6166. return j;
  6167. }
  6168. function d3_layout_stackReduceSum(d) {
  6169. return d.reduce(d3_layout_stackSum, 0);
  6170. }
  6171. function d3_layout_stackSum(p, d) {
  6172. return p + d[1];
  6173. }
  6174. d3.layout.histogram = function() {
  6175. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  6176. function histogram(data, i) {
  6177. 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;
  6178. while (++i < m) {
  6179. bin = bins[i] = [];
  6180. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  6181. bin.y = 0;
  6182. }
  6183. if (m > 0) {
  6184. i = -1;
  6185. while (++i < n) {
  6186. x = values[i];
  6187. if (x >= range[0] && x <= range[1]) {
  6188. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  6189. bin.y += k;
  6190. bin.push(data[i]);
  6191. }
  6192. }
  6193. }
  6194. return bins;
  6195. }
  6196. histogram.value = function(x) {
  6197. if (!arguments.length) return valuer;
  6198. valuer = x;
  6199. return histogram;
  6200. };
  6201. histogram.range = function(x) {
  6202. if (!arguments.length) return ranger;
  6203. ranger = d3_functor(x);
  6204. return histogram;
  6205. };
  6206. histogram.bins = function(x) {
  6207. if (!arguments.length) return binner;
  6208. binner = typeof x === "number" ? function(range) {
  6209. return d3_layout_histogramBinFixed(range, x);
  6210. } : d3_functor(x);
  6211. return histogram;
  6212. };
  6213. histogram.frequency = function(x) {
  6214. if (!arguments.length) return frequency;
  6215. frequency = !!x;
  6216. return histogram;
  6217. };
  6218. return histogram;
  6219. };
  6220. function d3_layout_histogramBinSturges(range, values) {
  6221. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  6222. }
  6223. function d3_layout_histogramBinFixed(range, n) {
  6224. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  6225. while (++x <= n) f[x] = m * x + b;
  6226. return f;
  6227. }
  6228. function d3_layout_histogramRange(values) {
  6229. return [ d3.min(values), d3.max(values) ];
  6230. }
  6231. d3.layout.tree = function() {
  6232. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  6233. function tree(d, i) {
  6234. var nodes = hierarchy.call(this, d, i), root = nodes[0];
  6235. function firstWalk(node, previousSibling) {
  6236. var children = node.children, layout = node._tree;
  6237. if (children && (n = children.length)) {
  6238. var n, firstChild = children[0], previousChild, ancestor = firstChild, child, i = -1;
  6239. while (++i < n) {
  6240. child = children[i];
  6241. firstWalk(child, previousChild);
  6242. ancestor = apportion(child, previousChild, ancestor);
  6243. previousChild = child;
  6244. }
  6245. d3_layout_treeShift(node);
  6246. var midpoint = .5 * (firstChild._tree.prelim + child._tree.prelim);
  6247. if (previousSibling) {
  6248. layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
  6249. layout.mod = layout.prelim - midpoint;
  6250. } else {
  6251. layout.prelim = midpoint;
  6252. }
  6253. } else {
  6254. if (previousSibling) {
  6255. layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
  6256. }
  6257. }
  6258. }
  6259. function secondWalk(node, x) {
  6260. node.x = node._tree.prelim + x;
  6261. var children = node.children;
  6262. if (children && (n = children.length)) {
  6263. var i = -1, n;
  6264. x += node._tree.mod;
  6265. while (++i < n) {
  6266. secondWalk(children[i], x);
  6267. }
  6268. }
  6269. }
  6270. function apportion(node, previousSibling, ancestor) {
  6271. if (previousSibling) {
  6272. var vip = node, vop = node, vim = previousSibling, vom = node.parent.children[0], sip = vip._tree.mod, sop = vop._tree.mod, sim = vim._tree.mod, som = vom._tree.mod, shift;
  6273. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  6274. vom = d3_layout_treeLeft(vom);
  6275. vop = d3_layout_treeRight(vop);
  6276. vop._tree.ancestor = node;
  6277. shift = vim._tree.prelim + sim - vip._tree.prelim - sip + separation(vim, vip);
  6278. if (shift > 0) {
  6279. d3_layout_treeMove(d3_layout_treeAncestor(vim, node, ancestor), node, shift);
  6280. sip += shift;
  6281. sop += shift;
  6282. }
  6283. sim += vim._tree.mod;
  6284. sip += vip._tree.mod;
  6285. som += vom._tree.mod;
  6286. sop += vop._tree.mod;
  6287. }
  6288. if (vim && !d3_layout_treeRight(vop)) {
  6289. vop._tree.thread = vim;
  6290. vop._tree.mod += sim - sop;
  6291. }
  6292. if (vip && !d3_layout_treeLeft(vom)) {
  6293. vom._tree.thread = vip;
  6294. vom._tree.mod += sip - som;
  6295. ancestor = node;
  6296. }
  6297. }
  6298. return ancestor;
  6299. }
  6300. d3_layout_treeVisitAfter(root, function(node, previousSibling) {
  6301. node._tree = {
  6302. ancestor: node,
  6303. prelim: 0,
  6304. mod: 0,
  6305. change: 0,
  6306. shift: 0,
  6307. number: previousSibling ? previousSibling._tree.number + 1 : 0
  6308. };
  6309. });
  6310. firstWalk(root);
  6311. secondWalk(root, -root._tree.prelim);
  6312. var left = d3_layout_treeSearch(root, d3_layout_treeLeftmost), right = d3_layout_treeSearch(root, d3_layout_treeRightmost), deep = d3_layout_treeSearch(root, d3_layout_treeDeepest), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2, y1 = deep.depth || 1;
  6313. d3_layout_treeVisitAfter(root, nodeSize ? function(node) {
  6314. node.x *= size[0];
  6315. node.y = node.depth * size[1];
  6316. delete node._tree;
  6317. } : function(node) {
  6318. node.x = (node.x - x0) / (x1 - x0) * size[0];
  6319. node.y = node.depth / y1 * size[1];
  6320. delete node._tree;
  6321. });
  6322. return nodes;
  6323. }
  6324. tree.separation = function(x) {
  6325. if (!arguments.length) return separation;
  6326. separation = x;
  6327. return tree;
  6328. };
  6329. tree.size = function(x) {
  6330. if (!arguments.length) return nodeSize ? null : size;
  6331. nodeSize = (size = x) == null;
  6332. return tree;
  6333. };
  6334. tree.nodeSize = function(x) {
  6335. if (!arguments.length) return nodeSize ? size : null;
  6336. nodeSize = (size = x) != null;
  6337. return tree;
  6338. };
  6339. return d3_layout_hierarchyRebind(tree, hierarchy);
  6340. };
  6341. function d3_layout_treeSeparation(a, b) {
  6342. return a.parent == b.parent ? 1 : 2;
  6343. }
  6344. function d3_layout_treeLeft(node) {
  6345. var children = node.children;
  6346. return children && children.length ? children[0] : node._tree.thread;
  6347. }
  6348. function d3_layout_treeRight(node) {
  6349. var children = node.children, n;
  6350. return children && (n = children.length) ? children[n - 1] : node._tree.thread;
  6351. }
  6352. function d3_layout_treeSearch(node, compare) {
  6353. var children = node.children;
  6354. if (children && (n = children.length)) {
  6355. var child, n, i = -1;
  6356. while (++i < n) {
  6357. if (compare(child = d3_layout_treeSearch(children[i], compare), node) > 0) {
  6358. node = child;
  6359. }
  6360. }
  6361. }
  6362. return node;
  6363. }
  6364. function d3_layout_treeRightmost(a, b) {
  6365. return a.x - b.x;
  6366. }
  6367. function d3_layout_treeLeftmost(a, b) {
  6368. return b.x - a.x;
  6369. }
  6370. function d3_layout_treeDeepest(a, b) {
  6371. return a.depth - b.depth;
  6372. }
  6373. function d3_layout_treeVisitAfter(node, callback) {
  6374. function visit(node, previousSibling) {
  6375. var children = node.children;
  6376. if (children && (n = children.length)) {
  6377. var child, previousChild = null, i = -1, n;
  6378. while (++i < n) {
  6379. child = children[i];
  6380. visit(child, previousChild);
  6381. previousChild = child;
  6382. }
  6383. }
  6384. callback(node, previousSibling);
  6385. }
  6386. visit(node, null);
  6387. }
  6388. function d3_layout_treeShift(node) {
  6389. var shift = 0, change = 0, children = node.children, i = children.length, child;
  6390. while (--i >= 0) {
  6391. child = children[i]._tree;
  6392. child.prelim += shift;
  6393. child.mod += shift;
  6394. shift += child.shift + (change += child.change);
  6395. }
  6396. }
  6397. function d3_layout_treeMove(ancestor, node, shift) {
  6398. ancestor = ancestor._tree;
  6399. node = node._tree;
  6400. var change = shift / (node.number - ancestor.number);
  6401. ancestor.change += change;
  6402. node.change -= change;
  6403. node.shift += shift;
  6404. node.prelim += shift;
  6405. node.mod += shift;
  6406. }
  6407. function d3_layout_treeAncestor(vim, node, ancestor) {
  6408. return vim._tree.ancestor.parent == node.parent ? vim._tree.ancestor : ancestor;
  6409. }
  6410. d3.layout.pack = function() {
  6411. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
  6412. function pack(d, i) {
  6413. 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() {
  6414. return radius;
  6415. };
  6416. root.x = root.y = 0;
  6417. d3_layout_treeVisitAfter(root, function(d) {
  6418. d.r = +r(d.value);
  6419. });
  6420. d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
  6421. if (padding) {
  6422. var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
  6423. d3_layout_treeVisitAfter(root, function(d) {
  6424. d.r += dr;
  6425. });
  6426. d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
  6427. d3_layout_treeVisitAfter(root, function(d) {
  6428. d.r -= dr;
  6429. });
  6430. }
  6431. d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
  6432. return nodes;
  6433. }
  6434. pack.size = function(_) {
  6435. if (!arguments.length) return size;
  6436. size = _;
  6437. return pack;
  6438. };
  6439. pack.radius = function(_) {
  6440. if (!arguments.length) return radius;
  6441. radius = _ == null || typeof _ === "function" ? _ : +_;
  6442. return pack;
  6443. };
  6444. pack.padding = function(_) {
  6445. if (!arguments.length) return padding;
  6446. padding = +_;
  6447. return pack;
  6448. };
  6449. return d3_layout_hierarchyRebind(pack, hierarchy);
  6450. };
  6451. function d3_layout_packSort(a, b) {
  6452. return a.value - b.value;
  6453. }
  6454. function d3_layout_packInsert(a, b) {
  6455. var c = a._pack_next;
  6456. a._pack_next = b;
  6457. b._pack_prev = a;
  6458. b._pack_next = c;
  6459. c._pack_prev = b;
  6460. }
  6461. function d3_layout_packSplice(a, b) {
  6462. a._pack_next = b;
  6463. b._pack_prev = a;
  6464. }
  6465. function d3_layout_packIntersects(a, b) {
  6466. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  6467. return .999 * dr * dr > dx * dx + dy * dy;
  6468. }
  6469. function d3_layout_packSiblings(node) {
  6470. if (!(nodes = node.children) || !(n = nodes.length)) return;
  6471. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  6472. function bound(node) {
  6473. xMin = Math.min(node.x - node.r, xMin);
  6474. xMax = Math.max(node.x + node.r, xMax);
  6475. yMin = Math.min(node.y - node.r, yMin);
  6476. yMax = Math.max(node.y + node.r, yMax);
  6477. }
  6478. nodes.forEach(d3_layout_packLink);
  6479. a = nodes[0];
  6480. a.x = -a.r;
  6481. a.y = 0;
  6482. bound(a);
  6483. if (n > 1) {
  6484. b = nodes[1];
  6485. b.x = b.r;
  6486. b.y = 0;
  6487. bound(b);
  6488. if (n > 2) {
  6489. c = nodes[2];
  6490. d3_layout_packPlace(a, b, c);
  6491. bound(c);
  6492. d3_layout_packInsert(a, c);
  6493. a._pack_prev = c;
  6494. d3_layout_packInsert(c, b);
  6495. b = a._pack_next;
  6496. for (i = 3; i < n; i++) {
  6497. d3_layout_packPlace(a, b, c = nodes[i]);
  6498. var isect = 0, s1 = 1, s2 = 1;
  6499. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  6500. if (d3_layout_packIntersects(j, c)) {
  6501. isect = 1;
  6502. break;
  6503. }
  6504. }
  6505. if (isect == 1) {
  6506. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  6507. if (d3_layout_packIntersects(k, c)) {
  6508. break;
  6509. }
  6510. }
  6511. }
  6512. if (isect) {
  6513. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  6514. i--;
  6515. } else {
  6516. d3_layout_packInsert(a, c);
  6517. b = c;
  6518. bound(c);
  6519. }
  6520. }
  6521. }
  6522. }
  6523. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  6524. for (i = 0; i < n; i++) {
  6525. c = nodes[i];
  6526. c.x -= cx;
  6527. c.y -= cy;
  6528. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  6529. }
  6530. node.r = cr;
  6531. nodes.forEach(d3_layout_packUnlink);
  6532. }
  6533. function d3_layout_packLink(node) {
  6534. node._pack_next = node._pack_prev = node;
  6535. }
  6536. function d3_layout_packUnlink(node) {
  6537. delete node._pack_next;
  6538. delete node._pack_prev;
  6539. }
  6540. function d3_layout_packTransform(node, x, y, k) {
  6541. var children = node.children;
  6542. node.x = x += k * node.x;
  6543. node.y = y += k * node.y;
  6544. node.r *= k;
  6545. if (children) {
  6546. var i = -1, n = children.length;
  6547. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  6548. }
  6549. }
  6550. function d3_layout_packPlace(a, b, c) {
  6551. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  6552. if (db && (dx || dy)) {
  6553. var da = b.r + c.r, dc = dx * dx + dy * dy;
  6554. da *= da;
  6555. db *= db;
  6556. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  6557. c.x = a.x + x * dx + y * dy;
  6558. c.y = a.y + x * dy - y * dx;
  6559. } else {
  6560. c.x = a.x + db;
  6561. c.y = a.y;
  6562. }
  6563. }
  6564. d3.layout.cluster = function() {
  6565. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  6566. function cluster(d, i) {
  6567. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  6568. d3_layout_treeVisitAfter(root, function(node) {
  6569. var children = node.children;
  6570. if (children && children.length) {
  6571. node.x = d3_layout_clusterX(children);
  6572. node.y = d3_layout_clusterY(children);
  6573. } else {
  6574. node.x = previousNode ? x += separation(node, previousNode) : 0;
  6575. node.y = 0;
  6576. previousNode = node;
  6577. }
  6578. });
  6579. 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;
  6580. d3_layout_treeVisitAfter(root, nodeSize ? function(node) {
  6581. node.x = (node.x - root.x) * size[0];
  6582. node.y = (root.y - node.y) * size[1];
  6583. } : function(node) {
  6584. node.x = (node.x - x0) / (x1 - x0) * size[0];
  6585. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  6586. });
  6587. return nodes;
  6588. }
  6589. cluster.separation = function(x) {
  6590. if (!arguments.length) return separation;
  6591. separation = x;
  6592. return cluster;
  6593. };
  6594. cluster.size = function(x) {
  6595. if (!arguments.length) return nodeSize ? null : size;
  6596. nodeSize = (size = x) == null;
  6597. return cluster;
  6598. };
  6599. cluster.nodeSize = function(x) {
  6600. if (!arguments.length) return nodeSize ? size : null;
  6601. nodeSize = (size = x) != null;
  6602. return cluster;
  6603. };
  6604. return d3_layout_hierarchyRebind(cluster, hierarchy);
  6605. };
  6606. function d3_layout_clusterY(children) {
  6607. return 1 + d3.max(children, function(child) {
  6608. return child.y;
  6609. });
  6610. }
  6611. function d3_layout_clusterX(children) {
  6612. return children.reduce(function(x, child) {
  6613. return x + child.x;
  6614. }, 0) / children.length;
  6615. }
  6616. function d3_layout_clusterLeft(node) {
  6617. var children = node.children;
  6618. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  6619. }
  6620. function d3_layout_clusterRight(node) {
  6621. var children = node.children, n;
  6622. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  6623. }
  6624. d3.layout.treemap = function() {
  6625. 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));
  6626. function scale(children, k) {
  6627. var i = -1, n = children.length, child, area;
  6628. while (++i < n) {
  6629. area = (child = children[i]).value * (k < 0 ? 0 : k);
  6630. child.area = isNaN(area) || area <= 0 ? 0 : area;
  6631. }
  6632. }
  6633. function squarify(node) {
  6634. var children = node.children;
  6635. if (children && children.length) {
  6636. 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;
  6637. scale(remaining, rect.dx * rect.dy / node.value);
  6638. row.area = 0;
  6639. while ((n = remaining.length) > 0) {
  6640. row.push(child = remaining[n - 1]);
  6641. row.area += child.area;
  6642. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  6643. remaining.pop();
  6644. best = score;
  6645. } else {
  6646. row.area -= row.pop().area;
  6647. position(row, u, rect, false);
  6648. u = Math.min(rect.dx, rect.dy);
  6649. row.length = row.area = 0;
  6650. best = Infinity;
  6651. }
  6652. }
  6653. if (row.length) {
  6654. position(row, u, rect, true);
  6655. row.length = row.area = 0;
  6656. }
  6657. children.forEach(squarify);
  6658. }
  6659. }
  6660. function stickify(node) {
  6661. var children = node.children;
  6662. if (children && children.length) {
  6663. var rect = pad(node), remaining = children.slice(), child, row = [];
  6664. scale(remaining, rect.dx * rect.dy / node.value);
  6665. row.area = 0;
  6666. while (child = remaining.pop()) {
  6667. row.push(child);
  6668. row.area += child.area;
  6669. if (child.z != null) {
  6670. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  6671. row.length = row.area = 0;
  6672. }
  6673. }
  6674. children.forEach(stickify);
  6675. }
  6676. }
  6677. function worst(row, u) {
  6678. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  6679. while (++i < n) {
  6680. if (!(r = row[i].area)) continue;
  6681. if (r < rmin) rmin = r;
  6682. if (r > rmax) rmax = r;
  6683. }
  6684. s *= s;
  6685. u *= u;
  6686. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  6687. }
  6688. function position(row, u, rect, flush) {
  6689. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  6690. if (u == rect.dx) {
  6691. if (flush || v > rect.dy) v = rect.dy;
  6692. while (++i < n) {
  6693. o = row[i];
  6694. o.x = x;
  6695. o.y = y;
  6696. o.dy = v;
  6697. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  6698. }
  6699. o.z = true;
  6700. o.dx += rect.x + rect.dx - x;
  6701. rect.y += v;
  6702. rect.dy -= v;
  6703. } else {
  6704. if (flush || v > rect.dx) v = rect.dx;
  6705. while (++i < n) {
  6706. o = row[i];
  6707. o.x = x;
  6708. o.y = y;
  6709. o.dx = v;
  6710. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  6711. }
  6712. o.z = false;
  6713. o.dy += rect.y + rect.dy - y;
  6714. rect.x += v;
  6715. rect.dx -= v;
  6716. }
  6717. }
  6718. function treemap(d) {
  6719. var nodes = stickies || hierarchy(d), root = nodes[0];
  6720. root.x = 0;
  6721. root.y = 0;
  6722. root.dx = size[0];
  6723. root.dy = size[1];
  6724. if (stickies) hierarchy.revalue(root);
  6725. scale([ root ], root.dx * root.dy / root.value);
  6726. (stickies ? stickify : squarify)(root);
  6727. if (sticky) stickies = nodes;
  6728. return nodes;
  6729. }
  6730. treemap.size = function(x) {
  6731. if (!arguments.length) return size;
  6732. size = x;
  6733. return treemap;
  6734. };
  6735. treemap.padding = function(x) {
  6736. if (!arguments.length) return padding;
  6737. function padFunction(node) {
  6738. var p = x.call(treemap, node, node.depth);
  6739. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  6740. }
  6741. function padConstant(node) {
  6742. return d3_layout_treemapPad(node, x);
  6743. }
  6744. var type;
  6745. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  6746. padConstant) : padConstant;
  6747. return treemap;
  6748. };
  6749. treemap.round = function(x) {
  6750. if (!arguments.length) return round != Number;
  6751. round = x ? Math.round : Number;
  6752. return treemap;
  6753. };
  6754. treemap.sticky = function(x) {
  6755. if (!arguments.length) return sticky;
  6756. sticky = x;
  6757. stickies = null;
  6758. return treemap;
  6759. };
  6760. treemap.ratio = function(x) {
  6761. if (!arguments.length) return ratio;
  6762. ratio = x;
  6763. return treemap;
  6764. };
  6765. treemap.mode = function(x) {
  6766. if (!arguments.length) return mode;
  6767. mode = x + "";
  6768. return treemap;
  6769. };
  6770. return d3_layout_hierarchyRebind(treemap, hierarchy);
  6771. };
  6772. function d3_layout_treemapPadNull(node) {
  6773. return {
  6774. x: node.x,
  6775. y: node.y,
  6776. dx: node.dx,
  6777. dy: node.dy
  6778. };
  6779. }
  6780. function d3_layout_treemapPad(node, padding) {
  6781. 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];
  6782. if (dx < 0) {
  6783. x += dx / 2;
  6784. dx = 0;
  6785. }
  6786. if (dy < 0) {
  6787. y += dy / 2;
  6788. dy = 0;
  6789. }
  6790. return {
  6791. x: x,
  6792. y: y,
  6793. dx: dx,
  6794. dy: dy
  6795. };
  6796. }
  6797. d3.random = {
  6798. normal: function(µ, σ) {
  6799. var n = arguments.length;
  6800. if (n < 2) σ = 1;
  6801. if (n < 1) µ = 0;
  6802. return function() {
  6803. var x, y, r;
  6804. do {
  6805. x = Math.random() * 2 - 1;
  6806. y = Math.random() * 2 - 1;
  6807. r = x * x + y * y;
  6808. } while (!r || r > 1);
  6809. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  6810. };
  6811. },
  6812. logNormal: function() {
  6813. var random = d3.random.normal.apply(d3, arguments);
  6814. return function() {
  6815. return Math.exp(random());
  6816. };
  6817. },
  6818. irwinHall: function(m) {
  6819. return function() {
  6820. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  6821. return s / m;
  6822. };
  6823. }
  6824. };
  6825. d3.scale = {};
  6826. function d3_scaleExtent(domain) {
  6827. var start = domain[0], stop = domain[domain.length - 1];
  6828. return start < stop ? [ start, stop ] : [ stop, start ];
  6829. }
  6830. function d3_scaleRange(scale) {
  6831. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  6832. }
  6833. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  6834. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  6835. return function(x) {
  6836. return i(u(x));
  6837. };
  6838. }
  6839. function d3_scale_nice(domain, nice) {
  6840. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  6841. if (x1 < x0) {
  6842. dx = i0, i0 = i1, i1 = dx;
  6843. dx = x0, x0 = x1, x1 = dx;
  6844. }
  6845. domain[i0] = nice.floor(x0);
  6846. domain[i1] = nice.ceil(x1);
  6847. return domain;
  6848. }
  6849. function d3_scale_niceStep(step) {
  6850. return step ? {
  6851. floor: function(x) {
  6852. return Math.floor(x / step) * step;
  6853. },
  6854. ceil: function(x) {
  6855. return Math.ceil(x / step) * step;
  6856. }
  6857. } : d3_scale_niceIdentity;
  6858. }
  6859. var d3_scale_niceIdentity = {
  6860. floor: d3_identity,
  6861. ceil: d3_identity
  6862. };
  6863. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  6864. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  6865. if (domain[k] < domain[0]) {
  6866. domain = domain.slice().reverse();
  6867. range = range.slice().reverse();
  6868. }
  6869. while (++j <= k) {
  6870. u.push(uninterpolate(domain[j - 1], domain[j]));
  6871. i.push(interpolate(range[j - 1], range[j]));
  6872. }
  6873. return function(x) {
  6874. var j = d3.bisect(domain, x, 1, k) - 1;
  6875. return i[j](u[j](x));
  6876. };
  6877. }
  6878. d3.scale.linear = function() {
  6879. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  6880. };
  6881. function d3_scale_linear(domain, range, interpolate, clamp) {
  6882. var output, input;
  6883. function rescale() {
  6884. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  6885. output = linear(domain, range, uninterpolate, interpolate);
  6886. input = linear(range, domain, uninterpolate, d3_interpolate);
  6887. return scale;
  6888. }
  6889. function scale(x) {
  6890. return output(x);
  6891. }
  6892. scale.invert = function(y) {
  6893. return input(y);
  6894. };
  6895. scale.domain = function(x) {
  6896. if (!arguments.length) return domain;
  6897. domain = x.map(Number);
  6898. return rescale();
  6899. };
  6900. scale.range = function(x) {
  6901. if (!arguments.length) return range;
  6902. range = x;
  6903. return rescale();
  6904. };
  6905. scale.rangeRound = function(x) {
  6906. return scale.range(x).interpolate(d3_interpolateRound);
  6907. };
  6908. scale.clamp = function(x) {
  6909. if (!arguments.length) return clamp;
  6910. clamp = x;
  6911. return rescale();
  6912. };
  6913. scale.interpolate = function(x) {
  6914. if (!arguments.length) return interpolate;
  6915. interpolate = x;
  6916. return rescale();
  6917. };
  6918. scale.ticks = function(m) {
  6919. return d3_scale_linearTicks(domain, m);
  6920. };
  6921. scale.tickFormat = function(m, format) {
  6922. return d3_scale_linearTickFormat(domain, m, format);
  6923. };
  6924. scale.nice = function(m) {
  6925. d3_scale_linearNice(domain, m);
  6926. return rescale();
  6927. };
  6928. scale.copy = function() {
  6929. return d3_scale_linear(domain, range, interpolate, clamp);
  6930. };
  6931. return rescale();
  6932. }
  6933. function d3_scale_linearRebind(scale, linear) {
  6934. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  6935. }
  6936. function d3_scale_linearNice(domain, m) {
  6937. return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  6938. }
  6939. function d3_scale_linearTickRange(domain, m) {
  6940. if (m == null) m = 10;
  6941. 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;
  6942. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  6943. extent[0] = Math.ceil(extent[0] / step) * step;
  6944. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  6945. extent[2] = step;
  6946. return extent;
  6947. }
  6948. function d3_scale_linearTicks(domain, m) {
  6949. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  6950. }
  6951. function d3_scale_linearTickFormat(domain, m, format) {
  6952. var precision = -Math.floor(Math.log(d3_scale_linearTickRange(domain, m)[2]) / Math.LN10 + .01);
  6953. return d3.format(format ? format.replace(d3_format_re, function(a, b, c, d, e, f, g, h, i, j) {
  6954. return [ b, c, d, e, f, g, h, i || "." + (precision - (j === "%") * 2), j ].join("");
  6955. }) : ",." + precision + "f");
  6956. }
  6957. d3.scale.log = function() {
  6958. return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
  6959. };
  6960. function d3_scale_log(linear, base, positive, domain) {
  6961. function log(x) {
  6962. return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
  6963. }
  6964. function pow(x) {
  6965. return positive ? Math.pow(base, x) : -Math.pow(base, -x);
  6966. }
  6967. function scale(x) {
  6968. return linear(log(x));
  6969. }
  6970. scale.invert = function(x) {
  6971. return pow(linear.invert(x));
  6972. };
  6973. scale.domain = function(x) {
  6974. if (!arguments.length) return domain;
  6975. positive = x[0] >= 0;
  6976. linear.domain((domain = x.map(Number)).map(log));
  6977. return scale;
  6978. };
  6979. scale.base = function(_) {
  6980. if (!arguments.length) return base;
  6981. base = +_;
  6982. linear.domain(domain.map(log));
  6983. return scale;
  6984. };
  6985. scale.nice = function() {
  6986. var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
  6987. linear.domain(niced);
  6988. domain = niced.map(pow);
  6989. return scale;
  6990. };
  6991. scale.ticks = function() {
  6992. 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;
  6993. if (isFinite(j - i)) {
  6994. if (positive) {
  6995. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
  6996. ticks.push(pow(i));
  6997. } else {
  6998. ticks.push(pow(i));
  6999. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
  7000. }
  7001. for (i = 0; ticks[i] < u; i++) {}
  7002. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  7003. ticks = ticks.slice(i, j);
  7004. }
  7005. return ticks;
  7006. };
  7007. scale.tickFormat = function(n, format) {
  7008. if (!arguments.length) return d3_scale_logFormat;
  7009. if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
  7010. var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
  7011. Math.floor), e;
  7012. return function(d) {
  7013. return d / pow(f(log(d) + e)) <= k ? format(d) : "";
  7014. };
  7015. };
  7016. scale.copy = function() {
  7017. return d3_scale_log(linear.copy(), base, positive, domain);
  7018. };
  7019. return d3_scale_linearRebind(scale, linear);
  7020. }
  7021. var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
  7022. floor: function(x) {
  7023. return -Math.ceil(-x);
  7024. },
  7025. ceil: function(x) {
  7026. return -Math.floor(-x);
  7027. }
  7028. };
  7029. d3.scale.pow = function() {
  7030. return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
  7031. };
  7032. function d3_scale_pow(linear, exponent, domain) {
  7033. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  7034. function scale(x) {
  7035. return linear(powp(x));
  7036. }
  7037. scale.invert = function(x) {
  7038. return powb(linear.invert(x));
  7039. };
  7040. scale.domain = function(x) {
  7041. if (!arguments.length) return domain;
  7042. linear.domain((domain = x.map(Number)).map(powp));
  7043. return scale;
  7044. };
  7045. scale.ticks = function(m) {
  7046. return d3_scale_linearTicks(domain, m);
  7047. };
  7048. scale.tickFormat = function(m, format) {
  7049. return d3_scale_linearTickFormat(domain, m, format);
  7050. };
  7051. scale.nice = function(m) {
  7052. return scale.domain(d3_scale_linearNice(domain, m));
  7053. };
  7054. scale.exponent = function(x) {
  7055. if (!arguments.length) return exponent;
  7056. powp = d3_scale_powPow(exponent = x);
  7057. powb = d3_scale_powPow(1 / exponent);
  7058. linear.domain(domain.map(powp));
  7059. return scale;
  7060. };
  7061. scale.copy = function() {
  7062. return d3_scale_pow(linear.copy(), exponent, domain);
  7063. };
  7064. return d3_scale_linearRebind(scale, linear);
  7065. }
  7066. function d3_scale_powPow(e) {
  7067. return function(x) {
  7068. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  7069. };
  7070. }
  7071. d3.scale.sqrt = function() {
  7072. return d3.scale.pow().exponent(.5);
  7073. };
  7074. d3.scale.ordinal = function() {
  7075. return d3_scale_ordinal([], {
  7076. t: "range",
  7077. a: [ [] ]
  7078. });
  7079. };
  7080. function d3_scale_ordinal(domain, ranger) {
  7081. var index, range, rangeBand;
  7082. function scale(x) {
  7083. return range[((index.get(x) || ranger.t === "range" && index.set(x, domain.push(x))) - 1) % range.length];
  7084. }
  7085. function steps(start, step) {
  7086. return d3.range(domain.length).map(function(i) {
  7087. return start + step * i;
  7088. });
  7089. }
  7090. scale.domain = function(x) {
  7091. if (!arguments.length) return domain;
  7092. domain = [];
  7093. index = new d3_Map();
  7094. var i = -1, n = x.length, xi;
  7095. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  7096. return scale[ranger.t].apply(scale, ranger.a);
  7097. };
  7098. scale.range = function(x) {
  7099. if (!arguments.length) return range;
  7100. range = x;
  7101. rangeBand = 0;
  7102. ranger = {
  7103. t: "range",
  7104. a: arguments
  7105. };
  7106. return scale;
  7107. };
  7108. scale.rangePoints = function(x, padding) {
  7109. if (arguments.length < 2) padding = 0;
  7110. var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
  7111. range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
  7112. rangeBand = 0;
  7113. ranger = {
  7114. t: "rangePoints",
  7115. a: arguments
  7116. };
  7117. return scale;
  7118. };
  7119. scale.rangeBands = function(x, padding, outerPadding) {
  7120. if (arguments.length < 2) padding = 0;
  7121. if (arguments.length < 3) outerPadding = padding;
  7122. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  7123. range = steps(start + step * outerPadding, step);
  7124. if (reverse) range.reverse();
  7125. rangeBand = step * (1 - padding);
  7126. ranger = {
  7127. t: "rangeBands",
  7128. a: arguments
  7129. };
  7130. return scale;
  7131. };
  7132. scale.rangeRoundBands = function(x, padding, outerPadding) {
  7133. if (arguments.length < 2) padding = 0;
  7134. if (arguments.length < 3) outerPadding = padding;
  7135. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding)), error = stop - start - (domain.length - padding) * step;
  7136. range = steps(start + Math.round(error / 2), step);
  7137. if (reverse) range.reverse();
  7138. rangeBand = Math.round(step * (1 - padding));
  7139. ranger = {
  7140. t: "rangeRoundBands",
  7141. a: arguments
  7142. };
  7143. return scale;
  7144. };
  7145. scale.rangeBand = function() {
  7146. return rangeBand;
  7147. };
  7148. scale.rangeExtent = function() {
  7149. return d3_scaleExtent(ranger.a[0]);
  7150. };
  7151. scale.copy = function() {
  7152. return d3_scale_ordinal(domain, ranger);
  7153. };
  7154. return scale.domain(domain);
  7155. }
  7156. d3.scale.category10 = function() {
  7157. return d3.scale.ordinal().range(d3_category10);
  7158. };
  7159. d3.scale.category20 = function() {
  7160. return d3.scale.ordinal().range(d3_category20);
  7161. };
  7162. d3.scale.category20b = function() {
  7163. return d3.scale.ordinal().range(d3_category20b);
  7164. };
  7165. d3.scale.category20c = function() {
  7166. return d3.scale.ordinal().range(d3_category20c);
  7167. };
  7168. var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
  7169. 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);
  7170. 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);
  7171. 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);
  7172. d3.scale.quantile = function() {
  7173. return d3_scale_quantile([], []);
  7174. };
  7175. function d3_scale_quantile(domain, range) {
  7176. var thresholds;
  7177. function rescale() {
  7178. var k = 0, q = range.length;
  7179. thresholds = [];
  7180. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  7181. return scale;
  7182. }
  7183. function scale(x) {
  7184. if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
  7185. }
  7186. scale.domain = function(x) {
  7187. if (!arguments.length) return domain;
  7188. domain = x.filter(function(d) {
  7189. return !isNaN(d);
  7190. }).sort(d3.ascending);
  7191. return rescale();
  7192. };
  7193. scale.range = function(x) {
  7194. if (!arguments.length) return range;
  7195. range = x;
  7196. return rescale();
  7197. };
  7198. scale.quantiles = function() {
  7199. return thresholds;
  7200. };
  7201. scale.invertExtent = function(y) {
  7202. y = range.indexOf(y);
  7203. return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
  7204. };
  7205. scale.copy = function() {
  7206. return d3_scale_quantile(domain, range);
  7207. };
  7208. return rescale();
  7209. }
  7210. d3.scale.quantize = function() {
  7211. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  7212. };
  7213. function d3_scale_quantize(x0, x1, range) {
  7214. var kx, i;
  7215. function scale(x) {
  7216. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  7217. }
  7218. function rescale() {
  7219. kx = range.length / (x1 - x0);
  7220. i = range.length - 1;
  7221. return scale;
  7222. }
  7223. scale.domain = function(x) {
  7224. if (!arguments.length) return [ x0, x1 ];
  7225. x0 = +x[0];
  7226. x1 = +x[x.length - 1];
  7227. return rescale();
  7228. };
  7229. scale.range = function(x) {
  7230. if (!arguments.length) return range;
  7231. range = x;
  7232. return rescale();
  7233. };
  7234. scale.invertExtent = function(y) {
  7235. y = range.indexOf(y);
  7236. y = y < 0 ? NaN : y / kx + x0;
  7237. return [ y, y + 1 / kx ];
  7238. };
  7239. scale.copy = function() {
  7240. return d3_scale_quantize(x0, x1, range);
  7241. };
  7242. return rescale();
  7243. }
  7244. d3.scale.threshold = function() {
  7245. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  7246. };
  7247. function d3_scale_threshold(domain, range) {
  7248. function scale(x) {
  7249. if (x <= x) return range[d3.bisect(domain, x)];
  7250. }
  7251. scale.domain = function(_) {
  7252. if (!arguments.length) return domain;
  7253. domain = _;
  7254. return scale;
  7255. };
  7256. scale.range = function(_) {
  7257. if (!arguments.length) return range;
  7258. range = _;
  7259. return scale;
  7260. };
  7261. scale.invertExtent = function(y) {
  7262. y = range.indexOf(y);
  7263. return [ domain[y - 1], domain[y] ];
  7264. };
  7265. scale.copy = function() {
  7266. return d3_scale_threshold(domain, range);
  7267. };
  7268. return scale;
  7269. }
  7270. d3.scale.identity = function() {
  7271. return d3_scale_identity([ 0, 1 ]);
  7272. };
  7273. function d3_scale_identity(domain) {
  7274. function identity(x) {
  7275. return +x;
  7276. }
  7277. identity.invert = identity;
  7278. identity.domain = identity.range = function(x) {
  7279. if (!arguments.length) return domain;
  7280. domain = x.map(identity);
  7281. return identity;
  7282. };
  7283. identity.ticks = function(m) {
  7284. return d3_scale_linearTicks(domain, m);
  7285. };
  7286. identity.tickFormat = function(m, format) {
  7287. return d3_scale_linearTickFormat(domain, m, format);
  7288. };
  7289. identity.copy = function() {
  7290. return d3_scale_identity(domain);
  7291. };
  7292. return identity;
  7293. }
  7294. d3.svg.arc = function() {
  7295. var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  7296. function arc() {
  7297. var r0 = innerRadius.apply(this, arguments), r1 = outerRadius.apply(this, arguments), a0 = startAngle.apply(this, arguments) + d3_svg_arcOffset, a1 = endAngle.apply(this, arguments) + d3_svg_arcOffset, da = (a1 < a0 && (da = a0,
  7298. a0 = a1, a1 = da), a1 - a0), df = da < π ? "0" : "1", c0 = Math.cos(a0), s0 = Math.sin(a0), c1 = Math.cos(a1), s1 = Math.sin(a1);
  7299. return da >= d3_svg_arcMax ? r0 ? "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "M0," + r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + -r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + r0 + "Z" : "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "Z" : r0 ? "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L" + r0 * c1 + "," + r0 * s1 + "A" + r0 + "," + r0 + " 0 " + df + ",0 " + r0 * c0 + "," + r0 * s0 + "Z" : "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L0,0" + "Z";
  7300. }
  7301. arc.innerRadius = function(v) {
  7302. if (!arguments.length) return innerRadius;
  7303. innerRadius = d3_functor(v);
  7304. return arc;
  7305. };
  7306. arc.outerRadius = function(v) {
  7307. if (!arguments.length) return outerRadius;
  7308. outerRadius = d3_functor(v);
  7309. return arc;
  7310. };
  7311. arc.startAngle = function(v) {
  7312. if (!arguments.length) return startAngle;
  7313. startAngle = d3_functor(v);
  7314. return arc;
  7315. };
  7316. arc.endAngle = function(v) {
  7317. if (!arguments.length) return endAngle;
  7318. endAngle = d3_functor(v);
  7319. return arc;
  7320. };
  7321. arc.centroid = function() {
  7322. var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
  7323. return [ Math.cos(a) * r, Math.sin(a) * r ];
  7324. };
  7325. return arc;
  7326. };
  7327. var d3_svg_arcOffset = -halfπ, d3_svg_arcMax = τ - ε;
  7328. function d3_svg_arcInnerRadius(d) {
  7329. return d.innerRadius;
  7330. }
  7331. function d3_svg_arcOuterRadius(d) {
  7332. return d.outerRadius;
  7333. }
  7334. function d3_svg_arcStartAngle(d) {
  7335. return d.startAngle;
  7336. }
  7337. function d3_svg_arcEndAngle(d) {
  7338. return d.endAngle;
  7339. }
  7340. d3.svg.line.radial = function() {
  7341. var line = d3_svg_line(d3_svg_lineRadial);
  7342. line.radius = line.x, delete line.x;
  7343. line.angle = line.y, delete line.y;
  7344. return line;
  7345. };
  7346. function d3_svg_lineRadial(points) {
  7347. var point, i = -1, n = points.length, r, a;
  7348. while (++i < n) {
  7349. point = points[i];
  7350. r = point[0];
  7351. a = point[1] + d3_svg_arcOffset;
  7352. point[0] = r * Math.cos(a);
  7353. point[1] = r * Math.sin(a);
  7354. }
  7355. return points;
  7356. }
  7357. function d3_svg_area(projection) {
  7358. var x0 = d3_svg_lineX, x1 = d3_svg_lineX, y0 = 0, y1 = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
  7359. function area(data) {
  7360. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  7361. return x;
  7362. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  7363. return y;
  7364. } : d3_functor(y1), x, y;
  7365. function segment() {
  7366. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  7367. }
  7368. while (++i < n) {
  7369. if (defined.call(this, d = data[i], i)) {
  7370. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  7371. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  7372. } else if (points0.length) {
  7373. segment();
  7374. points0 = [];
  7375. points1 = [];
  7376. }
  7377. }
  7378. if (points0.length) segment();
  7379. return segments.length ? segments.join("") : null;
  7380. }
  7381. area.x = function(_) {
  7382. if (!arguments.length) return x1;
  7383. x0 = x1 = _;
  7384. return area;
  7385. };
  7386. area.x0 = function(_) {
  7387. if (!arguments.length) return x0;
  7388. x0 = _;
  7389. return area;
  7390. };
  7391. area.x1 = function(_) {
  7392. if (!arguments.length) return x1;
  7393. x1 = _;
  7394. return area;
  7395. };
  7396. area.y = function(_) {
  7397. if (!arguments.length) return y1;
  7398. y0 = y1 = _;
  7399. return area;
  7400. };
  7401. area.y0 = function(_) {
  7402. if (!arguments.length) return y0;
  7403. y0 = _;
  7404. return area;
  7405. };
  7406. area.y1 = function(_) {
  7407. if (!arguments.length) return y1;
  7408. y1 = _;
  7409. return area;
  7410. };
  7411. area.defined = function(_) {
  7412. if (!arguments.length) return defined;
  7413. defined = _;
  7414. return area;
  7415. };
  7416. area.interpolate = function(_) {
  7417. if (!arguments.length) return interpolateKey;
  7418. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  7419. interpolateReverse = interpolate.reverse || interpolate;
  7420. L = interpolate.closed ? "M" : "L";
  7421. return area;
  7422. };
  7423. area.tension = function(_) {
  7424. if (!arguments.length) return tension;
  7425. tension = _;
  7426. return area;
  7427. };
  7428. return area;
  7429. }
  7430. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  7431. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  7432. d3.svg.area = function() {
  7433. return d3_svg_area(d3_identity);
  7434. };
  7435. d3.svg.area.radial = function() {
  7436. var area = d3_svg_area(d3_svg_lineRadial);
  7437. area.radius = area.x, delete area.x;
  7438. area.innerRadius = area.x0, delete area.x0;
  7439. area.outerRadius = area.x1, delete area.x1;
  7440. area.angle = area.y, delete area.y;
  7441. area.startAngle = area.y0, delete area.y0;
  7442. area.endAngle = area.y1, delete area.y1;
  7443. return area;
  7444. };
  7445. d3.svg.chord = function() {
  7446. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  7447. function chord(d, i) {
  7448. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  7449. 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";
  7450. }
  7451. function subgroup(self, f, d, i) {
  7452. var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) + d3_svg_arcOffset, a1 = endAngle.call(self, subgroup, i) + d3_svg_arcOffset;
  7453. return {
  7454. r: r,
  7455. a0: a0,
  7456. a1: a1,
  7457. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  7458. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  7459. };
  7460. }
  7461. function equals(a, b) {
  7462. return a.a0 == b.a0 && a.a1 == b.a1;
  7463. }
  7464. function arc(r, p, a) {
  7465. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  7466. }
  7467. function curve(r0, p0, r1, p1) {
  7468. return "Q 0,0 " + p1;
  7469. }
  7470. chord.radius = function(v) {
  7471. if (!arguments.length) return radius;
  7472. radius = d3_functor(v);
  7473. return chord;
  7474. };
  7475. chord.source = function(v) {
  7476. if (!arguments.length) return source;
  7477. source = d3_functor(v);
  7478. return chord;
  7479. };
  7480. chord.target = function(v) {
  7481. if (!arguments.length) return target;
  7482. target = d3_functor(v);
  7483. return chord;
  7484. };
  7485. chord.startAngle = function(v) {
  7486. if (!arguments.length) return startAngle;
  7487. startAngle = d3_functor(v);
  7488. return chord;
  7489. };
  7490. chord.endAngle = function(v) {
  7491. if (!arguments.length) return endAngle;
  7492. endAngle = d3_functor(v);
  7493. return chord;
  7494. };
  7495. return chord;
  7496. };
  7497. function d3_svg_chordRadius(d) {
  7498. return d.radius;
  7499. }
  7500. d3.svg.diagonal = function() {
  7501. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  7502. function diagonal(d, i) {
  7503. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  7504. x: p0.x,
  7505. y: m
  7506. }, {
  7507. x: p3.x,
  7508. y: m
  7509. }, p3 ];
  7510. p = p.map(projection);
  7511. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  7512. }
  7513. diagonal.source = function(x) {
  7514. if (!arguments.length) return source;
  7515. source = d3_functor(x);
  7516. return diagonal;
  7517. };
  7518. diagonal.target = function(x) {
  7519. if (!arguments.length) return target;
  7520. target = d3_functor(x);
  7521. return diagonal;
  7522. };
  7523. diagonal.projection = function(x) {
  7524. if (!arguments.length) return projection;
  7525. projection = x;
  7526. return diagonal;
  7527. };
  7528. return diagonal;
  7529. };
  7530. function d3_svg_diagonalProjection(d) {
  7531. return [ d.x, d.y ];
  7532. }
  7533. d3.svg.diagonal.radial = function() {
  7534. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  7535. diagonal.projection = function(x) {
  7536. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  7537. };
  7538. return diagonal;
  7539. };
  7540. function d3_svg_diagonalRadialProjection(projection) {
  7541. return function() {
  7542. var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
  7543. return [ r * Math.cos(a), r * Math.sin(a) ];
  7544. };
  7545. }
  7546. d3.svg.symbol = function() {
  7547. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  7548. function symbol(d, i) {
  7549. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  7550. }
  7551. symbol.type = function(x) {
  7552. if (!arguments.length) return type;
  7553. type = d3_functor(x);
  7554. return symbol;
  7555. };
  7556. symbol.size = function(x) {
  7557. if (!arguments.length) return size;
  7558. size = d3_functor(x);
  7559. return symbol;
  7560. };
  7561. return symbol;
  7562. };
  7563. function d3_svg_symbolSize() {
  7564. return 64;
  7565. }
  7566. function d3_svg_symbolType() {
  7567. return "circle";
  7568. }
  7569. function d3_svg_symbolCircle(size) {
  7570. var r = Math.sqrt(size / π);
  7571. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  7572. }
  7573. var d3_svg_symbols = d3.map({
  7574. circle: d3_svg_symbolCircle,
  7575. cross: function(size) {
  7576. var r = Math.sqrt(size / 5) / 2;
  7577. 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";
  7578. },
  7579. diamond: function(size) {
  7580. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  7581. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  7582. },
  7583. square: function(size) {
  7584. var r = Math.sqrt(size) / 2;
  7585. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  7586. },
  7587. "triangle-down": function(size) {
  7588. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  7589. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  7590. },
  7591. "triangle-up": function(size) {
  7592. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  7593. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  7594. }
  7595. });
  7596. d3.svg.symbolTypes = d3_svg_symbols.keys();
  7597. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  7598. function d3_transition(groups, id) {
  7599. d3_subclass(groups, d3_transitionPrototype);
  7600. groups.id = id;
  7601. return groups;
  7602. }
  7603. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
  7604. d3_transitionPrototype.call = d3_selectionPrototype.call;
  7605. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  7606. d3_transitionPrototype.node = d3_selectionPrototype.node;
  7607. d3_transitionPrototype.size = d3_selectionPrototype.size;
  7608. d3.transition = function(selection) {
  7609. return arguments.length ? d3_transitionInheritId ? selection.transition() : selection : d3_selectionRoot.transition();
  7610. };
  7611. d3.transition.prototype = d3_transitionPrototype;
  7612. d3_transitionPrototype.select = function(selector) {
  7613. var id = this.id, subgroups = [], subgroup, subnode, node;
  7614. selector = d3_selection_selector(selector);
  7615. for (var j = -1, m = this.length; ++j < m; ) {
  7616. subgroups.push(subgroup = []);
  7617. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  7618. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
  7619. if ("__data__" in node) subnode.__data__ = node.__data__;
  7620. d3_transitionNode(subnode, i, id, node.__transition__[id]);
  7621. subgroup.push(subnode);
  7622. } else {
  7623. subgroup.push(null);
  7624. }
  7625. }
  7626. }
  7627. return d3_transition(subgroups, id);
  7628. };
  7629. d3_transitionPrototype.selectAll = function(selector) {
  7630. var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition;
  7631. selector = d3_selection_selectorAll(selector);
  7632. for (var j = -1, m = this.length; ++j < m; ) {
  7633. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  7634. if (node = group[i]) {
  7635. transition = node.__transition__[id];
  7636. subnodes = selector.call(node, node.__data__, i, j);
  7637. subgroups.push(subgroup = []);
  7638. for (var k = -1, o = subnodes.length; ++k < o; ) {
  7639. if (subnode = subnodes[k]) d3_transitionNode(subnode, k, id, transition);
  7640. subgroup.push(subnode);
  7641. }
  7642. }
  7643. }
  7644. }
  7645. return d3_transition(subgroups, id);
  7646. };
  7647. d3_transitionPrototype.filter = function(filter) {
  7648. var subgroups = [], subgroup, group, node;
  7649. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  7650. for (var j = 0, m = this.length; j < m; j++) {
  7651. subgroups.push(subgroup = []);
  7652. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  7653. if ((node = group[i]) && filter.call(node, node.__data__, i)) {
  7654. subgroup.push(node);
  7655. }
  7656. }
  7657. }
  7658. return d3_transition(subgroups, this.id);
  7659. };
  7660. d3_transitionPrototype.tween = function(name, tween) {
  7661. var id = this.id;
  7662. if (arguments.length < 2) return this.node().__transition__[id].tween.get(name);
  7663. return d3_selection_each(this, tween == null ? function(node) {
  7664. node.__transition__[id].tween.remove(name);
  7665. } : function(node) {
  7666. node.__transition__[id].tween.set(name, tween);
  7667. });
  7668. };
  7669. function d3_transition_tween(groups, name, value, tween) {
  7670. var id = groups.id;
  7671. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  7672. node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  7673. } : (value = tween(value), function(node) {
  7674. node.__transition__[id].tween.set(name, value);
  7675. }));
  7676. }
  7677. d3_transitionPrototype.attr = function(nameNS, value) {
  7678. if (arguments.length < 2) {
  7679. for (value in nameNS) this.attr(value, nameNS[value]);
  7680. return this;
  7681. }
  7682. var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
  7683. function attrNull() {
  7684. this.removeAttribute(name);
  7685. }
  7686. function attrNullNS() {
  7687. this.removeAttributeNS(name.space, name.local);
  7688. }
  7689. function attrTween(b) {
  7690. return b == null ? attrNull : (b += "", function() {
  7691. var a = this.getAttribute(name), i;
  7692. return a !== b && (i = interpolate(a, b), function(t) {
  7693. this.setAttribute(name, i(t));
  7694. });
  7695. });
  7696. }
  7697. function attrTweenNS(b) {
  7698. return b == null ? attrNullNS : (b += "", function() {
  7699. var a = this.getAttributeNS(name.space, name.local), i;
  7700. return a !== b && (i = interpolate(a, b), function(t) {
  7701. this.setAttributeNS(name.space, name.local, i(t));
  7702. });
  7703. });
  7704. }
  7705. return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
  7706. };
  7707. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  7708. var name = d3.ns.qualify(nameNS);
  7709. function attrTween(d, i) {
  7710. var f = tween.call(this, d, i, this.getAttribute(name));
  7711. return f && function(t) {
  7712. this.setAttribute(name, f(t));
  7713. };
  7714. }
  7715. function attrTweenNS(d, i) {
  7716. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  7717. return f && function(t) {
  7718. this.setAttributeNS(name.space, name.local, f(t));
  7719. };
  7720. }
  7721. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  7722. };
  7723. d3_transitionPrototype.style = function(name, value, priority) {
  7724. var n = arguments.length;
  7725. if (n < 3) {
  7726. if (typeof name !== "string") {
  7727. if (n < 2) value = "";
  7728. for (priority in name) this.style(priority, name[priority], value);
  7729. return this;
  7730. }
  7731. priority = "";
  7732. }
  7733. function styleNull() {
  7734. this.style.removeProperty(name);
  7735. }
  7736. function styleString(b) {
  7737. return b == null ? styleNull : (b += "", function() {
  7738. var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
  7739. return a !== b && (i = d3_interpolate(a, b), function(t) {
  7740. this.style.setProperty(name, i(t), priority);
  7741. });
  7742. });
  7743. }
  7744. return d3_transition_tween(this, "style." + name, value, styleString);
  7745. };
  7746. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  7747. if (arguments.length < 3) priority = "";
  7748. function styleTween(d, i) {
  7749. var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
  7750. return f && function(t) {
  7751. this.style.setProperty(name, f(t), priority);
  7752. };
  7753. }
  7754. return this.tween("style." + name, styleTween);
  7755. };
  7756. d3_transitionPrototype.text = function(value) {
  7757. return d3_transition_tween(this, "text", value, d3_transition_text);
  7758. };
  7759. function d3_transition_text(b) {
  7760. if (b == null) b = "";
  7761. return function() {
  7762. this.textContent = b;
  7763. };
  7764. }
  7765. d3_transitionPrototype.remove = function() {
  7766. return this.each("end.transition", function() {
  7767. var p;
  7768. if (this.__transition__.count < 2 && (p = this.parentNode)) p.removeChild(this);
  7769. });
  7770. };
  7771. d3_transitionPrototype.ease = function(value) {
  7772. var id = this.id;
  7773. if (arguments.length < 1) return this.node().__transition__[id].ease;
  7774. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  7775. return d3_selection_each(this, function(node) {
  7776. node.__transition__[id].ease = value;
  7777. });
  7778. };
  7779. d3_transitionPrototype.delay = function(value) {
  7780. var id = this.id;
  7781. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  7782. node.__transition__[id].delay = +value.call(node, node.__data__, i, j);
  7783. } : (value = +value, function(node) {
  7784. node.__transition__[id].delay = value;
  7785. }));
  7786. };
  7787. d3_transitionPrototype.duration = function(value) {
  7788. var id = this.id;
  7789. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  7790. node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j));
  7791. } : (value = Math.max(1, value), function(node) {
  7792. node.__transition__[id].duration = value;
  7793. }));
  7794. };
  7795. d3_transitionPrototype.each = function(type, listener) {
  7796. var id = this.id;
  7797. if (arguments.length < 2) {
  7798. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  7799. d3_transitionInheritId = id;
  7800. d3_selection_each(this, function(node, i, j) {
  7801. d3_transitionInherit = node.__transition__[id];
  7802. type.call(node, node.__data__, i, j);
  7803. });
  7804. d3_transitionInherit = inherit;
  7805. d3_transitionInheritId = inheritId;
  7806. } else {
  7807. d3_selection_each(this, function(node) {
  7808. var transition = node.__transition__[id];
  7809. (transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
  7810. });
  7811. }
  7812. return this;
  7813. };
  7814. d3_transitionPrototype.transition = function() {
  7815. var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition;
  7816. for (var j = 0, m = this.length; j < m; j++) {
  7817. subgroups.push(subgroup = []);
  7818. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  7819. if (node = group[i]) {
  7820. transition = Object.create(node.__transition__[id0]);
  7821. transition.delay += transition.duration;
  7822. d3_transitionNode(node, i, id1, transition);
  7823. }
  7824. subgroup.push(node);
  7825. }
  7826. }
  7827. return d3_transition(subgroups, id1);
  7828. };
  7829. function d3_transitionNode(node, i, id, inherit) {
  7830. var lock = node.__transition__ || (node.__transition__ = {
  7831. active: 0,
  7832. count: 0
  7833. }), transition = lock[id];
  7834. if (!transition) {
  7835. var time = inherit.time;
  7836. transition = lock[id] = {
  7837. tween: new d3_Map(),
  7838. time: time,
  7839. ease: inherit.ease,
  7840. delay: inherit.delay,
  7841. duration: inherit.duration
  7842. };
  7843. ++lock.count;
  7844. d3.timer(function(elapsed) {
  7845. var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, tweened = [];
  7846. if (delay <= elapsed) return start(elapsed - delay);
  7847. d3_timer_replace(start, delay, time);
  7848. function start(elapsed) {
  7849. if (lock.active > id) return stop();
  7850. lock.active = id;
  7851. transition.event && transition.event.start.call(node, d, i);
  7852. transition.tween.forEach(function(key, value) {
  7853. if (value = value.call(node, d, i)) {
  7854. tweened.push(value);
  7855. }
  7856. });
  7857. if (tick(elapsed || 1)) return 1;
  7858. d3_timer_replace(tick, delay, time);
  7859. }
  7860. function tick(elapsed) {
  7861. if (lock.active !== id) return stop();
  7862. var t = elapsed / duration, e = ease(t), n = tweened.length;
  7863. while (n > 0) {
  7864. tweened[--n].call(node, e);
  7865. }
  7866. if (t >= 1) {
  7867. transition.event && transition.event.end.call(node, d, i);
  7868. return stop();
  7869. }
  7870. }
  7871. function stop() {
  7872. if (--lock.count) delete lock[id]; else delete node.__transition__;
  7873. return 1;
  7874. }
  7875. }, 0, time);
  7876. }
  7877. }
  7878. d3.svg.axis = function() {
  7879. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
  7880. function axis(g) {
  7881. g.each(function() {
  7882. var g = d3.select(this);
  7883. var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
  7884. 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).style("opacity", 1), tickTransform;
  7885. var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  7886. d3.transition(path));
  7887. tickEnter.append("line");
  7888. tickEnter.append("text");
  7889. var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
  7890. switch (orient) {
  7891. case "bottom":
  7892. {
  7893. tickTransform = d3_svg_axisX;
  7894. lineEnter.attr("y2", innerTickSize);
  7895. textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding);
  7896. lineUpdate.attr("x2", 0).attr("y2", innerTickSize);
  7897. textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding);
  7898. text.attr("dy", ".71em").style("text-anchor", "middle");
  7899. pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize);
  7900. break;
  7901. }
  7902. case "top":
  7903. {
  7904. tickTransform = d3_svg_axisX;
  7905. lineEnter.attr("y2", -innerTickSize);
  7906. textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
  7907. lineUpdate.attr("x2", 0).attr("y2", -innerTickSize);
  7908. textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
  7909. text.attr("dy", "0em").style("text-anchor", "middle");
  7910. pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize);
  7911. break;
  7912. }
  7913. case "left":
  7914. {
  7915. tickTransform = d3_svg_axisY;
  7916. lineEnter.attr("x2", -innerTickSize);
  7917. textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding));
  7918. lineUpdate.attr("x2", -innerTickSize).attr("y2", 0);
  7919. textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", 0);
  7920. text.attr("dy", ".32em").style("text-anchor", "end");
  7921. pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize);
  7922. break;
  7923. }
  7924. case "right":
  7925. {
  7926. tickTransform = d3_svg_axisY;
  7927. lineEnter.attr("x2", innerTickSize);
  7928. textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding);
  7929. lineUpdate.attr("x2", innerTickSize).attr("y2", 0);
  7930. textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0);
  7931. text.attr("dy", ".32em").style("text-anchor", "start");
  7932. pathUpdate.attr("d", "M" + outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + outerTickSize);
  7933. break;
  7934. }
  7935. }
  7936. if (scale1.rangeBand) {
  7937. var dx = scale1.rangeBand() / 2, x = function(d) {
  7938. return scale1(d) + dx;
  7939. };
  7940. tickEnter.call(tickTransform, x);
  7941. tickUpdate.call(tickTransform, x);
  7942. } else {
  7943. tickEnter.call(tickTransform, scale0);
  7944. tickUpdate.call(tickTransform, scale1);
  7945. tickExit.call(tickTransform, scale1);
  7946. }
  7947. });
  7948. }
  7949. axis.scale = function(x) {
  7950. if (!arguments.length) return scale;
  7951. scale = x;
  7952. return axis;
  7953. };
  7954. axis.orient = function(x) {
  7955. if (!arguments.length) return orient;
  7956. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  7957. return axis;
  7958. };
  7959. axis.ticks = function() {
  7960. if (!arguments.length) return tickArguments_;
  7961. tickArguments_ = arguments;
  7962. return axis;
  7963. };
  7964. axis.tickValues = function(x) {
  7965. if (!arguments.length) return tickValues;
  7966. tickValues = x;
  7967. return axis;
  7968. };
  7969. axis.tickFormat = function(x) {
  7970. if (!arguments.length) return tickFormat_;
  7971. tickFormat_ = x;
  7972. return axis;
  7973. };
  7974. axis.tickSize = function(x) {
  7975. var n = arguments.length;
  7976. if (!n) return innerTickSize;
  7977. innerTickSize = +x;
  7978. outerTickSize = +arguments[n - 1];
  7979. return axis;
  7980. };
  7981. axis.innerTickSize = function(x) {
  7982. if (!arguments.length) return innerTickSize;
  7983. innerTickSize = +x;
  7984. return axis;
  7985. };
  7986. axis.outerTickSize = function(x) {
  7987. if (!arguments.length) return outerTickSize;
  7988. outerTickSize = +x;
  7989. return axis;
  7990. };
  7991. axis.tickPadding = function(x) {
  7992. if (!arguments.length) return tickPadding;
  7993. tickPadding = +x;
  7994. return axis;
  7995. };
  7996. axis.tickSubdivide = function() {
  7997. return arguments.length && axis;
  7998. };
  7999. return axis;
  8000. };
  8001. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  8002. top: 1,
  8003. right: 1,
  8004. bottom: 1,
  8005. left: 1
  8006. };
  8007. function d3_svg_axisX(selection, x) {
  8008. selection.attr("transform", function(d) {
  8009. return "translate(" + x(d) + ",0)";
  8010. });
  8011. }
  8012. function d3_svg_axisY(selection, y) {
  8013. selection.attr("transform", function(d) {
  8014. return "translate(0," + y(d) + ")";
  8015. });
  8016. }
  8017. d3.svg.brush = function() {
  8018. 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];
  8019. function brush(g) {
  8020. g.each(function() {
  8021. 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);
  8022. var background = g.selectAll(".background").data([ 0 ]);
  8023. background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  8024. g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
  8025. var resize = g.selectAll(".resize").data(resizes, d3_identity);
  8026. resize.exit().remove();
  8027. resize.enter().append("g").attr("class", function(d) {
  8028. return "resize " + d;
  8029. }).style("cursor", function(d) {
  8030. return d3_svg_brushCursor[d];
  8031. }).append("rect").attr("x", function(d) {
  8032. return /[ew]$/.test(d) ? -3 : null;
  8033. }).attr("y", function(d) {
  8034. return /^[ns]/.test(d) ? -3 : null;
  8035. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  8036. resize.style("display", brush.empty() ? "none" : null);
  8037. var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
  8038. if (x) {
  8039. range = d3_scaleRange(x);
  8040. backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
  8041. redrawX(gUpdate);
  8042. }
  8043. if (y) {
  8044. range = d3_scaleRange(y);
  8045. backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
  8046. redrawY(gUpdate);
  8047. }
  8048. redraw(gUpdate);
  8049. });
  8050. }
  8051. brush.event = function(g) {
  8052. g.each(function() {
  8053. var event_ = event.of(this, arguments), extent1 = {
  8054. x: xExtent,
  8055. y: yExtent,
  8056. i: xExtentDomain,
  8057. j: yExtentDomain
  8058. }, extent0 = this.__chart__ || extent1;
  8059. this.__chart__ = extent1;
  8060. if (d3_transitionInheritId) {
  8061. d3.select(this).transition().each("start.brush", function() {
  8062. xExtentDomain = extent0.i;
  8063. yExtentDomain = extent0.j;
  8064. xExtent = extent0.x;
  8065. yExtent = extent0.y;
  8066. event_({
  8067. type: "brushstart"
  8068. });
  8069. }).tween("brush:brush", function() {
  8070. var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
  8071. xExtentDomain = yExtentDomain = null;
  8072. return function(t) {
  8073. xExtent = extent1.x = xi(t);
  8074. yExtent = extent1.y = yi(t);
  8075. event_({
  8076. type: "brush",
  8077. mode: "resize"
  8078. });
  8079. };
  8080. }).each("end.brush", function() {
  8081. xExtentDomain = extent1.i;
  8082. yExtentDomain = extent1.j;
  8083. event_({
  8084. type: "brush",
  8085. mode: "resize"
  8086. });
  8087. event_({
  8088. type: "brushend"
  8089. });
  8090. });
  8091. } else {
  8092. event_({
  8093. type: "brushstart"
  8094. });
  8095. event_({
  8096. type: "brush",
  8097. mode: "resize"
  8098. });
  8099. event_({
  8100. type: "brushend"
  8101. });
  8102. }
  8103. });
  8104. };
  8105. function redraw(g) {
  8106. g.selectAll(".resize").attr("transform", function(d) {
  8107. return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
  8108. });
  8109. }
  8110. function redrawX(g) {
  8111. g.select(".extent").attr("x", xExtent[0]);
  8112. g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
  8113. }
  8114. function redrawY(g) {
  8115. g.select(".extent").attr("y", yExtent[0]);
  8116. g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
  8117. }
  8118. function brushstart() {
  8119. 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(), center, origin = d3.mouse(target), offset;
  8120. var w = d3.select(d3_window).on("keydown.brush", keydown).on("keyup.brush", keyup);
  8121. if (d3.event.changedTouches) {
  8122. w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
  8123. } else {
  8124. w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
  8125. }
  8126. g.interrupt().selectAll("*").interrupt();
  8127. if (dragging) {
  8128. origin[0] = xExtent[0] - origin[0];
  8129. origin[1] = yExtent[0] - origin[1];
  8130. } else if (resizing) {
  8131. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  8132. offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
  8133. origin[0] = xExtent[ex];
  8134. origin[1] = yExtent[ey];
  8135. } else if (d3.event.altKey) center = origin.slice();
  8136. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  8137. d3.select("body").style("cursor", eventTarget.style("cursor"));
  8138. event_({
  8139. type: "brushstart"
  8140. });
  8141. brushmove();
  8142. function keydown() {
  8143. if (d3.event.keyCode == 32) {
  8144. if (!dragging) {
  8145. center = null;
  8146. origin[0] -= xExtent[1];
  8147. origin[1] -= yExtent[1];
  8148. dragging = 2;
  8149. }
  8150. d3_eventPreventDefault();
  8151. }
  8152. }
  8153. function keyup() {
  8154. if (d3.event.keyCode == 32 && dragging == 2) {
  8155. origin[0] += xExtent[1];
  8156. origin[1] += yExtent[1];
  8157. dragging = 0;
  8158. d3_eventPreventDefault();
  8159. }
  8160. }
  8161. function brushmove() {
  8162. var point = d3.mouse(target), moved = false;
  8163. if (offset) {
  8164. point[0] += offset[0];
  8165. point[1] += offset[1];
  8166. }
  8167. if (!dragging) {
  8168. if (d3.event.altKey) {
  8169. if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
  8170. origin[0] = xExtent[+(point[0] < center[0])];
  8171. origin[1] = yExtent[+(point[1] < center[1])];
  8172. } else center = null;
  8173. }
  8174. if (resizingX && move1(point, x, 0)) {
  8175. redrawX(g);
  8176. moved = true;
  8177. }
  8178. if (resizingY && move1(point, y, 1)) {
  8179. redrawY(g);
  8180. moved = true;
  8181. }
  8182. if (moved) {
  8183. redraw(g);
  8184. event_({
  8185. type: "brush",
  8186. mode: dragging ? "move" : "resize"
  8187. });
  8188. }
  8189. }
  8190. function move1(point, scale, i) {
  8191. 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;
  8192. if (dragging) {
  8193. r0 -= position;
  8194. r1 -= size + position;
  8195. }
  8196. min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
  8197. if (dragging) {
  8198. max = (min += position) + size;
  8199. } else {
  8200. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  8201. if (position < min) {
  8202. max = min;
  8203. min = position;
  8204. } else {
  8205. max = position;
  8206. }
  8207. }
  8208. if (extent[0] != min || extent[1] != max) {
  8209. if (i) yExtentDomain = null; else xExtentDomain = null;
  8210. extent[0] = min;
  8211. extent[1] = max;
  8212. return true;
  8213. }
  8214. }
  8215. function brushend() {
  8216. brushmove();
  8217. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  8218. d3.select("body").style("cursor", null);
  8219. 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);
  8220. dragRestore();
  8221. event_({
  8222. type: "brushend"
  8223. });
  8224. }
  8225. }
  8226. brush.x = function(z) {
  8227. if (!arguments.length) return x;
  8228. x = z;
  8229. resizes = d3_svg_brushResizes[!x << 1 | !y];
  8230. return brush;
  8231. };
  8232. brush.y = function(z) {
  8233. if (!arguments.length) return y;
  8234. y = z;
  8235. resizes = d3_svg_brushResizes[!x << 1 | !y];
  8236. return brush;
  8237. };
  8238. brush.clamp = function(z) {
  8239. if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
  8240. if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
  8241. return brush;
  8242. };
  8243. brush.extent = function(z) {
  8244. var x0, x1, y0, y1, t;
  8245. if (!arguments.length) {
  8246. if (x) {
  8247. if (xExtentDomain) {
  8248. x0 = xExtentDomain[0], x1 = xExtentDomain[1];
  8249. } else {
  8250. x0 = xExtent[0], x1 = xExtent[1];
  8251. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  8252. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  8253. }
  8254. }
  8255. if (y) {
  8256. if (yExtentDomain) {
  8257. y0 = yExtentDomain[0], y1 = yExtentDomain[1];
  8258. } else {
  8259. y0 = yExtent[0], y1 = yExtent[1];
  8260. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  8261. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  8262. }
  8263. }
  8264. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  8265. }
  8266. if (x) {
  8267. x0 = z[0], x1 = z[1];
  8268. if (y) x0 = x0[0], x1 = x1[0];
  8269. xExtentDomain = [ x0, x1 ];
  8270. if (x.invert) x0 = x(x0), x1 = x(x1);
  8271. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  8272. if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
  8273. }
  8274. if (y) {
  8275. y0 = z[0], y1 = z[1];
  8276. if (x) y0 = y0[1], y1 = y1[1];
  8277. yExtentDomain = [ y0, y1 ];
  8278. if (y.invert) y0 = y(y0), y1 = y(y1);
  8279. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  8280. if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
  8281. }
  8282. return brush;
  8283. };
  8284. brush.clear = function() {
  8285. if (!brush.empty()) {
  8286. xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
  8287. xExtentDomain = yExtentDomain = null;
  8288. }
  8289. return brush;
  8290. };
  8291. brush.empty = function() {
  8292. return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
  8293. };
  8294. return d3.rebind(brush, event, "on");
  8295. };
  8296. var d3_svg_brushCursor = {
  8297. n: "ns-resize",
  8298. e: "ew-resize",
  8299. s: "ns-resize",
  8300. w: "ew-resize",
  8301. nw: "nwse-resize",
  8302. ne: "nesw-resize",
  8303. se: "nwse-resize",
  8304. sw: "nesw-resize"
  8305. };
  8306. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  8307. var d3_time = d3.time = {}, d3_date = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
  8308. function d3_date_utc() {
  8309. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  8310. }
  8311. d3_date_utc.prototype = {
  8312. getDate: function() {
  8313. return this._.getUTCDate();
  8314. },
  8315. getDay: function() {
  8316. return this._.getUTCDay();
  8317. },
  8318. getFullYear: function() {
  8319. return this._.getUTCFullYear();
  8320. },
  8321. getHours: function() {
  8322. return this._.getUTCHours();
  8323. },
  8324. getMilliseconds: function() {
  8325. return this._.getUTCMilliseconds();
  8326. },
  8327. getMinutes: function() {
  8328. return this._.getUTCMinutes();
  8329. },
  8330. getMonth: function() {
  8331. return this._.getUTCMonth();
  8332. },
  8333. getSeconds: function() {
  8334. return this._.getUTCSeconds();
  8335. },
  8336. getTime: function() {
  8337. return this._.getTime();
  8338. },
  8339. getTimezoneOffset: function() {
  8340. return 0;
  8341. },
  8342. valueOf: function() {
  8343. return this._.valueOf();
  8344. },
  8345. setDate: function() {
  8346. d3_time_prototype.setUTCDate.apply(this._, arguments);
  8347. },
  8348. setDay: function() {
  8349. d3_time_prototype.setUTCDay.apply(this._, arguments);
  8350. },
  8351. setFullYear: function() {
  8352. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  8353. },
  8354. setHours: function() {
  8355. d3_time_prototype.setUTCHours.apply(this._, arguments);
  8356. },
  8357. setMilliseconds: function() {
  8358. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  8359. },
  8360. setMinutes: function() {
  8361. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  8362. },
  8363. setMonth: function() {
  8364. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  8365. },
  8366. setSeconds: function() {
  8367. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  8368. },
  8369. setTime: function() {
  8370. d3_time_prototype.setTime.apply(this._, arguments);
  8371. }
  8372. };
  8373. var d3_time_prototype = Date.prototype;
  8374. var d3_time_formatDateTime = "%a %b %e %X %Y", d3_time_formatDate = "%m/%d/%Y", d3_time_formatTime = "%H:%M:%S";
  8375. var d3_time_days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], d3_time_dayAbbreviations = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], d3_time_monthAbbreviations = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
  8376. function d3_time_interval(local, step, number) {
  8377. function round(date) {
  8378. var d0 = local(date), d1 = offset(d0, 1);
  8379. return date - d0 < d1 - date ? d0 : d1;
  8380. }
  8381. function ceil(date) {
  8382. step(date = local(new d3_date(date - 1)), 1);
  8383. return date;
  8384. }
  8385. function offset(date, k) {
  8386. step(date = new d3_date(+date), k);
  8387. return date;
  8388. }
  8389. function range(t0, t1, dt) {
  8390. var time = ceil(t0), times = [];
  8391. if (dt > 1) {
  8392. while (time < t1) {
  8393. if (!(number(time) % dt)) times.push(new Date(+time));
  8394. step(time, 1);
  8395. }
  8396. } else {
  8397. while (time < t1) times.push(new Date(+time)), step(time, 1);
  8398. }
  8399. return times;
  8400. }
  8401. function range_utc(t0, t1, dt) {
  8402. try {
  8403. d3_date = d3_date_utc;
  8404. var utc = new d3_date_utc();
  8405. utc._ = t0;
  8406. return range(utc, t1, dt);
  8407. } finally {
  8408. d3_date = Date;
  8409. }
  8410. }
  8411. local.floor = local;
  8412. local.round = round;
  8413. local.ceil = ceil;
  8414. local.offset = offset;
  8415. local.range = range;
  8416. var utc = local.utc = d3_time_interval_utc(local);
  8417. utc.floor = utc;
  8418. utc.round = d3_time_interval_utc(round);
  8419. utc.ceil = d3_time_interval_utc(ceil);
  8420. utc.offset = d3_time_interval_utc(offset);
  8421. utc.range = range_utc;
  8422. return local;
  8423. }
  8424. function d3_time_interval_utc(method) {
  8425. return function(date, k) {
  8426. try {
  8427. d3_date = d3_date_utc;
  8428. var utc = new d3_date_utc();
  8429. utc._ = date;
  8430. return method(utc, k)._;
  8431. } finally {
  8432. d3_date = Date;
  8433. }
  8434. };
  8435. }
  8436. d3_time.year = d3_time_interval(function(date) {
  8437. date = d3_time.day(date);
  8438. date.setMonth(0, 1);
  8439. return date;
  8440. }, function(date, offset) {
  8441. date.setFullYear(date.getFullYear() + offset);
  8442. }, function(date) {
  8443. return date.getFullYear();
  8444. });
  8445. d3_time.years = d3_time.year.range;
  8446. d3_time.years.utc = d3_time.year.utc.range;
  8447. d3_time.day = d3_time_interval(function(date) {
  8448. var day = new d3_date(2e3, 0);
  8449. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  8450. return day;
  8451. }, function(date, offset) {
  8452. date.setDate(date.getDate() + offset);
  8453. }, function(date) {
  8454. return date.getDate() - 1;
  8455. });
  8456. d3_time.days = d3_time.day.range;
  8457. d3_time.days.utc = d3_time.day.utc.range;
  8458. d3_time.dayOfYear = function(date) {
  8459. var year = d3_time.year(date);
  8460. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  8461. };
  8462. d3_time_daySymbols.forEach(function(day, i) {
  8463. day = day.toLowerCase();
  8464. i = 7 - i;
  8465. var interval = d3_time[day] = d3_time_interval(function(date) {
  8466. (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  8467. return date;
  8468. }, function(date, offset) {
  8469. date.setDate(date.getDate() + Math.floor(offset) * 7);
  8470. }, function(date) {
  8471. var day = d3_time.year(date).getDay();
  8472. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  8473. });
  8474. d3_time[day + "s"] = interval.range;
  8475. d3_time[day + "s"].utc = interval.utc.range;
  8476. d3_time[day + "OfYear"] = function(date) {
  8477. var day = d3_time.year(date).getDay();
  8478. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
  8479. };
  8480. });
  8481. d3_time.week = d3_time.sunday;
  8482. d3_time.weeks = d3_time.sunday.range;
  8483. d3_time.weeks.utc = d3_time.sunday.utc.range;
  8484. d3_time.weekOfYear = d3_time.sundayOfYear;
  8485. d3_time.format = d3_time_format;
  8486. function d3_time_format(template) {
  8487. var n = template.length;
  8488. function format(date) {
  8489. var string = [], i = -1, j = 0, c, p, f;
  8490. while (++i < n) {
  8491. if (template.charCodeAt(i) === 37) {
  8492. string.push(template.substring(j, i));
  8493. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  8494. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  8495. string.push(c);
  8496. j = i + 1;
  8497. }
  8498. }
  8499. string.push(template.substring(j, i));
  8500. return string.join("");
  8501. }
  8502. format.parse = function(string) {
  8503. var d = {
  8504. y: 1900,
  8505. m: 0,
  8506. d: 1,
  8507. H: 0,
  8508. M: 0,
  8509. S: 0,
  8510. L: 0,
  8511. Z: null
  8512. }, i = d3_time_parse(d, template, string, 0);
  8513. if (i != string.length) return null;
  8514. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  8515. var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
  8516. if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
  8517. date.setFullYear(d.y, 0, 1);
  8518. 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);
  8519. } else date.setFullYear(d.y, d.m, d.d);
  8520. date.setHours(d.H + Math.floor(d.Z / 100), d.M + d.Z % 100, d.S, d.L);
  8521. return localZ ? date._ : date;
  8522. };
  8523. format.toString = function() {
  8524. return template;
  8525. };
  8526. return format;
  8527. }
  8528. function d3_time_parse(date, template, string, j) {
  8529. var c, p, t, i = 0, n = template.length, m = string.length;
  8530. while (i < n) {
  8531. if (j >= m) return -1;
  8532. c = template.charCodeAt(i++);
  8533. if (c === 37) {
  8534. t = template.charAt(i++);
  8535. p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
  8536. if (!p || (j = p(date, string, j)) < 0) return -1;
  8537. } else if (c != string.charCodeAt(j++)) {
  8538. return -1;
  8539. }
  8540. }
  8541. return j;
  8542. }
  8543. function d3_time_formatRe(names) {
  8544. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  8545. }
  8546. function d3_time_formatLookup(names) {
  8547. var map = new d3_Map(), i = -1, n = names.length;
  8548. while (++i < n) map.set(names[i].toLowerCase(), i);
  8549. return map;
  8550. }
  8551. function d3_time_formatPad(value, fill, width) {
  8552. var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
  8553. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  8554. }
  8555. var d3_time_dayRe = d3_time_formatRe(d3_time_days), d3_time_dayLookup = d3_time_formatLookup(d3_time_days), d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations), d3_time_dayAbbrevLookup = d3_time_formatLookup(d3_time_dayAbbreviations), d3_time_monthRe = d3_time_formatRe(d3_time_months), d3_time_monthLookup = d3_time_formatLookup(d3_time_months), d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations), d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations), d3_time_percentRe = /^%/;
  8556. var d3_time_formatPads = {
  8557. "-": "",
  8558. _: " ",
  8559. "0": "0"
  8560. };
  8561. var d3_time_formats = {
  8562. a: function(d) {
  8563. return d3_time_dayAbbreviations[d.getDay()];
  8564. },
  8565. A: function(d) {
  8566. return d3_time_days[d.getDay()];
  8567. },
  8568. b: function(d) {
  8569. return d3_time_monthAbbreviations[d.getMonth()];
  8570. },
  8571. B: function(d) {
  8572. return d3_time_months[d.getMonth()];
  8573. },
  8574. c: d3_time_format(d3_time_formatDateTime),
  8575. d: function(d, p) {
  8576. return d3_time_formatPad(d.getDate(), p, 2);
  8577. },
  8578. e: function(d, p) {
  8579. return d3_time_formatPad(d.getDate(), p, 2);
  8580. },
  8581. H: function(d, p) {
  8582. return d3_time_formatPad(d.getHours(), p, 2);
  8583. },
  8584. I: function(d, p) {
  8585. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  8586. },
  8587. j: function(d, p) {
  8588. return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
  8589. },
  8590. L: function(d, p) {
  8591. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  8592. },
  8593. m: function(d, p) {
  8594. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  8595. },
  8596. M: function(d, p) {
  8597. return d3_time_formatPad(d.getMinutes(), p, 2);
  8598. },
  8599. p: function(d) {
  8600. return d.getHours() >= 12 ? "PM" : "AM";
  8601. },
  8602. S: function(d, p) {
  8603. return d3_time_formatPad(d.getSeconds(), p, 2);
  8604. },
  8605. U: function(d, p) {
  8606. return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
  8607. },
  8608. w: function(d) {
  8609. return d.getDay();
  8610. },
  8611. W: function(d, p) {
  8612. return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
  8613. },
  8614. x: d3_time_format(d3_time_formatDate),
  8615. X: d3_time_format(d3_time_formatTime),
  8616. y: function(d, p) {
  8617. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  8618. },
  8619. Y: function(d, p) {
  8620. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  8621. },
  8622. Z: d3_time_zone,
  8623. "%": function() {
  8624. return "%";
  8625. }
  8626. };
  8627. var d3_time_parsers = {
  8628. a: d3_time_parseWeekdayAbbrev,
  8629. A: d3_time_parseWeekday,
  8630. b: d3_time_parseMonthAbbrev,
  8631. B: d3_time_parseMonth,
  8632. c: d3_time_parseLocaleFull,
  8633. d: d3_time_parseDay,
  8634. e: d3_time_parseDay,
  8635. H: d3_time_parseHour24,
  8636. I: d3_time_parseHour24,
  8637. j: d3_time_parseDayOfYear,
  8638. L: d3_time_parseMilliseconds,
  8639. m: d3_time_parseMonthNumber,
  8640. M: d3_time_parseMinutes,
  8641. p: d3_time_parseAmPm,
  8642. S: d3_time_parseSeconds,
  8643. U: d3_time_parseWeekNumberSunday,
  8644. w: d3_time_parseWeekdayNumber,
  8645. W: d3_time_parseWeekNumberMonday,
  8646. x: d3_time_parseLocaleDate,
  8647. X: d3_time_parseLocaleTime,
  8648. y: d3_time_parseYear,
  8649. Y: d3_time_parseFullYear,
  8650. Z: d3_time_parseZone,
  8651. "%": d3_time_parseLiteralPercent
  8652. };
  8653. function d3_time_parseWeekdayAbbrev(date, string, i) {
  8654. d3_time_dayAbbrevRe.lastIndex = 0;
  8655. var n = d3_time_dayAbbrevRe.exec(string.substring(i));
  8656. return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  8657. }
  8658. function d3_time_parseWeekday(date, string, i) {
  8659. d3_time_dayRe.lastIndex = 0;
  8660. var n = d3_time_dayRe.exec(string.substring(i));
  8661. return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  8662. }
  8663. function d3_time_parseWeekdayNumber(date, string, i) {
  8664. d3_time_numberRe.lastIndex = 0;
  8665. var n = d3_time_numberRe.exec(string.substring(i, i + 1));
  8666. return n ? (date.w = +n[0], i + n[0].length) : -1;
  8667. }
  8668. function d3_time_parseWeekNumberSunday(date, string, i) {
  8669. d3_time_numberRe.lastIndex = 0;
  8670. var n = d3_time_numberRe.exec(string.substring(i));
  8671. return n ? (date.U = +n[0], i + n[0].length) : -1;
  8672. }
  8673. function d3_time_parseWeekNumberMonday(date, string, i) {
  8674. d3_time_numberRe.lastIndex = 0;
  8675. var n = d3_time_numberRe.exec(string.substring(i));
  8676. return n ? (date.W = +n[0], i + n[0].length) : -1;
  8677. }
  8678. function d3_time_parseMonthAbbrev(date, string, i) {
  8679. d3_time_monthAbbrevRe.lastIndex = 0;
  8680. var n = d3_time_monthAbbrevRe.exec(string.substring(i));
  8681. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  8682. }
  8683. function d3_time_parseMonth(date, string, i) {
  8684. d3_time_monthRe.lastIndex = 0;
  8685. var n = d3_time_monthRe.exec(string.substring(i));
  8686. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  8687. }
  8688. function d3_time_parseLocaleFull(date, string, i) {
  8689. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  8690. }
  8691. function d3_time_parseLocaleDate(date, string, i) {
  8692. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  8693. }
  8694. function d3_time_parseLocaleTime(date, string, i) {
  8695. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  8696. }
  8697. function d3_time_parseFullYear(date, string, i) {
  8698. d3_time_numberRe.lastIndex = 0;
  8699. var n = d3_time_numberRe.exec(string.substring(i, i + 4));
  8700. return n ? (date.y = +n[0], i + n[0].length) : -1;
  8701. }
  8702. function d3_time_parseYear(date, string, i) {
  8703. d3_time_numberRe.lastIndex = 0;
  8704. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8705. return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
  8706. }
  8707. function d3_time_parseZone(date, string, i) {
  8708. return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = +string,
  8709. i + 5) : -1;
  8710. }
  8711. function d3_time_expandYear(d) {
  8712. return d + (d > 68 ? 1900 : 2e3);
  8713. }
  8714. function d3_time_parseMonthNumber(date, string, i) {
  8715. d3_time_numberRe.lastIndex = 0;
  8716. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8717. return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
  8718. }
  8719. function d3_time_parseDay(date, string, i) {
  8720. d3_time_numberRe.lastIndex = 0;
  8721. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8722. return n ? (date.d = +n[0], i + n[0].length) : -1;
  8723. }
  8724. function d3_time_parseDayOfYear(date, string, i) {
  8725. d3_time_numberRe.lastIndex = 0;
  8726. var n = d3_time_numberRe.exec(string.substring(i, i + 3));
  8727. return n ? (date.j = +n[0], i + n[0].length) : -1;
  8728. }
  8729. function d3_time_parseHour24(date, string, i) {
  8730. d3_time_numberRe.lastIndex = 0;
  8731. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8732. return n ? (date.H = +n[0], i + n[0].length) : -1;
  8733. }
  8734. function d3_time_parseMinutes(date, string, i) {
  8735. d3_time_numberRe.lastIndex = 0;
  8736. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8737. return n ? (date.M = +n[0], i + n[0].length) : -1;
  8738. }
  8739. function d3_time_parseSeconds(date, string, i) {
  8740. d3_time_numberRe.lastIndex = 0;
  8741. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  8742. return n ? (date.S = +n[0], i + n[0].length) : -1;
  8743. }
  8744. function d3_time_parseMilliseconds(date, string, i) {
  8745. d3_time_numberRe.lastIndex = 0;
  8746. var n = d3_time_numberRe.exec(string.substring(i, i + 3));
  8747. return n ? (date.L = +n[0], i + n[0].length) : -1;
  8748. }
  8749. var d3_time_numberRe = /^\s*\d+/;
  8750. function d3_time_parseAmPm(date, string, i) {
  8751. var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
  8752. return n == null ? -1 : (date.p = n, i);
  8753. }
  8754. var d3_time_amPmLookup = d3.map({
  8755. am: 0,
  8756. pm: 1
  8757. });
  8758. function d3_time_zone(d) {
  8759. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(Math.abs(z) / 60), zm = Math.abs(z) % 60;
  8760. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  8761. }
  8762. function d3_time_parseLiteralPercent(date, string, i) {
  8763. d3_time_percentRe.lastIndex = 0;
  8764. var n = d3_time_percentRe.exec(string.substring(i, i + 1));
  8765. return n ? i + n[0].length : -1;
  8766. }
  8767. d3_time_format.utc = d3_time_formatUtc;
  8768. function d3_time_formatUtc(template) {
  8769. var local = d3_time_format(template);
  8770. function format(date) {
  8771. try {
  8772. d3_date = d3_date_utc;
  8773. var utc = new d3_date();
  8774. utc._ = date;
  8775. return local(utc);
  8776. } finally {
  8777. d3_date = Date;
  8778. }
  8779. }
  8780. format.parse = function(string) {
  8781. try {
  8782. d3_date = d3_date_utc;
  8783. var date = local.parse(string);
  8784. return date && date._;
  8785. } finally {
  8786. d3_date = Date;
  8787. }
  8788. };
  8789. format.toString = local.toString;
  8790. return format;
  8791. }
  8792. var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
  8793. d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  8794. function d3_time_formatIsoNative(date) {
  8795. return date.toISOString();
  8796. }
  8797. d3_time_formatIsoNative.parse = function(string) {
  8798. var date = new Date(string);
  8799. return isNaN(date) ? null : date;
  8800. };
  8801. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  8802. d3_time.second = d3_time_interval(function(date) {
  8803. return new d3_date(Math.floor(date / 1e3) * 1e3);
  8804. }, function(date, offset) {
  8805. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  8806. }, function(date) {
  8807. return date.getSeconds();
  8808. });
  8809. d3_time.seconds = d3_time.second.range;
  8810. d3_time.seconds.utc = d3_time.second.utc.range;
  8811. d3_time.minute = d3_time_interval(function(date) {
  8812. return new d3_date(Math.floor(date / 6e4) * 6e4);
  8813. }, function(date, offset) {
  8814. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  8815. }, function(date) {
  8816. return date.getMinutes();
  8817. });
  8818. d3_time.minutes = d3_time.minute.range;
  8819. d3_time.minutes.utc = d3_time.minute.utc.range;
  8820. d3_time.hour = d3_time_interval(function(date) {
  8821. var timezone = date.getTimezoneOffset() / 60;
  8822. return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  8823. }, function(date, offset) {
  8824. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  8825. }, function(date) {
  8826. return date.getHours();
  8827. });
  8828. d3_time.hours = d3_time.hour.range;
  8829. d3_time.hours.utc = d3_time.hour.utc.range;
  8830. d3_time.month = d3_time_interval(function(date) {
  8831. date = d3_time.day(date);
  8832. date.setDate(1);
  8833. return date;
  8834. }, function(date, offset) {
  8835. date.setMonth(date.getMonth() + offset);
  8836. }, function(date) {
  8837. return date.getMonth();
  8838. });
  8839. d3_time.months = d3_time.month.range;
  8840. d3_time.months.utc = d3_time.month.utc.range;
  8841. function d3_time_scale(linear, methods, format) {
  8842. function scale(x) {
  8843. return linear(x);
  8844. }
  8845. scale.invert = function(x) {
  8846. return d3_time_scaleDate(linear.invert(x));
  8847. };
  8848. scale.domain = function(x) {
  8849. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  8850. linear.domain(x);
  8851. return scale;
  8852. };
  8853. function tickMethod(extent, count) {
  8854. var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
  8855. return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
  8856. return d / 31536e6;
  8857. }), 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];
  8858. }
  8859. scale.nice = function(interval, skip) {
  8860. var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
  8861. if (method) interval = method[0], skip = method[1];
  8862. function skipped(date) {
  8863. return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
  8864. }
  8865. return scale.domain(d3_scale_nice(domain, skip > 1 ? {
  8866. floor: function(date) {
  8867. while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
  8868. return date;
  8869. },
  8870. ceil: function(date) {
  8871. while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
  8872. return date;
  8873. }
  8874. } : interval));
  8875. };
  8876. scale.ticks = function(interval, skip) {
  8877. var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
  8878. range: interval
  8879. }, skip ];
  8880. if (method) interval = method[0], skip = method[1];
  8881. return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
  8882. };
  8883. scale.tickFormat = function() {
  8884. return format;
  8885. };
  8886. scale.copy = function() {
  8887. return d3_time_scale(linear.copy(), methods, format);
  8888. };
  8889. return d3_scale_linearRebind(scale, linear);
  8890. }
  8891. function d3_time_scaleDate(t) {
  8892. return new Date(t);
  8893. }
  8894. function d3_time_scaleFormat(formats) {
  8895. return function(date) {
  8896. var i = formats.length - 1, f = formats[i];
  8897. while (!f[1](date)) f = formats[--i];
  8898. return f[0](date);
  8899. };
  8900. }
  8901. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  8902. 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 ] ];
  8903. var d3_time_scaleLocalFormats = [ [ d3_time_format("%Y"), d3_true ], [ d3_time_format("%B"), function(d) {
  8904. return d.getMonth();
  8905. } ], [ d3_time_format("%b %d"), function(d) {
  8906. return d.getDate() != 1;
  8907. } ], [ d3_time_format("%a %d"), function(d) {
  8908. return d.getDay() && d.getDate() != 1;
  8909. } ], [ d3_time_format("%I %p"), function(d) {
  8910. return d.getHours();
  8911. } ], [ d3_time_format("%I:%M"), function(d) {
  8912. return d.getMinutes();
  8913. } ], [ d3_time_format(":%S"), function(d) {
  8914. return d.getSeconds();
  8915. } ], [ d3_time_format(".%L"), function(d) {
  8916. return d.getMilliseconds();
  8917. } ] ];
  8918. var d3_time_scaleLocalFormat = d3_time_scaleFormat(d3_time_scaleLocalFormats);
  8919. d3_time_scaleLocalMethods.year = d3_time.year;
  8920. d3_time.scale = function() {
  8921. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  8922. };
  8923. var d3_time_scaleMilliseconds = {
  8924. range: function(start, stop, step) {
  8925. return d3.range(+start, +stop, step).map(d3_time_scaleDate);
  8926. }
  8927. };
  8928. var d3_time_scaleUTCMethods = d3_time_scaleLocalMethods.map(function(m) {
  8929. return [ m[0].utc, m[1] ];
  8930. });
  8931. var d3_time_scaleUTCFormats = [ [ d3_time_formatUtc("%Y"), d3_true ], [ d3_time_formatUtc("%B"), function(d) {
  8932. return d.getUTCMonth();
  8933. } ], [ d3_time_formatUtc("%b %d"), function(d) {
  8934. return d.getUTCDate() != 1;
  8935. } ], [ d3_time_formatUtc("%a %d"), function(d) {
  8936. return d.getUTCDay() && d.getUTCDate() != 1;
  8937. } ], [ d3_time_formatUtc("%I %p"), function(d) {
  8938. return d.getUTCHours();
  8939. } ], [ d3_time_formatUtc("%I:%M"), function(d) {
  8940. return d.getUTCMinutes();
  8941. } ], [ d3_time_formatUtc(":%S"), function(d) {
  8942. return d.getUTCSeconds();
  8943. } ], [ d3_time_formatUtc(".%L"), function(d) {
  8944. return d.getUTCMilliseconds();
  8945. } ] ];
  8946. var d3_time_scaleUTCFormat = d3_time_scaleFormat(d3_time_scaleUTCFormats);
  8947. d3_time_scaleUTCMethods.year = d3_time.year.utc;
  8948. d3_time.scale.utc = function() {
  8949. return d3_time_scale(d3.scale.linear(), d3_time_scaleUTCMethods, d3_time_scaleUTCFormat);
  8950. };
  8951. d3.text = d3_xhrType(function(request) {
  8952. return request.responseText;
  8953. });
  8954. d3.json = function(url, callback) {
  8955. return d3_xhr(url, "application/json", d3_json, callback);
  8956. };
  8957. function d3_json(request) {
  8958. return JSON.parse(request.responseText);
  8959. }
  8960. d3.html = function(url, callback) {
  8961. return d3_xhr(url, "text/html", d3_html, callback);
  8962. };
  8963. function d3_html(request) {
  8964. var range = d3_document.createRange();
  8965. range.selectNode(d3_document.body);
  8966. return range.createContextualFragment(request.responseText);
  8967. }
  8968. d3.xml = d3_xhrType(function(request) {
  8969. return request.responseXML;
  8970. });
  8971. return d3;
  8972. }();