d3.js 454 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904
  1. // https://d3js.org Version 4.10.2. Copyright 2017 Mike Bostock.
  2. // license:BSD 3-clause "New" or "Revised"
  3. (function (global, factory) {
  4. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  5. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  6. (factory((global.d3 = global.d3 || {})));
  7. }(this, (function (exports) { 'use strict';
  8. var version = "4.10.2";
  9. var ascending = function(a, b) {
  10. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  11. };
  12. var bisector = function(compare) {
  13. if (compare.length === 1) compare = ascendingComparator(compare);
  14. return {
  15. left: function(a, x, lo, hi) {
  16. if (lo == null) lo = 0;
  17. if (hi == null) hi = a.length;
  18. while (lo < hi) {
  19. var mid = lo + hi >>> 1;
  20. if (compare(a[mid], x) < 0) lo = mid + 1;
  21. else hi = mid;
  22. }
  23. return lo;
  24. },
  25. right: function(a, x, lo, hi) {
  26. if (lo == null) lo = 0;
  27. if (hi == null) hi = a.length;
  28. while (lo < hi) {
  29. var mid = lo + hi >>> 1;
  30. if (compare(a[mid], x) > 0) hi = mid;
  31. else lo = mid + 1;
  32. }
  33. return lo;
  34. }
  35. };
  36. };
  37. function ascendingComparator(f) {
  38. return function(d, x) {
  39. return ascending(f(d), x);
  40. };
  41. }
  42. var ascendingBisect = bisector(ascending);
  43. var bisectRight$1 = ascendingBisect.right;
  44. var bisectLeft = ascendingBisect.left;
  45. var pairs = function(array, f) {
  46. if (f == null) f = pair;
  47. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  48. while (i < n) pairs[i] = f(p, p = array[++i]);
  49. return pairs;
  50. };
  51. function pair(a, b) {
  52. return [a, b];
  53. }
  54. var cross = function(values0, values1, reduce) {
  55. var n0 = values0.length,
  56. n1 = values1.length,
  57. values = new Array(n0 * n1),
  58. i0,
  59. i1,
  60. i,
  61. value0;
  62. if (reduce == null) reduce = pair;
  63. for (i0 = i = 0; i0 < n0; ++i0) {
  64. for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
  65. values[i] = reduce(value0, values1[i1]);
  66. }
  67. }
  68. return values;
  69. };
  70. var descending = function(a, b) {
  71. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  72. };
  73. var number = function(x) {
  74. return x === null ? NaN : +x;
  75. };
  76. var variance = function(values, valueof) {
  77. var n = values.length,
  78. m = 0,
  79. i = -1,
  80. mean = 0,
  81. value,
  82. delta,
  83. sum = 0;
  84. if (valueof == null) {
  85. while (++i < n) {
  86. if (!isNaN(value = number(values[i]))) {
  87. delta = value - mean;
  88. mean += delta / ++m;
  89. sum += delta * (value - mean);
  90. }
  91. }
  92. }
  93. else {
  94. while (++i < n) {
  95. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  96. delta = value - mean;
  97. mean += delta / ++m;
  98. sum += delta * (value - mean);
  99. }
  100. }
  101. }
  102. if (m > 1) return sum / (m - 1);
  103. };
  104. var deviation = function(array, f) {
  105. var v = variance(array, f);
  106. return v ? Math.sqrt(v) : v;
  107. };
  108. var extent = function(values, valueof) {
  109. var n = values.length,
  110. i = -1,
  111. value,
  112. min,
  113. max;
  114. if (valueof == null) {
  115. while (++i < n) { // Find the first comparable value.
  116. if ((value = values[i]) != null && value >= value) {
  117. min = max = value;
  118. while (++i < n) { // Compare the remaining values.
  119. if ((value = values[i]) != null) {
  120. if (min > value) min = value;
  121. if (max < value) max = value;
  122. }
  123. }
  124. }
  125. }
  126. }
  127. else {
  128. while (++i < n) { // Find the first comparable value.
  129. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  130. min = max = value;
  131. while (++i < n) { // Compare the remaining values.
  132. if ((value = valueof(values[i], i, values)) != null) {
  133. if (min > value) min = value;
  134. if (max < value) max = value;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. return [min, max];
  141. };
  142. var array = Array.prototype;
  143. var slice = array.slice;
  144. var map = array.map;
  145. var constant = function(x) {
  146. return function() {
  147. return x;
  148. };
  149. };
  150. var identity = function(x) {
  151. return x;
  152. };
  153. var sequence = function(start, stop, step) {
  154. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  155. var i = -1,
  156. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  157. range = new Array(n);
  158. while (++i < n) {
  159. range[i] = start + i * step;
  160. }
  161. return range;
  162. };
  163. var e10 = Math.sqrt(50);
  164. var e5 = Math.sqrt(10);
  165. var e2 = Math.sqrt(2);
  166. var ticks = function(start, stop, count) {
  167. var reverse = stop < start,
  168. i = -1,
  169. n,
  170. ticks,
  171. step;
  172. if (reverse) n = start, start = stop, stop = n;
  173. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  174. if (step > 0) {
  175. start = Math.ceil(start / step);
  176. stop = Math.floor(stop / step);
  177. ticks = new Array(n = Math.ceil(stop - start + 1));
  178. while (++i < n) ticks[i] = (start + i) * step;
  179. } else {
  180. start = Math.floor(start * step);
  181. stop = Math.ceil(stop * step);
  182. ticks = new Array(n = Math.ceil(start - stop + 1));
  183. while (++i < n) ticks[i] = (start - i) / step;
  184. }
  185. if (reverse) ticks.reverse();
  186. return ticks;
  187. };
  188. function tickIncrement(start, stop, count) {
  189. var step = (stop - start) / Math.max(0, count),
  190. power = Math.floor(Math.log(step) / Math.LN10),
  191. error = step / Math.pow(10, power);
  192. return power >= 0
  193. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  194. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  195. }
  196. function tickStep(start, stop, count) {
  197. var step0 = Math.abs(stop - start) / Math.max(0, count),
  198. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  199. error = step0 / step1;
  200. if (error >= e10) step1 *= 10;
  201. else if (error >= e5) step1 *= 5;
  202. else if (error >= e2) step1 *= 2;
  203. return stop < start ? -step1 : step1;
  204. }
  205. var sturges = function(values) {
  206. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  207. };
  208. var histogram = function() {
  209. var value = identity,
  210. domain = extent,
  211. threshold = sturges;
  212. function histogram(data) {
  213. var i,
  214. n = data.length,
  215. x,
  216. values = new Array(n);
  217. for (i = 0; i < n; ++i) {
  218. values[i] = value(data[i], i, data);
  219. }
  220. var xz = domain(values),
  221. x0 = xz[0],
  222. x1 = xz[1],
  223. tz = threshold(values, x0, x1);
  224. // Convert number of thresholds into uniform thresholds.
  225. if (!Array.isArray(tz)) {
  226. tz = tickStep(x0, x1, tz);
  227. tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
  228. }
  229. // Remove any thresholds outside the domain.
  230. var m = tz.length;
  231. while (tz[0] <= x0) tz.shift(), --m;
  232. while (tz[m - 1] > x1) tz.pop(), --m;
  233. var bins = new Array(m + 1),
  234. bin;
  235. // Initialize bins.
  236. for (i = 0; i <= m; ++i) {
  237. bin = bins[i] = [];
  238. bin.x0 = i > 0 ? tz[i - 1] : x0;
  239. bin.x1 = i < m ? tz[i] : x1;
  240. }
  241. // Assign data to bins by value, ignoring any outside the domain.
  242. for (i = 0; i < n; ++i) {
  243. x = values[i];
  244. if (x0 <= x && x <= x1) {
  245. bins[bisectRight$1(tz, x, 0, m)].push(data[i]);
  246. }
  247. }
  248. return bins;
  249. }
  250. histogram.value = function(_) {
  251. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  252. };
  253. histogram.domain = function(_) {
  254. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  255. };
  256. histogram.thresholds = function(_) {
  257. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  258. };
  259. return histogram;
  260. };
  261. var threshold = function(values, p, valueof) {
  262. if (valueof == null) valueof = number;
  263. if (!(n = values.length)) return;
  264. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  265. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  266. var n,
  267. i = (n - 1) * p,
  268. i0 = Math.floor(i),
  269. value0 = +valueof(values[i0], i0, values),
  270. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  271. return value0 + (value1 - value0) * (i - i0);
  272. };
  273. var freedmanDiaconis = function(values, min, max) {
  274. values = map.call(values, number).sort(ascending);
  275. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  276. };
  277. var scott = function(values, min, max) {
  278. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  279. };
  280. var max = function(values, valueof) {
  281. var n = values.length,
  282. i = -1,
  283. value,
  284. max;
  285. if (valueof == null) {
  286. while (++i < n) { // Find the first comparable value.
  287. if ((value = values[i]) != null && value >= value) {
  288. max = value;
  289. while (++i < n) { // Compare the remaining values.
  290. if ((value = values[i]) != null && value > max) {
  291. max = value;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. else {
  298. while (++i < n) { // Find the first comparable value.
  299. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  300. max = value;
  301. while (++i < n) { // Compare the remaining values.
  302. if ((value = valueof(values[i], i, values)) != null && value > max) {
  303. max = value;
  304. }
  305. }
  306. }
  307. }
  308. }
  309. return max;
  310. };
  311. var mean = function(values, valueof) {
  312. var n = values.length,
  313. m = n,
  314. i = -1,
  315. value,
  316. sum = 0;
  317. if (valueof == null) {
  318. while (++i < n) {
  319. if (!isNaN(value = number(values[i]))) sum += value;
  320. else --m;
  321. }
  322. }
  323. else {
  324. while (++i < n) {
  325. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  326. else --m;
  327. }
  328. }
  329. if (m) return sum / m;
  330. };
  331. var median = function(values, valueof) {
  332. var n = values.length,
  333. i = -1,
  334. value,
  335. numbers = [];
  336. if (valueof == null) {
  337. while (++i < n) {
  338. if (!isNaN(value = number(values[i]))) {
  339. numbers.push(value);
  340. }
  341. }
  342. }
  343. else {
  344. while (++i < n) {
  345. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  346. numbers.push(value);
  347. }
  348. }
  349. }
  350. return threshold(numbers.sort(ascending), 0.5);
  351. };
  352. var merge = function(arrays) {
  353. var n = arrays.length,
  354. m,
  355. i = -1,
  356. j = 0,
  357. merged,
  358. array;
  359. while (++i < n) j += arrays[i].length;
  360. merged = new Array(j);
  361. while (--n >= 0) {
  362. array = arrays[n];
  363. m = array.length;
  364. while (--m >= 0) {
  365. merged[--j] = array[m];
  366. }
  367. }
  368. return merged;
  369. };
  370. var min = function(values, valueof) {
  371. var n = values.length,
  372. i = -1,
  373. value,
  374. min;
  375. if (valueof == null) {
  376. while (++i < n) { // Find the first comparable value.
  377. if ((value = values[i]) != null && value >= value) {
  378. min = value;
  379. while (++i < n) { // Compare the remaining values.
  380. if ((value = values[i]) != null && min > value) {
  381. min = value;
  382. }
  383. }
  384. }
  385. }
  386. }
  387. else {
  388. while (++i < n) { // Find the first comparable value.
  389. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  390. min = value;
  391. while (++i < n) { // Compare the remaining values.
  392. if ((value = valueof(values[i], i, values)) != null && min > value) {
  393. min = value;
  394. }
  395. }
  396. }
  397. }
  398. }
  399. return min;
  400. };
  401. var permute = function(array, indexes) {
  402. var i = indexes.length, permutes = new Array(i);
  403. while (i--) permutes[i] = array[indexes[i]];
  404. return permutes;
  405. };
  406. var scan = function(values, compare) {
  407. if (!(n = values.length)) return;
  408. var n,
  409. i = 0,
  410. j = 0,
  411. xi,
  412. xj = values[j];
  413. if (compare == null) compare = ascending;
  414. while (++i < n) {
  415. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  416. xj = xi, j = i;
  417. }
  418. }
  419. if (compare(xj, xj) === 0) return j;
  420. };
  421. var shuffle = function(array, i0, i1) {
  422. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  423. t,
  424. i;
  425. while (m) {
  426. i = Math.random() * m-- | 0;
  427. t = array[m + i0];
  428. array[m + i0] = array[i + i0];
  429. array[i + i0] = t;
  430. }
  431. return array;
  432. };
  433. var sum = function(values, valueof) {
  434. var n = values.length,
  435. i = -1,
  436. value,
  437. sum = 0;
  438. if (valueof == null) {
  439. while (++i < n) {
  440. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  441. }
  442. }
  443. else {
  444. while (++i < n) {
  445. if (value = +valueof(values[i], i, values)) sum += value;
  446. }
  447. }
  448. return sum;
  449. };
  450. var transpose = function(matrix) {
  451. if (!(n = matrix.length)) return [];
  452. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  453. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  454. row[j] = matrix[j][i];
  455. }
  456. }
  457. return transpose;
  458. };
  459. function length(d) {
  460. return d.length;
  461. }
  462. var zip = function() {
  463. return transpose(arguments);
  464. };
  465. var slice$1 = Array.prototype.slice;
  466. var identity$1 = function(x) {
  467. return x;
  468. };
  469. var top = 1;
  470. var right = 2;
  471. var bottom = 3;
  472. var left = 4;
  473. var epsilon = 1e-6;
  474. function translateX(x) {
  475. return "translate(" + (x + 0.5) + ",0)";
  476. }
  477. function translateY(y) {
  478. return "translate(0," + (y + 0.5) + ")";
  479. }
  480. function number$1(scale) {
  481. return function(d) {
  482. return +scale(d);
  483. };
  484. }
  485. function center(scale) {
  486. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  487. if (scale.round()) offset = Math.round(offset);
  488. return function(d) {
  489. return +scale(d) + offset;
  490. };
  491. }
  492. function entering() {
  493. return !this.__axis;
  494. }
  495. function axis(orient, scale) {
  496. var tickArguments = [],
  497. tickValues = null,
  498. tickFormat = null,
  499. tickSizeInner = 6,
  500. tickSizeOuter = 6,
  501. tickPadding = 3,
  502. k = orient === top || orient === left ? -1 : 1,
  503. x = orient === left || orient === right ? "x" : "y",
  504. transform = orient === top || orient === bottom ? translateX : translateY;
  505. function axis(context) {
  506. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  507. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  508. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  509. range = scale.range(),
  510. range0 = +range[0] + 0.5,
  511. range1 = +range[range.length - 1] + 0.5,
  512. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  513. selection = context.selection ? context.selection() : context,
  514. path = selection.selectAll(".domain").data([null]),
  515. tick = selection.selectAll(".tick").data(values, scale).order(),
  516. tickExit = tick.exit(),
  517. tickEnter = tick.enter().append("g").attr("class", "tick"),
  518. line = tick.select("line"),
  519. text = tick.select("text");
  520. path = path.merge(path.enter().insert("path", ".tick")
  521. .attr("class", "domain")
  522. .attr("stroke", "#000"));
  523. tick = tick.merge(tickEnter);
  524. line = line.merge(tickEnter.append("line")
  525. .attr("stroke", "#000")
  526. .attr(x + "2", k * tickSizeInner));
  527. text = text.merge(tickEnter.append("text")
  528. .attr("fill", "#000")
  529. .attr(x, k * spacing)
  530. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  531. if (context !== selection) {
  532. path = path.transition(context);
  533. tick = tick.transition(context);
  534. line = line.transition(context);
  535. text = text.transition(context);
  536. tickExit = tickExit.transition(context)
  537. .attr("opacity", epsilon)
  538. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  539. tickEnter
  540. .attr("opacity", epsilon)
  541. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  542. }
  543. tickExit.remove();
  544. path
  545. .attr("d", orient === left || orient == right
  546. ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
  547. : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
  548. tick
  549. .attr("opacity", 1)
  550. .attr("transform", function(d) { return transform(position(d)); });
  551. line
  552. .attr(x + "2", k * tickSizeInner);
  553. text
  554. .attr(x, k * spacing)
  555. .text(format);
  556. selection.filter(entering)
  557. .attr("fill", "none")
  558. .attr("font-size", 10)
  559. .attr("font-family", "sans-serif")
  560. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  561. selection
  562. .each(function() { this.__axis = position; });
  563. }
  564. axis.scale = function(_) {
  565. return arguments.length ? (scale = _, axis) : scale;
  566. };
  567. axis.ticks = function() {
  568. return tickArguments = slice$1.call(arguments), axis;
  569. };
  570. axis.tickArguments = function(_) {
  571. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  572. };
  573. axis.tickValues = function(_) {
  574. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  575. };
  576. axis.tickFormat = function(_) {
  577. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  578. };
  579. axis.tickSize = function(_) {
  580. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  581. };
  582. axis.tickSizeInner = function(_) {
  583. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  584. };
  585. axis.tickSizeOuter = function(_) {
  586. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  587. };
  588. axis.tickPadding = function(_) {
  589. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  590. };
  591. return axis;
  592. }
  593. function axisTop(scale) {
  594. return axis(top, scale);
  595. }
  596. function axisRight(scale) {
  597. return axis(right, scale);
  598. }
  599. function axisBottom(scale) {
  600. return axis(bottom, scale);
  601. }
  602. function axisLeft(scale) {
  603. return axis(left, scale);
  604. }
  605. var noop = {value: function() {}};
  606. function dispatch() {
  607. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  608. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  609. _[t] = [];
  610. }
  611. return new Dispatch(_);
  612. }
  613. function Dispatch(_) {
  614. this._ = _;
  615. }
  616. function parseTypenames(typenames, types) {
  617. return typenames.trim().split(/^|\s+/).map(function(t) {
  618. var name = "", i = t.indexOf(".");
  619. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  620. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  621. return {type: t, name: name};
  622. });
  623. }
  624. Dispatch.prototype = dispatch.prototype = {
  625. constructor: Dispatch,
  626. on: function(typename, callback) {
  627. var _ = this._,
  628. T = parseTypenames(typename + "", _),
  629. t,
  630. i = -1,
  631. n = T.length;
  632. // If no callback was specified, return the callback of the given type and name.
  633. if (arguments.length < 2) {
  634. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  635. return;
  636. }
  637. // If a type was specified, set the callback for the given type and name.
  638. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  639. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  640. while (++i < n) {
  641. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  642. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  643. }
  644. return this;
  645. },
  646. copy: function() {
  647. var copy = {}, _ = this._;
  648. for (var t in _) copy[t] = _[t].slice();
  649. return new Dispatch(copy);
  650. },
  651. call: function(type, that) {
  652. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  653. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  654. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  655. },
  656. apply: function(type, that, args) {
  657. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  658. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  659. }
  660. };
  661. function get(type, name) {
  662. for (var i = 0, n = type.length, c; i < n; ++i) {
  663. if ((c = type[i]).name === name) {
  664. return c.value;
  665. }
  666. }
  667. }
  668. function set(type, name, callback) {
  669. for (var i = 0, n = type.length; i < n; ++i) {
  670. if (type[i].name === name) {
  671. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  672. break;
  673. }
  674. }
  675. if (callback != null) type.push({name: name, value: callback});
  676. return type;
  677. }
  678. var xhtml = "http://www.w3.org/1999/xhtml";
  679. var namespaces = {
  680. svg: "http://www.w3.org/2000/svg",
  681. xhtml: xhtml,
  682. xlink: "http://www.w3.org/1999/xlink",
  683. xml: "http://www.w3.org/XML/1998/namespace",
  684. xmlns: "http://www.w3.org/2000/xmlns/"
  685. };
  686. var namespace = function(name) {
  687. var prefix = name += "", i = prefix.indexOf(":");
  688. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  689. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  690. };
  691. function creatorInherit(name) {
  692. return function() {
  693. var document = this.ownerDocument,
  694. uri = this.namespaceURI;
  695. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  696. ? document.createElement(name)
  697. : document.createElementNS(uri, name);
  698. };
  699. }
  700. function creatorFixed(fullname) {
  701. return function() {
  702. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  703. };
  704. }
  705. var creator = function(name) {
  706. var fullname = namespace(name);
  707. return (fullname.local
  708. ? creatorFixed
  709. : creatorInherit)(fullname);
  710. };
  711. var nextId = 0;
  712. function local$1() {
  713. return new Local;
  714. }
  715. function Local() {
  716. this._ = "@" + (++nextId).toString(36);
  717. }
  718. Local.prototype = local$1.prototype = {
  719. constructor: Local,
  720. get: function(node) {
  721. var id = this._;
  722. while (!(id in node)) if (!(node = node.parentNode)) return;
  723. return node[id];
  724. },
  725. set: function(node, value) {
  726. return node[this._] = value;
  727. },
  728. remove: function(node) {
  729. return this._ in node && delete node[this._];
  730. },
  731. toString: function() {
  732. return this._;
  733. }
  734. };
  735. var matcher = function(selector) {
  736. return function() {
  737. return this.matches(selector);
  738. };
  739. };
  740. if (typeof document !== "undefined") {
  741. var element = document.documentElement;
  742. if (!element.matches) {
  743. var vendorMatches = element.webkitMatchesSelector
  744. || element.msMatchesSelector
  745. || element.mozMatchesSelector
  746. || element.oMatchesSelector;
  747. matcher = function(selector) {
  748. return function() {
  749. return vendorMatches.call(this, selector);
  750. };
  751. };
  752. }
  753. }
  754. var matcher$1 = matcher;
  755. var filterEvents = {};
  756. exports.event = null;
  757. if (typeof document !== "undefined") {
  758. var element$1 = document.documentElement;
  759. if (!("onmouseenter" in element$1)) {
  760. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  761. }
  762. }
  763. function filterContextListener(listener, index, group) {
  764. listener = contextListener(listener, index, group);
  765. return function(event) {
  766. var related = event.relatedTarget;
  767. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  768. listener.call(this, event);
  769. }
  770. };
  771. }
  772. function contextListener(listener, index, group) {
  773. return function(event1) {
  774. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  775. exports.event = event1;
  776. try {
  777. listener.call(this, this.__data__, index, group);
  778. } finally {
  779. exports.event = event0;
  780. }
  781. };
  782. }
  783. function parseTypenames$1(typenames) {
  784. return typenames.trim().split(/^|\s+/).map(function(t) {
  785. var name = "", i = t.indexOf(".");
  786. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  787. return {type: t, name: name};
  788. });
  789. }
  790. function onRemove(typename) {
  791. return function() {
  792. var on = this.__on;
  793. if (!on) return;
  794. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  795. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  796. this.removeEventListener(o.type, o.listener, o.capture);
  797. } else {
  798. on[++i] = o;
  799. }
  800. }
  801. if (++i) on.length = i;
  802. else delete this.__on;
  803. };
  804. }
  805. function onAdd(typename, value, capture) {
  806. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  807. return function(d, i, group) {
  808. var on = this.__on, o, listener = wrap(value, i, group);
  809. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  810. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  811. this.removeEventListener(o.type, o.listener, o.capture);
  812. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  813. o.value = value;
  814. return;
  815. }
  816. }
  817. this.addEventListener(typename.type, listener, capture);
  818. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  819. if (!on) this.__on = [o];
  820. else on.push(o);
  821. };
  822. }
  823. var selection_on = function(typename, value, capture) {
  824. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  825. if (arguments.length < 2) {
  826. var on = this.node().__on;
  827. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  828. for (i = 0, o = on[j]; i < n; ++i) {
  829. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  830. return o.value;
  831. }
  832. }
  833. }
  834. return;
  835. }
  836. on = value ? onAdd : onRemove;
  837. if (capture == null) capture = false;
  838. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  839. return this;
  840. };
  841. function customEvent(event1, listener, that, args) {
  842. var event0 = exports.event;
  843. event1.sourceEvent = exports.event;
  844. exports.event = event1;
  845. try {
  846. return listener.apply(that, args);
  847. } finally {
  848. exports.event = event0;
  849. }
  850. }
  851. var sourceEvent = function() {
  852. var current = exports.event, source;
  853. while (source = current.sourceEvent) current = source;
  854. return current;
  855. };
  856. var point = function(node, event) {
  857. var svg = node.ownerSVGElement || node;
  858. if (svg.createSVGPoint) {
  859. var point = svg.createSVGPoint();
  860. point.x = event.clientX, point.y = event.clientY;
  861. point = point.matrixTransform(node.getScreenCTM().inverse());
  862. return [point.x, point.y];
  863. }
  864. var rect = node.getBoundingClientRect();
  865. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  866. };
  867. var mouse = function(node) {
  868. var event = sourceEvent();
  869. if (event.changedTouches) event = event.changedTouches[0];
  870. return point(node, event);
  871. };
  872. function none() {}
  873. var selector = function(selector) {
  874. return selector == null ? none : function() {
  875. return this.querySelector(selector);
  876. };
  877. };
  878. var selection_select = function(select) {
  879. if (typeof select !== "function") select = selector(select);
  880. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  881. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  882. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  883. if ("__data__" in node) subnode.__data__ = node.__data__;
  884. subgroup[i] = subnode;
  885. }
  886. }
  887. }
  888. return new Selection(subgroups, this._parents);
  889. };
  890. function empty$1() {
  891. return [];
  892. }
  893. var selectorAll = function(selector) {
  894. return selector == null ? empty$1 : function() {
  895. return this.querySelectorAll(selector);
  896. };
  897. };
  898. var selection_selectAll = function(select) {
  899. if (typeof select !== "function") select = selectorAll(select);
  900. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  901. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  902. if (node = group[i]) {
  903. subgroups.push(select.call(node, node.__data__, i, group));
  904. parents.push(node);
  905. }
  906. }
  907. }
  908. return new Selection(subgroups, parents);
  909. };
  910. var selection_filter = function(match) {
  911. if (typeof match !== "function") match = matcher$1(match);
  912. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  913. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  914. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  915. subgroup.push(node);
  916. }
  917. }
  918. }
  919. return new Selection(subgroups, this._parents);
  920. };
  921. var sparse = function(update) {
  922. return new Array(update.length);
  923. };
  924. var selection_enter = function() {
  925. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  926. };
  927. function EnterNode(parent, datum) {
  928. this.ownerDocument = parent.ownerDocument;
  929. this.namespaceURI = parent.namespaceURI;
  930. this._next = null;
  931. this._parent = parent;
  932. this.__data__ = datum;
  933. }
  934. EnterNode.prototype = {
  935. constructor: EnterNode,
  936. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  937. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  938. querySelector: function(selector) { return this._parent.querySelector(selector); },
  939. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  940. };
  941. var constant$1 = function(x) {
  942. return function() {
  943. return x;
  944. };
  945. };
  946. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  947. function bindIndex(parent, group, enter, update, exit, data) {
  948. var i = 0,
  949. node,
  950. groupLength = group.length,
  951. dataLength = data.length;
  952. // Put any non-null nodes that fit into update.
  953. // Put any null nodes into enter.
  954. // Put any remaining data into enter.
  955. for (; i < dataLength; ++i) {
  956. if (node = group[i]) {
  957. node.__data__ = data[i];
  958. update[i] = node;
  959. } else {
  960. enter[i] = new EnterNode(parent, data[i]);
  961. }
  962. }
  963. // Put any non-null nodes that don’t fit into exit.
  964. for (; i < groupLength; ++i) {
  965. if (node = group[i]) {
  966. exit[i] = node;
  967. }
  968. }
  969. }
  970. function bindKey(parent, group, enter, update, exit, data, key) {
  971. var i,
  972. node,
  973. nodeByKeyValue = {},
  974. groupLength = group.length,
  975. dataLength = data.length,
  976. keyValues = new Array(groupLength),
  977. keyValue;
  978. // Compute the key for each node.
  979. // If multiple nodes have the same key, the duplicates are added to exit.
  980. for (i = 0; i < groupLength; ++i) {
  981. if (node = group[i]) {
  982. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  983. if (keyValue in nodeByKeyValue) {
  984. exit[i] = node;
  985. } else {
  986. nodeByKeyValue[keyValue] = node;
  987. }
  988. }
  989. }
  990. // Compute the key for each datum.
  991. // If there a node associated with this key, join and add it to update.
  992. // If there is not (or the key is a duplicate), add it to enter.
  993. for (i = 0; i < dataLength; ++i) {
  994. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  995. if (node = nodeByKeyValue[keyValue]) {
  996. update[i] = node;
  997. node.__data__ = data[i];
  998. nodeByKeyValue[keyValue] = null;
  999. } else {
  1000. enter[i] = new EnterNode(parent, data[i]);
  1001. }
  1002. }
  1003. // Add any remaining nodes that were not bound to data to exit.
  1004. for (i = 0; i < groupLength; ++i) {
  1005. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  1006. exit[i] = node;
  1007. }
  1008. }
  1009. }
  1010. var selection_data = function(value, key) {
  1011. if (!value) {
  1012. data = new Array(this.size()), j = -1;
  1013. this.each(function(d) { data[++j] = d; });
  1014. return data;
  1015. }
  1016. var bind = key ? bindKey : bindIndex,
  1017. parents = this._parents,
  1018. groups = this._groups;
  1019. if (typeof value !== "function") value = constant$1(value);
  1020. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  1021. var parent = parents[j],
  1022. group = groups[j],
  1023. groupLength = group.length,
  1024. data = value.call(parent, parent && parent.__data__, j, parents),
  1025. dataLength = data.length,
  1026. enterGroup = enter[j] = new Array(dataLength),
  1027. updateGroup = update[j] = new Array(dataLength),
  1028. exitGroup = exit[j] = new Array(groupLength);
  1029. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  1030. // Now connect the enter nodes to their following update node, such that
  1031. // appendChild can insert the materialized enter node before this node,
  1032. // rather than at the end of the parent node.
  1033. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  1034. if (previous = enterGroup[i0]) {
  1035. if (i0 >= i1) i1 = i0 + 1;
  1036. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  1037. previous._next = next || null;
  1038. }
  1039. }
  1040. }
  1041. update = new Selection(update, parents);
  1042. update._enter = enter;
  1043. update._exit = exit;
  1044. return update;
  1045. };
  1046. var selection_exit = function() {
  1047. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  1048. };
  1049. var selection_merge = function(selection$$1) {
  1050. for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  1051. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  1052. if (node = group0[i] || group1[i]) {
  1053. merge[i] = node;
  1054. }
  1055. }
  1056. }
  1057. for (; j < m0; ++j) {
  1058. merges[j] = groups0[j];
  1059. }
  1060. return new Selection(merges, this._parents);
  1061. };
  1062. var selection_order = function() {
  1063. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  1064. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  1065. if (node = group[i]) {
  1066. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  1067. next = node;
  1068. }
  1069. }
  1070. }
  1071. return this;
  1072. };
  1073. var selection_sort = function(compare) {
  1074. if (!compare) compare = ascending$1;
  1075. function compareNode(a, b) {
  1076. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  1077. }
  1078. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  1079. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  1080. if (node = group[i]) {
  1081. sortgroup[i] = node;
  1082. }
  1083. }
  1084. sortgroup.sort(compareNode);
  1085. }
  1086. return new Selection(sortgroups, this._parents).order();
  1087. };
  1088. function ascending$1(a, b) {
  1089. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  1090. }
  1091. var selection_call = function() {
  1092. var callback = arguments[0];
  1093. arguments[0] = this;
  1094. callback.apply(null, arguments);
  1095. return this;
  1096. };
  1097. var selection_nodes = function() {
  1098. var nodes = new Array(this.size()), i = -1;
  1099. this.each(function() { nodes[++i] = this; });
  1100. return nodes;
  1101. };
  1102. var selection_node = function() {
  1103. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1104. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  1105. var node = group[i];
  1106. if (node) return node;
  1107. }
  1108. }
  1109. return null;
  1110. };
  1111. var selection_size = function() {
  1112. var size = 0;
  1113. this.each(function() { ++size; });
  1114. return size;
  1115. };
  1116. var selection_empty = function() {
  1117. return !this.node();
  1118. };
  1119. var selection_each = function(callback) {
  1120. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1121. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  1122. if (node = group[i]) callback.call(node, node.__data__, i, group);
  1123. }
  1124. }
  1125. return this;
  1126. };
  1127. function attrRemove(name) {
  1128. return function() {
  1129. this.removeAttribute(name);
  1130. };
  1131. }
  1132. function attrRemoveNS(fullname) {
  1133. return function() {
  1134. this.removeAttributeNS(fullname.space, fullname.local);
  1135. };
  1136. }
  1137. function attrConstant(name, value) {
  1138. return function() {
  1139. this.setAttribute(name, value);
  1140. };
  1141. }
  1142. function attrConstantNS(fullname, value) {
  1143. return function() {
  1144. this.setAttributeNS(fullname.space, fullname.local, value);
  1145. };
  1146. }
  1147. function attrFunction(name, value) {
  1148. return function() {
  1149. var v = value.apply(this, arguments);
  1150. if (v == null) this.removeAttribute(name);
  1151. else this.setAttribute(name, v);
  1152. };
  1153. }
  1154. function attrFunctionNS(fullname, value) {
  1155. return function() {
  1156. var v = value.apply(this, arguments);
  1157. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1158. else this.setAttributeNS(fullname.space, fullname.local, v);
  1159. };
  1160. }
  1161. var selection_attr = function(name, value) {
  1162. var fullname = namespace(name);
  1163. if (arguments.length < 2) {
  1164. var node = this.node();
  1165. return fullname.local
  1166. ? node.getAttributeNS(fullname.space, fullname.local)
  1167. : node.getAttribute(fullname);
  1168. }
  1169. return this.each((value == null
  1170. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1171. ? (fullname.local ? attrFunctionNS : attrFunction)
  1172. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1173. };
  1174. var defaultView = function(node) {
  1175. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1176. || (node.document && node) // node is a Window
  1177. || node.defaultView; // node is a Document
  1178. };
  1179. function styleRemove(name) {
  1180. return function() {
  1181. this.style.removeProperty(name);
  1182. };
  1183. }
  1184. function styleConstant(name, value, priority) {
  1185. return function() {
  1186. this.style.setProperty(name, value, priority);
  1187. };
  1188. }
  1189. function styleFunction(name, value, priority) {
  1190. return function() {
  1191. var v = value.apply(this, arguments);
  1192. if (v == null) this.style.removeProperty(name);
  1193. else this.style.setProperty(name, v, priority);
  1194. };
  1195. }
  1196. var selection_style = function(name, value, priority) {
  1197. return arguments.length > 1
  1198. ? this.each((value == null
  1199. ? styleRemove : typeof value === "function"
  1200. ? styleFunction
  1201. : styleConstant)(name, value, priority == null ? "" : priority))
  1202. : styleValue(this.node(), name);
  1203. };
  1204. function styleValue(node, name) {
  1205. return node.style.getPropertyValue(name)
  1206. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1207. }
  1208. function propertyRemove(name) {
  1209. return function() {
  1210. delete this[name];
  1211. };
  1212. }
  1213. function propertyConstant(name, value) {
  1214. return function() {
  1215. this[name] = value;
  1216. };
  1217. }
  1218. function propertyFunction(name, value) {
  1219. return function() {
  1220. var v = value.apply(this, arguments);
  1221. if (v == null) delete this[name];
  1222. else this[name] = v;
  1223. };
  1224. }
  1225. var selection_property = function(name, value) {
  1226. return arguments.length > 1
  1227. ? this.each((value == null
  1228. ? propertyRemove : typeof value === "function"
  1229. ? propertyFunction
  1230. : propertyConstant)(name, value))
  1231. : this.node()[name];
  1232. };
  1233. function classArray(string) {
  1234. return string.trim().split(/^|\s+/);
  1235. }
  1236. function classList(node) {
  1237. return node.classList || new ClassList(node);
  1238. }
  1239. function ClassList(node) {
  1240. this._node = node;
  1241. this._names = classArray(node.getAttribute("class") || "");
  1242. }
  1243. ClassList.prototype = {
  1244. add: function(name) {
  1245. var i = this._names.indexOf(name);
  1246. if (i < 0) {
  1247. this._names.push(name);
  1248. this._node.setAttribute("class", this._names.join(" "));
  1249. }
  1250. },
  1251. remove: function(name) {
  1252. var i = this._names.indexOf(name);
  1253. if (i >= 0) {
  1254. this._names.splice(i, 1);
  1255. this._node.setAttribute("class", this._names.join(" "));
  1256. }
  1257. },
  1258. contains: function(name) {
  1259. return this._names.indexOf(name) >= 0;
  1260. }
  1261. };
  1262. function classedAdd(node, names) {
  1263. var list = classList(node), i = -1, n = names.length;
  1264. while (++i < n) list.add(names[i]);
  1265. }
  1266. function classedRemove(node, names) {
  1267. var list = classList(node), i = -1, n = names.length;
  1268. while (++i < n) list.remove(names[i]);
  1269. }
  1270. function classedTrue(names) {
  1271. return function() {
  1272. classedAdd(this, names);
  1273. };
  1274. }
  1275. function classedFalse(names) {
  1276. return function() {
  1277. classedRemove(this, names);
  1278. };
  1279. }
  1280. function classedFunction(names, value) {
  1281. return function() {
  1282. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1283. };
  1284. }
  1285. var selection_classed = function(name, value) {
  1286. var names = classArray(name + "");
  1287. if (arguments.length < 2) {
  1288. var list = classList(this.node()), i = -1, n = names.length;
  1289. while (++i < n) if (!list.contains(names[i])) return false;
  1290. return true;
  1291. }
  1292. return this.each((typeof value === "function"
  1293. ? classedFunction : value
  1294. ? classedTrue
  1295. : classedFalse)(names, value));
  1296. };
  1297. function textRemove() {
  1298. this.textContent = "";
  1299. }
  1300. function textConstant(value) {
  1301. return function() {
  1302. this.textContent = value;
  1303. };
  1304. }
  1305. function textFunction(value) {
  1306. return function() {
  1307. var v = value.apply(this, arguments);
  1308. this.textContent = v == null ? "" : v;
  1309. };
  1310. }
  1311. var selection_text = function(value) {
  1312. return arguments.length
  1313. ? this.each(value == null
  1314. ? textRemove : (typeof value === "function"
  1315. ? textFunction
  1316. : textConstant)(value))
  1317. : this.node().textContent;
  1318. };
  1319. function htmlRemove() {
  1320. this.innerHTML = "";
  1321. }
  1322. function htmlConstant(value) {
  1323. return function() {
  1324. this.innerHTML = value;
  1325. };
  1326. }
  1327. function htmlFunction(value) {
  1328. return function() {
  1329. var v = value.apply(this, arguments);
  1330. this.innerHTML = v == null ? "" : v;
  1331. };
  1332. }
  1333. var selection_html = function(value) {
  1334. return arguments.length
  1335. ? this.each(value == null
  1336. ? htmlRemove : (typeof value === "function"
  1337. ? htmlFunction
  1338. : htmlConstant)(value))
  1339. : this.node().innerHTML;
  1340. };
  1341. function raise() {
  1342. if (this.nextSibling) this.parentNode.appendChild(this);
  1343. }
  1344. var selection_raise = function() {
  1345. return this.each(raise);
  1346. };
  1347. function lower() {
  1348. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1349. }
  1350. var selection_lower = function() {
  1351. return this.each(lower);
  1352. };
  1353. var selection_append = function(name) {
  1354. var create = typeof name === "function" ? name : creator(name);
  1355. return this.select(function() {
  1356. return this.appendChild(create.apply(this, arguments));
  1357. });
  1358. };
  1359. function constantNull() {
  1360. return null;
  1361. }
  1362. var selection_insert = function(name, before) {
  1363. var create = typeof name === "function" ? name : creator(name),
  1364. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1365. return this.select(function() {
  1366. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1367. });
  1368. };
  1369. function remove() {
  1370. var parent = this.parentNode;
  1371. if (parent) parent.removeChild(this);
  1372. }
  1373. var selection_remove = function() {
  1374. return this.each(remove);
  1375. };
  1376. var selection_datum = function(value) {
  1377. return arguments.length
  1378. ? this.property("__data__", value)
  1379. : this.node().__data__;
  1380. };
  1381. function dispatchEvent(node, type, params) {
  1382. var window = defaultView(node),
  1383. event = window.CustomEvent;
  1384. if (typeof event === "function") {
  1385. event = new event(type, params);
  1386. } else {
  1387. event = window.document.createEvent("Event");
  1388. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1389. else event.initEvent(type, false, false);
  1390. }
  1391. node.dispatchEvent(event);
  1392. }
  1393. function dispatchConstant(type, params) {
  1394. return function() {
  1395. return dispatchEvent(this, type, params);
  1396. };
  1397. }
  1398. function dispatchFunction(type, params) {
  1399. return function() {
  1400. return dispatchEvent(this, type, params.apply(this, arguments));
  1401. };
  1402. }
  1403. var selection_dispatch = function(type, params) {
  1404. return this.each((typeof params === "function"
  1405. ? dispatchFunction
  1406. : dispatchConstant)(type, params));
  1407. };
  1408. var root = [null];
  1409. function Selection(groups, parents) {
  1410. this._groups = groups;
  1411. this._parents = parents;
  1412. }
  1413. function selection() {
  1414. return new Selection([[document.documentElement]], root);
  1415. }
  1416. Selection.prototype = selection.prototype = {
  1417. constructor: Selection,
  1418. select: selection_select,
  1419. selectAll: selection_selectAll,
  1420. filter: selection_filter,
  1421. data: selection_data,
  1422. enter: selection_enter,
  1423. exit: selection_exit,
  1424. merge: selection_merge,
  1425. order: selection_order,
  1426. sort: selection_sort,
  1427. call: selection_call,
  1428. nodes: selection_nodes,
  1429. node: selection_node,
  1430. size: selection_size,
  1431. empty: selection_empty,
  1432. each: selection_each,
  1433. attr: selection_attr,
  1434. style: selection_style,
  1435. property: selection_property,
  1436. classed: selection_classed,
  1437. text: selection_text,
  1438. html: selection_html,
  1439. raise: selection_raise,
  1440. lower: selection_lower,
  1441. append: selection_append,
  1442. insert: selection_insert,
  1443. remove: selection_remove,
  1444. datum: selection_datum,
  1445. on: selection_on,
  1446. dispatch: selection_dispatch
  1447. };
  1448. var select = function(selector) {
  1449. return typeof selector === "string"
  1450. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1451. : new Selection([[selector]], root);
  1452. };
  1453. var selectAll = function(selector) {
  1454. return typeof selector === "string"
  1455. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1456. : new Selection([selector == null ? [] : selector], root);
  1457. };
  1458. var touch = function(node, touches, identifier) {
  1459. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1460. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1461. if ((touch = touches[i]).identifier === identifier) {
  1462. return point(node, touch);
  1463. }
  1464. }
  1465. return null;
  1466. };
  1467. var touches = function(node, touches) {
  1468. if (touches == null) touches = sourceEvent().touches;
  1469. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1470. points[i] = point(node, touches[i]);
  1471. }
  1472. return points;
  1473. };
  1474. function nopropagation() {
  1475. exports.event.stopImmediatePropagation();
  1476. }
  1477. var noevent = function() {
  1478. exports.event.preventDefault();
  1479. exports.event.stopImmediatePropagation();
  1480. };
  1481. var dragDisable = function(view) {
  1482. var root = view.document.documentElement,
  1483. selection = select(view).on("dragstart.drag", noevent, true);
  1484. if ("onselectstart" in root) {
  1485. selection.on("selectstart.drag", noevent, true);
  1486. } else {
  1487. root.__noselect = root.style.MozUserSelect;
  1488. root.style.MozUserSelect = "none";
  1489. }
  1490. };
  1491. function yesdrag(view, noclick) {
  1492. var root = view.document.documentElement,
  1493. selection = select(view).on("dragstart.drag", null);
  1494. if (noclick) {
  1495. selection.on("click.drag", noevent, true);
  1496. setTimeout(function() { selection.on("click.drag", null); }, 0);
  1497. }
  1498. if ("onselectstart" in root) {
  1499. selection.on("selectstart.drag", null);
  1500. } else {
  1501. root.style.MozUserSelect = root.__noselect;
  1502. delete root.__noselect;
  1503. }
  1504. }
  1505. var constant$2 = function(x) {
  1506. return function() {
  1507. return x;
  1508. };
  1509. };
  1510. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1511. this.target = target;
  1512. this.type = type;
  1513. this.subject = subject;
  1514. this.identifier = id;
  1515. this.active = active;
  1516. this.x = x;
  1517. this.y = y;
  1518. this.dx = dx;
  1519. this.dy = dy;
  1520. this._ = dispatch;
  1521. }
  1522. DragEvent.prototype.on = function() {
  1523. var value = this._.on.apply(this._, arguments);
  1524. return value === this._ ? this : value;
  1525. };
  1526. // Ignore right-click, since that should open the context menu.
  1527. function defaultFilter$1() {
  1528. return !exports.event.button;
  1529. }
  1530. function defaultContainer() {
  1531. return this.parentNode;
  1532. }
  1533. function defaultSubject(d) {
  1534. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1535. }
  1536. function touchable() {
  1537. return "ontouchstart" in this;
  1538. }
  1539. var drag = function() {
  1540. var filter = defaultFilter$1,
  1541. container = defaultContainer,
  1542. subject = defaultSubject,
  1543. gestures = {},
  1544. listeners = dispatch("start", "drag", "end"),
  1545. active = 0,
  1546. mousedownx,
  1547. mousedowny,
  1548. mousemoving,
  1549. touchending,
  1550. clickDistance2 = 0;
  1551. function drag(selection) {
  1552. selection
  1553. .on("mousedown.drag", mousedowned)
  1554. .filter(touchable)
  1555. .on("touchstart.drag", touchstarted)
  1556. .on("touchmove.drag", touchmoved)
  1557. .on("touchend.drag touchcancel.drag", touchended)
  1558. .style("touch-action", "none")
  1559. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1560. }
  1561. function mousedowned() {
  1562. if (touchending || !filter.apply(this, arguments)) return;
  1563. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1564. if (!gesture) return;
  1565. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1566. dragDisable(exports.event.view);
  1567. nopropagation();
  1568. mousemoving = false;
  1569. mousedownx = exports.event.clientX;
  1570. mousedowny = exports.event.clientY;
  1571. gesture("start");
  1572. }
  1573. function mousemoved() {
  1574. noevent();
  1575. if (!mousemoving) {
  1576. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1577. mousemoving = dx * dx + dy * dy > clickDistance2;
  1578. }
  1579. gestures.mouse("drag");
  1580. }
  1581. function mouseupped() {
  1582. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1583. yesdrag(exports.event.view, mousemoving);
  1584. noevent();
  1585. gestures.mouse("end");
  1586. }
  1587. function touchstarted() {
  1588. if (!filter.apply(this, arguments)) return;
  1589. var touches = exports.event.changedTouches,
  1590. c = container.apply(this, arguments),
  1591. n = touches.length, i, gesture;
  1592. for (i = 0; i < n; ++i) {
  1593. if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
  1594. nopropagation();
  1595. gesture("start");
  1596. }
  1597. }
  1598. }
  1599. function touchmoved() {
  1600. var touches = exports.event.changedTouches,
  1601. n = touches.length, i, gesture;
  1602. for (i = 0; i < n; ++i) {
  1603. if (gesture = gestures[touches[i].identifier]) {
  1604. noevent();
  1605. gesture("drag");
  1606. }
  1607. }
  1608. }
  1609. function touchended() {
  1610. var touches = exports.event.changedTouches,
  1611. n = touches.length, i, gesture;
  1612. if (touchending) clearTimeout(touchending);
  1613. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1614. for (i = 0; i < n; ++i) {
  1615. if (gesture = gestures[touches[i].identifier]) {
  1616. nopropagation();
  1617. gesture("end");
  1618. }
  1619. }
  1620. }
  1621. function beforestart(id, container, point, that, args) {
  1622. var p = point(container, id), s, dx, dy,
  1623. sublisteners = listeners.copy();
  1624. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1625. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1626. dx = s.x - p[0] || 0;
  1627. dy = s.y - p[1] || 0;
  1628. return true;
  1629. })) return;
  1630. return function gesture(type) {
  1631. var p0 = p, n;
  1632. switch (type) {
  1633. case "start": gestures[id] = gesture, n = active++; break;
  1634. case "end": delete gestures[id], --active; // nobreak
  1635. case "drag": p = point(container, id), n = active; break;
  1636. }
  1637. customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
  1638. };
  1639. }
  1640. drag.filter = function(_) {
  1641. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1642. };
  1643. drag.container = function(_) {
  1644. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1645. };
  1646. drag.subject = function(_) {
  1647. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1648. };
  1649. drag.on = function() {
  1650. var value = listeners.on.apply(listeners, arguments);
  1651. return value === listeners ? drag : value;
  1652. };
  1653. drag.clickDistance = function(_) {
  1654. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1655. };
  1656. return drag;
  1657. };
  1658. var define = function(constructor, factory, prototype) {
  1659. constructor.prototype = factory.prototype = prototype;
  1660. prototype.constructor = constructor;
  1661. };
  1662. function extend(parent, definition) {
  1663. var prototype = Object.create(parent.prototype);
  1664. for (var key in definition) prototype[key] = definition[key];
  1665. return prototype;
  1666. }
  1667. function Color() {}
  1668. var darker = 0.7;
  1669. var brighter = 1 / darker;
  1670. var reI = "\\s*([+-]?\\d+)\\s*";
  1671. var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
  1672. var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
  1673. var reHex3 = /^#([0-9a-f]{3})$/;
  1674. var reHex6 = /^#([0-9a-f]{6})$/;
  1675. var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
  1676. var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
  1677. var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
  1678. var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
  1679. var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
  1680. var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1681. var named = {
  1682. aliceblue: 0xf0f8ff,
  1683. antiquewhite: 0xfaebd7,
  1684. aqua: 0x00ffff,
  1685. aquamarine: 0x7fffd4,
  1686. azure: 0xf0ffff,
  1687. beige: 0xf5f5dc,
  1688. bisque: 0xffe4c4,
  1689. black: 0x000000,
  1690. blanchedalmond: 0xffebcd,
  1691. blue: 0x0000ff,
  1692. blueviolet: 0x8a2be2,
  1693. brown: 0xa52a2a,
  1694. burlywood: 0xdeb887,
  1695. cadetblue: 0x5f9ea0,
  1696. chartreuse: 0x7fff00,
  1697. chocolate: 0xd2691e,
  1698. coral: 0xff7f50,
  1699. cornflowerblue: 0x6495ed,
  1700. cornsilk: 0xfff8dc,
  1701. crimson: 0xdc143c,
  1702. cyan: 0x00ffff,
  1703. darkblue: 0x00008b,
  1704. darkcyan: 0x008b8b,
  1705. darkgoldenrod: 0xb8860b,
  1706. darkgray: 0xa9a9a9,
  1707. darkgreen: 0x006400,
  1708. darkgrey: 0xa9a9a9,
  1709. darkkhaki: 0xbdb76b,
  1710. darkmagenta: 0x8b008b,
  1711. darkolivegreen: 0x556b2f,
  1712. darkorange: 0xff8c00,
  1713. darkorchid: 0x9932cc,
  1714. darkred: 0x8b0000,
  1715. darksalmon: 0xe9967a,
  1716. darkseagreen: 0x8fbc8f,
  1717. darkslateblue: 0x483d8b,
  1718. darkslategray: 0x2f4f4f,
  1719. darkslategrey: 0x2f4f4f,
  1720. darkturquoise: 0x00ced1,
  1721. darkviolet: 0x9400d3,
  1722. deeppink: 0xff1493,
  1723. deepskyblue: 0x00bfff,
  1724. dimgray: 0x696969,
  1725. dimgrey: 0x696969,
  1726. dodgerblue: 0x1e90ff,
  1727. firebrick: 0xb22222,
  1728. floralwhite: 0xfffaf0,
  1729. forestgreen: 0x228b22,
  1730. fuchsia: 0xff00ff,
  1731. gainsboro: 0xdcdcdc,
  1732. ghostwhite: 0xf8f8ff,
  1733. gold: 0xffd700,
  1734. goldenrod: 0xdaa520,
  1735. gray: 0x808080,
  1736. green: 0x008000,
  1737. greenyellow: 0xadff2f,
  1738. grey: 0x808080,
  1739. honeydew: 0xf0fff0,
  1740. hotpink: 0xff69b4,
  1741. indianred: 0xcd5c5c,
  1742. indigo: 0x4b0082,
  1743. ivory: 0xfffff0,
  1744. khaki: 0xf0e68c,
  1745. lavender: 0xe6e6fa,
  1746. lavenderblush: 0xfff0f5,
  1747. lawngreen: 0x7cfc00,
  1748. lemonchiffon: 0xfffacd,
  1749. lightblue: 0xadd8e6,
  1750. lightcoral: 0xf08080,
  1751. lightcyan: 0xe0ffff,
  1752. lightgoldenrodyellow: 0xfafad2,
  1753. lightgray: 0xd3d3d3,
  1754. lightgreen: 0x90ee90,
  1755. lightgrey: 0xd3d3d3,
  1756. lightpink: 0xffb6c1,
  1757. lightsalmon: 0xffa07a,
  1758. lightseagreen: 0x20b2aa,
  1759. lightskyblue: 0x87cefa,
  1760. lightslategray: 0x778899,
  1761. lightslategrey: 0x778899,
  1762. lightsteelblue: 0xb0c4de,
  1763. lightyellow: 0xffffe0,
  1764. lime: 0x00ff00,
  1765. limegreen: 0x32cd32,
  1766. linen: 0xfaf0e6,
  1767. magenta: 0xff00ff,
  1768. maroon: 0x800000,
  1769. mediumaquamarine: 0x66cdaa,
  1770. mediumblue: 0x0000cd,
  1771. mediumorchid: 0xba55d3,
  1772. mediumpurple: 0x9370db,
  1773. mediumseagreen: 0x3cb371,
  1774. mediumslateblue: 0x7b68ee,
  1775. mediumspringgreen: 0x00fa9a,
  1776. mediumturquoise: 0x48d1cc,
  1777. mediumvioletred: 0xc71585,
  1778. midnightblue: 0x191970,
  1779. mintcream: 0xf5fffa,
  1780. mistyrose: 0xffe4e1,
  1781. moccasin: 0xffe4b5,
  1782. navajowhite: 0xffdead,
  1783. navy: 0x000080,
  1784. oldlace: 0xfdf5e6,
  1785. olive: 0x808000,
  1786. olivedrab: 0x6b8e23,
  1787. orange: 0xffa500,
  1788. orangered: 0xff4500,
  1789. orchid: 0xda70d6,
  1790. palegoldenrod: 0xeee8aa,
  1791. palegreen: 0x98fb98,
  1792. paleturquoise: 0xafeeee,
  1793. palevioletred: 0xdb7093,
  1794. papayawhip: 0xffefd5,
  1795. peachpuff: 0xffdab9,
  1796. peru: 0xcd853f,
  1797. pink: 0xffc0cb,
  1798. plum: 0xdda0dd,
  1799. powderblue: 0xb0e0e6,
  1800. purple: 0x800080,
  1801. rebeccapurple: 0x663399,
  1802. red: 0xff0000,
  1803. rosybrown: 0xbc8f8f,
  1804. royalblue: 0x4169e1,
  1805. saddlebrown: 0x8b4513,
  1806. salmon: 0xfa8072,
  1807. sandybrown: 0xf4a460,
  1808. seagreen: 0x2e8b57,
  1809. seashell: 0xfff5ee,
  1810. sienna: 0xa0522d,
  1811. silver: 0xc0c0c0,
  1812. skyblue: 0x87ceeb,
  1813. slateblue: 0x6a5acd,
  1814. slategray: 0x708090,
  1815. slategrey: 0x708090,
  1816. snow: 0xfffafa,
  1817. springgreen: 0x00ff7f,
  1818. steelblue: 0x4682b4,
  1819. tan: 0xd2b48c,
  1820. teal: 0x008080,
  1821. thistle: 0xd8bfd8,
  1822. tomato: 0xff6347,
  1823. turquoise: 0x40e0d0,
  1824. violet: 0xee82ee,
  1825. wheat: 0xf5deb3,
  1826. white: 0xffffff,
  1827. whitesmoke: 0xf5f5f5,
  1828. yellow: 0xffff00,
  1829. yellowgreen: 0x9acd32
  1830. };
  1831. define(Color, color, {
  1832. displayable: function() {
  1833. return this.rgb().displayable();
  1834. },
  1835. toString: function() {
  1836. return this.rgb() + "";
  1837. }
  1838. });
  1839. function color(format) {
  1840. var m;
  1841. format = (format + "").trim().toLowerCase();
  1842. return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
  1843. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  1844. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1845. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1846. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1847. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1848. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1849. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1850. : named.hasOwnProperty(format) ? rgbn(named[format])
  1851. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1852. : null;
  1853. }
  1854. function rgbn(n) {
  1855. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1856. }
  1857. function rgba(r, g, b, a) {
  1858. if (a <= 0) r = g = b = NaN;
  1859. return new Rgb(r, g, b, a);
  1860. }
  1861. function rgbConvert(o) {
  1862. if (!(o instanceof Color)) o = color(o);
  1863. if (!o) return new Rgb;
  1864. o = o.rgb();
  1865. return new Rgb(o.r, o.g, o.b, o.opacity);
  1866. }
  1867. function rgb(r, g, b, opacity) {
  1868. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1869. }
  1870. function Rgb(r, g, b, opacity) {
  1871. this.r = +r;
  1872. this.g = +g;
  1873. this.b = +b;
  1874. this.opacity = +opacity;
  1875. }
  1876. define(Rgb, rgb, extend(Color, {
  1877. brighter: function(k) {
  1878. k = k == null ? brighter : Math.pow(brighter, k);
  1879. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1880. },
  1881. darker: function(k) {
  1882. k = k == null ? darker : Math.pow(darker, k);
  1883. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1884. },
  1885. rgb: function() {
  1886. return this;
  1887. },
  1888. displayable: function() {
  1889. return (0 <= this.r && this.r <= 255)
  1890. && (0 <= this.g && this.g <= 255)
  1891. && (0 <= this.b && this.b <= 255)
  1892. && (0 <= this.opacity && this.opacity <= 1);
  1893. },
  1894. toString: function() {
  1895. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1896. return (a === 1 ? "rgb(" : "rgba(")
  1897. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1898. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1899. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1900. + (a === 1 ? ")" : ", " + a + ")");
  1901. }
  1902. }));
  1903. function hsla(h, s, l, a) {
  1904. if (a <= 0) h = s = l = NaN;
  1905. else if (l <= 0 || l >= 1) h = s = NaN;
  1906. else if (s <= 0) h = NaN;
  1907. return new Hsl(h, s, l, a);
  1908. }
  1909. function hslConvert(o) {
  1910. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1911. if (!(o instanceof Color)) o = color(o);
  1912. if (!o) return new Hsl;
  1913. if (o instanceof Hsl) return o;
  1914. o = o.rgb();
  1915. var r = o.r / 255,
  1916. g = o.g / 255,
  1917. b = o.b / 255,
  1918. min = Math.min(r, g, b),
  1919. max = Math.max(r, g, b),
  1920. h = NaN,
  1921. s = max - min,
  1922. l = (max + min) / 2;
  1923. if (s) {
  1924. if (r === max) h = (g - b) / s + (g < b) * 6;
  1925. else if (g === max) h = (b - r) / s + 2;
  1926. else h = (r - g) / s + 4;
  1927. s /= l < 0.5 ? max + min : 2 - max - min;
  1928. h *= 60;
  1929. } else {
  1930. s = l > 0 && l < 1 ? 0 : h;
  1931. }
  1932. return new Hsl(h, s, l, o.opacity);
  1933. }
  1934. function hsl(h, s, l, opacity) {
  1935. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1936. }
  1937. function Hsl(h, s, l, opacity) {
  1938. this.h = +h;
  1939. this.s = +s;
  1940. this.l = +l;
  1941. this.opacity = +opacity;
  1942. }
  1943. define(Hsl, hsl, extend(Color, {
  1944. brighter: function(k) {
  1945. k = k == null ? brighter : Math.pow(brighter, k);
  1946. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1947. },
  1948. darker: function(k) {
  1949. k = k == null ? darker : Math.pow(darker, k);
  1950. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1951. },
  1952. rgb: function() {
  1953. var h = this.h % 360 + (this.h < 0) * 360,
  1954. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1955. l = this.l,
  1956. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1957. m1 = 2 * l - m2;
  1958. return new Rgb(
  1959. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  1960. hsl2rgb(h, m1, m2),
  1961. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  1962. this.opacity
  1963. );
  1964. },
  1965. displayable: function() {
  1966. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  1967. && (0 <= this.l && this.l <= 1)
  1968. && (0 <= this.opacity && this.opacity <= 1);
  1969. }
  1970. }));
  1971. /* From FvD 13.37, CSS Color Module Level 3 */
  1972. function hsl2rgb(h, m1, m2) {
  1973. return (h < 60 ? m1 + (m2 - m1) * h / 60
  1974. : h < 180 ? m2
  1975. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  1976. : m1) * 255;
  1977. }
  1978. var deg2rad = Math.PI / 180;
  1979. var rad2deg = 180 / Math.PI;
  1980. var Kn = 18;
  1981. var Xn = 0.950470;
  1982. var Yn = 1;
  1983. var Zn = 1.088830;
  1984. var t0 = 4 / 29;
  1985. var t1 = 6 / 29;
  1986. var t2 = 3 * t1 * t1;
  1987. var t3 = t1 * t1 * t1;
  1988. function labConvert(o) {
  1989. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  1990. if (o instanceof Hcl) {
  1991. var h = o.h * deg2rad;
  1992. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  1993. }
  1994. if (!(o instanceof Rgb)) o = rgbConvert(o);
  1995. var b = rgb2xyz(o.r),
  1996. a = rgb2xyz(o.g),
  1997. l = rgb2xyz(o.b),
  1998. x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
  1999. y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
  2000. z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
  2001. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2002. }
  2003. function lab(l, a, b, opacity) {
  2004. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2005. }
  2006. function Lab(l, a, b, opacity) {
  2007. this.l = +l;
  2008. this.a = +a;
  2009. this.b = +b;
  2010. this.opacity = +opacity;
  2011. }
  2012. define(Lab, lab, extend(Color, {
  2013. brighter: function(k) {
  2014. return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2015. },
  2016. darker: function(k) {
  2017. return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2018. },
  2019. rgb: function() {
  2020. var y = (this.l + 16) / 116,
  2021. x = isNaN(this.a) ? y : y + this.a / 500,
  2022. z = isNaN(this.b) ? y : y - this.b / 200;
  2023. y = Yn * lab2xyz(y);
  2024. x = Xn * lab2xyz(x);
  2025. z = Zn * lab2xyz(z);
  2026. return new Rgb(
  2027. xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
  2028. xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
  2029. xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
  2030. this.opacity
  2031. );
  2032. }
  2033. }));
  2034. function xyz2lab(t) {
  2035. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2036. }
  2037. function lab2xyz(t) {
  2038. return t > t1 ? t * t * t : t2 * (t - t0);
  2039. }
  2040. function xyz2rgb(x) {
  2041. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2042. }
  2043. function rgb2xyz(x) {
  2044. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2045. }
  2046. function hclConvert(o) {
  2047. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2048. if (!(o instanceof Lab)) o = labConvert(o);
  2049. var h = Math.atan2(o.b, o.a) * rad2deg;
  2050. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2051. }
  2052. function hcl(h, c, l, opacity) {
  2053. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2054. }
  2055. function Hcl(h, c, l, opacity) {
  2056. this.h = +h;
  2057. this.c = +c;
  2058. this.l = +l;
  2059. this.opacity = +opacity;
  2060. }
  2061. define(Hcl, hcl, extend(Color, {
  2062. brighter: function(k) {
  2063. return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
  2064. },
  2065. darker: function(k) {
  2066. return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
  2067. },
  2068. rgb: function() {
  2069. return labConvert(this).rgb();
  2070. }
  2071. }));
  2072. var A = -0.14861;
  2073. var B = +1.78277;
  2074. var C = -0.29227;
  2075. var D = -0.90649;
  2076. var E = +1.97294;
  2077. var ED = E * D;
  2078. var EB = E * B;
  2079. var BC_DA = B * C - D * A;
  2080. function cubehelixConvert(o) {
  2081. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2082. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2083. var r = o.r / 255,
  2084. g = o.g / 255,
  2085. b = o.b / 255,
  2086. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2087. bl = b - l,
  2088. k = (E * (g - l) - C * bl) / D,
  2089. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2090. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2091. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2092. }
  2093. function cubehelix(h, s, l, opacity) {
  2094. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2095. }
  2096. function Cubehelix(h, s, l, opacity) {
  2097. this.h = +h;
  2098. this.s = +s;
  2099. this.l = +l;
  2100. this.opacity = +opacity;
  2101. }
  2102. define(Cubehelix, cubehelix, extend(Color, {
  2103. brighter: function(k) {
  2104. k = k == null ? brighter : Math.pow(brighter, k);
  2105. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2106. },
  2107. darker: function(k) {
  2108. k = k == null ? darker : Math.pow(darker, k);
  2109. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2110. },
  2111. rgb: function() {
  2112. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2113. l = +this.l,
  2114. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2115. cosh = Math.cos(h),
  2116. sinh = Math.sin(h);
  2117. return new Rgb(
  2118. 255 * (l + a * (A * cosh + B * sinh)),
  2119. 255 * (l + a * (C * cosh + D * sinh)),
  2120. 255 * (l + a * (E * cosh)),
  2121. this.opacity
  2122. );
  2123. }
  2124. }));
  2125. function basis(t1, v0, v1, v2, v3) {
  2126. var t2 = t1 * t1, t3 = t2 * t1;
  2127. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2128. + (4 - 6 * t2 + 3 * t3) * v1
  2129. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2130. + t3 * v3) / 6;
  2131. }
  2132. var basis$1 = function(values) {
  2133. var n = values.length - 1;
  2134. return function(t) {
  2135. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2136. v1 = values[i],
  2137. v2 = values[i + 1],
  2138. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2139. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2140. return basis((t - i / n) * n, v0, v1, v2, v3);
  2141. };
  2142. };
  2143. var basisClosed = function(values) {
  2144. var n = values.length;
  2145. return function(t) {
  2146. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2147. v0 = values[(i + n - 1) % n],
  2148. v1 = values[i % n],
  2149. v2 = values[(i + 1) % n],
  2150. v3 = values[(i + 2) % n];
  2151. return basis((t - i / n) * n, v0, v1, v2, v3);
  2152. };
  2153. };
  2154. var constant$3 = function(x) {
  2155. return function() {
  2156. return x;
  2157. };
  2158. };
  2159. function linear(a, d) {
  2160. return function(t) {
  2161. return a + t * d;
  2162. };
  2163. }
  2164. function exponential(a, b, y) {
  2165. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2166. return Math.pow(a + t * b, y);
  2167. };
  2168. }
  2169. function hue(a, b) {
  2170. var d = b - a;
  2171. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2172. }
  2173. function gamma(y) {
  2174. return (y = +y) === 1 ? nogamma : function(a, b) {
  2175. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2176. };
  2177. }
  2178. function nogamma(a, b) {
  2179. var d = b - a;
  2180. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2181. }
  2182. var interpolateRgb = (function rgbGamma(y) {
  2183. var color$$1 = gamma(y);
  2184. function rgb$$1(start, end) {
  2185. var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
  2186. g = color$$1(start.g, end.g),
  2187. b = color$$1(start.b, end.b),
  2188. opacity = nogamma(start.opacity, end.opacity);
  2189. return function(t) {
  2190. start.r = r(t);
  2191. start.g = g(t);
  2192. start.b = b(t);
  2193. start.opacity = opacity(t);
  2194. return start + "";
  2195. };
  2196. }
  2197. rgb$$1.gamma = rgbGamma;
  2198. return rgb$$1;
  2199. })(1);
  2200. function rgbSpline(spline) {
  2201. return function(colors) {
  2202. var n = colors.length,
  2203. r = new Array(n),
  2204. g = new Array(n),
  2205. b = new Array(n),
  2206. i, color$$1;
  2207. for (i = 0; i < n; ++i) {
  2208. color$$1 = rgb(colors[i]);
  2209. r[i] = color$$1.r || 0;
  2210. g[i] = color$$1.g || 0;
  2211. b[i] = color$$1.b || 0;
  2212. }
  2213. r = spline(r);
  2214. g = spline(g);
  2215. b = spline(b);
  2216. color$$1.opacity = 1;
  2217. return function(t) {
  2218. color$$1.r = r(t);
  2219. color$$1.g = g(t);
  2220. color$$1.b = b(t);
  2221. return color$$1 + "";
  2222. };
  2223. };
  2224. }
  2225. var rgbBasis = rgbSpline(basis$1);
  2226. var rgbBasisClosed = rgbSpline(basisClosed);
  2227. var array$1 = function(a, b) {
  2228. var nb = b ? b.length : 0,
  2229. na = a ? Math.min(nb, a.length) : 0,
  2230. x = new Array(nb),
  2231. c = new Array(nb),
  2232. i;
  2233. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2234. for (; i < nb; ++i) c[i] = b[i];
  2235. return function(t) {
  2236. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2237. return c;
  2238. };
  2239. };
  2240. var date = function(a, b) {
  2241. var d = new Date;
  2242. return a = +a, b -= a, function(t) {
  2243. return d.setTime(a + b * t), d;
  2244. };
  2245. };
  2246. var reinterpolate = function(a, b) {
  2247. return a = +a, b -= a, function(t) {
  2248. return a + b * t;
  2249. };
  2250. };
  2251. var object = function(a, b) {
  2252. var i = {},
  2253. c = {},
  2254. k;
  2255. if (a === null || typeof a !== "object") a = {};
  2256. if (b === null || typeof b !== "object") b = {};
  2257. for (k in b) {
  2258. if (k in a) {
  2259. i[k] = interpolateValue(a[k], b[k]);
  2260. } else {
  2261. c[k] = b[k];
  2262. }
  2263. }
  2264. return function(t) {
  2265. for (k in i) c[k] = i[k](t);
  2266. return c;
  2267. };
  2268. };
  2269. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
  2270. var reB = new RegExp(reA.source, "g");
  2271. function zero(b) {
  2272. return function() {
  2273. return b;
  2274. };
  2275. }
  2276. function one(b) {
  2277. return function(t) {
  2278. return b(t) + "";
  2279. };
  2280. }
  2281. var interpolateString = function(a, b) {
  2282. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2283. am, // current match in a
  2284. bm, // current match in b
  2285. bs, // string preceding current number in b, if any
  2286. i = -1, // index in s
  2287. s = [], // string constants and placeholders
  2288. q = []; // number interpolators
  2289. // Coerce inputs to strings.
  2290. a = a + "", b = b + "";
  2291. // Interpolate pairs of numbers in a & b.
  2292. while ((am = reA.exec(a))
  2293. && (bm = reB.exec(b))) {
  2294. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2295. bs = b.slice(bi, bs);
  2296. if (s[i]) s[i] += bs; // coalesce with previous string
  2297. else s[++i] = bs;
  2298. }
  2299. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2300. if (s[i]) s[i] += bm; // coalesce with previous string
  2301. else s[++i] = bm;
  2302. } else { // interpolate non-matching numbers
  2303. s[++i] = null;
  2304. q.push({i: i, x: reinterpolate(am, bm)});
  2305. }
  2306. bi = reB.lastIndex;
  2307. }
  2308. // Add remains of b.
  2309. if (bi < b.length) {
  2310. bs = b.slice(bi);
  2311. if (s[i]) s[i] += bs; // coalesce with previous string
  2312. else s[++i] = bs;
  2313. }
  2314. // Special optimization for only a single match.
  2315. // Otherwise, interpolate each of the numbers and rejoin the string.
  2316. return s.length < 2 ? (q[0]
  2317. ? one(q[0].x)
  2318. : zero(b))
  2319. : (b = q.length, function(t) {
  2320. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2321. return s.join("");
  2322. });
  2323. };
  2324. var interpolateValue = function(a, b) {
  2325. var t = typeof b, c;
  2326. return b == null || t === "boolean" ? constant$3(b)
  2327. : (t === "number" ? reinterpolate
  2328. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2329. : b instanceof color ? interpolateRgb
  2330. : b instanceof Date ? date
  2331. : Array.isArray(b) ? array$1
  2332. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2333. : reinterpolate)(a, b);
  2334. };
  2335. var interpolateRound = function(a, b) {
  2336. return a = +a, b -= a, function(t) {
  2337. return Math.round(a + b * t);
  2338. };
  2339. };
  2340. var degrees = 180 / Math.PI;
  2341. var identity$2 = {
  2342. translateX: 0,
  2343. translateY: 0,
  2344. rotate: 0,
  2345. skewX: 0,
  2346. scaleX: 1,
  2347. scaleY: 1
  2348. };
  2349. var decompose = function(a, b, c, d, e, f) {
  2350. var scaleX, scaleY, skewX;
  2351. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2352. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2353. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2354. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2355. return {
  2356. translateX: e,
  2357. translateY: f,
  2358. rotate: Math.atan2(b, a) * degrees,
  2359. skewX: Math.atan(skewX) * degrees,
  2360. scaleX: scaleX,
  2361. scaleY: scaleY
  2362. };
  2363. };
  2364. var cssNode;
  2365. var cssRoot;
  2366. var cssView;
  2367. var svgNode;
  2368. function parseCss(value) {
  2369. if (value === "none") return identity$2;
  2370. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2371. cssNode.style.transform = value;
  2372. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2373. cssRoot.removeChild(cssNode);
  2374. value = value.slice(7, -1).split(",");
  2375. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2376. }
  2377. function parseSvg(value) {
  2378. if (value == null) return identity$2;
  2379. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2380. svgNode.setAttribute("transform", value);
  2381. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2382. value = value.matrix;
  2383. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2384. }
  2385. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2386. function pop(s) {
  2387. return s.length ? s.pop() + " " : "";
  2388. }
  2389. function translate(xa, ya, xb, yb, s, q) {
  2390. if (xa !== xb || ya !== yb) {
  2391. var i = s.push("translate(", null, pxComma, null, pxParen);
  2392. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2393. } else if (xb || yb) {
  2394. s.push("translate(" + xb + pxComma + yb + pxParen);
  2395. }
  2396. }
  2397. function rotate(a, b, s, q) {
  2398. if (a !== b) {
  2399. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2400. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
  2401. } else if (b) {
  2402. s.push(pop(s) + "rotate(" + b + degParen);
  2403. }
  2404. }
  2405. function skewX(a, b, s, q) {
  2406. if (a !== b) {
  2407. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
  2408. } else if (b) {
  2409. s.push(pop(s) + "skewX(" + b + degParen);
  2410. }
  2411. }
  2412. function scale(xa, ya, xb, yb, s, q) {
  2413. if (xa !== xb || ya !== yb) {
  2414. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2415. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2416. } else if (xb !== 1 || yb !== 1) {
  2417. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2418. }
  2419. }
  2420. return function(a, b) {
  2421. var s = [], // string constants and placeholders
  2422. q = []; // number interpolators
  2423. a = parse(a), b = parse(b);
  2424. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2425. rotate(a.rotate, b.rotate, s, q);
  2426. skewX(a.skewX, b.skewX, s, q);
  2427. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2428. a = b = null; // gc
  2429. return function(t) {
  2430. var i = -1, n = q.length, o;
  2431. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2432. return s.join("");
  2433. };
  2434. };
  2435. }
  2436. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2437. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2438. var rho = Math.SQRT2;
  2439. var rho2 = 2;
  2440. var rho4 = 4;
  2441. var epsilon2 = 1e-12;
  2442. function cosh(x) {
  2443. return ((x = Math.exp(x)) + 1 / x) / 2;
  2444. }
  2445. function sinh(x) {
  2446. return ((x = Math.exp(x)) - 1 / x) / 2;
  2447. }
  2448. function tanh(x) {
  2449. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2450. }
  2451. // p0 = [ux0, uy0, w0]
  2452. // p1 = [ux1, uy1, w1]
  2453. var interpolateZoom = function(p0, p1) {
  2454. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2455. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2456. dx = ux1 - ux0,
  2457. dy = uy1 - uy0,
  2458. d2 = dx * dx + dy * dy,
  2459. i,
  2460. S;
  2461. // Special case for u0 ≅ u1.
  2462. if (d2 < epsilon2) {
  2463. S = Math.log(w1 / w0) / rho;
  2464. i = function(t) {
  2465. return [
  2466. ux0 + t * dx,
  2467. uy0 + t * dy,
  2468. w0 * Math.exp(rho * t * S)
  2469. ];
  2470. };
  2471. }
  2472. // General case.
  2473. else {
  2474. var d1 = Math.sqrt(d2),
  2475. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2476. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2477. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2478. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2479. S = (r1 - r0) / rho;
  2480. i = function(t) {
  2481. var s = t * S,
  2482. coshr0 = cosh(r0),
  2483. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2484. return [
  2485. ux0 + u * dx,
  2486. uy0 + u * dy,
  2487. w0 * coshr0 / cosh(rho * s + r0)
  2488. ];
  2489. };
  2490. }
  2491. i.duration = S * 1000;
  2492. return i;
  2493. };
  2494. function hsl$1(hue$$1) {
  2495. return function(start, end) {
  2496. var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
  2497. s = nogamma(start.s, end.s),
  2498. l = nogamma(start.l, end.l),
  2499. opacity = nogamma(start.opacity, end.opacity);
  2500. return function(t) {
  2501. start.h = h(t);
  2502. start.s = s(t);
  2503. start.l = l(t);
  2504. start.opacity = opacity(t);
  2505. return start + "";
  2506. };
  2507. }
  2508. }
  2509. var hsl$2 = hsl$1(hue);
  2510. var hslLong = hsl$1(nogamma);
  2511. function lab$1(start, end) {
  2512. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2513. a = nogamma(start.a, end.a),
  2514. b = nogamma(start.b, end.b),
  2515. opacity = nogamma(start.opacity, end.opacity);
  2516. return function(t) {
  2517. start.l = l(t);
  2518. start.a = a(t);
  2519. start.b = b(t);
  2520. start.opacity = opacity(t);
  2521. return start + "";
  2522. };
  2523. }
  2524. function hcl$1(hue$$1) {
  2525. return function(start, end) {
  2526. var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
  2527. c = nogamma(start.c, end.c),
  2528. l = nogamma(start.l, end.l),
  2529. opacity = nogamma(start.opacity, end.opacity);
  2530. return function(t) {
  2531. start.h = h(t);
  2532. start.c = c(t);
  2533. start.l = l(t);
  2534. start.opacity = opacity(t);
  2535. return start + "";
  2536. };
  2537. }
  2538. }
  2539. var hcl$2 = hcl$1(hue);
  2540. var hclLong = hcl$1(nogamma);
  2541. function cubehelix$1(hue$$1) {
  2542. return (function cubehelixGamma(y) {
  2543. y = +y;
  2544. function cubehelix$$1(start, end) {
  2545. var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2546. s = nogamma(start.s, end.s),
  2547. l = nogamma(start.l, end.l),
  2548. opacity = nogamma(start.opacity, end.opacity);
  2549. return function(t) {
  2550. start.h = h(t);
  2551. start.s = s(t);
  2552. start.l = l(Math.pow(t, y));
  2553. start.opacity = opacity(t);
  2554. return start + "";
  2555. };
  2556. }
  2557. cubehelix$$1.gamma = cubehelixGamma;
  2558. return cubehelix$$1;
  2559. })(1);
  2560. }
  2561. var cubehelix$2 = cubehelix$1(hue);
  2562. var cubehelixLong = cubehelix$1(nogamma);
  2563. var quantize = function(interpolator, n) {
  2564. var samples = new Array(n);
  2565. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2566. return samples;
  2567. };
  2568. var frame = 0;
  2569. var timeout = 0;
  2570. var interval = 0;
  2571. var pokeDelay = 1000;
  2572. var taskHead;
  2573. var taskTail;
  2574. var clockLast = 0;
  2575. var clockNow = 0;
  2576. var clockSkew = 0;
  2577. var clock = typeof performance === "object" && performance.now ? performance : Date;
  2578. var setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2579. function now() {
  2580. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2581. }
  2582. function clearNow() {
  2583. clockNow = 0;
  2584. }
  2585. function Timer() {
  2586. this._call =
  2587. this._time =
  2588. this._next = null;
  2589. }
  2590. Timer.prototype = timer.prototype = {
  2591. constructor: Timer,
  2592. restart: function(callback, delay, time) {
  2593. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2594. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2595. if (!this._next && taskTail !== this) {
  2596. if (taskTail) taskTail._next = this;
  2597. else taskHead = this;
  2598. taskTail = this;
  2599. }
  2600. this._call = callback;
  2601. this._time = time;
  2602. sleep();
  2603. },
  2604. stop: function() {
  2605. if (this._call) {
  2606. this._call = null;
  2607. this._time = Infinity;
  2608. sleep();
  2609. }
  2610. }
  2611. };
  2612. function timer(callback, delay, time) {
  2613. var t = new Timer;
  2614. t.restart(callback, delay, time);
  2615. return t;
  2616. }
  2617. function timerFlush() {
  2618. now(); // Get the current time, if not already set.
  2619. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2620. var t = taskHead, e;
  2621. while (t) {
  2622. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2623. t = t._next;
  2624. }
  2625. --frame;
  2626. }
  2627. function wake() {
  2628. clockNow = (clockLast = clock.now()) + clockSkew;
  2629. frame = timeout = 0;
  2630. try {
  2631. timerFlush();
  2632. } finally {
  2633. frame = 0;
  2634. nap();
  2635. clockNow = 0;
  2636. }
  2637. }
  2638. function poke() {
  2639. var now = clock.now(), delay = now - clockLast;
  2640. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2641. }
  2642. function nap() {
  2643. var t0, t1 = taskHead, t2, time = Infinity;
  2644. while (t1) {
  2645. if (t1._call) {
  2646. if (time > t1._time) time = t1._time;
  2647. t0 = t1, t1 = t1._next;
  2648. } else {
  2649. t2 = t1._next, t1._next = null;
  2650. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2651. }
  2652. }
  2653. taskTail = t0;
  2654. sleep(time);
  2655. }
  2656. function sleep(time) {
  2657. if (frame) return; // Soonest alarm already set, or will be.
  2658. if (timeout) timeout = clearTimeout(timeout);
  2659. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2660. if (delay > 24) {
  2661. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2662. if (interval) interval = clearInterval(interval);
  2663. } else {
  2664. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2665. frame = 1, setFrame(wake);
  2666. }
  2667. }
  2668. var timeout$1 = function(callback, delay, time) {
  2669. var t = new Timer;
  2670. delay = delay == null ? 0 : +delay;
  2671. t.restart(function(elapsed) {
  2672. t.stop();
  2673. callback(elapsed + delay);
  2674. }, delay, time);
  2675. return t;
  2676. };
  2677. var interval$1 = function(callback, delay, time) {
  2678. var t = new Timer, total = delay;
  2679. if (delay == null) return t.restart(callback, delay, time), t;
  2680. delay = +delay, time = time == null ? now() : +time;
  2681. t.restart(function tick(elapsed) {
  2682. elapsed += total;
  2683. t.restart(tick, total += delay, time);
  2684. callback(elapsed);
  2685. }, delay, time);
  2686. return t;
  2687. };
  2688. var emptyOn = dispatch("start", "end", "interrupt");
  2689. var emptyTween = [];
  2690. var CREATED = 0;
  2691. var SCHEDULED = 1;
  2692. var STARTING = 2;
  2693. var STARTED = 3;
  2694. var RUNNING = 4;
  2695. var ENDING = 5;
  2696. var ENDED = 6;
  2697. var schedule = function(node, name, id, index, group, timing) {
  2698. var schedules = node.__transition;
  2699. if (!schedules) node.__transition = {};
  2700. else if (id in schedules) return;
  2701. create(node, id, {
  2702. name: name,
  2703. index: index, // For context during callback.
  2704. group: group, // For context during callback.
  2705. on: emptyOn,
  2706. tween: emptyTween,
  2707. time: timing.time,
  2708. delay: timing.delay,
  2709. duration: timing.duration,
  2710. ease: timing.ease,
  2711. timer: null,
  2712. state: CREATED
  2713. });
  2714. };
  2715. function init(node, id) {
  2716. var schedule = node.__transition;
  2717. if (!schedule || !(schedule = schedule[id]) || schedule.state > CREATED) throw new Error("too late");
  2718. return schedule;
  2719. }
  2720. function set$1(node, id) {
  2721. var schedule = node.__transition;
  2722. if (!schedule || !(schedule = schedule[id]) || schedule.state > STARTING) throw new Error("too late");
  2723. return schedule;
  2724. }
  2725. function get$1(node, id) {
  2726. var schedule = node.__transition;
  2727. if (!schedule || !(schedule = schedule[id])) throw new Error("too late");
  2728. return schedule;
  2729. }
  2730. function create(node, id, self) {
  2731. var schedules = node.__transition,
  2732. tween;
  2733. // Initialize the self timer when the transition is created.
  2734. // Note the actual delay is not known until the first callback!
  2735. schedules[id] = self;
  2736. self.timer = timer(schedule, 0, self.time);
  2737. function schedule(elapsed) {
  2738. self.state = SCHEDULED;
  2739. self.timer.restart(start, self.delay, self.time);
  2740. // If the elapsed delay is less than our first sleep, start immediately.
  2741. if (self.delay <= elapsed) start(elapsed - self.delay);
  2742. }
  2743. function start(elapsed) {
  2744. var i, j, n, o;
  2745. // If the state is not SCHEDULED, then we previously errored on start.
  2746. if (self.state !== SCHEDULED) return stop();
  2747. for (i in schedules) {
  2748. o = schedules[i];
  2749. if (o.name !== self.name) continue;
  2750. // While this element already has a starting transition during this frame,
  2751. // defer starting an interrupting transition until that transition has a
  2752. // chance to tick (and possibly end); see d3/d3-transition#54!
  2753. if (o.state === STARTED) return timeout$1(start);
  2754. // Interrupt the active transition, if any.
  2755. // Dispatch the interrupt event.
  2756. if (o.state === RUNNING) {
  2757. o.state = ENDED;
  2758. o.timer.stop();
  2759. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2760. delete schedules[i];
  2761. }
  2762. // Cancel any pre-empted transitions. No interrupt event is dispatched
  2763. // because the cancelled transitions never started. Note that this also
  2764. // removes this transition from the pending list!
  2765. else if (+i < id) {
  2766. o.state = ENDED;
  2767. o.timer.stop();
  2768. delete schedules[i];
  2769. }
  2770. }
  2771. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2772. // Note the transition may be canceled after start and before the first tick!
  2773. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2774. // Assuming this is successful, subsequent callbacks go straight to tick.
  2775. timeout$1(function() {
  2776. if (self.state === STARTED) {
  2777. self.state = RUNNING;
  2778. self.timer.restart(tick, self.delay, self.time);
  2779. tick(elapsed);
  2780. }
  2781. });
  2782. // Dispatch the start event.
  2783. // Note this must be done before the tween are initialized.
  2784. self.state = STARTING;
  2785. self.on.call("start", node, node.__data__, self.index, self.group);
  2786. if (self.state !== STARTING) return; // interrupted
  2787. self.state = STARTED;
  2788. // Initialize the tween, deleting null tween.
  2789. tween = new Array(n = self.tween.length);
  2790. for (i = 0, j = -1; i < n; ++i) {
  2791. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2792. tween[++j] = o;
  2793. }
  2794. }
  2795. tween.length = j + 1;
  2796. }
  2797. function tick(elapsed) {
  2798. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2799. i = -1,
  2800. n = tween.length;
  2801. while (++i < n) {
  2802. tween[i].call(null, t);
  2803. }
  2804. // Dispatch the end event.
  2805. if (self.state === ENDING) {
  2806. self.on.call("end", node, node.__data__, self.index, self.group);
  2807. stop();
  2808. }
  2809. }
  2810. function stop() {
  2811. self.state = ENDED;
  2812. self.timer.stop();
  2813. delete schedules[id];
  2814. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2815. delete node.__transition;
  2816. }
  2817. }
  2818. var interrupt = function(node, name) {
  2819. var schedules = node.__transition,
  2820. schedule$$1,
  2821. active,
  2822. empty = true,
  2823. i;
  2824. if (!schedules) return;
  2825. name = name == null ? null : name + "";
  2826. for (i in schedules) {
  2827. if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
  2828. active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
  2829. schedule$$1.state = ENDED;
  2830. schedule$$1.timer.stop();
  2831. if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
  2832. delete schedules[i];
  2833. }
  2834. if (empty) delete node.__transition;
  2835. };
  2836. var selection_interrupt = function(name) {
  2837. return this.each(function() {
  2838. interrupt(this, name);
  2839. });
  2840. };
  2841. function tweenRemove(id, name) {
  2842. var tween0, tween1;
  2843. return function() {
  2844. var schedule$$1 = set$1(this, id),
  2845. tween = schedule$$1.tween;
  2846. // If this node shared tween with the previous node,
  2847. // just assign the updated shared tween and we’re done!
  2848. // Otherwise, copy-on-write.
  2849. if (tween !== tween0) {
  2850. tween1 = tween0 = tween;
  2851. for (var i = 0, n = tween1.length; i < n; ++i) {
  2852. if (tween1[i].name === name) {
  2853. tween1 = tween1.slice();
  2854. tween1.splice(i, 1);
  2855. break;
  2856. }
  2857. }
  2858. }
  2859. schedule$$1.tween = tween1;
  2860. };
  2861. }
  2862. function tweenFunction(id, name, value) {
  2863. var tween0, tween1;
  2864. if (typeof value !== "function") throw new Error;
  2865. return function() {
  2866. var schedule$$1 = set$1(this, id),
  2867. tween = schedule$$1.tween;
  2868. // If this node shared tween with the previous node,
  2869. // just assign the updated shared tween and we’re done!
  2870. // Otherwise, copy-on-write.
  2871. if (tween !== tween0) {
  2872. tween1 = (tween0 = tween).slice();
  2873. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2874. if (tween1[i].name === name) {
  2875. tween1[i] = t;
  2876. break;
  2877. }
  2878. }
  2879. if (i === n) tween1.push(t);
  2880. }
  2881. schedule$$1.tween = tween1;
  2882. };
  2883. }
  2884. var transition_tween = function(name, value) {
  2885. var id = this._id;
  2886. name += "";
  2887. if (arguments.length < 2) {
  2888. var tween = get$1(this.node(), id).tween;
  2889. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2890. if ((t = tween[i]).name === name) {
  2891. return t.value;
  2892. }
  2893. }
  2894. return null;
  2895. }
  2896. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2897. };
  2898. function tweenValue(transition, name, value) {
  2899. var id = transition._id;
  2900. transition.each(function() {
  2901. var schedule$$1 = set$1(this, id);
  2902. (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
  2903. });
  2904. return function(node) {
  2905. return get$1(node, id).value[name];
  2906. };
  2907. }
  2908. var interpolate = function(a, b) {
  2909. var c;
  2910. return (typeof b === "number" ? reinterpolate
  2911. : b instanceof color ? interpolateRgb
  2912. : (c = color(b)) ? (b = c, interpolateRgb)
  2913. : interpolateString)(a, b);
  2914. };
  2915. function attrRemove$1(name) {
  2916. return function() {
  2917. this.removeAttribute(name);
  2918. };
  2919. }
  2920. function attrRemoveNS$1(fullname) {
  2921. return function() {
  2922. this.removeAttributeNS(fullname.space, fullname.local);
  2923. };
  2924. }
  2925. function attrConstant$1(name, interpolate$$1, value1) {
  2926. var value00,
  2927. interpolate0;
  2928. return function() {
  2929. var value0 = this.getAttribute(name);
  2930. return value0 === value1 ? null
  2931. : value0 === value00 ? interpolate0
  2932. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2933. };
  2934. }
  2935. function attrConstantNS$1(fullname, interpolate$$1, value1) {
  2936. var value00,
  2937. interpolate0;
  2938. return function() {
  2939. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  2940. return value0 === value1 ? null
  2941. : value0 === value00 ? interpolate0
  2942. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2943. };
  2944. }
  2945. function attrFunction$1(name, interpolate$$1, value) {
  2946. var value00,
  2947. value10,
  2948. interpolate0;
  2949. return function() {
  2950. var value0, value1 = value(this);
  2951. if (value1 == null) return void this.removeAttribute(name);
  2952. value0 = this.getAttribute(name);
  2953. return value0 === value1 ? null
  2954. : value0 === value00 && value1 === value10 ? interpolate0
  2955. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2956. };
  2957. }
  2958. function attrFunctionNS$1(fullname, interpolate$$1, value) {
  2959. var value00,
  2960. value10,
  2961. interpolate0;
  2962. return function() {
  2963. var value0, value1 = value(this);
  2964. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  2965. value0 = this.getAttributeNS(fullname.space, fullname.local);
  2966. return value0 === value1 ? null
  2967. : value0 === value00 && value1 === value10 ? interpolate0
  2968. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2969. };
  2970. }
  2971. var transition_attr = function(name, value) {
  2972. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  2973. return this.attrTween(name, typeof value === "function"
  2974. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  2975. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  2976. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
  2977. };
  2978. function attrTweenNS(fullname, value) {
  2979. function tween() {
  2980. var node = this, i = value.apply(node, arguments);
  2981. return i && function(t) {
  2982. node.setAttributeNS(fullname.space, fullname.local, i(t));
  2983. };
  2984. }
  2985. tween._value = value;
  2986. return tween;
  2987. }
  2988. function attrTween(name, value) {
  2989. function tween() {
  2990. var node = this, i = value.apply(node, arguments);
  2991. return i && function(t) {
  2992. node.setAttribute(name, i(t));
  2993. };
  2994. }
  2995. tween._value = value;
  2996. return tween;
  2997. }
  2998. var transition_attrTween = function(name, value) {
  2999. var key = "attr." + name;
  3000. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3001. if (value == null) return this.tween(key, null);
  3002. if (typeof value !== "function") throw new Error;
  3003. var fullname = namespace(name);
  3004. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3005. };
  3006. function delayFunction(id, value) {
  3007. return function() {
  3008. init(this, id).delay = +value.apply(this, arguments);
  3009. };
  3010. }
  3011. function delayConstant(id, value) {
  3012. return value = +value, function() {
  3013. init(this, id).delay = value;
  3014. };
  3015. }
  3016. var transition_delay = function(value) {
  3017. var id = this._id;
  3018. return arguments.length
  3019. ? this.each((typeof value === "function"
  3020. ? delayFunction
  3021. : delayConstant)(id, value))
  3022. : get$1(this.node(), id).delay;
  3023. };
  3024. function durationFunction(id, value) {
  3025. return function() {
  3026. set$1(this, id).duration = +value.apply(this, arguments);
  3027. };
  3028. }
  3029. function durationConstant(id, value) {
  3030. return value = +value, function() {
  3031. set$1(this, id).duration = value;
  3032. };
  3033. }
  3034. var transition_duration = function(value) {
  3035. var id = this._id;
  3036. return arguments.length
  3037. ? this.each((typeof value === "function"
  3038. ? durationFunction
  3039. : durationConstant)(id, value))
  3040. : get$1(this.node(), id).duration;
  3041. };
  3042. function easeConstant(id, value) {
  3043. if (typeof value !== "function") throw new Error;
  3044. return function() {
  3045. set$1(this, id).ease = value;
  3046. };
  3047. }
  3048. var transition_ease = function(value) {
  3049. var id = this._id;
  3050. return arguments.length
  3051. ? this.each(easeConstant(id, value))
  3052. : get$1(this.node(), id).ease;
  3053. };
  3054. var transition_filter = function(match) {
  3055. if (typeof match !== "function") match = matcher$1(match);
  3056. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3057. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3058. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3059. subgroup.push(node);
  3060. }
  3061. }
  3062. }
  3063. return new Transition(subgroups, this._parents, this._name, this._id);
  3064. };
  3065. var transition_merge = function(transition$$1) {
  3066. if (transition$$1._id !== this._id) throw new Error;
  3067. for (var groups0 = this._groups, groups1 = transition$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  3068. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3069. if (node = group0[i] || group1[i]) {
  3070. merge[i] = node;
  3071. }
  3072. }
  3073. }
  3074. for (; j < m0; ++j) {
  3075. merges[j] = groups0[j];
  3076. }
  3077. return new Transition(merges, this._parents, this._name, this._id);
  3078. };
  3079. function start(name) {
  3080. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3081. var i = t.indexOf(".");
  3082. if (i >= 0) t = t.slice(0, i);
  3083. return !t || t === "start";
  3084. });
  3085. }
  3086. function onFunction(id, name, listener) {
  3087. var on0, on1, sit = start(name) ? init : set$1;
  3088. return function() {
  3089. var schedule$$1 = sit(this, id),
  3090. on = schedule$$1.on;
  3091. // If this node shared a dispatch with the previous node,
  3092. // just assign the updated shared dispatch and we’re done!
  3093. // Otherwise, copy-on-write.
  3094. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3095. schedule$$1.on = on1;
  3096. };
  3097. }
  3098. var transition_on = function(name, listener) {
  3099. var id = this._id;
  3100. return arguments.length < 2
  3101. ? get$1(this.node(), id).on.on(name)
  3102. : this.each(onFunction(id, name, listener));
  3103. };
  3104. function removeFunction(id) {
  3105. return function() {
  3106. var parent = this.parentNode;
  3107. for (var i in this.__transition) if (+i !== id) return;
  3108. if (parent) parent.removeChild(this);
  3109. };
  3110. }
  3111. var transition_remove = function() {
  3112. return this.on("end.remove", removeFunction(this._id));
  3113. };
  3114. var transition_select = function(select) {
  3115. var name = this._name,
  3116. id = this._id;
  3117. if (typeof select !== "function") select = selector(select);
  3118. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3119. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3120. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  3121. if ("__data__" in node) subnode.__data__ = node.__data__;
  3122. subgroup[i] = subnode;
  3123. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3124. }
  3125. }
  3126. }
  3127. return new Transition(subgroups, this._parents, name, id);
  3128. };
  3129. var transition_selectAll = function(select) {
  3130. var name = this._name,
  3131. id = this._id;
  3132. if (typeof select !== "function") select = selectorAll(select);
  3133. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3134. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3135. if (node = group[i]) {
  3136. for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3137. if (child = children[k]) {
  3138. schedule(child, name, id, k, children, inherit);
  3139. }
  3140. }
  3141. subgroups.push(children);
  3142. parents.push(node);
  3143. }
  3144. }
  3145. }
  3146. return new Transition(subgroups, parents, name, id);
  3147. };
  3148. var Selection$1 = selection.prototype.constructor;
  3149. var transition_selection = function() {
  3150. return new Selection$1(this._groups, this._parents);
  3151. };
  3152. function styleRemove$1(name, interpolate$$1) {
  3153. var value00,
  3154. value10,
  3155. interpolate0;
  3156. return function() {
  3157. var value0 = styleValue(this, name),
  3158. value1 = (this.style.removeProperty(name), styleValue(this, name));
  3159. return value0 === value1 ? null
  3160. : value0 === value00 && value1 === value10 ? interpolate0
  3161. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3162. };
  3163. }
  3164. function styleRemoveEnd(name) {
  3165. return function() {
  3166. this.style.removeProperty(name);
  3167. };
  3168. }
  3169. function styleConstant$1(name, interpolate$$1, value1) {
  3170. var value00,
  3171. interpolate0;
  3172. return function() {
  3173. var value0 = styleValue(this, name);
  3174. return value0 === value1 ? null
  3175. : value0 === value00 ? interpolate0
  3176. : interpolate0 = interpolate$$1(value00 = value0, value1);
  3177. };
  3178. }
  3179. function styleFunction$1(name, interpolate$$1, value) {
  3180. var value00,
  3181. value10,
  3182. interpolate0;
  3183. return function() {
  3184. var value0 = styleValue(this, name),
  3185. value1 = value(this);
  3186. if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
  3187. return value0 === value1 ? null
  3188. : value0 === value00 && value1 === value10 ? interpolate0
  3189. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3190. };
  3191. }
  3192. var transition_style = function(name, value, priority) {
  3193. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3194. return value == null ? this
  3195. .styleTween(name, styleRemove$1(name, i))
  3196. .on("end.style." + name, styleRemoveEnd(name))
  3197. : this.styleTween(name, typeof value === "function"
  3198. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  3199. : styleConstant$1(name, i, value + ""), priority);
  3200. };
  3201. function styleTween(name, value, priority) {
  3202. function tween() {
  3203. var node = this, i = value.apply(node, arguments);
  3204. return i && function(t) {
  3205. node.style.setProperty(name, i(t), priority);
  3206. };
  3207. }
  3208. tween._value = value;
  3209. return tween;
  3210. }
  3211. var transition_styleTween = function(name, value, priority) {
  3212. var key = "style." + (name += "");
  3213. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3214. if (value == null) return this.tween(key, null);
  3215. if (typeof value !== "function") throw new Error;
  3216. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3217. };
  3218. function textConstant$1(value) {
  3219. return function() {
  3220. this.textContent = value;
  3221. };
  3222. }
  3223. function textFunction$1(value) {
  3224. return function() {
  3225. var value1 = value(this);
  3226. this.textContent = value1 == null ? "" : value1;
  3227. };
  3228. }
  3229. var transition_text = function(value) {
  3230. return this.tween("text", typeof value === "function"
  3231. ? textFunction$1(tweenValue(this, "text", value))
  3232. : textConstant$1(value == null ? "" : value + ""));
  3233. };
  3234. var transition_transition = function() {
  3235. var name = this._name,
  3236. id0 = this._id,
  3237. id1 = newId();
  3238. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3239. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3240. if (node = group[i]) {
  3241. var inherit = get$1(node, id0);
  3242. schedule(node, name, id1, i, group, {
  3243. time: inherit.time + inherit.delay + inherit.duration,
  3244. delay: 0,
  3245. duration: inherit.duration,
  3246. ease: inherit.ease
  3247. });
  3248. }
  3249. }
  3250. }
  3251. return new Transition(groups, this._parents, name, id1);
  3252. };
  3253. var id = 0;
  3254. function Transition(groups, parents, name, id) {
  3255. this._groups = groups;
  3256. this._parents = parents;
  3257. this._name = name;
  3258. this._id = id;
  3259. }
  3260. function transition(name) {
  3261. return selection().transition(name);
  3262. }
  3263. function newId() {
  3264. return ++id;
  3265. }
  3266. var selection_prototype = selection.prototype;
  3267. Transition.prototype = transition.prototype = {
  3268. constructor: Transition,
  3269. select: transition_select,
  3270. selectAll: transition_selectAll,
  3271. filter: transition_filter,
  3272. merge: transition_merge,
  3273. selection: transition_selection,
  3274. transition: transition_transition,
  3275. call: selection_prototype.call,
  3276. nodes: selection_prototype.nodes,
  3277. node: selection_prototype.node,
  3278. size: selection_prototype.size,
  3279. empty: selection_prototype.empty,
  3280. each: selection_prototype.each,
  3281. on: transition_on,
  3282. attr: transition_attr,
  3283. attrTween: transition_attrTween,
  3284. style: transition_style,
  3285. styleTween: transition_styleTween,
  3286. text: transition_text,
  3287. remove: transition_remove,
  3288. tween: transition_tween,
  3289. delay: transition_delay,
  3290. duration: transition_duration,
  3291. ease: transition_ease
  3292. };
  3293. function linear$1(t) {
  3294. return +t;
  3295. }
  3296. function quadIn(t) {
  3297. return t * t;
  3298. }
  3299. function quadOut(t) {
  3300. return t * (2 - t);
  3301. }
  3302. function quadInOut(t) {
  3303. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3304. }
  3305. function cubicIn(t) {
  3306. return t * t * t;
  3307. }
  3308. function cubicOut(t) {
  3309. return --t * t * t + 1;
  3310. }
  3311. function cubicInOut(t) {
  3312. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3313. }
  3314. var exponent = 3;
  3315. var polyIn = (function custom(e) {
  3316. e = +e;
  3317. function polyIn(t) {
  3318. return Math.pow(t, e);
  3319. }
  3320. polyIn.exponent = custom;
  3321. return polyIn;
  3322. })(exponent);
  3323. var polyOut = (function custom(e) {
  3324. e = +e;
  3325. function polyOut(t) {
  3326. return 1 - Math.pow(1 - t, e);
  3327. }
  3328. polyOut.exponent = custom;
  3329. return polyOut;
  3330. })(exponent);
  3331. var polyInOut = (function custom(e) {
  3332. e = +e;
  3333. function polyInOut(t) {
  3334. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3335. }
  3336. polyInOut.exponent = custom;
  3337. return polyInOut;
  3338. })(exponent);
  3339. var pi = Math.PI;
  3340. var halfPi = pi / 2;
  3341. function sinIn(t) {
  3342. return 1 - Math.cos(t * halfPi);
  3343. }
  3344. function sinOut(t) {
  3345. return Math.sin(t * halfPi);
  3346. }
  3347. function sinInOut(t) {
  3348. return (1 - Math.cos(pi * t)) / 2;
  3349. }
  3350. function expIn(t) {
  3351. return Math.pow(2, 10 * t - 10);
  3352. }
  3353. function expOut(t) {
  3354. return 1 - Math.pow(2, -10 * t);
  3355. }
  3356. function expInOut(t) {
  3357. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3358. }
  3359. function circleIn(t) {
  3360. return 1 - Math.sqrt(1 - t * t);
  3361. }
  3362. function circleOut(t) {
  3363. return Math.sqrt(1 - --t * t);
  3364. }
  3365. function circleInOut(t) {
  3366. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3367. }
  3368. var b1 = 4 / 11;
  3369. var b2 = 6 / 11;
  3370. var b3 = 8 / 11;
  3371. var b4 = 3 / 4;
  3372. var b5 = 9 / 11;
  3373. var b6 = 10 / 11;
  3374. var b7 = 15 / 16;
  3375. var b8 = 21 / 22;
  3376. var b9 = 63 / 64;
  3377. var b0 = 1 / b1 / b1;
  3378. function bounceIn(t) {
  3379. return 1 - bounceOut(1 - t);
  3380. }
  3381. function bounceOut(t) {
  3382. return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
  3383. }
  3384. function bounceInOut(t) {
  3385. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3386. }
  3387. var overshoot = 1.70158;
  3388. var backIn = (function custom(s) {
  3389. s = +s;
  3390. function backIn(t) {
  3391. return t * t * ((s + 1) * t - s);
  3392. }
  3393. backIn.overshoot = custom;
  3394. return backIn;
  3395. })(overshoot);
  3396. var backOut = (function custom(s) {
  3397. s = +s;
  3398. function backOut(t) {
  3399. return --t * t * ((s + 1) * t + s) + 1;
  3400. }
  3401. backOut.overshoot = custom;
  3402. return backOut;
  3403. })(overshoot);
  3404. var backInOut = (function custom(s) {
  3405. s = +s;
  3406. function backInOut(t) {
  3407. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3408. }
  3409. backInOut.overshoot = custom;
  3410. return backInOut;
  3411. })(overshoot);
  3412. var tau = 2 * Math.PI;
  3413. var amplitude = 1;
  3414. var period = 0.3;
  3415. var elasticIn = (function custom(a, p) {
  3416. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3417. function elasticIn(t) {
  3418. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3419. }
  3420. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3421. elasticIn.period = function(p) { return custom(a, p); };
  3422. return elasticIn;
  3423. })(amplitude, period);
  3424. var elasticOut = (function custom(a, p) {
  3425. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3426. function elasticOut(t) {
  3427. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3428. }
  3429. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3430. elasticOut.period = function(p) { return custom(a, p); };
  3431. return elasticOut;
  3432. })(amplitude, period);
  3433. var elasticInOut = (function custom(a, p) {
  3434. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3435. function elasticInOut(t) {
  3436. return ((t = t * 2 - 1) < 0
  3437. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3438. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3439. }
  3440. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3441. elasticInOut.period = function(p) { return custom(a, p); };
  3442. return elasticInOut;
  3443. })(amplitude, period);
  3444. var defaultTiming = {
  3445. time: null, // Set on use.
  3446. delay: 0,
  3447. duration: 250,
  3448. ease: cubicInOut
  3449. };
  3450. function inherit(node, id) {
  3451. var timing;
  3452. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3453. if (!(node = node.parentNode)) {
  3454. return defaultTiming.time = now(), defaultTiming;
  3455. }
  3456. }
  3457. return timing;
  3458. }
  3459. var selection_transition = function(name) {
  3460. var id,
  3461. timing;
  3462. if (name instanceof Transition) {
  3463. id = name._id, name = name._name;
  3464. } else {
  3465. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3466. }
  3467. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3468. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3469. if (node = group[i]) {
  3470. schedule(node, name, id, i, group, timing || inherit(node, id));
  3471. }
  3472. }
  3473. }
  3474. return new Transition(groups, this._parents, name, id);
  3475. };
  3476. selection.prototype.interrupt = selection_interrupt;
  3477. selection.prototype.transition = selection_transition;
  3478. var root$1 = [null];
  3479. var active = function(node, name) {
  3480. var schedules = node.__transition,
  3481. schedule$$1,
  3482. i;
  3483. if (schedules) {
  3484. name = name == null ? null : name + "";
  3485. for (i in schedules) {
  3486. if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
  3487. return new Transition([[node]], root$1, name, +i);
  3488. }
  3489. }
  3490. }
  3491. return null;
  3492. };
  3493. var constant$4 = function(x) {
  3494. return function() {
  3495. return x;
  3496. };
  3497. };
  3498. var BrushEvent = function(target, type, selection) {
  3499. this.target = target;
  3500. this.type = type;
  3501. this.selection = selection;
  3502. };
  3503. function nopropagation$1() {
  3504. exports.event.stopImmediatePropagation();
  3505. }
  3506. var noevent$1 = function() {
  3507. exports.event.preventDefault();
  3508. exports.event.stopImmediatePropagation();
  3509. };
  3510. var MODE_DRAG = {name: "drag"};
  3511. var MODE_SPACE = {name: "space"};
  3512. var MODE_HANDLE = {name: "handle"};
  3513. var MODE_CENTER = {name: "center"};
  3514. var X = {
  3515. name: "x",
  3516. handles: ["e", "w"].map(type),
  3517. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  3518. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3519. };
  3520. var Y = {
  3521. name: "y",
  3522. handles: ["n", "s"].map(type),
  3523. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  3524. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3525. };
  3526. var XY = {
  3527. name: "xy",
  3528. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
  3529. input: function(xy) { return xy; },
  3530. output: function(xy) { return xy; }
  3531. };
  3532. var cursors = {
  3533. overlay: "crosshair",
  3534. selection: "move",
  3535. n: "ns-resize",
  3536. e: "ew-resize",
  3537. s: "ns-resize",
  3538. w: "ew-resize",
  3539. nw: "nwse-resize",
  3540. ne: "nesw-resize",
  3541. se: "nwse-resize",
  3542. sw: "nesw-resize"
  3543. };
  3544. var flipX = {
  3545. e: "w",
  3546. w: "e",
  3547. nw: "ne",
  3548. ne: "nw",
  3549. se: "sw",
  3550. sw: "se"
  3551. };
  3552. var flipY = {
  3553. n: "s",
  3554. s: "n",
  3555. nw: "sw",
  3556. ne: "se",
  3557. se: "ne",
  3558. sw: "nw"
  3559. };
  3560. var signsX = {
  3561. overlay: +1,
  3562. selection: +1,
  3563. n: null,
  3564. e: +1,
  3565. s: null,
  3566. w: -1,
  3567. nw: -1,
  3568. ne: +1,
  3569. se: +1,
  3570. sw: -1
  3571. };
  3572. var signsY = {
  3573. overlay: +1,
  3574. selection: +1,
  3575. n: -1,
  3576. e: null,
  3577. s: +1,
  3578. w: null,
  3579. nw: -1,
  3580. ne: -1,
  3581. se: +1,
  3582. sw: +1
  3583. };
  3584. function type(t) {
  3585. return {type: t};
  3586. }
  3587. // Ignore right-click, since that should open the context menu.
  3588. function defaultFilter() {
  3589. return !exports.event.button;
  3590. }
  3591. function defaultExtent() {
  3592. var svg = this.ownerSVGElement || this;
  3593. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3594. }
  3595. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3596. function local(node) {
  3597. while (!node.__brush) if (!(node = node.parentNode)) return;
  3598. return node.__brush;
  3599. }
  3600. function empty(extent) {
  3601. return extent[0][0] === extent[1][0]
  3602. || extent[0][1] === extent[1][1];
  3603. }
  3604. function brushSelection(node) {
  3605. var state = node.__brush;
  3606. return state ? state.dim.output(state.selection) : null;
  3607. }
  3608. function brushX() {
  3609. return brush$1(X);
  3610. }
  3611. function brushY() {
  3612. return brush$1(Y);
  3613. }
  3614. var brush = function() {
  3615. return brush$1(XY);
  3616. };
  3617. function brush$1(dim) {
  3618. var extent = defaultExtent,
  3619. filter = defaultFilter,
  3620. listeners = dispatch(brush, "start", "brush", "end"),
  3621. handleSize = 6,
  3622. touchending;
  3623. function brush(group) {
  3624. var overlay = group
  3625. .property("__brush", initialize)
  3626. .selectAll(".overlay")
  3627. .data([type("overlay")]);
  3628. overlay.enter().append("rect")
  3629. .attr("class", "overlay")
  3630. .attr("pointer-events", "all")
  3631. .attr("cursor", cursors.overlay)
  3632. .merge(overlay)
  3633. .each(function() {
  3634. var extent = local(this).extent;
  3635. select(this)
  3636. .attr("x", extent[0][0])
  3637. .attr("y", extent[0][1])
  3638. .attr("width", extent[1][0] - extent[0][0])
  3639. .attr("height", extent[1][1] - extent[0][1]);
  3640. });
  3641. group.selectAll(".selection")
  3642. .data([type("selection")])
  3643. .enter().append("rect")
  3644. .attr("class", "selection")
  3645. .attr("cursor", cursors.selection)
  3646. .attr("fill", "#777")
  3647. .attr("fill-opacity", 0.3)
  3648. .attr("stroke", "#fff")
  3649. .attr("shape-rendering", "crispEdges");
  3650. var handle = group.selectAll(".handle")
  3651. .data(dim.handles, function(d) { return d.type; });
  3652. handle.exit().remove();
  3653. handle.enter().append("rect")
  3654. .attr("class", function(d) { return "handle handle--" + d.type; })
  3655. .attr("cursor", function(d) { return cursors[d.type]; });
  3656. group
  3657. .each(redraw)
  3658. .attr("fill", "none")
  3659. .attr("pointer-events", "all")
  3660. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  3661. .on("mousedown.brush touchstart.brush", started);
  3662. }
  3663. brush.move = function(group, selection) {
  3664. if (group.selection) {
  3665. group
  3666. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3667. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3668. .tween("brush", function() {
  3669. var that = this,
  3670. state = that.__brush,
  3671. emit = emitter(that, arguments),
  3672. selection0 = state.selection,
  3673. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  3674. i = interpolateValue(selection0, selection1);
  3675. function tween(t) {
  3676. state.selection = t === 1 && empty(selection1) ? null : i(t);
  3677. redraw.call(that);
  3678. emit.brush();
  3679. }
  3680. return selection0 && selection1 ? tween : tween(1);
  3681. });
  3682. } else {
  3683. group
  3684. .each(function() {
  3685. var that = this,
  3686. args = arguments,
  3687. state = that.__brush,
  3688. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  3689. emit = emitter(that, args).beforestart();
  3690. interrupt(that);
  3691. state.selection = selection1 == null || empty(selection1) ? null : selection1;
  3692. redraw.call(that);
  3693. emit.start().brush().end();
  3694. });
  3695. }
  3696. };
  3697. function redraw() {
  3698. var group = select(this),
  3699. selection = local(this).selection;
  3700. if (selection) {
  3701. group.selectAll(".selection")
  3702. .style("display", null)
  3703. .attr("x", selection[0][0])
  3704. .attr("y", selection[0][1])
  3705. .attr("width", selection[1][0] - selection[0][0])
  3706. .attr("height", selection[1][1] - selection[0][1]);
  3707. group.selectAll(".handle")
  3708. .style("display", null)
  3709. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  3710. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  3711. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  3712. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  3713. }
  3714. else {
  3715. group.selectAll(".selection,.handle")
  3716. .style("display", "none")
  3717. .attr("x", null)
  3718. .attr("y", null)
  3719. .attr("width", null)
  3720. .attr("height", null);
  3721. }
  3722. }
  3723. function emitter(that, args) {
  3724. return that.__brush.emitter || new Emitter(that, args);
  3725. }
  3726. function Emitter(that, args) {
  3727. this.that = that;
  3728. this.args = args;
  3729. this.state = that.__brush;
  3730. this.active = 0;
  3731. }
  3732. Emitter.prototype = {
  3733. beforestart: function() {
  3734. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3735. return this;
  3736. },
  3737. start: function() {
  3738. if (this.starting) this.starting = false, this.emit("start");
  3739. return this;
  3740. },
  3741. brush: function() {
  3742. this.emit("brush");
  3743. return this;
  3744. },
  3745. end: function() {
  3746. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3747. return this;
  3748. },
  3749. emit: function(type) {
  3750. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3751. }
  3752. };
  3753. function started() {
  3754. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
  3755. else if (touchending) return;
  3756. if (!filter.apply(this, arguments)) return;
  3757. var that = this,
  3758. type = exports.event.target.__data__.type,
  3759. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3760. signX = dim === Y ? null : signsX[type],
  3761. signY = dim === X ? null : signsY[type],
  3762. state = local(that),
  3763. extent = state.extent,
  3764. selection = state.selection,
  3765. W = extent[0][0], w0, w1,
  3766. N = extent[0][1], n0, n1,
  3767. E = extent[1][0], e0, e1,
  3768. S = extent[1][1], s0, s1,
  3769. dx,
  3770. dy,
  3771. moving,
  3772. shifting = signX && signY && exports.event.shiftKey,
  3773. lockX,
  3774. lockY,
  3775. point0 = mouse(that),
  3776. point = point0,
  3777. emit = emitter(that, arguments).beforestart();
  3778. if (type === "overlay") {
  3779. state.selection = selection = [
  3780. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3781. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3782. ];
  3783. } else {
  3784. w0 = selection[0][0];
  3785. n0 = selection[0][1];
  3786. e0 = selection[1][0];
  3787. s0 = selection[1][1];
  3788. }
  3789. w1 = w0;
  3790. n1 = n0;
  3791. e1 = e0;
  3792. s1 = s0;
  3793. var group = select(that)
  3794. .attr("pointer-events", "none");
  3795. var overlay = group.selectAll(".overlay")
  3796. .attr("cursor", cursors[type]);
  3797. if (exports.event.touches) {
  3798. group
  3799. .on("touchmove.brush", moved, true)
  3800. .on("touchend.brush touchcancel.brush", ended, true);
  3801. } else {
  3802. var view = select(exports.event.view)
  3803. .on("keydown.brush", keydowned, true)
  3804. .on("keyup.brush", keyupped, true)
  3805. .on("mousemove.brush", moved, true)
  3806. .on("mouseup.brush", ended, true);
  3807. dragDisable(exports.event.view);
  3808. }
  3809. nopropagation$1();
  3810. interrupt(that);
  3811. redraw.call(that);
  3812. emit.start();
  3813. function moved() {
  3814. var point1 = mouse(that);
  3815. if (shifting && !lockX && !lockY) {
  3816. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  3817. else lockX = true;
  3818. }
  3819. point = point1;
  3820. moving = true;
  3821. noevent$1();
  3822. move();
  3823. }
  3824. function move() {
  3825. var t;
  3826. dx = point[0] - point0[0];
  3827. dy = point[1] - point0[1];
  3828. switch (mode) {
  3829. case MODE_SPACE:
  3830. case MODE_DRAG: {
  3831. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  3832. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  3833. break;
  3834. }
  3835. case MODE_HANDLE: {
  3836. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  3837. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  3838. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  3839. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  3840. break;
  3841. }
  3842. case MODE_CENTER: {
  3843. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  3844. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  3845. break;
  3846. }
  3847. }
  3848. if (e1 < w1) {
  3849. signX *= -1;
  3850. t = w0, w0 = e0, e0 = t;
  3851. t = w1, w1 = e1, e1 = t;
  3852. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  3853. }
  3854. if (s1 < n1) {
  3855. signY *= -1;
  3856. t = n0, n0 = s0, s0 = t;
  3857. t = n1, n1 = s1, s1 = t;
  3858. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  3859. }
  3860. if (state.selection) selection = state.selection; // May be set by brush.move!
  3861. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  3862. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  3863. if (selection[0][0] !== w1
  3864. || selection[0][1] !== n1
  3865. || selection[1][0] !== e1
  3866. || selection[1][1] !== s1) {
  3867. state.selection = [[w1, n1], [e1, s1]];
  3868. redraw.call(that);
  3869. emit.brush();
  3870. }
  3871. }
  3872. function ended() {
  3873. nopropagation$1();
  3874. if (exports.event.touches) {
  3875. if (exports.event.touches.length) return;
  3876. if (touchending) clearTimeout(touchending);
  3877. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  3878. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  3879. } else {
  3880. yesdrag(exports.event.view, moving);
  3881. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  3882. }
  3883. group.attr("pointer-events", "all");
  3884. overlay.attr("cursor", cursors.overlay);
  3885. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  3886. if (empty(selection)) state.selection = null, redraw.call(that);
  3887. emit.end();
  3888. }
  3889. function keydowned() {
  3890. switch (exports.event.keyCode) {
  3891. case 16: { // SHIFT
  3892. shifting = signX && signY;
  3893. break;
  3894. }
  3895. case 18: { // ALT
  3896. if (mode === MODE_HANDLE) {
  3897. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3898. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3899. mode = MODE_CENTER;
  3900. move();
  3901. }
  3902. break;
  3903. }
  3904. case 32: { // SPACE; takes priority over ALT
  3905. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  3906. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  3907. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  3908. mode = MODE_SPACE;
  3909. overlay.attr("cursor", cursors.selection);
  3910. move();
  3911. }
  3912. break;
  3913. }
  3914. default: return;
  3915. }
  3916. noevent$1();
  3917. }
  3918. function keyupped() {
  3919. switch (exports.event.keyCode) {
  3920. case 16: { // SHIFT
  3921. if (shifting) {
  3922. lockX = lockY = shifting = false;
  3923. move();
  3924. }
  3925. break;
  3926. }
  3927. case 18: { // ALT
  3928. if (mode === MODE_CENTER) {
  3929. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3930. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3931. mode = MODE_HANDLE;
  3932. move();
  3933. }
  3934. break;
  3935. }
  3936. case 32: { // SPACE
  3937. if (mode === MODE_SPACE) {
  3938. if (exports.event.altKey) {
  3939. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3940. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3941. mode = MODE_CENTER;
  3942. } else {
  3943. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3944. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3945. mode = MODE_HANDLE;
  3946. }
  3947. overlay.attr("cursor", cursors[type]);
  3948. move();
  3949. }
  3950. break;
  3951. }
  3952. default: return;
  3953. }
  3954. noevent$1();
  3955. }
  3956. }
  3957. function initialize() {
  3958. var state = this.__brush || {selection: null};
  3959. state.extent = extent.apply(this, arguments);
  3960. state.dim = dim;
  3961. return state;
  3962. }
  3963. brush.extent = function(_) {
  3964. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  3965. };
  3966. brush.filter = function(_) {
  3967. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  3968. };
  3969. brush.handleSize = function(_) {
  3970. return arguments.length ? (handleSize = +_, brush) : handleSize;
  3971. };
  3972. brush.on = function() {
  3973. var value = listeners.on.apply(listeners, arguments);
  3974. return value === listeners ? brush : value;
  3975. };
  3976. return brush;
  3977. }
  3978. var cos = Math.cos;
  3979. var sin = Math.sin;
  3980. var pi$1 = Math.PI;
  3981. var halfPi$1 = pi$1 / 2;
  3982. var tau$1 = pi$1 * 2;
  3983. var max$1 = Math.max;
  3984. function compareValue(compare) {
  3985. return function(a, b) {
  3986. return compare(
  3987. a.source.value + a.target.value,
  3988. b.source.value + b.target.value
  3989. );
  3990. };
  3991. }
  3992. var chord = function() {
  3993. var padAngle = 0,
  3994. sortGroups = null,
  3995. sortSubgroups = null,
  3996. sortChords = null;
  3997. function chord(matrix) {
  3998. var n = matrix.length,
  3999. groupSums = [],
  4000. groupIndex = sequence(n),
  4001. subgroupIndex = [],
  4002. chords = [],
  4003. groups = chords.groups = new Array(n),
  4004. subgroups = new Array(n * n),
  4005. k,
  4006. x,
  4007. x0,
  4008. dx,
  4009. i,
  4010. j;
  4011. // Compute the sum.
  4012. k = 0, i = -1; while (++i < n) {
  4013. x = 0, j = -1; while (++j < n) {
  4014. x += matrix[i][j];
  4015. }
  4016. groupSums.push(x);
  4017. subgroupIndex.push(sequence(n));
  4018. k += x;
  4019. }
  4020. // Sort groups…
  4021. if (sortGroups) groupIndex.sort(function(a, b) {
  4022. return sortGroups(groupSums[a], groupSums[b]);
  4023. });
  4024. // Sort subgroups…
  4025. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4026. d.sort(function(a, b) {
  4027. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4028. });
  4029. });
  4030. // Convert the sum to scaling factor for [0, 2pi].
  4031. // TODO Allow start and end angle to be specified?
  4032. // TODO Allow padding to be specified as percentage?
  4033. k = max$1(0, tau$1 - padAngle * n) / k;
  4034. dx = k ? padAngle : tau$1 / n;
  4035. // Compute the start and end angle for each group and subgroup.
  4036. // Note: Opera has a bug reordering object literal properties!
  4037. x = 0, i = -1; while (++i < n) {
  4038. x0 = x, j = -1; while (++j < n) {
  4039. var di = groupIndex[i],
  4040. dj = subgroupIndex[di][j],
  4041. v = matrix[di][dj],
  4042. a0 = x,
  4043. a1 = x += v * k;
  4044. subgroups[dj * n + di] = {
  4045. index: di,
  4046. subindex: dj,
  4047. startAngle: a0,
  4048. endAngle: a1,
  4049. value: v
  4050. };
  4051. }
  4052. groups[di] = {
  4053. index: di,
  4054. startAngle: x0,
  4055. endAngle: x,
  4056. value: groupSums[di]
  4057. };
  4058. x += dx;
  4059. }
  4060. // Generate chords for each (non-empty) subgroup-subgroup link.
  4061. i = -1; while (++i < n) {
  4062. j = i - 1; while (++j < n) {
  4063. var source = subgroups[j * n + i],
  4064. target = subgroups[i * n + j];
  4065. if (source.value || target.value) {
  4066. chords.push(source.value < target.value
  4067. ? {source: target, target: source}
  4068. : {source: source, target: target});
  4069. }
  4070. }
  4071. }
  4072. return sortChords ? chords.sort(sortChords) : chords;
  4073. }
  4074. chord.padAngle = function(_) {
  4075. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4076. };
  4077. chord.sortGroups = function(_) {
  4078. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4079. };
  4080. chord.sortSubgroups = function(_) {
  4081. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4082. };
  4083. chord.sortChords = function(_) {
  4084. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4085. };
  4086. return chord;
  4087. };
  4088. var slice$2 = Array.prototype.slice;
  4089. var constant$5 = function(x) {
  4090. return function() {
  4091. return x;
  4092. };
  4093. };
  4094. var pi$2 = Math.PI;
  4095. var tau$2 = 2 * pi$2;
  4096. var epsilon$1 = 1e-6;
  4097. var tauEpsilon = tau$2 - epsilon$1;
  4098. function Path() {
  4099. this._x0 = this._y0 = // start of current subpath
  4100. this._x1 = this._y1 = null; // end of current subpath
  4101. this._ = "";
  4102. }
  4103. function path() {
  4104. return new Path;
  4105. }
  4106. Path.prototype = path.prototype = {
  4107. constructor: Path,
  4108. moveTo: function(x, y) {
  4109. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4110. },
  4111. closePath: function() {
  4112. if (this._x1 !== null) {
  4113. this._x1 = this._x0, this._y1 = this._y0;
  4114. this._ += "Z";
  4115. }
  4116. },
  4117. lineTo: function(x, y) {
  4118. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4119. },
  4120. quadraticCurveTo: function(x1, y1, x, y) {
  4121. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4122. },
  4123. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4124. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4125. },
  4126. arcTo: function(x1, y1, x2, y2, r) {
  4127. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4128. var x0 = this._x1,
  4129. y0 = this._y1,
  4130. x21 = x2 - x1,
  4131. y21 = y2 - y1,
  4132. x01 = x0 - x1,
  4133. y01 = y0 - y1,
  4134. l01_2 = x01 * x01 + y01 * y01;
  4135. // Is the radius negative? Error.
  4136. if (r < 0) throw new Error("negative radius: " + r);
  4137. // Is this path empty? Move to (x1,y1).
  4138. if (this._x1 === null) {
  4139. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4140. }
  4141. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4142. else if (!(l01_2 > epsilon$1)) {}
  4143. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4144. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4145. // Or, is the radius zero? Line to (x1,y1).
  4146. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4147. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4148. }
  4149. // Otherwise, draw an arc!
  4150. else {
  4151. var x20 = x2 - x0,
  4152. y20 = y2 - y0,
  4153. l21_2 = x21 * x21 + y21 * y21,
  4154. l20_2 = x20 * x20 + y20 * y20,
  4155. l21 = Math.sqrt(l21_2),
  4156. l01 = Math.sqrt(l01_2),
  4157. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4158. t01 = l / l01,
  4159. t21 = l / l21;
  4160. // If the start tangent is not coincident with (x0,y0), line to.
  4161. if (Math.abs(t01 - 1) > epsilon$1) {
  4162. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4163. }
  4164. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4165. }
  4166. },
  4167. arc: function(x, y, r, a0, a1, ccw) {
  4168. x = +x, y = +y, r = +r;
  4169. var dx = r * Math.cos(a0),
  4170. dy = r * Math.sin(a0),
  4171. x0 = x + dx,
  4172. y0 = y + dy,
  4173. cw = 1 ^ ccw,
  4174. da = ccw ? a0 - a1 : a1 - a0;
  4175. // Is the radius negative? Error.
  4176. if (r < 0) throw new Error("negative radius: " + r);
  4177. // Is this path empty? Move to (x0,y0).
  4178. if (this._x1 === null) {
  4179. this._ += "M" + x0 + "," + y0;
  4180. }
  4181. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4182. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4183. this._ += "L" + x0 + "," + y0;
  4184. }
  4185. // Is this arc empty? We’re done.
  4186. if (!r) return;
  4187. // Does the angle go the wrong way? Flip the direction.
  4188. if (da < 0) da = da % tau$2 + tau$2;
  4189. // Is this a complete circle? Draw two arcs to complete the circle.
  4190. if (da > tauEpsilon) {
  4191. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4192. }
  4193. // Is this arc non-empty? Draw an arc!
  4194. else if (da > epsilon$1) {
  4195. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4196. }
  4197. },
  4198. rect: function(x, y, w, h) {
  4199. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4200. },
  4201. toString: function() {
  4202. return this._;
  4203. }
  4204. };
  4205. function defaultSource(d) {
  4206. return d.source;
  4207. }
  4208. function defaultTarget(d) {
  4209. return d.target;
  4210. }
  4211. function defaultRadius(d) {
  4212. return d.radius;
  4213. }
  4214. function defaultStartAngle(d) {
  4215. return d.startAngle;
  4216. }
  4217. function defaultEndAngle(d) {
  4218. return d.endAngle;
  4219. }
  4220. var ribbon = function() {
  4221. var source = defaultSource,
  4222. target = defaultTarget,
  4223. radius = defaultRadius,
  4224. startAngle = defaultStartAngle,
  4225. endAngle = defaultEndAngle,
  4226. context = null;
  4227. function ribbon() {
  4228. var buffer,
  4229. argv = slice$2.call(arguments),
  4230. s = source.apply(this, argv),
  4231. t = target.apply(this, argv),
  4232. sr = +radius.apply(this, (argv[0] = s, argv)),
  4233. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4234. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4235. sx0 = sr * cos(sa0),
  4236. sy0 = sr * sin(sa0),
  4237. tr = +radius.apply(this, (argv[0] = t, argv)),
  4238. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4239. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4240. if (!context) context = buffer = path();
  4241. context.moveTo(sx0, sy0);
  4242. context.arc(0, 0, sr, sa0, sa1);
  4243. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4244. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4245. context.arc(0, 0, tr, ta0, ta1);
  4246. }
  4247. context.quadraticCurveTo(0, 0, sx0, sy0);
  4248. context.closePath();
  4249. if (buffer) return context = null, buffer + "" || null;
  4250. }
  4251. ribbon.radius = function(_) {
  4252. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4253. };
  4254. ribbon.startAngle = function(_) {
  4255. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4256. };
  4257. ribbon.endAngle = function(_) {
  4258. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4259. };
  4260. ribbon.source = function(_) {
  4261. return arguments.length ? (source = _, ribbon) : source;
  4262. };
  4263. ribbon.target = function(_) {
  4264. return arguments.length ? (target = _, ribbon) : target;
  4265. };
  4266. ribbon.context = function(_) {
  4267. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  4268. };
  4269. return ribbon;
  4270. };
  4271. var prefix = "$";
  4272. function Map() {}
  4273. Map.prototype = map$1.prototype = {
  4274. constructor: Map,
  4275. has: function(key) {
  4276. return (prefix + key) in this;
  4277. },
  4278. get: function(key) {
  4279. return this[prefix + key];
  4280. },
  4281. set: function(key, value) {
  4282. this[prefix + key] = value;
  4283. return this;
  4284. },
  4285. remove: function(key) {
  4286. var property = prefix + key;
  4287. return property in this && delete this[property];
  4288. },
  4289. clear: function() {
  4290. for (var property in this) if (property[0] === prefix) delete this[property];
  4291. },
  4292. keys: function() {
  4293. var keys = [];
  4294. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4295. return keys;
  4296. },
  4297. values: function() {
  4298. var values = [];
  4299. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4300. return values;
  4301. },
  4302. entries: function() {
  4303. var entries = [];
  4304. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4305. return entries;
  4306. },
  4307. size: function() {
  4308. var size = 0;
  4309. for (var property in this) if (property[0] === prefix) ++size;
  4310. return size;
  4311. },
  4312. empty: function() {
  4313. for (var property in this) if (property[0] === prefix) return false;
  4314. return true;
  4315. },
  4316. each: function(f) {
  4317. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4318. }
  4319. };
  4320. function map$1(object, f) {
  4321. var map = new Map;
  4322. // Copy constructor.
  4323. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4324. // Index array by numeric index or specified key function.
  4325. else if (Array.isArray(object)) {
  4326. var i = -1,
  4327. n = object.length,
  4328. o;
  4329. if (f == null) while (++i < n) map.set(i, object[i]);
  4330. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4331. }
  4332. // Convert object to map.
  4333. else if (object) for (var key in object) map.set(key, object[key]);
  4334. return map;
  4335. }
  4336. var nest = function() {
  4337. var keys = [],
  4338. sortKeys = [],
  4339. sortValues,
  4340. rollup,
  4341. nest;
  4342. function apply(array, depth, createResult, setResult) {
  4343. if (depth >= keys.length) {
  4344. if (sortValues != null) array.sort(sortValues);
  4345. return rollup != null ? rollup(array) : array;
  4346. }
  4347. var i = -1,
  4348. n = array.length,
  4349. key = keys[depth++],
  4350. keyValue,
  4351. value,
  4352. valuesByKey = map$1(),
  4353. values,
  4354. result = createResult();
  4355. while (++i < n) {
  4356. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4357. values.push(value);
  4358. } else {
  4359. valuesByKey.set(keyValue, [value]);
  4360. }
  4361. }
  4362. valuesByKey.each(function(values, key) {
  4363. setResult(result, key, apply(values, depth, createResult, setResult));
  4364. });
  4365. return result;
  4366. }
  4367. function entries(map, depth) {
  4368. if (++depth > keys.length) return map;
  4369. var array, sortKey = sortKeys[depth - 1];
  4370. if (rollup != null && depth >= keys.length) array = map.entries();
  4371. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4372. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4373. }
  4374. return nest = {
  4375. object: function(array) { return apply(array, 0, createObject, setObject); },
  4376. map: function(array) { return apply(array, 0, createMap, setMap); },
  4377. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4378. key: function(d) { keys.push(d); return nest; },
  4379. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4380. sortValues: function(order) { sortValues = order; return nest; },
  4381. rollup: function(f) { rollup = f; return nest; }
  4382. };
  4383. };
  4384. function createObject() {
  4385. return {};
  4386. }
  4387. function setObject(object, key, value) {
  4388. object[key] = value;
  4389. }
  4390. function createMap() {
  4391. return map$1();
  4392. }
  4393. function setMap(map, key, value) {
  4394. map.set(key, value);
  4395. }
  4396. function Set() {}
  4397. var proto = map$1.prototype;
  4398. Set.prototype = set$2.prototype = {
  4399. constructor: Set,
  4400. has: proto.has,
  4401. add: function(value) {
  4402. value += "";
  4403. this[prefix + value] = value;
  4404. return this;
  4405. },
  4406. remove: proto.remove,
  4407. clear: proto.clear,
  4408. values: proto.keys,
  4409. size: proto.size,
  4410. empty: proto.empty,
  4411. each: proto.each
  4412. };
  4413. function set$2(object, f) {
  4414. var set = new Set;
  4415. // Copy constructor.
  4416. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4417. // Otherwise, assume it’s an array.
  4418. else if (object) {
  4419. var i = -1, n = object.length;
  4420. if (f == null) while (++i < n) set.add(object[i]);
  4421. else while (++i < n) set.add(f(object[i], i, object));
  4422. }
  4423. return set;
  4424. }
  4425. var keys = function(map) {
  4426. var keys = [];
  4427. for (var key in map) keys.push(key);
  4428. return keys;
  4429. };
  4430. var values = function(map) {
  4431. var values = [];
  4432. for (var key in map) values.push(map[key]);
  4433. return values;
  4434. };
  4435. var entries = function(map) {
  4436. var entries = [];
  4437. for (var key in map) entries.push({key: key, value: map[key]});
  4438. return entries;
  4439. };
  4440. var EOL = {};
  4441. var EOF = {};
  4442. var QUOTE = 34;
  4443. var NEWLINE = 10;
  4444. var RETURN = 13;
  4445. function objectConverter(columns) {
  4446. return new Function("d", "return {" + columns.map(function(name, i) {
  4447. return JSON.stringify(name) + ": d[" + i + "]";
  4448. }).join(",") + "}");
  4449. }
  4450. function customConverter(columns, f) {
  4451. var object = objectConverter(columns);
  4452. return function(row, i) {
  4453. return f(object(row), i, columns);
  4454. };
  4455. }
  4456. // Compute unique columns in order of discovery.
  4457. function inferColumns(rows) {
  4458. var columnSet = Object.create(null),
  4459. columns = [];
  4460. rows.forEach(function(row) {
  4461. for (var column in row) {
  4462. if (!(column in columnSet)) {
  4463. columns.push(columnSet[column] = column);
  4464. }
  4465. }
  4466. });
  4467. return columns;
  4468. }
  4469. var dsv = function(delimiter) {
  4470. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  4471. DELIMITER = delimiter.charCodeAt(0);
  4472. function parse(text, f) {
  4473. var convert, columns, rows = parseRows(text, function(row, i) {
  4474. if (convert) return convert(row, i - 1);
  4475. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  4476. });
  4477. rows.columns = columns;
  4478. return rows;
  4479. }
  4480. function parseRows(text, f) {
  4481. var rows = [], // output rows
  4482. N = text.length,
  4483. I = 0, // current character index
  4484. n = 0, // current line number
  4485. t, // current token
  4486. eof = N <= 0, // current token followed by EOF?
  4487. eol = false; // current token followed by EOL?
  4488. // Strip the trailing newline.
  4489. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  4490. if (text.charCodeAt(N - 1) === RETURN) --N;
  4491. function token() {
  4492. if (eof) return EOF;
  4493. if (eol) return eol = false, EOL;
  4494. // Unescape quotes.
  4495. var i, j = I, c;
  4496. if (text.charCodeAt(j) === QUOTE) {
  4497. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  4498. if ((i = I) >= N) eof = true;
  4499. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  4500. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4501. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  4502. }
  4503. // Find next delimiter or newline.
  4504. while (I < N) {
  4505. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  4506. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4507. else if (c !== DELIMITER) continue;
  4508. return text.slice(j, i);
  4509. }
  4510. // Return last token before EOF.
  4511. return eof = true, text.slice(j, N);
  4512. }
  4513. while ((t = token()) !== EOF) {
  4514. var row = [];
  4515. while (t !== EOL && t !== EOF) row.push(t), t = token();
  4516. if (f && (row = f(row, n++)) == null) continue;
  4517. rows.push(row);
  4518. }
  4519. return rows;
  4520. }
  4521. function format(rows, columns) {
  4522. if (columns == null) columns = inferColumns(rows);
  4523. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4524. return columns.map(function(column) {
  4525. return formatValue(row[column]);
  4526. }).join(delimiter);
  4527. })).join("\n");
  4528. }
  4529. function formatRows(rows) {
  4530. return rows.map(formatRow).join("\n");
  4531. }
  4532. function formatRow(row) {
  4533. return row.map(formatValue).join(delimiter);
  4534. }
  4535. function formatValue(text) {
  4536. return text == null ? ""
  4537. : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
  4538. : text;
  4539. }
  4540. return {
  4541. parse: parse,
  4542. parseRows: parseRows,
  4543. format: format,
  4544. formatRows: formatRows
  4545. };
  4546. };
  4547. var csv = dsv(",");
  4548. var csvParse = csv.parse;
  4549. var csvParseRows = csv.parseRows;
  4550. var csvFormat = csv.format;
  4551. var csvFormatRows = csv.formatRows;
  4552. var tsv = dsv("\t");
  4553. var tsvParse = tsv.parse;
  4554. var tsvParseRows = tsv.parseRows;
  4555. var tsvFormat = tsv.format;
  4556. var tsvFormatRows = tsv.formatRows;
  4557. var center$1 = function(x, y) {
  4558. var nodes;
  4559. if (x == null) x = 0;
  4560. if (y == null) y = 0;
  4561. function force() {
  4562. var i,
  4563. n = nodes.length,
  4564. node,
  4565. sx = 0,
  4566. sy = 0;
  4567. for (i = 0; i < n; ++i) {
  4568. node = nodes[i], sx += node.x, sy += node.y;
  4569. }
  4570. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  4571. node = nodes[i], node.x -= sx, node.y -= sy;
  4572. }
  4573. }
  4574. force.initialize = function(_) {
  4575. nodes = _;
  4576. };
  4577. force.x = function(_) {
  4578. return arguments.length ? (x = +_, force) : x;
  4579. };
  4580. force.y = function(_) {
  4581. return arguments.length ? (y = +_, force) : y;
  4582. };
  4583. return force;
  4584. };
  4585. var constant$6 = function(x) {
  4586. return function() {
  4587. return x;
  4588. };
  4589. };
  4590. var jiggle = function() {
  4591. return (Math.random() - 0.5) * 1e-6;
  4592. };
  4593. var tree_add = function(d) {
  4594. var x = +this._x.call(null, d),
  4595. y = +this._y.call(null, d);
  4596. return add(this.cover(x, y), x, y, d);
  4597. };
  4598. function add(tree, x, y, d) {
  4599. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  4600. var parent,
  4601. node = tree._root,
  4602. leaf = {data: d},
  4603. x0 = tree._x0,
  4604. y0 = tree._y0,
  4605. x1 = tree._x1,
  4606. y1 = tree._y1,
  4607. xm,
  4608. ym,
  4609. xp,
  4610. yp,
  4611. right,
  4612. bottom,
  4613. i,
  4614. j;
  4615. // If the tree is empty, initialize the root as a leaf.
  4616. if (!node) return tree._root = leaf, tree;
  4617. // Find the existing leaf for the new point, or add it.
  4618. while (node.length) {
  4619. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4620. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4621. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  4622. }
  4623. // Is the new point is exactly coincident with the existing point?
  4624. xp = +tree._x.call(null, node.data);
  4625. yp = +tree._y.call(null, node.data);
  4626. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  4627. // Otherwise, split the leaf node until the old and new point are separated.
  4628. do {
  4629. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  4630. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4631. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4632. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  4633. return parent[j] = node, parent[i] = leaf, tree;
  4634. }
  4635. function addAll(data) {
  4636. var d, i, n = data.length,
  4637. x,
  4638. y,
  4639. xz = new Array(n),
  4640. yz = new Array(n),
  4641. x0 = Infinity,
  4642. y0 = Infinity,
  4643. x1 = -Infinity,
  4644. y1 = -Infinity;
  4645. // Compute the points and their extent.
  4646. for (i = 0; i < n; ++i) {
  4647. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  4648. xz[i] = x;
  4649. yz[i] = y;
  4650. if (x < x0) x0 = x;
  4651. if (x > x1) x1 = x;
  4652. if (y < y0) y0 = y;
  4653. if (y > y1) y1 = y;
  4654. }
  4655. // If there were no (valid) points, inherit the existing extent.
  4656. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  4657. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  4658. // Expand the tree to cover the new points.
  4659. this.cover(x0, y0).cover(x1, y1);
  4660. // Add the new points.
  4661. for (i = 0; i < n; ++i) {
  4662. add(this, xz[i], yz[i], data[i]);
  4663. }
  4664. return this;
  4665. }
  4666. var tree_cover = function(x, y) {
  4667. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  4668. var x0 = this._x0,
  4669. y0 = this._y0,
  4670. x1 = this._x1,
  4671. y1 = this._y1;
  4672. // If the quadtree has no extent, initialize them.
  4673. // Integer extent are necessary so that if we later double the extent,
  4674. // the existing quadrant boundaries don’t change due to floating point error!
  4675. if (isNaN(x0)) {
  4676. x1 = (x0 = Math.floor(x)) + 1;
  4677. y1 = (y0 = Math.floor(y)) + 1;
  4678. }
  4679. // Otherwise, double repeatedly to cover.
  4680. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  4681. var z = x1 - x0,
  4682. node = this._root,
  4683. parent,
  4684. i;
  4685. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  4686. case 0: {
  4687. do parent = new Array(4), parent[i] = node, node = parent;
  4688. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  4689. break;
  4690. }
  4691. case 1: {
  4692. do parent = new Array(4), parent[i] = node, node = parent;
  4693. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  4694. break;
  4695. }
  4696. case 2: {
  4697. do parent = new Array(4), parent[i] = node, node = parent;
  4698. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  4699. break;
  4700. }
  4701. case 3: {
  4702. do parent = new Array(4), parent[i] = node, node = parent;
  4703. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  4704. break;
  4705. }
  4706. }
  4707. if (this._root && this._root.length) this._root = node;
  4708. }
  4709. // If the quadtree covers the point already, just return.
  4710. else return this;
  4711. this._x0 = x0;
  4712. this._y0 = y0;
  4713. this._x1 = x1;
  4714. this._y1 = y1;
  4715. return this;
  4716. };
  4717. var tree_data = function() {
  4718. var data = [];
  4719. this.visit(function(node) {
  4720. if (!node.length) do data.push(node.data); while (node = node.next)
  4721. });
  4722. return data;
  4723. };
  4724. var tree_extent = function(_) {
  4725. return arguments.length
  4726. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  4727. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  4728. };
  4729. var Quad = function(node, x0, y0, x1, y1) {
  4730. this.node = node;
  4731. this.x0 = x0;
  4732. this.y0 = y0;
  4733. this.x1 = x1;
  4734. this.y1 = y1;
  4735. };
  4736. var tree_find = function(x, y, radius) {
  4737. var data,
  4738. x0 = this._x0,
  4739. y0 = this._y0,
  4740. x1,
  4741. y1,
  4742. x2,
  4743. y2,
  4744. x3 = this._x1,
  4745. y3 = this._y1,
  4746. quads = [],
  4747. node = this._root,
  4748. q,
  4749. i;
  4750. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  4751. if (radius == null) radius = Infinity;
  4752. else {
  4753. x0 = x - radius, y0 = y - radius;
  4754. x3 = x + radius, y3 = y + radius;
  4755. radius *= radius;
  4756. }
  4757. while (q = quads.pop()) {
  4758. // Stop searching if this quadrant can’t contain a closer node.
  4759. if (!(node = q.node)
  4760. || (x1 = q.x0) > x3
  4761. || (y1 = q.y0) > y3
  4762. || (x2 = q.x1) < x0
  4763. || (y2 = q.y1) < y0) continue;
  4764. // Bisect the current quadrant.
  4765. if (node.length) {
  4766. var xm = (x1 + x2) / 2,
  4767. ym = (y1 + y2) / 2;
  4768. quads.push(
  4769. new Quad(node[3], xm, ym, x2, y2),
  4770. new Quad(node[2], x1, ym, xm, y2),
  4771. new Quad(node[1], xm, y1, x2, ym),
  4772. new Quad(node[0], x1, y1, xm, ym)
  4773. );
  4774. // Visit the closest quadrant first.
  4775. if (i = (y >= ym) << 1 | (x >= xm)) {
  4776. q = quads[quads.length - 1];
  4777. quads[quads.length - 1] = quads[quads.length - 1 - i];
  4778. quads[quads.length - 1 - i] = q;
  4779. }
  4780. }
  4781. // Visit this point. (Visiting coincident points isn’t necessary!)
  4782. else {
  4783. var dx = x - +this._x.call(null, node.data),
  4784. dy = y - +this._y.call(null, node.data),
  4785. d2 = dx * dx + dy * dy;
  4786. if (d2 < radius) {
  4787. var d = Math.sqrt(radius = d2);
  4788. x0 = x - d, y0 = y - d;
  4789. x3 = x + d, y3 = y + d;
  4790. data = node.data;
  4791. }
  4792. }
  4793. }
  4794. return data;
  4795. };
  4796. var tree_remove = function(d) {
  4797. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  4798. var parent,
  4799. node = this._root,
  4800. retainer,
  4801. previous,
  4802. next,
  4803. x0 = this._x0,
  4804. y0 = this._y0,
  4805. x1 = this._x1,
  4806. y1 = this._y1,
  4807. x,
  4808. y,
  4809. xm,
  4810. ym,
  4811. right,
  4812. bottom,
  4813. i,
  4814. j;
  4815. // If the tree is empty, initialize the root as a leaf.
  4816. if (!node) return this;
  4817. // Find the leaf node for the point.
  4818. // While descending, also retain the deepest parent with a non-removed sibling.
  4819. if (node.length) while (true) {
  4820. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4821. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4822. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  4823. if (!node.length) break;
  4824. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  4825. }
  4826. // Find the point to remove.
  4827. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  4828. if (next = node.next) delete node.next;
  4829. // If there are multiple coincident points, remove just the point.
  4830. if (previous) return (next ? previous.next = next : delete previous.next), this;
  4831. // If this is the root point, remove it.
  4832. if (!parent) return this._root = next, this;
  4833. // Remove this leaf.
  4834. next ? parent[i] = next : delete parent[i];
  4835. // If the parent now contains exactly one leaf, collapse superfluous parents.
  4836. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  4837. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  4838. && !node.length) {
  4839. if (retainer) retainer[j] = node;
  4840. else this._root = node;
  4841. }
  4842. return this;
  4843. };
  4844. function removeAll(data) {
  4845. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  4846. return this;
  4847. }
  4848. var tree_root = function() {
  4849. return this._root;
  4850. };
  4851. var tree_size = function() {
  4852. var size = 0;
  4853. this.visit(function(node) {
  4854. if (!node.length) do ++size; while (node = node.next)
  4855. });
  4856. return size;
  4857. };
  4858. var tree_visit = function(callback) {
  4859. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  4860. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  4861. while (q = quads.pop()) {
  4862. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  4863. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  4864. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  4865. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  4866. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  4867. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  4868. }
  4869. }
  4870. return this;
  4871. };
  4872. var tree_visitAfter = function(callback) {
  4873. var quads = [], next = [], q;
  4874. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  4875. while (q = quads.pop()) {
  4876. var node = q.node;
  4877. if (node.length) {
  4878. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  4879. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  4880. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  4881. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  4882. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  4883. }
  4884. next.push(q);
  4885. }
  4886. while (q = next.pop()) {
  4887. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  4888. }
  4889. return this;
  4890. };
  4891. function defaultX(d) {
  4892. return d[0];
  4893. }
  4894. var tree_x = function(_) {
  4895. return arguments.length ? (this._x = _, this) : this._x;
  4896. };
  4897. function defaultY(d) {
  4898. return d[1];
  4899. }
  4900. var tree_y = function(_) {
  4901. return arguments.length ? (this._y = _, this) : this._y;
  4902. };
  4903. function quadtree(nodes, x, y) {
  4904. var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
  4905. return nodes == null ? tree : tree.addAll(nodes);
  4906. }
  4907. function Quadtree(x, y, x0, y0, x1, y1) {
  4908. this._x = x;
  4909. this._y = y;
  4910. this._x0 = x0;
  4911. this._y0 = y0;
  4912. this._x1 = x1;
  4913. this._y1 = y1;
  4914. this._root = undefined;
  4915. }
  4916. function leaf_copy(leaf) {
  4917. var copy = {data: leaf.data}, next = copy;
  4918. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  4919. return copy;
  4920. }
  4921. var treeProto = quadtree.prototype = Quadtree.prototype;
  4922. treeProto.copy = function() {
  4923. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  4924. node = this._root,
  4925. nodes,
  4926. child;
  4927. if (!node) return copy;
  4928. if (!node.length) return copy._root = leaf_copy(node), copy;
  4929. nodes = [{source: node, target: copy._root = new Array(4)}];
  4930. while (node = nodes.pop()) {
  4931. for (var i = 0; i < 4; ++i) {
  4932. if (child = node.source[i]) {
  4933. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  4934. else node.target[i] = leaf_copy(child);
  4935. }
  4936. }
  4937. }
  4938. return copy;
  4939. };
  4940. treeProto.add = tree_add;
  4941. treeProto.addAll = addAll;
  4942. treeProto.cover = tree_cover;
  4943. treeProto.data = tree_data;
  4944. treeProto.extent = tree_extent;
  4945. treeProto.find = tree_find;
  4946. treeProto.remove = tree_remove;
  4947. treeProto.removeAll = removeAll;
  4948. treeProto.root = tree_root;
  4949. treeProto.size = tree_size;
  4950. treeProto.visit = tree_visit;
  4951. treeProto.visitAfter = tree_visitAfter;
  4952. treeProto.x = tree_x;
  4953. treeProto.y = tree_y;
  4954. function x$1(d) {
  4955. return d.x + d.vx;
  4956. }
  4957. function y(d) {
  4958. return d.y + d.vy;
  4959. }
  4960. var collide = function(radius) {
  4961. var nodes,
  4962. radii,
  4963. strength = 1,
  4964. iterations = 1;
  4965. if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
  4966. function force() {
  4967. var i, n = nodes.length,
  4968. tree,
  4969. node,
  4970. xi,
  4971. yi,
  4972. ri,
  4973. ri2;
  4974. for (var k = 0; k < iterations; ++k) {
  4975. tree = quadtree(nodes, x$1, y).visitAfter(prepare);
  4976. for (i = 0; i < n; ++i) {
  4977. node = nodes[i];
  4978. ri = radii[node.index], ri2 = ri * ri;
  4979. xi = node.x + node.vx;
  4980. yi = node.y + node.vy;
  4981. tree.visit(apply);
  4982. }
  4983. }
  4984. function apply(quad, x0, y0, x1, y1) {
  4985. var data = quad.data, rj = quad.r, r = ri + rj;
  4986. if (data) {
  4987. if (data.index > node.index) {
  4988. var x = xi - data.x - data.vx,
  4989. y = yi - data.y - data.vy,
  4990. l = x * x + y * y;
  4991. if (l < r * r) {
  4992. if (x === 0) x = jiggle(), l += x * x;
  4993. if (y === 0) y = jiggle(), l += y * y;
  4994. l = (r - (l = Math.sqrt(l))) / l * strength;
  4995. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  4996. node.vy += (y *= l) * r;
  4997. data.vx -= x * (r = 1 - r);
  4998. data.vy -= y * r;
  4999. }
  5000. }
  5001. return;
  5002. }
  5003. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5004. }
  5005. }
  5006. function prepare(quad) {
  5007. if (quad.data) return quad.r = radii[quad.data.index];
  5008. for (var i = quad.r = 0; i < 4; ++i) {
  5009. if (quad[i] && quad[i].r > quad.r) {
  5010. quad.r = quad[i].r;
  5011. }
  5012. }
  5013. }
  5014. function initialize() {
  5015. if (!nodes) return;
  5016. var i, n = nodes.length, node;
  5017. radii = new Array(n);
  5018. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5019. }
  5020. force.initialize = function(_) {
  5021. nodes = _;
  5022. initialize();
  5023. };
  5024. force.iterations = function(_) {
  5025. return arguments.length ? (iterations = +_, force) : iterations;
  5026. };
  5027. force.strength = function(_) {
  5028. return arguments.length ? (strength = +_, force) : strength;
  5029. };
  5030. force.radius = function(_) {
  5031. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
  5032. };
  5033. return force;
  5034. };
  5035. function index(d) {
  5036. return d.index;
  5037. }
  5038. function find(nodeById, nodeId) {
  5039. var node = nodeById.get(nodeId);
  5040. if (!node) throw new Error("missing: " + nodeId);
  5041. return node;
  5042. }
  5043. var link = function(links) {
  5044. var id = index,
  5045. strength = defaultStrength,
  5046. strengths,
  5047. distance = constant$6(30),
  5048. distances,
  5049. nodes,
  5050. count,
  5051. bias,
  5052. iterations = 1;
  5053. if (links == null) links = [];
  5054. function defaultStrength(link) {
  5055. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5056. }
  5057. function force(alpha) {
  5058. for (var k = 0, n = links.length; k < iterations; ++k) {
  5059. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5060. link = links[i], source = link.source, target = link.target;
  5061. x = target.x + target.vx - source.x - source.vx || jiggle();
  5062. y = target.y + target.vy - source.y - source.vy || jiggle();
  5063. l = Math.sqrt(x * x + y * y);
  5064. l = (l - distances[i]) / l * alpha * strengths[i];
  5065. x *= l, y *= l;
  5066. target.vx -= x * (b = bias[i]);
  5067. target.vy -= y * b;
  5068. source.vx += x * (b = 1 - b);
  5069. source.vy += y * b;
  5070. }
  5071. }
  5072. }
  5073. function initialize() {
  5074. if (!nodes) return;
  5075. var i,
  5076. n = nodes.length,
  5077. m = links.length,
  5078. nodeById = map$1(nodes, id),
  5079. link;
  5080. for (i = 0, count = new Array(n); i < m; ++i) {
  5081. link = links[i], link.index = i;
  5082. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5083. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5084. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5085. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5086. }
  5087. for (i = 0, bias = new Array(m); i < m; ++i) {
  5088. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5089. }
  5090. strengths = new Array(m), initializeStrength();
  5091. distances = new Array(m), initializeDistance();
  5092. }
  5093. function initializeStrength() {
  5094. if (!nodes) return;
  5095. for (var i = 0, n = links.length; i < n; ++i) {
  5096. strengths[i] = +strength(links[i], i, links);
  5097. }
  5098. }
  5099. function initializeDistance() {
  5100. if (!nodes) return;
  5101. for (var i = 0, n = links.length; i < n; ++i) {
  5102. distances[i] = +distance(links[i], i, links);
  5103. }
  5104. }
  5105. force.initialize = function(_) {
  5106. nodes = _;
  5107. initialize();
  5108. };
  5109. force.links = function(_) {
  5110. return arguments.length ? (links = _, initialize(), force) : links;
  5111. };
  5112. force.id = function(_) {
  5113. return arguments.length ? (id = _, force) : id;
  5114. };
  5115. force.iterations = function(_) {
  5116. return arguments.length ? (iterations = +_, force) : iterations;
  5117. };
  5118. force.strength = function(_) {
  5119. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
  5120. };
  5121. force.distance = function(_) {
  5122. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
  5123. };
  5124. return force;
  5125. };
  5126. function x$2(d) {
  5127. return d.x;
  5128. }
  5129. function y$1(d) {
  5130. return d.y;
  5131. }
  5132. var initialRadius = 10;
  5133. var initialAngle = Math.PI * (3 - Math.sqrt(5));
  5134. var simulation = function(nodes) {
  5135. var simulation,
  5136. alpha = 1,
  5137. alphaMin = 0.001,
  5138. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5139. alphaTarget = 0,
  5140. velocityDecay = 0.6,
  5141. forces = map$1(),
  5142. stepper = timer(step),
  5143. event = dispatch("tick", "end");
  5144. if (nodes == null) nodes = [];
  5145. function step() {
  5146. tick();
  5147. event.call("tick", simulation);
  5148. if (alpha < alphaMin) {
  5149. stepper.stop();
  5150. event.call("end", simulation);
  5151. }
  5152. }
  5153. function tick() {
  5154. var i, n = nodes.length, node;
  5155. alpha += (alphaTarget - alpha) * alphaDecay;
  5156. forces.each(function(force) {
  5157. force(alpha);
  5158. });
  5159. for (i = 0; i < n; ++i) {
  5160. node = nodes[i];
  5161. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5162. else node.x = node.fx, node.vx = 0;
  5163. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5164. else node.y = node.fy, node.vy = 0;
  5165. }
  5166. }
  5167. function initializeNodes() {
  5168. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5169. node = nodes[i], node.index = i;
  5170. if (isNaN(node.x) || isNaN(node.y)) {
  5171. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5172. node.x = radius * Math.cos(angle);
  5173. node.y = radius * Math.sin(angle);
  5174. }
  5175. if (isNaN(node.vx) || isNaN(node.vy)) {
  5176. node.vx = node.vy = 0;
  5177. }
  5178. }
  5179. }
  5180. function initializeForce(force) {
  5181. if (force.initialize) force.initialize(nodes);
  5182. return force;
  5183. }
  5184. initializeNodes();
  5185. return simulation = {
  5186. tick: tick,
  5187. restart: function() {
  5188. return stepper.restart(step), simulation;
  5189. },
  5190. stop: function() {
  5191. return stepper.stop(), simulation;
  5192. },
  5193. nodes: function(_) {
  5194. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5195. },
  5196. alpha: function(_) {
  5197. return arguments.length ? (alpha = +_, simulation) : alpha;
  5198. },
  5199. alphaMin: function(_) {
  5200. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5201. },
  5202. alphaDecay: function(_) {
  5203. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5204. },
  5205. alphaTarget: function(_) {
  5206. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5207. },
  5208. velocityDecay: function(_) {
  5209. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5210. },
  5211. force: function(name, _) {
  5212. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  5213. },
  5214. find: function(x, y, radius) {
  5215. var i = 0,
  5216. n = nodes.length,
  5217. dx,
  5218. dy,
  5219. d2,
  5220. node,
  5221. closest;
  5222. if (radius == null) radius = Infinity;
  5223. else radius *= radius;
  5224. for (i = 0; i < n; ++i) {
  5225. node = nodes[i];
  5226. dx = x - node.x;
  5227. dy = y - node.y;
  5228. d2 = dx * dx + dy * dy;
  5229. if (d2 < radius) closest = node, radius = d2;
  5230. }
  5231. return closest;
  5232. },
  5233. on: function(name, _) {
  5234. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5235. }
  5236. };
  5237. };
  5238. var manyBody = function() {
  5239. var nodes,
  5240. node,
  5241. alpha,
  5242. strength = constant$6(-30),
  5243. strengths,
  5244. distanceMin2 = 1,
  5245. distanceMax2 = Infinity,
  5246. theta2 = 0.81;
  5247. function force(_) {
  5248. var i, n = nodes.length, tree = quadtree(nodes, x$2, y$1).visitAfter(accumulate);
  5249. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5250. }
  5251. function initialize() {
  5252. if (!nodes) return;
  5253. var i, n = nodes.length, node;
  5254. strengths = new Array(n);
  5255. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5256. }
  5257. function accumulate(quad) {
  5258. var strength = 0, q, c, x, y, i;
  5259. // For internal nodes, accumulate forces from child quadrants.
  5260. if (quad.length) {
  5261. for (x = y = i = 0; i < 4; ++i) {
  5262. if ((q = quad[i]) && (c = q.value)) {
  5263. strength += c, x += c * q.x, y += c * q.y;
  5264. }
  5265. }
  5266. quad.x = x / strength;
  5267. quad.y = y / strength;
  5268. }
  5269. // For leaf nodes, accumulate forces from coincident quadrants.
  5270. else {
  5271. q = quad;
  5272. q.x = q.data.x;
  5273. q.y = q.data.y;
  5274. do strength += strengths[q.data.index];
  5275. while (q = q.next);
  5276. }
  5277. quad.value = strength;
  5278. }
  5279. function apply(quad, x1, _, x2) {
  5280. if (!quad.value) return true;
  5281. var x = quad.x - node.x,
  5282. y = quad.y - node.y,
  5283. w = x2 - x1,
  5284. l = x * x + y * y;
  5285. // Apply the Barnes-Hut approximation if possible.
  5286. // Limit forces for very close nodes; randomize direction if coincident.
  5287. if (w * w / theta2 < l) {
  5288. if (l < distanceMax2) {
  5289. if (x === 0) x = jiggle(), l += x * x;
  5290. if (y === 0) y = jiggle(), l += y * y;
  5291. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5292. node.vx += x * quad.value * alpha / l;
  5293. node.vy += y * quad.value * alpha / l;
  5294. }
  5295. return true;
  5296. }
  5297. // Otherwise, process points directly.
  5298. else if (quad.length || l >= distanceMax2) return;
  5299. // Limit forces for very close nodes; randomize direction if coincident.
  5300. if (quad.data !== node || quad.next) {
  5301. if (x === 0) x = jiggle(), l += x * x;
  5302. if (y === 0) y = jiggle(), l += y * y;
  5303. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5304. }
  5305. do if (quad.data !== node) {
  5306. w = strengths[quad.data.index] * alpha / l;
  5307. node.vx += x * w;
  5308. node.vy += y * w;
  5309. } while (quad = quad.next);
  5310. }
  5311. force.initialize = function(_) {
  5312. nodes = _;
  5313. initialize();
  5314. };
  5315. force.strength = function(_) {
  5316. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5317. };
  5318. force.distanceMin = function(_) {
  5319. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5320. };
  5321. force.distanceMax = function(_) {
  5322. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5323. };
  5324. force.theta = function(_) {
  5325. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5326. };
  5327. return force;
  5328. };
  5329. var x$3 = function(x) {
  5330. var strength = constant$6(0.1),
  5331. nodes,
  5332. strengths,
  5333. xz;
  5334. if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
  5335. function force(alpha) {
  5336. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5337. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  5338. }
  5339. }
  5340. function initialize() {
  5341. if (!nodes) return;
  5342. var i, n = nodes.length;
  5343. strengths = new Array(n);
  5344. xz = new Array(n);
  5345. for (i = 0; i < n; ++i) {
  5346. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5347. }
  5348. }
  5349. force.initialize = function(_) {
  5350. nodes = _;
  5351. initialize();
  5352. };
  5353. force.strength = function(_) {
  5354. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5355. };
  5356. force.x = function(_) {
  5357. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
  5358. };
  5359. return force;
  5360. };
  5361. var y$2 = function(y) {
  5362. var strength = constant$6(0.1),
  5363. nodes,
  5364. strengths,
  5365. yz;
  5366. if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
  5367. function force(alpha) {
  5368. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5369. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  5370. }
  5371. }
  5372. function initialize() {
  5373. if (!nodes) return;
  5374. var i, n = nodes.length;
  5375. strengths = new Array(n);
  5376. yz = new Array(n);
  5377. for (i = 0; i < n; ++i) {
  5378. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5379. }
  5380. }
  5381. force.initialize = function(_) {
  5382. nodes = _;
  5383. initialize();
  5384. };
  5385. force.strength = function(_) {
  5386. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5387. };
  5388. force.y = function(_) {
  5389. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
  5390. };
  5391. return force;
  5392. };
  5393. // Computes the decimal coefficient and exponent of the specified number x with
  5394. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  5395. // For example, formatDecimal(1.23) returns ["123", 0].
  5396. var formatDecimal = function(x, p) {
  5397. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  5398. var i, coefficient = x.slice(0, i);
  5399. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  5400. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  5401. return [
  5402. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  5403. +x.slice(i + 1)
  5404. ];
  5405. };
  5406. var exponent$1 = function(x) {
  5407. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  5408. };
  5409. var formatGroup = function(grouping, thousands) {
  5410. return function(value, width) {
  5411. var i = value.length,
  5412. t = [],
  5413. j = 0,
  5414. g = grouping[0],
  5415. length = 0;
  5416. while (i > 0 && g > 0) {
  5417. if (length + g + 1 > width) g = Math.max(1, width - length);
  5418. t.push(value.substring(i -= g, i + g));
  5419. if ((length += g + 1) > width) break;
  5420. g = grouping[j = (j + 1) % grouping.length];
  5421. }
  5422. return t.reverse().join(thousands);
  5423. };
  5424. };
  5425. var formatNumerals = function(numerals) {
  5426. return function(value) {
  5427. return value.replace(/[0-9]/g, function(i) {
  5428. return numerals[+i];
  5429. });
  5430. };
  5431. };
  5432. var formatDefault = function(x, p) {
  5433. x = x.toPrecision(p);
  5434. out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
  5435. switch (x[i]) {
  5436. case ".": i0 = i1 = i; break;
  5437. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  5438. case "e": break out;
  5439. default: if (i0 > 0) i0 = 0; break;
  5440. }
  5441. }
  5442. return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
  5443. };
  5444. var prefixExponent;
  5445. var formatPrefixAuto = function(x, p) {
  5446. var d = formatDecimal(x, p);
  5447. if (!d) return x + "";
  5448. var coefficient = d[0],
  5449. exponent = d[1],
  5450. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  5451. n = coefficient.length;
  5452. return i === n ? coefficient
  5453. : i > n ? coefficient + new Array(i - n + 1).join("0")
  5454. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  5455. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  5456. };
  5457. var formatRounded = function(x, p) {
  5458. var d = formatDecimal(x, p);
  5459. if (!d) return x + "";
  5460. var coefficient = d[0],
  5461. exponent = d[1];
  5462. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  5463. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  5464. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  5465. };
  5466. var formatTypes = {
  5467. "": formatDefault,
  5468. "%": function(x, p) { return (x * 100).toFixed(p); },
  5469. "b": function(x) { return Math.round(x).toString(2); },
  5470. "c": function(x) { return x + ""; },
  5471. "d": function(x) { return Math.round(x).toString(10); },
  5472. "e": function(x, p) { return x.toExponential(p); },
  5473. "f": function(x, p) { return x.toFixed(p); },
  5474. "g": function(x, p) { return x.toPrecision(p); },
  5475. "o": function(x) { return Math.round(x).toString(8); },
  5476. "p": function(x, p) { return formatRounded(x * 100, p); },
  5477. "r": formatRounded,
  5478. "s": formatPrefixAuto,
  5479. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  5480. "x": function(x) { return Math.round(x).toString(16); }
  5481. };
  5482. // [[fill]align][sign][symbol][0][width][,][.precision][type]
  5483. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
  5484. function formatSpecifier(specifier) {
  5485. return new FormatSpecifier(specifier);
  5486. }
  5487. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  5488. function FormatSpecifier(specifier) {
  5489. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  5490. var match,
  5491. fill = match[1] || " ",
  5492. align = match[2] || ">",
  5493. sign = match[3] || "-",
  5494. symbol = match[4] || "",
  5495. zero = !!match[5],
  5496. width = match[6] && +match[6],
  5497. comma = !!match[7],
  5498. precision = match[8] && +match[8].slice(1),
  5499. type = match[9] || "";
  5500. // The "n" type is an alias for ",g".
  5501. if (type === "n") comma = true, type = "g";
  5502. // Map invalid types to the default format.
  5503. else if (!formatTypes[type]) type = "";
  5504. // If zero fill is specified, padding goes after sign and before digits.
  5505. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  5506. this.fill = fill;
  5507. this.align = align;
  5508. this.sign = sign;
  5509. this.symbol = symbol;
  5510. this.zero = zero;
  5511. this.width = width;
  5512. this.comma = comma;
  5513. this.precision = precision;
  5514. this.type = type;
  5515. }
  5516. FormatSpecifier.prototype.toString = function() {
  5517. return this.fill
  5518. + this.align
  5519. + this.sign
  5520. + this.symbol
  5521. + (this.zero ? "0" : "")
  5522. + (this.width == null ? "" : Math.max(1, this.width | 0))
  5523. + (this.comma ? "," : "")
  5524. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  5525. + this.type;
  5526. };
  5527. var identity$3 = function(x) {
  5528. return x;
  5529. };
  5530. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  5531. var formatLocale = function(locale) {
  5532. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  5533. currency = locale.currency,
  5534. decimal = locale.decimal,
  5535. numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
  5536. percent = locale.percent || "%";
  5537. function newFormat(specifier) {
  5538. specifier = formatSpecifier(specifier);
  5539. var fill = specifier.fill,
  5540. align = specifier.align,
  5541. sign = specifier.sign,
  5542. symbol = specifier.symbol,
  5543. zero = specifier.zero,
  5544. width = specifier.width,
  5545. comma = specifier.comma,
  5546. precision = specifier.precision,
  5547. type = specifier.type;
  5548. // Compute the prefix and suffix.
  5549. // For SI-prefix, the suffix is lazily computed.
  5550. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  5551. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
  5552. // What format function should we use?
  5553. // Is this an integer type?
  5554. // Can this type generate exponential notation?
  5555. var formatType = formatTypes[type],
  5556. maybeSuffix = !type || /[defgprs%]/.test(type);
  5557. // Set the default precision if not specified,
  5558. // or clamp the specified precision to the supported range.
  5559. // For significant precision, it must be in [1, 21].
  5560. // For fixed precision, it must be in [0, 20].
  5561. precision = precision == null ? (type ? 6 : 12)
  5562. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  5563. : Math.max(0, Math.min(20, precision));
  5564. function format(value) {
  5565. var valuePrefix = prefix,
  5566. valueSuffix = suffix,
  5567. i, n, c;
  5568. if (type === "c") {
  5569. valueSuffix = formatType(value) + valueSuffix;
  5570. value = "";
  5571. } else {
  5572. value = +value;
  5573. // Perform the initial formatting.
  5574. var valueNegative = value < 0;
  5575. value = formatType(Math.abs(value), precision);
  5576. // If a negative value rounds to zero during formatting, treat as positive.
  5577. if (valueNegative && +value === 0) valueNegative = false;
  5578. // Compute the prefix and suffix.
  5579. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  5580. valueSuffix = valueSuffix + (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + (valueNegative && sign === "(" ? ")" : "");
  5581. // Break the formatted value into the integer “value” part that can be
  5582. // grouped, and fractional or exponential “suffix” part that is not.
  5583. if (maybeSuffix) {
  5584. i = -1, n = value.length;
  5585. while (++i < n) {
  5586. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  5587. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  5588. value = value.slice(0, i);
  5589. break;
  5590. }
  5591. }
  5592. }
  5593. }
  5594. // If the fill character is not "0", grouping is applied before padding.
  5595. if (comma && !zero) value = group(value, Infinity);
  5596. // Compute the padding.
  5597. var length = valuePrefix.length + value.length + valueSuffix.length,
  5598. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  5599. // If the fill character is "0", grouping is applied after padding.
  5600. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  5601. // Reconstruct the final output based on the desired alignment.
  5602. switch (align) {
  5603. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  5604. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  5605. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  5606. default: value = padding + valuePrefix + value + valueSuffix; break;
  5607. }
  5608. return numerals(value);
  5609. }
  5610. format.toString = function() {
  5611. return specifier + "";
  5612. };
  5613. return format;
  5614. }
  5615. function formatPrefix(specifier, value) {
  5616. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  5617. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  5618. k = Math.pow(10, -e),
  5619. prefix = prefixes[8 + e / 3];
  5620. return function(value) {
  5621. return f(k * value) + prefix;
  5622. };
  5623. }
  5624. return {
  5625. format: newFormat,
  5626. formatPrefix: formatPrefix
  5627. };
  5628. };
  5629. var locale$1;
  5630. defaultLocale({
  5631. decimal: ".",
  5632. thousands: ",",
  5633. grouping: [3],
  5634. currency: ["$", ""]
  5635. });
  5636. function defaultLocale(definition) {
  5637. locale$1 = formatLocale(definition);
  5638. exports.format = locale$1.format;
  5639. exports.formatPrefix = locale$1.formatPrefix;
  5640. return locale$1;
  5641. }
  5642. var precisionFixed = function(step) {
  5643. return Math.max(0, -exponent$1(Math.abs(step)));
  5644. };
  5645. var precisionPrefix = function(step, value) {
  5646. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  5647. };
  5648. var precisionRound = function(step, max) {
  5649. step = Math.abs(step), max = Math.abs(max) - step;
  5650. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  5651. };
  5652. // Adds floating point numbers with twice the normal precision.
  5653. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  5654. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  5655. // 305–363 (1997).
  5656. // Code adapted from GeographicLib by Charles F. F. Karney,
  5657. // http://geographiclib.sourceforge.net/
  5658. var adder = function() {
  5659. return new Adder;
  5660. };
  5661. function Adder() {
  5662. this.reset();
  5663. }
  5664. Adder.prototype = {
  5665. constructor: Adder,
  5666. reset: function() {
  5667. this.s = // rounded value
  5668. this.t = 0; // exact error
  5669. },
  5670. add: function(y) {
  5671. add$1(temp, y, this.t);
  5672. add$1(this, temp.s, this.s);
  5673. if (this.s) this.t += temp.t;
  5674. else this.s = temp.t;
  5675. },
  5676. valueOf: function() {
  5677. return this.s;
  5678. }
  5679. };
  5680. var temp = new Adder;
  5681. function add$1(adder, a, b) {
  5682. var x = adder.s = a + b,
  5683. bv = x - a,
  5684. av = x - bv;
  5685. adder.t = (a - av) + (b - bv);
  5686. }
  5687. var epsilon$2 = 1e-6;
  5688. var epsilon2$1 = 1e-12;
  5689. var pi$3 = Math.PI;
  5690. var halfPi$2 = pi$3 / 2;
  5691. var quarterPi = pi$3 / 4;
  5692. var tau$3 = pi$3 * 2;
  5693. var degrees$1 = 180 / pi$3;
  5694. var radians = pi$3 / 180;
  5695. var abs = Math.abs;
  5696. var atan = Math.atan;
  5697. var atan2 = Math.atan2;
  5698. var cos$1 = Math.cos;
  5699. var ceil = Math.ceil;
  5700. var exp = Math.exp;
  5701. var log = Math.log;
  5702. var pow = Math.pow;
  5703. var sin$1 = Math.sin;
  5704. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  5705. var sqrt = Math.sqrt;
  5706. var tan = Math.tan;
  5707. function acos(x) {
  5708. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  5709. }
  5710. function asin(x) {
  5711. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  5712. }
  5713. function haversin(x) {
  5714. return (x = sin$1(x / 2)) * x;
  5715. }
  5716. function noop$1() {}
  5717. function streamGeometry(geometry, stream) {
  5718. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  5719. streamGeometryType[geometry.type](geometry, stream);
  5720. }
  5721. }
  5722. var streamObjectType = {
  5723. Feature: function(object, stream) {
  5724. streamGeometry(object.geometry, stream);
  5725. },
  5726. FeatureCollection: function(object, stream) {
  5727. var features = object.features, i = -1, n = features.length;
  5728. while (++i < n) streamGeometry(features[i].geometry, stream);
  5729. }
  5730. };
  5731. var streamGeometryType = {
  5732. Sphere: function(object, stream) {
  5733. stream.sphere();
  5734. },
  5735. Point: function(object, stream) {
  5736. object = object.coordinates;
  5737. stream.point(object[0], object[1], object[2]);
  5738. },
  5739. MultiPoint: function(object, stream) {
  5740. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5741. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  5742. },
  5743. LineString: function(object, stream) {
  5744. streamLine(object.coordinates, stream, 0);
  5745. },
  5746. MultiLineString: function(object, stream) {
  5747. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5748. while (++i < n) streamLine(coordinates[i], stream, 0);
  5749. },
  5750. Polygon: function(object, stream) {
  5751. streamPolygon(object.coordinates, stream);
  5752. },
  5753. MultiPolygon: function(object, stream) {
  5754. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5755. while (++i < n) streamPolygon(coordinates[i], stream);
  5756. },
  5757. GeometryCollection: function(object, stream) {
  5758. var geometries = object.geometries, i = -1, n = geometries.length;
  5759. while (++i < n) streamGeometry(geometries[i], stream);
  5760. }
  5761. };
  5762. function streamLine(coordinates, stream, closed) {
  5763. var i = -1, n = coordinates.length - closed, coordinate;
  5764. stream.lineStart();
  5765. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  5766. stream.lineEnd();
  5767. }
  5768. function streamPolygon(coordinates, stream) {
  5769. var i = -1, n = coordinates.length;
  5770. stream.polygonStart();
  5771. while (++i < n) streamLine(coordinates[i], stream, 1);
  5772. stream.polygonEnd();
  5773. }
  5774. var geoStream = function(object, stream) {
  5775. if (object && streamObjectType.hasOwnProperty(object.type)) {
  5776. streamObjectType[object.type](object, stream);
  5777. } else {
  5778. streamGeometry(object, stream);
  5779. }
  5780. };
  5781. var areaRingSum = adder();
  5782. var areaSum = adder();
  5783. var lambda00;
  5784. var phi00;
  5785. var lambda0;
  5786. var cosPhi0;
  5787. var sinPhi0;
  5788. var areaStream = {
  5789. point: noop$1,
  5790. lineStart: noop$1,
  5791. lineEnd: noop$1,
  5792. polygonStart: function() {
  5793. areaRingSum.reset();
  5794. areaStream.lineStart = areaRingStart;
  5795. areaStream.lineEnd = areaRingEnd;
  5796. },
  5797. polygonEnd: function() {
  5798. var areaRing = +areaRingSum;
  5799. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  5800. this.lineStart = this.lineEnd = this.point = noop$1;
  5801. },
  5802. sphere: function() {
  5803. areaSum.add(tau$3);
  5804. }
  5805. };
  5806. function areaRingStart() {
  5807. areaStream.point = areaPointFirst;
  5808. }
  5809. function areaRingEnd() {
  5810. areaPoint(lambda00, phi00);
  5811. }
  5812. function areaPointFirst(lambda, phi) {
  5813. areaStream.point = areaPoint;
  5814. lambda00 = lambda, phi00 = phi;
  5815. lambda *= radians, phi *= radians;
  5816. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  5817. }
  5818. function areaPoint(lambda, phi) {
  5819. lambda *= radians, phi *= radians;
  5820. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  5821. // Spherical excess E for a spherical triangle with vertices: south pole,
  5822. // previous point, current point. Uses a formula derived from Cagnoli’s
  5823. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  5824. var dLambda = lambda - lambda0,
  5825. sdLambda = dLambda >= 0 ? 1 : -1,
  5826. adLambda = sdLambda * dLambda,
  5827. cosPhi = cos$1(phi),
  5828. sinPhi = sin$1(phi),
  5829. k = sinPhi0 * sinPhi,
  5830. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  5831. v = k * sdLambda * sin$1(adLambda);
  5832. areaRingSum.add(atan2(v, u));
  5833. // Advance the previous points.
  5834. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  5835. }
  5836. var area = function(object) {
  5837. areaSum.reset();
  5838. geoStream(object, areaStream);
  5839. return areaSum * 2;
  5840. };
  5841. function spherical(cartesian) {
  5842. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  5843. }
  5844. function cartesian(spherical) {
  5845. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  5846. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  5847. }
  5848. function cartesianDot(a, b) {
  5849. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  5850. }
  5851. function cartesianCross(a, b) {
  5852. 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]];
  5853. }
  5854. // TODO return a
  5855. function cartesianAddInPlace(a, b) {
  5856. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  5857. }
  5858. function cartesianScale(vector, k) {
  5859. return [vector[0] * k, vector[1] * k, vector[2] * k];
  5860. }
  5861. // TODO return d
  5862. function cartesianNormalizeInPlace(d) {
  5863. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  5864. d[0] /= l, d[1] /= l, d[2] /= l;
  5865. }
  5866. var lambda0$1;
  5867. var phi0;
  5868. var lambda1;
  5869. var phi1;
  5870. var lambda2;
  5871. var lambda00$1;
  5872. var phi00$1;
  5873. var p0;
  5874. var deltaSum = adder();
  5875. var ranges;
  5876. var range;
  5877. var boundsStream = {
  5878. point: boundsPoint,
  5879. lineStart: boundsLineStart,
  5880. lineEnd: boundsLineEnd,
  5881. polygonStart: function() {
  5882. boundsStream.point = boundsRingPoint;
  5883. boundsStream.lineStart = boundsRingStart;
  5884. boundsStream.lineEnd = boundsRingEnd;
  5885. deltaSum.reset();
  5886. areaStream.polygonStart();
  5887. },
  5888. polygonEnd: function() {
  5889. areaStream.polygonEnd();
  5890. boundsStream.point = boundsPoint;
  5891. boundsStream.lineStart = boundsLineStart;
  5892. boundsStream.lineEnd = boundsLineEnd;
  5893. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  5894. else if (deltaSum > epsilon$2) phi1 = 90;
  5895. else if (deltaSum < -epsilon$2) phi0 = -90;
  5896. range[0] = lambda0$1, range[1] = lambda1;
  5897. }
  5898. };
  5899. function boundsPoint(lambda, phi) {
  5900. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  5901. if (phi < phi0) phi0 = phi;
  5902. if (phi > phi1) phi1 = phi;
  5903. }
  5904. function linePoint(lambda, phi) {
  5905. var p = cartesian([lambda * radians, phi * radians]);
  5906. if (p0) {
  5907. var normal = cartesianCross(p0, p),
  5908. equatorial = [normal[1], -normal[0], 0],
  5909. inflection = cartesianCross(equatorial, normal);
  5910. cartesianNormalizeInPlace(inflection);
  5911. inflection = spherical(inflection);
  5912. var delta = lambda - lambda2,
  5913. sign$$1 = delta > 0 ? 1 : -1,
  5914. lambdai = inflection[0] * degrees$1 * sign$$1,
  5915. phii,
  5916. antimeridian = abs(delta) > 180;
  5917. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  5918. phii = inflection[1] * degrees$1;
  5919. if (phii > phi1) phi1 = phii;
  5920. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  5921. phii = -inflection[1] * degrees$1;
  5922. if (phii < phi0) phi0 = phii;
  5923. } else {
  5924. if (phi < phi0) phi0 = phi;
  5925. if (phi > phi1) phi1 = phi;
  5926. }
  5927. if (antimeridian) {
  5928. if (lambda < lambda2) {
  5929. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  5930. } else {
  5931. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  5932. }
  5933. } else {
  5934. if (lambda1 >= lambda0$1) {
  5935. if (lambda < lambda0$1) lambda0$1 = lambda;
  5936. if (lambda > lambda1) lambda1 = lambda;
  5937. } else {
  5938. if (lambda > lambda2) {
  5939. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  5940. } else {
  5941. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  5942. }
  5943. }
  5944. }
  5945. } else {
  5946. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  5947. }
  5948. if (phi < phi0) phi0 = phi;
  5949. if (phi > phi1) phi1 = phi;
  5950. p0 = p, lambda2 = lambda;
  5951. }
  5952. function boundsLineStart() {
  5953. boundsStream.point = linePoint;
  5954. }
  5955. function boundsLineEnd() {
  5956. range[0] = lambda0$1, range[1] = lambda1;
  5957. boundsStream.point = boundsPoint;
  5958. p0 = null;
  5959. }
  5960. function boundsRingPoint(lambda, phi) {
  5961. if (p0) {
  5962. var delta = lambda - lambda2;
  5963. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  5964. } else {
  5965. lambda00$1 = lambda, phi00$1 = phi;
  5966. }
  5967. areaStream.point(lambda, phi);
  5968. linePoint(lambda, phi);
  5969. }
  5970. function boundsRingStart() {
  5971. areaStream.lineStart();
  5972. }
  5973. function boundsRingEnd() {
  5974. boundsRingPoint(lambda00$1, phi00$1);
  5975. areaStream.lineEnd();
  5976. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  5977. range[0] = lambda0$1, range[1] = lambda1;
  5978. p0 = null;
  5979. }
  5980. // Finds the left-right distance between two longitudes.
  5981. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  5982. // the distance between ±180° to be 360°.
  5983. function angle(lambda0, lambda1) {
  5984. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  5985. }
  5986. function rangeCompare(a, b) {
  5987. return a[0] - b[0];
  5988. }
  5989. function rangeContains(range, x) {
  5990. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  5991. }
  5992. var bounds = function(feature) {
  5993. var i, n, a, b, merged, deltaMax, delta;
  5994. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  5995. ranges = [];
  5996. geoStream(feature, boundsStream);
  5997. // First, sort ranges by their minimum longitudes.
  5998. if (n = ranges.length) {
  5999. ranges.sort(rangeCompare);
  6000. // Then, merge any ranges that overlap.
  6001. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6002. b = ranges[i];
  6003. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6004. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6005. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6006. } else {
  6007. merged.push(a = b);
  6008. }
  6009. }
  6010. // Finally, find the largest gap between the merged ranges.
  6011. // The final bounding box will be the inverse of this gap.
  6012. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6013. b = merged[i];
  6014. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6015. }
  6016. }
  6017. ranges = range = null;
  6018. return lambda0$1 === Infinity || phi0 === Infinity
  6019. ? [[NaN, NaN], [NaN, NaN]]
  6020. : [[lambda0$1, phi0], [lambda1, phi1]];
  6021. };
  6022. var W0;
  6023. var W1;
  6024. var X0;
  6025. var Y0;
  6026. var Z0;
  6027. var X1;
  6028. var Y1;
  6029. var Z1;
  6030. var X2;
  6031. var Y2;
  6032. var Z2;
  6033. var lambda00$2;
  6034. var phi00$2;
  6035. var x0;
  6036. var y0;
  6037. var z0; // previous point
  6038. var centroidStream = {
  6039. sphere: noop$1,
  6040. point: centroidPoint,
  6041. lineStart: centroidLineStart,
  6042. lineEnd: centroidLineEnd,
  6043. polygonStart: function() {
  6044. centroidStream.lineStart = centroidRingStart;
  6045. centroidStream.lineEnd = centroidRingEnd;
  6046. },
  6047. polygonEnd: function() {
  6048. centroidStream.lineStart = centroidLineStart;
  6049. centroidStream.lineEnd = centroidLineEnd;
  6050. }
  6051. };
  6052. // Arithmetic mean of Cartesian vectors.
  6053. function centroidPoint(lambda, phi) {
  6054. lambda *= radians, phi *= radians;
  6055. var cosPhi = cos$1(phi);
  6056. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6057. }
  6058. function centroidPointCartesian(x, y, z) {
  6059. ++W0;
  6060. X0 += (x - X0) / W0;
  6061. Y0 += (y - Y0) / W0;
  6062. Z0 += (z - Z0) / W0;
  6063. }
  6064. function centroidLineStart() {
  6065. centroidStream.point = centroidLinePointFirst;
  6066. }
  6067. function centroidLinePointFirst(lambda, phi) {
  6068. lambda *= radians, phi *= radians;
  6069. var cosPhi = cos$1(phi);
  6070. x0 = cosPhi * cos$1(lambda);
  6071. y0 = cosPhi * sin$1(lambda);
  6072. z0 = sin$1(phi);
  6073. centroidStream.point = centroidLinePoint;
  6074. centroidPointCartesian(x0, y0, z0);
  6075. }
  6076. function centroidLinePoint(lambda, phi) {
  6077. lambda *= radians, phi *= radians;
  6078. var cosPhi = cos$1(phi),
  6079. x = cosPhi * cos$1(lambda),
  6080. y = cosPhi * sin$1(lambda),
  6081. z = sin$1(phi),
  6082. w = atan2(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);
  6083. W1 += w;
  6084. X1 += w * (x0 + (x0 = x));
  6085. Y1 += w * (y0 + (y0 = y));
  6086. Z1 += w * (z0 + (z0 = z));
  6087. centroidPointCartesian(x0, y0, z0);
  6088. }
  6089. function centroidLineEnd() {
  6090. centroidStream.point = centroidPoint;
  6091. }
  6092. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6093. // J. Applied Mechanics 42, 239 (1975).
  6094. function centroidRingStart() {
  6095. centroidStream.point = centroidRingPointFirst;
  6096. }
  6097. function centroidRingEnd() {
  6098. centroidRingPoint(lambda00$2, phi00$2);
  6099. centroidStream.point = centroidPoint;
  6100. }
  6101. function centroidRingPointFirst(lambda, phi) {
  6102. lambda00$2 = lambda, phi00$2 = phi;
  6103. lambda *= radians, phi *= radians;
  6104. centroidStream.point = centroidRingPoint;
  6105. var cosPhi = cos$1(phi);
  6106. x0 = cosPhi * cos$1(lambda);
  6107. y0 = cosPhi * sin$1(lambda);
  6108. z0 = sin$1(phi);
  6109. centroidPointCartesian(x0, y0, z0);
  6110. }
  6111. function centroidRingPoint(lambda, phi) {
  6112. lambda *= radians, phi *= radians;
  6113. var cosPhi = cos$1(phi),
  6114. x = cosPhi * cos$1(lambda),
  6115. y = cosPhi * sin$1(lambda),
  6116. z = sin$1(phi),
  6117. cx = y0 * z - z0 * y,
  6118. cy = z0 * x - x0 * z,
  6119. cz = x0 * y - y0 * x,
  6120. m = sqrt(cx * cx + cy * cy + cz * cz),
  6121. w = asin(m), // line weight = angle
  6122. v = m && -w / m; // area weight multiplier
  6123. X2 += v * cx;
  6124. Y2 += v * cy;
  6125. Z2 += v * cz;
  6126. W1 += w;
  6127. X1 += w * (x0 + (x0 = x));
  6128. Y1 += w * (y0 + (y0 = y));
  6129. Z1 += w * (z0 + (z0 = z));
  6130. centroidPointCartesian(x0, y0, z0);
  6131. }
  6132. var centroid = function(object) {
  6133. W0 = W1 =
  6134. X0 = Y0 = Z0 =
  6135. X1 = Y1 = Z1 =
  6136. X2 = Y2 = Z2 = 0;
  6137. geoStream(object, centroidStream);
  6138. var x = X2,
  6139. y = Y2,
  6140. z = Z2,
  6141. m = x * x + y * y + z * z;
  6142. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6143. if (m < epsilon2$1) {
  6144. x = X1, y = Y1, z = Z1;
  6145. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6146. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6147. m = x * x + y * y + z * z;
  6148. // If the feature still has an undefined ccentroid, then return.
  6149. if (m < epsilon2$1) return [NaN, NaN];
  6150. }
  6151. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6152. };
  6153. var constant$7 = function(x) {
  6154. return function() {
  6155. return x;
  6156. };
  6157. };
  6158. var compose = function(a, b) {
  6159. function compose(x, y) {
  6160. return x = a(x, y), b(x[0], x[1]);
  6161. }
  6162. if (a.invert && b.invert) compose.invert = function(x, y) {
  6163. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6164. };
  6165. return compose;
  6166. };
  6167. function rotationIdentity(lambda, phi) {
  6168. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6169. }
  6170. rotationIdentity.invert = rotationIdentity;
  6171. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6172. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6173. : rotationLambda(deltaLambda))
  6174. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6175. : rotationIdentity);
  6176. }
  6177. function forwardRotationLambda(deltaLambda) {
  6178. return function(lambda, phi) {
  6179. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6180. };
  6181. }
  6182. function rotationLambda(deltaLambda) {
  6183. var rotation = forwardRotationLambda(deltaLambda);
  6184. rotation.invert = forwardRotationLambda(-deltaLambda);
  6185. return rotation;
  6186. }
  6187. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6188. var cosDeltaPhi = cos$1(deltaPhi),
  6189. sinDeltaPhi = sin$1(deltaPhi),
  6190. cosDeltaGamma = cos$1(deltaGamma),
  6191. sinDeltaGamma = sin$1(deltaGamma);
  6192. function rotation(lambda, phi) {
  6193. var cosPhi = cos$1(phi),
  6194. x = cos$1(lambda) * cosPhi,
  6195. y = sin$1(lambda) * cosPhi,
  6196. z = sin$1(phi),
  6197. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6198. return [
  6199. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6200. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6201. ];
  6202. }
  6203. rotation.invert = function(lambda, phi) {
  6204. var cosPhi = cos$1(phi),
  6205. x = cos$1(lambda) * cosPhi,
  6206. y = sin$1(lambda) * cosPhi,
  6207. z = sin$1(phi),
  6208. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6209. return [
  6210. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6211. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6212. ];
  6213. };
  6214. return rotation;
  6215. }
  6216. var rotation = function(rotate) {
  6217. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6218. function forward(coordinates) {
  6219. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6220. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6221. }
  6222. forward.invert = function(coordinates) {
  6223. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6224. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6225. };
  6226. return forward;
  6227. };
  6228. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6229. function circleStream(stream, radius, delta, direction, t0, t1) {
  6230. if (!delta) return;
  6231. var cosRadius = cos$1(radius),
  6232. sinRadius = sin$1(radius),
  6233. step = direction * delta;
  6234. if (t0 == null) {
  6235. t0 = radius + direction * tau$3;
  6236. t1 = radius - step / 2;
  6237. } else {
  6238. t0 = circleRadius(cosRadius, t0);
  6239. t1 = circleRadius(cosRadius, t1);
  6240. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6241. }
  6242. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6243. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6244. stream.point(point[0], point[1]);
  6245. }
  6246. }
  6247. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6248. function circleRadius(cosRadius, point) {
  6249. point = cartesian(point), point[0] -= cosRadius;
  6250. cartesianNormalizeInPlace(point);
  6251. var radius = acos(-point[1]);
  6252. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6253. }
  6254. var circle = function() {
  6255. var center = constant$7([0, 0]),
  6256. radius = constant$7(90),
  6257. precision = constant$7(6),
  6258. ring,
  6259. rotate,
  6260. stream = {point: point};
  6261. function point(x, y) {
  6262. ring.push(x = rotate(x, y));
  6263. x[0] *= degrees$1, x[1] *= degrees$1;
  6264. }
  6265. function circle() {
  6266. var c = center.apply(this, arguments),
  6267. r = radius.apply(this, arguments) * radians,
  6268. p = precision.apply(this, arguments) * radians;
  6269. ring = [];
  6270. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6271. circleStream(stream, r, p, 1);
  6272. c = {type: "Polygon", coordinates: [ring]};
  6273. ring = rotate = null;
  6274. return c;
  6275. }
  6276. circle.center = function(_) {
  6277. return arguments.length ? (center = typeof _ === "function" ? _ : constant$7([+_[0], +_[1]]), circle) : center;
  6278. };
  6279. circle.radius = function(_) {
  6280. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), circle) : radius;
  6281. };
  6282. circle.precision = function(_) {
  6283. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$7(+_), circle) : precision;
  6284. };
  6285. return circle;
  6286. };
  6287. var clipBuffer = function() {
  6288. var lines = [],
  6289. line;
  6290. return {
  6291. point: function(x, y) {
  6292. line.push([x, y]);
  6293. },
  6294. lineStart: function() {
  6295. lines.push(line = []);
  6296. },
  6297. lineEnd: noop$1,
  6298. rejoin: function() {
  6299. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6300. },
  6301. result: function() {
  6302. var result = lines;
  6303. lines = [];
  6304. line = null;
  6305. return result;
  6306. }
  6307. };
  6308. };
  6309. var clipLine = function(a, b, x0, y0, x1, y1) {
  6310. var ax = a[0],
  6311. ay = a[1],
  6312. bx = b[0],
  6313. by = b[1],
  6314. t0 = 0,
  6315. t1 = 1,
  6316. dx = bx - ax,
  6317. dy = by - ay,
  6318. r;
  6319. r = x0 - ax;
  6320. if (!dx && r > 0) return;
  6321. r /= dx;
  6322. if (dx < 0) {
  6323. if (r < t0) return;
  6324. if (r < t1) t1 = r;
  6325. } else if (dx > 0) {
  6326. if (r > t1) return;
  6327. if (r > t0) t0 = r;
  6328. }
  6329. r = x1 - ax;
  6330. if (!dx && r < 0) return;
  6331. r /= dx;
  6332. if (dx < 0) {
  6333. if (r > t1) return;
  6334. if (r > t0) t0 = r;
  6335. } else if (dx > 0) {
  6336. if (r < t0) return;
  6337. if (r < t1) t1 = r;
  6338. }
  6339. r = y0 - ay;
  6340. if (!dy && r > 0) return;
  6341. r /= dy;
  6342. if (dy < 0) {
  6343. if (r < t0) return;
  6344. if (r < t1) t1 = r;
  6345. } else if (dy > 0) {
  6346. if (r > t1) return;
  6347. if (r > t0) t0 = r;
  6348. }
  6349. r = y1 - ay;
  6350. if (!dy && r < 0) return;
  6351. r /= dy;
  6352. if (dy < 0) {
  6353. if (r > t1) return;
  6354. if (r > t0) t0 = r;
  6355. } else if (dy > 0) {
  6356. if (r < t0) return;
  6357. if (r < t1) t1 = r;
  6358. }
  6359. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  6360. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  6361. return true;
  6362. };
  6363. var pointEqual = function(a, b) {
  6364. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6365. };
  6366. function Intersection(point, points, other, entry) {
  6367. this.x = point;
  6368. this.z = points;
  6369. this.o = other; // another intersection
  6370. this.e = entry; // is an entry?
  6371. this.v = false; // visited
  6372. this.n = this.p = null; // next & previous
  6373. }
  6374. // A generalized polygon clipping algorithm: given a polygon that has been cut
  6375. // into its visible line segments, and rejoins the segments by interpolating
  6376. // along the clip edge.
  6377. var clipPolygon = function(segments, compareIntersection, startInside, interpolate, stream) {
  6378. var subject = [],
  6379. clip = [],
  6380. i,
  6381. n;
  6382. segments.forEach(function(segment) {
  6383. if ((n = segment.length - 1) <= 0) return;
  6384. var n, p0 = segment[0], p1 = segment[n], x;
  6385. // If the first and last points of a segment are coincident, then treat as a
  6386. // closed ring. TODO if all rings are closed, then the winding order of the
  6387. // exterior ring should be checked.
  6388. if (pointEqual(p0, p1)) {
  6389. stream.lineStart();
  6390. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  6391. stream.lineEnd();
  6392. return;
  6393. }
  6394. subject.push(x = new Intersection(p0, segment, null, true));
  6395. clip.push(x.o = new Intersection(p0, null, x, false));
  6396. subject.push(x = new Intersection(p1, segment, null, false));
  6397. clip.push(x.o = new Intersection(p1, null, x, true));
  6398. });
  6399. if (!subject.length) return;
  6400. clip.sort(compareIntersection);
  6401. link$1(subject);
  6402. link$1(clip);
  6403. for (i = 0, n = clip.length; i < n; ++i) {
  6404. clip[i].e = startInside = !startInside;
  6405. }
  6406. var start = subject[0],
  6407. points,
  6408. point;
  6409. while (1) {
  6410. // Find first unvisited intersection.
  6411. var current = start,
  6412. isSubject = true;
  6413. while (current.v) if ((current = current.n) === start) return;
  6414. points = current.z;
  6415. stream.lineStart();
  6416. do {
  6417. current.v = current.o.v = true;
  6418. if (current.e) {
  6419. if (isSubject) {
  6420. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  6421. } else {
  6422. interpolate(current.x, current.n.x, 1, stream);
  6423. }
  6424. current = current.n;
  6425. } else {
  6426. if (isSubject) {
  6427. points = current.p.z;
  6428. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  6429. } else {
  6430. interpolate(current.x, current.p.x, -1, stream);
  6431. }
  6432. current = current.p;
  6433. }
  6434. current = current.o;
  6435. points = current.z;
  6436. isSubject = !isSubject;
  6437. } while (!current.v);
  6438. stream.lineEnd();
  6439. }
  6440. };
  6441. function link$1(array) {
  6442. if (!(n = array.length)) return;
  6443. var n,
  6444. i = 0,
  6445. a = array[0],
  6446. b;
  6447. while (++i < n) {
  6448. a.n = b = array[i];
  6449. b.p = a;
  6450. a = b;
  6451. }
  6452. a.n = b = array[0];
  6453. b.p = a;
  6454. }
  6455. var clipMax = 1e9;
  6456. var clipMin = -clipMax;
  6457. // TODO Use d3-polygon’s polygonContains here for the ring check?
  6458. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  6459. function clipExtent(x0, y0, x1, y1) {
  6460. function visible(x, y) {
  6461. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  6462. }
  6463. function interpolate(from, to, direction, stream) {
  6464. var a = 0, a1 = 0;
  6465. if (from == null
  6466. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  6467. || comparePoint(from, to) < 0 ^ direction > 0) {
  6468. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  6469. while ((a = (a + direction + 4) % 4) !== a1);
  6470. } else {
  6471. stream.point(to[0], to[1]);
  6472. }
  6473. }
  6474. function corner(p, direction) {
  6475. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  6476. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  6477. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  6478. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  6479. }
  6480. function compareIntersection(a, b) {
  6481. return comparePoint(a.x, b.x);
  6482. }
  6483. function comparePoint(a, b) {
  6484. var ca = corner(a, 1),
  6485. cb = corner(b, 1);
  6486. return ca !== cb ? ca - cb
  6487. : ca === 0 ? b[1] - a[1]
  6488. : ca === 1 ? a[0] - b[0]
  6489. : ca === 2 ? a[1] - b[1]
  6490. : b[0] - a[0];
  6491. }
  6492. return function(stream) {
  6493. var activeStream = stream,
  6494. bufferStream = clipBuffer(),
  6495. segments,
  6496. polygon,
  6497. ring,
  6498. x__, y__, v__, // first point
  6499. x_, y_, v_, // previous point
  6500. first,
  6501. clean;
  6502. var clipStream = {
  6503. point: point,
  6504. lineStart: lineStart,
  6505. lineEnd: lineEnd,
  6506. polygonStart: polygonStart,
  6507. polygonEnd: polygonEnd
  6508. };
  6509. function point(x, y) {
  6510. if (visible(x, y)) activeStream.point(x, y);
  6511. }
  6512. function polygonInside() {
  6513. var winding = 0;
  6514. for (var i = 0, n = polygon.length; i < n; ++i) {
  6515. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  6516. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  6517. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  6518. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  6519. }
  6520. }
  6521. return winding;
  6522. }
  6523. // Buffer geometry within a polygon and then clip it en masse.
  6524. function polygonStart() {
  6525. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  6526. }
  6527. function polygonEnd() {
  6528. var startInside = polygonInside(),
  6529. cleanInside = clean && startInside,
  6530. visible = (segments = merge(segments)).length;
  6531. if (cleanInside || visible) {
  6532. stream.polygonStart();
  6533. if (cleanInside) {
  6534. stream.lineStart();
  6535. interpolate(null, null, 1, stream);
  6536. stream.lineEnd();
  6537. }
  6538. if (visible) {
  6539. clipPolygon(segments, compareIntersection, startInside, interpolate, stream);
  6540. }
  6541. stream.polygonEnd();
  6542. }
  6543. activeStream = stream, segments = polygon = ring = null;
  6544. }
  6545. function lineStart() {
  6546. clipStream.point = linePoint;
  6547. if (polygon) polygon.push(ring = []);
  6548. first = true;
  6549. v_ = false;
  6550. x_ = y_ = NaN;
  6551. }
  6552. // TODO rather than special-case polygons, simply handle them separately.
  6553. // Ideally, coincident intersection points should be jittered to avoid
  6554. // clipping issues.
  6555. function lineEnd() {
  6556. if (segments) {
  6557. linePoint(x__, y__);
  6558. if (v__ && v_) bufferStream.rejoin();
  6559. segments.push(bufferStream.result());
  6560. }
  6561. clipStream.point = point;
  6562. if (v_) activeStream.lineEnd();
  6563. }
  6564. function linePoint(x, y) {
  6565. var v = visible(x, y);
  6566. if (polygon) ring.push([x, y]);
  6567. if (first) {
  6568. x__ = x, y__ = y, v__ = v;
  6569. first = false;
  6570. if (v) {
  6571. activeStream.lineStart();
  6572. activeStream.point(x, y);
  6573. }
  6574. } else {
  6575. if (v && v_) activeStream.point(x, y);
  6576. else {
  6577. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  6578. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  6579. if (clipLine(a, b, x0, y0, x1, y1)) {
  6580. if (!v_) {
  6581. activeStream.lineStart();
  6582. activeStream.point(a[0], a[1]);
  6583. }
  6584. activeStream.point(b[0], b[1]);
  6585. if (!v) activeStream.lineEnd();
  6586. clean = false;
  6587. } else if (v) {
  6588. activeStream.lineStart();
  6589. activeStream.point(x, y);
  6590. clean = false;
  6591. }
  6592. }
  6593. }
  6594. x_ = x, y_ = y, v_ = v;
  6595. }
  6596. return clipStream;
  6597. };
  6598. }
  6599. var extent$1 = function() {
  6600. var x0 = 0,
  6601. y0 = 0,
  6602. x1 = 960,
  6603. y1 = 500,
  6604. cache,
  6605. cacheStream,
  6606. clip;
  6607. return clip = {
  6608. stream: function(stream) {
  6609. return cache && cacheStream === stream ? cache : cache = clipExtent(x0, y0, x1, y1)(cacheStream = stream);
  6610. },
  6611. extent: function(_) {
  6612. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  6613. }
  6614. };
  6615. };
  6616. var sum$1 = adder();
  6617. var polygonContains = function(polygon, point) {
  6618. var lambda = point[0],
  6619. phi = point[1],
  6620. normal = [sin$1(lambda), -cos$1(lambda), 0],
  6621. angle = 0,
  6622. winding = 0;
  6623. sum$1.reset();
  6624. for (var i = 0, n = polygon.length; i < n; ++i) {
  6625. if (!(m = (ring = polygon[i]).length)) continue;
  6626. var ring,
  6627. m,
  6628. point0 = ring[m - 1],
  6629. lambda0 = point0[0],
  6630. phi0 = point0[1] / 2 + quarterPi,
  6631. sinPhi0 = sin$1(phi0),
  6632. cosPhi0 = cos$1(phi0);
  6633. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  6634. var point1 = ring[j],
  6635. lambda1 = point1[0],
  6636. phi1 = point1[1] / 2 + quarterPi,
  6637. sinPhi1 = sin$1(phi1),
  6638. cosPhi1 = cos$1(phi1),
  6639. delta = lambda1 - lambda0,
  6640. sign$$1 = delta >= 0 ? 1 : -1,
  6641. absDelta = sign$$1 * delta,
  6642. antimeridian = absDelta > pi$3,
  6643. k = sinPhi0 * sinPhi1;
  6644. sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  6645. angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
  6646. // Are the longitudes either side of the point’s meridian (lambda),
  6647. // and are the latitudes smaller than the parallel (phi)?
  6648. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  6649. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  6650. cartesianNormalizeInPlace(arc);
  6651. var intersection = cartesianCross(normal, arc);
  6652. cartesianNormalizeInPlace(intersection);
  6653. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  6654. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  6655. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  6656. }
  6657. }
  6658. }
  6659. }
  6660. // First, determine whether the South pole is inside or outside:
  6661. //
  6662. // It is inside if:
  6663. // * the polygon winds around it in a clockwise direction.
  6664. // * the polygon does not (cumulatively) wind around it, but has a negative
  6665. // (counter-clockwise) area.
  6666. //
  6667. // Second, count the (signed) number of times a segment crosses a lambda
  6668. // from the point to the South pole. If it is zero, then the point is the
  6669. // same side as the South pole.
  6670. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  6671. };
  6672. var lengthSum = adder();
  6673. var lambda0$2;
  6674. var sinPhi0$1;
  6675. var cosPhi0$1;
  6676. var lengthStream = {
  6677. sphere: noop$1,
  6678. point: noop$1,
  6679. lineStart: lengthLineStart,
  6680. lineEnd: noop$1,
  6681. polygonStart: noop$1,
  6682. polygonEnd: noop$1
  6683. };
  6684. function lengthLineStart() {
  6685. lengthStream.point = lengthPointFirst;
  6686. lengthStream.lineEnd = lengthLineEnd;
  6687. }
  6688. function lengthLineEnd() {
  6689. lengthStream.point = lengthStream.lineEnd = noop$1;
  6690. }
  6691. function lengthPointFirst(lambda, phi) {
  6692. lambda *= radians, phi *= radians;
  6693. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  6694. lengthStream.point = lengthPoint;
  6695. }
  6696. function lengthPoint(lambda, phi) {
  6697. lambda *= radians, phi *= radians;
  6698. var sinPhi = sin$1(phi),
  6699. cosPhi = cos$1(phi),
  6700. delta = abs(lambda - lambda0$2),
  6701. cosDelta = cos$1(delta),
  6702. sinDelta = sin$1(delta),
  6703. x = cosPhi * sinDelta,
  6704. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  6705. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  6706. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  6707. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  6708. }
  6709. var length$1 = function(object) {
  6710. lengthSum.reset();
  6711. geoStream(object, lengthStream);
  6712. return +lengthSum;
  6713. };
  6714. var coordinates = [null, null];
  6715. var object$1 = {type: "LineString", coordinates: coordinates};
  6716. var distance = function(a, b) {
  6717. coordinates[0] = a;
  6718. coordinates[1] = b;
  6719. return length$1(object$1);
  6720. };
  6721. var containsObjectType = {
  6722. Feature: function(object, point) {
  6723. return containsGeometry(object.geometry, point);
  6724. },
  6725. FeatureCollection: function(object, point) {
  6726. var features = object.features, i = -1, n = features.length;
  6727. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  6728. return false;
  6729. }
  6730. };
  6731. var containsGeometryType = {
  6732. Sphere: function() {
  6733. return true;
  6734. },
  6735. Point: function(object, point) {
  6736. return containsPoint(object.coordinates, point);
  6737. },
  6738. MultiPoint: function(object, point) {
  6739. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6740. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  6741. return false;
  6742. },
  6743. LineString: function(object, point) {
  6744. return containsLine(object.coordinates, point);
  6745. },
  6746. MultiLineString: function(object, point) {
  6747. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6748. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  6749. return false;
  6750. },
  6751. Polygon: function(object, point) {
  6752. return containsPolygon(object.coordinates, point);
  6753. },
  6754. MultiPolygon: function(object, point) {
  6755. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6756. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  6757. return false;
  6758. },
  6759. GeometryCollection: function(object, point) {
  6760. var geometries = object.geometries, i = -1, n = geometries.length;
  6761. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  6762. return false;
  6763. }
  6764. };
  6765. function containsGeometry(geometry, point) {
  6766. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  6767. ? containsGeometryType[geometry.type](geometry, point)
  6768. : false;
  6769. }
  6770. function containsPoint(coordinates, point) {
  6771. return distance(coordinates, point) === 0;
  6772. }
  6773. function containsLine(coordinates, point) {
  6774. var ab = distance(coordinates[0], coordinates[1]),
  6775. ao = distance(coordinates[0], point),
  6776. ob = distance(point, coordinates[1]);
  6777. return ao + ob <= ab + epsilon$2;
  6778. }
  6779. function containsPolygon(coordinates, point) {
  6780. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  6781. }
  6782. function ringRadians(ring) {
  6783. return ring = ring.map(pointRadians), ring.pop(), ring;
  6784. }
  6785. function pointRadians(point) {
  6786. return [point[0] * radians, point[1] * radians];
  6787. }
  6788. var contains = function(object, point) {
  6789. return (object && containsObjectType.hasOwnProperty(object.type)
  6790. ? containsObjectType[object.type]
  6791. : containsGeometry)(object, point);
  6792. };
  6793. function graticuleX(y0, y1, dy) {
  6794. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  6795. return function(x) { return y.map(function(y) { return [x, y]; }); };
  6796. }
  6797. function graticuleY(x0, x1, dx) {
  6798. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  6799. return function(y) { return x.map(function(x) { return [x, y]; }); };
  6800. }
  6801. function graticule() {
  6802. var x1, x0, X1, X0,
  6803. y1, y0, Y1, Y0,
  6804. dx = 10, dy = dx, DX = 90, DY = 360,
  6805. x, y, X, Y,
  6806. precision = 2.5;
  6807. function graticule() {
  6808. return {type: "MultiLineString", coordinates: lines()};
  6809. }
  6810. function lines() {
  6811. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  6812. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  6813. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  6814. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  6815. }
  6816. graticule.lines = function() {
  6817. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  6818. };
  6819. graticule.outline = function() {
  6820. return {
  6821. type: "Polygon",
  6822. coordinates: [
  6823. X(X0).concat(
  6824. Y(Y1).slice(1),
  6825. X(X1).reverse().slice(1),
  6826. Y(Y0).reverse().slice(1))
  6827. ]
  6828. };
  6829. };
  6830. graticule.extent = function(_) {
  6831. if (!arguments.length) return graticule.extentMinor();
  6832. return graticule.extentMajor(_).extentMinor(_);
  6833. };
  6834. graticule.extentMajor = function(_) {
  6835. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  6836. X0 = +_[0][0], X1 = +_[1][0];
  6837. Y0 = +_[0][1], Y1 = +_[1][1];
  6838. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  6839. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  6840. return graticule.precision(precision);
  6841. };
  6842. graticule.extentMinor = function(_) {
  6843. if (!arguments.length) return [[x0, y0], [x1, y1]];
  6844. x0 = +_[0][0], x1 = +_[1][0];
  6845. y0 = +_[0][1], y1 = +_[1][1];
  6846. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  6847. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  6848. return graticule.precision(precision);
  6849. };
  6850. graticule.step = function(_) {
  6851. if (!arguments.length) return graticule.stepMinor();
  6852. return graticule.stepMajor(_).stepMinor(_);
  6853. };
  6854. graticule.stepMajor = function(_) {
  6855. if (!arguments.length) return [DX, DY];
  6856. DX = +_[0], DY = +_[1];
  6857. return graticule;
  6858. };
  6859. graticule.stepMinor = function(_) {
  6860. if (!arguments.length) return [dx, dy];
  6861. dx = +_[0], dy = +_[1];
  6862. return graticule;
  6863. };
  6864. graticule.precision = function(_) {
  6865. if (!arguments.length) return precision;
  6866. precision = +_;
  6867. x = graticuleX(y0, y1, 90);
  6868. y = graticuleY(x0, x1, precision);
  6869. X = graticuleX(Y0, Y1, 90);
  6870. Y = graticuleY(X0, X1, precision);
  6871. return graticule;
  6872. };
  6873. return graticule
  6874. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  6875. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  6876. }
  6877. function graticule10() {
  6878. return graticule()();
  6879. }
  6880. var interpolate$1 = function(a, b) {
  6881. var x0 = a[0] * radians,
  6882. y0 = a[1] * radians,
  6883. x1 = b[0] * radians,
  6884. y1 = b[1] * radians,
  6885. cy0 = cos$1(y0),
  6886. sy0 = sin$1(y0),
  6887. cy1 = cos$1(y1),
  6888. sy1 = sin$1(y1),
  6889. kx0 = cy0 * cos$1(x0),
  6890. ky0 = cy0 * sin$1(x0),
  6891. kx1 = cy1 * cos$1(x1),
  6892. ky1 = cy1 * sin$1(x1),
  6893. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  6894. k = sin$1(d);
  6895. var interpolate = d ? function(t) {
  6896. var B = sin$1(t *= d) / k,
  6897. A = sin$1(d - t) / k,
  6898. x = A * kx0 + B * kx1,
  6899. y = A * ky0 + B * ky1,
  6900. z = A * sy0 + B * sy1;
  6901. return [
  6902. atan2(y, x) * degrees$1,
  6903. atan2(z, sqrt(x * x + y * y)) * degrees$1
  6904. ];
  6905. } : function() {
  6906. return [x0 * degrees$1, y0 * degrees$1];
  6907. };
  6908. interpolate.distance = d;
  6909. return interpolate;
  6910. };
  6911. var identity$4 = function(x) {
  6912. return x;
  6913. };
  6914. var areaSum$1 = adder();
  6915. var areaRingSum$1 = adder();
  6916. var x00;
  6917. var y00;
  6918. var x0$1;
  6919. var y0$1;
  6920. var areaStream$1 = {
  6921. point: noop$1,
  6922. lineStart: noop$1,
  6923. lineEnd: noop$1,
  6924. polygonStart: function() {
  6925. areaStream$1.lineStart = areaRingStart$1;
  6926. areaStream$1.lineEnd = areaRingEnd$1;
  6927. },
  6928. polygonEnd: function() {
  6929. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$1;
  6930. areaSum$1.add(abs(areaRingSum$1));
  6931. areaRingSum$1.reset();
  6932. },
  6933. result: function() {
  6934. var area = areaSum$1 / 2;
  6935. areaSum$1.reset();
  6936. return area;
  6937. }
  6938. };
  6939. function areaRingStart$1() {
  6940. areaStream$1.point = areaPointFirst$1;
  6941. }
  6942. function areaPointFirst$1(x, y) {
  6943. areaStream$1.point = areaPoint$1;
  6944. x00 = x0$1 = x, y00 = y0$1 = y;
  6945. }
  6946. function areaPoint$1(x, y) {
  6947. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  6948. x0$1 = x, y0$1 = y;
  6949. }
  6950. function areaRingEnd$1() {
  6951. areaPoint$1(x00, y00);
  6952. }
  6953. var x0$2 = Infinity;
  6954. var y0$2 = x0$2;
  6955. var x1 = -x0$2;
  6956. var y1 = x1;
  6957. var boundsStream$1 = {
  6958. point: boundsPoint$1,
  6959. lineStart: noop$1,
  6960. lineEnd: noop$1,
  6961. polygonStart: noop$1,
  6962. polygonEnd: noop$1,
  6963. result: function() {
  6964. var bounds = [[x0$2, y0$2], [x1, y1]];
  6965. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  6966. return bounds;
  6967. }
  6968. };
  6969. function boundsPoint$1(x, y) {
  6970. if (x < x0$2) x0$2 = x;
  6971. if (x > x1) x1 = x;
  6972. if (y < y0$2) y0$2 = y;
  6973. if (y > y1) y1 = y;
  6974. }
  6975. // TODO Enforce positive area for exterior, negative area for interior?
  6976. var X0$1 = 0;
  6977. var Y0$1 = 0;
  6978. var Z0$1 = 0;
  6979. var X1$1 = 0;
  6980. var Y1$1 = 0;
  6981. var Z1$1 = 0;
  6982. var X2$1 = 0;
  6983. var Y2$1 = 0;
  6984. var Z2$1 = 0;
  6985. var x00$1;
  6986. var y00$1;
  6987. var x0$3;
  6988. var y0$3;
  6989. var centroidStream$1 = {
  6990. point: centroidPoint$1,
  6991. lineStart: centroidLineStart$1,
  6992. lineEnd: centroidLineEnd$1,
  6993. polygonStart: function() {
  6994. centroidStream$1.lineStart = centroidRingStart$1;
  6995. centroidStream$1.lineEnd = centroidRingEnd$1;
  6996. },
  6997. polygonEnd: function() {
  6998. centroidStream$1.point = centroidPoint$1;
  6999. centroidStream$1.lineStart = centroidLineStart$1;
  7000. centroidStream$1.lineEnd = centroidLineEnd$1;
  7001. },
  7002. result: function() {
  7003. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  7004. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  7005. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  7006. : [NaN, NaN];
  7007. X0$1 = Y0$1 = Z0$1 =
  7008. X1$1 = Y1$1 = Z1$1 =
  7009. X2$1 = Y2$1 = Z2$1 = 0;
  7010. return centroid;
  7011. }
  7012. };
  7013. function centroidPoint$1(x, y) {
  7014. X0$1 += x;
  7015. Y0$1 += y;
  7016. ++Z0$1;
  7017. }
  7018. function centroidLineStart$1() {
  7019. centroidStream$1.point = centroidPointFirstLine;
  7020. }
  7021. function centroidPointFirstLine(x, y) {
  7022. centroidStream$1.point = centroidPointLine;
  7023. centroidPoint$1(x0$3 = x, y0$3 = y);
  7024. }
  7025. function centroidPointLine(x, y) {
  7026. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  7027. X1$1 += z * (x0$3 + x) / 2;
  7028. Y1$1 += z * (y0$3 + y) / 2;
  7029. Z1$1 += z;
  7030. centroidPoint$1(x0$3 = x, y0$3 = y);
  7031. }
  7032. function centroidLineEnd$1() {
  7033. centroidStream$1.point = centroidPoint$1;
  7034. }
  7035. function centroidRingStart$1() {
  7036. centroidStream$1.point = centroidPointFirstRing;
  7037. }
  7038. function centroidRingEnd$1() {
  7039. centroidPointRing(x00$1, y00$1);
  7040. }
  7041. function centroidPointFirstRing(x, y) {
  7042. centroidStream$1.point = centroidPointRing;
  7043. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  7044. }
  7045. function centroidPointRing(x, y) {
  7046. var dx = x - x0$3,
  7047. dy = y - y0$3,
  7048. z = sqrt(dx * dx + dy * dy);
  7049. X1$1 += z * (x0$3 + x) / 2;
  7050. Y1$1 += z * (y0$3 + y) / 2;
  7051. Z1$1 += z;
  7052. z = y0$3 * x - x0$3 * y;
  7053. X2$1 += z * (x0$3 + x);
  7054. Y2$1 += z * (y0$3 + y);
  7055. Z2$1 += z * 3;
  7056. centroidPoint$1(x0$3 = x, y0$3 = y);
  7057. }
  7058. function PathContext(context) {
  7059. this._context = context;
  7060. }
  7061. PathContext.prototype = {
  7062. _radius: 4.5,
  7063. pointRadius: function(_) {
  7064. return this._radius = _, this;
  7065. },
  7066. polygonStart: function() {
  7067. this._line = 0;
  7068. },
  7069. polygonEnd: function() {
  7070. this._line = NaN;
  7071. },
  7072. lineStart: function() {
  7073. this._point = 0;
  7074. },
  7075. lineEnd: function() {
  7076. if (this._line === 0) this._context.closePath();
  7077. this._point = NaN;
  7078. },
  7079. point: function(x, y) {
  7080. switch (this._point) {
  7081. case 0: {
  7082. this._context.moveTo(x, y);
  7083. this._point = 1;
  7084. break;
  7085. }
  7086. case 1: {
  7087. this._context.lineTo(x, y);
  7088. break;
  7089. }
  7090. default: {
  7091. this._context.moveTo(x + this._radius, y);
  7092. this._context.arc(x, y, this._radius, 0, tau$3);
  7093. break;
  7094. }
  7095. }
  7096. },
  7097. result: noop$1
  7098. };
  7099. var lengthSum$1 = adder();
  7100. var lengthRing;
  7101. var x00$2;
  7102. var y00$2;
  7103. var x0$4;
  7104. var y0$4;
  7105. var lengthStream$1 = {
  7106. point: noop$1,
  7107. lineStart: function() {
  7108. lengthStream$1.point = lengthPointFirst$1;
  7109. },
  7110. lineEnd: function() {
  7111. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  7112. lengthStream$1.point = noop$1;
  7113. },
  7114. polygonStart: function() {
  7115. lengthRing = true;
  7116. },
  7117. polygonEnd: function() {
  7118. lengthRing = null;
  7119. },
  7120. result: function() {
  7121. var length = +lengthSum$1;
  7122. lengthSum$1.reset();
  7123. return length;
  7124. }
  7125. };
  7126. function lengthPointFirst$1(x, y) {
  7127. lengthStream$1.point = lengthPoint$1;
  7128. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  7129. }
  7130. function lengthPoint$1(x, y) {
  7131. x0$4 -= x, y0$4 -= y;
  7132. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  7133. x0$4 = x, y0$4 = y;
  7134. }
  7135. function PathString() {
  7136. this._string = [];
  7137. }
  7138. PathString.prototype = {
  7139. _radius: 4.5,
  7140. _circle: circle$1(4.5),
  7141. pointRadius: function(_) {
  7142. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  7143. return this;
  7144. },
  7145. polygonStart: function() {
  7146. this._line = 0;
  7147. },
  7148. polygonEnd: function() {
  7149. this._line = NaN;
  7150. },
  7151. lineStart: function() {
  7152. this._point = 0;
  7153. },
  7154. lineEnd: function() {
  7155. if (this._line === 0) this._string.push("Z");
  7156. this._point = NaN;
  7157. },
  7158. point: function(x, y) {
  7159. switch (this._point) {
  7160. case 0: {
  7161. this._string.push("M", x, ",", y);
  7162. this._point = 1;
  7163. break;
  7164. }
  7165. case 1: {
  7166. this._string.push("L", x, ",", y);
  7167. break;
  7168. }
  7169. default: {
  7170. if (this._circle == null) this._circle = circle$1(this._radius);
  7171. this._string.push("M", x, ",", y, this._circle);
  7172. break;
  7173. }
  7174. }
  7175. },
  7176. result: function() {
  7177. if (this._string.length) {
  7178. var result = this._string.join("");
  7179. this._string = [];
  7180. return result;
  7181. } else {
  7182. return null;
  7183. }
  7184. }
  7185. };
  7186. function circle$1(radius) {
  7187. return "m0," + radius
  7188. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  7189. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  7190. + "z";
  7191. }
  7192. var index$1 = function(projection, context) {
  7193. var pointRadius = 4.5,
  7194. projectionStream,
  7195. contextStream;
  7196. function path(object) {
  7197. if (object) {
  7198. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  7199. geoStream(object, projectionStream(contextStream));
  7200. }
  7201. return contextStream.result();
  7202. }
  7203. path.area = function(object) {
  7204. geoStream(object, projectionStream(areaStream$1));
  7205. return areaStream$1.result();
  7206. };
  7207. path.measure = function(object) {
  7208. geoStream(object, projectionStream(lengthStream$1));
  7209. return lengthStream$1.result();
  7210. };
  7211. path.bounds = function(object) {
  7212. geoStream(object, projectionStream(boundsStream$1));
  7213. return boundsStream$1.result();
  7214. };
  7215. path.centroid = function(object) {
  7216. geoStream(object, projectionStream(centroidStream$1));
  7217. return centroidStream$1.result();
  7218. };
  7219. path.projection = function(_) {
  7220. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  7221. };
  7222. path.context = function(_) {
  7223. if (!arguments.length) return context;
  7224. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  7225. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  7226. return path;
  7227. };
  7228. path.pointRadius = function(_) {
  7229. if (!arguments.length) return pointRadius;
  7230. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  7231. return path;
  7232. };
  7233. return path.projection(projection).context(context);
  7234. };
  7235. var clip = function(pointVisible, clipLine, interpolate, start) {
  7236. return function(rotate, sink) {
  7237. var line = clipLine(sink),
  7238. rotatedStart = rotate.invert(start[0], start[1]),
  7239. ringBuffer = clipBuffer(),
  7240. ringSink = clipLine(ringBuffer),
  7241. polygonStarted = false,
  7242. polygon,
  7243. segments,
  7244. ring;
  7245. var clip = {
  7246. point: point,
  7247. lineStart: lineStart,
  7248. lineEnd: lineEnd,
  7249. polygonStart: function() {
  7250. clip.point = pointRing;
  7251. clip.lineStart = ringStart;
  7252. clip.lineEnd = ringEnd;
  7253. segments = [];
  7254. polygon = [];
  7255. },
  7256. polygonEnd: function() {
  7257. clip.point = point;
  7258. clip.lineStart = lineStart;
  7259. clip.lineEnd = lineEnd;
  7260. segments = merge(segments);
  7261. var startInside = polygonContains(polygon, rotatedStart);
  7262. if (segments.length) {
  7263. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7264. clipPolygon(segments, compareIntersection, startInside, interpolate, sink);
  7265. } else if (startInside) {
  7266. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7267. sink.lineStart();
  7268. interpolate(null, null, 1, sink);
  7269. sink.lineEnd();
  7270. }
  7271. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  7272. segments = polygon = null;
  7273. },
  7274. sphere: function() {
  7275. sink.polygonStart();
  7276. sink.lineStart();
  7277. interpolate(null, null, 1, sink);
  7278. sink.lineEnd();
  7279. sink.polygonEnd();
  7280. }
  7281. };
  7282. function point(lambda, phi) {
  7283. var point = rotate(lambda, phi);
  7284. if (pointVisible(lambda = point[0], phi = point[1])) sink.point(lambda, phi);
  7285. }
  7286. function pointLine(lambda, phi) {
  7287. var point = rotate(lambda, phi);
  7288. line.point(point[0], point[1]);
  7289. }
  7290. function lineStart() {
  7291. clip.point = pointLine;
  7292. line.lineStart();
  7293. }
  7294. function lineEnd() {
  7295. clip.point = point;
  7296. line.lineEnd();
  7297. }
  7298. function pointRing(lambda, phi) {
  7299. ring.push([lambda, phi]);
  7300. var point = rotate(lambda, phi);
  7301. ringSink.point(point[0], point[1]);
  7302. }
  7303. function ringStart() {
  7304. ringSink.lineStart();
  7305. ring = [];
  7306. }
  7307. function ringEnd() {
  7308. pointRing(ring[0][0], ring[0][1]);
  7309. ringSink.lineEnd();
  7310. var clean = ringSink.clean(),
  7311. ringSegments = ringBuffer.result(),
  7312. i, n = ringSegments.length, m,
  7313. segment,
  7314. point;
  7315. ring.pop();
  7316. polygon.push(ring);
  7317. ring = null;
  7318. if (!n) return;
  7319. // No intersections.
  7320. if (clean & 1) {
  7321. segment = ringSegments[0];
  7322. if ((m = segment.length - 1) > 0) {
  7323. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7324. sink.lineStart();
  7325. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7326. sink.lineEnd();
  7327. }
  7328. return;
  7329. }
  7330. // Rejoin connected segments.
  7331. // TODO reuse ringBuffer.rejoin()?
  7332. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7333. segments.push(ringSegments.filter(validSegment));
  7334. }
  7335. return clip;
  7336. };
  7337. };
  7338. function validSegment(segment) {
  7339. return segment.length > 1;
  7340. }
  7341. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7342. // and circle clipping, the same comparison is used.
  7343. function compareIntersection(a, b) {
  7344. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7345. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7346. }
  7347. var clipAntimeridian = clip(
  7348. function() { return true; },
  7349. clipAntimeridianLine,
  7350. clipAntimeridianInterpolate,
  7351. [-pi$3, -halfPi$2]
  7352. );
  7353. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7354. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7355. // intersections, and the first and last segments should be rejoined.
  7356. function clipAntimeridianLine(stream) {
  7357. var lambda0 = NaN,
  7358. phi0 = NaN,
  7359. sign0 = NaN,
  7360. clean; // no intersections
  7361. return {
  7362. lineStart: function() {
  7363. stream.lineStart();
  7364. clean = 1;
  7365. },
  7366. point: function(lambda1, phi1) {
  7367. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7368. delta = abs(lambda1 - lambda0);
  7369. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7370. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7371. stream.point(sign0, phi0);
  7372. stream.lineEnd();
  7373. stream.lineStart();
  7374. stream.point(sign1, phi0);
  7375. stream.point(lambda1, phi0);
  7376. clean = 0;
  7377. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7378. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7379. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7380. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7381. stream.point(sign0, phi0);
  7382. stream.lineEnd();
  7383. stream.lineStart();
  7384. stream.point(sign1, phi0);
  7385. clean = 0;
  7386. }
  7387. stream.point(lambda0 = lambda1, phi0 = phi1);
  7388. sign0 = sign1;
  7389. },
  7390. lineEnd: function() {
  7391. stream.lineEnd();
  7392. lambda0 = phi0 = NaN;
  7393. },
  7394. clean: function() {
  7395. return 2 - clean; // if intersections, rejoin first and last segments
  7396. }
  7397. };
  7398. }
  7399. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7400. var cosPhi0,
  7401. cosPhi1,
  7402. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7403. return abs(sinLambda0Lambda1) > epsilon$2
  7404. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7405. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7406. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7407. : (phi0 + phi1) / 2;
  7408. }
  7409. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7410. var phi;
  7411. if (from == null) {
  7412. phi = direction * halfPi$2;
  7413. stream.point(-pi$3, phi);
  7414. stream.point(0, phi);
  7415. stream.point(pi$3, phi);
  7416. stream.point(pi$3, 0);
  7417. stream.point(pi$3, -phi);
  7418. stream.point(0, -phi);
  7419. stream.point(-pi$3, -phi);
  7420. stream.point(-pi$3, 0);
  7421. stream.point(-pi$3, phi);
  7422. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7423. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7424. phi = direction * lambda / 2;
  7425. stream.point(-lambda, phi);
  7426. stream.point(0, phi);
  7427. stream.point(lambda, phi);
  7428. } else {
  7429. stream.point(to[0], to[1]);
  7430. }
  7431. }
  7432. var clipCircle = function(radius, delta) {
  7433. var cr = cos$1(radius),
  7434. smallRadius = cr > 0,
  7435. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7436. function interpolate(from, to, direction, stream) {
  7437. circleStream(stream, radius, delta, direction, from, to);
  7438. }
  7439. function visible(lambda, phi) {
  7440. return cos$1(lambda) * cos$1(phi) > cr;
  7441. }
  7442. // Takes a line and cuts into visible segments. Return values used for polygon
  7443. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7444. // intersections 2 - there were intersections, and the first and last segments
  7445. // should be rejoined.
  7446. function clipLine(stream) {
  7447. var point0, // previous point
  7448. c0, // code for previous point
  7449. v0, // visibility of previous point
  7450. v00, // visibility of first point
  7451. clean; // no intersections
  7452. return {
  7453. lineStart: function() {
  7454. v00 = v0 = false;
  7455. clean = 1;
  7456. },
  7457. point: function(lambda, phi) {
  7458. var point1 = [lambda, phi],
  7459. point2,
  7460. v = visible(lambda, phi),
  7461. c = smallRadius
  7462. ? v ? 0 : code(lambda, phi)
  7463. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7464. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7465. // Handle degeneracies.
  7466. // TODO ignore if not clipping polygons.
  7467. if (v !== v0) {
  7468. point2 = intersect(point0, point1);
  7469. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7470. point1[0] += epsilon$2;
  7471. point1[1] += epsilon$2;
  7472. v = visible(point1[0], point1[1]);
  7473. }
  7474. }
  7475. if (v !== v0) {
  7476. clean = 0;
  7477. if (v) {
  7478. // outside going in
  7479. stream.lineStart();
  7480. point2 = intersect(point1, point0);
  7481. stream.point(point2[0], point2[1]);
  7482. } else {
  7483. // inside going out
  7484. point2 = intersect(point0, point1);
  7485. stream.point(point2[0], point2[1]);
  7486. stream.lineEnd();
  7487. }
  7488. point0 = point2;
  7489. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7490. var t;
  7491. // If the codes for two points are different, or are both zero,
  7492. // and there this segment intersects with the small circle.
  7493. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7494. clean = 0;
  7495. if (smallRadius) {
  7496. stream.lineStart();
  7497. stream.point(t[0][0], t[0][1]);
  7498. stream.point(t[1][0], t[1][1]);
  7499. stream.lineEnd();
  7500. } else {
  7501. stream.point(t[1][0], t[1][1]);
  7502. stream.lineEnd();
  7503. stream.lineStart();
  7504. stream.point(t[0][0], t[0][1]);
  7505. }
  7506. }
  7507. }
  7508. if (v && (!point0 || !pointEqual(point0, point1))) {
  7509. stream.point(point1[0], point1[1]);
  7510. }
  7511. point0 = point1, v0 = v, c0 = c;
  7512. },
  7513. lineEnd: function() {
  7514. if (v0) stream.lineEnd();
  7515. point0 = null;
  7516. },
  7517. // Rejoin first and last segments if there were intersections and the first
  7518. // and last points were visible.
  7519. clean: function() {
  7520. return clean | ((v00 && v0) << 1);
  7521. }
  7522. };
  7523. }
  7524. // Intersects the great circle between a and b with the clip circle.
  7525. function intersect(a, b, two) {
  7526. var pa = cartesian(a),
  7527. pb = cartesian(b);
  7528. // We have two planes, n1.p = d1 and n2.p = d2.
  7529. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7530. var n1 = [1, 0, 0], // normal
  7531. n2 = cartesianCross(pa, pb),
  7532. n2n2 = cartesianDot(n2, n2),
  7533. n1n2 = n2[0], // cartesianDot(n1, n2),
  7534. determinant = n2n2 - n1n2 * n1n2;
  7535. // Two polar points.
  7536. if (!determinant) return !two && a;
  7537. var c1 = cr * n2n2 / determinant,
  7538. c2 = -cr * n1n2 / determinant,
  7539. n1xn2 = cartesianCross(n1, n2),
  7540. A = cartesianScale(n1, c1),
  7541. B = cartesianScale(n2, c2);
  7542. cartesianAddInPlace(A, B);
  7543. // Solve |p(t)|^2 = 1.
  7544. var u = n1xn2,
  7545. w = cartesianDot(A, u),
  7546. uu = cartesianDot(u, u),
  7547. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7548. if (t2 < 0) return;
  7549. var t = sqrt(t2),
  7550. q = cartesianScale(u, (-w - t) / uu);
  7551. cartesianAddInPlace(q, A);
  7552. q = spherical(q);
  7553. if (!two) return q;
  7554. // Two intersection points.
  7555. var lambda0 = a[0],
  7556. lambda1 = b[0],
  7557. phi0 = a[1],
  7558. phi1 = b[1],
  7559. z;
  7560. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7561. var delta = lambda1 - lambda0,
  7562. polar = abs(delta - pi$3) < epsilon$2,
  7563. meridian = polar || delta < epsilon$2;
  7564. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7565. // Check that the first point is between a and b.
  7566. if (meridian
  7567. ? polar
  7568. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7569. : phi0 <= q[1] && q[1] <= phi1
  7570. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7571. var q1 = cartesianScale(u, (-w + t) / uu);
  7572. cartesianAddInPlace(q1, A);
  7573. return [q, spherical(q1)];
  7574. }
  7575. }
  7576. // Generates a 4-bit vector representing the location of a point relative to
  7577. // the small circle's bounding box.
  7578. function code(lambda, phi) {
  7579. var r = smallRadius ? radius : pi$3 - radius,
  7580. code = 0;
  7581. if (lambda < -r) code |= 1; // left
  7582. else if (lambda > r) code |= 2; // right
  7583. if (phi < -r) code |= 4; // below
  7584. else if (phi > r) code |= 8; // above
  7585. return code;
  7586. }
  7587. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7588. };
  7589. var transform = function(methods) {
  7590. return {
  7591. stream: transformer(methods)
  7592. };
  7593. };
  7594. function transformer(methods) {
  7595. return function(stream) {
  7596. var s = new TransformStream;
  7597. for (var key in methods) s[key] = methods[key];
  7598. s.stream = stream;
  7599. return s;
  7600. };
  7601. }
  7602. function TransformStream() {}
  7603. TransformStream.prototype = {
  7604. constructor: TransformStream,
  7605. point: function(x, y) { this.stream.point(x, y); },
  7606. sphere: function() { this.stream.sphere(); },
  7607. lineStart: function() { this.stream.lineStart(); },
  7608. lineEnd: function() { this.stream.lineEnd(); },
  7609. polygonStart: function() { this.stream.polygonStart(); },
  7610. polygonEnd: function() { this.stream.polygonEnd(); }
  7611. };
  7612. function fitExtent(projection, extent, object) {
  7613. var w = extent[1][0] - extent[0][0],
  7614. h = extent[1][1] - extent[0][1],
  7615. clip = projection.clipExtent && projection.clipExtent();
  7616. projection
  7617. .scale(150)
  7618. .translate([0, 0]);
  7619. if (clip != null) projection.clipExtent(null);
  7620. geoStream(object, projection.stream(boundsStream$1));
  7621. var b = boundsStream$1.result(),
  7622. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  7623. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  7624. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  7625. if (clip != null) projection.clipExtent(clip);
  7626. return projection
  7627. .scale(k * 150)
  7628. .translate([x, y]);
  7629. }
  7630. function fitSize(projection, size, object) {
  7631. return fitExtent(projection, [[0, 0], size], object);
  7632. }
  7633. var maxDepth = 16;
  7634. var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  7635. var resample = function(project, delta2) {
  7636. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  7637. };
  7638. function resampleNone(project) {
  7639. return transformer({
  7640. point: function(x, y) {
  7641. x = project(x, y);
  7642. this.stream.point(x[0], x[1]);
  7643. }
  7644. });
  7645. }
  7646. function resample$1(project, delta2) {
  7647. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  7648. var dx = x1 - x0,
  7649. dy = y1 - y0,
  7650. d2 = dx * dx + dy * dy;
  7651. if (d2 > 4 * delta2 && depth--) {
  7652. var a = a0 + a1,
  7653. b = b0 + b1,
  7654. c = c0 + c1,
  7655. m = sqrt(a * a + b * b + c * c),
  7656. phi2 = asin(c /= m),
  7657. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  7658. p = project(lambda2, phi2),
  7659. x2 = p[0],
  7660. y2 = p[1],
  7661. dx2 = x2 - x0,
  7662. dy2 = y2 - y0,
  7663. dz = dy * dx2 - dx * dy2;
  7664. if (dz * dz / d2 > delta2 // perpendicular projected distance
  7665. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  7666. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  7667. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  7668. stream.point(x2, y2);
  7669. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  7670. }
  7671. }
  7672. }
  7673. return function(stream) {
  7674. var lambda00, x00, y00, a00, b00, c00, // first point
  7675. lambda0, x0, y0, a0, b0, c0; // previous point
  7676. var resampleStream = {
  7677. point: point,
  7678. lineStart: lineStart,
  7679. lineEnd: lineEnd,
  7680. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  7681. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  7682. };
  7683. function point(x, y) {
  7684. x = project(x, y);
  7685. stream.point(x[0], x[1]);
  7686. }
  7687. function lineStart() {
  7688. x0 = NaN;
  7689. resampleStream.point = linePoint;
  7690. stream.lineStart();
  7691. }
  7692. function linePoint(lambda, phi) {
  7693. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  7694. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x0 = p[0], y0 = p[1], lambda0 = lambda, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
  7695. stream.point(x0, y0);
  7696. }
  7697. function lineEnd() {
  7698. resampleStream.point = point;
  7699. stream.lineEnd();
  7700. }
  7701. function ringStart() {
  7702. lineStart();
  7703. resampleStream.point = ringPoint;
  7704. resampleStream.lineEnd = ringEnd;
  7705. }
  7706. function ringPoint(lambda, phi) {
  7707. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  7708. resampleStream.point = linePoint;
  7709. }
  7710. function ringEnd() {
  7711. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  7712. resampleStream.lineEnd = lineEnd;
  7713. lineEnd();
  7714. }
  7715. return resampleStream;
  7716. };
  7717. }
  7718. var transformRadians = transformer({
  7719. point: function(x, y) {
  7720. this.stream.point(x * radians, y * radians);
  7721. }
  7722. });
  7723. function projection(project) {
  7724. return projectionMutator(function() { return project; })();
  7725. }
  7726. function projectionMutator(projectAt) {
  7727. var project,
  7728. k = 150, // scale
  7729. x = 480, y = 250, // translate
  7730. dx, dy, lambda = 0, phi = 0, // center
  7731. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
  7732. theta = null, preclip = clipAntimeridian, // clip angle
  7733. x0 = null, y0, x1, y1, postclip = identity$4, // clip extent
  7734. delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
  7735. cache,
  7736. cacheStream;
  7737. function projection(point) {
  7738. point = projectRotate(point[0] * radians, point[1] * radians);
  7739. return [point[0] * k + dx, dy - point[1] * k];
  7740. }
  7741. function invert(point) {
  7742. point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
  7743. return point && [point[0] * degrees$1, point[1] * degrees$1];
  7744. }
  7745. function projectTransform(x, y) {
  7746. return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
  7747. }
  7748. projection.stream = function(stream) {
  7749. return cache && cacheStream === stream ? cache : cache = transformRadians(preclip(rotate, projectResample(postclip(cacheStream = stream))));
  7750. };
  7751. projection.clipAngle = function(_) {
  7752. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians, 6 * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  7753. };
  7754. projection.clipExtent = function(_) {
  7755. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  7756. };
  7757. projection.scale = function(_) {
  7758. return arguments.length ? (k = +_, recenter()) : k;
  7759. };
  7760. projection.translate = function(_) {
  7761. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  7762. };
  7763. projection.center = function(_) {
  7764. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  7765. };
  7766. projection.rotate = function(_) {
  7767. return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees$1, deltaPhi * degrees$1, deltaGamma * degrees$1];
  7768. };
  7769. projection.precision = function(_) {
  7770. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  7771. };
  7772. projection.fitExtent = function(extent, object) {
  7773. return fitExtent(projection, extent, object);
  7774. };
  7775. projection.fitSize = function(size, object) {
  7776. return fitSize(projection, size, object);
  7777. };
  7778. function recenter() {
  7779. projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
  7780. var center = project(lambda, phi);
  7781. dx = x - center[0] * k;
  7782. dy = y + center[1] * k;
  7783. return reset();
  7784. }
  7785. function reset() {
  7786. cache = cacheStream = null;
  7787. return projection;
  7788. }
  7789. return function() {
  7790. project = projectAt.apply(this, arguments);
  7791. projection.invert = project.invert && invert;
  7792. return recenter();
  7793. };
  7794. }
  7795. function conicProjection(projectAt) {
  7796. var phi0 = 0,
  7797. phi1 = pi$3 / 3,
  7798. m = projectionMutator(projectAt),
  7799. p = m(phi0, phi1);
  7800. p.parallels = function(_) {
  7801. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  7802. };
  7803. return p;
  7804. }
  7805. function cylindricalEqualAreaRaw(phi0) {
  7806. var cosPhi0 = cos$1(phi0);
  7807. function forward(lambda, phi) {
  7808. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  7809. }
  7810. forward.invert = function(x, y) {
  7811. return [x / cosPhi0, asin(y * cosPhi0)];
  7812. };
  7813. return forward;
  7814. }
  7815. function conicEqualAreaRaw(y0, y1) {
  7816. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  7817. // Are the parallels symmetrical around the Equator?
  7818. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  7819. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  7820. function project(x, y) {
  7821. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  7822. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  7823. }
  7824. project.invert = function(x, y) {
  7825. var r0y = r0 - y;
  7826. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  7827. };
  7828. return project;
  7829. }
  7830. var conicEqualArea = function() {
  7831. return conicProjection(conicEqualAreaRaw)
  7832. .scale(155.424)
  7833. .center([0, 33.6442]);
  7834. };
  7835. var albers = function() {
  7836. return conicEqualArea()
  7837. .parallels([29.5, 45.5])
  7838. .scale(1070)
  7839. .translate([480, 250])
  7840. .rotate([96, 0])
  7841. .center([-0.6, 38.7]);
  7842. };
  7843. // The projections must have mutually exclusive clip regions on the sphere,
  7844. // as this will avoid emitting interleaving lines and polygons.
  7845. function multiplex(streams) {
  7846. var n = streams.length;
  7847. return {
  7848. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  7849. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  7850. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  7851. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  7852. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  7853. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  7854. };
  7855. }
  7856. // A composite projection for the United States, configured by default for
  7857. // 960×500. The projection also works quite well at 960×600 if you change the
  7858. // scale to 1285 and adjust the translate accordingly. The set of standard
  7859. // parallels for each region comes from USGS, which is published here:
  7860. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  7861. var albersUsa = function() {
  7862. var cache,
  7863. cacheStream,
  7864. lower48 = albers(), lower48Point,
  7865. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  7866. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  7867. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  7868. function albersUsa(coordinates) {
  7869. var x = coordinates[0], y = coordinates[1];
  7870. return point = null,
  7871. (lower48Point.point(x, y), point)
  7872. || (alaskaPoint.point(x, y), point)
  7873. || (hawaiiPoint.point(x, y), point);
  7874. }
  7875. albersUsa.invert = function(coordinates) {
  7876. var k = lower48.scale(),
  7877. t = lower48.translate(),
  7878. x = (coordinates[0] - t[0]) / k,
  7879. y = (coordinates[1] - t[1]) / k;
  7880. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  7881. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  7882. : lower48).invert(coordinates);
  7883. };
  7884. albersUsa.stream = function(stream) {
  7885. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  7886. };
  7887. albersUsa.precision = function(_) {
  7888. if (!arguments.length) return lower48.precision();
  7889. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  7890. return reset();
  7891. };
  7892. albersUsa.scale = function(_) {
  7893. if (!arguments.length) return lower48.scale();
  7894. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  7895. return albersUsa.translate(lower48.translate());
  7896. };
  7897. albersUsa.translate = function(_) {
  7898. if (!arguments.length) return lower48.translate();
  7899. var k = lower48.scale(), x = +_[0], y = +_[1];
  7900. lower48Point = lower48
  7901. .translate(_)
  7902. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  7903. .stream(pointStream);
  7904. alaskaPoint = alaska
  7905. .translate([x - 0.307 * k, y + 0.201 * k])
  7906. .clipExtent([[x - 0.425 * k + epsilon$2, y + 0.120 * k + epsilon$2], [x - 0.214 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
  7907. .stream(pointStream);
  7908. hawaiiPoint = hawaii
  7909. .translate([x - 0.205 * k, y + 0.212 * k])
  7910. .clipExtent([[x - 0.214 * k + epsilon$2, y + 0.166 * k + epsilon$2], [x - 0.115 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
  7911. .stream(pointStream);
  7912. return reset();
  7913. };
  7914. albersUsa.fitExtent = function(extent, object) {
  7915. return fitExtent(albersUsa, extent, object);
  7916. };
  7917. albersUsa.fitSize = function(size, object) {
  7918. return fitSize(albersUsa, size, object);
  7919. };
  7920. function reset() {
  7921. cache = cacheStream = null;
  7922. return albersUsa;
  7923. }
  7924. return albersUsa.scale(1070);
  7925. };
  7926. function azimuthalRaw(scale) {
  7927. return function(x, y) {
  7928. var cx = cos$1(x),
  7929. cy = cos$1(y),
  7930. k = scale(cx * cy);
  7931. return [
  7932. k * cy * sin$1(x),
  7933. k * sin$1(y)
  7934. ];
  7935. }
  7936. }
  7937. function azimuthalInvert(angle) {
  7938. return function(x, y) {
  7939. var z = sqrt(x * x + y * y),
  7940. c = angle(z),
  7941. sc = sin$1(c),
  7942. cc = cos$1(c);
  7943. return [
  7944. atan2(x * sc, z * cc),
  7945. asin(z && y * sc / z)
  7946. ];
  7947. }
  7948. }
  7949. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  7950. return sqrt(2 / (1 + cxcy));
  7951. });
  7952. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  7953. return 2 * asin(z / 2);
  7954. });
  7955. var azimuthalEqualArea = function() {
  7956. return projection(azimuthalEqualAreaRaw)
  7957. .scale(124.75)
  7958. .clipAngle(180 - 1e-3);
  7959. };
  7960. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  7961. return (c = acos(c)) && c / sin$1(c);
  7962. });
  7963. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  7964. return z;
  7965. });
  7966. var azimuthalEquidistant = function() {
  7967. return projection(azimuthalEquidistantRaw)
  7968. .scale(79.4188)
  7969. .clipAngle(180 - 1e-3);
  7970. };
  7971. function mercatorRaw(lambda, phi) {
  7972. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  7973. }
  7974. mercatorRaw.invert = function(x, y) {
  7975. return [x, 2 * atan(exp(y)) - halfPi$2];
  7976. };
  7977. var mercator = function() {
  7978. return mercatorProjection(mercatorRaw)
  7979. .scale(961 / tau$3);
  7980. };
  7981. function mercatorProjection(project) {
  7982. var m = projection(project),
  7983. center = m.center,
  7984. scale = m.scale,
  7985. translate = m.translate,
  7986. clipExtent = m.clipExtent,
  7987. x0 = null, y0, x1, y1; // clip extent
  7988. m.scale = function(_) {
  7989. return arguments.length ? (scale(_), reclip()) : scale();
  7990. };
  7991. m.translate = function(_) {
  7992. return arguments.length ? (translate(_), reclip()) : translate();
  7993. };
  7994. m.center = function(_) {
  7995. return arguments.length ? (center(_), reclip()) : center();
  7996. };
  7997. m.clipExtent = function(_) {
  7998. return arguments.length ? ((_ == null ? x0 = y0 = x1 = y1 = null : (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1])), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  7999. };
  8000. function reclip() {
  8001. var k = pi$3 * scale(),
  8002. t = m(rotation(m.rotate()).invert([0, 0]));
  8003. return clipExtent(x0 == null
  8004. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8005. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8006. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8007. }
  8008. return reclip();
  8009. }
  8010. function tany(y) {
  8011. return tan((halfPi$2 + y) / 2);
  8012. }
  8013. function conicConformalRaw(y0, y1) {
  8014. var cy0 = cos$1(y0),
  8015. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8016. f = cy0 * pow(tany(y0), n) / n;
  8017. if (!n) return mercatorRaw;
  8018. function project(x, y) {
  8019. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8020. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8021. var r = f / pow(tany(y), n);
  8022. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8023. }
  8024. project.invert = function(x, y) {
  8025. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8026. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8027. };
  8028. return project;
  8029. }
  8030. var conicConformal = function() {
  8031. return conicProjection(conicConformalRaw)
  8032. .scale(109.5)
  8033. .parallels([30, 30]);
  8034. };
  8035. function equirectangularRaw(lambda, phi) {
  8036. return [lambda, phi];
  8037. }
  8038. equirectangularRaw.invert = equirectangularRaw;
  8039. var equirectangular = function() {
  8040. return projection(equirectangularRaw)
  8041. .scale(152.63);
  8042. };
  8043. function conicEquidistantRaw(y0, y1) {
  8044. var cy0 = cos$1(y0),
  8045. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8046. g = cy0 / n + y0;
  8047. if (abs(n) < epsilon$2) return equirectangularRaw;
  8048. function project(x, y) {
  8049. var gy = g - y, nx = n * x;
  8050. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8051. }
  8052. project.invert = function(x, y) {
  8053. var gy = g - y;
  8054. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8055. };
  8056. return project;
  8057. }
  8058. var conicEquidistant = function() {
  8059. return conicProjection(conicEquidistantRaw)
  8060. .scale(131.154)
  8061. .center([0, 13.9389]);
  8062. };
  8063. function gnomonicRaw(x, y) {
  8064. var cy = cos$1(y), k = cos$1(x) * cy;
  8065. return [cy * sin$1(x) / k, sin$1(y) / k];
  8066. }
  8067. gnomonicRaw.invert = azimuthalInvert(atan);
  8068. var gnomonic = function() {
  8069. return projection(gnomonicRaw)
  8070. .scale(144.049)
  8071. .clipAngle(60);
  8072. };
  8073. function scaleTranslate(kx, ky, tx, ty) {
  8074. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8075. point: function(x, y) {
  8076. this.stream.point(x * kx + tx, y * ky + ty);
  8077. }
  8078. });
  8079. }
  8080. var identity$5 = function() {
  8081. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
  8082. x0 = null, y0, x1, y1, clip = identity$4, // clip extent
  8083. cache,
  8084. cacheStream,
  8085. projection;
  8086. function reset() {
  8087. cache = cacheStream = null;
  8088. return projection;
  8089. }
  8090. return projection = {
  8091. stream: function(stream) {
  8092. return cache && cacheStream === stream ? cache : cache = transform$$1(clip(cacheStream = stream));
  8093. },
  8094. clipExtent: function(_) {
  8095. return arguments.length ? (clip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  8096. },
  8097. scale: function(_) {
  8098. return arguments.length ? (transform$$1 = scaleTranslate((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8099. },
  8100. translate: function(_) {
  8101. return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8102. },
  8103. reflectX: function(_) {
  8104. return arguments.length ? (transform$$1 = scaleTranslate(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8105. },
  8106. reflectY: function(_) {
  8107. return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8108. },
  8109. fitExtent: function(extent, object) {
  8110. return fitExtent(projection, extent, object);
  8111. },
  8112. fitSize: function(size, object) {
  8113. return fitSize(projection, size, object);
  8114. }
  8115. };
  8116. };
  8117. function orthographicRaw(x, y) {
  8118. return [cos$1(y) * sin$1(x), sin$1(y)];
  8119. }
  8120. orthographicRaw.invert = azimuthalInvert(asin);
  8121. var orthographic = function() {
  8122. return projection(orthographicRaw)
  8123. .scale(249.5)
  8124. .clipAngle(90 + epsilon$2);
  8125. };
  8126. function stereographicRaw(x, y) {
  8127. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8128. return [cy * sin$1(x) / k, sin$1(y) / k];
  8129. }
  8130. stereographicRaw.invert = azimuthalInvert(function(z) {
  8131. return 2 * atan(z);
  8132. });
  8133. var stereographic = function() {
  8134. return projection(stereographicRaw)
  8135. .scale(250)
  8136. .clipAngle(142);
  8137. };
  8138. function transverseMercatorRaw(lambda, phi) {
  8139. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8140. }
  8141. transverseMercatorRaw.invert = function(x, y) {
  8142. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8143. };
  8144. var transverseMercator = function() {
  8145. var m = mercatorProjection(transverseMercatorRaw),
  8146. center = m.center,
  8147. rotate = m.rotate;
  8148. m.center = function(_) {
  8149. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8150. };
  8151. m.rotate = function(_) {
  8152. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8153. };
  8154. return rotate([0, 0, 90])
  8155. .scale(159.155);
  8156. };
  8157. function defaultSeparation(a, b) {
  8158. return a.parent === b.parent ? 1 : 2;
  8159. }
  8160. function meanX(children) {
  8161. return children.reduce(meanXReduce, 0) / children.length;
  8162. }
  8163. function meanXReduce(x, c) {
  8164. return x + c.x;
  8165. }
  8166. function maxY(children) {
  8167. return 1 + children.reduce(maxYReduce, 0);
  8168. }
  8169. function maxYReduce(y, c) {
  8170. return Math.max(y, c.y);
  8171. }
  8172. function leafLeft(node) {
  8173. var children;
  8174. while (children = node.children) node = children[0];
  8175. return node;
  8176. }
  8177. function leafRight(node) {
  8178. var children;
  8179. while (children = node.children) node = children[children.length - 1];
  8180. return node;
  8181. }
  8182. var cluster = function() {
  8183. var separation = defaultSeparation,
  8184. dx = 1,
  8185. dy = 1,
  8186. nodeSize = false;
  8187. function cluster(root) {
  8188. var previousNode,
  8189. x = 0;
  8190. // First walk, computing the initial x & y values.
  8191. root.eachAfter(function(node) {
  8192. var children = node.children;
  8193. if (children) {
  8194. node.x = meanX(children);
  8195. node.y = maxY(children);
  8196. } else {
  8197. node.x = previousNode ? x += separation(node, previousNode) : 0;
  8198. node.y = 0;
  8199. previousNode = node;
  8200. }
  8201. });
  8202. var left = leafLeft(root),
  8203. right = leafRight(root),
  8204. x0 = left.x - separation(left, right) / 2,
  8205. x1 = right.x + separation(right, left) / 2;
  8206. // Second walk, normalizing x & y to the desired size.
  8207. return root.eachAfter(nodeSize ? function(node) {
  8208. node.x = (node.x - root.x) * dx;
  8209. node.y = (root.y - node.y) * dy;
  8210. } : function(node) {
  8211. node.x = (node.x - x0) / (x1 - x0) * dx;
  8212. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  8213. });
  8214. }
  8215. cluster.separation = function(x) {
  8216. return arguments.length ? (separation = x, cluster) : separation;
  8217. };
  8218. cluster.size = function(x) {
  8219. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  8220. };
  8221. cluster.nodeSize = function(x) {
  8222. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  8223. };
  8224. return cluster;
  8225. };
  8226. function count(node) {
  8227. var sum = 0,
  8228. children = node.children,
  8229. i = children && children.length;
  8230. if (!i) sum = 1;
  8231. else while (--i >= 0) sum += children[i].value;
  8232. node.value = sum;
  8233. }
  8234. var node_count = function() {
  8235. return this.eachAfter(count);
  8236. };
  8237. var node_each = function(callback) {
  8238. var node = this, current, next = [node], children, i, n;
  8239. do {
  8240. current = next.reverse(), next = [];
  8241. while (node = current.pop()) {
  8242. callback(node), children = node.children;
  8243. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8244. next.push(children[i]);
  8245. }
  8246. }
  8247. } while (next.length);
  8248. return this;
  8249. };
  8250. var node_eachBefore = function(callback) {
  8251. var node = this, nodes = [node], children, i;
  8252. while (node = nodes.pop()) {
  8253. callback(node), children = node.children;
  8254. if (children) for (i = children.length - 1; i >= 0; --i) {
  8255. nodes.push(children[i]);
  8256. }
  8257. }
  8258. return this;
  8259. };
  8260. var node_eachAfter = function(callback) {
  8261. var node = this, nodes = [node], next = [], children, i, n;
  8262. while (node = nodes.pop()) {
  8263. next.push(node), children = node.children;
  8264. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8265. nodes.push(children[i]);
  8266. }
  8267. }
  8268. while (node = next.pop()) {
  8269. callback(node);
  8270. }
  8271. return this;
  8272. };
  8273. var node_sum = function(value) {
  8274. return this.eachAfter(function(node) {
  8275. var sum = +value(node.data) || 0,
  8276. children = node.children,
  8277. i = children && children.length;
  8278. while (--i >= 0) sum += children[i].value;
  8279. node.value = sum;
  8280. });
  8281. };
  8282. var node_sort = function(compare) {
  8283. return this.eachBefore(function(node) {
  8284. if (node.children) {
  8285. node.children.sort(compare);
  8286. }
  8287. });
  8288. };
  8289. var node_path = function(end) {
  8290. var start = this,
  8291. ancestor = leastCommonAncestor(start, end),
  8292. nodes = [start];
  8293. while (start !== ancestor) {
  8294. start = start.parent;
  8295. nodes.push(start);
  8296. }
  8297. var k = nodes.length;
  8298. while (end !== ancestor) {
  8299. nodes.splice(k, 0, end);
  8300. end = end.parent;
  8301. }
  8302. return nodes;
  8303. };
  8304. function leastCommonAncestor(a, b) {
  8305. if (a === b) return a;
  8306. var aNodes = a.ancestors(),
  8307. bNodes = b.ancestors(),
  8308. c = null;
  8309. a = aNodes.pop();
  8310. b = bNodes.pop();
  8311. while (a === b) {
  8312. c = a;
  8313. a = aNodes.pop();
  8314. b = bNodes.pop();
  8315. }
  8316. return c;
  8317. }
  8318. var node_ancestors = function() {
  8319. var node = this, nodes = [node];
  8320. while (node = node.parent) {
  8321. nodes.push(node);
  8322. }
  8323. return nodes;
  8324. };
  8325. var node_descendants = function() {
  8326. var nodes = [];
  8327. this.each(function(node) {
  8328. nodes.push(node);
  8329. });
  8330. return nodes;
  8331. };
  8332. var node_leaves = function() {
  8333. var leaves = [];
  8334. this.eachBefore(function(node) {
  8335. if (!node.children) {
  8336. leaves.push(node);
  8337. }
  8338. });
  8339. return leaves;
  8340. };
  8341. var node_links = function() {
  8342. var root = this, links = [];
  8343. root.each(function(node) {
  8344. if (node !== root) { // Don’t include the root’s parent, if any.
  8345. links.push({source: node.parent, target: node});
  8346. }
  8347. });
  8348. return links;
  8349. };
  8350. function hierarchy(data, children) {
  8351. var root = new Node(data),
  8352. valued = +data.value && (root.value = data.value),
  8353. node,
  8354. nodes = [root],
  8355. child,
  8356. childs,
  8357. i,
  8358. n;
  8359. if (children == null) children = defaultChildren;
  8360. while (node = nodes.pop()) {
  8361. if (valued) node.value = +node.data.value;
  8362. if ((childs = children(node.data)) && (n = childs.length)) {
  8363. node.children = new Array(n);
  8364. for (i = n - 1; i >= 0; --i) {
  8365. nodes.push(child = node.children[i] = new Node(childs[i]));
  8366. child.parent = node;
  8367. child.depth = node.depth + 1;
  8368. }
  8369. }
  8370. }
  8371. return root.eachBefore(computeHeight);
  8372. }
  8373. function node_copy() {
  8374. return hierarchy(this).eachBefore(copyData);
  8375. }
  8376. function defaultChildren(d) {
  8377. return d.children;
  8378. }
  8379. function copyData(node) {
  8380. node.data = node.data.data;
  8381. }
  8382. function computeHeight(node) {
  8383. var height = 0;
  8384. do node.height = height;
  8385. while ((node = node.parent) && (node.height < ++height));
  8386. }
  8387. function Node(data) {
  8388. this.data = data;
  8389. this.depth =
  8390. this.height = 0;
  8391. this.parent = null;
  8392. }
  8393. Node.prototype = hierarchy.prototype = {
  8394. constructor: Node,
  8395. count: node_count,
  8396. each: node_each,
  8397. eachAfter: node_eachAfter,
  8398. eachBefore: node_eachBefore,
  8399. sum: node_sum,
  8400. sort: node_sort,
  8401. path: node_path,
  8402. ancestors: node_ancestors,
  8403. descendants: node_descendants,
  8404. leaves: node_leaves,
  8405. links: node_links,
  8406. copy: node_copy
  8407. };
  8408. var slice$3 = Array.prototype.slice;
  8409. function shuffle$1(array) {
  8410. var m = array.length,
  8411. t,
  8412. i;
  8413. while (m) {
  8414. i = Math.random() * m-- | 0;
  8415. t = array[m];
  8416. array[m] = array[i];
  8417. array[i] = t;
  8418. }
  8419. return array;
  8420. }
  8421. var enclose = function(circles) {
  8422. var i = 0, n = (circles = shuffle$1(slice$3.call(circles))).length, B = [], p, e;
  8423. while (i < n) {
  8424. p = circles[i];
  8425. if (e && enclosesWeak(e, p)) ++i;
  8426. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  8427. }
  8428. return e;
  8429. };
  8430. function extendBasis(B, p) {
  8431. var i, j;
  8432. if (enclosesWeakAll(p, B)) return [p];
  8433. // If we get here then B must have at least one element.
  8434. for (i = 0; i < B.length; ++i) {
  8435. if (enclosesNot(p, B[i])
  8436. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  8437. return [B[i], p];
  8438. }
  8439. }
  8440. // If we get here then B must have at least two elements.
  8441. for (i = 0; i < B.length - 1; ++i) {
  8442. for (j = i + 1; j < B.length; ++j) {
  8443. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  8444. && enclosesNot(encloseBasis2(B[i], p), B[j])
  8445. && enclosesNot(encloseBasis2(B[j], p), B[i])
  8446. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  8447. return [B[i], B[j], p];
  8448. }
  8449. }
  8450. }
  8451. // If we get here then something is very wrong.
  8452. throw new Error;
  8453. }
  8454. function enclosesNot(a, b) {
  8455. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  8456. return dr < 0 || dr * dr < dx * dx + dy * dy;
  8457. }
  8458. function enclosesWeak(a, b) {
  8459. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  8460. return dr > 0 && dr * dr > dx * dx + dy * dy;
  8461. }
  8462. function enclosesWeakAll(a, B) {
  8463. for (var i = 0; i < B.length; ++i) {
  8464. if (!enclosesWeak(a, B[i])) {
  8465. return false;
  8466. }
  8467. }
  8468. return true;
  8469. }
  8470. function encloseBasis(B) {
  8471. switch (B.length) {
  8472. case 1: return encloseBasis1(B[0]);
  8473. case 2: return encloseBasis2(B[0], B[1]);
  8474. case 3: return encloseBasis3(B[0], B[1], B[2]);
  8475. }
  8476. }
  8477. function encloseBasis1(a) {
  8478. return {
  8479. x: a.x,
  8480. y: a.y,
  8481. r: a.r
  8482. };
  8483. }
  8484. function encloseBasis2(a, b) {
  8485. var x1 = a.x, y1 = a.y, r1 = a.r,
  8486. x2 = b.x, y2 = b.y, r2 = b.r,
  8487. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  8488. l = Math.sqrt(x21 * x21 + y21 * y21);
  8489. return {
  8490. x: (x1 + x2 + x21 / l * r21) / 2,
  8491. y: (y1 + y2 + y21 / l * r21) / 2,
  8492. r: (l + r1 + r2) / 2
  8493. };
  8494. }
  8495. function encloseBasis3(a, b, c) {
  8496. var x1 = a.x, y1 = a.y, r1 = a.r,
  8497. x2 = b.x, y2 = b.y, r2 = b.r,
  8498. x3 = c.x, y3 = c.y, r3 = c.r,
  8499. a2 = x1 - x2,
  8500. a3 = x1 - x3,
  8501. b2 = y1 - y2,
  8502. b3 = y1 - y3,
  8503. c2 = r2 - r1,
  8504. c3 = r3 - r1,
  8505. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  8506. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  8507. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  8508. ab = a3 * b2 - a2 * b3,
  8509. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  8510. xb = (b3 * c2 - b2 * c3) / ab,
  8511. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  8512. yb = (a2 * c3 - a3 * c2) / ab,
  8513. A = xb * xb + yb * yb - 1,
  8514. B = 2 * (r1 + xa * xb + ya * yb),
  8515. C = xa * xa + ya * ya - r1 * r1,
  8516. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  8517. return {
  8518. x: x1 + xa + xb * r,
  8519. y: y1 + ya + yb * r,
  8520. r: r
  8521. };
  8522. }
  8523. function place(a, b, c) {
  8524. var ax = a.x,
  8525. ay = a.y,
  8526. da = b.r + c.r,
  8527. db = a.r + c.r,
  8528. dx = b.x - ax,
  8529. dy = b.y - ay,
  8530. dc = dx * dx + dy * dy;
  8531. if (dc) {
  8532. var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
  8533. y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  8534. c.x = ax + x * dx + y * dy;
  8535. c.y = ay + x * dy - y * dx;
  8536. } else {
  8537. c.x = ax + db;
  8538. c.y = ay;
  8539. }
  8540. }
  8541. function intersects(a, b) {
  8542. var dx = b.x - a.x,
  8543. dy = b.y - a.y,
  8544. dr = a.r + b.r;
  8545. return dr * dr - 1e-6 > dx * dx + dy * dy;
  8546. }
  8547. function score(node) {
  8548. var a = node._,
  8549. b = node.next._,
  8550. ab = a.r + b.r,
  8551. dx = (a.x * b.r + b.x * a.r) / ab,
  8552. dy = (a.y * b.r + b.y * a.r) / ab;
  8553. return dx * dx + dy * dy;
  8554. }
  8555. function Node$1(circle) {
  8556. this._ = circle;
  8557. this.next = null;
  8558. this.previous = null;
  8559. }
  8560. function packEnclose(circles) {
  8561. if (!(n = circles.length)) return 0;
  8562. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  8563. // Place the first circle.
  8564. a = circles[0], a.x = 0, a.y = 0;
  8565. if (!(n > 1)) return a.r;
  8566. // Place the second circle.
  8567. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  8568. if (!(n > 2)) return a.r + b.r;
  8569. // Place the third circle.
  8570. place(b, a, c = circles[2]);
  8571. // Initialize the front-chain using the first three circles a, b and c.
  8572. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  8573. a.next = c.previous = b;
  8574. b.next = a.previous = c;
  8575. c.next = b.previous = a;
  8576. // Attempt to place each remaining circle…
  8577. pack: for (i = 3; i < n; ++i) {
  8578. place(a._, b._, c = circles[i]), c = new Node$1(c);
  8579. // Find the closest intersecting circle on the front-chain, if any.
  8580. // “Closeness” is determined by linear distance along the front-chain.
  8581. // “Ahead” or “behind” is likewise determined by linear distance.
  8582. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  8583. do {
  8584. if (sj <= sk) {
  8585. if (intersects(j._, c._)) {
  8586. b = j, a.next = b, b.previous = a, --i;
  8587. continue pack;
  8588. }
  8589. sj += j._.r, j = j.next;
  8590. } else {
  8591. if (intersects(k._, c._)) {
  8592. a = k, a.next = b, b.previous = a, --i;
  8593. continue pack;
  8594. }
  8595. sk += k._.r, k = k.previous;
  8596. }
  8597. } while (j !== k.next);
  8598. // Success! Insert the new circle c between a and b.
  8599. c.previous = a, c.next = b, a.next = b.previous = b = c;
  8600. // Compute the new closest circle pair to the centroid.
  8601. aa = score(a);
  8602. while ((c = c.next) !== b) {
  8603. if ((ca = score(c)) < aa) {
  8604. a = c, aa = ca;
  8605. }
  8606. }
  8607. b = a.next;
  8608. }
  8609. // Compute the enclosing circle of the front chain.
  8610. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  8611. // Translate the circles to put the enclosing circle around the origin.
  8612. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  8613. return c.r;
  8614. }
  8615. var siblings = function(circles) {
  8616. packEnclose(circles);
  8617. return circles;
  8618. };
  8619. function optional(f) {
  8620. return f == null ? null : required(f);
  8621. }
  8622. function required(f) {
  8623. if (typeof f !== "function") throw new Error;
  8624. return f;
  8625. }
  8626. function constantZero() {
  8627. return 0;
  8628. }
  8629. var constant$8 = function(x) {
  8630. return function() {
  8631. return x;
  8632. };
  8633. };
  8634. function defaultRadius$1(d) {
  8635. return Math.sqrt(d.value);
  8636. }
  8637. var index$2 = function() {
  8638. var radius = null,
  8639. dx = 1,
  8640. dy = 1,
  8641. padding = constantZero;
  8642. function pack(root) {
  8643. root.x = dx / 2, root.y = dy / 2;
  8644. if (radius) {
  8645. root.eachBefore(radiusLeaf(radius))
  8646. .eachAfter(packChildren(padding, 0.5))
  8647. .eachBefore(translateChild(1));
  8648. } else {
  8649. root.eachBefore(radiusLeaf(defaultRadius$1))
  8650. .eachAfter(packChildren(constantZero, 1))
  8651. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  8652. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  8653. }
  8654. return root;
  8655. }
  8656. pack.radius = function(x) {
  8657. return arguments.length ? (radius = optional(x), pack) : radius;
  8658. };
  8659. pack.size = function(x) {
  8660. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  8661. };
  8662. pack.padding = function(x) {
  8663. return arguments.length ? (padding = typeof x === "function" ? x : constant$8(+x), pack) : padding;
  8664. };
  8665. return pack;
  8666. };
  8667. function radiusLeaf(radius) {
  8668. return function(node) {
  8669. if (!node.children) {
  8670. node.r = Math.max(0, +radius(node) || 0);
  8671. }
  8672. };
  8673. }
  8674. function packChildren(padding, k) {
  8675. return function(node) {
  8676. if (children = node.children) {
  8677. var children,
  8678. i,
  8679. n = children.length,
  8680. r = padding(node) * k || 0,
  8681. e;
  8682. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  8683. e = packEnclose(children);
  8684. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  8685. node.r = e + r;
  8686. }
  8687. };
  8688. }
  8689. function translateChild(k) {
  8690. return function(node) {
  8691. var parent = node.parent;
  8692. node.r *= k;
  8693. if (parent) {
  8694. node.x = parent.x + k * node.x;
  8695. node.y = parent.y + k * node.y;
  8696. }
  8697. };
  8698. }
  8699. var roundNode = function(node) {
  8700. node.x0 = Math.round(node.x0);
  8701. node.y0 = Math.round(node.y0);
  8702. node.x1 = Math.round(node.x1);
  8703. node.y1 = Math.round(node.y1);
  8704. };
  8705. var treemapDice = function(parent, x0, y0, x1, y1) {
  8706. var nodes = parent.children,
  8707. node,
  8708. i = -1,
  8709. n = nodes.length,
  8710. k = parent.value && (x1 - x0) / parent.value;
  8711. while (++i < n) {
  8712. node = nodes[i], node.y0 = y0, node.y1 = y1;
  8713. node.x0 = x0, node.x1 = x0 += node.value * k;
  8714. }
  8715. };
  8716. var partition = function() {
  8717. var dx = 1,
  8718. dy = 1,
  8719. padding = 0,
  8720. round = false;
  8721. function partition(root) {
  8722. var n = root.height + 1;
  8723. root.x0 =
  8724. root.y0 = padding;
  8725. root.x1 = dx;
  8726. root.y1 = dy / n;
  8727. root.eachBefore(positionNode(dy, n));
  8728. if (round) root.eachBefore(roundNode);
  8729. return root;
  8730. }
  8731. function positionNode(dy, n) {
  8732. return function(node) {
  8733. if (node.children) {
  8734. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  8735. }
  8736. var x0 = node.x0,
  8737. y0 = node.y0,
  8738. x1 = node.x1 - padding,
  8739. y1 = node.y1 - padding;
  8740. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8741. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8742. node.x0 = x0;
  8743. node.y0 = y0;
  8744. node.x1 = x1;
  8745. node.y1 = y1;
  8746. };
  8747. }
  8748. partition.round = function(x) {
  8749. return arguments.length ? (round = !!x, partition) : round;
  8750. };
  8751. partition.size = function(x) {
  8752. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  8753. };
  8754. partition.padding = function(x) {
  8755. return arguments.length ? (padding = +x, partition) : padding;
  8756. };
  8757. return partition;
  8758. };
  8759. var keyPrefix$1 = "$";
  8760. var preroot = {depth: -1};
  8761. var ambiguous = {};
  8762. function defaultId(d) {
  8763. return d.id;
  8764. }
  8765. function defaultParentId(d) {
  8766. return d.parentId;
  8767. }
  8768. var stratify = function() {
  8769. var id = defaultId,
  8770. parentId = defaultParentId;
  8771. function stratify(data) {
  8772. var d,
  8773. i,
  8774. n = data.length,
  8775. root,
  8776. parent,
  8777. node,
  8778. nodes = new Array(n),
  8779. nodeId,
  8780. nodeKey,
  8781. nodeByKey = {};
  8782. for (i = 0; i < n; ++i) {
  8783. d = data[i], node = nodes[i] = new Node(d);
  8784. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  8785. nodeKey = keyPrefix$1 + (node.id = nodeId);
  8786. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  8787. }
  8788. }
  8789. for (i = 0; i < n; ++i) {
  8790. node = nodes[i], nodeId = parentId(data[i], i, data);
  8791. if (nodeId == null || !(nodeId += "")) {
  8792. if (root) throw new Error("multiple roots");
  8793. root = node;
  8794. } else {
  8795. parent = nodeByKey[keyPrefix$1 + nodeId];
  8796. if (!parent) throw new Error("missing: " + nodeId);
  8797. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  8798. if (parent.children) parent.children.push(node);
  8799. else parent.children = [node];
  8800. node.parent = parent;
  8801. }
  8802. }
  8803. if (!root) throw new Error("no root");
  8804. root.parent = preroot;
  8805. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  8806. root.parent = null;
  8807. if (n > 0) throw new Error("cycle");
  8808. return root;
  8809. }
  8810. stratify.id = function(x) {
  8811. return arguments.length ? (id = required(x), stratify) : id;
  8812. };
  8813. stratify.parentId = function(x) {
  8814. return arguments.length ? (parentId = required(x), stratify) : parentId;
  8815. };
  8816. return stratify;
  8817. };
  8818. function defaultSeparation$1(a, b) {
  8819. return a.parent === b.parent ? 1 : 2;
  8820. }
  8821. // function radialSeparation(a, b) {
  8822. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  8823. // }
  8824. // This function is used to traverse the left contour of a subtree (or
  8825. // subforest). It returns the successor of v on this contour. This successor is
  8826. // either given by the leftmost child of v or by the thread of v. The function
  8827. // returns null if and only if v is on the highest level of its subtree.
  8828. function nextLeft(v) {
  8829. var children = v.children;
  8830. return children ? children[0] : v.t;
  8831. }
  8832. // This function works analogously to nextLeft.
  8833. function nextRight(v) {
  8834. var children = v.children;
  8835. return children ? children[children.length - 1] : v.t;
  8836. }
  8837. // Shifts the current subtree rooted at w+. This is done by increasing
  8838. // prelim(w+) and mod(w+) by shift.
  8839. function moveSubtree(wm, wp, shift) {
  8840. var change = shift / (wp.i - wm.i);
  8841. wp.c -= change;
  8842. wp.s += shift;
  8843. wm.c += change;
  8844. wp.z += shift;
  8845. wp.m += shift;
  8846. }
  8847. // All other shifts, applied to the smaller subtrees between w- and w+, are
  8848. // performed by this function. To prepare the shifts, we have to adjust
  8849. // change(w+), shift(w+), and change(w-).
  8850. function executeShifts(v) {
  8851. var shift = 0,
  8852. change = 0,
  8853. children = v.children,
  8854. i = children.length,
  8855. w;
  8856. while (--i >= 0) {
  8857. w = children[i];
  8858. w.z += shift;
  8859. w.m += shift;
  8860. shift += w.s + (change += w.c);
  8861. }
  8862. }
  8863. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  8864. // returns the specified (default) ancestor.
  8865. function nextAncestor(vim, v, ancestor) {
  8866. return vim.a.parent === v.parent ? vim.a : ancestor;
  8867. }
  8868. function TreeNode(node, i) {
  8869. this._ = node;
  8870. this.parent = null;
  8871. this.children = null;
  8872. this.A = null; // default ancestor
  8873. this.a = this; // ancestor
  8874. this.z = 0; // prelim
  8875. this.m = 0; // mod
  8876. this.c = 0; // change
  8877. this.s = 0; // shift
  8878. this.t = null; // thread
  8879. this.i = i; // number
  8880. }
  8881. TreeNode.prototype = Object.create(Node.prototype);
  8882. function treeRoot(root) {
  8883. var tree = new TreeNode(root, 0),
  8884. node,
  8885. nodes = [tree],
  8886. child,
  8887. children,
  8888. i,
  8889. n;
  8890. while (node = nodes.pop()) {
  8891. if (children = node._.children) {
  8892. node.children = new Array(n = children.length);
  8893. for (i = n - 1; i >= 0; --i) {
  8894. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  8895. child.parent = node;
  8896. }
  8897. }
  8898. }
  8899. (tree.parent = new TreeNode(null, 0)).children = [tree];
  8900. return tree;
  8901. }
  8902. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  8903. var tree = function() {
  8904. var separation = defaultSeparation$1,
  8905. dx = 1,
  8906. dy = 1,
  8907. nodeSize = null;
  8908. function tree(root) {
  8909. var t = treeRoot(root);
  8910. // Compute the layout using Buchheim et al.’s algorithm.
  8911. t.eachAfter(firstWalk), t.parent.m = -t.z;
  8912. t.eachBefore(secondWalk);
  8913. // If a fixed node size is specified, scale x and y.
  8914. if (nodeSize) root.eachBefore(sizeNode);
  8915. // If a fixed tree size is specified, scale x and y based on the extent.
  8916. // Compute the left-most, right-most, and depth-most nodes for extents.
  8917. else {
  8918. var left = root,
  8919. right = root,
  8920. bottom = root;
  8921. root.eachBefore(function(node) {
  8922. if (node.x < left.x) left = node;
  8923. if (node.x > right.x) right = node;
  8924. if (node.depth > bottom.depth) bottom = node;
  8925. });
  8926. var s = left === right ? 1 : separation(left, right) / 2,
  8927. tx = s - left.x,
  8928. kx = dx / (right.x + s + tx),
  8929. ky = dy / (bottom.depth || 1);
  8930. root.eachBefore(function(node) {
  8931. node.x = (node.x + tx) * kx;
  8932. node.y = node.depth * ky;
  8933. });
  8934. }
  8935. return root;
  8936. }
  8937. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  8938. // applied recursively to the children of v, as well as the function
  8939. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  8940. // node v is placed to the midpoint of its outermost children.
  8941. function firstWalk(v) {
  8942. var children = v.children,
  8943. siblings = v.parent.children,
  8944. w = v.i ? siblings[v.i - 1] : null;
  8945. if (children) {
  8946. executeShifts(v);
  8947. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  8948. if (w) {
  8949. v.z = w.z + separation(v._, w._);
  8950. v.m = v.z - midpoint;
  8951. } else {
  8952. v.z = midpoint;
  8953. }
  8954. } else if (w) {
  8955. v.z = w.z + separation(v._, w._);
  8956. }
  8957. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  8958. }
  8959. // Computes all real x-coordinates by summing up the modifiers recursively.
  8960. function secondWalk(v) {
  8961. v._.x = v.z + v.parent.m;
  8962. v.m += v.parent.m;
  8963. }
  8964. // The core of the algorithm. Here, a new subtree is combined with the
  8965. // previous subtrees. Threads are used to traverse the inside and outside
  8966. // contours of the left and right subtree up to the highest common level. The
  8967. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  8968. // superscript o means outside and i means inside, the subscript - means left
  8969. // subtree and + means right subtree. For summing up the modifiers along the
  8970. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  8971. // nodes of the inside contours conflict, we compute the left one of the
  8972. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  8973. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  8974. // Finally, we add a new thread (if necessary).
  8975. function apportion(v, w, ancestor) {
  8976. if (w) {
  8977. var vip = v,
  8978. vop = v,
  8979. vim = w,
  8980. vom = vip.parent.children[0],
  8981. sip = vip.m,
  8982. sop = vop.m,
  8983. sim = vim.m,
  8984. som = vom.m,
  8985. shift;
  8986. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  8987. vom = nextLeft(vom);
  8988. vop = nextRight(vop);
  8989. vop.a = v;
  8990. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  8991. if (shift > 0) {
  8992. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  8993. sip += shift;
  8994. sop += shift;
  8995. }
  8996. sim += vim.m;
  8997. sip += vip.m;
  8998. som += vom.m;
  8999. sop += vop.m;
  9000. }
  9001. if (vim && !nextRight(vop)) {
  9002. vop.t = vim;
  9003. vop.m += sim - sop;
  9004. }
  9005. if (vip && !nextLeft(vom)) {
  9006. vom.t = vip;
  9007. vom.m += sip - som;
  9008. ancestor = v;
  9009. }
  9010. }
  9011. return ancestor;
  9012. }
  9013. function sizeNode(node) {
  9014. node.x *= dx;
  9015. node.y = node.depth * dy;
  9016. }
  9017. tree.separation = function(x) {
  9018. return arguments.length ? (separation = x, tree) : separation;
  9019. };
  9020. tree.size = function(x) {
  9021. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9022. };
  9023. tree.nodeSize = function(x) {
  9024. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9025. };
  9026. return tree;
  9027. };
  9028. var treemapSlice = function(parent, x0, y0, x1, y1) {
  9029. var nodes = parent.children,
  9030. node,
  9031. i = -1,
  9032. n = nodes.length,
  9033. k = parent.value && (y1 - y0) / parent.value;
  9034. while (++i < n) {
  9035. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9036. node.y0 = y0, node.y1 = y0 += node.value * k;
  9037. }
  9038. };
  9039. var phi = (1 + Math.sqrt(5)) / 2;
  9040. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9041. var rows = [],
  9042. nodes = parent.children,
  9043. row,
  9044. nodeValue,
  9045. i0 = 0,
  9046. i1 = 0,
  9047. n = nodes.length,
  9048. dx, dy,
  9049. value = parent.value,
  9050. sumValue,
  9051. minValue,
  9052. maxValue,
  9053. newRatio,
  9054. minRatio,
  9055. alpha,
  9056. beta;
  9057. while (i0 < n) {
  9058. dx = x1 - x0, dy = y1 - y0;
  9059. // Find the next non-empty node.
  9060. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9061. minValue = maxValue = sumValue;
  9062. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9063. beta = sumValue * sumValue * alpha;
  9064. minRatio = Math.max(maxValue / beta, beta / minValue);
  9065. // Keep adding nodes while the aspect ratio maintains or improves.
  9066. for (; i1 < n; ++i1) {
  9067. sumValue += nodeValue = nodes[i1].value;
  9068. if (nodeValue < minValue) minValue = nodeValue;
  9069. if (nodeValue > maxValue) maxValue = nodeValue;
  9070. beta = sumValue * sumValue * alpha;
  9071. newRatio = Math.max(maxValue / beta, beta / minValue);
  9072. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9073. minRatio = newRatio;
  9074. }
  9075. // Position and record the row orientation.
  9076. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9077. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9078. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9079. value -= sumValue, i0 = i1;
  9080. }
  9081. return rows;
  9082. }
  9083. var squarify = (function custom(ratio) {
  9084. function squarify(parent, x0, y0, x1, y1) {
  9085. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9086. }
  9087. squarify.ratio = function(x) {
  9088. return custom((x = +x) > 1 ? x : 1);
  9089. };
  9090. return squarify;
  9091. })(phi);
  9092. var index$3 = function() {
  9093. var tile = squarify,
  9094. round = false,
  9095. dx = 1,
  9096. dy = 1,
  9097. paddingStack = [0],
  9098. paddingInner = constantZero,
  9099. paddingTop = constantZero,
  9100. paddingRight = constantZero,
  9101. paddingBottom = constantZero,
  9102. paddingLeft = constantZero;
  9103. function treemap(root) {
  9104. root.x0 =
  9105. root.y0 = 0;
  9106. root.x1 = dx;
  9107. root.y1 = dy;
  9108. root.eachBefore(positionNode);
  9109. paddingStack = [0];
  9110. if (round) root.eachBefore(roundNode);
  9111. return root;
  9112. }
  9113. function positionNode(node) {
  9114. var p = paddingStack[node.depth],
  9115. x0 = node.x0 + p,
  9116. y0 = node.y0 + p,
  9117. x1 = node.x1 - p,
  9118. y1 = node.y1 - p;
  9119. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9120. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9121. node.x0 = x0;
  9122. node.y0 = y0;
  9123. node.x1 = x1;
  9124. node.y1 = y1;
  9125. if (node.children) {
  9126. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9127. x0 += paddingLeft(node) - p;
  9128. y0 += paddingTop(node) - p;
  9129. x1 -= paddingRight(node) - p;
  9130. y1 -= paddingBottom(node) - p;
  9131. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9132. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9133. tile(node, x0, y0, x1, y1);
  9134. }
  9135. }
  9136. treemap.round = function(x) {
  9137. return arguments.length ? (round = !!x, treemap) : round;
  9138. };
  9139. treemap.size = function(x) {
  9140. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9141. };
  9142. treemap.tile = function(x) {
  9143. return arguments.length ? (tile = required(x), treemap) : tile;
  9144. };
  9145. treemap.padding = function(x) {
  9146. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9147. };
  9148. treemap.paddingInner = function(x) {
  9149. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$8(+x), treemap) : paddingInner;
  9150. };
  9151. treemap.paddingOuter = function(x) {
  9152. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9153. };
  9154. treemap.paddingTop = function(x) {
  9155. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$8(+x), treemap) : paddingTop;
  9156. };
  9157. treemap.paddingRight = function(x) {
  9158. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$8(+x), treemap) : paddingRight;
  9159. };
  9160. treemap.paddingBottom = function(x) {
  9161. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$8(+x), treemap) : paddingBottom;
  9162. };
  9163. treemap.paddingLeft = function(x) {
  9164. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$8(+x), treemap) : paddingLeft;
  9165. };
  9166. return treemap;
  9167. };
  9168. var binary = function(parent, x0, y0, x1, y1) {
  9169. var nodes = parent.children,
  9170. i, n = nodes.length,
  9171. sum, sums = new Array(n + 1);
  9172. for (sums[0] = sum = i = 0; i < n; ++i) {
  9173. sums[i + 1] = sum += nodes[i].value;
  9174. }
  9175. partition(0, n, parent.value, x0, y0, x1, y1);
  9176. function partition(i, j, value, x0, y0, x1, y1) {
  9177. if (i >= j - 1) {
  9178. var node = nodes[i];
  9179. node.x0 = x0, node.y0 = y0;
  9180. node.x1 = x1, node.y1 = y1;
  9181. return;
  9182. }
  9183. var valueOffset = sums[i],
  9184. valueTarget = (value / 2) + valueOffset,
  9185. k = i + 1,
  9186. hi = j - 1;
  9187. while (k < hi) {
  9188. var mid = k + hi >>> 1;
  9189. if (sums[mid] < valueTarget) k = mid + 1;
  9190. else hi = mid;
  9191. }
  9192. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  9193. var valueLeft = sums[k] - valueOffset,
  9194. valueRight = value - valueLeft;
  9195. if ((x1 - x0) > (y1 - y0)) {
  9196. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  9197. partition(i, k, valueLeft, x0, y0, xk, y1);
  9198. partition(k, j, valueRight, xk, y0, x1, y1);
  9199. } else {
  9200. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  9201. partition(i, k, valueLeft, x0, y0, x1, yk);
  9202. partition(k, j, valueRight, x0, yk, x1, y1);
  9203. }
  9204. }
  9205. };
  9206. var sliceDice = function(parent, x0, y0, x1, y1) {
  9207. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  9208. };
  9209. var resquarify = (function custom(ratio) {
  9210. function resquarify(parent, x0, y0, x1, y1) {
  9211. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  9212. var rows,
  9213. row,
  9214. nodes,
  9215. i,
  9216. j = -1,
  9217. n,
  9218. m = rows.length,
  9219. value = parent.value;
  9220. while (++j < m) {
  9221. row = rows[j], nodes = row.children;
  9222. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  9223. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  9224. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  9225. value -= row.value;
  9226. }
  9227. } else {
  9228. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9229. rows.ratio = ratio;
  9230. }
  9231. }
  9232. resquarify.ratio = function(x) {
  9233. return custom((x = +x) > 1 ? x : 1);
  9234. };
  9235. return resquarify;
  9236. })(phi);
  9237. var area$1 = function(polygon) {
  9238. var i = -1,
  9239. n = polygon.length,
  9240. a,
  9241. b = polygon[n - 1],
  9242. area = 0;
  9243. while (++i < n) {
  9244. a = b;
  9245. b = polygon[i];
  9246. area += a[1] * b[0] - a[0] * b[1];
  9247. }
  9248. return area / 2;
  9249. };
  9250. var centroid$1 = function(polygon) {
  9251. var i = -1,
  9252. n = polygon.length,
  9253. x = 0,
  9254. y = 0,
  9255. a,
  9256. b = polygon[n - 1],
  9257. c,
  9258. k = 0;
  9259. while (++i < n) {
  9260. a = b;
  9261. b = polygon[i];
  9262. k += c = a[0] * b[1] - b[0] * a[1];
  9263. x += (a[0] + b[0]) * c;
  9264. y += (a[1] + b[1]) * c;
  9265. }
  9266. return k *= 3, [x / k, y / k];
  9267. };
  9268. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  9269. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  9270. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  9271. // negative if clockwise, and zero if the points are collinear.
  9272. var cross$1 = function(a, b, c) {
  9273. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  9274. };
  9275. function lexicographicOrder(a, b) {
  9276. return a[0] - b[0] || a[1] - b[1];
  9277. }
  9278. // Computes the upper convex hull per the monotone chain algorithm.
  9279. // Assumes points.length >= 3, is sorted by x, unique in y.
  9280. // Returns an array of indices into points in left-to-right order.
  9281. function computeUpperHullIndexes(points) {
  9282. var n = points.length,
  9283. indexes = [0, 1],
  9284. size = 2;
  9285. for (var i = 2; i < n; ++i) {
  9286. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  9287. indexes[size++] = i;
  9288. }
  9289. return indexes.slice(0, size); // remove popped points
  9290. }
  9291. var hull = function(points) {
  9292. if ((n = points.length) < 3) return null;
  9293. var i,
  9294. n,
  9295. sortedPoints = new Array(n),
  9296. flippedPoints = new Array(n);
  9297. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  9298. sortedPoints.sort(lexicographicOrder);
  9299. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  9300. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  9301. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  9302. // Construct the hull polygon, removing possible duplicate endpoints.
  9303. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  9304. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  9305. hull = [];
  9306. // Add upper hull in right-to-l order.
  9307. // Then add lower hull in left-to-right order.
  9308. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  9309. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  9310. return hull;
  9311. };
  9312. var contains$1 = function(polygon, point) {
  9313. var n = polygon.length,
  9314. p = polygon[n - 1],
  9315. x = point[0], y = point[1],
  9316. x0 = p[0], y0 = p[1],
  9317. x1, y1,
  9318. inside = false;
  9319. for (var i = 0; i < n; ++i) {
  9320. p = polygon[i], x1 = p[0], y1 = p[1];
  9321. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  9322. x0 = x1, y0 = y1;
  9323. }
  9324. return inside;
  9325. };
  9326. var length$2 = function(polygon) {
  9327. var i = -1,
  9328. n = polygon.length,
  9329. b = polygon[n - 1],
  9330. xa,
  9331. ya,
  9332. xb = b[0],
  9333. yb = b[1],
  9334. perimeter = 0;
  9335. while (++i < n) {
  9336. xa = xb;
  9337. ya = yb;
  9338. b = polygon[i];
  9339. xb = b[0];
  9340. yb = b[1];
  9341. xa -= xb;
  9342. ya -= yb;
  9343. perimeter += Math.sqrt(xa * xa + ya * ya);
  9344. }
  9345. return perimeter;
  9346. };
  9347. var slice$4 = [].slice;
  9348. var noabort = {};
  9349. function Queue(size) {
  9350. this._size = size;
  9351. this._call =
  9352. this._error = null;
  9353. this._tasks = [];
  9354. this._data = [];
  9355. this._waiting =
  9356. this._active =
  9357. this._ended =
  9358. this._start = 0; // inside a synchronous task callback?
  9359. }
  9360. Queue.prototype = queue.prototype = {
  9361. constructor: Queue,
  9362. defer: function(callback) {
  9363. if (typeof callback !== "function") throw new Error("invalid callback");
  9364. if (this._call) throw new Error("defer after await");
  9365. if (this._error != null) return this;
  9366. var t = slice$4.call(arguments, 1);
  9367. t.push(callback);
  9368. ++this._waiting, this._tasks.push(t);
  9369. poke$1(this);
  9370. return this;
  9371. },
  9372. abort: function() {
  9373. if (this._error == null) abort(this, new Error("abort"));
  9374. return this;
  9375. },
  9376. await: function(callback) {
  9377. if (typeof callback !== "function") throw new Error("invalid callback");
  9378. if (this._call) throw new Error("multiple await");
  9379. this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
  9380. maybeNotify(this);
  9381. return this;
  9382. },
  9383. awaitAll: function(callback) {
  9384. if (typeof callback !== "function") throw new Error("invalid callback");
  9385. if (this._call) throw new Error("multiple await");
  9386. this._call = callback;
  9387. maybeNotify(this);
  9388. return this;
  9389. }
  9390. };
  9391. function poke$1(q) {
  9392. if (!q._start) {
  9393. try { start$1(q); } // let the current task complete
  9394. catch (e) {
  9395. if (q._tasks[q._ended + q._active - 1]) abort(q, e); // task errored synchronously
  9396. else if (!q._data) throw e; // await callback errored synchronously
  9397. }
  9398. }
  9399. }
  9400. function start$1(q) {
  9401. while (q._start = q._waiting && q._active < q._size) {
  9402. var i = q._ended + q._active,
  9403. t = q._tasks[i],
  9404. j = t.length - 1,
  9405. c = t[j];
  9406. t[j] = end(q, i);
  9407. --q._waiting, ++q._active;
  9408. t = c.apply(null, t);
  9409. if (!q._tasks[i]) continue; // task finished synchronously
  9410. q._tasks[i] = t || noabort;
  9411. }
  9412. }
  9413. function end(q, i) {
  9414. return function(e, r) {
  9415. if (!q._tasks[i]) return; // ignore multiple callbacks
  9416. --q._active, ++q._ended;
  9417. q._tasks[i] = null;
  9418. if (q._error != null) return; // ignore secondary errors
  9419. if (e != null) {
  9420. abort(q, e);
  9421. } else {
  9422. q._data[i] = r;
  9423. if (q._waiting) poke$1(q);
  9424. else maybeNotify(q);
  9425. }
  9426. };
  9427. }
  9428. function abort(q, e) {
  9429. var i = q._tasks.length, t;
  9430. q._error = e; // ignore active callbacks
  9431. q._data = undefined; // allow gc
  9432. q._waiting = NaN; // prevent starting
  9433. while (--i >= 0) {
  9434. if (t = q._tasks[i]) {
  9435. q._tasks[i] = null;
  9436. if (t.abort) {
  9437. try { t.abort(); }
  9438. catch (e) { /* ignore */ }
  9439. }
  9440. }
  9441. }
  9442. q._active = NaN; // allow notification
  9443. maybeNotify(q);
  9444. }
  9445. function maybeNotify(q) {
  9446. if (!q._active && q._call) {
  9447. var d = q._data;
  9448. q._data = undefined; // allow gc
  9449. q._call(q._error, d);
  9450. }
  9451. }
  9452. function queue(concurrency) {
  9453. if (concurrency == null) concurrency = Infinity;
  9454. else if (!((concurrency = +concurrency) >= 1)) throw new Error("invalid concurrency");
  9455. return new Queue(concurrency);
  9456. }
  9457. var defaultSource$1 = function() {
  9458. return Math.random();
  9459. };
  9460. var uniform = (function sourceRandomUniform(source) {
  9461. function randomUniform(min, max) {
  9462. min = min == null ? 0 : +min;
  9463. max = max == null ? 1 : +max;
  9464. if (arguments.length === 1) max = min, min = 0;
  9465. else max -= min;
  9466. return function() {
  9467. return source() * max + min;
  9468. };
  9469. }
  9470. randomUniform.source = sourceRandomUniform;
  9471. return randomUniform;
  9472. })(defaultSource$1);
  9473. var normal = (function sourceRandomNormal(source) {
  9474. function randomNormal(mu, sigma) {
  9475. var x, r;
  9476. mu = mu == null ? 0 : +mu;
  9477. sigma = sigma == null ? 1 : +sigma;
  9478. return function() {
  9479. var y;
  9480. // If available, use the second previously-generated uniform random.
  9481. if (x != null) y = x, x = null;
  9482. // Otherwise, generate a new x and y.
  9483. else do {
  9484. x = source() * 2 - 1;
  9485. y = source() * 2 - 1;
  9486. r = x * x + y * y;
  9487. } while (!r || r > 1);
  9488. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  9489. };
  9490. }
  9491. randomNormal.source = sourceRandomNormal;
  9492. return randomNormal;
  9493. })(defaultSource$1);
  9494. var logNormal = (function sourceRandomLogNormal(source) {
  9495. function randomLogNormal() {
  9496. var randomNormal = normal.source(source).apply(this, arguments);
  9497. return function() {
  9498. return Math.exp(randomNormal());
  9499. };
  9500. }
  9501. randomLogNormal.source = sourceRandomLogNormal;
  9502. return randomLogNormal;
  9503. })(defaultSource$1);
  9504. var irwinHall = (function sourceRandomIrwinHall(source) {
  9505. function randomIrwinHall(n) {
  9506. return function() {
  9507. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  9508. return sum;
  9509. };
  9510. }
  9511. randomIrwinHall.source = sourceRandomIrwinHall;
  9512. return randomIrwinHall;
  9513. })(defaultSource$1);
  9514. var bates = (function sourceRandomBates(source) {
  9515. function randomBates(n) {
  9516. var randomIrwinHall = irwinHall.source(source)(n);
  9517. return function() {
  9518. return randomIrwinHall() / n;
  9519. };
  9520. }
  9521. randomBates.source = sourceRandomBates;
  9522. return randomBates;
  9523. })(defaultSource$1);
  9524. var exponential$1 = (function sourceRandomExponential(source) {
  9525. function randomExponential(lambda) {
  9526. return function() {
  9527. return -Math.log(1 - source()) / lambda;
  9528. };
  9529. }
  9530. randomExponential.source = sourceRandomExponential;
  9531. return randomExponential;
  9532. })(defaultSource$1);
  9533. var request = function(url, callback) {
  9534. var request,
  9535. event = dispatch("beforesend", "progress", "load", "error"),
  9536. mimeType,
  9537. headers = map$1(),
  9538. xhr = new XMLHttpRequest,
  9539. user = null,
  9540. password = null,
  9541. response,
  9542. responseType,
  9543. timeout = 0;
  9544. // If IE does not support CORS, use XDomainRequest.
  9545. if (typeof XDomainRequest !== "undefined"
  9546. && !("withCredentials" in xhr)
  9547. && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
  9548. "onload" in xhr
  9549. ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
  9550. : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
  9551. function respond(o) {
  9552. var status = xhr.status, result;
  9553. if (!status && hasResponse(xhr)
  9554. || status >= 200 && status < 300
  9555. || status === 304) {
  9556. if (response) {
  9557. try {
  9558. result = response.call(request, xhr);
  9559. } catch (e) {
  9560. event.call("error", request, e);
  9561. return;
  9562. }
  9563. } else {
  9564. result = xhr;
  9565. }
  9566. event.call("load", request, result);
  9567. } else {
  9568. event.call("error", request, o);
  9569. }
  9570. }
  9571. xhr.onprogress = function(e) {
  9572. event.call("progress", request, e);
  9573. };
  9574. request = {
  9575. header: function(name, value) {
  9576. name = (name + "").toLowerCase();
  9577. if (arguments.length < 2) return headers.get(name);
  9578. if (value == null) headers.remove(name);
  9579. else headers.set(name, value + "");
  9580. return request;
  9581. },
  9582. // If mimeType is non-null and no Accept header is set, a default is used.
  9583. mimeType: function(value) {
  9584. if (!arguments.length) return mimeType;
  9585. mimeType = value == null ? null : value + "";
  9586. return request;
  9587. },
  9588. // Specifies what type the response value should take;
  9589. // for instance, arraybuffer, blob, document, or text.
  9590. responseType: function(value) {
  9591. if (!arguments.length) return responseType;
  9592. responseType = value;
  9593. return request;
  9594. },
  9595. timeout: function(value) {
  9596. if (!arguments.length) return timeout;
  9597. timeout = +value;
  9598. return request;
  9599. },
  9600. user: function(value) {
  9601. return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
  9602. },
  9603. password: function(value) {
  9604. return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
  9605. },
  9606. // Specify how to convert the response content to a specific type;
  9607. // changes the callback value on "load" events.
  9608. response: function(value) {
  9609. response = value;
  9610. return request;
  9611. },
  9612. // Alias for send("GET", …).
  9613. get: function(data, callback) {
  9614. return request.send("GET", data, callback);
  9615. },
  9616. // Alias for send("POST", …).
  9617. post: function(data, callback) {
  9618. return request.send("POST", data, callback);
  9619. },
  9620. // If callback is non-null, it will be used for error and load events.
  9621. send: function(method, data, callback) {
  9622. xhr.open(method, url, true, user, password);
  9623. if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
  9624. if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
  9625. if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
  9626. if (responseType != null) xhr.responseType = responseType;
  9627. if (timeout > 0) xhr.timeout = timeout;
  9628. if (callback == null && typeof data === "function") callback = data, data = null;
  9629. if (callback != null && callback.length === 1) callback = fixCallback(callback);
  9630. if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
  9631. event.call("beforesend", request, xhr);
  9632. xhr.send(data == null ? null : data);
  9633. return request;
  9634. },
  9635. abort: function() {
  9636. xhr.abort();
  9637. return request;
  9638. },
  9639. on: function() {
  9640. var value = event.on.apply(event, arguments);
  9641. return value === event ? request : value;
  9642. }
  9643. };
  9644. if (callback != null) {
  9645. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  9646. return request.get(callback);
  9647. }
  9648. return request;
  9649. };
  9650. function fixCallback(callback) {
  9651. return function(error, xhr) {
  9652. callback(error == null ? xhr : null);
  9653. };
  9654. }
  9655. function hasResponse(xhr) {
  9656. var type = xhr.responseType;
  9657. return type && type !== "text"
  9658. ? xhr.response // null on error
  9659. : xhr.responseText; // "" on error
  9660. }
  9661. var type$1 = function(defaultMimeType, response) {
  9662. return function(url, callback) {
  9663. var r = request(url).mimeType(defaultMimeType).response(response);
  9664. if (callback != null) {
  9665. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  9666. return r.get(callback);
  9667. }
  9668. return r;
  9669. };
  9670. };
  9671. var html = type$1("text/html", function(xhr) {
  9672. return document.createRange().createContextualFragment(xhr.responseText);
  9673. });
  9674. var json = type$1("application/json", function(xhr) {
  9675. return JSON.parse(xhr.responseText);
  9676. });
  9677. var text = type$1("text/plain", function(xhr) {
  9678. return xhr.responseText;
  9679. });
  9680. var xml = type$1("application/xml", function(xhr) {
  9681. var xml = xhr.responseXML;
  9682. if (!xml) throw new Error("parse error");
  9683. return xml;
  9684. });
  9685. var dsv$1 = function(defaultMimeType, parse) {
  9686. return function(url, row, callback) {
  9687. if (arguments.length < 3) callback = row, row = null;
  9688. var r = request(url).mimeType(defaultMimeType);
  9689. r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
  9690. r.row(row);
  9691. return callback ? r.get(callback) : r;
  9692. };
  9693. };
  9694. function responseOf(parse, row) {
  9695. return function(request$$1) {
  9696. return parse(request$$1.responseText, row);
  9697. };
  9698. }
  9699. var csv$1 = dsv$1("text/csv", csvParse);
  9700. var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
  9701. var array$2 = Array.prototype;
  9702. var map$3 = array$2.map;
  9703. var slice$5 = array$2.slice;
  9704. var implicit = {name: "implicit"};
  9705. function ordinal(range) {
  9706. var index = map$1(),
  9707. domain = [],
  9708. unknown = implicit;
  9709. range = range == null ? [] : slice$5.call(range);
  9710. function scale(d) {
  9711. var key = d + "", i = index.get(key);
  9712. if (!i) {
  9713. if (unknown !== implicit) return unknown;
  9714. index.set(key, i = domain.push(d));
  9715. }
  9716. return range[(i - 1) % range.length];
  9717. }
  9718. scale.domain = function(_) {
  9719. if (!arguments.length) return domain.slice();
  9720. domain = [], index = map$1();
  9721. var i = -1, n = _.length, d, key;
  9722. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  9723. return scale;
  9724. };
  9725. scale.range = function(_) {
  9726. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  9727. };
  9728. scale.unknown = function(_) {
  9729. return arguments.length ? (unknown = _, scale) : unknown;
  9730. };
  9731. scale.copy = function() {
  9732. return ordinal()
  9733. .domain(domain)
  9734. .range(range)
  9735. .unknown(unknown);
  9736. };
  9737. return scale;
  9738. }
  9739. function band() {
  9740. var scale = ordinal().unknown(undefined),
  9741. domain = scale.domain,
  9742. ordinalRange = scale.range,
  9743. range$$1 = [0, 1],
  9744. step,
  9745. bandwidth,
  9746. round = false,
  9747. paddingInner = 0,
  9748. paddingOuter = 0,
  9749. align = 0.5;
  9750. delete scale.unknown;
  9751. function rescale() {
  9752. var n = domain().length,
  9753. reverse = range$$1[1] < range$$1[0],
  9754. start = range$$1[reverse - 0],
  9755. stop = range$$1[1 - reverse];
  9756. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  9757. if (round) step = Math.floor(step);
  9758. start += (stop - start - step * (n - paddingInner)) * align;
  9759. bandwidth = step * (1 - paddingInner);
  9760. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  9761. var values = sequence(n).map(function(i) { return start + step * i; });
  9762. return ordinalRange(reverse ? values.reverse() : values);
  9763. }
  9764. scale.domain = function(_) {
  9765. return arguments.length ? (domain(_), rescale()) : domain();
  9766. };
  9767. scale.range = function(_) {
  9768. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  9769. };
  9770. scale.rangeRound = function(_) {
  9771. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  9772. };
  9773. scale.bandwidth = function() {
  9774. return bandwidth;
  9775. };
  9776. scale.step = function() {
  9777. return step;
  9778. };
  9779. scale.round = function(_) {
  9780. return arguments.length ? (round = !!_, rescale()) : round;
  9781. };
  9782. scale.padding = function(_) {
  9783. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  9784. };
  9785. scale.paddingInner = function(_) {
  9786. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  9787. };
  9788. scale.paddingOuter = function(_) {
  9789. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  9790. };
  9791. scale.align = function(_) {
  9792. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  9793. };
  9794. scale.copy = function() {
  9795. return band()
  9796. .domain(domain())
  9797. .range(range$$1)
  9798. .round(round)
  9799. .paddingInner(paddingInner)
  9800. .paddingOuter(paddingOuter)
  9801. .align(align);
  9802. };
  9803. return rescale();
  9804. }
  9805. function pointish(scale) {
  9806. var copy = scale.copy;
  9807. scale.padding = scale.paddingOuter;
  9808. delete scale.paddingInner;
  9809. delete scale.paddingOuter;
  9810. scale.copy = function() {
  9811. return pointish(copy());
  9812. };
  9813. return scale;
  9814. }
  9815. function point$1() {
  9816. return pointish(band().paddingInner(1));
  9817. }
  9818. var constant$9 = function(x) {
  9819. return function() {
  9820. return x;
  9821. };
  9822. };
  9823. var number$2 = function(x) {
  9824. return +x;
  9825. };
  9826. var unit = [0, 1];
  9827. function deinterpolateLinear(a, b) {
  9828. return (b -= (a = +a))
  9829. ? function(x) { return (x - a) / b; }
  9830. : constant$9(b);
  9831. }
  9832. function deinterpolateClamp(deinterpolate) {
  9833. return function(a, b) {
  9834. var d = deinterpolate(a = +a, b = +b);
  9835. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  9836. };
  9837. }
  9838. function reinterpolateClamp(reinterpolate) {
  9839. return function(a, b) {
  9840. var r = reinterpolate(a = +a, b = +b);
  9841. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  9842. };
  9843. }
  9844. function bimap(domain, range, deinterpolate, reinterpolate) {
  9845. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  9846. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
  9847. else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
  9848. return function(x) { return r0(d0(x)); };
  9849. }
  9850. function polymap(domain, range, deinterpolate, reinterpolate) {
  9851. var j = Math.min(domain.length, range.length) - 1,
  9852. d = new Array(j),
  9853. r = new Array(j),
  9854. i = -1;
  9855. // Reverse descending domains.
  9856. if (domain[j] < domain[0]) {
  9857. domain = domain.slice().reverse();
  9858. range = range.slice().reverse();
  9859. }
  9860. while (++i < j) {
  9861. d[i] = deinterpolate(domain[i], domain[i + 1]);
  9862. r[i] = reinterpolate(range[i], range[i + 1]);
  9863. }
  9864. return function(x) {
  9865. var i = bisectRight$1(domain, x, 1, j) - 1;
  9866. return r[i](d[i](x));
  9867. };
  9868. }
  9869. function copy(source, target) {
  9870. return target
  9871. .domain(source.domain())
  9872. .range(source.range())
  9873. .interpolate(source.interpolate())
  9874. .clamp(source.clamp());
  9875. }
  9876. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  9877. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  9878. function continuous(deinterpolate, reinterpolate) {
  9879. var domain = unit,
  9880. range = unit,
  9881. interpolate$$1 = interpolateValue,
  9882. clamp = false,
  9883. piecewise,
  9884. output,
  9885. input;
  9886. function rescale() {
  9887. piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  9888. output = input = null;
  9889. return scale;
  9890. }
  9891. function scale(x) {
  9892. return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  9893. }
  9894. scale.invert = function(y) {
  9895. return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
  9896. };
  9897. scale.domain = function(_) {
  9898. return arguments.length ? (domain = map$3.call(_, number$2), rescale()) : domain.slice();
  9899. };
  9900. scale.range = function(_) {
  9901. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  9902. };
  9903. scale.rangeRound = function(_) {
  9904. return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
  9905. };
  9906. scale.clamp = function(_) {
  9907. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  9908. };
  9909. scale.interpolate = function(_) {
  9910. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  9911. };
  9912. return rescale();
  9913. }
  9914. var tickFormat = function(domain, count, specifier) {
  9915. var start = domain[0],
  9916. stop = domain[domain.length - 1],
  9917. step = tickStep(start, stop, count == null ? 10 : count),
  9918. precision;
  9919. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  9920. switch (specifier.type) {
  9921. case "s": {
  9922. var value = Math.max(Math.abs(start), Math.abs(stop));
  9923. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  9924. return exports.formatPrefix(specifier, value);
  9925. }
  9926. case "":
  9927. case "e":
  9928. case "g":
  9929. case "p":
  9930. case "r": {
  9931. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  9932. break;
  9933. }
  9934. case "f":
  9935. case "%": {
  9936. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  9937. break;
  9938. }
  9939. }
  9940. return exports.format(specifier);
  9941. };
  9942. function linearish(scale) {
  9943. var domain = scale.domain;
  9944. scale.ticks = function(count) {
  9945. var d = domain();
  9946. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  9947. };
  9948. scale.tickFormat = function(count, specifier) {
  9949. return tickFormat(domain(), count, specifier);
  9950. };
  9951. scale.nice = function(count) {
  9952. if (count == null) count = 10;
  9953. var d = domain(),
  9954. i0 = 0,
  9955. i1 = d.length - 1,
  9956. start = d[i0],
  9957. stop = d[i1],
  9958. step;
  9959. if (stop < start) {
  9960. step = start, start = stop, stop = step;
  9961. step = i0, i0 = i1, i1 = step;
  9962. }
  9963. step = tickIncrement(start, stop, count);
  9964. if (step > 0) {
  9965. start = Math.floor(start / step) * step;
  9966. stop = Math.ceil(stop / step) * step;
  9967. step = tickIncrement(start, stop, count);
  9968. } else if (step < 0) {
  9969. start = Math.ceil(start * step) / step;
  9970. stop = Math.floor(stop * step) / step;
  9971. step = tickIncrement(start, stop, count);
  9972. }
  9973. if (step > 0) {
  9974. d[i0] = Math.floor(start / step) * step;
  9975. d[i1] = Math.ceil(stop / step) * step;
  9976. domain(d);
  9977. } else if (step < 0) {
  9978. d[i0] = Math.ceil(start * step) / step;
  9979. d[i1] = Math.floor(stop * step) / step;
  9980. domain(d);
  9981. }
  9982. return scale;
  9983. };
  9984. return scale;
  9985. }
  9986. function linear$2() {
  9987. var scale = continuous(deinterpolateLinear, reinterpolate);
  9988. scale.copy = function() {
  9989. return copy(scale, linear$2());
  9990. };
  9991. return linearish(scale);
  9992. }
  9993. function identity$6() {
  9994. var domain = [0, 1];
  9995. function scale(x) {
  9996. return +x;
  9997. }
  9998. scale.invert = scale;
  9999. scale.domain = scale.range = function(_) {
  10000. return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
  10001. };
  10002. scale.copy = function() {
  10003. return identity$6().domain(domain);
  10004. };
  10005. return linearish(scale);
  10006. }
  10007. var nice = function(domain, interval) {
  10008. domain = domain.slice();
  10009. var i0 = 0,
  10010. i1 = domain.length - 1,
  10011. x0 = domain[i0],
  10012. x1 = domain[i1],
  10013. t;
  10014. if (x1 < x0) {
  10015. t = i0, i0 = i1, i1 = t;
  10016. t = x0, x0 = x1, x1 = t;
  10017. }
  10018. domain[i0] = interval.floor(x0);
  10019. domain[i1] = interval.ceil(x1);
  10020. return domain;
  10021. };
  10022. function deinterpolate(a, b) {
  10023. return (b = Math.log(b / a))
  10024. ? function(x) { return Math.log(x / a) / b; }
  10025. : constant$9(b);
  10026. }
  10027. function reinterpolate$1(a, b) {
  10028. return a < 0
  10029. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  10030. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  10031. }
  10032. function pow10(x) {
  10033. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10034. }
  10035. function powp(base) {
  10036. return base === 10 ? pow10
  10037. : base === Math.E ? Math.exp
  10038. : function(x) { return Math.pow(base, x); };
  10039. }
  10040. function logp(base) {
  10041. return base === Math.E ? Math.log
  10042. : base === 10 && Math.log10
  10043. || base === 2 && Math.log2
  10044. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10045. }
  10046. function reflect(f) {
  10047. return function(x) {
  10048. return -f(-x);
  10049. };
  10050. }
  10051. function log$1() {
  10052. var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
  10053. domain = scale.domain,
  10054. base = 10,
  10055. logs = logp(10),
  10056. pows = powp(10);
  10057. function rescale() {
  10058. logs = logp(base), pows = powp(base);
  10059. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  10060. return scale;
  10061. }
  10062. scale.base = function(_) {
  10063. return arguments.length ? (base = +_, rescale()) : base;
  10064. };
  10065. scale.domain = function(_) {
  10066. return arguments.length ? (domain(_), rescale()) : domain();
  10067. };
  10068. scale.ticks = function(count) {
  10069. var d = domain(),
  10070. u = d[0],
  10071. v = d[d.length - 1],
  10072. r;
  10073. if (r = v < u) i = u, u = v, v = i;
  10074. var i = logs(u),
  10075. j = logs(v),
  10076. p,
  10077. k,
  10078. t,
  10079. n = count == null ? 10 : +count,
  10080. z = [];
  10081. if (!(base % 1) && j - i < n) {
  10082. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10083. if (u > 0) for (; i < j; ++i) {
  10084. for (k = 1, p = pows(i); k < base; ++k) {
  10085. t = p * k;
  10086. if (t < u) continue;
  10087. if (t > v) break;
  10088. z.push(t);
  10089. }
  10090. } else for (; i < j; ++i) {
  10091. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10092. t = p * k;
  10093. if (t < u) continue;
  10094. if (t > v) break;
  10095. z.push(t);
  10096. }
  10097. }
  10098. } else {
  10099. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10100. }
  10101. return r ? z.reverse() : z;
  10102. };
  10103. scale.tickFormat = function(count, specifier) {
  10104. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10105. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10106. if (count === Infinity) return specifier;
  10107. if (count == null) count = 10;
  10108. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10109. return function(d) {
  10110. var i = d / pows(Math.round(logs(d)));
  10111. if (i * base < base - 0.5) i *= base;
  10112. return i <= k ? specifier(d) : "";
  10113. };
  10114. };
  10115. scale.nice = function() {
  10116. return domain(nice(domain(), {
  10117. floor: function(x) { return pows(Math.floor(logs(x))); },
  10118. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10119. }));
  10120. };
  10121. scale.copy = function() {
  10122. return copy(scale, log$1().base(base));
  10123. };
  10124. return scale;
  10125. }
  10126. function raise$1(x, exponent) {
  10127. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10128. }
  10129. function pow$1() {
  10130. var exponent = 1,
  10131. scale = continuous(deinterpolate, reinterpolate),
  10132. domain = scale.domain;
  10133. function deinterpolate(a, b) {
  10134. return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
  10135. ? function(x) { return (raise$1(x, exponent) - a) / b; }
  10136. : constant$9(b);
  10137. }
  10138. function reinterpolate(a, b) {
  10139. b = raise$1(b, exponent) - (a = raise$1(a, exponent));
  10140. return function(t) { return raise$1(a + b * t, 1 / exponent); };
  10141. }
  10142. scale.exponent = function(_) {
  10143. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  10144. };
  10145. scale.copy = function() {
  10146. return copy(scale, pow$1().exponent(exponent));
  10147. };
  10148. return linearish(scale);
  10149. }
  10150. function sqrt$1() {
  10151. return pow$1().exponent(0.5);
  10152. }
  10153. function quantile$$1() {
  10154. var domain = [],
  10155. range = [],
  10156. thresholds = [];
  10157. function rescale() {
  10158. var i = 0, n = Math.max(1, range.length);
  10159. thresholds = new Array(n - 1);
  10160. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10161. return scale;
  10162. }
  10163. function scale(x) {
  10164. if (!isNaN(x = +x)) return range[bisectRight$1(thresholds, x)];
  10165. }
  10166. scale.invertExtent = function(y) {
  10167. var i = range.indexOf(y);
  10168. return i < 0 ? [NaN, NaN] : [
  10169. i > 0 ? thresholds[i - 1] : domain[0],
  10170. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10171. ];
  10172. };
  10173. scale.domain = function(_) {
  10174. if (!arguments.length) return domain.slice();
  10175. domain = [];
  10176. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10177. domain.sort(ascending);
  10178. return rescale();
  10179. };
  10180. scale.range = function(_) {
  10181. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10182. };
  10183. scale.quantiles = function() {
  10184. return thresholds.slice();
  10185. };
  10186. scale.copy = function() {
  10187. return quantile$$1()
  10188. .domain(domain)
  10189. .range(range);
  10190. };
  10191. return scale;
  10192. }
  10193. function quantize$1() {
  10194. var x0 = 0,
  10195. x1 = 1,
  10196. n = 1,
  10197. domain = [0.5],
  10198. range = [0, 1];
  10199. function scale(x) {
  10200. if (x <= x) return range[bisectRight$1(domain, x, 0, n)];
  10201. }
  10202. function rescale() {
  10203. var i = -1;
  10204. domain = new Array(n);
  10205. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10206. return scale;
  10207. }
  10208. scale.domain = function(_) {
  10209. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10210. };
  10211. scale.range = function(_) {
  10212. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10213. };
  10214. scale.invertExtent = function(y) {
  10215. var i = range.indexOf(y);
  10216. return i < 0 ? [NaN, NaN]
  10217. : i < 1 ? [x0, domain[0]]
  10218. : i >= n ? [domain[n - 1], x1]
  10219. : [domain[i - 1], domain[i]];
  10220. };
  10221. scale.copy = function() {
  10222. return quantize$1()
  10223. .domain([x0, x1])
  10224. .range(range);
  10225. };
  10226. return linearish(scale);
  10227. }
  10228. function threshold$1() {
  10229. var domain = [0.5],
  10230. range = [0, 1],
  10231. n = 1;
  10232. function scale(x) {
  10233. if (x <= x) return range[bisectRight$1(domain, x, 0, n)];
  10234. }
  10235. scale.domain = function(_) {
  10236. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10237. };
  10238. scale.range = function(_) {
  10239. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10240. };
  10241. scale.invertExtent = function(y) {
  10242. var i = range.indexOf(y);
  10243. return [domain[i - 1], domain[i]];
  10244. };
  10245. scale.copy = function() {
  10246. return threshold$1()
  10247. .domain(domain)
  10248. .range(range);
  10249. };
  10250. return scale;
  10251. }
  10252. var t0$1 = new Date;
  10253. var t1$1 = new Date;
  10254. function newInterval(floori, offseti, count, field) {
  10255. function interval(date) {
  10256. return floori(date = new Date(+date)), date;
  10257. }
  10258. interval.floor = interval;
  10259. interval.ceil = function(date) {
  10260. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10261. };
  10262. interval.round = function(date) {
  10263. var d0 = interval(date),
  10264. d1 = interval.ceil(date);
  10265. return date - d0 < d1 - date ? d0 : d1;
  10266. };
  10267. interval.offset = function(date, step) {
  10268. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10269. };
  10270. interval.range = function(start, stop, step) {
  10271. var range = [];
  10272. start = interval.ceil(start);
  10273. step = step == null ? 1 : Math.floor(step);
  10274. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10275. do range.push(new Date(+start)); while (offseti(start, step), floori(start), start < stop)
  10276. return range;
  10277. };
  10278. interval.filter = function(test) {
  10279. return newInterval(function(date) {
  10280. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10281. }, function(date, step) {
  10282. if (date >= date) {
  10283. if (step < 0) while (++step <= 0) {
  10284. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10285. } else while (--step >= 0) {
  10286. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10287. }
  10288. }
  10289. });
  10290. };
  10291. if (count) {
  10292. interval.count = function(start, end) {
  10293. t0$1.setTime(+start), t1$1.setTime(+end);
  10294. floori(t0$1), floori(t1$1);
  10295. return Math.floor(count(t0$1, t1$1));
  10296. };
  10297. interval.every = function(step) {
  10298. step = Math.floor(step);
  10299. return !isFinite(step) || !(step > 0) ? null
  10300. : !(step > 1) ? interval
  10301. : interval.filter(field
  10302. ? function(d) { return field(d) % step === 0; }
  10303. : function(d) { return interval.count(0, d) % step === 0; });
  10304. };
  10305. }
  10306. return interval;
  10307. }
  10308. var millisecond = newInterval(function() {
  10309. // noop
  10310. }, function(date, step) {
  10311. date.setTime(+date + step);
  10312. }, function(start, end) {
  10313. return end - start;
  10314. });
  10315. // An optimized implementation for this simple case.
  10316. millisecond.every = function(k) {
  10317. k = Math.floor(k);
  10318. if (!isFinite(k) || !(k > 0)) return null;
  10319. if (!(k > 1)) return millisecond;
  10320. return newInterval(function(date) {
  10321. date.setTime(Math.floor(date / k) * k);
  10322. }, function(date, step) {
  10323. date.setTime(+date + step * k);
  10324. }, function(start, end) {
  10325. return (end - start) / k;
  10326. });
  10327. };
  10328. var milliseconds = millisecond.range;
  10329. var durationSecond$1 = 1e3;
  10330. var durationMinute$1 = 6e4;
  10331. var durationHour$1 = 36e5;
  10332. var durationDay$1 = 864e5;
  10333. var durationWeek$1 = 6048e5;
  10334. var second = newInterval(function(date) {
  10335. date.setTime(Math.floor(date / durationSecond$1) * durationSecond$1);
  10336. }, function(date, step) {
  10337. date.setTime(+date + step * durationSecond$1);
  10338. }, function(start, end) {
  10339. return (end - start) / durationSecond$1;
  10340. }, function(date) {
  10341. return date.getUTCSeconds();
  10342. });
  10343. var seconds = second.range;
  10344. var minute = newInterval(function(date) {
  10345. date.setTime(Math.floor(date / durationMinute$1) * durationMinute$1);
  10346. }, function(date, step) {
  10347. date.setTime(+date + step * durationMinute$1);
  10348. }, function(start, end) {
  10349. return (end - start) / durationMinute$1;
  10350. }, function(date) {
  10351. return date.getMinutes();
  10352. });
  10353. var minutes = minute.range;
  10354. var hour = newInterval(function(date) {
  10355. var offset = date.getTimezoneOffset() * durationMinute$1 % durationHour$1;
  10356. if (offset < 0) offset += durationHour$1;
  10357. date.setTime(Math.floor((+date - offset) / durationHour$1) * durationHour$1 + offset);
  10358. }, function(date, step) {
  10359. date.setTime(+date + step * durationHour$1);
  10360. }, function(start, end) {
  10361. return (end - start) / durationHour$1;
  10362. }, function(date) {
  10363. return date.getHours();
  10364. });
  10365. var hours = hour.range;
  10366. var day = newInterval(function(date) {
  10367. date.setHours(0, 0, 0, 0);
  10368. }, function(date, step) {
  10369. date.setDate(date.getDate() + step);
  10370. }, function(start, end) {
  10371. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationDay$1;
  10372. }, function(date) {
  10373. return date.getDate() - 1;
  10374. });
  10375. var days = day.range;
  10376. function weekday(i) {
  10377. return newInterval(function(date) {
  10378. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  10379. date.setHours(0, 0, 0, 0);
  10380. }, function(date, step) {
  10381. date.setDate(date.getDate() + step * 7);
  10382. }, function(start, end) {
  10383. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
  10384. });
  10385. }
  10386. var sunday = weekday(0);
  10387. var monday = weekday(1);
  10388. var tuesday = weekday(2);
  10389. var wednesday = weekday(3);
  10390. var thursday = weekday(4);
  10391. var friday = weekday(5);
  10392. var saturday = weekday(6);
  10393. var sundays = sunday.range;
  10394. var mondays = monday.range;
  10395. var tuesdays = tuesday.range;
  10396. var wednesdays = wednesday.range;
  10397. var thursdays = thursday.range;
  10398. var fridays = friday.range;
  10399. var saturdays = saturday.range;
  10400. var month = newInterval(function(date) {
  10401. date.setDate(1);
  10402. date.setHours(0, 0, 0, 0);
  10403. }, function(date, step) {
  10404. date.setMonth(date.getMonth() + step);
  10405. }, function(start, end) {
  10406. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  10407. }, function(date) {
  10408. return date.getMonth();
  10409. });
  10410. var months = month.range;
  10411. var year = newInterval(function(date) {
  10412. date.setMonth(0, 1);
  10413. date.setHours(0, 0, 0, 0);
  10414. }, function(date, step) {
  10415. date.setFullYear(date.getFullYear() + step);
  10416. }, function(start, end) {
  10417. return end.getFullYear() - start.getFullYear();
  10418. }, function(date) {
  10419. return date.getFullYear();
  10420. });
  10421. // An optimized implementation for this simple case.
  10422. year.every = function(k) {
  10423. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10424. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  10425. date.setMonth(0, 1);
  10426. date.setHours(0, 0, 0, 0);
  10427. }, function(date, step) {
  10428. date.setFullYear(date.getFullYear() + step * k);
  10429. });
  10430. };
  10431. var years = year.range;
  10432. var utcMinute = newInterval(function(date) {
  10433. date.setUTCSeconds(0, 0);
  10434. }, function(date, step) {
  10435. date.setTime(+date + step * durationMinute$1);
  10436. }, function(start, end) {
  10437. return (end - start) / durationMinute$1;
  10438. }, function(date) {
  10439. return date.getUTCMinutes();
  10440. });
  10441. var utcMinutes = utcMinute.range;
  10442. var utcHour = newInterval(function(date) {
  10443. date.setUTCMinutes(0, 0, 0);
  10444. }, function(date, step) {
  10445. date.setTime(+date + step * durationHour$1);
  10446. }, function(start, end) {
  10447. return (end - start) / durationHour$1;
  10448. }, function(date) {
  10449. return date.getUTCHours();
  10450. });
  10451. var utcHours = utcHour.range;
  10452. var utcDay = newInterval(function(date) {
  10453. date.setUTCHours(0, 0, 0, 0);
  10454. }, function(date, step) {
  10455. date.setUTCDate(date.getUTCDate() + step);
  10456. }, function(start, end) {
  10457. return (end - start) / durationDay$1;
  10458. }, function(date) {
  10459. return date.getUTCDate() - 1;
  10460. });
  10461. var utcDays = utcDay.range;
  10462. function utcWeekday(i) {
  10463. return newInterval(function(date) {
  10464. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  10465. date.setUTCHours(0, 0, 0, 0);
  10466. }, function(date, step) {
  10467. date.setUTCDate(date.getUTCDate() + step * 7);
  10468. }, function(start, end) {
  10469. return (end - start) / durationWeek$1;
  10470. });
  10471. }
  10472. var utcSunday = utcWeekday(0);
  10473. var utcMonday = utcWeekday(1);
  10474. var utcTuesday = utcWeekday(2);
  10475. var utcWednesday = utcWeekday(3);
  10476. var utcThursday = utcWeekday(4);
  10477. var utcFriday = utcWeekday(5);
  10478. var utcSaturday = utcWeekday(6);
  10479. var utcSundays = utcSunday.range;
  10480. var utcMondays = utcMonday.range;
  10481. var utcTuesdays = utcTuesday.range;
  10482. var utcWednesdays = utcWednesday.range;
  10483. var utcThursdays = utcThursday.range;
  10484. var utcFridays = utcFriday.range;
  10485. var utcSaturdays = utcSaturday.range;
  10486. var utcMonth = newInterval(function(date) {
  10487. date.setUTCDate(1);
  10488. date.setUTCHours(0, 0, 0, 0);
  10489. }, function(date, step) {
  10490. date.setUTCMonth(date.getUTCMonth() + step);
  10491. }, function(start, end) {
  10492. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  10493. }, function(date) {
  10494. return date.getUTCMonth();
  10495. });
  10496. var utcMonths = utcMonth.range;
  10497. var utcYear = newInterval(function(date) {
  10498. date.setUTCMonth(0, 1);
  10499. date.setUTCHours(0, 0, 0, 0);
  10500. }, function(date, step) {
  10501. date.setUTCFullYear(date.getUTCFullYear() + step);
  10502. }, function(start, end) {
  10503. return end.getUTCFullYear() - start.getUTCFullYear();
  10504. }, function(date) {
  10505. return date.getUTCFullYear();
  10506. });
  10507. // An optimized implementation for this simple case.
  10508. utcYear.every = function(k) {
  10509. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10510. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  10511. date.setUTCMonth(0, 1);
  10512. date.setUTCHours(0, 0, 0, 0);
  10513. }, function(date, step) {
  10514. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  10515. });
  10516. };
  10517. var utcYears = utcYear.range;
  10518. function localDate(d) {
  10519. if (0 <= d.y && d.y < 100) {
  10520. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  10521. date.setFullYear(d.y);
  10522. return date;
  10523. }
  10524. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  10525. }
  10526. function utcDate(d) {
  10527. if (0 <= d.y && d.y < 100) {
  10528. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  10529. date.setUTCFullYear(d.y);
  10530. return date;
  10531. }
  10532. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  10533. }
  10534. function newYear(y) {
  10535. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  10536. }
  10537. function formatLocale$1(locale) {
  10538. var locale_dateTime = locale.dateTime,
  10539. locale_date = locale.date,
  10540. locale_time = locale.time,
  10541. locale_periods = locale.periods,
  10542. locale_weekdays = locale.days,
  10543. locale_shortWeekdays = locale.shortDays,
  10544. locale_months = locale.months,
  10545. locale_shortMonths = locale.shortMonths;
  10546. var periodRe = formatRe(locale_periods),
  10547. periodLookup = formatLookup(locale_periods),
  10548. weekdayRe = formatRe(locale_weekdays),
  10549. weekdayLookup = formatLookup(locale_weekdays),
  10550. shortWeekdayRe = formatRe(locale_shortWeekdays),
  10551. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  10552. monthRe = formatRe(locale_months),
  10553. monthLookup = formatLookup(locale_months),
  10554. shortMonthRe = formatRe(locale_shortMonths),
  10555. shortMonthLookup = formatLookup(locale_shortMonths);
  10556. var formats = {
  10557. "a": formatShortWeekday,
  10558. "A": formatWeekday,
  10559. "b": formatShortMonth,
  10560. "B": formatMonth,
  10561. "c": null,
  10562. "d": formatDayOfMonth,
  10563. "e": formatDayOfMonth,
  10564. "H": formatHour24,
  10565. "I": formatHour12,
  10566. "j": formatDayOfYear,
  10567. "L": formatMilliseconds,
  10568. "m": formatMonthNumber,
  10569. "M": formatMinutes,
  10570. "p": formatPeriod,
  10571. "S": formatSeconds,
  10572. "U": formatWeekNumberSunday,
  10573. "w": formatWeekdayNumber,
  10574. "W": formatWeekNumberMonday,
  10575. "x": null,
  10576. "X": null,
  10577. "y": formatYear,
  10578. "Y": formatFullYear,
  10579. "Z": formatZone,
  10580. "%": formatLiteralPercent
  10581. };
  10582. var utcFormats = {
  10583. "a": formatUTCShortWeekday,
  10584. "A": formatUTCWeekday,
  10585. "b": formatUTCShortMonth,
  10586. "B": formatUTCMonth,
  10587. "c": null,
  10588. "d": formatUTCDayOfMonth,
  10589. "e": formatUTCDayOfMonth,
  10590. "H": formatUTCHour24,
  10591. "I": formatUTCHour12,
  10592. "j": formatUTCDayOfYear,
  10593. "L": formatUTCMilliseconds,
  10594. "m": formatUTCMonthNumber,
  10595. "M": formatUTCMinutes,
  10596. "p": formatUTCPeriod,
  10597. "S": formatUTCSeconds,
  10598. "U": formatUTCWeekNumberSunday,
  10599. "w": formatUTCWeekdayNumber,
  10600. "W": formatUTCWeekNumberMonday,
  10601. "x": null,
  10602. "X": null,
  10603. "y": formatUTCYear,
  10604. "Y": formatUTCFullYear,
  10605. "Z": formatUTCZone,
  10606. "%": formatLiteralPercent
  10607. };
  10608. var parses = {
  10609. "a": parseShortWeekday,
  10610. "A": parseWeekday,
  10611. "b": parseShortMonth,
  10612. "B": parseMonth,
  10613. "c": parseLocaleDateTime,
  10614. "d": parseDayOfMonth,
  10615. "e": parseDayOfMonth,
  10616. "H": parseHour24,
  10617. "I": parseHour24,
  10618. "j": parseDayOfYear,
  10619. "L": parseMilliseconds,
  10620. "m": parseMonthNumber,
  10621. "M": parseMinutes,
  10622. "p": parsePeriod,
  10623. "S": parseSeconds,
  10624. "U": parseWeekNumberSunday,
  10625. "w": parseWeekdayNumber,
  10626. "W": parseWeekNumberMonday,
  10627. "x": parseLocaleDate,
  10628. "X": parseLocaleTime,
  10629. "y": parseYear,
  10630. "Y": parseFullYear,
  10631. "Z": parseZone,
  10632. "%": parseLiteralPercent
  10633. };
  10634. // These recursive directive definitions must be deferred.
  10635. formats.x = newFormat(locale_date, formats);
  10636. formats.X = newFormat(locale_time, formats);
  10637. formats.c = newFormat(locale_dateTime, formats);
  10638. utcFormats.x = newFormat(locale_date, utcFormats);
  10639. utcFormats.X = newFormat(locale_time, utcFormats);
  10640. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  10641. function newFormat(specifier, formats) {
  10642. return function(date) {
  10643. var string = [],
  10644. i = -1,
  10645. j = 0,
  10646. n = specifier.length,
  10647. c,
  10648. pad,
  10649. format;
  10650. if (!(date instanceof Date)) date = new Date(+date);
  10651. while (++i < n) {
  10652. if (specifier.charCodeAt(i) === 37) {
  10653. string.push(specifier.slice(j, i));
  10654. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  10655. else pad = c === "e" ? " " : "0";
  10656. if (format = formats[c]) c = format(date, pad);
  10657. string.push(c);
  10658. j = i + 1;
  10659. }
  10660. }
  10661. string.push(specifier.slice(j, i));
  10662. return string.join("");
  10663. };
  10664. }
  10665. function newParse(specifier, newDate) {
  10666. return function(string) {
  10667. var d = newYear(1900),
  10668. i = parseSpecifier(d, specifier, string += "", 0);
  10669. if (i != string.length) return null;
  10670. // The am-pm flag is 0 for AM, and 1 for PM.
  10671. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  10672. // Convert day-of-week and week-of-year to day-of-year.
  10673. if ("W" in d || "U" in d) {
  10674. if (!("w" in d)) d.w = "W" in d ? 1 : 0;
  10675. var day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  10676. d.m = 0;
  10677. d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$$1 + 5) % 7 : d.w + d.U * 7 - (day$$1 + 6) % 7;
  10678. }
  10679. // If a time zone is specified, all fields are interpreted as UTC and then
  10680. // offset according to the specified time zone.
  10681. if ("Z" in d) {
  10682. d.H += d.Z / 100 | 0;
  10683. d.M += d.Z % 100;
  10684. return utcDate(d);
  10685. }
  10686. // Otherwise, all fields are in local time.
  10687. return newDate(d);
  10688. };
  10689. }
  10690. function parseSpecifier(d, specifier, string, j) {
  10691. var i = 0,
  10692. n = specifier.length,
  10693. m = string.length,
  10694. c,
  10695. parse;
  10696. while (i < n) {
  10697. if (j >= m) return -1;
  10698. c = specifier.charCodeAt(i++);
  10699. if (c === 37) {
  10700. c = specifier.charAt(i++);
  10701. parse = parses[c in pads ? specifier.charAt(i++) : c];
  10702. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  10703. } else if (c != string.charCodeAt(j++)) {
  10704. return -1;
  10705. }
  10706. }
  10707. return j;
  10708. }
  10709. function parsePeriod(d, string, i) {
  10710. var n = periodRe.exec(string.slice(i));
  10711. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10712. }
  10713. function parseShortWeekday(d, string, i) {
  10714. var n = shortWeekdayRe.exec(string.slice(i));
  10715. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10716. }
  10717. function parseWeekday(d, string, i) {
  10718. var n = weekdayRe.exec(string.slice(i));
  10719. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10720. }
  10721. function parseShortMonth(d, string, i) {
  10722. var n = shortMonthRe.exec(string.slice(i));
  10723. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10724. }
  10725. function parseMonth(d, string, i) {
  10726. var n = monthRe.exec(string.slice(i));
  10727. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10728. }
  10729. function parseLocaleDateTime(d, string, i) {
  10730. return parseSpecifier(d, locale_dateTime, string, i);
  10731. }
  10732. function parseLocaleDate(d, string, i) {
  10733. return parseSpecifier(d, locale_date, string, i);
  10734. }
  10735. function parseLocaleTime(d, string, i) {
  10736. return parseSpecifier(d, locale_time, string, i);
  10737. }
  10738. function formatShortWeekday(d) {
  10739. return locale_shortWeekdays[d.getDay()];
  10740. }
  10741. function formatWeekday(d) {
  10742. return locale_weekdays[d.getDay()];
  10743. }
  10744. function formatShortMonth(d) {
  10745. return locale_shortMonths[d.getMonth()];
  10746. }
  10747. function formatMonth(d) {
  10748. return locale_months[d.getMonth()];
  10749. }
  10750. function formatPeriod(d) {
  10751. return locale_periods[+(d.getHours() >= 12)];
  10752. }
  10753. function formatUTCShortWeekday(d) {
  10754. return locale_shortWeekdays[d.getUTCDay()];
  10755. }
  10756. function formatUTCWeekday(d) {
  10757. return locale_weekdays[d.getUTCDay()];
  10758. }
  10759. function formatUTCShortMonth(d) {
  10760. return locale_shortMonths[d.getUTCMonth()];
  10761. }
  10762. function formatUTCMonth(d) {
  10763. return locale_months[d.getUTCMonth()];
  10764. }
  10765. function formatUTCPeriod(d) {
  10766. return locale_periods[+(d.getUTCHours() >= 12)];
  10767. }
  10768. return {
  10769. format: function(specifier) {
  10770. var f = newFormat(specifier += "", formats);
  10771. f.toString = function() { return specifier; };
  10772. return f;
  10773. },
  10774. parse: function(specifier) {
  10775. var p = newParse(specifier += "", localDate);
  10776. p.toString = function() { return specifier; };
  10777. return p;
  10778. },
  10779. utcFormat: function(specifier) {
  10780. var f = newFormat(specifier += "", utcFormats);
  10781. f.toString = function() { return specifier; };
  10782. return f;
  10783. },
  10784. utcParse: function(specifier) {
  10785. var p = newParse(specifier, utcDate);
  10786. p.toString = function() { return specifier; };
  10787. return p;
  10788. }
  10789. };
  10790. }
  10791. var pads = {"-": "", "_": " ", "0": "0"};
  10792. var numberRe = /^\s*\d+/;
  10793. var percentRe = /^%/;
  10794. var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  10795. function pad(value, fill, width) {
  10796. var sign = value < 0 ? "-" : "",
  10797. string = (sign ? -value : value) + "",
  10798. length = string.length;
  10799. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  10800. }
  10801. function requote(s) {
  10802. return s.replace(requoteRe, "\\$&");
  10803. }
  10804. function formatRe(names) {
  10805. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  10806. }
  10807. function formatLookup(names) {
  10808. var map = {}, i = -1, n = names.length;
  10809. while (++i < n) map[names[i].toLowerCase()] = i;
  10810. return map;
  10811. }
  10812. function parseWeekdayNumber(d, string, i) {
  10813. var n = numberRe.exec(string.slice(i, i + 1));
  10814. return n ? (d.w = +n[0], i + n[0].length) : -1;
  10815. }
  10816. function parseWeekNumberSunday(d, string, i) {
  10817. var n = numberRe.exec(string.slice(i));
  10818. return n ? (d.U = +n[0], i + n[0].length) : -1;
  10819. }
  10820. function parseWeekNumberMonday(d, string, i) {
  10821. var n = numberRe.exec(string.slice(i));
  10822. return n ? (d.W = +n[0], i + n[0].length) : -1;
  10823. }
  10824. function parseFullYear(d, string, i) {
  10825. var n = numberRe.exec(string.slice(i, i + 4));
  10826. return n ? (d.y = +n[0], i + n[0].length) : -1;
  10827. }
  10828. function parseYear(d, string, i) {
  10829. var n = numberRe.exec(string.slice(i, i + 2));
  10830. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  10831. }
  10832. function parseZone(d, string, i) {
  10833. var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
  10834. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  10835. }
  10836. function parseMonthNumber(d, string, i) {
  10837. var n = numberRe.exec(string.slice(i, i + 2));
  10838. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  10839. }
  10840. function parseDayOfMonth(d, string, i) {
  10841. var n = numberRe.exec(string.slice(i, i + 2));
  10842. return n ? (d.d = +n[0], i + n[0].length) : -1;
  10843. }
  10844. function parseDayOfYear(d, string, i) {
  10845. var n = numberRe.exec(string.slice(i, i + 3));
  10846. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  10847. }
  10848. function parseHour24(d, string, i) {
  10849. var n = numberRe.exec(string.slice(i, i + 2));
  10850. return n ? (d.H = +n[0], i + n[0].length) : -1;
  10851. }
  10852. function parseMinutes(d, string, i) {
  10853. var n = numberRe.exec(string.slice(i, i + 2));
  10854. return n ? (d.M = +n[0], i + n[0].length) : -1;
  10855. }
  10856. function parseSeconds(d, string, i) {
  10857. var n = numberRe.exec(string.slice(i, i + 2));
  10858. return n ? (d.S = +n[0], i + n[0].length) : -1;
  10859. }
  10860. function parseMilliseconds(d, string, i) {
  10861. var n = numberRe.exec(string.slice(i, i + 3));
  10862. return n ? (d.L = +n[0], i + n[0].length) : -1;
  10863. }
  10864. function parseLiteralPercent(d, string, i) {
  10865. var n = percentRe.exec(string.slice(i, i + 1));
  10866. return n ? i + n[0].length : -1;
  10867. }
  10868. function formatDayOfMonth(d, p) {
  10869. return pad(d.getDate(), p, 2);
  10870. }
  10871. function formatHour24(d, p) {
  10872. return pad(d.getHours(), p, 2);
  10873. }
  10874. function formatHour12(d, p) {
  10875. return pad(d.getHours() % 12 || 12, p, 2);
  10876. }
  10877. function formatDayOfYear(d, p) {
  10878. return pad(1 + day.count(year(d), d), p, 3);
  10879. }
  10880. function formatMilliseconds(d, p) {
  10881. return pad(d.getMilliseconds(), p, 3);
  10882. }
  10883. function formatMonthNumber(d, p) {
  10884. return pad(d.getMonth() + 1, p, 2);
  10885. }
  10886. function formatMinutes(d, p) {
  10887. return pad(d.getMinutes(), p, 2);
  10888. }
  10889. function formatSeconds(d, p) {
  10890. return pad(d.getSeconds(), p, 2);
  10891. }
  10892. function formatWeekNumberSunday(d, p) {
  10893. return pad(sunday.count(year(d), d), p, 2);
  10894. }
  10895. function formatWeekdayNumber(d) {
  10896. return d.getDay();
  10897. }
  10898. function formatWeekNumberMonday(d, p) {
  10899. return pad(monday.count(year(d), d), p, 2);
  10900. }
  10901. function formatYear(d, p) {
  10902. return pad(d.getFullYear() % 100, p, 2);
  10903. }
  10904. function formatFullYear(d, p) {
  10905. return pad(d.getFullYear() % 10000, p, 4);
  10906. }
  10907. function formatZone(d) {
  10908. var z = d.getTimezoneOffset();
  10909. return (z > 0 ? "-" : (z *= -1, "+"))
  10910. + pad(z / 60 | 0, "0", 2)
  10911. + pad(z % 60, "0", 2);
  10912. }
  10913. function formatUTCDayOfMonth(d, p) {
  10914. return pad(d.getUTCDate(), p, 2);
  10915. }
  10916. function formatUTCHour24(d, p) {
  10917. return pad(d.getUTCHours(), p, 2);
  10918. }
  10919. function formatUTCHour12(d, p) {
  10920. return pad(d.getUTCHours() % 12 || 12, p, 2);
  10921. }
  10922. function formatUTCDayOfYear(d, p) {
  10923. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  10924. }
  10925. function formatUTCMilliseconds(d, p) {
  10926. return pad(d.getUTCMilliseconds(), p, 3);
  10927. }
  10928. function formatUTCMonthNumber(d, p) {
  10929. return pad(d.getUTCMonth() + 1, p, 2);
  10930. }
  10931. function formatUTCMinutes(d, p) {
  10932. return pad(d.getUTCMinutes(), p, 2);
  10933. }
  10934. function formatUTCSeconds(d, p) {
  10935. return pad(d.getUTCSeconds(), p, 2);
  10936. }
  10937. function formatUTCWeekNumberSunday(d, p) {
  10938. return pad(utcSunday.count(utcYear(d), d), p, 2);
  10939. }
  10940. function formatUTCWeekdayNumber(d) {
  10941. return d.getUTCDay();
  10942. }
  10943. function formatUTCWeekNumberMonday(d, p) {
  10944. return pad(utcMonday.count(utcYear(d), d), p, 2);
  10945. }
  10946. function formatUTCYear(d, p) {
  10947. return pad(d.getUTCFullYear() % 100, p, 2);
  10948. }
  10949. function formatUTCFullYear(d, p) {
  10950. return pad(d.getUTCFullYear() % 10000, p, 4);
  10951. }
  10952. function formatUTCZone() {
  10953. return "+0000";
  10954. }
  10955. function formatLiteralPercent() {
  10956. return "%";
  10957. }
  10958. var locale$2;
  10959. defaultLocale$1({
  10960. dateTime: "%x, %X",
  10961. date: "%-m/%-d/%Y",
  10962. time: "%-I:%M:%S %p",
  10963. periods: ["AM", "PM"],
  10964. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  10965. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  10966. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  10967. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  10968. });
  10969. function defaultLocale$1(definition) {
  10970. locale$2 = formatLocale$1(definition);
  10971. exports.timeFormat = locale$2.format;
  10972. exports.timeParse = locale$2.parse;
  10973. exports.utcFormat = locale$2.utcFormat;
  10974. exports.utcParse = locale$2.utcParse;
  10975. return locale$2;
  10976. }
  10977. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  10978. function formatIsoNative(date) {
  10979. return date.toISOString();
  10980. }
  10981. var formatIso = Date.prototype.toISOString
  10982. ? formatIsoNative
  10983. : exports.utcFormat(isoSpecifier);
  10984. function parseIsoNative(string) {
  10985. var date = new Date(string);
  10986. return isNaN(date) ? null : date;
  10987. }
  10988. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  10989. ? parseIsoNative
  10990. : exports.utcParse(isoSpecifier);
  10991. var durationSecond = 1000;
  10992. var durationMinute = durationSecond * 60;
  10993. var durationHour = durationMinute * 60;
  10994. var durationDay = durationHour * 24;
  10995. var durationWeek = durationDay * 7;
  10996. var durationMonth = durationDay * 30;
  10997. var durationYear = durationDay * 365;
  10998. function date$1(t) {
  10999. return new Date(t);
  11000. }
  11001. function number$3(t) {
  11002. return t instanceof Date ? +t : +new Date(+t);
  11003. }
  11004. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  11005. var scale = continuous(deinterpolateLinear, reinterpolate),
  11006. invert = scale.invert,
  11007. domain = scale.domain;
  11008. var formatMillisecond = format(".%L"),
  11009. formatSecond = format(":%S"),
  11010. formatMinute = format("%I:%M"),
  11011. formatHour = format("%I %p"),
  11012. formatDay = format("%a %d"),
  11013. formatWeek = format("%b %d"),
  11014. formatMonth = format("%B"),
  11015. formatYear = format("%Y");
  11016. var tickIntervals = [
  11017. [second$$1, 1, durationSecond],
  11018. [second$$1, 5, 5 * durationSecond],
  11019. [second$$1, 15, 15 * durationSecond],
  11020. [second$$1, 30, 30 * durationSecond],
  11021. [minute$$1, 1, durationMinute],
  11022. [minute$$1, 5, 5 * durationMinute],
  11023. [minute$$1, 15, 15 * durationMinute],
  11024. [minute$$1, 30, 30 * durationMinute],
  11025. [ hour$$1, 1, durationHour ],
  11026. [ hour$$1, 3, 3 * durationHour ],
  11027. [ hour$$1, 6, 6 * durationHour ],
  11028. [ hour$$1, 12, 12 * durationHour ],
  11029. [ day$$1, 1, durationDay ],
  11030. [ day$$1, 2, 2 * durationDay ],
  11031. [ week, 1, durationWeek ],
  11032. [ month$$1, 1, durationMonth ],
  11033. [ month$$1, 3, 3 * durationMonth ],
  11034. [ year$$1, 1, durationYear ]
  11035. ];
  11036. function tickFormat(date) {
  11037. return (second$$1(date) < date ? formatMillisecond
  11038. : minute$$1(date) < date ? formatSecond
  11039. : hour$$1(date) < date ? formatMinute
  11040. : day$$1(date) < date ? formatHour
  11041. : month$$1(date) < date ? (week(date) < date ? formatDay : formatWeek)
  11042. : year$$1(date) < date ? formatMonth
  11043. : formatYear)(date);
  11044. }
  11045. function tickInterval(interval, start, stop, step) {
  11046. if (interval == null) interval = 10;
  11047. // If a desired tick count is specified, pick a reasonable tick interval
  11048. // based on the extent of the domain and a rough estimate of tick size.
  11049. // Otherwise, assume interval is already a time interval and use it.
  11050. if (typeof interval === "number") {
  11051. var target = Math.abs(stop - start) / interval,
  11052. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11053. if (i === tickIntervals.length) {
  11054. step = tickStep(start / durationYear, stop / durationYear, interval);
  11055. interval = year$$1;
  11056. } else if (i) {
  11057. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11058. step = i[1];
  11059. interval = i[0];
  11060. } else {
  11061. step = tickStep(start, stop, interval);
  11062. interval = millisecond$$1;
  11063. }
  11064. }
  11065. return step == null ? interval : interval.every(step);
  11066. }
  11067. scale.invert = function(y) {
  11068. return new Date(invert(y));
  11069. };
  11070. scale.domain = function(_) {
  11071. return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
  11072. };
  11073. scale.ticks = function(interval, step) {
  11074. var d = domain(),
  11075. t0 = d[0],
  11076. t1 = d[d.length - 1],
  11077. r = t1 < t0,
  11078. t;
  11079. if (r) t = t0, t0 = t1, t1 = t;
  11080. t = tickInterval(interval, t0, t1, step);
  11081. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11082. return r ? t.reverse() : t;
  11083. };
  11084. scale.tickFormat = function(count, specifier) {
  11085. return specifier == null ? tickFormat : format(specifier);
  11086. };
  11087. scale.nice = function(interval, step) {
  11088. var d = domain();
  11089. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11090. ? domain(nice(d, interval))
  11091. : scale;
  11092. };
  11093. scale.copy = function() {
  11094. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  11095. };
  11096. return scale;
  11097. }
  11098. var time = function() {
  11099. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  11100. };
  11101. var utcTime = function() {
  11102. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  11103. };
  11104. var colors = function(s) {
  11105. return s.match(/.{6}/g).map(function(x) {
  11106. return "#" + x;
  11107. });
  11108. };
  11109. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11110. var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
  11111. var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
  11112. var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
  11113. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  11114. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11115. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11116. var rainbow = cubehelix();
  11117. var rainbow$1 = function(t) {
  11118. if (t < 0 || t > 1) t -= Math.floor(t);
  11119. var ts = Math.abs(t - 0.5);
  11120. rainbow.h = 360 * t - 100;
  11121. rainbow.s = 1.5 - 1.5 * ts;
  11122. rainbow.l = 0.8 - 0.9 * ts;
  11123. return rainbow + "";
  11124. };
  11125. function ramp(range) {
  11126. var n = range.length;
  11127. return function(t) {
  11128. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  11129. };
  11130. }
  11131. var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  11132. var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  11133. var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  11134. var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  11135. function sequential(interpolator) {
  11136. var x0 = 0,
  11137. x1 = 1,
  11138. clamp = false;
  11139. function scale(x) {
  11140. var t = (x - x0) / (x1 - x0);
  11141. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11142. }
  11143. scale.domain = function(_) {
  11144. return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
  11145. };
  11146. scale.clamp = function(_) {
  11147. return arguments.length ? (clamp = !!_, scale) : clamp;
  11148. };
  11149. scale.interpolator = function(_) {
  11150. return arguments.length ? (interpolator = _, scale) : interpolator;
  11151. };
  11152. scale.copy = function() {
  11153. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  11154. };
  11155. return linearish(scale);
  11156. }
  11157. var constant$10 = function(x) {
  11158. return function constant() {
  11159. return x;
  11160. };
  11161. };
  11162. var abs$1 = Math.abs;
  11163. var atan2$1 = Math.atan2;
  11164. var cos$2 = Math.cos;
  11165. var max$2 = Math.max;
  11166. var min$1 = Math.min;
  11167. var sin$2 = Math.sin;
  11168. var sqrt$2 = Math.sqrt;
  11169. var epsilon$3 = 1e-12;
  11170. var pi$4 = Math.PI;
  11171. var halfPi$3 = pi$4 / 2;
  11172. var tau$4 = 2 * pi$4;
  11173. function acos$1(x) {
  11174. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11175. }
  11176. function asin$1(x) {
  11177. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  11178. }
  11179. function arcInnerRadius(d) {
  11180. return d.innerRadius;
  11181. }
  11182. function arcOuterRadius(d) {
  11183. return d.outerRadius;
  11184. }
  11185. function arcStartAngle(d) {
  11186. return d.startAngle;
  11187. }
  11188. function arcEndAngle(d) {
  11189. return d.endAngle;
  11190. }
  11191. function arcPadAngle(d) {
  11192. return d && d.padAngle; // Note: optional!
  11193. }
  11194. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11195. var x10 = x1 - x0, y10 = y1 - y0,
  11196. x32 = x3 - x2, y32 = y3 - y2,
  11197. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  11198. return [x0 + t * x10, y0 + t * y10];
  11199. }
  11200. // Compute perpendicular offset line of length rc.
  11201. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  11202. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  11203. var x01 = x0 - x1,
  11204. y01 = y0 - y1,
  11205. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  11206. ox = lo * y01,
  11207. oy = -lo * x01,
  11208. x11 = x0 + ox,
  11209. y11 = y0 + oy,
  11210. x10 = x1 + ox,
  11211. y10 = y1 + oy,
  11212. x00 = (x11 + x10) / 2,
  11213. y00 = (y11 + y10) / 2,
  11214. dx = x10 - x11,
  11215. dy = y10 - y11,
  11216. d2 = dx * dx + dy * dy,
  11217. r = r1 - rc,
  11218. D = x11 * y10 - x10 * y11,
  11219. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  11220. cx0 = (D * dy - dx * d) / d2,
  11221. cy0 = (-D * dx - dy * d) / d2,
  11222. cx1 = (D * dy + dx * d) / d2,
  11223. cy1 = (-D * dx + dy * d) / d2,
  11224. dx0 = cx0 - x00,
  11225. dy0 = cy0 - y00,
  11226. dx1 = cx1 - x00,
  11227. dy1 = cy1 - y00;
  11228. // Pick the closer of the two intersection points.
  11229. // TODO Is there a faster way to determine which intersection to use?
  11230. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  11231. return {
  11232. cx: cx0,
  11233. cy: cy0,
  11234. x01: -ox,
  11235. y01: -oy,
  11236. x11: cx0 * (r1 / r - 1),
  11237. y11: cy0 * (r1 / r - 1)
  11238. };
  11239. }
  11240. var arc = function() {
  11241. var innerRadius = arcInnerRadius,
  11242. outerRadius = arcOuterRadius,
  11243. cornerRadius = constant$10(0),
  11244. padRadius = null,
  11245. startAngle = arcStartAngle,
  11246. endAngle = arcEndAngle,
  11247. padAngle = arcPadAngle,
  11248. context = null;
  11249. function arc() {
  11250. var buffer,
  11251. r,
  11252. r0 = +innerRadius.apply(this, arguments),
  11253. r1 = +outerRadius.apply(this, arguments),
  11254. a0 = startAngle.apply(this, arguments) - halfPi$3,
  11255. a1 = endAngle.apply(this, arguments) - halfPi$3,
  11256. da = abs$1(a1 - a0),
  11257. cw = a1 > a0;
  11258. if (!context) context = buffer = path();
  11259. // Ensure that the outer radius is always larger than the inner radius.
  11260. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  11261. // Is it a point?
  11262. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  11263. // Or is it a circle or annulus?
  11264. else if (da > tau$4 - epsilon$3) {
  11265. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  11266. context.arc(0, 0, r1, a0, a1, !cw);
  11267. if (r0 > epsilon$3) {
  11268. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  11269. context.arc(0, 0, r0, a1, a0, cw);
  11270. }
  11271. }
  11272. // Or is it a circular or annular sector?
  11273. else {
  11274. var a01 = a0,
  11275. a11 = a1,
  11276. a00 = a0,
  11277. a10 = a1,
  11278. da0 = da,
  11279. da1 = da,
  11280. ap = padAngle.apply(this, arguments) / 2,
  11281. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  11282. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  11283. rc0 = rc,
  11284. rc1 = rc,
  11285. t0,
  11286. t1;
  11287. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  11288. if (rp > epsilon$3) {
  11289. var p0 = asin$1(rp / r0 * sin$2(ap)),
  11290. p1 = asin$1(rp / r1 * sin$2(ap));
  11291. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  11292. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  11293. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  11294. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  11295. }
  11296. var x01 = r1 * cos$2(a01),
  11297. y01 = r1 * sin$2(a01),
  11298. x10 = r0 * cos$2(a10),
  11299. y10 = r0 * sin$2(a10);
  11300. // Apply rounded corners?
  11301. if (rc > epsilon$3) {
  11302. var x11 = r1 * cos$2(a11),
  11303. y11 = r1 * sin$2(a11),
  11304. x00 = r0 * cos$2(a00),
  11305. y00 = r0 * sin$2(a00);
  11306. // Restrict the corner radius according to the sector angle.
  11307. if (da < pi$4) {
  11308. var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  11309. ax = x01 - oc[0],
  11310. ay = y01 - oc[1],
  11311. bx = x11 - oc[0],
  11312. by = y11 - oc[1],
  11313. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  11314. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  11315. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  11316. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  11317. }
  11318. }
  11319. // Is the sector collapsed to a line?
  11320. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  11321. // Does the sector’s outer ring have rounded corners?
  11322. else if (rc1 > epsilon$3) {
  11323. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  11324. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  11325. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  11326. // Have the corners merged?
  11327. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  11328. // Otherwise, draw the two corners and the ring.
  11329. else {
  11330. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  11331. context.arc(0, 0, r1, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  11332. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  11333. }
  11334. }
  11335. // Or is the outer ring just a circular arc?
  11336. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  11337. // Is there no inner ring, and it’s a circular sector?
  11338. // Or perhaps it’s an annular sector collapsed due to padding?
  11339. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  11340. // Does the sector’s inner ring (or point) have rounded corners?
  11341. else if (rc0 > epsilon$3) {
  11342. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  11343. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  11344. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  11345. // Have the corners merged?
  11346. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  11347. // Otherwise, draw the two corners and the ring.
  11348. else {
  11349. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  11350. context.arc(0, 0, r0, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  11351. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  11352. }
  11353. }
  11354. // Or is the inner ring just a circular arc?
  11355. else context.arc(0, 0, r0, a10, a00, cw);
  11356. }
  11357. context.closePath();
  11358. if (buffer) return context = null, buffer + "" || null;
  11359. }
  11360. arc.centroid = function() {
  11361. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  11362. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  11363. return [cos$2(a) * r, sin$2(a) * r];
  11364. };
  11365. arc.innerRadius = function(_) {
  11366. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : innerRadius;
  11367. };
  11368. arc.outerRadius = function(_) {
  11369. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : outerRadius;
  11370. };
  11371. arc.cornerRadius = function(_) {
  11372. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : cornerRadius;
  11373. };
  11374. arc.padRadius = function(_) {
  11375. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), arc) : padRadius;
  11376. };
  11377. arc.startAngle = function(_) {
  11378. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : startAngle;
  11379. };
  11380. arc.endAngle = function(_) {
  11381. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : endAngle;
  11382. };
  11383. arc.padAngle = function(_) {
  11384. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : padAngle;
  11385. };
  11386. arc.context = function(_) {
  11387. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  11388. };
  11389. return arc;
  11390. };
  11391. function Linear(context) {
  11392. this._context = context;
  11393. }
  11394. Linear.prototype = {
  11395. areaStart: function() {
  11396. this._line = 0;
  11397. },
  11398. areaEnd: function() {
  11399. this._line = NaN;
  11400. },
  11401. lineStart: function() {
  11402. this._point = 0;
  11403. },
  11404. lineEnd: function() {
  11405. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  11406. this._line = 1 - this._line;
  11407. },
  11408. point: function(x, y) {
  11409. x = +x, y = +y;
  11410. switch (this._point) {
  11411. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  11412. case 1: this._point = 2; // proceed
  11413. default: this._context.lineTo(x, y); break;
  11414. }
  11415. }
  11416. };
  11417. var curveLinear = function(context) {
  11418. return new Linear(context);
  11419. };
  11420. function x$4(p) {
  11421. return p[0];
  11422. }
  11423. function y$3(p) {
  11424. return p[1];
  11425. }
  11426. var line = function() {
  11427. var x$$1 = x$4,
  11428. y$$1 = y$3,
  11429. defined = constant$10(true),
  11430. context = null,
  11431. curve = curveLinear,
  11432. output = null;
  11433. function line(data) {
  11434. var i,
  11435. n = data.length,
  11436. d,
  11437. defined0 = false,
  11438. buffer;
  11439. if (context == null) output = curve(buffer = path());
  11440. for (i = 0; i <= n; ++i) {
  11441. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  11442. if (defined0 = !defined0) output.lineStart();
  11443. else output.lineEnd();
  11444. }
  11445. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  11446. }
  11447. if (buffer) return output = null, buffer + "" || null;
  11448. }
  11449. line.x = function(_) {
  11450. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : x$$1;
  11451. };
  11452. line.y = function(_) {
  11453. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : y$$1;
  11454. };
  11455. line.defined = function(_) {
  11456. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), line) : defined;
  11457. };
  11458. line.curve = function(_) {
  11459. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  11460. };
  11461. line.context = function(_) {
  11462. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  11463. };
  11464. return line;
  11465. };
  11466. var area$2 = function() {
  11467. var x0 = x$4,
  11468. x1 = null,
  11469. y0 = constant$10(0),
  11470. y1 = y$3,
  11471. defined = constant$10(true),
  11472. context = null,
  11473. curve = curveLinear,
  11474. output = null;
  11475. function area(data) {
  11476. var i,
  11477. j,
  11478. k,
  11479. n = data.length,
  11480. d,
  11481. defined0 = false,
  11482. buffer,
  11483. x0z = new Array(n),
  11484. y0z = new Array(n);
  11485. if (context == null) output = curve(buffer = path());
  11486. for (i = 0; i <= n; ++i) {
  11487. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  11488. if (defined0 = !defined0) {
  11489. j = i;
  11490. output.areaStart();
  11491. output.lineStart();
  11492. } else {
  11493. output.lineEnd();
  11494. output.lineStart();
  11495. for (k = i - 1; k >= j; --k) {
  11496. output.point(x0z[k], y0z[k]);
  11497. }
  11498. output.lineEnd();
  11499. output.areaEnd();
  11500. }
  11501. }
  11502. if (defined0) {
  11503. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  11504. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  11505. }
  11506. }
  11507. if (buffer) return output = null, buffer + "" || null;
  11508. }
  11509. function arealine() {
  11510. return line().defined(defined).curve(curve).context(context);
  11511. }
  11512. area.x = function(_) {
  11513. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), x1 = null, area) : x0;
  11514. };
  11515. area.x0 = function(_) {
  11516. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), area) : x0;
  11517. };
  11518. area.x1 = function(_) {
  11519. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : x1;
  11520. };
  11521. area.y = function(_) {
  11522. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), y1 = null, area) : y0;
  11523. };
  11524. area.y0 = function(_) {
  11525. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), area) : y0;
  11526. };
  11527. area.y1 = function(_) {
  11528. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : y1;
  11529. };
  11530. area.lineX0 =
  11531. area.lineY0 = function() {
  11532. return arealine().x(x0).y(y0);
  11533. };
  11534. area.lineY1 = function() {
  11535. return arealine().x(x0).y(y1);
  11536. };
  11537. area.lineX1 = function() {
  11538. return arealine().x(x1).y(y0);
  11539. };
  11540. area.defined = function(_) {
  11541. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), area) : defined;
  11542. };
  11543. area.curve = function(_) {
  11544. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  11545. };
  11546. area.context = function(_) {
  11547. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  11548. };
  11549. return area;
  11550. };
  11551. var descending$1 = function(a, b) {
  11552. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  11553. };
  11554. var identity$7 = function(d) {
  11555. return d;
  11556. };
  11557. var pie = function() {
  11558. var value = identity$7,
  11559. sortValues = descending$1,
  11560. sort = null,
  11561. startAngle = constant$10(0),
  11562. endAngle = constant$10(tau$4),
  11563. padAngle = constant$10(0);
  11564. function pie(data) {
  11565. var i,
  11566. n = data.length,
  11567. j,
  11568. k,
  11569. sum = 0,
  11570. index = new Array(n),
  11571. arcs = new Array(n),
  11572. a0 = +startAngle.apply(this, arguments),
  11573. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  11574. a1,
  11575. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  11576. pa = p * (da < 0 ? -1 : 1),
  11577. v;
  11578. for (i = 0; i < n; ++i) {
  11579. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  11580. sum += v;
  11581. }
  11582. }
  11583. // Optionally sort the arcs by previously-computed values or by data.
  11584. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  11585. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  11586. // Compute the arcs! They are stored in the original data's order.
  11587. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  11588. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  11589. data: data[j],
  11590. index: i,
  11591. value: v,
  11592. startAngle: a0,
  11593. endAngle: a1,
  11594. padAngle: p
  11595. };
  11596. }
  11597. return arcs;
  11598. }
  11599. pie.value = function(_) {
  11600. return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), pie) : value;
  11601. };
  11602. pie.sortValues = function(_) {
  11603. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  11604. };
  11605. pie.sort = function(_) {
  11606. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  11607. };
  11608. pie.startAngle = function(_) {
  11609. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : startAngle;
  11610. };
  11611. pie.endAngle = function(_) {
  11612. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : endAngle;
  11613. };
  11614. pie.padAngle = function(_) {
  11615. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : padAngle;
  11616. };
  11617. return pie;
  11618. };
  11619. var curveRadialLinear = curveRadial(curveLinear);
  11620. function Radial(curve) {
  11621. this._curve = curve;
  11622. }
  11623. Radial.prototype = {
  11624. areaStart: function() {
  11625. this._curve.areaStart();
  11626. },
  11627. areaEnd: function() {
  11628. this._curve.areaEnd();
  11629. },
  11630. lineStart: function() {
  11631. this._curve.lineStart();
  11632. },
  11633. lineEnd: function() {
  11634. this._curve.lineEnd();
  11635. },
  11636. point: function(a, r) {
  11637. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  11638. }
  11639. };
  11640. function curveRadial(curve) {
  11641. function radial(context) {
  11642. return new Radial(curve(context));
  11643. }
  11644. radial._curve = curve;
  11645. return radial;
  11646. }
  11647. function lineRadial(l) {
  11648. var c = l.curve;
  11649. l.angle = l.x, delete l.x;
  11650. l.radius = l.y, delete l.y;
  11651. l.curve = function(_) {
  11652. return arguments.length ? c(curveRadial(_)) : c()._curve;
  11653. };
  11654. return l;
  11655. }
  11656. var lineRadial$1 = function() {
  11657. return lineRadial(line().curve(curveRadialLinear));
  11658. };
  11659. var areaRadial = function() {
  11660. var a = area$2().curve(curveRadialLinear),
  11661. c = a.curve,
  11662. x0 = a.lineX0,
  11663. x1 = a.lineX1,
  11664. y0 = a.lineY0,
  11665. y1 = a.lineY1;
  11666. a.angle = a.x, delete a.x;
  11667. a.startAngle = a.x0, delete a.x0;
  11668. a.endAngle = a.x1, delete a.x1;
  11669. a.radius = a.y, delete a.y;
  11670. a.innerRadius = a.y0, delete a.y0;
  11671. a.outerRadius = a.y1, delete a.y1;
  11672. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  11673. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  11674. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  11675. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  11676. a.curve = function(_) {
  11677. return arguments.length ? c(curveRadial(_)) : c()._curve;
  11678. };
  11679. return a;
  11680. };
  11681. var pointRadial = function(x, y) {
  11682. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  11683. };
  11684. var slice$6 = Array.prototype.slice;
  11685. function linkSource(d) {
  11686. return d.source;
  11687. }
  11688. function linkTarget(d) {
  11689. return d.target;
  11690. }
  11691. function link$2(curve) {
  11692. var source = linkSource,
  11693. target = linkTarget,
  11694. x$$1 = x$4,
  11695. y$$1 = y$3,
  11696. context = null;
  11697. function link() {
  11698. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  11699. if (!context) context = buffer = path();
  11700. curve(context, +x$$1.apply(this, (argv[0] = s, argv)), +y$$1.apply(this, argv), +x$$1.apply(this, (argv[0] = t, argv)), +y$$1.apply(this, argv));
  11701. if (buffer) return context = null, buffer + "" || null;
  11702. }
  11703. link.source = function(_) {
  11704. return arguments.length ? (source = _, link) : source;
  11705. };
  11706. link.target = function(_) {
  11707. return arguments.length ? (target = _, link) : target;
  11708. };
  11709. link.x = function(_) {
  11710. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : x$$1;
  11711. };
  11712. link.y = function(_) {
  11713. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : y$$1;
  11714. };
  11715. link.context = function(_) {
  11716. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  11717. };
  11718. return link;
  11719. }
  11720. function curveHorizontal(context, x0, y0, x1, y1) {
  11721. context.moveTo(x0, y0);
  11722. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  11723. }
  11724. function curveVertical(context, x0, y0, x1, y1) {
  11725. context.moveTo(x0, y0);
  11726. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  11727. }
  11728. function curveRadial$1(context, x0, y0, x1, y1) {
  11729. var p0 = pointRadial(x0, y0),
  11730. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  11731. p2 = pointRadial(x1, y0),
  11732. p3 = pointRadial(x1, y1);
  11733. context.moveTo(p0[0], p0[1]);
  11734. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  11735. }
  11736. function linkHorizontal() {
  11737. return link$2(curveHorizontal);
  11738. }
  11739. function linkVertical() {
  11740. return link$2(curveVertical);
  11741. }
  11742. function linkRadial() {
  11743. var l = link$2(curveRadial$1);
  11744. l.angle = l.x, delete l.x;
  11745. l.radius = l.y, delete l.y;
  11746. return l;
  11747. }
  11748. var circle$2 = {
  11749. draw: function(context, size) {
  11750. var r = Math.sqrt(size / pi$4);
  11751. context.moveTo(r, 0);
  11752. context.arc(0, 0, r, 0, tau$4);
  11753. }
  11754. };
  11755. var cross$2 = {
  11756. draw: function(context, size) {
  11757. var r = Math.sqrt(size / 5) / 2;
  11758. context.moveTo(-3 * r, -r);
  11759. context.lineTo(-r, -r);
  11760. context.lineTo(-r, -3 * r);
  11761. context.lineTo(r, -3 * r);
  11762. context.lineTo(r, -r);
  11763. context.lineTo(3 * r, -r);
  11764. context.lineTo(3 * r, r);
  11765. context.lineTo(r, r);
  11766. context.lineTo(r, 3 * r);
  11767. context.lineTo(-r, 3 * r);
  11768. context.lineTo(-r, r);
  11769. context.lineTo(-3 * r, r);
  11770. context.closePath();
  11771. }
  11772. };
  11773. var tan30 = Math.sqrt(1 / 3);
  11774. var tan30_2 = tan30 * 2;
  11775. var diamond = {
  11776. draw: function(context, size) {
  11777. var y = Math.sqrt(size / tan30_2),
  11778. x = y * tan30;
  11779. context.moveTo(0, -y);
  11780. context.lineTo(x, 0);
  11781. context.lineTo(0, y);
  11782. context.lineTo(-x, 0);
  11783. context.closePath();
  11784. }
  11785. };
  11786. var ka = 0.89081309152928522810;
  11787. var kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10);
  11788. var kx = Math.sin(tau$4 / 10) * kr;
  11789. var ky = -Math.cos(tau$4 / 10) * kr;
  11790. var star = {
  11791. draw: function(context, size) {
  11792. var r = Math.sqrt(size * ka),
  11793. x = kx * r,
  11794. y = ky * r;
  11795. context.moveTo(0, -r);
  11796. context.lineTo(x, y);
  11797. for (var i = 1; i < 5; ++i) {
  11798. var a = tau$4 * i / 5,
  11799. c = Math.cos(a),
  11800. s = Math.sin(a);
  11801. context.lineTo(s * r, -c * r);
  11802. context.lineTo(c * x - s * y, s * x + c * y);
  11803. }
  11804. context.closePath();
  11805. }
  11806. };
  11807. var square = {
  11808. draw: function(context, size) {
  11809. var w = Math.sqrt(size),
  11810. x = -w / 2;
  11811. context.rect(x, x, w, w);
  11812. }
  11813. };
  11814. var sqrt3 = Math.sqrt(3);
  11815. var triangle = {
  11816. draw: function(context, size) {
  11817. var y = -Math.sqrt(size / (sqrt3 * 3));
  11818. context.moveTo(0, y * 2);
  11819. context.lineTo(-sqrt3 * y, -y);
  11820. context.lineTo(sqrt3 * y, -y);
  11821. context.closePath();
  11822. }
  11823. };
  11824. var c = -0.5;
  11825. var s = Math.sqrt(3) / 2;
  11826. var k = 1 / Math.sqrt(12);
  11827. var a = (k / 2 + 1) * 3;
  11828. var wye = {
  11829. draw: function(context, size) {
  11830. var r = Math.sqrt(size / a),
  11831. x0 = r / 2,
  11832. y0 = r * k,
  11833. x1 = x0,
  11834. y1 = r * k + r,
  11835. x2 = -x1,
  11836. y2 = y1;
  11837. context.moveTo(x0, y0);
  11838. context.lineTo(x1, y1);
  11839. context.lineTo(x2, y2);
  11840. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  11841. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  11842. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  11843. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  11844. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  11845. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  11846. context.closePath();
  11847. }
  11848. };
  11849. var symbols = [
  11850. circle$2,
  11851. cross$2,
  11852. diamond,
  11853. square,
  11854. star,
  11855. triangle,
  11856. wye
  11857. ];
  11858. var symbol = function() {
  11859. var type = constant$10(circle$2),
  11860. size = constant$10(64),
  11861. context = null;
  11862. function symbol() {
  11863. var buffer;
  11864. if (!context) context = buffer = path();
  11865. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  11866. if (buffer) return context = null, buffer + "" || null;
  11867. }
  11868. symbol.type = function(_) {
  11869. return arguments.length ? (type = typeof _ === "function" ? _ : constant$10(_), symbol) : type;
  11870. };
  11871. symbol.size = function(_) {
  11872. return arguments.length ? (size = typeof _ === "function" ? _ : constant$10(+_), symbol) : size;
  11873. };
  11874. symbol.context = function(_) {
  11875. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  11876. };
  11877. return symbol;
  11878. };
  11879. var noop$2 = function() {};
  11880. function point$2(that, x, y) {
  11881. that._context.bezierCurveTo(
  11882. (2 * that._x0 + that._x1) / 3,
  11883. (2 * that._y0 + that._y1) / 3,
  11884. (that._x0 + 2 * that._x1) / 3,
  11885. (that._y0 + 2 * that._y1) / 3,
  11886. (that._x0 + 4 * that._x1 + x) / 6,
  11887. (that._y0 + 4 * that._y1 + y) / 6
  11888. );
  11889. }
  11890. function Basis(context) {
  11891. this._context = context;
  11892. }
  11893. Basis.prototype = {
  11894. areaStart: function() {
  11895. this._line = 0;
  11896. },
  11897. areaEnd: function() {
  11898. this._line = NaN;
  11899. },
  11900. lineStart: function() {
  11901. this._x0 = this._x1 =
  11902. this._y0 = this._y1 = NaN;
  11903. this._point = 0;
  11904. },
  11905. lineEnd: function() {
  11906. switch (this._point) {
  11907. case 3: point$2(this, this._x1, this._y1); // proceed
  11908. case 2: this._context.lineTo(this._x1, this._y1); break;
  11909. }
  11910. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  11911. this._line = 1 - this._line;
  11912. },
  11913. point: function(x, y) {
  11914. x = +x, y = +y;
  11915. switch (this._point) {
  11916. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  11917. case 1: this._point = 2; break;
  11918. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  11919. default: point$2(this, x, y); break;
  11920. }
  11921. this._x0 = this._x1, this._x1 = x;
  11922. this._y0 = this._y1, this._y1 = y;
  11923. }
  11924. };
  11925. var basis$2 = function(context) {
  11926. return new Basis(context);
  11927. };
  11928. function BasisClosed(context) {
  11929. this._context = context;
  11930. }
  11931. BasisClosed.prototype = {
  11932. areaStart: noop$2,
  11933. areaEnd: noop$2,
  11934. lineStart: function() {
  11935. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  11936. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  11937. this._point = 0;
  11938. },
  11939. lineEnd: function() {
  11940. switch (this._point) {
  11941. case 1: {
  11942. this._context.moveTo(this._x2, this._y2);
  11943. this._context.closePath();
  11944. break;
  11945. }
  11946. case 2: {
  11947. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  11948. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  11949. this._context.closePath();
  11950. break;
  11951. }
  11952. case 3: {
  11953. this.point(this._x2, this._y2);
  11954. this.point(this._x3, this._y3);
  11955. this.point(this._x4, this._y4);
  11956. break;
  11957. }
  11958. }
  11959. },
  11960. point: function(x, y) {
  11961. x = +x, y = +y;
  11962. switch (this._point) {
  11963. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  11964. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  11965. case 2: this._point = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
  11966. default: point$2(this, x, y); break;
  11967. }
  11968. this._x0 = this._x1, this._x1 = x;
  11969. this._y0 = this._y1, this._y1 = y;
  11970. }
  11971. };
  11972. var basisClosed$1 = function(context) {
  11973. return new BasisClosed(context);
  11974. };
  11975. function BasisOpen(context) {
  11976. this._context = context;
  11977. }
  11978. BasisOpen.prototype = {
  11979. areaStart: function() {
  11980. this._line = 0;
  11981. },
  11982. areaEnd: function() {
  11983. this._line = NaN;
  11984. },
  11985. lineStart: function() {
  11986. this._x0 = this._x1 =
  11987. this._y0 = this._y1 = NaN;
  11988. this._point = 0;
  11989. },
  11990. lineEnd: function() {
  11991. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  11992. this._line = 1 - this._line;
  11993. },
  11994. point: function(x, y) {
  11995. x = +x, y = +y;
  11996. switch (this._point) {
  11997. case 0: this._point = 1; break;
  11998. case 1: this._point = 2; break;
  11999. case 2: this._point = 3; var x0 = (this._x0 + 4 * this._x1 + x) / 6, y0 = (this._y0 + 4 * this._y1 + y) / 6; this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0); break;
  12000. case 3: this._point = 4; // proceed
  12001. default: point$2(this, x, y); break;
  12002. }
  12003. this._x0 = this._x1, this._x1 = x;
  12004. this._y0 = this._y1, this._y1 = y;
  12005. }
  12006. };
  12007. var basisOpen = function(context) {
  12008. return new BasisOpen(context);
  12009. };
  12010. function Bundle(context, beta) {
  12011. this._basis = new Basis(context);
  12012. this._beta = beta;
  12013. }
  12014. Bundle.prototype = {
  12015. lineStart: function() {
  12016. this._x = [];
  12017. this._y = [];
  12018. this._basis.lineStart();
  12019. },
  12020. lineEnd: function() {
  12021. var x = this._x,
  12022. y = this._y,
  12023. j = x.length - 1;
  12024. if (j > 0) {
  12025. var x0 = x[0],
  12026. y0 = y[0],
  12027. dx = x[j] - x0,
  12028. dy = y[j] - y0,
  12029. i = -1,
  12030. t;
  12031. while (++i <= j) {
  12032. t = i / j;
  12033. this._basis.point(
  12034. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  12035. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  12036. );
  12037. }
  12038. }
  12039. this._x = this._y = null;
  12040. this._basis.lineEnd();
  12041. },
  12042. point: function(x, y) {
  12043. this._x.push(+x);
  12044. this._y.push(+y);
  12045. }
  12046. };
  12047. var bundle = (function custom(beta) {
  12048. function bundle(context) {
  12049. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  12050. }
  12051. bundle.beta = function(beta) {
  12052. return custom(+beta);
  12053. };
  12054. return bundle;
  12055. })(0.85);
  12056. function point$3(that, x, y) {
  12057. that._context.bezierCurveTo(
  12058. that._x1 + that._k * (that._x2 - that._x0),
  12059. that._y1 + that._k * (that._y2 - that._y0),
  12060. that._x2 + that._k * (that._x1 - x),
  12061. that._y2 + that._k * (that._y1 - y),
  12062. that._x2,
  12063. that._y2
  12064. );
  12065. }
  12066. function Cardinal(context, tension) {
  12067. this._context = context;
  12068. this._k = (1 - tension) / 6;
  12069. }
  12070. Cardinal.prototype = {
  12071. areaStart: function() {
  12072. this._line = 0;
  12073. },
  12074. areaEnd: function() {
  12075. this._line = NaN;
  12076. },
  12077. lineStart: function() {
  12078. this._x0 = this._x1 = this._x2 =
  12079. this._y0 = this._y1 = this._y2 = NaN;
  12080. this._point = 0;
  12081. },
  12082. lineEnd: function() {
  12083. switch (this._point) {
  12084. case 2: this._context.lineTo(this._x2, this._y2); break;
  12085. case 3: point$3(this, this._x1, this._y1); break;
  12086. }
  12087. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12088. this._line = 1 - this._line;
  12089. },
  12090. point: function(x, y) {
  12091. x = +x, y = +y;
  12092. switch (this._point) {
  12093. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12094. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  12095. case 2: this._point = 3; // proceed
  12096. default: point$3(this, x, y); break;
  12097. }
  12098. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12099. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12100. }
  12101. };
  12102. var cardinal = (function custom(tension) {
  12103. function cardinal(context) {
  12104. return new Cardinal(context, tension);
  12105. }
  12106. cardinal.tension = function(tension) {
  12107. return custom(+tension);
  12108. };
  12109. return cardinal;
  12110. })(0);
  12111. function CardinalClosed(context, tension) {
  12112. this._context = context;
  12113. this._k = (1 - tension) / 6;
  12114. }
  12115. CardinalClosed.prototype = {
  12116. areaStart: noop$2,
  12117. areaEnd: noop$2,
  12118. lineStart: function() {
  12119. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12120. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12121. this._point = 0;
  12122. },
  12123. lineEnd: function() {
  12124. switch (this._point) {
  12125. case 1: {
  12126. this._context.moveTo(this._x3, this._y3);
  12127. this._context.closePath();
  12128. break;
  12129. }
  12130. case 2: {
  12131. this._context.lineTo(this._x3, this._y3);
  12132. this._context.closePath();
  12133. break;
  12134. }
  12135. case 3: {
  12136. this.point(this._x3, this._y3);
  12137. this.point(this._x4, this._y4);
  12138. this.point(this._x5, this._y5);
  12139. break;
  12140. }
  12141. }
  12142. },
  12143. point: function(x, y) {
  12144. x = +x, y = +y;
  12145. switch (this._point) {
  12146. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12147. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12148. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12149. default: point$3(this, x, y); break;
  12150. }
  12151. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12152. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12153. }
  12154. };
  12155. var cardinalClosed = (function custom(tension) {
  12156. function cardinal$$1(context) {
  12157. return new CardinalClosed(context, tension);
  12158. }
  12159. cardinal$$1.tension = function(tension) {
  12160. return custom(+tension);
  12161. };
  12162. return cardinal$$1;
  12163. })(0);
  12164. function CardinalOpen(context, tension) {
  12165. this._context = context;
  12166. this._k = (1 - tension) / 6;
  12167. }
  12168. CardinalOpen.prototype = {
  12169. areaStart: function() {
  12170. this._line = 0;
  12171. },
  12172. areaEnd: function() {
  12173. this._line = NaN;
  12174. },
  12175. lineStart: function() {
  12176. this._x0 = this._x1 = this._x2 =
  12177. this._y0 = this._y1 = this._y2 = NaN;
  12178. this._point = 0;
  12179. },
  12180. lineEnd: function() {
  12181. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12182. this._line = 1 - this._line;
  12183. },
  12184. point: function(x, y) {
  12185. x = +x, y = +y;
  12186. switch (this._point) {
  12187. case 0: this._point = 1; break;
  12188. case 1: this._point = 2; break;
  12189. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12190. case 3: this._point = 4; // proceed
  12191. default: point$3(this, x, y); break;
  12192. }
  12193. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12194. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12195. }
  12196. };
  12197. var cardinalOpen = (function custom(tension) {
  12198. function cardinal$$1(context) {
  12199. return new CardinalOpen(context, tension);
  12200. }
  12201. cardinal$$1.tension = function(tension) {
  12202. return custom(+tension);
  12203. };
  12204. return cardinal$$1;
  12205. })(0);
  12206. function point$4(that, x, y) {
  12207. var x1 = that._x1,
  12208. y1 = that._y1,
  12209. x2 = that._x2,
  12210. y2 = that._y2;
  12211. if (that._l01_a > epsilon$3) {
  12212. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  12213. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  12214. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  12215. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  12216. }
  12217. if (that._l23_a > epsilon$3) {
  12218. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  12219. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  12220. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  12221. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  12222. }
  12223. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  12224. }
  12225. function CatmullRom(context, alpha) {
  12226. this._context = context;
  12227. this._alpha = alpha;
  12228. }
  12229. CatmullRom.prototype = {
  12230. areaStart: function() {
  12231. this._line = 0;
  12232. },
  12233. areaEnd: function() {
  12234. this._line = NaN;
  12235. },
  12236. lineStart: function() {
  12237. this._x0 = this._x1 = this._x2 =
  12238. this._y0 = this._y1 = this._y2 = NaN;
  12239. this._l01_a = this._l12_a = this._l23_a =
  12240. this._l01_2a = this._l12_2a = this._l23_2a =
  12241. this._point = 0;
  12242. },
  12243. lineEnd: function() {
  12244. switch (this._point) {
  12245. case 2: this._context.lineTo(this._x2, this._y2); break;
  12246. case 3: this.point(this._x2, this._y2); break;
  12247. }
  12248. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12249. this._line = 1 - this._line;
  12250. },
  12251. point: function(x, y) {
  12252. x = +x, y = +y;
  12253. if (this._point) {
  12254. var x23 = this._x2 - x,
  12255. y23 = this._y2 - y;
  12256. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12257. }
  12258. switch (this._point) {
  12259. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12260. case 1: this._point = 2; break;
  12261. case 2: this._point = 3; // proceed
  12262. default: point$4(this, x, y); break;
  12263. }
  12264. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12265. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12266. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12267. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12268. }
  12269. };
  12270. var catmullRom = (function custom(alpha) {
  12271. function catmullRom(context) {
  12272. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  12273. }
  12274. catmullRom.alpha = function(alpha) {
  12275. return custom(+alpha);
  12276. };
  12277. return catmullRom;
  12278. })(0.5);
  12279. function CatmullRomClosed(context, alpha) {
  12280. this._context = context;
  12281. this._alpha = alpha;
  12282. }
  12283. CatmullRomClosed.prototype = {
  12284. areaStart: noop$2,
  12285. areaEnd: noop$2,
  12286. lineStart: function() {
  12287. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12288. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12289. this._l01_a = this._l12_a = this._l23_a =
  12290. this._l01_2a = this._l12_2a = this._l23_2a =
  12291. this._point = 0;
  12292. },
  12293. lineEnd: function() {
  12294. switch (this._point) {
  12295. case 1: {
  12296. this._context.moveTo(this._x3, this._y3);
  12297. this._context.closePath();
  12298. break;
  12299. }
  12300. case 2: {
  12301. this._context.lineTo(this._x3, this._y3);
  12302. this._context.closePath();
  12303. break;
  12304. }
  12305. case 3: {
  12306. this.point(this._x3, this._y3);
  12307. this.point(this._x4, this._y4);
  12308. this.point(this._x5, this._y5);
  12309. break;
  12310. }
  12311. }
  12312. },
  12313. point: function(x, y) {
  12314. x = +x, y = +y;
  12315. if (this._point) {
  12316. var x23 = this._x2 - x,
  12317. y23 = this._y2 - y;
  12318. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12319. }
  12320. switch (this._point) {
  12321. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12322. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12323. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12324. default: point$4(this, x, y); break;
  12325. }
  12326. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12327. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12328. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12329. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12330. }
  12331. };
  12332. var catmullRomClosed = (function custom(alpha) {
  12333. function catmullRom$$1(context) {
  12334. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  12335. }
  12336. catmullRom$$1.alpha = function(alpha) {
  12337. return custom(+alpha);
  12338. };
  12339. return catmullRom$$1;
  12340. })(0.5);
  12341. function CatmullRomOpen(context, alpha) {
  12342. this._context = context;
  12343. this._alpha = alpha;
  12344. }
  12345. CatmullRomOpen.prototype = {
  12346. areaStart: function() {
  12347. this._line = 0;
  12348. },
  12349. areaEnd: function() {
  12350. this._line = NaN;
  12351. },
  12352. lineStart: function() {
  12353. this._x0 = this._x1 = this._x2 =
  12354. this._y0 = this._y1 = this._y2 = NaN;
  12355. this._l01_a = this._l12_a = this._l23_a =
  12356. this._l01_2a = this._l12_2a = this._l23_2a =
  12357. this._point = 0;
  12358. },
  12359. lineEnd: function() {
  12360. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12361. this._line = 1 - this._line;
  12362. },
  12363. point: function(x, y) {
  12364. x = +x, y = +y;
  12365. if (this._point) {
  12366. var x23 = this._x2 - x,
  12367. y23 = this._y2 - y;
  12368. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12369. }
  12370. switch (this._point) {
  12371. case 0: this._point = 1; break;
  12372. case 1: this._point = 2; break;
  12373. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12374. case 3: this._point = 4; // proceed
  12375. default: point$4(this, x, y); break;
  12376. }
  12377. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12378. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12379. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12380. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12381. }
  12382. };
  12383. var catmullRomOpen = (function custom(alpha) {
  12384. function catmullRom$$1(context) {
  12385. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  12386. }
  12387. catmullRom$$1.alpha = function(alpha) {
  12388. return custom(+alpha);
  12389. };
  12390. return catmullRom$$1;
  12391. })(0.5);
  12392. function LinearClosed(context) {
  12393. this._context = context;
  12394. }
  12395. LinearClosed.prototype = {
  12396. areaStart: noop$2,
  12397. areaEnd: noop$2,
  12398. lineStart: function() {
  12399. this._point = 0;
  12400. },
  12401. lineEnd: function() {
  12402. if (this._point) this._context.closePath();
  12403. },
  12404. point: function(x, y) {
  12405. x = +x, y = +y;
  12406. if (this._point) this._context.lineTo(x, y);
  12407. else this._point = 1, this._context.moveTo(x, y);
  12408. }
  12409. };
  12410. var linearClosed = function(context) {
  12411. return new LinearClosed(context);
  12412. };
  12413. function sign$1(x) {
  12414. return x < 0 ? -1 : 1;
  12415. }
  12416. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  12417. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  12418. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  12419. // NOV(II), P. 443, 1990.
  12420. function slope3(that, x2, y2) {
  12421. var h0 = that._x1 - that._x0,
  12422. h1 = x2 - that._x1,
  12423. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  12424. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  12425. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  12426. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  12427. }
  12428. // Calculate a one-sided slope.
  12429. function slope2(that, t) {
  12430. var h = that._x1 - that._x0;
  12431. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  12432. }
  12433. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  12434. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  12435. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  12436. function point$5(that, t0, t1) {
  12437. var x0 = that._x0,
  12438. y0 = that._y0,
  12439. x1 = that._x1,
  12440. y1 = that._y1,
  12441. dx = (x1 - x0) / 3;
  12442. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  12443. }
  12444. function MonotoneX(context) {
  12445. this._context = context;
  12446. }
  12447. MonotoneX.prototype = {
  12448. areaStart: function() {
  12449. this._line = 0;
  12450. },
  12451. areaEnd: function() {
  12452. this._line = NaN;
  12453. },
  12454. lineStart: function() {
  12455. this._x0 = this._x1 =
  12456. this._y0 = this._y1 =
  12457. this._t0 = NaN;
  12458. this._point = 0;
  12459. },
  12460. lineEnd: function() {
  12461. switch (this._point) {
  12462. case 2: this._context.lineTo(this._x1, this._y1); break;
  12463. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  12464. }
  12465. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12466. this._line = 1 - this._line;
  12467. },
  12468. point: function(x, y) {
  12469. var t1 = NaN;
  12470. x = +x, y = +y;
  12471. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  12472. switch (this._point) {
  12473. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12474. case 1: this._point = 2; break;
  12475. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  12476. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  12477. }
  12478. this._x0 = this._x1, this._x1 = x;
  12479. this._y0 = this._y1, this._y1 = y;
  12480. this._t0 = t1;
  12481. }
  12482. };
  12483. function MonotoneY(context) {
  12484. this._context = new ReflectContext(context);
  12485. }
  12486. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  12487. MonotoneX.prototype.point.call(this, y, x);
  12488. };
  12489. function ReflectContext(context) {
  12490. this._context = context;
  12491. }
  12492. ReflectContext.prototype = {
  12493. moveTo: function(x, y) { this._context.moveTo(y, x); },
  12494. closePath: function() { this._context.closePath(); },
  12495. lineTo: function(x, y) { this._context.lineTo(y, x); },
  12496. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  12497. };
  12498. function monotoneX(context) {
  12499. return new MonotoneX(context);
  12500. }
  12501. function monotoneY(context) {
  12502. return new MonotoneY(context);
  12503. }
  12504. function Natural(context) {
  12505. this._context = context;
  12506. }
  12507. Natural.prototype = {
  12508. areaStart: function() {
  12509. this._line = 0;
  12510. },
  12511. areaEnd: function() {
  12512. this._line = NaN;
  12513. },
  12514. lineStart: function() {
  12515. this._x = [];
  12516. this._y = [];
  12517. },
  12518. lineEnd: function() {
  12519. var x = this._x,
  12520. y = this._y,
  12521. n = x.length;
  12522. if (n) {
  12523. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  12524. if (n === 2) {
  12525. this._context.lineTo(x[1], y[1]);
  12526. } else {
  12527. var px = controlPoints(x),
  12528. py = controlPoints(y);
  12529. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  12530. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  12531. }
  12532. }
  12533. }
  12534. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  12535. this._line = 1 - this._line;
  12536. this._x = this._y = null;
  12537. },
  12538. point: function(x, y) {
  12539. this._x.push(+x);
  12540. this._y.push(+y);
  12541. }
  12542. };
  12543. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  12544. function controlPoints(x) {
  12545. var i,
  12546. n = x.length - 1,
  12547. m,
  12548. a = new Array(n),
  12549. b = new Array(n),
  12550. r = new Array(n);
  12551. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  12552. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  12553. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  12554. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  12555. a[n - 1] = r[n - 1] / b[n - 1];
  12556. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  12557. b[n - 1] = (x[n] + a[n - 1]) / 2;
  12558. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  12559. return [a, b];
  12560. }
  12561. var natural = function(context) {
  12562. return new Natural(context);
  12563. };
  12564. function Step(context, t) {
  12565. this._context = context;
  12566. this._t = t;
  12567. }
  12568. Step.prototype = {
  12569. areaStart: function() {
  12570. this._line = 0;
  12571. },
  12572. areaEnd: function() {
  12573. this._line = NaN;
  12574. },
  12575. lineStart: function() {
  12576. this._x = this._y = NaN;
  12577. this._point = 0;
  12578. },
  12579. lineEnd: function() {
  12580. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  12581. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12582. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  12583. },
  12584. point: function(x, y) {
  12585. x = +x, y = +y;
  12586. switch (this._point) {
  12587. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12588. case 1: this._point = 2; // proceed
  12589. default: {
  12590. if (this._t <= 0) {
  12591. this._context.lineTo(this._x, y);
  12592. this._context.lineTo(x, y);
  12593. } else {
  12594. var x1 = this._x * (1 - this._t) + x * this._t;
  12595. this._context.lineTo(x1, this._y);
  12596. this._context.lineTo(x1, y);
  12597. }
  12598. break;
  12599. }
  12600. }
  12601. this._x = x, this._y = y;
  12602. }
  12603. };
  12604. var step = function(context) {
  12605. return new Step(context, 0.5);
  12606. };
  12607. function stepBefore(context) {
  12608. return new Step(context, 0);
  12609. }
  12610. function stepAfter(context) {
  12611. return new Step(context, 1);
  12612. }
  12613. var none$1 = function(series, order) {
  12614. if (!((n = series.length) > 1)) return;
  12615. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  12616. s0 = s1, s1 = series[order[i]];
  12617. for (j = 0; j < m; ++j) {
  12618. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  12619. }
  12620. }
  12621. };
  12622. var none$2 = function(series) {
  12623. var n = series.length, o = new Array(n);
  12624. while (--n >= 0) o[n] = n;
  12625. return o;
  12626. };
  12627. function stackValue(d, key) {
  12628. return d[key];
  12629. }
  12630. var stack = function() {
  12631. var keys = constant$10([]),
  12632. order = none$2,
  12633. offset = none$1,
  12634. value = stackValue;
  12635. function stack(data) {
  12636. var kz = keys.apply(this, arguments),
  12637. i,
  12638. m = data.length,
  12639. n = kz.length,
  12640. sz = new Array(n),
  12641. oz;
  12642. for (i = 0; i < n; ++i) {
  12643. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  12644. si[j] = sij = [0, +value(data[j], ki, j, data)];
  12645. sij.data = data[j];
  12646. }
  12647. si.key = ki;
  12648. }
  12649. for (i = 0, oz = order(sz); i < n; ++i) {
  12650. sz[oz[i]].index = i;
  12651. }
  12652. offset(sz, oz);
  12653. return sz;
  12654. }
  12655. stack.keys = function(_) {
  12656. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : keys;
  12657. };
  12658. stack.value = function(_) {
  12659. return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), stack) : value;
  12660. };
  12661. stack.order = function(_) {
  12662. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : order;
  12663. };
  12664. stack.offset = function(_) {
  12665. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  12666. };
  12667. return stack;
  12668. };
  12669. var expand = function(series, order) {
  12670. if (!((n = series.length) > 0)) return;
  12671. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  12672. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  12673. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  12674. }
  12675. none$1(series, order);
  12676. };
  12677. var diverging = function(series, order) {
  12678. if (!((n = series.length) > 1)) return;
  12679. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  12680. for (yp = yn = 0, i = 0; i < n; ++i) {
  12681. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  12682. d[0] = yp, d[1] = yp += dy;
  12683. } else if (dy < 0) {
  12684. d[1] = yn, d[0] = yn += dy;
  12685. } else {
  12686. d[0] = yp;
  12687. }
  12688. }
  12689. }
  12690. };
  12691. var silhouette = function(series, order) {
  12692. if (!((n = series.length) > 0)) return;
  12693. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  12694. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  12695. s0[j][1] += s0[j][0] = -y / 2;
  12696. }
  12697. none$1(series, order);
  12698. };
  12699. var wiggle = function(series, order) {
  12700. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  12701. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  12702. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  12703. var si = series[order[i]],
  12704. sij0 = si[j][1] || 0,
  12705. sij1 = si[j - 1][1] || 0,
  12706. s3 = (sij0 - sij1) / 2;
  12707. for (var k = 0; k < i; ++k) {
  12708. var sk = series[order[k]],
  12709. skj0 = sk[j][1] || 0,
  12710. skj1 = sk[j - 1][1] || 0;
  12711. s3 += skj0 - skj1;
  12712. }
  12713. s1 += sij0, s2 += s3 * sij0;
  12714. }
  12715. s0[j - 1][1] += s0[j - 1][0] = y;
  12716. if (s1) y -= s2 / s1;
  12717. }
  12718. s0[j - 1][1] += s0[j - 1][0] = y;
  12719. none$1(series, order);
  12720. };
  12721. var ascending$2 = function(series) {
  12722. var sums = series.map(sum$2);
  12723. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  12724. };
  12725. function sum$2(series) {
  12726. var s = 0, i = -1, n = series.length, v;
  12727. while (++i < n) if (v = +series[i][1]) s += v;
  12728. return s;
  12729. }
  12730. var descending$2 = function(series) {
  12731. return ascending$2(series).reverse();
  12732. };
  12733. var insideOut = function(series) {
  12734. var n = series.length,
  12735. i,
  12736. j,
  12737. sums = series.map(sum$2),
  12738. order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  12739. top = 0,
  12740. bottom = 0,
  12741. tops = [],
  12742. bottoms = [];
  12743. for (i = 0; i < n; ++i) {
  12744. j = order[i];
  12745. if (top < bottom) {
  12746. top += sums[j];
  12747. tops.push(j);
  12748. } else {
  12749. bottom += sums[j];
  12750. bottoms.push(j);
  12751. }
  12752. }
  12753. return bottoms.reverse().concat(tops);
  12754. };
  12755. var reverse = function(series) {
  12756. return none$2(series).reverse();
  12757. };
  12758. var constant$11 = function(x) {
  12759. return function() {
  12760. return x;
  12761. };
  12762. };
  12763. function x$5(d) {
  12764. return d[0];
  12765. }
  12766. function y$4(d) {
  12767. return d[1];
  12768. }
  12769. function RedBlackTree() {
  12770. this._ = null; // root node
  12771. }
  12772. function RedBlackNode(node) {
  12773. node.U = // parent node
  12774. node.C = // color - true for red, false for black
  12775. node.L = // left node
  12776. node.R = // right node
  12777. node.P = // previous node
  12778. node.N = null; // next node
  12779. }
  12780. RedBlackTree.prototype = {
  12781. constructor: RedBlackTree,
  12782. insert: function(after, node) {
  12783. var parent, grandpa, uncle;
  12784. if (after) {
  12785. node.P = after;
  12786. node.N = after.N;
  12787. if (after.N) after.N.P = node;
  12788. after.N = node;
  12789. if (after.R) {
  12790. after = after.R;
  12791. while (after.L) after = after.L;
  12792. after.L = node;
  12793. } else {
  12794. after.R = node;
  12795. }
  12796. parent = after;
  12797. } else if (this._) {
  12798. after = RedBlackFirst(this._);
  12799. node.P = null;
  12800. node.N = after;
  12801. after.P = after.L = node;
  12802. parent = after;
  12803. } else {
  12804. node.P = node.N = null;
  12805. this._ = node;
  12806. parent = null;
  12807. }
  12808. node.L = node.R = null;
  12809. node.U = parent;
  12810. node.C = true;
  12811. after = node;
  12812. while (parent && parent.C) {
  12813. grandpa = parent.U;
  12814. if (parent === grandpa.L) {
  12815. uncle = grandpa.R;
  12816. if (uncle && uncle.C) {
  12817. parent.C = uncle.C = false;
  12818. grandpa.C = true;
  12819. after = grandpa;
  12820. } else {
  12821. if (after === parent.R) {
  12822. RedBlackRotateLeft(this, parent);
  12823. after = parent;
  12824. parent = after.U;
  12825. }
  12826. parent.C = false;
  12827. grandpa.C = true;
  12828. RedBlackRotateRight(this, grandpa);
  12829. }
  12830. } else {
  12831. uncle = grandpa.L;
  12832. if (uncle && uncle.C) {
  12833. parent.C = uncle.C = false;
  12834. grandpa.C = true;
  12835. after = grandpa;
  12836. } else {
  12837. if (after === parent.L) {
  12838. RedBlackRotateRight(this, parent);
  12839. after = parent;
  12840. parent = after.U;
  12841. }
  12842. parent.C = false;
  12843. grandpa.C = true;
  12844. RedBlackRotateLeft(this, grandpa);
  12845. }
  12846. }
  12847. parent = after.U;
  12848. }
  12849. this._.C = false;
  12850. },
  12851. remove: function(node) {
  12852. if (node.N) node.N.P = node.P;
  12853. if (node.P) node.P.N = node.N;
  12854. node.N = node.P = null;
  12855. var parent = node.U,
  12856. sibling,
  12857. left = node.L,
  12858. right = node.R,
  12859. next,
  12860. red;
  12861. if (!left) next = right;
  12862. else if (!right) next = left;
  12863. else next = RedBlackFirst(right);
  12864. if (parent) {
  12865. if (parent.L === node) parent.L = next;
  12866. else parent.R = next;
  12867. } else {
  12868. this._ = next;
  12869. }
  12870. if (left && right) {
  12871. red = next.C;
  12872. next.C = node.C;
  12873. next.L = left;
  12874. left.U = next;
  12875. if (next !== right) {
  12876. parent = next.U;
  12877. next.U = node.U;
  12878. node = next.R;
  12879. parent.L = node;
  12880. next.R = right;
  12881. right.U = next;
  12882. } else {
  12883. next.U = parent;
  12884. parent = next;
  12885. node = next.R;
  12886. }
  12887. } else {
  12888. red = node.C;
  12889. node = next;
  12890. }
  12891. if (node) node.U = parent;
  12892. if (red) return;
  12893. if (node && node.C) { node.C = false; return; }
  12894. do {
  12895. if (node === this._) break;
  12896. if (node === parent.L) {
  12897. sibling = parent.R;
  12898. if (sibling.C) {
  12899. sibling.C = false;
  12900. parent.C = true;
  12901. RedBlackRotateLeft(this, parent);
  12902. sibling = parent.R;
  12903. }
  12904. if ((sibling.L && sibling.L.C)
  12905. || (sibling.R && sibling.R.C)) {
  12906. if (!sibling.R || !sibling.R.C) {
  12907. sibling.L.C = false;
  12908. sibling.C = true;
  12909. RedBlackRotateRight(this, sibling);
  12910. sibling = parent.R;
  12911. }
  12912. sibling.C = parent.C;
  12913. parent.C = sibling.R.C = false;
  12914. RedBlackRotateLeft(this, parent);
  12915. node = this._;
  12916. break;
  12917. }
  12918. } else {
  12919. sibling = parent.L;
  12920. if (sibling.C) {
  12921. sibling.C = false;
  12922. parent.C = true;
  12923. RedBlackRotateRight(this, parent);
  12924. sibling = parent.L;
  12925. }
  12926. if ((sibling.L && sibling.L.C)
  12927. || (sibling.R && sibling.R.C)) {
  12928. if (!sibling.L || !sibling.L.C) {
  12929. sibling.R.C = false;
  12930. sibling.C = true;
  12931. RedBlackRotateLeft(this, sibling);
  12932. sibling = parent.L;
  12933. }
  12934. sibling.C = parent.C;
  12935. parent.C = sibling.L.C = false;
  12936. RedBlackRotateRight(this, parent);
  12937. node = this._;
  12938. break;
  12939. }
  12940. }
  12941. sibling.C = true;
  12942. node = parent;
  12943. parent = parent.U;
  12944. } while (!node.C);
  12945. if (node) node.C = false;
  12946. }
  12947. };
  12948. function RedBlackRotateLeft(tree, node) {
  12949. var p = node,
  12950. q = node.R,
  12951. parent = p.U;
  12952. if (parent) {
  12953. if (parent.L === p) parent.L = q;
  12954. else parent.R = q;
  12955. } else {
  12956. tree._ = q;
  12957. }
  12958. q.U = parent;
  12959. p.U = q;
  12960. p.R = q.L;
  12961. if (p.R) p.R.U = p;
  12962. q.L = p;
  12963. }
  12964. function RedBlackRotateRight(tree, node) {
  12965. var p = node,
  12966. q = node.L,
  12967. parent = p.U;
  12968. if (parent) {
  12969. if (parent.L === p) parent.L = q;
  12970. else parent.R = q;
  12971. } else {
  12972. tree._ = q;
  12973. }
  12974. q.U = parent;
  12975. p.U = q;
  12976. p.L = q.R;
  12977. if (p.L) p.L.U = p;
  12978. q.R = p;
  12979. }
  12980. function RedBlackFirst(node) {
  12981. while (node.L) node = node.L;
  12982. return node;
  12983. }
  12984. function createEdge(left, right, v0, v1) {
  12985. var edge = [null, null],
  12986. index = edges.push(edge) - 1;
  12987. edge.left = left;
  12988. edge.right = right;
  12989. if (v0) setEdgeEnd(edge, left, right, v0);
  12990. if (v1) setEdgeEnd(edge, right, left, v1);
  12991. cells[left.index].halfedges.push(index);
  12992. cells[right.index].halfedges.push(index);
  12993. return edge;
  12994. }
  12995. function createBorderEdge(left, v0, v1) {
  12996. var edge = [v0, v1];
  12997. edge.left = left;
  12998. return edge;
  12999. }
  13000. function setEdgeEnd(edge, left, right, vertex) {
  13001. if (!edge[0] && !edge[1]) {
  13002. edge[0] = vertex;
  13003. edge.left = left;
  13004. edge.right = right;
  13005. } else if (edge.left === right) {
  13006. edge[1] = vertex;
  13007. } else {
  13008. edge[0] = vertex;
  13009. }
  13010. }
  13011. // Liang–Barsky line clipping.
  13012. function clipEdge(edge, x0, y0, x1, y1) {
  13013. var a = edge[0],
  13014. b = edge[1],
  13015. ax = a[0],
  13016. ay = a[1],
  13017. bx = b[0],
  13018. by = b[1],
  13019. t0 = 0,
  13020. t1 = 1,
  13021. dx = bx - ax,
  13022. dy = by - ay,
  13023. r;
  13024. r = x0 - ax;
  13025. if (!dx && r > 0) return;
  13026. r /= dx;
  13027. if (dx < 0) {
  13028. if (r < t0) return;
  13029. if (r < t1) t1 = r;
  13030. } else if (dx > 0) {
  13031. if (r > t1) return;
  13032. if (r > t0) t0 = r;
  13033. }
  13034. r = x1 - ax;
  13035. if (!dx && r < 0) return;
  13036. r /= dx;
  13037. if (dx < 0) {
  13038. if (r > t1) return;
  13039. if (r > t0) t0 = r;
  13040. } else if (dx > 0) {
  13041. if (r < t0) return;
  13042. if (r < t1) t1 = r;
  13043. }
  13044. r = y0 - ay;
  13045. if (!dy && r > 0) return;
  13046. r /= dy;
  13047. if (dy < 0) {
  13048. if (r < t0) return;
  13049. if (r < t1) t1 = r;
  13050. } else if (dy > 0) {
  13051. if (r > t1) return;
  13052. if (r > t0) t0 = r;
  13053. }
  13054. r = y1 - ay;
  13055. if (!dy && r < 0) return;
  13056. r /= dy;
  13057. if (dy < 0) {
  13058. if (r > t1) return;
  13059. if (r > t0) t0 = r;
  13060. } else if (dy > 0) {
  13061. if (r < t0) return;
  13062. if (r < t1) t1 = r;
  13063. }
  13064. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  13065. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  13066. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  13067. return true;
  13068. }
  13069. function connectEdge(edge, x0, y0, x1, y1) {
  13070. var v1 = edge[1];
  13071. if (v1) return true;
  13072. var v0 = edge[0],
  13073. left = edge.left,
  13074. right = edge.right,
  13075. lx = left[0],
  13076. ly = left[1],
  13077. rx = right[0],
  13078. ry = right[1],
  13079. fx = (lx + rx) / 2,
  13080. fy = (ly + ry) / 2,
  13081. fm,
  13082. fb;
  13083. if (ry === ly) {
  13084. if (fx < x0 || fx >= x1) return;
  13085. if (lx > rx) {
  13086. if (!v0) v0 = [fx, y0];
  13087. else if (v0[1] >= y1) return;
  13088. v1 = [fx, y1];
  13089. } else {
  13090. if (!v0) v0 = [fx, y1];
  13091. else if (v0[1] < y0) return;
  13092. v1 = [fx, y0];
  13093. }
  13094. } else {
  13095. fm = (lx - rx) / (ry - ly);
  13096. fb = fy - fm * fx;
  13097. if (fm < -1 || fm > 1) {
  13098. if (lx > rx) {
  13099. if (!v0) v0 = [(y0 - fb) / fm, y0];
  13100. else if (v0[1] >= y1) return;
  13101. v1 = [(y1 - fb) / fm, y1];
  13102. } else {
  13103. if (!v0) v0 = [(y1 - fb) / fm, y1];
  13104. else if (v0[1] < y0) return;
  13105. v1 = [(y0 - fb) / fm, y0];
  13106. }
  13107. } else {
  13108. if (ly < ry) {
  13109. if (!v0) v0 = [x0, fm * x0 + fb];
  13110. else if (v0[0] >= x1) return;
  13111. v1 = [x1, fm * x1 + fb];
  13112. } else {
  13113. if (!v0) v0 = [x1, fm * x1 + fb];
  13114. else if (v0[0] < x0) return;
  13115. v1 = [x0, fm * x0 + fb];
  13116. }
  13117. }
  13118. }
  13119. edge[0] = v0;
  13120. edge[1] = v1;
  13121. return true;
  13122. }
  13123. function clipEdges(x0, y0, x1, y1) {
  13124. var i = edges.length,
  13125. edge;
  13126. while (i--) {
  13127. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  13128. || !clipEdge(edge, x0, y0, x1, y1)
  13129. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  13130. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  13131. delete edges[i];
  13132. }
  13133. }
  13134. }
  13135. function createCell(site) {
  13136. return cells[site.index] = {
  13137. site: site,
  13138. halfedges: []
  13139. };
  13140. }
  13141. function cellHalfedgeAngle(cell, edge) {
  13142. var site = cell.site,
  13143. va = edge.left,
  13144. vb = edge.right;
  13145. if (site === vb) vb = va, va = site;
  13146. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  13147. if (site === va) va = edge[1], vb = edge[0];
  13148. else va = edge[0], vb = edge[1];
  13149. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  13150. }
  13151. function cellHalfedgeStart(cell, edge) {
  13152. return edge[+(edge.left !== cell.site)];
  13153. }
  13154. function cellHalfedgeEnd(cell, edge) {
  13155. return edge[+(edge.left === cell.site)];
  13156. }
  13157. function sortCellHalfedges() {
  13158. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  13159. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  13160. var index = new Array(m),
  13161. array = new Array(m);
  13162. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  13163. index.sort(function(i, j) { return array[j] - array[i]; });
  13164. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  13165. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  13166. }
  13167. }
  13168. }
  13169. function clipCells(x0, y0, x1, y1) {
  13170. var nCells = cells.length,
  13171. iCell,
  13172. cell,
  13173. site,
  13174. iHalfedge,
  13175. halfedges,
  13176. nHalfedges,
  13177. start,
  13178. startX,
  13179. startY,
  13180. end,
  13181. endX,
  13182. endY,
  13183. cover = true;
  13184. for (iCell = 0; iCell < nCells; ++iCell) {
  13185. if (cell = cells[iCell]) {
  13186. site = cell.site;
  13187. halfedges = cell.halfedges;
  13188. iHalfedge = halfedges.length;
  13189. // Remove any dangling clipped edges.
  13190. while (iHalfedge--) {
  13191. if (!edges[halfedges[iHalfedge]]) {
  13192. halfedges.splice(iHalfedge, 1);
  13193. }
  13194. }
  13195. // Insert any border edges as necessary.
  13196. iHalfedge = 0, nHalfedges = halfedges.length;
  13197. while (iHalfedge < nHalfedges) {
  13198. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  13199. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  13200. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  13201. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  13202. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  13203. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  13204. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  13205. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  13206. : null)) - 1);
  13207. ++nHalfedges;
  13208. }
  13209. }
  13210. if (nHalfedges) cover = false;
  13211. }
  13212. }
  13213. // If there weren’t any edges, have the closest site cover the extent.
  13214. // It doesn’t matter which corner of the extent we measure!
  13215. if (cover) {
  13216. var dx, dy, d2, dc = Infinity;
  13217. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  13218. if (cell = cells[iCell]) {
  13219. site = cell.site;
  13220. dx = site[0] - x0;
  13221. dy = site[1] - y0;
  13222. d2 = dx * dx + dy * dy;
  13223. if (d2 < dc) dc = d2, cover = cell;
  13224. }
  13225. }
  13226. if (cover) {
  13227. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  13228. cover.halfedges.push(
  13229. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  13230. edges.push(createBorderEdge(site, v01, v11)) - 1,
  13231. edges.push(createBorderEdge(site, v11, v10)) - 1,
  13232. edges.push(createBorderEdge(site, v10, v00)) - 1
  13233. );
  13234. }
  13235. }
  13236. // Lastly delete any cells with no edges; these were entirely clipped.
  13237. for (iCell = 0; iCell < nCells; ++iCell) {
  13238. if (cell = cells[iCell]) {
  13239. if (!cell.halfedges.length) {
  13240. delete cells[iCell];
  13241. }
  13242. }
  13243. }
  13244. }
  13245. var circlePool = [];
  13246. var firstCircle;
  13247. function Circle() {
  13248. RedBlackNode(this);
  13249. this.x =
  13250. this.y =
  13251. this.arc =
  13252. this.site =
  13253. this.cy = null;
  13254. }
  13255. function attachCircle(arc) {
  13256. var lArc = arc.P,
  13257. rArc = arc.N;
  13258. if (!lArc || !rArc) return;
  13259. var lSite = lArc.site,
  13260. cSite = arc.site,
  13261. rSite = rArc.site;
  13262. if (lSite === rSite) return;
  13263. var bx = cSite[0],
  13264. by = cSite[1],
  13265. ax = lSite[0] - bx,
  13266. ay = lSite[1] - by,
  13267. cx = rSite[0] - bx,
  13268. cy = rSite[1] - by;
  13269. var d = 2 * (ax * cy - ay * cx);
  13270. if (d >= -epsilon2$2) return;
  13271. var ha = ax * ax + ay * ay,
  13272. hc = cx * cx + cy * cy,
  13273. x = (cy * ha - ay * hc) / d,
  13274. y = (ax * hc - cx * ha) / d;
  13275. var circle = circlePool.pop() || new Circle;
  13276. circle.arc = arc;
  13277. circle.site = cSite;
  13278. circle.x = x + bx;
  13279. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  13280. arc.circle = circle;
  13281. var before = null,
  13282. node = circles._;
  13283. while (node) {
  13284. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  13285. if (node.L) node = node.L;
  13286. else { before = node.P; break; }
  13287. } else {
  13288. if (node.R) node = node.R;
  13289. else { before = node; break; }
  13290. }
  13291. }
  13292. circles.insert(before, circle);
  13293. if (!before) firstCircle = circle;
  13294. }
  13295. function detachCircle(arc) {
  13296. var circle = arc.circle;
  13297. if (circle) {
  13298. if (!circle.P) firstCircle = circle.N;
  13299. circles.remove(circle);
  13300. circlePool.push(circle);
  13301. RedBlackNode(circle);
  13302. arc.circle = null;
  13303. }
  13304. }
  13305. var beachPool = [];
  13306. function Beach() {
  13307. RedBlackNode(this);
  13308. this.edge =
  13309. this.site =
  13310. this.circle = null;
  13311. }
  13312. function createBeach(site) {
  13313. var beach = beachPool.pop() || new Beach;
  13314. beach.site = site;
  13315. return beach;
  13316. }
  13317. function detachBeach(beach) {
  13318. detachCircle(beach);
  13319. beaches.remove(beach);
  13320. beachPool.push(beach);
  13321. RedBlackNode(beach);
  13322. }
  13323. function removeBeach(beach) {
  13324. var circle = beach.circle,
  13325. x = circle.x,
  13326. y = circle.cy,
  13327. vertex = [x, y],
  13328. previous = beach.P,
  13329. next = beach.N,
  13330. disappearing = [beach];
  13331. detachBeach(beach);
  13332. var lArc = previous;
  13333. while (lArc.circle
  13334. && Math.abs(x - lArc.circle.x) < epsilon$4
  13335. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  13336. previous = lArc.P;
  13337. disappearing.unshift(lArc);
  13338. detachBeach(lArc);
  13339. lArc = previous;
  13340. }
  13341. disappearing.unshift(lArc);
  13342. detachCircle(lArc);
  13343. var rArc = next;
  13344. while (rArc.circle
  13345. && Math.abs(x - rArc.circle.x) < epsilon$4
  13346. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  13347. next = rArc.N;
  13348. disappearing.push(rArc);
  13349. detachBeach(rArc);
  13350. rArc = next;
  13351. }
  13352. disappearing.push(rArc);
  13353. detachCircle(rArc);
  13354. var nArcs = disappearing.length,
  13355. iArc;
  13356. for (iArc = 1; iArc < nArcs; ++iArc) {
  13357. rArc = disappearing[iArc];
  13358. lArc = disappearing[iArc - 1];
  13359. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  13360. }
  13361. lArc = disappearing[0];
  13362. rArc = disappearing[nArcs - 1];
  13363. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  13364. attachCircle(lArc);
  13365. attachCircle(rArc);
  13366. }
  13367. function addBeach(site) {
  13368. var x = site[0],
  13369. directrix = site[1],
  13370. lArc,
  13371. rArc,
  13372. dxl,
  13373. dxr,
  13374. node = beaches._;
  13375. while (node) {
  13376. dxl = leftBreakPoint(node, directrix) - x;
  13377. if (dxl > epsilon$4) node = node.L; else {
  13378. dxr = x - rightBreakPoint(node, directrix);
  13379. if (dxr > epsilon$4) {
  13380. if (!node.R) {
  13381. lArc = node;
  13382. break;
  13383. }
  13384. node = node.R;
  13385. } else {
  13386. if (dxl > -epsilon$4) {
  13387. lArc = node.P;
  13388. rArc = node;
  13389. } else if (dxr > -epsilon$4) {
  13390. lArc = node;
  13391. rArc = node.N;
  13392. } else {
  13393. lArc = rArc = node;
  13394. }
  13395. break;
  13396. }
  13397. }
  13398. }
  13399. createCell(site);
  13400. var newArc = createBeach(site);
  13401. beaches.insert(lArc, newArc);
  13402. if (!lArc && !rArc) return;
  13403. if (lArc === rArc) {
  13404. detachCircle(lArc);
  13405. rArc = createBeach(lArc.site);
  13406. beaches.insert(newArc, rArc);
  13407. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  13408. attachCircle(lArc);
  13409. attachCircle(rArc);
  13410. return;
  13411. }
  13412. if (!rArc) { // && lArc
  13413. newArc.edge = createEdge(lArc.site, newArc.site);
  13414. return;
  13415. }
  13416. // else lArc !== rArc
  13417. detachCircle(lArc);
  13418. detachCircle(rArc);
  13419. var lSite = lArc.site,
  13420. ax = lSite[0],
  13421. ay = lSite[1],
  13422. bx = site[0] - ax,
  13423. by = site[1] - ay,
  13424. rSite = rArc.site,
  13425. cx = rSite[0] - ax,
  13426. cy = rSite[1] - ay,
  13427. d = 2 * (bx * cy - by * cx),
  13428. hb = bx * bx + by * by,
  13429. hc = cx * cx + cy * cy,
  13430. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  13431. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  13432. newArc.edge = createEdge(lSite, site, null, vertex);
  13433. rArc.edge = createEdge(site, rSite, null, vertex);
  13434. attachCircle(lArc);
  13435. attachCircle(rArc);
  13436. }
  13437. function leftBreakPoint(arc, directrix) {
  13438. var site = arc.site,
  13439. rfocx = site[0],
  13440. rfocy = site[1],
  13441. pby2 = rfocy - directrix;
  13442. if (!pby2) return rfocx;
  13443. var lArc = arc.P;
  13444. if (!lArc) return -Infinity;
  13445. site = lArc.site;
  13446. var lfocx = site[0],
  13447. lfocy = site[1],
  13448. plby2 = lfocy - directrix;
  13449. if (!plby2) return lfocx;
  13450. var hl = lfocx - rfocx,
  13451. aby2 = 1 / pby2 - 1 / plby2,
  13452. b = hl / plby2;
  13453. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  13454. return (rfocx + lfocx) / 2;
  13455. }
  13456. function rightBreakPoint(arc, directrix) {
  13457. var rArc = arc.N;
  13458. if (rArc) return leftBreakPoint(rArc, directrix);
  13459. var site = arc.site;
  13460. return site[1] === directrix ? site[0] : Infinity;
  13461. }
  13462. var epsilon$4 = 1e-6;
  13463. var epsilon2$2 = 1e-12;
  13464. var beaches;
  13465. var cells;
  13466. var circles;
  13467. var edges;
  13468. function triangleArea(a, b, c) {
  13469. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  13470. }
  13471. function lexicographic(a, b) {
  13472. return b[1] - a[1]
  13473. || b[0] - a[0];
  13474. }
  13475. function Diagram(sites, extent) {
  13476. var site = sites.sort(lexicographic).pop(),
  13477. x,
  13478. y,
  13479. circle;
  13480. edges = [];
  13481. cells = new Array(sites.length);
  13482. beaches = new RedBlackTree;
  13483. circles = new RedBlackTree;
  13484. while (true) {
  13485. circle = firstCircle;
  13486. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  13487. if (site[0] !== x || site[1] !== y) {
  13488. addBeach(site);
  13489. x = site[0], y = site[1];
  13490. }
  13491. site = sites.pop();
  13492. } else if (circle) {
  13493. removeBeach(circle.arc);
  13494. } else {
  13495. break;
  13496. }
  13497. }
  13498. sortCellHalfedges();
  13499. if (extent) {
  13500. var x0 = +extent[0][0],
  13501. y0 = +extent[0][1],
  13502. x1 = +extent[1][0],
  13503. y1 = +extent[1][1];
  13504. clipEdges(x0, y0, x1, y1);
  13505. clipCells(x0, y0, x1, y1);
  13506. }
  13507. this.edges = edges;
  13508. this.cells = cells;
  13509. beaches =
  13510. circles =
  13511. edges =
  13512. cells = null;
  13513. }
  13514. Diagram.prototype = {
  13515. constructor: Diagram,
  13516. polygons: function() {
  13517. var edges = this.edges;
  13518. return this.cells.map(function(cell) {
  13519. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  13520. polygon.data = cell.site.data;
  13521. return polygon;
  13522. });
  13523. },
  13524. triangles: function() {
  13525. var triangles = [],
  13526. edges = this.edges;
  13527. this.cells.forEach(function(cell, i) {
  13528. if (!(m = (halfedges = cell.halfedges).length)) return;
  13529. var site = cell.site,
  13530. halfedges,
  13531. j = -1,
  13532. m,
  13533. s0,
  13534. e1 = edges[halfedges[m - 1]],
  13535. s1 = e1.left === site ? e1.right : e1.left;
  13536. while (++j < m) {
  13537. s0 = s1;
  13538. e1 = edges[halfedges[j]];
  13539. s1 = e1.left === site ? e1.right : e1.left;
  13540. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  13541. triangles.push([site.data, s0.data, s1.data]);
  13542. }
  13543. }
  13544. });
  13545. return triangles;
  13546. },
  13547. links: function() {
  13548. return this.edges.filter(function(edge) {
  13549. return edge.right;
  13550. }).map(function(edge) {
  13551. return {
  13552. source: edge.left.data,
  13553. target: edge.right.data
  13554. };
  13555. });
  13556. },
  13557. find: function(x, y, radius) {
  13558. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  13559. // Use the previously-found cell, or start with an arbitrary one.
  13560. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  13561. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  13562. // Traverse the half-edges to find a closer cell, if any.
  13563. do {
  13564. cell = that.cells[i0 = i1], i1 = null;
  13565. cell.halfedges.forEach(function(e) {
  13566. var edge = that.edges[e], v = edge.left;
  13567. if ((v === cell.site || !v) && !(v = edge.right)) return;
  13568. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  13569. if (v2 < d2) d2 = v2, i1 = v.index;
  13570. });
  13571. } while (i1 !== null);
  13572. that._found = i0;
  13573. return radius == null || d2 <= radius * radius ? cell.site : null;
  13574. }
  13575. };
  13576. var voronoi = function() {
  13577. var x$$1 = x$5,
  13578. y$$1 = y$4,
  13579. extent = null;
  13580. function voronoi(data) {
  13581. return new Diagram(data.map(function(d, i) {
  13582. var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
  13583. s.index = i;
  13584. s.data = d;
  13585. return s;
  13586. }), extent);
  13587. }
  13588. voronoi.polygons = function(data) {
  13589. return voronoi(data).polygons();
  13590. };
  13591. voronoi.links = function(data) {
  13592. return voronoi(data).links();
  13593. };
  13594. voronoi.triangles = function(data) {
  13595. return voronoi(data).triangles();
  13596. };
  13597. voronoi.x = function(_) {
  13598. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : x$$1;
  13599. };
  13600. voronoi.y = function(_) {
  13601. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : y$$1;
  13602. };
  13603. voronoi.extent = function(_) {
  13604. return arguments.length ? (extent = _ == null ? null : [[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]], voronoi) : extent && [[extent[0][0], extent[0][1]], [extent[1][0], extent[1][1]]];
  13605. };
  13606. voronoi.size = function(_) {
  13607. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  13608. };
  13609. return voronoi;
  13610. };
  13611. var constant$12 = function(x) {
  13612. return function() {
  13613. return x;
  13614. };
  13615. };
  13616. function ZoomEvent(target, type, transform) {
  13617. this.target = target;
  13618. this.type = type;
  13619. this.transform = transform;
  13620. }
  13621. function Transform(k, x, y) {
  13622. this.k = k;
  13623. this.x = x;
  13624. this.y = y;
  13625. }
  13626. Transform.prototype = {
  13627. constructor: Transform,
  13628. scale: function(k) {
  13629. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  13630. },
  13631. translate: function(x, y) {
  13632. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  13633. },
  13634. apply: function(point) {
  13635. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  13636. },
  13637. applyX: function(x) {
  13638. return x * this.k + this.x;
  13639. },
  13640. applyY: function(y) {
  13641. return y * this.k + this.y;
  13642. },
  13643. invert: function(location) {
  13644. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  13645. },
  13646. invertX: function(x) {
  13647. return (x - this.x) / this.k;
  13648. },
  13649. invertY: function(y) {
  13650. return (y - this.y) / this.k;
  13651. },
  13652. rescaleX: function(x) {
  13653. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  13654. },
  13655. rescaleY: function(y) {
  13656. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  13657. },
  13658. toString: function() {
  13659. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  13660. }
  13661. };
  13662. var identity$8 = new Transform(1, 0, 0);
  13663. transform$1.prototype = Transform.prototype;
  13664. function transform$1(node) {
  13665. return node.__zoom || identity$8;
  13666. }
  13667. function nopropagation$2() {
  13668. exports.event.stopImmediatePropagation();
  13669. }
  13670. var noevent$2 = function() {
  13671. exports.event.preventDefault();
  13672. exports.event.stopImmediatePropagation();
  13673. };
  13674. // Ignore right-click, since that should open the context menu.
  13675. function defaultFilter$2() {
  13676. return !exports.event.button;
  13677. }
  13678. function defaultExtent$1() {
  13679. var e = this, w, h;
  13680. if (e instanceof SVGElement) {
  13681. e = e.ownerSVGElement || e;
  13682. w = e.width.baseVal.value;
  13683. h = e.height.baseVal.value;
  13684. } else {
  13685. w = e.clientWidth;
  13686. h = e.clientHeight;
  13687. }
  13688. return [[0, 0], [w, h]];
  13689. }
  13690. function defaultTransform() {
  13691. return this.__zoom || identity$8;
  13692. }
  13693. function defaultWheelDelta() {
  13694. return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
  13695. }
  13696. function touchable$1() {
  13697. return "ontouchstart" in this;
  13698. }
  13699. var zoom = function() {
  13700. var filter = defaultFilter$2,
  13701. extent = defaultExtent$1,
  13702. wheelDelta = defaultWheelDelta,
  13703. k0 = 0,
  13704. k1 = Infinity,
  13705. x0 = -k1,
  13706. x1 = k1,
  13707. y0 = x0,
  13708. y1 = x1,
  13709. duration = 250,
  13710. interpolate = interpolateZoom,
  13711. gestures = [],
  13712. listeners = dispatch("start", "zoom", "end"),
  13713. touchstarting,
  13714. touchending,
  13715. touchDelay = 500,
  13716. wheelDelay = 150,
  13717. clickDistance2 = 0;
  13718. function zoom(selection) {
  13719. selection
  13720. .property("__zoom", defaultTransform)
  13721. .on("wheel.zoom", wheeled)
  13722. .on("mousedown.zoom", mousedowned)
  13723. .on("dblclick.zoom", dblclicked)
  13724. .filter(touchable$1)
  13725. .on("touchstart.zoom", touchstarted)
  13726. .on("touchmove.zoom", touchmoved)
  13727. .on("touchend.zoom touchcancel.zoom", touchended)
  13728. .style("touch-action", "none")
  13729. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  13730. }
  13731. zoom.transform = function(collection, transform$$1) {
  13732. var selection = collection.selection ? collection.selection() : collection;
  13733. selection.property("__zoom", defaultTransform);
  13734. if (collection !== selection) {
  13735. schedule(collection, transform$$1);
  13736. } else {
  13737. selection.interrupt().each(function() {
  13738. gesture(this, arguments)
  13739. .start()
  13740. .zoom(null, typeof transform$$1 === "function" ? transform$$1.apply(this, arguments) : transform$$1)
  13741. .end();
  13742. });
  13743. }
  13744. };
  13745. zoom.scaleBy = function(selection, k) {
  13746. zoom.scaleTo(selection, function() {
  13747. var k0 = this.__zoom.k,
  13748. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  13749. return k0 * k1;
  13750. });
  13751. };
  13752. zoom.scaleTo = function(selection, k) {
  13753. zoom.transform(selection, function() {
  13754. var e = extent.apply(this, arguments),
  13755. t0 = this.__zoom,
  13756. p0 = centroid(e),
  13757. p1 = t0.invert(p0),
  13758. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  13759. return constrain(translate(scale(t0, k1), p0, p1), e);
  13760. });
  13761. };
  13762. zoom.translateBy = function(selection, x, y) {
  13763. zoom.transform(selection, function() {
  13764. return constrain(this.__zoom.translate(
  13765. typeof x === "function" ? x.apply(this, arguments) : x,
  13766. typeof y === "function" ? y.apply(this, arguments) : y
  13767. ), extent.apply(this, arguments));
  13768. });
  13769. };
  13770. zoom.translateTo = function(selection, x, y) {
  13771. zoom.transform(selection, function() {
  13772. var e = extent.apply(this, arguments),
  13773. t = this.__zoom,
  13774. p = centroid(e);
  13775. return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
  13776. typeof x === "function" ? -x.apply(this, arguments) : -x,
  13777. typeof y === "function" ? -y.apply(this, arguments) : -y
  13778. ), e);
  13779. });
  13780. };
  13781. function scale(transform$$1, k) {
  13782. k = Math.max(k0, Math.min(k1, k));
  13783. return k === transform$$1.k ? transform$$1 : new Transform(k, transform$$1.x, transform$$1.y);
  13784. }
  13785. function translate(transform$$1, p0, p1) {
  13786. var x = p0[0] - p1[0] * transform$$1.k, y = p0[1] - p1[1] * transform$$1.k;
  13787. return x === transform$$1.x && y === transform$$1.y ? transform$$1 : new Transform(transform$$1.k, x, y);
  13788. }
  13789. function constrain(transform$$1, extent) {
  13790. var dx0 = transform$$1.invertX(extent[0][0]) - x0,
  13791. dx1 = transform$$1.invertX(extent[1][0]) - x1,
  13792. dy0 = transform$$1.invertY(extent[0][1]) - y0,
  13793. dy1 = transform$$1.invertY(extent[1][1]) - y1;
  13794. return transform$$1.translate(
  13795. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  13796. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  13797. );
  13798. }
  13799. function centroid(extent) {
  13800. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  13801. }
  13802. function schedule(transition, transform$$1, center) {
  13803. transition
  13804. .on("start.zoom", function() { gesture(this, arguments).start(); })
  13805. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  13806. .tween("zoom", function() {
  13807. var that = this,
  13808. args = arguments,
  13809. g = gesture(that, args),
  13810. e = extent.apply(that, args),
  13811. p = center || centroid(e),
  13812. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  13813. a = that.__zoom,
  13814. b = typeof transform$$1 === "function" ? transform$$1.apply(that, args) : transform$$1,
  13815. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  13816. return function(t) {
  13817. if (t === 1) t = b; // Avoid rounding error on end.
  13818. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  13819. g.zoom(null, t);
  13820. };
  13821. });
  13822. }
  13823. function gesture(that, args) {
  13824. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  13825. if ((g = gestures[i]).that === that) {
  13826. return g;
  13827. }
  13828. }
  13829. return new Gesture(that, args);
  13830. }
  13831. function Gesture(that, args) {
  13832. this.that = that;
  13833. this.args = args;
  13834. this.index = -1;
  13835. this.active = 0;
  13836. this.extent = extent.apply(that, args);
  13837. }
  13838. Gesture.prototype = {
  13839. start: function() {
  13840. if (++this.active === 1) {
  13841. this.index = gestures.push(this) - 1;
  13842. this.emit("start");
  13843. }
  13844. return this;
  13845. },
  13846. zoom: function(key, transform$$1) {
  13847. if (this.mouse && key !== "mouse") this.mouse[1] = transform$$1.invert(this.mouse[0]);
  13848. if (this.touch0 && key !== "touch") this.touch0[1] = transform$$1.invert(this.touch0[0]);
  13849. if (this.touch1 && key !== "touch") this.touch1[1] = transform$$1.invert(this.touch1[0]);
  13850. this.that.__zoom = transform$$1;
  13851. this.emit("zoom");
  13852. return this;
  13853. },
  13854. end: function() {
  13855. if (--this.active === 0) {
  13856. gestures.splice(this.index, 1);
  13857. this.index = -1;
  13858. this.emit("end");
  13859. }
  13860. return this;
  13861. },
  13862. emit: function(type) {
  13863. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  13864. }
  13865. };
  13866. function wheeled() {
  13867. if (!filter.apply(this, arguments)) return;
  13868. var g = gesture(this, arguments),
  13869. t = this.__zoom,
  13870. k = Math.max(k0, Math.min(k1, t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  13871. p = mouse(this);
  13872. // If the mouse is in the same location as before, reuse it.
  13873. // If there were recent wheel events, reset the wheel idle timeout.
  13874. if (g.wheel) {
  13875. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  13876. g.mouse[1] = t.invert(g.mouse[0] = p);
  13877. }
  13878. clearTimeout(g.wheel);
  13879. }
  13880. // If this wheel event won’t trigger a transform change, ignore it.
  13881. else if (t.k === k) return;
  13882. // Otherwise, capture the mouse point and location at the start.
  13883. else {
  13884. g.mouse = [p, t.invert(p)];
  13885. interrupt(this);
  13886. g.start();
  13887. }
  13888. noevent$2();
  13889. g.wheel = setTimeout(wheelidled, wheelDelay);
  13890. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent));
  13891. function wheelidled() {
  13892. g.wheel = null;
  13893. g.end();
  13894. }
  13895. }
  13896. function mousedowned() {
  13897. if (touchending || !filter.apply(this, arguments)) return;
  13898. var g = gesture(this, arguments),
  13899. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  13900. p = mouse(this),
  13901. x0 = exports.event.clientX,
  13902. y0 = exports.event.clientY;
  13903. dragDisable(exports.event.view);
  13904. nopropagation$2();
  13905. g.mouse = [p, this.__zoom.invert(p)];
  13906. interrupt(this);
  13907. g.start();
  13908. function mousemoved() {
  13909. noevent$2();
  13910. if (!g.moved) {
  13911. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  13912. g.moved = dx * dx + dy * dy > clickDistance2;
  13913. }
  13914. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent));
  13915. }
  13916. function mouseupped() {
  13917. v.on("mousemove.zoom mouseup.zoom", null);
  13918. yesdrag(exports.event.view, g.moved);
  13919. noevent$2();
  13920. g.end();
  13921. }
  13922. }
  13923. function dblclicked() {
  13924. if (!filter.apply(this, arguments)) return;
  13925. var t0 = this.__zoom,
  13926. p0 = mouse(this),
  13927. p1 = t0.invert(p0),
  13928. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  13929. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments));
  13930. noevent$2();
  13931. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  13932. else select(this).call(zoom.transform, t1);
  13933. }
  13934. function touchstarted() {
  13935. if (!filter.apply(this, arguments)) return;
  13936. var g = gesture(this, arguments),
  13937. touches = exports.event.changedTouches,
  13938. started,
  13939. n = touches.length, i, t, p;
  13940. nopropagation$2();
  13941. for (i = 0; i < n; ++i) {
  13942. t = touches[i], p = touch(this, touches, t.identifier);
  13943. p = [p, this.__zoom.invert(p), t.identifier];
  13944. if (!g.touch0) g.touch0 = p, started = true;
  13945. else if (!g.touch1) g.touch1 = p;
  13946. }
  13947. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  13948. if (touchstarting) {
  13949. touchstarting = clearTimeout(touchstarting);
  13950. if (!g.touch1) {
  13951. g.end();
  13952. p = select(this).on("dblclick.zoom");
  13953. if (p) p.apply(this, arguments);
  13954. return;
  13955. }
  13956. }
  13957. if (started) {
  13958. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  13959. interrupt(this);
  13960. g.start();
  13961. }
  13962. }
  13963. function touchmoved() {
  13964. var g = gesture(this, arguments),
  13965. touches = exports.event.changedTouches,
  13966. n = touches.length, i, t, p, l;
  13967. noevent$2();
  13968. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  13969. for (i = 0; i < n; ++i) {
  13970. t = touches[i], p = touch(this, touches, t.identifier);
  13971. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  13972. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  13973. }
  13974. t = g.that.__zoom;
  13975. if (g.touch1) {
  13976. var p0 = g.touch0[0], l0 = g.touch0[1],
  13977. p1 = g.touch1[0], l1 = g.touch1[1],
  13978. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  13979. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  13980. t = scale(t, Math.sqrt(dp / dl));
  13981. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  13982. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  13983. }
  13984. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  13985. else return;
  13986. g.zoom("touch", constrain(translate(t, p, l), g.extent));
  13987. }
  13988. function touchended() {
  13989. var g = gesture(this, arguments),
  13990. touches = exports.event.changedTouches,
  13991. n = touches.length, i, t;
  13992. nopropagation$2();
  13993. if (touchending) clearTimeout(touchending);
  13994. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  13995. for (i = 0; i < n; ++i) {
  13996. t = touches[i];
  13997. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  13998. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  13999. }
  14000. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  14001. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  14002. else g.end();
  14003. }
  14004. zoom.wheelDelta = function(_) {
  14005. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$12(+_), zoom) : wheelDelta;
  14006. };
  14007. zoom.filter = function(_) {
  14008. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$12(!!_), zoom) : filter;
  14009. };
  14010. zoom.extent = function(_) {
  14011. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$12([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  14012. };
  14013. zoom.scaleExtent = function(_) {
  14014. return arguments.length ? (k0 = +_[0], k1 = +_[1], zoom) : [k0, k1];
  14015. };
  14016. zoom.translateExtent = function(_) {
  14017. return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], zoom) : [[x0, y0], [x1, y1]];
  14018. };
  14019. zoom.duration = function(_) {
  14020. return arguments.length ? (duration = +_, zoom) : duration;
  14021. };
  14022. zoom.interpolate = function(_) {
  14023. return arguments.length ? (interpolate = _, zoom) : interpolate;
  14024. };
  14025. zoom.on = function() {
  14026. var value = listeners.on.apply(listeners, arguments);
  14027. return value === listeners ? zoom : value;
  14028. };
  14029. zoom.clickDistance = function(_) {
  14030. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  14031. };
  14032. return zoom;
  14033. };
  14034. exports.version = version;
  14035. exports.bisect = bisectRight$1;
  14036. exports.bisectRight = bisectRight$1;
  14037. exports.bisectLeft = bisectLeft;
  14038. exports.ascending = ascending;
  14039. exports.bisector = bisector;
  14040. exports.cross = cross;
  14041. exports.descending = descending;
  14042. exports.deviation = deviation;
  14043. exports.extent = extent;
  14044. exports.histogram = histogram;
  14045. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  14046. exports.thresholdScott = scott;
  14047. exports.thresholdSturges = sturges;
  14048. exports.max = max;
  14049. exports.mean = mean;
  14050. exports.median = median;
  14051. exports.merge = merge;
  14052. exports.min = min;
  14053. exports.pairs = pairs;
  14054. exports.permute = permute;
  14055. exports.quantile = threshold;
  14056. exports.range = sequence;
  14057. exports.scan = scan;
  14058. exports.shuffle = shuffle;
  14059. exports.sum = sum;
  14060. exports.ticks = ticks;
  14061. exports.tickIncrement = tickIncrement;
  14062. exports.tickStep = tickStep;
  14063. exports.transpose = transpose;
  14064. exports.variance = variance;
  14065. exports.zip = zip;
  14066. exports.axisTop = axisTop;
  14067. exports.axisRight = axisRight;
  14068. exports.axisBottom = axisBottom;
  14069. exports.axisLeft = axisLeft;
  14070. exports.brush = brush;
  14071. exports.brushX = brushX;
  14072. exports.brushY = brushY;
  14073. exports.brushSelection = brushSelection;
  14074. exports.chord = chord;
  14075. exports.ribbon = ribbon;
  14076. exports.nest = nest;
  14077. exports.set = set$2;
  14078. exports.map = map$1;
  14079. exports.keys = keys;
  14080. exports.values = values;
  14081. exports.entries = entries;
  14082. exports.color = color;
  14083. exports.rgb = rgb;
  14084. exports.hsl = hsl;
  14085. exports.lab = lab;
  14086. exports.hcl = hcl;
  14087. exports.cubehelix = cubehelix;
  14088. exports.dispatch = dispatch;
  14089. exports.drag = drag;
  14090. exports.dragDisable = dragDisable;
  14091. exports.dragEnable = yesdrag;
  14092. exports.dsvFormat = dsv;
  14093. exports.csvParse = csvParse;
  14094. exports.csvParseRows = csvParseRows;
  14095. exports.csvFormat = csvFormat;
  14096. exports.csvFormatRows = csvFormatRows;
  14097. exports.tsvParse = tsvParse;
  14098. exports.tsvParseRows = tsvParseRows;
  14099. exports.tsvFormat = tsvFormat;
  14100. exports.tsvFormatRows = tsvFormatRows;
  14101. exports.easeLinear = linear$1;
  14102. exports.easeQuad = quadInOut;
  14103. exports.easeQuadIn = quadIn;
  14104. exports.easeQuadOut = quadOut;
  14105. exports.easeQuadInOut = quadInOut;
  14106. exports.easeCubic = cubicInOut;
  14107. exports.easeCubicIn = cubicIn;
  14108. exports.easeCubicOut = cubicOut;
  14109. exports.easeCubicInOut = cubicInOut;
  14110. exports.easePoly = polyInOut;
  14111. exports.easePolyIn = polyIn;
  14112. exports.easePolyOut = polyOut;
  14113. exports.easePolyInOut = polyInOut;
  14114. exports.easeSin = sinInOut;
  14115. exports.easeSinIn = sinIn;
  14116. exports.easeSinOut = sinOut;
  14117. exports.easeSinInOut = sinInOut;
  14118. exports.easeExp = expInOut;
  14119. exports.easeExpIn = expIn;
  14120. exports.easeExpOut = expOut;
  14121. exports.easeExpInOut = expInOut;
  14122. exports.easeCircle = circleInOut;
  14123. exports.easeCircleIn = circleIn;
  14124. exports.easeCircleOut = circleOut;
  14125. exports.easeCircleInOut = circleInOut;
  14126. exports.easeBounce = bounceOut;
  14127. exports.easeBounceIn = bounceIn;
  14128. exports.easeBounceOut = bounceOut;
  14129. exports.easeBounceInOut = bounceInOut;
  14130. exports.easeBack = backInOut;
  14131. exports.easeBackIn = backIn;
  14132. exports.easeBackOut = backOut;
  14133. exports.easeBackInOut = backInOut;
  14134. exports.easeElastic = elasticOut;
  14135. exports.easeElasticIn = elasticIn;
  14136. exports.easeElasticOut = elasticOut;
  14137. exports.easeElasticInOut = elasticInOut;
  14138. exports.forceCenter = center$1;
  14139. exports.forceCollide = collide;
  14140. exports.forceLink = link;
  14141. exports.forceManyBody = manyBody;
  14142. exports.forceSimulation = simulation;
  14143. exports.forceX = x$3;
  14144. exports.forceY = y$2;
  14145. exports.formatDefaultLocale = defaultLocale;
  14146. exports.formatLocale = formatLocale;
  14147. exports.formatSpecifier = formatSpecifier;
  14148. exports.precisionFixed = precisionFixed;
  14149. exports.precisionPrefix = precisionPrefix;
  14150. exports.precisionRound = precisionRound;
  14151. exports.geoArea = area;
  14152. exports.geoBounds = bounds;
  14153. exports.geoCentroid = centroid;
  14154. exports.geoCircle = circle;
  14155. exports.geoClipExtent = extent$1;
  14156. exports.geoContains = contains;
  14157. exports.geoDistance = distance;
  14158. exports.geoGraticule = graticule;
  14159. exports.geoGraticule10 = graticule10;
  14160. exports.geoInterpolate = interpolate$1;
  14161. exports.geoLength = length$1;
  14162. exports.geoPath = index$1;
  14163. exports.geoAlbers = albers;
  14164. exports.geoAlbersUsa = albersUsa;
  14165. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  14166. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  14167. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  14168. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  14169. exports.geoConicConformal = conicConformal;
  14170. exports.geoConicConformalRaw = conicConformalRaw;
  14171. exports.geoConicEqualArea = conicEqualArea;
  14172. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  14173. exports.geoConicEquidistant = conicEquidistant;
  14174. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  14175. exports.geoEquirectangular = equirectangular;
  14176. exports.geoEquirectangularRaw = equirectangularRaw;
  14177. exports.geoGnomonic = gnomonic;
  14178. exports.geoGnomonicRaw = gnomonicRaw;
  14179. exports.geoIdentity = identity$5;
  14180. exports.geoProjection = projection;
  14181. exports.geoProjectionMutator = projectionMutator;
  14182. exports.geoMercator = mercator;
  14183. exports.geoMercatorRaw = mercatorRaw;
  14184. exports.geoOrthographic = orthographic;
  14185. exports.geoOrthographicRaw = orthographicRaw;
  14186. exports.geoStereographic = stereographic;
  14187. exports.geoStereographicRaw = stereographicRaw;
  14188. exports.geoTransverseMercator = transverseMercator;
  14189. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  14190. exports.geoRotation = rotation;
  14191. exports.geoStream = geoStream;
  14192. exports.geoTransform = transform;
  14193. exports.cluster = cluster;
  14194. exports.hierarchy = hierarchy;
  14195. exports.pack = index$2;
  14196. exports.packSiblings = siblings;
  14197. exports.packEnclose = enclose;
  14198. exports.partition = partition;
  14199. exports.stratify = stratify;
  14200. exports.tree = tree;
  14201. exports.treemap = index$3;
  14202. exports.treemapBinary = binary;
  14203. exports.treemapDice = treemapDice;
  14204. exports.treemapSlice = treemapSlice;
  14205. exports.treemapSliceDice = sliceDice;
  14206. exports.treemapSquarify = squarify;
  14207. exports.treemapResquarify = resquarify;
  14208. exports.interpolate = interpolateValue;
  14209. exports.interpolateArray = array$1;
  14210. exports.interpolateBasis = basis$1;
  14211. exports.interpolateBasisClosed = basisClosed;
  14212. exports.interpolateDate = date;
  14213. exports.interpolateNumber = reinterpolate;
  14214. exports.interpolateObject = object;
  14215. exports.interpolateRound = interpolateRound;
  14216. exports.interpolateString = interpolateString;
  14217. exports.interpolateTransformCss = interpolateTransformCss;
  14218. exports.interpolateTransformSvg = interpolateTransformSvg;
  14219. exports.interpolateZoom = interpolateZoom;
  14220. exports.interpolateRgb = interpolateRgb;
  14221. exports.interpolateRgbBasis = rgbBasis;
  14222. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  14223. exports.interpolateHsl = hsl$2;
  14224. exports.interpolateHslLong = hslLong;
  14225. exports.interpolateLab = lab$1;
  14226. exports.interpolateHcl = hcl$2;
  14227. exports.interpolateHclLong = hclLong;
  14228. exports.interpolateCubehelix = cubehelix$2;
  14229. exports.interpolateCubehelixLong = cubehelixLong;
  14230. exports.quantize = quantize;
  14231. exports.path = path;
  14232. exports.polygonArea = area$1;
  14233. exports.polygonCentroid = centroid$1;
  14234. exports.polygonHull = hull;
  14235. exports.polygonContains = contains$1;
  14236. exports.polygonLength = length$2;
  14237. exports.quadtree = quadtree;
  14238. exports.queue = queue;
  14239. exports.randomUniform = uniform;
  14240. exports.randomNormal = normal;
  14241. exports.randomLogNormal = logNormal;
  14242. exports.randomBates = bates;
  14243. exports.randomIrwinHall = irwinHall;
  14244. exports.randomExponential = exponential$1;
  14245. exports.request = request;
  14246. exports.html = html;
  14247. exports.json = json;
  14248. exports.text = text;
  14249. exports.xml = xml;
  14250. exports.csv = csv$1;
  14251. exports.tsv = tsv$1;
  14252. exports.scaleBand = band;
  14253. exports.scalePoint = point$1;
  14254. exports.scaleIdentity = identity$6;
  14255. exports.scaleLinear = linear$2;
  14256. exports.scaleLog = log$1;
  14257. exports.scaleOrdinal = ordinal;
  14258. exports.scaleImplicit = implicit;
  14259. exports.scalePow = pow$1;
  14260. exports.scaleSqrt = sqrt$1;
  14261. exports.scaleQuantile = quantile$$1;
  14262. exports.scaleQuantize = quantize$1;
  14263. exports.scaleThreshold = threshold$1;
  14264. exports.scaleTime = time;
  14265. exports.scaleUtc = utcTime;
  14266. exports.schemeCategory10 = category10;
  14267. exports.schemeCategory20b = category20b;
  14268. exports.schemeCategory20c = category20c;
  14269. exports.schemeCategory20 = category20;
  14270. exports.interpolateCubehelixDefault = cubehelix$3;
  14271. exports.interpolateRainbow = rainbow$1;
  14272. exports.interpolateWarm = warm;
  14273. exports.interpolateCool = cool;
  14274. exports.interpolateViridis = viridis;
  14275. exports.interpolateMagma = magma;
  14276. exports.interpolateInferno = inferno;
  14277. exports.interpolatePlasma = plasma;
  14278. exports.scaleSequential = sequential;
  14279. exports.creator = creator;
  14280. exports.local = local$1;
  14281. exports.matcher = matcher$1;
  14282. exports.mouse = mouse;
  14283. exports.namespace = namespace;
  14284. exports.namespaces = namespaces;
  14285. exports.select = select;
  14286. exports.selectAll = selectAll;
  14287. exports.selection = selection;
  14288. exports.selector = selector;
  14289. exports.selectorAll = selectorAll;
  14290. exports.style = styleValue;
  14291. exports.touch = touch;
  14292. exports.touches = touches;
  14293. exports.window = defaultView;
  14294. exports.customEvent = customEvent;
  14295. exports.arc = arc;
  14296. exports.area = area$2;
  14297. exports.line = line;
  14298. exports.pie = pie;
  14299. exports.areaRadial = areaRadial;
  14300. exports.radialArea = areaRadial;
  14301. exports.lineRadial = lineRadial$1;
  14302. exports.radialLine = lineRadial$1;
  14303. exports.pointRadial = pointRadial;
  14304. exports.linkHorizontal = linkHorizontal;
  14305. exports.linkVertical = linkVertical;
  14306. exports.linkRadial = linkRadial;
  14307. exports.symbol = symbol;
  14308. exports.symbols = symbols;
  14309. exports.symbolCircle = circle$2;
  14310. exports.symbolCross = cross$2;
  14311. exports.symbolDiamond = diamond;
  14312. exports.symbolSquare = square;
  14313. exports.symbolStar = star;
  14314. exports.symbolTriangle = triangle;
  14315. exports.symbolWye = wye;
  14316. exports.curveBasisClosed = basisClosed$1;
  14317. exports.curveBasisOpen = basisOpen;
  14318. exports.curveBasis = basis$2;
  14319. exports.curveBundle = bundle;
  14320. exports.curveCardinalClosed = cardinalClosed;
  14321. exports.curveCardinalOpen = cardinalOpen;
  14322. exports.curveCardinal = cardinal;
  14323. exports.curveCatmullRomClosed = catmullRomClosed;
  14324. exports.curveCatmullRomOpen = catmullRomOpen;
  14325. exports.curveCatmullRom = catmullRom;
  14326. exports.curveLinearClosed = linearClosed;
  14327. exports.curveLinear = curveLinear;
  14328. exports.curveMonotoneX = monotoneX;
  14329. exports.curveMonotoneY = monotoneY;
  14330. exports.curveNatural = natural;
  14331. exports.curveStep = step;
  14332. exports.curveStepAfter = stepAfter;
  14333. exports.curveStepBefore = stepBefore;
  14334. exports.stack = stack;
  14335. exports.stackOffsetExpand = expand;
  14336. exports.stackOffsetDiverging = diverging;
  14337. exports.stackOffsetNone = none$1;
  14338. exports.stackOffsetSilhouette = silhouette;
  14339. exports.stackOffsetWiggle = wiggle;
  14340. exports.stackOrderAscending = ascending$2;
  14341. exports.stackOrderDescending = descending$2;
  14342. exports.stackOrderInsideOut = insideOut;
  14343. exports.stackOrderNone = none$2;
  14344. exports.stackOrderReverse = reverse;
  14345. exports.timeInterval = newInterval;
  14346. exports.timeMillisecond = millisecond;
  14347. exports.timeMilliseconds = milliseconds;
  14348. exports.utcMillisecond = millisecond;
  14349. exports.utcMilliseconds = milliseconds;
  14350. exports.timeSecond = second;
  14351. exports.timeSeconds = seconds;
  14352. exports.utcSecond = second;
  14353. exports.utcSeconds = seconds;
  14354. exports.timeMinute = minute;
  14355. exports.timeMinutes = minutes;
  14356. exports.timeHour = hour;
  14357. exports.timeHours = hours;
  14358. exports.timeDay = day;
  14359. exports.timeDays = days;
  14360. exports.timeWeek = sunday;
  14361. exports.timeWeeks = sundays;
  14362. exports.timeSunday = sunday;
  14363. exports.timeSundays = sundays;
  14364. exports.timeMonday = monday;
  14365. exports.timeMondays = mondays;
  14366. exports.timeTuesday = tuesday;
  14367. exports.timeTuesdays = tuesdays;
  14368. exports.timeWednesday = wednesday;
  14369. exports.timeWednesdays = wednesdays;
  14370. exports.timeThursday = thursday;
  14371. exports.timeThursdays = thursdays;
  14372. exports.timeFriday = friday;
  14373. exports.timeFridays = fridays;
  14374. exports.timeSaturday = saturday;
  14375. exports.timeSaturdays = saturdays;
  14376. exports.timeMonth = month;
  14377. exports.timeMonths = months;
  14378. exports.timeYear = year;
  14379. exports.timeYears = years;
  14380. exports.utcMinute = utcMinute;
  14381. exports.utcMinutes = utcMinutes;
  14382. exports.utcHour = utcHour;
  14383. exports.utcHours = utcHours;
  14384. exports.utcDay = utcDay;
  14385. exports.utcDays = utcDays;
  14386. exports.utcWeek = utcSunday;
  14387. exports.utcWeeks = utcSundays;
  14388. exports.utcSunday = utcSunday;
  14389. exports.utcSundays = utcSundays;
  14390. exports.utcMonday = utcMonday;
  14391. exports.utcMondays = utcMondays;
  14392. exports.utcTuesday = utcTuesday;
  14393. exports.utcTuesdays = utcTuesdays;
  14394. exports.utcWednesday = utcWednesday;
  14395. exports.utcWednesdays = utcWednesdays;
  14396. exports.utcThursday = utcThursday;
  14397. exports.utcThursdays = utcThursdays;
  14398. exports.utcFriday = utcFriday;
  14399. exports.utcFridays = utcFridays;
  14400. exports.utcSaturday = utcSaturday;
  14401. exports.utcSaturdays = utcSaturdays;
  14402. exports.utcMonth = utcMonth;
  14403. exports.utcMonths = utcMonths;
  14404. exports.utcYear = utcYear;
  14405. exports.utcYears = utcYears;
  14406. exports.timeFormatDefaultLocale = defaultLocale$1;
  14407. exports.timeFormatLocale = formatLocale$1;
  14408. exports.isoFormat = formatIso;
  14409. exports.isoParse = parseIso;
  14410. exports.now = now;
  14411. exports.timer = timer;
  14412. exports.timerFlush = timerFlush;
  14413. exports.timeout = timeout$1;
  14414. exports.interval = interval$1;
  14415. exports.transition = transition;
  14416. exports.active = active;
  14417. exports.interrupt = interrupt;
  14418. exports.voronoi = voronoi;
  14419. exports.zoom = zoom;
  14420. exports.zoomTransform = transform$1;
  14421. exports.zoomIdentity = identity$8;
  14422. Object.defineProperty(exports, '__esModule', { value: true });
  14423. })));