d3.js 453 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866
  1. // https://d3js.org Version 4.9.1. Copyright 2017 Mike Bostock.
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (factory((global.d3 = global.d3 || {})));
  6. }(this, (function (exports) { 'use strict';
  7. var version = "4.9.1";
  8. var ascending = function(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. };
  11. var bisector = function(compare) {
  12. if (compare.length === 1) compare = ascendingComparator(compare);
  13. return {
  14. left: function(a, x, lo, hi) {
  15. if (lo == null) lo = 0;
  16. if (hi == null) hi = a.length;
  17. while (lo < hi) {
  18. var mid = lo + hi >>> 1;
  19. if (compare(a[mid], x) < 0) lo = mid + 1;
  20. else hi = mid;
  21. }
  22. return lo;
  23. },
  24. right: function(a, x, lo, hi) {
  25. if (lo == null) lo = 0;
  26. if (hi == null) hi = a.length;
  27. while (lo < hi) {
  28. var mid = lo + hi >>> 1;
  29. if (compare(a[mid], x) > 0) hi = mid;
  30. else lo = mid + 1;
  31. }
  32. return lo;
  33. }
  34. };
  35. };
  36. function ascendingComparator(f) {
  37. return function(d, x) {
  38. return ascending(f(d), x);
  39. };
  40. }
  41. var ascendingBisect = bisector(ascending);
  42. var bisectRight = ascendingBisect.right;
  43. var bisectLeft = ascendingBisect.left;
  44. var pairs = function(array, f) {
  45. if (f == null) f = pair;
  46. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  47. while (i < n) pairs[i] = f(p, p = array[++i]);
  48. return pairs;
  49. };
  50. function pair(a, b) {
  51. return [a, b];
  52. }
  53. var cross = function(values0, values1, reduce) {
  54. var n0 = values0.length,
  55. n1 = values1.length,
  56. values = new Array(n0 * n1),
  57. i0,
  58. i1,
  59. i,
  60. value0;
  61. if (reduce == null) reduce = pair;
  62. for (i0 = i = 0; i0 < n0; ++i0) {
  63. for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
  64. values[i] = reduce(value0, values1[i1]);
  65. }
  66. }
  67. return values;
  68. };
  69. var descending = function(a, b) {
  70. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  71. };
  72. var number = function(x) {
  73. return x === null ? NaN : +x;
  74. };
  75. var variance = function(values, valueof) {
  76. var n = values.length,
  77. m = 0,
  78. i = -1,
  79. mean = 0,
  80. value,
  81. delta,
  82. sum = 0;
  83. if (valueof == null) {
  84. while (++i < n) {
  85. if (!isNaN(value = number(values[i]))) {
  86. delta = value - mean;
  87. mean += delta / ++m;
  88. sum += delta * (value - mean);
  89. }
  90. }
  91. }
  92. else {
  93. while (++i < n) {
  94. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  95. delta = value - mean;
  96. mean += delta / ++m;
  97. sum += delta * (value - mean);
  98. }
  99. }
  100. }
  101. if (m > 1) return sum / (m - 1);
  102. };
  103. var deviation = function(array, f) {
  104. var v = variance(array, f);
  105. return v ? Math.sqrt(v) : v;
  106. };
  107. var extent = function(values, valueof) {
  108. var n = values.length,
  109. i = -1,
  110. value,
  111. min,
  112. max;
  113. if (valueof == null) {
  114. while (++i < n) { // Find the first comparable value.
  115. if ((value = values[i]) != null && value >= value) {
  116. min = max = value;
  117. while (++i < n) { // Compare the remaining values.
  118. if ((value = values[i]) != null) {
  119. if (min > value) min = value;
  120. if (max < value) max = value;
  121. }
  122. }
  123. }
  124. }
  125. }
  126. else {
  127. while (++i < n) { // Find the first comparable value.
  128. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  129. min = max = value;
  130. while (++i < n) { // Compare the remaining values.
  131. if ((value = valueof(values[i], i, values)) != null) {
  132. if (min > value) min = value;
  133. if (max < value) max = value;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. return [min, max];
  140. };
  141. var array = Array.prototype;
  142. var slice = array.slice;
  143. var map = array.map;
  144. var constant = function(x) {
  145. return function() {
  146. return x;
  147. };
  148. };
  149. var identity = function(x) {
  150. return x;
  151. };
  152. var sequence = function(start, stop, step) {
  153. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  154. var i = -1,
  155. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  156. range = new Array(n);
  157. while (++i < n) {
  158. range[i] = start + i * step;
  159. }
  160. return range;
  161. };
  162. var e10 = Math.sqrt(50);
  163. var e5 = Math.sqrt(10);
  164. var e2 = Math.sqrt(2);
  165. var ticks = function(start, stop, count) {
  166. var reverse = stop < start,
  167. i = -1,
  168. n,
  169. ticks,
  170. step;
  171. if (reverse) n = start, start = stop, stop = n;
  172. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  173. if (step > 0) {
  174. start = Math.ceil(start / step);
  175. stop = Math.floor(stop / step);
  176. ticks = new Array(n = Math.ceil(stop - start + 1));
  177. while (++i < n) ticks[i] = (start + i) * step;
  178. } else {
  179. start = Math.floor(start * step);
  180. stop = Math.ceil(stop * step);
  181. ticks = new Array(n = Math.ceil(start - stop + 1));
  182. while (++i < n) ticks[i] = (start - i) / step;
  183. }
  184. if (reverse) ticks.reverse();
  185. return ticks;
  186. };
  187. function tickIncrement(start, stop, count) {
  188. var step = (stop - start) / Math.max(0, count),
  189. power = Math.floor(Math.log(step) / Math.LN10),
  190. error = step / Math.pow(10, power);
  191. return power >= 0
  192. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  193. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  194. }
  195. function tickStep(start, stop, count) {
  196. var step0 = Math.abs(stop - start) / Math.max(0, count),
  197. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  198. error = step0 / step1;
  199. if (error >= e10) step1 *= 10;
  200. else if (error >= e5) step1 *= 5;
  201. else if (error >= e2) step1 *= 2;
  202. return stop < start ? -step1 : step1;
  203. }
  204. var sturges = function(values) {
  205. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  206. };
  207. var histogram = function() {
  208. var value = identity,
  209. domain = extent,
  210. threshold = sturges;
  211. function histogram(data) {
  212. var i,
  213. n = data.length,
  214. x,
  215. values = new Array(n);
  216. for (i = 0; i < n; ++i) {
  217. values[i] = value(data[i], i, data);
  218. }
  219. var xz = domain(values),
  220. x0 = xz[0],
  221. x1 = xz[1],
  222. tz = threshold(values, x0, x1);
  223. // Convert number of thresholds into uniform thresholds.
  224. if (!Array.isArray(tz)) {
  225. tz = tickStep(x0, x1, tz);
  226. tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
  227. }
  228. // Remove any thresholds outside the domain.
  229. var m = tz.length;
  230. while (tz[0] <= x0) tz.shift(), --m;
  231. while (tz[m - 1] > x1) tz.pop(), --m;
  232. var bins = new Array(m + 1),
  233. bin;
  234. // Initialize bins.
  235. for (i = 0; i <= m; ++i) {
  236. bin = bins[i] = [];
  237. bin.x0 = i > 0 ? tz[i - 1] : x0;
  238. bin.x1 = i < m ? tz[i] : x1;
  239. }
  240. // Assign data to bins by value, ignoring any outside the domain.
  241. for (i = 0; i < n; ++i) {
  242. x = values[i];
  243. if (x0 <= x && x <= x1) {
  244. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  245. }
  246. }
  247. return bins;
  248. }
  249. histogram.value = function(_) {
  250. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  251. };
  252. histogram.domain = function(_) {
  253. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  254. };
  255. histogram.thresholds = function(_) {
  256. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  257. };
  258. return histogram;
  259. };
  260. var threshold = function(values, p, valueof) {
  261. if (valueof == null) valueof = number;
  262. if (!(n = values.length)) return;
  263. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  264. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  265. var n,
  266. i = (n - 1) * p,
  267. i0 = Math.floor(i),
  268. value0 = +valueof(values[i0], i0, values),
  269. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  270. return value0 + (value1 - value0) * (i - i0);
  271. };
  272. var freedmanDiaconis = function(values, min, max) {
  273. values = map.call(values, number).sort(ascending);
  274. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  275. };
  276. var scott = function(values, min, max) {
  277. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  278. };
  279. var max = function(values, valueof) {
  280. var n = values.length,
  281. i = -1,
  282. value,
  283. max;
  284. if (valueof == null) {
  285. while (++i < n) { // Find the first comparable value.
  286. if ((value = values[i]) != null && value >= value) {
  287. max = value;
  288. while (++i < n) { // Compare the remaining values.
  289. if ((value = values[i]) != null && value > max) {
  290. max = value;
  291. }
  292. }
  293. }
  294. }
  295. }
  296. else {
  297. while (++i < n) { // Find the first comparable value.
  298. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  299. max = value;
  300. while (++i < n) { // Compare the remaining values.
  301. if ((value = valueof(values[i], i, values)) != null && value > max) {
  302. max = value;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. return max;
  309. };
  310. var mean = function(values, valueof) {
  311. var n = values.length,
  312. m = n,
  313. i = -1,
  314. value,
  315. sum = 0;
  316. if (valueof == null) {
  317. while (++i < n) {
  318. if (!isNaN(value = number(values[i]))) sum += value;
  319. else --m;
  320. }
  321. }
  322. else {
  323. while (++i < n) {
  324. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  325. else --m;
  326. }
  327. }
  328. if (m) return sum / m;
  329. };
  330. var median = function(values, valueof) {
  331. var n = values.length,
  332. i = -1,
  333. value,
  334. numbers = [];
  335. if (valueof == null) {
  336. while (++i < n) {
  337. if (!isNaN(value = number(values[i]))) {
  338. numbers.push(value);
  339. }
  340. }
  341. }
  342. else {
  343. while (++i < n) {
  344. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  345. numbers.push(value);
  346. }
  347. }
  348. }
  349. return threshold(numbers.sort(ascending), 0.5);
  350. };
  351. var merge = function(arrays) {
  352. var n = arrays.length,
  353. m,
  354. i = -1,
  355. j = 0,
  356. merged,
  357. array;
  358. while (++i < n) j += arrays[i].length;
  359. merged = new Array(j);
  360. while (--n >= 0) {
  361. array = arrays[n];
  362. m = array.length;
  363. while (--m >= 0) {
  364. merged[--j] = array[m];
  365. }
  366. }
  367. return merged;
  368. };
  369. var min = function(values, valueof) {
  370. var n = values.length,
  371. i = -1,
  372. value,
  373. min;
  374. if (valueof == null) {
  375. while (++i < n) { // Find the first comparable value.
  376. if ((value = values[i]) != null && value >= value) {
  377. min = value;
  378. while (++i < n) { // Compare the remaining values.
  379. if ((value = values[i]) != null && min > value) {
  380. min = value;
  381. }
  382. }
  383. }
  384. }
  385. }
  386. else {
  387. while (++i < n) { // Find the first comparable value.
  388. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  389. min = value;
  390. while (++i < n) { // Compare the remaining values.
  391. if ((value = valueof(values[i], i, values)) != null && min > value) {
  392. min = value;
  393. }
  394. }
  395. }
  396. }
  397. }
  398. return min;
  399. };
  400. var permute = function(array, indexes) {
  401. var i = indexes.length, permutes = new Array(i);
  402. while (i--) permutes[i] = array[indexes[i]];
  403. return permutes;
  404. };
  405. var scan = function(values, compare) {
  406. if (!(n = values.length)) return;
  407. var n,
  408. i = 0,
  409. j = 0,
  410. xi,
  411. xj = values[j];
  412. if (compare == null) compare = ascending;
  413. while (++i < n) {
  414. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  415. xj = xi, j = i;
  416. }
  417. }
  418. if (compare(xj, xj) === 0) return j;
  419. };
  420. var shuffle = function(array, i0, i1) {
  421. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  422. t,
  423. i;
  424. while (m) {
  425. i = Math.random() * m-- | 0;
  426. t = array[m + i0];
  427. array[m + i0] = array[i + i0];
  428. array[i + i0] = t;
  429. }
  430. return array;
  431. };
  432. var sum = function(values, valueof) {
  433. var n = values.length,
  434. i = -1,
  435. value,
  436. sum = 0;
  437. if (valueof == null) {
  438. while (++i < n) {
  439. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  440. }
  441. }
  442. else {
  443. while (++i < n) {
  444. if (value = +valueof(values[i], i, values)) sum += value;
  445. }
  446. }
  447. return sum;
  448. };
  449. var transpose = function(matrix) {
  450. if (!(n = matrix.length)) return [];
  451. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  452. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  453. row[j] = matrix[j][i];
  454. }
  455. }
  456. return transpose;
  457. };
  458. function length(d) {
  459. return d.length;
  460. }
  461. var zip = function() {
  462. return transpose(arguments);
  463. };
  464. var slice$1 = Array.prototype.slice;
  465. var identity$1 = function(x) {
  466. return x;
  467. };
  468. var top = 1;
  469. var right = 2;
  470. var bottom = 3;
  471. var left = 4;
  472. var epsilon = 1e-6;
  473. function translateX(x) {
  474. return "translate(" + (x + 0.5) + ",0)";
  475. }
  476. function translateY(y) {
  477. return "translate(0," + (y + 0.5) + ")";
  478. }
  479. function center(scale) {
  480. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  481. if (scale.round()) offset = Math.round(offset);
  482. return function(d) {
  483. return scale(d) + offset;
  484. };
  485. }
  486. function entering() {
  487. return !this.__axis;
  488. }
  489. function axis(orient, scale) {
  490. var tickArguments = [],
  491. tickValues = null,
  492. tickFormat = null,
  493. tickSizeInner = 6,
  494. tickSizeOuter = 6,
  495. tickPadding = 3,
  496. k = orient === top || orient === left ? -1 : 1,
  497. x = orient === left || orient === right ? "x" : "y",
  498. transform = orient === top || orient === bottom ? translateX : translateY;
  499. function axis(context) {
  500. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  501. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  502. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  503. range = scale.range(),
  504. range0 = range[0] + 0.5,
  505. range1 = range[range.length - 1] + 0.5,
  506. position = (scale.bandwidth ? center : identity$1)(scale.copy()),
  507. selection = context.selection ? context.selection() : context,
  508. path = selection.selectAll(".domain").data([null]),
  509. tick = selection.selectAll(".tick").data(values, scale).order(),
  510. tickExit = tick.exit(),
  511. tickEnter = tick.enter().append("g").attr("class", "tick"),
  512. line = tick.select("line"),
  513. text = tick.select("text");
  514. path = path.merge(path.enter().insert("path", ".tick")
  515. .attr("class", "domain")
  516. .attr("stroke", "#000"));
  517. tick = tick.merge(tickEnter);
  518. line = line.merge(tickEnter.append("line")
  519. .attr("stroke", "#000")
  520. .attr(x + "2", k * tickSizeInner));
  521. text = text.merge(tickEnter.append("text")
  522. .attr("fill", "#000")
  523. .attr(x, k * spacing)
  524. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  525. if (context !== selection) {
  526. path = path.transition(context);
  527. tick = tick.transition(context);
  528. line = line.transition(context);
  529. text = text.transition(context);
  530. tickExit = tickExit.transition(context)
  531. .attr("opacity", epsilon)
  532. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  533. tickEnter
  534. .attr("opacity", epsilon)
  535. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  536. }
  537. tickExit.remove();
  538. path
  539. .attr("d", orient === left || orient == right
  540. ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
  541. : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
  542. tick
  543. .attr("opacity", 1)
  544. .attr("transform", function(d) { return transform(position(d)); });
  545. line
  546. .attr(x + "2", k * tickSizeInner);
  547. text
  548. .attr(x, k * spacing)
  549. .text(format);
  550. selection.filter(entering)
  551. .attr("fill", "none")
  552. .attr("font-size", 10)
  553. .attr("font-family", "sans-serif")
  554. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  555. selection
  556. .each(function() { this.__axis = position; });
  557. }
  558. axis.scale = function(_) {
  559. return arguments.length ? (scale = _, axis) : scale;
  560. };
  561. axis.ticks = function() {
  562. return tickArguments = slice$1.call(arguments), axis;
  563. };
  564. axis.tickArguments = function(_) {
  565. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  566. };
  567. axis.tickValues = function(_) {
  568. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  569. };
  570. axis.tickFormat = function(_) {
  571. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  572. };
  573. axis.tickSize = function(_) {
  574. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  575. };
  576. axis.tickSizeInner = function(_) {
  577. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  578. };
  579. axis.tickSizeOuter = function(_) {
  580. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  581. };
  582. axis.tickPadding = function(_) {
  583. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  584. };
  585. return axis;
  586. }
  587. function axisTop(scale) {
  588. return axis(top, scale);
  589. }
  590. function axisRight(scale) {
  591. return axis(right, scale);
  592. }
  593. function axisBottom(scale) {
  594. return axis(bottom, scale);
  595. }
  596. function axisLeft(scale) {
  597. return axis(left, scale);
  598. }
  599. var noop = {value: function() {}};
  600. function dispatch() {
  601. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  602. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  603. _[t] = [];
  604. }
  605. return new Dispatch(_);
  606. }
  607. function Dispatch(_) {
  608. this._ = _;
  609. }
  610. function parseTypenames(typenames, types) {
  611. return typenames.trim().split(/^|\s+/).map(function(t) {
  612. var name = "", i = t.indexOf(".");
  613. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  614. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  615. return {type: t, name: name};
  616. });
  617. }
  618. Dispatch.prototype = dispatch.prototype = {
  619. constructor: Dispatch,
  620. on: function(typename, callback) {
  621. var _ = this._,
  622. T = parseTypenames(typename + "", _),
  623. t,
  624. i = -1,
  625. n = T.length;
  626. // If no callback was specified, return the callback of the given type and name.
  627. if (arguments.length < 2) {
  628. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  629. return;
  630. }
  631. // If a type was specified, set the callback for the given type and name.
  632. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  633. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  634. while (++i < n) {
  635. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  636. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  637. }
  638. return this;
  639. },
  640. copy: function() {
  641. var copy = {}, _ = this._;
  642. for (var t in _) copy[t] = _[t].slice();
  643. return new Dispatch(copy);
  644. },
  645. call: function(type, that) {
  646. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  647. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  648. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  649. },
  650. apply: function(type, that, args) {
  651. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  652. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  653. }
  654. };
  655. function get(type, name) {
  656. for (var i = 0, n = type.length, c; i < n; ++i) {
  657. if ((c = type[i]).name === name) {
  658. return c.value;
  659. }
  660. }
  661. }
  662. function set(type, name, callback) {
  663. for (var i = 0, n = type.length; i < n; ++i) {
  664. if (type[i].name === name) {
  665. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  666. break;
  667. }
  668. }
  669. if (callback != null) type.push({name: name, value: callback});
  670. return type;
  671. }
  672. var xhtml = "http://www.w3.org/1999/xhtml";
  673. var namespaces = {
  674. svg: "http://www.w3.org/2000/svg",
  675. xhtml: xhtml,
  676. xlink: "http://www.w3.org/1999/xlink",
  677. xml: "http://www.w3.org/XML/1998/namespace",
  678. xmlns: "http://www.w3.org/2000/xmlns/"
  679. };
  680. var namespace = function(name) {
  681. var prefix = name += "", i = prefix.indexOf(":");
  682. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  683. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  684. };
  685. function creatorInherit(name) {
  686. return function() {
  687. var document = this.ownerDocument,
  688. uri = this.namespaceURI;
  689. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  690. ? document.createElement(name)
  691. : document.createElementNS(uri, name);
  692. };
  693. }
  694. function creatorFixed(fullname) {
  695. return function() {
  696. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  697. };
  698. }
  699. var creator = function(name) {
  700. var fullname = namespace(name);
  701. return (fullname.local
  702. ? creatorFixed
  703. : creatorInherit)(fullname);
  704. };
  705. var nextId = 0;
  706. function local$1() {
  707. return new Local;
  708. }
  709. function Local() {
  710. this._ = "@" + (++nextId).toString(36);
  711. }
  712. Local.prototype = local$1.prototype = {
  713. constructor: Local,
  714. get: function(node) {
  715. var id = this._;
  716. while (!(id in node)) if (!(node = node.parentNode)) return;
  717. return node[id];
  718. },
  719. set: function(node, value) {
  720. return node[this._] = value;
  721. },
  722. remove: function(node) {
  723. return this._ in node && delete node[this._];
  724. },
  725. toString: function() {
  726. return this._;
  727. }
  728. };
  729. var matcher = function(selector) {
  730. return function() {
  731. return this.matches(selector);
  732. };
  733. };
  734. if (typeof document !== "undefined") {
  735. var element = document.documentElement;
  736. if (!element.matches) {
  737. var vendorMatches = element.webkitMatchesSelector
  738. || element.msMatchesSelector
  739. || element.mozMatchesSelector
  740. || element.oMatchesSelector;
  741. matcher = function(selector) {
  742. return function() {
  743. return vendorMatches.call(this, selector);
  744. };
  745. };
  746. }
  747. }
  748. var matcher$1 = matcher;
  749. var filterEvents = {};
  750. exports.event = null;
  751. if (typeof document !== "undefined") {
  752. var element$1 = document.documentElement;
  753. if (!("onmouseenter" in element$1)) {
  754. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  755. }
  756. }
  757. function filterContextListener(listener, index, group) {
  758. listener = contextListener(listener, index, group);
  759. return function(event) {
  760. var related = event.relatedTarget;
  761. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  762. listener.call(this, event);
  763. }
  764. };
  765. }
  766. function contextListener(listener, index, group) {
  767. return function(event1) {
  768. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  769. exports.event = event1;
  770. try {
  771. listener.call(this, this.__data__, index, group);
  772. } finally {
  773. exports.event = event0;
  774. }
  775. };
  776. }
  777. function parseTypenames$1(typenames) {
  778. return typenames.trim().split(/^|\s+/).map(function(t) {
  779. var name = "", i = t.indexOf(".");
  780. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  781. return {type: t, name: name};
  782. });
  783. }
  784. function onRemove(typename) {
  785. return function() {
  786. var on = this.__on;
  787. if (!on) return;
  788. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  789. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  790. this.removeEventListener(o.type, o.listener, o.capture);
  791. } else {
  792. on[++i] = o;
  793. }
  794. }
  795. if (++i) on.length = i;
  796. else delete this.__on;
  797. };
  798. }
  799. function onAdd(typename, value, capture) {
  800. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  801. return function(d, i, group) {
  802. var on = this.__on, o, listener = wrap(value, i, group);
  803. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  804. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  805. this.removeEventListener(o.type, o.listener, o.capture);
  806. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  807. o.value = value;
  808. return;
  809. }
  810. }
  811. this.addEventListener(typename.type, listener, capture);
  812. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  813. if (!on) this.__on = [o];
  814. else on.push(o);
  815. };
  816. }
  817. var selection_on = function(typename, value, capture) {
  818. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  819. if (arguments.length < 2) {
  820. var on = this.node().__on;
  821. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  822. for (i = 0, o = on[j]; i < n; ++i) {
  823. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  824. return o.value;
  825. }
  826. }
  827. }
  828. return;
  829. }
  830. on = value ? onAdd : onRemove;
  831. if (capture == null) capture = false;
  832. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  833. return this;
  834. };
  835. function customEvent(event1, listener, that, args) {
  836. var event0 = exports.event;
  837. event1.sourceEvent = exports.event;
  838. exports.event = event1;
  839. try {
  840. return listener.apply(that, args);
  841. } finally {
  842. exports.event = event0;
  843. }
  844. }
  845. var sourceEvent = function() {
  846. var current = exports.event, source;
  847. while (source = current.sourceEvent) current = source;
  848. return current;
  849. };
  850. var point = function(node, event) {
  851. var svg = node.ownerSVGElement || node;
  852. if (svg.createSVGPoint) {
  853. var point = svg.createSVGPoint();
  854. point.x = event.clientX, point.y = event.clientY;
  855. point = point.matrixTransform(node.getScreenCTM().inverse());
  856. return [point.x, point.y];
  857. }
  858. var rect = node.getBoundingClientRect();
  859. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  860. };
  861. var mouse = function(node) {
  862. var event = sourceEvent();
  863. if (event.changedTouches) event = event.changedTouches[0];
  864. return point(node, event);
  865. };
  866. function none() {}
  867. var selector = function(selector) {
  868. return selector == null ? none : function() {
  869. return this.querySelector(selector);
  870. };
  871. };
  872. var selection_select = function(select) {
  873. if (typeof select !== "function") select = selector(select);
  874. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  875. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  876. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  877. if ("__data__" in node) subnode.__data__ = node.__data__;
  878. subgroup[i] = subnode;
  879. }
  880. }
  881. }
  882. return new Selection(subgroups, this._parents);
  883. };
  884. function empty$1() {
  885. return [];
  886. }
  887. var selectorAll = function(selector) {
  888. return selector == null ? empty$1 : function() {
  889. return this.querySelectorAll(selector);
  890. };
  891. };
  892. var selection_selectAll = function(select) {
  893. if (typeof select !== "function") select = selectorAll(select);
  894. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  895. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  896. if (node = group[i]) {
  897. subgroups.push(select.call(node, node.__data__, i, group));
  898. parents.push(node);
  899. }
  900. }
  901. }
  902. return new Selection(subgroups, parents);
  903. };
  904. var selection_filter = function(match) {
  905. if (typeof match !== "function") match = matcher$1(match);
  906. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  907. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  908. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  909. subgroup.push(node);
  910. }
  911. }
  912. }
  913. return new Selection(subgroups, this._parents);
  914. };
  915. var sparse = function(update) {
  916. return new Array(update.length);
  917. };
  918. var selection_enter = function() {
  919. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  920. };
  921. function EnterNode(parent, datum) {
  922. this.ownerDocument = parent.ownerDocument;
  923. this.namespaceURI = parent.namespaceURI;
  924. this._next = null;
  925. this._parent = parent;
  926. this.__data__ = datum;
  927. }
  928. EnterNode.prototype = {
  929. constructor: EnterNode,
  930. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  931. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  932. querySelector: function(selector) { return this._parent.querySelector(selector); },
  933. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  934. };
  935. var constant$1 = function(x) {
  936. return function() {
  937. return x;
  938. };
  939. };
  940. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  941. function bindIndex(parent, group, enter, update, exit, data) {
  942. var i = 0,
  943. node,
  944. groupLength = group.length,
  945. dataLength = data.length;
  946. // Put any non-null nodes that fit into update.
  947. // Put any null nodes into enter.
  948. // Put any remaining data into enter.
  949. for (; i < dataLength; ++i) {
  950. if (node = group[i]) {
  951. node.__data__ = data[i];
  952. update[i] = node;
  953. } else {
  954. enter[i] = new EnterNode(parent, data[i]);
  955. }
  956. }
  957. // Put any non-null nodes that don’t fit into exit.
  958. for (; i < groupLength; ++i) {
  959. if (node = group[i]) {
  960. exit[i] = node;
  961. }
  962. }
  963. }
  964. function bindKey(parent, group, enter, update, exit, data, key) {
  965. var i,
  966. node,
  967. nodeByKeyValue = {},
  968. groupLength = group.length,
  969. dataLength = data.length,
  970. keyValues = new Array(groupLength),
  971. keyValue;
  972. // Compute the key for each node.
  973. // If multiple nodes have the same key, the duplicates are added to exit.
  974. for (i = 0; i < groupLength; ++i) {
  975. if (node = group[i]) {
  976. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  977. if (keyValue in nodeByKeyValue) {
  978. exit[i] = node;
  979. } else {
  980. nodeByKeyValue[keyValue] = node;
  981. }
  982. }
  983. }
  984. // Compute the key for each datum.
  985. // If there a node associated with this key, join and add it to update.
  986. // If there is not (or the key is a duplicate), add it to enter.
  987. for (i = 0; i < dataLength; ++i) {
  988. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  989. if (node = nodeByKeyValue[keyValue]) {
  990. update[i] = node;
  991. node.__data__ = data[i];
  992. nodeByKeyValue[keyValue] = null;
  993. } else {
  994. enter[i] = new EnterNode(parent, data[i]);
  995. }
  996. }
  997. // Add any remaining nodes that were not bound to data to exit.
  998. for (i = 0; i < groupLength; ++i) {
  999. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  1000. exit[i] = node;
  1001. }
  1002. }
  1003. }
  1004. var selection_data = function(value, key) {
  1005. if (!value) {
  1006. data = new Array(this.size()), j = -1;
  1007. this.each(function(d) { data[++j] = d; });
  1008. return data;
  1009. }
  1010. var bind = key ? bindKey : bindIndex,
  1011. parents = this._parents,
  1012. groups = this._groups;
  1013. if (typeof value !== "function") value = constant$1(value);
  1014. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  1015. var parent = parents[j],
  1016. group = groups[j],
  1017. groupLength = group.length,
  1018. data = value.call(parent, parent && parent.__data__, j, parents),
  1019. dataLength = data.length,
  1020. enterGroup = enter[j] = new Array(dataLength),
  1021. updateGroup = update[j] = new Array(dataLength),
  1022. exitGroup = exit[j] = new Array(groupLength);
  1023. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  1024. // Now connect the enter nodes to their following update node, such that
  1025. // appendChild can insert the materialized enter node before this node,
  1026. // rather than at the end of the parent node.
  1027. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  1028. if (previous = enterGroup[i0]) {
  1029. if (i0 >= i1) i1 = i0 + 1;
  1030. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  1031. previous._next = next || null;
  1032. }
  1033. }
  1034. }
  1035. update = new Selection(update, parents);
  1036. update._enter = enter;
  1037. update._exit = exit;
  1038. return update;
  1039. };
  1040. var selection_exit = function() {
  1041. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  1042. };
  1043. var selection_merge = function(selection) {
  1044. for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  1045. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  1046. if (node = group0[i] || group1[i]) {
  1047. merge[i] = node;
  1048. }
  1049. }
  1050. }
  1051. for (; j < m0; ++j) {
  1052. merges[j] = groups0[j];
  1053. }
  1054. return new Selection(merges, this._parents);
  1055. };
  1056. var selection_order = function() {
  1057. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  1058. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  1059. if (node = group[i]) {
  1060. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  1061. next = node;
  1062. }
  1063. }
  1064. }
  1065. return this;
  1066. };
  1067. var selection_sort = function(compare) {
  1068. if (!compare) compare = ascending$1;
  1069. function compareNode(a, b) {
  1070. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  1071. }
  1072. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  1073. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  1074. if (node = group[i]) {
  1075. sortgroup[i] = node;
  1076. }
  1077. }
  1078. sortgroup.sort(compareNode);
  1079. }
  1080. return new Selection(sortgroups, this._parents).order();
  1081. };
  1082. function ascending$1(a, b) {
  1083. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  1084. }
  1085. var selection_call = function() {
  1086. var callback = arguments[0];
  1087. arguments[0] = this;
  1088. callback.apply(null, arguments);
  1089. return this;
  1090. };
  1091. var selection_nodes = function() {
  1092. var nodes = new Array(this.size()), i = -1;
  1093. this.each(function() { nodes[++i] = this; });
  1094. return nodes;
  1095. };
  1096. var selection_node = function() {
  1097. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1098. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  1099. var node = group[i];
  1100. if (node) return node;
  1101. }
  1102. }
  1103. return null;
  1104. };
  1105. var selection_size = function() {
  1106. var size = 0;
  1107. this.each(function() { ++size; });
  1108. return size;
  1109. };
  1110. var selection_empty = function() {
  1111. return !this.node();
  1112. };
  1113. var selection_each = function(callback) {
  1114. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1115. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  1116. if (node = group[i]) callback.call(node, node.__data__, i, group);
  1117. }
  1118. }
  1119. return this;
  1120. };
  1121. function attrRemove(name) {
  1122. return function() {
  1123. this.removeAttribute(name);
  1124. };
  1125. }
  1126. function attrRemoveNS(fullname) {
  1127. return function() {
  1128. this.removeAttributeNS(fullname.space, fullname.local);
  1129. };
  1130. }
  1131. function attrConstant(name, value) {
  1132. return function() {
  1133. this.setAttribute(name, value);
  1134. };
  1135. }
  1136. function attrConstantNS(fullname, value) {
  1137. return function() {
  1138. this.setAttributeNS(fullname.space, fullname.local, value);
  1139. };
  1140. }
  1141. function attrFunction(name, value) {
  1142. return function() {
  1143. var v = value.apply(this, arguments);
  1144. if (v == null) this.removeAttribute(name);
  1145. else this.setAttribute(name, v);
  1146. };
  1147. }
  1148. function attrFunctionNS(fullname, value) {
  1149. return function() {
  1150. var v = value.apply(this, arguments);
  1151. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1152. else this.setAttributeNS(fullname.space, fullname.local, v);
  1153. };
  1154. }
  1155. var selection_attr = function(name, value) {
  1156. var fullname = namespace(name);
  1157. if (arguments.length < 2) {
  1158. var node = this.node();
  1159. return fullname.local
  1160. ? node.getAttributeNS(fullname.space, fullname.local)
  1161. : node.getAttribute(fullname);
  1162. }
  1163. return this.each((value == null
  1164. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1165. ? (fullname.local ? attrFunctionNS : attrFunction)
  1166. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1167. };
  1168. var defaultView = function(node) {
  1169. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1170. || (node.document && node) // node is a Window
  1171. || node.defaultView; // node is a Document
  1172. };
  1173. function styleRemove(name) {
  1174. return function() {
  1175. this.style.removeProperty(name);
  1176. };
  1177. }
  1178. function styleConstant(name, value, priority) {
  1179. return function() {
  1180. this.style.setProperty(name, value, priority);
  1181. };
  1182. }
  1183. function styleFunction(name, value, priority) {
  1184. return function() {
  1185. var v = value.apply(this, arguments);
  1186. if (v == null) this.style.removeProperty(name);
  1187. else this.style.setProperty(name, v, priority);
  1188. };
  1189. }
  1190. var selection_style = function(name, value, priority) {
  1191. return arguments.length > 1
  1192. ? this.each((value == null
  1193. ? styleRemove : typeof value === "function"
  1194. ? styleFunction
  1195. : styleConstant)(name, value, priority == null ? "" : priority))
  1196. : styleValue(this.node(), name);
  1197. };
  1198. function styleValue(node, name) {
  1199. return node.style.getPropertyValue(name)
  1200. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1201. }
  1202. function propertyRemove(name) {
  1203. return function() {
  1204. delete this[name];
  1205. };
  1206. }
  1207. function propertyConstant(name, value) {
  1208. return function() {
  1209. this[name] = value;
  1210. };
  1211. }
  1212. function propertyFunction(name, value) {
  1213. return function() {
  1214. var v = value.apply(this, arguments);
  1215. if (v == null) delete this[name];
  1216. else this[name] = v;
  1217. };
  1218. }
  1219. var selection_property = function(name, value) {
  1220. return arguments.length > 1
  1221. ? this.each((value == null
  1222. ? propertyRemove : typeof value === "function"
  1223. ? propertyFunction
  1224. : propertyConstant)(name, value))
  1225. : this.node()[name];
  1226. };
  1227. function classArray(string) {
  1228. return string.trim().split(/^|\s+/);
  1229. }
  1230. function classList(node) {
  1231. return node.classList || new ClassList(node);
  1232. }
  1233. function ClassList(node) {
  1234. this._node = node;
  1235. this._names = classArray(node.getAttribute("class") || "");
  1236. }
  1237. ClassList.prototype = {
  1238. add: function(name) {
  1239. var i = this._names.indexOf(name);
  1240. if (i < 0) {
  1241. this._names.push(name);
  1242. this._node.setAttribute("class", this._names.join(" "));
  1243. }
  1244. },
  1245. remove: function(name) {
  1246. var i = this._names.indexOf(name);
  1247. if (i >= 0) {
  1248. this._names.splice(i, 1);
  1249. this._node.setAttribute("class", this._names.join(" "));
  1250. }
  1251. },
  1252. contains: function(name) {
  1253. return this._names.indexOf(name) >= 0;
  1254. }
  1255. };
  1256. function classedAdd(node, names) {
  1257. var list = classList(node), i = -1, n = names.length;
  1258. while (++i < n) list.add(names[i]);
  1259. }
  1260. function classedRemove(node, names) {
  1261. var list = classList(node), i = -1, n = names.length;
  1262. while (++i < n) list.remove(names[i]);
  1263. }
  1264. function classedTrue(names) {
  1265. return function() {
  1266. classedAdd(this, names);
  1267. };
  1268. }
  1269. function classedFalse(names) {
  1270. return function() {
  1271. classedRemove(this, names);
  1272. };
  1273. }
  1274. function classedFunction(names, value) {
  1275. return function() {
  1276. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1277. };
  1278. }
  1279. var selection_classed = function(name, value) {
  1280. var names = classArray(name + "");
  1281. if (arguments.length < 2) {
  1282. var list = classList(this.node()), i = -1, n = names.length;
  1283. while (++i < n) if (!list.contains(names[i])) return false;
  1284. return true;
  1285. }
  1286. return this.each((typeof value === "function"
  1287. ? classedFunction : value
  1288. ? classedTrue
  1289. : classedFalse)(names, value));
  1290. };
  1291. function textRemove() {
  1292. this.textContent = "";
  1293. }
  1294. function textConstant(value) {
  1295. return function() {
  1296. this.textContent = value;
  1297. };
  1298. }
  1299. function textFunction(value) {
  1300. return function() {
  1301. var v = value.apply(this, arguments);
  1302. this.textContent = v == null ? "" : v;
  1303. };
  1304. }
  1305. var selection_text = function(value) {
  1306. return arguments.length
  1307. ? this.each(value == null
  1308. ? textRemove : (typeof value === "function"
  1309. ? textFunction
  1310. : textConstant)(value))
  1311. : this.node().textContent;
  1312. };
  1313. function htmlRemove() {
  1314. this.innerHTML = "";
  1315. }
  1316. function htmlConstant(value) {
  1317. return function() {
  1318. this.innerHTML = value;
  1319. };
  1320. }
  1321. function htmlFunction(value) {
  1322. return function() {
  1323. var v = value.apply(this, arguments);
  1324. this.innerHTML = v == null ? "" : v;
  1325. };
  1326. }
  1327. var selection_html = function(value) {
  1328. return arguments.length
  1329. ? this.each(value == null
  1330. ? htmlRemove : (typeof value === "function"
  1331. ? htmlFunction
  1332. : htmlConstant)(value))
  1333. : this.node().innerHTML;
  1334. };
  1335. function raise() {
  1336. if (this.nextSibling) this.parentNode.appendChild(this);
  1337. }
  1338. var selection_raise = function() {
  1339. return this.each(raise);
  1340. };
  1341. function lower() {
  1342. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1343. }
  1344. var selection_lower = function() {
  1345. return this.each(lower);
  1346. };
  1347. var selection_append = function(name) {
  1348. var create = typeof name === "function" ? name : creator(name);
  1349. return this.select(function() {
  1350. return this.appendChild(create.apply(this, arguments));
  1351. });
  1352. };
  1353. function constantNull() {
  1354. return null;
  1355. }
  1356. var selection_insert = function(name, before) {
  1357. var create = typeof name === "function" ? name : creator(name),
  1358. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1359. return this.select(function() {
  1360. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1361. });
  1362. };
  1363. function remove() {
  1364. var parent = this.parentNode;
  1365. if (parent) parent.removeChild(this);
  1366. }
  1367. var selection_remove = function() {
  1368. return this.each(remove);
  1369. };
  1370. var selection_datum = function(value) {
  1371. return arguments.length
  1372. ? this.property("__data__", value)
  1373. : this.node().__data__;
  1374. };
  1375. function dispatchEvent(node, type, params) {
  1376. var window = defaultView(node),
  1377. event = window.CustomEvent;
  1378. if (typeof event === "function") {
  1379. event = new event(type, params);
  1380. } else {
  1381. event = window.document.createEvent("Event");
  1382. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1383. else event.initEvent(type, false, false);
  1384. }
  1385. node.dispatchEvent(event);
  1386. }
  1387. function dispatchConstant(type, params) {
  1388. return function() {
  1389. return dispatchEvent(this, type, params);
  1390. };
  1391. }
  1392. function dispatchFunction(type, params) {
  1393. return function() {
  1394. return dispatchEvent(this, type, params.apply(this, arguments));
  1395. };
  1396. }
  1397. var selection_dispatch = function(type, params) {
  1398. return this.each((typeof params === "function"
  1399. ? dispatchFunction
  1400. : dispatchConstant)(type, params));
  1401. };
  1402. var root = [null];
  1403. function Selection(groups, parents) {
  1404. this._groups = groups;
  1405. this._parents = parents;
  1406. }
  1407. function selection() {
  1408. return new Selection([[document.documentElement]], root);
  1409. }
  1410. Selection.prototype = selection.prototype = {
  1411. constructor: Selection,
  1412. select: selection_select,
  1413. selectAll: selection_selectAll,
  1414. filter: selection_filter,
  1415. data: selection_data,
  1416. enter: selection_enter,
  1417. exit: selection_exit,
  1418. merge: selection_merge,
  1419. order: selection_order,
  1420. sort: selection_sort,
  1421. call: selection_call,
  1422. nodes: selection_nodes,
  1423. node: selection_node,
  1424. size: selection_size,
  1425. empty: selection_empty,
  1426. each: selection_each,
  1427. attr: selection_attr,
  1428. style: selection_style,
  1429. property: selection_property,
  1430. classed: selection_classed,
  1431. text: selection_text,
  1432. html: selection_html,
  1433. raise: selection_raise,
  1434. lower: selection_lower,
  1435. append: selection_append,
  1436. insert: selection_insert,
  1437. remove: selection_remove,
  1438. datum: selection_datum,
  1439. on: selection_on,
  1440. dispatch: selection_dispatch
  1441. };
  1442. var select = function(selector) {
  1443. return typeof selector === "string"
  1444. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1445. : new Selection([[selector]], root);
  1446. };
  1447. var selectAll = function(selector) {
  1448. return typeof selector === "string"
  1449. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1450. : new Selection([selector == null ? [] : selector], root);
  1451. };
  1452. var touch = function(node, touches, identifier) {
  1453. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1454. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1455. if ((touch = touches[i]).identifier === identifier) {
  1456. return point(node, touch);
  1457. }
  1458. }
  1459. return null;
  1460. };
  1461. var touches = function(node, touches) {
  1462. if (touches == null) touches = sourceEvent().touches;
  1463. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1464. points[i] = point(node, touches[i]);
  1465. }
  1466. return points;
  1467. };
  1468. function nopropagation() {
  1469. exports.event.stopImmediatePropagation();
  1470. }
  1471. var noevent = function() {
  1472. exports.event.preventDefault();
  1473. exports.event.stopImmediatePropagation();
  1474. };
  1475. var dragDisable = function(view) {
  1476. var root = view.document.documentElement,
  1477. selection$$1 = select(view).on("dragstart.drag", noevent, true);
  1478. if ("onselectstart" in root) {
  1479. selection$$1.on("selectstart.drag", noevent, true);
  1480. } else {
  1481. root.__noselect = root.style.MozUserSelect;
  1482. root.style.MozUserSelect = "none";
  1483. }
  1484. };
  1485. function yesdrag(view, noclick) {
  1486. var root = view.document.documentElement,
  1487. selection$$1 = select(view).on("dragstart.drag", null);
  1488. if (noclick) {
  1489. selection$$1.on("click.drag", noevent, true);
  1490. setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
  1491. }
  1492. if ("onselectstart" in root) {
  1493. selection$$1.on("selectstart.drag", null);
  1494. } else {
  1495. root.style.MozUserSelect = root.__noselect;
  1496. delete root.__noselect;
  1497. }
  1498. }
  1499. var constant$2 = function(x) {
  1500. return function() {
  1501. return x;
  1502. };
  1503. };
  1504. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1505. this.target = target;
  1506. this.type = type;
  1507. this.subject = subject;
  1508. this.identifier = id;
  1509. this.active = active;
  1510. this.x = x;
  1511. this.y = y;
  1512. this.dx = dx;
  1513. this.dy = dy;
  1514. this._ = dispatch;
  1515. }
  1516. DragEvent.prototype.on = function() {
  1517. var value = this._.on.apply(this._, arguments);
  1518. return value === this._ ? this : value;
  1519. };
  1520. // Ignore right-click, since that should open the context menu.
  1521. function defaultFilter$1() {
  1522. return !exports.event.button;
  1523. }
  1524. function defaultContainer() {
  1525. return this.parentNode;
  1526. }
  1527. function defaultSubject(d) {
  1528. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1529. }
  1530. var drag = function() {
  1531. var filter = defaultFilter$1,
  1532. container = defaultContainer,
  1533. subject = defaultSubject,
  1534. gestures = {},
  1535. listeners = dispatch("start", "drag", "end"),
  1536. active = 0,
  1537. mousedownx,
  1538. mousedowny,
  1539. mousemoving,
  1540. touchending,
  1541. clickDistance2 = 0;
  1542. function drag(selection$$1) {
  1543. selection$$1
  1544. .on("mousedown.drag", mousedowned)
  1545. .on("touchstart.drag", touchstarted)
  1546. .on("touchmove.drag", touchmoved)
  1547. .on("touchend.drag touchcancel.drag", touchended)
  1548. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1549. }
  1550. function mousedowned() {
  1551. if (touchending || !filter.apply(this, arguments)) return;
  1552. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1553. if (!gesture) return;
  1554. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1555. dragDisable(exports.event.view);
  1556. nopropagation();
  1557. mousemoving = false;
  1558. mousedownx = exports.event.clientX;
  1559. mousedowny = exports.event.clientY;
  1560. gesture("start");
  1561. }
  1562. function mousemoved() {
  1563. noevent();
  1564. if (!mousemoving) {
  1565. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1566. mousemoving = dx * dx + dy * dy > clickDistance2;
  1567. }
  1568. gestures.mouse("drag");
  1569. }
  1570. function mouseupped() {
  1571. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1572. yesdrag(exports.event.view, mousemoving);
  1573. noevent();
  1574. gestures.mouse("end");
  1575. }
  1576. function touchstarted() {
  1577. if (!filter.apply(this, arguments)) return;
  1578. var touches$$1 = exports.event.changedTouches,
  1579. c = container.apply(this, arguments),
  1580. n = touches$$1.length, i, gesture;
  1581. for (i = 0; i < n; ++i) {
  1582. if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
  1583. nopropagation();
  1584. gesture("start");
  1585. }
  1586. }
  1587. }
  1588. function touchmoved() {
  1589. var touches$$1 = exports.event.changedTouches,
  1590. n = touches$$1.length, i, gesture;
  1591. for (i = 0; i < n; ++i) {
  1592. if (gesture = gestures[touches$$1[i].identifier]) {
  1593. noevent();
  1594. gesture("drag");
  1595. }
  1596. }
  1597. }
  1598. function touchended() {
  1599. var touches$$1 = exports.event.changedTouches,
  1600. n = touches$$1.length, i, gesture;
  1601. if (touchending) clearTimeout(touchending);
  1602. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1603. for (i = 0; i < n; ++i) {
  1604. if (gesture = gestures[touches$$1[i].identifier]) {
  1605. nopropagation();
  1606. gesture("end");
  1607. }
  1608. }
  1609. }
  1610. function beforestart(id, container, point, that, args) {
  1611. var p = point(container, id), s, dx, dy,
  1612. sublisteners = listeners.copy();
  1613. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1614. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1615. dx = s.x - p[0] || 0;
  1616. dy = s.y - p[1] || 0;
  1617. return true;
  1618. })) return;
  1619. return function gesture(type) {
  1620. var p0 = p, n;
  1621. switch (type) {
  1622. case "start": gestures[id] = gesture, n = active++; break;
  1623. case "end": delete gestures[id], --active; // nobreak
  1624. case "drag": p = point(container, id), n = active; break;
  1625. }
  1626. 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]);
  1627. };
  1628. }
  1629. drag.filter = function(_) {
  1630. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1631. };
  1632. drag.container = function(_) {
  1633. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1634. };
  1635. drag.subject = function(_) {
  1636. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1637. };
  1638. drag.on = function() {
  1639. var value = listeners.on.apply(listeners, arguments);
  1640. return value === listeners ? drag : value;
  1641. };
  1642. drag.clickDistance = function(_) {
  1643. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1644. };
  1645. return drag;
  1646. };
  1647. var define = function(constructor, factory, prototype) {
  1648. constructor.prototype = factory.prototype = prototype;
  1649. prototype.constructor = constructor;
  1650. };
  1651. function extend(parent, definition) {
  1652. var prototype = Object.create(parent.prototype);
  1653. for (var key in definition) prototype[key] = definition[key];
  1654. return prototype;
  1655. }
  1656. function Color() {}
  1657. var darker = 0.7;
  1658. var brighter = 1 / darker;
  1659. var reI = "\\s*([+-]?\\d+)\\s*";
  1660. var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
  1661. var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
  1662. var reHex3 = /^#([0-9a-f]{3})$/;
  1663. var reHex6 = /^#([0-9a-f]{6})$/;
  1664. var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
  1665. var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
  1666. var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
  1667. var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
  1668. var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
  1669. var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1670. var named = {
  1671. aliceblue: 0xf0f8ff,
  1672. antiquewhite: 0xfaebd7,
  1673. aqua: 0x00ffff,
  1674. aquamarine: 0x7fffd4,
  1675. azure: 0xf0ffff,
  1676. beige: 0xf5f5dc,
  1677. bisque: 0xffe4c4,
  1678. black: 0x000000,
  1679. blanchedalmond: 0xffebcd,
  1680. blue: 0x0000ff,
  1681. blueviolet: 0x8a2be2,
  1682. brown: 0xa52a2a,
  1683. burlywood: 0xdeb887,
  1684. cadetblue: 0x5f9ea0,
  1685. chartreuse: 0x7fff00,
  1686. chocolate: 0xd2691e,
  1687. coral: 0xff7f50,
  1688. cornflowerblue: 0x6495ed,
  1689. cornsilk: 0xfff8dc,
  1690. crimson: 0xdc143c,
  1691. cyan: 0x00ffff,
  1692. darkblue: 0x00008b,
  1693. darkcyan: 0x008b8b,
  1694. darkgoldenrod: 0xb8860b,
  1695. darkgray: 0xa9a9a9,
  1696. darkgreen: 0x006400,
  1697. darkgrey: 0xa9a9a9,
  1698. darkkhaki: 0xbdb76b,
  1699. darkmagenta: 0x8b008b,
  1700. darkolivegreen: 0x556b2f,
  1701. darkorange: 0xff8c00,
  1702. darkorchid: 0x9932cc,
  1703. darkred: 0x8b0000,
  1704. darksalmon: 0xe9967a,
  1705. darkseagreen: 0x8fbc8f,
  1706. darkslateblue: 0x483d8b,
  1707. darkslategray: 0x2f4f4f,
  1708. darkslategrey: 0x2f4f4f,
  1709. darkturquoise: 0x00ced1,
  1710. darkviolet: 0x9400d3,
  1711. deeppink: 0xff1493,
  1712. deepskyblue: 0x00bfff,
  1713. dimgray: 0x696969,
  1714. dimgrey: 0x696969,
  1715. dodgerblue: 0x1e90ff,
  1716. firebrick: 0xb22222,
  1717. floralwhite: 0xfffaf0,
  1718. forestgreen: 0x228b22,
  1719. fuchsia: 0xff00ff,
  1720. gainsboro: 0xdcdcdc,
  1721. ghostwhite: 0xf8f8ff,
  1722. gold: 0xffd700,
  1723. goldenrod: 0xdaa520,
  1724. gray: 0x808080,
  1725. green: 0x008000,
  1726. greenyellow: 0xadff2f,
  1727. grey: 0x808080,
  1728. honeydew: 0xf0fff0,
  1729. hotpink: 0xff69b4,
  1730. indianred: 0xcd5c5c,
  1731. indigo: 0x4b0082,
  1732. ivory: 0xfffff0,
  1733. khaki: 0xf0e68c,
  1734. lavender: 0xe6e6fa,
  1735. lavenderblush: 0xfff0f5,
  1736. lawngreen: 0x7cfc00,
  1737. lemonchiffon: 0xfffacd,
  1738. lightblue: 0xadd8e6,
  1739. lightcoral: 0xf08080,
  1740. lightcyan: 0xe0ffff,
  1741. lightgoldenrodyellow: 0xfafad2,
  1742. lightgray: 0xd3d3d3,
  1743. lightgreen: 0x90ee90,
  1744. lightgrey: 0xd3d3d3,
  1745. lightpink: 0xffb6c1,
  1746. lightsalmon: 0xffa07a,
  1747. lightseagreen: 0x20b2aa,
  1748. lightskyblue: 0x87cefa,
  1749. lightslategray: 0x778899,
  1750. lightslategrey: 0x778899,
  1751. lightsteelblue: 0xb0c4de,
  1752. lightyellow: 0xffffe0,
  1753. lime: 0x00ff00,
  1754. limegreen: 0x32cd32,
  1755. linen: 0xfaf0e6,
  1756. magenta: 0xff00ff,
  1757. maroon: 0x800000,
  1758. mediumaquamarine: 0x66cdaa,
  1759. mediumblue: 0x0000cd,
  1760. mediumorchid: 0xba55d3,
  1761. mediumpurple: 0x9370db,
  1762. mediumseagreen: 0x3cb371,
  1763. mediumslateblue: 0x7b68ee,
  1764. mediumspringgreen: 0x00fa9a,
  1765. mediumturquoise: 0x48d1cc,
  1766. mediumvioletred: 0xc71585,
  1767. midnightblue: 0x191970,
  1768. mintcream: 0xf5fffa,
  1769. mistyrose: 0xffe4e1,
  1770. moccasin: 0xffe4b5,
  1771. navajowhite: 0xffdead,
  1772. navy: 0x000080,
  1773. oldlace: 0xfdf5e6,
  1774. olive: 0x808000,
  1775. olivedrab: 0x6b8e23,
  1776. orange: 0xffa500,
  1777. orangered: 0xff4500,
  1778. orchid: 0xda70d6,
  1779. palegoldenrod: 0xeee8aa,
  1780. palegreen: 0x98fb98,
  1781. paleturquoise: 0xafeeee,
  1782. palevioletred: 0xdb7093,
  1783. papayawhip: 0xffefd5,
  1784. peachpuff: 0xffdab9,
  1785. peru: 0xcd853f,
  1786. pink: 0xffc0cb,
  1787. plum: 0xdda0dd,
  1788. powderblue: 0xb0e0e6,
  1789. purple: 0x800080,
  1790. rebeccapurple: 0x663399,
  1791. red: 0xff0000,
  1792. rosybrown: 0xbc8f8f,
  1793. royalblue: 0x4169e1,
  1794. saddlebrown: 0x8b4513,
  1795. salmon: 0xfa8072,
  1796. sandybrown: 0xf4a460,
  1797. seagreen: 0x2e8b57,
  1798. seashell: 0xfff5ee,
  1799. sienna: 0xa0522d,
  1800. silver: 0xc0c0c0,
  1801. skyblue: 0x87ceeb,
  1802. slateblue: 0x6a5acd,
  1803. slategray: 0x708090,
  1804. slategrey: 0x708090,
  1805. snow: 0xfffafa,
  1806. springgreen: 0x00ff7f,
  1807. steelblue: 0x4682b4,
  1808. tan: 0xd2b48c,
  1809. teal: 0x008080,
  1810. thistle: 0xd8bfd8,
  1811. tomato: 0xff6347,
  1812. turquoise: 0x40e0d0,
  1813. violet: 0xee82ee,
  1814. wheat: 0xf5deb3,
  1815. white: 0xffffff,
  1816. whitesmoke: 0xf5f5f5,
  1817. yellow: 0xffff00,
  1818. yellowgreen: 0x9acd32
  1819. };
  1820. define(Color, color, {
  1821. displayable: function() {
  1822. return this.rgb().displayable();
  1823. },
  1824. toString: function() {
  1825. return this.rgb() + "";
  1826. }
  1827. });
  1828. function color(format) {
  1829. var m;
  1830. format = (format + "").trim().toLowerCase();
  1831. 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
  1832. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  1833. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1834. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1835. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1836. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1837. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1838. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1839. : named.hasOwnProperty(format) ? rgbn(named[format])
  1840. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1841. : null;
  1842. }
  1843. function rgbn(n) {
  1844. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1845. }
  1846. function rgba(r, g, b, a) {
  1847. if (a <= 0) r = g = b = NaN;
  1848. return new Rgb(r, g, b, a);
  1849. }
  1850. function rgbConvert(o) {
  1851. if (!(o instanceof Color)) o = color(o);
  1852. if (!o) return new Rgb;
  1853. o = o.rgb();
  1854. return new Rgb(o.r, o.g, o.b, o.opacity);
  1855. }
  1856. function rgb(r, g, b, opacity) {
  1857. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1858. }
  1859. function Rgb(r, g, b, opacity) {
  1860. this.r = +r;
  1861. this.g = +g;
  1862. this.b = +b;
  1863. this.opacity = +opacity;
  1864. }
  1865. define(Rgb, rgb, extend(Color, {
  1866. brighter: function(k) {
  1867. k = k == null ? brighter : Math.pow(brighter, k);
  1868. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1869. },
  1870. darker: function(k) {
  1871. k = k == null ? darker : Math.pow(darker, k);
  1872. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1873. },
  1874. rgb: function() {
  1875. return this;
  1876. },
  1877. displayable: function() {
  1878. return (0 <= this.r && this.r <= 255)
  1879. && (0 <= this.g && this.g <= 255)
  1880. && (0 <= this.b && this.b <= 255)
  1881. && (0 <= this.opacity && this.opacity <= 1);
  1882. },
  1883. toString: function() {
  1884. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1885. return (a === 1 ? "rgb(" : "rgba(")
  1886. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1887. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1888. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1889. + (a === 1 ? ")" : ", " + a + ")");
  1890. }
  1891. }));
  1892. function hsla(h, s, l, a) {
  1893. if (a <= 0) h = s = l = NaN;
  1894. else if (l <= 0 || l >= 1) h = s = NaN;
  1895. else if (s <= 0) h = NaN;
  1896. return new Hsl(h, s, l, a);
  1897. }
  1898. function hslConvert(o) {
  1899. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1900. if (!(o instanceof Color)) o = color(o);
  1901. if (!o) return new Hsl;
  1902. if (o instanceof Hsl) return o;
  1903. o = o.rgb();
  1904. var r = o.r / 255,
  1905. g = o.g / 255,
  1906. b = o.b / 255,
  1907. min = Math.min(r, g, b),
  1908. max = Math.max(r, g, b),
  1909. h = NaN,
  1910. s = max - min,
  1911. l = (max + min) / 2;
  1912. if (s) {
  1913. if (r === max) h = (g - b) / s + (g < b) * 6;
  1914. else if (g === max) h = (b - r) / s + 2;
  1915. else h = (r - g) / s + 4;
  1916. s /= l < 0.5 ? max + min : 2 - max - min;
  1917. h *= 60;
  1918. } else {
  1919. s = l > 0 && l < 1 ? 0 : h;
  1920. }
  1921. return new Hsl(h, s, l, o.opacity);
  1922. }
  1923. function hsl(h, s, l, opacity) {
  1924. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1925. }
  1926. function Hsl(h, s, l, opacity) {
  1927. this.h = +h;
  1928. this.s = +s;
  1929. this.l = +l;
  1930. this.opacity = +opacity;
  1931. }
  1932. define(Hsl, hsl, extend(Color, {
  1933. brighter: function(k) {
  1934. k = k == null ? brighter : Math.pow(brighter, k);
  1935. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1936. },
  1937. darker: function(k) {
  1938. k = k == null ? darker : Math.pow(darker, k);
  1939. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1940. },
  1941. rgb: function() {
  1942. var h = this.h % 360 + (this.h < 0) * 360,
  1943. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1944. l = this.l,
  1945. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1946. m1 = 2 * l - m2;
  1947. return new Rgb(
  1948. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  1949. hsl2rgb(h, m1, m2),
  1950. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  1951. this.opacity
  1952. );
  1953. },
  1954. displayable: function() {
  1955. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  1956. && (0 <= this.l && this.l <= 1)
  1957. && (0 <= this.opacity && this.opacity <= 1);
  1958. }
  1959. }));
  1960. /* From FvD 13.37, CSS Color Module Level 3 */
  1961. function hsl2rgb(h, m1, m2) {
  1962. return (h < 60 ? m1 + (m2 - m1) * h / 60
  1963. : h < 180 ? m2
  1964. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  1965. : m1) * 255;
  1966. }
  1967. var deg2rad = Math.PI / 180;
  1968. var rad2deg = 180 / Math.PI;
  1969. var Kn = 18;
  1970. var Xn = 0.950470;
  1971. var Yn = 1;
  1972. var Zn = 1.088830;
  1973. var t0 = 4 / 29;
  1974. var t1 = 6 / 29;
  1975. var t2 = 3 * t1 * t1;
  1976. var t3 = t1 * t1 * t1;
  1977. function labConvert(o) {
  1978. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  1979. if (o instanceof Hcl) {
  1980. var h = o.h * deg2rad;
  1981. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  1982. }
  1983. if (!(o instanceof Rgb)) o = rgbConvert(o);
  1984. var b = rgb2xyz(o.r),
  1985. a = rgb2xyz(o.g),
  1986. l = rgb2xyz(o.b),
  1987. x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
  1988. y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
  1989. z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
  1990. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  1991. }
  1992. function lab(l, a, b, opacity) {
  1993. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  1994. }
  1995. function Lab(l, a, b, opacity) {
  1996. this.l = +l;
  1997. this.a = +a;
  1998. this.b = +b;
  1999. this.opacity = +opacity;
  2000. }
  2001. define(Lab, lab, extend(Color, {
  2002. brighter: function(k) {
  2003. return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2004. },
  2005. darker: function(k) {
  2006. return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2007. },
  2008. rgb: function() {
  2009. var y = (this.l + 16) / 116,
  2010. x = isNaN(this.a) ? y : y + this.a / 500,
  2011. z = isNaN(this.b) ? y : y - this.b / 200;
  2012. y = Yn * lab2xyz(y);
  2013. x = Xn * lab2xyz(x);
  2014. z = Zn * lab2xyz(z);
  2015. return new Rgb(
  2016. xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
  2017. xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
  2018. xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
  2019. this.opacity
  2020. );
  2021. }
  2022. }));
  2023. function xyz2lab(t) {
  2024. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2025. }
  2026. function lab2xyz(t) {
  2027. return t > t1 ? t * t * t : t2 * (t - t0);
  2028. }
  2029. function xyz2rgb(x) {
  2030. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2031. }
  2032. function rgb2xyz(x) {
  2033. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2034. }
  2035. function hclConvert(o) {
  2036. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2037. if (!(o instanceof Lab)) o = labConvert(o);
  2038. var h = Math.atan2(o.b, o.a) * rad2deg;
  2039. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2040. }
  2041. function hcl(h, c, l, opacity) {
  2042. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2043. }
  2044. function Hcl(h, c, l, opacity) {
  2045. this.h = +h;
  2046. this.c = +c;
  2047. this.l = +l;
  2048. this.opacity = +opacity;
  2049. }
  2050. define(Hcl, hcl, extend(Color, {
  2051. brighter: function(k) {
  2052. return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
  2053. },
  2054. darker: function(k) {
  2055. return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
  2056. },
  2057. rgb: function() {
  2058. return labConvert(this).rgb();
  2059. }
  2060. }));
  2061. var A = -0.14861;
  2062. var B = +1.78277;
  2063. var C = -0.29227;
  2064. var D = -0.90649;
  2065. var E = +1.97294;
  2066. var ED = E * D;
  2067. var EB = E * B;
  2068. var BC_DA = B * C - D * A;
  2069. function cubehelixConvert(o) {
  2070. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2071. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2072. var r = o.r / 255,
  2073. g = o.g / 255,
  2074. b = o.b / 255,
  2075. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2076. bl = b - l,
  2077. k = (E * (g - l) - C * bl) / D,
  2078. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2079. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2080. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2081. }
  2082. function cubehelix(h, s, l, opacity) {
  2083. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2084. }
  2085. function Cubehelix(h, s, l, opacity) {
  2086. this.h = +h;
  2087. this.s = +s;
  2088. this.l = +l;
  2089. this.opacity = +opacity;
  2090. }
  2091. define(Cubehelix, cubehelix, extend(Color, {
  2092. brighter: function(k) {
  2093. k = k == null ? brighter : Math.pow(brighter, k);
  2094. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2095. },
  2096. darker: function(k) {
  2097. k = k == null ? darker : Math.pow(darker, k);
  2098. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2099. },
  2100. rgb: function() {
  2101. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2102. l = +this.l,
  2103. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2104. cosh = Math.cos(h),
  2105. sinh = Math.sin(h);
  2106. return new Rgb(
  2107. 255 * (l + a * (A * cosh + B * sinh)),
  2108. 255 * (l + a * (C * cosh + D * sinh)),
  2109. 255 * (l + a * (E * cosh)),
  2110. this.opacity
  2111. );
  2112. }
  2113. }));
  2114. function basis(t1, v0, v1, v2, v3) {
  2115. var t2 = t1 * t1, t3 = t2 * t1;
  2116. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2117. + (4 - 6 * t2 + 3 * t3) * v1
  2118. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2119. + t3 * v3) / 6;
  2120. }
  2121. var basis$1 = function(values) {
  2122. var n = values.length - 1;
  2123. return function(t) {
  2124. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2125. v1 = values[i],
  2126. v2 = values[i + 1],
  2127. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2128. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2129. return basis((t - i / n) * n, v0, v1, v2, v3);
  2130. };
  2131. };
  2132. var basisClosed = function(values) {
  2133. var n = values.length;
  2134. return function(t) {
  2135. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2136. v0 = values[(i + n - 1) % n],
  2137. v1 = values[i % n],
  2138. v2 = values[(i + 1) % n],
  2139. v3 = values[(i + 2) % n];
  2140. return basis((t - i / n) * n, v0, v1, v2, v3);
  2141. };
  2142. };
  2143. var constant$3 = function(x) {
  2144. return function() {
  2145. return x;
  2146. };
  2147. };
  2148. function linear(a, d) {
  2149. return function(t) {
  2150. return a + t * d;
  2151. };
  2152. }
  2153. function exponential(a, b, y) {
  2154. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2155. return Math.pow(a + t * b, y);
  2156. };
  2157. }
  2158. function hue(a, b) {
  2159. var d = b - a;
  2160. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2161. }
  2162. function gamma(y) {
  2163. return (y = +y) === 1 ? nogamma : function(a, b) {
  2164. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2165. };
  2166. }
  2167. function nogamma(a, b) {
  2168. var d = b - a;
  2169. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2170. }
  2171. var interpolateRgb = ((function rgbGamma(y) {
  2172. var color$$1 = gamma(y);
  2173. function rgb$$1(start, end) {
  2174. var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
  2175. g = color$$1(start.g, end.g),
  2176. b = color$$1(start.b, end.b),
  2177. opacity = nogamma(start.opacity, end.opacity);
  2178. return function(t) {
  2179. start.r = r(t);
  2180. start.g = g(t);
  2181. start.b = b(t);
  2182. start.opacity = opacity(t);
  2183. return start + "";
  2184. };
  2185. }
  2186. rgb$$1.gamma = rgbGamma;
  2187. return rgb$$1;
  2188. }))(1);
  2189. function rgbSpline(spline) {
  2190. return function(colors) {
  2191. var n = colors.length,
  2192. r = new Array(n),
  2193. g = new Array(n),
  2194. b = new Array(n),
  2195. i, color$$1;
  2196. for (i = 0; i < n; ++i) {
  2197. color$$1 = rgb(colors[i]);
  2198. r[i] = color$$1.r || 0;
  2199. g[i] = color$$1.g || 0;
  2200. b[i] = color$$1.b || 0;
  2201. }
  2202. r = spline(r);
  2203. g = spline(g);
  2204. b = spline(b);
  2205. color$$1.opacity = 1;
  2206. return function(t) {
  2207. color$$1.r = r(t);
  2208. color$$1.g = g(t);
  2209. color$$1.b = b(t);
  2210. return color$$1 + "";
  2211. };
  2212. };
  2213. }
  2214. var rgbBasis = rgbSpline(basis$1);
  2215. var rgbBasisClosed = rgbSpline(basisClosed);
  2216. var array$1 = function(a, b) {
  2217. var nb = b ? b.length : 0,
  2218. na = a ? Math.min(nb, a.length) : 0,
  2219. x = new Array(nb),
  2220. c = new Array(nb),
  2221. i;
  2222. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2223. for (; i < nb; ++i) c[i] = b[i];
  2224. return function(t) {
  2225. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2226. return c;
  2227. };
  2228. };
  2229. var date = function(a, b) {
  2230. var d = new Date;
  2231. return a = +a, b -= a, function(t) {
  2232. return d.setTime(a + b * t), d;
  2233. };
  2234. };
  2235. var reinterpolate = function(a, b) {
  2236. return a = +a, b -= a, function(t) {
  2237. return a + b * t;
  2238. };
  2239. };
  2240. var object = function(a, b) {
  2241. var i = {},
  2242. c = {},
  2243. k;
  2244. if (a === null || typeof a !== "object") a = {};
  2245. if (b === null || typeof b !== "object") b = {};
  2246. for (k in b) {
  2247. if (k in a) {
  2248. i[k] = interpolateValue(a[k], b[k]);
  2249. } else {
  2250. c[k] = b[k];
  2251. }
  2252. }
  2253. return function(t) {
  2254. for (k in i) c[k] = i[k](t);
  2255. return c;
  2256. };
  2257. };
  2258. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
  2259. var reB = new RegExp(reA.source, "g");
  2260. function zero(b) {
  2261. return function() {
  2262. return b;
  2263. };
  2264. }
  2265. function one(b) {
  2266. return function(t) {
  2267. return b(t) + "";
  2268. };
  2269. }
  2270. var interpolateString = function(a, b) {
  2271. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2272. am, // current match in a
  2273. bm, // current match in b
  2274. bs, // string preceding current number in b, if any
  2275. i = -1, // index in s
  2276. s = [], // string constants and placeholders
  2277. q = []; // number interpolators
  2278. // Coerce inputs to strings.
  2279. a = a + "", b = b + "";
  2280. // Interpolate pairs of numbers in a & b.
  2281. while ((am = reA.exec(a))
  2282. && (bm = reB.exec(b))) {
  2283. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2284. bs = b.slice(bi, bs);
  2285. if (s[i]) s[i] += bs; // coalesce with previous string
  2286. else s[++i] = bs;
  2287. }
  2288. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2289. if (s[i]) s[i] += bm; // coalesce with previous string
  2290. else s[++i] = bm;
  2291. } else { // interpolate non-matching numbers
  2292. s[++i] = null;
  2293. q.push({i: i, x: reinterpolate(am, bm)});
  2294. }
  2295. bi = reB.lastIndex;
  2296. }
  2297. // Add remains of b.
  2298. if (bi < b.length) {
  2299. bs = b.slice(bi);
  2300. if (s[i]) s[i] += bs; // coalesce with previous string
  2301. else s[++i] = bs;
  2302. }
  2303. // Special optimization for only a single match.
  2304. // Otherwise, interpolate each of the numbers and rejoin the string.
  2305. return s.length < 2 ? (q[0]
  2306. ? one(q[0].x)
  2307. : zero(b))
  2308. : (b = q.length, function(t) {
  2309. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2310. return s.join("");
  2311. });
  2312. };
  2313. var interpolateValue = function(a, b) {
  2314. var t = typeof b, c;
  2315. return b == null || t === "boolean" ? constant$3(b)
  2316. : (t === "number" ? reinterpolate
  2317. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2318. : b instanceof color ? interpolateRgb
  2319. : b instanceof Date ? date
  2320. : Array.isArray(b) ? array$1
  2321. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2322. : reinterpolate)(a, b);
  2323. };
  2324. var interpolateRound = function(a, b) {
  2325. return a = +a, b -= a, function(t) {
  2326. return Math.round(a + b * t);
  2327. };
  2328. };
  2329. var degrees = 180 / Math.PI;
  2330. var identity$2 = {
  2331. translateX: 0,
  2332. translateY: 0,
  2333. rotate: 0,
  2334. skewX: 0,
  2335. scaleX: 1,
  2336. scaleY: 1
  2337. };
  2338. var decompose = function(a, b, c, d, e, f) {
  2339. var scaleX, scaleY, skewX;
  2340. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2341. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2342. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2343. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2344. return {
  2345. translateX: e,
  2346. translateY: f,
  2347. rotate: Math.atan2(b, a) * degrees,
  2348. skewX: Math.atan(skewX) * degrees,
  2349. scaleX: scaleX,
  2350. scaleY: scaleY
  2351. };
  2352. };
  2353. var cssNode;
  2354. var cssRoot;
  2355. var cssView;
  2356. var svgNode;
  2357. function parseCss(value) {
  2358. if (value === "none") return identity$2;
  2359. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2360. cssNode.style.transform = value;
  2361. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2362. cssRoot.removeChild(cssNode);
  2363. value = value.slice(7, -1).split(",");
  2364. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2365. }
  2366. function parseSvg(value) {
  2367. if (value == null) return identity$2;
  2368. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2369. svgNode.setAttribute("transform", value);
  2370. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2371. value = value.matrix;
  2372. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2373. }
  2374. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2375. function pop(s) {
  2376. return s.length ? s.pop() + " " : "";
  2377. }
  2378. function translate(xa, ya, xb, yb, s, q) {
  2379. if (xa !== xb || ya !== yb) {
  2380. var i = s.push("translate(", null, pxComma, null, pxParen);
  2381. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2382. } else if (xb || yb) {
  2383. s.push("translate(" + xb + pxComma + yb + pxParen);
  2384. }
  2385. }
  2386. function rotate(a, b, s, q) {
  2387. if (a !== b) {
  2388. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2389. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
  2390. } else if (b) {
  2391. s.push(pop(s) + "rotate(" + b + degParen);
  2392. }
  2393. }
  2394. function skewX(a, b, s, q) {
  2395. if (a !== b) {
  2396. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
  2397. } else if (b) {
  2398. s.push(pop(s) + "skewX(" + b + degParen);
  2399. }
  2400. }
  2401. function scale(xa, ya, xb, yb, s, q) {
  2402. if (xa !== xb || ya !== yb) {
  2403. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2404. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2405. } else if (xb !== 1 || yb !== 1) {
  2406. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2407. }
  2408. }
  2409. return function(a, b) {
  2410. var s = [], // string constants and placeholders
  2411. q = []; // number interpolators
  2412. a = parse(a), b = parse(b);
  2413. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2414. rotate(a.rotate, b.rotate, s, q);
  2415. skewX(a.skewX, b.skewX, s, q);
  2416. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2417. a = b = null; // gc
  2418. return function(t) {
  2419. var i = -1, n = q.length, o;
  2420. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2421. return s.join("");
  2422. };
  2423. };
  2424. }
  2425. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2426. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2427. var rho = Math.SQRT2;
  2428. var rho2 = 2;
  2429. var rho4 = 4;
  2430. var epsilon2 = 1e-12;
  2431. function cosh(x) {
  2432. return ((x = Math.exp(x)) + 1 / x) / 2;
  2433. }
  2434. function sinh(x) {
  2435. return ((x = Math.exp(x)) - 1 / x) / 2;
  2436. }
  2437. function tanh(x) {
  2438. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2439. }
  2440. // p0 = [ux0, uy0, w0]
  2441. // p1 = [ux1, uy1, w1]
  2442. var interpolateZoom = function(p0, p1) {
  2443. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2444. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2445. dx = ux1 - ux0,
  2446. dy = uy1 - uy0,
  2447. d2 = dx * dx + dy * dy,
  2448. i,
  2449. S;
  2450. // Special case for u0 ≅ u1.
  2451. if (d2 < epsilon2) {
  2452. S = Math.log(w1 / w0) / rho;
  2453. i = function(t) {
  2454. return [
  2455. ux0 + t * dx,
  2456. uy0 + t * dy,
  2457. w0 * Math.exp(rho * t * S)
  2458. ];
  2459. };
  2460. }
  2461. // General case.
  2462. else {
  2463. var d1 = Math.sqrt(d2),
  2464. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2465. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2466. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2467. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2468. S = (r1 - r0) / rho;
  2469. i = function(t) {
  2470. var s = t * S,
  2471. coshr0 = cosh(r0),
  2472. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2473. return [
  2474. ux0 + u * dx,
  2475. uy0 + u * dy,
  2476. w0 * coshr0 / cosh(rho * s + r0)
  2477. ];
  2478. };
  2479. }
  2480. i.duration = S * 1000;
  2481. return i;
  2482. };
  2483. function hsl$1(hue$$1) {
  2484. return function(start, end) {
  2485. var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
  2486. s = nogamma(start.s, end.s),
  2487. l = nogamma(start.l, end.l),
  2488. opacity = nogamma(start.opacity, end.opacity);
  2489. return function(t) {
  2490. start.h = h(t);
  2491. start.s = s(t);
  2492. start.l = l(t);
  2493. start.opacity = opacity(t);
  2494. return start + "";
  2495. };
  2496. }
  2497. }
  2498. var hsl$2 = hsl$1(hue);
  2499. var hslLong = hsl$1(nogamma);
  2500. function lab$1(start, end) {
  2501. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2502. a = nogamma(start.a, end.a),
  2503. b = nogamma(start.b, end.b),
  2504. opacity = nogamma(start.opacity, end.opacity);
  2505. return function(t) {
  2506. start.l = l(t);
  2507. start.a = a(t);
  2508. start.b = b(t);
  2509. start.opacity = opacity(t);
  2510. return start + "";
  2511. };
  2512. }
  2513. function hcl$1(hue$$1) {
  2514. return function(start, end) {
  2515. var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
  2516. c = nogamma(start.c, end.c),
  2517. l = nogamma(start.l, end.l),
  2518. opacity = nogamma(start.opacity, end.opacity);
  2519. return function(t) {
  2520. start.h = h(t);
  2521. start.c = c(t);
  2522. start.l = l(t);
  2523. start.opacity = opacity(t);
  2524. return start + "";
  2525. };
  2526. }
  2527. }
  2528. var hcl$2 = hcl$1(hue);
  2529. var hclLong = hcl$1(nogamma);
  2530. function cubehelix$1(hue$$1) {
  2531. return (function cubehelixGamma(y) {
  2532. y = +y;
  2533. function cubehelix$$1(start, end) {
  2534. var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2535. s = nogamma(start.s, end.s),
  2536. l = nogamma(start.l, end.l),
  2537. opacity = nogamma(start.opacity, end.opacity);
  2538. return function(t) {
  2539. start.h = h(t);
  2540. start.s = s(t);
  2541. start.l = l(Math.pow(t, y));
  2542. start.opacity = opacity(t);
  2543. return start + "";
  2544. };
  2545. }
  2546. cubehelix$$1.gamma = cubehelixGamma;
  2547. return cubehelix$$1;
  2548. })(1);
  2549. }
  2550. var cubehelix$2 = cubehelix$1(hue);
  2551. var cubehelixLong = cubehelix$1(nogamma);
  2552. var quantize = function(interpolator, n) {
  2553. var samples = new Array(n);
  2554. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2555. return samples;
  2556. };
  2557. var frame = 0;
  2558. var timeout = 0;
  2559. var interval = 0;
  2560. var pokeDelay = 1000;
  2561. var taskHead;
  2562. var taskTail;
  2563. var clockLast = 0;
  2564. var clockNow = 0;
  2565. var clockSkew = 0;
  2566. var clock = typeof performance === "object" && performance.now ? performance : Date;
  2567. var setFrame = typeof requestAnimationFrame === "function" ? requestAnimationFrame : function(f) { setTimeout(f, 17); };
  2568. function now() {
  2569. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2570. }
  2571. function clearNow() {
  2572. clockNow = 0;
  2573. }
  2574. function Timer() {
  2575. this._call =
  2576. this._time =
  2577. this._next = null;
  2578. }
  2579. Timer.prototype = timer.prototype = {
  2580. constructor: Timer,
  2581. restart: function(callback, delay, time) {
  2582. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2583. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2584. if (!this._next && taskTail !== this) {
  2585. if (taskTail) taskTail._next = this;
  2586. else taskHead = this;
  2587. taskTail = this;
  2588. }
  2589. this._call = callback;
  2590. this._time = time;
  2591. sleep();
  2592. },
  2593. stop: function() {
  2594. if (this._call) {
  2595. this._call = null;
  2596. this._time = Infinity;
  2597. sleep();
  2598. }
  2599. }
  2600. };
  2601. function timer(callback, delay, time) {
  2602. var t = new Timer;
  2603. t.restart(callback, delay, time);
  2604. return t;
  2605. }
  2606. function timerFlush() {
  2607. now(); // Get the current time, if not already set.
  2608. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2609. var t = taskHead, e;
  2610. while (t) {
  2611. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2612. t = t._next;
  2613. }
  2614. --frame;
  2615. }
  2616. function wake() {
  2617. clockNow = (clockLast = clock.now()) + clockSkew;
  2618. frame = timeout = 0;
  2619. try {
  2620. timerFlush();
  2621. } finally {
  2622. frame = 0;
  2623. nap();
  2624. clockNow = 0;
  2625. }
  2626. }
  2627. function poke() {
  2628. var now = clock.now(), delay = now - clockLast;
  2629. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2630. }
  2631. function nap() {
  2632. var t0, t1 = taskHead, t2, time = Infinity;
  2633. while (t1) {
  2634. if (t1._call) {
  2635. if (time > t1._time) time = t1._time;
  2636. t0 = t1, t1 = t1._next;
  2637. } else {
  2638. t2 = t1._next, t1._next = null;
  2639. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2640. }
  2641. }
  2642. taskTail = t0;
  2643. sleep(time);
  2644. }
  2645. function sleep(time) {
  2646. if (frame) return; // Soonest alarm already set, or will be.
  2647. if (timeout) timeout = clearTimeout(timeout);
  2648. var delay = time - clockNow;
  2649. if (delay > 24) {
  2650. if (time < Infinity) timeout = setTimeout(wake, delay);
  2651. if (interval) interval = clearInterval(interval);
  2652. } else {
  2653. if (!interval) clockLast = clockNow, interval = setInterval(poke, pokeDelay);
  2654. frame = 1, setFrame(wake);
  2655. }
  2656. }
  2657. var timeout$1 = function(callback, delay, time) {
  2658. var t = new Timer;
  2659. delay = delay == null ? 0 : +delay;
  2660. t.restart(function(elapsed) {
  2661. t.stop();
  2662. callback(elapsed + delay);
  2663. }, delay, time);
  2664. return t;
  2665. };
  2666. var interval$1 = function(callback, delay, time) {
  2667. var t = new Timer, total = delay;
  2668. if (delay == null) return t.restart(callback, delay, time), t;
  2669. delay = +delay, time = time == null ? now() : +time;
  2670. t.restart(function tick(elapsed) {
  2671. elapsed += total;
  2672. t.restart(tick, total += delay, time);
  2673. callback(elapsed);
  2674. }, delay, time);
  2675. return t;
  2676. };
  2677. var emptyOn = dispatch("start", "end", "interrupt");
  2678. var emptyTween = [];
  2679. var CREATED = 0;
  2680. var SCHEDULED = 1;
  2681. var STARTING = 2;
  2682. var STARTED = 3;
  2683. var RUNNING = 4;
  2684. var ENDING = 5;
  2685. var ENDED = 6;
  2686. var schedule = function(node, name, id, index, group, timing) {
  2687. var schedules = node.__transition;
  2688. if (!schedules) node.__transition = {};
  2689. else if (id in schedules) return;
  2690. create(node, id, {
  2691. name: name,
  2692. index: index, // For context during callback.
  2693. group: group, // For context during callback.
  2694. on: emptyOn,
  2695. tween: emptyTween,
  2696. time: timing.time,
  2697. delay: timing.delay,
  2698. duration: timing.duration,
  2699. ease: timing.ease,
  2700. timer: null,
  2701. state: CREATED
  2702. });
  2703. };
  2704. function init(node, id) {
  2705. var schedule = node.__transition;
  2706. if (!schedule || !(schedule = schedule[id]) || schedule.state > CREATED) throw new Error("too late");
  2707. return schedule;
  2708. }
  2709. function set$1(node, id) {
  2710. var schedule = node.__transition;
  2711. if (!schedule || !(schedule = schedule[id]) || schedule.state > STARTING) throw new Error("too late");
  2712. return schedule;
  2713. }
  2714. function get$1(node, id) {
  2715. var schedule = node.__transition;
  2716. if (!schedule || !(schedule = schedule[id])) throw new Error("too late");
  2717. return schedule;
  2718. }
  2719. function create(node, id, self) {
  2720. var schedules = node.__transition,
  2721. tween;
  2722. // Initialize the self timer when the transition is created.
  2723. // Note the actual delay is not known until the first callback!
  2724. schedules[id] = self;
  2725. self.timer = timer(schedule, 0, self.time);
  2726. function schedule(elapsed) {
  2727. self.state = SCHEDULED;
  2728. self.timer.restart(start, self.delay, self.time);
  2729. // If the elapsed delay is less than our first sleep, start immediately.
  2730. if (self.delay <= elapsed) start(elapsed - self.delay);
  2731. }
  2732. function start(elapsed) {
  2733. var i, j, n, o;
  2734. // If the state is not SCHEDULED, then we previously errored on start.
  2735. if (self.state !== SCHEDULED) return stop();
  2736. for (i in schedules) {
  2737. o = schedules[i];
  2738. if (o.name !== self.name) continue;
  2739. // While this element already has a starting transition during this frame,
  2740. // defer starting an interrupting transition until that transition has a
  2741. // chance to tick (and possibly end); see d3/d3-transition#54!
  2742. if (o.state === STARTED) return timeout$1(start);
  2743. // Interrupt the active transition, if any.
  2744. // Dispatch the interrupt event.
  2745. if (o.state === RUNNING) {
  2746. o.state = ENDED;
  2747. o.timer.stop();
  2748. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2749. delete schedules[i];
  2750. }
  2751. // Cancel any pre-empted transitions. No interrupt event is dispatched
  2752. // because the cancelled transitions never started. Note that this also
  2753. // removes this transition from the pending list!
  2754. else if (+i < id) {
  2755. o.state = ENDED;
  2756. o.timer.stop();
  2757. delete schedules[i];
  2758. }
  2759. }
  2760. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2761. // Note the transition may be canceled after start and before the first tick!
  2762. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2763. // Assuming this is successful, subsequent callbacks go straight to tick.
  2764. timeout$1(function() {
  2765. if (self.state === STARTED) {
  2766. self.state = RUNNING;
  2767. self.timer.restart(tick, self.delay, self.time);
  2768. tick(elapsed);
  2769. }
  2770. });
  2771. // Dispatch the start event.
  2772. // Note this must be done before the tween are initialized.
  2773. self.state = STARTING;
  2774. self.on.call("start", node, node.__data__, self.index, self.group);
  2775. if (self.state !== STARTING) return; // interrupted
  2776. self.state = STARTED;
  2777. // Initialize the tween, deleting null tween.
  2778. tween = new Array(n = self.tween.length);
  2779. for (i = 0, j = -1; i < n; ++i) {
  2780. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2781. tween[++j] = o;
  2782. }
  2783. }
  2784. tween.length = j + 1;
  2785. }
  2786. function tick(elapsed) {
  2787. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2788. i = -1,
  2789. n = tween.length;
  2790. while (++i < n) {
  2791. tween[i].call(null, t);
  2792. }
  2793. // Dispatch the end event.
  2794. if (self.state === ENDING) {
  2795. self.on.call("end", node, node.__data__, self.index, self.group);
  2796. stop();
  2797. }
  2798. }
  2799. function stop() {
  2800. self.state = ENDED;
  2801. self.timer.stop();
  2802. delete schedules[id];
  2803. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2804. delete node.__transition;
  2805. }
  2806. }
  2807. var interrupt = function(node, name) {
  2808. var schedules = node.__transition,
  2809. schedule,
  2810. active,
  2811. empty = true,
  2812. i;
  2813. if (!schedules) return;
  2814. name = name == null ? null : name + "";
  2815. for (i in schedules) {
  2816. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  2817. active = schedule.state > STARTING && schedule.state < ENDING;
  2818. schedule.state = ENDED;
  2819. schedule.timer.stop();
  2820. if (active) schedule.on.call("interrupt", node, node.__data__, schedule.index, schedule.group);
  2821. delete schedules[i];
  2822. }
  2823. if (empty) delete node.__transition;
  2824. };
  2825. var selection_interrupt = function(name) {
  2826. return this.each(function() {
  2827. interrupt(this, name);
  2828. });
  2829. };
  2830. function tweenRemove(id, name) {
  2831. var tween0, tween1;
  2832. return function() {
  2833. var schedule = set$1(this, id),
  2834. tween = schedule.tween;
  2835. // If this node shared tween with the previous node,
  2836. // just assign the updated shared tween and we’re done!
  2837. // Otherwise, copy-on-write.
  2838. if (tween !== tween0) {
  2839. tween1 = tween0 = tween;
  2840. for (var i = 0, n = tween1.length; i < n; ++i) {
  2841. if (tween1[i].name === name) {
  2842. tween1 = tween1.slice();
  2843. tween1.splice(i, 1);
  2844. break;
  2845. }
  2846. }
  2847. }
  2848. schedule.tween = tween1;
  2849. };
  2850. }
  2851. function tweenFunction(id, name, value) {
  2852. var tween0, tween1;
  2853. if (typeof value !== "function") throw new Error;
  2854. return function() {
  2855. var schedule = set$1(this, id),
  2856. tween = schedule.tween;
  2857. // If this node shared tween with the previous node,
  2858. // just assign the updated shared tween and we’re done!
  2859. // Otherwise, copy-on-write.
  2860. if (tween !== tween0) {
  2861. tween1 = (tween0 = tween).slice();
  2862. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2863. if (tween1[i].name === name) {
  2864. tween1[i] = t;
  2865. break;
  2866. }
  2867. }
  2868. if (i === n) tween1.push(t);
  2869. }
  2870. schedule.tween = tween1;
  2871. };
  2872. }
  2873. var transition_tween = function(name, value) {
  2874. var id = this._id;
  2875. name += "";
  2876. if (arguments.length < 2) {
  2877. var tween = get$1(this.node(), id).tween;
  2878. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2879. if ((t = tween[i]).name === name) {
  2880. return t.value;
  2881. }
  2882. }
  2883. return null;
  2884. }
  2885. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2886. };
  2887. function tweenValue(transition, name, value) {
  2888. var id = transition._id;
  2889. transition.each(function() {
  2890. var schedule = set$1(this, id);
  2891. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  2892. });
  2893. return function(node) {
  2894. return get$1(node, id).value[name];
  2895. };
  2896. }
  2897. var interpolate$$1 = function(a, b) {
  2898. var c;
  2899. return (typeof b === "number" ? reinterpolate
  2900. : b instanceof color ? interpolateRgb
  2901. : (c = color(b)) ? (b = c, interpolateRgb)
  2902. : interpolateString)(a, b);
  2903. };
  2904. function attrRemove$1(name) {
  2905. return function() {
  2906. this.removeAttribute(name);
  2907. };
  2908. }
  2909. function attrRemoveNS$1(fullname) {
  2910. return function() {
  2911. this.removeAttributeNS(fullname.space, fullname.local);
  2912. };
  2913. }
  2914. function attrConstant$1(name, interpolate$$1, value1) {
  2915. var value00,
  2916. interpolate0;
  2917. return function() {
  2918. var value0 = this.getAttribute(name);
  2919. return value0 === value1 ? null
  2920. : value0 === value00 ? interpolate0
  2921. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2922. };
  2923. }
  2924. function attrConstantNS$1(fullname, interpolate$$1, value1) {
  2925. var value00,
  2926. interpolate0;
  2927. return function() {
  2928. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  2929. return value0 === value1 ? null
  2930. : value0 === value00 ? interpolate0
  2931. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2932. };
  2933. }
  2934. function attrFunction$1(name, interpolate$$1, value) {
  2935. var value00,
  2936. value10,
  2937. interpolate0;
  2938. return function() {
  2939. var value0, value1 = value(this);
  2940. if (value1 == null) return void this.removeAttribute(name);
  2941. value0 = this.getAttribute(name);
  2942. return value0 === value1 ? null
  2943. : value0 === value00 && value1 === value10 ? interpolate0
  2944. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2945. };
  2946. }
  2947. function attrFunctionNS$1(fullname, interpolate$$1, value) {
  2948. var value00,
  2949. value10,
  2950. interpolate0;
  2951. return function() {
  2952. var value0, value1 = value(this);
  2953. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  2954. value0 = this.getAttributeNS(fullname.space, fullname.local);
  2955. return value0 === value1 ? null
  2956. : value0 === value00 && value1 === value10 ? interpolate0
  2957. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2958. };
  2959. }
  2960. var transition_attr = function(name, value) {
  2961. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$$1;
  2962. return this.attrTween(name, typeof value === "function"
  2963. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  2964. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  2965. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
  2966. };
  2967. function attrTweenNS(fullname, value) {
  2968. function tween() {
  2969. var node = this, i = value.apply(node, arguments);
  2970. return i && function(t) {
  2971. node.setAttributeNS(fullname.space, fullname.local, i(t));
  2972. };
  2973. }
  2974. tween._value = value;
  2975. return tween;
  2976. }
  2977. function attrTween(name, value) {
  2978. function tween() {
  2979. var node = this, i = value.apply(node, arguments);
  2980. return i && function(t) {
  2981. node.setAttribute(name, i(t));
  2982. };
  2983. }
  2984. tween._value = value;
  2985. return tween;
  2986. }
  2987. var transition_attrTween = function(name, value) {
  2988. var key = "attr." + name;
  2989. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  2990. if (value == null) return this.tween(key, null);
  2991. if (typeof value !== "function") throw new Error;
  2992. var fullname = namespace(name);
  2993. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  2994. };
  2995. function delayFunction(id, value) {
  2996. return function() {
  2997. init(this, id).delay = +value.apply(this, arguments);
  2998. };
  2999. }
  3000. function delayConstant(id, value) {
  3001. return value = +value, function() {
  3002. init(this, id).delay = value;
  3003. };
  3004. }
  3005. var transition_delay = function(value) {
  3006. var id = this._id;
  3007. return arguments.length
  3008. ? this.each((typeof value === "function"
  3009. ? delayFunction
  3010. : delayConstant)(id, value))
  3011. : get$1(this.node(), id).delay;
  3012. };
  3013. function durationFunction(id, value) {
  3014. return function() {
  3015. set$1(this, id).duration = +value.apply(this, arguments);
  3016. };
  3017. }
  3018. function durationConstant(id, value) {
  3019. return value = +value, function() {
  3020. set$1(this, id).duration = value;
  3021. };
  3022. }
  3023. var transition_duration = function(value) {
  3024. var id = this._id;
  3025. return arguments.length
  3026. ? this.each((typeof value === "function"
  3027. ? durationFunction
  3028. : durationConstant)(id, value))
  3029. : get$1(this.node(), id).duration;
  3030. };
  3031. function easeConstant(id, value) {
  3032. if (typeof value !== "function") throw new Error;
  3033. return function() {
  3034. set$1(this, id).ease = value;
  3035. };
  3036. }
  3037. var transition_ease = function(value) {
  3038. var id = this._id;
  3039. return arguments.length
  3040. ? this.each(easeConstant(id, value))
  3041. : get$1(this.node(), id).ease;
  3042. };
  3043. var transition_filter = function(match) {
  3044. if (typeof match !== "function") match = matcher$1(match);
  3045. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3046. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3047. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3048. subgroup.push(node);
  3049. }
  3050. }
  3051. }
  3052. return new Transition(subgroups, this._parents, this._name, this._id);
  3053. };
  3054. var transition_merge = function(transition) {
  3055. if (transition._id !== this._id) throw new Error;
  3056. for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  3057. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3058. if (node = group0[i] || group1[i]) {
  3059. merge[i] = node;
  3060. }
  3061. }
  3062. }
  3063. for (; j < m0; ++j) {
  3064. merges[j] = groups0[j];
  3065. }
  3066. return new Transition(merges, this._parents, this._name, this._id);
  3067. };
  3068. function start(name) {
  3069. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3070. var i = t.indexOf(".");
  3071. if (i >= 0) t = t.slice(0, i);
  3072. return !t || t === "start";
  3073. });
  3074. }
  3075. function onFunction(id, name, listener) {
  3076. var on0, on1, sit = start(name) ? init : set$1;
  3077. return function() {
  3078. var schedule = sit(this, id),
  3079. on = schedule.on;
  3080. // If this node shared a dispatch with the previous node,
  3081. // just assign the updated shared dispatch and we’re done!
  3082. // Otherwise, copy-on-write.
  3083. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3084. schedule.on = on1;
  3085. };
  3086. }
  3087. var transition_on = function(name, listener) {
  3088. var id = this._id;
  3089. return arguments.length < 2
  3090. ? get$1(this.node(), id).on.on(name)
  3091. : this.each(onFunction(id, name, listener));
  3092. };
  3093. function removeFunction(id) {
  3094. return function() {
  3095. var parent = this.parentNode;
  3096. for (var i in this.__transition) if (+i !== id) return;
  3097. if (parent) parent.removeChild(this);
  3098. };
  3099. }
  3100. var transition_remove = function() {
  3101. return this.on("end.remove", removeFunction(this._id));
  3102. };
  3103. var transition_select = function(select$$1) {
  3104. var name = this._name,
  3105. id = this._id;
  3106. if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
  3107. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3108. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3109. if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
  3110. if ("__data__" in node) subnode.__data__ = node.__data__;
  3111. subgroup[i] = subnode;
  3112. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3113. }
  3114. }
  3115. }
  3116. return new Transition(subgroups, this._parents, name, id);
  3117. };
  3118. var transition_selectAll = function(select$$1) {
  3119. var name = this._name,
  3120. id = this._id;
  3121. if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
  3122. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3123. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3124. if (node = group[i]) {
  3125. for (var children = select$$1.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3126. if (child = children[k]) {
  3127. schedule(child, name, id, k, children, inherit);
  3128. }
  3129. }
  3130. subgroups.push(children);
  3131. parents.push(node);
  3132. }
  3133. }
  3134. }
  3135. return new Transition(subgroups, parents, name, id);
  3136. };
  3137. var Selection$1 = selection.prototype.constructor;
  3138. var transition_selection = function() {
  3139. return new Selection$1(this._groups, this._parents);
  3140. };
  3141. function styleRemove$1(name, interpolate$$2) {
  3142. var value00,
  3143. value10,
  3144. interpolate0;
  3145. return function() {
  3146. var value0 = styleValue(this, name),
  3147. value1 = (this.style.removeProperty(name), styleValue(this, name));
  3148. return value0 === value1 ? null
  3149. : value0 === value00 && value1 === value10 ? interpolate0
  3150. : interpolate0 = interpolate$$2(value00 = value0, value10 = value1);
  3151. };
  3152. }
  3153. function styleRemoveEnd(name) {
  3154. return function() {
  3155. this.style.removeProperty(name);
  3156. };
  3157. }
  3158. function styleConstant$1(name, interpolate$$2, value1) {
  3159. var value00,
  3160. interpolate0;
  3161. return function() {
  3162. var value0 = styleValue(this, name);
  3163. return value0 === value1 ? null
  3164. : value0 === value00 ? interpolate0
  3165. : interpolate0 = interpolate$$2(value00 = value0, value1);
  3166. };
  3167. }
  3168. function styleFunction$1(name, interpolate$$2, value) {
  3169. var value00,
  3170. value10,
  3171. interpolate0;
  3172. return function() {
  3173. var value0 = styleValue(this, name),
  3174. value1 = value(this);
  3175. if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
  3176. return value0 === value1 ? null
  3177. : value0 === value00 && value1 === value10 ? interpolate0
  3178. : interpolate0 = interpolate$$2(value00 = value0, value10 = value1);
  3179. };
  3180. }
  3181. var transition_style = function(name, value, priority) {
  3182. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$$1;
  3183. return value == null ? this
  3184. .styleTween(name, styleRemove$1(name, i))
  3185. .on("end.style." + name, styleRemoveEnd(name))
  3186. : this.styleTween(name, typeof value === "function"
  3187. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  3188. : styleConstant$1(name, i, value + ""), priority);
  3189. };
  3190. function styleTween(name, value, priority) {
  3191. function tween() {
  3192. var node = this, i = value.apply(node, arguments);
  3193. return i && function(t) {
  3194. node.style.setProperty(name, i(t), priority);
  3195. };
  3196. }
  3197. tween._value = value;
  3198. return tween;
  3199. }
  3200. var transition_styleTween = function(name, value, priority) {
  3201. var key = "style." + (name += "");
  3202. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3203. if (value == null) return this.tween(key, null);
  3204. if (typeof value !== "function") throw new Error;
  3205. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3206. };
  3207. function textConstant$1(value) {
  3208. return function() {
  3209. this.textContent = value;
  3210. };
  3211. }
  3212. function textFunction$1(value) {
  3213. return function() {
  3214. var value1 = value(this);
  3215. this.textContent = value1 == null ? "" : value1;
  3216. };
  3217. }
  3218. var transition_text = function(value) {
  3219. return this.tween("text", typeof value === "function"
  3220. ? textFunction$1(tweenValue(this, "text", value))
  3221. : textConstant$1(value == null ? "" : value + ""));
  3222. };
  3223. var transition_transition = function() {
  3224. var name = this._name,
  3225. id0 = this._id,
  3226. id1 = newId();
  3227. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3228. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3229. if (node = group[i]) {
  3230. var inherit = get$1(node, id0);
  3231. schedule(node, name, id1, i, group, {
  3232. time: inherit.time + inherit.delay + inherit.duration,
  3233. delay: 0,
  3234. duration: inherit.duration,
  3235. ease: inherit.ease
  3236. });
  3237. }
  3238. }
  3239. }
  3240. return new Transition(groups, this._parents, name, id1);
  3241. };
  3242. var id = 0;
  3243. function Transition(groups, parents, name, id) {
  3244. this._groups = groups;
  3245. this._parents = parents;
  3246. this._name = name;
  3247. this._id = id;
  3248. }
  3249. function transition(name) {
  3250. return selection().transition(name);
  3251. }
  3252. function newId() {
  3253. return ++id;
  3254. }
  3255. var selection_prototype = selection.prototype;
  3256. Transition.prototype = transition.prototype = {
  3257. constructor: Transition,
  3258. select: transition_select,
  3259. selectAll: transition_selectAll,
  3260. filter: transition_filter,
  3261. merge: transition_merge,
  3262. selection: transition_selection,
  3263. transition: transition_transition,
  3264. call: selection_prototype.call,
  3265. nodes: selection_prototype.nodes,
  3266. node: selection_prototype.node,
  3267. size: selection_prototype.size,
  3268. empty: selection_prototype.empty,
  3269. each: selection_prototype.each,
  3270. on: transition_on,
  3271. attr: transition_attr,
  3272. attrTween: transition_attrTween,
  3273. style: transition_style,
  3274. styleTween: transition_styleTween,
  3275. text: transition_text,
  3276. remove: transition_remove,
  3277. tween: transition_tween,
  3278. delay: transition_delay,
  3279. duration: transition_duration,
  3280. ease: transition_ease
  3281. };
  3282. function linear$1(t) {
  3283. return +t;
  3284. }
  3285. function quadIn(t) {
  3286. return t * t;
  3287. }
  3288. function quadOut(t) {
  3289. return t * (2 - t);
  3290. }
  3291. function quadInOut(t) {
  3292. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3293. }
  3294. function cubicIn(t) {
  3295. return t * t * t;
  3296. }
  3297. function cubicOut(t) {
  3298. return --t * t * t + 1;
  3299. }
  3300. function cubicInOut(t) {
  3301. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3302. }
  3303. var exponent = 3;
  3304. var polyIn = (function custom(e) {
  3305. e = +e;
  3306. function polyIn(t) {
  3307. return Math.pow(t, e);
  3308. }
  3309. polyIn.exponent = custom;
  3310. return polyIn;
  3311. })(exponent);
  3312. var polyOut = (function custom(e) {
  3313. e = +e;
  3314. function polyOut(t) {
  3315. return 1 - Math.pow(1 - t, e);
  3316. }
  3317. polyOut.exponent = custom;
  3318. return polyOut;
  3319. })(exponent);
  3320. var polyInOut = (function custom(e) {
  3321. e = +e;
  3322. function polyInOut(t) {
  3323. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3324. }
  3325. polyInOut.exponent = custom;
  3326. return polyInOut;
  3327. })(exponent);
  3328. var pi = Math.PI;
  3329. var halfPi = pi / 2;
  3330. function sinIn(t) {
  3331. return 1 - Math.cos(t * halfPi);
  3332. }
  3333. function sinOut(t) {
  3334. return Math.sin(t * halfPi);
  3335. }
  3336. function sinInOut(t) {
  3337. return (1 - Math.cos(pi * t)) / 2;
  3338. }
  3339. function expIn(t) {
  3340. return Math.pow(2, 10 * t - 10);
  3341. }
  3342. function expOut(t) {
  3343. return 1 - Math.pow(2, -10 * t);
  3344. }
  3345. function expInOut(t) {
  3346. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3347. }
  3348. function circleIn(t) {
  3349. return 1 - Math.sqrt(1 - t * t);
  3350. }
  3351. function circleOut(t) {
  3352. return Math.sqrt(1 - --t * t);
  3353. }
  3354. function circleInOut(t) {
  3355. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3356. }
  3357. var b1 = 4 / 11;
  3358. var b2 = 6 / 11;
  3359. var b3 = 8 / 11;
  3360. var b4 = 3 / 4;
  3361. var b5 = 9 / 11;
  3362. var b6 = 10 / 11;
  3363. var b7 = 15 / 16;
  3364. var b8 = 21 / 22;
  3365. var b9 = 63 / 64;
  3366. var b0 = 1 / b1 / b1;
  3367. function bounceIn(t) {
  3368. return 1 - bounceOut(1 - t);
  3369. }
  3370. function bounceOut(t) {
  3371. 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;
  3372. }
  3373. function bounceInOut(t) {
  3374. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3375. }
  3376. var overshoot = 1.70158;
  3377. var backIn = (function custom(s) {
  3378. s = +s;
  3379. function backIn(t) {
  3380. return t * t * ((s + 1) * t - s);
  3381. }
  3382. backIn.overshoot = custom;
  3383. return backIn;
  3384. })(overshoot);
  3385. var backOut = (function custom(s) {
  3386. s = +s;
  3387. function backOut(t) {
  3388. return --t * t * ((s + 1) * t + s) + 1;
  3389. }
  3390. backOut.overshoot = custom;
  3391. return backOut;
  3392. })(overshoot);
  3393. var backInOut = (function custom(s) {
  3394. s = +s;
  3395. function backInOut(t) {
  3396. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3397. }
  3398. backInOut.overshoot = custom;
  3399. return backInOut;
  3400. })(overshoot);
  3401. var tau = 2 * Math.PI;
  3402. var amplitude = 1;
  3403. var period = 0.3;
  3404. var elasticIn = (function custom(a, p) {
  3405. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3406. function elasticIn(t) {
  3407. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3408. }
  3409. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3410. elasticIn.period = function(p) { return custom(a, p); };
  3411. return elasticIn;
  3412. })(amplitude, period);
  3413. var elasticOut = (function custom(a, p) {
  3414. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3415. function elasticOut(t) {
  3416. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3417. }
  3418. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3419. elasticOut.period = function(p) { return custom(a, p); };
  3420. return elasticOut;
  3421. })(amplitude, period);
  3422. var elasticInOut = (function custom(a, p) {
  3423. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3424. function elasticInOut(t) {
  3425. return ((t = t * 2 - 1) < 0
  3426. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3427. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3428. }
  3429. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3430. elasticInOut.period = function(p) { return custom(a, p); };
  3431. return elasticInOut;
  3432. })(amplitude, period);
  3433. var defaultTiming = {
  3434. time: null, // Set on use.
  3435. delay: 0,
  3436. duration: 250,
  3437. ease: cubicInOut
  3438. };
  3439. function inherit(node, id) {
  3440. var timing;
  3441. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3442. if (!(node = node.parentNode)) {
  3443. return defaultTiming.time = now(), defaultTiming;
  3444. }
  3445. }
  3446. return timing;
  3447. }
  3448. var selection_transition = function(name) {
  3449. var id,
  3450. timing;
  3451. if (name instanceof Transition) {
  3452. id = name._id, name = name._name;
  3453. } else {
  3454. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3455. }
  3456. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3457. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3458. if (node = group[i]) {
  3459. schedule(node, name, id, i, group, timing || inherit(node, id));
  3460. }
  3461. }
  3462. }
  3463. return new Transition(groups, this._parents, name, id);
  3464. };
  3465. selection.prototype.interrupt = selection_interrupt;
  3466. selection.prototype.transition = selection_transition;
  3467. var root$1 = [null];
  3468. var active = function(node, name) {
  3469. var schedules = node.__transition,
  3470. schedule,
  3471. i;
  3472. if (schedules) {
  3473. name = name == null ? null : name + "";
  3474. for (i in schedules) {
  3475. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  3476. return new Transition([[node]], root$1, name, +i);
  3477. }
  3478. }
  3479. }
  3480. return null;
  3481. };
  3482. var constant$4 = function(x) {
  3483. return function() {
  3484. return x;
  3485. };
  3486. };
  3487. var BrushEvent = function(target, type, selection) {
  3488. this.target = target;
  3489. this.type = type;
  3490. this.selection = selection;
  3491. };
  3492. function nopropagation$1() {
  3493. exports.event.stopImmediatePropagation();
  3494. }
  3495. var noevent$1 = function() {
  3496. exports.event.preventDefault();
  3497. exports.event.stopImmediatePropagation();
  3498. };
  3499. var MODE_DRAG = {name: "drag"};
  3500. var MODE_SPACE = {name: "space"};
  3501. var MODE_HANDLE = {name: "handle"};
  3502. var MODE_CENTER = {name: "center"};
  3503. var X = {
  3504. name: "x",
  3505. handles: ["e", "w"].map(type),
  3506. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  3507. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3508. };
  3509. var Y = {
  3510. name: "y",
  3511. handles: ["n", "s"].map(type),
  3512. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  3513. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3514. };
  3515. var XY = {
  3516. name: "xy",
  3517. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
  3518. input: function(xy) { return xy; },
  3519. output: function(xy) { return xy; }
  3520. };
  3521. var cursors = {
  3522. overlay: "crosshair",
  3523. selection: "move",
  3524. n: "ns-resize",
  3525. e: "ew-resize",
  3526. s: "ns-resize",
  3527. w: "ew-resize",
  3528. nw: "nwse-resize",
  3529. ne: "nesw-resize",
  3530. se: "nwse-resize",
  3531. sw: "nesw-resize"
  3532. };
  3533. var flipX = {
  3534. e: "w",
  3535. w: "e",
  3536. nw: "ne",
  3537. ne: "nw",
  3538. se: "sw",
  3539. sw: "se"
  3540. };
  3541. var flipY = {
  3542. n: "s",
  3543. s: "n",
  3544. nw: "sw",
  3545. ne: "se",
  3546. se: "ne",
  3547. sw: "nw"
  3548. };
  3549. var signsX = {
  3550. overlay: +1,
  3551. selection: +1,
  3552. n: null,
  3553. e: +1,
  3554. s: null,
  3555. w: -1,
  3556. nw: -1,
  3557. ne: +1,
  3558. se: +1,
  3559. sw: -1
  3560. };
  3561. var signsY = {
  3562. overlay: +1,
  3563. selection: +1,
  3564. n: -1,
  3565. e: null,
  3566. s: +1,
  3567. w: null,
  3568. nw: -1,
  3569. ne: -1,
  3570. se: +1,
  3571. sw: +1
  3572. };
  3573. function type(t) {
  3574. return {type: t};
  3575. }
  3576. // Ignore right-click, since that should open the context menu.
  3577. function defaultFilter() {
  3578. return !exports.event.button;
  3579. }
  3580. function defaultExtent() {
  3581. var svg = this.ownerSVGElement || this;
  3582. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3583. }
  3584. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3585. function local$$1(node) {
  3586. while (!node.__brush) if (!(node = node.parentNode)) return;
  3587. return node.__brush;
  3588. }
  3589. function empty(extent) {
  3590. return extent[0][0] === extent[1][0]
  3591. || extent[0][1] === extent[1][1];
  3592. }
  3593. function brushSelection(node) {
  3594. var state = node.__brush;
  3595. return state ? state.dim.output(state.selection) : null;
  3596. }
  3597. function brushX() {
  3598. return brush$1(X);
  3599. }
  3600. function brushY() {
  3601. return brush$1(Y);
  3602. }
  3603. var brush = function() {
  3604. return brush$1(XY);
  3605. };
  3606. function brush$1(dim) {
  3607. var extent = defaultExtent,
  3608. filter = defaultFilter,
  3609. listeners = dispatch(brush, "start", "brush", "end"),
  3610. handleSize = 6,
  3611. touchending;
  3612. function brush(group) {
  3613. var overlay = group
  3614. .property("__brush", initialize)
  3615. .selectAll(".overlay")
  3616. .data([type("overlay")]);
  3617. overlay.enter().append("rect")
  3618. .attr("class", "overlay")
  3619. .attr("pointer-events", "all")
  3620. .attr("cursor", cursors.overlay)
  3621. .merge(overlay)
  3622. .each(function() {
  3623. var extent = local$$1(this).extent;
  3624. select(this)
  3625. .attr("x", extent[0][0])
  3626. .attr("y", extent[0][1])
  3627. .attr("width", extent[1][0] - extent[0][0])
  3628. .attr("height", extent[1][1] - extent[0][1]);
  3629. });
  3630. group.selectAll(".selection")
  3631. .data([type("selection")])
  3632. .enter().append("rect")
  3633. .attr("class", "selection")
  3634. .attr("cursor", cursors.selection)
  3635. .attr("fill", "#777")
  3636. .attr("fill-opacity", 0.3)
  3637. .attr("stroke", "#fff")
  3638. .attr("shape-rendering", "crispEdges");
  3639. var handle = group.selectAll(".handle")
  3640. .data(dim.handles, function(d) { return d.type; });
  3641. handle.exit().remove();
  3642. handle.enter().append("rect")
  3643. .attr("class", function(d) { return "handle handle--" + d.type; })
  3644. .attr("cursor", function(d) { return cursors[d.type]; });
  3645. group
  3646. .each(redraw)
  3647. .attr("fill", "none")
  3648. .attr("pointer-events", "all")
  3649. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  3650. .on("mousedown.brush touchstart.brush", started);
  3651. }
  3652. brush.move = function(group, selection$$1) {
  3653. if (group.selection) {
  3654. group
  3655. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3656. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3657. .tween("brush", function() {
  3658. var that = this,
  3659. state = that.__brush,
  3660. emit = emitter(that, arguments),
  3661. selection0 = state.selection,
  3662. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
  3663. i = interpolateValue(selection0, selection1);
  3664. function tween(t) {
  3665. state.selection = t === 1 && empty(selection1) ? null : i(t);
  3666. redraw.call(that);
  3667. emit.brush();
  3668. }
  3669. return selection0 && selection1 ? tween : tween(1);
  3670. });
  3671. } else {
  3672. group
  3673. .each(function() {
  3674. var that = this,
  3675. args = arguments,
  3676. state = that.__brush,
  3677. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
  3678. emit = emitter(that, args).beforestart();
  3679. interrupt(that);
  3680. state.selection = selection1 == null || empty(selection1) ? null : selection1;
  3681. redraw.call(that);
  3682. emit.start().brush().end();
  3683. });
  3684. }
  3685. };
  3686. function redraw() {
  3687. var group = select(this),
  3688. selection$$1 = local$$1(this).selection;
  3689. if (selection$$1) {
  3690. group.selectAll(".selection")
  3691. .style("display", null)
  3692. .attr("x", selection$$1[0][0])
  3693. .attr("y", selection$$1[0][1])
  3694. .attr("width", selection$$1[1][0] - selection$$1[0][0])
  3695. .attr("height", selection$$1[1][1] - selection$$1[0][1]);
  3696. group.selectAll(".handle")
  3697. .style("display", null)
  3698. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
  3699. .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
  3700. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
  3701. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
  3702. }
  3703. else {
  3704. group.selectAll(".selection,.handle")
  3705. .style("display", "none")
  3706. .attr("x", null)
  3707. .attr("y", null)
  3708. .attr("width", null)
  3709. .attr("height", null);
  3710. }
  3711. }
  3712. function emitter(that, args) {
  3713. return that.__brush.emitter || new Emitter(that, args);
  3714. }
  3715. function Emitter(that, args) {
  3716. this.that = that;
  3717. this.args = args;
  3718. this.state = that.__brush;
  3719. this.active = 0;
  3720. }
  3721. Emitter.prototype = {
  3722. beforestart: function() {
  3723. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3724. return this;
  3725. },
  3726. start: function() {
  3727. if (this.starting) this.starting = false, this.emit("start");
  3728. return this;
  3729. },
  3730. brush: function() {
  3731. this.emit("brush");
  3732. return this;
  3733. },
  3734. end: function() {
  3735. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3736. return this;
  3737. },
  3738. emit: function(type) {
  3739. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3740. }
  3741. };
  3742. function started() {
  3743. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
  3744. else if (touchending) return;
  3745. if (!filter.apply(this, arguments)) return;
  3746. var that = this,
  3747. type = exports.event.target.__data__.type,
  3748. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3749. signX = dim === Y ? null : signsX[type],
  3750. signY = dim === X ? null : signsY[type],
  3751. state = local$$1(that),
  3752. extent = state.extent,
  3753. selection$$1 = state.selection,
  3754. W = extent[0][0], w0, w1,
  3755. N = extent[0][1], n0, n1,
  3756. E = extent[1][0], e0, e1,
  3757. S = extent[1][1], s0, s1,
  3758. dx,
  3759. dy,
  3760. moving,
  3761. shifting = signX && signY && exports.event.shiftKey,
  3762. lockX,
  3763. lockY,
  3764. point0 = mouse(that),
  3765. point = point0,
  3766. emit = emitter(that, arguments).beforestart();
  3767. if (type === "overlay") {
  3768. state.selection = selection$$1 = [
  3769. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3770. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3771. ];
  3772. } else {
  3773. w0 = selection$$1[0][0];
  3774. n0 = selection$$1[0][1];
  3775. e0 = selection$$1[1][0];
  3776. s0 = selection$$1[1][1];
  3777. }
  3778. w1 = w0;
  3779. n1 = n0;
  3780. e1 = e0;
  3781. s1 = s0;
  3782. var group = select(that)
  3783. .attr("pointer-events", "none");
  3784. var overlay = group.selectAll(".overlay")
  3785. .attr("cursor", cursors[type]);
  3786. if (exports.event.touches) {
  3787. group
  3788. .on("touchmove.brush", moved, true)
  3789. .on("touchend.brush touchcancel.brush", ended, true);
  3790. } else {
  3791. var view = select(exports.event.view)
  3792. .on("keydown.brush", keydowned, true)
  3793. .on("keyup.brush", keyupped, true)
  3794. .on("mousemove.brush", moved, true)
  3795. .on("mouseup.brush", ended, true);
  3796. dragDisable(exports.event.view);
  3797. }
  3798. nopropagation$1();
  3799. interrupt(that);
  3800. redraw.call(that);
  3801. emit.start();
  3802. function moved() {
  3803. var point1 = mouse(that);
  3804. if (shifting && !lockX && !lockY) {
  3805. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  3806. else lockX = true;
  3807. }
  3808. point = point1;
  3809. moving = true;
  3810. noevent$1();
  3811. move();
  3812. }
  3813. function move() {
  3814. var t;
  3815. dx = point[0] - point0[0];
  3816. dy = point[1] - point0[1];
  3817. switch (mode) {
  3818. case MODE_SPACE:
  3819. case MODE_DRAG: {
  3820. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  3821. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  3822. break;
  3823. }
  3824. case MODE_HANDLE: {
  3825. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  3826. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  3827. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  3828. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  3829. break;
  3830. }
  3831. case MODE_CENTER: {
  3832. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  3833. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  3834. break;
  3835. }
  3836. }
  3837. if (e1 < w1) {
  3838. signX *= -1;
  3839. t = w0, w0 = e0, e0 = t;
  3840. t = w1, w1 = e1, e1 = t;
  3841. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  3842. }
  3843. if (s1 < n1) {
  3844. signY *= -1;
  3845. t = n0, n0 = s0, s0 = t;
  3846. t = n1, n1 = s1, s1 = t;
  3847. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  3848. }
  3849. if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
  3850. if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
  3851. if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
  3852. if (selection$$1[0][0] !== w1
  3853. || selection$$1[0][1] !== n1
  3854. || selection$$1[1][0] !== e1
  3855. || selection$$1[1][1] !== s1) {
  3856. state.selection = [[w1, n1], [e1, s1]];
  3857. redraw.call(that);
  3858. emit.brush();
  3859. }
  3860. }
  3861. function ended() {
  3862. nopropagation$1();
  3863. if (exports.event.touches) {
  3864. if (exports.event.touches.length) return;
  3865. if (touchending) clearTimeout(touchending);
  3866. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  3867. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  3868. } else {
  3869. yesdrag(exports.event.view, moving);
  3870. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  3871. }
  3872. group.attr("pointer-events", "all");
  3873. overlay.attr("cursor", cursors.overlay);
  3874. if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
  3875. if (empty(selection$$1)) state.selection = null, redraw.call(that);
  3876. emit.end();
  3877. }
  3878. function keydowned() {
  3879. switch (exports.event.keyCode) {
  3880. case 16: { // SHIFT
  3881. shifting = signX && signY;
  3882. break;
  3883. }
  3884. case 18: { // ALT
  3885. if (mode === MODE_HANDLE) {
  3886. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3887. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3888. mode = MODE_CENTER;
  3889. move();
  3890. }
  3891. break;
  3892. }
  3893. case 32: { // SPACE; takes priority over ALT
  3894. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  3895. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  3896. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  3897. mode = MODE_SPACE;
  3898. overlay.attr("cursor", cursors.selection);
  3899. move();
  3900. }
  3901. break;
  3902. }
  3903. default: return;
  3904. }
  3905. noevent$1();
  3906. }
  3907. function keyupped() {
  3908. switch (exports.event.keyCode) {
  3909. case 16: { // SHIFT
  3910. if (shifting) {
  3911. lockX = lockY = shifting = false;
  3912. move();
  3913. }
  3914. break;
  3915. }
  3916. case 18: { // ALT
  3917. if (mode === MODE_CENTER) {
  3918. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3919. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3920. mode = MODE_HANDLE;
  3921. move();
  3922. }
  3923. break;
  3924. }
  3925. case 32: { // SPACE
  3926. if (mode === MODE_SPACE) {
  3927. if (exports.event.altKey) {
  3928. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3929. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3930. mode = MODE_CENTER;
  3931. } else {
  3932. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3933. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3934. mode = MODE_HANDLE;
  3935. }
  3936. overlay.attr("cursor", cursors[type]);
  3937. move();
  3938. }
  3939. break;
  3940. }
  3941. default: return;
  3942. }
  3943. noevent$1();
  3944. }
  3945. }
  3946. function initialize() {
  3947. var state = this.__brush || {selection: null};
  3948. state.extent = extent.apply(this, arguments);
  3949. state.dim = dim;
  3950. return state;
  3951. }
  3952. brush.extent = function(_) {
  3953. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  3954. };
  3955. brush.filter = function(_) {
  3956. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  3957. };
  3958. brush.handleSize = function(_) {
  3959. return arguments.length ? (handleSize = +_, brush) : handleSize;
  3960. };
  3961. brush.on = function() {
  3962. var value = listeners.on.apply(listeners, arguments);
  3963. return value === listeners ? brush : value;
  3964. };
  3965. return brush;
  3966. }
  3967. var cos = Math.cos;
  3968. var sin = Math.sin;
  3969. var pi$1 = Math.PI;
  3970. var halfPi$1 = pi$1 / 2;
  3971. var tau$1 = pi$1 * 2;
  3972. var max$1 = Math.max;
  3973. function compareValue(compare) {
  3974. return function(a, b) {
  3975. return compare(
  3976. a.source.value + a.target.value,
  3977. b.source.value + b.target.value
  3978. );
  3979. };
  3980. }
  3981. var chord = function() {
  3982. var padAngle = 0,
  3983. sortGroups = null,
  3984. sortSubgroups = null,
  3985. sortChords = null;
  3986. function chord(matrix) {
  3987. var n = matrix.length,
  3988. groupSums = [],
  3989. groupIndex = sequence(n),
  3990. subgroupIndex = [],
  3991. chords = [],
  3992. groups = chords.groups = new Array(n),
  3993. subgroups = new Array(n * n),
  3994. k,
  3995. x,
  3996. x0,
  3997. dx,
  3998. i,
  3999. j;
  4000. // Compute the sum.
  4001. k = 0, i = -1; while (++i < n) {
  4002. x = 0, j = -1; while (++j < n) {
  4003. x += matrix[i][j];
  4004. }
  4005. groupSums.push(x);
  4006. subgroupIndex.push(sequence(n));
  4007. k += x;
  4008. }
  4009. // Sort groups…
  4010. if (sortGroups) groupIndex.sort(function(a, b) {
  4011. return sortGroups(groupSums[a], groupSums[b]);
  4012. });
  4013. // Sort subgroups…
  4014. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4015. d.sort(function(a, b) {
  4016. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4017. });
  4018. });
  4019. // Convert the sum to scaling factor for [0, 2pi].
  4020. // TODO Allow start and end angle to be specified?
  4021. // TODO Allow padding to be specified as percentage?
  4022. k = max$1(0, tau$1 - padAngle * n) / k;
  4023. dx = k ? padAngle : tau$1 / n;
  4024. // Compute the start and end angle for each group and subgroup.
  4025. // Note: Opera has a bug reordering object literal properties!
  4026. x = 0, i = -1; while (++i < n) {
  4027. x0 = x, j = -1; while (++j < n) {
  4028. var di = groupIndex[i],
  4029. dj = subgroupIndex[di][j],
  4030. v = matrix[di][dj],
  4031. a0 = x,
  4032. a1 = x += v * k;
  4033. subgroups[dj * n + di] = {
  4034. index: di,
  4035. subindex: dj,
  4036. startAngle: a0,
  4037. endAngle: a1,
  4038. value: v
  4039. };
  4040. }
  4041. groups[di] = {
  4042. index: di,
  4043. startAngle: x0,
  4044. endAngle: x,
  4045. value: groupSums[di]
  4046. };
  4047. x += dx;
  4048. }
  4049. // Generate chords for each (non-empty) subgroup-subgroup link.
  4050. i = -1; while (++i < n) {
  4051. j = i - 1; while (++j < n) {
  4052. var source = subgroups[j * n + i],
  4053. target = subgroups[i * n + j];
  4054. if (source.value || target.value) {
  4055. chords.push(source.value < target.value
  4056. ? {source: target, target: source}
  4057. : {source: source, target: target});
  4058. }
  4059. }
  4060. }
  4061. return sortChords ? chords.sort(sortChords) : chords;
  4062. }
  4063. chord.padAngle = function(_) {
  4064. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4065. };
  4066. chord.sortGroups = function(_) {
  4067. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4068. };
  4069. chord.sortSubgroups = function(_) {
  4070. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4071. };
  4072. chord.sortChords = function(_) {
  4073. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4074. };
  4075. return chord;
  4076. };
  4077. var slice$2 = Array.prototype.slice;
  4078. var constant$5 = function(x) {
  4079. return function() {
  4080. return x;
  4081. };
  4082. };
  4083. var pi$2 = Math.PI;
  4084. var tau$2 = 2 * pi$2;
  4085. var epsilon$1 = 1e-6;
  4086. var tauEpsilon = tau$2 - epsilon$1;
  4087. function Path() {
  4088. this._x0 = this._y0 = // start of current subpath
  4089. this._x1 = this._y1 = null; // end of current subpath
  4090. this._ = "";
  4091. }
  4092. function path() {
  4093. return new Path;
  4094. }
  4095. Path.prototype = path.prototype = {
  4096. constructor: Path,
  4097. moveTo: function(x, y) {
  4098. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4099. },
  4100. closePath: function() {
  4101. if (this._x1 !== null) {
  4102. this._x1 = this._x0, this._y1 = this._y0;
  4103. this._ += "Z";
  4104. }
  4105. },
  4106. lineTo: function(x, y) {
  4107. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4108. },
  4109. quadraticCurveTo: function(x1, y1, x, y) {
  4110. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4111. },
  4112. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4113. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4114. },
  4115. arcTo: function(x1, y1, x2, y2, r) {
  4116. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4117. var x0 = this._x1,
  4118. y0 = this._y1,
  4119. x21 = x2 - x1,
  4120. y21 = y2 - y1,
  4121. x01 = x0 - x1,
  4122. y01 = y0 - y1,
  4123. l01_2 = x01 * x01 + y01 * y01;
  4124. // Is the radius negative? Error.
  4125. if (r < 0) throw new Error("negative radius: " + r);
  4126. // Is this path empty? Move to (x1,y1).
  4127. if (this._x1 === null) {
  4128. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4129. }
  4130. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4131. else if (!(l01_2 > epsilon$1)) {}
  4132. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4133. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4134. // Or, is the radius zero? Line to (x1,y1).
  4135. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4136. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4137. }
  4138. // Otherwise, draw an arc!
  4139. else {
  4140. var x20 = x2 - x0,
  4141. y20 = y2 - y0,
  4142. l21_2 = x21 * x21 + y21 * y21,
  4143. l20_2 = x20 * x20 + y20 * y20,
  4144. l21 = Math.sqrt(l21_2),
  4145. l01 = Math.sqrt(l01_2),
  4146. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4147. t01 = l / l01,
  4148. t21 = l / l21;
  4149. // If the start tangent is not coincident with (x0,y0), line to.
  4150. if (Math.abs(t01 - 1) > epsilon$1) {
  4151. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4152. }
  4153. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4154. }
  4155. },
  4156. arc: function(x, y, r, a0, a1, ccw) {
  4157. x = +x, y = +y, r = +r;
  4158. var dx = r * Math.cos(a0),
  4159. dy = r * Math.sin(a0),
  4160. x0 = x + dx,
  4161. y0 = y + dy,
  4162. cw = 1 ^ ccw,
  4163. da = ccw ? a0 - a1 : a1 - a0;
  4164. // Is the radius negative? Error.
  4165. if (r < 0) throw new Error("negative radius: " + r);
  4166. // Is this path empty? Move to (x0,y0).
  4167. if (this._x1 === null) {
  4168. this._ += "M" + x0 + "," + y0;
  4169. }
  4170. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4171. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4172. this._ += "L" + x0 + "," + y0;
  4173. }
  4174. // Is this arc empty? We’re done.
  4175. if (!r) return;
  4176. // Does the angle go the wrong way? Flip the direction.
  4177. if (da < 0) da = da % tau$2 + tau$2;
  4178. // Is this a complete circle? Draw two arcs to complete the circle.
  4179. if (da > tauEpsilon) {
  4180. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4181. }
  4182. // Is this arc non-empty? Draw an arc!
  4183. else if (da > epsilon$1) {
  4184. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4185. }
  4186. },
  4187. rect: function(x, y, w, h) {
  4188. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4189. },
  4190. toString: function() {
  4191. return this._;
  4192. }
  4193. };
  4194. function defaultSource(d) {
  4195. return d.source;
  4196. }
  4197. function defaultTarget(d) {
  4198. return d.target;
  4199. }
  4200. function defaultRadius(d) {
  4201. return d.radius;
  4202. }
  4203. function defaultStartAngle(d) {
  4204. return d.startAngle;
  4205. }
  4206. function defaultEndAngle(d) {
  4207. return d.endAngle;
  4208. }
  4209. var ribbon = function() {
  4210. var source = defaultSource,
  4211. target = defaultTarget,
  4212. radius = defaultRadius,
  4213. startAngle = defaultStartAngle,
  4214. endAngle = defaultEndAngle,
  4215. context = null;
  4216. function ribbon() {
  4217. var buffer,
  4218. argv = slice$2.call(arguments),
  4219. s = source.apply(this, argv),
  4220. t = target.apply(this, argv),
  4221. sr = +radius.apply(this, (argv[0] = s, argv)),
  4222. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4223. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4224. sx0 = sr * cos(sa0),
  4225. sy0 = sr * sin(sa0),
  4226. tr = +radius.apply(this, (argv[0] = t, argv)),
  4227. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4228. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4229. if (!context) context = buffer = path();
  4230. context.moveTo(sx0, sy0);
  4231. context.arc(0, 0, sr, sa0, sa1);
  4232. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4233. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4234. context.arc(0, 0, tr, ta0, ta1);
  4235. }
  4236. context.quadraticCurveTo(0, 0, sx0, sy0);
  4237. context.closePath();
  4238. if (buffer) return context = null, buffer + "" || null;
  4239. }
  4240. ribbon.radius = function(_) {
  4241. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4242. };
  4243. ribbon.startAngle = function(_) {
  4244. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4245. };
  4246. ribbon.endAngle = function(_) {
  4247. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4248. };
  4249. ribbon.source = function(_) {
  4250. return arguments.length ? (source = _, ribbon) : source;
  4251. };
  4252. ribbon.target = function(_) {
  4253. return arguments.length ? (target = _, ribbon) : target;
  4254. };
  4255. ribbon.context = function(_) {
  4256. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  4257. };
  4258. return ribbon;
  4259. };
  4260. var prefix = "$";
  4261. function Map() {}
  4262. Map.prototype = map$1.prototype = {
  4263. constructor: Map,
  4264. has: function(key) {
  4265. return (prefix + key) in this;
  4266. },
  4267. get: function(key) {
  4268. return this[prefix + key];
  4269. },
  4270. set: function(key, value) {
  4271. this[prefix + key] = value;
  4272. return this;
  4273. },
  4274. remove: function(key) {
  4275. var property = prefix + key;
  4276. return property in this && delete this[property];
  4277. },
  4278. clear: function() {
  4279. for (var property in this) if (property[0] === prefix) delete this[property];
  4280. },
  4281. keys: function() {
  4282. var keys = [];
  4283. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4284. return keys;
  4285. },
  4286. values: function() {
  4287. var values = [];
  4288. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4289. return values;
  4290. },
  4291. entries: function() {
  4292. var entries = [];
  4293. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4294. return entries;
  4295. },
  4296. size: function() {
  4297. var size = 0;
  4298. for (var property in this) if (property[0] === prefix) ++size;
  4299. return size;
  4300. },
  4301. empty: function() {
  4302. for (var property in this) if (property[0] === prefix) return false;
  4303. return true;
  4304. },
  4305. each: function(f) {
  4306. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4307. }
  4308. };
  4309. function map$1(object, f) {
  4310. var map = new Map;
  4311. // Copy constructor.
  4312. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4313. // Index array by numeric index or specified key function.
  4314. else if (Array.isArray(object)) {
  4315. var i = -1,
  4316. n = object.length,
  4317. o;
  4318. if (f == null) while (++i < n) map.set(i, object[i]);
  4319. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4320. }
  4321. // Convert object to map.
  4322. else if (object) for (var key in object) map.set(key, object[key]);
  4323. return map;
  4324. }
  4325. var nest = function() {
  4326. var keys = [],
  4327. sortKeys = [],
  4328. sortValues,
  4329. rollup,
  4330. nest;
  4331. function apply(array, depth, createResult, setResult) {
  4332. if (depth >= keys.length) return rollup != null
  4333. ? rollup(array) : (sortValues != null
  4334. ? array.sort(sortValues)
  4335. : array);
  4336. var i = -1,
  4337. n = array.length,
  4338. key = keys[depth++],
  4339. keyValue,
  4340. value,
  4341. valuesByKey = map$1(),
  4342. values,
  4343. result = createResult();
  4344. while (++i < n) {
  4345. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4346. values.push(value);
  4347. } else {
  4348. valuesByKey.set(keyValue, [value]);
  4349. }
  4350. }
  4351. valuesByKey.each(function(values, key) {
  4352. setResult(result, key, apply(values, depth, createResult, setResult));
  4353. });
  4354. return result;
  4355. }
  4356. function entries(map, depth) {
  4357. if (++depth > keys.length) return map;
  4358. var array, sortKey = sortKeys[depth - 1];
  4359. if (rollup != null && depth >= keys.length) array = map.entries();
  4360. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4361. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4362. }
  4363. return nest = {
  4364. object: function(array) { return apply(array, 0, createObject, setObject); },
  4365. map: function(array) { return apply(array, 0, createMap, setMap); },
  4366. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4367. key: function(d) { keys.push(d); return nest; },
  4368. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4369. sortValues: function(order) { sortValues = order; return nest; },
  4370. rollup: function(f) { rollup = f; return nest; }
  4371. };
  4372. };
  4373. function createObject() {
  4374. return {};
  4375. }
  4376. function setObject(object, key, value) {
  4377. object[key] = value;
  4378. }
  4379. function createMap() {
  4380. return map$1();
  4381. }
  4382. function setMap(map, key, value) {
  4383. map.set(key, value);
  4384. }
  4385. function Set() {}
  4386. var proto = map$1.prototype;
  4387. Set.prototype = set$2.prototype = {
  4388. constructor: Set,
  4389. has: proto.has,
  4390. add: function(value) {
  4391. value += "";
  4392. this[prefix + value] = value;
  4393. return this;
  4394. },
  4395. remove: proto.remove,
  4396. clear: proto.clear,
  4397. values: proto.keys,
  4398. size: proto.size,
  4399. empty: proto.empty,
  4400. each: proto.each
  4401. };
  4402. function set$2(object, f) {
  4403. var set = new Set;
  4404. // Copy constructor.
  4405. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4406. // Otherwise, assume it’s an array.
  4407. else if (object) {
  4408. var i = -1, n = object.length;
  4409. if (f == null) while (++i < n) set.add(object[i]);
  4410. else while (++i < n) set.add(f(object[i], i, object));
  4411. }
  4412. return set;
  4413. }
  4414. var keys = function(map) {
  4415. var keys = [];
  4416. for (var key in map) keys.push(key);
  4417. return keys;
  4418. };
  4419. var values = function(map) {
  4420. var values = [];
  4421. for (var key in map) values.push(map[key]);
  4422. return values;
  4423. };
  4424. var entries = function(map) {
  4425. var entries = [];
  4426. for (var key in map) entries.push({key: key, value: map[key]});
  4427. return entries;
  4428. };
  4429. function objectConverter(columns) {
  4430. return new Function("d", "return {" + columns.map(function(name, i) {
  4431. return JSON.stringify(name) + ": d[" + i + "]";
  4432. }).join(",") + "}");
  4433. }
  4434. function customConverter(columns, f) {
  4435. var object = objectConverter(columns);
  4436. return function(row, i) {
  4437. return f(object(row), i, columns);
  4438. };
  4439. }
  4440. // Compute unique columns in order of discovery.
  4441. function inferColumns(rows) {
  4442. var columnSet = Object.create(null),
  4443. columns = [];
  4444. rows.forEach(function(row) {
  4445. for (var column in row) {
  4446. if (!(column in columnSet)) {
  4447. columns.push(columnSet[column] = column);
  4448. }
  4449. }
  4450. });
  4451. return columns;
  4452. }
  4453. var dsv = function(delimiter) {
  4454. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  4455. delimiterCode = delimiter.charCodeAt(0);
  4456. function parse(text, f) {
  4457. var convert, columns, rows = parseRows(text, function(row, i) {
  4458. if (convert) return convert(row, i - 1);
  4459. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  4460. });
  4461. rows.columns = columns;
  4462. return rows;
  4463. }
  4464. function parseRows(text, f) {
  4465. var EOL = {}, // sentinel value for end-of-line
  4466. EOF = {}, // sentinel value for end-of-file
  4467. rows = [], // output rows
  4468. N = text.length,
  4469. I = 0, // current character index
  4470. n = 0, // the current line number
  4471. t, // the current token
  4472. eol; // is the current token followed by EOL?
  4473. function token() {
  4474. if (I >= N) return EOF; // special case: end of file
  4475. if (eol) return eol = false, EOL; // special case: end of line
  4476. // special case: quotes
  4477. var j = I, c;
  4478. if (text.charCodeAt(j) === 34) {
  4479. var i = j;
  4480. while (i++ < N) {
  4481. if (text.charCodeAt(i) === 34) {
  4482. if (text.charCodeAt(i + 1) !== 34) break;
  4483. ++i;
  4484. }
  4485. }
  4486. I = i + 2;
  4487. c = text.charCodeAt(i + 1);
  4488. if (c === 13) {
  4489. eol = true;
  4490. if (text.charCodeAt(i + 2) === 10) ++I;
  4491. } else if (c === 10) {
  4492. eol = true;
  4493. }
  4494. return text.slice(j + 1, i).replace(/""/g, "\"");
  4495. }
  4496. // common case: find next delimiter or newline
  4497. while (I < N) {
  4498. var k = 1;
  4499. c = text.charCodeAt(I++);
  4500. if (c === 10) eol = true; // \n
  4501. else if (c === 13) { eol = true; if (text.charCodeAt(I) === 10) ++I, ++k; } // \r|\r\n
  4502. else if (c !== delimiterCode) continue;
  4503. return text.slice(j, I - k);
  4504. }
  4505. // special case: last token before EOF
  4506. return text.slice(j);
  4507. }
  4508. while ((t = token()) !== EOF) {
  4509. var a = [];
  4510. while (t !== EOL && t !== EOF) {
  4511. a.push(t);
  4512. t = token();
  4513. }
  4514. if (f && (a = f(a, n++)) == null) continue;
  4515. rows.push(a);
  4516. }
  4517. return rows;
  4518. }
  4519. function format(rows, columns) {
  4520. if (columns == null) columns = inferColumns(rows);
  4521. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4522. return columns.map(function(column) {
  4523. return formatValue(row[column]);
  4524. }).join(delimiter);
  4525. })).join("\n");
  4526. }
  4527. function formatRows(rows) {
  4528. return rows.map(formatRow).join("\n");
  4529. }
  4530. function formatRow(row) {
  4531. return row.map(formatValue).join(delimiter);
  4532. }
  4533. function formatValue(text) {
  4534. return text == null ? ""
  4535. : reFormat.test(text += "") ? "\"" + text.replace(/\"/g, "\"\"") + "\""
  4536. : text;
  4537. }
  4538. return {
  4539. parse: parse,
  4540. parseRows: parseRows,
  4541. format: format,
  4542. formatRows: formatRows
  4543. };
  4544. };
  4545. var csv = dsv(",");
  4546. var csvParse = csv.parse;
  4547. var csvParseRows = csv.parseRows;
  4548. var csvFormat = csv.format;
  4549. var csvFormatRows = csv.formatRows;
  4550. var tsv = dsv("\t");
  4551. var tsvParse = tsv.parse;
  4552. var tsvParseRows = tsv.parseRows;
  4553. var tsvFormat = tsv.format;
  4554. var tsvFormatRows = tsv.formatRows;
  4555. var center$1 = function(x, y) {
  4556. var nodes;
  4557. if (x == null) x = 0;
  4558. if (y == null) y = 0;
  4559. function force() {
  4560. var i,
  4561. n = nodes.length,
  4562. node,
  4563. sx = 0,
  4564. sy = 0;
  4565. for (i = 0; i < n; ++i) {
  4566. node = nodes[i], sx += node.x, sy += node.y;
  4567. }
  4568. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  4569. node = nodes[i], node.x -= sx, node.y -= sy;
  4570. }
  4571. }
  4572. force.initialize = function(_) {
  4573. nodes = _;
  4574. };
  4575. force.x = function(_) {
  4576. return arguments.length ? (x = +_, force) : x;
  4577. };
  4578. force.y = function(_) {
  4579. return arguments.length ? (y = +_, force) : y;
  4580. };
  4581. return force;
  4582. };
  4583. var constant$6 = function(x) {
  4584. return function() {
  4585. return x;
  4586. };
  4587. };
  4588. var jiggle = function() {
  4589. return (Math.random() - 0.5) * 1e-6;
  4590. };
  4591. var tree_add = function(d) {
  4592. var x = +this._x.call(null, d),
  4593. y = +this._y.call(null, d);
  4594. return add(this.cover(x, y), x, y, d);
  4595. };
  4596. function add(tree, x, y, d) {
  4597. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  4598. var parent,
  4599. node = tree._root,
  4600. leaf = {data: d},
  4601. x0 = tree._x0,
  4602. y0 = tree._y0,
  4603. x1 = tree._x1,
  4604. y1 = tree._y1,
  4605. xm,
  4606. ym,
  4607. xp,
  4608. yp,
  4609. right,
  4610. bottom,
  4611. i,
  4612. j;
  4613. // If the tree is empty, initialize the root as a leaf.
  4614. if (!node) return tree._root = leaf, tree;
  4615. // Find the existing leaf for the new point, or add it.
  4616. while (node.length) {
  4617. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4618. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4619. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  4620. }
  4621. // Is the new point is exactly coincident with the existing point?
  4622. xp = +tree._x.call(null, node.data);
  4623. yp = +tree._y.call(null, node.data);
  4624. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  4625. // Otherwise, split the leaf node until the old and new point are separated.
  4626. do {
  4627. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  4628. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4629. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4630. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  4631. return parent[j] = node, parent[i] = leaf, tree;
  4632. }
  4633. function addAll(data) {
  4634. var d, i, n = data.length,
  4635. x,
  4636. y,
  4637. xz = new Array(n),
  4638. yz = new Array(n),
  4639. x0 = Infinity,
  4640. y0 = Infinity,
  4641. x1 = -Infinity,
  4642. y1 = -Infinity;
  4643. // Compute the points and their extent.
  4644. for (i = 0; i < n; ++i) {
  4645. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  4646. xz[i] = x;
  4647. yz[i] = y;
  4648. if (x < x0) x0 = x;
  4649. if (x > x1) x1 = x;
  4650. if (y < y0) y0 = y;
  4651. if (y > y1) y1 = y;
  4652. }
  4653. // If there were no (valid) points, inherit the existing extent.
  4654. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  4655. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  4656. // Expand the tree to cover the new points.
  4657. this.cover(x0, y0).cover(x1, y1);
  4658. // Add the new points.
  4659. for (i = 0; i < n; ++i) {
  4660. add(this, xz[i], yz[i], data[i]);
  4661. }
  4662. return this;
  4663. }
  4664. var tree_cover = function(x, y) {
  4665. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  4666. var x0 = this._x0,
  4667. y0 = this._y0,
  4668. x1 = this._x1,
  4669. y1 = this._y1;
  4670. // If the quadtree has no extent, initialize them.
  4671. // Integer extent are necessary so that if we later double the extent,
  4672. // the existing quadrant boundaries don’t change due to floating point error!
  4673. if (isNaN(x0)) {
  4674. x1 = (x0 = Math.floor(x)) + 1;
  4675. y1 = (y0 = Math.floor(y)) + 1;
  4676. }
  4677. // Otherwise, double repeatedly to cover.
  4678. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  4679. var z = x1 - x0,
  4680. node = this._root,
  4681. parent,
  4682. i;
  4683. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  4684. case 0: {
  4685. do parent = new Array(4), parent[i] = node, node = parent;
  4686. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  4687. break;
  4688. }
  4689. case 1: {
  4690. do parent = new Array(4), parent[i] = node, node = parent;
  4691. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  4692. break;
  4693. }
  4694. case 2: {
  4695. do parent = new Array(4), parent[i] = node, node = parent;
  4696. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  4697. break;
  4698. }
  4699. case 3: {
  4700. do parent = new Array(4), parent[i] = node, node = parent;
  4701. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  4702. break;
  4703. }
  4704. }
  4705. if (this._root && this._root.length) this._root = node;
  4706. }
  4707. // If the quadtree covers the point already, just return.
  4708. else return this;
  4709. this._x0 = x0;
  4710. this._y0 = y0;
  4711. this._x1 = x1;
  4712. this._y1 = y1;
  4713. return this;
  4714. };
  4715. var tree_data = function() {
  4716. var data = [];
  4717. this.visit(function(node) {
  4718. if (!node.length) do data.push(node.data); while (node = node.next)
  4719. });
  4720. return data;
  4721. };
  4722. var tree_extent = function(_) {
  4723. return arguments.length
  4724. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  4725. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  4726. };
  4727. var Quad = function(node, x0, y0, x1, y1) {
  4728. this.node = node;
  4729. this.x0 = x0;
  4730. this.y0 = y0;
  4731. this.x1 = x1;
  4732. this.y1 = y1;
  4733. };
  4734. var tree_find = function(x, y, radius) {
  4735. var data,
  4736. x0 = this._x0,
  4737. y0 = this._y0,
  4738. x1,
  4739. y1,
  4740. x2,
  4741. y2,
  4742. x3 = this._x1,
  4743. y3 = this._y1,
  4744. quads = [],
  4745. node = this._root,
  4746. q,
  4747. i;
  4748. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  4749. if (radius == null) radius = Infinity;
  4750. else {
  4751. x0 = x - radius, y0 = y - radius;
  4752. x3 = x + radius, y3 = y + radius;
  4753. radius *= radius;
  4754. }
  4755. while (q = quads.pop()) {
  4756. // Stop searching if this quadrant can’t contain a closer node.
  4757. if (!(node = q.node)
  4758. || (x1 = q.x0) > x3
  4759. || (y1 = q.y0) > y3
  4760. || (x2 = q.x1) < x0
  4761. || (y2 = q.y1) < y0) continue;
  4762. // Bisect the current quadrant.
  4763. if (node.length) {
  4764. var xm = (x1 + x2) / 2,
  4765. ym = (y1 + y2) / 2;
  4766. quads.push(
  4767. new Quad(node[3], xm, ym, x2, y2),
  4768. new Quad(node[2], x1, ym, xm, y2),
  4769. new Quad(node[1], xm, y1, x2, ym),
  4770. new Quad(node[0], x1, y1, xm, ym)
  4771. );
  4772. // Visit the closest quadrant first.
  4773. if (i = (y >= ym) << 1 | (x >= xm)) {
  4774. q = quads[quads.length - 1];
  4775. quads[quads.length - 1] = quads[quads.length - 1 - i];
  4776. quads[quads.length - 1 - i] = q;
  4777. }
  4778. }
  4779. // Visit this point. (Visiting coincident points isn’t necessary!)
  4780. else {
  4781. var dx = x - +this._x.call(null, node.data),
  4782. dy = y - +this._y.call(null, node.data),
  4783. d2 = dx * dx + dy * dy;
  4784. if (d2 < radius) {
  4785. var d = Math.sqrt(radius = d2);
  4786. x0 = x - d, y0 = y - d;
  4787. x3 = x + d, y3 = y + d;
  4788. data = node.data;
  4789. }
  4790. }
  4791. }
  4792. return data;
  4793. };
  4794. var tree_remove = function(d) {
  4795. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  4796. var parent,
  4797. node = this._root,
  4798. retainer,
  4799. previous,
  4800. next,
  4801. x0 = this._x0,
  4802. y0 = this._y0,
  4803. x1 = this._x1,
  4804. y1 = this._y1,
  4805. x,
  4806. y,
  4807. xm,
  4808. ym,
  4809. right,
  4810. bottom,
  4811. i,
  4812. j;
  4813. // If the tree is empty, initialize the root as a leaf.
  4814. if (!node) return this;
  4815. // Find the leaf node for the point.
  4816. // While descending, also retain the deepest parent with a non-removed sibling.
  4817. if (node.length) while (true) {
  4818. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4819. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4820. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  4821. if (!node.length) break;
  4822. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  4823. }
  4824. // Find the point to remove.
  4825. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  4826. if (next = node.next) delete node.next;
  4827. // If there are multiple coincident points, remove just the point.
  4828. if (previous) return (next ? previous.next = next : delete previous.next), this;
  4829. // If this is the root point, remove it.
  4830. if (!parent) return this._root = next, this;
  4831. // Remove this leaf.
  4832. next ? parent[i] = next : delete parent[i];
  4833. // If the parent now contains exactly one leaf, collapse superfluous parents.
  4834. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  4835. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  4836. && !node.length) {
  4837. if (retainer) retainer[j] = node;
  4838. else this._root = node;
  4839. }
  4840. return this;
  4841. };
  4842. function removeAll(data) {
  4843. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  4844. return this;
  4845. }
  4846. var tree_root = function() {
  4847. return this._root;
  4848. };
  4849. var tree_size = function() {
  4850. var size = 0;
  4851. this.visit(function(node) {
  4852. if (!node.length) do ++size; while (node = node.next)
  4853. });
  4854. return size;
  4855. };
  4856. var tree_visit = function(callback) {
  4857. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  4858. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  4859. while (q = quads.pop()) {
  4860. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  4861. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  4862. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  4863. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  4864. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  4865. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  4866. }
  4867. }
  4868. return this;
  4869. };
  4870. var tree_visitAfter = function(callback) {
  4871. var quads = [], next = [], q;
  4872. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  4873. while (q = quads.pop()) {
  4874. var node = q.node;
  4875. if (node.length) {
  4876. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  4877. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  4878. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  4879. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  4880. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  4881. }
  4882. next.push(q);
  4883. }
  4884. while (q = next.pop()) {
  4885. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  4886. }
  4887. return this;
  4888. };
  4889. function defaultX(d) {
  4890. return d[0];
  4891. }
  4892. var tree_x = function(_) {
  4893. return arguments.length ? (this._x = _, this) : this._x;
  4894. };
  4895. function defaultY(d) {
  4896. return d[1];
  4897. }
  4898. var tree_y = function(_) {
  4899. return arguments.length ? (this._y = _, this) : this._y;
  4900. };
  4901. function quadtree(nodes, x, y) {
  4902. var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
  4903. return nodes == null ? tree : tree.addAll(nodes);
  4904. }
  4905. function Quadtree(x, y, x0, y0, x1, y1) {
  4906. this._x = x;
  4907. this._y = y;
  4908. this._x0 = x0;
  4909. this._y0 = y0;
  4910. this._x1 = x1;
  4911. this._y1 = y1;
  4912. this._root = undefined;
  4913. }
  4914. function leaf_copy(leaf) {
  4915. var copy = {data: leaf.data}, next = copy;
  4916. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  4917. return copy;
  4918. }
  4919. var treeProto = quadtree.prototype = Quadtree.prototype;
  4920. treeProto.copy = function() {
  4921. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  4922. node = this._root,
  4923. nodes,
  4924. child;
  4925. if (!node) return copy;
  4926. if (!node.length) return copy._root = leaf_copy(node), copy;
  4927. nodes = [{source: node, target: copy._root = new Array(4)}];
  4928. while (node = nodes.pop()) {
  4929. for (var i = 0; i < 4; ++i) {
  4930. if (child = node.source[i]) {
  4931. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  4932. else node.target[i] = leaf_copy(child);
  4933. }
  4934. }
  4935. }
  4936. return copy;
  4937. };
  4938. treeProto.add = tree_add;
  4939. treeProto.addAll = addAll;
  4940. treeProto.cover = tree_cover;
  4941. treeProto.data = tree_data;
  4942. treeProto.extent = tree_extent;
  4943. treeProto.find = tree_find;
  4944. treeProto.remove = tree_remove;
  4945. treeProto.removeAll = removeAll;
  4946. treeProto.root = tree_root;
  4947. treeProto.size = tree_size;
  4948. treeProto.visit = tree_visit;
  4949. treeProto.visitAfter = tree_visitAfter;
  4950. treeProto.x = tree_x;
  4951. treeProto.y = tree_y;
  4952. function x(d) {
  4953. return d.x + d.vx;
  4954. }
  4955. function y(d) {
  4956. return d.y + d.vy;
  4957. }
  4958. var collide = function(radius) {
  4959. var nodes,
  4960. radii,
  4961. strength = 1,
  4962. iterations = 1;
  4963. if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
  4964. function force() {
  4965. var i, n = nodes.length,
  4966. tree,
  4967. node,
  4968. xi,
  4969. yi,
  4970. ri,
  4971. ri2;
  4972. for (var k = 0; k < iterations; ++k) {
  4973. tree = quadtree(nodes, x, y).visitAfter(prepare);
  4974. for (i = 0; i < n; ++i) {
  4975. node = nodes[i];
  4976. ri = radii[node.index], ri2 = ri * ri;
  4977. xi = node.x + node.vx;
  4978. yi = node.y + node.vy;
  4979. tree.visit(apply);
  4980. }
  4981. }
  4982. function apply(quad, x0, y0, x1, y1) {
  4983. var data = quad.data, rj = quad.r, r = ri + rj;
  4984. if (data) {
  4985. if (data.index > node.index) {
  4986. var x = xi - data.x - data.vx,
  4987. y = yi - data.y - data.vy,
  4988. l = x * x + y * y;
  4989. if (l < r * r) {
  4990. if (x === 0) x = jiggle(), l += x * x;
  4991. if (y === 0) y = jiggle(), l += y * y;
  4992. l = (r - (l = Math.sqrt(l))) / l * strength;
  4993. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  4994. node.vy += (y *= l) * r;
  4995. data.vx -= x * (r = 1 - r);
  4996. data.vy -= y * r;
  4997. }
  4998. }
  4999. return;
  5000. }
  5001. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5002. }
  5003. }
  5004. function prepare(quad) {
  5005. if (quad.data) return quad.r = radii[quad.data.index];
  5006. for (var i = quad.r = 0; i < 4; ++i) {
  5007. if (quad[i] && quad[i].r > quad.r) {
  5008. quad.r = quad[i].r;
  5009. }
  5010. }
  5011. }
  5012. function initialize() {
  5013. if (!nodes) return;
  5014. var i, n = nodes.length, node;
  5015. radii = new Array(n);
  5016. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5017. }
  5018. force.initialize = function(_) {
  5019. nodes = _;
  5020. initialize();
  5021. };
  5022. force.iterations = function(_) {
  5023. return arguments.length ? (iterations = +_, force) : iterations;
  5024. };
  5025. force.strength = function(_) {
  5026. return arguments.length ? (strength = +_, force) : strength;
  5027. };
  5028. force.radius = function(_) {
  5029. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
  5030. };
  5031. return force;
  5032. };
  5033. function index(d) {
  5034. return d.index;
  5035. }
  5036. function find(nodeById, nodeId) {
  5037. var node = nodeById.get(nodeId);
  5038. if (!node) throw new Error("missing: " + nodeId);
  5039. return node;
  5040. }
  5041. var link = function(links) {
  5042. var id = index,
  5043. strength = defaultStrength,
  5044. strengths,
  5045. distance = constant$6(30),
  5046. distances,
  5047. nodes,
  5048. count,
  5049. bias,
  5050. iterations = 1;
  5051. if (links == null) links = [];
  5052. function defaultStrength(link) {
  5053. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5054. }
  5055. function force(alpha) {
  5056. for (var k = 0, n = links.length; k < iterations; ++k) {
  5057. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5058. link = links[i], source = link.source, target = link.target;
  5059. x = target.x + target.vx - source.x - source.vx || jiggle();
  5060. y = target.y + target.vy - source.y - source.vy || jiggle();
  5061. l = Math.sqrt(x * x + y * y);
  5062. l = (l - distances[i]) / l * alpha * strengths[i];
  5063. x *= l, y *= l;
  5064. target.vx -= x * (b = bias[i]);
  5065. target.vy -= y * b;
  5066. source.vx += x * (b = 1 - b);
  5067. source.vy += y * b;
  5068. }
  5069. }
  5070. }
  5071. function initialize() {
  5072. if (!nodes) return;
  5073. var i,
  5074. n = nodes.length,
  5075. m = links.length,
  5076. nodeById = map$1(nodes, id),
  5077. link;
  5078. for (i = 0, count = new Array(n); i < m; ++i) {
  5079. link = links[i], link.index = i;
  5080. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5081. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5082. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5083. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5084. }
  5085. for (i = 0, bias = new Array(m); i < m; ++i) {
  5086. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5087. }
  5088. strengths = new Array(m), initializeStrength();
  5089. distances = new Array(m), initializeDistance();
  5090. }
  5091. function initializeStrength() {
  5092. if (!nodes) return;
  5093. for (var i = 0, n = links.length; i < n; ++i) {
  5094. strengths[i] = +strength(links[i], i, links);
  5095. }
  5096. }
  5097. function initializeDistance() {
  5098. if (!nodes) return;
  5099. for (var i = 0, n = links.length; i < n; ++i) {
  5100. distances[i] = +distance(links[i], i, links);
  5101. }
  5102. }
  5103. force.initialize = function(_) {
  5104. nodes = _;
  5105. initialize();
  5106. };
  5107. force.links = function(_) {
  5108. return arguments.length ? (links = _, initialize(), force) : links;
  5109. };
  5110. force.id = function(_) {
  5111. return arguments.length ? (id = _, force) : id;
  5112. };
  5113. force.iterations = function(_) {
  5114. return arguments.length ? (iterations = +_, force) : iterations;
  5115. };
  5116. force.strength = function(_) {
  5117. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
  5118. };
  5119. force.distance = function(_) {
  5120. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
  5121. };
  5122. return force;
  5123. };
  5124. function x$1(d) {
  5125. return d.x;
  5126. }
  5127. function y$1(d) {
  5128. return d.y;
  5129. }
  5130. var initialRadius = 10;
  5131. var initialAngle = Math.PI * (3 - Math.sqrt(5));
  5132. var simulation = function(nodes) {
  5133. var simulation,
  5134. alpha = 1,
  5135. alphaMin = 0.001,
  5136. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5137. alphaTarget = 0,
  5138. velocityDecay = 0.6,
  5139. forces = map$1(),
  5140. stepper = timer(step),
  5141. event = dispatch("tick", "end");
  5142. if (nodes == null) nodes = [];
  5143. function step() {
  5144. tick();
  5145. event.call("tick", simulation);
  5146. if (alpha < alphaMin) {
  5147. stepper.stop();
  5148. event.call("end", simulation);
  5149. }
  5150. }
  5151. function tick() {
  5152. var i, n = nodes.length, node;
  5153. alpha += (alphaTarget - alpha) * alphaDecay;
  5154. forces.each(function(force) {
  5155. force(alpha);
  5156. });
  5157. for (i = 0; i < n; ++i) {
  5158. node = nodes[i];
  5159. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5160. else node.x = node.fx, node.vx = 0;
  5161. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5162. else node.y = node.fy, node.vy = 0;
  5163. }
  5164. }
  5165. function initializeNodes() {
  5166. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5167. node = nodes[i], node.index = i;
  5168. if (isNaN(node.x) || isNaN(node.y)) {
  5169. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5170. node.x = radius * Math.cos(angle);
  5171. node.y = radius * Math.sin(angle);
  5172. }
  5173. if (isNaN(node.vx) || isNaN(node.vy)) {
  5174. node.vx = node.vy = 0;
  5175. }
  5176. }
  5177. }
  5178. function initializeForce(force) {
  5179. if (force.initialize) force.initialize(nodes);
  5180. return force;
  5181. }
  5182. initializeNodes();
  5183. return simulation = {
  5184. tick: tick,
  5185. restart: function() {
  5186. return stepper.restart(step), simulation;
  5187. },
  5188. stop: function() {
  5189. return stepper.stop(), simulation;
  5190. },
  5191. nodes: function(_) {
  5192. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5193. },
  5194. alpha: function(_) {
  5195. return arguments.length ? (alpha = +_, simulation) : alpha;
  5196. },
  5197. alphaMin: function(_) {
  5198. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5199. },
  5200. alphaDecay: function(_) {
  5201. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5202. },
  5203. alphaTarget: function(_) {
  5204. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5205. },
  5206. velocityDecay: function(_) {
  5207. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5208. },
  5209. force: function(name, _) {
  5210. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  5211. },
  5212. find: function(x, y, radius) {
  5213. var i = 0,
  5214. n = nodes.length,
  5215. dx,
  5216. dy,
  5217. d2,
  5218. node,
  5219. closest;
  5220. if (radius == null) radius = Infinity;
  5221. else radius *= radius;
  5222. for (i = 0; i < n; ++i) {
  5223. node = nodes[i];
  5224. dx = x - node.x;
  5225. dy = y - node.y;
  5226. d2 = dx * dx + dy * dy;
  5227. if (d2 < radius) closest = node, radius = d2;
  5228. }
  5229. return closest;
  5230. },
  5231. on: function(name, _) {
  5232. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5233. }
  5234. };
  5235. };
  5236. var manyBody = function() {
  5237. var nodes,
  5238. node,
  5239. alpha,
  5240. strength = constant$6(-30),
  5241. strengths,
  5242. distanceMin2 = 1,
  5243. distanceMax2 = Infinity,
  5244. theta2 = 0.81;
  5245. function force(_) {
  5246. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5247. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5248. }
  5249. function initialize() {
  5250. if (!nodes) return;
  5251. var i, n = nodes.length, node;
  5252. strengths = new Array(n);
  5253. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5254. }
  5255. function accumulate(quad) {
  5256. var strength = 0, q, c, x$$1, y$$1, i;
  5257. // For internal nodes, accumulate forces from child quadrants.
  5258. if (quad.length) {
  5259. for (x$$1 = y$$1 = i = 0; i < 4; ++i) {
  5260. if ((q = quad[i]) && (c = q.value)) {
  5261. strength += c, x$$1 += c * q.x, y$$1 += c * q.y;
  5262. }
  5263. }
  5264. quad.x = x$$1 / strength;
  5265. quad.y = y$$1 / strength;
  5266. }
  5267. // For leaf nodes, accumulate forces from coincident quadrants.
  5268. else {
  5269. q = quad;
  5270. q.x = q.data.x;
  5271. q.y = q.data.y;
  5272. do strength += strengths[q.data.index];
  5273. while (q = q.next);
  5274. }
  5275. quad.value = strength;
  5276. }
  5277. function apply(quad, x1, _, x2) {
  5278. if (!quad.value) return true;
  5279. var x$$1 = quad.x - node.x,
  5280. y$$1 = quad.y - node.y,
  5281. w = x2 - x1,
  5282. l = x$$1 * x$$1 + y$$1 * y$$1;
  5283. // Apply the Barnes-Hut approximation if possible.
  5284. // Limit forces for very close nodes; randomize direction if coincident.
  5285. if (w * w / theta2 < l) {
  5286. if (l < distanceMax2) {
  5287. if (x$$1 === 0) x$$1 = jiggle(), l += x$$1 * x$$1;
  5288. if (y$$1 === 0) y$$1 = jiggle(), l += y$$1 * y$$1;
  5289. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5290. node.vx += x$$1 * quad.value * alpha / l;
  5291. node.vy += y$$1 * quad.value * alpha / l;
  5292. }
  5293. return true;
  5294. }
  5295. // Otherwise, process points directly.
  5296. else if (quad.length || l >= distanceMax2) return;
  5297. // Limit forces for very close nodes; randomize direction if coincident.
  5298. if (quad.data !== node || quad.next) {
  5299. if (x$$1 === 0) x$$1 = jiggle(), l += x$$1 * x$$1;
  5300. if (y$$1 === 0) y$$1 = jiggle(), l += y$$1 * y$$1;
  5301. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5302. }
  5303. do if (quad.data !== node) {
  5304. w = strengths[quad.data.index] * alpha / l;
  5305. node.vx += x$$1 * w;
  5306. node.vy += y$$1 * w;
  5307. } while (quad = quad.next);
  5308. }
  5309. force.initialize = function(_) {
  5310. nodes = _;
  5311. initialize();
  5312. };
  5313. force.strength = function(_) {
  5314. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5315. };
  5316. force.distanceMin = function(_) {
  5317. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5318. };
  5319. force.distanceMax = function(_) {
  5320. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5321. };
  5322. force.theta = function(_) {
  5323. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5324. };
  5325. return force;
  5326. };
  5327. var x$2 = function(x) {
  5328. var strength = constant$6(0.1),
  5329. nodes,
  5330. strengths,
  5331. xz;
  5332. if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
  5333. function force(alpha) {
  5334. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5335. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  5336. }
  5337. }
  5338. function initialize() {
  5339. if (!nodes) return;
  5340. var i, n = nodes.length;
  5341. strengths = new Array(n);
  5342. xz = new Array(n);
  5343. for (i = 0; i < n; ++i) {
  5344. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5345. }
  5346. }
  5347. force.initialize = function(_) {
  5348. nodes = _;
  5349. initialize();
  5350. };
  5351. force.strength = function(_) {
  5352. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5353. };
  5354. force.x = function(_) {
  5355. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
  5356. };
  5357. return force;
  5358. };
  5359. var y$2 = function(y) {
  5360. var strength = constant$6(0.1),
  5361. nodes,
  5362. strengths,
  5363. yz;
  5364. if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
  5365. function force(alpha) {
  5366. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5367. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  5368. }
  5369. }
  5370. function initialize() {
  5371. if (!nodes) return;
  5372. var i, n = nodes.length;
  5373. strengths = new Array(n);
  5374. yz = new Array(n);
  5375. for (i = 0; i < n; ++i) {
  5376. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5377. }
  5378. }
  5379. force.initialize = function(_) {
  5380. nodes = _;
  5381. initialize();
  5382. };
  5383. force.strength = function(_) {
  5384. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5385. };
  5386. force.y = function(_) {
  5387. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
  5388. };
  5389. return force;
  5390. };
  5391. // Computes the decimal coefficient and exponent of the specified number x with
  5392. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  5393. // For example, formatDecimal(1.23) returns ["123", 0].
  5394. var formatDecimal = function(x, p) {
  5395. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  5396. var i, coefficient = x.slice(0, i);
  5397. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  5398. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  5399. return [
  5400. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  5401. +x.slice(i + 1)
  5402. ];
  5403. };
  5404. var exponent$1 = function(x) {
  5405. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  5406. };
  5407. var formatGroup = function(grouping, thousands) {
  5408. return function(value, width) {
  5409. var i = value.length,
  5410. t = [],
  5411. j = 0,
  5412. g = grouping[0],
  5413. length = 0;
  5414. while (i > 0 && g > 0) {
  5415. if (length + g + 1 > width) g = Math.max(1, width - length);
  5416. t.push(value.substring(i -= g, i + g));
  5417. if ((length += g + 1) > width) break;
  5418. g = grouping[j = (j + 1) % grouping.length];
  5419. }
  5420. return t.reverse().join(thousands);
  5421. };
  5422. };
  5423. var formatNumerals = function(numerals) {
  5424. return function(value) {
  5425. return value.replace(/[0-9]/g, function(i) {
  5426. return numerals[+i];
  5427. });
  5428. };
  5429. };
  5430. var formatDefault = function(x, p) {
  5431. x = x.toPrecision(p);
  5432. out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
  5433. switch (x[i]) {
  5434. case ".": i0 = i1 = i; break;
  5435. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  5436. case "e": break out;
  5437. default: if (i0 > 0) i0 = 0; break;
  5438. }
  5439. }
  5440. return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
  5441. };
  5442. var prefixExponent;
  5443. var formatPrefixAuto = function(x, p) {
  5444. var d = formatDecimal(x, p);
  5445. if (!d) return x + "";
  5446. var coefficient = d[0],
  5447. exponent = d[1],
  5448. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  5449. n = coefficient.length;
  5450. return i === n ? coefficient
  5451. : i > n ? coefficient + new Array(i - n + 1).join("0")
  5452. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  5453. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  5454. };
  5455. var formatRounded = function(x, p) {
  5456. var d = formatDecimal(x, p);
  5457. if (!d) return x + "";
  5458. var coefficient = d[0],
  5459. exponent = d[1];
  5460. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  5461. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  5462. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  5463. };
  5464. var formatTypes = {
  5465. "": formatDefault,
  5466. "%": function(x, p) { return (x * 100).toFixed(p); },
  5467. "b": function(x) { return Math.round(x).toString(2); },
  5468. "c": function(x) { return x + ""; },
  5469. "d": function(x) { return Math.round(x).toString(10); },
  5470. "e": function(x, p) { return x.toExponential(p); },
  5471. "f": function(x, p) { return x.toFixed(p); },
  5472. "g": function(x, p) { return x.toPrecision(p); },
  5473. "o": function(x) { return Math.round(x).toString(8); },
  5474. "p": function(x, p) { return formatRounded(x * 100, p); },
  5475. "r": formatRounded,
  5476. "s": formatPrefixAuto,
  5477. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  5478. "x": function(x) { return Math.round(x).toString(16); }
  5479. };
  5480. // [[fill]align][sign][symbol][0][width][,][.precision][type]
  5481. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
  5482. function formatSpecifier(specifier) {
  5483. return new FormatSpecifier(specifier);
  5484. }
  5485. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  5486. function FormatSpecifier(specifier) {
  5487. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  5488. var match,
  5489. fill = match[1] || " ",
  5490. align = match[2] || ">",
  5491. sign = match[3] || "-",
  5492. symbol = match[4] || "",
  5493. zero = !!match[5],
  5494. width = match[6] && +match[6],
  5495. comma = !!match[7],
  5496. precision = match[8] && +match[8].slice(1),
  5497. type = match[9] || "";
  5498. // The "n" type is an alias for ",g".
  5499. if (type === "n") comma = true, type = "g";
  5500. // Map invalid types to the default format.
  5501. else if (!formatTypes[type]) type = "";
  5502. // If zero fill is specified, padding goes after sign and before digits.
  5503. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  5504. this.fill = fill;
  5505. this.align = align;
  5506. this.sign = sign;
  5507. this.symbol = symbol;
  5508. this.zero = zero;
  5509. this.width = width;
  5510. this.comma = comma;
  5511. this.precision = precision;
  5512. this.type = type;
  5513. }
  5514. FormatSpecifier.prototype.toString = function() {
  5515. return this.fill
  5516. + this.align
  5517. + this.sign
  5518. + this.symbol
  5519. + (this.zero ? "0" : "")
  5520. + (this.width == null ? "" : Math.max(1, this.width | 0))
  5521. + (this.comma ? "," : "")
  5522. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  5523. + this.type;
  5524. };
  5525. var identity$3 = function(x) {
  5526. return x;
  5527. };
  5528. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  5529. var formatLocale = function(locale) {
  5530. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  5531. currency = locale.currency,
  5532. decimal = locale.decimal,
  5533. numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
  5534. percent = locale.percent || "%";
  5535. function newFormat(specifier) {
  5536. specifier = formatSpecifier(specifier);
  5537. var fill = specifier.fill,
  5538. align = specifier.align,
  5539. sign = specifier.sign,
  5540. symbol = specifier.symbol,
  5541. zero = specifier.zero,
  5542. width = specifier.width,
  5543. comma = specifier.comma,
  5544. precision = specifier.precision,
  5545. type = specifier.type;
  5546. // Compute the prefix and suffix.
  5547. // For SI-prefix, the suffix is lazily computed.
  5548. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  5549. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
  5550. // What format function should we use?
  5551. // Is this an integer type?
  5552. // Can this type generate exponential notation?
  5553. var formatType = formatTypes[type],
  5554. maybeSuffix = !type || /[defgprs%]/.test(type);
  5555. // Set the default precision if not specified,
  5556. // or clamp the specified precision to the supported range.
  5557. // For significant precision, it must be in [1, 21].
  5558. // For fixed precision, it must be in [0, 20].
  5559. precision = precision == null ? (type ? 6 : 12)
  5560. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  5561. : Math.max(0, Math.min(20, precision));
  5562. function format(value) {
  5563. var valuePrefix = prefix,
  5564. valueSuffix = suffix,
  5565. i, n, c;
  5566. if (type === "c") {
  5567. valueSuffix = formatType(value) + valueSuffix;
  5568. value = "";
  5569. } else {
  5570. value = +value;
  5571. // Perform the initial formatting.
  5572. var valueNegative = value < 0;
  5573. value = formatType(Math.abs(value), precision);
  5574. // If a negative value rounds to zero during formatting, treat as positive.
  5575. if (valueNegative && +value === 0) valueNegative = false;
  5576. // Compute the prefix and suffix.
  5577. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  5578. valueSuffix = valueSuffix + (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + (valueNegative && sign === "(" ? ")" : "");
  5579. // Break the formatted value into the integer “value” part that can be
  5580. // grouped, and fractional or exponential “suffix” part that is not.
  5581. if (maybeSuffix) {
  5582. i = -1, n = value.length;
  5583. while (++i < n) {
  5584. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  5585. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  5586. value = value.slice(0, i);
  5587. break;
  5588. }
  5589. }
  5590. }
  5591. }
  5592. // If the fill character is not "0", grouping is applied before padding.
  5593. if (comma && !zero) value = group(value, Infinity);
  5594. // Compute the padding.
  5595. var length = valuePrefix.length + value.length + valueSuffix.length,
  5596. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  5597. // If the fill character is "0", grouping is applied after padding.
  5598. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  5599. // Reconstruct the final output based on the desired alignment.
  5600. switch (align) {
  5601. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  5602. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  5603. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  5604. default: value = padding + valuePrefix + value + valueSuffix; break;
  5605. }
  5606. return numerals(value);
  5607. }
  5608. format.toString = function() {
  5609. return specifier + "";
  5610. };
  5611. return format;
  5612. }
  5613. function formatPrefix(specifier, value) {
  5614. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  5615. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  5616. k = Math.pow(10, -e),
  5617. prefix = prefixes[8 + e / 3];
  5618. return function(value) {
  5619. return f(k * value) + prefix;
  5620. };
  5621. }
  5622. return {
  5623. format: newFormat,
  5624. formatPrefix: formatPrefix
  5625. };
  5626. };
  5627. var locale$1;
  5628. defaultLocale({
  5629. decimal: ".",
  5630. thousands: ",",
  5631. grouping: [3],
  5632. currency: ["$", ""]
  5633. });
  5634. function defaultLocale(definition) {
  5635. locale$1 = formatLocale(definition);
  5636. exports.format = locale$1.format;
  5637. exports.formatPrefix = locale$1.formatPrefix;
  5638. return locale$1;
  5639. }
  5640. var precisionFixed = function(step) {
  5641. return Math.max(0, -exponent$1(Math.abs(step)));
  5642. };
  5643. var precisionPrefix = function(step, value) {
  5644. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  5645. };
  5646. var precisionRound = function(step, max) {
  5647. step = Math.abs(step), max = Math.abs(max) - step;
  5648. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  5649. };
  5650. // Adds floating point numbers with twice the normal precision.
  5651. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  5652. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  5653. // 305–363 (1997).
  5654. // Code adapted from GeographicLib by Charles F. F. Karney,
  5655. // http://geographiclib.sourceforge.net/
  5656. var adder = function() {
  5657. return new Adder;
  5658. };
  5659. function Adder() {
  5660. this.reset();
  5661. }
  5662. Adder.prototype = {
  5663. constructor: Adder,
  5664. reset: function() {
  5665. this.s = // rounded value
  5666. this.t = 0; // exact error
  5667. },
  5668. add: function(y) {
  5669. add$1(temp, y, this.t);
  5670. add$1(this, temp.s, this.s);
  5671. if (this.s) this.t += temp.t;
  5672. else this.s = temp.t;
  5673. },
  5674. valueOf: function() {
  5675. return this.s;
  5676. }
  5677. };
  5678. var temp = new Adder;
  5679. function add$1(adder, a, b) {
  5680. var x = adder.s = a + b,
  5681. bv = x - a,
  5682. av = x - bv;
  5683. adder.t = (a - av) + (b - bv);
  5684. }
  5685. var epsilon$2 = 1e-6;
  5686. var epsilon2$1 = 1e-12;
  5687. var pi$3 = Math.PI;
  5688. var halfPi$2 = pi$3 / 2;
  5689. var quarterPi = pi$3 / 4;
  5690. var tau$3 = pi$3 * 2;
  5691. var degrees$1 = 180 / pi$3;
  5692. var radians = pi$3 / 180;
  5693. var abs = Math.abs;
  5694. var atan = Math.atan;
  5695. var atan2 = Math.atan2;
  5696. var cos$1 = Math.cos;
  5697. var ceil = Math.ceil;
  5698. var exp = Math.exp;
  5699. var log = Math.log;
  5700. var pow = Math.pow;
  5701. var sin$1 = Math.sin;
  5702. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  5703. var sqrt = Math.sqrt;
  5704. var tan = Math.tan;
  5705. function acos(x) {
  5706. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  5707. }
  5708. function asin(x) {
  5709. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  5710. }
  5711. function haversin(x) {
  5712. return (x = sin$1(x / 2)) * x;
  5713. }
  5714. function noop$1() {}
  5715. function streamGeometry(geometry, stream) {
  5716. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  5717. streamGeometryType[geometry.type](geometry, stream);
  5718. }
  5719. }
  5720. var streamObjectType = {
  5721. Feature: function(object, stream) {
  5722. streamGeometry(object.geometry, stream);
  5723. },
  5724. FeatureCollection: function(object, stream) {
  5725. var features = object.features, i = -1, n = features.length;
  5726. while (++i < n) streamGeometry(features[i].geometry, stream);
  5727. }
  5728. };
  5729. var streamGeometryType = {
  5730. Sphere: function(object, stream) {
  5731. stream.sphere();
  5732. },
  5733. Point: function(object, stream) {
  5734. object = object.coordinates;
  5735. stream.point(object[0], object[1], object[2]);
  5736. },
  5737. MultiPoint: function(object, stream) {
  5738. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5739. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  5740. },
  5741. LineString: function(object, stream) {
  5742. streamLine(object.coordinates, stream, 0);
  5743. },
  5744. MultiLineString: function(object, stream) {
  5745. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5746. while (++i < n) streamLine(coordinates[i], stream, 0);
  5747. },
  5748. Polygon: function(object, stream) {
  5749. streamPolygon(object.coordinates, stream);
  5750. },
  5751. MultiPolygon: function(object, stream) {
  5752. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5753. while (++i < n) streamPolygon(coordinates[i], stream);
  5754. },
  5755. GeometryCollection: function(object, stream) {
  5756. var geometries = object.geometries, i = -1, n = geometries.length;
  5757. while (++i < n) streamGeometry(geometries[i], stream);
  5758. }
  5759. };
  5760. function streamLine(coordinates, stream, closed) {
  5761. var i = -1, n = coordinates.length - closed, coordinate;
  5762. stream.lineStart();
  5763. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  5764. stream.lineEnd();
  5765. }
  5766. function streamPolygon(coordinates, stream) {
  5767. var i = -1, n = coordinates.length;
  5768. stream.polygonStart();
  5769. while (++i < n) streamLine(coordinates[i], stream, 1);
  5770. stream.polygonEnd();
  5771. }
  5772. var geoStream = function(object, stream) {
  5773. if (object && streamObjectType.hasOwnProperty(object.type)) {
  5774. streamObjectType[object.type](object, stream);
  5775. } else {
  5776. streamGeometry(object, stream);
  5777. }
  5778. };
  5779. var areaRingSum = adder();
  5780. var areaSum = adder();
  5781. var lambda00;
  5782. var phi00;
  5783. var lambda0;
  5784. var cosPhi0;
  5785. var sinPhi0;
  5786. var areaStream = {
  5787. point: noop$1,
  5788. lineStart: noop$1,
  5789. lineEnd: noop$1,
  5790. polygonStart: function() {
  5791. areaRingSum.reset();
  5792. areaStream.lineStart = areaRingStart;
  5793. areaStream.lineEnd = areaRingEnd;
  5794. },
  5795. polygonEnd: function() {
  5796. var areaRing = +areaRingSum;
  5797. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  5798. this.lineStart = this.lineEnd = this.point = noop$1;
  5799. },
  5800. sphere: function() {
  5801. areaSum.add(tau$3);
  5802. }
  5803. };
  5804. function areaRingStart() {
  5805. areaStream.point = areaPointFirst;
  5806. }
  5807. function areaRingEnd() {
  5808. areaPoint(lambda00, phi00);
  5809. }
  5810. function areaPointFirst(lambda, phi) {
  5811. areaStream.point = areaPoint;
  5812. lambda00 = lambda, phi00 = phi;
  5813. lambda *= radians, phi *= radians;
  5814. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  5815. }
  5816. function areaPoint(lambda, phi) {
  5817. lambda *= radians, phi *= radians;
  5818. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  5819. // Spherical excess E for a spherical triangle with vertices: south pole,
  5820. // previous point, current point. Uses a formula derived from Cagnoli’s
  5821. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  5822. var dLambda = lambda - lambda0,
  5823. sdLambda = dLambda >= 0 ? 1 : -1,
  5824. adLambda = sdLambda * dLambda,
  5825. cosPhi = cos$1(phi),
  5826. sinPhi = sin$1(phi),
  5827. k = sinPhi0 * sinPhi,
  5828. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  5829. v = k * sdLambda * sin$1(adLambda);
  5830. areaRingSum.add(atan2(v, u));
  5831. // Advance the previous points.
  5832. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  5833. }
  5834. var area = function(object) {
  5835. areaSum.reset();
  5836. geoStream(object, areaStream);
  5837. return areaSum * 2;
  5838. };
  5839. function spherical(cartesian) {
  5840. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  5841. }
  5842. function cartesian(spherical) {
  5843. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  5844. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  5845. }
  5846. function cartesianDot(a, b) {
  5847. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  5848. }
  5849. function cartesianCross(a, b) {
  5850. 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]];
  5851. }
  5852. // TODO return a
  5853. function cartesianAddInPlace(a, b) {
  5854. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  5855. }
  5856. function cartesianScale(vector, k) {
  5857. return [vector[0] * k, vector[1] * k, vector[2] * k];
  5858. }
  5859. // TODO return d
  5860. function cartesianNormalizeInPlace(d) {
  5861. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  5862. d[0] /= l, d[1] /= l, d[2] /= l;
  5863. }
  5864. var lambda0$1;
  5865. var phi0;
  5866. var lambda1;
  5867. var phi1;
  5868. var lambda2;
  5869. var lambda00$1;
  5870. var phi00$1;
  5871. var p0;
  5872. var deltaSum = adder();
  5873. var ranges;
  5874. var range;
  5875. var boundsStream = {
  5876. point: boundsPoint,
  5877. lineStart: boundsLineStart,
  5878. lineEnd: boundsLineEnd,
  5879. polygonStart: function() {
  5880. boundsStream.point = boundsRingPoint;
  5881. boundsStream.lineStart = boundsRingStart;
  5882. boundsStream.lineEnd = boundsRingEnd;
  5883. deltaSum.reset();
  5884. areaStream.polygonStart();
  5885. },
  5886. polygonEnd: function() {
  5887. areaStream.polygonEnd();
  5888. boundsStream.point = boundsPoint;
  5889. boundsStream.lineStart = boundsLineStart;
  5890. boundsStream.lineEnd = boundsLineEnd;
  5891. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  5892. else if (deltaSum > epsilon$2) phi1 = 90;
  5893. else if (deltaSum < -epsilon$2) phi0 = -90;
  5894. range[0] = lambda0$1, range[1] = lambda1;
  5895. }
  5896. };
  5897. function boundsPoint(lambda, phi) {
  5898. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  5899. if (phi < phi0) phi0 = phi;
  5900. if (phi > phi1) phi1 = phi;
  5901. }
  5902. function linePoint(lambda, phi) {
  5903. var p = cartesian([lambda * radians, phi * radians]);
  5904. if (p0) {
  5905. var normal = cartesianCross(p0, p),
  5906. equatorial = [normal[1], -normal[0], 0],
  5907. inflection = cartesianCross(equatorial, normal);
  5908. cartesianNormalizeInPlace(inflection);
  5909. inflection = spherical(inflection);
  5910. var delta = lambda - lambda2,
  5911. sign$$1 = delta > 0 ? 1 : -1,
  5912. lambdai = inflection[0] * degrees$1 * sign$$1,
  5913. phii,
  5914. antimeridian = abs(delta) > 180;
  5915. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  5916. phii = inflection[1] * degrees$1;
  5917. if (phii > phi1) phi1 = phii;
  5918. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  5919. phii = -inflection[1] * degrees$1;
  5920. if (phii < phi0) phi0 = phii;
  5921. } else {
  5922. if (phi < phi0) phi0 = phi;
  5923. if (phi > phi1) phi1 = phi;
  5924. }
  5925. if (antimeridian) {
  5926. if (lambda < lambda2) {
  5927. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  5928. } else {
  5929. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  5930. }
  5931. } else {
  5932. if (lambda1 >= lambda0$1) {
  5933. if (lambda < lambda0$1) lambda0$1 = lambda;
  5934. if (lambda > lambda1) lambda1 = lambda;
  5935. } else {
  5936. if (lambda > lambda2) {
  5937. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  5938. } else {
  5939. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  5940. }
  5941. }
  5942. }
  5943. } else {
  5944. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  5945. }
  5946. if (phi < phi0) phi0 = phi;
  5947. if (phi > phi1) phi1 = phi;
  5948. p0 = p, lambda2 = lambda;
  5949. }
  5950. function boundsLineStart() {
  5951. boundsStream.point = linePoint;
  5952. }
  5953. function boundsLineEnd() {
  5954. range[0] = lambda0$1, range[1] = lambda1;
  5955. boundsStream.point = boundsPoint;
  5956. p0 = null;
  5957. }
  5958. function boundsRingPoint(lambda, phi) {
  5959. if (p0) {
  5960. var delta = lambda - lambda2;
  5961. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  5962. } else {
  5963. lambda00$1 = lambda, phi00$1 = phi;
  5964. }
  5965. areaStream.point(lambda, phi);
  5966. linePoint(lambda, phi);
  5967. }
  5968. function boundsRingStart() {
  5969. areaStream.lineStart();
  5970. }
  5971. function boundsRingEnd() {
  5972. boundsRingPoint(lambda00$1, phi00$1);
  5973. areaStream.lineEnd();
  5974. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  5975. range[0] = lambda0$1, range[1] = lambda1;
  5976. p0 = null;
  5977. }
  5978. // Finds the left-right distance between two longitudes.
  5979. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  5980. // the distance between ±180° to be 360°.
  5981. function angle(lambda0, lambda1) {
  5982. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  5983. }
  5984. function rangeCompare(a, b) {
  5985. return a[0] - b[0];
  5986. }
  5987. function rangeContains(range, x) {
  5988. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  5989. }
  5990. var bounds = function(feature) {
  5991. var i, n, a, b, merged, deltaMax, delta;
  5992. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  5993. ranges = [];
  5994. geoStream(feature, boundsStream);
  5995. // First, sort ranges by their minimum longitudes.
  5996. if (n = ranges.length) {
  5997. ranges.sort(rangeCompare);
  5998. // Then, merge any ranges that overlap.
  5999. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6000. b = ranges[i];
  6001. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6002. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6003. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6004. } else {
  6005. merged.push(a = b);
  6006. }
  6007. }
  6008. // Finally, find the largest gap between the merged ranges.
  6009. // The final bounding box will be the inverse of this gap.
  6010. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6011. b = merged[i];
  6012. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6013. }
  6014. }
  6015. ranges = range = null;
  6016. return lambda0$1 === Infinity || phi0 === Infinity
  6017. ? [[NaN, NaN], [NaN, NaN]]
  6018. : [[lambda0$1, phi0], [lambda1, phi1]];
  6019. };
  6020. var W0;
  6021. var W1;
  6022. var X0;
  6023. var Y0;
  6024. var Z0;
  6025. var X1;
  6026. var Y1;
  6027. var Z1;
  6028. var X2;
  6029. var Y2;
  6030. var Z2;
  6031. var lambda00$2;
  6032. var phi00$2;
  6033. var x0;
  6034. var y0;
  6035. var z0; // previous point
  6036. var centroidStream = {
  6037. sphere: noop$1,
  6038. point: centroidPoint,
  6039. lineStart: centroidLineStart,
  6040. lineEnd: centroidLineEnd,
  6041. polygonStart: function() {
  6042. centroidStream.lineStart = centroidRingStart;
  6043. centroidStream.lineEnd = centroidRingEnd;
  6044. },
  6045. polygonEnd: function() {
  6046. centroidStream.lineStart = centroidLineStart;
  6047. centroidStream.lineEnd = centroidLineEnd;
  6048. }
  6049. };
  6050. // Arithmetic mean of Cartesian vectors.
  6051. function centroidPoint(lambda, phi) {
  6052. lambda *= radians, phi *= radians;
  6053. var cosPhi = cos$1(phi);
  6054. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6055. }
  6056. function centroidPointCartesian(x, y, z) {
  6057. ++W0;
  6058. X0 += (x - X0) / W0;
  6059. Y0 += (y - Y0) / W0;
  6060. Z0 += (z - Z0) / W0;
  6061. }
  6062. function centroidLineStart() {
  6063. centroidStream.point = centroidLinePointFirst;
  6064. }
  6065. function centroidLinePointFirst(lambda, phi) {
  6066. lambda *= radians, phi *= radians;
  6067. var cosPhi = cos$1(phi);
  6068. x0 = cosPhi * cos$1(lambda);
  6069. y0 = cosPhi * sin$1(lambda);
  6070. z0 = sin$1(phi);
  6071. centroidStream.point = centroidLinePoint;
  6072. centroidPointCartesian(x0, y0, z0);
  6073. }
  6074. function centroidLinePoint(lambda, phi) {
  6075. lambda *= radians, phi *= radians;
  6076. var cosPhi = cos$1(phi),
  6077. x = cosPhi * cos$1(lambda),
  6078. y = cosPhi * sin$1(lambda),
  6079. z = sin$1(phi),
  6080. 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);
  6081. W1 += w;
  6082. X1 += w * (x0 + (x0 = x));
  6083. Y1 += w * (y0 + (y0 = y));
  6084. Z1 += w * (z0 + (z0 = z));
  6085. centroidPointCartesian(x0, y0, z0);
  6086. }
  6087. function centroidLineEnd() {
  6088. centroidStream.point = centroidPoint;
  6089. }
  6090. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6091. // J. Applied Mechanics 42, 239 (1975).
  6092. function centroidRingStart() {
  6093. centroidStream.point = centroidRingPointFirst;
  6094. }
  6095. function centroidRingEnd() {
  6096. centroidRingPoint(lambda00$2, phi00$2);
  6097. centroidStream.point = centroidPoint;
  6098. }
  6099. function centroidRingPointFirst(lambda, phi) {
  6100. lambda00$2 = lambda, phi00$2 = phi;
  6101. lambda *= radians, phi *= radians;
  6102. centroidStream.point = centroidRingPoint;
  6103. var cosPhi = cos$1(phi);
  6104. x0 = cosPhi * cos$1(lambda);
  6105. y0 = cosPhi * sin$1(lambda);
  6106. z0 = sin$1(phi);
  6107. centroidPointCartesian(x0, y0, z0);
  6108. }
  6109. function centroidRingPoint(lambda, phi) {
  6110. lambda *= radians, phi *= radians;
  6111. var cosPhi = cos$1(phi),
  6112. x = cosPhi * cos$1(lambda),
  6113. y = cosPhi * sin$1(lambda),
  6114. z = sin$1(phi),
  6115. cx = y0 * z - z0 * y,
  6116. cy = z0 * x - x0 * z,
  6117. cz = x0 * y - y0 * x,
  6118. m = sqrt(cx * cx + cy * cy + cz * cz),
  6119. w = asin(m), // line weight = angle
  6120. v = m && -w / m; // area weight multiplier
  6121. X2 += v * cx;
  6122. Y2 += v * cy;
  6123. Z2 += v * cz;
  6124. W1 += w;
  6125. X1 += w * (x0 + (x0 = x));
  6126. Y1 += w * (y0 + (y0 = y));
  6127. Z1 += w * (z0 + (z0 = z));
  6128. centroidPointCartesian(x0, y0, z0);
  6129. }
  6130. var centroid = function(object) {
  6131. W0 = W1 =
  6132. X0 = Y0 = Z0 =
  6133. X1 = Y1 = Z1 =
  6134. X2 = Y2 = Z2 = 0;
  6135. geoStream(object, centroidStream);
  6136. var x = X2,
  6137. y = Y2,
  6138. z = Z2,
  6139. m = x * x + y * y + z * z;
  6140. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6141. if (m < epsilon2$1) {
  6142. x = X1, y = Y1, z = Z1;
  6143. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6144. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6145. m = x * x + y * y + z * z;
  6146. // If the feature still has an undefined ccentroid, then return.
  6147. if (m < epsilon2$1) return [NaN, NaN];
  6148. }
  6149. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6150. };
  6151. var constant$7 = function(x) {
  6152. return function() {
  6153. return x;
  6154. };
  6155. };
  6156. var compose = function(a, b) {
  6157. function compose(x, y) {
  6158. return x = a(x, y), b(x[0], x[1]);
  6159. }
  6160. if (a.invert && b.invert) compose.invert = function(x, y) {
  6161. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6162. };
  6163. return compose;
  6164. };
  6165. function rotationIdentity(lambda, phi) {
  6166. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6167. }
  6168. rotationIdentity.invert = rotationIdentity;
  6169. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6170. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6171. : rotationLambda(deltaLambda))
  6172. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6173. : rotationIdentity);
  6174. }
  6175. function forwardRotationLambda(deltaLambda) {
  6176. return function(lambda, phi) {
  6177. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6178. };
  6179. }
  6180. function rotationLambda(deltaLambda) {
  6181. var rotation = forwardRotationLambda(deltaLambda);
  6182. rotation.invert = forwardRotationLambda(-deltaLambda);
  6183. return rotation;
  6184. }
  6185. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6186. var cosDeltaPhi = cos$1(deltaPhi),
  6187. sinDeltaPhi = sin$1(deltaPhi),
  6188. cosDeltaGamma = cos$1(deltaGamma),
  6189. sinDeltaGamma = sin$1(deltaGamma);
  6190. function rotation(lambda, phi) {
  6191. var cosPhi = cos$1(phi),
  6192. x = cos$1(lambda) * cosPhi,
  6193. y = sin$1(lambda) * cosPhi,
  6194. z = sin$1(phi),
  6195. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6196. return [
  6197. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6198. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6199. ];
  6200. }
  6201. rotation.invert = function(lambda, phi) {
  6202. var cosPhi = cos$1(phi),
  6203. x = cos$1(lambda) * cosPhi,
  6204. y = sin$1(lambda) * cosPhi,
  6205. z = sin$1(phi),
  6206. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6207. return [
  6208. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6209. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6210. ];
  6211. };
  6212. return rotation;
  6213. }
  6214. var rotation = function(rotate) {
  6215. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6216. function forward(coordinates) {
  6217. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6218. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6219. }
  6220. forward.invert = function(coordinates) {
  6221. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6222. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6223. };
  6224. return forward;
  6225. };
  6226. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6227. function circleStream(stream, radius, delta, direction, t0, t1) {
  6228. if (!delta) return;
  6229. var cosRadius = cos$1(radius),
  6230. sinRadius = sin$1(radius),
  6231. step = direction * delta;
  6232. if (t0 == null) {
  6233. t0 = radius + direction * tau$3;
  6234. t1 = radius - step / 2;
  6235. } else {
  6236. t0 = circleRadius(cosRadius, t0);
  6237. t1 = circleRadius(cosRadius, t1);
  6238. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6239. }
  6240. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6241. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6242. stream.point(point[0], point[1]);
  6243. }
  6244. }
  6245. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6246. function circleRadius(cosRadius, point) {
  6247. point = cartesian(point), point[0] -= cosRadius;
  6248. cartesianNormalizeInPlace(point);
  6249. var radius = acos(-point[1]);
  6250. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6251. }
  6252. var circle = function() {
  6253. var center = constant$7([0, 0]),
  6254. radius = constant$7(90),
  6255. precision = constant$7(6),
  6256. ring,
  6257. rotate,
  6258. stream = {point: point};
  6259. function point(x, y) {
  6260. ring.push(x = rotate(x, y));
  6261. x[0] *= degrees$1, x[1] *= degrees$1;
  6262. }
  6263. function circle() {
  6264. var c = center.apply(this, arguments),
  6265. r = radius.apply(this, arguments) * radians,
  6266. p = precision.apply(this, arguments) * radians;
  6267. ring = [];
  6268. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6269. circleStream(stream, r, p, 1);
  6270. c = {type: "Polygon", coordinates: [ring]};
  6271. ring = rotate = null;
  6272. return c;
  6273. }
  6274. circle.center = function(_) {
  6275. return arguments.length ? (center = typeof _ === "function" ? _ : constant$7([+_[0], +_[1]]), circle) : center;
  6276. };
  6277. circle.radius = function(_) {
  6278. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), circle) : radius;
  6279. };
  6280. circle.precision = function(_) {
  6281. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$7(+_), circle) : precision;
  6282. };
  6283. return circle;
  6284. };
  6285. var clipBuffer = function() {
  6286. var lines = [],
  6287. line;
  6288. return {
  6289. point: function(x, y) {
  6290. line.push([x, y]);
  6291. },
  6292. lineStart: function() {
  6293. lines.push(line = []);
  6294. },
  6295. lineEnd: noop$1,
  6296. rejoin: function() {
  6297. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6298. },
  6299. result: function() {
  6300. var result = lines;
  6301. lines = [];
  6302. line = null;
  6303. return result;
  6304. }
  6305. };
  6306. };
  6307. var clipLine = function(a, b, x0, y0, x1, y1) {
  6308. var ax = a[0],
  6309. ay = a[1],
  6310. bx = b[0],
  6311. by = b[1],
  6312. t0 = 0,
  6313. t1 = 1,
  6314. dx = bx - ax,
  6315. dy = by - ay,
  6316. r;
  6317. r = x0 - ax;
  6318. if (!dx && r > 0) return;
  6319. r /= dx;
  6320. if (dx < 0) {
  6321. if (r < t0) return;
  6322. if (r < t1) t1 = r;
  6323. } else if (dx > 0) {
  6324. if (r > t1) return;
  6325. if (r > t0) t0 = r;
  6326. }
  6327. r = x1 - ax;
  6328. if (!dx && r < 0) return;
  6329. r /= dx;
  6330. if (dx < 0) {
  6331. if (r > t1) return;
  6332. if (r > t0) t0 = r;
  6333. } else if (dx > 0) {
  6334. if (r < t0) return;
  6335. if (r < t1) t1 = r;
  6336. }
  6337. r = y0 - ay;
  6338. if (!dy && r > 0) return;
  6339. r /= dy;
  6340. if (dy < 0) {
  6341. if (r < t0) return;
  6342. if (r < t1) t1 = r;
  6343. } else if (dy > 0) {
  6344. if (r > t1) return;
  6345. if (r > t0) t0 = r;
  6346. }
  6347. r = y1 - ay;
  6348. if (!dy && r < 0) return;
  6349. r /= dy;
  6350. if (dy < 0) {
  6351. if (r > t1) return;
  6352. if (r > t0) t0 = r;
  6353. } else if (dy > 0) {
  6354. if (r < t0) return;
  6355. if (r < t1) t1 = r;
  6356. }
  6357. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  6358. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  6359. return true;
  6360. };
  6361. var pointEqual = function(a, b) {
  6362. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6363. };
  6364. function Intersection(point, points, other, entry) {
  6365. this.x = point;
  6366. this.z = points;
  6367. this.o = other; // another intersection
  6368. this.e = entry; // is an entry?
  6369. this.v = false; // visited
  6370. this.n = this.p = null; // next & previous
  6371. }
  6372. // A generalized polygon clipping algorithm: given a polygon that has been cut
  6373. // into its visible line segments, and rejoins the segments by interpolating
  6374. // along the clip edge.
  6375. var clipPolygon = function(segments, compareIntersection, startInside, interpolate, stream) {
  6376. var subject = [],
  6377. clip = [],
  6378. i,
  6379. n;
  6380. segments.forEach(function(segment) {
  6381. if ((n = segment.length - 1) <= 0) return;
  6382. var n, p0 = segment[0], p1 = segment[n], x;
  6383. // If the first and last points of a segment are coincident, then treat as a
  6384. // closed ring. TODO if all rings are closed, then the winding order of the
  6385. // exterior ring should be checked.
  6386. if (pointEqual(p0, p1)) {
  6387. stream.lineStart();
  6388. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  6389. stream.lineEnd();
  6390. return;
  6391. }
  6392. subject.push(x = new Intersection(p0, segment, null, true));
  6393. clip.push(x.o = new Intersection(p0, null, x, false));
  6394. subject.push(x = new Intersection(p1, segment, null, false));
  6395. clip.push(x.o = new Intersection(p1, null, x, true));
  6396. });
  6397. if (!subject.length) return;
  6398. clip.sort(compareIntersection);
  6399. link$1(subject);
  6400. link$1(clip);
  6401. for (i = 0, n = clip.length; i < n; ++i) {
  6402. clip[i].e = startInside = !startInside;
  6403. }
  6404. var start = subject[0],
  6405. points,
  6406. point;
  6407. while (1) {
  6408. // Find first unvisited intersection.
  6409. var current = start,
  6410. isSubject = true;
  6411. while (current.v) if ((current = current.n) === start) return;
  6412. points = current.z;
  6413. stream.lineStart();
  6414. do {
  6415. current.v = current.o.v = true;
  6416. if (current.e) {
  6417. if (isSubject) {
  6418. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  6419. } else {
  6420. interpolate(current.x, current.n.x, 1, stream);
  6421. }
  6422. current = current.n;
  6423. } else {
  6424. if (isSubject) {
  6425. points = current.p.z;
  6426. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  6427. } else {
  6428. interpolate(current.x, current.p.x, -1, stream);
  6429. }
  6430. current = current.p;
  6431. }
  6432. current = current.o;
  6433. points = current.z;
  6434. isSubject = !isSubject;
  6435. } while (!current.v);
  6436. stream.lineEnd();
  6437. }
  6438. };
  6439. function link$1(array) {
  6440. if (!(n = array.length)) return;
  6441. var n,
  6442. i = 0,
  6443. a = array[0],
  6444. b;
  6445. while (++i < n) {
  6446. a.n = b = array[i];
  6447. b.p = a;
  6448. a = b;
  6449. }
  6450. a.n = b = array[0];
  6451. b.p = a;
  6452. }
  6453. var clipMax = 1e9;
  6454. var clipMin = -clipMax;
  6455. // TODO Use d3-polygon’s polygonContains here for the ring check?
  6456. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  6457. function clipExtent(x0, y0, x1, y1) {
  6458. function visible(x, y) {
  6459. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  6460. }
  6461. function interpolate(from, to, direction, stream) {
  6462. var a = 0, a1 = 0;
  6463. if (from == null
  6464. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  6465. || comparePoint(from, to) < 0 ^ direction > 0) {
  6466. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  6467. while ((a = (a + direction + 4) % 4) !== a1);
  6468. } else {
  6469. stream.point(to[0], to[1]);
  6470. }
  6471. }
  6472. function corner(p, direction) {
  6473. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  6474. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  6475. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  6476. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  6477. }
  6478. function compareIntersection(a, b) {
  6479. return comparePoint(a.x, b.x);
  6480. }
  6481. function comparePoint(a, b) {
  6482. var ca = corner(a, 1),
  6483. cb = corner(b, 1);
  6484. return ca !== cb ? ca - cb
  6485. : ca === 0 ? b[1] - a[1]
  6486. : ca === 1 ? a[0] - b[0]
  6487. : ca === 2 ? a[1] - b[1]
  6488. : b[0] - a[0];
  6489. }
  6490. return function(stream) {
  6491. var activeStream = stream,
  6492. bufferStream = clipBuffer(),
  6493. segments,
  6494. polygon,
  6495. ring,
  6496. x__, y__, v__, // first point
  6497. x_, y_, v_, // previous point
  6498. first,
  6499. clean;
  6500. var clipStream = {
  6501. point: point,
  6502. lineStart: lineStart,
  6503. lineEnd: lineEnd,
  6504. polygonStart: polygonStart,
  6505. polygonEnd: polygonEnd
  6506. };
  6507. function point(x, y) {
  6508. if (visible(x, y)) activeStream.point(x, y);
  6509. }
  6510. function polygonInside() {
  6511. var winding = 0;
  6512. for (var i = 0, n = polygon.length; i < n; ++i) {
  6513. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  6514. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  6515. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  6516. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  6517. }
  6518. }
  6519. return winding;
  6520. }
  6521. // Buffer geometry within a polygon and then clip it en masse.
  6522. function polygonStart() {
  6523. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  6524. }
  6525. function polygonEnd() {
  6526. var startInside = polygonInside(),
  6527. cleanInside = clean && startInside,
  6528. visible = (segments = merge(segments)).length;
  6529. if (cleanInside || visible) {
  6530. stream.polygonStart();
  6531. if (cleanInside) {
  6532. stream.lineStart();
  6533. interpolate(null, null, 1, stream);
  6534. stream.lineEnd();
  6535. }
  6536. if (visible) {
  6537. clipPolygon(segments, compareIntersection, startInside, interpolate, stream);
  6538. }
  6539. stream.polygonEnd();
  6540. }
  6541. activeStream = stream, segments = polygon = ring = null;
  6542. }
  6543. function lineStart() {
  6544. clipStream.point = linePoint;
  6545. if (polygon) polygon.push(ring = []);
  6546. first = true;
  6547. v_ = false;
  6548. x_ = y_ = NaN;
  6549. }
  6550. // TODO rather than special-case polygons, simply handle them separately.
  6551. // Ideally, coincident intersection points should be jittered to avoid
  6552. // clipping issues.
  6553. function lineEnd() {
  6554. if (segments) {
  6555. linePoint(x__, y__);
  6556. if (v__ && v_) bufferStream.rejoin();
  6557. segments.push(bufferStream.result());
  6558. }
  6559. clipStream.point = point;
  6560. if (v_) activeStream.lineEnd();
  6561. }
  6562. function linePoint(x, y) {
  6563. var v = visible(x, y);
  6564. if (polygon) ring.push([x, y]);
  6565. if (first) {
  6566. x__ = x, y__ = y, v__ = v;
  6567. first = false;
  6568. if (v) {
  6569. activeStream.lineStart();
  6570. activeStream.point(x, y);
  6571. }
  6572. } else {
  6573. if (v && v_) activeStream.point(x, y);
  6574. else {
  6575. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  6576. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  6577. if (clipLine(a, b, x0, y0, x1, y1)) {
  6578. if (!v_) {
  6579. activeStream.lineStart();
  6580. activeStream.point(a[0], a[1]);
  6581. }
  6582. activeStream.point(b[0], b[1]);
  6583. if (!v) activeStream.lineEnd();
  6584. clean = false;
  6585. } else if (v) {
  6586. activeStream.lineStart();
  6587. activeStream.point(x, y);
  6588. clean = false;
  6589. }
  6590. }
  6591. }
  6592. x_ = x, y_ = y, v_ = v;
  6593. }
  6594. return clipStream;
  6595. };
  6596. }
  6597. var extent$1 = function() {
  6598. var x0 = 0,
  6599. y0 = 0,
  6600. x1 = 960,
  6601. y1 = 500,
  6602. cache,
  6603. cacheStream,
  6604. clip;
  6605. return clip = {
  6606. stream: function(stream) {
  6607. return cache && cacheStream === stream ? cache : cache = clipExtent(x0, y0, x1, y1)(cacheStream = stream);
  6608. },
  6609. extent: function(_) {
  6610. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  6611. }
  6612. };
  6613. };
  6614. var sum$1 = adder();
  6615. var polygonContains = function(polygon, point) {
  6616. var lambda = point[0],
  6617. phi = point[1],
  6618. normal = [sin$1(lambda), -cos$1(lambda), 0],
  6619. angle = 0,
  6620. winding = 0;
  6621. sum$1.reset();
  6622. for (var i = 0, n = polygon.length; i < n; ++i) {
  6623. if (!(m = (ring = polygon[i]).length)) continue;
  6624. var ring,
  6625. m,
  6626. point0 = ring[m - 1],
  6627. lambda0 = point0[0],
  6628. phi0 = point0[1] / 2 + quarterPi,
  6629. sinPhi0 = sin$1(phi0),
  6630. cosPhi0 = cos$1(phi0);
  6631. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  6632. var point1 = ring[j],
  6633. lambda1 = point1[0],
  6634. phi1 = point1[1] / 2 + quarterPi,
  6635. sinPhi1 = sin$1(phi1),
  6636. cosPhi1 = cos$1(phi1),
  6637. delta = lambda1 - lambda0,
  6638. sign$$1 = delta >= 0 ? 1 : -1,
  6639. absDelta = sign$$1 * delta,
  6640. antimeridian = absDelta > pi$3,
  6641. k = sinPhi0 * sinPhi1;
  6642. sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  6643. angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
  6644. // Are the longitudes either side of the point’s meridian (lambda),
  6645. // and are the latitudes smaller than the parallel (phi)?
  6646. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  6647. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  6648. cartesianNormalizeInPlace(arc);
  6649. var intersection = cartesianCross(normal, arc);
  6650. cartesianNormalizeInPlace(intersection);
  6651. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  6652. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  6653. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  6654. }
  6655. }
  6656. }
  6657. }
  6658. // First, determine whether the South pole is inside or outside:
  6659. //
  6660. // It is inside if:
  6661. // * the polygon winds around it in a clockwise direction.
  6662. // * the polygon does not (cumulatively) wind around it, but has a negative
  6663. // (counter-clockwise) area.
  6664. //
  6665. // Second, count the (signed) number of times a segment crosses a lambda
  6666. // from the point to the South pole. If it is zero, then the point is the
  6667. // same side as the South pole.
  6668. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  6669. };
  6670. var lengthSum = adder();
  6671. var lambda0$2;
  6672. var sinPhi0$1;
  6673. var cosPhi0$1;
  6674. var lengthStream = {
  6675. sphere: noop$1,
  6676. point: noop$1,
  6677. lineStart: lengthLineStart,
  6678. lineEnd: noop$1,
  6679. polygonStart: noop$1,
  6680. polygonEnd: noop$1
  6681. };
  6682. function lengthLineStart() {
  6683. lengthStream.point = lengthPointFirst;
  6684. lengthStream.lineEnd = lengthLineEnd;
  6685. }
  6686. function lengthLineEnd() {
  6687. lengthStream.point = lengthStream.lineEnd = noop$1;
  6688. }
  6689. function lengthPointFirst(lambda, phi) {
  6690. lambda *= radians, phi *= radians;
  6691. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  6692. lengthStream.point = lengthPoint;
  6693. }
  6694. function lengthPoint(lambda, phi) {
  6695. lambda *= radians, phi *= radians;
  6696. var sinPhi = sin$1(phi),
  6697. cosPhi = cos$1(phi),
  6698. delta = abs(lambda - lambda0$2),
  6699. cosDelta = cos$1(delta),
  6700. sinDelta = sin$1(delta),
  6701. x = cosPhi * sinDelta,
  6702. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  6703. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  6704. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  6705. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  6706. }
  6707. var length$1 = function(object) {
  6708. lengthSum.reset();
  6709. geoStream(object, lengthStream);
  6710. return +lengthSum;
  6711. };
  6712. var coordinates = [null, null];
  6713. var object$1 = {type: "LineString", coordinates: coordinates};
  6714. var distance = function(a, b) {
  6715. coordinates[0] = a;
  6716. coordinates[1] = b;
  6717. return length$1(object$1);
  6718. };
  6719. var containsObjectType = {
  6720. Feature: function(object, point) {
  6721. return containsGeometry(object.geometry, point);
  6722. },
  6723. FeatureCollection: function(object, point) {
  6724. var features = object.features, i = -1, n = features.length;
  6725. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  6726. return false;
  6727. }
  6728. };
  6729. var containsGeometryType = {
  6730. Sphere: function() {
  6731. return true;
  6732. },
  6733. Point: function(object, point) {
  6734. return containsPoint(object.coordinates, point);
  6735. },
  6736. MultiPoint: function(object, point) {
  6737. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6738. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  6739. return false;
  6740. },
  6741. LineString: function(object, point) {
  6742. return containsLine(object.coordinates, point);
  6743. },
  6744. MultiLineString: function(object, point) {
  6745. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6746. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  6747. return false;
  6748. },
  6749. Polygon: function(object, point) {
  6750. return containsPolygon(object.coordinates, point);
  6751. },
  6752. MultiPolygon: function(object, point) {
  6753. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6754. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  6755. return false;
  6756. },
  6757. GeometryCollection: function(object, point) {
  6758. var geometries = object.geometries, i = -1, n = geometries.length;
  6759. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  6760. return false;
  6761. }
  6762. };
  6763. function containsGeometry(geometry, point) {
  6764. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  6765. ? containsGeometryType[geometry.type](geometry, point)
  6766. : false;
  6767. }
  6768. function containsPoint(coordinates, point) {
  6769. return distance(coordinates, point) === 0;
  6770. }
  6771. function containsLine(coordinates, point) {
  6772. var ab = distance(coordinates[0], coordinates[1]),
  6773. ao = distance(coordinates[0], point),
  6774. ob = distance(point, coordinates[1]);
  6775. return ao + ob <= ab + epsilon$2;
  6776. }
  6777. function containsPolygon(coordinates, point) {
  6778. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  6779. }
  6780. function ringRadians(ring) {
  6781. return ring = ring.map(pointRadians), ring.pop(), ring;
  6782. }
  6783. function pointRadians(point) {
  6784. return [point[0] * radians, point[1] * radians];
  6785. }
  6786. var contains = function(object, point) {
  6787. return (object && containsObjectType.hasOwnProperty(object.type)
  6788. ? containsObjectType[object.type]
  6789. : containsGeometry)(object, point);
  6790. };
  6791. function graticuleX(y0, y1, dy) {
  6792. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  6793. return function(x) { return y.map(function(y) { return [x, y]; }); };
  6794. }
  6795. function graticuleY(x0, x1, dx) {
  6796. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  6797. return function(y) { return x.map(function(x) { return [x, y]; }); };
  6798. }
  6799. function graticule() {
  6800. var x1, x0, X1, X0,
  6801. y1, y0, Y1, Y0,
  6802. dx = 10, dy = dx, DX = 90, DY = 360,
  6803. x, y, X, Y,
  6804. precision = 2.5;
  6805. function graticule() {
  6806. return {type: "MultiLineString", coordinates: lines()};
  6807. }
  6808. function lines() {
  6809. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  6810. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  6811. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  6812. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  6813. }
  6814. graticule.lines = function() {
  6815. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  6816. };
  6817. graticule.outline = function() {
  6818. return {
  6819. type: "Polygon",
  6820. coordinates: [
  6821. X(X0).concat(
  6822. Y(Y1).slice(1),
  6823. X(X1).reverse().slice(1),
  6824. Y(Y0).reverse().slice(1))
  6825. ]
  6826. };
  6827. };
  6828. graticule.extent = function(_) {
  6829. if (!arguments.length) return graticule.extentMinor();
  6830. return graticule.extentMajor(_).extentMinor(_);
  6831. };
  6832. graticule.extentMajor = function(_) {
  6833. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  6834. X0 = +_[0][0], X1 = +_[1][0];
  6835. Y0 = +_[0][1], Y1 = +_[1][1];
  6836. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  6837. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  6838. return graticule.precision(precision);
  6839. };
  6840. graticule.extentMinor = function(_) {
  6841. if (!arguments.length) return [[x0, y0], [x1, y1]];
  6842. x0 = +_[0][0], x1 = +_[1][0];
  6843. y0 = +_[0][1], y1 = +_[1][1];
  6844. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  6845. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  6846. return graticule.precision(precision);
  6847. };
  6848. graticule.step = function(_) {
  6849. if (!arguments.length) return graticule.stepMinor();
  6850. return graticule.stepMajor(_).stepMinor(_);
  6851. };
  6852. graticule.stepMajor = function(_) {
  6853. if (!arguments.length) return [DX, DY];
  6854. DX = +_[0], DY = +_[1];
  6855. return graticule;
  6856. };
  6857. graticule.stepMinor = function(_) {
  6858. if (!arguments.length) return [dx, dy];
  6859. dx = +_[0], dy = +_[1];
  6860. return graticule;
  6861. };
  6862. graticule.precision = function(_) {
  6863. if (!arguments.length) return precision;
  6864. precision = +_;
  6865. x = graticuleX(y0, y1, 90);
  6866. y = graticuleY(x0, x1, precision);
  6867. X = graticuleX(Y0, Y1, 90);
  6868. Y = graticuleY(X0, X1, precision);
  6869. return graticule;
  6870. };
  6871. return graticule
  6872. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  6873. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  6874. }
  6875. function graticule10() {
  6876. return graticule()();
  6877. }
  6878. var interpolate$1 = function(a, b) {
  6879. var x0 = a[0] * radians,
  6880. y0 = a[1] * radians,
  6881. x1 = b[0] * radians,
  6882. y1 = b[1] * radians,
  6883. cy0 = cos$1(y0),
  6884. sy0 = sin$1(y0),
  6885. cy1 = cos$1(y1),
  6886. sy1 = sin$1(y1),
  6887. kx0 = cy0 * cos$1(x0),
  6888. ky0 = cy0 * sin$1(x0),
  6889. kx1 = cy1 * cos$1(x1),
  6890. ky1 = cy1 * sin$1(x1),
  6891. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  6892. k = sin$1(d);
  6893. var interpolate = d ? function(t) {
  6894. var B = sin$1(t *= d) / k,
  6895. A = sin$1(d - t) / k,
  6896. x = A * kx0 + B * kx1,
  6897. y = A * ky0 + B * ky1,
  6898. z = A * sy0 + B * sy1;
  6899. return [
  6900. atan2(y, x) * degrees$1,
  6901. atan2(z, sqrt(x * x + y * y)) * degrees$1
  6902. ];
  6903. } : function() {
  6904. return [x0 * degrees$1, y0 * degrees$1];
  6905. };
  6906. interpolate.distance = d;
  6907. return interpolate;
  6908. };
  6909. var identity$4 = function(x) {
  6910. return x;
  6911. };
  6912. var areaSum$1 = adder();
  6913. var areaRingSum$1 = adder();
  6914. var x00;
  6915. var y00;
  6916. var x0$1;
  6917. var y0$1;
  6918. var areaStream$1 = {
  6919. point: noop$1,
  6920. lineStart: noop$1,
  6921. lineEnd: noop$1,
  6922. polygonStart: function() {
  6923. areaStream$1.lineStart = areaRingStart$1;
  6924. areaStream$1.lineEnd = areaRingEnd$1;
  6925. },
  6926. polygonEnd: function() {
  6927. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$1;
  6928. areaSum$1.add(abs(areaRingSum$1));
  6929. areaRingSum$1.reset();
  6930. },
  6931. result: function() {
  6932. var area = areaSum$1 / 2;
  6933. areaSum$1.reset();
  6934. return area;
  6935. }
  6936. };
  6937. function areaRingStart$1() {
  6938. areaStream$1.point = areaPointFirst$1;
  6939. }
  6940. function areaPointFirst$1(x, y) {
  6941. areaStream$1.point = areaPoint$1;
  6942. x00 = x0$1 = x, y00 = y0$1 = y;
  6943. }
  6944. function areaPoint$1(x, y) {
  6945. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  6946. x0$1 = x, y0$1 = y;
  6947. }
  6948. function areaRingEnd$1() {
  6949. areaPoint$1(x00, y00);
  6950. }
  6951. var x0$2 = Infinity;
  6952. var y0$2 = x0$2;
  6953. var x1 = -x0$2;
  6954. var y1 = x1;
  6955. var boundsStream$1 = {
  6956. point: boundsPoint$1,
  6957. lineStart: noop$1,
  6958. lineEnd: noop$1,
  6959. polygonStart: noop$1,
  6960. polygonEnd: noop$1,
  6961. result: function() {
  6962. var bounds = [[x0$2, y0$2], [x1, y1]];
  6963. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  6964. return bounds;
  6965. }
  6966. };
  6967. function boundsPoint$1(x, y) {
  6968. if (x < x0$2) x0$2 = x;
  6969. if (x > x1) x1 = x;
  6970. if (y < y0$2) y0$2 = y;
  6971. if (y > y1) y1 = y;
  6972. }
  6973. // TODO Enforce positive area for exterior, negative area for interior?
  6974. var X0$1 = 0;
  6975. var Y0$1 = 0;
  6976. var Z0$1 = 0;
  6977. var X1$1 = 0;
  6978. var Y1$1 = 0;
  6979. var Z1$1 = 0;
  6980. var X2$1 = 0;
  6981. var Y2$1 = 0;
  6982. var Z2$1 = 0;
  6983. var x00$1;
  6984. var y00$1;
  6985. var x0$3;
  6986. var y0$3;
  6987. var centroidStream$1 = {
  6988. point: centroidPoint$1,
  6989. lineStart: centroidLineStart$1,
  6990. lineEnd: centroidLineEnd$1,
  6991. polygonStart: function() {
  6992. centroidStream$1.lineStart = centroidRingStart$1;
  6993. centroidStream$1.lineEnd = centroidRingEnd$1;
  6994. },
  6995. polygonEnd: function() {
  6996. centroidStream$1.point = centroidPoint$1;
  6997. centroidStream$1.lineStart = centroidLineStart$1;
  6998. centroidStream$1.lineEnd = centroidLineEnd$1;
  6999. },
  7000. result: function() {
  7001. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  7002. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  7003. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  7004. : [NaN, NaN];
  7005. X0$1 = Y0$1 = Z0$1 =
  7006. X1$1 = Y1$1 = Z1$1 =
  7007. X2$1 = Y2$1 = Z2$1 = 0;
  7008. return centroid;
  7009. }
  7010. };
  7011. function centroidPoint$1(x, y) {
  7012. X0$1 += x;
  7013. Y0$1 += y;
  7014. ++Z0$1;
  7015. }
  7016. function centroidLineStart$1() {
  7017. centroidStream$1.point = centroidPointFirstLine;
  7018. }
  7019. function centroidPointFirstLine(x, y) {
  7020. centroidStream$1.point = centroidPointLine;
  7021. centroidPoint$1(x0$3 = x, y0$3 = y);
  7022. }
  7023. function centroidPointLine(x, y) {
  7024. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  7025. X1$1 += z * (x0$3 + x) / 2;
  7026. Y1$1 += z * (y0$3 + y) / 2;
  7027. Z1$1 += z;
  7028. centroidPoint$1(x0$3 = x, y0$3 = y);
  7029. }
  7030. function centroidLineEnd$1() {
  7031. centroidStream$1.point = centroidPoint$1;
  7032. }
  7033. function centroidRingStart$1() {
  7034. centroidStream$1.point = centroidPointFirstRing;
  7035. }
  7036. function centroidRingEnd$1() {
  7037. centroidPointRing(x00$1, y00$1);
  7038. }
  7039. function centroidPointFirstRing(x, y) {
  7040. centroidStream$1.point = centroidPointRing;
  7041. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  7042. }
  7043. function centroidPointRing(x, y) {
  7044. var dx = x - x0$3,
  7045. dy = y - y0$3,
  7046. z = sqrt(dx * dx + dy * dy);
  7047. X1$1 += z * (x0$3 + x) / 2;
  7048. Y1$1 += z * (y0$3 + y) / 2;
  7049. Z1$1 += z;
  7050. z = y0$3 * x - x0$3 * y;
  7051. X2$1 += z * (x0$3 + x);
  7052. Y2$1 += z * (y0$3 + y);
  7053. Z2$1 += z * 3;
  7054. centroidPoint$1(x0$3 = x, y0$3 = y);
  7055. }
  7056. function PathContext(context) {
  7057. this._context = context;
  7058. }
  7059. PathContext.prototype = {
  7060. _radius: 4.5,
  7061. pointRadius: function(_) {
  7062. return this._radius = _, this;
  7063. },
  7064. polygonStart: function() {
  7065. this._line = 0;
  7066. },
  7067. polygonEnd: function() {
  7068. this._line = NaN;
  7069. },
  7070. lineStart: function() {
  7071. this._point = 0;
  7072. },
  7073. lineEnd: function() {
  7074. if (this._line === 0) this._context.closePath();
  7075. this._point = NaN;
  7076. },
  7077. point: function(x, y) {
  7078. switch (this._point) {
  7079. case 0: {
  7080. this._context.moveTo(x, y);
  7081. this._point = 1;
  7082. break;
  7083. }
  7084. case 1: {
  7085. this._context.lineTo(x, y);
  7086. break;
  7087. }
  7088. default: {
  7089. this._context.moveTo(x + this._radius, y);
  7090. this._context.arc(x, y, this._radius, 0, tau$3);
  7091. break;
  7092. }
  7093. }
  7094. },
  7095. result: noop$1
  7096. };
  7097. var lengthSum$1 = adder();
  7098. var lengthRing;
  7099. var x00$2;
  7100. var y00$2;
  7101. var x0$4;
  7102. var y0$4;
  7103. var lengthStream$1 = {
  7104. point: noop$1,
  7105. lineStart: function() {
  7106. lengthStream$1.point = lengthPointFirst$1;
  7107. },
  7108. lineEnd: function() {
  7109. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  7110. lengthStream$1.point = noop$1;
  7111. },
  7112. polygonStart: function() {
  7113. lengthRing = true;
  7114. },
  7115. polygonEnd: function() {
  7116. lengthRing = null;
  7117. },
  7118. result: function() {
  7119. var length = +lengthSum$1;
  7120. lengthSum$1.reset();
  7121. return length;
  7122. }
  7123. };
  7124. function lengthPointFirst$1(x, y) {
  7125. lengthStream$1.point = lengthPoint$1;
  7126. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  7127. }
  7128. function lengthPoint$1(x, y) {
  7129. x0$4 -= x, y0$4 -= y;
  7130. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  7131. x0$4 = x, y0$4 = y;
  7132. }
  7133. function PathString() {
  7134. this._string = [];
  7135. }
  7136. PathString.prototype = {
  7137. _radius: 4.5,
  7138. _circle: circle$1(4.5),
  7139. pointRadius: function(_) {
  7140. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  7141. return this;
  7142. },
  7143. polygonStart: function() {
  7144. this._line = 0;
  7145. },
  7146. polygonEnd: function() {
  7147. this._line = NaN;
  7148. },
  7149. lineStart: function() {
  7150. this._point = 0;
  7151. },
  7152. lineEnd: function() {
  7153. if (this._line === 0) this._string.push("Z");
  7154. this._point = NaN;
  7155. },
  7156. point: function(x, y) {
  7157. switch (this._point) {
  7158. case 0: {
  7159. this._string.push("M", x, ",", y);
  7160. this._point = 1;
  7161. break;
  7162. }
  7163. case 1: {
  7164. this._string.push("L", x, ",", y);
  7165. break;
  7166. }
  7167. default: {
  7168. if (this._circle == null) this._circle = circle$1(this._radius);
  7169. this._string.push("M", x, ",", y, this._circle);
  7170. break;
  7171. }
  7172. }
  7173. },
  7174. result: function() {
  7175. if (this._string.length) {
  7176. var result = this._string.join("");
  7177. this._string = [];
  7178. return result;
  7179. } else {
  7180. return null;
  7181. }
  7182. }
  7183. };
  7184. function circle$1(radius) {
  7185. return "m0," + radius
  7186. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  7187. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  7188. + "z";
  7189. }
  7190. var index$1 = function(projection, context) {
  7191. var pointRadius = 4.5,
  7192. projectionStream,
  7193. contextStream;
  7194. function path(object) {
  7195. if (object) {
  7196. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  7197. geoStream(object, projectionStream(contextStream));
  7198. }
  7199. return contextStream.result();
  7200. }
  7201. path.area = function(object) {
  7202. geoStream(object, projectionStream(areaStream$1));
  7203. return areaStream$1.result();
  7204. };
  7205. path.measure = function(object) {
  7206. geoStream(object, projectionStream(lengthStream$1));
  7207. return lengthStream$1.result();
  7208. };
  7209. path.bounds = function(object) {
  7210. geoStream(object, projectionStream(boundsStream$1));
  7211. return boundsStream$1.result();
  7212. };
  7213. path.centroid = function(object) {
  7214. geoStream(object, projectionStream(centroidStream$1));
  7215. return centroidStream$1.result();
  7216. };
  7217. path.projection = function(_) {
  7218. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  7219. };
  7220. path.context = function(_) {
  7221. if (!arguments.length) return context;
  7222. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  7223. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  7224. return path;
  7225. };
  7226. path.pointRadius = function(_) {
  7227. if (!arguments.length) return pointRadius;
  7228. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  7229. return path;
  7230. };
  7231. return path.projection(projection).context(context);
  7232. };
  7233. var clip = function(pointVisible, clipLine, interpolate, start) {
  7234. return function(rotate, sink) {
  7235. var line = clipLine(sink),
  7236. rotatedStart = rotate.invert(start[0], start[1]),
  7237. ringBuffer = clipBuffer(),
  7238. ringSink = clipLine(ringBuffer),
  7239. polygonStarted = false,
  7240. polygon,
  7241. segments,
  7242. ring;
  7243. var clip = {
  7244. point: point,
  7245. lineStart: lineStart,
  7246. lineEnd: lineEnd,
  7247. polygonStart: function() {
  7248. clip.point = pointRing;
  7249. clip.lineStart = ringStart;
  7250. clip.lineEnd = ringEnd;
  7251. segments = [];
  7252. polygon = [];
  7253. },
  7254. polygonEnd: function() {
  7255. clip.point = point;
  7256. clip.lineStart = lineStart;
  7257. clip.lineEnd = lineEnd;
  7258. segments = merge(segments);
  7259. var startInside = polygonContains(polygon, rotatedStart);
  7260. if (segments.length) {
  7261. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7262. clipPolygon(segments, compareIntersection, startInside, interpolate, sink);
  7263. } else if (startInside) {
  7264. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7265. sink.lineStart();
  7266. interpolate(null, null, 1, sink);
  7267. sink.lineEnd();
  7268. }
  7269. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  7270. segments = polygon = null;
  7271. },
  7272. sphere: function() {
  7273. sink.polygonStart();
  7274. sink.lineStart();
  7275. interpolate(null, null, 1, sink);
  7276. sink.lineEnd();
  7277. sink.polygonEnd();
  7278. }
  7279. };
  7280. function point(lambda, phi) {
  7281. var point = rotate(lambda, phi);
  7282. if (pointVisible(lambda = point[0], phi = point[1])) sink.point(lambda, phi);
  7283. }
  7284. function pointLine(lambda, phi) {
  7285. var point = rotate(lambda, phi);
  7286. line.point(point[0], point[1]);
  7287. }
  7288. function lineStart() {
  7289. clip.point = pointLine;
  7290. line.lineStart();
  7291. }
  7292. function lineEnd() {
  7293. clip.point = point;
  7294. line.lineEnd();
  7295. }
  7296. function pointRing(lambda, phi) {
  7297. ring.push([lambda, phi]);
  7298. var point = rotate(lambda, phi);
  7299. ringSink.point(point[0], point[1]);
  7300. }
  7301. function ringStart() {
  7302. ringSink.lineStart();
  7303. ring = [];
  7304. }
  7305. function ringEnd() {
  7306. pointRing(ring[0][0], ring[0][1]);
  7307. ringSink.lineEnd();
  7308. var clean = ringSink.clean(),
  7309. ringSegments = ringBuffer.result(),
  7310. i, n = ringSegments.length, m,
  7311. segment,
  7312. point;
  7313. ring.pop();
  7314. polygon.push(ring);
  7315. ring = null;
  7316. if (!n) return;
  7317. // No intersections.
  7318. if (clean & 1) {
  7319. segment = ringSegments[0];
  7320. if ((m = segment.length - 1) > 0) {
  7321. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7322. sink.lineStart();
  7323. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7324. sink.lineEnd();
  7325. }
  7326. return;
  7327. }
  7328. // Rejoin connected segments.
  7329. // TODO reuse ringBuffer.rejoin()?
  7330. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7331. segments.push(ringSegments.filter(validSegment));
  7332. }
  7333. return clip;
  7334. };
  7335. };
  7336. function validSegment(segment) {
  7337. return segment.length > 1;
  7338. }
  7339. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7340. // and circle clipping, the same comparison is used.
  7341. function compareIntersection(a, b) {
  7342. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7343. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7344. }
  7345. var clipAntimeridian = clip(
  7346. function() { return true; },
  7347. clipAntimeridianLine,
  7348. clipAntimeridianInterpolate,
  7349. [-pi$3, -halfPi$2]
  7350. );
  7351. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7352. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7353. // intersections, and the first and last segments should be rejoined.
  7354. function clipAntimeridianLine(stream) {
  7355. var lambda0 = NaN,
  7356. phi0 = NaN,
  7357. sign0 = NaN,
  7358. clean; // no intersections
  7359. return {
  7360. lineStart: function() {
  7361. stream.lineStart();
  7362. clean = 1;
  7363. },
  7364. point: function(lambda1, phi1) {
  7365. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7366. delta = abs(lambda1 - lambda0);
  7367. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7368. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7369. stream.point(sign0, phi0);
  7370. stream.lineEnd();
  7371. stream.lineStart();
  7372. stream.point(sign1, phi0);
  7373. stream.point(lambda1, phi0);
  7374. clean = 0;
  7375. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7376. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7377. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7378. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7379. stream.point(sign0, phi0);
  7380. stream.lineEnd();
  7381. stream.lineStart();
  7382. stream.point(sign1, phi0);
  7383. clean = 0;
  7384. }
  7385. stream.point(lambda0 = lambda1, phi0 = phi1);
  7386. sign0 = sign1;
  7387. },
  7388. lineEnd: function() {
  7389. stream.lineEnd();
  7390. lambda0 = phi0 = NaN;
  7391. },
  7392. clean: function() {
  7393. return 2 - clean; // if intersections, rejoin first and last segments
  7394. }
  7395. };
  7396. }
  7397. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7398. var cosPhi0,
  7399. cosPhi1,
  7400. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7401. return abs(sinLambda0Lambda1) > epsilon$2
  7402. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7403. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7404. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7405. : (phi0 + phi1) / 2;
  7406. }
  7407. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7408. var phi;
  7409. if (from == null) {
  7410. phi = direction * halfPi$2;
  7411. stream.point(-pi$3, phi);
  7412. stream.point(0, phi);
  7413. stream.point(pi$3, phi);
  7414. stream.point(pi$3, 0);
  7415. stream.point(pi$3, -phi);
  7416. stream.point(0, -phi);
  7417. stream.point(-pi$3, -phi);
  7418. stream.point(-pi$3, 0);
  7419. stream.point(-pi$3, phi);
  7420. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7421. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7422. phi = direction * lambda / 2;
  7423. stream.point(-lambda, phi);
  7424. stream.point(0, phi);
  7425. stream.point(lambda, phi);
  7426. } else {
  7427. stream.point(to[0], to[1]);
  7428. }
  7429. }
  7430. var clipCircle = function(radius, delta) {
  7431. var cr = cos$1(radius),
  7432. smallRadius = cr > 0,
  7433. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7434. function interpolate(from, to, direction, stream) {
  7435. circleStream(stream, radius, delta, direction, from, to);
  7436. }
  7437. function visible(lambda, phi) {
  7438. return cos$1(lambda) * cos$1(phi) > cr;
  7439. }
  7440. // Takes a line and cuts into visible segments. Return values used for polygon
  7441. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7442. // intersections 2 - there were intersections, and the first and last segments
  7443. // should be rejoined.
  7444. function clipLine(stream) {
  7445. var point0, // previous point
  7446. c0, // code for previous point
  7447. v0, // visibility of previous point
  7448. v00, // visibility of first point
  7449. clean; // no intersections
  7450. return {
  7451. lineStart: function() {
  7452. v00 = v0 = false;
  7453. clean = 1;
  7454. },
  7455. point: function(lambda, phi) {
  7456. var point1 = [lambda, phi],
  7457. point2,
  7458. v = visible(lambda, phi),
  7459. c = smallRadius
  7460. ? v ? 0 : code(lambda, phi)
  7461. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7462. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7463. // Handle degeneracies.
  7464. // TODO ignore if not clipping polygons.
  7465. if (v !== v0) {
  7466. point2 = intersect(point0, point1);
  7467. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7468. point1[0] += epsilon$2;
  7469. point1[1] += epsilon$2;
  7470. v = visible(point1[0], point1[1]);
  7471. }
  7472. }
  7473. if (v !== v0) {
  7474. clean = 0;
  7475. if (v) {
  7476. // outside going in
  7477. stream.lineStart();
  7478. point2 = intersect(point1, point0);
  7479. stream.point(point2[0], point2[1]);
  7480. } else {
  7481. // inside going out
  7482. point2 = intersect(point0, point1);
  7483. stream.point(point2[0], point2[1]);
  7484. stream.lineEnd();
  7485. }
  7486. point0 = point2;
  7487. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7488. var t;
  7489. // If the codes for two points are different, or are both zero,
  7490. // and there this segment intersects with the small circle.
  7491. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7492. clean = 0;
  7493. if (smallRadius) {
  7494. stream.lineStart();
  7495. stream.point(t[0][0], t[0][1]);
  7496. stream.point(t[1][0], t[1][1]);
  7497. stream.lineEnd();
  7498. } else {
  7499. stream.point(t[1][0], t[1][1]);
  7500. stream.lineEnd();
  7501. stream.lineStart();
  7502. stream.point(t[0][0], t[0][1]);
  7503. }
  7504. }
  7505. }
  7506. if (v && (!point0 || !pointEqual(point0, point1))) {
  7507. stream.point(point1[0], point1[1]);
  7508. }
  7509. point0 = point1, v0 = v, c0 = c;
  7510. },
  7511. lineEnd: function() {
  7512. if (v0) stream.lineEnd();
  7513. point0 = null;
  7514. },
  7515. // Rejoin first and last segments if there were intersections and the first
  7516. // and last points were visible.
  7517. clean: function() {
  7518. return clean | ((v00 && v0) << 1);
  7519. }
  7520. };
  7521. }
  7522. // Intersects the great circle between a and b with the clip circle.
  7523. function intersect(a, b, two) {
  7524. var pa = cartesian(a),
  7525. pb = cartesian(b);
  7526. // We have two planes, n1.p = d1 and n2.p = d2.
  7527. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7528. var n1 = [1, 0, 0], // normal
  7529. n2 = cartesianCross(pa, pb),
  7530. n2n2 = cartesianDot(n2, n2),
  7531. n1n2 = n2[0], // cartesianDot(n1, n2),
  7532. determinant = n2n2 - n1n2 * n1n2;
  7533. // Two polar points.
  7534. if (!determinant) return !two && a;
  7535. var c1 = cr * n2n2 / determinant,
  7536. c2 = -cr * n1n2 / determinant,
  7537. n1xn2 = cartesianCross(n1, n2),
  7538. A = cartesianScale(n1, c1),
  7539. B = cartesianScale(n2, c2);
  7540. cartesianAddInPlace(A, B);
  7541. // Solve |p(t)|^2 = 1.
  7542. var u = n1xn2,
  7543. w = cartesianDot(A, u),
  7544. uu = cartesianDot(u, u),
  7545. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7546. if (t2 < 0) return;
  7547. var t = sqrt(t2),
  7548. q = cartesianScale(u, (-w - t) / uu);
  7549. cartesianAddInPlace(q, A);
  7550. q = spherical(q);
  7551. if (!two) return q;
  7552. // Two intersection points.
  7553. var lambda0 = a[0],
  7554. lambda1 = b[0],
  7555. phi0 = a[1],
  7556. phi1 = b[1],
  7557. z;
  7558. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7559. var delta = lambda1 - lambda0,
  7560. polar = abs(delta - pi$3) < epsilon$2,
  7561. meridian = polar || delta < epsilon$2;
  7562. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7563. // Check that the first point is between a and b.
  7564. if (meridian
  7565. ? polar
  7566. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7567. : phi0 <= q[1] && q[1] <= phi1
  7568. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7569. var q1 = cartesianScale(u, (-w + t) / uu);
  7570. cartesianAddInPlace(q1, A);
  7571. return [q, spherical(q1)];
  7572. }
  7573. }
  7574. // Generates a 4-bit vector representing the location of a point relative to
  7575. // the small circle's bounding box.
  7576. function code(lambda, phi) {
  7577. var r = smallRadius ? radius : pi$3 - radius,
  7578. code = 0;
  7579. if (lambda < -r) code |= 1; // left
  7580. else if (lambda > r) code |= 2; // right
  7581. if (phi < -r) code |= 4; // below
  7582. else if (phi > r) code |= 8; // above
  7583. return code;
  7584. }
  7585. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7586. };
  7587. var transform = function(methods) {
  7588. return {
  7589. stream: transformer(methods)
  7590. };
  7591. };
  7592. function transformer(methods) {
  7593. return function(stream) {
  7594. var s = new TransformStream;
  7595. for (var key in methods) s[key] = methods[key];
  7596. s.stream = stream;
  7597. return s;
  7598. };
  7599. }
  7600. function TransformStream() {}
  7601. TransformStream.prototype = {
  7602. constructor: TransformStream,
  7603. point: function(x, y) { this.stream.point(x, y); },
  7604. sphere: function() { this.stream.sphere(); },
  7605. lineStart: function() { this.stream.lineStart(); },
  7606. lineEnd: function() { this.stream.lineEnd(); },
  7607. polygonStart: function() { this.stream.polygonStart(); },
  7608. polygonEnd: function() { this.stream.polygonEnd(); }
  7609. };
  7610. function fitExtent(projection, extent, object) {
  7611. var w = extent[1][0] - extent[0][0],
  7612. h = extent[1][1] - extent[0][1],
  7613. clip = projection.clipExtent && projection.clipExtent();
  7614. projection
  7615. .scale(150)
  7616. .translate([0, 0]);
  7617. if (clip != null) projection.clipExtent(null);
  7618. geoStream(object, projection.stream(boundsStream$1));
  7619. var b = boundsStream$1.result(),
  7620. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  7621. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  7622. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  7623. if (clip != null) projection.clipExtent(clip);
  7624. return projection
  7625. .scale(k * 150)
  7626. .translate([x, y]);
  7627. }
  7628. function fitSize(projection, size, object) {
  7629. return fitExtent(projection, [[0, 0], size], object);
  7630. }
  7631. var maxDepth = 16;
  7632. var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  7633. var resample = function(project, delta2) {
  7634. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  7635. };
  7636. function resampleNone(project) {
  7637. return transformer({
  7638. point: function(x, y) {
  7639. x = project(x, y);
  7640. this.stream.point(x[0], x[1]);
  7641. }
  7642. });
  7643. }
  7644. function resample$1(project, delta2) {
  7645. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  7646. var dx = x1 - x0,
  7647. dy = y1 - y0,
  7648. d2 = dx * dx + dy * dy;
  7649. if (d2 > 4 * delta2 && depth--) {
  7650. var a = a0 + a1,
  7651. b = b0 + b1,
  7652. c = c0 + c1,
  7653. m = sqrt(a * a + b * b + c * c),
  7654. phi2 = asin(c /= m),
  7655. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  7656. p = project(lambda2, phi2),
  7657. x2 = p[0],
  7658. y2 = p[1],
  7659. dx2 = x2 - x0,
  7660. dy2 = y2 - y0,
  7661. dz = dy * dx2 - dx * dy2;
  7662. if (dz * dz / d2 > delta2 // perpendicular projected distance
  7663. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  7664. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  7665. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  7666. stream.point(x2, y2);
  7667. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  7668. }
  7669. }
  7670. }
  7671. return function(stream) {
  7672. var lambda00, x00, y00, a00, b00, c00, // first point
  7673. lambda0, x0, y0, a0, b0, c0; // previous point
  7674. var resampleStream = {
  7675. point: point,
  7676. lineStart: lineStart,
  7677. lineEnd: lineEnd,
  7678. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  7679. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  7680. };
  7681. function point(x, y) {
  7682. x = project(x, y);
  7683. stream.point(x[0], x[1]);
  7684. }
  7685. function lineStart() {
  7686. x0 = NaN;
  7687. resampleStream.point = linePoint;
  7688. stream.lineStart();
  7689. }
  7690. function linePoint(lambda, phi) {
  7691. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  7692. 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);
  7693. stream.point(x0, y0);
  7694. }
  7695. function lineEnd() {
  7696. resampleStream.point = point;
  7697. stream.lineEnd();
  7698. }
  7699. function ringStart() {
  7700. lineStart();
  7701. resampleStream.point = ringPoint;
  7702. resampleStream.lineEnd = ringEnd;
  7703. }
  7704. function ringPoint(lambda, phi) {
  7705. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  7706. resampleStream.point = linePoint;
  7707. }
  7708. function ringEnd() {
  7709. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  7710. resampleStream.lineEnd = lineEnd;
  7711. lineEnd();
  7712. }
  7713. return resampleStream;
  7714. };
  7715. }
  7716. var transformRadians = transformer({
  7717. point: function(x, y) {
  7718. this.stream.point(x * radians, y * radians);
  7719. }
  7720. });
  7721. function projection(project) {
  7722. return projectionMutator(function() { return project; })();
  7723. }
  7724. function projectionMutator(projectAt) {
  7725. var project,
  7726. k = 150, // scale
  7727. x = 480, y = 250, // translate
  7728. dx, dy, lambda = 0, phi = 0, // center
  7729. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
  7730. theta = null, preclip = clipAntimeridian, // clip angle
  7731. x0 = null, y0, x1, y1, postclip = identity$4, // clip extent
  7732. delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
  7733. cache,
  7734. cacheStream;
  7735. function projection(point) {
  7736. point = projectRotate(point[0] * radians, point[1] * radians);
  7737. return [point[0] * k + dx, dy - point[1] * k];
  7738. }
  7739. function invert(point) {
  7740. point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
  7741. return point && [point[0] * degrees$1, point[1] * degrees$1];
  7742. }
  7743. function projectTransform(x, y) {
  7744. return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
  7745. }
  7746. projection.stream = function(stream) {
  7747. return cache && cacheStream === stream ? cache : cache = transformRadians(preclip(rotate, projectResample(postclip(cacheStream = stream))));
  7748. };
  7749. projection.clipAngle = function(_) {
  7750. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians, 6 * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  7751. };
  7752. projection.clipExtent = function(_) {
  7753. 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]];
  7754. };
  7755. projection.scale = function(_) {
  7756. return arguments.length ? (k = +_, recenter()) : k;
  7757. };
  7758. projection.translate = function(_) {
  7759. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  7760. };
  7761. projection.center = function(_) {
  7762. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  7763. };
  7764. projection.rotate = function(_) {
  7765. 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];
  7766. };
  7767. projection.precision = function(_) {
  7768. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  7769. };
  7770. projection.fitExtent = function(extent, object) {
  7771. return fitExtent(projection, extent, object);
  7772. };
  7773. projection.fitSize = function(size, object) {
  7774. return fitSize(projection, size, object);
  7775. };
  7776. function recenter() {
  7777. projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
  7778. var center = project(lambda, phi);
  7779. dx = x - center[0] * k;
  7780. dy = y + center[1] * k;
  7781. return reset();
  7782. }
  7783. function reset() {
  7784. cache = cacheStream = null;
  7785. return projection;
  7786. }
  7787. return function() {
  7788. project = projectAt.apply(this, arguments);
  7789. projection.invert = project.invert && invert;
  7790. return recenter();
  7791. };
  7792. }
  7793. function conicProjection(projectAt) {
  7794. var phi0 = 0,
  7795. phi1 = pi$3 / 3,
  7796. m = projectionMutator(projectAt),
  7797. p = m(phi0, phi1);
  7798. p.parallels = function(_) {
  7799. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  7800. };
  7801. return p;
  7802. }
  7803. function cylindricalEqualAreaRaw(phi0) {
  7804. var cosPhi0 = cos$1(phi0);
  7805. function forward(lambda, phi) {
  7806. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  7807. }
  7808. forward.invert = function(x, y) {
  7809. return [x / cosPhi0, asin(y * cosPhi0)];
  7810. };
  7811. return forward;
  7812. }
  7813. function conicEqualAreaRaw(y0, y1) {
  7814. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  7815. // Are the parallels symmetrical around the Equator?
  7816. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  7817. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  7818. function project(x, y) {
  7819. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  7820. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  7821. }
  7822. project.invert = function(x, y) {
  7823. var r0y = r0 - y;
  7824. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  7825. };
  7826. return project;
  7827. }
  7828. var conicEqualArea = function() {
  7829. return conicProjection(conicEqualAreaRaw)
  7830. .scale(155.424)
  7831. .center([0, 33.6442]);
  7832. };
  7833. var albers = function() {
  7834. return conicEqualArea()
  7835. .parallels([29.5, 45.5])
  7836. .scale(1070)
  7837. .translate([480, 250])
  7838. .rotate([96, 0])
  7839. .center([-0.6, 38.7]);
  7840. };
  7841. // The projections must have mutually exclusive clip regions on the sphere,
  7842. // as this will avoid emitting interleaving lines and polygons.
  7843. function multiplex(streams) {
  7844. var n = streams.length;
  7845. return {
  7846. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  7847. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  7848. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  7849. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  7850. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  7851. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  7852. };
  7853. }
  7854. // A composite projection for the United States, configured by default for
  7855. // 960×500. The projection also works quite well at 960×600 if you change the
  7856. // scale to 1285 and adjust the translate accordingly. The set of standard
  7857. // parallels for each region comes from USGS, which is published here:
  7858. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  7859. var albersUsa = function() {
  7860. var cache,
  7861. cacheStream,
  7862. lower48 = albers(), lower48Point,
  7863. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  7864. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  7865. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  7866. function albersUsa(coordinates) {
  7867. var x = coordinates[0], y = coordinates[1];
  7868. return point = null,
  7869. (lower48Point.point(x, y), point)
  7870. || (alaskaPoint.point(x, y), point)
  7871. || (hawaiiPoint.point(x, y), point);
  7872. }
  7873. albersUsa.invert = function(coordinates) {
  7874. var k = lower48.scale(),
  7875. t = lower48.translate(),
  7876. x = (coordinates[0] - t[0]) / k,
  7877. y = (coordinates[1] - t[1]) / k;
  7878. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  7879. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  7880. : lower48).invert(coordinates);
  7881. };
  7882. albersUsa.stream = function(stream) {
  7883. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  7884. };
  7885. albersUsa.precision = function(_) {
  7886. if (!arguments.length) return lower48.precision();
  7887. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  7888. return reset();
  7889. };
  7890. albersUsa.scale = function(_) {
  7891. if (!arguments.length) return lower48.scale();
  7892. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  7893. return albersUsa.translate(lower48.translate());
  7894. };
  7895. albersUsa.translate = function(_) {
  7896. if (!arguments.length) return lower48.translate();
  7897. var k = lower48.scale(), x = +_[0], y = +_[1];
  7898. lower48Point = lower48
  7899. .translate(_)
  7900. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  7901. .stream(pointStream);
  7902. alaskaPoint = alaska
  7903. .translate([x - 0.307 * k, y + 0.201 * k])
  7904. .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]])
  7905. .stream(pointStream);
  7906. hawaiiPoint = hawaii
  7907. .translate([x - 0.205 * k, y + 0.212 * k])
  7908. .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]])
  7909. .stream(pointStream);
  7910. return reset();
  7911. };
  7912. albersUsa.fitExtent = function(extent, object) {
  7913. return fitExtent(albersUsa, extent, object);
  7914. };
  7915. albersUsa.fitSize = function(size, object) {
  7916. return fitSize(albersUsa, size, object);
  7917. };
  7918. function reset() {
  7919. cache = cacheStream = null;
  7920. return albersUsa;
  7921. }
  7922. return albersUsa.scale(1070);
  7923. };
  7924. function azimuthalRaw(scale) {
  7925. return function(x, y) {
  7926. var cx = cos$1(x),
  7927. cy = cos$1(y),
  7928. k = scale(cx * cy);
  7929. return [
  7930. k * cy * sin$1(x),
  7931. k * sin$1(y)
  7932. ];
  7933. }
  7934. }
  7935. function azimuthalInvert(angle) {
  7936. return function(x, y) {
  7937. var z = sqrt(x * x + y * y),
  7938. c = angle(z),
  7939. sc = sin$1(c),
  7940. cc = cos$1(c);
  7941. return [
  7942. atan2(x * sc, z * cc),
  7943. asin(z && y * sc / z)
  7944. ];
  7945. }
  7946. }
  7947. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  7948. return sqrt(2 / (1 + cxcy));
  7949. });
  7950. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  7951. return 2 * asin(z / 2);
  7952. });
  7953. var azimuthalEqualArea = function() {
  7954. return projection(azimuthalEqualAreaRaw)
  7955. .scale(124.75)
  7956. .clipAngle(180 - 1e-3);
  7957. };
  7958. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  7959. return (c = acos(c)) && c / sin$1(c);
  7960. });
  7961. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  7962. return z;
  7963. });
  7964. var azimuthalEquidistant = function() {
  7965. return projection(azimuthalEquidistantRaw)
  7966. .scale(79.4188)
  7967. .clipAngle(180 - 1e-3);
  7968. };
  7969. function mercatorRaw(lambda, phi) {
  7970. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  7971. }
  7972. mercatorRaw.invert = function(x, y) {
  7973. return [x, 2 * atan(exp(y)) - halfPi$2];
  7974. };
  7975. var mercator = function() {
  7976. return mercatorProjection(mercatorRaw)
  7977. .scale(961 / tau$3);
  7978. };
  7979. function mercatorProjection(project) {
  7980. var m = projection(project),
  7981. center = m.center,
  7982. scale = m.scale,
  7983. translate = m.translate,
  7984. clipExtent = m.clipExtent,
  7985. x0 = null, y0, x1, y1; // clip extent
  7986. m.scale = function(_) {
  7987. return arguments.length ? (scale(_), reclip()) : scale();
  7988. };
  7989. m.translate = function(_) {
  7990. return arguments.length ? (translate(_), reclip()) : translate();
  7991. };
  7992. m.center = function(_) {
  7993. return arguments.length ? (center(_), reclip()) : center();
  7994. };
  7995. m.clipExtent = function(_) {
  7996. 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]];
  7997. };
  7998. function reclip() {
  7999. var k = pi$3 * scale(),
  8000. t = m(rotation(m.rotate()).invert([0, 0]));
  8001. return clipExtent(x0 == null
  8002. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8003. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8004. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8005. }
  8006. return reclip();
  8007. }
  8008. function tany(y) {
  8009. return tan((halfPi$2 + y) / 2);
  8010. }
  8011. function conicConformalRaw(y0, y1) {
  8012. var cy0 = cos$1(y0),
  8013. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8014. f = cy0 * pow(tany(y0), n) / n;
  8015. if (!n) return mercatorRaw;
  8016. function project(x, y) {
  8017. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8018. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8019. var r = f / pow(tany(y), n);
  8020. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8021. }
  8022. project.invert = function(x, y) {
  8023. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8024. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8025. };
  8026. return project;
  8027. }
  8028. var conicConformal = function() {
  8029. return conicProjection(conicConformalRaw)
  8030. .scale(109.5)
  8031. .parallels([30, 30]);
  8032. };
  8033. function equirectangularRaw(lambda, phi) {
  8034. return [lambda, phi];
  8035. }
  8036. equirectangularRaw.invert = equirectangularRaw;
  8037. var equirectangular = function() {
  8038. return projection(equirectangularRaw)
  8039. .scale(152.63);
  8040. };
  8041. function conicEquidistantRaw(y0, y1) {
  8042. var cy0 = cos$1(y0),
  8043. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8044. g = cy0 / n + y0;
  8045. if (abs(n) < epsilon$2) return equirectangularRaw;
  8046. function project(x, y) {
  8047. var gy = g - y, nx = n * x;
  8048. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8049. }
  8050. project.invert = function(x, y) {
  8051. var gy = g - y;
  8052. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8053. };
  8054. return project;
  8055. }
  8056. var conicEquidistant = function() {
  8057. return conicProjection(conicEquidistantRaw)
  8058. .scale(131.154)
  8059. .center([0, 13.9389]);
  8060. };
  8061. function gnomonicRaw(x, y) {
  8062. var cy = cos$1(y), k = cos$1(x) * cy;
  8063. return [cy * sin$1(x) / k, sin$1(y) / k];
  8064. }
  8065. gnomonicRaw.invert = azimuthalInvert(atan);
  8066. var gnomonic = function() {
  8067. return projection(gnomonicRaw)
  8068. .scale(144.049)
  8069. .clipAngle(60);
  8070. };
  8071. function scaleTranslate(kx, ky, tx, ty) {
  8072. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8073. point: function(x, y) {
  8074. this.stream.point(x * kx + tx, y * ky + ty);
  8075. }
  8076. });
  8077. }
  8078. var identity$5 = function() {
  8079. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform = identity$4, // scale, translate and reflect
  8080. x0 = null, y0, x1, y1, clip = identity$4, // clip extent
  8081. cache,
  8082. cacheStream,
  8083. projection;
  8084. function reset() {
  8085. cache = cacheStream = null;
  8086. return projection;
  8087. }
  8088. return projection = {
  8089. stream: function(stream) {
  8090. return cache && cacheStream === stream ? cache : cache = transform(clip(cacheStream = stream));
  8091. },
  8092. clipExtent: function(_) {
  8093. 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]];
  8094. },
  8095. scale: function(_) {
  8096. return arguments.length ? (transform = scaleTranslate((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8097. },
  8098. translate: function(_) {
  8099. return arguments.length ? (transform = scaleTranslate(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8100. },
  8101. reflectX: function(_) {
  8102. return arguments.length ? (transform = scaleTranslate(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8103. },
  8104. reflectY: function(_) {
  8105. return arguments.length ? (transform = scaleTranslate(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8106. },
  8107. fitExtent: function(extent, object) {
  8108. return fitExtent(projection, extent, object);
  8109. },
  8110. fitSize: function(size, object) {
  8111. return fitSize(projection, size, object);
  8112. }
  8113. };
  8114. };
  8115. function orthographicRaw(x, y) {
  8116. return [cos$1(y) * sin$1(x), sin$1(y)];
  8117. }
  8118. orthographicRaw.invert = azimuthalInvert(asin);
  8119. var orthographic = function() {
  8120. return projection(orthographicRaw)
  8121. .scale(249.5)
  8122. .clipAngle(90 + epsilon$2);
  8123. };
  8124. function stereographicRaw(x, y) {
  8125. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8126. return [cy * sin$1(x) / k, sin$1(y) / k];
  8127. }
  8128. stereographicRaw.invert = azimuthalInvert(function(z) {
  8129. return 2 * atan(z);
  8130. });
  8131. var stereographic = function() {
  8132. return projection(stereographicRaw)
  8133. .scale(250)
  8134. .clipAngle(142);
  8135. };
  8136. function transverseMercatorRaw(lambda, phi) {
  8137. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8138. }
  8139. transverseMercatorRaw.invert = function(x, y) {
  8140. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8141. };
  8142. var transverseMercator = function() {
  8143. var m = mercatorProjection(transverseMercatorRaw),
  8144. center = m.center,
  8145. rotate = m.rotate;
  8146. m.center = function(_) {
  8147. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8148. };
  8149. m.rotate = function(_) {
  8150. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8151. };
  8152. return rotate([0, 0, 90])
  8153. .scale(159.155);
  8154. };
  8155. function defaultSeparation(a, b) {
  8156. return a.parent === b.parent ? 1 : 2;
  8157. }
  8158. function meanX(children) {
  8159. return children.reduce(meanXReduce, 0) / children.length;
  8160. }
  8161. function meanXReduce(x, c) {
  8162. return x + c.x;
  8163. }
  8164. function maxY(children) {
  8165. return 1 + children.reduce(maxYReduce, 0);
  8166. }
  8167. function maxYReduce(y, c) {
  8168. return Math.max(y, c.y);
  8169. }
  8170. function leafLeft(node) {
  8171. var children;
  8172. while (children = node.children) node = children[0];
  8173. return node;
  8174. }
  8175. function leafRight(node) {
  8176. var children;
  8177. while (children = node.children) node = children[children.length - 1];
  8178. return node;
  8179. }
  8180. var cluster = function() {
  8181. var separation = defaultSeparation,
  8182. dx = 1,
  8183. dy = 1,
  8184. nodeSize = false;
  8185. function cluster(root) {
  8186. var previousNode,
  8187. x = 0;
  8188. // First walk, computing the initial x & y values.
  8189. root.eachAfter(function(node) {
  8190. var children = node.children;
  8191. if (children) {
  8192. node.x = meanX(children);
  8193. node.y = maxY(children);
  8194. } else {
  8195. node.x = previousNode ? x += separation(node, previousNode) : 0;
  8196. node.y = 0;
  8197. previousNode = node;
  8198. }
  8199. });
  8200. var left = leafLeft(root),
  8201. right = leafRight(root),
  8202. x0 = left.x - separation(left, right) / 2,
  8203. x1 = right.x + separation(right, left) / 2;
  8204. // Second walk, normalizing x & y to the desired size.
  8205. return root.eachAfter(nodeSize ? function(node) {
  8206. node.x = (node.x - root.x) * dx;
  8207. node.y = (root.y - node.y) * dy;
  8208. } : function(node) {
  8209. node.x = (node.x - x0) / (x1 - x0) * dx;
  8210. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  8211. });
  8212. }
  8213. cluster.separation = function(x) {
  8214. return arguments.length ? (separation = x, cluster) : separation;
  8215. };
  8216. cluster.size = function(x) {
  8217. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  8218. };
  8219. cluster.nodeSize = function(x) {
  8220. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  8221. };
  8222. return cluster;
  8223. };
  8224. function count(node) {
  8225. var sum = 0,
  8226. children = node.children,
  8227. i = children && children.length;
  8228. if (!i) sum = 1;
  8229. else while (--i >= 0) sum += children[i].value;
  8230. node.value = sum;
  8231. }
  8232. var node_count = function() {
  8233. return this.eachAfter(count);
  8234. };
  8235. var node_each = function(callback) {
  8236. var node = this, current, next = [node], children, i, n;
  8237. do {
  8238. current = next.reverse(), next = [];
  8239. while (node = current.pop()) {
  8240. callback(node), children = node.children;
  8241. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8242. next.push(children[i]);
  8243. }
  8244. }
  8245. } while (next.length);
  8246. return this;
  8247. };
  8248. var node_eachBefore = function(callback) {
  8249. var node = this, nodes = [node], children, i;
  8250. while (node = nodes.pop()) {
  8251. callback(node), children = node.children;
  8252. if (children) for (i = children.length - 1; i >= 0; --i) {
  8253. nodes.push(children[i]);
  8254. }
  8255. }
  8256. return this;
  8257. };
  8258. var node_eachAfter = function(callback) {
  8259. var node = this, nodes = [node], next = [], children, i, n;
  8260. while (node = nodes.pop()) {
  8261. next.push(node), children = node.children;
  8262. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8263. nodes.push(children[i]);
  8264. }
  8265. }
  8266. while (node = next.pop()) {
  8267. callback(node);
  8268. }
  8269. return this;
  8270. };
  8271. var node_sum = function(value) {
  8272. return this.eachAfter(function(node) {
  8273. var sum = +value(node.data) || 0,
  8274. children = node.children,
  8275. i = children && children.length;
  8276. while (--i >= 0) sum += children[i].value;
  8277. node.value = sum;
  8278. });
  8279. };
  8280. var node_sort = function(compare) {
  8281. return this.eachBefore(function(node) {
  8282. if (node.children) {
  8283. node.children.sort(compare);
  8284. }
  8285. });
  8286. };
  8287. var node_path = function(end) {
  8288. var start = this,
  8289. ancestor = leastCommonAncestor(start, end),
  8290. nodes = [start];
  8291. while (start !== ancestor) {
  8292. start = start.parent;
  8293. nodes.push(start);
  8294. }
  8295. var k = nodes.length;
  8296. while (end !== ancestor) {
  8297. nodes.splice(k, 0, end);
  8298. end = end.parent;
  8299. }
  8300. return nodes;
  8301. };
  8302. function leastCommonAncestor(a, b) {
  8303. if (a === b) return a;
  8304. var aNodes = a.ancestors(),
  8305. bNodes = b.ancestors(),
  8306. c = null;
  8307. a = aNodes.pop();
  8308. b = bNodes.pop();
  8309. while (a === b) {
  8310. c = a;
  8311. a = aNodes.pop();
  8312. b = bNodes.pop();
  8313. }
  8314. return c;
  8315. }
  8316. var node_ancestors = function() {
  8317. var node = this, nodes = [node];
  8318. while (node = node.parent) {
  8319. nodes.push(node);
  8320. }
  8321. return nodes;
  8322. };
  8323. var node_descendants = function() {
  8324. var nodes = [];
  8325. this.each(function(node) {
  8326. nodes.push(node);
  8327. });
  8328. return nodes;
  8329. };
  8330. var node_leaves = function() {
  8331. var leaves = [];
  8332. this.eachBefore(function(node) {
  8333. if (!node.children) {
  8334. leaves.push(node);
  8335. }
  8336. });
  8337. return leaves;
  8338. };
  8339. var node_links = function() {
  8340. var root = this, links = [];
  8341. root.each(function(node) {
  8342. if (node !== root) { // Don’t include the root’s parent, if any.
  8343. links.push({source: node.parent, target: node});
  8344. }
  8345. });
  8346. return links;
  8347. };
  8348. function hierarchy(data, children) {
  8349. var root = new Node(data),
  8350. valued = +data.value && (root.value = data.value),
  8351. node,
  8352. nodes = [root],
  8353. child,
  8354. childs,
  8355. i,
  8356. n;
  8357. if (children == null) children = defaultChildren;
  8358. while (node = nodes.pop()) {
  8359. if (valued) node.value = +node.data.value;
  8360. if ((childs = children(node.data)) && (n = childs.length)) {
  8361. node.children = new Array(n);
  8362. for (i = n - 1; i >= 0; --i) {
  8363. nodes.push(child = node.children[i] = new Node(childs[i]));
  8364. child.parent = node;
  8365. child.depth = node.depth + 1;
  8366. }
  8367. }
  8368. }
  8369. return root.eachBefore(computeHeight);
  8370. }
  8371. function node_copy() {
  8372. return hierarchy(this).eachBefore(copyData);
  8373. }
  8374. function defaultChildren(d) {
  8375. return d.children;
  8376. }
  8377. function copyData(node) {
  8378. node.data = node.data.data;
  8379. }
  8380. function computeHeight(node) {
  8381. var height = 0;
  8382. do node.height = height;
  8383. while ((node = node.parent) && (node.height < ++height));
  8384. }
  8385. function Node(data) {
  8386. this.data = data;
  8387. this.depth =
  8388. this.height = 0;
  8389. this.parent = null;
  8390. }
  8391. Node.prototype = hierarchy.prototype = {
  8392. constructor: Node,
  8393. count: node_count,
  8394. each: node_each,
  8395. eachAfter: node_eachAfter,
  8396. eachBefore: node_eachBefore,
  8397. sum: node_sum,
  8398. sort: node_sort,
  8399. path: node_path,
  8400. ancestors: node_ancestors,
  8401. descendants: node_descendants,
  8402. leaves: node_leaves,
  8403. links: node_links,
  8404. copy: node_copy
  8405. };
  8406. function Node$2(value) {
  8407. this._ = value;
  8408. this.next = null;
  8409. }
  8410. var shuffle$1 = function(array) {
  8411. var i,
  8412. n = (array = array.slice()).length,
  8413. head = null,
  8414. node = head;
  8415. while (n) {
  8416. var next = new Node$2(array[n - 1]);
  8417. if (node) node = node.next = next;
  8418. else node = head = next;
  8419. array[i] = array[--n];
  8420. }
  8421. return {
  8422. head: head,
  8423. tail: node
  8424. };
  8425. };
  8426. var enclose = function(circles) {
  8427. return encloseN(shuffle$1(circles), []);
  8428. };
  8429. function encloses(a, b) {
  8430. var dx = b.x - a.x,
  8431. dy = b.y - a.y,
  8432. dr = a.r - b.r;
  8433. return dr * dr + 1e-6 > dx * dx + dy * dy;
  8434. }
  8435. // Returns the smallest circle that contains circles L and intersects circles B.
  8436. function encloseN(L, B) {
  8437. var circle,
  8438. l0 = null,
  8439. l1 = L.head,
  8440. l2,
  8441. p1;
  8442. switch (B.length) {
  8443. case 1: circle = enclose1(B[0]); break;
  8444. case 2: circle = enclose2(B[0], B[1]); break;
  8445. case 3: circle = enclose3(B[0], B[1], B[2]); break;
  8446. }
  8447. while (l1) {
  8448. p1 = l1._, l2 = l1.next;
  8449. if (!circle || !encloses(circle, p1)) {
  8450. // Temporarily truncate L before l1.
  8451. if (l0) L.tail = l0, l0.next = null;
  8452. else L.head = L.tail = null;
  8453. B.push(p1);
  8454. circle = encloseN(L, B); // Note: reorders L!
  8455. B.pop();
  8456. // Move l1 to the front of L and reconnect the truncated list L.
  8457. if (L.head) l1.next = L.head, L.head = l1;
  8458. else l1.next = null, L.head = L.tail = l1;
  8459. l0 = L.tail, l0.next = l2;
  8460. } else {
  8461. l0 = l1;
  8462. }
  8463. l1 = l2;
  8464. }
  8465. L.tail = l0;
  8466. return circle;
  8467. }
  8468. function enclose1(a) {
  8469. return {
  8470. x: a.x,
  8471. y: a.y,
  8472. r: a.r
  8473. };
  8474. }
  8475. function enclose2(a, b) {
  8476. var x1 = a.x, y1 = a.y, r1 = a.r,
  8477. x2 = b.x, y2 = b.y, r2 = b.r,
  8478. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  8479. l = Math.sqrt(x21 * x21 + y21 * y21);
  8480. return {
  8481. x: (x1 + x2 + x21 / l * r21) / 2,
  8482. y: (y1 + y2 + y21 / l * r21) / 2,
  8483. r: (l + r1 + r2) / 2
  8484. };
  8485. }
  8486. function enclose3(a, b, c) {
  8487. var x1 = a.x, y1 = a.y, r1 = a.r,
  8488. x2 = b.x, y2 = b.y, r2 = b.r,
  8489. x3 = c.x, y3 = c.y, r3 = c.r,
  8490. a2 = 2 * (x1 - x2),
  8491. b2 = 2 * (y1 - y2),
  8492. c2 = 2 * (r2 - r1),
  8493. d2 = x1 * x1 + y1 * y1 - r1 * r1 - x2 * x2 - y2 * y2 + r2 * r2,
  8494. a3 = 2 * (x1 - x3),
  8495. b3 = 2 * (y1 - y3),
  8496. c3 = 2 * (r3 - r1),
  8497. d3 = x1 * x1 + y1 * y1 - r1 * r1 - x3 * x3 - y3 * y3 + r3 * r3,
  8498. ab = a3 * b2 - a2 * b3,
  8499. xa = (b2 * d3 - b3 * d2) / ab - x1,
  8500. xb = (b3 * c2 - b2 * c3) / ab,
  8501. ya = (a3 * d2 - a2 * d3) / ab - y1,
  8502. yb = (a2 * c3 - a3 * c2) / ab,
  8503. A = xb * xb + yb * yb - 1,
  8504. B = 2 * (xa * xb + ya * yb + r1),
  8505. C = xa * xa + ya * ya - r1 * r1,
  8506. r = (-B - Math.sqrt(B * B - 4 * A * C)) / (2 * A);
  8507. return {
  8508. x: xa + xb * r + x1,
  8509. y: ya + yb * r + y1,
  8510. r: r
  8511. };
  8512. }
  8513. function place(a, b, c) {
  8514. var ax = a.x,
  8515. ay = a.y,
  8516. da = b.r + c.r,
  8517. db = a.r + c.r,
  8518. dx = b.x - ax,
  8519. dy = b.y - ay,
  8520. dc = dx * dx + dy * dy;
  8521. if (dc) {
  8522. var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
  8523. y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  8524. c.x = ax + x * dx + y * dy;
  8525. c.y = ay + x * dy - y * dx;
  8526. } else {
  8527. c.x = ax + db;
  8528. c.y = ay;
  8529. }
  8530. }
  8531. function intersects(a, b) {
  8532. var dx = b.x - a.x,
  8533. dy = b.y - a.y,
  8534. dr = a.r + b.r;
  8535. return dr * dr - 1e-6 > dx * dx + dy * dy;
  8536. }
  8537. function distance2(node, x, y) {
  8538. var a = node._,
  8539. b = node.next._,
  8540. ab = a.r + b.r,
  8541. dx = (a.x * b.r + b.x * a.r) / ab - x,
  8542. dy = (a.y * b.r + b.y * a.r) / ab - y;
  8543. return dx * dx + dy * dy;
  8544. }
  8545. function Node$1(circle) {
  8546. this._ = circle;
  8547. this.next = null;
  8548. this.previous = null;
  8549. }
  8550. function packEnclose(circles) {
  8551. if (!(n = circles.length)) return 0;
  8552. var a, b, c, n;
  8553. // Place the first circle.
  8554. a = circles[0], a.x = 0, a.y = 0;
  8555. if (!(n > 1)) return a.r;
  8556. // Place the second circle.
  8557. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  8558. if (!(n > 2)) return a.r + b.r;
  8559. // Place the third circle.
  8560. place(b, a, c = circles[2]);
  8561. // Initialize the weighted centroid.
  8562. var aa = a.r * a.r,
  8563. ba = b.r * b.r,
  8564. ca = c.r * c.r,
  8565. oa = aa + ba + ca,
  8566. ox = aa * a.x + ba * b.x + ca * c.x,
  8567. oy = aa * a.y + ba * b.y + ca * c.y,
  8568. cx, cy, i, j, k, sj, sk;
  8569. // Initialize the front-chain using the first three circles a, b and c.
  8570. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  8571. a.next = c.previous = b;
  8572. b.next = a.previous = c;
  8573. c.next = b.previous = a;
  8574. // Attempt to place each remaining circle…
  8575. pack: for (i = 3; i < n; ++i) {
  8576. place(a._, b._, c = circles[i]), c = new Node$1(c);
  8577. // Find the closest intersecting circle on the front-chain, if any.
  8578. // “Closeness” is determined by linear distance along the front-chain.
  8579. // “Ahead” or “behind” is likewise determined by linear distance.
  8580. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  8581. do {
  8582. if (sj <= sk) {
  8583. if (intersects(j._, c._)) {
  8584. b = j, a.next = b, b.previous = a, --i;
  8585. continue pack;
  8586. }
  8587. sj += j._.r, j = j.next;
  8588. } else {
  8589. if (intersects(k._, c._)) {
  8590. a = k, a.next = b, b.previous = a, --i;
  8591. continue pack;
  8592. }
  8593. sk += k._.r, k = k.previous;
  8594. }
  8595. } while (j !== k.next);
  8596. // Success! Insert the new circle c between a and b.
  8597. c.previous = a, c.next = b, a.next = b.previous = b = c;
  8598. // Update the weighted centroid.
  8599. oa += ca = c._.r * c._.r;
  8600. ox += ca * c._.x;
  8601. oy += ca * c._.y;
  8602. // Compute the new closest circle pair to the centroid.
  8603. aa = distance2(a, cx = ox / oa, cy = oy / oa);
  8604. while ((c = c.next) !== b) {
  8605. if ((ca = distance2(c, cx, cy)) < aa) {
  8606. a = c, aa = ca;
  8607. }
  8608. }
  8609. b = a.next;
  8610. }
  8611. // Compute the enclosing circle of the front chain.
  8612. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  8613. // Translate the circles to put the enclosing circle around the origin.
  8614. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  8615. return c.r;
  8616. }
  8617. var siblings = function(circles) {
  8618. packEnclose(circles);
  8619. return circles;
  8620. };
  8621. function optional(f) {
  8622. return f == null ? null : required(f);
  8623. }
  8624. function required(f) {
  8625. if (typeof f !== "function") throw new Error;
  8626. return f;
  8627. }
  8628. function constantZero() {
  8629. return 0;
  8630. }
  8631. var constant$8 = function(x) {
  8632. return function() {
  8633. return x;
  8634. };
  8635. };
  8636. function defaultRadius$1(d) {
  8637. return Math.sqrt(d.value);
  8638. }
  8639. var index$2 = function() {
  8640. var radius = null,
  8641. dx = 1,
  8642. dy = 1,
  8643. padding = constantZero;
  8644. function pack(root) {
  8645. root.x = dx / 2, root.y = dy / 2;
  8646. if (radius) {
  8647. root.eachBefore(radiusLeaf(radius))
  8648. .eachAfter(packChildren(padding, 0.5))
  8649. .eachBefore(translateChild(1));
  8650. } else {
  8651. root.eachBefore(radiusLeaf(defaultRadius$1))
  8652. .eachAfter(packChildren(constantZero, 1))
  8653. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  8654. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  8655. }
  8656. return root;
  8657. }
  8658. pack.radius = function(x) {
  8659. return arguments.length ? (radius = optional(x), pack) : radius;
  8660. };
  8661. pack.size = function(x) {
  8662. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  8663. };
  8664. pack.padding = function(x) {
  8665. return arguments.length ? (padding = typeof x === "function" ? x : constant$8(+x), pack) : padding;
  8666. };
  8667. return pack;
  8668. };
  8669. function radiusLeaf(radius) {
  8670. return function(node) {
  8671. if (!node.children) {
  8672. node.r = Math.max(0, +radius(node) || 0);
  8673. }
  8674. };
  8675. }
  8676. function packChildren(padding, k) {
  8677. return function(node) {
  8678. if (children = node.children) {
  8679. var children,
  8680. i,
  8681. n = children.length,
  8682. r = padding(node) * k || 0,
  8683. e;
  8684. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  8685. e = packEnclose(children);
  8686. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  8687. node.r = e + r;
  8688. }
  8689. };
  8690. }
  8691. function translateChild(k) {
  8692. return function(node) {
  8693. var parent = node.parent;
  8694. node.r *= k;
  8695. if (parent) {
  8696. node.x = parent.x + k * node.x;
  8697. node.y = parent.y + k * node.y;
  8698. }
  8699. };
  8700. }
  8701. var roundNode = function(node) {
  8702. node.x0 = Math.round(node.x0);
  8703. node.y0 = Math.round(node.y0);
  8704. node.x1 = Math.round(node.x1);
  8705. node.y1 = Math.round(node.y1);
  8706. };
  8707. var treemapDice = function(parent, x0, y0, x1, y1) {
  8708. var nodes = parent.children,
  8709. node,
  8710. i = -1,
  8711. n = nodes.length,
  8712. k = parent.value && (x1 - x0) / parent.value;
  8713. while (++i < n) {
  8714. node = nodes[i], node.y0 = y0, node.y1 = y1;
  8715. node.x0 = x0, node.x1 = x0 += node.value * k;
  8716. }
  8717. };
  8718. var partition = function() {
  8719. var dx = 1,
  8720. dy = 1,
  8721. padding = 0,
  8722. round = false;
  8723. function partition(root) {
  8724. var n = root.height + 1;
  8725. root.x0 =
  8726. root.y0 = padding;
  8727. root.x1 = dx;
  8728. root.y1 = dy / n;
  8729. root.eachBefore(positionNode(dy, n));
  8730. if (round) root.eachBefore(roundNode);
  8731. return root;
  8732. }
  8733. function positionNode(dy, n) {
  8734. return function(node) {
  8735. if (node.children) {
  8736. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  8737. }
  8738. var x0 = node.x0,
  8739. y0 = node.y0,
  8740. x1 = node.x1 - padding,
  8741. y1 = node.y1 - padding;
  8742. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8743. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8744. node.x0 = x0;
  8745. node.y0 = y0;
  8746. node.x1 = x1;
  8747. node.y1 = y1;
  8748. };
  8749. }
  8750. partition.round = function(x) {
  8751. return arguments.length ? (round = !!x, partition) : round;
  8752. };
  8753. partition.size = function(x) {
  8754. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  8755. };
  8756. partition.padding = function(x) {
  8757. return arguments.length ? (padding = +x, partition) : padding;
  8758. };
  8759. return partition;
  8760. };
  8761. var keyPrefix$1 = "$";
  8762. var preroot = {depth: -1};
  8763. var ambiguous = {};
  8764. function defaultId(d) {
  8765. return d.id;
  8766. }
  8767. function defaultParentId(d) {
  8768. return d.parentId;
  8769. }
  8770. var stratify = function() {
  8771. var id = defaultId,
  8772. parentId = defaultParentId;
  8773. function stratify(data) {
  8774. var d,
  8775. i,
  8776. n = data.length,
  8777. root,
  8778. parent,
  8779. node,
  8780. nodes = new Array(n),
  8781. nodeId,
  8782. nodeKey,
  8783. nodeByKey = {};
  8784. for (i = 0; i < n; ++i) {
  8785. d = data[i], node = nodes[i] = new Node(d);
  8786. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  8787. nodeKey = keyPrefix$1 + (node.id = nodeId);
  8788. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  8789. }
  8790. }
  8791. for (i = 0; i < n; ++i) {
  8792. node = nodes[i], nodeId = parentId(data[i], i, data);
  8793. if (nodeId == null || !(nodeId += "")) {
  8794. if (root) throw new Error("multiple roots");
  8795. root = node;
  8796. } else {
  8797. parent = nodeByKey[keyPrefix$1 + nodeId];
  8798. if (!parent) throw new Error("missing: " + nodeId);
  8799. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  8800. if (parent.children) parent.children.push(node);
  8801. else parent.children = [node];
  8802. node.parent = parent;
  8803. }
  8804. }
  8805. if (!root) throw new Error("no root");
  8806. root.parent = preroot;
  8807. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  8808. root.parent = null;
  8809. if (n > 0) throw new Error("cycle");
  8810. return root;
  8811. }
  8812. stratify.id = function(x) {
  8813. return arguments.length ? (id = required(x), stratify) : id;
  8814. };
  8815. stratify.parentId = function(x) {
  8816. return arguments.length ? (parentId = required(x), stratify) : parentId;
  8817. };
  8818. return stratify;
  8819. };
  8820. function defaultSeparation$1(a, b) {
  8821. return a.parent === b.parent ? 1 : 2;
  8822. }
  8823. // function radialSeparation(a, b) {
  8824. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  8825. // }
  8826. // This function is used to traverse the left contour of a subtree (or
  8827. // subforest). It returns the successor of v on this contour. This successor is
  8828. // either given by the leftmost child of v or by the thread of v. The function
  8829. // returns null if and only if v is on the highest level of its subtree.
  8830. function nextLeft(v) {
  8831. var children = v.children;
  8832. return children ? children[0] : v.t;
  8833. }
  8834. // This function works analogously to nextLeft.
  8835. function nextRight(v) {
  8836. var children = v.children;
  8837. return children ? children[children.length - 1] : v.t;
  8838. }
  8839. // Shifts the current subtree rooted at w+. This is done by increasing
  8840. // prelim(w+) and mod(w+) by shift.
  8841. function moveSubtree(wm, wp, shift) {
  8842. var change = shift / (wp.i - wm.i);
  8843. wp.c -= change;
  8844. wp.s += shift;
  8845. wm.c += change;
  8846. wp.z += shift;
  8847. wp.m += shift;
  8848. }
  8849. // All other shifts, applied to the smaller subtrees between w- and w+, are
  8850. // performed by this function. To prepare the shifts, we have to adjust
  8851. // change(w+), shift(w+), and change(w-).
  8852. function executeShifts(v) {
  8853. var shift = 0,
  8854. change = 0,
  8855. children = v.children,
  8856. i = children.length,
  8857. w;
  8858. while (--i >= 0) {
  8859. w = children[i];
  8860. w.z += shift;
  8861. w.m += shift;
  8862. shift += w.s + (change += w.c);
  8863. }
  8864. }
  8865. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  8866. // returns the specified (default) ancestor.
  8867. function nextAncestor(vim, v, ancestor) {
  8868. return vim.a.parent === v.parent ? vim.a : ancestor;
  8869. }
  8870. function TreeNode(node, i) {
  8871. this._ = node;
  8872. this.parent = null;
  8873. this.children = null;
  8874. this.A = null; // default ancestor
  8875. this.a = this; // ancestor
  8876. this.z = 0; // prelim
  8877. this.m = 0; // mod
  8878. this.c = 0; // change
  8879. this.s = 0; // shift
  8880. this.t = null; // thread
  8881. this.i = i; // number
  8882. }
  8883. TreeNode.prototype = Object.create(Node.prototype);
  8884. function treeRoot(root) {
  8885. var tree = new TreeNode(root, 0),
  8886. node,
  8887. nodes = [tree],
  8888. child,
  8889. children,
  8890. i,
  8891. n;
  8892. while (node = nodes.pop()) {
  8893. if (children = node._.children) {
  8894. node.children = new Array(n = children.length);
  8895. for (i = n - 1; i >= 0; --i) {
  8896. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  8897. child.parent = node;
  8898. }
  8899. }
  8900. }
  8901. (tree.parent = new TreeNode(null, 0)).children = [tree];
  8902. return tree;
  8903. }
  8904. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  8905. var tree = function() {
  8906. var separation = defaultSeparation$1,
  8907. dx = 1,
  8908. dy = 1,
  8909. nodeSize = null;
  8910. function tree(root) {
  8911. var t = treeRoot(root);
  8912. // Compute the layout using Buchheim et al.’s algorithm.
  8913. t.eachAfter(firstWalk), t.parent.m = -t.z;
  8914. t.eachBefore(secondWalk);
  8915. // If a fixed node size is specified, scale x and y.
  8916. if (nodeSize) root.eachBefore(sizeNode);
  8917. // If a fixed tree size is specified, scale x and y based on the extent.
  8918. // Compute the left-most, right-most, and depth-most nodes for extents.
  8919. else {
  8920. var left = root,
  8921. right = root,
  8922. bottom = root;
  8923. root.eachBefore(function(node) {
  8924. if (node.x < left.x) left = node;
  8925. if (node.x > right.x) right = node;
  8926. if (node.depth > bottom.depth) bottom = node;
  8927. });
  8928. var s = left === right ? 1 : separation(left, right) / 2,
  8929. tx = s - left.x,
  8930. kx = dx / (right.x + s + tx),
  8931. ky = dy / (bottom.depth || 1);
  8932. root.eachBefore(function(node) {
  8933. node.x = (node.x + tx) * kx;
  8934. node.y = node.depth * ky;
  8935. });
  8936. }
  8937. return root;
  8938. }
  8939. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  8940. // applied recursively to the children of v, as well as the function
  8941. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  8942. // node v is placed to the midpoint of its outermost children.
  8943. function firstWalk(v) {
  8944. var children = v.children,
  8945. siblings = v.parent.children,
  8946. w = v.i ? siblings[v.i - 1] : null;
  8947. if (children) {
  8948. executeShifts(v);
  8949. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  8950. if (w) {
  8951. v.z = w.z + separation(v._, w._);
  8952. v.m = v.z - midpoint;
  8953. } else {
  8954. v.z = midpoint;
  8955. }
  8956. } else if (w) {
  8957. v.z = w.z + separation(v._, w._);
  8958. }
  8959. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  8960. }
  8961. // Computes all real x-coordinates by summing up the modifiers recursively.
  8962. function secondWalk(v) {
  8963. v._.x = v.z + v.parent.m;
  8964. v.m += v.parent.m;
  8965. }
  8966. // The core of the algorithm. Here, a new subtree is combined with the
  8967. // previous subtrees. Threads are used to traverse the inside and outside
  8968. // contours of the left and right subtree up to the highest common level. The
  8969. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  8970. // superscript o means outside and i means inside, the subscript - means left
  8971. // subtree and + means right subtree. For summing up the modifiers along the
  8972. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  8973. // nodes of the inside contours conflict, we compute the left one of the
  8974. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  8975. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  8976. // Finally, we add a new thread (if necessary).
  8977. function apportion(v, w, ancestor) {
  8978. if (w) {
  8979. var vip = v,
  8980. vop = v,
  8981. vim = w,
  8982. vom = vip.parent.children[0],
  8983. sip = vip.m,
  8984. sop = vop.m,
  8985. sim = vim.m,
  8986. som = vom.m,
  8987. shift;
  8988. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  8989. vom = nextLeft(vom);
  8990. vop = nextRight(vop);
  8991. vop.a = v;
  8992. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  8993. if (shift > 0) {
  8994. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  8995. sip += shift;
  8996. sop += shift;
  8997. }
  8998. sim += vim.m;
  8999. sip += vip.m;
  9000. som += vom.m;
  9001. sop += vop.m;
  9002. }
  9003. if (vim && !nextRight(vop)) {
  9004. vop.t = vim;
  9005. vop.m += sim - sop;
  9006. }
  9007. if (vip && !nextLeft(vom)) {
  9008. vom.t = vip;
  9009. vom.m += sip - som;
  9010. ancestor = v;
  9011. }
  9012. }
  9013. return ancestor;
  9014. }
  9015. function sizeNode(node) {
  9016. node.x *= dx;
  9017. node.y = node.depth * dy;
  9018. }
  9019. tree.separation = function(x) {
  9020. return arguments.length ? (separation = x, tree) : separation;
  9021. };
  9022. tree.size = function(x) {
  9023. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9024. };
  9025. tree.nodeSize = function(x) {
  9026. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9027. };
  9028. return tree;
  9029. };
  9030. var treemapSlice = function(parent, x0, y0, x1, y1) {
  9031. var nodes = parent.children,
  9032. node,
  9033. i = -1,
  9034. n = nodes.length,
  9035. k = parent.value && (y1 - y0) / parent.value;
  9036. while (++i < n) {
  9037. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9038. node.y0 = y0, node.y1 = y0 += node.value * k;
  9039. }
  9040. };
  9041. var phi = (1 + Math.sqrt(5)) / 2;
  9042. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9043. var rows = [],
  9044. nodes = parent.children,
  9045. row,
  9046. nodeValue,
  9047. i0 = 0,
  9048. i1 = 0,
  9049. n = nodes.length,
  9050. dx, dy,
  9051. value = parent.value,
  9052. sumValue,
  9053. minValue,
  9054. maxValue,
  9055. newRatio,
  9056. minRatio,
  9057. alpha,
  9058. beta;
  9059. while (i0 < n) {
  9060. dx = x1 - x0, dy = y1 - y0;
  9061. // Find the next non-empty node.
  9062. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9063. minValue = maxValue = sumValue;
  9064. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9065. beta = sumValue * sumValue * alpha;
  9066. minRatio = Math.max(maxValue / beta, beta / minValue);
  9067. // Keep adding nodes while the aspect ratio maintains or improves.
  9068. for (; i1 < n; ++i1) {
  9069. sumValue += nodeValue = nodes[i1].value;
  9070. if (nodeValue < minValue) minValue = nodeValue;
  9071. if (nodeValue > maxValue) maxValue = nodeValue;
  9072. beta = sumValue * sumValue * alpha;
  9073. newRatio = Math.max(maxValue / beta, beta / minValue);
  9074. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9075. minRatio = newRatio;
  9076. }
  9077. // Position and record the row orientation.
  9078. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9079. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9080. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9081. value -= sumValue, i0 = i1;
  9082. }
  9083. return rows;
  9084. }
  9085. var squarify = ((function custom(ratio) {
  9086. function squarify(parent, x0, y0, x1, y1) {
  9087. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9088. }
  9089. squarify.ratio = function(x) {
  9090. return custom((x = +x) > 1 ? x : 1);
  9091. };
  9092. return squarify;
  9093. }))(phi);
  9094. var index$3 = function() {
  9095. var tile = squarify,
  9096. round = false,
  9097. dx = 1,
  9098. dy = 1,
  9099. paddingStack = [0],
  9100. paddingInner = constantZero,
  9101. paddingTop = constantZero,
  9102. paddingRight = constantZero,
  9103. paddingBottom = constantZero,
  9104. paddingLeft = constantZero;
  9105. function treemap(root) {
  9106. root.x0 =
  9107. root.y0 = 0;
  9108. root.x1 = dx;
  9109. root.y1 = dy;
  9110. root.eachBefore(positionNode);
  9111. paddingStack = [0];
  9112. if (round) root.eachBefore(roundNode);
  9113. return root;
  9114. }
  9115. function positionNode(node) {
  9116. var p = paddingStack[node.depth],
  9117. x0 = node.x0 + p,
  9118. y0 = node.y0 + p,
  9119. x1 = node.x1 - p,
  9120. y1 = node.y1 - p;
  9121. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9122. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9123. node.x0 = x0;
  9124. node.y0 = y0;
  9125. node.x1 = x1;
  9126. node.y1 = y1;
  9127. if (node.children) {
  9128. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9129. x0 += paddingLeft(node) - p;
  9130. y0 += paddingTop(node) - p;
  9131. x1 -= paddingRight(node) - p;
  9132. y1 -= paddingBottom(node) - p;
  9133. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9134. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9135. tile(node, x0, y0, x1, y1);
  9136. }
  9137. }
  9138. treemap.round = function(x) {
  9139. return arguments.length ? (round = !!x, treemap) : round;
  9140. };
  9141. treemap.size = function(x) {
  9142. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9143. };
  9144. treemap.tile = function(x) {
  9145. return arguments.length ? (tile = required(x), treemap) : tile;
  9146. };
  9147. treemap.padding = function(x) {
  9148. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9149. };
  9150. treemap.paddingInner = function(x) {
  9151. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$8(+x), treemap) : paddingInner;
  9152. };
  9153. treemap.paddingOuter = function(x) {
  9154. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9155. };
  9156. treemap.paddingTop = function(x) {
  9157. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$8(+x), treemap) : paddingTop;
  9158. };
  9159. treemap.paddingRight = function(x) {
  9160. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$8(+x), treemap) : paddingRight;
  9161. };
  9162. treemap.paddingBottom = function(x) {
  9163. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$8(+x), treemap) : paddingBottom;
  9164. };
  9165. treemap.paddingLeft = function(x) {
  9166. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$8(+x), treemap) : paddingLeft;
  9167. };
  9168. return treemap;
  9169. };
  9170. var binary = function(parent, x0, y0, x1, y1) {
  9171. var nodes = parent.children,
  9172. i, n = nodes.length,
  9173. sum, sums = new Array(n + 1);
  9174. for (sums[0] = sum = i = 0; i < n; ++i) {
  9175. sums[i + 1] = sum += nodes[i].value;
  9176. }
  9177. partition(0, n, parent.value, x0, y0, x1, y1);
  9178. function partition(i, j, value, x0, y0, x1, y1) {
  9179. if (i >= j - 1) {
  9180. var node = nodes[i];
  9181. node.x0 = x0, node.y0 = y0;
  9182. node.x1 = x1, node.y1 = y1;
  9183. return;
  9184. }
  9185. var valueOffset = sums[i],
  9186. valueTarget = (value / 2) + valueOffset,
  9187. k = i + 1,
  9188. hi = j - 1;
  9189. while (k < hi) {
  9190. var mid = k + hi >>> 1;
  9191. if (sums[mid] < valueTarget) k = mid + 1;
  9192. else hi = mid;
  9193. }
  9194. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  9195. var valueLeft = sums[k] - valueOffset,
  9196. valueRight = value - valueLeft;
  9197. if ((x1 - x0) > (y1 - y0)) {
  9198. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  9199. partition(i, k, valueLeft, x0, y0, xk, y1);
  9200. partition(k, j, valueRight, xk, y0, x1, y1);
  9201. } else {
  9202. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  9203. partition(i, k, valueLeft, x0, y0, x1, yk);
  9204. partition(k, j, valueRight, x0, yk, x1, y1);
  9205. }
  9206. }
  9207. };
  9208. var sliceDice = function(parent, x0, y0, x1, y1) {
  9209. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  9210. };
  9211. var resquarify = ((function custom(ratio) {
  9212. function resquarify(parent, x0, y0, x1, y1) {
  9213. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  9214. var rows,
  9215. row,
  9216. nodes,
  9217. i,
  9218. j = -1,
  9219. n,
  9220. m = rows.length,
  9221. value = parent.value;
  9222. while (++j < m) {
  9223. row = rows[j], nodes = row.children;
  9224. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  9225. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  9226. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  9227. value -= row.value;
  9228. }
  9229. } else {
  9230. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9231. rows.ratio = ratio;
  9232. }
  9233. }
  9234. resquarify.ratio = function(x) {
  9235. return custom((x = +x) > 1 ? x : 1);
  9236. };
  9237. return resquarify;
  9238. }))(phi);
  9239. var area$1 = function(polygon) {
  9240. var i = -1,
  9241. n = polygon.length,
  9242. a,
  9243. b = polygon[n - 1],
  9244. area = 0;
  9245. while (++i < n) {
  9246. a = b;
  9247. b = polygon[i];
  9248. area += a[1] * b[0] - a[0] * b[1];
  9249. }
  9250. return area / 2;
  9251. };
  9252. var centroid$1 = function(polygon) {
  9253. var i = -1,
  9254. n = polygon.length,
  9255. x = 0,
  9256. y = 0,
  9257. a,
  9258. b = polygon[n - 1],
  9259. c,
  9260. k = 0;
  9261. while (++i < n) {
  9262. a = b;
  9263. b = polygon[i];
  9264. k += c = a[0] * b[1] - b[0] * a[1];
  9265. x += (a[0] + b[0]) * c;
  9266. y += (a[1] + b[1]) * c;
  9267. }
  9268. return k *= 3, [x / k, y / k];
  9269. };
  9270. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  9271. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  9272. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  9273. // negative if clockwise, and zero if the points are collinear.
  9274. var cross$1 = function(a, b, c) {
  9275. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  9276. };
  9277. function lexicographicOrder(a, b) {
  9278. return a[0] - b[0] || a[1] - b[1];
  9279. }
  9280. // Computes the upper convex hull per the monotone chain algorithm.
  9281. // Assumes points.length >= 3, is sorted by x, unique in y.
  9282. // Returns an array of indices into points in left-to-right order.
  9283. function computeUpperHullIndexes(points) {
  9284. var n = points.length,
  9285. indexes = [0, 1],
  9286. size = 2;
  9287. for (var i = 2; i < n; ++i) {
  9288. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  9289. indexes[size++] = i;
  9290. }
  9291. return indexes.slice(0, size); // remove popped points
  9292. }
  9293. var hull = function(points) {
  9294. if ((n = points.length) < 3) return null;
  9295. var i,
  9296. n,
  9297. sortedPoints = new Array(n),
  9298. flippedPoints = new Array(n);
  9299. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  9300. sortedPoints.sort(lexicographicOrder);
  9301. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  9302. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  9303. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  9304. // Construct the hull polygon, removing possible duplicate endpoints.
  9305. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  9306. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  9307. hull = [];
  9308. // Add upper hull in right-to-l order.
  9309. // Then add lower hull in left-to-right order.
  9310. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  9311. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  9312. return hull;
  9313. };
  9314. var contains$1 = function(polygon, point) {
  9315. var n = polygon.length,
  9316. p = polygon[n - 1],
  9317. x = point[0], y = point[1],
  9318. x0 = p[0], y0 = p[1],
  9319. x1, y1,
  9320. inside = false;
  9321. for (var i = 0; i < n; ++i) {
  9322. p = polygon[i], x1 = p[0], y1 = p[1];
  9323. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  9324. x0 = x1, y0 = y1;
  9325. }
  9326. return inside;
  9327. };
  9328. var length$2 = function(polygon) {
  9329. var i = -1,
  9330. n = polygon.length,
  9331. b = polygon[n - 1],
  9332. xa,
  9333. ya,
  9334. xb = b[0],
  9335. yb = b[1],
  9336. perimeter = 0;
  9337. while (++i < n) {
  9338. xa = xb;
  9339. ya = yb;
  9340. b = polygon[i];
  9341. xb = b[0];
  9342. yb = b[1];
  9343. xa -= xb;
  9344. ya -= yb;
  9345. perimeter += Math.sqrt(xa * xa + ya * ya);
  9346. }
  9347. return perimeter;
  9348. };
  9349. var slice$3 = [].slice;
  9350. var noabort = {};
  9351. function Queue(size) {
  9352. this._size = size;
  9353. this._call =
  9354. this._error = null;
  9355. this._tasks = [];
  9356. this._data = [];
  9357. this._waiting =
  9358. this._active =
  9359. this._ended =
  9360. this._start = 0; // inside a synchronous task callback?
  9361. }
  9362. Queue.prototype = queue.prototype = {
  9363. constructor: Queue,
  9364. defer: function(callback) {
  9365. if (typeof callback !== "function") throw new Error("invalid callback");
  9366. if (this._call) throw new Error("defer after await");
  9367. if (this._error != null) return this;
  9368. var t = slice$3.call(arguments, 1);
  9369. t.push(callback);
  9370. ++this._waiting, this._tasks.push(t);
  9371. poke$1(this);
  9372. return this;
  9373. },
  9374. abort: function() {
  9375. if (this._error == null) abort(this, new Error("abort"));
  9376. return this;
  9377. },
  9378. await: function(callback) {
  9379. if (typeof callback !== "function") throw new Error("invalid callback");
  9380. if (this._call) throw new Error("multiple await");
  9381. this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
  9382. maybeNotify(this);
  9383. return this;
  9384. },
  9385. awaitAll: function(callback) {
  9386. if (typeof callback !== "function") throw new Error("invalid callback");
  9387. if (this._call) throw new Error("multiple await");
  9388. this._call = callback;
  9389. maybeNotify(this);
  9390. return this;
  9391. }
  9392. };
  9393. function poke$1(q) {
  9394. if (!q._start) {
  9395. try { start$1(q); } // let the current task complete
  9396. catch (e) {
  9397. if (q._tasks[q._ended + q._active - 1]) abort(q, e); // task errored synchronously
  9398. else if (!q._data) throw e; // await callback errored synchronously
  9399. }
  9400. }
  9401. }
  9402. function start$1(q) {
  9403. while (q._start = q._waiting && q._active < q._size) {
  9404. var i = q._ended + q._active,
  9405. t = q._tasks[i],
  9406. j = t.length - 1,
  9407. c = t[j];
  9408. t[j] = end(q, i);
  9409. --q._waiting, ++q._active;
  9410. t = c.apply(null, t);
  9411. if (!q._tasks[i]) continue; // task finished synchronously
  9412. q._tasks[i] = t || noabort;
  9413. }
  9414. }
  9415. function end(q, i) {
  9416. return function(e, r) {
  9417. if (!q._tasks[i]) return; // ignore multiple callbacks
  9418. --q._active, ++q._ended;
  9419. q._tasks[i] = null;
  9420. if (q._error != null) return; // ignore secondary errors
  9421. if (e != null) {
  9422. abort(q, e);
  9423. } else {
  9424. q._data[i] = r;
  9425. if (q._waiting) poke$1(q);
  9426. else maybeNotify(q);
  9427. }
  9428. };
  9429. }
  9430. function abort(q, e) {
  9431. var i = q._tasks.length, t;
  9432. q._error = e; // ignore active callbacks
  9433. q._data = undefined; // allow gc
  9434. q._waiting = NaN; // prevent starting
  9435. while (--i >= 0) {
  9436. if (t = q._tasks[i]) {
  9437. q._tasks[i] = null;
  9438. if (t.abort) {
  9439. try { t.abort(); }
  9440. catch (e) { /* ignore */ }
  9441. }
  9442. }
  9443. }
  9444. q._active = NaN; // allow notification
  9445. maybeNotify(q);
  9446. }
  9447. function maybeNotify(q) {
  9448. if (!q._active && q._call) {
  9449. var d = q._data;
  9450. q._data = undefined; // allow gc
  9451. q._call(q._error, d);
  9452. }
  9453. }
  9454. function queue(concurrency) {
  9455. if (concurrency == null) concurrency = Infinity;
  9456. else if (!((concurrency = +concurrency) >= 1)) throw new Error("invalid concurrency");
  9457. return new Queue(concurrency);
  9458. }
  9459. var defaultSource$1 = function() {
  9460. return Math.random();
  9461. };
  9462. var uniform = ((function sourceRandomUniform(source) {
  9463. function randomUniform(min, max) {
  9464. min = min == null ? 0 : +min;
  9465. max = max == null ? 1 : +max;
  9466. if (arguments.length === 1) max = min, min = 0;
  9467. else max -= min;
  9468. return function() {
  9469. return source() * max + min;
  9470. };
  9471. }
  9472. randomUniform.source = sourceRandomUniform;
  9473. return randomUniform;
  9474. }))(defaultSource$1);
  9475. var normal = ((function sourceRandomNormal(source) {
  9476. function randomNormal(mu, sigma) {
  9477. var x, r;
  9478. mu = mu == null ? 0 : +mu;
  9479. sigma = sigma == null ? 1 : +sigma;
  9480. return function() {
  9481. var y;
  9482. // If available, use the second previously-generated uniform random.
  9483. if (x != null) y = x, x = null;
  9484. // Otherwise, generate a new x and y.
  9485. else do {
  9486. x = source() * 2 - 1;
  9487. y = source() * 2 - 1;
  9488. r = x * x + y * y;
  9489. } while (!r || r > 1);
  9490. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  9491. };
  9492. }
  9493. randomNormal.source = sourceRandomNormal;
  9494. return randomNormal;
  9495. }))(defaultSource$1);
  9496. var logNormal = ((function sourceRandomLogNormal(source) {
  9497. function randomLogNormal() {
  9498. var randomNormal = normal.source(source).apply(this, arguments);
  9499. return function() {
  9500. return Math.exp(randomNormal());
  9501. };
  9502. }
  9503. randomLogNormal.source = sourceRandomLogNormal;
  9504. return randomLogNormal;
  9505. }))(defaultSource$1);
  9506. var irwinHall = ((function sourceRandomIrwinHall(source) {
  9507. function randomIrwinHall(n) {
  9508. return function() {
  9509. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  9510. return sum;
  9511. };
  9512. }
  9513. randomIrwinHall.source = sourceRandomIrwinHall;
  9514. return randomIrwinHall;
  9515. }))(defaultSource$1);
  9516. var bates = ((function sourceRandomBates(source) {
  9517. function randomBates(n) {
  9518. var randomIrwinHall = irwinHall.source(source)(n);
  9519. return function() {
  9520. return randomIrwinHall() / n;
  9521. };
  9522. }
  9523. randomBates.source = sourceRandomBates;
  9524. return randomBates;
  9525. }))(defaultSource$1);
  9526. var exponential$1 = ((function sourceRandomExponential(source) {
  9527. function randomExponential(lambda) {
  9528. return function() {
  9529. return -Math.log(1 - source()) / lambda;
  9530. };
  9531. }
  9532. randomExponential.source = sourceRandomExponential;
  9533. return randomExponential;
  9534. }))(defaultSource$1);
  9535. var request = function(url, callback) {
  9536. var request,
  9537. event = dispatch("beforesend", "progress", "load", "error"),
  9538. mimeType,
  9539. headers = map$1(),
  9540. xhr = new XMLHttpRequest,
  9541. user = null,
  9542. password = null,
  9543. response,
  9544. responseType,
  9545. timeout = 0;
  9546. // If IE does not support CORS, use XDomainRequest.
  9547. if (typeof XDomainRequest !== "undefined"
  9548. && !("withCredentials" in xhr)
  9549. && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
  9550. "onload" in xhr
  9551. ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
  9552. : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
  9553. function respond(o) {
  9554. var status = xhr.status, result;
  9555. if (!status && hasResponse(xhr)
  9556. || status >= 200 && status < 300
  9557. || status === 304) {
  9558. if (response) {
  9559. try {
  9560. result = response.call(request, xhr);
  9561. } catch (e) {
  9562. event.call("error", request, e);
  9563. return;
  9564. }
  9565. } else {
  9566. result = xhr;
  9567. }
  9568. event.call("load", request, result);
  9569. } else {
  9570. event.call("error", request, o);
  9571. }
  9572. }
  9573. xhr.onprogress = function(e) {
  9574. event.call("progress", request, e);
  9575. };
  9576. request = {
  9577. header: function(name, value) {
  9578. name = (name + "").toLowerCase();
  9579. if (arguments.length < 2) return headers.get(name);
  9580. if (value == null) headers.remove(name);
  9581. else headers.set(name, value + "");
  9582. return request;
  9583. },
  9584. // If mimeType is non-null and no Accept header is set, a default is used.
  9585. mimeType: function(value) {
  9586. if (!arguments.length) return mimeType;
  9587. mimeType = value == null ? null : value + "";
  9588. return request;
  9589. },
  9590. // Specifies what type the response value should take;
  9591. // for instance, arraybuffer, blob, document, or text.
  9592. responseType: function(value) {
  9593. if (!arguments.length) return responseType;
  9594. responseType = value;
  9595. return request;
  9596. },
  9597. timeout: function(value) {
  9598. if (!arguments.length) return timeout;
  9599. timeout = +value;
  9600. return request;
  9601. },
  9602. user: function(value) {
  9603. return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
  9604. },
  9605. password: function(value) {
  9606. return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
  9607. },
  9608. // Specify how to convert the response content to a specific type;
  9609. // changes the callback value on "load" events.
  9610. response: function(value) {
  9611. response = value;
  9612. return request;
  9613. },
  9614. // Alias for send("GET", …).
  9615. get: function(data, callback) {
  9616. return request.send("GET", data, callback);
  9617. },
  9618. // Alias for send("POST", …).
  9619. post: function(data, callback) {
  9620. return request.send("POST", data, callback);
  9621. },
  9622. // If callback is non-null, it will be used for error and load events.
  9623. send: function(method, data, callback) {
  9624. xhr.open(method, url, true, user, password);
  9625. if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
  9626. if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
  9627. if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
  9628. if (responseType != null) xhr.responseType = responseType;
  9629. if (timeout > 0) xhr.timeout = timeout;
  9630. if (callback == null && typeof data === "function") callback = data, data = null;
  9631. if (callback != null && callback.length === 1) callback = fixCallback(callback);
  9632. if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
  9633. event.call("beforesend", request, xhr);
  9634. xhr.send(data == null ? null : data);
  9635. return request;
  9636. },
  9637. abort: function() {
  9638. xhr.abort();
  9639. return request;
  9640. },
  9641. on: function() {
  9642. var value = event.on.apply(event, arguments);
  9643. return value === event ? request : value;
  9644. }
  9645. };
  9646. if (callback != null) {
  9647. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  9648. return request.get(callback);
  9649. }
  9650. return request;
  9651. };
  9652. function fixCallback(callback) {
  9653. return function(error, xhr) {
  9654. callback(error == null ? xhr : null);
  9655. };
  9656. }
  9657. function hasResponse(xhr) {
  9658. var type = xhr.responseType;
  9659. return type && type !== "text"
  9660. ? xhr.response // null on error
  9661. : xhr.responseText; // "" on error
  9662. }
  9663. var type$1 = function(defaultMimeType, response) {
  9664. return function(url, callback) {
  9665. var r = request(url).mimeType(defaultMimeType).response(response);
  9666. if (callback != null) {
  9667. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  9668. return r.get(callback);
  9669. }
  9670. return r;
  9671. };
  9672. };
  9673. var html = type$1("text/html", function(xhr) {
  9674. return document.createRange().createContextualFragment(xhr.responseText);
  9675. });
  9676. var json = type$1("application/json", function(xhr) {
  9677. return JSON.parse(xhr.responseText);
  9678. });
  9679. var text = type$1("text/plain", function(xhr) {
  9680. return xhr.responseText;
  9681. });
  9682. var xml = type$1("application/xml", function(xhr) {
  9683. var xml = xhr.responseXML;
  9684. if (!xml) throw new Error("parse error");
  9685. return xml;
  9686. });
  9687. var dsv$1 = function(defaultMimeType, parse) {
  9688. return function(url, row, callback) {
  9689. if (arguments.length < 3) callback = row, row = null;
  9690. var r = request(url).mimeType(defaultMimeType);
  9691. r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
  9692. r.row(row);
  9693. return callback ? r.get(callback) : r;
  9694. };
  9695. };
  9696. function responseOf(parse, row) {
  9697. return function(request$$1) {
  9698. return parse(request$$1.responseText, row);
  9699. };
  9700. }
  9701. var csv$1 = dsv$1("text/csv", csvParse);
  9702. var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
  9703. var array$2 = Array.prototype;
  9704. var map$3 = array$2.map;
  9705. var slice$4 = array$2.slice;
  9706. var implicit = {name: "implicit"};
  9707. function ordinal(range) {
  9708. var index = map$1(),
  9709. domain = [],
  9710. unknown = implicit;
  9711. range = range == null ? [] : slice$4.call(range);
  9712. function scale(d) {
  9713. var key = d + "", i = index.get(key);
  9714. if (!i) {
  9715. if (unknown !== implicit) return unknown;
  9716. index.set(key, i = domain.push(d));
  9717. }
  9718. return range[(i - 1) % range.length];
  9719. }
  9720. scale.domain = function(_) {
  9721. if (!arguments.length) return domain.slice();
  9722. domain = [], index = map$1();
  9723. var i = -1, n = _.length, d, key;
  9724. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  9725. return scale;
  9726. };
  9727. scale.range = function(_) {
  9728. return arguments.length ? (range = slice$4.call(_), scale) : range.slice();
  9729. };
  9730. scale.unknown = function(_) {
  9731. return arguments.length ? (unknown = _, scale) : unknown;
  9732. };
  9733. scale.copy = function() {
  9734. return ordinal()
  9735. .domain(domain)
  9736. .range(range)
  9737. .unknown(unknown);
  9738. };
  9739. return scale;
  9740. }
  9741. function band() {
  9742. var scale = ordinal().unknown(undefined),
  9743. domain = scale.domain,
  9744. ordinalRange = scale.range,
  9745. range$$1 = [0, 1],
  9746. step,
  9747. bandwidth,
  9748. round = false,
  9749. paddingInner = 0,
  9750. paddingOuter = 0,
  9751. align = 0.5;
  9752. delete scale.unknown;
  9753. function rescale() {
  9754. var n = domain().length,
  9755. reverse = range$$1[1] < range$$1[0],
  9756. start = range$$1[reverse - 0],
  9757. stop = range$$1[1 - reverse];
  9758. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  9759. if (round) step = Math.floor(step);
  9760. start += (stop - start - step * (n - paddingInner)) * align;
  9761. bandwidth = step * (1 - paddingInner);
  9762. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  9763. var values = sequence(n).map(function(i) { return start + step * i; });
  9764. return ordinalRange(reverse ? values.reverse() : values);
  9765. }
  9766. scale.domain = function(_) {
  9767. return arguments.length ? (domain(_), rescale()) : domain();
  9768. };
  9769. scale.range = function(_) {
  9770. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  9771. };
  9772. scale.rangeRound = function(_) {
  9773. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  9774. };
  9775. scale.bandwidth = function() {
  9776. return bandwidth;
  9777. };
  9778. scale.step = function() {
  9779. return step;
  9780. };
  9781. scale.round = function(_) {
  9782. return arguments.length ? (round = !!_, rescale()) : round;
  9783. };
  9784. scale.padding = function(_) {
  9785. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  9786. };
  9787. scale.paddingInner = function(_) {
  9788. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  9789. };
  9790. scale.paddingOuter = function(_) {
  9791. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  9792. };
  9793. scale.align = function(_) {
  9794. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  9795. };
  9796. scale.copy = function() {
  9797. return band()
  9798. .domain(domain())
  9799. .range(range$$1)
  9800. .round(round)
  9801. .paddingInner(paddingInner)
  9802. .paddingOuter(paddingOuter)
  9803. .align(align);
  9804. };
  9805. return rescale();
  9806. }
  9807. function pointish(scale) {
  9808. var copy = scale.copy;
  9809. scale.padding = scale.paddingOuter;
  9810. delete scale.paddingInner;
  9811. delete scale.paddingOuter;
  9812. scale.copy = function() {
  9813. return pointish(copy());
  9814. };
  9815. return scale;
  9816. }
  9817. function point$1() {
  9818. return pointish(band().paddingInner(1));
  9819. }
  9820. var constant$9 = function(x) {
  9821. return function() {
  9822. return x;
  9823. };
  9824. };
  9825. var number$1 = function(x) {
  9826. return +x;
  9827. };
  9828. var unit = [0, 1];
  9829. function deinterpolateLinear(a, b) {
  9830. return (b -= (a = +a))
  9831. ? function(x) { return (x - a) / b; }
  9832. : constant$9(b);
  9833. }
  9834. function deinterpolateClamp(deinterpolate) {
  9835. return function(a, b) {
  9836. var d = deinterpolate(a = +a, b = +b);
  9837. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  9838. };
  9839. }
  9840. function reinterpolateClamp(reinterpolate) {
  9841. return function(a, b) {
  9842. var r = reinterpolate(a = +a, b = +b);
  9843. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  9844. };
  9845. }
  9846. function bimap(domain, range$$1, deinterpolate, reinterpolate) {
  9847. var d0 = domain[0], d1 = domain[1], r0 = range$$1[0], r1 = range$$1[1];
  9848. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
  9849. else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
  9850. return function(x) { return r0(d0(x)); };
  9851. }
  9852. function polymap(domain, range$$1, deinterpolate, reinterpolate) {
  9853. var j = Math.min(domain.length, range$$1.length) - 1,
  9854. d = new Array(j),
  9855. r = new Array(j),
  9856. i = -1;
  9857. // Reverse descending domains.
  9858. if (domain[j] < domain[0]) {
  9859. domain = domain.slice().reverse();
  9860. range$$1 = range$$1.slice().reverse();
  9861. }
  9862. while (++i < j) {
  9863. d[i] = deinterpolate(domain[i], domain[i + 1]);
  9864. r[i] = reinterpolate(range$$1[i], range$$1[i + 1]);
  9865. }
  9866. return function(x) {
  9867. var i = bisectRight(domain, x, 1, j) - 1;
  9868. return r[i](d[i](x));
  9869. };
  9870. }
  9871. function copy(source, target) {
  9872. return target
  9873. .domain(source.domain())
  9874. .range(source.range())
  9875. .interpolate(source.interpolate())
  9876. .clamp(source.clamp());
  9877. }
  9878. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  9879. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  9880. function continuous(deinterpolate, reinterpolate) {
  9881. var domain = unit,
  9882. range$$1 = unit,
  9883. interpolate$$1 = interpolateValue,
  9884. clamp = false,
  9885. piecewise,
  9886. output,
  9887. input;
  9888. function rescale() {
  9889. piecewise = Math.min(domain.length, range$$1.length) > 2 ? polymap : bimap;
  9890. output = input = null;
  9891. return scale;
  9892. }
  9893. function scale(x) {
  9894. return (output || (output = piecewise(domain, range$$1, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  9895. }
  9896. scale.invert = function(y) {
  9897. return (input || (input = piecewise(range$$1, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
  9898. };
  9899. scale.domain = function(_) {
  9900. return arguments.length ? (domain = map$3.call(_, number$1), rescale()) : domain.slice();
  9901. };
  9902. scale.range = function(_) {
  9903. return arguments.length ? (range$$1 = slice$4.call(_), rescale()) : range$$1.slice();
  9904. };
  9905. scale.rangeRound = function(_) {
  9906. return range$$1 = slice$4.call(_), interpolate$$1 = interpolateRound, rescale();
  9907. };
  9908. scale.clamp = function(_) {
  9909. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  9910. };
  9911. scale.interpolate = function(_) {
  9912. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  9913. };
  9914. return rescale();
  9915. }
  9916. var tickFormat = function(domain, count, specifier) {
  9917. var start = domain[0],
  9918. stop = domain[domain.length - 1],
  9919. step = tickStep(start, stop, count == null ? 10 : count),
  9920. precision;
  9921. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  9922. switch (specifier.type) {
  9923. case "s": {
  9924. var value = Math.max(Math.abs(start), Math.abs(stop));
  9925. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  9926. return exports.formatPrefix(specifier, value);
  9927. }
  9928. case "":
  9929. case "e":
  9930. case "g":
  9931. case "p":
  9932. case "r": {
  9933. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  9934. break;
  9935. }
  9936. case "f":
  9937. case "%": {
  9938. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  9939. break;
  9940. }
  9941. }
  9942. return exports.format(specifier);
  9943. };
  9944. function linearish(scale) {
  9945. var domain = scale.domain;
  9946. scale.ticks = function(count) {
  9947. var d = domain();
  9948. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  9949. };
  9950. scale.tickFormat = function(count, specifier) {
  9951. return tickFormat(domain(), count, specifier);
  9952. };
  9953. scale.nice = function(count) {
  9954. if (count == null) count = 10;
  9955. var d = domain(),
  9956. i0 = 0,
  9957. i1 = d.length - 1,
  9958. start = d[i0],
  9959. stop = d[i1],
  9960. step;
  9961. if (stop < start) {
  9962. step = start, start = stop, stop = step;
  9963. step = i0, i0 = i1, i1 = step;
  9964. }
  9965. step = tickIncrement(start, stop, count);
  9966. if (step > 0) {
  9967. start = Math.floor(start / step) * step;
  9968. stop = Math.ceil(stop / step) * step;
  9969. step = tickIncrement(start, stop, count);
  9970. } else if (step < 0) {
  9971. start = Math.ceil(start * step) / step;
  9972. stop = Math.floor(stop * step) / step;
  9973. step = tickIncrement(start, stop, count);
  9974. }
  9975. if (step > 0) {
  9976. d[i0] = Math.floor(start / step) * step;
  9977. d[i1] = Math.ceil(stop / step) * step;
  9978. domain(d);
  9979. } else if (step < 0) {
  9980. d[i0] = Math.ceil(start * step) / step;
  9981. d[i1] = Math.floor(stop * step) / step;
  9982. domain(d);
  9983. }
  9984. return scale;
  9985. };
  9986. return scale;
  9987. }
  9988. function linear$2() {
  9989. var scale = continuous(deinterpolateLinear, reinterpolate);
  9990. scale.copy = function() {
  9991. return copy(scale, linear$2());
  9992. };
  9993. return linearish(scale);
  9994. }
  9995. function identity$6() {
  9996. var domain = [0, 1];
  9997. function scale(x) {
  9998. return +x;
  9999. }
  10000. scale.invert = scale;
  10001. scale.domain = scale.range = function(_) {
  10002. return arguments.length ? (domain = map$3.call(_, number$1), scale) : domain.slice();
  10003. };
  10004. scale.copy = function() {
  10005. return identity$6().domain(domain);
  10006. };
  10007. return linearish(scale);
  10008. }
  10009. var nice = function(domain, interval) {
  10010. domain = domain.slice();
  10011. var i0 = 0,
  10012. i1 = domain.length - 1,
  10013. x0 = domain[i0],
  10014. x1 = domain[i1],
  10015. t;
  10016. if (x1 < x0) {
  10017. t = i0, i0 = i1, i1 = t;
  10018. t = x0, x0 = x1, x1 = t;
  10019. }
  10020. domain[i0] = interval.floor(x0);
  10021. domain[i1] = interval.ceil(x1);
  10022. return domain;
  10023. };
  10024. function deinterpolate(a, b) {
  10025. return (b = Math.log(b / a))
  10026. ? function(x) { return Math.log(x / a) / b; }
  10027. : constant$9(b);
  10028. }
  10029. function reinterpolate$1(a, b) {
  10030. return a < 0
  10031. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  10032. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  10033. }
  10034. function pow10(x) {
  10035. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10036. }
  10037. function powp(base) {
  10038. return base === 10 ? pow10
  10039. : base === Math.E ? Math.exp
  10040. : function(x) { return Math.pow(base, x); };
  10041. }
  10042. function logp(base) {
  10043. return base === Math.E ? Math.log
  10044. : base === 10 && Math.log10
  10045. || base === 2 && Math.log2
  10046. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10047. }
  10048. function reflect(f) {
  10049. return function(x) {
  10050. return -f(-x);
  10051. };
  10052. }
  10053. function log$1() {
  10054. var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
  10055. domain = scale.domain,
  10056. base = 10,
  10057. logs = logp(10),
  10058. pows = powp(10);
  10059. function rescale() {
  10060. logs = logp(base), pows = powp(base);
  10061. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  10062. return scale;
  10063. }
  10064. scale.base = function(_) {
  10065. return arguments.length ? (base = +_, rescale()) : base;
  10066. };
  10067. scale.domain = function(_) {
  10068. return arguments.length ? (domain(_), rescale()) : domain();
  10069. };
  10070. scale.ticks = function(count) {
  10071. var d = domain(),
  10072. u = d[0],
  10073. v = d[d.length - 1],
  10074. r;
  10075. if (r = v < u) i = u, u = v, v = i;
  10076. var i = logs(u),
  10077. j = logs(v),
  10078. p,
  10079. k,
  10080. t,
  10081. n = count == null ? 10 : +count,
  10082. z = [];
  10083. if (!(base % 1) && j - i < n) {
  10084. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10085. if (u > 0) for (; i < j; ++i) {
  10086. for (k = 1, p = pows(i); k < base; ++k) {
  10087. t = p * k;
  10088. if (t < u) continue;
  10089. if (t > v) break;
  10090. z.push(t);
  10091. }
  10092. } else for (; i < j; ++i) {
  10093. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10094. t = p * k;
  10095. if (t < u) continue;
  10096. if (t > v) break;
  10097. z.push(t);
  10098. }
  10099. }
  10100. } else {
  10101. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10102. }
  10103. return r ? z.reverse() : z;
  10104. };
  10105. scale.tickFormat = function(count, specifier) {
  10106. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10107. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10108. if (count === Infinity) return specifier;
  10109. if (count == null) count = 10;
  10110. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10111. return function(d) {
  10112. var i = d / pows(Math.round(logs(d)));
  10113. if (i * base < base - 0.5) i *= base;
  10114. return i <= k ? specifier(d) : "";
  10115. };
  10116. };
  10117. scale.nice = function() {
  10118. return domain(nice(domain(), {
  10119. floor: function(x) { return pows(Math.floor(logs(x))); },
  10120. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10121. }));
  10122. };
  10123. scale.copy = function() {
  10124. return copy(scale, log$1().base(base));
  10125. };
  10126. return scale;
  10127. }
  10128. function raise$1(x, exponent) {
  10129. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10130. }
  10131. function pow$1() {
  10132. var exponent = 1,
  10133. scale = continuous(deinterpolate, reinterpolate),
  10134. domain = scale.domain;
  10135. function deinterpolate(a, b) {
  10136. return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
  10137. ? function(x) { return (raise$1(x, exponent) - a) / b; }
  10138. : constant$9(b);
  10139. }
  10140. function reinterpolate(a, b) {
  10141. b = raise$1(b, exponent) - (a = raise$1(a, exponent));
  10142. return function(t) { return raise$1(a + b * t, 1 / exponent); };
  10143. }
  10144. scale.exponent = function(_) {
  10145. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  10146. };
  10147. scale.copy = function() {
  10148. return copy(scale, pow$1().exponent(exponent));
  10149. };
  10150. return linearish(scale);
  10151. }
  10152. function sqrt$1() {
  10153. return pow$1().exponent(0.5);
  10154. }
  10155. function quantile$$1() {
  10156. var domain = [],
  10157. range$$1 = [],
  10158. thresholds = [];
  10159. function rescale() {
  10160. var i = 0, n = Math.max(1, range$$1.length);
  10161. thresholds = new Array(n - 1);
  10162. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10163. return scale;
  10164. }
  10165. function scale(x) {
  10166. if (!isNaN(x = +x)) return range$$1[bisectRight(thresholds, x)];
  10167. }
  10168. scale.invertExtent = function(y) {
  10169. var i = range$$1.indexOf(y);
  10170. return i < 0 ? [NaN, NaN] : [
  10171. i > 0 ? thresholds[i - 1] : domain[0],
  10172. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10173. ];
  10174. };
  10175. scale.domain = function(_) {
  10176. if (!arguments.length) return domain.slice();
  10177. domain = [];
  10178. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10179. domain.sort(ascending);
  10180. return rescale();
  10181. };
  10182. scale.range = function(_) {
  10183. return arguments.length ? (range$$1 = slice$4.call(_), rescale()) : range$$1.slice();
  10184. };
  10185. scale.quantiles = function() {
  10186. return thresholds.slice();
  10187. };
  10188. scale.copy = function() {
  10189. return quantile$$1()
  10190. .domain(domain)
  10191. .range(range$$1);
  10192. };
  10193. return scale;
  10194. }
  10195. function quantize$1() {
  10196. var x0 = 0,
  10197. x1 = 1,
  10198. n = 1,
  10199. domain = [0.5],
  10200. range$$1 = [0, 1];
  10201. function scale(x) {
  10202. if (x <= x) return range$$1[bisectRight(domain, x, 0, n)];
  10203. }
  10204. function rescale() {
  10205. var i = -1;
  10206. domain = new Array(n);
  10207. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10208. return scale;
  10209. }
  10210. scale.domain = function(_) {
  10211. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10212. };
  10213. scale.range = function(_) {
  10214. return arguments.length ? (n = (range$$1 = slice$4.call(_)).length - 1, rescale()) : range$$1.slice();
  10215. };
  10216. scale.invertExtent = function(y) {
  10217. var i = range$$1.indexOf(y);
  10218. return i < 0 ? [NaN, NaN]
  10219. : i < 1 ? [x0, domain[0]]
  10220. : i >= n ? [domain[n - 1], x1]
  10221. : [domain[i - 1], domain[i]];
  10222. };
  10223. scale.copy = function() {
  10224. return quantize$1()
  10225. .domain([x0, x1])
  10226. .range(range$$1);
  10227. };
  10228. return linearish(scale);
  10229. }
  10230. function threshold$1() {
  10231. var domain = [0.5],
  10232. range$$1 = [0, 1],
  10233. n = 1;
  10234. function scale(x) {
  10235. if (x <= x) return range$$1[bisectRight(domain, x, 0, n)];
  10236. }
  10237. scale.domain = function(_) {
  10238. return arguments.length ? (domain = slice$4.call(_), n = Math.min(domain.length, range$$1.length - 1), scale) : domain.slice();
  10239. };
  10240. scale.range = function(_) {
  10241. return arguments.length ? (range$$1 = slice$4.call(_), n = Math.min(domain.length, range$$1.length - 1), scale) : range$$1.slice();
  10242. };
  10243. scale.invertExtent = function(y) {
  10244. var i = range$$1.indexOf(y);
  10245. return [domain[i - 1], domain[i]];
  10246. };
  10247. scale.copy = function() {
  10248. return threshold$1()
  10249. .domain(domain)
  10250. .range(range$$1);
  10251. };
  10252. return scale;
  10253. }
  10254. var t0$1 = new Date;
  10255. var t1$1 = new Date;
  10256. function newInterval(floori, offseti, count, field) {
  10257. function interval(date) {
  10258. return floori(date = new Date(+date)), date;
  10259. }
  10260. interval.floor = interval;
  10261. interval.ceil = function(date) {
  10262. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10263. };
  10264. interval.round = function(date) {
  10265. var d0 = interval(date),
  10266. d1 = interval.ceil(date);
  10267. return date - d0 < d1 - date ? d0 : d1;
  10268. };
  10269. interval.offset = function(date, step) {
  10270. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10271. };
  10272. interval.range = function(start, stop, step) {
  10273. var range = [];
  10274. start = interval.ceil(start);
  10275. step = step == null ? 1 : Math.floor(step);
  10276. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10277. do range.push(new Date(+start)); while (offseti(start, step), floori(start), start < stop)
  10278. return range;
  10279. };
  10280. interval.filter = function(test) {
  10281. return newInterval(function(date) {
  10282. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10283. }, function(date, step) {
  10284. if (date >= date) while (--step >= 0) while (offseti(date, 1), !test(date)) {} // eslint-disable-line no-empty
  10285. });
  10286. };
  10287. if (count) {
  10288. interval.count = function(start, end) {
  10289. t0$1.setTime(+start), t1$1.setTime(+end);
  10290. floori(t0$1), floori(t1$1);
  10291. return Math.floor(count(t0$1, t1$1));
  10292. };
  10293. interval.every = function(step) {
  10294. step = Math.floor(step);
  10295. return !isFinite(step) || !(step > 0) ? null
  10296. : !(step > 1) ? interval
  10297. : interval.filter(field
  10298. ? function(d) { return field(d) % step === 0; }
  10299. : function(d) { return interval.count(0, d) % step === 0; });
  10300. };
  10301. }
  10302. return interval;
  10303. }
  10304. var millisecond = newInterval(function() {
  10305. // noop
  10306. }, function(date, step) {
  10307. date.setTime(+date + step);
  10308. }, function(start, end) {
  10309. return end - start;
  10310. });
  10311. // An optimized implementation for this simple case.
  10312. millisecond.every = function(k) {
  10313. k = Math.floor(k);
  10314. if (!isFinite(k) || !(k > 0)) return null;
  10315. if (!(k > 1)) return millisecond;
  10316. return newInterval(function(date) {
  10317. date.setTime(Math.floor(date / k) * k);
  10318. }, function(date, step) {
  10319. date.setTime(+date + step * k);
  10320. }, function(start, end) {
  10321. return (end - start) / k;
  10322. });
  10323. };
  10324. var milliseconds = millisecond.range;
  10325. var durationSecond$1 = 1e3;
  10326. var durationMinute$1 = 6e4;
  10327. var durationHour$1 = 36e5;
  10328. var durationDay$1 = 864e5;
  10329. var durationWeek$1 = 6048e5;
  10330. var second = newInterval(function(date) {
  10331. date.setTime(Math.floor(date / durationSecond$1) * durationSecond$1);
  10332. }, function(date, step) {
  10333. date.setTime(+date + step * durationSecond$1);
  10334. }, function(start, end) {
  10335. return (end - start) / durationSecond$1;
  10336. }, function(date) {
  10337. return date.getUTCSeconds();
  10338. });
  10339. var seconds = second.range;
  10340. var minute = newInterval(function(date) {
  10341. date.setTime(Math.floor(date / durationMinute$1) * durationMinute$1);
  10342. }, function(date, step) {
  10343. date.setTime(+date + step * durationMinute$1);
  10344. }, function(start, end) {
  10345. return (end - start) / durationMinute$1;
  10346. }, function(date) {
  10347. return date.getMinutes();
  10348. });
  10349. var minutes = minute.range;
  10350. var hour = newInterval(function(date) {
  10351. var offset = date.getTimezoneOffset() * durationMinute$1 % durationHour$1;
  10352. if (offset < 0) offset += durationHour$1;
  10353. date.setTime(Math.floor((+date - offset) / durationHour$1) * durationHour$1 + offset);
  10354. }, function(date, step) {
  10355. date.setTime(+date + step * durationHour$1);
  10356. }, function(start, end) {
  10357. return (end - start) / durationHour$1;
  10358. }, function(date) {
  10359. return date.getHours();
  10360. });
  10361. var hours = hour.range;
  10362. var day = newInterval(function(date) {
  10363. date.setHours(0, 0, 0, 0);
  10364. }, function(date, step) {
  10365. date.setDate(date.getDate() + step);
  10366. }, function(start, end) {
  10367. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationDay$1;
  10368. }, function(date) {
  10369. return date.getDate() - 1;
  10370. });
  10371. var days = day.range;
  10372. function weekday(i) {
  10373. return newInterval(function(date) {
  10374. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  10375. date.setHours(0, 0, 0, 0);
  10376. }, function(date, step) {
  10377. date.setDate(date.getDate() + step * 7);
  10378. }, function(start, end) {
  10379. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
  10380. });
  10381. }
  10382. var sunday = weekday(0);
  10383. var monday = weekday(1);
  10384. var tuesday = weekday(2);
  10385. var wednesday = weekday(3);
  10386. var thursday = weekday(4);
  10387. var friday = weekday(5);
  10388. var saturday = weekday(6);
  10389. var sundays = sunday.range;
  10390. var mondays = monday.range;
  10391. var tuesdays = tuesday.range;
  10392. var wednesdays = wednesday.range;
  10393. var thursdays = thursday.range;
  10394. var fridays = friday.range;
  10395. var saturdays = saturday.range;
  10396. var month = newInterval(function(date) {
  10397. date.setDate(1);
  10398. date.setHours(0, 0, 0, 0);
  10399. }, function(date, step) {
  10400. date.setMonth(date.getMonth() + step);
  10401. }, function(start, end) {
  10402. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  10403. }, function(date) {
  10404. return date.getMonth();
  10405. });
  10406. var months = month.range;
  10407. var year = newInterval(function(date) {
  10408. date.setMonth(0, 1);
  10409. date.setHours(0, 0, 0, 0);
  10410. }, function(date, step) {
  10411. date.setFullYear(date.getFullYear() + step);
  10412. }, function(start, end) {
  10413. return end.getFullYear() - start.getFullYear();
  10414. }, function(date) {
  10415. return date.getFullYear();
  10416. });
  10417. // An optimized implementation for this simple case.
  10418. year.every = function(k) {
  10419. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10420. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  10421. date.setMonth(0, 1);
  10422. date.setHours(0, 0, 0, 0);
  10423. }, function(date, step) {
  10424. date.setFullYear(date.getFullYear() + step * k);
  10425. });
  10426. };
  10427. var years = year.range;
  10428. var utcMinute = newInterval(function(date) {
  10429. date.setUTCSeconds(0, 0);
  10430. }, function(date, step) {
  10431. date.setTime(+date + step * durationMinute$1);
  10432. }, function(start, end) {
  10433. return (end - start) / durationMinute$1;
  10434. }, function(date) {
  10435. return date.getUTCMinutes();
  10436. });
  10437. var utcMinutes = utcMinute.range;
  10438. var utcHour = newInterval(function(date) {
  10439. date.setUTCMinutes(0, 0, 0);
  10440. }, function(date, step) {
  10441. date.setTime(+date + step * durationHour$1);
  10442. }, function(start, end) {
  10443. return (end - start) / durationHour$1;
  10444. }, function(date) {
  10445. return date.getUTCHours();
  10446. });
  10447. var utcHours = utcHour.range;
  10448. var utcDay = newInterval(function(date) {
  10449. date.setUTCHours(0, 0, 0, 0);
  10450. }, function(date, step) {
  10451. date.setUTCDate(date.getUTCDate() + step);
  10452. }, function(start, end) {
  10453. return (end - start) / durationDay$1;
  10454. }, function(date) {
  10455. return date.getUTCDate() - 1;
  10456. });
  10457. var utcDays = utcDay.range;
  10458. function utcWeekday(i) {
  10459. return newInterval(function(date) {
  10460. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  10461. date.setUTCHours(0, 0, 0, 0);
  10462. }, function(date, step) {
  10463. date.setUTCDate(date.getUTCDate() + step * 7);
  10464. }, function(start, end) {
  10465. return (end - start) / durationWeek$1;
  10466. });
  10467. }
  10468. var utcSunday = utcWeekday(0);
  10469. var utcMonday = utcWeekday(1);
  10470. var utcTuesday = utcWeekday(2);
  10471. var utcWednesday = utcWeekday(3);
  10472. var utcThursday = utcWeekday(4);
  10473. var utcFriday = utcWeekday(5);
  10474. var utcSaturday = utcWeekday(6);
  10475. var utcSundays = utcSunday.range;
  10476. var utcMondays = utcMonday.range;
  10477. var utcTuesdays = utcTuesday.range;
  10478. var utcWednesdays = utcWednesday.range;
  10479. var utcThursdays = utcThursday.range;
  10480. var utcFridays = utcFriday.range;
  10481. var utcSaturdays = utcSaturday.range;
  10482. var utcMonth = newInterval(function(date) {
  10483. date.setUTCDate(1);
  10484. date.setUTCHours(0, 0, 0, 0);
  10485. }, function(date, step) {
  10486. date.setUTCMonth(date.getUTCMonth() + step);
  10487. }, function(start, end) {
  10488. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  10489. }, function(date) {
  10490. return date.getUTCMonth();
  10491. });
  10492. var utcMonths = utcMonth.range;
  10493. var utcYear = newInterval(function(date) {
  10494. date.setUTCMonth(0, 1);
  10495. date.setUTCHours(0, 0, 0, 0);
  10496. }, function(date, step) {
  10497. date.setUTCFullYear(date.getUTCFullYear() + step);
  10498. }, function(start, end) {
  10499. return end.getUTCFullYear() - start.getUTCFullYear();
  10500. }, function(date) {
  10501. return date.getUTCFullYear();
  10502. });
  10503. // An optimized implementation for this simple case.
  10504. utcYear.every = function(k) {
  10505. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10506. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  10507. date.setUTCMonth(0, 1);
  10508. date.setUTCHours(0, 0, 0, 0);
  10509. }, function(date, step) {
  10510. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  10511. });
  10512. };
  10513. var utcYears = utcYear.range;
  10514. function localDate(d) {
  10515. if (0 <= d.y && d.y < 100) {
  10516. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  10517. date.setFullYear(d.y);
  10518. return date;
  10519. }
  10520. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  10521. }
  10522. function utcDate(d) {
  10523. if (0 <= d.y && d.y < 100) {
  10524. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  10525. date.setUTCFullYear(d.y);
  10526. return date;
  10527. }
  10528. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  10529. }
  10530. function newYear(y) {
  10531. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  10532. }
  10533. function formatLocale$1(locale) {
  10534. var locale_dateTime = locale.dateTime,
  10535. locale_date = locale.date,
  10536. locale_time = locale.time,
  10537. locale_periods = locale.periods,
  10538. locale_weekdays = locale.days,
  10539. locale_shortWeekdays = locale.shortDays,
  10540. locale_months = locale.months,
  10541. locale_shortMonths = locale.shortMonths;
  10542. var periodRe = formatRe(locale_periods),
  10543. periodLookup = formatLookup(locale_periods),
  10544. weekdayRe = formatRe(locale_weekdays),
  10545. weekdayLookup = formatLookup(locale_weekdays),
  10546. shortWeekdayRe = formatRe(locale_shortWeekdays),
  10547. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  10548. monthRe = formatRe(locale_months),
  10549. monthLookup = formatLookup(locale_months),
  10550. shortMonthRe = formatRe(locale_shortMonths),
  10551. shortMonthLookup = formatLookup(locale_shortMonths);
  10552. var formats = {
  10553. "a": formatShortWeekday,
  10554. "A": formatWeekday,
  10555. "b": formatShortMonth,
  10556. "B": formatMonth,
  10557. "c": null,
  10558. "d": formatDayOfMonth,
  10559. "e": formatDayOfMonth,
  10560. "H": formatHour24,
  10561. "I": formatHour12,
  10562. "j": formatDayOfYear,
  10563. "L": formatMilliseconds,
  10564. "m": formatMonthNumber,
  10565. "M": formatMinutes,
  10566. "p": formatPeriod,
  10567. "S": formatSeconds,
  10568. "U": formatWeekNumberSunday,
  10569. "w": formatWeekdayNumber,
  10570. "W": formatWeekNumberMonday,
  10571. "x": null,
  10572. "X": null,
  10573. "y": formatYear,
  10574. "Y": formatFullYear,
  10575. "Z": formatZone,
  10576. "%": formatLiteralPercent
  10577. };
  10578. var utcFormats = {
  10579. "a": formatUTCShortWeekday,
  10580. "A": formatUTCWeekday,
  10581. "b": formatUTCShortMonth,
  10582. "B": formatUTCMonth,
  10583. "c": null,
  10584. "d": formatUTCDayOfMonth,
  10585. "e": formatUTCDayOfMonth,
  10586. "H": formatUTCHour24,
  10587. "I": formatUTCHour12,
  10588. "j": formatUTCDayOfYear,
  10589. "L": formatUTCMilliseconds,
  10590. "m": formatUTCMonthNumber,
  10591. "M": formatUTCMinutes,
  10592. "p": formatUTCPeriod,
  10593. "S": formatUTCSeconds,
  10594. "U": formatUTCWeekNumberSunday,
  10595. "w": formatUTCWeekdayNumber,
  10596. "W": formatUTCWeekNumberMonday,
  10597. "x": null,
  10598. "X": null,
  10599. "y": formatUTCYear,
  10600. "Y": formatUTCFullYear,
  10601. "Z": formatUTCZone,
  10602. "%": formatLiteralPercent
  10603. };
  10604. var parses = {
  10605. "a": parseShortWeekday,
  10606. "A": parseWeekday,
  10607. "b": parseShortMonth,
  10608. "B": parseMonth,
  10609. "c": parseLocaleDateTime,
  10610. "d": parseDayOfMonth,
  10611. "e": parseDayOfMonth,
  10612. "H": parseHour24,
  10613. "I": parseHour24,
  10614. "j": parseDayOfYear,
  10615. "L": parseMilliseconds,
  10616. "m": parseMonthNumber,
  10617. "M": parseMinutes,
  10618. "p": parsePeriod,
  10619. "S": parseSeconds,
  10620. "U": parseWeekNumberSunday,
  10621. "w": parseWeekdayNumber,
  10622. "W": parseWeekNumberMonday,
  10623. "x": parseLocaleDate,
  10624. "X": parseLocaleTime,
  10625. "y": parseYear,
  10626. "Y": parseFullYear,
  10627. "Z": parseZone,
  10628. "%": parseLiteralPercent
  10629. };
  10630. // These recursive directive definitions must be deferred.
  10631. formats.x = newFormat(locale_date, formats);
  10632. formats.X = newFormat(locale_time, formats);
  10633. formats.c = newFormat(locale_dateTime, formats);
  10634. utcFormats.x = newFormat(locale_date, utcFormats);
  10635. utcFormats.X = newFormat(locale_time, utcFormats);
  10636. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  10637. function newFormat(specifier, formats) {
  10638. return function(date) {
  10639. var string = [],
  10640. i = -1,
  10641. j = 0,
  10642. n = specifier.length,
  10643. c,
  10644. pad,
  10645. format;
  10646. if (!(date instanceof Date)) date = new Date(+date);
  10647. while (++i < n) {
  10648. if (specifier.charCodeAt(i) === 37) {
  10649. string.push(specifier.slice(j, i));
  10650. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  10651. else pad = c === "e" ? " " : "0";
  10652. if (format = formats[c]) c = format(date, pad);
  10653. string.push(c);
  10654. j = i + 1;
  10655. }
  10656. }
  10657. string.push(specifier.slice(j, i));
  10658. return string.join("");
  10659. };
  10660. }
  10661. function newParse(specifier, newDate) {
  10662. return function(string) {
  10663. var d = newYear(1900),
  10664. i = parseSpecifier(d, specifier, string += "", 0);
  10665. if (i != string.length) return null;
  10666. // The am-pm flag is 0 for AM, and 1 for PM.
  10667. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  10668. // Convert day-of-week and week-of-year to day-of-year.
  10669. if ("W" in d || "U" in d) {
  10670. if (!("w" in d)) d.w = "W" in d ? 1 : 0;
  10671. var day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  10672. d.m = 0;
  10673. 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;
  10674. }
  10675. // If a time zone is specified, all fields are interpreted as UTC and then
  10676. // offset according to the specified time zone.
  10677. if ("Z" in d) {
  10678. d.H += d.Z / 100 | 0;
  10679. d.M += d.Z % 100;
  10680. return utcDate(d);
  10681. }
  10682. // Otherwise, all fields are in local time.
  10683. return newDate(d);
  10684. };
  10685. }
  10686. function parseSpecifier(d, specifier, string, j) {
  10687. var i = 0,
  10688. n = specifier.length,
  10689. m = string.length,
  10690. c,
  10691. parse;
  10692. while (i < n) {
  10693. if (j >= m) return -1;
  10694. c = specifier.charCodeAt(i++);
  10695. if (c === 37) {
  10696. c = specifier.charAt(i++);
  10697. parse = parses[c in pads ? specifier.charAt(i++) : c];
  10698. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  10699. } else if (c != string.charCodeAt(j++)) {
  10700. return -1;
  10701. }
  10702. }
  10703. return j;
  10704. }
  10705. function parsePeriod(d, string, i) {
  10706. var n = periodRe.exec(string.slice(i));
  10707. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10708. }
  10709. function parseShortWeekday(d, string, i) {
  10710. var n = shortWeekdayRe.exec(string.slice(i));
  10711. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10712. }
  10713. function parseWeekday(d, string, i) {
  10714. var n = weekdayRe.exec(string.slice(i));
  10715. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10716. }
  10717. function parseShortMonth(d, string, i) {
  10718. var n = shortMonthRe.exec(string.slice(i));
  10719. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10720. }
  10721. function parseMonth(d, string, i) {
  10722. var n = monthRe.exec(string.slice(i));
  10723. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10724. }
  10725. function parseLocaleDateTime(d, string, i) {
  10726. return parseSpecifier(d, locale_dateTime, string, i);
  10727. }
  10728. function parseLocaleDate(d, string, i) {
  10729. return parseSpecifier(d, locale_date, string, i);
  10730. }
  10731. function parseLocaleTime(d, string, i) {
  10732. return parseSpecifier(d, locale_time, string, i);
  10733. }
  10734. function formatShortWeekday(d) {
  10735. return locale_shortWeekdays[d.getDay()];
  10736. }
  10737. function formatWeekday(d) {
  10738. return locale_weekdays[d.getDay()];
  10739. }
  10740. function formatShortMonth(d) {
  10741. return locale_shortMonths[d.getMonth()];
  10742. }
  10743. function formatMonth(d) {
  10744. return locale_months[d.getMonth()];
  10745. }
  10746. function formatPeriod(d) {
  10747. return locale_periods[+(d.getHours() >= 12)];
  10748. }
  10749. function formatUTCShortWeekday(d) {
  10750. return locale_shortWeekdays[d.getUTCDay()];
  10751. }
  10752. function formatUTCWeekday(d) {
  10753. return locale_weekdays[d.getUTCDay()];
  10754. }
  10755. function formatUTCShortMonth(d) {
  10756. return locale_shortMonths[d.getUTCMonth()];
  10757. }
  10758. function formatUTCMonth(d) {
  10759. return locale_months[d.getUTCMonth()];
  10760. }
  10761. function formatUTCPeriod(d) {
  10762. return locale_periods[+(d.getUTCHours() >= 12)];
  10763. }
  10764. return {
  10765. format: function(specifier) {
  10766. var f = newFormat(specifier += "", formats);
  10767. f.toString = function() { return specifier; };
  10768. return f;
  10769. },
  10770. parse: function(specifier) {
  10771. var p = newParse(specifier += "", localDate);
  10772. p.toString = function() { return specifier; };
  10773. return p;
  10774. },
  10775. utcFormat: function(specifier) {
  10776. var f = newFormat(specifier += "", utcFormats);
  10777. f.toString = function() { return specifier; };
  10778. return f;
  10779. },
  10780. utcParse: function(specifier) {
  10781. var p = newParse(specifier, utcDate);
  10782. p.toString = function() { return specifier; };
  10783. return p;
  10784. }
  10785. };
  10786. }
  10787. var pads = {"-": "", "_": " ", "0": "0"};
  10788. var numberRe = /^\s*\d+/;
  10789. var percentRe = /^%/;
  10790. var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  10791. function pad(value, fill, width) {
  10792. var sign = value < 0 ? "-" : "",
  10793. string = (sign ? -value : value) + "",
  10794. length = string.length;
  10795. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  10796. }
  10797. function requote(s) {
  10798. return s.replace(requoteRe, "\\$&");
  10799. }
  10800. function formatRe(names) {
  10801. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  10802. }
  10803. function formatLookup(names) {
  10804. var map = {}, i = -1, n = names.length;
  10805. while (++i < n) map[names[i].toLowerCase()] = i;
  10806. return map;
  10807. }
  10808. function parseWeekdayNumber(d, string, i) {
  10809. var n = numberRe.exec(string.slice(i, i + 1));
  10810. return n ? (d.w = +n[0], i + n[0].length) : -1;
  10811. }
  10812. function parseWeekNumberSunday(d, string, i) {
  10813. var n = numberRe.exec(string.slice(i));
  10814. return n ? (d.U = +n[0], i + n[0].length) : -1;
  10815. }
  10816. function parseWeekNumberMonday(d, string, i) {
  10817. var n = numberRe.exec(string.slice(i));
  10818. return n ? (d.W = +n[0], i + n[0].length) : -1;
  10819. }
  10820. function parseFullYear(d, string, i) {
  10821. var n = numberRe.exec(string.slice(i, i + 4));
  10822. return n ? (d.y = +n[0], i + n[0].length) : -1;
  10823. }
  10824. function parseYear(d, string, i) {
  10825. var n = numberRe.exec(string.slice(i, i + 2));
  10826. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  10827. }
  10828. function parseZone(d, string, i) {
  10829. var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
  10830. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  10831. }
  10832. function parseMonthNumber(d, string, i) {
  10833. var n = numberRe.exec(string.slice(i, i + 2));
  10834. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  10835. }
  10836. function parseDayOfMonth(d, string, i) {
  10837. var n = numberRe.exec(string.slice(i, i + 2));
  10838. return n ? (d.d = +n[0], i + n[0].length) : -1;
  10839. }
  10840. function parseDayOfYear(d, string, i) {
  10841. var n = numberRe.exec(string.slice(i, i + 3));
  10842. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  10843. }
  10844. function parseHour24(d, string, i) {
  10845. var n = numberRe.exec(string.slice(i, i + 2));
  10846. return n ? (d.H = +n[0], i + n[0].length) : -1;
  10847. }
  10848. function parseMinutes(d, string, i) {
  10849. var n = numberRe.exec(string.slice(i, i + 2));
  10850. return n ? (d.M = +n[0], i + n[0].length) : -1;
  10851. }
  10852. function parseSeconds(d, string, i) {
  10853. var n = numberRe.exec(string.slice(i, i + 2));
  10854. return n ? (d.S = +n[0], i + n[0].length) : -1;
  10855. }
  10856. function parseMilliseconds(d, string, i) {
  10857. var n = numberRe.exec(string.slice(i, i + 3));
  10858. return n ? (d.L = +n[0], i + n[0].length) : -1;
  10859. }
  10860. function parseLiteralPercent(d, string, i) {
  10861. var n = percentRe.exec(string.slice(i, i + 1));
  10862. return n ? i + n[0].length : -1;
  10863. }
  10864. function formatDayOfMonth(d, p) {
  10865. return pad(d.getDate(), p, 2);
  10866. }
  10867. function formatHour24(d, p) {
  10868. return pad(d.getHours(), p, 2);
  10869. }
  10870. function formatHour12(d, p) {
  10871. return pad(d.getHours() % 12 || 12, p, 2);
  10872. }
  10873. function formatDayOfYear(d, p) {
  10874. return pad(1 + day.count(year(d), d), p, 3);
  10875. }
  10876. function formatMilliseconds(d, p) {
  10877. return pad(d.getMilliseconds(), p, 3);
  10878. }
  10879. function formatMonthNumber(d, p) {
  10880. return pad(d.getMonth() + 1, p, 2);
  10881. }
  10882. function formatMinutes(d, p) {
  10883. return pad(d.getMinutes(), p, 2);
  10884. }
  10885. function formatSeconds(d, p) {
  10886. return pad(d.getSeconds(), p, 2);
  10887. }
  10888. function formatWeekNumberSunday(d, p) {
  10889. return pad(sunday.count(year(d), d), p, 2);
  10890. }
  10891. function formatWeekdayNumber(d) {
  10892. return d.getDay();
  10893. }
  10894. function formatWeekNumberMonday(d, p) {
  10895. return pad(monday.count(year(d), d), p, 2);
  10896. }
  10897. function formatYear(d, p) {
  10898. return pad(d.getFullYear() % 100, p, 2);
  10899. }
  10900. function formatFullYear(d, p) {
  10901. return pad(d.getFullYear() % 10000, p, 4);
  10902. }
  10903. function formatZone(d) {
  10904. var z = d.getTimezoneOffset();
  10905. return (z > 0 ? "-" : (z *= -1, "+"))
  10906. + pad(z / 60 | 0, "0", 2)
  10907. + pad(z % 60, "0", 2);
  10908. }
  10909. function formatUTCDayOfMonth(d, p) {
  10910. return pad(d.getUTCDate(), p, 2);
  10911. }
  10912. function formatUTCHour24(d, p) {
  10913. return pad(d.getUTCHours(), p, 2);
  10914. }
  10915. function formatUTCHour12(d, p) {
  10916. return pad(d.getUTCHours() % 12 || 12, p, 2);
  10917. }
  10918. function formatUTCDayOfYear(d, p) {
  10919. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  10920. }
  10921. function formatUTCMilliseconds(d, p) {
  10922. return pad(d.getUTCMilliseconds(), p, 3);
  10923. }
  10924. function formatUTCMonthNumber(d, p) {
  10925. return pad(d.getUTCMonth() + 1, p, 2);
  10926. }
  10927. function formatUTCMinutes(d, p) {
  10928. return pad(d.getUTCMinutes(), p, 2);
  10929. }
  10930. function formatUTCSeconds(d, p) {
  10931. return pad(d.getUTCSeconds(), p, 2);
  10932. }
  10933. function formatUTCWeekNumberSunday(d, p) {
  10934. return pad(utcSunday.count(utcYear(d), d), p, 2);
  10935. }
  10936. function formatUTCWeekdayNumber(d) {
  10937. return d.getUTCDay();
  10938. }
  10939. function formatUTCWeekNumberMonday(d, p) {
  10940. return pad(utcMonday.count(utcYear(d), d), p, 2);
  10941. }
  10942. function formatUTCYear(d, p) {
  10943. return pad(d.getUTCFullYear() % 100, p, 2);
  10944. }
  10945. function formatUTCFullYear(d, p) {
  10946. return pad(d.getUTCFullYear() % 10000, p, 4);
  10947. }
  10948. function formatUTCZone() {
  10949. return "+0000";
  10950. }
  10951. function formatLiteralPercent() {
  10952. return "%";
  10953. }
  10954. var locale$2;
  10955. defaultLocale$1({
  10956. dateTime: "%x, %X",
  10957. date: "%-m/%-d/%Y",
  10958. time: "%-I:%M:%S %p",
  10959. periods: ["AM", "PM"],
  10960. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  10961. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  10962. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  10963. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  10964. });
  10965. function defaultLocale$1(definition) {
  10966. locale$2 = formatLocale$1(definition);
  10967. exports.timeFormat = locale$2.format;
  10968. exports.timeParse = locale$2.parse;
  10969. exports.utcFormat = locale$2.utcFormat;
  10970. exports.utcParse = locale$2.utcParse;
  10971. return locale$2;
  10972. }
  10973. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  10974. function formatIsoNative(date) {
  10975. return date.toISOString();
  10976. }
  10977. var formatIso = Date.prototype.toISOString
  10978. ? formatIsoNative
  10979. : exports.utcFormat(isoSpecifier);
  10980. function parseIsoNative(string) {
  10981. var date = new Date(string);
  10982. return isNaN(date) ? null : date;
  10983. }
  10984. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  10985. ? parseIsoNative
  10986. : exports.utcParse(isoSpecifier);
  10987. var durationSecond = 1000;
  10988. var durationMinute = durationSecond * 60;
  10989. var durationHour = durationMinute * 60;
  10990. var durationDay = durationHour * 24;
  10991. var durationWeek = durationDay * 7;
  10992. var durationMonth = durationDay * 30;
  10993. var durationYear = durationDay * 365;
  10994. function date$1(t) {
  10995. return new Date(t);
  10996. }
  10997. function number$2(t) {
  10998. return t instanceof Date ? +t : +new Date(+t);
  10999. }
  11000. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  11001. var scale = continuous(deinterpolateLinear, reinterpolate),
  11002. invert = scale.invert,
  11003. domain = scale.domain;
  11004. var formatMillisecond = format(".%L"),
  11005. formatSecond = format(":%S"),
  11006. formatMinute = format("%I:%M"),
  11007. formatHour = format("%I %p"),
  11008. formatDay = format("%a %d"),
  11009. formatWeek = format("%b %d"),
  11010. formatMonth = format("%B"),
  11011. formatYear = format("%Y");
  11012. var tickIntervals = [
  11013. [second$$1, 1, durationSecond],
  11014. [second$$1, 5, 5 * durationSecond],
  11015. [second$$1, 15, 15 * durationSecond],
  11016. [second$$1, 30, 30 * durationSecond],
  11017. [minute$$1, 1, durationMinute],
  11018. [minute$$1, 5, 5 * durationMinute],
  11019. [minute$$1, 15, 15 * durationMinute],
  11020. [minute$$1, 30, 30 * durationMinute],
  11021. [ hour$$1, 1, durationHour ],
  11022. [ hour$$1, 3, 3 * durationHour ],
  11023. [ hour$$1, 6, 6 * durationHour ],
  11024. [ hour$$1, 12, 12 * durationHour ],
  11025. [ day$$1, 1, durationDay ],
  11026. [ day$$1, 2, 2 * durationDay ],
  11027. [ week, 1, durationWeek ],
  11028. [ month$$1, 1, durationMonth ],
  11029. [ month$$1, 3, 3 * durationMonth ],
  11030. [ year$$1, 1, durationYear ]
  11031. ];
  11032. function tickFormat(date) {
  11033. return (second$$1(date) < date ? formatMillisecond
  11034. : minute$$1(date) < date ? formatSecond
  11035. : hour$$1(date) < date ? formatMinute
  11036. : day$$1(date) < date ? formatHour
  11037. : month$$1(date) < date ? (week(date) < date ? formatDay : formatWeek)
  11038. : year$$1(date) < date ? formatMonth
  11039. : formatYear)(date);
  11040. }
  11041. function tickInterval(interval, start, stop, step) {
  11042. if (interval == null) interval = 10;
  11043. // If a desired tick count is specified, pick a reasonable tick interval
  11044. // based on the extent of the domain and a rough estimate of tick size.
  11045. // Otherwise, assume interval is already a time interval and use it.
  11046. if (typeof interval === "number") {
  11047. var target = Math.abs(stop - start) / interval,
  11048. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11049. if (i === tickIntervals.length) {
  11050. step = tickStep(start / durationYear, stop / durationYear, interval);
  11051. interval = year$$1;
  11052. } else if (i) {
  11053. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11054. step = i[1];
  11055. interval = i[0];
  11056. } else {
  11057. step = tickStep(start, stop, interval);
  11058. interval = millisecond$$1;
  11059. }
  11060. }
  11061. return step == null ? interval : interval.every(step);
  11062. }
  11063. scale.invert = function(y) {
  11064. return new Date(invert(y));
  11065. };
  11066. scale.domain = function(_) {
  11067. return arguments.length ? domain(map$3.call(_, number$2)) : domain().map(date$1);
  11068. };
  11069. scale.ticks = function(interval, step) {
  11070. var d = domain(),
  11071. t0 = d[0],
  11072. t1 = d[d.length - 1],
  11073. r = t1 < t0,
  11074. t;
  11075. if (r) t = t0, t0 = t1, t1 = t;
  11076. t = tickInterval(interval, t0, t1, step);
  11077. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11078. return r ? t.reverse() : t;
  11079. };
  11080. scale.tickFormat = function(count, specifier) {
  11081. return specifier == null ? tickFormat : format(specifier);
  11082. };
  11083. scale.nice = function(interval, step) {
  11084. var d = domain();
  11085. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11086. ? domain(nice(d, interval))
  11087. : scale;
  11088. };
  11089. scale.copy = function() {
  11090. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  11091. };
  11092. return scale;
  11093. }
  11094. var time = function() {
  11095. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  11096. };
  11097. var utcTime = function() {
  11098. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  11099. };
  11100. var colors = function(s) {
  11101. return s.match(/.{6}/g).map(function(x) {
  11102. return "#" + x;
  11103. });
  11104. };
  11105. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11106. var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
  11107. var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
  11108. var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
  11109. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  11110. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11111. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11112. var rainbow = cubehelix();
  11113. var rainbow$1 = function(t) {
  11114. if (t < 0 || t > 1) t -= Math.floor(t);
  11115. var ts = Math.abs(t - 0.5);
  11116. rainbow.h = 360 * t - 100;
  11117. rainbow.s = 1.5 - 1.5 * ts;
  11118. rainbow.l = 0.8 - 0.9 * ts;
  11119. return rainbow + "";
  11120. };
  11121. function ramp(range) {
  11122. var n = range.length;
  11123. return function(t) {
  11124. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  11125. };
  11126. }
  11127. var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  11128. var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  11129. var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  11130. var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  11131. function sequential(interpolator) {
  11132. var x0 = 0,
  11133. x1 = 1,
  11134. clamp = false;
  11135. function scale(x) {
  11136. var t = (x - x0) / (x1 - x0);
  11137. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11138. }
  11139. scale.domain = function(_) {
  11140. return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
  11141. };
  11142. scale.clamp = function(_) {
  11143. return arguments.length ? (clamp = !!_, scale) : clamp;
  11144. };
  11145. scale.interpolator = function(_) {
  11146. return arguments.length ? (interpolator = _, scale) : interpolator;
  11147. };
  11148. scale.copy = function() {
  11149. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  11150. };
  11151. return linearish(scale);
  11152. }
  11153. var constant$10 = function(x) {
  11154. return function constant() {
  11155. return x;
  11156. };
  11157. };
  11158. var abs$1 = Math.abs;
  11159. var atan2$1 = Math.atan2;
  11160. var cos$2 = Math.cos;
  11161. var max$2 = Math.max;
  11162. var min$1 = Math.min;
  11163. var sin$2 = Math.sin;
  11164. var sqrt$2 = Math.sqrt;
  11165. var epsilon$3 = 1e-12;
  11166. var pi$4 = Math.PI;
  11167. var halfPi$3 = pi$4 / 2;
  11168. var tau$4 = 2 * pi$4;
  11169. function acos$1(x) {
  11170. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11171. }
  11172. function asin$1(x) {
  11173. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  11174. }
  11175. function arcInnerRadius(d) {
  11176. return d.innerRadius;
  11177. }
  11178. function arcOuterRadius(d) {
  11179. return d.outerRadius;
  11180. }
  11181. function arcStartAngle(d) {
  11182. return d.startAngle;
  11183. }
  11184. function arcEndAngle(d) {
  11185. return d.endAngle;
  11186. }
  11187. function arcPadAngle(d) {
  11188. return d && d.padAngle; // Note: optional!
  11189. }
  11190. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11191. var x10 = x1 - x0, y10 = y1 - y0,
  11192. x32 = x3 - x2, y32 = y3 - y2,
  11193. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  11194. return [x0 + t * x10, y0 + t * y10];
  11195. }
  11196. // Compute perpendicular offset line of length rc.
  11197. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  11198. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  11199. var x01 = x0 - x1,
  11200. y01 = y0 - y1,
  11201. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  11202. ox = lo * y01,
  11203. oy = -lo * x01,
  11204. x11 = x0 + ox,
  11205. y11 = y0 + oy,
  11206. x10 = x1 + ox,
  11207. y10 = y1 + oy,
  11208. x00 = (x11 + x10) / 2,
  11209. y00 = (y11 + y10) / 2,
  11210. dx = x10 - x11,
  11211. dy = y10 - y11,
  11212. d2 = dx * dx + dy * dy,
  11213. r = r1 - rc,
  11214. D = x11 * y10 - x10 * y11,
  11215. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  11216. cx0 = (D * dy - dx * d) / d2,
  11217. cy0 = (-D * dx - dy * d) / d2,
  11218. cx1 = (D * dy + dx * d) / d2,
  11219. cy1 = (-D * dx + dy * d) / d2,
  11220. dx0 = cx0 - x00,
  11221. dy0 = cy0 - y00,
  11222. dx1 = cx1 - x00,
  11223. dy1 = cy1 - y00;
  11224. // Pick the closer of the two intersection points.
  11225. // TODO Is there a faster way to determine which intersection to use?
  11226. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  11227. return {
  11228. cx: cx0,
  11229. cy: cy0,
  11230. x01: -ox,
  11231. y01: -oy,
  11232. x11: cx0 * (r1 / r - 1),
  11233. y11: cy0 * (r1 / r - 1)
  11234. };
  11235. }
  11236. var arc = function() {
  11237. var innerRadius = arcInnerRadius,
  11238. outerRadius = arcOuterRadius,
  11239. cornerRadius = constant$10(0),
  11240. padRadius = null,
  11241. startAngle = arcStartAngle,
  11242. endAngle = arcEndAngle,
  11243. padAngle = arcPadAngle,
  11244. context = null;
  11245. function arc() {
  11246. var buffer,
  11247. r,
  11248. r0 = +innerRadius.apply(this, arguments),
  11249. r1 = +outerRadius.apply(this, arguments),
  11250. a0 = startAngle.apply(this, arguments) - halfPi$3,
  11251. a1 = endAngle.apply(this, arguments) - halfPi$3,
  11252. da = abs$1(a1 - a0),
  11253. cw = a1 > a0;
  11254. if (!context) context = buffer = path();
  11255. // Ensure that the outer radius is always larger than the inner radius.
  11256. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  11257. // Is it a point?
  11258. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  11259. // Or is it a circle or annulus?
  11260. else if (da > tau$4 - epsilon$3) {
  11261. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  11262. context.arc(0, 0, r1, a0, a1, !cw);
  11263. if (r0 > epsilon$3) {
  11264. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  11265. context.arc(0, 0, r0, a1, a0, cw);
  11266. }
  11267. }
  11268. // Or is it a circular or annular sector?
  11269. else {
  11270. var a01 = a0,
  11271. a11 = a1,
  11272. a00 = a0,
  11273. a10 = a1,
  11274. da0 = da,
  11275. da1 = da,
  11276. ap = padAngle.apply(this, arguments) / 2,
  11277. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  11278. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  11279. rc0 = rc,
  11280. rc1 = rc,
  11281. t0,
  11282. t1;
  11283. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  11284. if (rp > epsilon$3) {
  11285. var p0 = asin$1(rp / r0 * sin$2(ap)),
  11286. p1 = asin$1(rp / r1 * sin$2(ap));
  11287. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  11288. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  11289. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  11290. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  11291. }
  11292. var x01 = r1 * cos$2(a01),
  11293. y01 = r1 * sin$2(a01),
  11294. x10 = r0 * cos$2(a10),
  11295. y10 = r0 * sin$2(a10);
  11296. // Apply rounded corners?
  11297. if (rc > epsilon$3) {
  11298. var x11 = r1 * cos$2(a11),
  11299. y11 = r1 * sin$2(a11),
  11300. x00 = r0 * cos$2(a00),
  11301. y00 = r0 * sin$2(a00);
  11302. // Restrict the corner radius according to the sector angle.
  11303. if (da < pi$4) {
  11304. var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  11305. ax = x01 - oc[0],
  11306. ay = y01 - oc[1],
  11307. bx = x11 - oc[0],
  11308. by = y11 - oc[1],
  11309. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  11310. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  11311. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  11312. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  11313. }
  11314. }
  11315. // Is the sector collapsed to a line?
  11316. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  11317. // Does the sector’s outer ring have rounded corners?
  11318. else if (rc1 > epsilon$3) {
  11319. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  11320. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  11321. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  11322. // Have the corners merged?
  11323. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  11324. // Otherwise, draw the two corners and the ring.
  11325. else {
  11326. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  11327. 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);
  11328. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  11329. }
  11330. }
  11331. // Or is the outer ring just a circular arc?
  11332. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  11333. // Is there no inner ring, and it’s a circular sector?
  11334. // Or perhaps it’s an annular sector collapsed due to padding?
  11335. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  11336. // Does the sector’s inner ring (or point) have rounded corners?
  11337. else if (rc0 > epsilon$3) {
  11338. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  11339. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  11340. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  11341. // Have the corners merged?
  11342. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  11343. // Otherwise, draw the two corners and the ring.
  11344. else {
  11345. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  11346. 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);
  11347. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  11348. }
  11349. }
  11350. // Or is the inner ring just a circular arc?
  11351. else context.arc(0, 0, r0, a10, a00, cw);
  11352. }
  11353. context.closePath();
  11354. if (buffer) return context = null, buffer + "" || null;
  11355. }
  11356. arc.centroid = function() {
  11357. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  11358. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  11359. return [cos$2(a) * r, sin$2(a) * r];
  11360. };
  11361. arc.innerRadius = function(_) {
  11362. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : innerRadius;
  11363. };
  11364. arc.outerRadius = function(_) {
  11365. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : outerRadius;
  11366. };
  11367. arc.cornerRadius = function(_) {
  11368. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : cornerRadius;
  11369. };
  11370. arc.padRadius = function(_) {
  11371. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), arc) : padRadius;
  11372. };
  11373. arc.startAngle = function(_) {
  11374. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : startAngle;
  11375. };
  11376. arc.endAngle = function(_) {
  11377. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : endAngle;
  11378. };
  11379. arc.padAngle = function(_) {
  11380. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : padAngle;
  11381. };
  11382. arc.context = function(_) {
  11383. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  11384. };
  11385. return arc;
  11386. };
  11387. function Linear(context) {
  11388. this._context = context;
  11389. }
  11390. Linear.prototype = {
  11391. areaStart: function() {
  11392. this._line = 0;
  11393. },
  11394. areaEnd: function() {
  11395. this._line = NaN;
  11396. },
  11397. lineStart: function() {
  11398. this._point = 0;
  11399. },
  11400. lineEnd: function() {
  11401. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  11402. this._line = 1 - this._line;
  11403. },
  11404. point: function(x, y) {
  11405. x = +x, y = +y;
  11406. switch (this._point) {
  11407. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  11408. case 1: this._point = 2; // proceed
  11409. default: this._context.lineTo(x, y); break;
  11410. }
  11411. }
  11412. };
  11413. var curveLinear = function(context) {
  11414. return new Linear(context);
  11415. };
  11416. function x$3(p) {
  11417. return p[0];
  11418. }
  11419. function y$3(p) {
  11420. return p[1];
  11421. }
  11422. var line = function() {
  11423. var x$$1 = x$3,
  11424. y$$1 = y$3,
  11425. defined = constant$10(true),
  11426. context = null,
  11427. curve = curveLinear,
  11428. output = null;
  11429. function line(data) {
  11430. var i,
  11431. n = data.length,
  11432. d,
  11433. defined0 = false,
  11434. buffer;
  11435. if (context == null) output = curve(buffer = path());
  11436. for (i = 0; i <= n; ++i) {
  11437. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  11438. if (defined0 = !defined0) output.lineStart();
  11439. else output.lineEnd();
  11440. }
  11441. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  11442. }
  11443. if (buffer) return output = null, buffer + "" || null;
  11444. }
  11445. line.x = function(_) {
  11446. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : x$$1;
  11447. };
  11448. line.y = function(_) {
  11449. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : y$$1;
  11450. };
  11451. line.defined = function(_) {
  11452. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), line) : defined;
  11453. };
  11454. line.curve = function(_) {
  11455. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  11456. };
  11457. line.context = function(_) {
  11458. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  11459. };
  11460. return line;
  11461. };
  11462. var area$2 = function() {
  11463. var x0 = x$3,
  11464. x1 = null,
  11465. y0 = constant$10(0),
  11466. y1 = y$3,
  11467. defined = constant$10(true),
  11468. context = null,
  11469. curve = curveLinear,
  11470. output = null;
  11471. function area(data) {
  11472. var i,
  11473. j,
  11474. k,
  11475. n = data.length,
  11476. d,
  11477. defined0 = false,
  11478. buffer,
  11479. x0z = new Array(n),
  11480. y0z = new Array(n);
  11481. if (context == null) output = curve(buffer = path());
  11482. for (i = 0; i <= n; ++i) {
  11483. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  11484. if (defined0 = !defined0) {
  11485. j = i;
  11486. output.areaStart();
  11487. output.lineStart();
  11488. } else {
  11489. output.lineEnd();
  11490. output.lineStart();
  11491. for (k = i - 1; k >= j; --k) {
  11492. output.point(x0z[k], y0z[k]);
  11493. }
  11494. output.lineEnd();
  11495. output.areaEnd();
  11496. }
  11497. }
  11498. if (defined0) {
  11499. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  11500. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  11501. }
  11502. }
  11503. if (buffer) return output = null, buffer + "" || null;
  11504. }
  11505. function arealine() {
  11506. return line().defined(defined).curve(curve).context(context);
  11507. }
  11508. area.x = function(_) {
  11509. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), x1 = null, area) : x0;
  11510. };
  11511. area.x0 = function(_) {
  11512. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), area) : x0;
  11513. };
  11514. area.x1 = function(_) {
  11515. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : x1;
  11516. };
  11517. area.y = function(_) {
  11518. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), y1 = null, area) : y0;
  11519. };
  11520. area.y0 = function(_) {
  11521. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), area) : y0;
  11522. };
  11523. area.y1 = function(_) {
  11524. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : y1;
  11525. };
  11526. area.lineX0 =
  11527. area.lineY0 = function() {
  11528. return arealine().x(x0).y(y0);
  11529. };
  11530. area.lineY1 = function() {
  11531. return arealine().x(x0).y(y1);
  11532. };
  11533. area.lineX1 = function() {
  11534. return arealine().x(x1).y(y0);
  11535. };
  11536. area.defined = function(_) {
  11537. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), area) : defined;
  11538. };
  11539. area.curve = function(_) {
  11540. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  11541. };
  11542. area.context = function(_) {
  11543. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  11544. };
  11545. return area;
  11546. };
  11547. var descending$1 = function(a, b) {
  11548. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  11549. };
  11550. var identity$7 = function(d) {
  11551. return d;
  11552. };
  11553. var pie = function() {
  11554. var value = identity$7,
  11555. sortValues = descending$1,
  11556. sort = null,
  11557. startAngle = constant$10(0),
  11558. endAngle = constant$10(tau$4),
  11559. padAngle = constant$10(0);
  11560. function pie(data) {
  11561. var i,
  11562. n = data.length,
  11563. j,
  11564. k,
  11565. sum = 0,
  11566. index = new Array(n),
  11567. arcs = new Array(n),
  11568. a0 = +startAngle.apply(this, arguments),
  11569. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  11570. a1,
  11571. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  11572. pa = p * (da < 0 ? -1 : 1),
  11573. v;
  11574. for (i = 0; i < n; ++i) {
  11575. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  11576. sum += v;
  11577. }
  11578. }
  11579. // Optionally sort the arcs by previously-computed values or by data.
  11580. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  11581. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  11582. // Compute the arcs! They are stored in the original data's order.
  11583. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  11584. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  11585. data: data[j],
  11586. index: i,
  11587. value: v,
  11588. startAngle: a0,
  11589. endAngle: a1,
  11590. padAngle: p
  11591. };
  11592. }
  11593. return arcs;
  11594. }
  11595. pie.value = function(_) {
  11596. return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), pie) : value;
  11597. };
  11598. pie.sortValues = function(_) {
  11599. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  11600. };
  11601. pie.sort = function(_) {
  11602. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  11603. };
  11604. pie.startAngle = function(_) {
  11605. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : startAngle;
  11606. };
  11607. pie.endAngle = function(_) {
  11608. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : endAngle;
  11609. };
  11610. pie.padAngle = function(_) {
  11611. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : padAngle;
  11612. };
  11613. return pie;
  11614. };
  11615. var curveRadialLinear = curveRadial(curveLinear);
  11616. function Radial(curve) {
  11617. this._curve = curve;
  11618. }
  11619. Radial.prototype = {
  11620. areaStart: function() {
  11621. this._curve.areaStart();
  11622. },
  11623. areaEnd: function() {
  11624. this._curve.areaEnd();
  11625. },
  11626. lineStart: function() {
  11627. this._curve.lineStart();
  11628. },
  11629. lineEnd: function() {
  11630. this._curve.lineEnd();
  11631. },
  11632. point: function(a, r) {
  11633. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  11634. }
  11635. };
  11636. function curveRadial(curve) {
  11637. function radial(context) {
  11638. return new Radial(curve(context));
  11639. }
  11640. radial._curve = curve;
  11641. return radial;
  11642. }
  11643. function radialLine(l) {
  11644. var c = l.curve;
  11645. l.angle = l.x, delete l.x;
  11646. l.radius = l.y, delete l.y;
  11647. l.curve = function(_) {
  11648. return arguments.length ? c(curveRadial(_)) : c()._curve;
  11649. };
  11650. return l;
  11651. }
  11652. var radialLine$1 = function() {
  11653. return radialLine(line().curve(curveRadialLinear));
  11654. };
  11655. var radialArea = function() {
  11656. var a = area$2().curve(curveRadialLinear),
  11657. c = a.curve,
  11658. x0 = a.lineX0,
  11659. x1 = a.lineX1,
  11660. y0 = a.lineY0,
  11661. y1 = a.lineY1;
  11662. a.angle = a.x, delete a.x;
  11663. a.startAngle = a.x0, delete a.x0;
  11664. a.endAngle = a.x1, delete a.x1;
  11665. a.radius = a.y, delete a.y;
  11666. a.innerRadius = a.y0, delete a.y0;
  11667. a.outerRadius = a.y1, delete a.y1;
  11668. a.lineStartAngle = function() { return radialLine(x0()); }, delete a.lineX0;
  11669. a.lineEndAngle = function() { return radialLine(x1()); }, delete a.lineX1;
  11670. a.lineInnerRadius = function() { return radialLine(y0()); }, delete a.lineY0;
  11671. a.lineOuterRadius = function() { return radialLine(y1()); }, delete a.lineY1;
  11672. a.curve = function(_) {
  11673. return arguments.length ? c(curveRadial(_)) : c()._curve;
  11674. };
  11675. return a;
  11676. };
  11677. var slice$5 = Array.prototype.slice;
  11678. var radialPoint = function(x, y) {
  11679. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  11680. };
  11681. function linkSource(d) {
  11682. return d.source;
  11683. }
  11684. function linkTarget(d) {
  11685. return d.target;
  11686. }
  11687. function link$2(curve) {
  11688. var source = linkSource,
  11689. target = linkTarget,
  11690. x$$1 = x$3,
  11691. y$$1 = y$3,
  11692. context = null;
  11693. function link() {
  11694. var buffer, argv = slice$5.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  11695. if (!context) context = buffer = path();
  11696. 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));
  11697. if (buffer) return context = null, buffer + "" || null;
  11698. }
  11699. link.source = function(_) {
  11700. return arguments.length ? (source = _, link) : source;
  11701. };
  11702. link.target = function(_) {
  11703. return arguments.length ? (target = _, link) : target;
  11704. };
  11705. link.x = function(_) {
  11706. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : x$$1;
  11707. };
  11708. link.y = function(_) {
  11709. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : y$$1;
  11710. };
  11711. link.context = function(_) {
  11712. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  11713. };
  11714. return link;
  11715. }
  11716. function curveHorizontal(context, x0, y0, x1, y1) {
  11717. context.moveTo(x0, y0);
  11718. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  11719. }
  11720. function curveVertical(context, x0, y0, x1, y1) {
  11721. context.moveTo(x0, y0);
  11722. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  11723. }
  11724. function curveRadial$1(context, x0, y0, x1, y1) {
  11725. var p0 = radialPoint(x0, y0),
  11726. p1 = radialPoint(x0, y0 = (y0 + y1) / 2),
  11727. p2 = radialPoint(x1, y0),
  11728. p3 = radialPoint(x1, y1);
  11729. context.moveTo(p0[0], p0[1]);
  11730. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  11731. }
  11732. function linkHorizontal() {
  11733. return link$2(curveHorizontal);
  11734. }
  11735. function linkVertical() {
  11736. return link$2(curveVertical);
  11737. }
  11738. function linkRadial() {
  11739. var l = link$2(curveRadial$1);
  11740. l.angle = l.x, delete l.x;
  11741. l.radius = l.y, delete l.y;
  11742. return l;
  11743. }
  11744. var circle$2 = {
  11745. draw: function(context, size) {
  11746. var r = Math.sqrt(size / pi$4);
  11747. context.moveTo(r, 0);
  11748. context.arc(0, 0, r, 0, tau$4);
  11749. }
  11750. };
  11751. var cross$2 = {
  11752. draw: function(context, size) {
  11753. var r = Math.sqrt(size / 5) / 2;
  11754. context.moveTo(-3 * r, -r);
  11755. context.lineTo(-r, -r);
  11756. context.lineTo(-r, -3 * r);
  11757. context.lineTo(r, -3 * r);
  11758. context.lineTo(r, -r);
  11759. context.lineTo(3 * r, -r);
  11760. context.lineTo(3 * r, r);
  11761. context.lineTo(r, r);
  11762. context.lineTo(r, 3 * r);
  11763. context.lineTo(-r, 3 * r);
  11764. context.lineTo(-r, r);
  11765. context.lineTo(-3 * r, r);
  11766. context.closePath();
  11767. }
  11768. };
  11769. var tan30 = Math.sqrt(1 / 3);
  11770. var tan30_2 = tan30 * 2;
  11771. var diamond = {
  11772. draw: function(context, size) {
  11773. var y = Math.sqrt(size / tan30_2),
  11774. x = y * tan30;
  11775. context.moveTo(0, -y);
  11776. context.lineTo(x, 0);
  11777. context.lineTo(0, y);
  11778. context.lineTo(-x, 0);
  11779. context.closePath();
  11780. }
  11781. };
  11782. var ka = 0.89081309152928522810;
  11783. var kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10);
  11784. var kx = Math.sin(tau$4 / 10) * kr;
  11785. var ky = -Math.cos(tau$4 / 10) * kr;
  11786. var star = {
  11787. draw: function(context, size) {
  11788. var r = Math.sqrt(size * ka),
  11789. x = kx * r,
  11790. y = ky * r;
  11791. context.moveTo(0, -r);
  11792. context.lineTo(x, y);
  11793. for (var i = 1; i < 5; ++i) {
  11794. var a = tau$4 * i / 5,
  11795. c = Math.cos(a),
  11796. s = Math.sin(a);
  11797. context.lineTo(s * r, -c * r);
  11798. context.lineTo(c * x - s * y, s * x + c * y);
  11799. }
  11800. context.closePath();
  11801. }
  11802. };
  11803. var square = {
  11804. draw: function(context, size) {
  11805. var w = Math.sqrt(size),
  11806. x = -w / 2;
  11807. context.rect(x, x, w, w);
  11808. }
  11809. };
  11810. var sqrt3 = Math.sqrt(3);
  11811. var triangle = {
  11812. draw: function(context, size) {
  11813. var y = -Math.sqrt(size / (sqrt3 * 3));
  11814. context.moveTo(0, y * 2);
  11815. context.lineTo(-sqrt3 * y, -y);
  11816. context.lineTo(sqrt3 * y, -y);
  11817. context.closePath();
  11818. }
  11819. };
  11820. var c = -0.5;
  11821. var s = Math.sqrt(3) / 2;
  11822. var k = 1 / Math.sqrt(12);
  11823. var a = (k / 2 + 1) * 3;
  11824. var wye = {
  11825. draw: function(context, size) {
  11826. var r = Math.sqrt(size / a),
  11827. x0 = r / 2,
  11828. y0 = r * k,
  11829. x1 = x0,
  11830. y1 = r * k + r,
  11831. x2 = -x1,
  11832. y2 = y1;
  11833. context.moveTo(x0, y0);
  11834. context.lineTo(x1, y1);
  11835. context.lineTo(x2, y2);
  11836. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  11837. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  11838. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  11839. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  11840. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  11841. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  11842. context.closePath();
  11843. }
  11844. };
  11845. var symbols = [
  11846. circle$2,
  11847. cross$2,
  11848. diamond,
  11849. square,
  11850. star,
  11851. triangle,
  11852. wye
  11853. ];
  11854. var symbol = function() {
  11855. var type = constant$10(circle$2),
  11856. size = constant$10(64),
  11857. context = null;
  11858. function symbol() {
  11859. var buffer;
  11860. if (!context) context = buffer = path();
  11861. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  11862. if (buffer) return context = null, buffer + "" || null;
  11863. }
  11864. symbol.type = function(_) {
  11865. return arguments.length ? (type = typeof _ === "function" ? _ : constant$10(_), symbol) : type;
  11866. };
  11867. symbol.size = function(_) {
  11868. return arguments.length ? (size = typeof _ === "function" ? _ : constant$10(+_), symbol) : size;
  11869. };
  11870. symbol.context = function(_) {
  11871. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  11872. };
  11873. return symbol;
  11874. };
  11875. var noop$2 = function() {};
  11876. function point$2(that, x, y) {
  11877. that._context.bezierCurveTo(
  11878. (2 * that._x0 + that._x1) / 3,
  11879. (2 * that._y0 + that._y1) / 3,
  11880. (that._x0 + 2 * that._x1) / 3,
  11881. (that._y0 + 2 * that._y1) / 3,
  11882. (that._x0 + 4 * that._x1 + x) / 6,
  11883. (that._y0 + 4 * that._y1 + y) / 6
  11884. );
  11885. }
  11886. function Basis(context) {
  11887. this._context = context;
  11888. }
  11889. Basis.prototype = {
  11890. areaStart: function() {
  11891. this._line = 0;
  11892. },
  11893. areaEnd: function() {
  11894. this._line = NaN;
  11895. },
  11896. lineStart: function() {
  11897. this._x0 = this._x1 =
  11898. this._y0 = this._y1 = NaN;
  11899. this._point = 0;
  11900. },
  11901. lineEnd: function() {
  11902. switch (this._point) {
  11903. case 3: point$2(this, this._x1, this._y1); // proceed
  11904. case 2: this._context.lineTo(this._x1, this._y1); break;
  11905. }
  11906. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  11907. this._line = 1 - this._line;
  11908. },
  11909. point: function(x, y) {
  11910. x = +x, y = +y;
  11911. switch (this._point) {
  11912. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  11913. case 1: this._point = 2; break;
  11914. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  11915. default: point$2(this, x, y); break;
  11916. }
  11917. this._x0 = this._x1, this._x1 = x;
  11918. this._y0 = this._y1, this._y1 = y;
  11919. }
  11920. };
  11921. var basis$2 = function(context) {
  11922. return new Basis(context);
  11923. };
  11924. function BasisClosed(context) {
  11925. this._context = context;
  11926. }
  11927. BasisClosed.prototype = {
  11928. areaStart: noop$2,
  11929. areaEnd: noop$2,
  11930. lineStart: function() {
  11931. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  11932. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  11933. this._point = 0;
  11934. },
  11935. lineEnd: function() {
  11936. switch (this._point) {
  11937. case 1: {
  11938. this._context.moveTo(this._x2, this._y2);
  11939. this._context.closePath();
  11940. break;
  11941. }
  11942. case 2: {
  11943. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  11944. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  11945. this._context.closePath();
  11946. break;
  11947. }
  11948. case 3: {
  11949. this.point(this._x2, this._y2);
  11950. this.point(this._x3, this._y3);
  11951. this.point(this._x4, this._y4);
  11952. break;
  11953. }
  11954. }
  11955. },
  11956. point: function(x, y) {
  11957. x = +x, y = +y;
  11958. switch (this._point) {
  11959. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  11960. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  11961. 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;
  11962. default: point$2(this, x, y); break;
  11963. }
  11964. this._x0 = this._x1, this._x1 = x;
  11965. this._y0 = this._y1, this._y1 = y;
  11966. }
  11967. };
  11968. var basisClosed$1 = function(context) {
  11969. return new BasisClosed(context);
  11970. };
  11971. function BasisOpen(context) {
  11972. this._context = context;
  11973. }
  11974. BasisOpen.prototype = {
  11975. areaStart: function() {
  11976. this._line = 0;
  11977. },
  11978. areaEnd: function() {
  11979. this._line = NaN;
  11980. },
  11981. lineStart: function() {
  11982. this._x0 = this._x1 =
  11983. this._y0 = this._y1 = NaN;
  11984. this._point = 0;
  11985. },
  11986. lineEnd: function() {
  11987. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  11988. this._line = 1 - this._line;
  11989. },
  11990. point: function(x, y) {
  11991. x = +x, y = +y;
  11992. switch (this._point) {
  11993. case 0: this._point = 1; break;
  11994. case 1: this._point = 2; break;
  11995. 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;
  11996. case 3: this._point = 4; // proceed
  11997. default: point$2(this, x, y); break;
  11998. }
  11999. this._x0 = this._x1, this._x1 = x;
  12000. this._y0 = this._y1, this._y1 = y;
  12001. }
  12002. };
  12003. var basisOpen = function(context) {
  12004. return new BasisOpen(context);
  12005. };
  12006. function Bundle(context, beta) {
  12007. this._basis = new Basis(context);
  12008. this._beta = beta;
  12009. }
  12010. Bundle.prototype = {
  12011. lineStart: function() {
  12012. this._x = [];
  12013. this._y = [];
  12014. this._basis.lineStart();
  12015. },
  12016. lineEnd: function() {
  12017. var x = this._x,
  12018. y = this._y,
  12019. j = x.length - 1;
  12020. if (j > 0) {
  12021. var x0 = x[0],
  12022. y0 = y[0],
  12023. dx = x[j] - x0,
  12024. dy = y[j] - y0,
  12025. i = -1,
  12026. t;
  12027. while (++i <= j) {
  12028. t = i / j;
  12029. this._basis.point(
  12030. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  12031. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  12032. );
  12033. }
  12034. }
  12035. this._x = this._y = null;
  12036. this._basis.lineEnd();
  12037. },
  12038. point: function(x, y) {
  12039. this._x.push(+x);
  12040. this._y.push(+y);
  12041. }
  12042. };
  12043. var bundle = ((function custom(beta) {
  12044. function bundle(context) {
  12045. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  12046. }
  12047. bundle.beta = function(beta) {
  12048. return custom(+beta);
  12049. };
  12050. return bundle;
  12051. }))(0.85);
  12052. function point$3(that, x, y) {
  12053. that._context.bezierCurveTo(
  12054. that._x1 + that._k * (that._x2 - that._x0),
  12055. that._y1 + that._k * (that._y2 - that._y0),
  12056. that._x2 + that._k * (that._x1 - x),
  12057. that._y2 + that._k * (that._y1 - y),
  12058. that._x2,
  12059. that._y2
  12060. );
  12061. }
  12062. function Cardinal(context, tension) {
  12063. this._context = context;
  12064. this._k = (1 - tension) / 6;
  12065. }
  12066. Cardinal.prototype = {
  12067. areaStart: function() {
  12068. this._line = 0;
  12069. },
  12070. areaEnd: function() {
  12071. this._line = NaN;
  12072. },
  12073. lineStart: function() {
  12074. this._x0 = this._x1 = this._x2 =
  12075. this._y0 = this._y1 = this._y2 = NaN;
  12076. this._point = 0;
  12077. },
  12078. lineEnd: function() {
  12079. switch (this._point) {
  12080. case 2: this._context.lineTo(this._x2, this._y2); break;
  12081. case 3: point$3(this, this._x1, this._y1); break;
  12082. }
  12083. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12084. this._line = 1 - this._line;
  12085. },
  12086. point: function(x, y) {
  12087. x = +x, y = +y;
  12088. switch (this._point) {
  12089. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12090. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  12091. case 2: this._point = 3; // proceed
  12092. default: point$3(this, x, y); break;
  12093. }
  12094. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12095. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12096. }
  12097. };
  12098. var cardinal = ((function custom(tension) {
  12099. function cardinal(context) {
  12100. return new Cardinal(context, tension);
  12101. }
  12102. cardinal.tension = function(tension) {
  12103. return custom(+tension);
  12104. };
  12105. return cardinal;
  12106. }))(0);
  12107. function CardinalClosed(context, tension) {
  12108. this._context = context;
  12109. this._k = (1 - tension) / 6;
  12110. }
  12111. CardinalClosed.prototype = {
  12112. areaStart: noop$2,
  12113. areaEnd: noop$2,
  12114. lineStart: function() {
  12115. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12116. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12117. this._point = 0;
  12118. },
  12119. lineEnd: function() {
  12120. switch (this._point) {
  12121. case 1: {
  12122. this._context.moveTo(this._x3, this._y3);
  12123. this._context.closePath();
  12124. break;
  12125. }
  12126. case 2: {
  12127. this._context.lineTo(this._x3, this._y3);
  12128. this._context.closePath();
  12129. break;
  12130. }
  12131. case 3: {
  12132. this.point(this._x3, this._y3);
  12133. this.point(this._x4, this._y4);
  12134. this.point(this._x5, this._y5);
  12135. break;
  12136. }
  12137. }
  12138. },
  12139. point: function(x, y) {
  12140. x = +x, y = +y;
  12141. switch (this._point) {
  12142. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12143. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12144. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12145. default: point$3(this, x, y); break;
  12146. }
  12147. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12148. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12149. }
  12150. };
  12151. var cardinalClosed = ((function custom(tension) {
  12152. function cardinal(context) {
  12153. return new CardinalClosed(context, tension);
  12154. }
  12155. cardinal.tension = function(tension) {
  12156. return custom(+tension);
  12157. };
  12158. return cardinal;
  12159. }))(0);
  12160. function CardinalOpen(context, tension) {
  12161. this._context = context;
  12162. this._k = (1 - tension) / 6;
  12163. }
  12164. CardinalOpen.prototype = {
  12165. areaStart: function() {
  12166. this._line = 0;
  12167. },
  12168. areaEnd: function() {
  12169. this._line = NaN;
  12170. },
  12171. lineStart: function() {
  12172. this._x0 = this._x1 = this._x2 =
  12173. this._y0 = this._y1 = this._y2 = NaN;
  12174. this._point = 0;
  12175. },
  12176. lineEnd: function() {
  12177. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12178. this._line = 1 - this._line;
  12179. },
  12180. point: function(x, y) {
  12181. x = +x, y = +y;
  12182. switch (this._point) {
  12183. case 0: this._point = 1; break;
  12184. case 1: this._point = 2; break;
  12185. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12186. case 3: this._point = 4; // proceed
  12187. default: point$3(this, x, y); break;
  12188. }
  12189. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12190. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12191. }
  12192. };
  12193. var cardinalOpen = ((function custom(tension) {
  12194. function cardinal(context) {
  12195. return new CardinalOpen(context, tension);
  12196. }
  12197. cardinal.tension = function(tension) {
  12198. return custom(+tension);
  12199. };
  12200. return cardinal;
  12201. }))(0);
  12202. function point$4(that, x, y) {
  12203. var x1 = that._x1,
  12204. y1 = that._y1,
  12205. x2 = that._x2,
  12206. y2 = that._y2;
  12207. if (that._l01_a > epsilon$3) {
  12208. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  12209. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  12210. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  12211. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  12212. }
  12213. if (that._l23_a > epsilon$3) {
  12214. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  12215. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  12216. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  12217. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  12218. }
  12219. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  12220. }
  12221. function CatmullRom(context, alpha) {
  12222. this._context = context;
  12223. this._alpha = alpha;
  12224. }
  12225. CatmullRom.prototype = {
  12226. areaStart: function() {
  12227. this._line = 0;
  12228. },
  12229. areaEnd: function() {
  12230. this._line = NaN;
  12231. },
  12232. lineStart: function() {
  12233. this._x0 = this._x1 = this._x2 =
  12234. this._y0 = this._y1 = this._y2 = NaN;
  12235. this._l01_a = this._l12_a = this._l23_a =
  12236. this._l01_2a = this._l12_2a = this._l23_2a =
  12237. this._point = 0;
  12238. },
  12239. lineEnd: function() {
  12240. switch (this._point) {
  12241. case 2: this._context.lineTo(this._x2, this._y2); break;
  12242. case 3: this.point(this._x2, this._y2); break;
  12243. }
  12244. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12245. this._line = 1 - this._line;
  12246. },
  12247. point: function(x, y) {
  12248. x = +x, y = +y;
  12249. if (this._point) {
  12250. var x23 = this._x2 - x,
  12251. y23 = this._y2 - y;
  12252. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12253. }
  12254. switch (this._point) {
  12255. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12256. case 1: this._point = 2; break;
  12257. case 2: this._point = 3; // proceed
  12258. default: point$4(this, x, y); break;
  12259. }
  12260. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12261. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12262. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12263. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12264. }
  12265. };
  12266. var catmullRom = ((function custom(alpha) {
  12267. function catmullRom(context) {
  12268. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  12269. }
  12270. catmullRom.alpha = function(alpha) {
  12271. return custom(+alpha);
  12272. };
  12273. return catmullRom;
  12274. }))(0.5);
  12275. function CatmullRomClosed(context, alpha) {
  12276. this._context = context;
  12277. this._alpha = alpha;
  12278. }
  12279. CatmullRomClosed.prototype = {
  12280. areaStart: noop$2,
  12281. areaEnd: noop$2,
  12282. lineStart: function() {
  12283. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12284. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12285. this._l01_a = this._l12_a = this._l23_a =
  12286. this._l01_2a = this._l12_2a = this._l23_2a =
  12287. this._point = 0;
  12288. },
  12289. lineEnd: function() {
  12290. switch (this._point) {
  12291. case 1: {
  12292. this._context.moveTo(this._x3, this._y3);
  12293. this._context.closePath();
  12294. break;
  12295. }
  12296. case 2: {
  12297. this._context.lineTo(this._x3, this._y3);
  12298. this._context.closePath();
  12299. break;
  12300. }
  12301. case 3: {
  12302. this.point(this._x3, this._y3);
  12303. this.point(this._x4, this._y4);
  12304. this.point(this._x5, this._y5);
  12305. break;
  12306. }
  12307. }
  12308. },
  12309. point: function(x, y) {
  12310. x = +x, y = +y;
  12311. if (this._point) {
  12312. var x23 = this._x2 - x,
  12313. y23 = this._y2 - y;
  12314. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12315. }
  12316. switch (this._point) {
  12317. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12318. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12319. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12320. default: point$4(this, x, y); break;
  12321. }
  12322. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12323. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12324. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12325. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12326. }
  12327. };
  12328. var catmullRomClosed = ((function custom(alpha) {
  12329. function catmullRom(context) {
  12330. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  12331. }
  12332. catmullRom.alpha = function(alpha) {
  12333. return custom(+alpha);
  12334. };
  12335. return catmullRom;
  12336. }))(0.5);
  12337. function CatmullRomOpen(context, alpha) {
  12338. this._context = context;
  12339. this._alpha = alpha;
  12340. }
  12341. CatmullRomOpen.prototype = {
  12342. areaStart: function() {
  12343. this._line = 0;
  12344. },
  12345. areaEnd: function() {
  12346. this._line = NaN;
  12347. },
  12348. lineStart: function() {
  12349. this._x0 = this._x1 = this._x2 =
  12350. this._y0 = this._y1 = this._y2 = NaN;
  12351. this._l01_a = this._l12_a = this._l23_a =
  12352. this._l01_2a = this._l12_2a = this._l23_2a =
  12353. this._point = 0;
  12354. },
  12355. lineEnd: function() {
  12356. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12357. this._line = 1 - this._line;
  12358. },
  12359. point: function(x, y) {
  12360. x = +x, y = +y;
  12361. if (this._point) {
  12362. var x23 = this._x2 - x,
  12363. y23 = this._y2 - y;
  12364. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12365. }
  12366. switch (this._point) {
  12367. case 0: this._point = 1; break;
  12368. case 1: this._point = 2; break;
  12369. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12370. case 3: this._point = 4; // proceed
  12371. default: point$4(this, x, y); break;
  12372. }
  12373. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12374. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12375. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12376. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12377. }
  12378. };
  12379. var catmullRomOpen = ((function custom(alpha) {
  12380. function catmullRom(context) {
  12381. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  12382. }
  12383. catmullRom.alpha = function(alpha) {
  12384. return custom(+alpha);
  12385. };
  12386. return catmullRom;
  12387. }))(0.5);
  12388. function LinearClosed(context) {
  12389. this._context = context;
  12390. }
  12391. LinearClosed.prototype = {
  12392. areaStart: noop$2,
  12393. areaEnd: noop$2,
  12394. lineStart: function() {
  12395. this._point = 0;
  12396. },
  12397. lineEnd: function() {
  12398. if (this._point) this._context.closePath();
  12399. },
  12400. point: function(x, y) {
  12401. x = +x, y = +y;
  12402. if (this._point) this._context.lineTo(x, y);
  12403. else this._point = 1, this._context.moveTo(x, y);
  12404. }
  12405. };
  12406. var linearClosed = function(context) {
  12407. return new LinearClosed(context);
  12408. };
  12409. function sign$1(x) {
  12410. return x < 0 ? -1 : 1;
  12411. }
  12412. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  12413. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  12414. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  12415. // NOV(II), P. 443, 1990.
  12416. function slope3(that, x2, y2) {
  12417. var h0 = that._x1 - that._x0,
  12418. h1 = x2 - that._x1,
  12419. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  12420. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  12421. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  12422. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  12423. }
  12424. // Calculate a one-sided slope.
  12425. function slope2(that, t) {
  12426. var h = that._x1 - that._x0;
  12427. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  12428. }
  12429. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  12430. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  12431. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  12432. function point$5(that, t0, t1) {
  12433. var x0 = that._x0,
  12434. y0 = that._y0,
  12435. x1 = that._x1,
  12436. y1 = that._y1,
  12437. dx = (x1 - x0) / 3;
  12438. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  12439. }
  12440. function MonotoneX(context) {
  12441. this._context = context;
  12442. }
  12443. MonotoneX.prototype = {
  12444. areaStart: function() {
  12445. this._line = 0;
  12446. },
  12447. areaEnd: function() {
  12448. this._line = NaN;
  12449. },
  12450. lineStart: function() {
  12451. this._x0 = this._x1 =
  12452. this._y0 = this._y1 =
  12453. this._t0 = NaN;
  12454. this._point = 0;
  12455. },
  12456. lineEnd: function() {
  12457. switch (this._point) {
  12458. case 2: this._context.lineTo(this._x1, this._y1); break;
  12459. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  12460. }
  12461. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12462. this._line = 1 - this._line;
  12463. },
  12464. point: function(x, y) {
  12465. var t1 = NaN;
  12466. x = +x, y = +y;
  12467. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  12468. switch (this._point) {
  12469. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12470. case 1: this._point = 2; break;
  12471. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  12472. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  12473. }
  12474. this._x0 = this._x1, this._x1 = x;
  12475. this._y0 = this._y1, this._y1 = y;
  12476. this._t0 = t1;
  12477. }
  12478. };
  12479. function MonotoneY(context) {
  12480. this._context = new ReflectContext(context);
  12481. }
  12482. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  12483. MonotoneX.prototype.point.call(this, y, x);
  12484. };
  12485. function ReflectContext(context) {
  12486. this._context = context;
  12487. }
  12488. ReflectContext.prototype = {
  12489. moveTo: function(x, y) { this._context.moveTo(y, x); },
  12490. closePath: function() { this._context.closePath(); },
  12491. lineTo: function(x, y) { this._context.lineTo(y, x); },
  12492. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  12493. };
  12494. function monotoneX(context) {
  12495. return new MonotoneX(context);
  12496. }
  12497. function monotoneY(context) {
  12498. return new MonotoneY(context);
  12499. }
  12500. function Natural(context) {
  12501. this._context = context;
  12502. }
  12503. Natural.prototype = {
  12504. areaStart: function() {
  12505. this._line = 0;
  12506. },
  12507. areaEnd: function() {
  12508. this._line = NaN;
  12509. },
  12510. lineStart: function() {
  12511. this._x = [];
  12512. this._y = [];
  12513. },
  12514. lineEnd: function() {
  12515. var x = this._x,
  12516. y = this._y,
  12517. n = x.length;
  12518. if (n) {
  12519. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  12520. if (n === 2) {
  12521. this._context.lineTo(x[1], y[1]);
  12522. } else {
  12523. var px = controlPoints(x),
  12524. py = controlPoints(y);
  12525. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  12526. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  12527. }
  12528. }
  12529. }
  12530. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  12531. this._line = 1 - this._line;
  12532. this._x = this._y = null;
  12533. },
  12534. point: function(x, y) {
  12535. this._x.push(+x);
  12536. this._y.push(+y);
  12537. }
  12538. };
  12539. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  12540. function controlPoints(x) {
  12541. var i,
  12542. n = x.length - 1,
  12543. m,
  12544. a = new Array(n),
  12545. b = new Array(n),
  12546. r = new Array(n);
  12547. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  12548. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  12549. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  12550. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  12551. a[n - 1] = r[n - 1] / b[n - 1];
  12552. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  12553. b[n - 1] = (x[n] + a[n - 1]) / 2;
  12554. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  12555. return [a, b];
  12556. }
  12557. var natural = function(context) {
  12558. return new Natural(context);
  12559. };
  12560. function Step(context, t) {
  12561. this._context = context;
  12562. this._t = t;
  12563. }
  12564. Step.prototype = {
  12565. areaStart: function() {
  12566. this._line = 0;
  12567. },
  12568. areaEnd: function() {
  12569. this._line = NaN;
  12570. },
  12571. lineStart: function() {
  12572. this._x = this._y = NaN;
  12573. this._point = 0;
  12574. },
  12575. lineEnd: function() {
  12576. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  12577. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12578. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  12579. },
  12580. point: function(x, y) {
  12581. x = +x, y = +y;
  12582. switch (this._point) {
  12583. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12584. case 1: this._point = 2; // proceed
  12585. default: {
  12586. if (this._t <= 0) {
  12587. this._context.lineTo(this._x, y);
  12588. this._context.lineTo(x, y);
  12589. } else {
  12590. var x1 = this._x * (1 - this._t) + x * this._t;
  12591. this._context.lineTo(x1, this._y);
  12592. this._context.lineTo(x1, y);
  12593. }
  12594. break;
  12595. }
  12596. }
  12597. this._x = x, this._y = y;
  12598. }
  12599. };
  12600. var step = function(context) {
  12601. return new Step(context, 0.5);
  12602. };
  12603. function stepBefore(context) {
  12604. return new Step(context, 0);
  12605. }
  12606. function stepAfter(context) {
  12607. return new Step(context, 1);
  12608. }
  12609. var none$1 = function(series, order) {
  12610. if (!((n = series.length) > 1)) return;
  12611. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  12612. s0 = s1, s1 = series[order[i]];
  12613. for (j = 0; j < m; ++j) {
  12614. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  12615. }
  12616. }
  12617. };
  12618. var none$2 = function(series) {
  12619. var n = series.length, o = new Array(n);
  12620. while (--n >= 0) o[n] = n;
  12621. return o;
  12622. };
  12623. function stackValue(d, key) {
  12624. return d[key];
  12625. }
  12626. var stack = function() {
  12627. var keys = constant$10([]),
  12628. order = none$2,
  12629. offset = none$1,
  12630. value = stackValue;
  12631. function stack(data) {
  12632. var kz = keys.apply(this, arguments),
  12633. i,
  12634. m = data.length,
  12635. n = kz.length,
  12636. sz = new Array(n),
  12637. oz;
  12638. for (i = 0; i < n; ++i) {
  12639. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  12640. si[j] = sij = [0, +value(data[j], ki, j, data)];
  12641. sij.data = data[j];
  12642. }
  12643. si.key = ki;
  12644. }
  12645. for (i = 0, oz = order(sz); i < n; ++i) {
  12646. sz[oz[i]].index = i;
  12647. }
  12648. offset(sz, oz);
  12649. return sz;
  12650. }
  12651. stack.keys = function(_) {
  12652. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$10(slice$5.call(_)), stack) : keys;
  12653. };
  12654. stack.value = function(_) {
  12655. return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), stack) : value;
  12656. };
  12657. stack.order = function(_) {
  12658. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$10(slice$5.call(_)), stack) : order;
  12659. };
  12660. stack.offset = function(_) {
  12661. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  12662. };
  12663. return stack;
  12664. };
  12665. var expand = function(series, order) {
  12666. if (!((n = series.length) > 0)) return;
  12667. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  12668. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  12669. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  12670. }
  12671. none$1(series, order);
  12672. };
  12673. var diverging = function(series, order) {
  12674. if (!((n = series.length) > 1)) return;
  12675. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  12676. for (yp = yn = 0, i = 0; i < n; ++i) {
  12677. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  12678. d[0] = yp, d[1] = yp += dy;
  12679. } else if (dy < 0) {
  12680. d[1] = yn, d[0] = yn += dy;
  12681. } else {
  12682. d[0] = yp;
  12683. }
  12684. }
  12685. }
  12686. };
  12687. var silhouette = function(series, order) {
  12688. if (!((n = series.length) > 0)) return;
  12689. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  12690. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  12691. s0[j][1] += s0[j][0] = -y / 2;
  12692. }
  12693. none$1(series, order);
  12694. };
  12695. var wiggle = function(series, order) {
  12696. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  12697. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  12698. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  12699. var si = series[order[i]],
  12700. sij0 = si[j][1] || 0,
  12701. sij1 = si[j - 1][1] || 0,
  12702. s3 = (sij0 - sij1) / 2;
  12703. for (var k = 0; k < i; ++k) {
  12704. var sk = series[order[k]],
  12705. skj0 = sk[j][1] || 0,
  12706. skj1 = sk[j - 1][1] || 0;
  12707. s3 += skj0 - skj1;
  12708. }
  12709. s1 += sij0, s2 += s3 * sij0;
  12710. }
  12711. s0[j - 1][1] += s0[j - 1][0] = y;
  12712. if (s1) y -= s2 / s1;
  12713. }
  12714. s0[j - 1][1] += s0[j - 1][0] = y;
  12715. none$1(series, order);
  12716. };
  12717. var ascending$2 = function(series) {
  12718. var sums = series.map(sum$2);
  12719. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  12720. };
  12721. function sum$2(series) {
  12722. var s = 0, i = -1, n = series.length, v;
  12723. while (++i < n) if (v = +series[i][1]) s += v;
  12724. return s;
  12725. }
  12726. var descending$2 = function(series) {
  12727. return ascending$2(series).reverse();
  12728. };
  12729. var insideOut = function(series) {
  12730. var n = series.length,
  12731. i,
  12732. j,
  12733. sums = series.map(sum$2),
  12734. order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  12735. top = 0,
  12736. bottom = 0,
  12737. tops = [],
  12738. bottoms = [];
  12739. for (i = 0; i < n; ++i) {
  12740. j = order[i];
  12741. if (top < bottom) {
  12742. top += sums[j];
  12743. tops.push(j);
  12744. } else {
  12745. bottom += sums[j];
  12746. bottoms.push(j);
  12747. }
  12748. }
  12749. return bottoms.reverse().concat(tops);
  12750. };
  12751. var reverse = function(series) {
  12752. return none$2(series).reverse();
  12753. };
  12754. var constant$11 = function(x) {
  12755. return function() {
  12756. return x;
  12757. };
  12758. };
  12759. function x$4(d) {
  12760. return d[0];
  12761. }
  12762. function y$4(d) {
  12763. return d[1];
  12764. }
  12765. function RedBlackTree() {
  12766. this._ = null; // root node
  12767. }
  12768. function RedBlackNode(node) {
  12769. node.U = // parent node
  12770. node.C = // color - true for red, false for black
  12771. node.L = // left node
  12772. node.R = // right node
  12773. node.P = // previous node
  12774. node.N = null; // next node
  12775. }
  12776. RedBlackTree.prototype = {
  12777. constructor: RedBlackTree,
  12778. insert: function(after, node) {
  12779. var parent, grandpa, uncle;
  12780. if (after) {
  12781. node.P = after;
  12782. node.N = after.N;
  12783. if (after.N) after.N.P = node;
  12784. after.N = node;
  12785. if (after.R) {
  12786. after = after.R;
  12787. while (after.L) after = after.L;
  12788. after.L = node;
  12789. } else {
  12790. after.R = node;
  12791. }
  12792. parent = after;
  12793. } else if (this._) {
  12794. after = RedBlackFirst(this._);
  12795. node.P = null;
  12796. node.N = after;
  12797. after.P = after.L = node;
  12798. parent = after;
  12799. } else {
  12800. node.P = node.N = null;
  12801. this._ = node;
  12802. parent = null;
  12803. }
  12804. node.L = node.R = null;
  12805. node.U = parent;
  12806. node.C = true;
  12807. after = node;
  12808. while (parent && parent.C) {
  12809. grandpa = parent.U;
  12810. if (parent === grandpa.L) {
  12811. uncle = grandpa.R;
  12812. if (uncle && uncle.C) {
  12813. parent.C = uncle.C = false;
  12814. grandpa.C = true;
  12815. after = grandpa;
  12816. } else {
  12817. if (after === parent.R) {
  12818. RedBlackRotateLeft(this, parent);
  12819. after = parent;
  12820. parent = after.U;
  12821. }
  12822. parent.C = false;
  12823. grandpa.C = true;
  12824. RedBlackRotateRight(this, grandpa);
  12825. }
  12826. } else {
  12827. uncle = grandpa.L;
  12828. if (uncle && uncle.C) {
  12829. parent.C = uncle.C = false;
  12830. grandpa.C = true;
  12831. after = grandpa;
  12832. } else {
  12833. if (after === parent.L) {
  12834. RedBlackRotateRight(this, parent);
  12835. after = parent;
  12836. parent = after.U;
  12837. }
  12838. parent.C = false;
  12839. grandpa.C = true;
  12840. RedBlackRotateLeft(this, grandpa);
  12841. }
  12842. }
  12843. parent = after.U;
  12844. }
  12845. this._.C = false;
  12846. },
  12847. remove: function(node) {
  12848. if (node.N) node.N.P = node.P;
  12849. if (node.P) node.P.N = node.N;
  12850. node.N = node.P = null;
  12851. var parent = node.U,
  12852. sibling,
  12853. left = node.L,
  12854. right = node.R,
  12855. next,
  12856. red;
  12857. if (!left) next = right;
  12858. else if (!right) next = left;
  12859. else next = RedBlackFirst(right);
  12860. if (parent) {
  12861. if (parent.L === node) parent.L = next;
  12862. else parent.R = next;
  12863. } else {
  12864. this._ = next;
  12865. }
  12866. if (left && right) {
  12867. red = next.C;
  12868. next.C = node.C;
  12869. next.L = left;
  12870. left.U = next;
  12871. if (next !== right) {
  12872. parent = next.U;
  12873. next.U = node.U;
  12874. node = next.R;
  12875. parent.L = node;
  12876. next.R = right;
  12877. right.U = next;
  12878. } else {
  12879. next.U = parent;
  12880. parent = next;
  12881. node = next.R;
  12882. }
  12883. } else {
  12884. red = node.C;
  12885. node = next;
  12886. }
  12887. if (node) node.U = parent;
  12888. if (red) return;
  12889. if (node && node.C) { node.C = false; return; }
  12890. do {
  12891. if (node === this._) break;
  12892. if (node === parent.L) {
  12893. sibling = parent.R;
  12894. if (sibling.C) {
  12895. sibling.C = false;
  12896. parent.C = true;
  12897. RedBlackRotateLeft(this, parent);
  12898. sibling = parent.R;
  12899. }
  12900. if ((sibling.L && sibling.L.C)
  12901. || (sibling.R && sibling.R.C)) {
  12902. if (!sibling.R || !sibling.R.C) {
  12903. sibling.L.C = false;
  12904. sibling.C = true;
  12905. RedBlackRotateRight(this, sibling);
  12906. sibling = parent.R;
  12907. }
  12908. sibling.C = parent.C;
  12909. parent.C = sibling.R.C = false;
  12910. RedBlackRotateLeft(this, parent);
  12911. node = this._;
  12912. break;
  12913. }
  12914. } else {
  12915. sibling = parent.L;
  12916. if (sibling.C) {
  12917. sibling.C = false;
  12918. parent.C = true;
  12919. RedBlackRotateRight(this, parent);
  12920. sibling = parent.L;
  12921. }
  12922. if ((sibling.L && sibling.L.C)
  12923. || (sibling.R && sibling.R.C)) {
  12924. if (!sibling.L || !sibling.L.C) {
  12925. sibling.R.C = false;
  12926. sibling.C = true;
  12927. RedBlackRotateLeft(this, sibling);
  12928. sibling = parent.L;
  12929. }
  12930. sibling.C = parent.C;
  12931. parent.C = sibling.L.C = false;
  12932. RedBlackRotateRight(this, parent);
  12933. node = this._;
  12934. break;
  12935. }
  12936. }
  12937. sibling.C = true;
  12938. node = parent;
  12939. parent = parent.U;
  12940. } while (!node.C);
  12941. if (node) node.C = false;
  12942. }
  12943. };
  12944. function RedBlackRotateLeft(tree, node) {
  12945. var p = node,
  12946. q = node.R,
  12947. parent = p.U;
  12948. if (parent) {
  12949. if (parent.L === p) parent.L = q;
  12950. else parent.R = q;
  12951. } else {
  12952. tree._ = q;
  12953. }
  12954. q.U = parent;
  12955. p.U = q;
  12956. p.R = q.L;
  12957. if (p.R) p.R.U = p;
  12958. q.L = p;
  12959. }
  12960. function RedBlackRotateRight(tree, node) {
  12961. var p = node,
  12962. q = node.L,
  12963. parent = p.U;
  12964. if (parent) {
  12965. if (parent.L === p) parent.L = q;
  12966. else parent.R = q;
  12967. } else {
  12968. tree._ = q;
  12969. }
  12970. q.U = parent;
  12971. p.U = q;
  12972. p.L = q.R;
  12973. if (p.L) p.L.U = p;
  12974. q.R = p;
  12975. }
  12976. function RedBlackFirst(node) {
  12977. while (node.L) node = node.L;
  12978. return node;
  12979. }
  12980. function createEdge(left, right, v0, v1) {
  12981. var edge = [null, null],
  12982. index = edges.push(edge) - 1;
  12983. edge.left = left;
  12984. edge.right = right;
  12985. if (v0) setEdgeEnd(edge, left, right, v0);
  12986. if (v1) setEdgeEnd(edge, right, left, v1);
  12987. cells[left.index].halfedges.push(index);
  12988. cells[right.index].halfedges.push(index);
  12989. return edge;
  12990. }
  12991. function createBorderEdge(left, v0, v1) {
  12992. var edge = [v0, v1];
  12993. edge.left = left;
  12994. return edge;
  12995. }
  12996. function setEdgeEnd(edge, left, right, vertex) {
  12997. if (!edge[0] && !edge[1]) {
  12998. edge[0] = vertex;
  12999. edge.left = left;
  13000. edge.right = right;
  13001. } else if (edge.left === right) {
  13002. edge[1] = vertex;
  13003. } else {
  13004. edge[0] = vertex;
  13005. }
  13006. }
  13007. // Liang–Barsky line clipping.
  13008. function clipEdge(edge, x0, y0, x1, y1) {
  13009. var a = edge[0],
  13010. b = edge[1],
  13011. ax = a[0],
  13012. ay = a[1],
  13013. bx = b[0],
  13014. by = b[1],
  13015. t0 = 0,
  13016. t1 = 1,
  13017. dx = bx - ax,
  13018. dy = by - ay,
  13019. r;
  13020. r = x0 - ax;
  13021. if (!dx && r > 0) return;
  13022. r /= dx;
  13023. if (dx < 0) {
  13024. if (r < t0) return;
  13025. if (r < t1) t1 = r;
  13026. } else if (dx > 0) {
  13027. if (r > t1) return;
  13028. if (r > t0) t0 = r;
  13029. }
  13030. r = x1 - ax;
  13031. if (!dx && r < 0) return;
  13032. r /= dx;
  13033. if (dx < 0) {
  13034. if (r > t1) return;
  13035. if (r > t0) t0 = r;
  13036. } else if (dx > 0) {
  13037. if (r < t0) return;
  13038. if (r < t1) t1 = r;
  13039. }
  13040. r = y0 - ay;
  13041. if (!dy && r > 0) return;
  13042. r /= dy;
  13043. if (dy < 0) {
  13044. if (r < t0) return;
  13045. if (r < t1) t1 = r;
  13046. } else if (dy > 0) {
  13047. if (r > t1) return;
  13048. if (r > t0) t0 = r;
  13049. }
  13050. r = y1 - ay;
  13051. if (!dy && r < 0) return;
  13052. r /= dy;
  13053. if (dy < 0) {
  13054. if (r > t1) return;
  13055. if (r > t0) t0 = r;
  13056. } else if (dy > 0) {
  13057. if (r < t0) return;
  13058. if (r < t1) t1 = r;
  13059. }
  13060. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  13061. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  13062. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  13063. return true;
  13064. }
  13065. function connectEdge(edge, x0, y0, x1, y1) {
  13066. var v1 = edge[1];
  13067. if (v1) return true;
  13068. var v0 = edge[0],
  13069. left = edge.left,
  13070. right = edge.right,
  13071. lx = left[0],
  13072. ly = left[1],
  13073. rx = right[0],
  13074. ry = right[1],
  13075. fx = (lx + rx) / 2,
  13076. fy = (ly + ry) / 2,
  13077. fm,
  13078. fb;
  13079. if (ry === ly) {
  13080. if (fx < x0 || fx >= x1) return;
  13081. if (lx > rx) {
  13082. if (!v0) v0 = [fx, y0];
  13083. else if (v0[1] >= y1) return;
  13084. v1 = [fx, y1];
  13085. } else {
  13086. if (!v0) v0 = [fx, y1];
  13087. else if (v0[1] < y0) return;
  13088. v1 = [fx, y0];
  13089. }
  13090. } else {
  13091. fm = (lx - rx) / (ry - ly);
  13092. fb = fy - fm * fx;
  13093. if (fm < -1 || fm > 1) {
  13094. if (lx > rx) {
  13095. if (!v0) v0 = [(y0 - fb) / fm, y0];
  13096. else if (v0[1] >= y1) return;
  13097. v1 = [(y1 - fb) / fm, y1];
  13098. } else {
  13099. if (!v0) v0 = [(y1 - fb) / fm, y1];
  13100. else if (v0[1] < y0) return;
  13101. v1 = [(y0 - fb) / fm, y0];
  13102. }
  13103. } else {
  13104. if (ly < ry) {
  13105. if (!v0) v0 = [x0, fm * x0 + fb];
  13106. else if (v0[0] >= x1) return;
  13107. v1 = [x1, fm * x1 + fb];
  13108. } else {
  13109. if (!v0) v0 = [x1, fm * x1 + fb];
  13110. else if (v0[0] < x0) return;
  13111. v1 = [x0, fm * x0 + fb];
  13112. }
  13113. }
  13114. }
  13115. edge[0] = v0;
  13116. edge[1] = v1;
  13117. return true;
  13118. }
  13119. function clipEdges(x0, y0, x1, y1) {
  13120. var i = edges.length,
  13121. edge;
  13122. while (i--) {
  13123. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  13124. || !clipEdge(edge, x0, y0, x1, y1)
  13125. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  13126. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  13127. delete edges[i];
  13128. }
  13129. }
  13130. }
  13131. function createCell(site) {
  13132. return cells[site.index] = {
  13133. site: site,
  13134. halfedges: []
  13135. };
  13136. }
  13137. function cellHalfedgeAngle(cell, edge) {
  13138. var site = cell.site,
  13139. va = edge.left,
  13140. vb = edge.right;
  13141. if (site === vb) vb = va, va = site;
  13142. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  13143. if (site === va) va = edge[1], vb = edge[0];
  13144. else va = edge[0], vb = edge[1];
  13145. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  13146. }
  13147. function cellHalfedgeStart(cell, edge) {
  13148. return edge[+(edge.left !== cell.site)];
  13149. }
  13150. function cellHalfedgeEnd(cell, edge) {
  13151. return edge[+(edge.left === cell.site)];
  13152. }
  13153. function sortCellHalfedges() {
  13154. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  13155. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  13156. var index = new Array(m),
  13157. array = new Array(m);
  13158. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  13159. index.sort(function(i, j) { return array[j] - array[i]; });
  13160. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  13161. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  13162. }
  13163. }
  13164. }
  13165. function clipCells(x0, y0, x1, y1) {
  13166. var nCells = cells.length,
  13167. iCell,
  13168. cell,
  13169. site,
  13170. iHalfedge,
  13171. halfedges,
  13172. nHalfedges,
  13173. start,
  13174. startX,
  13175. startY,
  13176. end,
  13177. endX,
  13178. endY,
  13179. cover = true;
  13180. for (iCell = 0; iCell < nCells; ++iCell) {
  13181. if (cell = cells[iCell]) {
  13182. site = cell.site;
  13183. halfedges = cell.halfedges;
  13184. iHalfedge = halfedges.length;
  13185. // Remove any dangling clipped edges.
  13186. while (iHalfedge--) {
  13187. if (!edges[halfedges[iHalfedge]]) {
  13188. halfedges.splice(iHalfedge, 1);
  13189. }
  13190. }
  13191. // Insert any border edges as necessary.
  13192. iHalfedge = 0, nHalfedges = halfedges.length;
  13193. while (iHalfedge < nHalfedges) {
  13194. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  13195. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  13196. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  13197. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  13198. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  13199. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  13200. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  13201. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  13202. : null)) - 1);
  13203. ++nHalfedges;
  13204. }
  13205. }
  13206. if (nHalfedges) cover = false;
  13207. }
  13208. }
  13209. // If there weren’t any edges, have the closest site cover the extent.
  13210. // It doesn’t matter which corner of the extent we measure!
  13211. if (cover) {
  13212. var dx, dy, d2, dc = Infinity;
  13213. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  13214. if (cell = cells[iCell]) {
  13215. site = cell.site;
  13216. dx = site[0] - x0;
  13217. dy = site[1] - y0;
  13218. d2 = dx * dx + dy * dy;
  13219. if (d2 < dc) dc = d2, cover = cell;
  13220. }
  13221. }
  13222. if (cover) {
  13223. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  13224. cover.halfedges.push(
  13225. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  13226. edges.push(createBorderEdge(site, v01, v11)) - 1,
  13227. edges.push(createBorderEdge(site, v11, v10)) - 1,
  13228. edges.push(createBorderEdge(site, v10, v00)) - 1
  13229. );
  13230. }
  13231. }
  13232. // Lastly delete any cells with no edges; these were entirely clipped.
  13233. for (iCell = 0; iCell < nCells; ++iCell) {
  13234. if (cell = cells[iCell]) {
  13235. if (!cell.halfedges.length) {
  13236. delete cells[iCell];
  13237. }
  13238. }
  13239. }
  13240. }
  13241. var circlePool = [];
  13242. var firstCircle;
  13243. function Circle() {
  13244. RedBlackNode(this);
  13245. this.x =
  13246. this.y =
  13247. this.arc =
  13248. this.site =
  13249. this.cy = null;
  13250. }
  13251. function attachCircle(arc) {
  13252. var lArc = arc.P,
  13253. rArc = arc.N;
  13254. if (!lArc || !rArc) return;
  13255. var lSite = lArc.site,
  13256. cSite = arc.site,
  13257. rSite = rArc.site;
  13258. if (lSite === rSite) return;
  13259. var bx = cSite[0],
  13260. by = cSite[1],
  13261. ax = lSite[0] - bx,
  13262. ay = lSite[1] - by,
  13263. cx = rSite[0] - bx,
  13264. cy = rSite[1] - by;
  13265. var d = 2 * (ax * cy - ay * cx);
  13266. if (d >= -epsilon2$2) return;
  13267. var ha = ax * ax + ay * ay,
  13268. hc = cx * cx + cy * cy,
  13269. x = (cy * ha - ay * hc) / d,
  13270. y = (ax * hc - cx * ha) / d;
  13271. var circle = circlePool.pop() || new Circle;
  13272. circle.arc = arc;
  13273. circle.site = cSite;
  13274. circle.x = x + bx;
  13275. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  13276. arc.circle = circle;
  13277. var before = null,
  13278. node = circles._;
  13279. while (node) {
  13280. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  13281. if (node.L) node = node.L;
  13282. else { before = node.P; break; }
  13283. } else {
  13284. if (node.R) node = node.R;
  13285. else { before = node; break; }
  13286. }
  13287. }
  13288. circles.insert(before, circle);
  13289. if (!before) firstCircle = circle;
  13290. }
  13291. function detachCircle(arc) {
  13292. var circle = arc.circle;
  13293. if (circle) {
  13294. if (!circle.P) firstCircle = circle.N;
  13295. circles.remove(circle);
  13296. circlePool.push(circle);
  13297. RedBlackNode(circle);
  13298. arc.circle = null;
  13299. }
  13300. }
  13301. var beachPool = [];
  13302. function Beach() {
  13303. RedBlackNode(this);
  13304. this.edge =
  13305. this.site =
  13306. this.circle = null;
  13307. }
  13308. function createBeach(site) {
  13309. var beach = beachPool.pop() || new Beach;
  13310. beach.site = site;
  13311. return beach;
  13312. }
  13313. function detachBeach(beach) {
  13314. detachCircle(beach);
  13315. beaches.remove(beach);
  13316. beachPool.push(beach);
  13317. RedBlackNode(beach);
  13318. }
  13319. function removeBeach(beach) {
  13320. var circle = beach.circle,
  13321. x = circle.x,
  13322. y = circle.cy,
  13323. vertex = [x, y],
  13324. previous = beach.P,
  13325. next = beach.N,
  13326. disappearing = [beach];
  13327. detachBeach(beach);
  13328. var lArc = previous;
  13329. while (lArc.circle
  13330. && Math.abs(x - lArc.circle.x) < epsilon$4
  13331. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  13332. previous = lArc.P;
  13333. disappearing.unshift(lArc);
  13334. detachBeach(lArc);
  13335. lArc = previous;
  13336. }
  13337. disappearing.unshift(lArc);
  13338. detachCircle(lArc);
  13339. var rArc = next;
  13340. while (rArc.circle
  13341. && Math.abs(x - rArc.circle.x) < epsilon$4
  13342. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  13343. next = rArc.N;
  13344. disappearing.push(rArc);
  13345. detachBeach(rArc);
  13346. rArc = next;
  13347. }
  13348. disappearing.push(rArc);
  13349. detachCircle(rArc);
  13350. var nArcs = disappearing.length,
  13351. iArc;
  13352. for (iArc = 1; iArc < nArcs; ++iArc) {
  13353. rArc = disappearing[iArc];
  13354. lArc = disappearing[iArc - 1];
  13355. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  13356. }
  13357. lArc = disappearing[0];
  13358. rArc = disappearing[nArcs - 1];
  13359. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  13360. attachCircle(lArc);
  13361. attachCircle(rArc);
  13362. }
  13363. function addBeach(site) {
  13364. var x = site[0],
  13365. directrix = site[1],
  13366. lArc,
  13367. rArc,
  13368. dxl,
  13369. dxr,
  13370. node = beaches._;
  13371. while (node) {
  13372. dxl = leftBreakPoint(node, directrix) - x;
  13373. if (dxl > epsilon$4) node = node.L; else {
  13374. dxr = x - rightBreakPoint(node, directrix);
  13375. if (dxr > epsilon$4) {
  13376. if (!node.R) {
  13377. lArc = node;
  13378. break;
  13379. }
  13380. node = node.R;
  13381. } else {
  13382. if (dxl > -epsilon$4) {
  13383. lArc = node.P;
  13384. rArc = node;
  13385. } else if (dxr > -epsilon$4) {
  13386. lArc = node;
  13387. rArc = node.N;
  13388. } else {
  13389. lArc = rArc = node;
  13390. }
  13391. break;
  13392. }
  13393. }
  13394. }
  13395. createCell(site);
  13396. var newArc = createBeach(site);
  13397. beaches.insert(lArc, newArc);
  13398. if (!lArc && !rArc) return;
  13399. if (lArc === rArc) {
  13400. detachCircle(lArc);
  13401. rArc = createBeach(lArc.site);
  13402. beaches.insert(newArc, rArc);
  13403. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  13404. attachCircle(lArc);
  13405. attachCircle(rArc);
  13406. return;
  13407. }
  13408. if (!rArc) { // && lArc
  13409. newArc.edge = createEdge(lArc.site, newArc.site);
  13410. return;
  13411. }
  13412. // else lArc !== rArc
  13413. detachCircle(lArc);
  13414. detachCircle(rArc);
  13415. var lSite = lArc.site,
  13416. ax = lSite[0],
  13417. ay = lSite[1],
  13418. bx = site[0] - ax,
  13419. by = site[1] - ay,
  13420. rSite = rArc.site,
  13421. cx = rSite[0] - ax,
  13422. cy = rSite[1] - ay,
  13423. d = 2 * (bx * cy - by * cx),
  13424. hb = bx * bx + by * by,
  13425. hc = cx * cx + cy * cy,
  13426. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  13427. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  13428. newArc.edge = createEdge(lSite, site, null, vertex);
  13429. rArc.edge = createEdge(site, rSite, null, vertex);
  13430. attachCircle(lArc);
  13431. attachCircle(rArc);
  13432. }
  13433. function leftBreakPoint(arc, directrix) {
  13434. var site = arc.site,
  13435. rfocx = site[0],
  13436. rfocy = site[1],
  13437. pby2 = rfocy - directrix;
  13438. if (!pby2) return rfocx;
  13439. var lArc = arc.P;
  13440. if (!lArc) return -Infinity;
  13441. site = lArc.site;
  13442. var lfocx = site[0],
  13443. lfocy = site[1],
  13444. plby2 = lfocy - directrix;
  13445. if (!plby2) return lfocx;
  13446. var hl = lfocx - rfocx,
  13447. aby2 = 1 / pby2 - 1 / plby2,
  13448. b = hl / plby2;
  13449. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  13450. return (rfocx + lfocx) / 2;
  13451. }
  13452. function rightBreakPoint(arc, directrix) {
  13453. var rArc = arc.N;
  13454. if (rArc) return leftBreakPoint(rArc, directrix);
  13455. var site = arc.site;
  13456. return site[1] === directrix ? site[0] : Infinity;
  13457. }
  13458. var epsilon$4 = 1e-6;
  13459. var epsilon2$2 = 1e-12;
  13460. var beaches;
  13461. var cells;
  13462. var circles;
  13463. var edges;
  13464. function triangleArea(a, b, c) {
  13465. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  13466. }
  13467. function lexicographic(a, b) {
  13468. return b[1] - a[1]
  13469. || b[0] - a[0];
  13470. }
  13471. function Diagram(sites, extent) {
  13472. var site = sites.sort(lexicographic).pop(),
  13473. x,
  13474. y,
  13475. circle;
  13476. edges = [];
  13477. cells = new Array(sites.length);
  13478. beaches = new RedBlackTree;
  13479. circles = new RedBlackTree;
  13480. while (true) {
  13481. circle = firstCircle;
  13482. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  13483. if (site[0] !== x || site[1] !== y) {
  13484. addBeach(site);
  13485. x = site[0], y = site[1];
  13486. }
  13487. site = sites.pop();
  13488. } else if (circle) {
  13489. removeBeach(circle.arc);
  13490. } else {
  13491. break;
  13492. }
  13493. }
  13494. sortCellHalfedges();
  13495. if (extent) {
  13496. var x0 = +extent[0][0],
  13497. y0 = +extent[0][1],
  13498. x1 = +extent[1][0],
  13499. y1 = +extent[1][1];
  13500. clipEdges(x0, y0, x1, y1);
  13501. clipCells(x0, y0, x1, y1);
  13502. }
  13503. this.edges = edges;
  13504. this.cells = cells;
  13505. beaches =
  13506. circles =
  13507. edges =
  13508. cells = null;
  13509. }
  13510. Diagram.prototype = {
  13511. constructor: Diagram,
  13512. polygons: function() {
  13513. var edges = this.edges;
  13514. return this.cells.map(function(cell) {
  13515. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  13516. polygon.data = cell.site.data;
  13517. return polygon;
  13518. });
  13519. },
  13520. triangles: function() {
  13521. var triangles = [],
  13522. edges = this.edges;
  13523. this.cells.forEach(function(cell, i) {
  13524. if (!(m = (halfedges = cell.halfedges).length)) return;
  13525. var site = cell.site,
  13526. halfedges,
  13527. j = -1,
  13528. m,
  13529. s0,
  13530. e1 = edges[halfedges[m - 1]],
  13531. s1 = e1.left === site ? e1.right : e1.left;
  13532. while (++j < m) {
  13533. s0 = s1;
  13534. e1 = edges[halfedges[j]];
  13535. s1 = e1.left === site ? e1.right : e1.left;
  13536. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  13537. triangles.push([site.data, s0.data, s1.data]);
  13538. }
  13539. }
  13540. });
  13541. return triangles;
  13542. },
  13543. links: function() {
  13544. return this.edges.filter(function(edge) {
  13545. return edge.right;
  13546. }).map(function(edge) {
  13547. return {
  13548. source: edge.left.data,
  13549. target: edge.right.data
  13550. };
  13551. });
  13552. },
  13553. find: function(x, y, radius) {
  13554. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  13555. // Use the previously-found cell, or start with an arbitrary one.
  13556. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  13557. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  13558. // Traverse the half-edges to find a closer cell, if any.
  13559. do {
  13560. cell = that.cells[i0 = i1], i1 = null;
  13561. cell.halfedges.forEach(function(e) {
  13562. var edge = that.edges[e], v = edge.left;
  13563. if ((v === cell.site || !v) && !(v = edge.right)) return;
  13564. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  13565. if (v2 < d2) d2 = v2, i1 = v.index;
  13566. });
  13567. } while (i1 !== null);
  13568. that._found = i0;
  13569. return radius == null || d2 <= radius * radius ? cell.site : null;
  13570. }
  13571. };
  13572. var voronoi = function() {
  13573. var x$$1 = x$4,
  13574. y$$1 = y$4,
  13575. extent = null;
  13576. function voronoi(data) {
  13577. return new Diagram(data.map(function(d, i) {
  13578. var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
  13579. s.index = i;
  13580. s.data = d;
  13581. return s;
  13582. }), extent);
  13583. }
  13584. voronoi.polygons = function(data) {
  13585. return voronoi(data).polygons();
  13586. };
  13587. voronoi.links = function(data) {
  13588. return voronoi(data).links();
  13589. };
  13590. voronoi.triangles = function(data) {
  13591. return voronoi(data).triangles();
  13592. };
  13593. voronoi.x = function(_) {
  13594. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : x$$1;
  13595. };
  13596. voronoi.y = function(_) {
  13597. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : y$$1;
  13598. };
  13599. voronoi.extent = function(_) {
  13600. 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]]];
  13601. };
  13602. voronoi.size = function(_) {
  13603. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  13604. };
  13605. return voronoi;
  13606. };
  13607. var constant$12 = function(x) {
  13608. return function() {
  13609. return x;
  13610. };
  13611. };
  13612. function ZoomEvent(target, type, transform) {
  13613. this.target = target;
  13614. this.type = type;
  13615. this.transform = transform;
  13616. }
  13617. function Transform(k, x, y) {
  13618. this.k = k;
  13619. this.x = x;
  13620. this.y = y;
  13621. }
  13622. Transform.prototype = {
  13623. constructor: Transform,
  13624. scale: function(k) {
  13625. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  13626. },
  13627. translate: function(x, y) {
  13628. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  13629. },
  13630. apply: function(point) {
  13631. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  13632. },
  13633. applyX: function(x) {
  13634. return x * this.k + this.x;
  13635. },
  13636. applyY: function(y) {
  13637. return y * this.k + this.y;
  13638. },
  13639. invert: function(location) {
  13640. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  13641. },
  13642. invertX: function(x) {
  13643. return (x - this.x) / this.k;
  13644. },
  13645. invertY: function(y) {
  13646. return (y - this.y) / this.k;
  13647. },
  13648. rescaleX: function(x) {
  13649. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  13650. },
  13651. rescaleY: function(y) {
  13652. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  13653. },
  13654. toString: function() {
  13655. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  13656. }
  13657. };
  13658. var identity$8 = new Transform(1, 0, 0);
  13659. transform$1.prototype = Transform.prototype;
  13660. function transform$1(node) {
  13661. return node.__zoom || identity$8;
  13662. }
  13663. function nopropagation$2() {
  13664. exports.event.stopImmediatePropagation();
  13665. }
  13666. var noevent$2 = function() {
  13667. exports.event.preventDefault();
  13668. exports.event.stopImmediatePropagation();
  13669. };
  13670. // Ignore right-click, since that should open the context menu.
  13671. function defaultFilter$2() {
  13672. return !exports.event.button;
  13673. }
  13674. function defaultExtent$1() {
  13675. var e = this, w, h;
  13676. if (e instanceof SVGElement) {
  13677. e = e.ownerSVGElement || e;
  13678. w = e.width.baseVal.value;
  13679. h = e.height.baseVal.value;
  13680. } else {
  13681. w = e.clientWidth;
  13682. h = e.clientHeight;
  13683. }
  13684. return [[0, 0], [w, h]];
  13685. }
  13686. function defaultTransform() {
  13687. return this.__zoom || identity$8;
  13688. }
  13689. var zoom = function() {
  13690. var filter = defaultFilter$2,
  13691. extent = defaultExtent$1,
  13692. k0 = 0,
  13693. k1 = Infinity,
  13694. x0 = -k1,
  13695. x1 = k1,
  13696. y0 = x0,
  13697. y1 = x1,
  13698. duration = 250,
  13699. interpolate$$1 = interpolateZoom,
  13700. gestures = [],
  13701. listeners = dispatch("start", "zoom", "end"),
  13702. touchstarting,
  13703. touchending,
  13704. touchDelay = 500,
  13705. wheelDelay = 150,
  13706. clickDistance2 = 0;
  13707. function zoom(selection$$1) {
  13708. selection$$1
  13709. .on("wheel.zoom", wheeled)
  13710. .on("mousedown.zoom", mousedowned)
  13711. .on("dblclick.zoom", dblclicked)
  13712. .on("touchstart.zoom", touchstarted)
  13713. .on("touchmove.zoom", touchmoved)
  13714. .on("touchend.zoom touchcancel.zoom", touchended)
  13715. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  13716. .property("__zoom", defaultTransform);
  13717. }
  13718. zoom.transform = function(collection, transform) {
  13719. var selection$$1 = collection.selection ? collection.selection() : collection;
  13720. selection$$1.property("__zoom", defaultTransform);
  13721. if (collection !== selection$$1) {
  13722. schedule(collection, transform);
  13723. } else {
  13724. selection$$1.interrupt().each(function() {
  13725. gesture(this, arguments)
  13726. .start()
  13727. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  13728. .end();
  13729. });
  13730. }
  13731. };
  13732. zoom.scaleBy = function(selection$$1, k) {
  13733. zoom.scaleTo(selection$$1, function() {
  13734. var k0 = this.__zoom.k,
  13735. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  13736. return k0 * k1;
  13737. });
  13738. };
  13739. zoom.scaleTo = function(selection$$1, k) {
  13740. zoom.transform(selection$$1, function() {
  13741. var e = extent.apply(this, arguments),
  13742. t0 = this.__zoom,
  13743. p0 = centroid(e),
  13744. p1 = t0.invert(p0),
  13745. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  13746. return constrain(translate(scale(t0, k1), p0, p1), e);
  13747. });
  13748. };
  13749. zoom.translateBy = function(selection$$1, x, y) {
  13750. zoom.transform(selection$$1, function() {
  13751. return constrain(this.__zoom.translate(
  13752. typeof x === "function" ? x.apply(this, arguments) : x,
  13753. typeof y === "function" ? y.apply(this, arguments) : y
  13754. ), extent.apply(this, arguments));
  13755. });
  13756. };
  13757. function scale(transform, k) {
  13758. k = Math.max(k0, Math.min(k1, k));
  13759. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  13760. }
  13761. function translate(transform, p0, p1) {
  13762. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  13763. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  13764. }
  13765. function constrain(transform, extent) {
  13766. var dx0 = transform.invertX(extent[0][0]) - x0,
  13767. dx1 = transform.invertX(extent[1][0]) - x1,
  13768. dy0 = transform.invertY(extent[0][1]) - y0,
  13769. dy1 = transform.invertY(extent[1][1]) - y1;
  13770. return transform.translate(
  13771. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  13772. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  13773. );
  13774. }
  13775. function centroid(extent) {
  13776. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  13777. }
  13778. function schedule(transition$$1, transform, center) {
  13779. transition$$1
  13780. .on("start.zoom", function() { gesture(this, arguments).start(); })
  13781. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  13782. .tween("zoom", function() {
  13783. var that = this,
  13784. args = arguments,
  13785. g = gesture(that, args),
  13786. e = extent.apply(that, args),
  13787. p = center || centroid(e),
  13788. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  13789. a = that.__zoom,
  13790. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  13791. i = interpolate$$1(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  13792. return function(t) {
  13793. if (t === 1) t = b; // Avoid rounding error on end.
  13794. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  13795. g.zoom(null, t);
  13796. };
  13797. });
  13798. }
  13799. function gesture(that, args) {
  13800. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  13801. if ((g = gestures[i]).that === that) {
  13802. return g;
  13803. }
  13804. }
  13805. return new Gesture(that, args);
  13806. }
  13807. function Gesture(that, args) {
  13808. this.that = that;
  13809. this.args = args;
  13810. this.index = -1;
  13811. this.active = 0;
  13812. this.extent = extent.apply(that, args);
  13813. }
  13814. Gesture.prototype = {
  13815. start: function() {
  13816. if (++this.active === 1) {
  13817. this.index = gestures.push(this) - 1;
  13818. this.emit("start");
  13819. }
  13820. return this;
  13821. },
  13822. zoom: function(key, transform) {
  13823. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  13824. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  13825. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  13826. this.that.__zoom = transform;
  13827. this.emit("zoom");
  13828. return this;
  13829. },
  13830. end: function() {
  13831. if (--this.active === 0) {
  13832. gestures.splice(this.index, 1);
  13833. this.index = -1;
  13834. this.emit("end");
  13835. }
  13836. return this;
  13837. },
  13838. emit: function(type) {
  13839. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  13840. }
  13841. };
  13842. function wheeled() {
  13843. if (!filter.apply(this, arguments)) return;
  13844. var g = gesture(this, arguments),
  13845. t = this.__zoom,
  13846. k = Math.max(k0, Math.min(k1, t.k * Math.pow(2, -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500))),
  13847. p = mouse(this);
  13848. // If the mouse is in the same location as before, reuse it.
  13849. // If there were recent wheel events, reset the wheel idle timeout.
  13850. if (g.wheel) {
  13851. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  13852. g.mouse[1] = t.invert(g.mouse[0] = p);
  13853. }
  13854. clearTimeout(g.wheel);
  13855. }
  13856. // If this wheel event won’t trigger a transform change, ignore it.
  13857. else if (t.k === k) return;
  13858. // Otherwise, capture the mouse point and location at the start.
  13859. else {
  13860. g.mouse = [p, t.invert(p)];
  13861. interrupt(this);
  13862. g.start();
  13863. }
  13864. noevent$2();
  13865. g.wheel = setTimeout(wheelidled, wheelDelay);
  13866. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent));
  13867. function wheelidled() {
  13868. g.wheel = null;
  13869. g.end();
  13870. }
  13871. }
  13872. function mousedowned() {
  13873. if (touchending || !filter.apply(this, arguments)) return;
  13874. var g = gesture(this, arguments),
  13875. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  13876. p = mouse(this),
  13877. x0 = exports.event.clientX,
  13878. y0 = exports.event.clientY;
  13879. dragDisable(exports.event.view);
  13880. nopropagation$2();
  13881. g.mouse = [p, this.__zoom.invert(p)];
  13882. interrupt(this);
  13883. g.start();
  13884. function mousemoved() {
  13885. noevent$2();
  13886. if (!g.moved) {
  13887. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  13888. g.moved = dx * dx + dy * dy > clickDistance2;
  13889. }
  13890. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent));
  13891. }
  13892. function mouseupped() {
  13893. v.on("mousemove.zoom mouseup.zoom", null);
  13894. yesdrag(exports.event.view, g.moved);
  13895. noevent$2();
  13896. g.end();
  13897. }
  13898. }
  13899. function dblclicked() {
  13900. if (!filter.apply(this, arguments)) return;
  13901. var t0 = this.__zoom,
  13902. p0 = mouse(this),
  13903. p1 = t0.invert(p0),
  13904. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  13905. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments));
  13906. noevent$2();
  13907. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  13908. else select(this).call(zoom.transform, t1);
  13909. }
  13910. function touchstarted() {
  13911. if (!filter.apply(this, arguments)) return;
  13912. var g = gesture(this, arguments),
  13913. touches$$1 = exports.event.changedTouches,
  13914. started,
  13915. n = touches$$1.length, i, t, p;
  13916. nopropagation$2();
  13917. for (i = 0; i < n; ++i) {
  13918. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  13919. p = [p, this.__zoom.invert(p), t.identifier];
  13920. if (!g.touch0) g.touch0 = p, started = true;
  13921. else if (!g.touch1) g.touch1 = p;
  13922. }
  13923. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  13924. if (touchstarting) {
  13925. touchstarting = clearTimeout(touchstarting);
  13926. if (!g.touch1) {
  13927. g.end();
  13928. p = select(this).on("dblclick.zoom");
  13929. if (p) p.apply(this, arguments);
  13930. return;
  13931. }
  13932. }
  13933. if (started) {
  13934. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  13935. interrupt(this);
  13936. g.start();
  13937. }
  13938. }
  13939. function touchmoved() {
  13940. var g = gesture(this, arguments),
  13941. touches$$1 = exports.event.changedTouches,
  13942. n = touches$$1.length, i, t, p, l;
  13943. noevent$2();
  13944. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  13945. for (i = 0; i < n; ++i) {
  13946. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  13947. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  13948. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  13949. }
  13950. t = g.that.__zoom;
  13951. if (g.touch1) {
  13952. var p0 = g.touch0[0], l0 = g.touch0[1],
  13953. p1 = g.touch1[0], l1 = g.touch1[1],
  13954. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  13955. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  13956. t = scale(t, Math.sqrt(dp / dl));
  13957. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  13958. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  13959. }
  13960. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  13961. else return;
  13962. g.zoom("touch", constrain(translate(t, p, l), g.extent));
  13963. }
  13964. function touchended() {
  13965. var g = gesture(this, arguments),
  13966. touches$$1 = exports.event.changedTouches,
  13967. n = touches$$1.length, i, t;
  13968. nopropagation$2();
  13969. if (touchending) clearTimeout(touchending);
  13970. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  13971. for (i = 0; i < n; ++i) {
  13972. t = touches$$1[i];
  13973. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  13974. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  13975. }
  13976. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  13977. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  13978. else g.end();
  13979. }
  13980. zoom.filter = function(_) {
  13981. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$12(!!_), zoom) : filter;
  13982. };
  13983. zoom.extent = function(_) {
  13984. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$12([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  13985. };
  13986. zoom.scaleExtent = function(_) {
  13987. return arguments.length ? (k0 = +_[0], k1 = +_[1], zoom) : [k0, k1];
  13988. };
  13989. zoom.translateExtent = function(_) {
  13990. return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], zoom) : [[x0, y0], [x1, y1]];
  13991. };
  13992. zoom.duration = function(_) {
  13993. return arguments.length ? (duration = +_, zoom) : duration;
  13994. };
  13995. zoom.interpolate = function(_) {
  13996. return arguments.length ? (interpolate$$1 = _, zoom) : interpolate$$1;
  13997. };
  13998. zoom.on = function() {
  13999. var value = listeners.on.apply(listeners, arguments);
  14000. return value === listeners ? zoom : value;
  14001. };
  14002. zoom.clickDistance = function(_) {
  14003. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  14004. };
  14005. return zoom;
  14006. };
  14007. exports.version = version;
  14008. exports.bisect = bisectRight;
  14009. exports.bisectRight = bisectRight;
  14010. exports.bisectLeft = bisectLeft;
  14011. exports.ascending = ascending;
  14012. exports.bisector = bisector;
  14013. exports.cross = cross;
  14014. exports.descending = descending;
  14015. exports.deviation = deviation;
  14016. exports.extent = extent;
  14017. exports.histogram = histogram;
  14018. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  14019. exports.thresholdScott = scott;
  14020. exports.thresholdSturges = sturges;
  14021. exports.max = max;
  14022. exports.mean = mean;
  14023. exports.median = median;
  14024. exports.merge = merge;
  14025. exports.min = min;
  14026. exports.pairs = pairs;
  14027. exports.permute = permute;
  14028. exports.quantile = threshold;
  14029. exports.range = sequence;
  14030. exports.scan = scan;
  14031. exports.shuffle = shuffle;
  14032. exports.sum = sum;
  14033. exports.ticks = ticks;
  14034. exports.tickIncrement = tickIncrement;
  14035. exports.tickStep = tickStep;
  14036. exports.transpose = transpose;
  14037. exports.variance = variance;
  14038. exports.zip = zip;
  14039. exports.axisTop = axisTop;
  14040. exports.axisRight = axisRight;
  14041. exports.axisBottom = axisBottom;
  14042. exports.axisLeft = axisLeft;
  14043. exports.brush = brush;
  14044. exports.brushX = brushX;
  14045. exports.brushY = brushY;
  14046. exports.brushSelection = brushSelection;
  14047. exports.chord = chord;
  14048. exports.ribbon = ribbon;
  14049. exports.nest = nest;
  14050. exports.set = set$2;
  14051. exports.map = map$1;
  14052. exports.keys = keys;
  14053. exports.values = values;
  14054. exports.entries = entries;
  14055. exports.color = color;
  14056. exports.rgb = rgb;
  14057. exports.hsl = hsl;
  14058. exports.lab = lab;
  14059. exports.hcl = hcl;
  14060. exports.cubehelix = cubehelix;
  14061. exports.dispatch = dispatch;
  14062. exports.drag = drag;
  14063. exports.dragDisable = dragDisable;
  14064. exports.dragEnable = yesdrag;
  14065. exports.dsvFormat = dsv;
  14066. exports.csvParse = csvParse;
  14067. exports.csvParseRows = csvParseRows;
  14068. exports.csvFormat = csvFormat;
  14069. exports.csvFormatRows = csvFormatRows;
  14070. exports.tsvParse = tsvParse;
  14071. exports.tsvParseRows = tsvParseRows;
  14072. exports.tsvFormat = tsvFormat;
  14073. exports.tsvFormatRows = tsvFormatRows;
  14074. exports.easeLinear = linear$1;
  14075. exports.easeQuad = quadInOut;
  14076. exports.easeQuadIn = quadIn;
  14077. exports.easeQuadOut = quadOut;
  14078. exports.easeQuadInOut = quadInOut;
  14079. exports.easeCubic = cubicInOut;
  14080. exports.easeCubicIn = cubicIn;
  14081. exports.easeCubicOut = cubicOut;
  14082. exports.easeCubicInOut = cubicInOut;
  14083. exports.easePoly = polyInOut;
  14084. exports.easePolyIn = polyIn;
  14085. exports.easePolyOut = polyOut;
  14086. exports.easePolyInOut = polyInOut;
  14087. exports.easeSin = sinInOut;
  14088. exports.easeSinIn = sinIn;
  14089. exports.easeSinOut = sinOut;
  14090. exports.easeSinInOut = sinInOut;
  14091. exports.easeExp = expInOut;
  14092. exports.easeExpIn = expIn;
  14093. exports.easeExpOut = expOut;
  14094. exports.easeExpInOut = expInOut;
  14095. exports.easeCircle = circleInOut;
  14096. exports.easeCircleIn = circleIn;
  14097. exports.easeCircleOut = circleOut;
  14098. exports.easeCircleInOut = circleInOut;
  14099. exports.easeBounce = bounceOut;
  14100. exports.easeBounceIn = bounceIn;
  14101. exports.easeBounceOut = bounceOut;
  14102. exports.easeBounceInOut = bounceInOut;
  14103. exports.easeBack = backInOut;
  14104. exports.easeBackIn = backIn;
  14105. exports.easeBackOut = backOut;
  14106. exports.easeBackInOut = backInOut;
  14107. exports.easeElastic = elasticOut;
  14108. exports.easeElasticIn = elasticIn;
  14109. exports.easeElasticOut = elasticOut;
  14110. exports.easeElasticInOut = elasticInOut;
  14111. exports.forceCenter = center$1;
  14112. exports.forceCollide = collide;
  14113. exports.forceLink = link;
  14114. exports.forceManyBody = manyBody;
  14115. exports.forceSimulation = simulation;
  14116. exports.forceX = x$2;
  14117. exports.forceY = y$2;
  14118. exports.formatDefaultLocale = defaultLocale;
  14119. exports.formatLocale = formatLocale;
  14120. exports.formatSpecifier = formatSpecifier;
  14121. exports.precisionFixed = precisionFixed;
  14122. exports.precisionPrefix = precisionPrefix;
  14123. exports.precisionRound = precisionRound;
  14124. exports.geoArea = area;
  14125. exports.geoBounds = bounds;
  14126. exports.geoCentroid = centroid;
  14127. exports.geoCircle = circle;
  14128. exports.geoClipExtent = extent$1;
  14129. exports.geoContains = contains;
  14130. exports.geoDistance = distance;
  14131. exports.geoGraticule = graticule;
  14132. exports.geoGraticule10 = graticule10;
  14133. exports.geoInterpolate = interpolate$1;
  14134. exports.geoLength = length$1;
  14135. exports.geoPath = index$1;
  14136. exports.geoAlbers = albers;
  14137. exports.geoAlbersUsa = albersUsa;
  14138. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  14139. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  14140. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  14141. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  14142. exports.geoConicConformal = conicConformal;
  14143. exports.geoConicConformalRaw = conicConformalRaw;
  14144. exports.geoConicEqualArea = conicEqualArea;
  14145. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  14146. exports.geoConicEquidistant = conicEquidistant;
  14147. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  14148. exports.geoEquirectangular = equirectangular;
  14149. exports.geoEquirectangularRaw = equirectangularRaw;
  14150. exports.geoGnomonic = gnomonic;
  14151. exports.geoGnomonicRaw = gnomonicRaw;
  14152. exports.geoIdentity = identity$5;
  14153. exports.geoProjection = projection;
  14154. exports.geoProjectionMutator = projectionMutator;
  14155. exports.geoMercator = mercator;
  14156. exports.geoMercatorRaw = mercatorRaw;
  14157. exports.geoOrthographic = orthographic;
  14158. exports.geoOrthographicRaw = orthographicRaw;
  14159. exports.geoStereographic = stereographic;
  14160. exports.geoStereographicRaw = stereographicRaw;
  14161. exports.geoTransverseMercator = transverseMercator;
  14162. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  14163. exports.geoRotation = rotation;
  14164. exports.geoStream = geoStream;
  14165. exports.geoTransform = transform;
  14166. exports.cluster = cluster;
  14167. exports.hierarchy = hierarchy;
  14168. exports.pack = index$2;
  14169. exports.packSiblings = siblings;
  14170. exports.packEnclose = enclose;
  14171. exports.partition = partition;
  14172. exports.stratify = stratify;
  14173. exports.tree = tree;
  14174. exports.treemap = index$3;
  14175. exports.treemapBinary = binary;
  14176. exports.treemapDice = treemapDice;
  14177. exports.treemapSlice = treemapSlice;
  14178. exports.treemapSliceDice = sliceDice;
  14179. exports.treemapSquarify = squarify;
  14180. exports.treemapResquarify = resquarify;
  14181. exports.interpolate = interpolateValue;
  14182. exports.interpolateArray = array$1;
  14183. exports.interpolateBasis = basis$1;
  14184. exports.interpolateBasisClosed = basisClosed;
  14185. exports.interpolateDate = date;
  14186. exports.interpolateNumber = reinterpolate;
  14187. exports.interpolateObject = object;
  14188. exports.interpolateRound = interpolateRound;
  14189. exports.interpolateString = interpolateString;
  14190. exports.interpolateTransformCss = interpolateTransformCss;
  14191. exports.interpolateTransformSvg = interpolateTransformSvg;
  14192. exports.interpolateZoom = interpolateZoom;
  14193. exports.interpolateRgb = interpolateRgb;
  14194. exports.interpolateRgbBasis = rgbBasis;
  14195. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  14196. exports.interpolateHsl = hsl$2;
  14197. exports.interpolateHslLong = hslLong;
  14198. exports.interpolateLab = lab$1;
  14199. exports.interpolateHcl = hcl$2;
  14200. exports.interpolateHclLong = hclLong;
  14201. exports.interpolateCubehelix = cubehelix$2;
  14202. exports.interpolateCubehelixLong = cubehelixLong;
  14203. exports.quantize = quantize;
  14204. exports.path = path;
  14205. exports.polygonArea = area$1;
  14206. exports.polygonCentroid = centroid$1;
  14207. exports.polygonHull = hull;
  14208. exports.polygonContains = contains$1;
  14209. exports.polygonLength = length$2;
  14210. exports.quadtree = quadtree;
  14211. exports.queue = queue;
  14212. exports.randomUniform = uniform;
  14213. exports.randomNormal = normal;
  14214. exports.randomLogNormal = logNormal;
  14215. exports.randomBates = bates;
  14216. exports.randomIrwinHall = irwinHall;
  14217. exports.randomExponential = exponential$1;
  14218. exports.request = request;
  14219. exports.html = html;
  14220. exports.json = json;
  14221. exports.text = text;
  14222. exports.xml = xml;
  14223. exports.csv = csv$1;
  14224. exports.tsv = tsv$1;
  14225. exports.scaleBand = band;
  14226. exports.scalePoint = point$1;
  14227. exports.scaleIdentity = identity$6;
  14228. exports.scaleLinear = linear$2;
  14229. exports.scaleLog = log$1;
  14230. exports.scaleOrdinal = ordinal;
  14231. exports.scaleImplicit = implicit;
  14232. exports.scalePow = pow$1;
  14233. exports.scaleSqrt = sqrt$1;
  14234. exports.scaleQuantile = quantile$$1;
  14235. exports.scaleQuantize = quantize$1;
  14236. exports.scaleThreshold = threshold$1;
  14237. exports.scaleTime = time;
  14238. exports.scaleUtc = utcTime;
  14239. exports.schemeCategory10 = category10;
  14240. exports.schemeCategory20b = category20b;
  14241. exports.schemeCategory20c = category20c;
  14242. exports.schemeCategory20 = category20;
  14243. exports.interpolateCubehelixDefault = cubehelix$3;
  14244. exports.interpolateRainbow = rainbow$1;
  14245. exports.interpolateWarm = warm;
  14246. exports.interpolateCool = cool;
  14247. exports.interpolateViridis = viridis;
  14248. exports.interpolateMagma = magma;
  14249. exports.interpolateInferno = inferno;
  14250. exports.interpolatePlasma = plasma;
  14251. exports.scaleSequential = sequential;
  14252. exports.creator = creator;
  14253. exports.local = local$1;
  14254. exports.matcher = matcher$1;
  14255. exports.mouse = mouse;
  14256. exports.namespace = namespace;
  14257. exports.namespaces = namespaces;
  14258. exports.select = select;
  14259. exports.selectAll = selectAll;
  14260. exports.selection = selection;
  14261. exports.selector = selector;
  14262. exports.selectorAll = selectorAll;
  14263. exports.style = styleValue;
  14264. exports.touch = touch;
  14265. exports.touches = touches;
  14266. exports.window = defaultView;
  14267. exports.customEvent = customEvent;
  14268. exports.arc = arc;
  14269. exports.area = area$2;
  14270. exports.line = line;
  14271. exports.pie = pie;
  14272. exports.radialArea = radialArea;
  14273. exports.radialLine = radialLine$1;
  14274. exports.linkHorizontal = linkHorizontal;
  14275. exports.linkVertical = linkVertical;
  14276. exports.linkRadial = linkRadial;
  14277. exports.symbol = symbol;
  14278. exports.symbols = symbols;
  14279. exports.symbolCircle = circle$2;
  14280. exports.symbolCross = cross$2;
  14281. exports.symbolDiamond = diamond;
  14282. exports.symbolSquare = square;
  14283. exports.symbolStar = star;
  14284. exports.symbolTriangle = triangle;
  14285. exports.symbolWye = wye;
  14286. exports.curveBasisClosed = basisClosed$1;
  14287. exports.curveBasisOpen = basisOpen;
  14288. exports.curveBasis = basis$2;
  14289. exports.curveBundle = bundle;
  14290. exports.curveCardinalClosed = cardinalClosed;
  14291. exports.curveCardinalOpen = cardinalOpen;
  14292. exports.curveCardinal = cardinal;
  14293. exports.curveCatmullRomClosed = catmullRomClosed;
  14294. exports.curveCatmullRomOpen = catmullRomOpen;
  14295. exports.curveCatmullRom = catmullRom;
  14296. exports.curveLinearClosed = linearClosed;
  14297. exports.curveLinear = curveLinear;
  14298. exports.curveMonotoneX = monotoneX;
  14299. exports.curveMonotoneY = monotoneY;
  14300. exports.curveNatural = natural;
  14301. exports.curveStep = step;
  14302. exports.curveStepAfter = stepAfter;
  14303. exports.curveStepBefore = stepBefore;
  14304. exports.stack = stack;
  14305. exports.stackOffsetExpand = expand;
  14306. exports.stackOffsetDiverging = diverging;
  14307. exports.stackOffsetNone = none$1;
  14308. exports.stackOffsetSilhouette = silhouette;
  14309. exports.stackOffsetWiggle = wiggle;
  14310. exports.stackOrderAscending = ascending$2;
  14311. exports.stackOrderDescending = descending$2;
  14312. exports.stackOrderInsideOut = insideOut;
  14313. exports.stackOrderNone = none$2;
  14314. exports.stackOrderReverse = reverse;
  14315. exports.timeInterval = newInterval;
  14316. exports.timeMillisecond = millisecond;
  14317. exports.timeMilliseconds = milliseconds;
  14318. exports.utcMillisecond = millisecond;
  14319. exports.utcMilliseconds = milliseconds;
  14320. exports.timeSecond = second;
  14321. exports.timeSeconds = seconds;
  14322. exports.utcSecond = second;
  14323. exports.utcSeconds = seconds;
  14324. exports.timeMinute = minute;
  14325. exports.timeMinutes = minutes;
  14326. exports.timeHour = hour;
  14327. exports.timeHours = hours;
  14328. exports.timeDay = day;
  14329. exports.timeDays = days;
  14330. exports.timeWeek = sunday;
  14331. exports.timeWeeks = sundays;
  14332. exports.timeSunday = sunday;
  14333. exports.timeSundays = sundays;
  14334. exports.timeMonday = monday;
  14335. exports.timeMondays = mondays;
  14336. exports.timeTuesday = tuesday;
  14337. exports.timeTuesdays = tuesdays;
  14338. exports.timeWednesday = wednesday;
  14339. exports.timeWednesdays = wednesdays;
  14340. exports.timeThursday = thursday;
  14341. exports.timeThursdays = thursdays;
  14342. exports.timeFriday = friday;
  14343. exports.timeFridays = fridays;
  14344. exports.timeSaturday = saturday;
  14345. exports.timeSaturdays = saturdays;
  14346. exports.timeMonth = month;
  14347. exports.timeMonths = months;
  14348. exports.timeYear = year;
  14349. exports.timeYears = years;
  14350. exports.utcMinute = utcMinute;
  14351. exports.utcMinutes = utcMinutes;
  14352. exports.utcHour = utcHour;
  14353. exports.utcHours = utcHours;
  14354. exports.utcDay = utcDay;
  14355. exports.utcDays = utcDays;
  14356. exports.utcWeek = utcSunday;
  14357. exports.utcWeeks = utcSundays;
  14358. exports.utcSunday = utcSunday;
  14359. exports.utcSundays = utcSundays;
  14360. exports.utcMonday = utcMonday;
  14361. exports.utcMondays = utcMondays;
  14362. exports.utcTuesday = utcTuesday;
  14363. exports.utcTuesdays = utcTuesdays;
  14364. exports.utcWednesday = utcWednesday;
  14365. exports.utcWednesdays = utcWednesdays;
  14366. exports.utcThursday = utcThursday;
  14367. exports.utcThursdays = utcThursdays;
  14368. exports.utcFriday = utcFriday;
  14369. exports.utcFridays = utcFridays;
  14370. exports.utcSaturday = utcSaturday;
  14371. exports.utcSaturdays = utcSaturdays;
  14372. exports.utcMonth = utcMonth;
  14373. exports.utcMonths = utcMonths;
  14374. exports.utcYear = utcYear;
  14375. exports.utcYears = utcYears;
  14376. exports.timeFormatDefaultLocale = defaultLocale$1;
  14377. exports.timeFormatLocale = formatLocale$1;
  14378. exports.isoFormat = formatIso;
  14379. exports.isoParse = parseIso;
  14380. exports.now = now;
  14381. exports.timer = timer;
  14382. exports.timerFlush = timerFlush;
  14383. exports.timeout = timeout$1;
  14384. exports.interval = interval$1;
  14385. exports.transition = transition;
  14386. exports.active = active;
  14387. exports.interrupt = interrupt;
  14388. exports.voronoi = voronoi;
  14389. exports.zoom = zoom;
  14390. exports.zoomTransform = transform$1;
  14391. exports.zoomIdentity = identity$8;
  14392. Object.defineProperty(exports, '__esModule', { value: true });
  14393. })));