d3.js 370 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233
  1. !function() {
  2. var d3 = {
  3. version: "3.4.11"
  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 = d3_ascending;
  36. function d3_ascending(a, b) {
  37. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  38. }
  39. d3.descending = function(a, b) {
  40. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  41. };
  42. d3.min = function(array, f) {
  43. var i = -1, n = array.length, a, b;
  44. if (arguments.length === 1) {
  45. while (++i < n && !((a = array[i]) != null && a <= a)) a = undefined;
  46. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  47. } else {
  48. while (++i < n && !((a = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
  49. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  50. }
  51. return a;
  52. };
  53. d3.max = function(array, f) {
  54. var i = -1, n = array.length, a, b;
  55. if (arguments.length === 1) {
  56. while (++i < n && !((a = array[i]) != null && a <= a)) a = undefined;
  57. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  58. } else {
  59. while (++i < n && !((a = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
  60. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  61. }
  62. return a;
  63. };
  64. d3.extent = function(array, f) {
  65. var i = -1, n = array.length, a, b, c;
  66. if (arguments.length === 1) {
  67. while (++i < n && !((a = c = array[i]) != null && a <= a)) a = c = undefined;
  68. while (++i < n) if ((b = array[i]) != null) {
  69. if (a > b) a = b;
  70. if (c < b) c = b;
  71. }
  72. } else {
  73. while (++i < n && !((a = c = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
  74. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  75. if (a > b) a = b;
  76. if (c < b) c = b;
  77. }
  78. }
  79. return [ a, c ];
  80. };
  81. d3.sum = function(array, f) {
  82. var s = 0, n = array.length, a, i = -1;
  83. if (arguments.length === 1) {
  84. while (++i < n) if (!isNaN(a = +array[i])) s += a;
  85. } else {
  86. while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
  87. }
  88. return s;
  89. };
  90. function d3_number(x) {
  91. return x != null && !isNaN(x);
  92. }
  93. d3.mean = function(array, f) {
  94. var s = 0, n = array.length, a, i = -1, j = n;
  95. if (arguments.length === 1) {
  96. while (++i < n) if (d3_number(a = array[i])) s += a; else --j;
  97. } else {
  98. while (++i < n) if (d3_number(a = f.call(array, array[i], i))) s += a; else --j;
  99. }
  100. return j ? s / j : undefined;
  101. };
  102. d3.quantile = function(values, p) {
  103. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  104. return e ? v + e * (values[h] - v) : v;
  105. };
  106. d3.median = function(array, f) {
  107. if (arguments.length > 1) array = array.map(f);
  108. array = array.filter(d3_number);
  109. return array.length ? d3.quantile(array.sort(d3_ascending), .5) : undefined;
  110. };
  111. function d3_bisector(compare) {
  112. return {
  113. left: function(a, x, lo, hi) {
  114. if (arguments.length < 3) lo = 0;
  115. if (arguments.length < 4) hi = a.length;
  116. while (lo < hi) {
  117. var mid = lo + hi >>> 1;
  118. if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
  119. }
  120. return lo;
  121. },
  122. right: function(a, x, lo, hi) {
  123. if (arguments.length < 3) lo = 0;
  124. if (arguments.length < 4) hi = a.length;
  125. while (lo < hi) {
  126. var mid = lo + hi >>> 1;
  127. if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
  128. }
  129. return lo;
  130. }
  131. };
  132. }
  133. var d3_bisect = d3_bisector(d3_ascending);
  134. d3.bisectLeft = d3_bisect.left;
  135. d3.bisect = d3.bisectRight = d3_bisect.right;
  136. d3.bisector = function(f) {
  137. return d3_bisector(f.length === 1 ? function(d, x) {
  138. return d3_ascending(f(d), x);
  139. } : f);
  140. };
  141. d3.shuffle = function(array) {
  142. var m = array.length, t, i;
  143. while (m) {
  144. i = Math.random() * m-- | 0;
  145. t = array[m], array[m] = array[i], array[i] = t;
  146. }
  147. return array;
  148. };
  149. d3.permute = function(array, indexes) {
  150. var i = indexes.length, permutes = new Array(i);
  151. while (i--) permutes[i] = array[indexes[i]];
  152. return permutes;
  153. };
  154. d3.pairs = function(array) {
  155. var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
  156. while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
  157. return pairs;
  158. };
  159. d3.zip = function() {
  160. if (!(n = arguments.length)) return [];
  161. for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
  162. for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
  163. zip[j] = arguments[j][i];
  164. }
  165. }
  166. return zips;
  167. };
  168. function d3_zipLength(d) {
  169. return d.length;
  170. }
  171. d3.transpose = function(matrix) {
  172. return d3.zip.apply(d3, matrix);
  173. };
  174. d3.keys = function(map) {
  175. var keys = [];
  176. for (var key in map) keys.push(key);
  177. return keys;
  178. };
  179. d3.values = function(map) {
  180. var values = [];
  181. for (var key in map) values.push(map[key]);
  182. return values;
  183. };
  184. d3.entries = function(map) {
  185. var entries = [];
  186. for (var key in map) entries.push({
  187. key: key,
  188. value: map[key]
  189. });
  190. return entries;
  191. };
  192. d3.merge = function(arrays) {
  193. var n = arrays.length, m, i = -1, j = 0, merged, array;
  194. while (++i < n) j += arrays[i].length;
  195. merged = new Array(j);
  196. while (--n >= 0) {
  197. array = arrays[n];
  198. m = array.length;
  199. while (--m >= 0) {
  200. merged[--j] = array[m];
  201. }
  202. }
  203. return merged;
  204. };
  205. var abs = Math.abs;
  206. d3.range = function(start, stop, step) {
  207. if (arguments.length < 3) {
  208. step = 1;
  209. if (arguments.length < 2) {
  210. stop = start;
  211. start = 0;
  212. }
  213. }
  214. if ((stop - start) / step === Infinity) throw new Error("infinite range");
  215. var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
  216. start *= k, stop *= k, step *= k;
  217. if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
  218. return range;
  219. };
  220. function d3_range_integerScale(x) {
  221. var k = 1;
  222. while (x * k % 1) k *= 10;
  223. return k;
  224. }
  225. function d3_class(ctor, properties) {
  226. try {
  227. for (var key in properties) {
  228. Object.defineProperty(ctor.prototype, key, {
  229. value: properties[key],
  230. enumerable: false
  231. });
  232. }
  233. } catch (e) {
  234. ctor.prototype = properties;
  235. }
  236. }
  237. d3.map = function(object) {
  238. var map = new d3_Map();
  239. if (object instanceof d3_Map) object.forEach(function(key, value) {
  240. map.set(key, value);
  241. }); else for (var key in object) map.set(key, object[key]);
  242. return map;
  243. };
  244. function d3_Map() {}
  245. d3_class(d3_Map, {
  246. has: d3_map_has,
  247. get: function(key) {
  248. return this[d3_map_prefix + key];
  249. },
  250. set: function(key, value) {
  251. return this[d3_map_prefix + key] = value;
  252. },
  253. remove: d3_map_remove,
  254. keys: d3_map_keys,
  255. values: function() {
  256. var values = [];
  257. this.forEach(function(key, value) {
  258. values.push(value);
  259. });
  260. return values;
  261. },
  262. entries: function() {
  263. var entries = [];
  264. this.forEach(function(key, value) {
  265. entries.push({
  266. key: key,
  267. value: value
  268. });
  269. });
  270. return entries;
  271. },
  272. size: d3_map_size,
  273. empty: d3_map_empty,
  274. forEach: function(f) {
  275. for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) f.call(this, key.substring(1), this[key]);
  276. }
  277. });
  278. var d3_map_prefix = "\x00", d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
  279. function d3_map_has(key) {
  280. return d3_map_prefix + key in this;
  281. }
  282. function d3_map_remove(key) {
  283. key = d3_map_prefix + key;
  284. return key in this && delete this[key];
  285. }
  286. function d3_map_keys() {
  287. var keys = [];
  288. this.forEach(function(key) {
  289. keys.push(key);
  290. });
  291. return keys;
  292. }
  293. function d3_map_size() {
  294. var size = 0;
  295. for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) ++size;
  296. return size;
  297. }
  298. function d3_map_empty() {
  299. for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) return false;
  300. return true;
  301. }
  302. d3.nest = function() {
  303. var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
  304. function map(mapType, array, depth) {
  305. if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
  306. var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
  307. while (++i < n) {
  308. if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
  309. values.push(object);
  310. } else {
  311. valuesByKey.set(keyValue, [ object ]);
  312. }
  313. }
  314. if (mapType) {
  315. object = mapType();
  316. setter = function(keyValue, values) {
  317. object.set(keyValue, map(mapType, values, depth));
  318. };
  319. } else {
  320. object = {};
  321. setter = function(keyValue, values) {
  322. object[keyValue] = map(mapType, values, depth);
  323. };
  324. }
  325. valuesByKey.forEach(setter);
  326. return object;
  327. }
  328. function entries(map, depth) {
  329. if (depth >= keys.length) return map;
  330. var array = [], sortKey = sortKeys[depth++];
  331. map.forEach(function(key, keyMap) {
  332. array.push({
  333. key: key,
  334. values: entries(keyMap, depth)
  335. });
  336. });
  337. return sortKey ? array.sort(function(a, b) {
  338. return sortKey(a.key, b.key);
  339. }) : array;
  340. }
  341. nest.map = function(array, mapType) {
  342. return map(mapType, array, 0);
  343. };
  344. nest.entries = function(array) {
  345. return entries(map(d3.map, array, 0), 0);
  346. };
  347. nest.key = function(d) {
  348. keys.push(d);
  349. return nest;
  350. };
  351. nest.sortKeys = function(order) {
  352. sortKeys[keys.length - 1] = order;
  353. return nest;
  354. };
  355. nest.sortValues = function(order) {
  356. sortValues = order;
  357. return nest;
  358. };
  359. nest.rollup = function(f) {
  360. rollup = f;
  361. return nest;
  362. };
  363. return nest;
  364. };
  365. d3.set = function(array) {
  366. var set = new d3_Set();
  367. if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
  368. return set;
  369. };
  370. function d3_Set() {}
  371. d3_class(d3_Set, {
  372. has: d3_map_has,
  373. add: function(value) {
  374. this[d3_map_prefix + value] = true;
  375. return value;
  376. },
  377. remove: function(value) {
  378. value = d3_map_prefix + value;
  379. return value in this && delete this[value];
  380. },
  381. values: d3_map_keys,
  382. size: d3_map_size,
  383. empty: d3_map_empty,
  384. forEach: function(f) {
  385. for (var value in this) if (value.charCodeAt(0) === d3_map_prefixCode) f.call(this, value.substring(1));
  386. }
  387. });
  388. d3.behavior = {};
  389. d3.rebind = function(target, source) {
  390. var i = 1, n = arguments.length, method;
  391. while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
  392. return target;
  393. };
  394. function d3_rebind(target, source, method) {
  395. return function() {
  396. var value = method.apply(source, arguments);
  397. return value === source ? target : value;
  398. };
  399. }
  400. function d3_vendorSymbol(object, name) {
  401. if (name in object) return name;
  402. name = name.charAt(0).toUpperCase() + name.substring(1);
  403. for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
  404. var prefixName = d3_vendorPrefixes[i] + name;
  405. if (prefixName in object) return prefixName;
  406. }
  407. }
  408. var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
  409. function d3_noop() {}
  410. d3.dispatch = function() {
  411. var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
  412. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  413. return dispatch;
  414. };
  415. function d3_dispatch() {}
  416. d3_dispatch.prototype.on = function(type, listener) {
  417. var i = type.indexOf("."), name = "";
  418. if (i >= 0) {
  419. name = type.substring(i + 1);
  420. type = type.substring(0, i);
  421. }
  422. if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
  423. if (arguments.length === 2) {
  424. if (listener == null) for (type in this) {
  425. if (this.hasOwnProperty(type)) this[type].on(name, null);
  426. }
  427. return this;
  428. }
  429. };
  430. function d3_dispatch_event(dispatch) {
  431. var listeners = [], listenerByName = new d3_Map();
  432. function event() {
  433. var z = listeners, i = -1, n = z.length, l;
  434. while (++i < n) if (l = z[i].on) l.apply(this, arguments);
  435. return dispatch;
  436. }
  437. event.on = function(name, listener) {
  438. var l = listenerByName.get(name), i;
  439. if (arguments.length < 2) return l && l.on;
  440. if (l) {
  441. l.on = null;
  442. listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
  443. listenerByName.remove(name);
  444. }
  445. if (listener) listeners.push(listenerByName.set(name, {
  446. on: listener
  447. }));
  448. return dispatch;
  449. };
  450. return event;
  451. }
  452. d3.event = null;
  453. function d3_eventPreventDefault() {
  454. d3.event.preventDefault();
  455. }
  456. function d3_eventSource() {
  457. var e = d3.event, s;
  458. while (s = e.sourceEvent) e = s;
  459. return e;
  460. }
  461. function d3_eventDispatch(target) {
  462. var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
  463. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  464. dispatch.of = function(thiz, argumentz) {
  465. return function(e1) {
  466. try {
  467. var e0 = e1.sourceEvent = d3.event;
  468. e1.target = target;
  469. d3.event = e1;
  470. dispatch[e1.type].apply(thiz, argumentz);
  471. } finally {
  472. d3.event = e0;
  473. }
  474. };
  475. };
  476. return dispatch;
  477. }
  478. d3.requote = function(s) {
  479. return s.replace(d3_requote_re, "\\$&");
  480. };
  481. var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  482. var d3_subclass = {}.__proto__ ? function(object, prototype) {
  483. object.__proto__ = prototype;
  484. } : function(object, prototype) {
  485. for (var property in prototype) object[property] = prototype[property];
  486. };
  487. function d3_selection(groups) {
  488. d3_subclass(groups, d3_selectionPrototype);
  489. return groups;
  490. }
  491. var d3_select = function(s, n) {
  492. return n.querySelector(s);
  493. }, d3_selectAll = function(s, n) {
  494. return n.querySelectorAll(s);
  495. }, d3_selectMatcher = d3_documentElement.matches || d3_documentElement[d3_vendorSymbol(d3_documentElement, "matchesSelector")], d3_selectMatches = function(n, s) {
  496. return d3_selectMatcher.call(n, s);
  497. };
  498. if (typeof Sizzle === "function") {
  499. d3_select = function(s, n) {
  500. return Sizzle(s, n)[0] || null;
  501. };
  502. d3_selectAll = Sizzle;
  503. d3_selectMatches = Sizzle.matchesSelector;
  504. }
  505. d3.selection = function() {
  506. return d3_selectionRoot;
  507. };
  508. var d3_selectionPrototype = d3.selection.prototype = [];
  509. d3_selectionPrototype.select = function(selector) {
  510. var subgroups = [], subgroup, subnode, group, node;
  511. selector = d3_selection_selector(selector);
  512. for (var j = -1, m = this.length; ++j < m; ) {
  513. subgroups.push(subgroup = []);
  514. subgroup.parentNode = (group = this[j]).parentNode;
  515. for (var i = -1, n = group.length; ++i < n; ) {
  516. if (node = group[i]) {
  517. subgroup.push(subnode = selector.call(node, node.__data__, i, j));
  518. if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
  519. } else {
  520. subgroup.push(null);
  521. }
  522. }
  523. }
  524. return d3_selection(subgroups);
  525. };
  526. function d3_selection_selector(selector) {
  527. return typeof selector === "function" ? selector : function() {
  528. return d3_select(selector, this);
  529. };
  530. }
  531. d3_selectionPrototype.selectAll = function(selector) {
  532. var subgroups = [], subgroup, node;
  533. selector = d3_selection_selectorAll(selector);
  534. for (var j = -1, m = this.length; ++j < m; ) {
  535. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  536. if (node = group[i]) {
  537. subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
  538. subgroup.parentNode = node;
  539. }
  540. }
  541. }
  542. return d3_selection(subgroups);
  543. };
  544. function d3_selection_selectorAll(selector) {
  545. return typeof selector === "function" ? selector : function() {
  546. return d3_selectAll(selector, this);
  547. };
  548. }
  549. var d3_nsPrefix = {
  550. svg: "http://www.w3.org/2000/svg",
  551. xhtml: "http://www.w3.org/1999/xhtml",
  552. xlink: "http://www.w3.org/1999/xlink",
  553. xml: "http://www.w3.org/XML/1998/namespace",
  554. xmlns: "http://www.w3.org/2000/xmlns/"
  555. };
  556. d3.ns = {
  557. prefix: d3_nsPrefix,
  558. qualify: function(name) {
  559. var i = name.indexOf(":"), prefix = name;
  560. if (i >= 0) {
  561. prefix = name.substring(0, i);
  562. name = name.substring(i + 1);
  563. }
  564. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  565. space: d3_nsPrefix[prefix],
  566. local: name
  567. } : name;
  568. }
  569. };
  570. d3_selectionPrototype.attr = function(name, value) {
  571. if (arguments.length < 2) {
  572. if (typeof name === "string") {
  573. var node = this.node();
  574. name = d3.ns.qualify(name);
  575. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  576. }
  577. for (value in name) this.each(d3_selection_attr(value, name[value]));
  578. return this;
  579. }
  580. return this.each(d3_selection_attr(name, value));
  581. };
  582. function d3_selection_attr(name, value) {
  583. name = d3.ns.qualify(name);
  584. function attrNull() {
  585. this.removeAttribute(name);
  586. }
  587. function attrNullNS() {
  588. this.removeAttributeNS(name.space, name.local);
  589. }
  590. function attrConstant() {
  591. this.setAttribute(name, value);
  592. }
  593. function attrConstantNS() {
  594. this.setAttributeNS(name.space, name.local, value);
  595. }
  596. function attrFunction() {
  597. var x = value.apply(this, arguments);
  598. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  599. }
  600. function attrFunctionNS() {
  601. var x = value.apply(this, arguments);
  602. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  603. }
  604. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  605. }
  606. function d3_collapse(s) {
  607. return s.trim().replace(/\s+/g, " ");
  608. }
  609. d3_selectionPrototype.classed = function(name, value) {
  610. if (arguments.length < 2) {
  611. if (typeof name === "string") {
  612. var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
  613. if (value = node.classList) {
  614. while (++i < n) if (!value.contains(name[i])) return false;
  615. } else {
  616. value = node.getAttribute("class");
  617. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  618. }
  619. return true;
  620. }
  621. for (value in name) this.each(d3_selection_classed(value, name[value]));
  622. return this;
  623. }
  624. return this.each(d3_selection_classed(name, value));
  625. };
  626. function d3_selection_classedRe(name) {
  627. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  628. }
  629. function d3_selection_classes(name) {
  630. return (name + "").trim().split(/^|\s+/);
  631. }
  632. function d3_selection_classed(name, value) {
  633. name = d3_selection_classes(name).map(d3_selection_classedName);
  634. var n = name.length;
  635. function classedConstant() {
  636. var i = -1;
  637. while (++i < n) name[i](this, value);
  638. }
  639. function classedFunction() {
  640. var i = -1, x = value.apply(this, arguments);
  641. while (++i < n) name[i](this, x);
  642. }
  643. return typeof value === "function" ? classedFunction : classedConstant;
  644. }
  645. function d3_selection_classedName(name) {
  646. var re = d3_selection_classedRe(name);
  647. return function(node, value) {
  648. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  649. var c = node.getAttribute("class") || "";
  650. if (value) {
  651. re.lastIndex = 0;
  652. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  653. } else {
  654. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  655. }
  656. };
  657. }
  658. d3_selectionPrototype.style = function(name, value, priority) {
  659. var n = arguments.length;
  660. if (n < 3) {
  661. if (typeof name !== "string") {
  662. if (n < 2) value = "";
  663. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  664. return this;
  665. }
  666. if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
  667. priority = "";
  668. }
  669. return this.each(d3_selection_style(name, value, priority));
  670. };
  671. function d3_selection_style(name, value, priority) {
  672. function styleNull() {
  673. this.style.removeProperty(name);
  674. }
  675. function styleConstant() {
  676. this.style.setProperty(name, value, priority);
  677. }
  678. function styleFunction() {
  679. var x = value.apply(this, arguments);
  680. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  681. }
  682. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  683. }
  684. d3_selectionPrototype.property = function(name, value) {
  685. if (arguments.length < 2) {
  686. if (typeof name === "string") return this.node()[name];
  687. for (value in name) this.each(d3_selection_property(value, name[value]));
  688. return this;
  689. }
  690. return this.each(d3_selection_property(name, value));
  691. };
  692. function d3_selection_property(name, value) {
  693. function propertyNull() {
  694. delete this[name];
  695. }
  696. function propertyConstant() {
  697. this[name] = value;
  698. }
  699. function propertyFunction() {
  700. var x = value.apply(this, arguments);
  701. if (x == null) delete this[name]; else this[name] = x;
  702. }
  703. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  704. }
  705. d3_selectionPrototype.text = function(value) {
  706. return arguments.length ? this.each(typeof value === "function" ? function() {
  707. var v = value.apply(this, arguments);
  708. this.textContent = v == null ? "" : v;
  709. } : value == null ? function() {
  710. this.textContent = "";
  711. } : function() {
  712. this.textContent = value;
  713. }) : this.node().textContent;
  714. };
  715. d3_selectionPrototype.html = function(value) {
  716. return arguments.length ? this.each(typeof value === "function" ? function() {
  717. var v = value.apply(this, arguments);
  718. this.innerHTML = v == null ? "" : v;
  719. } : value == null ? function() {
  720. this.innerHTML = "";
  721. } : function() {
  722. this.innerHTML = value;
  723. }) : this.node().innerHTML;
  724. };
  725. d3_selectionPrototype.append = function(name) {
  726. name = d3_selection_creator(name);
  727. return this.select(function() {
  728. return this.appendChild(name.apply(this, arguments));
  729. });
  730. };
  731. function d3_selection_creator(name) {
  732. return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? function() {
  733. return this.ownerDocument.createElementNS(name.space, name.local);
  734. } : function() {
  735. return this.ownerDocument.createElementNS(this.namespaceURI, name);
  736. };
  737. }
  738. d3_selectionPrototype.insert = function(name, before) {
  739. name = d3_selection_creator(name);
  740. before = d3_selection_selector(before);
  741. return this.select(function() {
  742. return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
  743. });
  744. };
  745. d3_selectionPrototype.remove = function() {
  746. return this.each(function() {
  747. var parent = this.parentNode;
  748. if (parent) parent.removeChild(this);
  749. });
  750. };
  751. d3_selectionPrototype.data = function(value, key) {
  752. var i = -1, n = this.length, group, node;
  753. if (!arguments.length) {
  754. value = new Array(n = (group = this[0]).length);
  755. while (++i < n) {
  756. if (node = group[i]) {
  757. value[i] = node.__data__;
  758. }
  759. }
  760. return value;
  761. }
  762. function bind(group, groupData) {
  763. 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;
  764. if (key) {
  765. var nodeByKeyValue = new d3_Map(), dataByKeyValue = new d3_Map(), keyValues = [], keyValue;
  766. for (i = -1; ++i < n; ) {
  767. keyValue = key.call(node = group[i], node.__data__, i);
  768. if (nodeByKeyValue.has(keyValue)) {
  769. exitNodes[i] = node;
  770. } else {
  771. nodeByKeyValue.set(keyValue, node);
  772. }
  773. keyValues.push(keyValue);
  774. }
  775. for (i = -1; ++i < m; ) {
  776. keyValue = key.call(groupData, nodeData = groupData[i], i);
  777. if (node = nodeByKeyValue.get(keyValue)) {
  778. updateNodes[i] = node;
  779. node.__data__ = nodeData;
  780. } else if (!dataByKeyValue.has(keyValue)) {
  781. enterNodes[i] = d3_selection_dataNode(nodeData);
  782. }
  783. dataByKeyValue.set(keyValue, nodeData);
  784. nodeByKeyValue.remove(keyValue);
  785. }
  786. for (i = -1; ++i < n; ) {
  787. if (nodeByKeyValue.has(keyValues[i])) {
  788. exitNodes[i] = group[i];
  789. }
  790. }
  791. } else {
  792. for (i = -1; ++i < n0; ) {
  793. node = group[i];
  794. nodeData = groupData[i];
  795. if (node) {
  796. node.__data__ = nodeData;
  797. updateNodes[i] = node;
  798. } else {
  799. enterNodes[i] = d3_selection_dataNode(nodeData);
  800. }
  801. }
  802. for (;i < m; ++i) {
  803. enterNodes[i] = d3_selection_dataNode(groupData[i]);
  804. }
  805. for (;i < n; ++i) {
  806. exitNodes[i] = group[i];
  807. }
  808. }
  809. enterNodes.update = updateNodes;
  810. enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
  811. enter.push(enterNodes);
  812. update.push(updateNodes);
  813. exit.push(exitNodes);
  814. }
  815. var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
  816. if (typeof value === "function") {
  817. while (++i < n) {
  818. bind(group = this[i], value.call(group, group.parentNode.__data__, i));
  819. }
  820. } else {
  821. while (++i < n) {
  822. bind(group = this[i], value);
  823. }
  824. }
  825. update.enter = function() {
  826. return enter;
  827. };
  828. update.exit = function() {
  829. return exit;
  830. };
  831. return update;
  832. };
  833. function d3_selection_dataNode(data) {
  834. return {
  835. __data__: data
  836. };
  837. }
  838. d3_selectionPrototype.datum = function(value) {
  839. return arguments.length ? this.property("__data__", value) : this.property("__data__");
  840. };
  841. d3_selectionPrototype.filter = function(filter) {
  842. var subgroups = [], subgroup, group, node;
  843. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  844. for (var j = 0, m = this.length; j < m; j++) {
  845. subgroups.push(subgroup = []);
  846. subgroup.parentNode = (group = this[j]).parentNode;
  847. for (var i = 0, n = group.length; i < n; i++) {
  848. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  849. subgroup.push(node);
  850. }
  851. }
  852. }
  853. return d3_selection(subgroups);
  854. };
  855. function d3_selection_filter(selector) {
  856. return function() {
  857. return d3_selectMatches(this, selector);
  858. };
  859. }
  860. d3_selectionPrototype.order = function() {
  861. for (var j = -1, m = this.length; ++j < m; ) {
  862. for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
  863. if (node = group[i]) {
  864. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  865. next = node;
  866. }
  867. }
  868. }
  869. return this;
  870. };
  871. d3_selectionPrototype.sort = function(comparator) {
  872. comparator = d3_selection_sortComparator.apply(this, arguments);
  873. for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
  874. return this.order();
  875. };
  876. function d3_selection_sortComparator(comparator) {
  877. if (!arguments.length) comparator = d3_ascending;
  878. return function(a, b) {
  879. return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
  880. };
  881. }
  882. d3_selectionPrototype.each = function(callback) {
  883. return d3_selection_each(this, function(node, i, j) {
  884. callback.call(node, node.__data__, i, j);
  885. });
  886. };
  887. function d3_selection_each(groups, callback) {
  888. for (var j = 0, m = groups.length; j < m; j++) {
  889. for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
  890. if (node = group[i]) callback(node, i, j);
  891. }
  892. }
  893. return groups;
  894. }
  895. d3_selectionPrototype.call = function(callback) {
  896. var args = d3_array(arguments);
  897. callback.apply(args[0] = this, args);
  898. return this;
  899. };
  900. d3_selectionPrototype.empty = function() {
  901. return !this.node();
  902. };
  903. d3_selectionPrototype.node = function() {
  904. for (var j = 0, m = this.length; j < m; j++) {
  905. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  906. var node = group[i];
  907. if (node) return node;
  908. }
  909. }
  910. return null;
  911. };
  912. d3_selectionPrototype.size = function() {
  913. var n = 0;
  914. this.each(function() {
  915. ++n;
  916. });
  917. return n;
  918. };
  919. function d3_selection_enter(selection) {
  920. d3_subclass(selection, d3_selection_enterPrototype);
  921. return selection;
  922. }
  923. var d3_selection_enterPrototype = [];
  924. d3.selection.enter = d3_selection_enter;
  925. d3.selection.enter.prototype = d3_selection_enterPrototype;
  926. d3_selection_enterPrototype.append = d3_selectionPrototype.append;
  927. d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
  928. d3_selection_enterPrototype.node = d3_selectionPrototype.node;
  929. d3_selection_enterPrototype.call = d3_selectionPrototype.call;
  930. d3_selection_enterPrototype.size = d3_selectionPrototype.size;
  931. d3_selection_enterPrototype.select = function(selector) {
  932. var subgroups = [], subgroup, subnode, upgroup, group, node;
  933. for (var j = -1, m = this.length; ++j < m; ) {
  934. upgroup = (group = this[j]).update;
  935. subgroups.push(subgroup = []);
  936. subgroup.parentNode = group.parentNode;
  937. for (var i = -1, n = group.length; ++i < n; ) {
  938. if (node = group[i]) {
  939. subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
  940. subnode.__data__ = node.__data__;
  941. } else {
  942. subgroup.push(null);
  943. }
  944. }
  945. }
  946. return d3_selection(subgroups);
  947. };
  948. d3_selection_enterPrototype.insert = function(name, before) {
  949. if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
  950. return d3_selectionPrototype.insert.call(this, name, before);
  951. };
  952. function d3_selection_enterInsertBefore(enter) {
  953. var i0, j0;
  954. return function(d, i, j) {
  955. var group = enter[j].update, n = group.length, node;
  956. if (j != j0) j0 = j, i0 = 0;
  957. if (i >= i0) i0 = i + 1;
  958. while (!(node = group[i0]) && ++i0 < n) ;
  959. return node;
  960. };
  961. }
  962. d3_selectionPrototype.transition = function() {
  963. var id = d3_transitionInheritId || ++d3_transitionId, subgroups = [], subgroup, node, transition = d3_transitionInherit || {
  964. time: Date.now(),
  965. ease: d3_ease_cubicInOut,
  966. delay: 0,
  967. duration: 250
  968. };
  969. for (var j = -1, m = this.length; ++j < m; ) {
  970. subgroups.push(subgroup = []);
  971. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  972. if (node = group[i]) d3_transitionNode(node, i, id, transition);
  973. subgroup.push(node);
  974. }
  975. }
  976. return d3_transition(subgroups, id);
  977. };
  978. d3_selectionPrototype.interrupt = function() {
  979. return this.each(d3_selection_interrupt);
  980. };
  981. function d3_selection_interrupt() {
  982. var lock = this.__transition__;
  983. if (lock) ++lock.active;
  984. }
  985. d3.select = function(node) {
  986. var group = [ typeof node === "string" ? d3_select(node, d3_document) : node ];
  987. group.parentNode = d3_documentElement;
  988. return d3_selection([ group ]);
  989. };
  990. d3.selectAll = function(nodes) {
  991. var group = d3_array(typeof nodes === "string" ? d3_selectAll(nodes, d3_document) : nodes);
  992. group.parentNode = d3_documentElement;
  993. return d3_selection([ group ]);
  994. };
  995. var d3_selectionRoot = d3.select(d3_documentElement);
  996. d3_selectionPrototype.on = function(type, listener, capture) {
  997. var n = arguments.length;
  998. if (n < 3) {
  999. if (typeof type !== "string") {
  1000. if (n < 2) listener = false;
  1001. for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
  1002. return this;
  1003. }
  1004. if (n < 2) return (n = this.node()["__on" + type]) && n._;
  1005. capture = false;
  1006. }
  1007. return this.each(d3_selection_on(type, listener, capture));
  1008. };
  1009. function d3_selection_on(type, listener, capture) {
  1010. var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
  1011. if (i > 0) type = type.substring(0, i);
  1012. var filter = d3_selection_onFilters.get(type);
  1013. if (filter) type = filter, wrap = d3_selection_onFilter;
  1014. function onRemove() {
  1015. var l = this[name];
  1016. if (l) {
  1017. this.removeEventListener(type, l, l.$);
  1018. delete this[name];
  1019. }
  1020. }
  1021. function onAdd() {
  1022. var l = wrap(listener, d3_array(arguments));
  1023. onRemove.call(this);
  1024. this.addEventListener(type, this[name] = l, l.$ = capture);
  1025. l._ = listener;
  1026. }
  1027. function removeAll() {
  1028. var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
  1029. for (var name in this) {
  1030. if (match = name.match(re)) {
  1031. var l = this[name];
  1032. this.removeEventListener(match[1], l, l.$);
  1033. delete this[name];
  1034. }
  1035. }
  1036. }
  1037. return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
  1038. }
  1039. var d3_selection_onFilters = d3.map({
  1040. mouseenter: "mouseover",
  1041. mouseleave: "mouseout"
  1042. });
  1043. d3_selection_onFilters.forEach(function(k) {
  1044. if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
  1045. });
  1046. function d3_selection_onListener(listener, argumentz) {
  1047. return function(e) {
  1048. var o = d3.event;
  1049. d3.event = e;
  1050. argumentz[0] = this.__data__;
  1051. try {
  1052. listener.apply(this, argumentz);
  1053. } finally {
  1054. d3.event = o;
  1055. }
  1056. };
  1057. }
  1058. function d3_selection_onFilter(listener, argumentz) {
  1059. var l = d3_selection_onListener(listener, argumentz);
  1060. return function(e) {
  1061. var target = this, related = e.relatedTarget;
  1062. if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
  1063. l.call(target, e);
  1064. }
  1065. };
  1066. }
  1067. var d3_event_dragSelect = "onselectstart" in d3_document ? null : d3_vendorSymbol(d3_documentElement.style, "userSelect"), d3_event_dragId = 0;
  1068. function d3_event_dragSuppress() {
  1069. var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
  1070. if (d3_event_dragSelect) {
  1071. var style = d3_documentElement.style, select = style[d3_event_dragSelect];
  1072. style[d3_event_dragSelect] = "none";
  1073. }
  1074. return function(suppressClick) {
  1075. w.on(name, null);
  1076. if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
  1077. if (suppressClick) {
  1078. function off() {
  1079. w.on(click, null);
  1080. }
  1081. w.on(click, function() {
  1082. d3_eventPreventDefault();
  1083. off();
  1084. }, true);
  1085. setTimeout(off, 0);
  1086. }
  1087. };
  1088. }
  1089. d3.mouse = function(container) {
  1090. return d3_mousePoint(container, d3_eventSource());
  1091. };
  1092. var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
  1093. function d3_mousePoint(container, e) {
  1094. if (e.changedTouches) e = e.changedTouches[0];
  1095. var svg = container.ownerSVGElement || container;
  1096. if (svg.createSVGPoint) {
  1097. var point = svg.createSVGPoint();
  1098. if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
  1099. svg = d3.select("body").append("svg").style({
  1100. position: "absolute",
  1101. top: 0,
  1102. left: 0,
  1103. margin: 0,
  1104. padding: 0,
  1105. border: "none"
  1106. }, "important");
  1107. var ctm = svg[0][0].getScreenCTM();
  1108. d3_mouse_bug44083 = !(ctm.f || ctm.e);
  1109. svg.remove();
  1110. }
  1111. if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
  1112. point.y = e.clientY;
  1113. point = point.matrixTransform(container.getScreenCTM().inverse());
  1114. return [ point.x, point.y ];
  1115. }
  1116. var rect = container.getBoundingClientRect();
  1117. return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
  1118. }
  1119. d3.touches = function(container, touches) {
  1120. if (arguments.length < 2) touches = d3_eventSource().touches;
  1121. return touches ? d3_array(touches).map(function(touch) {
  1122. var point = d3_mousePoint(container, touch);
  1123. point.identifier = touch.identifier;
  1124. return point;
  1125. }) : [];
  1126. };
  1127. d3.behavior.drag = function() {
  1128. var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_behavior_dragMouseSubject, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_behavior_dragTouchSubject, "touchmove", "touchend");
  1129. function drag() {
  1130. this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
  1131. }
  1132. function dragstart(id, position, subject, move, end) {
  1133. return function() {
  1134. var that = this, target = d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject()).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(), position0 = position(parent, dragId);
  1135. if (origin) {
  1136. dragOffset = origin.apply(that, arguments);
  1137. dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
  1138. } else {
  1139. dragOffset = [ 0, 0 ];
  1140. }
  1141. dispatch({
  1142. type: "dragstart"
  1143. });
  1144. function moved() {
  1145. var position1 = position(parent, dragId), dx, dy;
  1146. if (!position1) return;
  1147. dx = position1[0] - position0[0];
  1148. dy = position1[1] - position0[1];
  1149. dragged |= dx | dy;
  1150. position0 = position1;
  1151. dispatch({
  1152. type: "drag",
  1153. x: position1[0] + dragOffset[0],
  1154. y: position1[1] + dragOffset[1],
  1155. dx: dx,
  1156. dy: dy
  1157. });
  1158. }
  1159. function ended() {
  1160. if (!position(parent, dragId)) return;
  1161. dragSubject.on(move + dragName, null).on(end + dragName, null);
  1162. dragRestore(dragged && d3.event.target === target);
  1163. dispatch({
  1164. type: "dragend"
  1165. });
  1166. }
  1167. };
  1168. }
  1169. drag.origin = function(x) {
  1170. if (!arguments.length) return origin;
  1171. origin = x;
  1172. return drag;
  1173. };
  1174. return d3.rebind(drag, event, "on");
  1175. };
  1176. function d3_behavior_dragTouchId() {
  1177. return d3.event.changedTouches[0].identifier;
  1178. }
  1179. function d3_behavior_dragTouchSubject() {
  1180. return d3.event.target;
  1181. }
  1182. function d3_behavior_dragMouseSubject() {
  1183. return d3_window;
  1184. }
  1185. var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
  1186. function d3_sgn(x) {
  1187. return x > 0 ? 1 : x < 0 ? -1 : 0;
  1188. }
  1189. function d3_cross2d(a, b, c) {
  1190. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  1191. }
  1192. function d3_acos(x) {
  1193. return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
  1194. }
  1195. function d3_asin(x) {
  1196. return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
  1197. }
  1198. function d3_sinh(x) {
  1199. return ((x = Math.exp(x)) - 1 / x) / 2;
  1200. }
  1201. function d3_cosh(x) {
  1202. return ((x = Math.exp(x)) + 1 / x) / 2;
  1203. }
  1204. function d3_tanh(x) {
  1205. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  1206. }
  1207. function d3_haversin(x) {
  1208. return (x = Math.sin(x / 2)) * x;
  1209. }
  1210. var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
  1211. d3.interpolateZoom = function(p0, p1) {
  1212. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
  1213. 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)) / ρ;
  1214. function interpolate(t) {
  1215. var s = t * S;
  1216. if (dr) {
  1217. var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
  1218. return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
  1219. }
  1220. return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
  1221. }
  1222. interpolate.duration = S * 1e3;
  1223. return interpolate;
  1224. };
  1225. d3.behavior.zoom = function() {
  1226. var view = {
  1227. x: 0,
  1228. y: 0,
  1229. k: 1
  1230. }, translate0, center0, 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;
  1231. function zoom(g) {
  1232. g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
  1233. }
  1234. zoom.event = function(g) {
  1235. g.each(function() {
  1236. var dispatch = event.of(this, arguments), view1 = view;
  1237. if (d3_transitionInheritId) {
  1238. d3.select(this).transition().each("start.zoom", function() {
  1239. view = this.__chart__ || {
  1240. x: 0,
  1241. y: 0,
  1242. k: 1
  1243. };
  1244. zoomstarted(dispatch);
  1245. }).tween("zoom:zoom", function() {
  1246. 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 ]);
  1247. return function(t) {
  1248. var l = i(t), k = dx / l[2];
  1249. this.__chart__ = view = {
  1250. x: cx - l[0] * k,
  1251. y: cy - l[1] * k,
  1252. k: k
  1253. };
  1254. zoomed(dispatch);
  1255. };
  1256. }).each("end.zoom", function() {
  1257. zoomended(dispatch);
  1258. });
  1259. } else {
  1260. this.__chart__ = view;
  1261. zoomstarted(dispatch);
  1262. zoomed(dispatch);
  1263. zoomended(dispatch);
  1264. }
  1265. });
  1266. };
  1267. zoom.translate = function(_) {
  1268. if (!arguments.length) return [ view.x, view.y ];
  1269. view = {
  1270. x: +_[0],
  1271. y: +_[1],
  1272. k: view.k
  1273. };
  1274. rescale();
  1275. return zoom;
  1276. };
  1277. zoom.scale = function(_) {
  1278. if (!arguments.length) return view.k;
  1279. view = {
  1280. x: view.x,
  1281. y: view.y,
  1282. k: +_
  1283. };
  1284. rescale();
  1285. return zoom;
  1286. };
  1287. zoom.scaleExtent = function(_) {
  1288. if (!arguments.length) return scaleExtent;
  1289. scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
  1290. return zoom;
  1291. };
  1292. zoom.center = function(_) {
  1293. if (!arguments.length) return center;
  1294. center = _ && [ +_[0], +_[1] ];
  1295. return zoom;
  1296. };
  1297. zoom.size = function(_) {
  1298. if (!arguments.length) return size;
  1299. size = _ && [ +_[0], +_[1] ];
  1300. return zoom;
  1301. };
  1302. zoom.x = function(z) {
  1303. if (!arguments.length) return x1;
  1304. x1 = z;
  1305. x0 = z.copy();
  1306. view = {
  1307. x: 0,
  1308. y: 0,
  1309. k: 1
  1310. };
  1311. return zoom;
  1312. };
  1313. zoom.y = function(z) {
  1314. if (!arguments.length) return y1;
  1315. y1 = z;
  1316. y0 = z.copy();
  1317. view = {
  1318. x: 0,
  1319. y: 0,
  1320. k: 1
  1321. };
  1322. return zoom;
  1323. };
  1324. function location(p) {
  1325. return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
  1326. }
  1327. function point(l) {
  1328. return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
  1329. }
  1330. function scaleTo(s) {
  1331. view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  1332. }
  1333. function translateTo(p, l) {
  1334. l = point(l);
  1335. view.x += p[0] - l[0];
  1336. view.y += p[1] - l[1];
  1337. }
  1338. function rescale() {
  1339. if (x1) x1.domain(x0.range().map(function(x) {
  1340. return (x - view.x) / view.k;
  1341. }).map(x0.invert));
  1342. if (y1) y1.domain(y0.range().map(function(y) {
  1343. return (y - view.y) / view.k;
  1344. }).map(y0.invert));
  1345. }
  1346. function zoomstarted(dispatch) {
  1347. dispatch({
  1348. type: "zoomstart"
  1349. });
  1350. }
  1351. function zoomed(dispatch) {
  1352. rescale();
  1353. dispatch({
  1354. type: "zoom",
  1355. scale: view.k,
  1356. translate: [ view.x, view.y ]
  1357. });
  1358. }
  1359. function zoomended(dispatch) {
  1360. dispatch({
  1361. type: "zoomend"
  1362. });
  1363. }
  1364. function mousedowned() {
  1365. var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress();
  1366. d3_selection_interrupt.call(that);
  1367. zoomstarted(dispatch);
  1368. function moved() {
  1369. dragged = 1;
  1370. translateTo(d3.mouse(that), location0);
  1371. zoomed(dispatch);
  1372. }
  1373. function ended() {
  1374. subject.on(mousemove, null).on(mouseup, null);
  1375. dragRestore(dragged && d3.event.target === target);
  1376. zoomended(dispatch);
  1377. }
  1378. }
  1379. function touchstarted() {
  1380. var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress();
  1381. d3_selection_interrupt.call(that);
  1382. started();
  1383. zoomstarted(dispatch);
  1384. function relocate() {
  1385. var touches = d3.touches(that);
  1386. scale0 = view.k;
  1387. touches.forEach(function(t) {
  1388. if (t.identifier in locations0) locations0[t.identifier] = location(t);
  1389. });
  1390. return touches;
  1391. }
  1392. function started() {
  1393. var target = d3.event.target;
  1394. d3.select(target).on(touchmove, moved).on(touchend, ended);
  1395. targets.push(target);
  1396. var changed = d3.event.changedTouches;
  1397. for (var i = 0, n = changed.length; i < n; ++i) {
  1398. locations0[changed[i].identifier] = null;
  1399. }
  1400. var touches = relocate(), now = Date.now();
  1401. if (touches.length === 1) {
  1402. if (now - touchtime < 500) {
  1403. var p = touches[0], l = locations0[p.identifier];
  1404. scaleTo(view.k * 2);
  1405. translateTo(p, l);
  1406. d3_eventPreventDefault();
  1407. zoomed(dispatch);
  1408. }
  1409. touchtime = now;
  1410. } else if (touches.length > 1) {
  1411. var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
  1412. distance0 = dx * dx + dy * dy;
  1413. }
  1414. }
  1415. function moved() {
  1416. var touches = d3.touches(that), p0, l0, p1, l1;
  1417. for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
  1418. p1 = touches[i];
  1419. if (l1 = locations0[p1.identifier]) {
  1420. if (l0) break;
  1421. p0 = p1, l0 = l1;
  1422. }
  1423. }
  1424. if (l1) {
  1425. var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
  1426. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  1427. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  1428. scaleTo(scale1 * scale0);
  1429. }
  1430. touchtime = null;
  1431. translateTo(p0, l0);
  1432. zoomed(dispatch);
  1433. }
  1434. function ended() {
  1435. if (d3.event.touches.length) {
  1436. var changed = d3.event.changedTouches;
  1437. for (var i = 0, n = changed.length; i < n; ++i) {
  1438. delete locations0[changed[i].identifier];
  1439. }
  1440. for (var identifier in locations0) {
  1441. return void relocate();
  1442. }
  1443. }
  1444. d3.selectAll(targets).on(zoomName, null);
  1445. subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
  1446. dragRestore();
  1447. zoomended(dispatch);
  1448. }
  1449. }
  1450. function mousewheeled() {
  1451. var dispatch = event.of(this, arguments);
  1452. if (mousewheelTimer) clearTimeout(mousewheelTimer); else translate0 = location(center0 = center || d3.mouse(this)),
  1453. d3_selection_interrupt.call(this), zoomstarted(dispatch);
  1454. mousewheelTimer = setTimeout(function() {
  1455. mousewheelTimer = null;
  1456. zoomended(dispatch);
  1457. }, 50);
  1458. d3_eventPreventDefault();
  1459. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
  1460. translateTo(center0, translate0);
  1461. zoomed(dispatch);
  1462. }
  1463. function dblclicked() {
  1464. var dispatch = event.of(this, arguments), p = d3.mouse(this), l = location(p), k = Math.log(view.k) / Math.LN2;
  1465. zoomstarted(dispatch);
  1466. scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
  1467. translateTo(p, l);
  1468. zoomed(dispatch);
  1469. zoomended(dispatch);
  1470. }
  1471. return d3.rebind(zoom, event, "on");
  1472. };
  1473. var d3_behavior_zoomInfinity = [ 0, Infinity ];
  1474. var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1475. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  1476. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1477. return d3.event.wheelDelta;
  1478. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  1479. return -d3.event.detail;
  1480. }, "MozMousePixelScroll");
  1481. d3.color = d3_color;
  1482. function d3_color() {}
  1483. d3_color.prototype.toString = function() {
  1484. return this.rgb() + "";
  1485. };
  1486. d3.hsl = d3_hsl;
  1487. function d3_hsl(h, s, l) {
  1488. return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
  1489. }
  1490. var d3_hslPrototype = d3_hsl.prototype = new d3_color();
  1491. d3_hslPrototype.brighter = function(k) {
  1492. k = Math.pow(.7, arguments.length ? k : 1);
  1493. return new d3_hsl(this.h, this.s, this.l / k);
  1494. };
  1495. d3_hslPrototype.darker = function(k) {
  1496. k = Math.pow(.7, arguments.length ? k : 1);
  1497. return new d3_hsl(this.h, this.s, k * this.l);
  1498. };
  1499. d3_hslPrototype.rgb = function() {
  1500. return d3_hsl_rgb(this.h, this.s, this.l);
  1501. };
  1502. function d3_hsl_rgb(h, s, l) {
  1503. var m1, m2;
  1504. h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
  1505. s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
  1506. l = l < 0 ? 0 : l > 1 ? 1 : l;
  1507. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  1508. m1 = 2 * l - m2;
  1509. function v(h) {
  1510. if (h > 360) h -= 360; else if (h < 0) h += 360;
  1511. if (h < 60) return m1 + (m2 - m1) * h / 60;
  1512. if (h < 180) return m2;
  1513. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  1514. return m1;
  1515. }
  1516. function vv(h) {
  1517. return Math.round(v(h) * 255);
  1518. }
  1519. return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  1520. }
  1521. d3.hcl = d3_hcl;
  1522. function d3_hcl(h, c, l) {
  1523. return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);
  1524. }
  1525. var d3_hclPrototype = d3_hcl.prototype = new d3_color();
  1526. d3_hclPrototype.brighter = function(k) {
  1527. return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  1528. };
  1529. d3_hclPrototype.darker = function(k) {
  1530. return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  1531. };
  1532. d3_hclPrototype.rgb = function() {
  1533. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  1534. };
  1535. function d3_hcl_lab(h, c, l) {
  1536. if (isNaN(h)) h = 0;
  1537. if (isNaN(c)) c = 0;
  1538. return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  1539. }
  1540. d3.lab = d3_lab;
  1541. function d3_lab(l, a, b) {
  1542. return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
  1543. }
  1544. var d3_lab_K = 18;
  1545. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  1546. var d3_labPrototype = d3_lab.prototype = new d3_color();
  1547. d3_labPrototype.brighter = function(k) {
  1548. return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1549. };
  1550. d3_labPrototype.darker = function(k) {
  1551. return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1552. };
  1553. d3_labPrototype.rgb = function() {
  1554. return d3_lab_rgb(this.l, this.a, this.b);
  1555. };
  1556. function d3_lab_rgb(l, a, b) {
  1557. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  1558. x = d3_lab_xyz(x) * d3_lab_X;
  1559. y = d3_lab_xyz(y) * d3_lab_Y;
  1560. z = d3_lab_xyz(z) * d3_lab_Z;
  1561. return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
  1562. }
  1563. function d3_lab_hcl(l, a, b) {
  1564. return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
  1565. }
  1566. function d3_lab_xyz(x) {
  1567. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  1568. }
  1569. function d3_xyz_lab(x) {
  1570. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  1571. }
  1572. function d3_xyz_rgb(r) {
  1573. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  1574. }
  1575. d3.rgb = d3_rgb;
  1576. function d3_rgb(r, g, b) {
  1577. return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
  1578. }
  1579. function d3_rgbNumber(value) {
  1580. return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
  1581. }
  1582. function d3_rgbString(value) {
  1583. return d3_rgbNumber(value) + "";
  1584. }
  1585. var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
  1586. d3_rgbPrototype.brighter = function(k) {
  1587. k = Math.pow(.7, arguments.length ? k : 1);
  1588. var r = this.r, g = this.g, b = this.b, i = 30;
  1589. if (!r && !g && !b) return new d3_rgb(i, i, i);
  1590. if (r && r < i) r = i;
  1591. if (g && g < i) g = i;
  1592. if (b && b < i) b = i;
  1593. return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
  1594. };
  1595. d3_rgbPrototype.darker = function(k) {
  1596. k = Math.pow(.7, arguments.length ? k : 1);
  1597. return new d3_rgb(k * this.r, k * this.g, k * this.b);
  1598. };
  1599. d3_rgbPrototype.hsl = function() {
  1600. return d3_rgb_hsl(this.r, this.g, this.b);
  1601. };
  1602. d3_rgbPrototype.toString = function() {
  1603. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  1604. };
  1605. function d3_rgb_hex(v) {
  1606. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  1607. }
  1608. function d3_rgb_parse(format, rgb, hsl) {
  1609. var r = 0, g = 0, b = 0, m1, m2, color;
  1610. m1 = /([a-z]+)\((.*)\)/i.exec(format);
  1611. if (m1) {
  1612. m2 = m1[2].split(",");
  1613. switch (m1[1]) {
  1614. case "hsl":
  1615. {
  1616. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  1617. }
  1618. case "rgb":
  1619. {
  1620. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  1621. }
  1622. }
  1623. }
  1624. if (color = d3_rgb_names.get(format)) return rgb(color.r, color.g, color.b);
  1625. if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.substring(1), 16))) {
  1626. if (format.length === 4) {
  1627. r = (color & 3840) >> 4;
  1628. r = r >> 4 | r;
  1629. g = color & 240;
  1630. g = g >> 4 | g;
  1631. b = color & 15;
  1632. b = b << 4 | b;
  1633. } else if (format.length === 7) {
  1634. r = (color & 16711680) >> 16;
  1635. g = (color & 65280) >> 8;
  1636. b = color & 255;
  1637. }
  1638. }
  1639. return rgb(r, g, b);
  1640. }
  1641. function d3_rgb_hsl(r, g, b) {
  1642. 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;
  1643. if (d) {
  1644. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  1645. 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;
  1646. h *= 60;
  1647. } else {
  1648. h = NaN;
  1649. s = l > 0 && l < 1 ? 0 : h;
  1650. }
  1651. return new d3_hsl(h, s, l);
  1652. }
  1653. function d3_rgb_lab(r, g, b) {
  1654. r = d3_rgb_xyz(r);
  1655. g = d3_rgb_xyz(g);
  1656. b = d3_rgb_xyz(b);
  1657. 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);
  1658. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  1659. }
  1660. function d3_rgb_xyz(r) {
  1661. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  1662. }
  1663. function d3_rgb_parseNumber(c) {
  1664. var f = parseFloat(c);
  1665. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  1666. }
  1667. var d3_rgb_names = d3.map({
  1668. aliceblue: 15792383,
  1669. antiquewhite: 16444375,
  1670. aqua: 65535,
  1671. aquamarine: 8388564,
  1672. azure: 15794175,
  1673. beige: 16119260,
  1674. bisque: 16770244,
  1675. black: 0,
  1676. blanchedalmond: 16772045,
  1677. blue: 255,
  1678. blueviolet: 9055202,
  1679. brown: 10824234,
  1680. burlywood: 14596231,
  1681. cadetblue: 6266528,
  1682. chartreuse: 8388352,
  1683. chocolate: 13789470,
  1684. coral: 16744272,
  1685. cornflowerblue: 6591981,
  1686. cornsilk: 16775388,
  1687. crimson: 14423100,
  1688. cyan: 65535,
  1689. darkblue: 139,
  1690. darkcyan: 35723,
  1691. darkgoldenrod: 12092939,
  1692. darkgray: 11119017,
  1693. darkgreen: 25600,
  1694. darkgrey: 11119017,
  1695. darkkhaki: 12433259,
  1696. darkmagenta: 9109643,
  1697. darkolivegreen: 5597999,
  1698. darkorange: 16747520,
  1699. darkorchid: 10040012,
  1700. darkred: 9109504,
  1701. darksalmon: 15308410,
  1702. darkseagreen: 9419919,
  1703. darkslateblue: 4734347,
  1704. darkslategray: 3100495,
  1705. darkslategrey: 3100495,
  1706. darkturquoise: 52945,
  1707. darkviolet: 9699539,
  1708. deeppink: 16716947,
  1709. deepskyblue: 49151,
  1710. dimgray: 6908265,
  1711. dimgrey: 6908265,
  1712. dodgerblue: 2003199,
  1713. firebrick: 11674146,
  1714. floralwhite: 16775920,
  1715. forestgreen: 2263842,
  1716. fuchsia: 16711935,
  1717. gainsboro: 14474460,
  1718. ghostwhite: 16316671,
  1719. gold: 16766720,
  1720. goldenrod: 14329120,
  1721. gray: 8421504,
  1722. green: 32768,
  1723. greenyellow: 11403055,
  1724. grey: 8421504,
  1725. honeydew: 15794160,
  1726. hotpink: 16738740,
  1727. indianred: 13458524,
  1728. indigo: 4915330,
  1729. ivory: 16777200,
  1730. khaki: 15787660,
  1731. lavender: 15132410,
  1732. lavenderblush: 16773365,
  1733. lawngreen: 8190976,
  1734. lemonchiffon: 16775885,
  1735. lightblue: 11393254,
  1736. lightcoral: 15761536,
  1737. lightcyan: 14745599,
  1738. lightgoldenrodyellow: 16448210,
  1739. lightgray: 13882323,
  1740. lightgreen: 9498256,
  1741. lightgrey: 13882323,
  1742. lightpink: 16758465,
  1743. lightsalmon: 16752762,
  1744. lightseagreen: 2142890,
  1745. lightskyblue: 8900346,
  1746. lightslategray: 7833753,
  1747. lightslategrey: 7833753,
  1748. lightsteelblue: 11584734,
  1749. lightyellow: 16777184,
  1750. lime: 65280,
  1751. limegreen: 3329330,
  1752. linen: 16445670,
  1753. magenta: 16711935,
  1754. maroon: 8388608,
  1755. mediumaquamarine: 6737322,
  1756. mediumblue: 205,
  1757. mediumorchid: 12211667,
  1758. mediumpurple: 9662683,
  1759. mediumseagreen: 3978097,
  1760. mediumslateblue: 8087790,
  1761. mediumspringgreen: 64154,
  1762. mediumturquoise: 4772300,
  1763. mediumvioletred: 13047173,
  1764. midnightblue: 1644912,
  1765. mintcream: 16121850,
  1766. mistyrose: 16770273,
  1767. moccasin: 16770229,
  1768. navajowhite: 16768685,
  1769. navy: 128,
  1770. oldlace: 16643558,
  1771. olive: 8421376,
  1772. olivedrab: 7048739,
  1773. orange: 16753920,
  1774. orangered: 16729344,
  1775. orchid: 14315734,
  1776. palegoldenrod: 15657130,
  1777. palegreen: 10025880,
  1778. paleturquoise: 11529966,
  1779. palevioletred: 14381203,
  1780. papayawhip: 16773077,
  1781. peachpuff: 16767673,
  1782. peru: 13468991,
  1783. pink: 16761035,
  1784. plum: 14524637,
  1785. powderblue: 11591910,
  1786. purple: 8388736,
  1787. red: 16711680,
  1788. rosybrown: 12357519,
  1789. royalblue: 4286945,
  1790. saddlebrown: 9127187,
  1791. salmon: 16416882,
  1792. sandybrown: 16032864,
  1793. seagreen: 3050327,
  1794. seashell: 16774638,
  1795. sienna: 10506797,
  1796. silver: 12632256,
  1797. skyblue: 8900331,
  1798. slateblue: 6970061,
  1799. slategray: 7372944,
  1800. slategrey: 7372944,
  1801. snow: 16775930,
  1802. springgreen: 65407,
  1803. steelblue: 4620980,
  1804. tan: 13808780,
  1805. teal: 32896,
  1806. thistle: 14204888,
  1807. tomato: 16737095,
  1808. turquoise: 4251856,
  1809. violet: 15631086,
  1810. wheat: 16113331,
  1811. white: 16777215,
  1812. whitesmoke: 16119285,
  1813. yellow: 16776960,
  1814. yellowgreen: 10145074
  1815. });
  1816. d3_rgb_names.forEach(function(key, value) {
  1817. d3_rgb_names.set(key, d3_rgbNumber(value));
  1818. });
  1819. function d3_functor(v) {
  1820. return typeof v === "function" ? v : function() {
  1821. return v;
  1822. };
  1823. }
  1824. d3.functor = d3_functor;
  1825. function d3_identity(d) {
  1826. return d;
  1827. }
  1828. d3.xhr = d3_xhrType(d3_identity);
  1829. function d3_xhrType(response) {
  1830. return function(url, mimeType, callback) {
  1831. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  1832. mimeType = null;
  1833. return d3_xhr(url, mimeType, response, callback);
  1834. };
  1835. }
  1836. function d3_xhr(url, mimeType, response, callback) {
  1837. var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
  1838. if (d3_window.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
  1839. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  1840. request.readyState > 3 && respond();
  1841. };
  1842. function respond() {
  1843. var status = request.status, result;
  1844. if (!status && request.responseText || status >= 200 && status < 300 || status === 304) {
  1845. try {
  1846. result = response.call(xhr, request);
  1847. } catch (e) {
  1848. dispatch.error.call(xhr, e);
  1849. return;
  1850. }
  1851. dispatch.load.call(xhr, result);
  1852. } else {
  1853. dispatch.error.call(xhr, request);
  1854. }
  1855. }
  1856. request.onprogress = function(event) {
  1857. var o = d3.event;
  1858. d3.event = event;
  1859. try {
  1860. dispatch.progress.call(xhr, request);
  1861. } finally {
  1862. d3.event = o;
  1863. }
  1864. };
  1865. xhr.header = function(name, value) {
  1866. name = (name + "").toLowerCase();
  1867. if (arguments.length < 2) return headers[name];
  1868. if (value == null) delete headers[name]; else headers[name] = value + "";
  1869. return xhr;
  1870. };
  1871. xhr.mimeType = function(value) {
  1872. if (!arguments.length) return mimeType;
  1873. mimeType = value == null ? null : value + "";
  1874. return xhr;
  1875. };
  1876. xhr.responseType = function(value) {
  1877. if (!arguments.length) return responseType;
  1878. responseType = value;
  1879. return xhr;
  1880. };
  1881. xhr.response = function(value) {
  1882. response = value;
  1883. return xhr;
  1884. };
  1885. [ "get", "post" ].forEach(function(method) {
  1886. xhr[method] = function() {
  1887. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  1888. };
  1889. });
  1890. xhr.send = function(method, data, callback) {
  1891. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  1892. request.open(method, url, true);
  1893. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  1894. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  1895. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  1896. if (responseType != null) request.responseType = responseType;
  1897. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  1898. callback(null, request);
  1899. });
  1900. dispatch.beforesend.call(xhr, request);
  1901. request.send(data == null ? null : data);
  1902. return xhr;
  1903. };
  1904. xhr.abort = function() {
  1905. request.abort();
  1906. return xhr;
  1907. };
  1908. d3.rebind(xhr, dispatch, "on");
  1909. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  1910. }
  1911. function d3_xhr_fixCallback(callback) {
  1912. return callback.length === 1 ? function(error, request) {
  1913. callback(error == null ? request : null);
  1914. } : callback;
  1915. }
  1916. d3.dsv = function(delimiter, mimeType) {
  1917. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  1918. function dsv(url, row, callback) {
  1919. if (arguments.length < 3) callback = row, row = null;
  1920. var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
  1921. xhr.row = function(_) {
  1922. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  1923. };
  1924. return xhr;
  1925. }
  1926. function response(request) {
  1927. return dsv.parse(request.responseText);
  1928. }
  1929. function typedResponse(f) {
  1930. return function(request) {
  1931. return dsv.parse(request.responseText, f);
  1932. };
  1933. }
  1934. dsv.parse = function(text, f) {
  1935. var o;
  1936. return dsv.parseRows(text, function(row, i) {
  1937. if (o) return o(row, i - 1);
  1938. var a = new Function("d", "return {" + row.map(function(name, i) {
  1939. return JSON.stringify(name) + ": d[" + i + "]";
  1940. }).join(",") + "}");
  1941. o = f ? function(row, i) {
  1942. return f(a(row), i);
  1943. } : a;
  1944. });
  1945. };
  1946. dsv.parseRows = function(text, f) {
  1947. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  1948. function token() {
  1949. if (I >= N) return EOF;
  1950. if (eol) return eol = false, EOL;
  1951. var j = I;
  1952. if (text.charCodeAt(j) === 34) {
  1953. var i = j;
  1954. while (i++ < N) {
  1955. if (text.charCodeAt(i) === 34) {
  1956. if (text.charCodeAt(i + 1) !== 34) break;
  1957. ++i;
  1958. }
  1959. }
  1960. I = i + 2;
  1961. var c = text.charCodeAt(i + 1);
  1962. if (c === 13) {
  1963. eol = true;
  1964. if (text.charCodeAt(i + 2) === 10) ++I;
  1965. } else if (c === 10) {
  1966. eol = true;
  1967. }
  1968. return text.substring(j + 1, i).replace(/""/g, '"');
  1969. }
  1970. while (I < N) {
  1971. var c = text.charCodeAt(I++), k = 1;
  1972. if (c === 10) eol = true; else if (c === 13) {
  1973. eol = true;
  1974. if (text.charCodeAt(I) === 10) ++I, ++k;
  1975. } else if (c !== delimiterCode) continue;
  1976. return text.substring(j, I - k);
  1977. }
  1978. return text.substring(j);
  1979. }
  1980. while ((t = token()) !== EOF) {
  1981. var a = [];
  1982. while (t !== EOL && t !== EOF) {
  1983. a.push(t);
  1984. t = token();
  1985. }
  1986. if (f && !(a = f(a, n++))) continue;
  1987. rows.push(a);
  1988. }
  1989. return rows;
  1990. };
  1991. dsv.format = function(rows) {
  1992. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  1993. var fieldSet = new d3_Set(), fields = [];
  1994. rows.forEach(function(row) {
  1995. for (var field in row) {
  1996. if (!fieldSet.has(field)) {
  1997. fields.push(fieldSet.add(field));
  1998. }
  1999. }
  2000. });
  2001. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  2002. return fields.map(function(field) {
  2003. return formatValue(row[field]);
  2004. }).join(delimiter);
  2005. })).join("\n");
  2006. };
  2007. dsv.formatRows = function(rows) {
  2008. return rows.map(formatRow).join("\n");
  2009. };
  2010. function formatRow(row) {
  2011. return row.map(formatValue).join(delimiter);
  2012. }
  2013. function formatValue(text) {
  2014. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  2015. }
  2016. return dsv;
  2017. };
  2018. d3.csv = d3.dsv(",", "text/csv");
  2019. d3.tsv = d3.dsv(" ", "text/tab-separated-values");
  2020. d3.touch = function(container, touches, identifier) {
  2021. if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
  2022. if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
  2023. if ((touch = touches[i]).identifier === identifier) {
  2024. return d3_mousePoint(container, touch);
  2025. }
  2026. }
  2027. };
  2028. 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) {
  2029. setTimeout(callback, 17);
  2030. };
  2031. d3.timer = function(callback, delay, then) {
  2032. var n = arguments.length;
  2033. if (n < 2) delay = 0;
  2034. if (n < 3) then = Date.now();
  2035. var time = then + delay, timer = {
  2036. c: callback,
  2037. t: time,
  2038. f: false,
  2039. n: null
  2040. };
  2041. if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
  2042. d3_timer_queueTail = timer;
  2043. if (!d3_timer_interval) {
  2044. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  2045. d3_timer_interval = 1;
  2046. d3_timer_frame(d3_timer_step);
  2047. }
  2048. };
  2049. function d3_timer_step() {
  2050. var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
  2051. if (delay > 24) {
  2052. if (isFinite(delay)) {
  2053. clearTimeout(d3_timer_timeout);
  2054. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  2055. }
  2056. d3_timer_interval = 0;
  2057. } else {
  2058. d3_timer_interval = 1;
  2059. d3_timer_frame(d3_timer_step);
  2060. }
  2061. }
  2062. d3.timer.flush = function() {
  2063. d3_timer_mark();
  2064. d3_timer_sweep();
  2065. };
  2066. function d3_timer_mark() {
  2067. var now = Date.now();
  2068. d3_timer_active = d3_timer_queueHead;
  2069. while (d3_timer_active) {
  2070. if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
  2071. d3_timer_active = d3_timer_active.n;
  2072. }
  2073. return now;
  2074. }
  2075. function d3_timer_sweep() {
  2076. var t0, t1 = d3_timer_queueHead, time = Infinity;
  2077. while (t1) {
  2078. if (t1.f) {
  2079. t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
  2080. } else {
  2081. if (t1.t < time) time = t1.t;
  2082. t1 = (t0 = t1).n;
  2083. }
  2084. }
  2085. d3_timer_queueTail = t0;
  2086. return time;
  2087. }
  2088. function d3_format_precision(x, p) {
  2089. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  2090. }
  2091. d3.round = function(x, n) {
  2092. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  2093. };
  2094. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  2095. d3.formatPrefix = function(value, precision) {
  2096. var i = 0;
  2097. if (value) {
  2098. if (value < 0) value *= -1;
  2099. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  2100. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  2101. i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
  2102. }
  2103. return d3_formatPrefixes[8 + i / 3];
  2104. };
  2105. function d3_formatPrefix(d, i) {
  2106. var k = Math.pow(10, abs(8 - i) * 3);
  2107. return {
  2108. scale: i > 8 ? function(d) {
  2109. return d / k;
  2110. } : function(d) {
  2111. return d * k;
  2112. },
  2113. symbol: d
  2114. };
  2115. }
  2116. function d3_locale_numberFormat(locale) {
  2117. var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping ? function(value) {
  2118. var i = value.length, t = [], j = 0, g = locale_grouping[0];
  2119. while (i > 0 && g > 0) {
  2120. t.push(value.substring(i -= g, i + g));
  2121. g = locale_grouping[j = (j + 1) % locale_grouping.length];
  2122. }
  2123. return t.reverse().join(locale_thousands);
  2124. } : d3_identity;
  2125. return function(specifier) {
  2126. var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false;
  2127. if (precision) precision = +precision.substring(1);
  2128. if (zfill || fill === "0" && align === "=") {
  2129. zfill = fill = "0";
  2130. align = "=";
  2131. if (comma) width -= Math.floor((width - 1) / 4);
  2132. }
  2133. switch (type) {
  2134. case "n":
  2135. comma = true;
  2136. type = "g";
  2137. break;
  2138. case "%":
  2139. scale = 100;
  2140. suffix = "%";
  2141. type = "f";
  2142. break;
  2143. case "p":
  2144. scale = 100;
  2145. suffix = "%";
  2146. type = "r";
  2147. break;
  2148. case "b":
  2149. case "o":
  2150. case "x":
  2151. case "X":
  2152. if (symbol === "#") prefix = "0" + type.toLowerCase();
  2153. case "c":
  2154. case "d":
  2155. integer = true;
  2156. precision = 0;
  2157. break;
  2158. case "s":
  2159. scale = -1;
  2160. type = "r";
  2161. break;
  2162. }
  2163. if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
  2164. if (type == "r" && !precision) type = "g";
  2165. if (precision != null) {
  2166. 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));
  2167. }
  2168. type = d3_format_types.get(type) || d3_format_typeDefault;
  2169. var zcomma = zfill && comma;
  2170. return function(value) {
  2171. var fullSuffix = suffix;
  2172. if (integer && value % 1) return "";
  2173. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign;
  2174. if (scale < 0) {
  2175. var unit = d3.formatPrefix(value, precision);
  2176. value = unit.scale(value);
  2177. fullSuffix = unit.symbol + suffix;
  2178. } else {
  2179. value *= scale;
  2180. }
  2181. value = type(value, precision);
  2182. var i = value.lastIndexOf("."), before = i < 0 ? value : value.substring(0, i), after = i < 0 ? "" : locale_decimal + value.substring(i + 1);
  2183. if (!zfill && comma) before = formatGroup(before);
  2184. var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  2185. if (zcomma) before = formatGroup(padding + before);
  2186. negative += prefix;
  2187. value = before + after;
  2188. return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix;
  2189. };
  2190. };
  2191. }
  2192. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  2193. var d3_format_types = d3.map({
  2194. b: function(x) {
  2195. return x.toString(2);
  2196. },
  2197. c: function(x) {
  2198. return String.fromCharCode(x);
  2199. },
  2200. o: function(x) {
  2201. return x.toString(8);
  2202. },
  2203. x: function(x) {
  2204. return x.toString(16);
  2205. },
  2206. X: function(x) {
  2207. return x.toString(16).toUpperCase();
  2208. },
  2209. g: function(x, p) {
  2210. return x.toPrecision(p);
  2211. },
  2212. e: function(x, p) {
  2213. return x.toExponential(p);
  2214. },
  2215. f: function(x, p) {
  2216. return x.toFixed(p);
  2217. },
  2218. r: function(x, p) {
  2219. 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))));
  2220. }
  2221. });
  2222. function d3_format_typeDefault(x) {
  2223. return x + "";
  2224. }
  2225. var d3_time = d3.time = {}, d3_date = Date;
  2226. function d3_date_utc() {
  2227. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  2228. }
  2229. d3_date_utc.prototype = {
  2230. getDate: function() {
  2231. return this._.getUTCDate();
  2232. },
  2233. getDay: function() {
  2234. return this._.getUTCDay();
  2235. },
  2236. getFullYear: function() {
  2237. return this._.getUTCFullYear();
  2238. },
  2239. getHours: function() {
  2240. return this._.getUTCHours();
  2241. },
  2242. getMilliseconds: function() {
  2243. return this._.getUTCMilliseconds();
  2244. },
  2245. getMinutes: function() {
  2246. return this._.getUTCMinutes();
  2247. },
  2248. getMonth: function() {
  2249. return this._.getUTCMonth();
  2250. },
  2251. getSeconds: function() {
  2252. return this._.getUTCSeconds();
  2253. },
  2254. getTime: function() {
  2255. return this._.getTime();
  2256. },
  2257. getTimezoneOffset: function() {
  2258. return 0;
  2259. },
  2260. valueOf: function() {
  2261. return this._.valueOf();
  2262. },
  2263. setDate: function() {
  2264. d3_time_prototype.setUTCDate.apply(this._, arguments);
  2265. },
  2266. setDay: function() {
  2267. d3_time_prototype.setUTCDay.apply(this._, arguments);
  2268. },
  2269. setFullYear: function() {
  2270. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  2271. },
  2272. setHours: function() {
  2273. d3_time_prototype.setUTCHours.apply(this._, arguments);
  2274. },
  2275. setMilliseconds: function() {
  2276. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  2277. },
  2278. setMinutes: function() {
  2279. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  2280. },
  2281. setMonth: function() {
  2282. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  2283. },
  2284. setSeconds: function() {
  2285. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  2286. },
  2287. setTime: function() {
  2288. d3_time_prototype.setTime.apply(this._, arguments);
  2289. }
  2290. };
  2291. var d3_time_prototype = Date.prototype;
  2292. function d3_time_interval(local, step, number) {
  2293. function round(date) {
  2294. var d0 = local(date), d1 = offset(d0, 1);
  2295. return date - d0 < d1 - date ? d0 : d1;
  2296. }
  2297. function ceil(date) {
  2298. step(date = local(new d3_date(date - 1)), 1);
  2299. return date;
  2300. }
  2301. function offset(date, k) {
  2302. step(date = new d3_date(+date), k);
  2303. return date;
  2304. }
  2305. function range(t0, t1, dt) {
  2306. var time = ceil(t0), times = [];
  2307. if (dt > 1) {
  2308. while (time < t1) {
  2309. if (!(number(time) % dt)) times.push(new Date(+time));
  2310. step(time, 1);
  2311. }
  2312. } else {
  2313. while (time < t1) times.push(new Date(+time)), step(time, 1);
  2314. }
  2315. return times;
  2316. }
  2317. function range_utc(t0, t1, dt) {
  2318. try {
  2319. d3_date = d3_date_utc;
  2320. var utc = new d3_date_utc();
  2321. utc._ = t0;
  2322. return range(utc, t1, dt);
  2323. } finally {
  2324. d3_date = Date;
  2325. }
  2326. }
  2327. local.floor = local;
  2328. local.round = round;
  2329. local.ceil = ceil;
  2330. local.offset = offset;
  2331. local.range = range;
  2332. var utc = local.utc = d3_time_interval_utc(local);
  2333. utc.floor = utc;
  2334. utc.round = d3_time_interval_utc(round);
  2335. utc.ceil = d3_time_interval_utc(ceil);
  2336. utc.offset = d3_time_interval_utc(offset);
  2337. utc.range = range_utc;
  2338. return local;
  2339. }
  2340. function d3_time_interval_utc(method) {
  2341. return function(date, k) {
  2342. try {
  2343. d3_date = d3_date_utc;
  2344. var utc = new d3_date_utc();
  2345. utc._ = date;
  2346. return method(utc, k)._;
  2347. } finally {
  2348. d3_date = Date;
  2349. }
  2350. };
  2351. }
  2352. d3_time.year = d3_time_interval(function(date) {
  2353. date = d3_time.day(date);
  2354. date.setMonth(0, 1);
  2355. return date;
  2356. }, function(date, offset) {
  2357. date.setFullYear(date.getFullYear() + offset);
  2358. }, function(date) {
  2359. return date.getFullYear();
  2360. });
  2361. d3_time.years = d3_time.year.range;
  2362. d3_time.years.utc = d3_time.year.utc.range;
  2363. d3_time.day = d3_time_interval(function(date) {
  2364. var day = new d3_date(2e3, 0);
  2365. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  2366. return day;
  2367. }, function(date, offset) {
  2368. date.setDate(date.getDate() + offset);
  2369. }, function(date) {
  2370. return date.getDate() - 1;
  2371. });
  2372. d3_time.days = d3_time.day.range;
  2373. d3_time.days.utc = d3_time.day.utc.range;
  2374. d3_time.dayOfYear = function(date) {
  2375. var year = d3_time.year(date);
  2376. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  2377. };
  2378. [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
  2379. i = 7 - i;
  2380. var interval = d3_time[day] = d3_time_interval(function(date) {
  2381. (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  2382. return date;
  2383. }, function(date, offset) {
  2384. date.setDate(date.getDate() + Math.floor(offset) * 7);
  2385. }, function(date) {
  2386. var day = d3_time.year(date).getDay();
  2387. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  2388. });
  2389. d3_time[day + "s"] = interval.range;
  2390. d3_time[day + "s"].utc = interval.utc.range;
  2391. d3_time[day + "OfYear"] = function(date) {
  2392. var day = d3_time.year(date).getDay();
  2393. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
  2394. };
  2395. });
  2396. d3_time.week = d3_time.sunday;
  2397. d3_time.weeks = d3_time.sunday.range;
  2398. d3_time.weeks.utc = d3_time.sunday.utc.range;
  2399. d3_time.weekOfYear = d3_time.sundayOfYear;
  2400. function d3_locale_timeFormat(locale) {
  2401. var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;
  2402. function d3_time_format(template) {
  2403. var n = template.length;
  2404. function format(date) {
  2405. var string = [], i = -1, j = 0, c, p, f;
  2406. while (++i < n) {
  2407. if (template.charCodeAt(i) === 37) {
  2408. string.push(template.substring(j, i));
  2409. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  2410. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  2411. string.push(c);
  2412. j = i + 1;
  2413. }
  2414. }
  2415. string.push(template.substring(j, i));
  2416. return string.join("");
  2417. }
  2418. format.parse = function(string) {
  2419. var d = {
  2420. y: 1900,
  2421. m: 0,
  2422. d: 1,
  2423. H: 0,
  2424. M: 0,
  2425. S: 0,
  2426. L: 0,
  2427. Z: null
  2428. }, i = d3_time_parse(d, template, string, 0);
  2429. if (i != string.length) return null;
  2430. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  2431. var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
  2432. if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
  2433. date.setFullYear(d.y, 0, 1);
  2434. 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);
  2435. } else date.setFullYear(d.y, d.m, d.d);
  2436. date.setHours(d.H + Math.floor(d.Z / 100), d.M + d.Z % 100, d.S, d.L);
  2437. return localZ ? date._ : date;
  2438. };
  2439. format.toString = function() {
  2440. return template;
  2441. };
  2442. return format;
  2443. }
  2444. function d3_time_parse(date, template, string, j) {
  2445. var c, p, t, i = 0, n = template.length, m = string.length;
  2446. while (i < n) {
  2447. if (j >= m) return -1;
  2448. c = template.charCodeAt(i++);
  2449. if (c === 37) {
  2450. t = template.charAt(i++);
  2451. p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
  2452. if (!p || (j = p(date, string, j)) < 0) return -1;
  2453. } else if (c != string.charCodeAt(j++)) {
  2454. return -1;
  2455. }
  2456. }
  2457. return j;
  2458. }
  2459. d3_time_format.utc = function(template) {
  2460. var local = d3_time_format(template);
  2461. function format(date) {
  2462. try {
  2463. d3_date = d3_date_utc;
  2464. var utc = new d3_date();
  2465. utc._ = date;
  2466. return local(utc);
  2467. } finally {
  2468. d3_date = Date;
  2469. }
  2470. }
  2471. format.parse = function(string) {
  2472. try {
  2473. d3_date = d3_date_utc;
  2474. var date = local.parse(string);
  2475. return date && date._;
  2476. } finally {
  2477. d3_date = Date;
  2478. }
  2479. };
  2480. format.toString = local.toString;
  2481. return format;
  2482. };
  2483. d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
  2484. var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths);
  2485. locale_periods.forEach(function(p, i) {
  2486. d3_time_periodLookup.set(p.toLowerCase(), i);
  2487. });
  2488. var d3_time_formats = {
  2489. a: function(d) {
  2490. return locale_shortDays[d.getDay()];
  2491. },
  2492. A: function(d) {
  2493. return locale_days[d.getDay()];
  2494. },
  2495. b: function(d) {
  2496. return locale_shortMonths[d.getMonth()];
  2497. },
  2498. B: function(d) {
  2499. return locale_months[d.getMonth()];
  2500. },
  2501. c: d3_time_format(locale_dateTime),
  2502. d: function(d, p) {
  2503. return d3_time_formatPad(d.getDate(), p, 2);
  2504. },
  2505. e: function(d, p) {
  2506. return d3_time_formatPad(d.getDate(), p, 2);
  2507. },
  2508. H: function(d, p) {
  2509. return d3_time_formatPad(d.getHours(), p, 2);
  2510. },
  2511. I: function(d, p) {
  2512. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  2513. },
  2514. j: function(d, p) {
  2515. return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
  2516. },
  2517. L: function(d, p) {
  2518. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  2519. },
  2520. m: function(d, p) {
  2521. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  2522. },
  2523. M: function(d, p) {
  2524. return d3_time_formatPad(d.getMinutes(), p, 2);
  2525. },
  2526. p: function(d) {
  2527. return locale_periods[+(d.getHours() >= 12)];
  2528. },
  2529. S: function(d, p) {
  2530. return d3_time_formatPad(d.getSeconds(), p, 2);
  2531. },
  2532. U: function(d, p) {
  2533. return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
  2534. },
  2535. w: function(d) {
  2536. return d.getDay();
  2537. },
  2538. W: function(d, p) {
  2539. return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
  2540. },
  2541. x: d3_time_format(locale_date),
  2542. X: d3_time_format(locale_time),
  2543. y: function(d, p) {
  2544. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  2545. },
  2546. Y: function(d, p) {
  2547. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  2548. },
  2549. Z: d3_time_zone,
  2550. "%": function() {
  2551. return "%";
  2552. }
  2553. };
  2554. var d3_time_parsers = {
  2555. a: d3_time_parseWeekdayAbbrev,
  2556. A: d3_time_parseWeekday,
  2557. b: d3_time_parseMonthAbbrev,
  2558. B: d3_time_parseMonth,
  2559. c: d3_time_parseLocaleFull,
  2560. d: d3_time_parseDay,
  2561. e: d3_time_parseDay,
  2562. H: d3_time_parseHour24,
  2563. I: d3_time_parseHour24,
  2564. j: d3_time_parseDayOfYear,
  2565. L: d3_time_parseMilliseconds,
  2566. m: d3_time_parseMonthNumber,
  2567. M: d3_time_parseMinutes,
  2568. p: d3_time_parseAmPm,
  2569. S: d3_time_parseSeconds,
  2570. U: d3_time_parseWeekNumberSunday,
  2571. w: d3_time_parseWeekdayNumber,
  2572. W: d3_time_parseWeekNumberMonday,
  2573. x: d3_time_parseLocaleDate,
  2574. X: d3_time_parseLocaleTime,
  2575. y: d3_time_parseYear,
  2576. Y: d3_time_parseFullYear,
  2577. Z: d3_time_parseZone,
  2578. "%": d3_time_parseLiteralPercent
  2579. };
  2580. function d3_time_parseWeekdayAbbrev(date, string, i) {
  2581. d3_time_dayAbbrevRe.lastIndex = 0;
  2582. var n = d3_time_dayAbbrevRe.exec(string.substring(i));
  2583. return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2584. }
  2585. function d3_time_parseWeekday(date, string, i) {
  2586. d3_time_dayRe.lastIndex = 0;
  2587. var n = d3_time_dayRe.exec(string.substring(i));
  2588. return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2589. }
  2590. function d3_time_parseMonthAbbrev(date, string, i) {
  2591. d3_time_monthAbbrevRe.lastIndex = 0;
  2592. var n = d3_time_monthAbbrevRe.exec(string.substring(i));
  2593. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2594. }
  2595. function d3_time_parseMonth(date, string, i) {
  2596. d3_time_monthRe.lastIndex = 0;
  2597. var n = d3_time_monthRe.exec(string.substring(i));
  2598. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2599. }
  2600. function d3_time_parseLocaleFull(date, string, i) {
  2601. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  2602. }
  2603. function d3_time_parseLocaleDate(date, string, i) {
  2604. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  2605. }
  2606. function d3_time_parseLocaleTime(date, string, i) {
  2607. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  2608. }
  2609. function d3_time_parseAmPm(date, string, i) {
  2610. var n = d3_time_periodLookup.get(string.substring(i, i += 2).toLowerCase());
  2611. return n == null ? -1 : (date.p = n, i);
  2612. }
  2613. return d3_time_format;
  2614. }
  2615. var d3_time_formatPads = {
  2616. "-": "",
  2617. _: " ",
  2618. "0": "0"
  2619. }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
  2620. function d3_time_formatPad(value, fill, width) {
  2621. var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
  2622. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  2623. }
  2624. function d3_time_formatRe(names) {
  2625. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  2626. }
  2627. function d3_time_formatLookup(names) {
  2628. var map = new d3_Map(), i = -1, n = names.length;
  2629. while (++i < n) map.set(names[i].toLowerCase(), i);
  2630. return map;
  2631. }
  2632. function d3_time_parseWeekdayNumber(date, string, i) {
  2633. d3_time_numberRe.lastIndex = 0;
  2634. var n = d3_time_numberRe.exec(string.substring(i, i + 1));
  2635. return n ? (date.w = +n[0], i + n[0].length) : -1;
  2636. }
  2637. function d3_time_parseWeekNumberSunday(date, string, i) {
  2638. d3_time_numberRe.lastIndex = 0;
  2639. var n = d3_time_numberRe.exec(string.substring(i));
  2640. return n ? (date.U = +n[0], i + n[0].length) : -1;
  2641. }
  2642. function d3_time_parseWeekNumberMonday(date, string, i) {
  2643. d3_time_numberRe.lastIndex = 0;
  2644. var n = d3_time_numberRe.exec(string.substring(i));
  2645. return n ? (date.W = +n[0], i + n[0].length) : -1;
  2646. }
  2647. function d3_time_parseFullYear(date, string, i) {
  2648. d3_time_numberRe.lastIndex = 0;
  2649. var n = d3_time_numberRe.exec(string.substring(i, i + 4));
  2650. return n ? (date.y = +n[0], i + n[0].length) : -1;
  2651. }
  2652. function d3_time_parseYear(date, string, i) {
  2653. d3_time_numberRe.lastIndex = 0;
  2654. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  2655. return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
  2656. }
  2657. function d3_time_parseZone(date, string, i) {
  2658. return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = -string,
  2659. i + 5) : -1;
  2660. }
  2661. function d3_time_expandYear(d) {
  2662. return d + (d > 68 ? 1900 : 2e3);
  2663. }
  2664. function d3_time_parseMonthNumber(date, string, i) {
  2665. d3_time_numberRe.lastIndex = 0;
  2666. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  2667. return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
  2668. }
  2669. function d3_time_parseDay(date, string, i) {
  2670. d3_time_numberRe.lastIndex = 0;
  2671. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  2672. return n ? (date.d = +n[0], i + n[0].length) : -1;
  2673. }
  2674. function d3_time_parseDayOfYear(date, string, i) {
  2675. d3_time_numberRe.lastIndex = 0;
  2676. var n = d3_time_numberRe.exec(string.substring(i, i + 3));
  2677. return n ? (date.j = +n[0], i + n[0].length) : -1;
  2678. }
  2679. function d3_time_parseHour24(date, string, i) {
  2680. d3_time_numberRe.lastIndex = 0;
  2681. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  2682. return n ? (date.H = +n[0], i + n[0].length) : -1;
  2683. }
  2684. function d3_time_parseMinutes(date, string, i) {
  2685. d3_time_numberRe.lastIndex = 0;
  2686. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  2687. return n ? (date.M = +n[0], i + n[0].length) : -1;
  2688. }
  2689. function d3_time_parseSeconds(date, string, i) {
  2690. d3_time_numberRe.lastIndex = 0;
  2691. var n = d3_time_numberRe.exec(string.substring(i, i + 2));
  2692. return n ? (date.S = +n[0], i + n[0].length) : -1;
  2693. }
  2694. function d3_time_parseMilliseconds(date, string, i) {
  2695. d3_time_numberRe.lastIndex = 0;
  2696. var n = d3_time_numberRe.exec(string.substring(i, i + 3));
  2697. return n ? (date.L = +n[0], i + n[0].length) : -1;
  2698. }
  2699. function d3_time_zone(d) {
  2700. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(abs(z) / 60), zm = abs(z) % 60;
  2701. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  2702. }
  2703. function d3_time_parseLiteralPercent(date, string, i) {
  2704. d3_time_percentRe.lastIndex = 0;
  2705. var n = d3_time_percentRe.exec(string.substring(i, i + 1));
  2706. return n ? i + n[0].length : -1;
  2707. }
  2708. function d3_time_formatMulti(formats) {
  2709. var n = formats.length, i = -1;
  2710. while (++i < n) formats[i][0] = this(formats[i][0]);
  2711. return function(date) {
  2712. var i = 0, f = formats[i];
  2713. while (!f[1](date)) f = formats[++i];
  2714. return f[0](date);
  2715. };
  2716. }
  2717. d3.locale = function(locale) {
  2718. return {
  2719. numberFormat: d3_locale_numberFormat(locale),
  2720. timeFormat: d3_locale_timeFormat(locale)
  2721. };
  2722. };
  2723. var d3_locale_enUS = d3.locale({
  2724. decimal: ".",
  2725. thousands: ",",
  2726. grouping: [ 3 ],
  2727. currency: [ "$", "" ],
  2728. dateTime: "%a %b %e %X %Y",
  2729. date: "%m/%d/%Y",
  2730. time: "%H:%M:%S",
  2731. periods: [ "AM", "PM" ],
  2732. days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
  2733. shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
  2734. months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  2735. shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
  2736. });
  2737. d3.format = d3_locale_enUS.numberFormat;
  2738. d3.geo = {};
  2739. function d3_adder() {}
  2740. d3_adder.prototype = {
  2741. s: 0,
  2742. t: 0,
  2743. add: function(y) {
  2744. d3_adderSum(y, this.t, d3_adderTemp);
  2745. d3_adderSum(d3_adderTemp.s, this.s, this);
  2746. if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
  2747. },
  2748. reset: function() {
  2749. this.s = this.t = 0;
  2750. },
  2751. valueOf: function() {
  2752. return this.s;
  2753. }
  2754. };
  2755. var d3_adderTemp = new d3_adder();
  2756. function d3_adderSum(a, b, o) {
  2757. var x = o.s = a + b, bv = x - a, av = x - bv;
  2758. o.t = a - av + (b - bv);
  2759. }
  2760. d3.geo.stream = function(object, listener) {
  2761. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  2762. d3_geo_streamObjectType[object.type](object, listener);
  2763. } else {
  2764. d3_geo_streamGeometry(object, listener);
  2765. }
  2766. };
  2767. function d3_geo_streamGeometry(geometry, listener) {
  2768. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  2769. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  2770. }
  2771. }
  2772. var d3_geo_streamObjectType = {
  2773. Feature: function(feature, listener) {
  2774. d3_geo_streamGeometry(feature.geometry, listener);
  2775. },
  2776. FeatureCollection: function(object, listener) {
  2777. var features = object.features, i = -1, n = features.length;
  2778. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  2779. }
  2780. };
  2781. var d3_geo_streamGeometryType = {
  2782. Sphere: function(object, listener) {
  2783. listener.sphere();
  2784. },
  2785. Point: function(object, listener) {
  2786. object = object.coordinates;
  2787. listener.point(object[0], object[1], object[2]);
  2788. },
  2789. MultiPoint: function(object, listener) {
  2790. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2791. while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
  2792. },
  2793. LineString: function(object, listener) {
  2794. d3_geo_streamLine(object.coordinates, listener, 0);
  2795. },
  2796. MultiLineString: function(object, listener) {
  2797. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2798. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  2799. },
  2800. Polygon: function(object, listener) {
  2801. d3_geo_streamPolygon(object.coordinates, listener);
  2802. },
  2803. MultiPolygon: function(object, listener) {
  2804. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2805. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  2806. },
  2807. GeometryCollection: function(object, listener) {
  2808. var geometries = object.geometries, i = -1, n = geometries.length;
  2809. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  2810. }
  2811. };
  2812. function d3_geo_streamLine(coordinates, listener, closed) {
  2813. var i = -1, n = coordinates.length - closed, coordinate;
  2814. listener.lineStart();
  2815. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
  2816. listener.lineEnd();
  2817. }
  2818. function d3_geo_streamPolygon(coordinates, listener) {
  2819. var i = -1, n = coordinates.length;
  2820. listener.polygonStart();
  2821. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  2822. listener.polygonEnd();
  2823. }
  2824. d3.geo.area = function(object) {
  2825. d3_geo_areaSum = 0;
  2826. d3.geo.stream(object, d3_geo_area);
  2827. return d3_geo_areaSum;
  2828. };
  2829. var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
  2830. var d3_geo_area = {
  2831. sphere: function() {
  2832. d3_geo_areaSum += 4 * π;
  2833. },
  2834. point: d3_noop,
  2835. lineStart: d3_noop,
  2836. lineEnd: d3_noop,
  2837. polygonStart: function() {
  2838. d3_geo_areaRingSum.reset();
  2839. d3_geo_area.lineStart = d3_geo_areaRingStart;
  2840. },
  2841. polygonEnd: function() {
  2842. var area = 2 * d3_geo_areaRingSum;
  2843. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  2844. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  2845. }
  2846. };
  2847. function d3_geo_areaRingStart() {
  2848. var λ00, φ00, λ0, cosφ0, sinφ0;
  2849. d3_geo_area.point = function(λ, φ) {
  2850. d3_geo_area.point = nextPoint;
  2851. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  2852. sinφ0 = Math.sin(φ);
  2853. };
  2854. function nextPoint(λ, φ) {
  2855. λ *= d3_radians;
  2856. φ = φ * d3_radians / 2 + π / 4;
  2857. var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
  2858. d3_geo_areaRingSum.add(Math.atan2(v, u));
  2859. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  2860. }
  2861. d3_geo_area.lineEnd = function() {
  2862. nextPoint(λ00, φ00);
  2863. };
  2864. }
  2865. function d3_geo_cartesian(spherical) {
  2866. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  2867. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  2868. }
  2869. function d3_geo_cartesianDot(a, b) {
  2870. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  2871. }
  2872. function d3_geo_cartesianCross(a, b) {
  2873. 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] ];
  2874. }
  2875. function d3_geo_cartesianAdd(a, b) {
  2876. a[0] += b[0];
  2877. a[1] += b[1];
  2878. a[2] += b[2];
  2879. }
  2880. function d3_geo_cartesianScale(vector, k) {
  2881. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  2882. }
  2883. function d3_geo_cartesianNormalize(d) {
  2884. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  2885. d[0] /= l;
  2886. d[1] /= l;
  2887. d[2] /= l;
  2888. }
  2889. function d3_geo_spherical(cartesian) {
  2890. return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
  2891. }
  2892. function d3_geo_sphericalEqual(a, b) {
  2893. return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
  2894. }
  2895. d3.geo.bounds = function() {
  2896. var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
  2897. var bound = {
  2898. point: point,
  2899. lineStart: lineStart,
  2900. lineEnd: lineEnd,
  2901. polygonStart: function() {
  2902. bound.point = ringPoint;
  2903. bound.lineStart = ringStart;
  2904. bound.lineEnd = ringEnd;
  2905. dλSum = 0;
  2906. d3_geo_area.polygonStart();
  2907. },
  2908. polygonEnd: function() {
  2909. d3_geo_area.polygonEnd();
  2910. bound.point = point;
  2911. bound.lineStart = lineStart;
  2912. bound.lineEnd = lineEnd;
  2913. if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
  2914. range[0] = λ0, range[1] = λ1;
  2915. }
  2916. };
  2917. function point(λ, φ) {
  2918. ranges.push(range = [ λ0 = λ, λ1 = λ ]);
  2919. if (φ < φ0) φ0 = φ;
  2920. if (φ > φ1) φ1 = φ;
  2921. }
  2922. function linePoint(λ, φ) {
  2923. var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
  2924. if (p0) {
  2925. var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
  2926. d3_geo_cartesianNormalize(inflection);
  2927. inflection = d3_geo_spherical(inflection);
  2928. var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
  2929. if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  2930. var φi = inflection[1] * d3_degrees;
  2931. if (φi > φ1) φ1 = φi;
  2932. } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  2933. var φi = -inflection[1] * d3_degrees;
  2934. if (φi < φ0) φ0 = φi;
  2935. } else {
  2936. if (φ < φ0) φ0 = φ;
  2937. if (φ > φ1) φ1 = φ;
  2938. }
  2939. if (antimeridian) {
  2940. if (λ < λ_) {
  2941. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  2942. } else {
  2943. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  2944. }
  2945. } else {
  2946. if (λ1 >= λ0) {
  2947. if (λ < λ0) λ0 = λ;
  2948. if (λ > λ1) λ1 = λ;
  2949. } else {
  2950. if (λ > λ_) {
  2951. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  2952. } else {
  2953. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  2954. }
  2955. }
  2956. }
  2957. } else {
  2958. point(λ, φ);
  2959. }
  2960. p0 = p, λ_ = λ;
  2961. }
  2962. function lineStart() {
  2963. bound.point = linePoint;
  2964. }
  2965. function lineEnd() {
  2966. range[0] = λ0, range[1] = λ1;
  2967. bound.point = point;
  2968. p0 = null;
  2969. }
  2970. function ringPoint(λ, φ) {
  2971. if (p0) {
  2972. var dλ = λ - λ_;
  2973. dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
  2974. } else λ__ = λ, φ__ = φ;
  2975. d3_geo_area.point(λ, φ);
  2976. linePoint(λ, φ);
  2977. }
  2978. function ringStart() {
  2979. d3_geo_area.lineStart();
  2980. }
  2981. function ringEnd() {
  2982. ringPoint(λ__, φ__);
  2983. d3_geo_area.lineEnd();
  2984. if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
  2985. range[0] = λ0, range[1] = λ1;
  2986. p0 = null;
  2987. }
  2988. function angle(λ0, λ1) {
  2989. return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
  2990. }
  2991. function compareRanges(a, b) {
  2992. return a[0] - b[0];
  2993. }
  2994. function withinRange(x, range) {
  2995. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  2996. }
  2997. return function(feature) {
  2998. φ1 = λ1 = -(λ0 = φ0 = Infinity);
  2999. ranges = [];
  3000. d3.geo.stream(feature, bound);
  3001. var n = ranges.length;
  3002. if (n) {
  3003. ranges.sort(compareRanges);
  3004. for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
  3005. b = ranges[i];
  3006. if (withinRange(b[0], a) || withinRange(b[1], a)) {
  3007. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  3008. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  3009. } else {
  3010. merged.push(a = b);
  3011. }
  3012. }
  3013. var best = -Infinity, dλ;
  3014. for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
  3015. b = merged[i];
  3016. if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
  3017. }
  3018. }
  3019. ranges = range = null;
  3020. return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
  3021. };
  3022. }();
  3023. d3.geo.centroid = function(object) {
  3024. 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;
  3025. d3.geo.stream(object, d3_geo_centroid);
  3026. var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
  3027. if (m < ε2) {
  3028. x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
  3029. if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
  3030. m = x * x + y * y + z * z;
  3031. if (m < ε2) return [ NaN, NaN ];
  3032. }
  3033. return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
  3034. };
  3035. 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;
  3036. var d3_geo_centroid = {
  3037. sphere: d3_noop,
  3038. point: d3_geo_centroidPoint,
  3039. lineStart: d3_geo_centroidLineStart,
  3040. lineEnd: d3_geo_centroidLineEnd,
  3041. polygonStart: function() {
  3042. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  3043. },
  3044. polygonEnd: function() {
  3045. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  3046. }
  3047. };
  3048. function d3_geo_centroidPoint(λ, φ) {
  3049. λ *= d3_radians;
  3050. var cosφ = Math.cos(φ *= d3_radians);
  3051. d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
  3052. }
  3053. function d3_geo_centroidPointXYZ(x, y, z) {
  3054. ++d3_geo_centroidW0;
  3055. d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
  3056. d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
  3057. d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
  3058. }
  3059. function d3_geo_centroidLineStart() {
  3060. var x0, y0, z0;
  3061. d3_geo_centroid.point = function(λ, φ) {
  3062. λ *= d3_radians;
  3063. var cosφ = Math.cos(φ *= d3_radians);
  3064. x0 = cosφ * Math.cos(λ);
  3065. y0 = cosφ * Math.sin(λ);
  3066. z0 = Math.sin(φ);
  3067. d3_geo_centroid.point = nextPoint;
  3068. d3_geo_centroidPointXYZ(x0, y0, z0);
  3069. };
  3070. function nextPoint(λ, φ) {
  3071. λ *= d3_radians;
  3072. 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);
  3073. d3_geo_centroidW1 += w;
  3074. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3075. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3076. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3077. d3_geo_centroidPointXYZ(x0, y0, z0);
  3078. }
  3079. }
  3080. function d3_geo_centroidLineEnd() {
  3081. d3_geo_centroid.point = d3_geo_centroidPoint;
  3082. }
  3083. function d3_geo_centroidRingStart() {
  3084. var λ00, φ00, x0, y0, z0;
  3085. d3_geo_centroid.point = function(λ, φ) {
  3086. λ00 = λ, φ00 = φ;
  3087. d3_geo_centroid.point = nextPoint;
  3088. λ *= d3_radians;
  3089. var cosφ = Math.cos(φ *= d3_radians);
  3090. x0 = cosφ * Math.cos(λ);
  3091. y0 = cosφ * Math.sin(λ);
  3092. z0 = Math.sin(φ);
  3093. d3_geo_centroidPointXYZ(x0, y0, z0);
  3094. };
  3095. d3_geo_centroid.lineEnd = function() {
  3096. nextPoint(λ00, φ00);
  3097. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  3098. d3_geo_centroid.point = d3_geo_centroidPoint;
  3099. };
  3100. function nextPoint(λ, φ) {
  3101. λ *= d3_radians;
  3102. 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);
  3103. d3_geo_centroidX2 += v * cx;
  3104. d3_geo_centroidY2 += v * cy;
  3105. d3_geo_centroidZ2 += v * cz;
  3106. d3_geo_centroidW1 += w;
  3107. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3108. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3109. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3110. d3_geo_centroidPointXYZ(x0, y0, z0);
  3111. }
  3112. }
  3113. function d3_true() {
  3114. return true;
  3115. }
  3116. function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
  3117. var subject = [], clip = [];
  3118. segments.forEach(function(segment) {
  3119. if ((n = segment.length - 1) <= 0) return;
  3120. var n, p0 = segment[0], p1 = segment[n];
  3121. if (d3_geo_sphericalEqual(p0, p1)) {
  3122. listener.lineStart();
  3123. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  3124. listener.lineEnd();
  3125. return;
  3126. }
  3127. var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
  3128. a.o = b;
  3129. subject.push(a);
  3130. clip.push(b);
  3131. a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
  3132. b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
  3133. a.o = b;
  3134. subject.push(a);
  3135. clip.push(b);
  3136. });
  3137. clip.sort(compare);
  3138. d3_geo_clipPolygonLinkCircular(subject);
  3139. d3_geo_clipPolygonLinkCircular(clip);
  3140. if (!subject.length) return;
  3141. for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
  3142. clip[i].e = entry = !entry;
  3143. }
  3144. var start = subject[0], points, point;
  3145. while (1) {
  3146. var current = start, isSubject = true;
  3147. while (current.v) if ((current = current.n) === start) return;
  3148. points = current.z;
  3149. listener.lineStart();
  3150. do {
  3151. current.v = current.o.v = true;
  3152. if (current.e) {
  3153. if (isSubject) {
  3154. for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
  3155. } else {
  3156. interpolate(current.x, current.n.x, 1, listener);
  3157. }
  3158. current = current.n;
  3159. } else {
  3160. if (isSubject) {
  3161. points = current.p.z;
  3162. for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
  3163. } else {
  3164. interpolate(current.x, current.p.x, -1, listener);
  3165. }
  3166. current = current.p;
  3167. }
  3168. current = current.o;
  3169. points = current.z;
  3170. isSubject = !isSubject;
  3171. } while (!current.v);
  3172. listener.lineEnd();
  3173. }
  3174. }
  3175. function d3_geo_clipPolygonLinkCircular(array) {
  3176. if (!(n = array.length)) return;
  3177. var n, i = 0, a = array[0], b;
  3178. while (++i < n) {
  3179. a.n = b = array[i];
  3180. b.p = a;
  3181. a = b;
  3182. }
  3183. a.n = b = array[0];
  3184. b.p = a;
  3185. }
  3186. function d3_geo_clipPolygonIntersection(point, points, other, entry) {
  3187. this.x = point;
  3188. this.z = points;
  3189. this.o = other;
  3190. this.e = entry;
  3191. this.v = false;
  3192. this.n = this.p = null;
  3193. }
  3194. function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
  3195. return function(rotate, listener) {
  3196. var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
  3197. var clip = {
  3198. point: point,
  3199. lineStart: lineStart,
  3200. lineEnd: lineEnd,
  3201. polygonStart: function() {
  3202. clip.point = pointRing;
  3203. clip.lineStart = ringStart;
  3204. clip.lineEnd = ringEnd;
  3205. segments = [];
  3206. polygon = [];
  3207. },
  3208. polygonEnd: function() {
  3209. clip.point = point;
  3210. clip.lineStart = lineStart;
  3211. clip.lineEnd = lineEnd;
  3212. segments = d3.merge(segments);
  3213. var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
  3214. if (segments.length) {
  3215. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3216. d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
  3217. } else if (clipStartInside) {
  3218. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3219. listener.lineStart();
  3220. interpolate(null, null, 1, listener);
  3221. listener.lineEnd();
  3222. }
  3223. if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
  3224. segments = polygon = null;
  3225. },
  3226. sphere: function() {
  3227. listener.polygonStart();
  3228. listener.lineStart();
  3229. interpolate(null, null, 1, listener);
  3230. listener.lineEnd();
  3231. listener.polygonEnd();
  3232. }
  3233. };
  3234. function point(λ, φ) {
  3235. var point = rotate(λ, φ);
  3236. if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
  3237. }
  3238. function pointLine(λ, φ) {
  3239. var point = rotate(λ, φ);
  3240. line.point(point[0], point[1]);
  3241. }
  3242. function lineStart() {
  3243. clip.point = pointLine;
  3244. line.lineStart();
  3245. }
  3246. function lineEnd() {
  3247. clip.point = point;
  3248. line.lineEnd();
  3249. }
  3250. var segments;
  3251. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
  3252. function pointRing(λ, φ) {
  3253. ring.push([ λ, φ ]);
  3254. var point = rotate(λ, φ);
  3255. ringListener.point(point[0], point[1]);
  3256. }
  3257. function ringStart() {
  3258. ringListener.lineStart();
  3259. ring = [];
  3260. }
  3261. function ringEnd() {
  3262. pointRing(ring[0][0], ring[0][1]);
  3263. ringListener.lineEnd();
  3264. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  3265. ring.pop();
  3266. polygon.push(ring);
  3267. ring = null;
  3268. if (!n) return;
  3269. if (clean & 1) {
  3270. segment = ringSegments[0];
  3271. var n = segment.length - 1, i = -1, point;
  3272. if (n > 0) {
  3273. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3274. listener.lineStart();
  3275. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  3276. listener.lineEnd();
  3277. }
  3278. return;
  3279. }
  3280. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  3281. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  3282. }
  3283. return clip;
  3284. };
  3285. }
  3286. function d3_geo_clipSegmentLength1(segment) {
  3287. return segment.length > 1;
  3288. }
  3289. function d3_geo_clipBufferListener() {
  3290. var lines = [], line;
  3291. return {
  3292. lineStart: function() {
  3293. lines.push(line = []);
  3294. },
  3295. point: function(λ, φ) {
  3296. line.push([ λ, φ ]);
  3297. },
  3298. lineEnd: d3_noop,
  3299. buffer: function() {
  3300. var buffer = lines;
  3301. lines = [];
  3302. line = null;
  3303. return buffer;
  3304. },
  3305. rejoin: function() {
  3306. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  3307. }
  3308. };
  3309. }
  3310. function d3_geo_clipSort(a, b) {
  3311. return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
  3312. }
  3313. function d3_geo_pointInPolygon(point, polygon) {
  3314. var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
  3315. d3_geo_areaRingSum.reset();
  3316. for (var i = 0, n = polygon.length; i < n; ++i) {
  3317. var ring = polygon[i], m = ring.length;
  3318. if (!m) continue;
  3319. var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
  3320. while (true) {
  3321. if (j === m) j = 0;
  3322. point = ring[j];
  3323. var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;
  3324. d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
  3325. polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
  3326. if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
  3327. var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
  3328. d3_geo_cartesianNormalize(arc);
  3329. var intersection = d3_geo_cartesianCross(meridianNormal, arc);
  3330. d3_geo_cartesianNormalize(intersection);
  3331. var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
  3332. if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
  3333. winding += antimeridian ^ dλ >= 0 ? 1 : -1;
  3334. }
  3335. }
  3336. if (!j++) break;
  3337. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
  3338. }
  3339. }
  3340. return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
  3341. }
  3342. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
  3343. function d3_geo_clipAntimeridianLine(listener) {
  3344. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  3345. return {
  3346. lineStart: function() {
  3347. listener.lineStart();
  3348. clean = 1;
  3349. },
  3350. point: function(λ1, φ1) {
  3351. var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
  3352. if (abs(dλ - π) < ε) {
  3353. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
  3354. listener.point(sλ0, φ0);
  3355. listener.lineEnd();
  3356. listener.lineStart();
  3357. listener.point(sλ1, φ0);
  3358. listener.point(λ1, φ0);
  3359. clean = 0;
  3360. } else if (sλ0 !== sλ1 && dλ >= π) {
  3361. if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  3362. if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  3363. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  3364. listener.point(sλ0, φ0);
  3365. listener.lineEnd();
  3366. listener.lineStart();
  3367. listener.point(sλ1, φ0);
  3368. clean = 0;
  3369. }
  3370. listener.point(λ0 = λ1, φ0 = φ1);
  3371. sλ0 = sλ1;
  3372. },
  3373. lineEnd: function() {
  3374. listener.lineEnd();
  3375. λ0 = φ0 = NaN;
  3376. },
  3377. clean: function() {
  3378. return 2 - clean;
  3379. }
  3380. };
  3381. }
  3382. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  3383. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  3384. return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
  3385. }
  3386. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  3387. var φ;
  3388. if (from == null) {
  3389. φ = direction * halfπ;
  3390. listener.point(-π, φ);
  3391. listener.point(0, φ);
  3392. listener.point(π, φ);
  3393. listener.point(π, 0);
  3394. listener.point(π, -φ);
  3395. listener.point(0, -φ);
  3396. listener.point(-π, -φ);
  3397. listener.point(-π, 0);
  3398. listener.point(-π, φ);
  3399. } else if (abs(from[0] - to[0]) > ε) {
  3400. var s = from[0] < to[0] ? π : -π;
  3401. φ = direction * s / 2;
  3402. listener.point(-s, φ);
  3403. listener.point(0, φ);
  3404. listener.point(s, φ);
  3405. } else {
  3406. listener.point(to[0], to[1]);
  3407. }
  3408. }
  3409. function d3_geo_clipCircle(radius) {
  3410. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  3411. return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
  3412. function visible(λ, φ) {
  3413. return Math.cos(λ) * Math.cos(φ) > cr;
  3414. }
  3415. function clipLine(listener) {
  3416. var point0, c0, v0, v00, clean;
  3417. return {
  3418. lineStart: function() {
  3419. v00 = v0 = false;
  3420. clean = 1;
  3421. },
  3422. point: function(λ, φ) {
  3423. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  3424. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  3425. if (v !== v0) {
  3426. point2 = intersect(point0, point1);
  3427. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  3428. point1[0] += ε;
  3429. point1[1] += ε;
  3430. v = visible(point1[0], point1[1]);
  3431. }
  3432. }
  3433. if (v !== v0) {
  3434. clean = 0;
  3435. if (v) {
  3436. listener.lineStart();
  3437. point2 = intersect(point1, point0);
  3438. listener.point(point2[0], point2[1]);
  3439. } else {
  3440. point2 = intersect(point0, point1);
  3441. listener.point(point2[0], point2[1]);
  3442. listener.lineEnd();
  3443. }
  3444. point0 = point2;
  3445. } else if (notHemisphere && point0 && smallRadius ^ v) {
  3446. var t;
  3447. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  3448. clean = 0;
  3449. if (smallRadius) {
  3450. listener.lineStart();
  3451. listener.point(t[0][0], t[0][1]);
  3452. listener.point(t[1][0], t[1][1]);
  3453. listener.lineEnd();
  3454. } else {
  3455. listener.point(t[1][0], t[1][1]);
  3456. listener.lineEnd();
  3457. listener.lineStart();
  3458. listener.point(t[0][0], t[0][1]);
  3459. }
  3460. }
  3461. }
  3462. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  3463. listener.point(point1[0], point1[1]);
  3464. }
  3465. point0 = point1, v0 = v, c0 = c;
  3466. },
  3467. lineEnd: function() {
  3468. if (v0) listener.lineEnd();
  3469. point0 = null;
  3470. },
  3471. clean: function() {
  3472. return clean | (v00 && v0) << 1;
  3473. }
  3474. };
  3475. }
  3476. function intersect(a, b, two) {
  3477. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  3478. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  3479. if (!determinant) return !two && a;
  3480. 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);
  3481. d3_geo_cartesianAdd(A, B);
  3482. 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);
  3483. if (t2 < 0) return;
  3484. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  3485. d3_geo_cartesianAdd(q, A);
  3486. q = d3_geo_spherical(q);
  3487. if (!two) return q;
  3488. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  3489. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  3490. var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
  3491. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  3492. if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
  3493. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  3494. d3_geo_cartesianAdd(q1, A);
  3495. return [ q, d3_geo_spherical(q1) ];
  3496. }
  3497. }
  3498. function code(λ, φ) {
  3499. var r = smallRadius ? radius : π - radius, code = 0;
  3500. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  3501. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  3502. return code;
  3503. }
  3504. }
  3505. function d3_geom_clipLine(x0, y0, x1, y1) {
  3506. return function(line) {
  3507. var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
  3508. r = x0 - ax;
  3509. if (!dx && r > 0) return;
  3510. r /= dx;
  3511. if (dx < 0) {
  3512. if (r < t0) return;
  3513. if (r < t1) t1 = r;
  3514. } else if (dx > 0) {
  3515. if (r > t1) return;
  3516. if (r > t0) t0 = r;
  3517. }
  3518. r = x1 - ax;
  3519. if (!dx && r < 0) return;
  3520. r /= dx;
  3521. if (dx < 0) {
  3522. if (r > t1) return;
  3523. if (r > t0) t0 = r;
  3524. } else if (dx > 0) {
  3525. if (r < t0) return;
  3526. if (r < t1) t1 = r;
  3527. }
  3528. r = y0 - ay;
  3529. if (!dy && r > 0) return;
  3530. r /= dy;
  3531. if (dy < 0) {
  3532. if (r < t0) return;
  3533. if (r < t1) t1 = r;
  3534. } else if (dy > 0) {
  3535. if (r > t1) return;
  3536. if (r > t0) t0 = r;
  3537. }
  3538. r = y1 - ay;
  3539. if (!dy && r < 0) return;
  3540. r /= dy;
  3541. if (dy < 0) {
  3542. if (r > t1) return;
  3543. if (r > t0) t0 = r;
  3544. } else if (dy > 0) {
  3545. if (r < t0) return;
  3546. if (r < t1) t1 = r;
  3547. }
  3548. if (t0 > 0) line.a = {
  3549. x: ax + t0 * dx,
  3550. y: ay + t0 * dy
  3551. };
  3552. if (t1 < 1) line.b = {
  3553. x: ax + t1 * dx,
  3554. y: ay + t1 * dy
  3555. };
  3556. return line;
  3557. };
  3558. }
  3559. var d3_geo_clipExtentMAX = 1e9;
  3560. d3.geo.clipExtent = function() {
  3561. var x0, y0, x1, y1, stream, clip, clipExtent = {
  3562. stream: function(output) {
  3563. if (stream) stream.valid = false;
  3564. stream = clip(output);
  3565. stream.valid = true;
  3566. return stream;
  3567. },
  3568. extent: function(_) {
  3569. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3570. clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
  3571. if (stream) stream.valid = false, stream = null;
  3572. return clipExtent;
  3573. }
  3574. };
  3575. return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
  3576. };
  3577. function d3_geo_clipExtent(x0, y0, x1, y1) {
  3578. return function(listener) {
  3579. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
  3580. var clip = {
  3581. point: point,
  3582. lineStart: lineStart,
  3583. lineEnd: lineEnd,
  3584. polygonStart: function() {
  3585. listener = bufferListener;
  3586. segments = [];
  3587. polygon = [];
  3588. clean = true;
  3589. },
  3590. polygonEnd: function() {
  3591. listener = listener_;
  3592. segments = d3.merge(segments);
  3593. var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
  3594. if (inside || visible) {
  3595. listener.polygonStart();
  3596. if (inside) {
  3597. listener.lineStart();
  3598. interpolate(null, null, 1, listener);
  3599. listener.lineEnd();
  3600. }
  3601. if (visible) {
  3602. d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
  3603. }
  3604. listener.polygonEnd();
  3605. }
  3606. segments = polygon = ring = null;
  3607. }
  3608. };
  3609. function insidePolygon(p) {
  3610. var wn = 0, n = polygon.length, y = p[1];
  3611. for (var i = 0; i < n; ++i) {
  3612. for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
  3613. b = v[j];
  3614. if (a[1] <= y) {
  3615. if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
  3616. } else {
  3617. if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
  3618. }
  3619. a = b;
  3620. }
  3621. }
  3622. return wn !== 0;
  3623. }
  3624. function interpolate(from, to, direction, listener) {
  3625. var a = 0, a1 = 0;
  3626. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  3627. do {
  3628. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  3629. } while ((a = (a + direction + 4) % 4) !== a1);
  3630. } else {
  3631. listener.point(to[0], to[1]);
  3632. }
  3633. }
  3634. function pointVisible(x, y) {
  3635. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  3636. }
  3637. function point(x, y) {
  3638. if (pointVisible(x, y)) listener.point(x, y);
  3639. }
  3640. var x__, y__, v__, x_, y_, v_, first, clean;
  3641. function lineStart() {
  3642. clip.point = linePoint;
  3643. if (polygon) polygon.push(ring = []);
  3644. first = true;
  3645. v_ = false;
  3646. x_ = y_ = NaN;
  3647. }
  3648. function lineEnd() {
  3649. if (segments) {
  3650. linePoint(x__, y__);
  3651. if (v__ && v_) bufferListener.rejoin();
  3652. segments.push(bufferListener.buffer());
  3653. }
  3654. clip.point = point;
  3655. if (v_) listener.lineEnd();
  3656. }
  3657. function linePoint(x, y) {
  3658. x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
  3659. y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
  3660. var v = pointVisible(x, y);
  3661. if (polygon) ring.push([ x, y ]);
  3662. if (first) {
  3663. x__ = x, y__ = y, v__ = v;
  3664. first = false;
  3665. if (v) {
  3666. listener.lineStart();
  3667. listener.point(x, y);
  3668. }
  3669. } else {
  3670. if (v && v_) listener.point(x, y); else {
  3671. var l = {
  3672. a: {
  3673. x: x_,
  3674. y: y_
  3675. },
  3676. b: {
  3677. x: x,
  3678. y: y
  3679. }
  3680. };
  3681. if (clipLine(l)) {
  3682. if (!v_) {
  3683. listener.lineStart();
  3684. listener.point(l.a.x, l.a.y);
  3685. }
  3686. listener.point(l.b.x, l.b.y);
  3687. if (!v) listener.lineEnd();
  3688. clean = false;
  3689. } else if (v) {
  3690. listener.lineStart();
  3691. listener.point(x, y);
  3692. clean = false;
  3693. }
  3694. }
  3695. }
  3696. x_ = x, y_ = y, v_ = v;
  3697. }
  3698. return clip;
  3699. };
  3700. function corner(p, direction) {
  3701. return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
  3702. }
  3703. function compare(a, b) {
  3704. return comparePoints(a.x, b.x);
  3705. }
  3706. function comparePoints(a, b) {
  3707. var ca = corner(a, 1), cb = corner(b, 1);
  3708. 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];
  3709. }
  3710. }
  3711. function d3_geo_compose(a, b) {
  3712. function compose(x, y) {
  3713. return x = a(x, y), b(x[0], x[1]);
  3714. }
  3715. if (a.invert && b.invert) compose.invert = function(x, y) {
  3716. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  3717. };
  3718. return compose;
  3719. }
  3720. function d3_geo_conic(projectAt) {
  3721. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  3722. p.parallels = function(_) {
  3723. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  3724. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  3725. };
  3726. return p;
  3727. }
  3728. function d3_geo_conicEqualArea(φ0, φ1) {
  3729. 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;
  3730. function forward(λ, φ) {
  3731. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  3732. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  3733. }
  3734. forward.invert = function(x, y) {
  3735. var ρ0_y = ρ0 - y;
  3736. return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  3737. };
  3738. return forward;
  3739. }
  3740. (d3.geo.conicEqualArea = function() {
  3741. return d3_geo_conic(d3_geo_conicEqualArea);
  3742. }).raw = d3_geo_conicEqualArea;
  3743. d3.geo.albers = function() {
  3744. return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
  3745. };
  3746. d3.geo.albersUsa = function() {
  3747. var lower48 = d3.geo.albers();
  3748. var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
  3749. var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
  3750. var point, pointStream = {
  3751. point: function(x, y) {
  3752. point = [ x, y ];
  3753. }
  3754. }, lower48Point, alaskaPoint, hawaiiPoint;
  3755. function albersUsa(coordinates) {
  3756. var x = coordinates[0], y = coordinates[1];
  3757. point = null;
  3758. (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
  3759. return point;
  3760. }
  3761. albersUsa.invert = function(coordinates) {
  3762. var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
  3763. return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
  3764. };
  3765. albersUsa.stream = function(stream) {
  3766. var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
  3767. return {
  3768. point: function(x, y) {
  3769. lower48Stream.point(x, y);
  3770. alaskaStream.point(x, y);
  3771. hawaiiStream.point(x, y);
  3772. },
  3773. sphere: function() {
  3774. lower48Stream.sphere();
  3775. alaskaStream.sphere();
  3776. hawaiiStream.sphere();
  3777. },
  3778. lineStart: function() {
  3779. lower48Stream.lineStart();
  3780. alaskaStream.lineStart();
  3781. hawaiiStream.lineStart();
  3782. },
  3783. lineEnd: function() {
  3784. lower48Stream.lineEnd();
  3785. alaskaStream.lineEnd();
  3786. hawaiiStream.lineEnd();
  3787. },
  3788. polygonStart: function() {
  3789. lower48Stream.polygonStart();
  3790. alaskaStream.polygonStart();
  3791. hawaiiStream.polygonStart();
  3792. },
  3793. polygonEnd: function() {
  3794. lower48Stream.polygonEnd();
  3795. alaskaStream.polygonEnd();
  3796. hawaiiStream.polygonEnd();
  3797. }
  3798. };
  3799. };
  3800. albersUsa.precision = function(_) {
  3801. if (!arguments.length) return lower48.precision();
  3802. lower48.precision(_);
  3803. alaska.precision(_);
  3804. hawaii.precision(_);
  3805. return albersUsa;
  3806. };
  3807. albersUsa.scale = function(_) {
  3808. if (!arguments.length) return lower48.scale();
  3809. lower48.scale(_);
  3810. alaska.scale(_ * .35);
  3811. hawaii.scale(_);
  3812. return albersUsa.translate(lower48.translate());
  3813. };
  3814. albersUsa.translate = function(_) {
  3815. if (!arguments.length) return lower48.translate();
  3816. var k = lower48.scale(), x = +_[0], y = +_[1];
  3817. lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
  3818. 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;
  3819. 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;
  3820. return albersUsa;
  3821. };
  3822. return albersUsa.scale(1070);
  3823. };
  3824. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  3825. point: d3_noop,
  3826. lineStart: d3_noop,
  3827. lineEnd: d3_noop,
  3828. polygonStart: function() {
  3829. d3_geo_pathAreaPolygon = 0;
  3830. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  3831. },
  3832. polygonEnd: function() {
  3833. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  3834. d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
  3835. }
  3836. };
  3837. function d3_geo_pathAreaRingStart() {
  3838. var x00, y00, x0, y0;
  3839. d3_geo_pathArea.point = function(x, y) {
  3840. d3_geo_pathArea.point = nextPoint;
  3841. x00 = x0 = x, y00 = y0 = y;
  3842. };
  3843. function nextPoint(x, y) {
  3844. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  3845. x0 = x, y0 = y;
  3846. }
  3847. d3_geo_pathArea.lineEnd = function() {
  3848. nextPoint(x00, y00);
  3849. };
  3850. }
  3851. var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
  3852. var d3_geo_pathBounds = {
  3853. point: d3_geo_pathBoundsPoint,
  3854. lineStart: d3_noop,
  3855. lineEnd: d3_noop,
  3856. polygonStart: d3_noop,
  3857. polygonEnd: d3_noop
  3858. };
  3859. function d3_geo_pathBoundsPoint(x, y) {
  3860. if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
  3861. if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
  3862. if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
  3863. if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
  3864. }
  3865. function d3_geo_pathBuffer() {
  3866. var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
  3867. var stream = {
  3868. point: point,
  3869. lineStart: function() {
  3870. stream.point = pointLineStart;
  3871. },
  3872. lineEnd: lineEnd,
  3873. polygonStart: function() {
  3874. stream.lineEnd = lineEndPolygon;
  3875. },
  3876. polygonEnd: function() {
  3877. stream.lineEnd = lineEnd;
  3878. stream.point = point;
  3879. },
  3880. pointRadius: function(_) {
  3881. pointCircle = d3_geo_pathBufferCircle(_);
  3882. return stream;
  3883. },
  3884. result: function() {
  3885. if (buffer.length) {
  3886. var result = buffer.join("");
  3887. buffer = [];
  3888. return result;
  3889. }
  3890. }
  3891. };
  3892. function point(x, y) {
  3893. buffer.push("M", x, ",", y, pointCircle);
  3894. }
  3895. function pointLineStart(x, y) {
  3896. buffer.push("M", x, ",", y);
  3897. stream.point = pointLine;
  3898. }
  3899. function pointLine(x, y) {
  3900. buffer.push("L", x, ",", y);
  3901. }
  3902. function lineEnd() {
  3903. stream.point = point;
  3904. }
  3905. function lineEndPolygon() {
  3906. buffer.push("Z");
  3907. }
  3908. return stream;
  3909. }
  3910. function d3_geo_pathBufferCircle(radius) {
  3911. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
  3912. }
  3913. var d3_geo_pathCentroid = {
  3914. point: d3_geo_pathCentroidPoint,
  3915. lineStart: d3_geo_pathCentroidLineStart,
  3916. lineEnd: d3_geo_pathCentroidLineEnd,
  3917. polygonStart: function() {
  3918. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  3919. },
  3920. polygonEnd: function() {
  3921. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  3922. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  3923. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  3924. }
  3925. };
  3926. function d3_geo_pathCentroidPoint(x, y) {
  3927. d3_geo_centroidX0 += x;
  3928. d3_geo_centroidY0 += y;
  3929. ++d3_geo_centroidZ0;
  3930. }
  3931. function d3_geo_pathCentroidLineStart() {
  3932. var x0, y0;
  3933. d3_geo_pathCentroid.point = function(x, y) {
  3934. d3_geo_pathCentroid.point = nextPoint;
  3935. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  3936. };
  3937. function nextPoint(x, y) {
  3938. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  3939. d3_geo_centroidX1 += z * (x0 + x) / 2;
  3940. d3_geo_centroidY1 += z * (y0 + y) / 2;
  3941. d3_geo_centroidZ1 += z;
  3942. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  3943. }
  3944. }
  3945. function d3_geo_pathCentroidLineEnd() {
  3946. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  3947. }
  3948. function d3_geo_pathCentroidRingStart() {
  3949. var x00, y00, x0, y0;
  3950. d3_geo_pathCentroid.point = function(x, y) {
  3951. d3_geo_pathCentroid.point = nextPoint;
  3952. d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
  3953. };
  3954. function nextPoint(x, y) {
  3955. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  3956. d3_geo_centroidX1 += z * (x0 + x) / 2;
  3957. d3_geo_centroidY1 += z * (y0 + y) / 2;
  3958. d3_geo_centroidZ1 += z;
  3959. z = y0 * x - x0 * y;
  3960. d3_geo_centroidX2 += z * (x0 + x);
  3961. d3_geo_centroidY2 += z * (y0 + y);
  3962. d3_geo_centroidZ2 += z * 3;
  3963. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  3964. }
  3965. d3_geo_pathCentroid.lineEnd = function() {
  3966. nextPoint(x00, y00);
  3967. };
  3968. }
  3969. function d3_geo_pathContext(context) {
  3970. var pointRadius = 4.5;
  3971. var stream = {
  3972. point: point,
  3973. lineStart: function() {
  3974. stream.point = pointLineStart;
  3975. },
  3976. lineEnd: lineEnd,
  3977. polygonStart: function() {
  3978. stream.lineEnd = lineEndPolygon;
  3979. },
  3980. polygonEnd: function() {
  3981. stream.lineEnd = lineEnd;
  3982. stream.point = point;
  3983. },
  3984. pointRadius: function(_) {
  3985. pointRadius = _;
  3986. return stream;
  3987. },
  3988. result: d3_noop
  3989. };
  3990. function point(x, y) {
  3991. context.moveTo(x, y);
  3992. context.arc(x, y, pointRadius, 0, τ);
  3993. }
  3994. function pointLineStart(x, y) {
  3995. context.moveTo(x, y);
  3996. stream.point = pointLine;
  3997. }
  3998. function pointLine(x, y) {
  3999. context.lineTo(x, y);
  4000. }
  4001. function lineEnd() {
  4002. stream.point = point;
  4003. }
  4004. function lineEndPolygon() {
  4005. context.closePath();
  4006. }
  4007. return stream;
  4008. }
  4009. function d3_geo_resample(project) {
  4010. var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
  4011. function resample(stream) {
  4012. return (maxDepth ? resampleRecursive : resampleNone)(stream);
  4013. }
  4014. function resampleNone(stream) {
  4015. return d3_geo_transformPoint(stream, function(x, y) {
  4016. x = project(x, y);
  4017. stream.point(x[0], x[1]);
  4018. });
  4019. }
  4020. function resampleRecursive(stream) {
  4021. var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
  4022. var resample = {
  4023. point: point,
  4024. lineStart: lineStart,
  4025. lineEnd: lineEnd,
  4026. polygonStart: function() {
  4027. stream.polygonStart();
  4028. resample.lineStart = ringStart;
  4029. },
  4030. polygonEnd: function() {
  4031. stream.polygonEnd();
  4032. resample.lineStart = lineStart;
  4033. }
  4034. };
  4035. function point(x, y) {
  4036. x = project(x, y);
  4037. stream.point(x[0], x[1]);
  4038. }
  4039. function lineStart() {
  4040. x0 = NaN;
  4041. resample.point = linePoint;
  4042. stream.lineStart();
  4043. }
  4044. function linePoint(λ, φ) {
  4045. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  4046. 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);
  4047. stream.point(x0, y0);
  4048. }
  4049. function lineEnd() {
  4050. resample.point = point;
  4051. stream.lineEnd();
  4052. }
  4053. function ringStart() {
  4054. lineStart();
  4055. resample.point = ringPoint;
  4056. resample.lineEnd = ringEnd;
  4057. }
  4058. function ringPoint(λ, φ) {
  4059. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  4060. resample.point = linePoint;
  4061. }
  4062. function ringEnd() {
  4063. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  4064. resample.lineEnd = lineEnd;
  4065. lineEnd();
  4066. }
  4067. return resample;
  4068. }
  4069. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  4070. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  4071. if (d2 > 4 * δ2 && depth--) {
  4072. var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = abs(abs(c) - 1) < ε || abs(λ0 - λ1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
  4073. if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
  4074. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  4075. stream.point(x2, y2);
  4076. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  4077. }
  4078. }
  4079. }
  4080. resample.precision = function(_) {
  4081. if (!arguments.length) return Math.sqrt(δ2);
  4082. maxDepth = (δ2 = _ * _) > 0 && 16;
  4083. return resample;
  4084. };
  4085. return resample;
  4086. }
  4087. d3.geo.path = function() {
  4088. var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
  4089. function path(object) {
  4090. if (object) {
  4091. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  4092. if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
  4093. d3.geo.stream(object, cacheStream);
  4094. }
  4095. return contextStream.result();
  4096. }
  4097. path.area = function(object) {
  4098. d3_geo_pathAreaSum = 0;
  4099. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  4100. return d3_geo_pathAreaSum;
  4101. };
  4102. path.centroid = function(object) {
  4103. 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;
  4104. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  4105. 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 ];
  4106. };
  4107. path.bounds = function(object) {
  4108. d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
  4109. d3.geo.stream(object, projectStream(d3_geo_pathBounds));
  4110. return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
  4111. };
  4112. path.projection = function(_) {
  4113. if (!arguments.length) return projection;
  4114. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  4115. return reset();
  4116. };
  4117. path.context = function(_) {
  4118. if (!arguments.length) return context;
  4119. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  4120. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  4121. return reset();
  4122. };
  4123. path.pointRadius = function(_) {
  4124. if (!arguments.length) return pointRadius;
  4125. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  4126. return path;
  4127. };
  4128. function reset() {
  4129. cacheStream = null;
  4130. return path;
  4131. }
  4132. return path.projection(d3.geo.albersUsa()).context(null);
  4133. };
  4134. function d3_geo_pathProjectStream(project) {
  4135. var resample = d3_geo_resample(function(x, y) {
  4136. return project([ x * d3_degrees, y * d3_degrees ]);
  4137. });
  4138. return function(stream) {
  4139. return d3_geo_projectionRadians(resample(stream));
  4140. };
  4141. }
  4142. d3.geo.transform = function(methods) {
  4143. return {
  4144. stream: function(stream) {
  4145. var transform = new d3_geo_transform(stream);
  4146. for (var k in methods) transform[k] = methods[k];
  4147. return transform;
  4148. }
  4149. };
  4150. };
  4151. function d3_geo_transform(stream) {
  4152. this.stream = stream;
  4153. }
  4154. d3_geo_transform.prototype = {
  4155. point: function(x, y) {
  4156. this.stream.point(x, y);
  4157. },
  4158. sphere: function() {
  4159. this.stream.sphere();
  4160. },
  4161. lineStart: function() {
  4162. this.stream.lineStart();
  4163. },
  4164. lineEnd: function() {
  4165. this.stream.lineEnd();
  4166. },
  4167. polygonStart: function() {
  4168. this.stream.polygonStart();
  4169. },
  4170. polygonEnd: function() {
  4171. this.stream.polygonEnd();
  4172. }
  4173. };
  4174. function d3_geo_transformPoint(stream, point) {
  4175. return {
  4176. point: point,
  4177. sphere: function() {
  4178. stream.sphere();
  4179. },
  4180. lineStart: function() {
  4181. stream.lineStart();
  4182. },
  4183. lineEnd: function() {
  4184. stream.lineEnd();
  4185. },
  4186. polygonStart: function() {
  4187. stream.polygonStart();
  4188. },
  4189. polygonEnd: function() {
  4190. stream.polygonEnd();
  4191. }
  4192. };
  4193. }
  4194. d3.geo.projection = d3_geo_projection;
  4195. d3.geo.projectionMutator = d3_geo_projectionMutator;
  4196. function d3_geo_projection(project) {
  4197. return d3_geo_projectionMutator(function() {
  4198. return project;
  4199. })();
  4200. }
  4201. function d3_geo_projectionMutator(projectAt) {
  4202. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  4203. x = project(x, y);
  4204. return [ x[0] * k + δx, δy - x[1] * k ];
  4205. }), 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;
  4206. function projection(point) {
  4207. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  4208. return [ point[0] * k + δx, δy - point[1] * k ];
  4209. }
  4210. function invert(point) {
  4211. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  4212. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  4213. }
  4214. projection.stream = function(output) {
  4215. if (stream) stream.valid = false;
  4216. stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
  4217. stream.valid = true;
  4218. return stream;
  4219. };
  4220. projection.clipAngle = function(_) {
  4221. if (!arguments.length) return clipAngle;
  4222. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  4223. return invalidate();
  4224. };
  4225. projection.clipExtent = function(_) {
  4226. if (!arguments.length) return clipExtent;
  4227. clipExtent = _;
  4228. postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
  4229. return invalidate();
  4230. };
  4231. projection.scale = function(_) {
  4232. if (!arguments.length) return k;
  4233. k = +_;
  4234. return reset();
  4235. };
  4236. projection.translate = function(_) {
  4237. if (!arguments.length) return [ x, y ];
  4238. x = +_[0];
  4239. y = +_[1];
  4240. return reset();
  4241. };
  4242. projection.center = function(_) {
  4243. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  4244. λ = _[0] % 360 * d3_radians;
  4245. φ = _[1] % 360 * d3_radians;
  4246. return reset();
  4247. };
  4248. projection.rotate = function(_) {
  4249. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  4250. δλ = _[0] % 360 * d3_radians;
  4251. δφ = _[1] % 360 * d3_radians;
  4252. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  4253. return reset();
  4254. };
  4255. d3.rebind(projection, projectResample, "precision");
  4256. function reset() {
  4257. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  4258. var center = project(λ, φ);
  4259. δx = x - center[0] * k;
  4260. δy = y + center[1] * k;
  4261. return invalidate();
  4262. }
  4263. function invalidate() {
  4264. if (stream) stream.valid = false, stream = null;
  4265. return projection;
  4266. }
  4267. return function() {
  4268. project = projectAt.apply(this, arguments);
  4269. projection.invert = project.invert && invert;
  4270. return reset();
  4271. };
  4272. }
  4273. function d3_geo_projectionRadians(stream) {
  4274. return d3_geo_transformPoint(stream, function(x, y) {
  4275. stream.point(x * d3_radians, y * d3_radians);
  4276. });
  4277. }
  4278. function d3_geo_equirectangular(λ, φ) {
  4279. return [ λ, φ ];
  4280. }
  4281. (d3.geo.equirectangular = function() {
  4282. return d3_geo_projection(d3_geo_equirectangular);
  4283. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  4284. d3.geo.rotation = function(rotate) {
  4285. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  4286. function forward(coordinates) {
  4287. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4288. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4289. }
  4290. forward.invert = function(coordinates) {
  4291. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4292. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4293. };
  4294. return forward;
  4295. };
  4296. function d3_geo_identityRotation(λ, φ) {
  4297. return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4298. }
  4299. d3_geo_identityRotation.invert = d3_geo_equirectangular;
  4300. function d3_geo_rotation(δλ, δφ, δγ) {
  4301. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
  4302. }
  4303. function d3_geo_forwardRotationλ(δλ) {
  4304. return function(λ, φ) {
  4305. return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4306. };
  4307. }
  4308. function d3_geo_rotationλ(δλ) {
  4309. var rotation = d3_geo_forwardRotationλ(δλ);
  4310. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  4311. return rotation;
  4312. }
  4313. function d3_geo_rotationφγ(δφ, δγ) {
  4314. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  4315. function rotation(λ, φ) {
  4316. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  4317. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
  4318. }
  4319. rotation.invert = function(λ, φ) {
  4320. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  4321. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
  4322. };
  4323. return rotation;
  4324. }
  4325. d3.geo.circle = function() {
  4326. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  4327. function circle() {
  4328. 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 = [];
  4329. interpolate(null, null, 1, {
  4330. point: function(x, y) {
  4331. ring.push(x = rotate(x, y));
  4332. x[0] *= d3_degrees, x[1] *= d3_degrees;
  4333. }
  4334. });
  4335. return {
  4336. type: "Polygon",
  4337. coordinates: [ ring ]
  4338. };
  4339. }
  4340. circle.origin = function(x) {
  4341. if (!arguments.length) return origin;
  4342. origin = x;
  4343. return circle;
  4344. };
  4345. circle.angle = function(x) {
  4346. if (!arguments.length) return angle;
  4347. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  4348. return circle;
  4349. };
  4350. circle.precision = function(_) {
  4351. if (!arguments.length) return precision;
  4352. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  4353. return circle;
  4354. };
  4355. return circle.angle(90);
  4356. };
  4357. function d3_geo_circleInterpolate(radius, precision) {
  4358. var cr = Math.cos(radius), sr = Math.sin(radius);
  4359. return function(from, to, direction, listener) {
  4360. var step = direction * precision;
  4361. if (from != null) {
  4362. from = d3_geo_circleAngle(cr, from);
  4363. to = d3_geo_circleAngle(cr, to);
  4364. if (direction > 0 ? from < to : from > to) from += direction * τ;
  4365. } else {
  4366. from = radius + direction * τ;
  4367. to = radius - .5 * step;
  4368. }
  4369. for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
  4370. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  4371. }
  4372. };
  4373. }
  4374. function d3_geo_circleAngle(cr, point) {
  4375. var a = d3_geo_cartesian(point);
  4376. a[0] -= cr;
  4377. d3_geo_cartesianNormalize(a);
  4378. var angle = d3_acos(-a[1]);
  4379. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  4380. }
  4381. d3.geo.distance = function(a, b) {
  4382. 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;
  4383. 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Δλ);
  4384. };
  4385. d3.geo.graticule = function() {
  4386. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  4387. function graticule() {
  4388. return {
  4389. type: "MultiLineString",
  4390. coordinates: lines()
  4391. };
  4392. }
  4393. function lines() {
  4394. 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) {
  4395. return abs(x % DX) > ε;
  4396. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  4397. return abs(y % DY) > ε;
  4398. }).map(y));
  4399. }
  4400. graticule.lines = function() {
  4401. return lines().map(function(coordinates) {
  4402. return {
  4403. type: "LineString",
  4404. coordinates: coordinates
  4405. };
  4406. });
  4407. };
  4408. graticule.outline = function() {
  4409. return {
  4410. type: "Polygon",
  4411. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  4412. };
  4413. };
  4414. graticule.extent = function(_) {
  4415. if (!arguments.length) return graticule.minorExtent();
  4416. return graticule.majorExtent(_).minorExtent(_);
  4417. };
  4418. graticule.majorExtent = function(_) {
  4419. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  4420. X0 = +_[0][0], X1 = +_[1][0];
  4421. Y0 = +_[0][1], Y1 = +_[1][1];
  4422. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  4423. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  4424. return graticule.precision(precision);
  4425. };
  4426. graticule.minorExtent = function(_) {
  4427. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  4428. x0 = +_[0][0], x1 = +_[1][0];
  4429. y0 = +_[0][1], y1 = +_[1][1];
  4430. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  4431. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  4432. return graticule.precision(precision);
  4433. };
  4434. graticule.step = function(_) {
  4435. if (!arguments.length) return graticule.minorStep();
  4436. return graticule.majorStep(_).minorStep(_);
  4437. };
  4438. graticule.majorStep = function(_) {
  4439. if (!arguments.length) return [ DX, DY ];
  4440. DX = +_[0], DY = +_[1];
  4441. return graticule;
  4442. };
  4443. graticule.minorStep = function(_) {
  4444. if (!arguments.length) return [ dx, dy ];
  4445. dx = +_[0], dy = +_[1];
  4446. return graticule;
  4447. };
  4448. graticule.precision = function(_) {
  4449. if (!arguments.length) return precision;
  4450. precision = +_;
  4451. x = d3_geo_graticuleX(y0, y1, 90);
  4452. y = d3_geo_graticuleY(x0, x1, precision);
  4453. X = d3_geo_graticuleX(Y0, Y1, 90);
  4454. Y = d3_geo_graticuleY(X0, X1, precision);
  4455. return graticule;
  4456. };
  4457. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  4458. };
  4459. function d3_geo_graticuleX(y0, y1, dy) {
  4460. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  4461. return function(x) {
  4462. return y.map(function(y) {
  4463. return [ x, y ];
  4464. });
  4465. };
  4466. }
  4467. function d3_geo_graticuleY(x0, x1, dx) {
  4468. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  4469. return function(y) {
  4470. return x.map(function(x) {
  4471. return [ x, y ];
  4472. });
  4473. };
  4474. }
  4475. function d3_source(d) {
  4476. return d.source;
  4477. }
  4478. function d3_target(d) {
  4479. return d.target;
  4480. }
  4481. d3.geo.greatArc = function() {
  4482. var source = d3_source, source_, target = d3_target, target_;
  4483. function greatArc() {
  4484. return {
  4485. type: "LineString",
  4486. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  4487. };
  4488. }
  4489. greatArc.distance = function() {
  4490. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  4491. };
  4492. greatArc.source = function(_) {
  4493. if (!arguments.length) return source;
  4494. source = _, source_ = typeof _ === "function" ? null : _;
  4495. return greatArc;
  4496. };
  4497. greatArc.target = function(_) {
  4498. if (!arguments.length) return target;
  4499. target = _, target_ = typeof _ === "function" ? null : _;
  4500. return greatArc;
  4501. };
  4502. greatArc.precision = function() {
  4503. return arguments.length ? greatArc : 0;
  4504. };
  4505. return greatArc;
  4506. };
  4507. d3.geo.interpolate = function(source, target) {
  4508. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  4509. };
  4510. function d3_geo_interpolate(x0, y0, x1, y1) {
  4511. 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);
  4512. var interpolate = d ? function(t) {
  4513. 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;
  4514. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  4515. } : function() {
  4516. return [ x0 * d3_degrees, y0 * d3_degrees ];
  4517. };
  4518. interpolate.distance = d;
  4519. return interpolate;
  4520. }
  4521. d3.geo.length = function(object) {
  4522. d3_geo_lengthSum = 0;
  4523. d3.geo.stream(object, d3_geo_length);
  4524. return d3_geo_lengthSum;
  4525. };
  4526. var d3_geo_lengthSum;
  4527. var d3_geo_length = {
  4528. sphere: d3_noop,
  4529. point: d3_noop,
  4530. lineStart: d3_geo_lengthLineStart,
  4531. lineEnd: d3_noop,
  4532. polygonStart: d3_noop,
  4533. polygonEnd: d3_noop
  4534. };
  4535. function d3_geo_lengthLineStart() {
  4536. var λ0, sinφ0, cosφ0;
  4537. d3_geo_length.point = function(λ, φ) {
  4538. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  4539. d3_geo_length.point = nextPoint;
  4540. };
  4541. d3_geo_length.lineEnd = function() {
  4542. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  4543. };
  4544. function nextPoint(λ, φ) {
  4545. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  4546. 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Δλ);
  4547. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  4548. }
  4549. }
  4550. function d3_geo_azimuthal(scale, angle) {
  4551. function azimuthal(λ, φ) {
  4552. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  4553. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  4554. }
  4555. azimuthal.invert = function(x, y) {
  4556. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  4557. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  4558. };
  4559. return azimuthal;
  4560. }
  4561. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  4562. return Math.sqrt(2 / (1 + cosλcosφ));
  4563. }, function(ρ) {
  4564. return 2 * Math.asin(ρ / 2);
  4565. });
  4566. (d3.geo.azimuthalEqualArea = function() {
  4567. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  4568. }).raw = d3_geo_azimuthalEqualArea;
  4569. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  4570. var c = Math.acos(cosλcosφ);
  4571. return c && c / Math.sin(c);
  4572. }, d3_identity);
  4573. (d3.geo.azimuthalEquidistant = function() {
  4574. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  4575. }).raw = d3_geo_azimuthalEquidistant;
  4576. function d3_geo_conicConformal(φ0, φ1) {
  4577. var cosφ0 = Math.cos(φ0), t = function(φ) {
  4578. return Math.tan(π / 4 + φ / 2);
  4579. }, 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;
  4580. if (!n) return d3_geo_mercator;
  4581. function forward(λ, φ) {
  4582. if (F > 0) {
  4583. if (φ < -halfπ + ε) φ = -halfπ + ε;
  4584. } else {
  4585. if (φ > halfπ - ε) φ = halfπ - ε;
  4586. }
  4587. var ρ = F / Math.pow(t(φ), n);
  4588. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  4589. }
  4590. forward.invert = function(x, y) {
  4591. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  4592. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
  4593. };
  4594. return forward;
  4595. }
  4596. (d3.geo.conicConformal = function() {
  4597. return d3_geo_conic(d3_geo_conicConformal);
  4598. }).raw = d3_geo_conicConformal;
  4599. function d3_geo_conicEquidistant(φ0, φ1) {
  4600. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  4601. if (abs(n) < ε) return d3_geo_equirectangular;
  4602. function forward(λ, φ) {
  4603. var ρ = G - φ;
  4604. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  4605. }
  4606. forward.invert = function(x, y) {
  4607. var ρ0_y = G - y;
  4608. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  4609. };
  4610. return forward;
  4611. }
  4612. (d3.geo.conicEquidistant = function() {
  4613. return d3_geo_conic(d3_geo_conicEquidistant);
  4614. }).raw = d3_geo_conicEquidistant;
  4615. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  4616. return 1 / cosλcosφ;
  4617. }, Math.atan);
  4618. (d3.geo.gnomonic = function() {
  4619. return d3_geo_projection(d3_geo_gnomonic);
  4620. }).raw = d3_geo_gnomonic;
  4621. function d3_geo_mercator(λ, φ) {
  4622. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  4623. }
  4624. d3_geo_mercator.invert = function(x, y) {
  4625. return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
  4626. };
  4627. function d3_geo_mercatorProjection(project) {
  4628. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  4629. m.scale = function() {
  4630. var v = scale.apply(m, arguments);
  4631. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4632. };
  4633. m.translate = function() {
  4634. var v = translate.apply(m, arguments);
  4635. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4636. };
  4637. m.clipExtent = function(_) {
  4638. var v = clipExtent.apply(m, arguments);
  4639. if (v === m) {
  4640. if (clipAuto = _ == null) {
  4641. var k = π * scale(), t = translate();
  4642. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  4643. }
  4644. } else if (clipAuto) {
  4645. v = null;
  4646. }
  4647. return v;
  4648. };
  4649. return m.clipExtent(null);
  4650. }
  4651. (d3.geo.mercator = function() {
  4652. return d3_geo_mercatorProjection(d3_geo_mercator);
  4653. }).raw = d3_geo_mercator;
  4654. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  4655. return 1;
  4656. }, Math.asin);
  4657. (d3.geo.orthographic = function() {
  4658. return d3_geo_projection(d3_geo_orthographic);
  4659. }).raw = d3_geo_orthographic;
  4660. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  4661. return 1 / (1 + cosλcosφ);
  4662. }, function(ρ) {
  4663. return 2 * Math.atan(ρ);
  4664. });
  4665. (d3.geo.stereographic = function() {
  4666. return d3_geo_projection(d3_geo_stereographic);
  4667. }).raw = d3_geo_stereographic;
  4668. function d3_geo_transverseMercator(λ, φ) {
  4669. return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
  4670. }
  4671. d3_geo_transverseMercator.invert = function(x, y) {
  4672. return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
  4673. };
  4674. (d3.geo.transverseMercator = function() {
  4675. var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
  4676. projection.center = function(_) {
  4677. return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
  4678. };
  4679. projection.rotate = function(_) {
  4680. return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
  4681. [ _[0], _[1], _[2] - 90 ]);
  4682. };
  4683. return rotate([ 0, 0, 90 ]);
  4684. }).raw = d3_geo_transverseMercator;
  4685. d3.geom = {};
  4686. function d3_geom_pointX(d) {
  4687. return d[0];
  4688. }
  4689. function d3_geom_pointY(d) {
  4690. return d[1];
  4691. }
  4692. d3.geom.hull = function(vertices) {
  4693. var x = d3_geom_pointX, y = d3_geom_pointY;
  4694. if (arguments.length) return hull(vertices);
  4695. function hull(data) {
  4696. if (data.length < 3) return [];
  4697. var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
  4698. for (i = 0; i < n; i++) {
  4699. points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
  4700. }
  4701. points.sort(d3_geom_hullOrder);
  4702. for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
  4703. var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
  4704. var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
  4705. for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
  4706. for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
  4707. return polygon;
  4708. }
  4709. hull.x = function(_) {
  4710. return arguments.length ? (x = _, hull) : x;
  4711. };
  4712. hull.y = function(_) {
  4713. return arguments.length ? (y = _, hull) : y;
  4714. };
  4715. return hull;
  4716. };
  4717. function d3_geom_hullUpper(points) {
  4718. var n = points.length, hull = [ 0, 1 ], hs = 2;
  4719. for (var i = 2; i < n; i++) {
  4720. while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
  4721. hull[hs++] = i;
  4722. }
  4723. return hull.slice(0, hs);
  4724. }
  4725. function d3_geom_hullOrder(a, b) {
  4726. return a[0] - b[0] || a[1] - b[1];
  4727. }
  4728. d3.geom.polygon = function(coordinates) {
  4729. d3_subclass(coordinates, d3_geom_polygonPrototype);
  4730. return coordinates;
  4731. };
  4732. var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
  4733. d3_geom_polygonPrototype.area = function() {
  4734. var i = -1, n = this.length, a, b = this[n - 1], area = 0;
  4735. while (++i < n) {
  4736. a = b;
  4737. b = this[i];
  4738. area += a[1] * b[0] - a[0] * b[1];
  4739. }
  4740. return area * .5;
  4741. };
  4742. d3_geom_polygonPrototype.centroid = function(k) {
  4743. var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
  4744. if (!arguments.length) k = -1 / (6 * this.area());
  4745. while (++i < n) {
  4746. a = b;
  4747. b = this[i];
  4748. c = a[0] * b[1] - b[0] * a[1];
  4749. x += (a[0] + b[0]) * c;
  4750. y += (a[1] + b[1]) * c;
  4751. }
  4752. return [ x * k, y * k ];
  4753. };
  4754. d3_geom_polygonPrototype.clip = function(subject) {
  4755. 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;
  4756. while (++i < n) {
  4757. input = subject.slice();
  4758. subject.length = 0;
  4759. b = this[i];
  4760. c = input[(m = input.length - closed) - 1];
  4761. j = -1;
  4762. while (++j < m) {
  4763. d = input[j];
  4764. if (d3_geom_polygonInside(d, a, b)) {
  4765. if (!d3_geom_polygonInside(c, a, b)) {
  4766. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4767. }
  4768. subject.push(d);
  4769. } else if (d3_geom_polygonInside(c, a, b)) {
  4770. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4771. }
  4772. c = d;
  4773. }
  4774. if (closed) subject.push(subject[0]);
  4775. a = b;
  4776. }
  4777. return subject;
  4778. };
  4779. function d3_geom_polygonInside(p, a, b) {
  4780. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  4781. }
  4782. function d3_geom_polygonIntersect(c, d, a, b) {
  4783. 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);
  4784. return [ x1 + ua * x21, y1 + ua * y21 ];
  4785. }
  4786. function d3_geom_polygonClosed(coordinates) {
  4787. var a = coordinates[0], b = coordinates[coordinates.length - 1];
  4788. return !(a[0] - b[0] || a[1] - b[1]);
  4789. }
  4790. var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
  4791. function d3_geom_voronoiBeach() {
  4792. d3_geom_voronoiRedBlackNode(this);
  4793. this.edge = this.site = this.circle = null;
  4794. }
  4795. function d3_geom_voronoiCreateBeach(site) {
  4796. var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
  4797. beach.site = site;
  4798. return beach;
  4799. }
  4800. function d3_geom_voronoiDetachBeach(beach) {
  4801. d3_geom_voronoiDetachCircle(beach);
  4802. d3_geom_voronoiBeaches.remove(beach);
  4803. d3_geom_voronoiBeachPool.push(beach);
  4804. d3_geom_voronoiRedBlackNode(beach);
  4805. }
  4806. function d3_geom_voronoiRemoveBeach(beach) {
  4807. var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
  4808. x: x,
  4809. y: y
  4810. }, previous = beach.P, next = beach.N, disappearing = [ beach ];
  4811. d3_geom_voronoiDetachBeach(beach);
  4812. var lArc = previous;
  4813. while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
  4814. previous = lArc.P;
  4815. disappearing.unshift(lArc);
  4816. d3_geom_voronoiDetachBeach(lArc);
  4817. lArc = previous;
  4818. }
  4819. disappearing.unshift(lArc);
  4820. d3_geom_voronoiDetachCircle(lArc);
  4821. var rArc = next;
  4822. while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
  4823. next = rArc.N;
  4824. disappearing.push(rArc);
  4825. d3_geom_voronoiDetachBeach(rArc);
  4826. rArc = next;
  4827. }
  4828. disappearing.push(rArc);
  4829. d3_geom_voronoiDetachCircle(rArc);
  4830. var nArcs = disappearing.length, iArc;
  4831. for (iArc = 1; iArc < nArcs; ++iArc) {
  4832. rArc = disappearing[iArc];
  4833. lArc = disappearing[iArc - 1];
  4834. d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  4835. }
  4836. lArc = disappearing[0];
  4837. rArc = disappearing[nArcs - 1];
  4838. rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
  4839. d3_geom_voronoiAttachCircle(lArc);
  4840. d3_geom_voronoiAttachCircle(rArc);
  4841. }
  4842. function d3_geom_voronoiAddBeach(site) {
  4843. var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
  4844. while (node) {
  4845. dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
  4846. if (dxl > ε) node = node.L; else {
  4847. dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
  4848. if (dxr > ε) {
  4849. if (!node.R) {
  4850. lArc = node;
  4851. break;
  4852. }
  4853. node = node.R;
  4854. } else {
  4855. if (dxl > -ε) {
  4856. lArc = node.P;
  4857. rArc = node;
  4858. } else if (dxr > -ε) {
  4859. lArc = node;
  4860. rArc = node.N;
  4861. } else {
  4862. lArc = rArc = node;
  4863. }
  4864. break;
  4865. }
  4866. }
  4867. }
  4868. var newArc = d3_geom_voronoiCreateBeach(site);
  4869. d3_geom_voronoiBeaches.insert(lArc, newArc);
  4870. if (!lArc && !rArc) return;
  4871. if (lArc === rArc) {
  4872. d3_geom_voronoiDetachCircle(lArc);
  4873. rArc = d3_geom_voronoiCreateBeach(lArc.site);
  4874. d3_geom_voronoiBeaches.insert(newArc, rArc);
  4875. newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4876. d3_geom_voronoiAttachCircle(lArc);
  4877. d3_geom_voronoiAttachCircle(rArc);
  4878. return;
  4879. }
  4880. if (!rArc) {
  4881. newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4882. return;
  4883. }
  4884. d3_geom_voronoiDetachCircle(lArc);
  4885. d3_geom_voronoiDetachCircle(rArc);
  4886. var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
  4887. x: (cy * hb - by * hc) / d + ax,
  4888. y: (bx * hc - cx * hb) / d + ay
  4889. };
  4890. d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
  4891. newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
  4892. rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
  4893. d3_geom_voronoiAttachCircle(lArc);
  4894. d3_geom_voronoiAttachCircle(rArc);
  4895. }
  4896. function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
  4897. var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
  4898. if (!pby2) return rfocx;
  4899. var lArc = arc.P;
  4900. if (!lArc) return -Infinity;
  4901. site = lArc.site;
  4902. var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
  4903. if (!plby2) return lfocx;
  4904. var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
  4905. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  4906. return (rfocx + lfocx) / 2;
  4907. }
  4908. function d3_geom_voronoiRightBreakPoint(arc, directrix) {
  4909. var rArc = arc.N;
  4910. if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
  4911. var site = arc.site;
  4912. return site.y === directrix ? site.x : Infinity;
  4913. }
  4914. function d3_geom_voronoiCell(site) {
  4915. this.site = site;
  4916. this.edges = [];
  4917. }
  4918. d3_geom_voronoiCell.prototype.prepare = function() {
  4919. var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
  4920. while (iHalfEdge--) {
  4921. edge = halfEdges[iHalfEdge].edge;
  4922. if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
  4923. }
  4924. halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
  4925. return halfEdges.length;
  4926. };
  4927. function d3_geom_voronoiCloseCells(extent) {
  4928. var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
  4929. while (iCell--) {
  4930. cell = cells[iCell];
  4931. if (!cell || !cell.prepare()) continue;
  4932. halfEdges = cell.edges;
  4933. nHalfEdges = halfEdges.length;
  4934. iHalfEdge = 0;
  4935. while (iHalfEdge < nHalfEdges) {
  4936. end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
  4937. start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
  4938. if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
  4939. halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
  4940. x: x0,
  4941. y: abs(x2 - x0) < ε ? y2 : y1
  4942. } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
  4943. x: abs(y2 - y1) < ε ? x2 : x1,
  4944. y: y1
  4945. } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
  4946. x: x1,
  4947. y: abs(x2 - x1) < ε ? y2 : y0
  4948. } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
  4949. x: abs(y2 - y0) < ε ? x2 : x0,
  4950. y: y0
  4951. } : null), cell.site, null));
  4952. ++nHalfEdges;
  4953. }
  4954. }
  4955. }
  4956. }
  4957. function d3_geom_voronoiHalfEdgeOrder(a, b) {
  4958. return b.angle - a.angle;
  4959. }
  4960. function d3_geom_voronoiCircle() {
  4961. d3_geom_voronoiRedBlackNode(this);
  4962. this.x = this.y = this.arc = this.site = this.cy = null;
  4963. }
  4964. function d3_geom_voronoiAttachCircle(arc) {
  4965. var lArc = arc.P, rArc = arc.N;
  4966. if (!lArc || !rArc) return;
  4967. var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
  4968. if (lSite === rSite) return;
  4969. var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
  4970. var d = 2 * (ax * cy - ay * cx);
  4971. if (d >= -ε2) return;
  4972. var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
  4973. var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
  4974. circle.arc = arc;
  4975. circle.site = cSite;
  4976. circle.x = x + bx;
  4977. circle.y = cy + Math.sqrt(x * x + y * y);
  4978. circle.cy = cy;
  4979. arc.circle = circle;
  4980. var before = null, node = d3_geom_voronoiCircles._;
  4981. while (node) {
  4982. if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
  4983. if (node.L) node = node.L; else {
  4984. before = node.P;
  4985. break;
  4986. }
  4987. } else {
  4988. if (node.R) node = node.R; else {
  4989. before = node;
  4990. break;
  4991. }
  4992. }
  4993. }
  4994. d3_geom_voronoiCircles.insert(before, circle);
  4995. if (!before) d3_geom_voronoiFirstCircle = circle;
  4996. }
  4997. function d3_geom_voronoiDetachCircle(arc) {
  4998. var circle = arc.circle;
  4999. if (circle) {
  5000. if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
  5001. d3_geom_voronoiCircles.remove(circle);
  5002. d3_geom_voronoiCirclePool.push(circle);
  5003. d3_geom_voronoiRedBlackNode(circle);
  5004. arc.circle = null;
  5005. }
  5006. }
  5007. function d3_geom_voronoiClipEdges(extent) {
  5008. var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
  5009. while (i--) {
  5010. e = edges[i];
  5011. if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
  5012. e.a = e.b = null;
  5013. edges.splice(i, 1);
  5014. }
  5015. }
  5016. }
  5017. function d3_geom_voronoiConnectEdge(edge, extent) {
  5018. var vb = edge.b;
  5019. if (vb) return true;
  5020. var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
  5021. if (ry === ly) {
  5022. if (fx < x0 || fx >= x1) return;
  5023. if (lx > rx) {
  5024. if (!va) va = {
  5025. x: fx,
  5026. y: y0
  5027. }; else if (va.y >= y1) return;
  5028. vb = {
  5029. x: fx,
  5030. y: y1
  5031. };
  5032. } else {
  5033. if (!va) va = {
  5034. x: fx,
  5035. y: y1
  5036. }; else if (va.y < y0) return;
  5037. vb = {
  5038. x: fx,
  5039. y: y0
  5040. };
  5041. }
  5042. } else {
  5043. fm = (lx - rx) / (ry - ly);
  5044. fb = fy - fm * fx;
  5045. if (fm < -1 || fm > 1) {
  5046. if (lx > rx) {
  5047. if (!va) va = {
  5048. x: (y0 - fb) / fm,
  5049. y: y0
  5050. }; else if (va.y >= y1) return;
  5051. vb = {
  5052. x: (y1 - fb) / fm,
  5053. y: y1
  5054. };
  5055. } else {
  5056. if (!va) va = {
  5057. x: (y1 - fb) / fm,
  5058. y: y1
  5059. }; else if (va.y < y0) return;
  5060. vb = {
  5061. x: (y0 - fb) / fm,
  5062. y: y0
  5063. };
  5064. }
  5065. } else {
  5066. if (ly < ry) {
  5067. if (!va) va = {
  5068. x: x0,
  5069. y: fm * x0 + fb
  5070. }; else if (va.x >= x1) return;
  5071. vb = {
  5072. x: x1,
  5073. y: fm * x1 + fb
  5074. };
  5075. } else {
  5076. if (!va) va = {
  5077. x: x1,
  5078. y: fm * x1 + fb
  5079. }; else if (va.x < x0) return;
  5080. vb = {
  5081. x: x0,
  5082. y: fm * x0 + fb
  5083. };
  5084. }
  5085. }
  5086. }
  5087. edge.a = va;
  5088. edge.b = vb;
  5089. return true;
  5090. }
  5091. function d3_geom_voronoiEdge(lSite, rSite) {
  5092. this.l = lSite;
  5093. this.r = rSite;
  5094. this.a = this.b = null;
  5095. }
  5096. function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
  5097. var edge = new d3_geom_voronoiEdge(lSite, rSite);
  5098. d3_geom_voronoiEdges.push(edge);
  5099. if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
  5100. if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
  5101. d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
  5102. d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
  5103. return edge;
  5104. }
  5105. function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
  5106. var edge = new d3_geom_voronoiEdge(lSite, null);
  5107. edge.a = va;
  5108. edge.b = vb;
  5109. d3_geom_voronoiEdges.push(edge);
  5110. return edge;
  5111. }
  5112. function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
  5113. if (!edge.a && !edge.b) {
  5114. edge.a = vertex;
  5115. edge.l = lSite;
  5116. edge.r = rSite;
  5117. } else if (edge.l === rSite) {
  5118. edge.b = vertex;
  5119. } else {
  5120. edge.a = vertex;
  5121. }
  5122. }
  5123. function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
  5124. var va = edge.a, vb = edge.b;
  5125. this.edge = edge;
  5126. this.site = lSite;
  5127. this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
  5128. }
  5129. d3_geom_voronoiHalfEdge.prototype = {
  5130. start: function() {
  5131. return this.edge.l === this.site ? this.edge.a : this.edge.b;
  5132. },
  5133. end: function() {
  5134. return this.edge.l === this.site ? this.edge.b : this.edge.a;
  5135. }
  5136. };
  5137. function d3_geom_voronoiRedBlackTree() {
  5138. this._ = null;
  5139. }
  5140. function d3_geom_voronoiRedBlackNode(node) {
  5141. node.U = node.C = node.L = node.R = node.P = node.N = null;
  5142. }
  5143. d3_geom_voronoiRedBlackTree.prototype = {
  5144. insert: function(after, node) {
  5145. var parent, grandpa, uncle;
  5146. if (after) {
  5147. node.P = after;
  5148. node.N = after.N;
  5149. if (after.N) after.N.P = node;
  5150. after.N = node;
  5151. if (after.R) {
  5152. after = after.R;
  5153. while (after.L) after = after.L;
  5154. after.L = node;
  5155. } else {
  5156. after.R = node;
  5157. }
  5158. parent = after;
  5159. } else if (this._) {
  5160. after = d3_geom_voronoiRedBlackFirst(this._);
  5161. node.P = null;
  5162. node.N = after;
  5163. after.P = after.L = node;
  5164. parent = after;
  5165. } else {
  5166. node.P = node.N = null;
  5167. this._ = node;
  5168. parent = null;
  5169. }
  5170. node.L = node.R = null;
  5171. node.U = parent;
  5172. node.C = true;
  5173. after = node;
  5174. while (parent && parent.C) {
  5175. grandpa = parent.U;
  5176. if (parent === grandpa.L) {
  5177. uncle = grandpa.R;
  5178. if (uncle && uncle.C) {
  5179. parent.C = uncle.C = false;
  5180. grandpa.C = true;
  5181. after = grandpa;
  5182. } else {
  5183. if (after === parent.R) {
  5184. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5185. after = parent;
  5186. parent = after.U;
  5187. }
  5188. parent.C = false;
  5189. grandpa.C = true;
  5190. d3_geom_voronoiRedBlackRotateRight(this, grandpa);
  5191. }
  5192. } else {
  5193. uncle = grandpa.L;
  5194. if (uncle && uncle.C) {
  5195. parent.C = uncle.C = false;
  5196. grandpa.C = true;
  5197. after = grandpa;
  5198. } else {
  5199. if (after === parent.L) {
  5200. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5201. after = parent;
  5202. parent = after.U;
  5203. }
  5204. parent.C = false;
  5205. grandpa.C = true;
  5206. d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
  5207. }
  5208. }
  5209. parent = after.U;
  5210. }
  5211. this._.C = false;
  5212. },
  5213. remove: function(node) {
  5214. if (node.N) node.N.P = node.P;
  5215. if (node.P) node.P.N = node.N;
  5216. node.N = node.P = null;
  5217. var parent = node.U, sibling, left = node.L, right = node.R, next, red;
  5218. if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
  5219. if (parent) {
  5220. if (parent.L === node) parent.L = next; else parent.R = next;
  5221. } else {
  5222. this._ = next;
  5223. }
  5224. if (left && right) {
  5225. red = next.C;
  5226. next.C = node.C;
  5227. next.L = left;
  5228. left.U = next;
  5229. if (next !== right) {
  5230. parent = next.U;
  5231. next.U = node.U;
  5232. node = next.R;
  5233. parent.L = node;
  5234. next.R = right;
  5235. right.U = next;
  5236. } else {
  5237. next.U = parent;
  5238. parent = next;
  5239. node = next.R;
  5240. }
  5241. } else {
  5242. red = node.C;
  5243. node = next;
  5244. }
  5245. if (node) node.U = parent;
  5246. if (red) return;
  5247. if (node && node.C) {
  5248. node.C = false;
  5249. return;
  5250. }
  5251. do {
  5252. if (node === this._) break;
  5253. if (node === parent.L) {
  5254. sibling = parent.R;
  5255. if (sibling.C) {
  5256. sibling.C = false;
  5257. parent.C = true;
  5258. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5259. sibling = parent.R;
  5260. }
  5261. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5262. if (!sibling.R || !sibling.R.C) {
  5263. sibling.L.C = false;
  5264. sibling.C = true;
  5265. d3_geom_voronoiRedBlackRotateRight(this, sibling);
  5266. sibling = parent.R;
  5267. }
  5268. sibling.C = parent.C;
  5269. parent.C = sibling.R.C = false;
  5270. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5271. node = this._;
  5272. break;
  5273. }
  5274. } else {
  5275. sibling = parent.L;
  5276. if (sibling.C) {
  5277. sibling.C = false;
  5278. parent.C = true;
  5279. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5280. sibling = parent.L;
  5281. }
  5282. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5283. if (!sibling.L || !sibling.L.C) {
  5284. sibling.R.C = false;
  5285. sibling.C = true;
  5286. d3_geom_voronoiRedBlackRotateLeft(this, sibling);
  5287. sibling = parent.L;
  5288. }
  5289. sibling.C = parent.C;
  5290. parent.C = sibling.L.C = false;
  5291. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5292. node = this._;
  5293. break;
  5294. }
  5295. }
  5296. sibling.C = true;
  5297. node = parent;
  5298. parent = parent.U;
  5299. } while (!node.C);
  5300. if (node) node.C = false;
  5301. }
  5302. };
  5303. function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
  5304. var p = node, q = node.R, parent = p.U;
  5305. if (parent) {
  5306. if (parent.L === p) parent.L = q; else parent.R = q;
  5307. } else {
  5308. tree._ = q;
  5309. }
  5310. q.U = parent;
  5311. p.U = q;
  5312. p.R = q.L;
  5313. if (p.R) p.R.U = p;
  5314. q.L = p;
  5315. }
  5316. function d3_geom_voronoiRedBlackRotateRight(tree, node) {
  5317. var p = node, q = node.L, parent = p.U;
  5318. if (parent) {
  5319. if (parent.L === p) parent.L = q; else parent.R = q;
  5320. } else {
  5321. tree._ = q;
  5322. }
  5323. q.U = parent;
  5324. p.U = q;
  5325. p.L = q.R;
  5326. if (p.L) p.L.U = p;
  5327. q.R = p;
  5328. }
  5329. function d3_geom_voronoiRedBlackFirst(node) {
  5330. while (node.L) node = node.L;
  5331. return node;
  5332. }
  5333. function d3_geom_voronoi(sites, bbox) {
  5334. var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
  5335. d3_geom_voronoiEdges = [];
  5336. d3_geom_voronoiCells = new Array(sites.length);
  5337. d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
  5338. d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
  5339. while (true) {
  5340. circle = d3_geom_voronoiFirstCircle;
  5341. if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
  5342. if (site.x !== x0 || site.y !== y0) {
  5343. d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
  5344. d3_geom_voronoiAddBeach(site);
  5345. x0 = site.x, y0 = site.y;
  5346. }
  5347. site = sites.pop();
  5348. } else if (circle) {
  5349. d3_geom_voronoiRemoveBeach(circle.arc);
  5350. } else {
  5351. break;
  5352. }
  5353. }
  5354. if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
  5355. var diagram = {
  5356. cells: d3_geom_voronoiCells,
  5357. edges: d3_geom_voronoiEdges
  5358. };
  5359. d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
  5360. return diagram;
  5361. }
  5362. function d3_geom_voronoiVertexOrder(a, b) {
  5363. return b.y - a.y || b.x - a.x;
  5364. }
  5365. d3.geom.voronoi = function(points) {
  5366. var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
  5367. if (points) return voronoi(points);
  5368. function voronoi(data) {
  5369. var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
  5370. d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
  5371. var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
  5372. var s = e.start();
  5373. return [ s.x, s.y ];
  5374. }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
  5375. polygon.point = data[i];
  5376. });
  5377. return polygons;
  5378. }
  5379. function sites(data) {
  5380. return data.map(function(d, i) {
  5381. return {
  5382. x: Math.round(fx(d, i) / ε) * ε,
  5383. y: Math.round(fy(d, i) / ε) * ε,
  5384. i: i
  5385. };
  5386. });
  5387. }
  5388. voronoi.links = function(data) {
  5389. return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
  5390. return edge.l && edge.r;
  5391. }).map(function(edge) {
  5392. return {
  5393. source: data[edge.l.i],
  5394. target: data[edge.r.i]
  5395. };
  5396. });
  5397. };
  5398. voronoi.triangles = function(data) {
  5399. var triangles = [];
  5400. d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
  5401. var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
  5402. while (++j < m) {
  5403. e0 = e1;
  5404. s0 = s1;
  5405. e1 = edges[j].edge;
  5406. s1 = e1.l === site ? e1.r : e1.l;
  5407. if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
  5408. triangles.push([ data[i], data[s0.i], data[s1.i] ]);
  5409. }
  5410. }
  5411. });
  5412. return triangles;
  5413. };
  5414. voronoi.x = function(_) {
  5415. return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
  5416. };
  5417. voronoi.y = function(_) {
  5418. return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
  5419. };
  5420. voronoi.clipExtent = function(_) {
  5421. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
  5422. clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
  5423. return voronoi;
  5424. };
  5425. voronoi.size = function(_) {
  5426. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
  5427. return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
  5428. };
  5429. return voronoi;
  5430. };
  5431. var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
  5432. function d3_geom_voronoiTriangleArea(a, b, c) {
  5433. return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
  5434. }
  5435. d3.geom.delaunay = function(vertices) {
  5436. return d3.geom.voronoi().triangles(vertices);
  5437. };
  5438. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  5439. var x = d3_geom_pointX, y = d3_geom_pointY, compat;
  5440. if (compat = arguments.length) {
  5441. x = d3_geom_quadtreeCompatX;
  5442. y = d3_geom_quadtreeCompatY;
  5443. if (compat === 3) {
  5444. y2 = y1;
  5445. x2 = x1;
  5446. y1 = x1 = 0;
  5447. }
  5448. return quadtree(points);
  5449. }
  5450. function quadtree(data) {
  5451. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  5452. if (x1 != null) {
  5453. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  5454. } else {
  5455. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  5456. xs = [], ys = [];
  5457. n = data.length;
  5458. if (compat) for (i = 0; i < n; ++i) {
  5459. d = data[i];
  5460. if (d.x < x1_) x1_ = d.x;
  5461. if (d.y < y1_) y1_ = d.y;
  5462. if (d.x > x2_) x2_ = d.x;
  5463. if (d.y > y2_) y2_ = d.y;
  5464. xs.push(d.x);
  5465. ys.push(d.y);
  5466. } else for (i = 0; i < n; ++i) {
  5467. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  5468. if (x_ < x1_) x1_ = x_;
  5469. if (y_ < y1_) y1_ = y_;
  5470. if (x_ > x2_) x2_ = x_;
  5471. if (y_ > y2_) y2_ = y_;
  5472. xs.push(x_);
  5473. ys.push(y_);
  5474. }
  5475. }
  5476. var dx = x2_ - x1_, dy = y2_ - y1_;
  5477. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  5478. function insert(n, d, x, y, x1, y1, x2, y2) {
  5479. if (isNaN(x) || isNaN(y)) return;
  5480. if (n.leaf) {
  5481. var nx = n.x, ny = n.y;
  5482. if (nx != null) {
  5483. if (abs(nx - x) + abs(ny - y) < .01) {
  5484. insertChild(n, d, x, y, x1, y1, x2, y2);
  5485. } else {
  5486. var nPoint = n.point;
  5487. n.x = n.y = n.point = null;
  5488. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  5489. insertChild(n, d, x, y, x1, y1, x2, y2);
  5490. }
  5491. } else {
  5492. n.x = x, n.y = y, n.point = d;
  5493. }
  5494. } else {
  5495. insertChild(n, d, x, y, x1, y1, x2, y2);
  5496. }
  5497. }
  5498. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  5499. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = x >= sx, bottom = y >= sy, i = (bottom << 1) + right;
  5500. n.leaf = false;
  5501. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  5502. if (right) x1 = sx; else x2 = sx;
  5503. if (bottom) y1 = sy; else y2 = sy;
  5504. insert(n, d, x, y, x1, y1, x2, y2);
  5505. }
  5506. var root = d3_geom_quadtreeNode();
  5507. root.add = function(d) {
  5508. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  5509. };
  5510. root.visit = function(f) {
  5511. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  5512. };
  5513. i = -1;
  5514. if (x1 == null) {
  5515. while (++i < n) {
  5516. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  5517. }
  5518. --i;
  5519. } else data.forEach(root.add);
  5520. xs = ys = data = d = null;
  5521. return root;
  5522. }
  5523. quadtree.x = function(_) {
  5524. return arguments.length ? (x = _, quadtree) : x;
  5525. };
  5526. quadtree.y = function(_) {
  5527. return arguments.length ? (y = _, quadtree) : y;
  5528. };
  5529. quadtree.extent = function(_) {
  5530. if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
  5531. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
  5532. y2 = +_[1][1];
  5533. return quadtree;
  5534. };
  5535. quadtree.size = function(_) {
  5536. if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
  5537. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
  5538. return quadtree;
  5539. };
  5540. return quadtree;
  5541. };
  5542. function d3_geom_quadtreeCompatX(d) {
  5543. return d.x;
  5544. }
  5545. function d3_geom_quadtreeCompatY(d) {
  5546. return d.y;
  5547. }
  5548. function d3_geom_quadtreeNode() {
  5549. return {
  5550. leaf: true,
  5551. nodes: [],
  5552. point: null,
  5553. x: null,
  5554. y: null
  5555. };
  5556. }
  5557. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  5558. if (!f(node, x1, y1, x2, y2)) {
  5559. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  5560. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  5561. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  5562. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  5563. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  5564. }
  5565. }
  5566. d3.interpolateRgb = d3_interpolateRgb;
  5567. function d3_interpolateRgb(a, b) {
  5568. a = d3.rgb(a);
  5569. b = d3.rgb(b);
  5570. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  5571. return function(t) {
  5572. 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));
  5573. };
  5574. }
  5575. d3.interpolateObject = d3_interpolateObject;
  5576. function d3_interpolateObject(a, b) {
  5577. var i = {}, c = {}, k;
  5578. for (k in a) {
  5579. if (k in b) {
  5580. i[k] = d3_interpolate(a[k], b[k]);
  5581. } else {
  5582. c[k] = a[k];
  5583. }
  5584. }
  5585. for (k in b) {
  5586. if (!(k in a)) {
  5587. c[k] = b[k];
  5588. }
  5589. }
  5590. return function(t) {
  5591. for (k in i) c[k] = i[k](t);
  5592. return c;
  5593. };
  5594. }
  5595. d3.interpolateNumber = d3_interpolateNumber;
  5596. function d3_interpolateNumber(a, b) {
  5597. b -= a = +a;
  5598. return function(t) {
  5599. return a + b * t;
  5600. };
  5601. }
  5602. d3.interpolateString = d3_interpolateString;
  5603. function d3_interpolateString(a, b) {
  5604. var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
  5605. a = a + "", b = b + "";
  5606. while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
  5607. if ((bs = bm.index) > bi) {
  5608. bs = b.substring(bi, bs);
  5609. if (s[i]) s[i] += bs; else s[++i] = bs;
  5610. }
  5611. if ((am = am[0]) === (bm = bm[0])) {
  5612. if (s[i]) s[i] += bm; else s[++i] = bm;
  5613. } else {
  5614. s[++i] = null;
  5615. q.push({
  5616. i: i,
  5617. x: d3_interpolateNumber(am, bm)
  5618. });
  5619. }
  5620. bi = d3_interpolate_numberB.lastIndex;
  5621. }
  5622. if (bi < b.length) {
  5623. bs = b.substring(bi);
  5624. if (s[i]) s[i] += bs; else s[++i] = bs;
  5625. }
  5626. return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
  5627. return b(t) + "";
  5628. }) : function() {
  5629. return b;
  5630. } : (b = q.length, function(t) {
  5631. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  5632. return s.join("");
  5633. });
  5634. }
  5635. var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
  5636. d3.interpolate = d3_interpolate;
  5637. function d3_interpolate(a, b) {
  5638. var i = d3.interpolators.length, f;
  5639. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  5640. return f;
  5641. }
  5642. d3.interpolators = [ function(a, b) {
  5643. var t = typeof b;
  5644. return (t === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
  5645. } ];
  5646. d3.interpolateArray = d3_interpolateArray;
  5647. function d3_interpolateArray(a, b) {
  5648. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  5649. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  5650. for (;i < na; ++i) c[i] = a[i];
  5651. for (;i < nb; ++i) c[i] = b[i];
  5652. return function(t) {
  5653. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  5654. return c;
  5655. };
  5656. }
  5657. var d3_ease_default = function() {
  5658. return d3_identity;
  5659. };
  5660. var d3_ease = d3.map({
  5661. linear: d3_ease_default,
  5662. poly: d3_ease_poly,
  5663. quad: function() {
  5664. return d3_ease_quad;
  5665. },
  5666. cubic: function() {
  5667. return d3_ease_cubic;
  5668. },
  5669. sin: function() {
  5670. return d3_ease_sin;
  5671. },
  5672. exp: function() {
  5673. return d3_ease_exp;
  5674. },
  5675. circle: function() {
  5676. return d3_ease_circle;
  5677. },
  5678. elastic: d3_ease_elastic,
  5679. back: d3_ease_back,
  5680. bounce: function() {
  5681. return d3_ease_bounce;
  5682. }
  5683. });
  5684. var d3_ease_mode = d3.map({
  5685. "in": d3_identity,
  5686. out: d3_ease_reverse,
  5687. "in-out": d3_ease_reflect,
  5688. "out-in": function(f) {
  5689. return d3_ease_reflect(d3_ease_reverse(f));
  5690. }
  5691. });
  5692. d3.ease = function(name) {
  5693. var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
  5694. t = d3_ease.get(t) || d3_ease_default;
  5695. m = d3_ease_mode.get(m) || d3_identity;
  5696. return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
  5697. };
  5698. function d3_ease_clamp(f) {
  5699. return function(t) {
  5700. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  5701. };
  5702. }
  5703. function d3_ease_reverse(f) {
  5704. return function(t) {
  5705. return 1 - f(1 - t);
  5706. };
  5707. }
  5708. function d3_ease_reflect(f) {
  5709. return function(t) {
  5710. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  5711. };
  5712. }
  5713. function d3_ease_quad(t) {
  5714. return t * t;
  5715. }
  5716. function d3_ease_cubic(t) {
  5717. return t * t * t;
  5718. }
  5719. function d3_ease_cubicInOut(t) {
  5720. if (t <= 0) return 0;
  5721. if (t >= 1) return 1;
  5722. var t2 = t * t, t3 = t2 * t;
  5723. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  5724. }
  5725. function d3_ease_poly(e) {
  5726. return function(t) {
  5727. return Math.pow(t, e);
  5728. };
  5729. }
  5730. function d3_ease_sin(t) {
  5731. return 1 - Math.cos(t * halfπ);
  5732. }
  5733. function d3_ease_exp(t) {
  5734. return Math.pow(2, 10 * (t - 1));
  5735. }
  5736. function d3_ease_circle(t) {
  5737. return 1 - Math.sqrt(1 - t * t);
  5738. }
  5739. function d3_ease_elastic(a, p) {
  5740. var s;
  5741. if (arguments.length < 2) p = .45;
  5742. if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
  5743. return function(t) {
  5744. return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
  5745. };
  5746. }
  5747. function d3_ease_back(s) {
  5748. if (!s) s = 1.70158;
  5749. return function(t) {
  5750. return t * t * ((s + 1) * t - s);
  5751. };
  5752. }
  5753. function d3_ease_bounce(t) {
  5754. 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;
  5755. }
  5756. d3.interpolateHcl = d3_interpolateHcl;
  5757. function d3_interpolateHcl(a, b) {
  5758. a = d3.hcl(a);
  5759. b = d3.hcl(b);
  5760. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  5761. if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
  5762. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5763. return function(t) {
  5764. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  5765. };
  5766. }
  5767. d3.interpolateHsl = d3_interpolateHsl;
  5768. function d3_interpolateHsl(a, b) {
  5769. a = d3.hsl(a);
  5770. b = d3.hsl(b);
  5771. var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
  5772. if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
  5773. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5774. return function(t) {
  5775. return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
  5776. };
  5777. }
  5778. d3.interpolateLab = d3_interpolateLab;
  5779. function d3_interpolateLab(a, b) {
  5780. a = d3.lab(a);
  5781. b = d3.lab(b);
  5782. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  5783. return function(t) {
  5784. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  5785. };
  5786. }
  5787. d3.interpolateRound = d3_interpolateRound;
  5788. function d3_interpolateRound(a, b) {
  5789. b -= a;
  5790. return function(t) {
  5791. return Math.round(a + b * t);
  5792. };
  5793. }
  5794. d3.transform = function(string) {
  5795. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  5796. return (d3.transform = function(string) {
  5797. if (string != null) {
  5798. g.setAttribute("transform", string);
  5799. var t = g.transform.baseVal.consolidate();
  5800. }
  5801. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  5802. })(string);
  5803. };
  5804. function d3_transform(m) {
  5805. 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;
  5806. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  5807. r0[0] *= -1;
  5808. r0[1] *= -1;
  5809. kx *= -1;
  5810. kz *= -1;
  5811. }
  5812. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  5813. this.translate = [ m.e, m.f ];
  5814. this.scale = [ kx, ky ];
  5815. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  5816. }
  5817. d3_transform.prototype.toString = function() {
  5818. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  5819. };
  5820. function d3_transformDot(a, b) {
  5821. return a[0] * b[0] + a[1] * b[1];
  5822. }
  5823. function d3_transformNormalize(a) {
  5824. var k = Math.sqrt(d3_transformDot(a, a));
  5825. if (k) {
  5826. a[0] /= k;
  5827. a[1] /= k;
  5828. }
  5829. return k;
  5830. }
  5831. function d3_transformCombine(a, b, k) {
  5832. a[0] += k * b[0];
  5833. a[1] += k * b[1];
  5834. return a;
  5835. }
  5836. var d3_transformIdentity = {
  5837. a: 1,
  5838. b: 0,
  5839. c: 0,
  5840. d: 1,
  5841. e: 0,
  5842. f: 0
  5843. };
  5844. d3.interpolateTransform = d3_interpolateTransform;
  5845. function d3_interpolateTransform(a, b) {
  5846. 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;
  5847. if (ta[0] != tb[0] || ta[1] != tb[1]) {
  5848. s.push("translate(", null, ",", null, ")");
  5849. q.push({
  5850. i: 1,
  5851. x: d3_interpolateNumber(ta[0], tb[0])
  5852. }, {
  5853. i: 3,
  5854. x: d3_interpolateNumber(ta[1], tb[1])
  5855. });
  5856. } else if (tb[0] || tb[1]) {
  5857. s.push("translate(" + tb + ")");
  5858. } else {
  5859. s.push("");
  5860. }
  5861. if (ra != rb) {
  5862. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  5863. q.push({
  5864. i: s.push(s.pop() + "rotate(", null, ")") - 2,
  5865. x: d3_interpolateNumber(ra, rb)
  5866. });
  5867. } else if (rb) {
  5868. s.push(s.pop() + "rotate(" + rb + ")");
  5869. }
  5870. if (wa != wb) {
  5871. q.push({
  5872. i: s.push(s.pop() + "skewX(", null, ")") - 2,
  5873. x: d3_interpolateNumber(wa, wb)
  5874. });
  5875. } else if (wb) {
  5876. s.push(s.pop() + "skewX(" + wb + ")");
  5877. }
  5878. if (ka[0] != kb[0] || ka[1] != kb[1]) {
  5879. n = s.push(s.pop() + "scale(", null, ",", null, ")");
  5880. q.push({
  5881. i: n - 4,
  5882. x: d3_interpolateNumber(ka[0], kb[0])
  5883. }, {
  5884. i: n - 2,
  5885. x: d3_interpolateNumber(ka[1], kb[1])
  5886. });
  5887. } else if (kb[0] != 1 || kb[1] != 1) {
  5888. s.push(s.pop() + "scale(" + kb + ")");
  5889. }
  5890. n = q.length;
  5891. return function(t) {
  5892. var i = -1, o;
  5893. while (++i < n) s[(o = q[i]).i] = o.x(t);
  5894. return s.join("");
  5895. };
  5896. }
  5897. function d3_uninterpolateNumber(a, b) {
  5898. b = b - (a = +a) ? 1 / (b - a) : 0;
  5899. return function(x) {
  5900. return (x - a) * b;
  5901. };
  5902. }
  5903. function d3_uninterpolateClamp(a, b) {
  5904. b = b - (a = +a) ? 1 / (b - a) : 0;
  5905. return function(x) {
  5906. return Math.max(0, Math.min(1, (x - a) * b));
  5907. };
  5908. }
  5909. d3.layout = {};
  5910. d3.layout.bundle = function() {
  5911. return function(links) {
  5912. var paths = [], i = -1, n = links.length;
  5913. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  5914. return paths;
  5915. };
  5916. };
  5917. function d3_layout_bundlePath(link) {
  5918. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  5919. while (start !== lca) {
  5920. start = start.parent;
  5921. points.push(start);
  5922. }
  5923. var k = points.length;
  5924. while (end !== lca) {
  5925. points.splice(k, 0, end);
  5926. end = end.parent;
  5927. }
  5928. return points;
  5929. }
  5930. function d3_layout_bundleAncestors(node) {
  5931. var ancestors = [], parent = node.parent;
  5932. while (parent != null) {
  5933. ancestors.push(node);
  5934. node = parent;
  5935. parent = parent.parent;
  5936. }
  5937. ancestors.push(node);
  5938. return ancestors;
  5939. }
  5940. function d3_layout_bundleLeastCommonAncestor(a, b) {
  5941. if (a === b) return a;
  5942. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  5943. while (aNode === bNode) {
  5944. sharedNode = aNode;
  5945. aNode = aNodes.pop();
  5946. bNode = bNodes.pop();
  5947. }
  5948. return sharedNode;
  5949. }
  5950. d3.layout.chord = function() {
  5951. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  5952. function relayout() {
  5953. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  5954. chords = [];
  5955. groups = [];
  5956. k = 0, i = -1;
  5957. while (++i < n) {
  5958. x = 0, j = -1;
  5959. while (++j < n) {
  5960. x += matrix[i][j];
  5961. }
  5962. groupSums.push(x);
  5963. subgroupIndex.push(d3.range(n));
  5964. k += x;
  5965. }
  5966. if (sortGroups) {
  5967. groupIndex.sort(function(a, b) {
  5968. return sortGroups(groupSums[a], groupSums[b]);
  5969. });
  5970. }
  5971. if (sortSubgroups) {
  5972. subgroupIndex.forEach(function(d, i) {
  5973. d.sort(function(a, b) {
  5974. return sortSubgroups(matrix[i][a], matrix[i][b]);
  5975. });
  5976. });
  5977. }
  5978. k = (τ - padding * n) / k;
  5979. x = 0, i = -1;
  5980. while (++i < n) {
  5981. x0 = x, j = -1;
  5982. while (++j < n) {
  5983. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  5984. subgroups[di + "-" + dj] = {
  5985. index: di,
  5986. subindex: dj,
  5987. startAngle: a0,
  5988. endAngle: a1,
  5989. value: v
  5990. };
  5991. }
  5992. groups[di] = {
  5993. index: di,
  5994. startAngle: x0,
  5995. endAngle: x,
  5996. value: (x - x0) / k
  5997. };
  5998. x += padding;
  5999. }
  6000. i = -1;
  6001. while (++i < n) {
  6002. j = i - 1;
  6003. while (++j < n) {
  6004. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  6005. if (source.value || target.value) {
  6006. chords.push(source.value < target.value ? {
  6007. source: target,
  6008. target: source
  6009. } : {
  6010. source: source,
  6011. target: target
  6012. });
  6013. }
  6014. }
  6015. }
  6016. if (sortChords) resort();
  6017. }
  6018. function resort() {
  6019. chords.sort(function(a, b) {
  6020. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  6021. });
  6022. }
  6023. chord.matrix = function(x) {
  6024. if (!arguments.length) return matrix;
  6025. n = (matrix = x) && matrix.length;
  6026. chords = groups = null;
  6027. return chord;
  6028. };
  6029. chord.padding = function(x) {
  6030. if (!arguments.length) return padding;
  6031. padding = x;
  6032. chords = groups = null;
  6033. return chord;
  6034. };
  6035. chord.sortGroups = function(x) {
  6036. if (!arguments.length) return sortGroups;
  6037. sortGroups = x;
  6038. chords = groups = null;
  6039. return chord;
  6040. };
  6041. chord.sortSubgroups = function(x) {
  6042. if (!arguments.length) return sortSubgroups;
  6043. sortSubgroups = x;
  6044. chords = null;
  6045. return chord;
  6046. };
  6047. chord.sortChords = function(x) {
  6048. if (!arguments.length) return sortChords;
  6049. sortChords = x;
  6050. if (chords) resort();
  6051. return chord;
  6052. };
  6053. chord.chords = function() {
  6054. if (!chords) relayout();
  6055. return chords;
  6056. };
  6057. chord.groups = function() {
  6058. if (!groups) relayout();
  6059. return groups;
  6060. };
  6061. return chord;
  6062. };
  6063. d3.layout.force = function() {
  6064. var force = {}, event = d3.dispatch("start", "tick", "end"), size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
  6065. function repulse(node) {
  6066. return function(quad, x1, _, x2) {
  6067. if (quad.point !== node) {
  6068. var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
  6069. if (dw * dw / theta2 < dn) {
  6070. if (dn < chargeDistance2) {
  6071. var k = quad.charge / dn;
  6072. node.px -= dx * k;
  6073. node.py -= dy * k;
  6074. }
  6075. return true;
  6076. }
  6077. if (quad.point && dn && dn < chargeDistance2) {
  6078. var k = quad.pointCharge / dn;
  6079. node.px -= dx * k;
  6080. node.py -= dy * k;
  6081. }
  6082. }
  6083. return !quad.charge;
  6084. };
  6085. }
  6086. force.tick = function() {
  6087. if ((alpha *= .99) < .005) {
  6088. event.end({
  6089. type: "end",
  6090. alpha: alpha = 0
  6091. });
  6092. return true;
  6093. }
  6094. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  6095. for (i = 0; i < m; ++i) {
  6096. o = links[i];
  6097. s = o.source;
  6098. t = o.target;
  6099. x = t.x - s.x;
  6100. y = t.y - s.y;
  6101. if (l = x * x + y * y) {
  6102. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  6103. x *= l;
  6104. y *= l;
  6105. t.x -= x * (k = s.weight / (t.weight + s.weight));
  6106. t.y -= y * k;
  6107. s.x += x * (k = 1 - k);
  6108. s.y += y * k;
  6109. }
  6110. }
  6111. if (k = alpha * gravity) {
  6112. x = size[0] / 2;
  6113. y = size[1] / 2;
  6114. i = -1;
  6115. if (k) while (++i < n) {
  6116. o = nodes[i];
  6117. o.x += (x - o.x) * k;
  6118. o.y += (y - o.y) * k;
  6119. }
  6120. }
  6121. if (charge) {
  6122. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  6123. i = -1;
  6124. while (++i < n) {
  6125. if (!(o = nodes[i]).fixed) {
  6126. q.visit(repulse(o));
  6127. }
  6128. }
  6129. }
  6130. i = -1;
  6131. while (++i < n) {
  6132. o = nodes[i];
  6133. if (o.fixed) {
  6134. o.x = o.px;
  6135. o.y = o.py;
  6136. } else {
  6137. o.x -= (o.px - (o.px = o.x)) * friction;
  6138. o.y -= (o.py - (o.py = o.y)) * friction;
  6139. }
  6140. }
  6141. event.tick({
  6142. type: "tick",
  6143. alpha: alpha
  6144. });
  6145. };
  6146. force.nodes = function(x) {
  6147. if (!arguments.length) return nodes;
  6148. nodes = x;
  6149. return force;
  6150. };
  6151. force.links = function(x) {
  6152. if (!arguments.length) return links;
  6153. links = x;
  6154. return force;
  6155. };
  6156. force.size = function(x) {
  6157. if (!arguments.length) return size;
  6158. size = x;
  6159. return force;
  6160. };
  6161. force.linkDistance = function(x) {
  6162. if (!arguments.length) return linkDistance;
  6163. linkDistance = typeof x === "function" ? x : +x;
  6164. return force;
  6165. };
  6166. force.distance = force.linkDistance;
  6167. force.linkStrength = function(x) {
  6168. if (!arguments.length) return linkStrength;
  6169. linkStrength = typeof x === "function" ? x : +x;
  6170. return force;
  6171. };
  6172. force.friction = function(x) {
  6173. if (!arguments.length) return friction;
  6174. friction = +x;
  6175. return force;
  6176. };
  6177. force.charge = function(x) {
  6178. if (!arguments.length) return charge;
  6179. charge = typeof x === "function" ? x : +x;
  6180. return force;
  6181. };
  6182. force.chargeDistance = function(x) {
  6183. if (!arguments.length) return Math.sqrt(chargeDistance2);
  6184. chargeDistance2 = x * x;
  6185. return force;
  6186. };
  6187. force.gravity = function(x) {
  6188. if (!arguments.length) return gravity;
  6189. gravity = +x;
  6190. return force;
  6191. };
  6192. force.theta = function(x) {
  6193. if (!arguments.length) return Math.sqrt(theta2);
  6194. theta2 = x * x;
  6195. return force;
  6196. };
  6197. force.alpha = function(x) {
  6198. if (!arguments.length) return alpha;
  6199. x = +x;
  6200. if (alpha) {
  6201. if (x > 0) alpha = x; else alpha = 0;
  6202. } else if (x > 0) {
  6203. event.start({
  6204. type: "start",
  6205. alpha: alpha = x
  6206. });
  6207. d3.timer(force.tick);
  6208. }
  6209. return force;
  6210. };
  6211. force.start = function() {
  6212. var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  6213. for (i = 0; i < n; ++i) {
  6214. (o = nodes[i]).index = i;
  6215. o.weight = 0;
  6216. }
  6217. for (i = 0; i < m; ++i) {
  6218. o = links[i];
  6219. if (typeof o.source == "number") o.source = nodes[o.source];
  6220. if (typeof o.target == "number") o.target = nodes[o.target];
  6221. ++o.source.weight;
  6222. ++o.target.weight;
  6223. }
  6224. for (i = 0; i < n; ++i) {
  6225. o = nodes[i];
  6226. if (isNaN(o.x)) o.x = position("x", w);
  6227. if (isNaN(o.y)) o.y = position("y", h);
  6228. if (isNaN(o.px)) o.px = o.x;
  6229. if (isNaN(o.py)) o.py = o.y;
  6230. }
  6231. distances = [];
  6232. 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;
  6233. strengths = [];
  6234. 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;
  6235. charges = [];
  6236. 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;
  6237. function position(dimension, size) {
  6238. if (!neighbors) {
  6239. neighbors = new Array(n);
  6240. for (j = 0; j < n; ++j) {
  6241. neighbors[j] = [];
  6242. }
  6243. for (j = 0; j < m; ++j) {
  6244. var o = links[j];
  6245. neighbors[o.source.index].push(o.target);
  6246. neighbors[o.target.index].push(o.source);
  6247. }
  6248. }
  6249. var candidates = neighbors[i], j = -1, m = candidates.length, x;
  6250. while (++j < m) if (!isNaN(x = candidates[j][dimension])) return x;
  6251. return Math.random() * size;
  6252. }
  6253. return force.resume();
  6254. };
  6255. force.resume = function() {
  6256. return force.alpha(.1);
  6257. };
  6258. force.stop = function() {
  6259. return force.alpha(0);
  6260. };
  6261. force.drag = function() {
  6262. 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);
  6263. if (!arguments.length) return drag;
  6264. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  6265. };
  6266. function dragmove(d) {
  6267. d.px = d3.event.x, d.py = d3.event.y;
  6268. force.resume();
  6269. }
  6270. return d3.rebind(force, event, "on");
  6271. };
  6272. function d3_layout_forceDragstart(d) {
  6273. d.fixed |= 2;
  6274. }
  6275. function d3_layout_forceDragend(d) {
  6276. d.fixed &= ~6;
  6277. }
  6278. function d3_layout_forceMouseover(d) {
  6279. d.fixed |= 4;
  6280. d.px = d.x, d.py = d.y;
  6281. }
  6282. function d3_layout_forceMouseout(d) {
  6283. d.fixed &= ~4;
  6284. }
  6285. function d3_layout_forceAccumulate(quad, alpha, charges) {
  6286. var cx = 0, cy = 0;
  6287. quad.charge = 0;
  6288. if (!quad.leaf) {
  6289. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  6290. while (++i < n) {
  6291. c = nodes[i];
  6292. if (c == null) continue;
  6293. d3_layout_forceAccumulate(c, alpha, charges);
  6294. quad.charge += c.charge;
  6295. cx += c.charge * c.cx;
  6296. cy += c.charge * c.cy;
  6297. }
  6298. }
  6299. if (quad.point) {
  6300. if (!quad.leaf) {
  6301. quad.point.x += Math.random() - .5;
  6302. quad.point.y += Math.random() - .5;
  6303. }
  6304. var k = alpha * charges[quad.point.index];
  6305. quad.charge += quad.pointCharge = k;
  6306. cx += k * quad.point.x;
  6307. cy += k * quad.point.y;
  6308. }
  6309. quad.cx = cx / quad.charge;
  6310. quad.cy = cy / quad.charge;
  6311. }
  6312. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
  6313. d3.layout.hierarchy = function() {
  6314. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  6315. function hierarchy(root) {
  6316. var stack = [ root ], nodes = [], node;
  6317. root.depth = 0;
  6318. while ((node = stack.pop()) != null) {
  6319. nodes.push(node);
  6320. if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
  6321. var n, childs, child;
  6322. while (--n >= 0) {
  6323. stack.push(child = childs[n]);
  6324. child.parent = node;
  6325. child.depth = node.depth + 1;
  6326. }
  6327. if (value) node.value = 0;
  6328. node.children = childs;
  6329. } else {
  6330. if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6331. delete node.children;
  6332. }
  6333. }
  6334. d3_layout_hierarchyVisitAfter(root, function(node) {
  6335. var childs, parent;
  6336. if (sort && (childs = node.children)) childs.sort(sort);
  6337. if (value && (parent = node.parent)) parent.value += node.value;
  6338. });
  6339. return nodes;
  6340. }
  6341. hierarchy.sort = function(x) {
  6342. if (!arguments.length) return sort;
  6343. sort = x;
  6344. return hierarchy;
  6345. };
  6346. hierarchy.children = function(x) {
  6347. if (!arguments.length) return children;
  6348. children = x;
  6349. return hierarchy;
  6350. };
  6351. hierarchy.value = function(x) {
  6352. if (!arguments.length) return value;
  6353. value = x;
  6354. return hierarchy;
  6355. };
  6356. hierarchy.revalue = function(root) {
  6357. if (value) {
  6358. d3_layout_hierarchyVisitBefore(root, function(node) {
  6359. if (node.children) node.value = 0;
  6360. });
  6361. d3_layout_hierarchyVisitAfter(root, function(node) {
  6362. var parent;
  6363. if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6364. if (parent = node.parent) parent.value += node.value;
  6365. });
  6366. }
  6367. return root;
  6368. };
  6369. return hierarchy;
  6370. };
  6371. function d3_layout_hierarchyRebind(object, hierarchy) {
  6372. d3.rebind(object, hierarchy, "sort", "children", "value");
  6373. object.nodes = object;
  6374. object.links = d3_layout_hierarchyLinks;
  6375. return object;
  6376. }
  6377. function d3_layout_hierarchyVisitBefore(node, callback) {
  6378. var nodes = [ node ];
  6379. while ((node = nodes.pop()) != null) {
  6380. callback(node);
  6381. if ((children = node.children) && (n = children.length)) {
  6382. var n, children;
  6383. while (--n >= 0) nodes.push(children[n]);
  6384. }
  6385. }
  6386. }
  6387. function d3_layout_hierarchyVisitAfter(node, callback) {
  6388. var nodes = [ node ], nodes2 = [];
  6389. while ((node = nodes.pop()) != null) {
  6390. nodes2.push(node);
  6391. if ((children = node.children) && (n = children.length)) {
  6392. var i = -1, n, children;
  6393. while (++i < n) nodes.push(children[i]);
  6394. }
  6395. }
  6396. while ((node = nodes2.pop()) != null) {
  6397. callback(node);
  6398. }
  6399. }
  6400. function d3_layout_hierarchyChildren(d) {
  6401. return d.children;
  6402. }
  6403. function d3_layout_hierarchyValue(d) {
  6404. return d.value;
  6405. }
  6406. function d3_layout_hierarchySort(a, b) {
  6407. return b.value - a.value;
  6408. }
  6409. function d3_layout_hierarchyLinks(nodes) {
  6410. return d3.merge(nodes.map(function(parent) {
  6411. return (parent.children || []).map(function(child) {
  6412. return {
  6413. source: parent,
  6414. target: child
  6415. };
  6416. });
  6417. }));
  6418. }
  6419. d3.layout.partition = function() {
  6420. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  6421. function position(node, x, dx, dy) {
  6422. var children = node.children;
  6423. node.x = x;
  6424. node.y = node.depth * dy;
  6425. node.dx = dx;
  6426. node.dy = dy;
  6427. if (children && (n = children.length)) {
  6428. var i = -1, n, c, d;
  6429. dx = node.value ? dx / node.value : 0;
  6430. while (++i < n) {
  6431. position(c = children[i], x, d = c.value * dx, dy);
  6432. x += d;
  6433. }
  6434. }
  6435. }
  6436. function depth(node) {
  6437. var children = node.children, d = 0;
  6438. if (children && (n = children.length)) {
  6439. var i = -1, n;
  6440. while (++i < n) d = Math.max(d, depth(children[i]));
  6441. }
  6442. return 1 + d;
  6443. }
  6444. function partition(d, i) {
  6445. var nodes = hierarchy.call(this, d, i);
  6446. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  6447. return nodes;
  6448. }
  6449. partition.size = function(x) {
  6450. if (!arguments.length) return size;
  6451. size = x;
  6452. return partition;
  6453. };
  6454. return d3_layout_hierarchyRebind(partition, hierarchy);
  6455. };
  6456. d3.layout.pie = function() {
  6457. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ;
  6458. function pie(data) {
  6459. var values = data.map(function(d, i) {
  6460. return +value.call(pie, d, i);
  6461. });
  6462. var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
  6463. var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a) / d3.sum(values);
  6464. var index = d3.range(data.length);
  6465. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  6466. return values[j] - values[i];
  6467. } : function(i, j) {
  6468. return sort(data[i], data[j]);
  6469. });
  6470. var arcs = [];
  6471. index.forEach(function(i) {
  6472. var d;
  6473. arcs[i] = {
  6474. data: data[i],
  6475. value: d = values[i],
  6476. startAngle: a,
  6477. endAngle: a += d * k
  6478. };
  6479. });
  6480. return arcs;
  6481. }
  6482. pie.value = function(x) {
  6483. if (!arguments.length) return value;
  6484. value = x;
  6485. return pie;
  6486. };
  6487. pie.sort = function(x) {
  6488. if (!arguments.length) return sort;
  6489. sort = x;
  6490. return pie;
  6491. };
  6492. pie.startAngle = function(x) {
  6493. if (!arguments.length) return startAngle;
  6494. startAngle = x;
  6495. return pie;
  6496. };
  6497. pie.endAngle = function(x) {
  6498. if (!arguments.length) return endAngle;
  6499. endAngle = x;
  6500. return pie;
  6501. };
  6502. return pie;
  6503. };
  6504. var d3_layout_pieSortByValue = {};
  6505. d3.layout.stack = function() {
  6506. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  6507. function stack(data, index) {
  6508. var series = data.map(function(d, i) {
  6509. return values.call(stack, d, i);
  6510. });
  6511. var points = series.map(function(d) {
  6512. return d.map(function(v, i) {
  6513. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  6514. });
  6515. });
  6516. var orders = order.call(stack, points, index);
  6517. series = d3.permute(series, orders);
  6518. points = d3.permute(points, orders);
  6519. var offsets = offset.call(stack, points, index);
  6520. var n = series.length, m = series[0].length, i, j, o;
  6521. for (j = 0; j < m; ++j) {
  6522. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  6523. for (i = 1; i < n; ++i) {
  6524. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  6525. }
  6526. }
  6527. return data;
  6528. }
  6529. stack.values = function(x) {
  6530. if (!arguments.length) return values;
  6531. values = x;
  6532. return stack;
  6533. };
  6534. stack.order = function(x) {
  6535. if (!arguments.length) return order;
  6536. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  6537. return stack;
  6538. };
  6539. stack.offset = function(x) {
  6540. if (!arguments.length) return offset;
  6541. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  6542. return stack;
  6543. };
  6544. stack.x = function(z) {
  6545. if (!arguments.length) return x;
  6546. x = z;
  6547. return stack;
  6548. };
  6549. stack.y = function(z) {
  6550. if (!arguments.length) return y;
  6551. y = z;
  6552. return stack;
  6553. };
  6554. stack.out = function(z) {
  6555. if (!arguments.length) return out;
  6556. out = z;
  6557. return stack;
  6558. };
  6559. return stack;
  6560. };
  6561. function d3_layout_stackX(d) {
  6562. return d.x;
  6563. }
  6564. function d3_layout_stackY(d) {
  6565. return d.y;
  6566. }
  6567. function d3_layout_stackOut(d, y0, y) {
  6568. d.y0 = y0;
  6569. d.y = y;
  6570. }
  6571. var d3_layout_stackOrders = d3.map({
  6572. "inside-out": function(data) {
  6573. 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) {
  6574. return max[a] - max[b];
  6575. }), top = 0, bottom = 0, tops = [], bottoms = [];
  6576. for (i = 0; i < n; ++i) {
  6577. j = index[i];
  6578. if (top < bottom) {
  6579. top += sums[j];
  6580. tops.push(j);
  6581. } else {
  6582. bottom += sums[j];
  6583. bottoms.push(j);
  6584. }
  6585. }
  6586. return bottoms.reverse().concat(tops);
  6587. },
  6588. reverse: function(data) {
  6589. return d3.range(data.length).reverse();
  6590. },
  6591. "default": d3_layout_stackOrderDefault
  6592. });
  6593. var d3_layout_stackOffsets = d3.map({
  6594. silhouette: function(data) {
  6595. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  6596. for (j = 0; j < m; ++j) {
  6597. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6598. if (o > max) max = o;
  6599. sums.push(o);
  6600. }
  6601. for (j = 0; j < m; ++j) {
  6602. y0[j] = (max - sums[j]) / 2;
  6603. }
  6604. return y0;
  6605. },
  6606. wiggle: function(data) {
  6607. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  6608. y0[0] = o = o0 = 0;
  6609. for (j = 1; j < m; ++j) {
  6610. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  6611. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  6612. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  6613. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  6614. }
  6615. s2 += s3 * data[i][j][1];
  6616. }
  6617. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  6618. if (o < o0) o0 = o;
  6619. }
  6620. for (j = 0; j < m; ++j) y0[j] -= o0;
  6621. return y0;
  6622. },
  6623. expand: function(data) {
  6624. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  6625. for (j = 0; j < m; ++j) {
  6626. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6627. 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;
  6628. }
  6629. for (j = 0; j < m; ++j) y0[j] = 0;
  6630. return y0;
  6631. },
  6632. zero: d3_layout_stackOffsetZero
  6633. });
  6634. function d3_layout_stackOrderDefault(data) {
  6635. return d3.range(data.length);
  6636. }
  6637. function d3_layout_stackOffsetZero(data) {
  6638. var j = -1, m = data[0].length, y0 = [];
  6639. while (++j < m) y0[j] = 0;
  6640. return y0;
  6641. }
  6642. function d3_layout_stackMaxIndex(array) {
  6643. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  6644. for (;i < n; ++i) {
  6645. if ((k = array[i][1]) > v) {
  6646. j = i;
  6647. v = k;
  6648. }
  6649. }
  6650. return j;
  6651. }
  6652. function d3_layout_stackReduceSum(d) {
  6653. return d.reduce(d3_layout_stackSum, 0);
  6654. }
  6655. function d3_layout_stackSum(p, d) {
  6656. return p + d[1];
  6657. }
  6658. d3.layout.histogram = function() {
  6659. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  6660. function histogram(data, i) {
  6661. 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;
  6662. while (++i < m) {
  6663. bin = bins[i] = [];
  6664. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  6665. bin.y = 0;
  6666. }
  6667. if (m > 0) {
  6668. i = -1;
  6669. while (++i < n) {
  6670. x = values[i];
  6671. if (x >= range[0] && x <= range[1]) {
  6672. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  6673. bin.y += k;
  6674. bin.push(data[i]);
  6675. }
  6676. }
  6677. }
  6678. return bins;
  6679. }
  6680. histogram.value = function(x) {
  6681. if (!arguments.length) return valuer;
  6682. valuer = x;
  6683. return histogram;
  6684. };
  6685. histogram.range = function(x) {
  6686. if (!arguments.length) return ranger;
  6687. ranger = d3_functor(x);
  6688. return histogram;
  6689. };
  6690. histogram.bins = function(x) {
  6691. if (!arguments.length) return binner;
  6692. binner = typeof x === "number" ? function(range) {
  6693. return d3_layout_histogramBinFixed(range, x);
  6694. } : d3_functor(x);
  6695. return histogram;
  6696. };
  6697. histogram.frequency = function(x) {
  6698. if (!arguments.length) return frequency;
  6699. frequency = !!x;
  6700. return histogram;
  6701. };
  6702. return histogram;
  6703. };
  6704. function d3_layout_histogramBinSturges(range, values) {
  6705. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  6706. }
  6707. function d3_layout_histogramBinFixed(range, n) {
  6708. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  6709. while (++x <= n) f[x] = m * x + b;
  6710. return f;
  6711. }
  6712. function d3_layout_histogramRange(values) {
  6713. return [ d3.min(values), d3.max(values) ];
  6714. }
  6715. d3.layout.pack = function() {
  6716. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
  6717. function pack(d, i) {
  6718. 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() {
  6719. return radius;
  6720. };
  6721. root.x = root.y = 0;
  6722. d3_layout_hierarchyVisitAfter(root, function(d) {
  6723. d.r = +r(d.value);
  6724. });
  6725. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6726. if (padding) {
  6727. var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
  6728. d3_layout_hierarchyVisitAfter(root, function(d) {
  6729. d.r += dr;
  6730. });
  6731. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6732. d3_layout_hierarchyVisitAfter(root, function(d) {
  6733. d.r -= dr;
  6734. });
  6735. }
  6736. d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
  6737. return nodes;
  6738. }
  6739. pack.size = function(_) {
  6740. if (!arguments.length) return size;
  6741. size = _;
  6742. return pack;
  6743. };
  6744. pack.radius = function(_) {
  6745. if (!arguments.length) return radius;
  6746. radius = _ == null || typeof _ === "function" ? _ : +_;
  6747. return pack;
  6748. };
  6749. pack.padding = function(_) {
  6750. if (!arguments.length) return padding;
  6751. padding = +_;
  6752. return pack;
  6753. };
  6754. return d3_layout_hierarchyRebind(pack, hierarchy);
  6755. };
  6756. function d3_layout_packSort(a, b) {
  6757. return a.value - b.value;
  6758. }
  6759. function d3_layout_packInsert(a, b) {
  6760. var c = a._pack_next;
  6761. a._pack_next = b;
  6762. b._pack_prev = a;
  6763. b._pack_next = c;
  6764. c._pack_prev = b;
  6765. }
  6766. function d3_layout_packSplice(a, b) {
  6767. a._pack_next = b;
  6768. b._pack_prev = a;
  6769. }
  6770. function d3_layout_packIntersects(a, b) {
  6771. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  6772. return .999 * dr * dr > dx * dx + dy * dy;
  6773. }
  6774. function d3_layout_packSiblings(node) {
  6775. if (!(nodes = node.children) || !(n = nodes.length)) return;
  6776. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  6777. function bound(node) {
  6778. xMin = Math.min(node.x - node.r, xMin);
  6779. xMax = Math.max(node.x + node.r, xMax);
  6780. yMin = Math.min(node.y - node.r, yMin);
  6781. yMax = Math.max(node.y + node.r, yMax);
  6782. }
  6783. nodes.forEach(d3_layout_packLink);
  6784. a = nodes[0];
  6785. a.x = -a.r;
  6786. a.y = 0;
  6787. bound(a);
  6788. if (n > 1) {
  6789. b = nodes[1];
  6790. b.x = b.r;
  6791. b.y = 0;
  6792. bound(b);
  6793. if (n > 2) {
  6794. c = nodes[2];
  6795. d3_layout_packPlace(a, b, c);
  6796. bound(c);
  6797. d3_layout_packInsert(a, c);
  6798. a._pack_prev = c;
  6799. d3_layout_packInsert(c, b);
  6800. b = a._pack_next;
  6801. for (i = 3; i < n; i++) {
  6802. d3_layout_packPlace(a, b, c = nodes[i]);
  6803. var isect = 0, s1 = 1, s2 = 1;
  6804. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  6805. if (d3_layout_packIntersects(j, c)) {
  6806. isect = 1;
  6807. break;
  6808. }
  6809. }
  6810. if (isect == 1) {
  6811. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  6812. if (d3_layout_packIntersects(k, c)) {
  6813. break;
  6814. }
  6815. }
  6816. }
  6817. if (isect) {
  6818. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  6819. i--;
  6820. } else {
  6821. d3_layout_packInsert(a, c);
  6822. b = c;
  6823. bound(c);
  6824. }
  6825. }
  6826. }
  6827. }
  6828. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  6829. for (i = 0; i < n; i++) {
  6830. c = nodes[i];
  6831. c.x -= cx;
  6832. c.y -= cy;
  6833. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  6834. }
  6835. node.r = cr;
  6836. nodes.forEach(d3_layout_packUnlink);
  6837. }
  6838. function d3_layout_packLink(node) {
  6839. node._pack_next = node._pack_prev = node;
  6840. }
  6841. function d3_layout_packUnlink(node) {
  6842. delete node._pack_next;
  6843. delete node._pack_prev;
  6844. }
  6845. function d3_layout_packTransform(node, x, y, k) {
  6846. var children = node.children;
  6847. node.x = x += k * node.x;
  6848. node.y = y += k * node.y;
  6849. node.r *= k;
  6850. if (children) {
  6851. var i = -1, n = children.length;
  6852. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  6853. }
  6854. }
  6855. function d3_layout_packPlace(a, b, c) {
  6856. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  6857. if (db && (dx || dy)) {
  6858. var da = b.r + c.r, dc = dx * dx + dy * dy;
  6859. da *= da;
  6860. db *= db;
  6861. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  6862. c.x = a.x + x * dx + y * dy;
  6863. c.y = a.y + x * dy - y * dx;
  6864. } else {
  6865. c.x = a.x + db;
  6866. c.y = a.y;
  6867. }
  6868. }
  6869. d3.layout.tree = function() {
  6870. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
  6871. function tree(d, i) {
  6872. var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
  6873. d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
  6874. d3_layout_hierarchyVisitBefore(root1, secondWalk);
  6875. if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
  6876. var left = root0, right = root0, bottom = root0;
  6877. d3_layout_hierarchyVisitBefore(root0, function(node) {
  6878. if (node.x < left.x) left = node;
  6879. if (node.x > right.x) right = node;
  6880. if (node.depth > bottom.depth) bottom = node;
  6881. });
  6882. var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
  6883. d3_layout_hierarchyVisitBefore(root0, function(node) {
  6884. node.x = (node.x + tx) * kx;
  6885. node.y = node.depth * ky;
  6886. });
  6887. }
  6888. return nodes;
  6889. }
  6890. function wrapTree(root0) {
  6891. var root1 = {
  6892. A: null,
  6893. children: [ root0 ]
  6894. }, queue = [ root1 ], node1;
  6895. while ((node1 = queue.pop()) != null) {
  6896. for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
  6897. queue.push((children[i] = child = {
  6898. _: children[i],
  6899. parent: node1,
  6900. children: (child = children[i].children) && child.slice() || [],
  6901. A: null,
  6902. a: null,
  6903. z: 0,
  6904. m: 0,
  6905. c: 0,
  6906. s: 0,
  6907. t: null,
  6908. i: i
  6909. }).a = child);
  6910. }
  6911. }
  6912. return root1.children[0];
  6913. }
  6914. function firstWalk(v) {
  6915. var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
  6916. if (children.length) {
  6917. d3_layout_treeShift(v);
  6918. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  6919. if (w) {
  6920. v.z = w.z + separation(v._, w._);
  6921. v.m = v.z - midpoint;
  6922. } else {
  6923. v.z = midpoint;
  6924. }
  6925. } else if (w) {
  6926. v.z = w.z + separation(v._, w._);
  6927. }
  6928. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  6929. }
  6930. function secondWalk(v) {
  6931. v._.x = v.z + v.parent.m;
  6932. v.m += v.parent.m;
  6933. }
  6934. function apportion(v, w, ancestor) {
  6935. if (w) {
  6936. var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
  6937. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  6938. vom = d3_layout_treeLeft(vom);
  6939. vop = d3_layout_treeRight(vop);
  6940. vop.a = v;
  6941. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  6942. if (shift > 0) {
  6943. d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
  6944. sip += shift;
  6945. sop += shift;
  6946. }
  6947. sim += vim.m;
  6948. sip += vip.m;
  6949. som += vom.m;
  6950. sop += vop.m;
  6951. }
  6952. if (vim && !d3_layout_treeRight(vop)) {
  6953. vop.t = vim;
  6954. vop.m += sim - sop;
  6955. }
  6956. if (vip && !d3_layout_treeLeft(vom)) {
  6957. vom.t = vip;
  6958. vom.m += sip - som;
  6959. ancestor = v;
  6960. }
  6961. }
  6962. return ancestor;
  6963. }
  6964. function sizeNode(node) {
  6965. node.x *= size[0];
  6966. node.y = node.depth * size[1];
  6967. }
  6968. tree.separation = function(x) {
  6969. if (!arguments.length) return separation;
  6970. separation = x;
  6971. return tree;
  6972. };
  6973. tree.size = function(x) {
  6974. if (!arguments.length) return nodeSize ? null : size;
  6975. nodeSize = (size = x) == null ? sizeNode : null;
  6976. return tree;
  6977. };
  6978. tree.nodeSize = function(x) {
  6979. if (!arguments.length) return nodeSize ? size : null;
  6980. nodeSize = (size = x) == null ? null : sizeNode;
  6981. return tree;
  6982. };
  6983. return d3_layout_hierarchyRebind(tree, hierarchy);
  6984. };
  6985. function d3_layout_treeSeparation(a, b) {
  6986. return a.parent == b.parent ? 1 : 2;
  6987. }
  6988. function d3_layout_treeLeft(v) {
  6989. var children = v.children;
  6990. return children.length ? children[0] : v.t;
  6991. }
  6992. function d3_layout_treeRight(v) {
  6993. var children = v.children, n;
  6994. return (n = children.length) ? children[n - 1] : v.t;
  6995. }
  6996. function d3_layout_treeMove(wm, wp, shift) {
  6997. var change = shift / (wp.i - wm.i);
  6998. wp.c -= change;
  6999. wp.s += shift;
  7000. wm.c += change;
  7001. wp.z += shift;
  7002. wp.m += shift;
  7003. }
  7004. function d3_layout_treeShift(v) {
  7005. var shift = 0, change = 0, children = v.children, i = children.length, w;
  7006. while (--i >= 0) {
  7007. w = children[i];
  7008. w.z += shift;
  7009. w.m += shift;
  7010. shift += w.s + (change += w.c);
  7011. }
  7012. }
  7013. function d3_layout_treeAncestor(vim, v, ancestor) {
  7014. return vim.a.parent === v.parent ? vim.a : ancestor;
  7015. }
  7016. d3.layout.cluster = function() {
  7017. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  7018. function cluster(d, i) {
  7019. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  7020. d3_layout_hierarchyVisitAfter(root, function(node) {
  7021. var children = node.children;
  7022. if (children && children.length) {
  7023. node.x = d3_layout_clusterX(children);
  7024. node.y = d3_layout_clusterY(children);
  7025. } else {
  7026. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7027. node.y = 0;
  7028. previousNode = node;
  7029. }
  7030. });
  7031. 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;
  7032. d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
  7033. node.x = (node.x - root.x) * size[0];
  7034. node.y = (root.y - node.y) * size[1];
  7035. } : function(node) {
  7036. node.x = (node.x - x0) / (x1 - x0) * size[0];
  7037. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  7038. });
  7039. return nodes;
  7040. }
  7041. cluster.separation = function(x) {
  7042. if (!arguments.length) return separation;
  7043. separation = x;
  7044. return cluster;
  7045. };
  7046. cluster.size = function(x) {
  7047. if (!arguments.length) return nodeSize ? null : size;
  7048. nodeSize = (size = x) == null;
  7049. return cluster;
  7050. };
  7051. cluster.nodeSize = function(x) {
  7052. if (!arguments.length) return nodeSize ? size : null;
  7053. nodeSize = (size = x) != null;
  7054. return cluster;
  7055. };
  7056. return d3_layout_hierarchyRebind(cluster, hierarchy);
  7057. };
  7058. function d3_layout_clusterY(children) {
  7059. return 1 + d3.max(children, function(child) {
  7060. return child.y;
  7061. });
  7062. }
  7063. function d3_layout_clusterX(children) {
  7064. return children.reduce(function(x, child) {
  7065. return x + child.x;
  7066. }, 0) / children.length;
  7067. }
  7068. function d3_layout_clusterLeft(node) {
  7069. var children = node.children;
  7070. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  7071. }
  7072. function d3_layout_clusterRight(node) {
  7073. var children = node.children, n;
  7074. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  7075. }
  7076. d3.layout.treemap = function() {
  7077. 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));
  7078. function scale(children, k) {
  7079. var i = -1, n = children.length, child, area;
  7080. while (++i < n) {
  7081. area = (child = children[i]).value * (k < 0 ? 0 : k);
  7082. child.area = isNaN(area) || area <= 0 ? 0 : area;
  7083. }
  7084. }
  7085. function squarify(node) {
  7086. var children = node.children;
  7087. if (children && children.length) {
  7088. 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;
  7089. scale(remaining, rect.dx * rect.dy / node.value);
  7090. row.area = 0;
  7091. while ((n = remaining.length) > 0) {
  7092. row.push(child = remaining[n - 1]);
  7093. row.area += child.area;
  7094. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  7095. remaining.pop();
  7096. best = score;
  7097. } else {
  7098. row.area -= row.pop().area;
  7099. position(row, u, rect, false);
  7100. u = Math.min(rect.dx, rect.dy);
  7101. row.length = row.area = 0;
  7102. best = Infinity;
  7103. }
  7104. }
  7105. if (row.length) {
  7106. position(row, u, rect, true);
  7107. row.length = row.area = 0;
  7108. }
  7109. children.forEach(squarify);
  7110. }
  7111. }
  7112. function stickify(node) {
  7113. var children = node.children;
  7114. if (children && children.length) {
  7115. var rect = pad(node), remaining = children.slice(), child, row = [];
  7116. scale(remaining, rect.dx * rect.dy / node.value);
  7117. row.area = 0;
  7118. while (child = remaining.pop()) {
  7119. row.push(child);
  7120. row.area += child.area;
  7121. if (child.z != null) {
  7122. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  7123. row.length = row.area = 0;
  7124. }
  7125. }
  7126. children.forEach(stickify);
  7127. }
  7128. }
  7129. function worst(row, u) {
  7130. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  7131. while (++i < n) {
  7132. if (!(r = row[i].area)) continue;
  7133. if (r < rmin) rmin = r;
  7134. if (r > rmax) rmax = r;
  7135. }
  7136. s *= s;
  7137. u *= u;
  7138. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  7139. }
  7140. function position(row, u, rect, flush) {
  7141. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  7142. if (u == rect.dx) {
  7143. if (flush || v > rect.dy) v = rect.dy;
  7144. while (++i < n) {
  7145. o = row[i];
  7146. o.x = x;
  7147. o.y = y;
  7148. o.dy = v;
  7149. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  7150. }
  7151. o.z = true;
  7152. o.dx += rect.x + rect.dx - x;
  7153. rect.y += v;
  7154. rect.dy -= v;
  7155. } else {
  7156. if (flush || v > rect.dx) v = rect.dx;
  7157. while (++i < n) {
  7158. o = row[i];
  7159. o.x = x;
  7160. o.y = y;
  7161. o.dx = v;
  7162. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  7163. }
  7164. o.z = false;
  7165. o.dy += rect.y + rect.dy - y;
  7166. rect.x += v;
  7167. rect.dx -= v;
  7168. }
  7169. }
  7170. function treemap(d) {
  7171. var nodes = stickies || hierarchy(d), root = nodes[0];
  7172. root.x = 0;
  7173. root.y = 0;
  7174. root.dx = size[0];
  7175. root.dy = size[1];
  7176. if (stickies) hierarchy.revalue(root);
  7177. scale([ root ], root.dx * root.dy / root.value);
  7178. (stickies ? stickify : squarify)(root);
  7179. if (sticky) stickies = nodes;
  7180. return nodes;
  7181. }
  7182. treemap.size = function(x) {
  7183. if (!arguments.length) return size;
  7184. size = x;
  7185. return treemap;
  7186. };
  7187. treemap.padding = function(x) {
  7188. if (!arguments.length) return padding;
  7189. function padFunction(node) {
  7190. var p = x.call(treemap, node, node.depth);
  7191. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  7192. }
  7193. function padConstant(node) {
  7194. return d3_layout_treemapPad(node, x);
  7195. }
  7196. var type;
  7197. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  7198. padConstant) : padConstant;
  7199. return treemap;
  7200. };
  7201. treemap.round = function(x) {
  7202. if (!arguments.length) return round != Number;
  7203. round = x ? Math.round : Number;
  7204. return treemap;
  7205. };
  7206. treemap.sticky = function(x) {
  7207. if (!arguments.length) return sticky;
  7208. sticky = x;
  7209. stickies = null;
  7210. return treemap;
  7211. };
  7212. treemap.ratio = function(x) {
  7213. if (!arguments.length) return ratio;
  7214. ratio = x;
  7215. return treemap;
  7216. };
  7217. treemap.mode = function(x) {
  7218. if (!arguments.length) return mode;
  7219. mode = x + "";
  7220. return treemap;
  7221. };
  7222. return d3_layout_hierarchyRebind(treemap, hierarchy);
  7223. };
  7224. function d3_layout_treemapPadNull(node) {
  7225. return {
  7226. x: node.x,
  7227. y: node.y,
  7228. dx: node.dx,
  7229. dy: node.dy
  7230. };
  7231. }
  7232. function d3_layout_treemapPad(node, padding) {
  7233. 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];
  7234. if (dx < 0) {
  7235. x += dx / 2;
  7236. dx = 0;
  7237. }
  7238. if (dy < 0) {
  7239. y += dy / 2;
  7240. dy = 0;
  7241. }
  7242. return {
  7243. x: x,
  7244. y: y,
  7245. dx: dx,
  7246. dy: dy
  7247. };
  7248. }
  7249. d3.random = {
  7250. normal: function(µ, σ) {
  7251. var n = arguments.length;
  7252. if (n < 2) σ = 1;
  7253. if (n < 1) µ = 0;
  7254. return function() {
  7255. var x, y, r;
  7256. do {
  7257. x = Math.random() * 2 - 1;
  7258. y = Math.random() * 2 - 1;
  7259. r = x * x + y * y;
  7260. } while (!r || r > 1);
  7261. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  7262. };
  7263. },
  7264. logNormal: function() {
  7265. var random = d3.random.normal.apply(d3, arguments);
  7266. return function() {
  7267. return Math.exp(random());
  7268. };
  7269. },
  7270. bates: function(m) {
  7271. var random = d3.random.irwinHall(m);
  7272. return function() {
  7273. return random() / m;
  7274. };
  7275. },
  7276. irwinHall: function(m) {
  7277. return function() {
  7278. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  7279. return s;
  7280. };
  7281. }
  7282. };
  7283. d3.scale = {};
  7284. function d3_scaleExtent(domain) {
  7285. var start = domain[0], stop = domain[domain.length - 1];
  7286. return start < stop ? [ start, stop ] : [ stop, start ];
  7287. }
  7288. function d3_scaleRange(scale) {
  7289. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  7290. }
  7291. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  7292. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  7293. return function(x) {
  7294. return i(u(x));
  7295. };
  7296. }
  7297. function d3_scale_nice(domain, nice) {
  7298. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  7299. if (x1 < x0) {
  7300. dx = i0, i0 = i1, i1 = dx;
  7301. dx = x0, x0 = x1, x1 = dx;
  7302. }
  7303. domain[i0] = nice.floor(x0);
  7304. domain[i1] = nice.ceil(x1);
  7305. return domain;
  7306. }
  7307. function d3_scale_niceStep(step) {
  7308. return step ? {
  7309. floor: function(x) {
  7310. return Math.floor(x / step) * step;
  7311. },
  7312. ceil: function(x) {
  7313. return Math.ceil(x / step) * step;
  7314. }
  7315. } : d3_scale_niceIdentity;
  7316. }
  7317. var d3_scale_niceIdentity = {
  7318. floor: d3_identity,
  7319. ceil: d3_identity
  7320. };
  7321. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  7322. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  7323. if (domain[k] < domain[0]) {
  7324. domain = domain.slice().reverse();
  7325. range = range.slice().reverse();
  7326. }
  7327. while (++j <= k) {
  7328. u.push(uninterpolate(domain[j - 1], domain[j]));
  7329. i.push(interpolate(range[j - 1], range[j]));
  7330. }
  7331. return function(x) {
  7332. var j = d3.bisect(domain, x, 1, k) - 1;
  7333. return i[j](u[j](x));
  7334. };
  7335. }
  7336. d3.scale.linear = function() {
  7337. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  7338. };
  7339. function d3_scale_linear(domain, range, interpolate, clamp) {
  7340. var output, input;
  7341. function rescale() {
  7342. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  7343. output = linear(domain, range, uninterpolate, interpolate);
  7344. input = linear(range, domain, uninterpolate, d3_interpolate);
  7345. return scale;
  7346. }
  7347. function scale(x) {
  7348. return output(x);
  7349. }
  7350. scale.invert = function(y) {
  7351. return input(y);
  7352. };
  7353. scale.domain = function(x) {
  7354. if (!arguments.length) return domain;
  7355. domain = x.map(Number);
  7356. return rescale();
  7357. };
  7358. scale.range = function(x) {
  7359. if (!arguments.length) return range;
  7360. range = x;
  7361. return rescale();
  7362. };
  7363. scale.rangeRound = function(x) {
  7364. return scale.range(x).interpolate(d3_interpolateRound);
  7365. };
  7366. scale.clamp = function(x) {
  7367. if (!arguments.length) return clamp;
  7368. clamp = x;
  7369. return rescale();
  7370. };
  7371. scale.interpolate = function(x) {
  7372. if (!arguments.length) return interpolate;
  7373. interpolate = x;
  7374. return rescale();
  7375. };
  7376. scale.ticks = function(m) {
  7377. return d3_scale_linearTicks(domain, m);
  7378. };
  7379. scale.tickFormat = function(m, format) {
  7380. return d3_scale_linearTickFormat(domain, m, format);
  7381. };
  7382. scale.nice = function(m) {
  7383. d3_scale_linearNice(domain, m);
  7384. return rescale();
  7385. };
  7386. scale.copy = function() {
  7387. return d3_scale_linear(domain, range, interpolate, clamp);
  7388. };
  7389. return rescale();
  7390. }
  7391. function d3_scale_linearRebind(scale, linear) {
  7392. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  7393. }
  7394. function d3_scale_linearNice(domain, m) {
  7395. return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  7396. }
  7397. function d3_scale_linearTickRange(domain, m) {
  7398. if (m == null) m = 10;
  7399. 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;
  7400. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  7401. extent[0] = Math.ceil(extent[0] / step) * step;
  7402. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  7403. extent[2] = step;
  7404. return extent;
  7405. }
  7406. function d3_scale_linearTicks(domain, m) {
  7407. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  7408. }
  7409. function d3_scale_linearTickFormat(domain, m, format) {
  7410. var range = d3_scale_linearTickRange(domain, m);
  7411. if (format) {
  7412. var match = d3_format_re.exec(format);
  7413. match.shift();
  7414. if (match[8] === "s") {
  7415. var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
  7416. if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
  7417. match[8] = "f";
  7418. format = d3.format(match.join(""));
  7419. return function(d) {
  7420. return format(prefix.scale(d)) + prefix.symbol;
  7421. };
  7422. }
  7423. if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
  7424. format = match.join("");
  7425. } else {
  7426. format = ",." + d3_scale_linearPrecision(range[2]) + "f";
  7427. }
  7428. return d3.format(format);
  7429. }
  7430. var d3_scale_linearFormatSignificant = {
  7431. s: 1,
  7432. g: 1,
  7433. p: 1,
  7434. r: 1,
  7435. e: 1
  7436. };
  7437. function d3_scale_linearPrecision(value) {
  7438. return -Math.floor(Math.log(value) / Math.LN10 + .01);
  7439. }
  7440. function d3_scale_linearFormatPrecision(type, range) {
  7441. var p = d3_scale_linearPrecision(range[2]);
  7442. return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
  7443. }
  7444. d3.scale.log = function() {
  7445. return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
  7446. };
  7447. function d3_scale_log(linear, base, positive, domain) {
  7448. function log(x) {
  7449. return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
  7450. }
  7451. function pow(x) {
  7452. return positive ? Math.pow(base, x) : -Math.pow(base, -x);
  7453. }
  7454. function scale(x) {
  7455. return linear(log(x));
  7456. }
  7457. scale.invert = function(x) {
  7458. return pow(linear.invert(x));
  7459. };
  7460. scale.domain = function(x) {
  7461. if (!arguments.length) return domain;
  7462. positive = x[0] >= 0;
  7463. linear.domain((domain = x.map(Number)).map(log));
  7464. return scale;
  7465. };
  7466. scale.base = function(_) {
  7467. if (!arguments.length) return base;
  7468. base = +_;
  7469. linear.domain(domain.map(log));
  7470. return scale;
  7471. };
  7472. scale.nice = function() {
  7473. var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
  7474. linear.domain(niced);
  7475. domain = niced.map(pow);
  7476. return scale;
  7477. };
  7478. scale.ticks = function() {
  7479. 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;
  7480. if (isFinite(j - i)) {
  7481. if (positive) {
  7482. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
  7483. ticks.push(pow(i));
  7484. } else {
  7485. ticks.push(pow(i));
  7486. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
  7487. }
  7488. for (i = 0; ticks[i] < u; i++) {}
  7489. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  7490. ticks = ticks.slice(i, j);
  7491. }
  7492. return ticks;
  7493. };
  7494. scale.tickFormat = function(n, format) {
  7495. if (!arguments.length) return d3_scale_logFormat;
  7496. if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
  7497. var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
  7498. Math.floor), e;
  7499. return function(d) {
  7500. return d / pow(f(log(d) + e)) <= k ? format(d) : "";
  7501. };
  7502. };
  7503. scale.copy = function() {
  7504. return d3_scale_log(linear.copy(), base, positive, domain);
  7505. };
  7506. return d3_scale_linearRebind(scale, linear);
  7507. }
  7508. var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
  7509. floor: function(x) {
  7510. return -Math.ceil(-x);
  7511. },
  7512. ceil: function(x) {
  7513. return -Math.floor(-x);
  7514. }
  7515. };
  7516. d3.scale.pow = function() {
  7517. return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
  7518. };
  7519. function d3_scale_pow(linear, exponent, domain) {
  7520. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  7521. function scale(x) {
  7522. return linear(powp(x));
  7523. }
  7524. scale.invert = function(x) {
  7525. return powb(linear.invert(x));
  7526. };
  7527. scale.domain = function(x) {
  7528. if (!arguments.length) return domain;
  7529. linear.domain((domain = x.map(Number)).map(powp));
  7530. return scale;
  7531. };
  7532. scale.ticks = function(m) {
  7533. return d3_scale_linearTicks(domain, m);
  7534. };
  7535. scale.tickFormat = function(m, format) {
  7536. return d3_scale_linearTickFormat(domain, m, format);
  7537. };
  7538. scale.nice = function(m) {
  7539. return scale.domain(d3_scale_linearNice(domain, m));
  7540. };
  7541. scale.exponent = function(x) {
  7542. if (!arguments.length) return exponent;
  7543. powp = d3_scale_powPow(exponent = x);
  7544. powb = d3_scale_powPow(1 / exponent);
  7545. linear.domain(domain.map(powp));
  7546. return scale;
  7547. };
  7548. scale.copy = function() {
  7549. return d3_scale_pow(linear.copy(), exponent, domain);
  7550. };
  7551. return d3_scale_linearRebind(scale, linear);
  7552. }
  7553. function d3_scale_powPow(e) {
  7554. return function(x) {
  7555. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  7556. };
  7557. }
  7558. d3.scale.sqrt = function() {
  7559. return d3.scale.pow().exponent(.5);
  7560. };
  7561. d3.scale.ordinal = function() {
  7562. return d3_scale_ordinal([], {
  7563. t: "range",
  7564. a: [ [] ]
  7565. });
  7566. };
  7567. function d3_scale_ordinal(domain, ranger) {
  7568. var index, range, rangeBand;
  7569. function scale(x) {
  7570. return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
  7571. }
  7572. function steps(start, step) {
  7573. return d3.range(domain.length).map(function(i) {
  7574. return start + step * i;
  7575. });
  7576. }
  7577. scale.domain = function(x) {
  7578. if (!arguments.length) return domain;
  7579. domain = [];
  7580. index = new d3_Map();
  7581. var i = -1, n = x.length, xi;
  7582. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  7583. return scale[ranger.t].apply(scale, ranger.a);
  7584. };
  7585. scale.range = function(x) {
  7586. if (!arguments.length) return range;
  7587. range = x;
  7588. rangeBand = 0;
  7589. ranger = {
  7590. t: "range",
  7591. a: arguments
  7592. };
  7593. return scale;
  7594. };
  7595. scale.rangePoints = function(x, padding) {
  7596. if (arguments.length < 2) padding = 0;
  7597. var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
  7598. range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
  7599. rangeBand = 0;
  7600. ranger = {
  7601. t: "rangePoints",
  7602. a: arguments
  7603. };
  7604. return scale;
  7605. };
  7606. scale.rangeBands = function(x, padding, outerPadding) {
  7607. if (arguments.length < 2) padding = 0;
  7608. if (arguments.length < 3) outerPadding = padding;
  7609. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  7610. range = steps(start + step * outerPadding, step);
  7611. if (reverse) range.reverse();
  7612. rangeBand = step * (1 - padding);
  7613. ranger = {
  7614. t: "rangeBands",
  7615. a: arguments
  7616. };
  7617. return scale;
  7618. };
  7619. scale.rangeRoundBands = function(x, padding, outerPadding) {
  7620. if (arguments.length < 2) padding = 0;
  7621. if (arguments.length < 3) outerPadding = padding;
  7622. 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;
  7623. range = steps(start + Math.round(error / 2), step);
  7624. if (reverse) range.reverse();
  7625. rangeBand = Math.round(step * (1 - padding));
  7626. ranger = {
  7627. t: "rangeRoundBands",
  7628. a: arguments
  7629. };
  7630. return scale;
  7631. };
  7632. scale.rangeBand = function() {
  7633. return rangeBand;
  7634. };
  7635. scale.rangeExtent = function() {
  7636. return d3_scaleExtent(ranger.a[0]);
  7637. };
  7638. scale.copy = function() {
  7639. return d3_scale_ordinal(domain, ranger);
  7640. };
  7641. return scale.domain(domain);
  7642. }
  7643. d3.scale.category10 = function() {
  7644. return d3.scale.ordinal().range(d3_category10);
  7645. };
  7646. d3.scale.category20 = function() {
  7647. return d3.scale.ordinal().range(d3_category20);
  7648. };
  7649. d3.scale.category20b = function() {
  7650. return d3.scale.ordinal().range(d3_category20b);
  7651. };
  7652. d3.scale.category20c = function() {
  7653. return d3.scale.ordinal().range(d3_category20c);
  7654. };
  7655. var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
  7656. 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);
  7657. 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);
  7658. 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);
  7659. d3.scale.quantile = function() {
  7660. return d3_scale_quantile([], []);
  7661. };
  7662. function d3_scale_quantile(domain, range) {
  7663. var thresholds;
  7664. function rescale() {
  7665. var k = 0, q = range.length;
  7666. thresholds = [];
  7667. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  7668. return scale;
  7669. }
  7670. function scale(x) {
  7671. if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
  7672. }
  7673. scale.domain = function(x) {
  7674. if (!arguments.length) return domain;
  7675. domain = x.filter(d3_number).sort(d3_ascending);
  7676. return rescale();
  7677. };
  7678. scale.range = function(x) {
  7679. if (!arguments.length) return range;
  7680. range = x;
  7681. return rescale();
  7682. };
  7683. scale.quantiles = function() {
  7684. return thresholds;
  7685. };
  7686. scale.invertExtent = function(y) {
  7687. y = range.indexOf(y);
  7688. return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
  7689. };
  7690. scale.copy = function() {
  7691. return d3_scale_quantile(domain, range);
  7692. };
  7693. return rescale();
  7694. }
  7695. d3.scale.quantize = function() {
  7696. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  7697. };
  7698. function d3_scale_quantize(x0, x1, range) {
  7699. var kx, i;
  7700. function scale(x) {
  7701. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  7702. }
  7703. function rescale() {
  7704. kx = range.length / (x1 - x0);
  7705. i = range.length - 1;
  7706. return scale;
  7707. }
  7708. scale.domain = function(x) {
  7709. if (!arguments.length) return [ x0, x1 ];
  7710. x0 = +x[0];
  7711. x1 = +x[x.length - 1];
  7712. return rescale();
  7713. };
  7714. scale.range = function(x) {
  7715. if (!arguments.length) return range;
  7716. range = x;
  7717. return rescale();
  7718. };
  7719. scale.invertExtent = function(y) {
  7720. y = range.indexOf(y);
  7721. y = y < 0 ? NaN : y / kx + x0;
  7722. return [ y, y + 1 / kx ];
  7723. };
  7724. scale.copy = function() {
  7725. return d3_scale_quantize(x0, x1, range);
  7726. };
  7727. return rescale();
  7728. }
  7729. d3.scale.threshold = function() {
  7730. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  7731. };
  7732. function d3_scale_threshold(domain, range) {
  7733. function scale(x) {
  7734. if (x <= x) return range[d3.bisect(domain, x)];
  7735. }
  7736. scale.domain = function(_) {
  7737. if (!arguments.length) return domain;
  7738. domain = _;
  7739. return scale;
  7740. };
  7741. scale.range = function(_) {
  7742. if (!arguments.length) return range;
  7743. range = _;
  7744. return scale;
  7745. };
  7746. scale.invertExtent = function(y) {
  7747. y = range.indexOf(y);
  7748. return [ domain[y - 1], domain[y] ];
  7749. };
  7750. scale.copy = function() {
  7751. return d3_scale_threshold(domain, range);
  7752. };
  7753. return scale;
  7754. }
  7755. d3.scale.identity = function() {
  7756. return d3_scale_identity([ 0, 1 ]);
  7757. };
  7758. function d3_scale_identity(domain) {
  7759. function identity(x) {
  7760. return +x;
  7761. }
  7762. identity.invert = identity;
  7763. identity.domain = identity.range = function(x) {
  7764. if (!arguments.length) return domain;
  7765. domain = x.map(identity);
  7766. return identity;
  7767. };
  7768. identity.ticks = function(m) {
  7769. return d3_scale_linearTicks(domain, m);
  7770. };
  7771. identity.tickFormat = function(m, format) {
  7772. return d3_scale_linearTickFormat(domain, m, format);
  7773. };
  7774. identity.copy = function() {
  7775. return d3_scale_identity(domain);
  7776. };
  7777. return identity;
  7778. }
  7779. d3.svg = {};
  7780. d3.svg.arc = function() {
  7781. var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  7782. function arc() {
  7783. 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,
  7784. 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);
  7785. 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";
  7786. }
  7787. arc.innerRadius = function(v) {
  7788. if (!arguments.length) return innerRadius;
  7789. innerRadius = d3_functor(v);
  7790. return arc;
  7791. };
  7792. arc.outerRadius = function(v) {
  7793. if (!arguments.length) return outerRadius;
  7794. outerRadius = d3_functor(v);
  7795. return arc;
  7796. };
  7797. arc.startAngle = function(v) {
  7798. if (!arguments.length) return startAngle;
  7799. startAngle = d3_functor(v);
  7800. return arc;
  7801. };
  7802. arc.endAngle = function(v) {
  7803. if (!arguments.length) return endAngle;
  7804. endAngle = d3_functor(v);
  7805. return arc;
  7806. };
  7807. arc.centroid = function() {
  7808. var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
  7809. return [ Math.cos(a) * r, Math.sin(a) * r ];
  7810. };
  7811. return arc;
  7812. };
  7813. var d3_svg_arcOffset = -halfπ, d3_svg_arcMax = τ - ε;
  7814. function d3_svg_arcInnerRadius(d) {
  7815. return d.innerRadius;
  7816. }
  7817. function d3_svg_arcOuterRadius(d) {
  7818. return d.outerRadius;
  7819. }
  7820. function d3_svg_arcStartAngle(d) {
  7821. return d.startAngle;
  7822. }
  7823. function d3_svg_arcEndAngle(d) {
  7824. return d.endAngle;
  7825. }
  7826. function d3_svg_line(projection) {
  7827. var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  7828. function line(data) {
  7829. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  7830. function segment() {
  7831. segments.push("M", interpolate(projection(points), tension));
  7832. }
  7833. while (++i < n) {
  7834. if (defined.call(this, d = data[i], i)) {
  7835. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  7836. } else if (points.length) {
  7837. segment();
  7838. points = [];
  7839. }
  7840. }
  7841. if (points.length) segment();
  7842. return segments.length ? segments.join("") : null;
  7843. }
  7844. line.x = function(_) {
  7845. if (!arguments.length) return x;
  7846. x = _;
  7847. return line;
  7848. };
  7849. line.y = function(_) {
  7850. if (!arguments.length) return y;
  7851. y = _;
  7852. return line;
  7853. };
  7854. line.defined = function(_) {
  7855. if (!arguments.length) return defined;
  7856. defined = _;
  7857. return line;
  7858. };
  7859. line.interpolate = function(_) {
  7860. if (!arguments.length) return interpolateKey;
  7861. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  7862. return line;
  7863. };
  7864. line.tension = function(_) {
  7865. if (!arguments.length) return tension;
  7866. tension = _;
  7867. return line;
  7868. };
  7869. return line;
  7870. }
  7871. d3.svg.line = function() {
  7872. return d3_svg_line(d3_identity);
  7873. };
  7874. var d3_svg_lineInterpolators = d3.map({
  7875. linear: d3_svg_lineLinear,
  7876. "linear-closed": d3_svg_lineLinearClosed,
  7877. step: d3_svg_lineStep,
  7878. "step-before": d3_svg_lineStepBefore,
  7879. "step-after": d3_svg_lineStepAfter,
  7880. basis: d3_svg_lineBasis,
  7881. "basis-open": d3_svg_lineBasisOpen,
  7882. "basis-closed": d3_svg_lineBasisClosed,
  7883. bundle: d3_svg_lineBundle,
  7884. cardinal: d3_svg_lineCardinal,
  7885. "cardinal-open": d3_svg_lineCardinalOpen,
  7886. "cardinal-closed": d3_svg_lineCardinalClosed,
  7887. monotone: d3_svg_lineMonotone
  7888. });
  7889. d3_svg_lineInterpolators.forEach(function(key, value) {
  7890. value.key = key;
  7891. value.closed = /-closed$/.test(key);
  7892. });
  7893. function d3_svg_lineLinear(points) {
  7894. return points.join("L");
  7895. }
  7896. function d3_svg_lineLinearClosed(points) {
  7897. return d3_svg_lineLinear(points) + "Z";
  7898. }
  7899. function d3_svg_lineStep(points) {
  7900. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  7901. while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
  7902. if (n > 1) path.push("H", p[0]);
  7903. return path.join("");
  7904. }
  7905. function d3_svg_lineStepBefore(points) {
  7906. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  7907. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  7908. return path.join("");
  7909. }
  7910. function d3_svg_lineStepAfter(points) {
  7911. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  7912. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  7913. return path.join("");
  7914. }
  7915. function d3_svg_lineCardinalOpen(points, tension) {
  7916. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
  7917. }
  7918. function d3_svg_lineCardinalClosed(points, tension) {
  7919. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  7920. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  7921. }
  7922. function d3_svg_lineCardinal(points, tension) {
  7923. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  7924. }
  7925. function d3_svg_lineHermite(points, tangents) {
  7926. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  7927. return d3_svg_lineLinear(points);
  7928. }
  7929. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  7930. if (quad) {
  7931. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  7932. p0 = points[1];
  7933. pi = 2;
  7934. }
  7935. if (tangents.length > 1) {
  7936. t = tangents[1];
  7937. p = points[pi];
  7938. pi++;
  7939. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  7940. for (var i = 2; i < tangents.length; i++, pi++) {
  7941. p = points[pi];
  7942. t = tangents[i];
  7943. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  7944. }
  7945. }
  7946. if (quad) {
  7947. var lp = points[pi];
  7948. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  7949. }
  7950. return path;
  7951. }
  7952. function d3_svg_lineCardinalTangents(points, tension) {
  7953. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  7954. while (++i < n) {
  7955. p0 = p1;
  7956. p1 = p2;
  7957. p2 = points[i];
  7958. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  7959. }
  7960. return tangents;
  7961. }
  7962. function d3_svg_lineBasis(points) {
  7963. if (points.length < 3) return d3_svg_lineLinear(points);
  7964. 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) ];
  7965. points.push(points[n - 1]);
  7966. while (++i <= n) {
  7967. pi = points[i];
  7968. px.shift();
  7969. px.push(pi[0]);
  7970. py.shift();
  7971. py.push(pi[1]);
  7972. d3_svg_lineBasisBezier(path, px, py);
  7973. }
  7974. points.pop();
  7975. path.push("L", pi);
  7976. return path.join("");
  7977. }
  7978. function d3_svg_lineBasisOpen(points) {
  7979. if (points.length < 4) return d3_svg_lineLinear(points);
  7980. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  7981. while (++i < 3) {
  7982. pi = points[i];
  7983. px.push(pi[0]);
  7984. py.push(pi[1]);
  7985. }
  7986. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  7987. --i;
  7988. while (++i < n) {
  7989. pi = points[i];
  7990. px.shift();
  7991. px.push(pi[0]);
  7992. py.shift();
  7993. py.push(pi[1]);
  7994. d3_svg_lineBasisBezier(path, px, py);
  7995. }
  7996. return path.join("");
  7997. }
  7998. function d3_svg_lineBasisClosed(points) {
  7999. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  8000. while (++i < 4) {
  8001. pi = points[i % n];
  8002. px.push(pi[0]);
  8003. py.push(pi[1]);
  8004. }
  8005. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8006. --i;
  8007. while (++i < m) {
  8008. pi = points[i % n];
  8009. px.shift();
  8010. px.push(pi[0]);
  8011. py.shift();
  8012. py.push(pi[1]);
  8013. d3_svg_lineBasisBezier(path, px, py);
  8014. }
  8015. return path.join("");
  8016. }
  8017. function d3_svg_lineBundle(points, tension) {
  8018. var n = points.length - 1;
  8019. if (n) {
  8020. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  8021. while (++i <= n) {
  8022. p = points[i];
  8023. t = i / n;
  8024. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  8025. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  8026. }
  8027. }
  8028. return d3_svg_lineBasis(points);
  8029. }
  8030. function d3_svg_lineDot4(a, b) {
  8031. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  8032. }
  8033. 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 ];
  8034. function d3_svg_lineBasisBezier(path, x, y) {
  8035. 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));
  8036. }
  8037. function d3_svg_lineSlope(p0, p1) {
  8038. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  8039. }
  8040. function d3_svg_lineFiniteDifferences(points) {
  8041. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  8042. while (++i < j) {
  8043. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  8044. }
  8045. m[i] = d;
  8046. return m;
  8047. }
  8048. function d3_svg_lineMonotoneTangents(points) {
  8049. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  8050. while (++i < j) {
  8051. d = d3_svg_lineSlope(points[i], points[i + 1]);
  8052. if (abs(d) < ε) {
  8053. m[i] = m[i + 1] = 0;
  8054. } else {
  8055. a = m[i] / d;
  8056. b = m[i + 1] / d;
  8057. s = a * a + b * b;
  8058. if (s > 9) {
  8059. s = d * 3 / Math.sqrt(s);
  8060. m[i] = s * a;
  8061. m[i + 1] = s * b;
  8062. }
  8063. }
  8064. }
  8065. i = -1;
  8066. while (++i <= j) {
  8067. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  8068. tangents.push([ s || 0, m[i] * s || 0 ]);
  8069. }
  8070. return tangents;
  8071. }
  8072. function d3_svg_lineMonotone(points) {
  8073. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  8074. }
  8075. d3.svg.line.radial = function() {
  8076. var line = d3_svg_line(d3_svg_lineRadial);
  8077. line.radius = line.x, delete line.x;
  8078. line.angle = line.y, delete line.y;
  8079. return line;
  8080. };
  8081. function d3_svg_lineRadial(points) {
  8082. var point, i = -1, n = points.length, r, a;
  8083. while (++i < n) {
  8084. point = points[i];
  8085. r = point[0];
  8086. a = point[1] + d3_svg_arcOffset;
  8087. point[0] = r * Math.cos(a);
  8088. point[1] = r * Math.sin(a);
  8089. }
  8090. return points;
  8091. }
  8092. function d3_svg_area(projection) {
  8093. var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
  8094. function area(data) {
  8095. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  8096. return x;
  8097. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  8098. return y;
  8099. } : d3_functor(y1), x, y;
  8100. function segment() {
  8101. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  8102. }
  8103. while (++i < n) {
  8104. if (defined.call(this, d = data[i], i)) {
  8105. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  8106. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  8107. } else if (points0.length) {
  8108. segment();
  8109. points0 = [];
  8110. points1 = [];
  8111. }
  8112. }
  8113. if (points0.length) segment();
  8114. return segments.length ? segments.join("") : null;
  8115. }
  8116. area.x = function(_) {
  8117. if (!arguments.length) return x1;
  8118. x0 = x1 = _;
  8119. return area;
  8120. };
  8121. area.x0 = function(_) {
  8122. if (!arguments.length) return x0;
  8123. x0 = _;
  8124. return area;
  8125. };
  8126. area.x1 = function(_) {
  8127. if (!arguments.length) return x1;
  8128. x1 = _;
  8129. return area;
  8130. };
  8131. area.y = function(_) {
  8132. if (!arguments.length) return y1;
  8133. y0 = y1 = _;
  8134. return area;
  8135. };
  8136. area.y0 = function(_) {
  8137. if (!arguments.length) return y0;
  8138. y0 = _;
  8139. return area;
  8140. };
  8141. area.y1 = function(_) {
  8142. if (!arguments.length) return y1;
  8143. y1 = _;
  8144. return area;
  8145. };
  8146. area.defined = function(_) {
  8147. if (!arguments.length) return defined;
  8148. defined = _;
  8149. return area;
  8150. };
  8151. area.interpolate = function(_) {
  8152. if (!arguments.length) return interpolateKey;
  8153. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8154. interpolateReverse = interpolate.reverse || interpolate;
  8155. L = interpolate.closed ? "M" : "L";
  8156. return area;
  8157. };
  8158. area.tension = function(_) {
  8159. if (!arguments.length) return tension;
  8160. tension = _;
  8161. return area;
  8162. };
  8163. return area;
  8164. }
  8165. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  8166. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  8167. d3.svg.area = function() {
  8168. return d3_svg_area(d3_identity);
  8169. };
  8170. d3.svg.area.radial = function() {
  8171. var area = d3_svg_area(d3_svg_lineRadial);
  8172. area.radius = area.x, delete area.x;
  8173. area.innerRadius = area.x0, delete area.x0;
  8174. area.outerRadius = area.x1, delete area.x1;
  8175. area.angle = area.y, delete area.y;
  8176. area.startAngle = area.y0, delete area.y0;
  8177. area.endAngle = area.y1, delete area.y1;
  8178. return area;
  8179. };
  8180. d3.svg.chord = function() {
  8181. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  8182. function chord(d, i) {
  8183. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  8184. 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";
  8185. }
  8186. function subgroup(self, f, d, i) {
  8187. 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;
  8188. return {
  8189. r: r,
  8190. a0: a0,
  8191. a1: a1,
  8192. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  8193. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  8194. };
  8195. }
  8196. function equals(a, b) {
  8197. return a.a0 == b.a0 && a.a1 == b.a1;
  8198. }
  8199. function arc(r, p, a) {
  8200. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  8201. }
  8202. function curve(r0, p0, r1, p1) {
  8203. return "Q 0,0 " + p1;
  8204. }
  8205. chord.radius = function(v) {
  8206. if (!arguments.length) return radius;
  8207. radius = d3_functor(v);
  8208. return chord;
  8209. };
  8210. chord.source = function(v) {
  8211. if (!arguments.length) return source;
  8212. source = d3_functor(v);
  8213. return chord;
  8214. };
  8215. chord.target = function(v) {
  8216. if (!arguments.length) return target;
  8217. target = d3_functor(v);
  8218. return chord;
  8219. };
  8220. chord.startAngle = function(v) {
  8221. if (!arguments.length) return startAngle;
  8222. startAngle = d3_functor(v);
  8223. return chord;
  8224. };
  8225. chord.endAngle = function(v) {
  8226. if (!arguments.length) return endAngle;
  8227. endAngle = d3_functor(v);
  8228. return chord;
  8229. };
  8230. return chord;
  8231. };
  8232. function d3_svg_chordRadius(d) {
  8233. return d.radius;
  8234. }
  8235. d3.svg.diagonal = function() {
  8236. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  8237. function diagonal(d, i) {
  8238. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  8239. x: p0.x,
  8240. y: m
  8241. }, {
  8242. x: p3.x,
  8243. y: m
  8244. }, p3 ];
  8245. p = p.map(projection);
  8246. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  8247. }
  8248. diagonal.source = function(x) {
  8249. if (!arguments.length) return source;
  8250. source = d3_functor(x);
  8251. return diagonal;
  8252. };
  8253. diagonal.target = function(x) {
  8254. if (!arguments.length) return target;
  8255. target = d3_functor(x);
  8256. return diagonal;
  8257. };
  8258. diagonal.projection = function(x) {
  8259. if (!arguments.length) return projection;
  8260. projection = x;
  8261. return diagonal;
  8262. };
  8263. return diagonal;
  8264. };
  8265. function d3_svg_diagonalProjection(d) {
  8266. return [ d.x, d.y ];
  8267. }
  8268. d3.svg.diagonal.radial = function() {
  8269. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  8270. diagonal.projection = function(x) {
  8271. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  8272. };
  8273. return diagonal;
  8274. };
  8275. function d3_svg_diagonalRadialProjection(projection) {
  8276. return function() {
  8277. var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
  8278. return [ r * Math.cos(a), r * Math.sin(a) ];
  8279. };
  8280. }
  8281. d3.svg.symbol = function() {
  8282. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  8283. function symbol(d, i) {
  8284. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  8285. }
  8286. symbol.type = function(x) {
  8287. if (!arguments.length) return type;
  8288. type = d3_functor(x);
  8289. return symbol;
  8290. };
  8291. symbol.size = function(x) {
  8292. if (!arguments.length) return size;
  8293. size = d3_functor(x);
  8294. return symbol;
  8295. };
  8296. return symbol;
  8297. };
  8298. function d3_svg_symbolSize() {
  8299. return 64;
  8300. }
  8301. function d3_svg_symbolType() {
  8302. return "circle";
  8303. }
  8304. function d3_svg_symbolCircle(size) {
  8305. var r = Math.sqrt(size / π);
  8306. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  8307. }
  8308. var d3_svg_symbols = d3.map({
  8309. circle: d3_svg_symbolCircle,
  8310. cross: function(size) {
  8311. var r = Math.sqrt(size / 5) / 2;
  8312. 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";
  8313. },
  8314. diamond: function(size) {
  8315. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  8316. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  8317. },
  8318. square: function(size) {
  8319. var r = Math.sqrt(size) / 2;
  8320. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  8321. },
  8322. "triangle-down": function(size) {
  8323. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8324. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  8325. },
  8326. "triangle-up": function(size) {
  8327. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8328. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  8329. }
  8330. });
  8331. d3.svg.symbolTypes = d3_svg_symbols.keys();
  8332. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  8333. function d3_transition(groups, id) {
  8334. d3_subclass(groups, d3_transitionPrototype);
  8335. groups.id = id;
  8336. return groups;
  8337. }
  8338. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
  8339. d3_transitionPrototype.call = d3_selectionPrototype.call;
  8340. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  8341. d3_transitionPrototype.node = d3_selectionPrototype.node;
  8342. d3_transitionPrototype.size = d3_selectionPrototype.size;
  8343. d3.transition = function(selection) {
  8344. return arguments.length ? d3_transitionInheritId ? selection.transition() : selection : d3_selectionRoot.transition();
  8345. };
  8346. d3.transition.prototype = d3_transitionPrototype;
  8347. d3_transitionPrototype.select = function(selector) {
  8348. var id = this.id, subgroups = [], subgroup, subnode, node;
  8349. selector = d3_selection_selector(selector);
  8350. for (var j = -1, m = this.length; ++j < m; ) {
  8351. subgroups.push(subgroup = []);
  8352. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8353. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
  8354. if ("__data__" in node) subnode.__data__ = node.__data__;
  8355. d3_transitionNode(subnode, i, id, node.__transition__[id]);
  8356. subgroup.push(subnode);
  8357. } else {
  8358. subgroup.push(null);
  8359. }
  8360. }
  8361. }
  8362. return d3_transition(subgroups, id);
  8363. };
  8364. d3_transitionPrototype.selectAll = function(selector) {
  8365. var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition;
  8366. selector = d3_selection_selectorAll(selector);
  8367. for (var j = -1, m = this.length; ++j < m; ) {
  8368. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8369. if (node = group[i]) {
  8370. transition = node.__transition__[id];
  8371. subnodes = selector.call(node, node.__data__, i, j);
  8372. subgroups.push(subgroup = []);
  8373. for (var k = -1, o = subnodes.length; ++k < o; ) {
  8374. if (subnode = subnodes[k]) d3_transitionNode(subnode, k, id, transition);
  8375. subgroup.push(subnode);
  8376. }
  8377. }
  8378. }
  8379. }
  8380. return d3_transition(subgroups, id);
  8381. };
  8382. d3_transitionPrototype.filter = function(filter) {
  8383. var subgroups = [], subgroup, group, node;
  8384. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  8385. for (var j = 0, m = this.length; j < m; j++) {
  8386. subgroups.push(subgroup = []);
  8387. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8388. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  8389. subgroup.push(node);
  8390. }
  8391. }
  8392. }
  8393. return d3_transition(subgroups, this.id);
  8394. };
  8395. d3_transitionPrototype.tween = function(name, tween) {
  8396. var id = this.id;
  8397. if (arguments.length < 2) return this.node().__transition__[id].tween.get(name);
  8398. return d3_selection_each(this, tween == null ? function(node) {
  8399. node.__transition__[id].tween.remove(name);
  8400. } : function(node) {
  8401. node.__transition__[id].tween.set(name, tween);
  8402. });
  8403. };
  8404. function d3_transition_tween(groups, name, value, tween) {
  8405. var id = groups.id;
  8406. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  8407. node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  8408. } : (value = tween(value), function(node) {
  8409. node.__transition__[id].tween.set(name, value);
  8410. }));
  8411. }
  8412. d3_transitionPrototype.attr = function(nameNS, value) {
  8413. if (arguments.length < 2) {
  8414. for (value in nameNS) this.attr(value, nameNS[value]);
  8415. return this;
  8416. }
  8417. var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
  8418. function attrNull() {
  8419. this.removeAttribute(name);
  8420. }
  8421. function attrNullNS() {
  8422. this.removeAttributeNS(name.space, name.local);
  8423. }
  8424. function attrTween(b) {
  8425. return b == null ? attrNull : (b += "", function() {
  8426. var a = this.getAttribute(name), i;
  8427. return a !== b && (i = interpolate(a, b), function(t) {
  8428. this.setAttribute(name, i(t));
  8429. });
  8430. });
  8431. }
  8432. function attrTweenNS(b) {
  8433. return b == null ? attrNullNS : (b += "", function() {
  8434. var a = this.getAttributeNS(name.space, name.local), i;
  8435. return a !== b && (i = interpolate(a, b), function(t) {
  8436. this.setAttributeNS(name.space, name.local, i(t));
  8437. });
  8438. });
  8439. }
  8440. return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
  8441. };
  8442. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  8443. var name = d3.ns.qualify(nameNS);
  8444. function attrTween(d, i) {
  8445. var f = tween.call(this, d, i, this.getAttribute(name));
  8446. return f && function(t) {
  8447. this.setAttribute(name, f(t));
  8448. };
  8449. }
  8450. function attrTweenNS(d, i) {
  8451. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  8452. return f && function(t) {
  8453. this.setAttributeNS(name.space, name.local, f(t));
  8454. };
  8455. }
  8456. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  8457. };
  8458. d3_transitionPrototype.style = function(name, value, priority) {
  8459. var n = arguments.length;
  8460. if (n < 3) {
  8461. if (typeof name !== "string") {
  8462. if (n < 2) value = "";
  8463. for (priority in name) this.style(priority, name[priority], value);
  8464. return this;
  8465. }
  8466. priority = "";
  8467. }
  8468. function styleNull() {
  8469. this.style.removeProperty(name);
  8470. }
  8471. function styleString(b) {
  8472. return b == null ? styleNull : (b += "", function() {
  8473. var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
  8474. return a !== b && (i = d3_interpolate(a, b), function(t) {
  8475. this.style.setProperty(name, i(t), priority);
  8476. });
  8477. });
  8478. }
  8479. return d3_transition_tween(this, "style." + name, value, styleString);
  8480. };
  8481. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  8482. if (arguments.length < 3) priority = "";
  8483. function styleTween(d, i) {
  8484. var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
  8485. return f && function(t) {
  8486. this.style.setProperty(name, f(t), priority);
  8487. };
  8488. }
  8489. return this.tween("style." + name, styleTween);
  8490. };
  8491. d3_transitionPrototype.text = function(value) {
  8492. return d3_transition_tween(this, "text", value, d3_transition_text);
  8493. };
  8494. function d3_transition_text(b) {
  8495. if (b == null) b = "";
  8496. return function() {
  8497. this.textContent = b;
  8498. };
  8499. }
  8500. d3_transitionPrototype.remove = function() {
  8501. return this.each("end.transition", function() {
  8502. var p;
  8503. if (this.__transition__.count < 2 && (p = this.parentNode)) p.removeChild(this);
  8504. });
  8505. };
  8506. d3_transitionPrototype.ease = function(value) {
  8507. var id = this.id;
  8508. if (arguments.length < 1) return this.node().__transition__[id].ease;
  8509. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  8510. return d3_selection_each(this, function(node) {
  8511. node.__transition__[id].ease = value;
  8512. });
  8513. };
  8514. d3_transitionPrototype.delay = function(value) {
  8515. var id = this.id;
  8516. if (arguments.length < 1) return this.node().__transition__[id].delay;
  8517. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8518. node.__transition__[id].delay = +value.call(node, node.__data__, i, j);
  8519. } : (value = +value, function(node) {
  8520. node.__transition__[id].delay = value;
  8521. }));
  8522. };
  8523. d3_transitionPrototype.duration = function(value) {
  8524. var id = this.id;
  8525. if (arguments.length < 1) return this.node().__transition__[id].duration;
  8526. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8527. node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j));
  8528. } : (value = Math.max(1, value), function(node) {
  8529. node.__transition__[id].duration = value;
  8530. }));
  8531. };
  8532. d3_transitionPrototype.each = function(type, listener) {
  8533. var id = this.id;
  8534. if (arguments.length < 2) {
  8535. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  8536. d3_transitionInheritId = id;
  8537. d3_selection_each(this, function(node, i, j) {
  8538. d3_transitionInherit = node.__transition__[id];
  8539. type.call(node, node.__data__, i, j);
  8540. });
  8541. d3_transitionInherit = inherit;
  8542. d3_transitionInheritId = inheritId;
  8543. } else {
  8544. d3_selection_each(this, function(node) {
  8545. var transition = node.__transition__[id];
  8546. (transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
  8547. });
  8548. }
  8549. return this;
  8550. };
  8551. d3_transitionPrototype.transition = function() {
  8552. var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition;
  8553. for (var j = 0, m = this.length; j < m; j++) {
  8554. subgroups.push(subgroup = []);
  8555. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8556. if (node = group[i]) {
  8557. transition = Object.create(node.__transition__[id0]);
  8558. transition.delay += transition.duration;
  8559. d3_transitionNode(node, i, id1, transition);
  8560. }
  8561. subgroup.push(node);
  8562. }
  8563. }
  8564. return d3_transition(subgroups, id1);
  8565. };
  8566. function d3_transitionNode(node, i, id, inherit) {
  8567. var lock = node.__transition__ || (node.__transition__ = {
  8568. active: 0,
  8569. count: 0
  8570. }), transition = lock[id];
  8571. if (!transition) {
  8572. var time = inherit.time;
  8573. transition = lock[id] = {
  8574. tween: new d3_Map(),
  8575. time: time,
  8576. ease: inherit.ease,
  8577. delay: inherit.delay,
  8578. duration: inherit.duration
  8579. };
  8580. ++lock.count;
  8581. d3.timer(function(elapsed) {
  8582. var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, timer = d3_timer_active, tweened = [];
  8583. timer.t = delay + time;
  8584. if (delay <= elapsed) return start(elapsed - delay);
  8585. timer.c = start;
  8586. function start(elapsed) {
  8587. if (lock.active > id) return stop();
  8588. lock.active = id;
  8589. transition.event && transition.event.start.call(node, d, i);
  8590. transition.tween.forEach(function(key, value) {
  8591. if (value = value.call(node, d, i)) {
  8592. tweened.push(value);
  8593. }
  8594. });
  8595. d3.timer(function() {
  8596. timer.c = tick(elapsed || 1) ? d3_true : tick;
  8597. return 1;
  8598. }, 0, time);
  8599. }
  8600. function tick(elapsed) {
  8601. if (lock.active !== id) return stop();
  8602. var t = elapsed / duration, e = ease(t), n = tweened.length;
  8603. while (n > 0) {
  8604. tweened[--n].call(node, e);
  8605. }
  8606. if (t >= 1) {
  8607. transition.event && transition.event.end.call(node, d, i);
  8608. return stop();
  8609. }
  8610. }
  8611. function stop() {
  8612. if (--lock.count) delete lock[id]; else delete node.__transition__;
  8613. return 1;
  8614. }
  8615. }, 0, time);
  8616. }
  8617. }
  8618. d3.svg.axis = function() {
  8619. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
  8620. function axis(g) {
  8621. g.each(function() {
  8622. var g = d3.select(this);
  8623. var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
  8624. var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickTransform;
  8625. var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  8626. d3.transition(path));
  8627. tickEnter.append("line");
  8628. tickEnter.append("text");
  8629. var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
  8630. switch (orient) {
  8631. case "bottom":
  8632. {
  8633. tickTransform = d3_svg_axisX;
  8634. lineEnter.attr("y2", innerTickSize);
  8635. textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding);
  8636. lineUpdate.attr("x2", 0).attr("y2", innerTickSize);
  8637. textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding);
  8638. text.attr("dy", ".71em").style("text-anchor", "middle");
  8639. pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize);
  8640. break;
  8641. }
  8642. case "top":
  8643. {
  8644. tickTransform = d3_svg_axisX;
  8645. lineEnter.attr("y2", -innerTickSize);
  8646. textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
  8647. lineUpdate.attr("x2", 0).attr("y2", -innerTickSize);
  8648. textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
  8649. text.attr("dy", "0em").style("text-anchor", "middle");
  8650. pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize);
  8651. break;
  8652. }
  8653. case "left":
  8654. {
  8655. tickTransform = d3_svg_axisY;
  8656. lineEnter.attr("x2", -innerTickSize);
  8657. textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding));
  8658. lineUpdate.attr("x2", -innerTickSize).attr("y2", 0);
  8659. textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", 0);
  8660. text.attr("dy", ".32em").style("text-anchor", "end");
  8661. pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize);
  8662. break;
  8663. }
  8664. case "right":
  8665. {
  8666. tickTransform = d3_svg_axisY;
  8667. lineEnter.attr("x2", innerTickSize);
  8668. textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding);
  8669. lineUpdate.attr("x2", innerTickSize).attr("y2", 0);
  8670. textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0);
  8671. text.attr("dy", ".32em").style("text-anchor", "start");
  8672. pathUpdate.attr("d", "M" + outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + outerTickSize);
  8673. break;
  8674. }
  8675. }
  8676. if (scale1.rangeBand) {
  8677. var x = scale1, dx = x.rangeBand() / 2;
  8678. scale0 = scale1 = function(d) {
  8679. return x(d) + dx;
  8680. };
  8681. } else if (scale0.rangeBand) {
  8682. scale0 = scale1;
  8683. } else {
  8684. tickExit.call(tickTransform, scale1);
  8685. }
  8686. tickEnter.call(tickTransform, scale0);
  8687. tickUpdate.call(tickTransform, scale1);
  8688. });
  8689. }
  8690. axis.scale = function(x) {
  8691. if (!arguments.length) return scale;
  8692. scale = x;
  8693. return axis;
  8694. };
  8695. axis.orient = function(x) {
  8696. if (!arguments.length) return orient;
  8697. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  8698. return axis;
  8699. };
  8700. axis.ticks = function() {
  8701. if (!arguments.length) return tickArguments_;
  8702. tickArguments_ = arguments;
  8703. return axis;
  8704. };
  8705. axis.tickValues = function(x) {
  8706. if (!arguments.length) return tickValues;
  8707. tickValues = x;
  8708. return axis;
  8709. };
  8710. axis.tickFormat = function(x) {
  8711. if (!arguments.length) return tickFormat_;
  8712. tickFormat_ = x;
  8713. return axis;
  8714. };
  8715. axis.tickSize = function(x) {
  8716. var n = arguments.length;
  8717. if (!n) return innerTickSize;
  8718. innerTickSize = +x;
  8719. outerTickSize = +arguments[n - 1];
  8720. return axis;
  8721. };
  8722. axis.innerTickSize = function(x) {
  8723. if (!arguments.length) return innerTickSize;
  8724. innerTickSize = +x;
  8725. return axis;
  8726. };
  8727. axis.outerTickSize = function(x) {
  8728. if (!arguments.length) return outerTickSize;
  8729. outerTickSize = +x;
  8730. return axis;
  8731. };
  8732. axis.tickPadding = function(x) {
  8733. if (!arguments.length) return tickPadding;
  8734. tickPadding = +x;
  8735. return axis;
  8736. };
  8737. axis.tickSubdivide = function() {
  8738. return arguments.length && axis;
  8739. };
  8740. return axis;
  8741. };
  8742. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  8743. top: 1,
  8744. right: 1,
  8745. bottom: 1,
  8746. left: 1
  8747. };
  8748. function d3_svg_axisX(selection, x) {
  8749. selection.attr("transform", function(d) {
  8750. return "translate(" + x(d) + ",0)";
  8751. });
  8752. }
  8753. function d3_svg_axisY(selection, y) {
  8754. selection.attr("transform", function(d) {
  8755. return "translate(0," + y(d) + ")";
  8756. });
  8757. }
  8758. d3.svg.brush = function() {
  8759. 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];
  8760. function brush(g) {
  8761. g.each(function() {
  8762. 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);
  8763. var background = g.selectAll(".background").data([ 0 ]);
  8764. background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  8765. g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
  8766. var resize = g.selectAll(".resize").data(resizes, d3_identity);
  8767. resize.exit().remove();
  8768. resize.enter().append("g").attr("class", function(d) {
  8769. return "resize " + d;
  8770. }).style("cursor", function(d) {
  8771. return d3_svg_brushCursor[d];
  8772. }).append("rect").attr("x", function(d) {
  8773. return /[ew]$/.test(d) ? -3 : null;
  8774. }).attr("y", function(d) {
  8775. return /^[ns]/.test(d) ? -3 : null;
  8776. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  8777. resize.style("display", brush.empty() ? "none" : null);
  8778. var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
  8779. if (x) {
  8780. range = d3_scaleRange(x);
  8781. backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
  8782. redrawX(gUpdate);
  8783. }
  8784. if (y) {
  8785. range = d3_scaleRange(y);
  8786. backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
  8787. redrawY(gUpdate);
  8788. }
  8789. redraw(gUpdate);
  8790. });
  8791. }
  8792. brush.event = function(g) {
  8793. g.each(function() {
  8794. var event_ = event.of(this, arguments), extent1 = {
  8795. x: xExtent,
  8796. y: yExtent,
  8797. i: xExtentDomain,
  8798. j: yExtentDomain
  8799. }, extent0 = this.__chart__ || extent1;
  8800. this.__chart__ = extent1;
  8801. if (d3_transitionInheritId) {
  8802. d3.select(this).transition().each("start.brush", function() {
  8803. xExtentDomain = extent0.i;
  8804. yExtentDomain = extent0.j;
  8805. xExtent = extent0.x;
  8806. yExtent = extent0.y;
  8807. event_({
  8808. type: "brushstart"
  8809. });
  8810. }).tween("brush:brush", function() {
  8811. var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
  8812. xExtentDomain = yExtentDomain = null;
  8813. return function(t) {
  8814. xExtent = extent1.x = xi(t);
  8815. yExtent = extent1.y = yi(t);
  8816. event_({
  8817. type: "brush",
  8818. mode: "resize"
  8819. });
  8820. };
  8821. }).each("end.brush", function() {
  8822. xExtentDomain = extent1.i;
  8823. yExtentDomain = extent1.j;
  8824. event_({
  8825. type: "brush",
  8826. mode: "resize"
  8827. });
  8828. event_({
  8829. type: "brushend"
  8830. });
  8831. });
  8832. } else {
  8833. event_({
  8834. type: "brushstart"
  8835. });
  8836. event_({
  8837. type: "brush",
  8838. mode: "resize"
  8839. });
  8840. event_({
  8841. type: "brushend"
  8842. });
  8843. }
  8844. });
  8845. };
  8846. function redraw(g) {
  8847. g.selectAll(".resize").attr("transform", function(d) {
  8848. return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
  8849. });
  8850. }
  8851. function redrawX(g) {
  8852. g.select(".extent").attr("x", xExtent[0]);
  8853. g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
  8854. }
  8855. function redrawY(g) {
  8856. g.select(".extent").attr("y", yExtent[0]);
  8857. g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
  8858. }
  8859. function brushstart() {
  8860. 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;
  8861. var w = d3.select(d3_window).on("keydown.brush", keydown).on("keyup.brush", keyup);
  8862. if (d3.event.changedTouches) {
  8863. w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
  8864. } else {
  8865. w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
  8866. }
  8867. g.interrupt().selectAll("*").interrupt();
  8868. if (dragging) {
  8869. origin[0] = xExtent[0] - origin[0];
  8870. origin[1] = yExtent[0] - origin[1];
  8871. } else if (resizing) {
  8872. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  8873. offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
  8874. origin[0] = xExtent[ex];
  8875. origin[1] = yExtent[ey];
  8876. } else if (d3.event.altKey) center = origin.slice();
  8877. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  8878. d3.select("body").style("cursor", eventTarget.style("cursor"));
  8879. event_({
  8880. type: "brushstart"
  8881. });
  8882. brushmove();
  8883. function keydown() {
  8884. if (d3.event.keyCode == 32) {
  8885. if (!dragging) {
  8886. center = null;
  8887. origin[0] -= xExtent[1];
  8888. origin[1] -= yExtent[1];
  8889. dragging = 2;
  8890. }
  8891. d3_eventPreventDefault();
  8892. }
  8893. }
  8894. function keyup() {
  8895. if (d3.event.keyCode == 32 && dragging == 2) {
  8896. origin[0] += xExtent[1];
  8897. origin[1] += yExtent[1];
  8898. dragging = 0;
  8899. d3_eventPreventDefault();
  8900. }
  8901. }
  8902. function brushmove() {
  8903. var point = d3.mouse(target), moved = false;
  8904. if (offset) {
  8905. point[0] += offset[0];
  8906. point[1] += offset[1];
  8907. }
  8908. if (!dragging) {
  8909. if (d3.event.altKey) {
  8910. if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
  8911. origin[0] = xExtent[+(point[0] < center[0])];
  8912. origin[1] = yExtent[+(point[1] < center[1])];
  8913. } else center = null;
  8914. }
  8915. if (resizingX && move1(point, x, 0)) {
  8916. redrawX(g);
  8917. moved = true;
  8918. }
  8919. if (resizingY && move1(point, y, 1)) {
  8920. redrawY(g);
  8921. moved = true;
  8922. }
  8923. if (moved) {
  8924. redraw(g);
  8925. event_({
  8926. type: "brush",
  8927. mode: dragging ? "move" : "resize"
  8928. });
  8929. }
  8930. }
  8931. function move1(point, scale, i) {
  8932. 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;
  8933. if (dragging) {
  8934. r0 -= position;
  8935. r1 -= size + position;
  8936. }
  8937. min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
  8938. if (dragging) {
  8939. max = (min += position) + size;
  8940. } else {
  8941. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  8942. if (position < min) {
  8943. max = min;
  8944. min = position;
  8945. } else {
  8946. max = position;
  8947. }
  8948. }
  8949. if (extent[0] != min || extent[1] != max) {
  8950. if (i) yExtentDomain = null; else xExtentDomain = null;
  8951. extent[0] = min;
  8952. extent[1] = max;
  8953. return true;
  8954. }
  8955. }
  8956. function brushend() {
  8957. brushmove();
  8958. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  8959. d3.select("body").style("cursor", null);
  8960. 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);
  8961. dragRestore();
  8962. event_({
  8963. type: "brushend"
  8964. });
  8965. }
  8966. }
  8967. brush.x = function(z) {
  8968. if (!arguments.length) return x;
  8969. x = z;
  8970. resizes = d3_svg_brushResizes[!x << 1 | !y];
  8971. return brush;
  8972. };
  8973. brush.y = function(z) {
  8974. if (!arguments.length) return y;
  8975. y = z;
  8976. resizes = d3_svg_brushResizes[!x << 1 | !y];
  8977. return brush;
  8978. };
  8979. brush.clamp = function(z) {
  8980. if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
  8981. if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
  8982. return brush;
  8983. };
  8984. brush.extent = function(z) {
  8985. var x0, x1, y0, y1, t;
  8986. if (!arguments.length) {
  8987. if (x) {
  8988. if (xExtentDomain) {
  8989. x0 = xExtentDomain[0], x1 = xExtentDomain[1];
  8990. } else {
  8991. x0 = xExtent[0], x1 = xExtent[1];
  8992. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  8993. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  8994. }
  8995. }
  8996. if (y) {
  8997. if (yExtentDomain) {
  8998. y0 = yExtentDomain[0], y1 = yExtentDomain[1];
  8999. } else {
  9000. y0 = yExtent[0], y1 = yExtent[1];
  9001. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  9002. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9003. }
  9004. }
  9005. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  9006. }
  9007. if (x) {
  9008. x0 = z[0], x1 = z[1];
  9009. if (y) x0 = x0[0], x1 = x1[0];
  9010. xExtentDomain = [ x0, x1 ];
  9011. if (x.invert) x0 = x(x0), x1 = x(x1);
  9012. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9013. if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
  9014. }
  9015. if (y) {
  9016. y0 = z[0], y1 = z[1];
  9017. if (x) y0 = y0[1], y1 = y1[1];
  9018. yExtentDomain = [ y0, y1 ];
  9019. if (y.invert) y0 = y(y0), y1 = y(y1);
  9020. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9021. if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
  9022. }
  9023. return brush;
  9024. };
  9025. brush.clear = function() {
  9026. if (!brush.empty()) {
  9027. xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
  9028. xExtentDomain = yExtentDomain = null;
  9029. }
  9030. return brush;
  9031. };
  9032. brush.empty = function() {
  9033. return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
  9034. };
  9035. return d3.rebind(brush, event, "on");
  9036. };
  9037. var d3_svg_brushCursor = {
  9038. n: "ns-resize",
  9039. e: "ew-resize",
  9040. s: "ns-resize",
  9041. w: "ew-resize",
  9042. nw: "nwse-resize",
  9043. ne: "nesw-resize",
  9044. se: "nwse-resize",
  9045. sw: "nesw-resize"
  9046. };
  9047. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  9048. var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
  9049. var d3_time_formatUtc = d3_time_format.utc;
  9050. var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
  9051. d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  9052. function d3_time_formatIsoNative(date) {
  9053. return date.toISOString();
  9054. }
  9055. d3_time_formatIsoNative.parse = function(string) {
  9056. var date = new Date(string);
  9057. return isNaN(date) ? null : date;
  9058. };
  9059. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  9060. d3_time.second = d3_time_interval(function(date) {
  9061. return new d3_date(Math.floor(date / 1e3) * 1e3);
  9062. }, function(date, offset) {
  9063. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  9064. }, function(date) {
  9065. return date.getSeconds();
  9066. });
  9067. d3_time.seconds = d3_time.second.range;
  9068. d3_time.seconds.utc = d3_time.second.utc.range;
  9069. d3_time.minute = d3_time_interval(function(date) {
  9070. return new d3_date(Math.floor(date / 6e4) * 6e4);
  9071. }, function(date, offset) {
  9072. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  9073. }, function(date) {
  9074. return date.getMinutes();
  9075. });
  9076. d3_time.minutes = d3_time.minute.range;
  9077. d3_time.minutes.utc = d3_time.minute.utc.range;
  9078. d3_time.hour = d3_time_interval(function(date) {
  9079. var timezone = date.getTimezoneOffset() / 60;
  9080. return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  9081. }, function(date, offset) {
  9082. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  9083. }, function(date) {
  9084. return date.getHours();
  9085. });
  9086. d3_time.hours = d3_time.hour.range;
  9087. d3_time.hours.utc = d3_time.hour.utc.range;
  9088. d3_time.month = d3_time_interval(function(date) {
  9089. date = d3_time.day(date);
  9090. date.setDate(1);
  9091. return date;
  9092. }, function(date, offset) {
  9093. date.setMonth(date.getMonth() + offset);
  9094. }, function(date) {
  9095. return date.getMonth();
  9096. });
  9097. d3_time.months = d3_time.month.range;
  9098. d3_time.months.utc = d3_time.month.utc.range;
  9099. function d3_time_scale(linear, methods, format) {
  9100. function scale(x) {
  9101. return linear(x);
  9102. }
  9103. scale.invert = function(x) {
  9104. return d3_time_scaleDate(linear.invert(x));
  9105. };
  9106. scale.domain = function(x) {
  9107. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  9108. linear.domain(x);
  9109. return scale;
  9110. };
  9111. function tickMethod(extent, count) {
  9112. var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
  9113. return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
  9114. return d / 31536e6;
  9115. }), 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];
  9116. }
  9117. scale.nice = function(interval, skip) {
  9118. var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
  9119. if (method) interval = method[0], skip = method[1];
  9120. function skipped(date) {
  9121. return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
  9122. }
  9123. return scale.domain(d3_scale_nice(domain, skip > 1 ? {
  9124. floor: function(date) {
  9125. while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
  9126. return date;
  9127. },
  9128. ceil: function(date) {
  9129. while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
  9130. return date;
  9131. }
  9132. } : interval));
  9133. };
  9134. scale.ticks = function(interval, skip) {
  9135. var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
  9136. range: interval
  9137. }, skip ];
  9138. if (method) interval = method[0], skip = method[1];
  9139. return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
  9140. };
  9141. scale.tickFormat = function() {
  9142. return format;
  9143. };
  9144. scale.copy = function() {
  9145. return d3_time_scale(linear.copy(), methods, format);
  9146. };
  9147. return d3_scale_linearRebind(scale, linear);
  9148. }
  9149. function d3_time_scaleDate(t) {
  9150. return new Date(t);
  9151. }
  9152. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  9153. 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 ] ];
  9154. var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
  9155. return d.getMilliseconds();
  9156. } ], [ ":%S", function(d) {
  9157. return d.getSeconds();
  9158. } ], [ "%I:%M", function(d) {
  9159. return d.getMinutes();
  9160. } ], [ "%I %p", function(d) {
  9161. return d.getHours();
  9162. } ], [ "%a %d", function(d) {
  9163. return d.getDay() && d.getDate() != 1;
  9164. } ], [ "%b %d", function(d) {
  9165. return d.getDate() != 1;
  9166. } ], [ "%B", function(d) {
  9167. return d.getMonth();
  9168. } ], [ "%Y", d3_true ] ]);
  9169. var d3_time_scaleMilliseconds = {
  9170. range: function(start, stop, step) {
  9171. return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
  9172. },
  9173. floor: d3_identity,
  9174. ceil: d3_identity
  9175. };
  9176. d3_time_scaleLocalMethods.year = d3_time.year;
  9177. d3_time.scale = function() {
  9178. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  9179. };
  9180. var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
  9181. return [ m[0].utc, m[1] ];
  9182. });
  9183. var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
  9184. return d.getUTCMilliseconds();
  9185. } ], [ ":%S", function(d) {
  9186. return d.getUTCSeconds();
  9187. } ], [ "%I:%M", function(d) {
  9188. return d.getUTCMinutes();
  9189. } ], [ "%I %p", function(d) {
  9190. return d.getUTCHours();
  9191. } ], [ "%a %d", function(d) {
  9192. return d.getUTCDay() && d.getUTCDate() != 1;
  9193. } ], [ "%b %d", function(d) {
  9194. return d.getUTCDate() != 1;
  9195. } ], [ "%B", function(d) {
  9196. return d.getUTCMonth();
  9197. } ], [ "%Y", d3_true ] ]);
  9198. d3_time_scaleUtcMethods.year = d3_time.year.utc;
  9199. d3_time.scale.utc = function() {
  9200. return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
  9201. };
  9202. d3.text = d3_xhrType(function(request) {
  9203. return request.responseText;
  9204. });
  9205. d3.json = function(url, callback) {
  9206. return d3_xhr(url, "application/json", d3_json, callback);
  9207. };
  9208. function d3_json(request) {
  9209. return JSON.parse(request.responseText);
  9210. }
  9211. d3.html = function(url, callback) {
  9212. return d3_xhr(url, "text/html", d3_html, callback);
  9213. };
  9214. function d3_html(request) {
  9215. var range = d3_document.createRange();
  9216. range.selectNode(d3_document.body);
  9217. return range.createContextualFragment(request.responseText);
  9218. }
  9219. d3.xml = d3_xhrType(function(request) {
  9220. return request.responseXML;
  9221. });
  9222. if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3;
  9223. this.d3 = d3;
  9224. }();