d3.js 484 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858
  1. // https://d3js.org Version 5.6.0 Copyright 2018 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 = "5.6.0";
  8. function ascending(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function bisector(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. function pairs(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. function cross(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. function descending(a, b) {
  70. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  71. }
  72. function number(x) {
  73. return x === null ? NaN : +x;
  74. }
  75. function variance(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. function deviation(array, f) {
  104. var v = variance(array, f);
  105. return v ? Math.sqrt(v) : v;
  106. }
  107. function extent(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. function constant(x) {
  145. return function() {
  146. return x;
  147. };
  148. }
  149. function identity(x) {
  150. return x;
  151. }
  152. function sequence(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. e5 = Math.sqrt(10),
  164. e2 = Math.sqrt(2);
  165. function ticks(start, stop, count) {
  166. var reverse,
  167. i = -1,
  168. n,
  169. ticks,
  170. step;
  171. stop = +stop, start = +start, count = +count;
  172. if (start === stop && count > 0) return [start];
  173. if (reverse = stop < start) n = start, start = stop, stop = n;
  174. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  175. if (step > 0) {
  176. start = Math.ceil(start / step);
  177. stop = Math.floor(stop / step);
  178. ticks = new Array(n = Math.ceil(stop - start + 1));
  179. while (++i < n) ticks[i] = (start + i) * step;
  180. } else {
  181. start = Math.floor(start * step);
  182. stop = Math.ceil(stop * step);
  183. ticks = new Array(n = Math.ceil(start - stop + 1));
  184. while (++i < n) ticks[i] = (start - i) / step;
  185. }
  186. if (reverse) ticks.reverse();
  187. return ticks;
  188. }
  189. function tickIncrement(start, stop, count) {
  190. var step = (stop - start) / Math.max(0, count),
  191. power = Math.floor(Math.log(step) / Math.LN10),
  192. error = step / Math.pow(10, power);
  193. return power >= 0
  194. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  195. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  196. }
  197. function tickStep(start, stop, count) {
  198. var step0 = Math.abs(stop - start) / Math.max(0, count),
  199. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  200. error = step0 / step1;
  201. if (error >= e10) step1 *= 10;
  202. else if (error >= e5) step1 *= 5;
  203. else if (error >= e2) step1 *= 2;
  204. return stop < start ? -step1 : step1;
  205. }
  206. function thresholdSturges(values) {
  207. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  208. }
  209. function histogram() {
  210. var value = identity,
  211. domain = extent,
  212. threshold = thresholdSturges;
  213. function histogram(data) {
  214. var i,
  215. n = data.length,
  216. x,
  217. values = new Array(n);
  218. for (i = 0; i < n; ++i) {
  219. values[i] = value(data[i], i, data);
  220. }
  221. var xz = domain(values),
  222. x0 = xz[0],
  223. x1 = xz[1],
  224. tz = threshold(values, x0, x1);
  225. // Convert number of thresholds into uniform thresholds.
  226. if (!Array.isArray(tz)) {
  227. tz = tickStep(x0, x1, tz);
  228. tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
  229. }
  230. // Remove any thresholds outside the domain.
  231. var m = tz.length;
  232. while (tz[0] <= x0) tz.shift(), --m;
  233. while (tz[m - 1] > x1) tz.pop(), --m;
  234. var bins = new Array(m + 1),
  235. bin;
  236. // Initialize bins.
  237. for (i = 0; i <= m; ++i) {
  238. bin = bins[i] = [];
  239. bin.x0 = i > 0 ? tz[i - 1] : x0;
  240. bin.x1 = i < m ? tz[i] : x1;
  241. }
  242. // Assign data to bins by value, ignoring any outside the domain.
  243. for (i = 0; i < n; ++i) {
  244. x = values[i];
  245. if (x0 <= x && x <= x1) {
  246. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  247. }
  248. }
  249. return bins;
  250. }
  251. histogram.value = function(_) {
  252. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  253. };
  254. histogram.domain = function(_) {
  255. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  256. };
  257. histogram.thresholds = function(_) {
  258. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  259. };
  260. return histogram;
  261. }
  262. function threshold(values, p, valueof) {
  263. if (valueof == null) valueof = number;
  264. if (!(n = values.length)) return;
  265. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  266. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  267. var n,
  268. i = (n - 1) * p,
  269. i0 = Math.floor(i),
  270. value0 = +valueof(values[i0], i0, values),
  271. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  272. return value0 + (value1 - value0) * (i - i0);
  273. }
  274. function freedmanDiaconis(values, min, max) {
  275. values = map.call(values, number).sort(ascending);
  276. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  277. }
  278. function scott(values, min, max) {
  279. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  280. }
  281. function max(values, valueof) {
  282. var n = values.length,
  283. i = -1,
  284. value,
  285. max;
  286. if (valueof == null) {
  287. while (++i < n) { // Find the first comparable value.
  288. if ((value = values[i]) != null && value >= value) {
  289. max = value;
  290. while (++i < n) { // Compare the remaining values.
  291. if ((value = values[i]) != null && value > max) {
  292. max = value;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. else {
  299. while (++i < n) { // Find the first comparable value.
  300. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  301. max = value;
  302. while (++i < n) { // Compare the remaining values.
  303. if ((value = valueof(values[i], i, values)) != null && value > max) {
  304. max = value;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. return max;
  311. }
  312. function mean(values, valueof) {
  313. var n = values.length,
  314. m = n,
  315. i = -1,
  316. value,
  317. sum = 0;
  318. if (valueof == null) {
  319. while (++i < n) {
  320. if (!isNaN(value = number(values[i]))) sum += value;
  321. else --m;
  322. }
  323. }
  324. else {
  325. while (++i < n) {
  326. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  327. else --m;
  328. }
  329. }
  330. if (m) return sum / m;
  331. }
  332. function median(values, valueof) {
  333. var n = values.length,
  334. i = -1,
  335. value,
  336. numbers = [];
  337. if (valueof == null) {
  338. while (++i < n) {
  339. if (!isNaN(value = number(values[i]))) {
  340. numbers.push(value);
  341. }
  342. }
  343. }
  344. else {
  345. while (++i < n) {
  346. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  347. numbers.push(value);
  348. }
  349. }
  350. }
  351. return threshold(numbers.sort(ascending), 0.5);
  352. }
  353. function merge(arrays) {
  354. var n = arrays.length,
  355. m,
  356. i = -1,
  357. j = 0,
  358. merged,
  359. array;
  360. while (++i < n) j += arrays[i].length;
  361. merged = new Array(j);
  362. while (--n >= 0) {
  363. array = arrays[n];
  364. m = array.length;
  365. while (--m >= 0) {
  366. merged[--j] = array[m];
  367. }
  368. }
  369. return merged;
  370. }
  371. function min(values, valueof) {
  372. var n = values.length,
  373. i = -1,
  374. value,
  375. min;
  376. if (valueof == null) {
  377. while (++i < n) { // Find the first comparable value.
  378. if ((value = values[i]) != null && value >= value) {
  379. min = value;
  380. while (++i < n) { // Compare the remaining values.
  381. if ((value = values[i]) != null && min > value) {
  382. min = value;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. else {
  389. while (++i < n) { // Find the first comparable value.
  390. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  391. min = value;
  392. while (++i < n) { // Compare the remaining values.
  393. if ((value = valueof(values[i], i, values)) != null && min > value) {
  394. min = value;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. return min;
  401. }
  402. function permute(array, indexes) {
  403. var i = indexes.length, permutes = new Array(i);
  404. while (i--) permutes[i] = array[indexes[i]];
  405. return permutes;
  406. }
  407. function scan(values, compare) {
  408. if (!(n = values.length)) return;
  409. var n,
  410. i = 0,
  411. j = 0,
  412. xi,
  413. xj = values[j];
  414. if (compare == null) compare = ascending;
  415. while (++i < n) {
  416. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  417. xj = xi, j = i;
  418. }
  419. }
  420. if (compare(xj, xj) === 0) return j;
  421. }
  422. function shuffle(array, i0, i1) {
  423. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  424. t,
  425. i;
  426. while (m) {
  427. i = Math.random() * m-- | 0;
  428. t = array[m + i0];
  429. array[m + i0] = array[i + i0];
  430. array[i + i0] = t;
  431. }
  432. return array;
  433. }
  434. function sum(values, valueof) {
  435. var n = values.length,
  436. i = -1,
  437. value,
  438. sum = 0;
  439. if (valueof == null) {
  440. while (++i < n) {
  441. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  442. }
  443. }
  444. else {
  445. while (++i < n) {
  446. if (value = +valueof(values[i], i, values)) sum += value;
  447. }
  448. }
  449. return sum;
  450. }
  451. function transpose(matrix) {
  452. if (!(n = matrix.length)) return [];
  453. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  454. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  455. row[j] = matrix[j][i];
  456. }
  457. }
  458. return transpose;
  459. }
  460. function length(d) {
  461. return d.length;
  462. }
  463. function zip() {
  464. return transpose(arguments);
  465. }
  466. var slice$1 = Array.prototype.slice;
  467. function identity$1(x) {
  468. return x;
  469. }
  470. var top = 1,
  471. right = 2,
  472. bottom = 3,
  473. left = 4,
  474. epsilon = 1e-6;
  475. function translateX(x) {
  476. return "translate(" + (x + 0.5) + ",0)";
  477. }
  478. function translateY(y) {
  479. return "translate(0," + (y + 0.5) + ")";
  480. }
  481. function number$1(scale) {
  482. return function(d) {
  483. return +scale(d);
  484. };
  485. }
  486. function center(scale) {
  487. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  488. if (scale.round()) offset = Math.round(offset);
  489. return function(d) {
  490. return +scale(d) + offset;
  491. };
  492. }
  493. function entering() {
  494. return !this.__axis;
  495. }
  496. function axis(orient, scale) {
  497. var tickArguments = [],
  498. tickValues = null,
  499. tickFormat = null,
  500. tickSizeInner = 6,
  501. tickSizeOuter = 6,
  502. tickPadding = 3,
  503. k = orient === top || orient === left ? -1 : 1,
  504. x = orient === left || orient === right ? "x" : "y",
  505. transform = orient === top || orient === bottom ? translateX : translateY;
  506. function axis(context) {
  507. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  508. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  509. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  510. range = scale.range(),
  511. range0 = +range[0] + 0.5,
  512. range1 = +range[range.length - 1] + 0.5,
  513. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  514. selection = context.selection ? context.selection() : context,
  515. path = selection.selectAll(".domain").data([null]),
  516. tick = selection.selectAll(".tick").data(values, scale).order(),
  517. tickExit = tick.exit(),
  518. tickEnter = tick.enter().append("g").attr("class", "tick"),
  519. line = tick.select("line"),
  520. text = tick.select("text");
  521. path = path.merge(path.enter().insert("path", ".tick")
  522. .attr("class", "domain")
  523. .attr("stroke", "currentColor"));
  524. tick = tick.merge(tickEnter);
  525. line = line.merge(tickEnter.append("line")
  526. .attr("stroke", "currentColor")
  527. .attr(x + "2", k * tickSizeInner));
  528. text = text.merge(tickEnter.append("text")
  529. .attr("fill", "currentColor")
  530. .attr(x, k * spacing)
  531. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  532. if (context !== selection) {
  533. path = path.transition(context);
  534. tick = tick.transition(context);
  535. line = line.transition(context);
  536. text = text.transition(context);
  537. tickExit = tickExit.transition(context)
  538. .attr("opacity", epsilon)
  539. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  540. tickEnter
  541. .attr("opacity", epsilon)
  542. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  543. }
  544. tickExit.remove();
  545. path
  546. .attr("d", orient === left || orient == right
  547. ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
  548. : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
  549. tick
  550. .attr("opacity", 1)
  551. .attr("transform", function(d) { return transform(position(d)); });
  552. line
  553. .attr(x + "2", k * tickSizeInner);
  554. text
  555. .attr(x, k * spacing)
  556. .text(format);
  557. selection.filter(entering)
  558. .attr("fill", "none")
  559. .attr("font-size", 10)
  560. .attr("font-family", "sans-serif")
  561. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  562. selection
  563. .each(function() { this.__axis = position; });
  564. }
  565. axis.scale = function(_) {
  566. return arguments.length ? (scale = _, axis) : scale;
  567. };
  568. axis.ticks = function() {
  569. return tickArguments = slice$1.call(arguments), axis;
  570. };
  571. axis.tickArguments = function(_) {
  572. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  573. };
  574. axis.tickValues = function(_) {
  575. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  576. };
  577. axis.tickFormat = function(_) {
  578. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  579. };
  580. axis.tickSize = function(_) {
  581. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  582. };
  583. axis.tickSizeInner = function(_) {
  584. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  585. };
  586. axis.tickSizeOuter = function(_) {
  587. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  588. };
  589. axis.tickPadding = function(_) {
  590. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  591. };
  592. return axis;
  593. }
  594. function axisTop(scale) {
  595. return axis(top, scale);
  596. }
  597. function axisRight(scale) {
  598. return axis(right, scale);
  599. }
  600. function axisBottom(scale) {
  601. return axis(bottom, scale);
  602. }
  603. function axisLeft(scale) {
  604. return axis(left, scale);
  605. }
  606. var noop = {value: function() {}};
  607. function dispatch() {
  608. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  609. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  610. _[t] = [];
  611. }
  612. return new Dispatch(_);
  613. }
  614. function Dispatch(_) {
  615. this._ = _;
  616. }
  617. function parseTypenames(typenames, types) {
  618. return typenames.trim().split(/^|\s+/).map(function(t) {
  619. var name = "", i = t.indexOf(".");
  620. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  621. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  622. return {type: t, name: name};
  623. });
  624. }
  625. Dispatch.prototype = dispatch.prototype = {
  626. constructor: Dispatch,
  627. on: function(typename, callback) {
  628. var _ = this._,
  629. T = parseTypenames(typename + "", _),
  630. t,
  631. i = -1,
  632. n = T.length;
  633. // If no callback was specified, return the callback of the given type and name.
  634. if (arguments.length < 2) {
  635. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  636. return;
  637. }
  638. // If a type was specified, set the callback for the given type and name.
  639. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  640. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  641. while (++i < n) {
  642. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  643. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  644. }
  645. return this;
  646. },
  647. copy: function() {
  648. var copy = {}, _ = this._;
  649. for (var t in _) copy[t] = _[t].slice();
  650. return new Dispatch(copy);
  651. },
  652. call: function(type, that) {
  653. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  654. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  655. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  656. },
  657. apply: function(type, that, args) {
  658. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  659. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  660. }
  661. };
  662. function get(type, name) {
  663. for (var i = 0, n = type.length, c; i < n; ++i) {
  664. if ((c = type[i]).name === name) {
  665. return c.value;
  666. }
  667. }
  668. }
  669. function set(type, name, callback) {
  670. for (var i = 0, n = type.length; i < n; ++i) {
  671. if (type[i].name === name) {
  672. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  673. break;
  674. }
  675. }
  676. if (callback != null) type.push({name: name, value: callback});
  677. return type;
  678. }
  679. var xhtml = "http://www.w3.org/1999/xhtml";
  680. var namespaces = {
  681. svg: "http://www.w3.org/2000/svg",
  682. xhtml: xhtml,
  683. xlink: "http://www.w3.org/1999/xlink",
  684. xml: "http://www.w3.org/XML/1998/namespace",
  685. xmlns: "http://www.w3.org/2000/xmlns/"
  686. };
  687. function namespace(name) {
  688. var prefix = name += "", i = prefix.indexOf(":");
  689. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  690. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  691. }
  692. function creatorInherit(name) {
  693. return function() {
  694. var document = this.ownerDocument,
  695. uri = this.namespaceURI;
  696. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  697. ? document.createElement(name)
  698. : document.createElementNS(uri, name);
  699. };
  700. }
  701. function creatorFixed(fullname) {
  702. return function() {
  703. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  704. };
  705. }
  706. function creator(name) {
  707. var fullname = namespace(name);
  708. return (fullname.local
  709. ? creatorFixed
  710. : creatorInherit)(fullname);
  711. }
  712. function none() {}
  713. function selector(selector) {
  714. return selector == null ? none : function() {
  715. return this.querySelector(selector);
  716. };
  717. }
  718. function selection_select(select) {
  719. if (typeof select !== "function") select = selector(select);
  720. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  721. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  722. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  723. if ("__data__" in node) subnode.__data__ = node.__data__;
  724. subgroup[i] = subnode;
  725. }
  726. }
  727. }
  728. return new Selection(subgroups, this._parents);
  729. }
  730. function empty() {
  731. return [];
  732. }
  733. function selectorAll(selector) {
  734. return selector == null ? empty : function() {
  735. return this.querySelectorAll(selector);
  736. };
  737. }
  738. function selection_selectAll(select) {
  739. if (typeof select !== "function") select = selectorAll(select);
  740. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  741. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  742. if (node = group[i]) {
  743. subgroups.push(select.call(node, node.__data__, i, group));
  744. parents.push(node);
  745. }
  746. }
  747. }
  748. return new Selection(subgroups, parents);
  749. }
  750. var matcher = function(selector) {
  751. return function() {
  752. return this.matches(selector);
  753. };
  754. };
  755. if (typeof document !== "undefined") {
  756. var element = document.documentElement;
  757. if (!element.matches) {
  758. var vendorMatches = element.webkitMatchesSelector
  759. || element.msMatchesSelector
  760. || element.mozMatchesSelector
  761. || element.oMatchesSelector;
  762. matcher = function(selector) {
  763. return function() {
  764. return vendorMatches.call(this, selector);
  765. };
  766. };
  767. }
  768. }
  769. var matcher$1 = matcher;
  770. function selection_filter(match) {
  771. if (typeof match !== "function") match = matcher$1(match);
  772. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  773. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  774. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  775. subgroup.push(node);
  776. }
  777. }
  778. }
  779. return new Selection(subgroups, this._parents);
  780. }
  781. function sparse(update) {
  782. return new Array(update.length);
  783. }
  784. function selection_enter() {
  785. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  786. }
  787. function EnterNode(parent, datum) {
  788. this.ownerDocument = parent.ownerDocument;
  789. this.namespaceURI = parent.namespaceURI;
  790. this._next = null;
  791. this._parent = parent;
  792. this.__data__ = datum;
  793. }
  794. EnterNode.prototype = {
  795. constructor: EnterNode,
  796. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  797. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  798. querySelector: function(selector) { return this._parent.querySelector(selector); },
  799. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  800. };
  801. function constant$1(x) {
  802. return function() {
  803. return x;
  804. };
  805. }
  806. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  807. function bindIndex(parent, group, enter, update, exit, data) {
  808. var i = 0,
  809. node,
  810. groupLength = group.length,
  811. dataLength = data.length;
  812. // Put any non-null nodes that fit into update.
  813. // Put any null nodes into enter.
  814. // Put any remaining data into enter.
  815. for (; i < dataLength; ++i) {
  816. if (node = group[i]) {
  817. node.__data__ = data[i];
  818. update[i] = node;
  819. } else {
  820. enter[i] = new EnterNode(parent, data[i]);
  821. }
  822. }
  823. // Put any non-null nodes that don’t fit into exit.
  824. for (; i < groupLength; ++i) {
  825. if (node = group[i]) {
  826. exit[i] = node;
  827. }
  828. }
  829. }
  830. function bindKey(parent, group, enter, update, exit, data, key) {
  831. var i,
  832. node,
  833. nodeByKeyValue = {},
  834. groupLength = group.length,
  835. dataLength = data.length,
  836. keyValues = new Array(groupLength),
  837. keyValue;
  838. // Compute the key for each node.
  839. // If multiple nodes have the same key, the duplicates are added to exit.
  840. for (i = 0; i < groupLength; ++i) {
  841. if (node = group[i]) {
  842. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  843. if (keyValue in nodeByKeyValue) {
  844. exit[i] = node;
  845. } else {
  846. nodeByKeyValue[keyValue] = node;
  847. }
  848. }
  849. }
  850. // Compute the key for each datum.
  851. // If there a node associated with this key, join and add it to update.
  852. // If there is not (or the key is a duplicate), add it to enter.
  853. for (i = 0; i < dataLength; ++i) {
  854. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  855. if (node = nodeByKeyValue[keyValue]) {
  856. update[i] = node;
  857. node.__data__ = data[i];
  858. nodeByKeyValue[keyValue] = null;
  859. } else {
  860. enter[i] = new EnterNode(parent, data[i]);
  861. }
  862. }
  863. // Add any remaining nodes that were not bound to data to exit.
  864. for (i = 0; i < groupLength; ++i) {
  865. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  866. exit[i] = node;
  867. }
  868. }
  869. }
  870. function selection_data(value, key) {
  871. if (!value) {
  872. data = new Array(this.size()), j = -1;
  873. this.each(function(d) { data[++j] = d; });
  874. return data;
  875. }
  876. var bind = key ? bindKey : bindIndex,
  877. parents = this._parents,
  878. groups = this._groups;
  879. if (typeof value !== "function") value = constant$1(value);
  880. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  881. var parent = parents[j],
  882. group = groups[j],
  883. groupLength = group.length,
  884. data = value.call(parent, parent && parent.__data__, j, parents),
  885. dataLength = data.length,
  886. enterGroup = enter[j] = new Array(dataLength),
  887. updateGroup = update[j] = new Array(dataLength),
  888. exitGroup = exit[j] = new Array(groupLength);
  889. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  890. // Now connect the enter nodes to their following update node, such that
  891. // appendChild can insert the materialized enter node before this node,
  892. // rather than at the end of the parent node.
  893. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  894. if (previous = enterGroup[i0]) {
  895. if (i0 >= i1) i1 = i0 + 1;
  896. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  897. previous._next = next || null;
  898. }
  899. }
  900. }
  901. update = new Selection(update, parents);
  902. update._enter = enter;
  903. update._exit = exit;
  904. return update;
  905. }
  906. function selection_exit() {
  907. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  908. }
  909. function selection_merge(selection$$1) {
  910. for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  911. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  912. if (node = group0[i] || group1[i]) {
  913. merge[i] = node;
  914. }
  915. }
  916. }
  917. for (; j < m0; ++j) {
  918. merges[j] = groups0[j];
  919. }
  920. return new Selection(merges, this._parents);
  921. }
  922. function selection_order() {
  923. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  924. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  925. if (node = group[i]) {
  926. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  927. next = node;
  928. }
  929. }
  930. }
  931. return this;
  932. }
  933. function selection_sort(compare) {
  934. if (!compare) compare = ascending$1;
  935. function compareNode(a, b) {
  936. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  937. }
  938. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  939. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  940. if (node = group[i]) {
  941. sortgroup[i] = node;
  942. }
  943. }
  944. sortgroup.sort(compareNode);
  945. }
  946. return new Selection(sortgroups, this._parents).order();
  947. }
  948. function ascending$1(a, b) {
  949. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  950. }
  951. function selection_call() {
  952. var callback = arguments[0];
  953. arguments[0] = this;
  954. callback.apply(null, arguments);
  955. return this;
  956. }
  957. function selection_nodes() {
  958. var nodes = new Array(this.size()), i = -1;
  959. this.each(function() { nodes[++i] = this; });
  960. return nodes;
  961. }
  962. function selection_node() {
  963. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  964. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  965. var node = group[i];
  966. if (node) return node;
  967. }
  968. }
  969. return null;
  970. }
  971. function selection_size() {
  972. var size = 0;
  973. this.each(function() { ++size; });
  974. return size;
  975. }
  976. function selection_empty() {
  977. return !this.node();
  978. }
  979. function selection_each(callback) {
  980. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  981. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  982. if (node = group[i]) callback.call(node, node.__data__, i, group);
  983. }
  984. }
  985. return this;
  986. }
  987. function attrRemove(name) {
  988. return function() {
  989. this.removeAttribute(name);
  990. };
  991. }
  992. function attrRemoveNS(fullname) {
  993. return function() {
  994. this.removeAttributeNS(fullname.space, fullname.local);
  995. };
  996. }
  997. function attrConstant(name, value) {
  998. return function() {
  999. this.setAttribute(name, value);
  1000. };
  1001. }
  1002. function attrConstantNS(fullname, value) {
  1003. return function() {
  1004. this.setAttributeNS(fullname.space, fullname.local, value);
  1005. };
  1006. }
  1007. function attrFunction(name, value) {
  1008. return function() {
  1009. var v = value.apply(this, arguments);
  1010. if (v == null) this.removeAttribute(name);
  1011. else this.setAttribute(name, v);
  1012. };
  1013. }
  1014. function attrFunctionNS(fullname, value) {
  1015. return function() {
  1016. var v = value.apply(this, arguments);
  1017. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1018. else this.setAttributeNS(fullname.space, fullname.local, v);
  1019. };
  1020. }
  1021. function selection_attr(name, value) {
  1022. var fullname = namespace(name);
  1023. if (arguments.length < 2) {
  1024. var node = this.node();
  1025. return fullname.local
  1026. ? node.getAttributeNS(fullname.space, fullname.local)
  1027. : node.getAttribute(fullname);
  1028. }
  1029. return this.each((value == null
  1030. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1031. ? (fullname.local ? attrFunctionNS : attrFunction)
  1032. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1033. }
  1034. function defaultView(node) {
  1035. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1036. || (node.document && node) // node is a Window
  1037. || node.defaultView; // node is a Document
  1038. }
  1039. function styleRemove(name) {
  1040. return function() {
  1041. this.style.removeProperty(name);
  1042. };
  1043. }
  1044. function styleConstant(name, value, priority) {
  1045. return function() {
  1046. this.style.setProperty(name, value, priority);
  1047. };
  1048. }
  1049. function styleFunction(name, value, priority) {
  1050. return function() {
  1051. var v = value.apply(this, arguments);
  1052. if (v == null) this.style.removeProperty(name);
  1053. else this.style.setProperty(name, v, priority);
  1054. };
  1055. }
  1056. function selection_style(name, value, priority) {
  1057. return arguments.length > 1
  1058. ? this.each((value == null
  1059. ? styleRemove : typeof value === "function"
  1060. ? styleFunction
  1061. : styleConstant)(name, value, priority == null ? "" : priority))
  1062. : styleValue(this.node(), name);
  1063. }
  1064. function styleValue(node, name) {
  1065. return node.style.getPropertyValue(name)
  1066. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1067. }
  1068. function propertyRemove(name) {
  1069. return function() {
  1070. delete this[name];
  1071. };
  1072. }
  1073. function propertyConstant(name, value) {
  1074. return function() {
  1075. this[name] = value;
  1076. };
  1077. }
  1078. function propertyFunction(name, value) {
  1079. return function() {
  1080. var v = value.apply(this, arguments);
  1081. if (v == null) delete this[name];
  1082. else this[name] = v;
  1083. };
  1084. }
  1085. function selection_property(name, value) {
  1086. return arguments.length > 1
  1087. ? this.each((value == null
  1088. ? propertyRemove : typeof value === "function"
  1089. ? propertyFunction
  1090. : propertyConstant)(name, value))
  1091. : this.node()[name];
  1092. }
  1093. function classArray(string) {
  1094. return string.trim().split(/^|\s+/);
  1095. }
  1096. function classList(node) {
  1097. return node.classList || new ClassList(node);
  1098. }
  1099. function ClassList(node) {
  1100. this._node = node;
  1101. this._names = classArray(node.getAttribute("class") || "");
  1102. }
  1103. ClassList.prototype = {
  1104. add: function(name) {
  1105. var i = this._names.indexOf(name);
  1106. if (i < 0) {
  1107. this._names.push(name);
  1108. this._node.setAttribute("class", this._names.join(" "));
  1109. }
  1110. },
  1111. remove: function(name) {
  1112. var i = this._names.indexOf(name);
  1113. if (i >= 0) {
  1114. this._names.splice(i, 1);
  1115. this._node.setAttribute("class", this._names.join(" "));
  1116. }
  1117. },
  1118. contains: function(name) {
  1119. return this._names.indexOf(name) >= 0;
  1120. }
  1121. };
  1122. function classedAdd(node, names) {
  1123. var list = classList(node), i = -1, n = names.length;
  1124. while (++i < n) list.add(names[i]);
  1125. }
  1126. function classedRemove(node, names) {
  1127. var list = classList(node), i = -1, n = names.length;
  1128. while (++i < n) list.remove(names[i]);
  1129. }
  1130. function classedTrue(names) {
  1131. return function() {
  1132. classedAdd(this, names);
  1133. };
  1134. }
  1135. function classedFalse(names) {
  1136. return function() {
  1137. classedRemove(this, names);
  1138. };
  1139. }
  1140. function classedFunction(names, value) {
  1141. return function() {
  1142. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1143. };
  1144. }
  1145. function selection_classed(name, value) {
  1146. var names = classArray(name + "");
  1147. if (arguments.length < 2) {
  1148. var list = classList(this.node()), i = -1, n = names.length;
  1149. while (++i < n) if (!list.contains(names[i])) return false;
  1150. return true;
  1151. }
  1152. return this.each((typeof value === "function"
  1153. ? classedFunction : value
  1154. ? classedTrue
  1155. : classedFalse)(names, value));
  1156. }
  1157. function textRemove() {
  1158. this.textContent = "";
  1159. }
  1160. function textConstant(value) {
  1161. return function() {
  1162. this.textContent = value;
  1163. };
  1164. }
  1165. function textFunction(value) {
  1166. return function() {
  1167. var v = value.apply(this, arguments);
  1168. this.textContent = v == null ? "" : v;
  1169. };
  1170. }
  1171. function selection_text(value) {
  1172. return arguments.length
  1173. ? this.each(value == null
  1174. ? textRemove : (typeof value === "function"
  1175. ? textFunction
  1176. : textConstant)(value))
  1177. : this.node().textContent;
  1178. }
  1179. function htmlRemove() {
  1180. this.innerHTML = "";
  1181. }
  1182. function htmlConstant(value) {
  1183. return function() {
  1184. this.innerHTML = value;
  1185. };
  1186. }
  1187. function htmlFunction(value) {
  1188. return function() {
  1189. var v = value.apply(this, arguments);
  1190. this.innerHTML = v == null ? "" : v;
  1191. };
  1192. }
  1193. function selection_html(value) {
  1194. return arguments.length
  1195. ? this.each(value == null
  1196. ? htmlRemove : (typeof value === "function"
  1197. ? htmlFunction
  1198. : htmlConstant)(value))
  1199. : this.node().innerHTML;
  1200. }
  1201. function raise() {
  1202. if (this.nextSibling) this.parentNode.appendChild(this);
  1203. }
  1204. function selection_raise() {
  1205. return this.each(raise);
  1206. }
  1207. function lower() {
  1208. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1209. }
  1210. function selection_lower() {
  1211. return this.each(lower);
  1212. }
  1213. function selection_append(name) {
  1214. var create = typeof name === "function" ? name : creator(name);
  1215. return this.select(function() {
  1216. return this.appendChild(create.apply(this, arguments));
  1217. });
  1218. }
  1219. function constantNull() {
  1220. return null;
  1221. }
  1222. function selection_insert(name, before) {
  1223. var create = typeof name === "function" ? name : creator(name),
  1224. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1225. return this.select(function() {
  1226. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1227. });
  1228. }
  1229. function remove() {
  1230. var parent = this.parentNode;
  1231. if (parent) parent.removeChild(this);
  1232. }
  1233. function selection_remove() {
  1234. return this.each(remove);
  1235. }
  1236. function selection_cloneShallow() {
  1237. return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
  1238. }
  1239. function selection_cloneDeep() {
  1240. return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
  1241. }
  1242. function selection_clone(deep) {
  1243. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  1244. }
  1245. function selection_datum(value) {
  1246. return arguments.length
  1247. ? this.property("__data__", value)
  1248. : this.node().__data__;
  1249. }
  1250. var filterEvents = {};
  1251. exports.event = null;
  1252. if (typeof document !== "undefined") {
  1253. var element$1 = document.documentElement;
  1254. if (!("onmouseenter" in element$1)) {
  1255. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  1256. }
  1257. }
  1258. function filterContextListener(listener, index, group) {
  1259. listener = contextListener(listener, index, group);
  1260. return function(event) {
  1261. var related = event.relatedTarget;
  1262. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  1263. listener.call(this, event);
  1264. }
  1265. };
  1266. }
  1267. function contextListener(listener, index, group) {
  1268. return function(event1) {
  1269. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  1270. exports.event = event1;
  1271. try {
  1272. listener.call(this, this.__data__, index, group);
  1273. } finally {
  1274. exports.event = event0;
  1275. }
  1276. };
  1277. }
  1278. function parseTypenames$1(typenames) {
  1279. return typenames.trim().split(/^|\s+/).map(function(t) {
  1280. var name = "", i = t.indexOf(".");
  1281. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1282. return {type: t, name: name};
  1283. });
  1284. }
  1285. function onRemove(typename) {
  1286. return function() {
  1287. var on = this.__on;
  1288. if (!on) return;
  1289. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  1290. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  1291. this.removeEventListener(o.type, o.listener, o.capture);
  1292. } else {
  1293. on[++i] = o;
  1294. }
  1295. }
  1296. if (++i) on.length = i;
  1297. else delete this.__on;
  1298. };
  1299. }
  1300. function onAdd(typename, value, capture) {
  1301. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  1302. return function(d, i, group) {
  1303. var on = this.__on, o, listener = wrap(value, i, group);
  1304. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  1305. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  1306. this.removeEventListener(o.type, o.listener, o.capture);
  1307. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  1308. o.value = value;
  1309. return;
  1310. }
  1311. }
  1312. this.addEventListener(typename.type, listener, capture);
  1313. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  1314. if (!on) this.__on = [o];
  1315. else on.push(o);
  1316. };
  1317. }
  1318. function selection_on(typename, value, capture) {
  1319. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  1320. if (arguments.length < 2) {
  1321. var on = this.node().__on;
  1322. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  1323. for (i = 0, o = on[j]; i < n; ++i) {
  1324. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  1325. return o.value;
  1326. }
  1327. }
  1328. }
  1329. return;
  1330. }
  1331. on = value ? onAdd : onRemove;
  1332. if (capture == null) capture = false;
  1333. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  1334. return this;
  1335. }
  1336. function customEvent(event1, listener, that, args) {
  1337. var event0 = exports.event;
  1338. event1.sourceEvent = exports.event;
  1339. exports.event = event1;
  1340. try {
  1341. return listener.apply(that, args);
  1342. } finally {
  1343. exports.event = event0;
  1344. }
  1345. }
  1346. function dispatchEvent(node, type, params) {
  1347. var window = defaultView(node),
  1348. event = window.CustomEvent;
  1349. if (typeof event === "function") {
  1350. event = new event(type, params);
  1351. } else {
  1352. event = window.document.createEvent("Event");
  1353. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1354. else event.initEvent(type, false, false);
  1355. }
  1356. node.dispatchEvent(event);
  1357. }
  1358. function dispatchConstant(type, params) {
  1359. return function() {
  1360. return dispatchEvent(this, type, params);
  1361. };
  1362. }
  1363. function dispatchFunction(type, params) {
  1364. return function() {
  1365. return dispatchEvent(this, type, params.apply(this, arguments));
  1366. };
  1367. }
  1368. function selection_dispatch(type, params) {
  1369. return this.each((typeof params === "function"
  1370. ? dispatchFunction
  1371. : dispatchConstant)(type, params));
  1372. }
  1373. var root = [null];
  1374. function Selection(groups, parents) {
  1375. this._groups = groups;
  1376. this._parents = parents;
  1377. }
  1378. function selection() {
  1379. return new Selection([[document.documentElement]], root);
  1380. }
  1381. Selection.prototype = selection.prototype = {
  1382. constructor: Selection,
  1383. select: selection_select,
  1384. selectAll: selection_selectAll,
  1385. filter: selection_filter,
  1386. data: selection_data,
  1387. enter: selection_enter,
  1388. exit: selection_exit,
  1389. merge: selection_merge,
  1390. order: selection_order,
  1391. sort: selection_sort,
  1392. call: selection_call,
  1393. nodes: selection_nodes,
  1394. node: selection_node,
  1395. size: selection_size,
  1396. empty: selection_empty,
  1397. each: selection_each,
  1398. attr: selection_attr,
  1399. style: selection_style,
  1400. property: selection_property,
  1401. classed: selection_classed,
  1402. text: selection_text,
  1403. html: selection_html,
  1404. raise: selection_raise,
  1405. lower: selection_lower,
  1406. append: selection_append,
  1407. insert: selection_insert,
  1408. remove: selection_remove,
  1409. clone: selection_clone,
  1410. datum: selection_datum,
  1411. on: selection_on,
  1412. dispatch: selection_dispatch
  1413. };
  1414. function select(selector) {
  1415. return typeof selector === "string"
  1416. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1417. : new Selection([[selector]], root);
  1418. }
  1419. function create(name) {
  1420. return select(creator(name).call(document.documentElement));
  1421. }
  1422. var nextId = 0;
  1423. function local() {
  1424. return new Local;
  1425. }
  1426. function Local() {
  1427. this._ = "@" + (++nextId).toString(36);
  1428. }
  1429. Local.prototype = local.prototype = {
  1430. constructor: Local,
  1431. get: function(node) {
  1432. var id = this._;
  1433. while (!(id in node)) if (!(node = node.parentNode)) return;
  1434. return node[id];
  1435. },
  1436. set: function(node, value) {
  1437. return node[this._] = value;
  1438. },
  1439. remove: function(node) {
  1440. return this._ in node && delete node[this._];
  1441. },
  1442. toString: function() {
  1443. return this._;
  1444. }
  1445. };
  1446. function sourceEvent() {
  1447. var current = exports.event, source;
  1448. while (source = current.sourceEvent) current = source;
  1449. return current;
  1450. }
  1451. function point(node, event) {
  1452. var svg = node.ownerSVGElement || node;
  1453. if (svg.createSVGPoint) {
  1454. var point = svg.createSVGPoint();
  1455. point.x = event.clientX, point.y = event.clientY;
  1456. point = point.matrixTransform(node.getScreenCTM().inverse());
  1457. return [point.x, point.y];
  1458. }
  1459. var rect = node.getBoundingClientRect();
  1460. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  1461. }
  1462. function mouse(node) {
  1463. var event = sourceEvent();
  1464. if (event.changedTouches) event = event.changedTouches[0];
  1465. return point(node, event);
  1466. }
  1467. function selectAll(selector) {
  1468. return typeof selector === "string"
  1469. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1470. : new Selection([selector == null ? [] : selector], root);
  1471. }
  1472. function touch(node, touches, identifier) {
  1473. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1474. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1475. if ((touch = touches[i]).identifier === identifier) {
  1476. return point(node, touch);
  1477. }
  1478. }
  1479. return null;
  1480. }
  1481. function touches(node, touches) {
  1482. if (touches == null) touches = sourceEvent().touches;
  1483. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1484. points[i] = point(node, touches[i]);
  1485. }
  1486. return points;
  1487. }
  1488. function nopropagation() {
  1489. exports.event.stopImmediatePropagation();
  1490. }
  1491. function noevent() {
  1492. exports.event.preventDefault();
  1493. exports.event.stopImmediatePropagation();
  1494. }
  1495. function dragDisable(view) {
  1496. var root = view.document.documentElement,
  1497. selection$$1 = select(view).on("dragstart.drag", noevent, true);
  1498. if ("onselectstart" in root) {
  1499. selection$$1.on("selectstart.drag", noevent, true);
  1500. } else {
  1501. root.__noselect = root.style.MozUserSelect;
  1502. root.style.MozUserSelect = "none";
  1503. }
  1504. }
  1505. function yesdrag(view, noclick) {
  1506. var root = view.document.documentElement,
  1507. selection$$1 = select(view).on("dragstart.drag", null);
  1508. if (noclick) {
  1509. selection$$1.on("click.drag", noevent, true);
  1510. setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
  1511. }
  1512. if ("onselectstart" in root) {
  1513. selection$$1.on("selectstart.drag", null);
  1514. } else {
  1515. root.style.MozUserSelect = root.__noselect;
  1516. delete root.__noselect;
  1517. }
  1518. }
  1519. function constant$2(x) {
  1520. return function() {
  1521. return x;
  1522. };
  1523. }
  1524. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1525. this.target = target;
  1526. this.type = type;
  1527. this.subject = subject;
  1528. this.identifier = id;
  1529. this.active = active;
  1530. this.x = x;
  1531. this.y = y;
  1532. this.dx = dx;
  1533. this.dy = dy;
  1534. this._ = dispatch;
  1535. }
  1536. DragEvent.prototype.on = function() {
  1537. var value = this._.on.apply(this._, arguments);
  1538. return value === this._ ? this : value;
  1539. };
  1540. // Ignore right-click, since that should open the context menu.
  1541. function defaultFilter() {
  1542. return !exports.event.button;
  1543. }
  1544. function defaultContainer() {
  1545. return this.parentNode;
  1546. }
  1547. function defaultSubject(d) {
  1548. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1549. }
  1550. function defaultTouchable() {
  1551. return "ontouchstart" in this;
  1552. }
  1553. function drag() {
  1554. var filter = defaultFilter,
  1555. container = defaultContainer,
  1556. subject = defaultSubject,
  1557. touchable = defaultTouchable,
  1558. gestures = {},
  1559. listeners = dispatch("start", "drag", "end"),
  1560. active = 0,
  1561. mousedownx,
  1562. mousedowny,
  1563. mousemoving,
  1564. touchending,
  1565. clickDistance2 = 0;
  1566. function drag(selection$$1) {
  1567. selection$$1
  1568. .on("mousedown.drag", mousedowned)
  1569. .filter(touchable)
  1570. .on("touchstart.drag", touchstarted)
  1571. .on("touchmove.drag", touchmoved)
  1572. .on("touchend.drag touchcancel.drag", touchended)
  1573. .style("touch-action", "none")
  1574. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1575. }
  1576. function mousedowned() {
  1577. if (touchending || !filter.apply(this, arguments)) return;
  1578. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1579. if (!gesture) return;
  1580. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1581. dragDisable(exports.event.view);
  1582. nopropagation();
  1583. mousemoving = false;
  1584. mousedownx = exports.event.clientX;
  1585. mousedowny = exports.event.clientY;
  1586. gesture("start");
  1587. }
  1588. function mousemoved() {
  1589. noevent();
  1590. if (!mousemoving) {
  1591. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1592. mousemoving = dx * dx + dy * dy > clickDistance2;
  1593. }
  1594. gestures.mouse("drag");
  1595. }
  1596. function mouseupped() {
  1597. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1598. yesdrag(exports.event.view, mousemoving);
  1599. noevent();
  1600. gestures.mouse("end");
  1601. }
  1602. function touchstarted() {
  1603. if (!filter.apply(this, arguments)) return;
  1604. var touches$$1 = exports.event.changedTouches,
  1605. c = container.apply(this, arguments),
  1606. n = touches$$1.length, i, gesture;
  1607. for (i = 0; i < n; ++i) {
  1608. if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
  1609. nopropagation();
  1610. gesture("start");
  1611. }
  1612. }
  1613. }
  1614. function touchmoved() {
  1615. var touches$$1 = exports.event.changedTouches,
  1616. n = touches$$1.length, i, gesture;
  1617. for (i = 0; i < n; ++i) {
  1618. if (gesture = gestures[touches$$1[i].identifier]) {
  1619. noevent();
  1620. gesture("drag");
  1621. }
  1622. }
  1623. }
  1624. function touchended() {
  1625. var touches$$1 = exports.event.changedTouches,
  1626. n = touches$$1.length, i, gesture;
  1627. if (touchending) clearTimeout(touchending);
  1628. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1629. for (i = 0; i < n; ++i) {
  1630. if (gesture = gestures[touches$$1[i].identifier]) {
  1631. nopropagation();
  1632. gesture("end");
  1633. }
  1634. }
  1635. }
  1636. function beforestart(id, container, point$$1, that, args) {
  1637. var p = point$$1(container, id), s, dx, dy,
  1638. sublisteners = listeners.copy();
  1639. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1640. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1641. dx = s.x - p[0] || 0;
  1642. dy = s.y - p[1] || 0;
  1643. return true;
  1644. })) return;
  1645. return function gesture(type) {
  1646. var p0 = p, n;
  1647. switch (type) {
  1648. case "start": gestures[id] = gesture, n = active++; break;
  1649. case "end": delete gestures[id], --active; // nobreak
  1650. case "drag": p = point$$1(container, id), n = active; break;
  1651. }
  1652. 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]);
  1653. };
  1654. }
  1655. drag.filter = function(_) {
  1656. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1657. };
  1658. drag.container = function(_) {
  1659. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1660. };
  1661. drag.subject = function(_) {
  1662. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1663. };
  1664. drag.touchable = function(_) {
  1665. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  1666. };
  1667. drag.on = function() {
  1668. var value = listeners.on.apply(listeners, arguments);
  1669. return value === listeners ? drag : value;
  1670. };
  1671. drag.clickDistance = function(_) {
  1672. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1673. };
  1674. return drag;
  1675. }
  1676. function define(constructor, factory, prototype) {
  1677. constructor.prototype = factory.prototype = prototype;
  1678. prototype.constructor = constructor;
  1679. }
  1680. function extend(parent, definition) {
  1681. var prototype = Object.create(parent.prototype);
  1682. for (var key in definition) prototype[key] = definition[key];
  1683. return prototype;
  1684. }
  1685. function Color() {}
  1686. var darker = 0.7;
  1687. var brighter = 1 / darker;
  1688. var reI = "\\s*([+-]?\\d+)\\s*",
  1689. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  1690. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  1691. reHex3 = /^#([0-9a-f]{3})$/,
  1692. reHex6 = /^#([0-9a-f]{6})$/,
  1693. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  1694. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  1695. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  1696. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  1697. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  1698. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1699. var named = {
  1700. aliceblue: 0xf0f8ff,
  1701. antiquewhite: 0xfaebd7,
  1702. aqua: 0x00ffff,
  1703. aquamarine: 0x7fffd4,
  1704. azure: 0xf0ffff,
  1705. beige: 0xf5f5dc,
  1706. bisque: 0xffe4c4,
  1707. black: 0x000000,
  1708. blanchedalmond: 0xffebcd,
  1709. blue: 0x0000ff,
  1710. blueviolet: 0x8a2be2,
  1711. brown: 0xa52a2a,
  1712. burlywood: 0xdeb887,
  1713. cadetblue: 0x5f9ea0,
  1714. chartreuse: 0x7fff00,
  1715. chocolate: 0xd2691e,
  1716. coral: 0xff7f50,
  1717. cornflowerblue: 0x6495ed,
  1718. cornsilk: 0xfff8dc,
  1719. crimson: 0xdc143c,
  1720. cyan: 0x00ffff,
  1721. darkblue: 0x00008b,
  1722. darkcyan: 0x008b8b,
  1723. darkgoldenrod: 0xb8860b,
  1724. darkgray: 0xa9a9a9,
  1725. darkgreen: 0x006400,
  1726. darkgrey: 0xa9a9a9,
  1727. darkkhaki: 0xbdb76b,
  1728. darkmagenta: 0x8b008b,
  1729. darkolivegreen: 0x556b2f,
  1730. darkorange: 0xff8c00,
  1731. darkorchid: 0x9932cc,
  1732. darkred: 0x8b0000,
  1733. darksalmon: 0xe9967a,
  1734. darkseagreen: 0x8fbc8f,
  1735. darkslateblue: 0x483d8b,
  1736. darkslategray: 0x2f4f4f,
  1737. darkslategrey: 0x2f4f4f,
  1738. darkturquoise: 0x00ced1,
  1739. darkviolet: 0x9400d3,
  1740. deeppink: 0xff1493,
  1741. deepskyblue: 0x00bfff,
  1742. dimgray: 0x696969,
  1743. dimgrey: 0x696969,
  1744. dodgerblue: 0x1e90ff,
  1745. firebrick: 0xb22222,
  1746. floralwhite: 0xfffaf0,
  1747. forestgreen: 0x228b22,
  1748. fuchsia: 0xff00ff,
  1749. gainsboro: 0xdcdcdc,
  1750. ghostwhite: 0xf8f8ff,
  1751. gold: 0xffd700,
  1752. goldenrod: 0xdaa520,
  1753. gray: 0x808080,
  1754. green: 0x008000,
  1755. greenyellow: 0xadff2f,
  1756. grey: 0x808080,
  1757. honeydew: 0xf0fff0,
  1758. hotpink: 0xff69b4,
  1759. indianred: 0xcd5c5c,
  1760. indigo: 0x4b0082,
  1761. ivory: 0xfffff0,
  1762. khaki: 0xf0e68c,
  1763. lavender: 0xe6e6fa,
  1764. lavenderblush: 0xfff0f5,
  1765. lawngreen: 0x7cfc00,
  1766. lemonchiffon: 0xfffacd,
  1767. lightblue: 0xadd8e6,
  1768. lightcoral: 0xf08080,
  1769. lightcyan: 0xe0ffff,
  1770. lightgoldenrodyellow: 0xfafad2,
  1771. lightgray: 0xd3d3d3,
  1772. lightgreen: 0x90ee90,
  1773. lightgrey: 0xd3d3d3,
  1774. lightpink: 0xffb6c1,
  1775. lightsalmon: 0xffa07a,
  1776. lightseagreen: 0x20b2aa,
  1777. lightskyblue: 0x87cefa,
  1778. lightslategray: 0x778899,
  1779. lightslategrey: 0x778899,
  1780. lightsteelblue: 0xb0c4de,
  1781. lightyellow: 0xffffe0,
  1782. lime: 0x00ff00,
  1783. limegreen: 0x32cd32,
  1784. linen: 0xfaf0e6,
  1785. magenta: 0xff00ff,
  1786. maroon: 0x800000,
  1787. mediumaquamarine: 0x66cdaa,
  1788. mediumblue: 0x0000cd,
  1789. mediumorchid: 0xba55d3,
  1790. mediumpurple: 0x9370db,
  1791. mediumseagreen: 0x3cb371,
  1792. mediumslateblue: 0x7b68ee,
  1793. mediumspringgreen: 0x00fa9a,
  1794. mediumturquoise: 0x48d1cc,
  1795. mediumvioletred: 0xc71585,
  1796. midnightblue: 0x191970,
  1797. mintcream: 0xf5fffa,
  1798. mistyrose: 0xffe4e1,
  1799. moccasin: 0xffe4b5,
  1800. navajowhite: 0xffdead,
  1801. navy: 0x000080,
  1802. oldlace: 0xfdf5e6,
  1803. olive: 0x808000,
  1804. olivedrab: 0x6b8e23,
  1805. orange: 0xffa500,
  1806. orangered: 0xff4500,
  1807. orchid: 0xda70d6,
  1808. palegoldenrod: 0xeee8aa,
  1809. palegreen: 0x98fb98,
  1810. paleturquoise: 0xafeeee,
  1811. palevioletred: 0xdb7093,
  1812. papayawhip: 0xffefd5,
  1813. peachpuff: 0xffdab9,
  1814. peru: 0xcd853f,
  1815. pink: 0xffc0cb,
  1816. plum: 0xdda0dd,
  1817. powderblue: 0xb0e0e6,
  1818. purple: 0x800080,
  1819. rebeccapurple: 0x663399,
  1820. red: 0xff0000,
  1821. rosybrown: 0xbc8f8f,
  1822. royalblue: 0x4169e1,
  1823. saddlebrown: 0x8b4513,
  1824. salmon: 0xfa8072,
  1825. sandybrown: 0xf4a460,
  1826. seagreen: 0x2e8b57,
  1827. seashell: 0xfff5ee,
  1828. sienna: 0xa0522d,
  1829. silver: 0xc0c0c0,
  1830. skyblue: 0x87ceeb,
  1831. slateblue: 0x6a5acd,
  1832. slategray: 0x708090,
  1833. slategrey: 0x708090,
  1834. snow: 0xfffafa,
  1835. springgreen: 0x00ff7f,
  1836. steelblue: 0x4682b4,
  1837. tan: 0xd2b48c,
  1838. teal: 0x008080,
  1839. thistle: 0xd8bfd8,
  1840. tomato: 0xff6347,
  1841. turquoise: 0x40e0d0,
  1842. violet: 0xee82ee,
  1843. wheat: 0xf5deb3,
  1844. white: 0xffffff,
  1845. whitesmoke: 0xf5f5f5,
  1846. yellow: 0xffff00,
  1847. yellowgreen: 0x9acd32
  1848. };
  1849. define(Color, color, {
  1850. displayable: function() {
  1851. return this.rgb().displayable();
  1852. },
  1853. hex: function() {
  1854. return this.rgb().hex();
  1855. },
  1856. toString: function() {
  1857. return this.rgb() + "";
  1858. }
  1859. });
  1860. function color(format) {
  1861. var m;
  1862. format = (format + "").trim().toLowerCase();
  1863. 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
  1864. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  1865. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1866. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1867. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1868. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1869. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1870. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1871. : named.hasOwnProperty(format) ? rgbn(named[format])
  1872. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1873. : null;
  1874. }
  1875. function rgbn(n) {
  1876. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1877. }
  1878. function rgba(r, g, b, a) {
  1879. if (a <= 0) r = g = b = NaN;
  1880. return new Rgb(r, g, b, a);
  1881. }
  1882. function rgbConvert(o) {
  1883. if (!(o instanceof Color)) o = color(o);
  1884. if (!o) return new Rgb;
  1885. o = o.rgb();
  1886. return new Rgb(o.r, o.g, o.b, o.opacity);
  1887. }
  1888. function rgb(r, g, b, opacity) {
  1889. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1890. }
  1891. function Rgb(r, g, b, opacity) {
  1892. this.r = +r;
  1893. this.g = +g;
  1894. this.b = +b;
  1895. this.opacity = +opacity;
  1896. }
  1897. define(Rgb, rgb, extend(Color, {
  1898. brighter: function(k) {
  1899. k = k == null ? brighter : Math.pow(brighter, k);
  1900. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1901. },
  1902. darker: function(k) {
  1903. k = k == null ? darker : Math.pow(darker, k);
  1904. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1905. },
  1906. rgb: function() {
  1907. return this;
  1908. },
  1909. displayable: function() {
  1910. return (0 <= this.r && this.r <= 255)
  1911. && (0 <= this.g && this.g <= 255)
  1912. && (0 <= this.b && this.b <= 255)
  1913. && (0 <= this.opacity && this.opacity <= 1);
  1914. },
  1915. hex: function() {
  1916. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  1917. },
  1918. toString: function() {
  1919. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1920. return (a === 1 ? "rgb(" : "rgba(")
  1921. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1922. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1923. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1924. + (a === 1 ? ")" : ", " + a + ")");
  1925. }
  1926. }));
  1927. function hex(value) {
  1928. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  1929. return (value < 16 ? "0" : "") + value.toString(16);
  1930. }
  1931. function hsla(h, s, l, a) {
  1932. if (a <= 0) h = s = l = NaN;
  1933. else if (l <= 0 || l >= 1) h = s = NaN;
  1934. else if (s <= 0) h = NaN;
  1935. return new Hsl(h, s, l, a);
  1936. }
  1937. function hslConvert(o) {
  1938. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1939. if (!(o instanceof Color)) o = color(o);
  1940. if (!o) return new Hsl;
  1941. if (o instanceof Hsl) return o;
  1942. o = o.rgb();
  1943. var r = o.r / 255,
  1944. g = o.g / 255,
  1945. b = o.b / 255,
  1946. min = Math.min(r, g, b),
  1947. max = Math.max(r, g, b),
  1948. h = NaN,
  1949. s = max - min,
  1950. l = (max + min) / 2;
  1951. if (s) {
  1952. if (r === max) h = (g - b) / s + (g < b) * 6;
  1953. else if (g === max) h = (b - r) / s + 2;
  1954. else h = (r - g) / s + 4;
  1955. s /= l < 0.5 ? max + min : 2 - max - min;
  1956. h *= 60;
  1957. } else {
  1958. s = l > 0 && l < 1 ? 0 : h;
  1959. }
  1960. return new Hsl(h, s, l, o.opacity);
  1961. }
  1962. function hsl(h, s, l, opacity) {
  1963. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1964. }
  1965. function Hsl(h, s, l, opacity) {
  1966. this.h = +h;
  1967. this.s = +s;
  1968. this.l = +l;
  1969. this.opacity = +opacity;
  1970. }
  1971. define(Hsl, hsl, extend(Color, {
  1972. brighter: function(k) {
  1973. k = k == null ? brighter : Math.pow(brighter, k);
  1974. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1975. },
  1976. darker: function(k) {
  1977. k = k == null ? darker : Math.pow(darker, k);
  1978. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1979. },
  1980. rgb: function() {
  1981. var h = this.h % 360 + (this.h < 0) * 360,
  1982. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1983. l = this.l,
  1984. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1985. m1 = 2 * l - m2;
  1986. return new Rgb(
  1987. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  1988. hsl2rgb(h, m1, m2),
  1989. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  1990. this.opacity
  1991. );
  1992. },
  1993. displayable: function() {
  1994. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  1995. && (0 <= this.l && this.l <= 1)
  1996. && (0 <= this.opacity && this.opacity <= 1);
  1997. }
  1998. }));
  1999. /* From FvD 13.37, CSS Color Module Level 3 */
  2000. function hsl2rgb(h, m1, m2) {
  2001. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2002. : h < 180 ? m2
  2003. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2004. : m1) * 255;
  2005. }
  2006. var deg2rad = Math.PI / 180;
  2007. var rad2deg = 180 / Math.PI;
  2008. // https://beta.observablehq.com/@mbostock/lab-and-rgb
  2009. var K = 18,
  2010. Xn = 0.96422,
  2011. Yn = 1,
  2012. Zn = 0.82521,
  2013. t0 = 4 / 29,
  2014. t1 = 6 / 29,
  2015. t2 = 3 * t1 * t1,
  2016. t3 = t1 * t1 * t1;
  2017. function labConvert(o) {
  2018. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2019. if (o instanceof Hcl) {
  2020. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2021. var h = o.h * deg2rad;
  2022. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2023. }
  2024. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2025. var r = rgb2lrgb(o.r),
  2026. g = rgb2lrgb(o.g),
  2027. b = rgb2lrgb(o.b),
  2028. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2029. if (r === g && g === b) x = z = y; else {
  2030. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2031. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2032. }
  2033. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2034. }
  2035. function gray(l, opacity) {
  2036. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2037. }
  2038. function lab(l, a, b, opacity) {
  2039. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2040. }
  2041. function Lab(l, a, b, opacity) {
  2042. this.l = +l;
  2043. this.a = +a;
  2044. this.b = +b;
  2045. this.opacity = +opacity;
  2046. }
  2047. define(Lab, lab, extend(Color, {
  2048. brighter: function(k) {
  2049. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2050. },
  2051. darker: function(k) {
  2052. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2053. },
  2054. rgb: function() {
  2055. var y = (this.l + 16) / 116,
  2056. x = isNaN(this.a) ? y : y + this.a / 500,
  2057. z = isNaN(this.b) ? y : y - this.b / 200;
  2058. x = Xn * lab2xyz(x);
  2059. y = Yn * lab2xyz(y);
  2060. z = Zn * lab2xyz(z);
  2061. return new Rgb(
  2062. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2063. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2064. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2065. this.opacity
  2066. );
  2067. }
  2068. }));
  2069. function xyz2lab(t) {
  2070. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2071. }
  2072. function lab2xyz(t) {
  2073. return t > t1 ? t * t * t : t2 * (t - t0);
  2074. }
  2075. function lrgb2rgb(x) {
  2076. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2077. }
  2078. function rgb2lrgb(x) {
  2079. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2080. }
  2081. function hclConvert(o) {
  2082. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2083. if (!(o instanceof Lab)) o = labConvert(o);
  2084. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);
  2085. var h = Math.atan2(o.b, o.a) * rad2deg;
  2086. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2087. }
  2088. function lch(l, c, h, opacity) {
  2089. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2090. }
  2091. function hcl(h, c, l, opacity) {
  2092. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2093. }
  2094. function Hcl(h, c, l, opacity) {
  2095. this.h = +h;
  2096. this.c = +c;
  2097. this.l = +l;
  2098. this.opacity = +opacity;
  2099. }
  2100. define(Hcl, hcl, extend(Color, {
  2101. brighter: function(k) {
  2102. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2103. },
  2104. darker: function(k) {
  2105. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2106. },
  2107. rgb: function() {
  2108. return labConvert(this).rgb();
  2109. }
  2110. }));
  2111. var A = -0.14861,
  2112. B = +1.78277,
  2113. C = -0.29227,
  2114. D = -0.90649,
  2115. E = +1.97294,
  2116. ED = E * D,
  2117. EB = E * B,
  2118. BC_DA = B * C - D * A;
  2119. function cubehelixConvert(o) {
  2120. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2121. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2122. var r = o.r / 255,
  2123. g = o.g / 255,
  2124. b = o.b / 255,
  2125. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2126. bl = b - l,
  2127. k = (E * (g - l) - C * bl) / D,
  2128. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2129. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2130. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2131. }
  2132. function cubehelix(h, s, l, opacity) {
  2133. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2134. }
  2135. function Cubehelix(h, s, l, opacity) {
  2136. this.h = +h;
  2137. this.s = +s;
  2138. this.l = +l;
  2139. this.opacity = +opacity;
  2140. }
  2141. define(Cubehelix, cubehelix, extend(Color, {
  2142. brighter: function(k) {
  2143. k = k == null ? brighter : Math.pow(brighter, k);
  2144. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2145. },
  2146. darker: function(k) {
  2147. k = k == null ? darker : Math.pow(darker, k);
  2148. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2149. },
  2150. rgb: function() {
  2151. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2152. l = +this.l,
  2153. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2154. cosh = Math.cos(h),
  2155. sinh = Math.sin(h);
  2156. return new Rgb(
  2157. 255 * (l + a * (A * cosh + B * sinh)),
  2158. 255 * (l + a * (C * cosh + D * sinh)),
  2159. 255 * (l + a * (E * cosh)),
  2160. this.opacity
  2161. );
  2162. }
  2163. }));
  2164. function basis(t1, v0, v1, v2, v3) {
  2165. var t2 = t1 * t1, t3 = t2 * t1;
  2166. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2167. + (4 - 6 * t2 + 3 * t3) * v1
  2168. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2169. + t3 * v3) / 6;
  2170. }
  2171. function basis$1(values) {
  2172. var n = values.length - 1;
  2173. return function(t) {
  2174. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2175. v1 = values[i],
  2176. v2 = values[i + 1],
  2177. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2178. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2179. return basis((t - i / n) * n, v0, v1, v2, v3);
  2180. };
  2181. }
  2182. function basisClosed(values) {
  2183. var n = values.length;
  2184. return function(t) {
  2185. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2186. v0 = values[(i + n - 1) % n],
  2187. v1 = values[i % n],
  2188. v2 = values[(i + 1) % n],
  2189. v3 = values[(i + 2) % n];
  2190. return basis((t - i / n) * n, v0, v1, v2, v3);
  2191. };
  2192. }
  2193. function constant$3(x) {
  2194. return function() {
  2195. return x;
  2196. };
  2197. }
  2198. function linear(a, d) {
  2199. return function(t) {
  2200. return a + t * d;
  2201. };
  2202. }
  2203. function exponential(a, b, y) {
  2204. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2205. return Math.pow(a + t * b, y);
  2206. };
  2207. }
  2208. function hue(a, b) {
  2209. var d = b - a;
  2210. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2211. }
  2212. function gamma(y) {
  2213. return (y = +y) === 1 ? nogamma : function(a, b) {
  2214. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2215. };
  2216. }
  2217. function nogamma(a, b) {
  2218. var d = b - a;
  2219. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2220. }
  2221. var interpolateRgb = (function rgbGamma(y) {
  2222. var color$$1 = gamma(y);
  2223. function rgb$$1(start, end) {
  2224. var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
  2225. g = color$$1(start.g, end.g),
  2226. b = color$$1(start.b, end.b),
  2227. opacity = nogamma(start.opacity, end.opacity);
  2228. return function(t) {
  2229. start.r = r(t);
  2230. start.g = g(t);
  2231. start.b = b(t);
  2232. start.opacity = opacity(t);
  2233. return start + "";
  2234. };
  2235. }
  2236. rgb$$1.gamma = rgbGamma;
  2237. return rgb$$1;
  2238. })(1);
  2239. function rgbSpline(spline) {
  2240. return function(colors) {
  2241. var n = colors.length,
  2242. r = new Array(n),
  2243. g = new Array(n),
  2244. b = new Array(n),
  2245. i, color$$1;
  2246. for (i = 0; i < n; ++i) {
  2247. color$$1 = rgb(colors[i]);
  2248. r[i] = color$$1.r || 0;
  2249. g[i] = color$$1.g || 0;
  2250. b[i] = color$$1.b || 0;
  2251. }
  2252. r = spline(r);
  2253. g = spline(g);
  2254. b = spline(b);
  2255. color$$1.opacity = 1;
  2256. return function(t) {
  2257. color$$1.r = r(t);
  2258. color$$1.g = g(t);
  2259. color$$1.b = b(t);
  2260. return color$$1 + "";
  2261. };
  2262. };
  2263. }
  2264. var rgbBasis = rgbSpline(basis$1);
  2265. var rgbBasisClosed = rgbSpline(basisClosed);
  2266. function array$1(a, b) {
  2267. var nb = b ? b.length : 0,
  2268. na = a ? Math.min(nb, a.length) : 0,
  2269. x = new Array(na),
  2270. c = new Array(nb),
  2271. i;
  2272. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2273. for (; i < nb; ++i) c[i] = b[i];
  2274. return function(t) {
  2275. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2276. return c;
  2277. };
  2278. }
  2279. function date(a, b) {
  2280. var d = new Date;
  2281. return a = +a, b -= a, function(t) {
  2282. return d.setTime(a + b * t), d;
  2283. };
  2284. }
  2285. function interpolateNumber(a, b) {
  2286. return a = +a, b -= a, function(t) {
  2287. return a + b * t;
  2288. };
  2289. }
  2290. function object(a, b) {
  2291. var i = {},
  2292. c = {},
  2293. k;
  2294. if (a === null || typeof a !== "object") a = {};
  2295. if (b === null || typeof b !== "object") b = {};
  2296. for (k in b) {
  2297. if (k in a) {
  2298. i[k] = interpolateValue(a[k], b[k]);
  2299. } else {
  2300. c[k] = b[k];
  2301. }
  2302. }
  2303. return function(t) {
  2304. for (k in i) c[k] = i[k](t);
  2305. return c;
  2306. };
  2307. }
  2308. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  2309. reB = new RegExp(reA.source, "g");
  2310. function zero(b) {
  2311. return function() {
  2312. return b;
  2313. };
  2314. }
  2315. function one(b) {
  2316. return function(t) {
  2317. return b(t) + "";
  2318. };
  2319. }
  2320. function interpolateString(a, b) {
  2321. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2322. am, // current match in a
  2323. bm, // current match in b
  2324. bs, // string preceding current number in b, if any
  2325. i = -1, // index in s
  2326. s = [], // string constants and placeholders
  2327. q = []; // number interpolators
  2328. // Coerce inputs to strings.
  2329. a = a + "", b = b + "";
  2330. // Interpolate pairs of numbers in a & b.
  2331. while ((am = reA.exec(a))
  2332. && (bm = reB.exec(b))) {
  2333. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2334. bs = b.slice(bi, bs);
  2335. if (s[i]) s[i] += bs; // coalesce with previous string
  2336. else s[++i] = bs;
  2337. }
  2338. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2339. if (s[i]) s[i] += bm; // coalesce with previous string
  2340. else s[++i] = bm;
  2341. } else { // interpolate non-matching numbers
  2342. s[++i] = null;
  2343. q.push({i: i, x: interpolateNumber(am, bm)});
  2344. }
  2345. bi = reB.lastIndex;
  2346. }
  2347. // Add remains of b.
  2348. if (bi < b.length) {
  2349. bs = b.slice(bi);
  2350. if (s[i]) s[i] += bs; // coalesce with previous string
  2351. else s[++i] = bs;
  2352. }
  2353. // Special optimization for only a single match.
  2354. // Otherwise, interpolate each of the numbers and rejoin the string.
  2355. return s.length < 2 ? (q[0]
  2356. ? one(q[0].x)
  2357. : zero(b))
  2358. : (b = q.length, function(t) {
  2359. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2360. return s.join("");
  2361. });
  2362. }
  2363. function interpolateValue(a, b) {
  2364. var t = typeof b, c;
  2365. return b == null || t === "boolean" ? constant$3(b)
  2366. : (t === "number" ? interpolateNumber
  2367. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2368. : b instanceof color ? interpolateRgb
  2369. : b instanceof Date ? date
  2370. : Array.isArray(b) ? array$1
  2371. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2372. : interpolateNumber)(a, b);
  2373. }
  2374. function interpolateRound(a, b) {
  2375. return a = +a, b -= a, function(t) {
  2376. return Math.round(a + b * t);
  2377. };
  2378. }
  2379. var degrees = 180 / Math.PI;
  2380. var identity$2 = {
  2381. translateX: 0,
  2382. translateY: 0,
  2383. rotate: 0,
  2384. skewX: 0,
  2385. scaleX: 1,
  2386. scaleY: 1
  2387. };
  2388. function decompose(a, b, c, d, e, f) {
  2389. var scaleX, scaleY, skewX;
  2390. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2391. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2392. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2393. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2394. return {
  2395. translateX: e,
  2396. translateY: f,
  2397. rotate: Math.atan2(b, a) * degrees,
  2398. skewX: Math.atan(skewX) * degrees,
  2399. scaleX: scaleX,
  2400. scaleY: scaleY
  2401. };
  2402. }
  2403. var cssNode,
  2404. cssRoot,
  2405. cssView,
  2406. svgNode;
  2407. function parseCss(value) {
  2408. if (value === "none") return identity$2;
  2409. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2410. cssNode.style.transform = value;
  2411. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2412. cssRoot.removeChild(cssNode);
  2413. value = value.slice(7, -1).split(",");
  2414. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2415. }
  2416. function parseSvg(value) {
  2417. if (value == null) return identity$2;
  2418. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2419. svgNode.setAttribute("transform", value);
  2420. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2421. value = value.matrix;
  2422. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2423. }
  2424. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2425. function pop(s) {
  2426. return s.length ? s.pop() + " " : "";
  2427. }
  2428. function translate(xa, ya, xb, yb, s, q) {
  2429. if (xa !== xb || ya !== yb) {
  2430. var i = s.push("translate(", null, pxComma, null, pxParen);
  2431. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2432. } else if (xb || yb) {
  2433. s.push("translate(" + xb + pxComma + yb + pxParen);
  2434. }
  2435. }
  2436. function rotate(a, b, s, q) {
  2437. if (a !== b) {
  2438. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2439. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2440. } else if (b) {
  2441. s.push(pop(s) + "rotate(" + b + degParen);
  2442. }
  2443. }
  2444. function skewX(a, b, s, q) {
  2445. if (a !== b) {
  2446. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2447. } else if (b) {
  2448. s.push(pop(s) + "skewX(" + b + degParen);
  2449. }
  2450. }
  2451. function scale(xa, ya, xb, yb, s, q) {
  2452. if (xa !== xb || ya !== yb) {
  2453. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2454. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2455. } else if (xb !== 1 || yb !== 1) {
  2456. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2457. }
  2458. }
  2459. return function(a, b) {
  2460. var s = [], // string constants and placeholders
  2461. q = []; // number interpolators
  2462. a = parse(a), b = parse(b);
  2463. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2464. rotate(a.rotate, b.rotate, s, q);
  2465. skewX(a.skewX, b.skewX, s, q);
  2466. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2467. a = b = null; // gc
  2468. return function(t) {
  2469. var i = -1, n = q.length, o;
  2470. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2471. return s.join("");
  2472. };
  2473. };
  2474. }
  2475. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2476. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2477. var rho = Math.SQRT2,
  2478. rho2 = 2,
  2479. rho4 = 4,
  2480. epsilon2 = 1e-12;
  2481. function cosh(x) {
  2482. return ((x = Math.exp(x)) + 1 / x) / 2;
  2483. }
  2484. function sinh(x) {
  2485. return ((x = Math.exp(x)) - 1 / x) / 2;
  2486. }
  2487. function tanh(x) {
  2488. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2489. }
  2490. // p0 = [ux0, uy0, w0]
  2491. // p1 = [ux1, uy1, w1]
  2492. function interpolateZoom(p0, p1) {
  2493. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2494. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2495. dx = ux1 - ux0,
  2496. dy = uy1 - uy0,
  2497. d2 = dx * dx + dy * dy,
  2498. i,
  2499. S;
  2500. // Special case for u0 ≅ u1.
  2501. if (d2 < epsilon2) {
  2502. S = Math.log(w1 / w0) / rho;
  2503. i = function(t) {
  2504. return [
  2505. ux0 + t * dx,
  2506. uy0 + t * dy,
  2507. w0 * Math.exp(rho * t * S)
  2508. ];
  2509. };
  2510. }
  2511. // General case.
  2512. else {
  2513. var d1 = Math.sqrt(d2),
  2514. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2515. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2516. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2517. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2518. S = (r1 - r0) / rho;
  2519. i = function(t) {
  2520. var s = t * S,
  2521. coshr0 = cosh(r0),
  2522. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2523. return [
  2524. ux0 + u * dx,
  2525. uy0 + u * dy,
  2526. w0 * coshr0 / cosh(rho * s + r0)
  2527. ];
  2528. };
  2529. }
  2530. i.duration = S * 1000;
  2531. return i;
  2532. }
  2533. function hsl$1(hue$$1) {
  2534. return function(start, end) {
  2535. var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
  2536. s = nogamma(start.s, end.s),
  2537. l = nogamma(start.l, end.l),
  2538. opacity = nogamma(start.opacity, end.opacity);
  2539. return function(t) {
  2540. start.h = h(t);
  2541. start.s = s(t);
  2542. start.l = l(t);
  2543. start.opacity = opacity(t);
  2544. return start + "";
  2545. };
  2546. }
  2547. }
  2548. var hsl$2 = hsl$1(hue);
  2549. var hslLong = hsl$1(nogamma);
  2550. function lab$1(start, end) {
  2551. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2552. a = nogamma(start.a, end.a),
  2553. b = nogamma(start.b, end.b),
  2554. opacity = nogamma(start.opacity, end.opacity);
  2555. return function(t) {
  2556. start.l = l(t);
  2557. start.a = a(t);
  2558. start.b = b(t);
  2559. start.opacity = opacity(t);
  2560. return start + "";
  2561. };
  2562. }
  2563. function hcl$1(hue$$1) {
  2564. return function(start, end) {
  2565. var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
  2566. c = nogamma(start.c, end.c),
  2567. l = nogamma(start.l, end.l),
  2568. opacity = nogamma(start.opacity, end.opacity);
  2569. return function(t) {
  2570. start.h = h(t);
  2571. start.c = c(t);
  2572. start.l = l(t);
  2573. start.opacity = opacity(t);
  2574. return start + "";
  2575. };
  2576. }
  2577. }
  2578. var hcl$2 = hcl$1(hue);
  2579. var hclLong = hcl$1(nogamma);
  2580. function cubehelix$1(hue$$1) {
  2581. return (function cubehelixGamma(y) {
  2582. y = +y;
  2583. function cubehelix$$1(start, end) {
  2584. var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2585. s = nogamma(start.s, end.s),
  2586. l = nogamma(start.l, end.l),
  2587. opacity = nogamma(start.opacity, end.opacity);
  2588. return function(t) {
  2589. start.h = h(t);
  2590. start.s = s(t);
  2591. start.l = l(Math.pow(t, y));
  2592. start.opacity = opacity(t);
  2593. return start + "";
  2594. };
  2595. }
  2596. cubehelix$$1.gamma = cubehelixGamma;
  2597. return cubehelix$$1;
  2598. })(1);
  2599. }
  2600. var cubehelix$2 = cubehelix$1(hue);
  2601. var cubehelixLong = cubehelix$1(nogamma);
  2602. function piecewise(interpolate, values) {
  2603. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  2604. while (i < n) I[i] = interpolate(v, v = values[++i]);
  2605. return function(t) {
  2606. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  2607. return I[i](t - i);
  2608. };
  2609. }
  2610. function quantize(interpolator, n) {
  2611. var samples = new Array(n);
  2612. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2613. return samples;
  2614. }
  2615. var frame = 0, // is an animation frame pending?
  2616. timeout = 0, // is a timeout pending?
  2617. interval = 0, // are any timers active?
  2618. pokeDelay = 1000, // how frequently we check for clock skew
  2619. taskHead,
  2620. taskTail,
  2621. clockLast = 0,
  2622. clockNow = 0,
  2623. clockSkew = 0,
  2624. clock = typeof performance === "object" && performance.now ? performance : Date,
  2625. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2626. function now() {
  2627. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2628. }
  2629. function clearNow() {
  2630. clockNow = 0;
  2631. }
  2632. function Timer() {
  2633. this._call =
  2634. this._time =
  2635. this._next = null;
  2636. }
  2637. Timer.prototype = timer.prototype = {
  2638. constructor: Timer,
  2639. restart: function(callback, delay, time) {
  2640. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2641. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2642. if (!this._next && taskTail !== this) {
  2643. if (taskTail) taskTail._next = this;
  2644. else taskHead = this;
  2645. taskTail = this;
  2646. }
  2647. this._call = callback;
  2648. this._time = time;
  2649. sleep();
  2650. },
  2651. stop: function() {
  2652. if (this._call) {
  2653. this._call = null;
  2654. this._time = Infinity;
  2655. sleep();
  2656. }
  2657. }
  2658. };
  2659. function timer(callback, delay, time) {
  2660. var t = new Timer;
  2661. t.restart(callback, delay, time);
  2662. return t;
  2663. }
  2664. function timerFlush() {
  2665. now(); // Get the current time, if not already set.
  2666. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2667. var t = taskHead, e;
  2668. while (t) {
  2669. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2670. t = t._next;
  2671. }
  2672. --frame;
  2673. }
  2674. function wake() {
  2675. clockNow = (clockLast = clock.now()) + clockSkew;
  2676. frame = timeout = 0;
  2677. try {
  2678. timerFlush();
  2679. } finally {
  2680. frame = 0;
  2681. nap();
  2682. clockNow = 0;
  2683. }
  2684. }
  2685. function poke() {
  2686. var now = clock.now(), delay = now - clockLast;
  2687. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2688. }
  2689. function nap() {
  2690. var t0, t1 = taskHead, t2, time = Infinity;
  2691. while (t1) {
  2692. if (t1._call) {
  2693. if (time > t1._time) time = t1._time;
  2694. t0 = t1, t1 = t1._next;
  2695. } else {
  2696. t2 = t1._next, t1._next = null;
  2697. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2698. }
  2699. }
  2700. taskTail = t0;
  2701. sleep(time);
  2702. }
  2703. function sleep(time) {
  2704. if (frame) return; // Soonest alarm already set, or will be.
  2705. if (timeout) timeout = clearTimeout(timeout);
  2706. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2707. if (delay > 24) {
  2708. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2709. if (interval) interval = clearInterval(interval);
  2710. } else {
  2711. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2712. frame = 1, setFrame(wake);
  2713. }
  2714. }
  2715. function timeout$1(callback, delay, time) {
  2716. var t = new Timer;
  2717. delay = delay == null ? 0 : +delay;
  2718. t.restart(function(elapsed) {
  2719. t.stop();
  2720. callback(elapsed + delay);
  2721. }, delay, time);
  2722. return t;
  2723. }
  2724. function interval$1(callback, delay, time) {
  2725. var t = new Timer, total = delay;
  2726. if (delay == null) return t.restart(callback, delay, time), t;
  2727. delay = +delay, time = time == null ? now() : +time;
  2728. t.restart(function tick(elapsed) {
  2729. elapsed += total;
  2730. t.restart(tick, total += delay, time);
  2731. callback(elapsed);
  2732. }, delay, time);
  2733. return t;
  2734. }
  2735. var emptyOn = dispatch("start", "end", "interrupt");
  2736. var emptyTween = [];
  2737. var CREATED = 0;
  2738. var SCHEDULED = 1;
  2739. var STARTING = 2;
  2740. var STARTED = 3;
  2741. var RUNNING = 4;
  2742. var ENDING = 5;
  2743. var ENDED = 6;
  2744. function schedule(node, name, id, index, group, timing) {
  2745. var schedules = node.__transition;
  2746. if (!schedules) node.__transition = {};
  2747. else if (id in schedules) return;
  2748. create$1(node, id, {
  2749. name: name,
  2750. index: index, // For context during callback.
  2751. group: group, // For context during callback.
  2752. on: emptyOn,
  2753. tween: emptyTween,
  2754. time: timing.time,
  2755. delay: timing.delay,
  2756. duration: timing.duration,
  2757. ease: timing.ease,
  2758. timer: null,
  2759. state: CREATED
  2760. });
  2761. }
  2762. function init(node, id) {
  2763. var schedule = get$1(node, id);
  2764. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  2765. return schedule;
  2766. }
  2767. function set$1(node, id) {
  2768. var schedule = get$1(node, id);
  2769. if (schedule.state > STARTING) throw new Error("too late; already started");
  2770. return schedule;
  2771. }
  2772. function get$1(node, id) {
  2773. var schedule = node.__transition;
  2774. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  2775. return schedule;
  2776. }
  2777. function create$1(node, id, self) {
  2778. var schedules = node.__transition,
  2779. tween;
  2780. // Initialize the self timer when the transition is created.
  2781. // Note the actual delay is not known until the first callback!
  2782. schedules[id] = self;
  2783. self.timer = timer(schedule, 0, self.time);
  2784. function schedule(elapsed) {
  2785. self.state = SCHEDULED;
  2786. self.timer.restart(start, self.delay, self.time);
  2787. // If the elapsed delay is less than our first sleep, start immediately.
  2788. if (self.delay <= elapsed) start(elapsed - self.delay);
  2789. }
  2790. function start(elapsed) {
  2791. var i, j, n, o;
  2792. // If the state is not SCHEDULED, then we previously errored on start.
  2793. if (self.state !== SCHEDULED) return stop();
  2794. for (i in schedules) {
  2795. o = schedules[i];
  2796. if (o.name !== self.name) continue;
  2797. // While this element already has a starting transition during this frame,
  2798. // defer starting an interrupting transition until that transition has a
  2799. // chance to tick (and possibly end); see d3/d3-transition#54!
  2800. if (o.state === STARTED) return timeout$1(start);
  2801. // Interrupt the active transition, if any.
  2802. // Dispatch the interrupt event.
  2803. if (o.state === RUNNING) {
  2804. o.state = ENDED;
  2805. o.timer.stop();
  2806. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2807. delete schedules[i];
  2808. }
  2809. // Cancel any pre-empted transitions. No interrupt event is dispatched
  2810. // because the cancelled transitions never started. Note that this also
  2811. // removes this transition from the pending list!
  2812. else if (+i < id) {
  2813. o.state = ENDED;
  2814. o.timer.stop();
  2815. delete schedules[i];
  2816. }
  2817. }
  2818. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2819. // Note the transition may be canceled after start and before the first tick!
  2820. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2821. // Assuming this is successful, subsequent callbacks go straight to tick.
  2822. timeout$1(function() {
  2823. if (self.state === STARTED) {
  2824. self.state = RUNNING;
  2825. self.timer.restart(tick, self.delay, self.time);
  2826. tick(elapsed);
  2827. }
  2828. });
  2829. // Dispatch the start event.
  2830. // Note this must be done before the tween are initialized.
  2831. self.state = STARTING;
  2832. self.on.call("start", node, node.__data__, self.index, self.group);
  2833. if (self.state !== STARTING) return; // interrupted
  2834. self.state = STARTED;
  2835. // Initialize the tween, deleting null tween.
  2836. tween = new Array(n = self.tween.length);
  2837. for (i = 0, j = -1; i < n; ++i) {
  2838. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2839. tween[++j] = o;
  2840. }
  2841. }
  2842. tween.length = j + 1;
  2843. }
  2844. function tick(elapsed) {
  2845. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2846. i = -1,
  2847. n = tween.length;
  2848. while (++i < n) {
  2849. tween[i].call(null, t);
  2850. }
  2851. // Dispatch the end event.
  2852. if (self.state === ENDING) {
  2853. self.on.call("end", node, node.__data__, self.index, self.group);
  2854. stop();
  2855. }
  2856. }
  2857. function stop() {
  2858. self.state = ENDED;
  2859. self.timer.stop();
  2860. delete schedules[id];
  2861. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2862. delete node.__transition;
  2863. }
  2864. }
  2865. function interrupt(node, name) {
  2866. var schedules = node.__transition,
  2867. schedule$$1,
  2868. active,
  2869. empty = true,
  2870. i;
  2871. if (!schedules) return;
  2872. name = name == null ? null : name + "";
  2873. for (i in schedules) {
  2874. if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
  2875. active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
  2876. schedule$$1.state = ENDED;
  2877. schedule$$1.timer.stop();
  2878. if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
  2879. delete schedules[i];
  2880. }
  2881. if (empty) delete node.__transition;
  2882. }
  2883. function selection_interrupt(name) {
  2884. return this.each(function() {
  2885. interrupt(this, name);
  2886. });
  2887. }
  2888. function tweenRemove(id, name) {
  2889. var tween0, tween1;
  2890. return function() {
  2891. var schedule$$1 = set$1(this, id),
  2892. tween = schedule$$1.tween;
  2893. // If this node shared tween with the previous node,
  2894. // just assign the updated shared tween and we’re done!
  2895. // Otherwise, copy-on-write.
  2896. if (tween !== tween0) {
  2897. tween1 = tween0 = tween;
  2898. for (var i = 0, n = tween1.length; i < n; ++i) {
  2899. if (tween1[i].name === name) {
  2900. tween1 = tween1.slice();
  2901. tween1.splice(i, 1);
  2902. break;
  2903. }
  2904. }
  2905. }
  2906. schedule$$1.tween = tween1;
  2907. };
  2908. }
  2909. function tweenFunction(id, name, value) {
  2910. var tween0, tween1;
  2911. if (typeof value !== "function") throw new Error;
  2912. return function() {
  2913. var schedule$$1 = set$1(this, id),
  2914. tween = schedule$$1.tween;
  2915. // If this node shared tween with the previous node,
  2916. // just assign the updated shared tween and we’re done!
  2917. // Otherwise, copy-on-write.
  2918. if (tween !== tween0) {
  2919. tween1 = (tween0 = tween).slice();
  2920. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2921. if (tween1[i].name === name) {
  2922. tween1[i] = t;
  2923. break;
  2924. }
  2925. }
  2926. if (i === n) tween1.push(t);
  2927. }
  2928. schedule$$1.tween = tween1;
  2929. };
  2930. }
  2931. function transition_tween(name, value) {
  2932. var id = this._id;
  2933. name += "";
  2934. if (arguments.length < 2) {
  2935. var tween = get$1(this.node(), id).tween;
  2936. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2937. if ((t = tween[i]).name === name) {
  2938. return t.value;
  2939. }
  2940. }
  2941. return null;
  2942. }
  2943. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2944. }
  2945. function tweenValue(transition, name, value) {
  2946. var id = transition._id;
  2947. transition.each(function() {
  2948. var schedule$$1 = set$1(this, id);
  2949. (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
  2950. });
  2951. return function(node) {
  2952. return get$1(node, id).value[name];
  2953. };
  2954. }
  2955. function interpolate(a, b) {
  2956. var c;
  2957. return (typeof b === "number" ? interpolateNumber
  2958. : b instanceof color ? interpolateRgb
  2959. : (c = color(b)) ? (b = c, interpolateRgb)
  2960. : interpolateString)(a, b);
  2961. }
  2962. function attrRemove$1(name) {
  2963. return function() {
  2964. this.removeAttribute(name);
  2965. };
  2966. }
  2967. function attrRemoveNS$1(fullname) {
  2968. return function() {
  2969. this.removeAttributeNS(fullname.space, fullname.local);
  2970. };
  2971. }
  2972. function attrConstant$1(name, interpolate$$1, value1) {
  2973. var value00,
  2974. interpolate0;
  2975. return function() {
  2976. var value0 = this.getAttribute(name);
  2977. return value0 === value1 ? null
  2978. : value0 === value00 ? interpolate0
  2979. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2980. };
  2981. }
  2982. function attrConstantNS$1(fullname, interpolate$$1, value1) {
  2983. var value00,
  2984. interpolate0;
  2985. return function() {
  2986. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  2987. return value0 === value1 ? null
  2988. : value0 === value00 ? interpolate0
  2989. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2990. };
  2991. }
  2992. function attrFunction$1(name, interpolate$$1, value) {
  2993. var value00,
  2994. value10,
  2995. interpolate0;
  2996. return function() {
  2997. var value0, value1 = value(this);
  2998. if (value1 == null) return void this.removeAttribute(name);
  2999. value0 = this.getAttribute(name);
  3000. return value0 === value1 ? null
  3001. : value0 === value00 && value1 === value10 ? interpolate0
  3002. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3003. };
  3004. }
  3005. function attrFunctionNS$1(fullname, interpolate$$1, value) {
  3006. var value00,
  3007. value10,
  3008. interpolate0;
  3009. return function() {
  3010. var value0, value1 = value(this);
  3011. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3012. value0 = this.getAttributeNS(fullname.space, fullname.local);
  3013. return value0 === value1 ? null
  3014. : value0 === value00 && value1 === value10 ? interpolate0
  3015. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3016. };
  3017. }
  3018. function transition_attr(name, value) {
  3019. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  3020. return this.attrTween(name, typeof value === "function"
  3021. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  3022. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  3023. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
  3024. }
  3025. function attrTweenNS(fullname, value) {
  3026. function tween() {
  3027. var node = this, i = value.apply(node, arguments);
  3028. return i && function(t) {
  3029. node.setAttributeNS(fullname.space, fullname.local, i(t));
  3030. };
  3031. }
  3032. tween._value = value;
  3033. return tween;
  3034. }
  3035. function attrTween(name, value) {
  3036. function tween() {
  3037. var node = this, i = value.apply(node, arguments);
  3038. return i && function(t) {
  3039. node.setAttribute(name, i(t));
  3040. };
  3041. }
  3042. tween._value = value;
  3043. return tween;
  3044. }
  3045. function transition_attrTween(name, value) {
  3046. var key = "attr." + name;
  3047. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3048. if (value == null) return this.tween(key, null);
  3049. if (typeof value !== "function") throw new Error;
  3050. var fullname = namespace(name);
  3051. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3052. }
  3053. function delayFunction(id, value) {
  3054. return function() {
  3055. init(this, id).delay = +value.apply(this, arguments);
  3056. };
  3057. }
  3058. function delayConstant(id, value) {
  3059. return value = +value, function() {
  3060. init(this, id).delay = value;
  3061. };
  3062. }
  3063. function transition_delay(value) {
  3064. var id = this._id;
  3065. return arguments.length
  3066. ? this.each((typeof value === "function"
  3067. ? delayFunction
  3068. : delayConstant)(id, value))
  3069. : get$1(this.node(), id).delay;
  3070. }
  3071. function durationFunction(id, value) {
  3072. return function() {
  3073. set$1(this, id).duration = +value.apply(this, arguments);
  3074. };
  3075. }
  3076. function durationConstant(id, value) {
  3077. return value = +value, function() {
  3078. set$1(this, id).duration = value;
  3079. };
  3080. }
  3081. function transition_duration(value) {
  3082. var id = this._id;
  3083. return arguments.length
  3084. ? this.each((typeof value === "function"
  3085. ? durationFunction
  3086. : durationConstant)(id, value))
  3087. : get$1(this.node(), id).duration;
  3088. }
  3089. function easeConstant(id, value) {
  3090. if (typeof value !== "function") throw new Error;
  3091. return function() {
  3092. set$1(this, id).ease = value;
  3093. };
  3094. }
  3095. function transition_ease(value) {
  3096. var id = this._id;
  3097. return arguments.length
  3098. ? this.each(easeConstant(id, value))
  3099. : get$1(this.node(), id).ease;
  3100. }
  3101. function transition_filter(match) {
  3102. if (typeof match !== "function") match = matcher$1(match);
  3103. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3104. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3105. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3106. subgroup.push(node);
  3107. }
  3108. }
  3109. }
  3110. return new Transition(subgroups, this._parents, this._name, this._id);
  3111. }
  3112. function transition_merge(transition$$1) {
  3113. if (transition$$1._id !== this._id) throw new Error;
  3114. for (var groups0 = this._groups, groups1 = transition$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  3115. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3116. if (node = group0[i] || group1[i]) {
  3117. merge[i] = node;
  3118. }
  3119. }
  3120. }
  3121. for (; j < m0; ++j) {
  3122. merges[j] = groups0[j];
  3123. }
  3124. return new Transition(merges, this._parents, this._name, this._id);
  3125. }
  3126. function start(name) {
  3127. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3128. var i = t.indexOf(".");
  3129. if (i >= 0) t = t.slice(0, i);
  3130. return !t || t === "start";
  3131. });
  3132. }
  3133. function onFunction(id, name, listener) {
  3134. var on0, on1, sit = start(name) ? init : set$1;
  3135. return function() {
  3136. var schedule$$1 = sit(this, id),
  3137. on = schedule$$1.on;
  3138. // If this node shared a dispatch with the previous node,
  3139. // just assign the updated shared dispatch and we’re done!
  3140. // Otherwise, copy-on-write.
  3141. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3142. schedule$$1.on = on1;
  3143. };
  3144. }
  3145. function transition_on(name, listener) {
  3146. var id = this._id;
  3147. return arguments.length < 2
  3148. ? get$1(this.node(), id).on.on(name)
  3149. : this.each(onFunction(id, name, listener));
  3150. }
  3151. function removeFunction(id) {
  3152. return function() {
  3153. var parent = this.parentNode;
  3154. for (var i in this.__transition) if (+i !== id) return;
  3155. if (parent) parent.removeChild(this);
  3156. };
  3157. }
  3158. function transition_remove() {
  3159. return this.on("end.remove", removeFunction(this._id));
  3160. }
  3161. function transition_select(select$$1) {
  3162. var name = this._name,
  3163. id = this._id;
  3164. if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
  3165. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3166. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3167. if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
  3168. if ("__data__" in node) subnode.__data__ = node.__data__;
  3169. subgroup[i] = subnode;
  3170. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3171. }
  3172. }
  3173. }
  3174. return new Transition(subgroups, this._parents, name, id);
  3175. }
  3176. function transition_selectAll(select$$1) {
  3177. var name = this._name,
  3178. id = this._id;
  3179. if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
  3180. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3181. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3182. if (node = group[i]) {
  3183. 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) {
  3184. if (child = children[k]) {
  3185. schedule(child, name, id, k, children, inherit);
  3186. }
  3187. }
  3188. subgroups.push(children);
  3189. parents.push(node);
  3190. }
  3191. }
  3192. }
  3193. return new Transition(subgroups, parents, name, id);
  3194. }
  3195. var Selection$1 = selection.prototype.constructor;
  3196. function transition_selection() {
  3197. return new Selection$1(this._groups, this._parents);
  3198. }
  3199. function styleRemove$1(name, interpolate$$1) {
  3200. var value00,
  3201. value10,
  3202. interpolate0;
  3203. return function() {
  3204. var value0 = styleValue(this, name),
  3205. value1 = (this.style.removeProperty(name), styleValue(this, name));
  3206. return value0 === value1 ? null
  3207. : value0 === value00 && value1 === value10 ? interpolate0
  3208. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3209. };
  3210. }
  3211. function styleRemoveEnd(name) {
  3212. return function() {
  3213. this.style.removeProperty(name);
  3214. };
  3215. }
  3216. function styleConstant$1(name, interpolate$$1, value1) {
  3217. var value00,
  3218. interpolate0;
  3219. return function() {
  3220. var value0 = styleValue(this, name);
  3221. return value0 === value1 ? null
  3222. : value0 === value00 ? interpolate0
  3223. : interpolate0 = interpolate$$1(value00 = value0, value1);
  3224. };
  3225. }
  3226. function styleFunction$1(name, interpolate$$1, value) {
  3227. var value00,
  3228. value10,
  3229. interpolate0;
  3230. return function() {
  3231. var value0 = styleValue(this, name),
  3232. value1 = value(this);
  3233. if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
  3234. return value0 === value1 ? null
  3235. : value0 === value00 && value1 === value10 ? interpolate0
  3236. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3237. };
  3238. }
  3239. function transition_style(name, value, priority) {
  3240. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3241. return value == null ? this
  3242. .styleTween(name, styleRemove$1(name, i))
  3243. .on("end.style." + name, styleRemoveEnd(name))
  3244. : this.styleTween(name, typeof value === "function"
  3245. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  3246. : styleConstant$1(name, i, value + ""), priority);
  3247. }
  3248. function styleTween(name, value, priority) {
  3249. function tween() {
  3250. var node = this, i = value.apply(node, arguments);
  3251. return i && function(t) {
  3252. node.style.setProperty(name, i(t), priority);
  3253. };
  3254. }
  3255. tween._value = value;
  3256. return tween;
  3257. }
  3258. function transition_styleTween(name, value, priority) {
  3259. var key = "style." + (name += "");
  3260. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3261. if (value == null) return this.tween(key, null);
  3262. if (typeof value !== "function") throw new Error;
  3263. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3264. }
  3265. function textConstant$1(value) {
  3266. return function() {
  3267. this.textContent = value;
  3268. };
  3269. }
  3270. function textFunction$1(value) {
  3271. return function() {
  3272. var value1 = value(this);
  3273. this.textContent = value1 == null ? "" : value1;
  3274. };
  3275. }
  3276. function transition_text(value) {
  3277. return this.tween("text", typeof value === "function"
  3278. ? textFunction$1(tweenValue(this, "text", value))
  3279. : textConstant$1(value == null ? "" : value + ""));
  3280. }
  3281. function transition_transition() {
  3282. var name = this._name,
  3283. id0 = this._id,
  3284. id1 = newId();
  3285. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3286. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3287. if (node = group[i]) {
  3288. var inherit = get$1(node, id0);
  3289. schedule(node, name, id1, i, group, {
  3290. time: inherit.time + inherit.delay + inherit.duration,
  3291. delay: 0,
  3292. duration: inherit.duration,
  3293. ease: inherit.ease
  3294. });
  3295. }
  3296. }
  3297. }
  3298. return new Transition(groups, this._parents, name, id1);
  3299. }
  3300. var id = 0;
  3301. function Transition(groups, parents, name, id) {
  3302. this._groups = groups;
  3303. this._parents = parents;
  3304. this._name = name;
  3305. this._id = id;
  3306. }
  3307. function transition(name) {
  3308. return selection().transition(name);
  3309. }
  3310. function newId() {
  3311. return ++id;
  3312. }
  3313. var selection_prototype = selection.prototype;
  3314. Transition.prototype = transition.prototype = {
  3315. constructor: Transition,
  3316. select: transition_select,
  3317. selectAll: transition_selectAll,
  3318. filter: transition_filter,
  3319. merge: transition_merge,
  3320. selection: transition_selection,
  3321. transition: transition_transition,
  3322. call: selection_prototype.call,
  3323. nodes: selection_prototype.nodes,
  3324. node: selection_prototype.node,
  3325. size: selection_prototype.size,
  3326. empty: selection_prototype.empty,
  3327. each: selection_prototype.each,
  3328. on: transition_on,
  3329. attr: transition_attr,
  3330. attrTween: transition_attrTween,
  3331. style: transition_style,
  3332. styleTween: transition_styleTween,
  3333. text: transition_text,
  3334. remove: transition_remove,
  3335. tween: transition_tween,
  3336. delay: transition_delay,
  3337. duration: transition_duration,
  3338. ease: transition_ease
  3339. };
  3340. function linear$1(t) {
  3341. return +t;
  3342. }
  3343. function quadIn(t) {
  3344. return t * t;
  3345. }
  3346. function quadOut(t) {
  3347. return t * (2 - t);
  3348. }
  3349. function quadInOut(t) {
  3350. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3351. }
  3352. function cubicIn(t) {
  3353. return t * t * t;
  3354. }
  3355. function cubicOut(t) {
  3356. return --t * t * t + 1;
  3357. }
  3358. function cubicInOut(t) {
  3359. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3360. }
  3361. var exponent = 3;
  3362. var polyIn = (function custom(e) {
  3363. e = +e;
  3364. function polyIn(t) {
  3365. return Math.pow(t, e);
  3366. }
  3367. polyIn.exponent = custom;
  3368. return polyIn;
  3369. })(exponent);
  3370. var polyOut = (function custom(e) {
  3371. e = +e;
  3372. function polyOut(t) {
  3373. return 1 - Math.pow(1 - t, e);
  3374. }
  3375. polyOut.exponent = custom;
  3376. return polyOut;
  3377. })(exponent);
  3378. var polyInOut = (function custom(e) {
  3379. e = +e;
  3380. function polyInOut(t) {
  3381. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3382. }
  3383. polyInOut.exponent = custom;
  3384. return polyInOut;
  3385. })(exponent);
  3386. var pi = Math.PI,
  3387. halfPi = pi / 2;
  3388. function sinIn(t) {
  3389. return 1 - Math.cos(t * halfPi);
  3390. }
  3391. function sinOut(t) {
  3392. return Math.sin(t * halfPi);
  3393. }
  3394. function sinInOut(t) {
  3395. return (1 - Math.cos(pi * t)) / 2;
  3396. }
  3397. function expIn(t) {
  3398. return Math.pow(2, 10 * t - 10);
  3399. }
  3400. function expOut(t) {
  3401. return 1 - Math.pow(2, -10 * t);
  3402. }
  3403. function expInOut(t) {
  3404. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3405. }
  3406. function circleIn(t) {
  3407. return 1 - Math.sqrt(1 - t * t);
  3408. }
  3409. function circleOut(t) {
  3410. return Math.sqrt(1 - --t * t);
  3411. }
  3412. function circleInOut(t) {
  3413. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3414. }
  3415. var b1 = 4 / 11,
  3416. b2 = 6 / 11,
  3417. b3 = 8 / 11,
  3418. b4 = 3 / 4,
  3419. b5 = 9 / 11,
  3420. b6 = 10 / 11,
  3421. b7 = 15 / 16,
  3422. b8 = 21 / 22,
  3423. b9 = 63 / 64,
  3424. b0 = 1 / b1 / b1;
  3425. function bounceIn(t) {
  3426. return 1 - bounceOut(1 - t);
  3427. }
  3428. function bounceOut(t) {
  3429. 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;
  3430. }
  3431. function bounceInOut(t) {
  3432. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3433. }
  3434. var overshoot = 1.70158;
  3435. var backIn = (function custom(s) {
  3436. s = +s;
  3437. function backIn(t) {
  3438. return t * t * ((s + 1) * t - s);
  3439. }
  3440. backIn.overshoot = custom;
  3441. return backIn;
  3442. })(overshoot);
  3443. var backOut = (function custom(s) {
  3444. s = +s;
  3445. function backOut(t) {
  3446. return --t * t * ((s + 1) * t + s) + 1;
  3447. }
  3448. backOut.overshoot = custom;
  3449. return backOut;
  3450. })(overshoot);
  3451. var backInOut = (function custom(s) {
  3452. s = +s;
  3453. function backInOut(t) {
  3454. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3455. }
  3456. backInOut.overshoot = custom;
  3457. return backInOut;
  3458. })(overshoot);
  3459. var tau = 2 * Math.PI,
  3460. amplitude = 1,
  3461. period = 0.3;
  3462. var elasticIn = (function custom(a, p) {
  3463. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3464. function elasticIn(t) {
  3465. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3466. }
  3467. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3468. elasticIn.period = function(p) { return custom(a, p); };
  3469. return elasticIn;
  3470. })(amplitude, period);
  3471. var elasticOut = (function custom(a, p) {
  3472. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3473. function elasticOut(t) {
  3474. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3475. }
  3476. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3477. elasticOut.period = function(p) { return custom(a, p); };
  3478. return elasticOut;
  3479. })(amplitude, period);
  3480. var elasticInOut = (function custom(a, p) {
  3481. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3482. function elasticInOut(t) {
  3483. return ((t = t * 2 - 1) < 0
  3484. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3485. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3486. }
  3487. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3488. elasticInOut.period = function(p) { return custom(a, p); };
  3489. return elasticInOut;
  3490. })(amplitude, period);
  3491. var defaultTiming = {
  3492. time: null, // Set on use.
  3493. delay: 0,
  3494. duration: 250,
  3495. ease: cubicInOut
  3496. };
  3497. function inherit(node, id) {
  3498. var timing;
  3499. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3500. if (!(node = node.parentNode)) {
  3501. return defaultTiming.time = now(), defaultTiming;
  3502. }
  3503. }
  3504. return timing;
  3505. }
  3506. function selection_transition(name) {
  3507. var id,
  3508. timing;
  3509. if (name instanceof Transition) {
  3510. id = name._id, name = name._name;
  3511. } else {
  3512. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3513. }
  3514. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3515. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3516. if (node = group[i]) {
  3517. schedule(node, name, id, i, group, timing || inherit(node, id));
  3518. }
  3519. }
  3520. }
  3521. return new Transition(groups, this._parents, name, id);
  3522. }
  3523. selection.prototype.interrupt = selection_interrupt;
  3524. selection.prototype.transition = selection_transition;
  3525. var root$1 = [null];
  3526. function active(node, name) {
  3527. var schedules = node.__transition,
  3528. schedule$$1,
  3529. i;
  3530. if (schedules) {
  3531. name = name == null ? null : name + "";
  3532. for (i in schedules) {
  3533. if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
  3534. return new Transition([[node]], root$1, name, +i);
  3535. }
  3536. }
  3537. }
  3538. return null;
  3539. }
  3540. function constant$4(x) {
  3541. return function() {
  3542. return x;
  3543. };
  3544. }
  3545. function BrushEvent(target, type, selection) {
  3546. this.target = target;
  3547. this.type = type;
  3548. this.selection = selection;
  3549. }
  3550. function nopropagation$1() {
  3551. exports.event.stopImmediatePropagation();
  3552. }
  3553. function noevent$1() {
  3554. exports.event.preventDefault();
  3555. exports.event.stopImmediatePropagation();
  3556. }
  3557. var MODE_DRAG = {name: "drag"},
  3558. MODE_SPACE = {name: "space"},
  3559. MODE_HANDLE = {name: "handle"},
  3560. MODE_CENTER = {name: "center"};
  3561. var X = {
  3562. name: "x",
  3563. handles: ["e", "w"].map(type),
  3564. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  3565. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3566. };
  3567. var Y = {
  3568. name: "y",
  3569. handles: ["n", "s"].map(type),
  3570. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  3571. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3572. };
  3573. var XY = {
  3574. name: "xy",
  3575. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
  3576. input: function(xy) { return xy; },
  3577. output: function(xy) { return xy; }
  3578. };
  3579. var cursors = {
  3580. overlay: "crosshair",
  3581. selection: "move",
  3582. n: "ns-resize",
  3583. e: "ew-resize",
  3584. s: "ns-resize",
  3585. w: "ew-resize",
  3586. nw: "nwse-resize",
  3587. ne: "nesw-resize",
  3588. se: "nwse-resize",
  3589. sw: "nesw-resize"
  3590. };
  3591. var flipX = {
  3592. e: "w",
  3593. w: "e",
  3594. nw: "ne",
  3595. ne: "nw",
  3596. se: "sw",
  3597. sw: "se"
  3598. };
  3599. var flipY = {
  3600. n: "s",
  3601. s: "n",
  3602. nw: "sw",
  3603. ne: "se",
  3604. se: "ne",
  3605. sw: "nw"
  3606. };
  3607. var signsX = {
  3608. overlay: +1,
  3609. selection: +1,
  3610. n: null,
  3611. e: +1,
  3612. s: null,
  3613. w: -1,
  3614. nw: -1,
  3615. ne: +1,
  3616. se: +1,
  3617. sw: -1
  3618. };
  3619. var signsY = {
  3620. overlay: +1,
  3621. selection: +1,
  3622. n: -1,
  3623. e: null,
  3624. s: +1,
  3625. w: null,
  3626. nw: -1,
  3627. ne: -1,
  3628. se: +1,
  3629. sw: +1
  3630. };
  3631. function type(t) {
  3632. return {type: t};
  3633. }
  3634. // Ignore right-click, since that should open the context menu.
  3635. function defaultFilter$1() {
  3636. return !exports.event.button;
  3637. }
  3638. function defaultExtent() {
  3639. var svg = this.ownerSVGElement || this;
  3640. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3641. }
  3642. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3643. function local$1(node) {
  3644. while (!node.__brush) if (!(node = node.parentNode)) return;
  3645. return node.__brush;
  3646. }
  3647. function empty$1(extent) {
  3648. return extent[0][0] === extent[1][0]
  3649. || extent[0][1] === extent[1][1];
  3650. }
  3651. function brushSelection(node) {
  3652. var state = node.__brush;
  3653. return state ? state.dim.output(state.selection) : null;
  3654. }
  3655. function brushX() {
  3656. return brush$1(X);
  3657. }
  3658. function brushY() {
  3659. return brush$1(Y);
  3660. }
  3661. function brush() {
  3662. return brush$1(XY);
  3663. }
  3664. function brush$1(dim) {
  3665. var extent = defaultExtent,
  3666. filter = defaultFilter$1,
  3667. listeners = dispatch(brush, "start", "brush", "end"),
  3668. handleSize = 6,
  3669. touchending;
  3670. function brush(group) {
  3671. var overlay = group
  3672. .property("__brush", initialize)
  3673. .selectAll(".overlay")
  3674. .data([type("overlay")]);
  3675. overlay.enter().append("rect")
  3676. .attr("class", "overlay")
  3677. .attr("pointer-events", "all")
  3678. .attr("cursor", cursors.overlay)
  3679. .merge(overlay)
  3680. .each(function() {
  3681. var extent = local$1(this).extent;
  3682. select(this)
  3683. .attr("x", extent[0][0])
  3684. .attr("y", extent[0][1])
  3685. .attr("width", extent[1][0] - extent[0][0])
  3686. .attr("height", extent[1][1] - extent[0][1]);
  3687. });
  3688. group.selectAll(".selection")
  3689. .data([type("selection")])
  3690. .enter().append("rect")
  3691. .attr("class", "selection")
  3692. .attr("cursor", cursors.selection)
  3693. .attr("fill", "#777")
  3694. .attr("fill-opacity", 0.3)
  3695. .attr("stroke", "#fff")
  3696. .attr("shape-rendering", "crispEdges");
  3697. var handle = group.selectAll(".handle")
  3698. .data(dim.handles, function(d) { return d.type; });
  3699. handle.exit().remove();
  3700. handle.enter().append("rect")
  3701. .attr("class", function(d) { return "handle handle--" + d.type; })
  3702. .attr("cursor", function(d) { return cursors[d.type]; });
  3703. group
  3704. .each(redraw)
  3705. .attr("fill", "none")
  3706. .attr("pointer-events", "all")
  3707. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  3708. .on("mousedown.brush touchstart.brush", started);
  3709. }
  3710. brush.move = function(group, selection$$1) {
  3711. if (group.selection) {
  3712. group
  3713. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3714. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3715. .tween("brush", function() {
  3716. var that = this,
  3717. state = that.__brush,
  3718. emit = emitter(that, arguments),
  3719. selection0 = state.selection,
  3720. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
  3721. i = interpolateValue(selection0, selection1);
  3722. function tween(t) {
  3723. state.selection = t === 1 && empty$1(selection1) ? null : i(t);
  3724. redraw.call(that);
  3725. emit.brush();
  3726. }
  3727. return selection0 && selection1 ? tween : tween(1);
  3728. });
  3729. } else {
  3730. group
  3731. .each(function() {
  3732. var that = this,
  3733. args = arguments,
  3734. state = that.__brush,
  3735. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
  3736. emit = emitter(that, args).beforestart();
  3737. interrupt(that);
  3738. state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
  3739. redraw.call(that);
  3740. emit.start().brush().end();
  3741. });
  3742. }
  3743. };
  3744. function redraw() {
  3745. var group = select(this),
  3746. selection$$1 = local$1(this).selection;
  3747. if (selection$$1) {
  3748. group.selectAll(".selection")
  3749. .style("display", null)
  3750. .attr("x", selection$$1[0][0])
  3751. .attr("y", selection$$1[0][1])
  3752. .attr("width", selection$$1[1][0] - selection$$1[0][0])
  3753. .attr("height", selection$$1[1][1] - selection$$1[0][1]);
  3754. group.selectAll(".handle")
  3755. .style("display", null)
  3756. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
  3757. .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
  3758. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
  3759. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
  3760. }
  3761. else {
  3762. group.selectAll(".selection,.handle")
  3763. .style("display", "none")
  3764. .attr("x", null)
  3765. .attr("y", null)
  3766. .attr("width", null)
  3767. .attr("height", null);
  3768. }
  3769. }
  3770. function emitter(that, args) {
  3771. return that.__brush.emitter || new Emitter(that, args);
  3772. }
  3773. function Emitter(that, args) {
  3774. this.that = that;
  3775. this.args = args;
  3776. this.state = that.__brush;
  3777. this.active = 0;
  3778. }
  3779. Emitter.prototype = {
  3780. beforestart: function() {
  3781. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3782. return this;
  3783. },
  3784. start: function() {
  3785. if (this.starting) this.starting = false, this.emit("start");
  3786. return this;
  3787. },
  3788. brush: function() {
  3789. this.emit("brush");
  3790. return this;
  3791. },
  3792. end: function() {
  3793. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3794. return this;
  3795. },
  3796. emit: function(type) {
  3797. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3798. }
  3799. };
  3800. function started() {
  3801. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
  3802. else if (touchending) return;
  3803. if (!filter.apply(this, arguments)) return;
  3804. var that = this,
  3805. type = exports.event.target.__data__.type,
  3806. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3807. signX = dim === Y ? null : signsX[type],
  3808. signY = dim === X ? null : signsY[type],
  3809. state = local$1(that),
  3810. extent = state.extent,
  3811. selection$$1 = state.selection,
  3812. W = extent[0][0], w0, w1,
  3813. N = extent[0][1], n0, n1,
  3814. E = extent[1][0], e0, e1,
  3815. S = extent[1][1], s0, s1,
  3816. dx,
  3817. dy,
  3818. moving,
  3819. shifting = signX && signY && exports.event.shiftKey,
  3820. lockX,
  3821. lockY,
  3822. point0 = mouse(that),
  3823. point$$1 = point0,
  3824. emit = emitter(that, arguments).beforestart();
  3825. if (type === "overlay") {
  3826. state.selection = selection$$1 = [
  3827. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3828. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3829. ];
  3830. } else {
  3831. w0 = selection$$1[0][0];
  3832. n0 = selection$$1[0][1];
  3833. e0 = selection$$1[1][0];
  3834. s0 = selection$$1[1][1];
  3835. }
  3836. w1 = w0;
  3837. n1 = n0;
  3838. e1 = e0;
  3839. s1 = s0;
  3840. var group = select(that)
  3841. .attr("pointer-events", "none");
  3842. var overlay = group.selectAll(".overlay")
  3843. .attr("cursor", cursors[type]);
  3844. if (exports.event.touches) {
  3845. group
  3846. .on("touchmove.brush", moved, true)
  3847. .on("touchend.brush touchcancel.brush", ended, true);
  3848. } else {
  3849. var view = select(exports.event.view)
  3850. .on("keydown.brush", keydowned, true)
  3851. .on("keyup.brush", keyupped, true)
  3852. .on("mousemove.brush", moved, true)
  3853. .on("mouseup.brush", ended, true);
  3854. dragDisable(exports.event.view);
  3855. }
  3856. nopropagation$1();
  3857. interrupt(that);
  3858. redraw.call(that);
  3859. emit.start();
  3860. function moved() {
  3861. var point1 = mouse(that);
  3862. if (shifting && !lockX && !lockY) {
  3863. if (Math.abs(point1[0] - point$$1[0]) > Math.abs(point1[1] - point$$1[1])) lockY = true;
  3864. else lockX = true;
  3865. }
  3866. point$$1 = point1;
  3867. moving = true;
  3868. noevent$1();
  3869. move();
  3870. }
  3871. function move() {
  3872. var t;
  3873. dx = point$$1[0] - point0[0];
  3874. dy = point$$1[1] - point0[1];
  3875. switch (mode) {
  3876. case MODE_SPACE:
  3877. case MODE_DRAG: {
  3878. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  3879. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  3880. break;
  3881. }
  3882. case MODE_HANDLE: {
  3883. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  3884. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  3885. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  3886. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  3887. break;
  3888. }
  3889. case MODE_CENTER: {
  3890. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  3891. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  3892. break;
  3893. }
  3894. }
  3895. if (e1 < w1) {
  3896. signX *= -1;
  3897. t = w0, w0 = e0, e0 = t;
  3898. t = w1, w1 = e1, e1 = t;
  3899. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  3900. }
  3901. if (s1 < n1) {
  3902. signY *= -1;
  3903. t = n0, n0 = s0, s0 = t;
  3904. t = n1, n1 = s1, s1 = t;
  3905. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  3906. }
  3907. if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
  3908. if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
  3909. if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
  3910. if (selection$$1[0][0] !== w1
  3911. || selection$$1[0][1] !== n1
  3912. || selection$$1[1][0] !== e1
  3913. || selection$$1[1][1] !== s1) {
  3914. state.selection = [[w1, n1], [e1, s1]];
  3915. redraw.call(that);
  3916. emit.brush();
  3917. }
  3918. }
  3919. function ended() {
  3920. nopropagation$1();
  3921. if (exports.event.touches) {
  3922. if (exports.event.touches.length) return;
  3923. if (touchending) clearTimeout(touchending);
  3924. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  3925. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  3926. } else {
  3927. yesdrag(exports.event.view, moving);
  3928. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  3929. }
  3930. group.attr("pointer-events", "all");
  3931. overlay.attr("cursor", cursors.overlay);
  3932. if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
  3933. if (empty$1(selection$$1)) state.selection = null, redraw.call(that);
  3934. emit.end();
  3935. }
  3936. function keydowned() {
  3937. switch (exports.event.keyCode) {
  3938. case 16: { // SHIFT
  3939. shifting = signX && signY;
  3940. break;
  3941. }
  3942. case 18: { // ALT
  3943. if (mode === MODE_HANDLE) {
  3944. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3945. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3946. mode = MODE_CENTER;
  3947. move();
  3948. }
  3949. break;
  3950. }
  3951. case 32: { // SPACE; takes priority over ALT
  3952. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  3953. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  3954. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  3955. mode = MODE_SPACE;
  3956. overlay.attr("cursor", cursors.selection);
  3957. move();
  3958. }
  3959. break;
  3960. }
  3961. default: return;
  3962. }
  3963. noevent$1();
  3964. }
  3965. function keyupped() {
  3966. switch (exports.event.keyCode) {
  3967. case 16: { // SHIFT
  3968. if (shifting) {
  3969. lockX = lockY = shifting = false;
  3970. move();
  3971. }
  3972. break;
  3973. }
  3974. case 18: { // ALT
  3975. if (mode === MODE_CENTER) {
  3976. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3977. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3978. mode = MODE_HANDLE;
  3979. move();
  3980. }
  3981. break;
  3982. }
  3983. case 32: { // SPACE
  3984. if (mode === MODE_SPACE) {
  3985. if (exports.event.altKey) {
  3986. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3987. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3988. mode = MODE_CENTER;
  3989. } else {
  3990. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3991. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3992. mode = MODE_HANDLE;
  3993. }
  3994. overlay.attr("cursor", cursors[type]);
  3995. move();
  3996. }
  3997. break;
  3998. }
  3999. default: return;
  4000. }
  4001. noevent$1();
  4002. }
  4003. }
  4004. function initialize() {
  4005. var state = this.__brush || {selection: null};
  4006. state.extent = extent.apply(this, arguments);
  4007. state.dim = dim;
  4008. return state;
  4009. }
  4010. brush.extent = function(_) {
  4011. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  4012. };
  4013. brush.filter = function(_) {
  4014. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  4015. };
  4016. brush.handleSize = function(_) {
  4017. return arguments.length ? (handleSize = +_, brush) : handleSize;
  4018. };
  4019. brush.on = function() {
  4020. var value = listeners.on.apply(listeners, arguments);
  4021. return value === listeners ? brush : value;
  4022. };
  4023. return brush;
  4024. }
  4025. var cos = Math.cos;
  4026. var sin = Math.sin;
  4027. var pi$1 = Math.PI;
  4028. var halfPi$1 = pi$1 / 2;
  4029. var tau$1 = pi$1 * 2;
  4030. var max$1 = Math.max;
  4031. function compareValue(compare) {
  4032. return function(a, b) {
  4033. return compare(
  4034. a.source.value + a.target.value,
  4035. b.source.value + b.target.value
  4036. );
  4037. };
  4038. }
  4039. function chord() {
  4040. var padAngle = 0,
  4041. sortGroups = null,
  4042. sortSubgroups = null,
  4043. sortChords = null;
  4044. function chord(matrix) {
  4045. var n = matrix.length,
  4046. groupSums = [],
  4047. groupIndex = sequence(n),
  4048. subgroupIndex = [],
  4049. chords = [],
  4050. groups = chords.groups = new Array(n),
  4051. subgroups = new Array(n * n),
  4052. k,
  4053. x,
  4054. x0,
  4055. dx,
  4056. i,
  4057. j;
  4058. // Compute the sum.
  4059. k = 0, i = -1; while (++i < n) {
  4060. x = 0, j = -1; while (++j < n) {
  4061. x += matrix[i][j];
  4062. }
  4063. groupSums.push(x);
  4064. subgroupIndex.push(sequence(n));
  4065. k += x;
  4066. }
  4067. // Sort groups…
  4068. if (sortGroups) groupIndex.sort(function(a, b) {
  4069. return sortGroups(groupSums[a], groupSums[b]);
  4070. });
  4071. // Sort subgroups…
  4072. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4073. d.sort(function(a, b) {
  4074. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4075. });
  4076. });
  4077. // Convert the sum to scaling factor for [0, 2pi].
  4078. // TODO Allow start and end angle to be specified?
  4079. // TODO Allow padding to be specified as percentage?
  4080. k = max$1(0, tau$1 - padAngle * n) / k;
  4081. dx = k ? padAngle : tau$1 / n;
  4082. // Compute the start and end angle for each group and subgroup.
  4083. // Note: Opera has a bug reordering object literal properties!
  4084. x = 0, i = -1; while (++i < n) {
  4085. x0 = x, j = -1; while (++j < n) {
  4086. var di = groupIndex[i],
  4087. dj = subgroupIndex[di][j],
  4088. v = matrix[di][dj],
  4089. a0 = x,
  4090. a1 = x += v * k;
  4091. subgroups[dj * n + di] = {
  4092. index: di,
  4093. subindex: dj,
  4094. startAngle: a0,
  4095. endAngle: a1,
  4096. value: v
  4097. };
  4098. }
  4099. groups[di] = {
  4100. index: di,
  4101. startAngle: x0,
  4102. endAngle: x,
  4103. value: groupSums[di]
  4104. };
  4105. x += dx;
  4106. }
  4107. // Generate chords for each (non-empty) subgroup-subgroup link.
  4108. i = -1; while (++i < n) {
  4109. j = i - 1; while (++j < n) {
  4110. var source = subgroups[j * n + i],
  4111. target = subgroups[i * n + j];
  4112. if (source.value || target.value) {
  4113. chords.push(source.value < target.value
  4114. ? {source: target, target: source}
  4115. : {source: source, target: target});
  4116. }
  4117. }
  4118. }
  4119. return sortChords ? chords.sort(sortChords) : chords;
  4120. }
  4121. chord.padAngle = function(_) {
  4122. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4123. };
  4124. chord.sortGroups = function(_) {
  4125. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4126. };
  4127. chord.sortSubgroups = function(_) {
  4128. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4129. };
  4130. chord.sortChords = function(_) {
  4131. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4132. };
  4133. return chord;
  4134. }
  4135. var slice$2 = Array.prototype.slice;
  4136. function constant$5(x) {
  4137. return function() {
  4138. return x;
  4139. };
  4140. }
  4141. var pi$2 = Math.PI,
  4142. tau$2 = 2 * pi$2,
  4143. epsilon$1 = 1e-6,
  4144. tauEpsilon = tau$2 - epsilon$1;
  4145. function Path() {
  4146. this._x0 = this._y0 = // start of current subpath
  4147. this._x1 = this._y1 = null; // end of current subpath
  4148. this._ = "";
  4149. }
  4150. function path() {
  4151. return new Path;
  4152. }
  4153. Path.prototype = path.prototype = {
  4154. constructor: Path,
  4155. moveTo: function(x, y) {
  4156. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4157. },
  4158. closePath: function() {
  4159. if (this._x1 !== null) {
  4160. this._x1 = this._x0, this._y1 = this._y0;
  4161. this._ += "Z";
  4162. }
  4163. },
  4164. lineTo: function(x, y) {
  4165. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4166. },
  4167. quadraticCurveTo: function(x1, y1, x, y) {
  4168. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4169. },
  4170. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4171. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4172. },
  4173. arcTo: function(x1, y1, x2, y2, r) {
  4174. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4175. var x0 = this._x1,
  4176. y0 = this._y1,
  4177. x21 = x2 - x1,
  4178. y21 = y2 - y1,
  4179. x01 = x0 - x1,
  4180. y01 = y0 - y1,
  4181. l01_2 = x01 * x01 + y01 * y01;
  4182. // Is the radius negative? Error.
  4183. if (r < 0) throw new Error("negative radius: " + r);
  4184. // Is this path empty? Move to (x1,y1).
  4185. if (this._x1 === null) {
  4186. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4187. }
  4188. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4189. else if (!(l01_2 > epsilon$1)) ;
  4190. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4191. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4192. // Or, is the radius zero? Line to (x1,y1).
  4193. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4194. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4195. }
  4196. // Otherwise, draw an arc!
  4197. else {
  4198. var x20 = x2 - x0,
  4199. y20 = y2 - y0,
  4200. l21_2 = x21 * x21 + y21 * y21,
  4201. l20_2 = x20 * x20 + y20 * y20,
  4202. l21 = Math.sqrt(l21_2),
  4203. l01 = Math.sqrt(l01_2),
  4204. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4205. t01 = l / l01,
  4206. t21 = l / l21;
  4207. // If the start tangent is not coincident with (x0,y0), line to.
  4208. if (Math.abs(t01 - 1) > epsilon$1) {
  4209. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4210. }
  4211. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4212. }
  4213. },
  4214. arc: function(x, y, r, a0, a1, ccw) {
  4215. x = +x, y = +y, r = +r;
  4216. var dx = r * Math.cos(a0),
  4217. dy = r * Math.sin(a0),
  4218. x0 = x + dx,
  4219. y0 = y + dy,
  4220. cw = 1 ^ ccw,
  4221. da = ccw ? a0 - a1 : a1 - a0;
  4222. // Is the radius negative? Error.
  4223. if (r < 0) throw new Error("negative radius: " + r);
  4224. // Is this path empty? Move to (x0,y0).
  4225. if (this._x1 === null) {
  4226. this._ += "M" + x0 + "," + y0;
  4227. }
  4228. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4229. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4230. this._ += "L" + x0 + "," + y0;
  4231. }
  4232. // Is this arc empty? We’re done.
  4233. if (!r) return;
  4234. // Does the angle go the wrong way? Flip the direction.
  4235. if (da < 0) da = da % tau$2 + tau$2;
  4236. // Is this a complete circle? Draw two arcs to complete the circle.
  4237. if (da > tauEpsilon) {
  4238. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4239. }
  4240. // Is this arc non-empty? Draw an arc!
  4241. else if (da > epsilon$1) {
  4242. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4243. }
  4244. },
  4245. rect: function(x, y, w, h) {
  4246. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4247. },
  4248. toString: function() {
  4249. return this._;
  4250. }
  4251. };
  4252. function defaultSource(d) {
  4253. return d.source;
  4254. }
  4255. function defaultTarget(d) {
  4256. return d.target;
  4257. }
  4258. function defaultRadius(d) {
  4259. return d.radius;
  4260. }
  4261. function defaultStartAngle(d) {
  4262. return d.startAngle;
  4263. }
  4264. function defaultEndAngle(d) {
  4265. return d.endAngle;
  4266. }
  4267. function ribbon() {
  4268. var source = defaultSource,
  4269. target = defaultTarget,
  4270. radius = defaultRadius,
  4271. startAngle = defaultStartAngle,
  4272. endAngle = defaultEndAngle,
  4273. context = null;
  4274. function ribbon() {
  4275. var buffer,
  4276. argv = slice$2.call(arguments),
  4277. s = source.apply(this, argv),
  4278. t = target.apply(this, argv),
  4279. sr = +radius.apply(this, (argv[0] = s, argv)),
  4280. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4281. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4282. sx0 = sr * cos(sa0),
  4283. sy0 = sr * sin(sa0),
  4284. tr = +radius.apply(this, (argv[0] = t, argv)),
  4285. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4286. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4287. if (!context) context = buffer = path();
  4288. context.moveTo(sx0, sy0);
  4289. context.arc(0, 0, sr, sa0, sa1);
  4290. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4291. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4292. context.arc(0, 0, tr, ta0, ta1);
  4293. }
  4294. context.quadraticCurveTo(0, 0, sx0, sy0);
  4295. context.closePath();
  4296. if (buffer) return context = null, buffer + "" || null;
  4297. }
  4298. ribbon.radius = function(_) {
  4299. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4300. };
  4301. ribbon.startAngle = function(_) {
  4302. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4303. };
  4304. ribbon.endAngle = function(_) {
  4305. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4306. };
  4307. ribbon.source = function(_) {
  4308. return arguments.length ? (source = _, ribbon) : source;
  4309. };
  4310. ribbon.target = function(_) {
  4311. return arguments.length ? (target = _, ribbon) : target;
  4312. };
  4313. ribbon.context = function(_) {
  4314. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  4315. };
  4316. return ribbon;
  4317. }
  4318. var prefix = "$";
  4319. function Map() {}
  4320. Map.prototype = map$1.prototype = {
  4321. constructor: Map,
  4322. has: function(key) {
  4323. return (prefix + key) in this;
  4324. },
  4325. get: function(key) {
  4326. return this[prefix + key];
  4327. },
  4328. set: function(key, value) {
  4329. this[prefix + key] = value;
  4330. return this;
  4331. },
  4332. remove: function(key) {
  4333. var property = prefix + key;
  4334. return property in this && delete this[property];
  4335. },
  4336. clear: function() {
  4337. for (var property in this) if (property[0] === prefix) delete this[property];
  4338. },
  4339. keys: function() {
  4340. var keys = [];
  4341. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4342. return keys;
  4343. },
  4344. values: function() {
  4345. var values = [];
  4346. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4347. return values;
  4348. },
  4349. entries: function() {
  4350. var entries = [];
  4351. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4352. return entries;
  4353. },
  4354. size: function() {
  4355. var size = 0;
  4356. for (var property in this) if (property[0] === prefix) ++size;
  4357. return size;
  4358. },
  4359. empty: function() {
  4360. for (var property in this) if (property[0] === prefix) return false;
  4361. return true;
  4362. },
  4363. each: function(f) {
  4364. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4365. }
  4366. };
  4367. function map$1(object, f) {
  4368. var map = new Map;
  4369. // Copy constructor.
  4370. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4371. // Index array by numeric index or specified key function.
  4372. else if (Array.isArray(object)) {
  4373. var i = -1,
  4374. n = object.length,
  4375. o;
  4376. if (f == null) while (++i < n) map.set(i, object[i]);
  4377. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4378. }
  4379. // Convert object to map.
  4380. else if (object) for (var key in object) map.set(key, object[key]);
  4381. return map;
  4382. }
  4383. function nest() {
  4384. var keys = [],
  4385. sortKeys = [],
  4386. sortValues,
  4387. rollup,
  4388. nest;
  4389. function apply(array, depth, createResult, setResult) {
  4390. if (depth >= keys.length) {
  4391. if (sortValues != null) array.sort(sortValues);
  4392. return rollup != null ? rollup(array) : array;
  4393. }
  4394. var i = -1,
  4395. n = array.length,
  4396. key = keys[depth++],
  4397. keyValue,
  4398. value,
  4399. valuesByKey = map$1(),
  4400. values,
  4401. result = createResult();
  4402. while (++i < n) {
  4403. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4404. values.push(value);
  4405. } else {
  4406. valuesByKey.set(keyValue, [value]);
  4407. }
  4408. }
  4409. valuesByKey.each(function(values, key) {
  4410. setResult(result, key, apply(values, depth, createResult, setResult));
  4411. });
  4412. return result;
  4413. }
  4414. function entries(map, depth) {
  4415. if (++depth > keys.length) return map;
  4416. var array, sortKey = sortKeys[depth - 1];
  4417. if (rollup != null && depth >= keys.length) array = map.entries();
  4418. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4419. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4420. }
  4421. return nest = {
  4422. object: function(array) { return apply(array, 0, createObject, setObject); },
  4423. map: function(array) { return apply(array, 0, createMap, setMap); },
  4424. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4425. key: function(d) { keys.push(d); return nest; },
  4426. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4427. sortValues: function(order) { sortValues = order; return nest; },
  4428. rollup: function(f) { rollup = f; return nest; }
  4429. };
  4430. }
  4431. function createObject() {
  4432. return {};
  4433. }
  4434. function setObject(object, key, value) {
  4435. object[key] = value;
  4436. }
  4437. function createMap() {
  4438. return map$1();
  4439. }
  4440. function setMap(map, key, value) {
  4441. map.set(key, value);
  4442. }
  4443. function Set() {}
  4444. var proto = map$1.prototype;
  4445. Set.prototype = set$2.prototype = {
  4446. constructor: Set,
  4447. has: proto.has,
  4448. add: function(value) {
  4449. value += "";
  4450. this[prefix + value] = value;
  4451. return this;
  4452. },
  4453. remove: proto.remove,
  4454. clear: proto.clear,
  4455. values: proto.keys,
  4456. size: proto.size,
  4457. empty: proto.empty,
  4458. each: proto.each
  4459. };
  4460. function set$2(object, f) {
  4461. var set = new Set;
  4462. // Copy constructor.
  4463. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4464. // Otherwise, assume it’s an array.
  4465. else if (object) {
  4466. var i = -1, n = object.length;
  4467. if (f == null) while (++i < n) set.add(object[i]);
  4468. else while (++i < n) set.add(f(object[i], i, object));
  4469. }
  4470. return set;
  4471. }
  4472. function keys(map) {
  4473. var keys = [];
  4474. for (var key in map) keys.push(key);
  4475. return keys;
  4476. }
  4477. function values(map) {
  4478. var values = [];
  4479. for (var key in map) values.push(map[key]);
  4480. return values;
  4481. }
  4482. function entries(map) {
  4483. var entries = [];
  4484. for (var key in map) entries.push({key: key, value: map[key]});
  4485. return entries;
  4486. }
  4487. var array$2 = Array.prototype;
  4488. var slice$3 = array$2.slice;
  4489. function ascending$2(a, b) {
  4490. return a - b;
  4491. }
  4492. function area(ring) {
  4493. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  4494. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  4495. return area;
  4496. }
  4497. function constant$6(x) {
  4498. return function() {
  4499. return x;
  4500. };
  4501. }
  4502. function contains(ring, hole) {
  4503. var i = -1, n = hole.length, c;
  4504. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  4505. return 0;
  4506. }
  4507. function ringContains(ring, point) {
  4508. var x = point[0], y = point[1], contains = -1;
  4509. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  4510. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  4511. if (segmentContains(pi, pj, point)) return 0;
  4512. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  4513. }
  4514. return contains;
  4515. }
  4516. function segmentContains(a, b, c) {
  4517. var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  4518. }
  4519. function collinear(a, b, c) {
  4520. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  4521. }
  4522. function within(p, q, r) {
  4523. return p <= q && q <= r || r <= q && q <= p;
  4524. }
  4525. function noop$1() {}
  4526. var cases = [
  4527. [],
  4528. [[[1.0, 1.5], [0.5, 1.0]]],
  4529. [[[1.5, 1.0], [1.0, 1.5]]],
  4530. [[[1.5, 1.0], [0.5, 1.0]]],
  4531. [[[1.0, 0.5], [1.5, 1.0]]],
  4532. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  4533. [[[1.0, 0.5], [1.0, 1.5]]],
  4534. [[[1.0, 0.5], [0.5, 1.0]]],
  4535. [[[0.5, 1.0], [1.0, 0.5]]],
  4536. [[[1.0, 1.5], [1.0, 0.5]]],
  4537. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  4538. [[[1.5, 1.0], [1.0, 0.5]]],
  4539. [[[0.5, 1.0], [1.5, 1.0]]],
  4540. [[[1.0, 1.5], [1.5, 1.0]]],
  4541. [[[0.5, 1.0], [1.0, 1.5]]],
  4542. []
  4543. ];
  4544. function contours() {
  4545. var dx = 1,
  4546. dy = 1,
  4547. threshold$$1 = thresholdSturges,
  4548. smooth = smoothLinear;
  4549. function contours(values) {
  4550. var tz = threshold$$1(values);
  4551. // Convert number of thresholds into uniform thresholds.
  4552. if (!Array.isArray(tz)) {
  4553. var domain = extent(values), start = domain[0], stop = domain[1];
  4554. tz = tickStep(start, stop, tz);
  4555. tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
  4556. } else {
  4557. tz = tz.slice().sort(ascending$2);
  4558. }
  4559. return tz.map(function(value) {
  4560. return contour(values, value);
  4561. });
  4562. }
  4563. // Accumulate, smooth contour rings, assign holes to exterior rings.
  4564. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  4565. function contour(values, value) {
  4566. var polygons = [],
  4567. holes = [];
  4568. isorings(values, value, function(ring) {
  4569. smooth(ring, values, value);
  4570. if (area(ring) > 0) polygons.push([ring]);
  4571. else holes.push(ring);
  4572. });
  4573. holes.forEach(function(hole) {
  4574. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  4575. if (contains((polygon = polygons[i])[0], hole) !== -1) {
  4576. polygon.push(hole);
  4577. return;
  4578. }
  4579. }
  4580. });
  4581. return {
  4582. type: "MultiPolygon",
  4583. value: value,
  4584. coordinates: polygons
  4585. };
  4586. }
  4587. // Marching squares with isolines stitched into rings.
  4588. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  4589. function isorings(values, value, callback) {
  4590. var fragmentByStart = new Array,
  4591. fragmentByEnd = new Array,
  4592. x, y, t0, t1, t2, t3;
  4593. // Special case for the first row (y = -1, t2 = t3 = 0).
  4594. x = y = -1;
  4595. t1 = values[0] >= value;
  4596. cases[t1 << 1].forEach(stitch);
  4597. while (++x < dx - 1) {
  4598. t0 = t1, t1 = values[x + 1] >= value;
  4599. cases[t0 | t1 << 1].forEach(stitch);
  4600. }
  4601. cases[t1 << 0].forEach(stitch);
  4602. // General case for the intermediate rows.
  4603. while (++y < dy - 1) {
  4604. x = -1;
  4605. t1 = values[y * dx + dx] >= value;
  4606. t2 = values[y * dx] >= value;
  4607. cases[t1 << 1 | t2 << 2].forEach(stitch);
  4608. while (++x < dx - 1) {
  4609. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  4610. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4611. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  4612. }
  4613. cases[t1 | t2 << 3].forEach(stitch);
  4614. }
  4615. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  4616. x = -1;
  4617. t2 = values[y * dx] >= value;
  4618. cases[t2 << 2].forEach(stitch);
  4619. while (++x < dx - 1) {
  4620. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4621. cases[t2 << 2 | t3 << 3].forEach(stitch);
  4622. }
  4623. cases[t2 << 3].forEach(stitch);
  4624. function stitch(line) {
  4625. var start = [line[0][0] + x, line[0][1] + y],
  4626. end = [line[1][0] + x, line[1][1] + y],
  4627. startIndex = index(start),
  4628. endIndex = index(end),
  4629. f, g;
  4630. if (f = fragmentByEnd[startIndex]) {
  4631. if (g = fragmentByStart[endIndex]) {
  4632. delete fragmentByEnd[f.end];
  4633. delete fragmentByStart[g.start];
  4634. if (f === g) {
  4635. f.ring.push(end);
  4636. callback(f.ring);
  4637. } else {
  4638. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  4639. }
  4640. } else {
  4641. delete fragmentByEnd[f.end];
  4642. f.ring.push(end);
  4643. fragmentByEnd[f.end = endIndex] = f;
  4644. }
  4645. } else if (f = fragmentByStart[endIndex]) {
  4646. if (g = fragmentByEnd[startIndex]) {
  4647. delete fragmentByStart[f.start];
  4648. delete fragmentByEnd[g.end];
  4649. if (f === g) {
  4650. f.ring.push(end);
  4651. callback(f.ring);
  4652. } else {
  4653. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  4654. }
  4655. } else {
  4656. delete fragmentByStart[f.start];
  4657. f.ring.unshift(start);
  4658. fragmentByStart[f.start = startIndex] = f;
  4659. }
  4660. } else {
  4661. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  4662. }
  4663. }
  4664. }
  4665. function index(point) {
  4666. return point[0] * 2 + point[1] * (dx + 1) * 4;
  4667. }
  4668. function smoothLinear(ring, values, value) {
  4669. ring.forEach(function(point) {
  4670. var x = point[0],
  4671. y = point[1],
  4672. xt = x | 0,
  4673. yt = y | 0,
  4674. v0,
  4675. v1 = values[yt * dx + xt];
  4676. if (x > 0 && x < dx && xt === x) {
  4677. v0 = values[yt * dx + xt - 1];
  4678. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  4679. }
  4680. if (y > 0 && y < dy && yt === y) {
  4681. v0 = values[(yt - 1) * dx + xt];
  4682. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  4683. }
  4684. });
  4685. }
  4686. contours.contour = contour;
  4687. contours.size = function(_) {
  4688. if (!arguments.length) return [dx, dy];
  4689. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4690. if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
  4691. return dx = _0, dy = _1, contours;
  4692. };
  4693. contours.thresholds = function(_) {
  4694. return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold$$1;
  4695. };
  4696. contours.smooth = function(_) {
  4697. return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
  4698. };
  4699. return contours;
  4700. }
  4701. // TODO Optimize edge cases.
  4702. // TODO Optimize index calculation.
  4703. // TODO Optimize arguments.
  4704. function blurX(source, target, r) {
  4705. var n = source.width,
  4706. m = source.height,
  4707. w = (r << 1) + 1;
  4708. for (var j = 0; j < m; ++j) {
  4709. for (var i = 0, sr = 0; i < n + r; ++i) {
  4710. if (i < n) {
  4711. sr += source.data[i + j * n];
  4712. }
  4713. if (i >= r) {
  4714. if (i >= w) {
  4715. sr -= source.data[i - w + j * n];
  4716. }
  4717. target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
  4718. }
  4719. }
  4720. }
  4721. }
  4722. // TODO Optimize edge cases.
  4723. // TODO Optimize index calculation.
  4724. // TODO Optimize arguments.
  4725. function blurY(source, target, r) {
  4726. var n = source.width,
  4727. m = source.height,
  4728. w = (r << 1) + 1;
  4729. for (var i = 0; i < n; ++i) {
  4730. for (var j = 0, sr = 0; j < m + r; ++j) {
  4731. if (j < m) {
  4732. sr += source.data[i + j * n];
  4733. }
  4734. if (j >= r) {
  4735. if (j >= w) {
  4736. sr -= source.data[i + (j - w) * n];
  4737. }
  4738. target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
  4739. }
  4740. }
  4741. }
  4742. }
  4743. function defaultX(d) {
  4744. return d[0];
  4745. }
  4746. function defaultY(d) {
  4747. return d[1];
  4748. }
  4749. function defaultWeight() {
  4750. return 1;
  4751. }
  4752. function density() {
  4753. var x = defaultX,
  4754. y = defaultY,
  4755. weight = defaultWeight,
  4756. dx = 960,
  4757. dy = 500,
  4758. r = 20, // blur radius
  4759. k = 2, // log2(grid cell size)
  4760. o = r * 3, // grid offset, to pad for blur
  4761. n = (dx + o * 2) >> k, // grid width
  4762. m = (dy + o * 2) >> k, // grid height
  4763. threshold$$1 = constant$6(20);
  4764. function density(data) {
  4765. var values0 = new Float32Array(n * m),
  4766. values1 = new Float32Array(n * m);
  4767. data.forEach(function(d, i, data) {
  4768. var xi = (+x(d, i, data) + o) >> k,
  4769. yi = (+y(d, i, data) + o) >> k,
  4770. wi = +weight(d, i, data);
  4771. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  4772. values0[xi + yi * n] += wi;
  4773. }
  4774. });
  4775. // TODO Optimize.
  4776. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4777. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4778. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4779. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4780. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4781. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4782. var tz = threshold$$1(values0);
  4783. // Convert number of thresholds into uniform thresholds.
  4784. if (!Array.isArray(tz)) {
  4785. var stop = max(values0);
  4786. tz = tickStep(0, stop, tz);
  4787. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  4788. tz.shift();
  4789. }
  4790. return contours()
  4791. .thresholds(tz)
  4792. .size([n, m])
  4793. (values0)
  4794. .map(transform);
  4795. }
  4796. function transform(geometry) {
  4797. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  4798. geometry.coordinates.forEach(transformPolygon);
  4799. return geometry;
  4800. }
  4801. function transformPolygon(coordinates) {
  4802. coordinates.forEach(transformRing);
  4803. }
  4804. function transformRing(coordinates) {
  4805. coordinates.forEach(transformPoint);
  4806. }
  4807. // TODO Optimize.
  4808. function transformPoint(coordinates) {
  4809. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  4810. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  4811. }
  4812. function resize() {
  4813. o = r * 3;
  4814. n = (dx + o * 2) >> k;
  4815. m = (dy + o * 2) >> k;
  4816. return density;
  4817. }
  4818. density.x = function(_) {
  4819. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  4820. };
  4821. density.y = function(_) {
  4822. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  4823. };
  4824. density.weight = function(_) {
  4825. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
  4826. };
  4827. density.size = function(_) {
  4828. if (!arguments.length) return [dx, dy];
  4829. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4830. if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
  4831. return dx = _0, dy = _1, resize();
  4832. };
  4833. density.cellSize = function(_) {
  4834. if (!arguments.length) return 1 << k;
  4835. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  4836. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  4837. };
  4838. density.thresholds = function(_) {
  4839. return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold$$1;
  4840. };
  4841. density.bandwidth = function(_) {
  4842. if (!arguments.length) return Math.sqrt(r * (r + 1));
  4843. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  4844. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  4845. };
  4846. return density;
  4847. }
  4848. var EOL = {},
  4849. EOF = {},
  4850. QUOTE = 34,
  4851. NEWLINE = 10,
  4852. RETURN = 13;
  4853. function objectConverter(columns) {
  4854. return new Function("d", "return {" + columns.map(function(name, i) {
  4855. return JSON.stringify(name) + ": d[" + i + "]";
  4856. }).join(",") + "}");
  4857. }
  4858. function customConverter(columns, f) {
  4859. var object = objectConverter(columns);
  4860. return function(row, i) {
  4861. return f(object(row), i, columns);
  4862. };
  4863. }
  4864. // Compute unique columns in order of discovery.
  4865. function inferColumns(rows) {
  4866. var columnSet = Object.create(null),
  4867. columns = [];
  4868. rows.forEach(function(row) {
  4869. for (var column in row) {
  4870. if (!(column in columnSet)) {
  4871. columns.push(columnSet[column] = column);
  4872. }
  4873. }
  4874. });
  4875. return columns;
  4876. }
  4877. function dsv(delimiter) {
  4878. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  4879. DELIMITER = delimiter.charCodeAt(0);
  4880. function parse(text, f) {
  4881. var convert, columns, rows = parseRows(text, function(row, i) {
  4882. if (convert) return convert(row, i - 1);
  4883. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  4884. });
  4885. rows.columns = columns || [];
  4886. return rows;
  4887. }
  4888. function parseRows(text, f) {
  4889. var rows = [], // output rows
  4890. N = text.length,
  4891. I = 0, // current character index
  4892. n = 0, // current line number
  4893. t, // current token
  4894. eof = N <= 0, // current token followed by EOF?
  4895. eol = false; // current token followed by EOL?
  4896. // Strip the trailing newline.
  4897. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  4898. if (text.charCodeAt(N - 1) === RETURN) --N;
  4899. function token() {
  4900. if (eof) return EOF;
  4901. if (eol) return eol = false, EOL;
  4902. // Unescape quotes.
  4903. var i, j = I, c;
  4904. if (text.charCodeAt(j) === QUOTE) {
  4905. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  4906. if ((i = I) >= N) eof = true;
  4907. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  4908. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4909. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  4910. }
  4911. // Find next delimiter or newline.
  4912. while (I < N) {
  4913. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  4914. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4915. else if (c !== DELIMITER) continue;
  4916. return text.slice(j, i);
  4917. }
  4918. // Return last token before EOF.
  4919. return eof = true, text.slice(j, N);
  4920. }
  4921. while ((t = token()) !== EOF) {
  4922. var row = [];
  4923. while (t !== EOL && t !== EOF) row.push(t), t = token();
  4924. if (f && (row = f(row, n++)) == null) continue;
  4925. rows.push(row);
  4926. }
  4927. return rows;
  4928. }
  4929. function format(rows, columns) {
  4930. if (columns == null) columns = inferColumns(rows);
  4931. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4932. return columns.map(function(column) {
  4933. return formatValue(row[column]);
  4934. }).join(delimiter);
  4935. })).join("\n");
  4936. }
  4937. function formatRows(rows) {
  4938. return rows.map(formatRow).join("\n");
  4939. }
  4940. function formatRow(row) {
  4941. return row.map(formatValue).join(delimiter);
  4942. }
  4943. function formatValue(text) {
  4944. return text == null ? ""
  4945. : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
  4946. : text;
  4947. }
  4948. return {
  4949. parse: parse,
  4950. parseRows: parseRows,
  4951. format: format,
  4952. formatRows: formatRows
  4953. };
  4954. }
  4955. var csv = dsv(",");
  4956. var csvParse = csv.parse;
  4957. var csvParseRows = csv.parseRows;
  4958. var csvFormat = csv.format;
  4959. var csvFormatRows = csv.formatRows;
  4960. var tsv = dsv("\t");
  4961. var tsvParse = tsv.parse;
  4962. var tsvParseRows = tsv.parseRows;
  4963. var tsvFormat = tsv.format;
  4964. var tsvFormatRows = tsv.formatRows;
  4965. function responseBlob(response) {
  4966. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4967. return response.blob();
  4968. }
  4969. function blob(input, init) {
  4970. return fetch(input, init).then(responseBlob);
  4971. }
  4972. function responseArrayBuffer(response) {
  4973. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4974. return response.arrayBuffer();
  4975. }
  4976. function buffer(input, init) {
  4977. return fetch(input, init).then(responseArrayBuffer);
  4978. }
  4979. function responseText(response) {
  4980. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4981. return response.text();
  4982. }
  4983. function text(input, init) {
  4984. return fetch(input, init).then(responseText);
  4985. }
  4986. function dsvParse(parse) {
  4987. return function(input, init, row) {
  4988. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  4989. return text(input, init).then(function(response) {
  4990. return parse(response, row);
  4991. });
  4992. };
  4993. }
  4994. function dsv$1(delimiter, input, init, row) {
  4995. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  4996. var format = dsv(delimiter);
  4997. return text(input, init).then(function(response) {
  4998. return format.parse(response, row);
  4999. });
  5000. }
  5001. var csv$1 = dsvParse(csvParse);
  5002. var tsv$1 = dsvParse(tsvParse);
  5003. function image(input, init) {
  5004. return new Promise(function(resolve, reject) {
  5005. var image = new Image;
  5006. for (var key in init) image[key] = init[key];
  5007. image.onerror = reject;
  5008. image.onload = function() { resolve(image); };
  5009. image.src = input;
  5010. });
  5011. }
  5012. function responseJson(response) {
  5013. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5014. return response.json();
  5015. }
  5016. function json(input, init) {
  5017. return fetch(input, init).then(responseJson);
  5018. }
  5019. function parser(type) {
  5020. return function(input, init) {
  5021. return text(input, init).then(function(text$$1) {
  5022. return (new DOMParser).parseFromString(text$$1, type);
  5023. });
  5024. };
  5025. }
  5026. var xml = parser("application/xml");
  5027. var html = parser("text/html");
  5028. var svg = parser("image/svg+xml");
  5029. function center$1(x, y) {
  5030. var nodes;
  5031. if (x == null) x = 0;
  5032. if (y == null) y = 0;
  5033. function force() {
  5034. var i,
  5035. n = nodes.length,
  5036. node,
  5037. sx = 0,
  5038. sy = 0;
  5039. for (i = 0; i < n; ++i) {
  5040. node = nodes[i], sx += node.x, sy += node.y;
  5041. }
  5042. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  5043. node = nodes[i], node.x -= sx, node.y -= sy;
  5044. }
  5045. }
  5046. force.initialize = function(_) {
  5047. nodes = _;
  5048. };
  5049. force.x = function(_) {
  5050. return arguments.length ? (x = +_, force) : x;
  5051. };
  5052. force.y = function(_) {
  5053. return arguments.length ? (y = +_, force) : y;
  5054. };
  5055. return force;
  5056. }
  5057. function constant$7(x) {
  5058. return function() {
  5059. return x;
  5060. };
  5061. }
  5062. function jiggle() {
  5063. return (Math.random() - 0.5) * 1e-6;
  5064. }
  5065. function tree_add(d) {
  5066. var x = +this._x.call(null, d),
  5067. y = +this._y.call(null, d);
  5068. return add(this.cover(x, y), x, y, d);
  5069. }
  5070. function add(tree, x, y, d) {
  5071. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  5072. var parent,
  5073. node = tree._root,
  5074. leaf = {data: d},
  5075. x0 = tree._x0,
  5076. y0 = tree._y0,
  5077. x1 = tree._x1,
  5078. y1 = tree._y1,
  5079. xm,
  5080. ym,
  5081. xp,
  5082. yp,
  5083. right,
  5084. bottom,
  5085. i,
  5086. j;
  5087. // If the tree is empty, initialize the root as a leaf.
  5088. if (!node) return tree._root = leaf, tree;
  5089. // Find the existing leaf for the new point, or add it.
  5090. while (node.length) {
  5091. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5092. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5093. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  5094. }
  5095. // Is the new point is exactly coincident with the existing point?
  5096. xp = +tree._x.call(null, node.data);
  5097. yp = +tree._y.call(null, node.data);
  5098. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  5099. // Otherwise, split the leaf node until the old and new point are separated.
  5100. do {
  5101. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  5102. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5103. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5104. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  5105. return parent[j] = node, parent[i] = leaf, tree;
  5106. }
  5107. function addAll(data) {
  5108. var d, i, n = data.length,
  5109. x,
  5110. y,
  5111. xz = new Array(n),
  5112. yz = new Array(n),
  5113. x0 = Infinity,
  5114. y0 = Infinity,
  5115. x1 = -Infinity,
  5116. y1 = -Infinity;
  5117. // Compute the points and their extent.
  5118. for (i = 0; i < n; ++i) {
  5119. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  5120. xz[i] = x;
  5121. yz[i] = y;
  5122. if (x < x0) x0 = x;
  5123. if (x > x1) x1 = x;
  5124. if (y < y0) y0 = y;
  5125. if (y > y1) y1 = y;
  5126. }
  5127. // If there were no (valid) points, inherit the existing extent.
  5128. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  5129. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  5130. // Expand the tree to cover the new points.
  5131. this.cover(x0, y0).cover(x1, y1);
  5132. // Add the new points.
  5133. for (i = 0; i < n; ++i) {
  5134. add(this, xz[i], yz[i], data[i]);
  5135. }
  5136. return this;
  5137. }
  5138. function tree_cover(x, y) {
  5139. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  5140. var x0 = this._x0,
  5141. y0 = this._y0,
  5142. x1 = this._x1,
  5143. y1 = this._y1;
  5144. // If the quadtree has no extent, initialize them.
  5145. // Integer extent are necessary so that if we later double the extent,
  5146. // the existing quadrant boundaries don’t change due to floating point error!
  5147. if (isNaN(x0)) {
  5148. x1 = (x0 = Math.floor(x)) + 1;
  5149. y1 = (y0 = Math.floor(y)) + 1;
  5150. }
  5151. // Otherwise, double repeatedly to cover.
  5152. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  5153. var z = x1 - x0,
  5154. node = this._root,
  5155. parent,
  5156. i;
  5157. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  5158. case 0: {
  5159. do parent = new Array(4), parent[i] = node, node = parent;
  5160. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  5161. break;
  5162. }
  5163. case 1: {
  5164. do parent = new Array(4), parent[i] = node, node = parent;
  5165. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  5166. break;
  5167. }
  5168. case 2: {
  5169. do parent = new Array(4), parent[i] = node, node = parent;
  5170. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  5171. break;
  5172. }
  5173. case 3: {
  5174. do parent = new Array(4), parent[i] = node, node = parent;
  5175. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  5176. break;
  5177. }
  5178. }
  5179. if (this._root && this._root.length) this._root = node;
  5180. }
  5181. // If the quadtree covers the point already, just return.
  5182. else return this;
  5183. this._x0 = x0;
  5184. this._y0 = y0;
  5185. this._x1 = x1;
  5186. this._y1 = y1;
  5187. return this;
  5188. }
  5189. function tree_data() {
  5190. var data = [];
  5191. this.visit(function(node) {
  5192. if (!node.length) do data.push(node.data); while (node = node.next)
  5193. });
  5194. return data;
  5195. }
  5196. function tree_extent(_) {
  5197. return arguments.length
  5198. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  5199. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  5200. }
  5201. function Quad(node, x0, y0, x1, y1) {
  5202. this.node = node;
  5203. this.x0 = x0;
  5204. this.y0 = y0;
  5205. this.x1 = x1;
  5206. this.y1 = y1;
  5207. }
  5208. function tree_find(x, y, radius) {
  5209. var data,
  5210. x0 = this._x0,
  5211. y0 = this._y0,
  5212. x1,
  5213. y1,
  5214. x2,
  5215. y2,
  5216. x3 = this._x1,
  5217. y3 = this._y1,
  5218. quads = [],
  5219. node = this._root,
  5220. q,
  5221. i;
  5222. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  5223. if (radius == null) radius = Infinity;
  5224. else {
  5225. x0 = x - radius, y0 = y - radius;
  5226. x3 = x + radius, y3 = y + radius;
  5227. radius *= radius;
  5228. }
  5229. while (q = quads.pop()) {
  5230. // Stop searching if this quadrant can’t contain a closer node.
  5231. if (!(node = q.node)
  5232. || (x1 = q.x0) > x3
  5233. || (y1 = q.y0) > y3
  5234. || (x2 = q.x1) < x0
  5235. || (y2 = q.y1) < y0) continue;
  5236. // Bisect the current quadrant.
  5237. if (node.length) {
  5238. var xm = (x1 + x2) / 2,
  5239. ym = (y1 + y2) / 2;
  5240. quads.push(
  5241. new Quad(node[3], xm, ym, x2, y2),
  5242. new Quad(node[2], x1, ym, xm, y2),
  5243. new Quad(node[1], xm, y1, x2, ym),
  5244. new Quad(node[0], x1, y1, xm, ym)
  5245. );
  5246. // Visit the closest quadrant first.
  5247. if (i = (y >= ym) << 1 | (x >= xm)) {
  5248. q = quads[quads.length - 1];
  5249. quads[quads.length - 1] = quads[quads.length - 1 - i];
  5250. quads[quads.length - 1 - i] = q;
  5251. }
  5252. }
  5253. // Visit this point. (Visiting coincident points isn’t necessary!)
  5254. else {
  5255. var dx = x - +this._x.call(null, node.data),
  5256. dy = y - +this._y.call(null, node.data),
  5257. d2 = dx * dx + dy * dy;
  5258. if (d2 < radius) {
  5259. var d = Math.sqrt(radius = d2);
  5260. x0 = x - d, y0 = y - d;
  5261. x3 = x + d, y3 = y + d;
  5262. data = node.data;
  5263. }
  5264. }
  5265. }
  5266. return data;
  5267. }
  5268. function tree_remove(d) {
  5269. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  5270. var parent,
  5271. node = this._root,
  5272. retainer,
  5273. previous,
  5274. next,
  5275. x0 = this._x0,
  5276. y0 = this._y0,
  5277. x1 = this._x1,
  5278. y1 = this._y1,
  5279. x,
  5280. y,
  5281. xm,
  5282. ym,
  5283. right,
  5284. bottom,
  5285. i,
  5286. j;
  5287. // If the tree is empty, initialize the root as a leaf.
  5288. if (!node) return this;
  5289. // Find the leaf node for the point.
  5290. // While descending, also retain the deepest parent with a non-removed sibling.
  5291. if (node.length) while (true) {
  5292. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5293. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5294. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  5295. if (!node.length) break;
  5296. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  5297. }
  5298. // Find the point to remove.
  5299. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  5300. if (next = node.next) delete node.next;
  5301. // If there are multiple coincident points, remove just the point.
  5302. if (previous) return (next ? previous.next = next : delete previous.next), this;
  5303. // If this is the root point, remove it.
  5304. if (!parent) return this._root = next, this;
  5305. // Remove this leaf.
  5306. next ? parent[i] = next : delete parent[i];
  5307. // If the parent now contains exactly one leaf, collapse superfluous parents.
  5308. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  5309. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  5310. && !node.length) {
  5311. if (retainer) retainer[j] = node;
  5312. else this._root = node;
  5313. }
  5314. return this;
  5315. }
  5316. function removeAll(data) {
  5317. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  5318. return this;
  5319. }
  5320. function tree_root() {
  5321. return this._root;
  5322. }
  5323. function tree_size() {
  5324. var size = 0;
  5325. this.visit(function(node) {
  5326. if (!node.length) do ++size; while (node = node.next)
  5327. });
  5328. return size;
  5329. }
  5330. function tree_visit(callback) {
  5331. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  5332. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  5333. while (q = quads.pop()) {
  5334. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  5335. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5336. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5337. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5338. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5339. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5340. }
  5341. }
  5342. return this;
  5343. }
  5344. function tree_visitAfter(callback) {
  5345. var quads = [], next = [], q;
  5346. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  5347. while (q = quads.pop()) {
  5348. var node = q.node;
  5349. if (node.length) {
  5350. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5351. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5352. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5353. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5354. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5355. }
  5356. next.push(q);
  5357. }
  5358. while (q = next.pop()) {
  5359. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  5360. }
  5361. return this;
  5362. }
  5363. function defaultX$1(d) {
  5364. return d[0];
  5365. }
  5366. function tree_x(_) {
  5367. return arguments.length ? (this._x = _, this) : this._x;
  5368. }
  5369. function defaultY$1(d) {
  5370. return d[1];
  5371. }
  5372. function tree_y(_) {
  5373. return arguments.length ? (this._y = _, this) : this._y;
  5374. }
  5375. function quadtree(nodes, x, y) {
  5376. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  5377. return nodes == null ? tree : tree.addAll(nodes);
  5378. }
  5379. function Quadtree(x, y, x0, y0, x1, y1) {
  5380. this._x = x;
  5381. this._y = y;
  5382. this._x0 = x0;
  5383. this._y0 = y0;
  5384. this._x1 = x1;
  5385. this._y1 = y1;
  5386. this._root = undefined;
  5387. }
  5388. function leaf_copy(leaf) {
  5389. var copy = {data: leaf.data}, next = copy;
  5390. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  5391. return copy;
  5392. }
  5393. var treeProto = quadtree.prototype = Quadtree.prototype;
  5394. treeProto.copy = function() {
  5395. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  5396. node = this._root,
  5397. nodes,
  5398. child;
  5399. if (!node) return copy;
  5400. if (!node.length) return copy._root = leaf_copy(node), copy;
  5401. nodes = [{source: node, target: copy._root = new Array(4)}];
  5402. while (node = nodes.pop()) {
  5403. for (var i = 0; i < 4; ++i) {
  5404. if (child = node.source[i]) {
  5405. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  5406. else node.target[i] = leaf_copy(child);
  5407. }
  5408. }
  5409. }
  5410. return copy;
  5411. };
  5412. treeProto.add = tree_add;
  5413. treeProto.addAll = addAll;
  5414. treeProto.cover = tree_cover;
  5415. treeProto.data = tree_data;
  5416. treeProto.extent = tree_extent;
  5417. treeProto.find = tree_find;
  5418. treeProto.remove = tree_remove;
  5419. treeProto.removeAll = removeAll;
  5420. treeProto.root = tree_root;
  5421. treeProto.size = tree_size;
  5422. treeProto.visit = tree_visit;
  5423. treeProto.visitAfter = tree_visitAfter;
  5424. treeProto.x = tree_x;
  5425. treeProto.y = tree_y;
  5426. function x(d) {
  5427. return d.x + d.vx;
  5428. }
  5429. function y(d) {
  5430. return d.y + d.vy;
  5431. }
  5432. function collide(radius) {
  5433. var nodes,
  5434. radii,
  5435. strength = 1,
  5436. iterations = 1;
  5437. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  5438. function force() {
  5439. var i, n = nodes.length,
  5440. tree,
  5441. node,
  5442. xi,
  5443. yi,
  5444. ri,
  5445. ri2;
  5446. for (var k = 0; k < iterations; ++k) {
  5447. tree = quadtree(nodes, x, y).visitAfter(prepare);
  5448. for (i = 0; i < n; ++i) {
  5449. node = nodes[i];
  5450. ri = radii[node.index], ri2 = ri * ri;
  5451. xi = node.x + node.vx;
  5452. yi = node.y + node.vy;
  5453. tree.visit(apply);
  5454. }
  5455. }
  5456. function apply(quad, x0, y0, x1, y1) {
  5457. var data = quad.data, rj = quad.r, r = ri + rj;
  5458. if (data) {
  5459. if (data.index > node.index) {
  5460. var x = xi - data.x - data.vx,
  5461. y = yi - data.y - data.vy,
  5462. l = x * x + y * y;
  5463. if (l < r * r) {
  5464. if (x === 0) x = jiggle(), l += x * x;
  5465. if (y === 0) y = jiggle(), l += y * y;
  5466. l = (r - (l = Math.sqrt(l))) / l * strength;
  5467. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5468. node.vy += (y *= l) * r;
  5469. data.vx -= x * (r = 1 - r);
  5470. data.vy -= y * r;
  5471. }
  5472. }
  5473. return;
  5474. }
  5475. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5476. }
  5477. }
  5478. function prepare(quad) {
  5479. if (quad.data) return quad.r = radii[quad.data.index];
  5480. for (var i = quad.r = 0; i < 4; ++i) {
  5481. if (quad[i] && quad[i].r > quad.r) {
  5482. quad.r = quad[i].r;
  5483. }
  5484. }
  5485. }
  5486. function initialize() {
  5487. if (!nodes) return;
  5488. var i, n = nodes.length, node;
  5489. radii = new Array(n);
  5490. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5491. }
  5492. force.initialize = function(_) {
  5493. nodes = _;
  5494. initialize();
  5495. };
  5496. force.iterations = function(_) {
  5497. return arguments.length ? (iterations = +_, force) : iterations;
  5498. };
  5499. force.strength = function(_) {
  5500. return arguments.length ? (strength = +_, force) : strength;
  5501. };
  5502. force.radius = function(_) {
  5503. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5504. };
  5505. return force;
  5506. }
  5507. function index(d) {
  5508. return d.index;
  5509. }
  5510. function find(nodeById, nodeId) {
  5511. var node = nodeById.get(nodeId);
  5512. if (!node) throw new Error("missing: " + nodeId);
  5513. return node;
  5514. }
  5515. function link(links) {
  5516. var id = index,
  5517. strength = defaultStrength,
  5518. strengths,
  5519. distance = constant$7(30),
  5520. distances,
  5521. nodes,
  5522. count,
  5523. bias,
  5524. iterations = 1;
  5525. if (links == null) links = [];
  5526. function defaultStrength(link) {
  5527. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5528. }
  5529. function force(alpha) {
  5530. for (var k = 0, n = links.length; k < iterations; ++k) {
  5531. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5532. link = links[i], source = link.source, target = link.target;
  5533. x = target.x + target.vx - source.x - source.vx || jiggle();
  5534. y = target.y + target.vy - source.y - source.vy || jiggle();
  5535. l = Math.sqrt(x * x + y * y);
  5536. l = (l - distances[i]) / l * alpha * strengths[i];
  5537. x *= l, y *= l;
  5538. target.vx -= x * (b = bias[i]);
  5539. target.vy -= y * b;
  5540. source.vx += x * (b = 1 - b);
  5541. source.vy += y * b;
  5542. }
  5543. }
  5544. }
  5545. function initialize() {
  5546. if (!nodes) return;
  5547. var i,
  5548. n = nodes.length,
  5549. m = links.length,
  5550. nodeById = map$1(nodes, id),
  5551. link;
  5552. for (i = 0, count = new Array(n); i < m; ++i) {
  5553. link = links[i], link.index = i;
  5554. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5555. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5556. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5557. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5558. }
  5559. for (i = 0, bias = new Array(m); i < m; ++i) {
  5560. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5561. }
  5562. strengths = new Array(m), initializeStrength();
  5563. distances = new Array(m), initializeDistance();
  5564. }
  5565. function initializeStrength() {
  5566. if (!nodes) return;
  5567. for (var i = 0, n = links.length; i < n; ++i) {
  5568. strengths[i] = +strength(links[i], i, links);
  5569. }
  5570. }
  5571. function initializeDistance() {
  5572. if (!nodes) return;
  5573. for (var i = 0, n = links.length; i < n; ++i) {
  5574. distances[i] = +distance(links[i], i, links);
  5575. }
  5576. }
  5577. force.initialize = function(_) {
  5578. nodes = _;
  5579. initialize();
  5580. };
  5581. force.links = function(_) {
  5582. return arguments.length ? (links = _, initialize(), force) : links;
  5583. };
  5584. force.id = function(_) {
  5585. return arguments.length ? (id = _, force) : id;
  5586. };
  5587. force.iterations = function(_) {
  5588. return arguments.length ? (iterations = +_, force) : iterations;
  5589. };
  5590. force.strength = function(_) {
  5591. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  5592. };
  5593. force.distance = function(_) {
  5594. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  5595. };
  5596. return force;
  5597. }
  5598. function x$1(d) {
  5599. return d.x;
  5600. }
  5601. function y$1(d) {
  5602. return d.y;
  5603. }
  5604. var initialRadius = 10,
  5605. initialAngle = Math.PI * (3 - Math.sqrt(5));
  5606. function simulation(nodes) {
  5607. var simulation,
  5608. alpha = 1,
  5609. alphaMin = 0.001,
  5610. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5611. alphaTarget = 0,
  5612. velocityDecay = 0.6,
  5613. forces = map$1(),
  5614. stepper = timer(step),
  5615. event = dispatch("tick", "end");
  5616. if (nodes == null) nodes = [];
  5617. function step() {
  5618. tick();
  5619. event.call("tick", simulation);
  5620. if (alpha < alphaMin) {
  5621. stepper.stop();
  5622. event.call("end", simulation);
  5623. }
  5624. }
  5625. function tick() {
  5626. var i, n = nodes.length, node;
  5627. alpha += (alphaTarget - alpha) * alphaDecay;
  5628. forces.each(function(force) {
  5629. force(alpha);
  5630. });
  5631. for (i = 0; i < n; ++i) {
  5632. node = nodes[i];
  5633. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5634. else node.x = node.fx, node.vx = 0;
  5635. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5636. else node.y = node.fy, node.vy = 0;
  5637. }
  5638. }
  5639. function initializeNodes() {
  5640. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5641. node = nodes[i], node.index = i;
  5642. if (isNaN(node.x) || isNaN(node.y)) {
  5643. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5644. node.x = radius * Math.cos(angle);
  5645. node.y = radius * Math.sin(angle);
  5646. }
  5647. if (isNaN(node.vx) || isNaN(node.vy)) {
  5648. node.vx = node.vy = 0;
  5649. }
  5650. }
  5651. }
  5652. function initializeForce(force) {
  5653. if (force.initialize) force.initialize(nodes);
  5654. return force;
  5655. }
  5656. initializeNodes();
  5657. return simulation = {
  5658. tick: tick,
  5659. restart: function() {
  5660. return stepper.restart(step), simulation;
  5661. },
  5662. stop: function() {
  5663. return stepper.stop(), simulation;
  5664. },
  5665. nodes: function(_) {
  5666. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5667. },
  5668. alpha: function(_) {
  5669. return arguments.length ? (alpha = +_, simulation) : alpha;
  5670. },
  5671. alphaMin: function(_) {
  5672. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5673. },
  5674. alphaDecay: function(_) {
  5675. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5676. },
  5677. alphaTarget: function(_) {
  5678. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5679. },
  5680. velocityDecay: function(_) {
  5681. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5682. },
  5683. force: function(name, _) {
  5684. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  5685. },
  5686. find: function(x, y, radius) {
  5687. var i = 0,
  5688. n = nodes.length,
  5689. dx,
  5690. dy,
  5691. d2,
  5692. node,
  5693. closest;
  5694. if (radius == null) radius = Infinity;
  5695. else radius *= radius;
  5696. for (i = 0; i < n; ++i) {
  5697. node = nodes[i];
  5698. dx = x - node.x;
  5699. dy = y - node.y;
  5700. d2 = dx * dx + dy * dy;
  5701. if (d2 < radius) closest = node, radius = d2;
  5702. }
  5703. return closest;
  5704. },
  5705. on: function(name, _) {
  5706. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5707. }
  5708. };
  5709. }
  5710. function manyBody() {
  5711. var nodes,
  5712. node,
  5713. alpha,
  5714. strength = constant$7(-30),
  5715. strengths,
  5716. distanceMin2 = 1,
  5717. distanceMax2 = Infinity,
  5718. theta2 = 0.81;
  5719. function force(_) {
  5720. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5721. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5722. }
  5723. function initialize() {
  5724. if (!nodes) return;
  5725. var i, n = nodes.length, node;
  5726. strengths = new Array(n);
  5727. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5728. }
  5729. function accumulate(quad) {
  5730. var strength = 0, q, c, weight = 0, x, y, i;
  5731. // For internal nodes, accumulate forces from child quadrants.
  5732. if (quad.length) {
  5733. for (x = y = i = 0; i < 4; ++i) {
  5734. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5735. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5736. }
  5737. }
  5738. quad.x = x / weight;
  5739. quad.y = y / weight;
  5740. }
  5741. // For leaf nodes, accumulate forces from coincident quadrants.
  5742. else {
  5743. q = quad;
  5744. q.x = q.data.x;
  5745. q.y = q.data.y;
  5746. do strength += strengths[q.data.index];
  5747. while (q = q.next);
  5748. }
  5749. quad.value = strength;
  5750. }
  5751. function apply(quad, x1, _, x2) {
  5752. if (!quad.value) return true;
  5753. var x = quad.x - node.x,
  5754. y = quad.y - node.y,
  5755. w = x2 - x1,
  5756. l = x * x + y * y;
  5757. // Apply the Barnes-Hut approximation if possible.
  5758. // Limit forces for very close nodes; randomize direction if coincident.
  5759. if (w * w / theta2 < l) {
  5760. if (l < distanceMax2) {
  5761. if (x === 0) x = jiggle(), l += x * x;
  5762. if (y === 0) y = jiggle(), l += y * y;
  5763. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5764. node.vx += x * quad.value * alpha / l;
  5765. node.vy += y * quad.value * alpha / l;
  5766. }
  5767. return true;
  5768. }
  5769. // Otherwise, process points directly.
  5770. else if (quad.length || l >= distanceMax2) return;
  5771. // Limit forces for very close nodes; randomize direction if coincident.
  5772. if (quad.data !== node || quad.next) {
  5773. if (x === 0) x = jiggle(), l += x * x;
  5774. if (y === 0) y = jiggle(), l += y * y;
  5775. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5776. }
  5777. do if (quad.data !== node) {
  5778. w = strengths[quad.data.index] * alpha / l;
  5779. node.vx += x * w;
  5780. node.vy += y * w;
  5781. } while (quad = quad.next);
  5782. }
  5783. force.initialize = function(_) {
  5784. nodes = _;
  5785. initialize();
  5786. };
  5787. force.strength = function(_) {
  5788. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5789. };
  5790. force.distanceMin = function(_) {
  5791. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5792. };
  5793. force.distanceMax = function(_) {
  5794. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5795. };
  5796. force.theta = function(_) {
  5797. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5798. };
  5799. return force;
  5800. }
  5801. function radial(radius, x, y) {
  5802. var nodes,
  5803. strength = constant$7(0.1),
  5804. strengths,
  5805. radiuses;
  5806. if (typeof radius !== "function") radius = constant$7(+radius);
  5807. if (x == null) x = 0;
  5808. if (y == null) y = 0;
  5809. function force(alpha) {
  5810. for (var i = 0, n = nodes.length; i < n; ++i) {
  5811. var node = nodes[i],
  5812. dx = node.x - x || 1e-6,
  5813. dy = node.y - y || 1e-6,
  5814. r = Math.sqrt(dx * dx + dy * dy),
  5815. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  5816. node.vx += dx * k;
  5817. node.vy += dy * k;
  5818. }
  5819. }
  5820. function initialize() {
  5821. if (!nodes) return;
  5822. var i, n = nodes.length;
  5823. strengths = new Array(n);
  5824. radiuses = new Array(n);
  5825. for (i = 0; i < n; ++i) {
  5826. radiuses[i] = +radius(nodes[i], i, nodes);
  5827. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  5828. }
  5829. }
  5830. force.initialize = function(_) {
  5831. nodes = _, initialize();
  5832. };
  5833. force.strength = function(_) {
  5834. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5835. };
  5836. force.radius = function(_) {
  5837. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5838. };
  5839. force.x = function(_) {
  5840. return arguments.length ? (x = +_, force) : x;
  5841. };
  5842. force.y = function(_) {
  5843. return arguments.length ? (y = +_, force) : y;
  5844. };
  5845. return force;
  5846. }
  5847. function x$2(x) {
  5848. var strength = constant$7(0.1),
  5849. nodes,
  5850. strengths,
  5851. xz;
  5852. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  5853. function force(alpha) {
  5854. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5855. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  5856. }
  5857. }
  5858. function initialize() {
  5859. if (!nodes) return;
  5860. var i, n = nodes.length;
  5861. strengths = new Array(n);
  5862. xz = new Array(n);
  5863. for (i = 0; i < n; ++i) {
  5864. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5865. }
  5866. }
  5867. force.initialize = function(_) {
  5868. nodes = _;
  5869. initialize();
  5870. };
  5871. force.strength = function(_) {
  5872. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5873. };
  5874. force.x = function(_) {
  5875. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  5876. };
  5877. return force;
  5878. }
  5879. function y$2(y) {
  5880. var strength = constant$7(0.1),
  5881. nodes,
  5882. strengths,
  5883. yz;
  5884. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  5885. function force(alpha) {
  5886. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5887. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  5888. }
  5889. }
  5890. function initialize() {
  5891. if (!nodes) return;
  5892. var i, n = nodes.length;
  5893. strengths = new Array(n);
  5894. yz = new Array(n);
  5895. for (i = 0; i < n; ++i) {
  5896. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5897. }
  5898. }
  5899. force.initialize = function(_) {
  5900. nodes = _;
  5901. initialize();
  5902. };
  5903. force.strength = function(_) {
  5904. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5905. };
  5906. force.y = function(_) {
  5907. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  5908. };
  5909. return force;
  5910. }
  5911. // Computes the decimal coefficient and exponent of the specified number x with
  5912. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  5913. // For example, formatDecimal(1.23) returns ["123", 0].
  5914. function formatDecimal(x, p) {
  5915. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  5916. var i, coefficient = x.slice(0, i);
  5917. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  5918. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  5919. return [
  5920. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  5921. +x.slice(i + 1)
  5922. ];
  5923. }
  5924. function exponent$1(x) {
  5925. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  5926. }
  5927. function formatGroup(grouping, thousands) {
  5928. return function(value, width) {
  5929. var i = value.length,
  5930. t = [],
  5931. j = 0,
  5932. g = grouping[0],
  5933. length = 0;
  5934. while (i > 0 && g > 0) {
  5935. if (length + g + 1 > width) g = Math.max(1, width - length);
  5936. t.push(value.substring(i -= g, i + g));
  5937. if ((length += g + 1) > width) break;
  5938. g = grouping[j = (j + 1) % grouping.length];
  5939. }
  5940. return t.reverse().join(thousands);
  5941. };
  5942. }
  5943. function formatNumerals(numerals) {
  5944. return function(value) {
  5945. return value.replace(/[0-9]/g, function(i) {
  5946. return numerals[+i];
  5947. });
  5948. };
  5949. }
  5950. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  5951. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  5952. function formatSpecifier(specifier) {
  5953. return new FormatSpecifier(specifier);
  5954. }
  5955. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  5956. function FormatSpecifier(specifier) {
  5957. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  5958. var match;
  5959. this.fill = match[1] || " ";
  5960. this.align = match[2] || ">";
  5961. this.sign = match[3] || "-";
  5962. this.symbol = match[4] || "";
  5963. this.zero = !!match[5];
  5964. this.width = match[6] && +match[6];
  5965. this.comma = !!match[7];
  5966. this.precision = match[8] && +match[8].slice(1);
  5967. this.trim = !!match[9];
  5968. this.type = match[10] || "";
  5969. }
  5970. FormatSpecifier.prototype.toString = function() {
  5971. return this.fill
  5972. + this.align
  5973. + this.sign
  5974. + this.symbol
  5975. + (this.zero ? "0" : "")
  5976. + (this.width == null ? "" : Math.max(1, this.width | 0))
  5977. + (this.comma ? "," : "")
  5978. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  5979. + (this.trim ? "~" : "")
  5980. + this.type;
  5981. };
  5982. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  5983. function formatTrim(s) {
  5984. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  5985. switch (s[i]) {
  5986. case ".": i0 = i1 = i; break;
  5987. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  5988. default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
  5989. }
  5990. }
  5991. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  5992. }
  5993. var prefixExponent;
  5994. function formatPrefixAuto(x, p) {
  5995. var d = formatDecimal(x, p);
  5996. if (!d) return x + "";
  5997. var coefficient = d[0],
  5998. exponent = d[1],
  5999. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  6000. n = coefficient.length;
  6001. return i === n ? coefficient
  6002. : i > n ? coefficient + new Array(i - n + 1).join("0")
  6003. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  6004. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  6005. }
  6006. function formatRounded(x, p) {
  6007. var d = formatDecimal(x, p);
  6008. if (!d) return x + "";
  6009. var coefficient = d[0],
  6010. exponent = d[1];
  6011. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  6012. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  6013. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  6014. }
  6015. var formatTypes = {
  6016. "%": function(x, p) { return (x * 100).toFixed(p); },
  6017. "b": function(x) { return Math.round(x).toString(2); },
  6018. "c": function(x) { return x + ""; },
  6019. "d": function(x) { return Math.round(x).toString(10); },
  6020. "e": function(x, p) { return x.toExponential(p); },
  6021. "f": function(x, p) { return x.toFixed(p); },
  6022. "g": function(x, p) { return x.toPrecision(p); },
  6023. "o": function(x) { return Math.round(x).toString(8); },
  6024. "p": function(x, p) { return formatRounded(x * 100, p); },
  6025. "r": formatRounded,
  6026. "s": formatPrefixAuto,
  6027. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  6028. "x": function(x) { return Math.round(x).toString(16); }
  6029. };
  6030. function identity$3(x) {
  6031. return x;
  6032. }
  6033. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  6034. function formatLocale(locale) {
  6035. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  6036. currency = locale.currency,
  6037. decimal = locale.decimal,
  6038. numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
  6039. percent = locale.percent || "%";
  6040. function newFormat(specifier) {
  6041. specifier = formatSpecifier(specifier);
  6042. var fill = specifier.fill,
  6043. align = specifier.align,
  6044. sign = specifier.sign,
  6045. symbol = specifier.symbol,
  6046. zero = specifier.zero,
  6047. width = specifier.width,
  6048. comma = specifier.comma,
  6049. precision = specifier.precision,
  6050. trim = specifier.trim,
  6051. type = specifier.type;
  6052. // The "n" type is an alias for ",g".
  6053. if (type === "n") comma = true, type = "g";
  6054. // The "" type, and any invalid type, is an alias for ".12~g".
  6055. else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
  6056. // If zero fill is specified, padding goes after sign and before digits.
  6057. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  6058. // Compute the prefix and suffix.
  6059. // For SI-prefix, the suffix is lazily computed.
  6060. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  6061. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
  6062. // What format function should we use?
  6063. // Is this an integer type?
  6064. // Can this type generate exponential notation?
  6065. var formatType = formatTypes[type],
  6066. maybeSuffix = /[defgprs%]/.test(type);
  6067. // Set the default precision if not specified,
  6068. // or clamp the specified precision to the supported range.
  6069. // For significant precision, it must be in [1, 21].
  6070. // For fixed precision, it must be in [0, 20].
  6071. precision = precision == null ? 6
  6072. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  6073. : Math.max(0, Math.min(20, precision));
  6074. function format(value) {
  6075. var valuePrefix = prefix,
  6076. valueSuffix = suffix,
  6077. i, n, c;
  6078. if (type === "c") {
  6079. valueSuffix = formatType(value) + valueSuffix;
  6080. value = "";
  6081. } else {
  6082. value = +value;
  6083. // Perform the initial formatting.
  6084. var valueNegative = value < 0;
  6085. value = formatType(Math.abs(value), precision);
  6086. // Trim insignificant zeros.
  6087. if (trim) value = formatTrim(value);
  6088. // If a negative value rounds to zero during formatting, treat as positive.
  6089. if (valueNegative && +value === 0) valueNegative = false;
  6090. // Compute the prefix and suffix.
  6091. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  6092. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  6093. // Break the formatted value into the integer “value” part that can be
  6094. // grouped, and fractional or exponential “suffix” part that is not.
  6095. if (maybeSuffix) {
  6096. i = -1, n = value.length;
  6097. while (++i < n) {
  6098. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  6099. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  6100. value = value.slice(0, i);
  6101. break;
  6102. }
  6103. }
  6104. }
  6105. }
  6106. // If the fill character is not "0", grouping is applied before padding.
  6107. if (comma && !zero) value = group(value, Infinity);
  6108. // Compute the padding.
  6109. var length = valuePrefix.length + value.length + valueSuffix.length,
  6110. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  6111. // If the fill character is "0", grouping is applied after padding.
  6112. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  6113. // Reconstruct the final output based on the desired alignment.
  6114. switch (align) {
  6115. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  6116. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  6117. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  6118. default: value = padding + valuePrefix + value + valueSuffix; break;
  6119. }
  6120. return numerals(value);
  6121. }
  6122. format.toString = function() {
  6123. return specifier + "";
  6124. };
  6125. return format;
  6126. }
  6127. function formatPrefix(specifier, value) {
  6128. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  6129. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  6130. k = Math.pow(10, -e),
  6131. prefix = prefixes[8 + e / 3];
  6132. return function(value) {
  6133. return f(k * value) + prefix;
  6134. };
  6135. }
  6136. return {
  6137. format: newFormat,
  6138. formatPrefix: formatPrefix
  6139. };
  6140. }
  6141. var locale;
  6142. defaultLocale({
  6143. decimal: ".",
  6144. thousands: ",",
  6145. grouping: [3],
  6146. currency: ["$", ""]
  6147. });
  6148. function defaultLocale(definition) {
  6149. locale = formatLocale(definition);
  6150. exports.format = locale.format;
  6151. exports.formatPrefix = locale.formatPrefix;
  6152. return locale;
  6153. }
  6154. function precisionFixed(step) {
  6155. return Math.max(0, -exponent$1(Math.abs(step)));
  6156. }
  6157. function precisionPrefix(step, value) {
  6158. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  6159. }
  6160. function precisionRound(step, max) {
  6161. step = Math.abs(step), max = Math.abs(max) - step;
  6162. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  6163. }
  6164. // Adds floating point numbers with twice the normal precision.
  6165. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  6166. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  6167. // 305–363 (1997).
  6168. // Code adapted from GeographicLib by Charles F. F. Karney,
  6169. // http://geographiclib.sourceforge.net/
  6170. function adder() {
  6171. return new Adder;
  6172. }
  6173. function Adder() {
  6174. this.reset();
  6175. }
  6176. Adder.prototype = {
  6177. constructor: Adder,
  6178. reset: function() {
  6179. this.s = // rounded value
  6180. this.t = 0; // exact error
  6181. },
  6182. add: function(y) {
  6183. add$1(temp, y, this.t);
  6184. add$1(this, temp.s, this.s);
  6185. if (this.s) this.t += temp.t;
  6186. else this.s = temp.t;
  6187. },
  6188. valueOf: function() {
  6189. return this.s;
  6190. }
  6191. };
  6192. var temp = new Adder;
  6193. function add$1(adder, a, b) {
  6194. var x = adder.s = a + b,
  6195. bv = x - a,
  6196. av = x - bv;
  6197. adder.t = (a - av) + (b - bv);
  6198. }
  6199. var epsilon$2 = 1e-6;
  6200. var epsilon2$1 = 1e-12;
  6201. var pi$3 = Math.PI;
  6202. var halfPi$2 = pi$3 / 2;
  6203. var quarterPi = pi$3 / 4;
  6204. var tau$3 = pi$3 * 2;
  6205. var degrees$1 = 180 / pi$3;
  6206. var radians = pi$3 / 180;
  6207. var abs = Math.abs;
  6208. var atan = Math.atan;
  6209. var atan2 = Math.atan2;
  6210. var cos$1 = Math.cos;
  6211. var ceil = Math.ceil;
  6212. var exp = Math.exp;
  6213. var log = Math.log;
  6214. var pow = Math.pow;
  6215. var sin$1 = Math.sin;
  6216. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  6217. var sqrt = Math.sqrt;
  6218. var tan = Math.tan;
  6219. function acos(x) {
  6220. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  6221. }
  6222. function asin(x) {
  6223. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  6224. }
  6225. function haversin(x) {
  6226. return (x = sin$1(x / 2)) * x;
  6227. }
  6228. function noop$2() {}
  6229. function streamGeometry(geometry, stream) {
  6230. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  6231. streamGeometryType[geometry.type](geometry, stream);
  6232. }
  6233. }
  6234. var streamObjectType = {
  6235. Feature: function(object, stream) {
  6236. streamGeometry(object.geometry, stream);
  6237. },
  6238. FeatureCollection: function(object, stream) {
  6239. var features = object.features, i = -1, n = features.length;
  6240. while (++i < n) streamGeometry(features[i].geometry, stream);
  6241. }
  6242. };
  6243. var streamGeometryType = {
  6244. Sphere: function(object, stream) {
  6245. stream.sphere();
  6246. },
  6247. Point: function(object, stream) {
  6248. object = object.coordinates;
  6249. stream.point(object[0], object[1], object[2]);
  6250. },
  6251. MultiPoint: function(object, stream) {
  6252. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6253. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  6254. },
  6255. LineString: function(object, stream) {
  6256. streamLine(object.coordinates, stream, 0);
  6257. },
  6258. MultiLineString: function(object, stream) {
  6259. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6260. while (++i < n) streamLine(coordinates[i], stream, 0);
  6261. },
  6262. Polygon: function(object, stream) {
  6263. streamPolygon(object.coordinates, stream);
  6264. },
  6265. MultiPolygon: function(object, stream) {
  6266. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6267. while (++i < n) streamPolygon(coordinates[i], stream);
  6268. },
  6269. GeometryCollection: function(object, stream) {
  6270. var geometries = object.geometries, i = -1, n = geometries.length;
  6271. while (++i < n) streamGeometry(geometries[i], stream);
  6272. }
  6273. };
  6274. function streamLine(coordinates, stream, closed) {
  6275. var i = -1, n = coordinates.length - closed, coordinate;
  6276. stream.lineStart();
  6277. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  6278. stream.lineEnd();
  6279. }
  6280. function streamPolygon(coordinates, stream) {
  6281. var i = -1, n = coordinates.length;
  6282. stream.polygonStart();
  6283. while (++i < n) streamLine(coordinates[i], stream, 1);
  6284. stream.polygonEnd();
  6285. }
  6286. function geoStream(object, stream) {
  6287. if (object && streamObjectType.hasOwnProperty(object.type)) {
  6288. streamObjectType[object.type](object, stream);
  6289. } else {
  6290. streamGeometry(object, stream);
  6291. }
  6292. }
  6293. var areaRingSum = adder();
  6294. var areaSum = adder(),
  6295. lambda00,
  6296. phi00,
  6297. lambda0,
  6298. cosPhi0,
  6299. sinPhi0;
  6300. var areaStream = {
  6301. point: noop$2,
  6302. lineStart: noop$2,
  6303. lineEnd: noop$2,
  6304. polygonStart: function() {
  6305. areaRingSum.reset();
  6306. areaStream.lineStart = areaRingStart;
  6307. areaStream.lineEnd = areaRingEnd;
  6308. },
  6309. polygonEnd: function() {
  6310. var areaRing = +areaRingSum;
  6311. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  6312. this.lineStart = this.lineEnd = this.point = noop$2;
  6313. },
  6314. sphere: function() {
  6315. areaSum.add(tau$3);
  6316. }
  6317. };
  6318. function areaRingStart() {
  6319. areaStream.point = areaPointFirst;
  6320. }
  6321. function areaRingEnd() {
  6322. areaPoint(lambda00, phi00);
  6323. }
  6324. function areaPointFirst(lambda, phi) {
  6325. areaStream.point = areaPoint;
  6326. lambda00 = lambda, phi00 = phi;
  6327. lambda *= radians, phi *= radians;
  6328. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  6329. }
  6330. function areaPoint(lambda, phi) {
  6331. lambda *= radians, phi *= radians;
  6332. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  6333. // Spherical excess E for a spherical triangle with vertices: south pole,
  6334. // previous point, current point. Uses a formula derived from Cagnoli’s
  6335. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  6336. var dLambda = lambda - lambda0,
  6337. sdLambda = dLambda >= 0 ? 1 : -1,
  6338. adLambda = sdLambda * dLambda,
  6339. cosPhi = cos$1(phi),
  6340. sinPhi = sin$1(phi),
  6341. k = sinPhi0 * sinPhi,
  6342. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  6343. v = k * sdLambda * sin$1(adLambda);
  6344. areaRingSum.add(atan2(v, u));
  6345. // Advance the previous points.
  6346. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  6347. }
  6348. function area$1(object) {
  6349. areaSum.reset();
  6350. geoStream(object, areaStream);
  6351. return areaSum * 2;
  6352. }
  6353. function spherical(cartesian) {
  6354. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  6355. }
  6356. function cartesian(spherical) {
  6357. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  6358. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  6359. }
  6360. function cartesianDot(a, b) {
  6361. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6362. }
  6363. function cartesianCross(a, b) {
  6364. 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]];
  6365. }
  6366. // TODO return a
  6367. function cartesianAddInPlace(a, b) {
  6368. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  6369. }
  6370. function cartesianScale(vector, k) {
  6371. return [vector[0] * k, vector[1] * k, vector[2] * k];
  6372. }
  6373. // TODO return d
  6374. function cartesianNormalizeInPlace(d) {
  6375. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  6376. d[0] /= l, d[1] /= l, d[2] /= l;
  6377. }
  6378. var lambda0$1, phi0, lambda1, phi1, // bounds
  6379. lambda2, // previous lambda-coordinate
  6380. lambda00$1, phi00$1, // first point
  6381. p0, // previous 3D point
  6382. deltaSum = adder(),
  6383. ranges,
  6384. range;
  6385. var boundsStream = {
  6386. point: boundsPoint,
  6387. lineStart: boundsLineStart,
  6388. lineEnd: boundsLineEnd,
  6389. polygonStart: function() {
  6390. boundsStream.point = boundsRingPoint;
  6391. boundsStream.lineStart = boundsRingStart;
  6392. boundsStream.lineEnd = boundsRingEnd;
  6393. deltaSum.reset();
  6394. areaStream.polygonStart();
  6395. },
  6396. polygonEnd: function() {
  6397. areaStream.polygonEnd();
  6398. boundsStream.point = boundsPoint;
  6399. boundsStream.lineStart = boundsLineStart;
  6400. boundsStream.lineEnd = boundsLineEnd;
  6401. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6402. else if (deltaSum > epsilon$2) phi1 = 90;
  6403. else if (deltaSum < -epsilon$2) phi0 = -90;
  6404. range[0] = lambda0$1, range[1] = lambda1;
  6405. }
  6406. };
  6407. function boundsPoint(lambda, phi) {
  6408. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6409. if (phi < phi0) phi0 = phi;
  6410. if (phi > phi1) phi1 = phi;
  6411. }
  6412. function linePoint(lambda, phi) {
  6413. var p = cartesian([lambda * radians, phi * radians]);
  6414. if (p0) {
  6415. var normal = cartesianCross(p0, p),
  6416. equatorial = [normal[1], -normal[0], 0],
  6417. inflection = cartesianCross(equatorial, normal);
  6418. cartesianNormalizeInPlace(inflection);
  6419. inflection = spherical(inflection);
  6420. var delta = lambda - lambda2,
  6421. sign$$1 = delta > 0 ? 1 : -1,
  6422. lambdai = inflection[0] * degrees$1 * sign$$1,
  6423. phii,
  6424. antimeridian = abs(delta) > 180;
  6425. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6426. phii = inflection[1] * degrees$1;
  6427. if (phii > phi1) phi1 = phii;
  6428. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6429. phii = -inflection[1] * degrees$1;
  6430. if (phii < phi0) phi0 = phii;
  6431. } else {
  6432. if (phi < phi0) phi0 = phi;
  6433. if (phi > phi1) phi1 = phi;
  6434. }
  6435. if (antimeridian) {
  6436. if (lambda < lambda2) {
  6437. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6438. } else {
  6439. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6440. }
  6441. } else {
  6442. if (lambda1 >= lambda0$1) {
  6443. if (lambda < lambda0$1) lambda0$1 = lambda;
  6444. if (lambda > lambda1) lambda1 = lambda;
  6445. } else {
  6446. if (lambda > lambda2) {
  6447. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6448. } else {
  6449. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6450. }
  6451. }
  6452. }
  6453. } else {
  6454. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6455. }
  6456. if (phi < phi0) phi0 = phi;
  6457. if (phi > phi1) phi1 = phi;
  6458. p0 = p, lambda2 = lambda;
  6459. }
  6460. function boundsLineStart() {
  6461. boundsStream.point = linePoint;
  6462. }
  6463. function boundsLineEnd() {
  6464. range[0] = lambda0$1, range[1] = lambda1;
  6465. boundsStream.point = boundsPoint;
  6466. p0 = null;
  6467. }
  6468. function boundsRingPoint(lambda, phi) {
  6469. if (p0) {
  6470. var delta = lambda - lambda2;
  6471. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6472. } else {
  6473. lambda00$1 = lambda, phi00$1 = phi;
  6474. }
  6475. areaStream.point(lambda, phi);
  6476. linePoint(lambda, phi);
  6477. }
  6478. function boundsRingStart() {
  6479. areaStream.lineStart();
  6480. }
  6481. function boundsRingEnd() {
  6482. boundsRingPoint(lambda00$1, phi00$1);
  6483. areaStream.lineEnd();
  6484. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6485. range[0] = lambda0$1, range[1] = lambda1;
  6486. p0 = null;
  6487. }
  6488. // Finds the left-right distance between two longitudes.
  6489. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6490. // the distance between ±180° to be 360°.
  6491. function angle(lambda0, lambda1) {
  6492. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6493. }
  6494. function rangeCompare(a, b) {
  6495. return a[0] - b[0];
  6496. }
  6497. function rangeContains(range, x) {
  6498. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6499. }
  6500. function bounds(feature) {
  6501. var i, n, a, b, merged, deltaMax, delta;
  6502. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6503. ranges = [];
  6504. geoStream(feature, boundsStream);
  6505. // First, sort ranges by their minimum longitudes.
  6506. if (n = ranges.length) {
  6507. ranges.sort(rangeCompare);
  6508. // Then, merge any ranges that overlap.
  6509. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6510. b = ranges[i];
  6511. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6512. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6513. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6514. } else {
  6515. merged.push(a = b);
  6516. }
  6517. }
  6518. // Finally, find the largest gap between the merged ranges.
  6519. // The final bounding box will be the inverse of this gap.
  6520. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6521. b = merged[i];
  6522. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6523. }
  6524. }
  6525. ranges = range = null;
  6526. return lambda0$1 === Infinity || phi0 === Infinity
  6527. ? [[NaN, NaN], [NaN, NaN]]
  6528. : [[lambda0$1, phi0], [lambda1, phi1]];
  6529. }
  6530. var W0, W1,
  6531. X0, Y0, Z0,
  6532. X1, Y1, Z1,
  6533. X2, Y2, Z2,
  6534. lambda00$2, phi00$2, // first point
  6535. x0, y0, z0; // previous point
  6536. var centroidStream = {
  6537. sphere: noop$2,
  6538. point: centroidPoint,
  6539. lineStart: centroidLineStart,
  6540. lineEnd: centroidLineEnd,
  6541. polygonStart: function() {
  6542. centroidStream.lineStart = centroidRingStart;
  6543. centroidStream.lineEnd = centroidRingEnd;
  6544. },
  6545. polygonEnd: function() {
  6546. centroidStream.lineStart = centroidLineStart;
  6547. centroidStream.lineEnd = centroidLineEnd;
  6548. }
  6549. };
  6550. // Arithmetic mean of Cartesian vectors.
  6551. function centroidPoint(lambda, phi) {
  6552. lambda *= radians, phi *= radians;
  6553. var cosPhi = cos$1(phi);
  6554. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6555. }
  6556. function centroidPointCartesian(x, y, z) {
  6557. ++W0;
  6558. X0 += (x - X0) / W0;
  6559. Y0 += (y - Y0) / W0;
  6560. Z0 += (z - Z0) / W0;
  6561. }
  6562. function centroidLineStart() {
  6563. centroidStream.point = centroidLinePointFirst;
  6564. }
  6565. function centroidLinePointFirst(lambda, phi) {
  6566. lambda *= radians, phi *= radians;
  6567. var cosPhi = cos$1(phi);
  6568. x0 = cosPhi * cos$1(lambda);
  6569. y0 = cosPhi * sin$1(lambda);
  6570. z0 = sin$1(phi);
  6571. centroidStream.point = centroidLinePoint;
  6572. centroidPointCartesian(x0, y0, z0);
  6573. }
  6574. function centroidLinePoint(lambda, phi) {
  6575. lambda *= radians, phi *= radians;
  6576. var cosPhi = cos$1(phi),
  6577. x = cosPhi * cos$1(lambda),
  6578. y = cosPhi * sin$1(lambda),
  6579. z = sin$1(phi),
  6580. 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);
  6581. W1 += w;
  6582. X1 += w * (x0 + (x0 = x));
  6583. Y1 += w * (y0 + (y0 = y));
  6584. Z1 += w * (z0 + (z0 = z));
  6585. centroidPointCartesian(x0, y0, z0);
  6586. }
  6587. function centroidLineEnd() {
  6588. centroidStream.point = centroidPoint;
  6589. }
  6590. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6591. // J. Applied Mechanics 42, 239 (1975).
  6592. function centroidRingStart() {
  6593. centroidStream.point = centroidRingPointFirst;
  6594. }
  6595. function centroidRingEnd() {
  6596. centroidRingPoint(lambda00$2, phi00$2);
  6597. centroidStream.point = centroidPoint;
  6598. }
  6599. function centroidRingPointFirst(lambda, phi) {
  6600. lambda00$2 = lambda, phi00$2 = phi;
  6601. lambda *= radians, phi *= radians;
  6602. centroidStream.point = centroidRingPoint;
  6603. var cosPhi = cos$1(phi);
  6604. x0 = cosPhi * cos$1(lambda);
  6605. y0 = cosPhi * sin$1(lambda);
  6606. z0 = sin$1(phi);
  6607. centroidPointCartesian(x0, y0, z0);
  6608. }
  6609. function centroidRingPoint(lambda, phi) {
  6610. lambda *= radians, phi *= radians;
  6611. var cosPhi = cos$1(phi),
  6612. x = cosPhi * cos$1(lambda),
  6613. y = cosPhi * sin$1(lambda),
  6614. z = sin$1(phi),
  6615. cx = y0 * z - z0 * y,
  6616. cy = z0 * x - x0 * z,
  6617. cz = x0 * y - y0 * x,
  6618. m = sqrt(cx * cx + cy * cy + cz * cz),
  6619. w = asin(m), // line weight = angle
  6620. v = m && -w / m; // area weight multiplier
  6621. X2 += v * cx;
  6622. Y2 += v * cy;
  6623. Z2 += v * cz;
  6624. W1 += w;
  6625. X1 += w * (x0 + (x0 = x));
  6626. Y1 += w * (y0 + (y0 = y));
  6627. Z1 += w * (z0 + (z0 = z));
  6628. centroidPointCartesian(x0, y0, z0);
  6629. }
  6630. function centroid(object) {
  6631. W0 = W1 =
  6632. X0 = Y0 = Z0 =
  6633. X1 = Y1 = Z1 =
  6634. X2 = Y2 = Z2 = 0;
  6635. geoStream(object, centroidStream);
  6636. var x = X2,
  6637. y = Y2,
  6638. z = Z2,
  6639. m = x * x + y * y + z * z;
  6640. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6641. if (m < epsilon2$1) {
  6642. x = X1, y = Y1, z = Z1;
  6643. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6644. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6645. m = x * x + y * y + z * z;
  6646. // If the feature still has an undefined ccentroid, then return.
  6647. if (m < epsilon2$1) return [NaN, NaN];
  6648. }
  6649. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6650. }
  6651. function constant$8(x) {
  6652. return function() {
  6653. return x;
  6654. };
  6655. }
  6656. function compose(a, b) {
  6657. function compose(x, y) {
  6658. return x = a(x, y), b(x[0], x[1]);
  6659. }
  6660. if (a.invert && b.invert) compose.invert = function(x, y) {
  6661. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6662. };
  6663. return compose;
  6664. }
  6665. function rotationIdentity(lambda, phi) {
  6666. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6667. }
  6668. rotationIdentity.invert = rotationIdentity;
  6669. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6670. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6671. : rotationLambda(deltaLambda))
  6672. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6673. : rotationIdentity);
  6674. }
  6675. function forwardRotationLambda(deltaLambda) {
  6676. return function(lambda, phi) {
  6677. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6678. };
  6679. }
  6680. function rotationLambda(deltaLambda) {
  6681. var rotation = forwardRotationLambda(deltaLambda);
  6682. rotation.invert = forwardRotationLambda(-deltaLambda);
  6683. return rotation;
  6684. }
  6685. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6686. var cosDeltaPhi = cos$1(deltaPhi),
  6687. sinDeltaPhi = sin$1(deltaPhi),
  6688. cosDeltaGamma = cos$1(deltaGamma),
  6689. sinDeltaGamma = sin$1(deltaGamma);
  6690. function rotation(lambda, phi) {
  6691. var cosPhi = cos$1(phi),
  6692. x = cos$1(lambda) * cosPhi,
  6693. y = sin$1(lambda) * cosPhi,
  6694. z = sin$1(phi),
  6695. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6696. return [
  6697. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6698. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6699. ];
  6700. }
  6701. rotation.invert = function(lambda, phi) {
  6702. var cosPhi = cos$1(phi),
  6703. x = cos$1(lambda) * cosPhi,
  6704. y = sin$1(lambda) * cosPhi,
  6705. z = sin$1(phi),
  6706. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6707. return [
  6708. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6709. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6710. ];
  6711. };
  6712. return rotation;
  6713. }
  6714. function rotation(rotate) {
  6715. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6716. function forward(coordinates) {
  6717. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6718. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6719. }
  6720. forward.invert = function(coordinates) {
  6721. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6722. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6723. };
  6724. return forward;
  6725. }
  6726. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6727. function circleStream(stream, radius, delta, direction, t0, t1) {
  6728. if (!delta) return;
  6729. var cosRadius = cos$1(radius),
  6730. sinRadius = sin$1(radius),
  6731. step = direction * delta;
  6732. if (t0 == null) {
  6733. t0 = radius + direction * tau$3;
  6734. t1 = radius - step / 2;
  6735. } else {
  6736. t0 = circleRadius(cosRadius, t0);
  6737. t1 = circleRadius(cosRadius, t1);
  6738. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6739. }
  6740. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6741. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6742. stream.point(point[0], point[1]);
  6743. }
  6744. }
  6745. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6746. function circleRadius(cosRadius, point) {
  6747. point = cartesian(point), point[0] -= cosRadius;
  6748. cartesianNormalizeInPlace(point);
  6749. var radius = acos(-point[1]);
  6750. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6751. }
  6752. function circle() {
  6753. var center = constant$8([0, 0]),
  6754. radius = constant$8(90),
  6755. precision = constant$8(6),
  6756. ring,
  6757. rotate,
  6758. stream = {point: point};
  6759. function point(x, y) {
  6760. ring.push(x = rotate(x, y));
  6761. x[0] *= degrees$1, x[1] *= degrees$1;
  6762. }
  6763. function circle() {
  6764. var c = center.apply(this, arguments),
  6765. r = radius.apply(this, arguments) * radians,
  6766. p = precision.apply(this, arguments) * radians;
  6767. ring = [];
  6768. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6769. circleStream(stream, r, p, 1);
  6770. c = {type: "Polygon", coordinates: [ring]};
  6771. ring = rotate = null;
  6772. return c;
  6773. }
  6774. circle.center = function(_) {
  6775. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  6776. };
  6777. circle.radius = function(_) {
  6778. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  6779. };
  6780. circle.precision = function(_) {
  6781. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  6782. };
  6783. return circle;
  6784. }
  6785. function clipBuffer() {
  6786. var lines = [],
  6787. line;
  6788. return {
  6789. point: function(x, y) {
  6790. line.push([x, y]);
  6791. },
  6792. lineStart: function() {
  6793. lines.push(line = []);
  6794. },
  6795. lineEnd: noop$2,
  6796. rejoin: function() {
  6797. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6798. },
  6799. result: function() {
  6800. var result = lines;
  6801. lines = [];
  6802. line = null;
  6803. return result;
  6804. }
  6805. };
  6806. }
  6807. function pointEqual(a, b) {
  6808. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6809. }
  6810. function Intersection(point, points, other, entry) {
  6811. this.x = point;
  6812. this.z = points;
  6813. this.o = other; // another intersection
  6814. this.e = entry; // is an entry?
  6815. this.v = false; // visited
  6816. this.n = this.p = null; // next & previous
  6817. }
  6818. // A generalized polygon clipping algorithm: given a polygon that has been cut
  6819. // into its visible line segments, and rejoins the segments by interpolating
  6820. // along the clip edge.
  6821. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  6822. var subject = [],
  6823. clip = [],
  6824. i,
  6825. n;
  6826. segments.forEach(function(segment) {
  6827. if ((n = segment.length - 1) <= 0) return;
  6828. var n, p0 = segment[0], p1 = segment[n], x;
  6829. // If the first and last points of a segment are coincident, then treat as a
  6830. // closed ring. TODO if all rings are closed, then the winding order of the
  6831. // exterior ring should be checked.
  6832. if (pointEqual(p0, p1)) {
  6833. stream.lineStart();
  6834. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  6835. stream.lineEnd();
  6836. return;
  6837. }
  6838. subject.push(x = new Intersection(p0, segment, null, true));
  6839. clip.push(x.o = new Intersection(p0, null, x, false));
  6840. subject.push(x = new Intersection(p1, segment, null, false));
  6841. clip.push(x.o = new Intersection(p1, null, x, true));
  6842. });
  6843. if (!subject.length) return;
  6844. clip.sort(compareIntersection);
  6845. link$1(subject);
  6846. link$1(clip);
  6847. for (i = 0, n = clip.length; i < n; ++i) {
  6848. clip[i].e = startInside = !startInside;
  6849. }
  6850. var start = subject[0],
  6851. points,
  6852. point;
  6853. while (1) {
  6854. // Find first unvisited intersection.
  6855. var current = start,
  6856. isSubject = true;
  6857. while (current.v) if ((current = current.n) === start) return;
  6858. points = current.z;
  6859. stream.lineStart();
  6860. do {
  6861. current.v = current.o.v = true;
  6862. if (current.e) {
  6863. if (isSubject) {
  6864. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  6865. } else {
  6866. interpolate(current.x, current.n.x, 1, stream);
  6867. }
  6868. current = current.n;
  6869. } else {
  6870. if (isSubject) {
  6871. points = current.p.z;
  6872. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  6873. } else {
  6874. interpolate(current.x, current.p.x, -1, stream);
  6875. }
  6876. current = current.p;
  6877. }
  6878. current = current.o;
  6879. points = current.z;
  6880. isSubject = !isSubject;
  6881. } while (!current.v);
  6882. stream.lineEnd();
  6883. }
  6884. }
  6885. function link$1(array) {
  6886. if (!(n = array.length)) return;
  6887. var n,
  6888. i = 0,
  6889. a = array[0],
  6890. b;
  6891. while (++i < n) {
  6892. a.n = b = array[i];
  6893. b.p = a;
  6894. a = b;
  6895. }
  6896. a.n = b = array[0];
  6897. b.p = a;
  6898. }
  6899. var sum$1 = adder();
  6900. function polygonContains(polygon, point) {
  6901. var lambda = point[0],
  6902. phi = point[1],
  6903. sinPhi = sin$1(phi),
  6904. normal = [sin$1(lambda), -cos$1(lambda), 0],
  6905. angle = 0,
  6906. winding = 0;
  6907. sum$1.reset();
  6908. if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
  6909. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
  6910. for (var i = 0, n = polygon.length; i < n; ++i) {
  6911. if (!(m = (ring = polygon[i]).length)) continue;
  6912. var ring,
  6913. m,
  6914. point0 = ring[m - 1],
  6915. lambda0 = point0[0],
  6916. phi0 = point0[1] / 2 + quarterPi,
  6917. sinPhi0 = sin$1(phi0),
  6918. cosPhi0 = cos$1(phi0);
  6919. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  6920. var point1 = ring[j],
  6921. lambda1 = point1[0],
  6922. phi1 = point1[1] / 2 + quarterPi,
  6923. sinPhi1 = sin$1(phi1),
  6924. cosPhi1 = cos$1(phi1),
  6925. delta = lambda1 - lambda0,
  6926. sign$$1 = delta >= 0 ? 1 : -1,
  6927. absDelta = sign$$1 * delta,
  6928. antimeridian = absDelta > pi$3,
  6929. k = sinPhi0 * sinPhi1;
  6930. sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  6931. angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
  6932. // Are the longitudes either side of the point’s meridian (lambda),
  6933. // and are the latitudes smaller than the parallel (phi)?
  6934. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  6935. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  6936. cartesianNormalizeInPlace(arc);
  6937. var intersection = cartesianCross(normal, arc);
  6938. cartesianNormalizeInPlace(intersection);
  6939. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  6940. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  6941. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  6942. }
  6943. }
  6944. }
  6945. }
  6946. // First, determine whether the South pole is inside or outside:
  6947. //
  6948. // It is inside if:
  6949. // * the polygon winds around it in a clockwise direction.
  6950. // * the polygon does not (cumulatively) wind around it, but has a negative
  6951. // (counter-clockwise) area.
  6952. //
  6953. // Second, count the (signed) number of times a segment crosses a lambda
  6954. // from the point to the South pole. If it is zero, then the point is the
  6955. // same side as the South pole.
  6956. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  6957. }
  6958. function clip(pointVisible, clipLine, interpolate, start) {
  6959. return function(sink) {
  6960. var line = clipLine(sink),
  6961. ringBuffer = clipBuffer(),
  6962. ringSink = clipLine(ringBuffer),
  6963. polygonStarted = false,
  6964. polygon,
  6965. segments,
  6966. ring;
  6967. var clip = {
  6968. point: point,
  6969. lineStart: lineStart,
  6970. lineEnd: lineEnd,
  6971. polygonStart: function() {
  6972. clip.point = pointRing;
  6973. clip.lineStart = ringStart;
  6974. clip.lineEnd = ringEnd;
  6975. segments = [];
  6976. polygon = [];
  6977. },
  6978. polygonEnd: function() {
  6979. clip.point = point;
  6980. clip.lineStart = lineStart;
  6981. clip.lineEnd = lineEnd;
  6982. segments = merge(segments);
  6983. var startInside = polygonContains(polygon, start);
  6984. if (segments.length) {
  6985. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6986. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  6987. } else if (startInside) {
  6988. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6989. sink.lineStart();
  6990. interpolate(null, null, 1, sink);
  6991. sink.lineEnd();
  6992. }
  6993. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  6994. segments = polygon = null;
  6995. },
  6996. sphere: function() {
  6997. sink.polygonStart();
  6998. sink.lineStart();
  6999. interpolate(null, null, 1, sink);
  7000. sink.lineEnd();
  7001. sink.polygonEnd();
  7002. }
  7003. };
  7004. function point(lambda, phi) {
  7005. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  7006. }
  7007. function pointLine(lambda, phi) {
  7008. line.point(lambda, phi);
  7009. }
  7010. function lineStart() {
  7011. clip.point = pointLine;
  7012. line.lineStart();
  7013. }
  7014. function lineEnd() {
  7015. clip.point = point;
  7016. line.lineEnd();
  7017. }
  7018. function pointRing(lambda, phi) {
  7019. ring.push([lambda, phi]);
  7020. ringSink.point(lambda, phi);
  7021. }
  7022. function ringStart() {
  7023. ringSink.lineStart();
  7024. ring = [];
  7025. }
  7026. function ringEnd() {
  7027. pointRing(ring[0][0], ring[0][1]);
  7028. ringSink.lineEnd();
  7029. var clean = ringSink.clean(),
  7030. ringSegments = ringBuffer.result(),
  7031. i, n = ringSegments.length, m,
  7032. segment,
  7033. point;
  7034. ring.pop();
  7035. polygon.push(ring);
  7036. ring = null;
  7037. if (!n) return;
  7038. // No intersections.
  7039. if (clean & 1) {
  7040. segment = ringSegments[0];
  7041. if ((m = segment.length - 1) > 0) {
  7042. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7043. sink.lineStart();
  7044. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7045. sink.lineEnd();
  7046. }
  7047. return;
  7048. }
  7049. // Rejoin connected segments.
  7050. // TODO reuse ringBuffer.rejoin()?
  7051. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7052. segments.push(ringSegments.filter(validSegment));
  7053. }
  7054. return clip;
  7055. };
  7056. }
  7057. function validSegment(segment) {
  7058. return segment.length > 1;
  7059. }
  7060. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7061. // and circle clipping, the same comparison is used.
  7062. function compareIntersection(a, b) {
  7063. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7064. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7065. }
  7066. var clipAntimeridian = clip(
  7067. function() { return true; },
  7068. clipAntimeridianLine,
  7069. clipAntimeridianInterpolate,
  7070. [-pi$3, -halfPi$2]
  7071. );
  7072. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7073. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7074. // intersections, and the first and last segments should be rejoined.
  7075. function clipAntimeridianLine(stream) {
  7076. var lambda0 = NaN,
  7077. phi0 = NaN,
  7078. sign0 = NaN,
  7079. clean; // no intersections
  7080. return {
  7081. lineStart: function() {
  7082. stream.lineStart();
  7083. clean = 1;
  7084. },
  7085. point: function(lambda1, phi1) {
  7086. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7087. delta = abs(lambda1 - lambda0);
  7088. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7089. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7090. stream.point(sign0, phi0);
  7091. stream.lineEnd();
  7092. stream.lineStart();
  7093. stream.point(sign1, phi0);
  7094. stream.point(lambda1, phi0);
  7095. clean = 0;
  7096. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7097. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7098. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7099. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7100. stream.point(sign0, phi0);
  7101. stream.lineEnd();
  7102. stream.lineStart();
  7103. stream.point(sign1, phi0);
  7104. clean = 0;
  7105. }
  7106. stream.point(lambda0 = lambda1, phi0 = phi1);
  7107. sign0 = sign1;
  7108. },
  7109. lineEnd: function() {
  7110. stream.lineEnd();
  7111. lambda0 = phi0 = NaN;
  7112. },
  7113. clean: function() {
  7114. return 2 - clean; // if intersections, rejoin first and last segments
  7115. }
  7116. };
  7117. }
  7118. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7119. var cosPhi0,
  7120. cosPhi1,
  7121. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7122. return abs(sinLambda0Lambda1) > epsilon$2
  7123. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7124. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7125. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7126. : (phi0 + phi1) / 2;
  7127. }
  7128. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7129. var phi;
  7130. if (from == null) {
  7131. phi = direction * halfPi$2;
  7132. stream.point(-pi$3, phi);
  7133. stream.point(0, phi);
  7134. stream.point(pi$3, phi);
  7135. stream.point(pi$3, 0);
  7136. stream.point(pi$3, -phi);
  7137. stream.point(0, -phi);
  7138. stream.point(-pi$3, -phi);
  7139. stream.point(-pi$3, 0);
  7140. stream.point(-pi$3, phi);
  7141. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7142. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7143. phi = direction * lambda / 2;
  7144. stream.point(-lambda, phi);
  7145. stream.point(0, phi);
  7146. stream.point(lambda, phi);
  7147. } else {
  7148. stream.point(to[0], to[1]);
  7149. }
  7150. }
  7151. function clipCircle(radius) {
  7152. var cr = cos$1(radius),
  7153. delta = 6 * radians,
  7154. smallRadius = cr > 0,
  7155. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7156. function interpolate(from, to, direction, stream) {
  7157. circleStream(stream, radius, delta, direction, from, to);
  7158. }
  7159. function visible(lambda, phi) {
  7160. return cos$1(lambda) * cos$1(phi) > cr;
  7161. }
  7162. // Takes a line and cuts into visible segments. Return values used for polygon
  7163. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7164. // intersections 2 - there were intersections, and the first and last segments
  7165. // should be rejoined.
  7166. function clipLine(stream) {
  7167. var point0, // previous point
  7168. c0, // code for previous point
  7169. v0, // visibility of previous point
  7170. v00, // visibility of first point
  7171. clean; // no intersections
  7172. return {
  7173. lineStart: function() {
  7174. v00 = v0 = false;
  7175. clean = 1;
  7176. },
  7177. point: function(lambda, phi) {
  7178. var point1 = [lambda, phi],
  7179. point2,
  7180. v = visible(lambda, phi),
  7181. c = smallRadius
  7182. ? v ? 0 : code(lambda, phi)
  7183. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7184. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7185. // Handle degeneracies.
  7186. // TODO ignore if not clipping polygons.
  7187. if (v !== v0) {
  7188. point2 = intersect(point0, point1);
  7189. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7190. point1[0] += epsilon$2;
  7191. point1[1] += epsilon$2;
  7192. v = visible(point1[0], point1[1]);
  7193. }
  7194. }
  7195. if (v !== v0) {
  7196. clean = 0;
  7197. if (v) {
  7198. // outside going in
  7199. stream.lineStart();
  7200. point2 = intersect(point1, point0);
  7201. stream.point(point2[0], point2[1]);
  7202. } else {
  7203. // inside going out
  7204. point2 = intersect(point0, point1);
  7205. stream.point(point2[0], point2[1]);
  7206. stream.lineEnd();
  7207. }
  7208. point0 = point2;
  7209. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7210. var t;
  7211. // If the codes for two points are different, or are both zero,
  7212. // and there this segment intersects with the small circle.
  7213. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7214. clean = 0;
  7215. if (smallRadius) {
  7216. stream.lineStart();
  7217. stream.point(t[0][0], t[0][1]);
  7218. stream.point(t[1][0], t[1][1]);
  7219. stream.lineEnd();
  7220. } else {
  7221. stream.point(t[1][0], t[1][1]);
  7222. stream.lineEnd();
  7223. stream.lineStart();
  7224. stream.point(t[0][0], t[0][1]);
  7225. }
  7226. }
  7227. }
  7228. if (v && (!point0 || !pointEqual(point0, point1))) {
  7229. stream.point(point1[0], point1[1]);
  7230. }
  7231. point0 = point1, v0 = v, c0 = c;
  7232. },
  7233. lineEnd: function() {
  7234. if (v0) stream.lineEnd();
  7235. point0 = null;
  7236. },
  7237. // Rejoin first and last segments if there were intersections and the first
  7238. // and last points were visible.
  7239. clean: function() {
  7240. return clean | ((v00 && v0) << 1);
  7241. }
  7242. };
  7243. }
  7244. // Intersects the great circle between a and b with the clip circle.
  7245. function intersect(a, b, two) {
  7246. var pa = cartesian(a),
  7247. pb = cartesian(b);
  7248. // We have two planes, n1.p = d1 and n2.p = d2.
  7249. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7250. var n1 = [1, 0, 0], // normal
  7251. n2 = cartesianCross(pa, pb),
  7252. n2n2 = cartesianDot(n2, n2),
  7253. n1n2 = n2[0], // cartesianDot(n1, n2),
  7254. determinant = n2n2 - n1n2 * n1n2;
  7255. // Two polar points.
  7256. if (!determinant) return !two && a;
  7257. var c1 = cr * n2n2 / determinant,
  7258. c2 = -cr * n1n2 / determinant,
  7259. n1xn2 = cartesianCross(n1, n2),
  7260. A = cartesianScale(n1, c1),
  7261. B = cartesianScale(n2, c2);
  7262. cartesianAddInPlace(A, B);
  7263. // Solve |p(t)|^2 = 1.
  7264. var u = n1xn2,
  7265. w = cartesianDot(A, u),
  7266. uu = cartesianDot(u, u),
  7267. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7268. if (t2 < 0) return;
  7269. var t = sqrt(t2),
  7270. q = cartesianScale(u, (-w - t) / uu);
  7271. cartesianAddInPlace(q, A);
  7272. q = spherical(q);
  7273. if (!two) return q;
  7274. // Two intersection points.
  7275. var lambda0 = a[0],
  7276. lambda1 = b[0],
  7277. phi0 = a[1],
  7278. phi1 = b[1],
  7279. z;
  7280. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7281. var delta = lambda1 - lambda0,
  7282. polar = abs(delta - pi$3) < epsilon$2,
  7283. meridian = polar || delta < epsilon$2;
  7284. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7285. // Check that the first point is between a and b.
  7286. if (meridian
  7287. ? polar
  7288. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7289. : phi0 <= q[1] && q[1] <= phi1
  7290. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7291. var q1 = cartesianScale(u, (-w + t) / uu);
  7292. cartesianAddInPlace(q1, A);
  7293. return [q, spherical(q1)];
  7294. }
  7295. }
  7296. // Generates a 4-bit vector representing the location of a point relative to
  7297. // the small circle's bounding box.
  7298. function code(lambda, phi) {
  7299. var r = smallRadius ? radius : pi$3 - radius,
  7300. code = 0;
  7301. if (lambda < -r) code |= 1; // left
  7302. else if (lambda > r) code |= 2; // right
  7303. if (phi < -r) code |= 4; // below
  7304. else if (phi > r) code |= 8; // above
  7305. return code;
  7306. }
  7307. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7308. }
  7309. function clipLine(a, b, x0, y0, x1, y1) {
  7310. var ax = a[0],
  7311. ay = a[1],
  7312. bx = b[0],
  7313. by = b[1],
  7314. t0 = 0,
  7315. t1 = 1,
  7316. dx = bx - ax,
  7317. dy = by - ay,
  7318. r;
  7319. r = x0 - ax;
  7320. if (!dx && r > 0) return;
  7321. r /= dx;
  7322. if (dx < 0) {
  7323. if (r < t0) return;
  7324. if (r < t1) t1 = r;
  7325. } else if (dx > 0) {
  7326. if (r > t1) return;
  7327. if (r > t0) t0 = r;
  7328. }
  7329. r = x1 - ax;
  7330. if (!dx && r < 0) return;
  7331. r /= dx;
  7332. if (dx < 0) {
  7333. if (r > t1) return;
  7334. if (r > t0) t0 = r;
  7335. } else if (dx > 0) {
  7336. if (r < t0) return;
  7337. if (r < t1) t1 = r;
  7338. }
  7339. r = y0 - ay;
  7340. if (!dy && r > 0) return;
  7341. r /= dy;
  7342. if (dy < 0) {
  7343. if (r < t0) return;
  7344. if (r < t1) t1 = r;
  7345. } else if (dy > 0) {
  7346. if (r > t1) return;
  7347. if (r > t0) t0 = r;
  7348. }
  7349. r = y1 - ay;
  7350. if (!dy && r < 0) return;
  7351. r /= dy;
  7352. if (dy < 0) {
  7353. if (r > t1) return;
  7354. if (r > t0) t0 = r;
  7355. } else if (dy > 0) {
  7356. if (r < t0) return;
  7357. if (r < t1) t1 = r;
  7358. }
  7359. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  7360. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  7361. return true;
  7362. }
  7363. var clipMax = 1e9, clipMin = -clipMax;
  7364. // TODO Use d3-polygon’s polygonContains here for the ring check?
  7365. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  7366. function clipRectangle(x0, y0, x1, y1) {
  7367. function visible(x, y) {
  7368. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  7369. }
  7370. function interpolate(from, to, direction, stream) {
  7371. var a = 0, a1 = 0;
  7372. if (from == null
  7373. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  7374. || comparePoint(from, to) < 0 ^ direction > 0) {
  7375. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  7376. while ((a = (a + direction + 4) % 4) !== a1);
  7377. } else {
  7378. stream.point(to[0], to[1]);
  7379. }
  7380. }
  7381. function corner(p, direction) {
  7382. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  7383. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  7384. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  7385. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  7386. }
  7387. function compareIntersection(a, b) {
  7388. return comparePoint(a.x, b.x);
  7389. }
  7390. function comparePoint(a, b) {
  7391. var ca = corner(a, 1),
  7392. cb = corner(b, 1);
  7393. return ca !== cb ? ca - cb
  7394. : ca === 0 ? b[1] - a[1]
  7395. : ca === 1 ? a[0] - b[0]
  7396. : ca === 2 ? a[1] - b[1]
  7397. : b[0] - a[0];
  7398. }
  7399. return function(stream) {
  7400. var activeStream = stream,
  7401. bufferStream = clipBuffer(),
  7402. segments,
  7403. polygon,
  7404. ring,
  7405. x__, y__, v__, // first point
  7406. x_, y_, v_, // previous point
  7407. first,
  7408. clean;
  7409. var clipStream = {
  7410. point: point,
  7411. lineStart: lineStart,
  7412. lineEnd: lineEnd,
  7413. polygonStart: polygonStart,
  7414. polygonEnd: polygonEnd
  7415. };
  7416. function point(x, y) {
  7417. if (visible(x, y)) activeStream.point(x, y);
  7418. }
  7419. function polygonInside() {
  7420. var winding = 0;
  7421. for (var i = 0, n = polygon.length; i < n; ++i) {
  7422. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  7423. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  7424. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  7425. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  7426. }
  7427. }
  7428. return winding;
  7429. }
  7430. // Buffer geometry within a polygon and then clip it en masse.
  7431. function polygonStart() {
  7432. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  7433. }
  7434. function polygonEnd() {
  7435. var startInside = polygonInside(),
  7436. cleanInside = clean && startInside,
  7437. visible = (segments = merge(segments)).length;
  7438. if (cleanInside || visible) {
  7439. stream.polygonStart();
  7440. if (cleanInside) {
  7441. stream.lineStart();
  7442. interpolate(null, null, 1, stream);
  7443. stream.lineEnd();
  7444. }
  7445. if (visible) {
  7446. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7447. }
  7448. stream.polygonEnd();
  7449. }
  7450. activeStream = stream, segments = polygon = ring = null;
  7451. }
  7452. function lineStart() {
  7453. clipStream.point = linePoint;
  7454. if (polygon) polygon.push(ring = []);
  7455. first = true;
  7456. v_ = false;
  7457. x_ = y_ = NaN;
  7458. }
  7459. // TODO rather than special-case polygons, simply handle them separately.
  7460. // Ideally, coincident intersection points should be jittered to avoid
  7461. // clipping issues.
  7462. function lineEnd() {
  7463. if (segments) {
  7464. linePoint(x__, y__);
  7465. if (v__ && v_) bufferStream.rejoin();
  7466. segments.push(bufferStream.result());
  7467. }
  7468. clipStream.point = point;
  7469. if (v_) activeStream.lineEnd();
  7470. }
  7471. function linePoint(x, y) {
  7472. var v = visible(x, y);
  7473. if (polygon) ring.push([x, y]);
  7474. if (first) {
  7475. x__ = x, y__ = y, v__ = v;
  7476. first = false;
  7477. if (v) {
  7478. activeStream.lineStart();
  7479. activeStream.point(x, y);
  7480. }
  7481. } else {
  7482. if (v && v_) activeStream.point(x, y);
  7483. else {
  7484. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7485. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7486. if (clipLine(a, b, x0, y0, x1, y1)) {
  7487. if (!v_) {
  7488. activeStream.lineStart();
  7489. activeStream.point(a[0], a[1]);
  7490. }
  7491. activeStream.point(b[0], b[1]);
  7492. if (!v) activeStream.lineEnd();
  7493. clean = false;
  7494. } else if (v) {
  7495. activeStream.lineStart();
  7496. activeStream.point(x, y);
  7497. clean = false;
  7498. }
  7499. }
  7500. }
  7501. x_ = x, y_ = y, v_ = v;
  7502. }
  7503. return clipStream;
  7504. };
  7505. }
  7506. function extent$1() {
  7507. var x0 = 0,
  7508. y0 = 0,
  7509. x1 = 960,
  7510. y1 = 500,
  7511. cache,
  7512. cacheStream,
  7513. clip;
  7514. return clip = {
  7515. stream: function(stream) {
  7516. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7517. },
  7518. extent: function(_) {
  7519. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7520. }
  7521. };
  7522. }
  7523. var lengthSum = adder(),
  7524. lambda0$2,
  7525. sinPhi0$1,
  7526. cosPhi0$1;
  7527. var lengthStream = {
  7528. sphere: noop$2,
  7529. point: noop$2,
  7530. lineStart: lengthLineStart,
  7531. lineEnd: noop$2,
  7532. polygonStart: noop$2,
  7533. polygonEnd: noop$2
  7534. };
  7535. function lengthLineStart() {
  7536. lengthStream.point = lengthPointFirst;
  7537. lengthStream.lineEnd = lengthLineEnd;
  7538. }
  7539. function lengthLineEnd() {
  7540. lengthStream.point = lengthStream.lineEnd = noop$2;
  7541. }
  7542. function lengthPointFirst(lambda, phi) {
  7543. lambda *= radians, phi *= radians;
  7544. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7545. lengthStream.point = lengthPoint;
  7546. }
  7547. function lengthPoint(lambda, phi) {
  7548. lambda *= radians, phi *= radians;
  7549. var sinPhi = sin$1(phi),
  7550. cosPhi = cos$1(phi),
  7551. delta = abs(lambda - lambda0$2),
  7552. cosDelta = cos$1(delta),
  7553. sinDelta = sin$1(delta),
  7554. x = cosPhi * sinDelta,
  7555. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7556. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7557. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7558. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7559. }
  7560. function length$1(object) {
  7561. lengthSum.reset();
  7562. geoStream(object, lengthStream);
  7563. return +lengthSum;
  7564. }
  7565. var coordinates = [null, null],
  7566. object$1 = {type: "LineString", coordinates: coordinates};
  7567. function distance(a, b) {
  7568. coordinates[0] = a;
  7569. coordinates[1] = b;
  7570. return length$1(object$1);
  7571. }
  7572. var containsObjectType = {
  7573. Feature: function(object, point) {
  7574. return containsGeometry(object.geometry, point);
  7575. },
  7576. FeatureCollection: function(object, point) {
  7577. var features = object.features, i = -1, n = features.length;
  7578. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7579. return false;
  7580. }
  7581. };
  7582. var containsGeometryType = {
  7583. Sphere: function() {
  7584. return true;
  7585. },
  7586. Point: function(object, point) {
  7587. return containsPoint(object.coordinates, point);
  7588. },
  7589. MultiPoint: function(object, point) {
  7590. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7591. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7592. return false;
  7593. },
  7594. LineString: function(object, point) {
  7595. return containsLine(object.coordinates, point);
  7596. },
  7597. MultiLineString: function(object, point) {
  7598. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7599. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7600. return false;
  7601. },
  7602. Polygon: function(object, point) {
  7603. return containsPolygon(object.coordinates, point);
  7604. },
  7605. MultiPolygon: function(object, point) {
  7606. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7607. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7608. return false;
  7609. },
  7610. GeometryCollection: function(object, point) {
  7611. var geometries = object.geometries, i = -1, n = geometries.length;
  7612. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7613. return false;
  7614. }
  7615. };
  7616. function containsGeometry(geometry, point) {
  7617. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7618. ? containsGeometryType[geometry.type](geometry, point)
  7619. : false;
  7620. }
  7621. function containsPoint(coordinates, point) {
  7622. return distance(coordinates, point) === 0;
  7623. }
  7624. function containsLine(coordinates, point) {
  7625. var ab = distance(coordinates[0], coordinates[1]),
  7626. ao = distance(coordinates[0], point),
  7627. ob = distance(point, coordinates[1]);
  7628. return ao + ob <= ab + epsilon$2;
  7629. }
  7630. function containsPolygon(coordinates, point) {
  7631. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7632. }
  7633. function ringRadians(ring) {
  7634. return ring = ring.map(pointRadians), ring.pop(), ring;
  7635. }
  7636. function pointRadians(point) {
  7637. return [point[0] * radians, point[1] * radians];
  7638. }
  7639. function contains$1(object, point) {
  7640. return (object && containsObjectType.hasOwnProperty(object.type)
  7641. ? containsObjectType[object.type]
  7642. : containsGeometry)(object, point);
  7643. }
  7644. function graticuleX(y0, y1, dy) {
  7645. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7646. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7647. }
  7648. function graticuleY(x0, x1, dx) {
  7649. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7650. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7651. }
  7652. function graticule() {
  7653. var x1, x0, X1, X0,
  7654. y1, y0, Y1, Y0,
  7655. dx = 10, dy = dx, DX = 90, DY = 360,
  7656. x, y, X, Y,
  7657. precision = 2.5;
  7658. function graticule() {
  7659. return {type: "MultiLineString", coordinates: lines()};
  7660. }
  7661. function lines() {
  7662. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7663. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7664. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7665. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7666. }
  7667. graticule.lines = function() {
  7668. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7669. };
  7670. graticule.outline = function() {
  7671. return {
  7672. type: "Polygon",
  7673. coordinates: [
  7674. X(X0).concat(
  7675. Y(Y1).slice(1),
  7676. X(X1).reverse().slice(1),
  7677. Y(Y0).reverse().slice(1))
  7678. ]
  7679. };
  7680. };
  7681. graticule.extent = function(_) {
  7682. if (!arguments.length) return graticule.extentMinor();
  7683. return graticule.extentMajor(_).extentMinor(_);
  7684. };
  7685. graticule.extentMajor = function(_) {
  7686. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7687. X0 = +_[0][0], X1 = +_[1][0];
  7688. Y0 = +_[0][1], Y1 = +_[1][1];
  7689. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7690. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7691. return graticule.precision(precision);
  7692. };
  7693. graticule.extentMinor = function(_) {
  7694. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7695. x0 = +_[0][0], x1 = +_[1][0];
  7696. y0 = +_[0][1], y1 = +_[1][1];
  7697. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7698. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7699. return graticule.precision(precision);
  7700. };
  7701. graticule.step = function(_) {
  7702. if (!arguments.length) return graticule.stepMinor();
  7703. return graticule.stepMajor(_).stepMinor(_);
  7704. };
  7705. graticule.stepMajor = function(_) {
  7706. if (!arguments.length) return [DX, DY];
  7707. DX = +_[0], DY = +_[1];
  7708. return graticule;
  7709. };
  7710. graticule.stepMinor = function(_) {
  7711. if (!arguments.length) return [dx, dy];
  7712. dx = +_[0], dy = +_[1];
  7713. return graticule;
  7714. };
  7715. graticule.precision = function(_) {
  7716. if (!arguments.length) return precision;
  7717. precision = +_;
  7718. x = graticuleX(y0, y1, 90);
  7719. y = graticuleY(x0, x1, precision);
  7720. X = graticuleX(Y0, Y1, 90);
  7721. Y = graticuleY(X0, X1, precision);
  7722. return graticule;
  7723. };
  7724. return graticule
  7725. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7726. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7727. }
  7728. function graticule10() {
  7729. return graticule()();
  7730. }
  7731. function interpolate$1(a, b) {
  7732. var x0 = a[0] * radians,
  7733. y0 = a[1] * radians,
  7734. x1 = b[0] * radians,
  7735. y1 = b[1] * radians,
  7736. cy0 = cos$1(y0),
  7737. sy0 = sin$1(y0),
  7738. cy1 = cos$1(y1),
  7739. sy1 = sin$1(y1),
  7740. kx0 = cy0 * cos$1(x0),
  7741. ky0 = cy0 * sin$1(x0),
  7742. kx1 = cy1 * cos$1(x1),
  7743. ky1 = cy1 * sin$1(x1),
  7744. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  7745. k = sin$1(d);
  7746. var interpolate = d ? function(t) {
  7747. var B = sin$1(t *= d) / k,
  7748. A = sin$1(d - t) / k,
  7749. x = A * kx0 + B * kx1,
  7750. y = A * ky0 + B * ky1,
  7751. z = A * sy0 + B * sy1;
  7752. return [
  7753. atan2(y, x) * degrees$1,
  7754. atan2(z, sqrt(x * x + y * y)) * degrees$1
  7755. ];
  7756. } : function() {
  7757. return [x0 * degrees$1, y0 * degrees$1];
  7758. };
  7759. interpolate.distance = d;
  7760. return interpolate;
  7761. }
  7762. function identity$4(x) {
  7763. return x;
  7764. }
  7765. var areaSum$1 = adder(),
  7766. areaRingSum$1 = adder(),
  7767. x00,
  7768. y00,
  7769. x0$1,
  7770. y0$1;
  7771. var areaStream$1 = {
  7772. point: noop$2,
  7773. lineStart: noop$2,
  7774. lineEnd: noop$2,
  7775. polygonStart: function() {
  7776. areaStream$1.lineStart = areaRingStart$1;
  7777. areaStream$1.lineEnd = areaRingEnd$1;
  7778. },
  7779. polygonEnd: function() {
  7780. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  7781. areaSum$1.add(abs(areaRingSum$1));
  7782. areaRingSum$1.reset();
  7783. },
  7784. result: function() {
  7785. var area = areaSum$1 / 2;
  7786. areaSum$1.reset();
  7787. return area;
  7788. }
  7789. };
  7790. function areaRingStart$1() {
  7791. areaStream$1.point = areaPointFirst$1;
  7792. }
  7793. function areaPointFirst$1(x, y) {
  7794. areaStream$1.point = areaPoint$1;
  7795. x00 = x0$1 = x, y00 = y0$1 = y;
  7796. }
  7797. function areaPoint$1(x, y) {
  7798. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  7799. x0$1 = x, y0$1 = y;
  7800. }
  7801. function areaRingEnd$1() {
  7802. areaPoint$1(x00, y00);
  7803. }
  7804. var x0$2 = Infinity,
  7805. y0$2 = x0$2,
  7806. x1 = -x0$2,
  7807. y1 = x1;
  7808. var boundsStream$1 = {
  7809. point: boundsPoint$1,
  7810. lineStart: noop$2,
  7811. lineEnd: noop$2,
  7812. polygonStart: noop$2,
  7813. polygonEnd: noop$2,
  7814. result: function() {
  7815. var bounds = [[x0$2, y0$2], [x1, y1]];
  7816. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  7817. return bounds;
  7818. }
  7819. };
  7820. function boundsPoint$1(x, y) {
  7821. if (x < x0$2) x0$2 = x;
  7822. if (x > x1) x1 = x;
  7823. if (y < y0$2) y0$2 = y;
  7824. if (y > y1) y1 = y;
  7825. }
  7826. // TODO Enforce positive area for exterior, negative area for interior?
  7827. var X0$1 = 0,
  7828. Y0$1 = 0,
  7829. Z0$1 = 0,
  7830. X1$1 = 0,
  7831. Y1$1 = 0,
  7832. Z1$1 = 0,
  7833. X2$1 = 0,
  7834. Y2$1 = 0,
  7835. Z2$1 = 0,
  7836. x00$1,
  7837. y00$1,
  7838. x0$3,
  7839. y0$3;
  7840. var centroidStream$1 = {
  7841. point: centroidPoint$1,
  7842. lineStart: centroidLineStart$1,
  7843. lineEnd: centroidLineEnd$1,
  7844. polygonStart: function() {
  7845. centroidStream$1.lineStart = centroidRingStart$1;
  7846. centroidStream$1.lineEnd = centroidRingEnd$1;
  7847. },
  7848. polygonEnd: function() {
  7849. centroidStream$1.point = centroidPoint$1;
  7850. centroidStream$1.lineStart = centroidLineStart$1;
  7851. centroidStream$1.lineEnd = centroidLineEnd$1;
  7852. },
  7853. result: function() {
  7854. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  7855. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  7856. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  7857. : [NaN, NaN];
  7858. X0$1 = Y0$1 = Z0$1 =
  7859. X1$1 = Y1$1 = Z1$1 =
  7860. X2$1 = Y2$1 = Z2$1 = 0;
  7861. return centroid;
  7862. }
  7863. };
  7864. function centroidPoint$1(x, y) {
  7865. X0$1 += x;
  7866. Y0$1 += y;
  7867. ++Z0$1;
  7868. }
  7869. function centroidLineStart$1() {
  7870. centroidStream$1.point = centroidPointFirstLine;
  7871. }
  7872. function centroidPointFirstLine(x, y) {
  7873. centroidStream$1.point = centroidPointLine;
  7874. centroidPoint$1(x0$3 = x, y0$3 = y);
  7875. }
  7876. function centroidPointLine(x, y) {
  7877. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  7878. X1$1 += z * (x0$3 + x) / 2;
  7879. Y1$1 += z * (y0$3 + y) / 2;
  7880. Z1$1 += z;
  7881. centroidPoint$1(x0$3 = x, y0$3 = y);
  7882. }
  7883. function centroidLineEnd$1() {
  7884. centroidStream$1.point = centroidPoint$1;
  7885. }
  7886. function centroidRingStart$1() {
  7887. centroidStream$1.point = centroidPointFirstRing;
  7888. }
  7889. function centroidRingEnd$1() {
  7890. centroidPointRing(x00$1, y00$1);
  7891. }
  7892. function centroidPointFirstRing(x, y) {
  7893. centroidStream$1.point = centroidPointRing;
  7894. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  7895. }
  7896. function centroidPointRing(x, y) {
  7897. var dx = x - x0$3,
  7898. dy = y - y0$3,
  7899. z = sqrt(dx * dx + dy * dy);
  7900. X1$1 += z * (x0$3 + x) / 2;
  7901. Y1$1 += z * (y0$3 + y) / 2;
  7902. Z1$1 += z;
  7903. z = y0$3 * x - x0$3 * y;
  7904. X2$1 += z * (x0$3 + x);
  7905. Y2$1 += z * (y0$3 + y);
  7906. Z2$1 += z * 3;
  7907. centroidPoint$1(x0$3 = x, y0$3 = y);
  7908. }
  7909. function PathContext(context) {
  7910. this._context = context;
  7911. }
  7912. PathContext.prototype = {
  7913. _radius: 4.5,
  7914. pointRadius: function(_) {
  7915. return this._radius = _, this;
  7916. },
  7917. polygonStart: function() {
  7918. this._line = 0;
  7919. },
  7920. polygonEnd: function() {
  7921. this._line = NaN;
  7922. },
  7923. lineStart: function() {
  7924. this._point = 0;
  7925. },
  7926. lineEnd: function() {
  7927. if (this._line === 0) this._context.closePath();
  7928. this._point = NaN;
  7929. },
  7930. point: function(x, y) {
  7931. switch (this._point) {
  7932. case 0: {
  7933. this._context.moveTo(x, y);
  7934. this._point = 1;
  7935. break;
  7936. }
  7937. case 1: {
  7938. this._context.lineTo(x, y);
  7939. break;
  7940. }
  7941. default: {
  7942. this._context.moveTo(x + this._radius, y);
  7943. this._context.arc(x, y, this._radius, 0, tau$3);
  7944. break;
  7945. }
  7946. }
  7947. },
  7948. result: noop$2
  7949. };
  7950. var lengthSum$1 = adder(),
  7951. lengthRing,
  7952. x00$2,
  7953. y00$2,
  7954. x0$4,
  7955. y0$4;
  7956. var lengthStream$1 = {
  7957. point: noop$2,
  7958. lineStart: function() {
  7959. lengthStream$1.point = lengthPointFirst$1;
  7960. },
  7961. lineEnd: function() {
  7962. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  7963. lengthStream$1.point = noop$2;
  7964. },
  7965. polygonStart: function() {
  7966. lengthRing = true;
  7967. },
  7968. polygonEnd: function() {
  7969. lengthRing = null;
  7970. },
  7971. result: function() {
  7972. var length = +lengthSum$1;
  7973. lengthSum$1.reset();
  7974. return length;
  7975. }
  7976. };
  7977. function lengthPointFirst$1(x, y) {
  7978. lengthStream$1.point = lengthPoint$1;
  7979. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  7980. }
  7981. function lengthPoint$1(x, y) {
  7982. x0$4 -= x, y0$4 -= y;
  7983. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  7984. x0$4 = x, y0$4 = y;
  7985. }
  7986. function PathString() {
  7987. this._string = [];
  7988. }
  7989. PathString.prototype = {
  7990. _radius: 4.5,
  7991. _circle: circle$1(4.5),
  7992. pointRadius: function(_) {
  7993. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  7994. return this;
  7995. },
  7996. polygonStart: function() {
  7997. this._line = 0;
  7998. },
  7999. polygonEnd: function() {
  8000. this._line = NaN;
  8001. },
  8002. lineStart: function() {
  8003. this._point = 0;
  8004. },
  8005. lineEnd: function() {
  8006. if (this._line === 0) this._string.push("Z");
  8007. this._point = NaN;
  8008. },
  8009. point: function(x, y) {
  8010. switch (this._point) {
  8011. case 0: {
  8012. this._string.push("M", x, ",", y);
  8013. this._point = 1;
  8014. break;
  8015. }
  8016. case 1: {
  8017. this._string.push("L", x, ",", y);
  8018. break;
  8019. }
  8020. default: {
  8021. if (this._circle == null) this._circle = circle$1(this._radius);
  8022. this._string.push("M", x, ",", y, this._circle);
  8023. break;
  8024. }
  8025. }
  8026. },
  8027. result: function() {
  8028. if (this._string.length) {
  8029. var result = this._string.join("");
  8030. this._string = [];
  8031. return result;
  8032. } else {
  8033. return null;
  8034. }
  8035. }
  8036. };
  8037. function circle$1(radius) {
  8038. return "m0," + radius
  8039. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  8040. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  8041. + "z";
  8042. }
  8043. function index$1(projection, context) {
  8044. var pointRadius = 4.5,
  8045. projectionStream,
  8046. contextStream;
  8047. function path(object) {
  8048. if (object) {
  8049. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  8050. geoStream(object, projectionStream(contextStream));
  8051. }
  8052. return contextStream.result();
  8053. }
  8054. path.area = function(object) {
  8055. geoStream(object, projectionStream(areaStream$1));
  8056. return areaStream$1.result();
  8057. };
  8058. path.measure = function(object) {
  8059. geoStream(object, projectionStream(lengthStream$1));
  8060. return lengthStream$1.result();
  8061. };
  8062. path.bounds = function(object) {
  8063. geoStream(object, projectionStream(boundsStream$1));
  8064. return boundsStream$1.result();
  8065. };
  8066. path.centroid = function(object) {
  8067. geoStream(object, projectionStream(centroidStream$1));
  8068. return centroidStream$1.result();
  8069. };
  8070. path.projection = function(_) {
  8071. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  8072. };
  8073. path.context = function(_) {
  8074. if (!arguments.length) return context;
  8075. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  8076. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  8077. return path;
  8078. };
  8079. path.pointRadius = function(_) {
  8080. if (!arguments.length) return pointRadius;
  8081. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  8082. return path;
  8083. };
  8084. return path.projection(projection).context(context);
  8085. }
  8086. function transform(methods) {
  8087. return {
  8088. stream: transformer(methods)
  8089. };
  8090. }
  8091. function transformer(methods) {
  8092. return function(stream) {
  8093. var s = new TransformStream;
  8094. for (var key in methods) s[key] = methods[key];
  8095. s.stream = stream;
  8096. return s;
  8097. };
  8098. }
  8099. function TransformStream() {}
  8100. TransformStream.prototype = {
  8101. constructor: TransformStream,
  8102. point: function(x, y) { this.stream.point(x, y); },
  8103. sphere: function() { this.stream.sphere(); },
  8104. lineStart: function() { this.stream.lineStart(); },
  8105. lineEnd: function() { this.stream.lineEnd(); },
  8106. polygonStart: function() { this.stream.polygonStart(); },
  8107. polygonEnd: function() { this.stream.polygonEnd(); }
  8108. };
  8109. function fit(projection, fitBounds, object) {
  8110. var clip = projection.clipExtent && projection.clipExtent();
  8111. projection.scale(150).translate([0, 0]);
  8112. if (clip != null) projection.clipExtent(null);
  8113. geoStream(object, projection.stream(boundsStream$1));
  8114. fitBounds(boundsStream$1.result());
  8115. if (clip != null) projection.clipExtent(clip);
  8116. return projection;
  8117. }
  8118. function fitExtent(projection, extent, object) {
  8119. return fit(projection, function(b) {
  8120. var w = extent[1][0] - extent[0][0],
  8121. h = extent[1][1] - extent[0][1],
  8122. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  8123. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  8124. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  8125. projection.scale(150 * k).translate([x, y]);
  8126. }, object);
  8127. }
  8128. function fitSize(projection, size, object) {
  8129. return fitExtent(projection, [[0, 0], size], object);
  8130. }
  8131. function fitWidth(projection, width, object) {
  8132. return fit(projection, function(b) {
  8133. var w = +width,
  8134. k = w / (b[1][0] - b[0][0]),
  8135. x = (w - k * (b[1][0] + b[0][0])) / 2,
  8136. y = -k * b[0][1];
  8137. projection.scale(150 * k).translate([x, y]);
  8138. }, object);
  8139. }
  8140. function fitHeight(projection, height, object) {
  8141. return fit(projection, function(b) {
  8142. var h = +height,
  8143. k = h / (b[1][1] - b[0][1]),
  8144. x = -k * b[0][0],
  8145. y = (h - k * (b[1][1] + b[0][1])) / 2;
  8146. projection.scale(150 * k).translate([x, y]);
  8147. }, object);
  8148. }
  8149. var maxDepth = 16, // maximum depth of subdivision
  8150. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  8151. function resample(project, delta2) {
  8152. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  8153. }
  8154. function resampleNone(project) {
  8155. return transformer({
  8156. point: function(x, y) {
  8157. x = project(x, y);
  8158. this.stream.point(x[0], x[1]);
  8159. }
  8160. });
  8161. }
  8162. function resample$1(project, delta2) {
  8163. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  8164. var dx = x1 - x0,
  8165. dy = y1 - y0,
  8166. d2 = dx * dx + dy * dy;
  8167. if (d2 > 4 * delta2 && depth--) {
  8168. var a = a0 + a1,
  8169. b = b0 + b1,
  8170. c = c0 + c1,
  8171. m = sqrt(a * a + b * b + c * c),
  8172. phi2 = asin(c /= m),
  8173. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  8174. p = project(lambda2, phi2),
  8175. x2 = p[0],
  8176. y2 = p[1],
  8177. dx2 = x2 - x0,
  8178. dy2 = y2 - y0,
  8179. dz = dy * dx2 - dx * dy2;
  8180. if (dz * dz / d2 > delta2 // perpendicular projected distance
  8181. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  8182. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  8183. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  8184. stream.point(x2, y2);
  8185. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  8186. }
  8187. }
  8188. }
  8189. return function(stream) {
  8190. var lambda00, x00, y00, a00, b00, c00, // first point
  8191. lambda0, x0, y0, a0, b0, c0; // previous point
  8192. var resampleStream = {
  8193. point: point,
  8194. lineStart: lineStart,
  8195. lineEnd: lineEnd,
  8196. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  8197. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  8198. };
  8199. function point(x, y) {
  8200. x = project(x, y);
  8201. stream.point(x[0], x[1]);
  8202. }
  8203. function lineStart() {
  8204. x0 = NaN;
  8205. resampleStream.point = linePoint;
  8206. stream.lineStart();
  8207. }
  8208. function linePoint(lambda, phi) {
  8209. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  8210. 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);
  8211. stream.point(x0, y0);
  8212. }
  8213. function lineEnd() {
  8214. resampleStream.point = point;
  8215. stream.lineEnd();
  8216. }
  8217. function ringStart() {
  8218. lineStart();
  8219. resampleStream.point = ringPoint;
  8220. resampleStream.lineEnd = ringEnd;
  8221. }
  8222. function ringPoint(lambda, phi) {
  8223. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  8224. resampleStream.point = linePoint;
  8225. }
  8226. function ringEnd() {
  8227. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  8228. resampleStream.lineEnd = lineEnd;
  8229. lineEnd();
  8230. }
  8231. return resampleStream;
  8232. };
  8233. }
  8234. var transformRadians = transformer({
  8235. point: function(x, y) {
  8236. this.stream.point(x * radians, y * radians);
  8237. }
  8238. });
  8239. function transformRotate(rotate) {
  8240. return transformer({
  8241. point: function(x, y) {
  8242. var r = rotate(x, y);
  8243. return this.stream.point(r[0], r[1]);
  8244. }
  8245. });
  8246. }
  8247. function scaleTranslate(k, dx, dy) {
  8248. function transform$$1(x, y) {
  8249. return [dx + k * x, dy - k * y];
  8250. }
  8251. transform$$1.invert = function(x, y) {
  8252. return [(x - dx) / k, (dy - y) / k];
  8253. };
  8254. return transform$$1;
  8255. }
  8256. function scaleTranslateRotate(k, dx, dy, alpha) {
  8257. var cosAlpha = cos$1(alpha),
  8258. sinAlpha = sin$1(alpha),
  8259. a = cosAlpha * k,
  8260. b = sinAlpha * k,
  8261. ai = cosAlpha / k,
  8262. bi = sinAlpha / k,
  8263. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  8264. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  8265. function transform$$1(x, y) {
  8266. return [a * x - b * y + dx, dy - b * x - a * y];
  8267. }
  8268. transform$$1.invert = function(x, y) {
  8269. return [ai * x - bi * y + ci, fi - bi * x - ai * y];
  8270. };
  8271. return transform$$1;
  8272. }
  8273. function projection(project) {
  8274. return projectionMutator(function() { return project; })();
  8275. }
  8276. function projectionMutator(projectAt) {
  8277. var project,
  8278. k = 150, // scale
  8279. x = 480, y = 250, // translate
  8280. lambda = 0, phi = 0, // center
  8281. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  8282. alpha = 0, // post-rotate
  8283. theta = null, preclip = clipAntimeridian, // pre-clip angle
  8284. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  8285. delta2 = 0.5, // precision
  8286. projectResample,
  8287. projectTransform,
  8288. projectRotateTransform,
  8289. cache,
  8290. cacheStream;
  8291. function projection(point) {
  8292. return projectRotateTransform(point[0] * radians, point[1] * radians);
  8293. }
  8294. function invert(point) {
  8295. point = projectRotateTransform.invert(point[0], point[1]);
  8296. return point && [point[0] * degrees$1, point[1] * degrees$1];
  8297. }
  8298. projection.stream = function(stream) {
  8299. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  8300. };
  8301. projection.preclip = function(_) {
  8302. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  8303. };
  8304. projection.postclip = function(_) {
  8305. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8306. };
  8307. projection.clipAngle = function(_) {
  8308. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  8309. };
  8310. projection.clipExtent = function(_) {
  8311. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  8312. };
  8313. projection.scale = function(_) {
  8314. return arguments.length ? (k = +_, recenter()) : k;
  8315. };
  8316. projection.translate = function(_) {
  8317. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  8318. };
  8319. projection.center = function(_) {
  8320. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  8321. };
  8322. projection.rotate = function(_) {
  8323. 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];
  8324. };
  8325. projection.angle = function(_) {
  8326. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
  8327. };
  8328. projection.precision = function(_) {
  8329. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  8330. };
  8331. projection.fitExtent = function(extent, object) {
  8332. return fitExtent(projection, extent, object);
  8333. };
  8334. projection.fitSize = function(size, object) {
  8335. return fitSize(projection, size, object);
  8336. };
  8337. projection.fitWidth = function(width, object) {
  8338. return fitWidth(projection, width, object);
  8339. };
  8340. projection.fitHeight = function(height, object) {
  8341. return fitHeight(projection, height, object);
  8342. };
  8343. function recenter() {
  8344. var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
  8345. transform$$1 = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
  8346. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  8347. projectTransform = compose(project, transform$$1);
  8348. projectRotateTransform = compose(rotate, projectTransform);
  8349. projectResample = resample(projectTransform, delta2);
  8350. return reset();
  8351. }
  8352. function reset() {
  8353. cache = cacheStream = null;
  8354. return projection;
  8355. }
  8356. return function() {
  8357. project = projectAt.apply(this, arguments);
  8358. projection.invert = project.invert && invert;
  8359. return recenter();
  8360. };
  8361. }
  8362. function conicProjection(projectAt) {
  8363. var phi0 = 0,
  8364. phi1 = pi$3 / 3,
  8365. m = projectionMutator(projectAt),
  8366. p = m(phi0, phi1);
  8367. p.parallels = function(_) {
  8368. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  8369. };
  8370. return p;
  8371. }
  8372. function cylindricalEqualAreaRaw(phi0) {
  8373. var cosPhi0 = cos$1(phi0);
  8374. function forward(lambda, phi) {
  8375. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  8376. }
  8377. forward.invert = function(x, y) {
  8378. return [x / cosPhi0, asin(y * cosPhi0)];
  8379. };
  8380. return forward;
  8381. }
  8382. function conicEqualAreaRaw(y0, y1) {
  8383. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  8384. // Are the parallels symmetrical around the Equator?
  8385. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  8386. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  8387. function project(x, y) {
  8388. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  8389. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  8390. }
  8391. project.invert = function(x, y) {
  8392. var r0y = r0 - y;
  8393. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  8394. };
  8395. return project;
  8396. }
  8397. function conicEqualArea() {
  8398. return conicProjection(conicEqualAreaRaw)
  8399. .scale(155.424)
  8400. .center([0, 33.6442]);
  8401. }
  8402. function albers() {
  8403. return conicEqualArea()
  8404. .parallels([29.5, 45.5])
  8405. .scale(1070)
  8406. .translate([480, 250])
  8407. .rotate([96, 0])
  8408. .center([-0.6, 38.7]);
  8409. }
  8410. // The projections must have mutually exclusive clip regions on the sphere,
  8411. // as this will avoid emitting interleaving lines and polygons.
  8412. function multiplex(streams) {
  8413. var n = streams.length;
  8414. return {
  8415. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  8416. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  8417. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  8418. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  8419. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  8420. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  8421. };
  8422. }
  8423. // A composite projection for the United States, configured by default for
  8424. // 960×500. The projection also works quite well at 960×600 if you change the
  8425. // scale to 1285 and adjust the translate accordingly. The set of standard
  8426. // parallels for each region comes from USGS, which is published here:
  8427. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  8428. function albersUsa() {
  8429. var cache,
  8430. cacheStream,
  8431. lower48 = albers(), lower48Point,
  8432. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  8433. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  8434. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  8435. function albersUsa(coordinates) {
  8436. var x = coordinates[0], y = coordinates[1];
  8437. return point = null,
  8438. (lower48Point.point(x, y), point)
  8439. || (alaskaPoint.point(x, y), point)
  8440. || (hawaiiPoint.point(x, y), point);
  8441. }
  8442. albersUsa.invert = function(coordinates) {
  8443. var k = lower48.scale(),
  8444. t = lower48.translate(),
  8445. x = (coordinates[0] - t[0]) / k,
  8446. y = (coordinates[1] - t[1]) / k;
  8447. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  8448. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  8449. : lower48).invert(coordinates);
  8450. };
  8451. albersUsa.stream = function(stream) {
  8452. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  8453. };
  8454. albersUsa.precision = function(_) {
  8455. if (!arguments.length) return lower48.precision();
  8456. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  8457. return reset();
  8458. };
  8459. albersUsa.scale = function(_) {
  8460. if (!arguments.length) return lower48.scale();
  8461. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  8462. return albersUsa.translate(lower48.translate());
  8463. };
  8464. albersUsa.translate = function(_) {
  8465. if (!arguments.length) return lower48.translate();
  8466. var k = lower48.scale(), x = +_[0], y = +_[1];
  8467. lower48Point = lower48
  8468. .translate(_)
  8469. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8470. .stream(pointStream);
  8471. alaskaPoint = alaska
  8472. .translate([x - 0.307 * k, y + 0.201 * k])
  8473. .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]])
  8474. .stream(pointStream);
  8475. hawaiiPoint = hawaii
  8476. .translate([x - 0.205 * k, y + 0.212 * k])
  8477. .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]])
  8478. .stream(pointStream);
  8479. return reset();
  8480. };
  8481. albersUsa.fitExtent = function(extent, object) {
  8482. return fitExtent(albersUsa, extent, object);
  8483. };
  8484. albersUsa.fitSize = function(size, object) {
  8485. return fitSize(albersUsa, size, object);
  8486. };
  8487. albersUsa.fitWidth = function(width, object) {
  8488. return fitWidth(albersUsa, width, object);
  8489. };
  8490. albersUsa.fitHeight = function(height, object) {
  8491. return fitHeight(albersUsa, height, object);
  8492. };
  8493. function reset() {
  8494. cache = cacheStream = null;
  8495. return albersUsa;
  8496. }
  8497. return albersUsa.scale(1070);
  8498. }
  8499. function azimuthalRaw(scale) {
  8500. return function(x, y) {
  8501. var cx = cos$1(x),
  8502. cy = cos$1(y),
  8503. k = scale(cx * cy);
  8504. return [
  8505. k * cy * sin$1(x),
  8506. k * sin$1(y)
  8507. ];
  8508. }
  8509. }
  8510. function azimuthalInvert(angle) {
  8511. return function(x, y) {
  8512. var z = sqrt(x * x + y * y),
  8513. c = angle(z),
  8514. sc = sin$1(c),
  8515. cc = cos$1(c);
  8516. return [
  8517. atan2(x * sc, z * cc),
  8518. asin(z && y * sc / z)
  8519. ];
  8520. }
  8521. }
  8522. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8523. return sqrt(2 / (1 + cxcy));
  8524. });
  8525. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8526. return 2 * asin(z / 2);
  8527. });
  8528. function azimuthalEqualArea() {
  8529. return projection(azimuthalEqualAreaRaw)
  8530. .scale(124.75)
  8531. .clipAngle(180 - 1e-3);
  8532. }
  8533. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8534. return (c = acos(c)) && c / sin$1(c);
  8535. });
  8536. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8537. return z;
  8538. });
  8539. function azimuthalEquidistant() {
  8540. return projection(azimuthalEquidistantRaw)
  8541. .scale(79.4188)
  8542. .clipAngle(180 - 1e-3);
  8543. }
  8544. function mercatorRaw(lambda, phi) {
  8545. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8546. }
  8547. mercatorRaw.invert = function(x, y) {
  8548. return [x, 2 * atan(exp(y)) - halfPi$2];
  8549. };
  8550. function mercator() {
  8551. return mercatorProjection(mercatorRaw)
  8552. .scale(961 / tau$3);
  8553. }
  8554. function mercatorProjection(project) {
  8555. var m = projection(project),
  8556. center = m.center,
  8557. scale = m.scale,
  8558. translate = m.translate,
  8559. clipExtent = m.clipExtent,
  8560. x0 = null, y0, x1, y1; // clip extent
  8561. m.scale = function(_) {
  8562. return arguments.length ? (scale(_), reclip()) : scale();
  8563. };
  8564. m.translate = function(_) {
  8565. return arguments.length ? (translate(_), reclip()) : translate();
  8566. };
  8567. m.center = function(_) {
  8568. return arguments.length ? (center(_), reclip()) : center();
  8569. };
  8570. m.clipExtent = function(_) {
  8571. 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]];
  8572. };
  8573. function reclip() {
  8574. var k = pi$3 * scale(),
  8575. t = m(rotation(m.rotate()).invert([0, 0]));
  8576. return clipExtent(x0 == null
  8577. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8578. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8579. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8580. }
  8581. return reclip();
  8582. }
  8583. function tany(y) {
  8584. return tan((halfPi$2 + y) / 2);
  8585. }
  8586. function conicConformalRaw(y0, y1) {
  8587. var cy0 = cos$1(y0),
  8588. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8589. f = cy0 * pow(tany(y0), n) / n;
  8590. if (!n) return mercatorRaw;
  8591. function project(x, y) {
  8592. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8593. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8594. var r = f / pow(tany(y), n);
  8595. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8596. }
  8597. project.invert = function(x, y) {
  8598. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8599. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8600. };
  8601. return project;
  8602. }
  8603. function conicConformal() {
  8604. return conicProjection(conicConformalRaw)
  8605. .scale(109.5)
  8606. .parallels([30, 30]);
  8607. }
  8608. function equirectangularRaw(lambda, phi) {
  8609. return [lambda, phi];
  8610. }
  8611. equirectangularRaw.invert = equirectangularRaw;
  8612. function equirectangular() {
  8613. return projection(equirectangularRaw)
  8614. .scale(152.63);
  8615. }
  8616. function conicEquidistantRaw(y0, y1) {
  8617. var cy0 = cos$1(y0),
  8618. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8619. g = cy0 / n + y0;
  8620. if (abs(n) < epsilon$2) return equirectangularRaw;
  8621. function project(x, y) {
  8622. var gy = g - y, nx = n * x;
  8623. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8624. }
  8625. project.invert = function(x, y) {
  8626. var gy = g - y;
  8627. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8628. };
  8629. return project;
  8630. }
  8631. function conicEquidistant() {
  8632. return conicProjection(conicEquidistantRaw)
  8633. .scale(131.154)
  8634. .center([0, 13.9389]);
  8635. }
  8636. function gnomonicRaw(x, y) {
  8637. var cy = cos$1(y), k = cos$1(x) * cy;
  8638. return [cy * sin$1(x) / k, sin$1(y) / k];
  8639. }
  8640. gnomonicRaw.invert = azimuthalInvert(atan);
  8641. function gnomonic() {
  8642. return projection(gnomonicRaw)
  8643. .scale(144.049)
  8644. .clipAngle(60);
  8645. }
  8646. function scaleTranslate$1(kx, ky, tx, ty) {
  8647. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8648. point: function(x, y) {
  8649. this.stream.point(x * kx + tx, y * ky + ty);
  8650. }
  8651. });
  8652. }
  8653. function identity$5() {
  8654. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
  8655. x0 = null, y0, x1, y1, // clip extent
  8656. postclip = identity$4,
  8657. cache,
  8658. cacheStream,
  8659. projection;
  8660. function reset() {
  8661. cache = cacheStream = null;
  8662. return projection;
  8663. }
  8664. return projection = {
  8665. stream: function(stream) {
  8666. return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
  8667. },
  8668. postclip: function(_) {
  8669. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8670. },
  8671. clipExtent: function(_) {
  8672. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  8673. },
  8674. scale: function(_) {
  8675. return arguments.length ? (transform$$1 = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8676. },
  8677. translate: function(_) {
  8678. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8679. },
  8680. reflectX: function(_) {
  8681. return arguments.length ? (transform$$1 = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8682. },
  8683. reflectY: function(_) {
  8684. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8685. },
  8686. fitExtent: function(extent, object) {
  8687. return fitExtent(projection, extent, object);
  8688. },
  8689. fitSize: function(size, object) {
  8690. return fitSize(projection, size, object);
  8691. },
  8692. fitWidth: function(width, object) {
  8693. return fitWidth(projection, width, object);
  8694. },
  8695. fitHeight: function(height, object) {
  8696. return fitHeight(projection, height, object);
  8697. }
  8698. };
  8699. }
  8700. function naturalEarth1Raw(lambda, phi) {
  8701. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8702. return [
  8703. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8704. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8705. ];
  8706. }
  8707. naturalEarth1Raw.invert = function(x, y) {
  8708. var phi = y, i = 25, delta;
  8709. do {
  8710. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8711. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  8712. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  8713. } while (abs(delta) > epsilon$2 && --i > 0);
  8714. return [
  8715. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  8716. phi
  8717. ];
  8718. };
  8719. function naturalEarth1() {
  8720. return projection(naturalEarth1Raw)
  8721. .scale(175.295);
  8722. }
  8723. function orthographicRaw(x, y) {
  8724. return [cos$1(y) * sin$1(x), sin$1(y)];
  8725. }
  8726. orthographicRaw.invert = azimuthalInvert(asin);
  8727. function orthographic() {
  8728. return projection(orthographicRaw)
  8729. .scale(249.5)
  8730. .clipAngle(90 + epsilon$2);
  8731. }
  8732. function stereographicRaw(x, y) {
  8733. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8734. return [cy * sin$1(x) / k, sin$1(y) / k];
  8735. }
  8736. stereographicRaw.invert = azimuthalInvert(function(z) {
  8737. return 2 * atan(z);
  8738. });
  8739. function stereographic() {
  8740. return projection(stereographicRaw)
  8741. .scale(250)
  8742. .clipAngle(142);
  8743. }
  8744. function transverseMercatorRaw(lambda, phi) {
  8745. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8746. }
  8747. transverseMercatorRaw.invert = function(x, y) {
  8748. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8749. };
  8750. function transverseMercator() {
  8751. var m = mercatorProjection(transverseMercatorRaw),
  8752. center = m.center,
  8753. rotate = m.rotate;
  8754. m.center = function(_) {
  8755. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8756. };
  8757. m.rotate = function(_) {
  8758. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8759. };
  8760. return rotate([0, 0, 90])
  8761. .scale(159.155);
  8762. }
  8763. function defaultSeparation(a, b) {
  8764. return a.parent === b.parent ? 1 : 2;
  8765. }
  8766. function meanX(children) {
  8767. return children.reduce(meanXReduce, 0) / children.length;
  8768. }
  8769. function meanXReduce(x, c) {
  8770. return x + c.x;
  8771. }
  8772. function maxY(children) {
  8773. return 1 + children.reduce(maxYReduce, 0);
  8774. }
  8775. function maxYReduce(y, c) {
  8776. return Math.max(y, c.y);
  8777. }
  8778. function leafLeft(node) {
  8779. var children;
  8780. while (children = node.children) node = children[0];
  8781. return node;
  8782. }
  8783. function leafRight(node) {
  8784. var children;
  8785. while (children = node.children) node = children[children.length - 1];
  8786. return node;
  8787. }
  8788. function cluster() {
  8789. var separation = defaultSeparation,
  8790. dx = 1,
  8791. dy = 1,
  8792. nodeSize = false;
  8793. function cluster(root) {
  8794. var previousNode,
  8795. x = 0;
  8796. // First walk, computing the initial x & y values.
  8797. root.eachAfter(function(node) {
  8798. var children = node.children;
  8799. if (children) {
  8800. node.x = meanX(children);
  8801. node.y = maxY(children);
  8802. } else {
  8803. node.x = previousNode ? x += separation(node, previousNode) : 0;
  8804. node.y = 0;
  8805. previousNode = node;
  8806. }
  8807. });
  8808. var left = leafLeft(root),
  8809. right = leafRight(root),
  8810. x0 = left.x - separation(left, right) / 2,
  8811. x1 = right.x + separation(right, left) / 2;
  8812. // Second walk, normalizing x & y to the desired size.
  8813. return root.eachAfter(nodeSize ? function(node) {
  8814. node.x = (node.x - root.x) * dx;
  8815. node.y = (root.y - node.y) * dy;
  8816. } : function(node) {
  8817. node.x = (node.x - x0) / (x1 - x0) * dx;
  8818. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  8819. });
  8820. }
  8821. cluster.separation = function(x) {
  8822. return arguments.length ? (separation = x, cluster) : separation;
  8823. };
  8824. cluster.size = function(x) {
  8825. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  8826. };
  8827. cluster.nodeSize = function(x) {
  8828. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  8829. };
  8830. return cluster;
  8831. }
  8832. function count(node) {
  8833. var sum = 0,
  8834. children = node.children,
  8835. i = children && children.length;
  8836. if (!i) sum = 1;
  8837. else while (--i >= 0) sum += children[i].value;
  8838. node.value = sum;
  8839. }
  8840. function node_count() {
  8841. return this.eachAfter(count);
  8842. }
  8843. function node_each(callback) {
  8844. var node = this, current, next = [node], children, i, n;
  8845. do {
  8846. current = next.reverse(), next = [];
  8847. while (node = current.pop()) {
  8848. callback(node), children = node.children;
  8849. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8850. next.push(children[i]);
  8851. }
  8852. }
  8853. } while (next.length);
  8854. return this;
  8855. }
  8856. function node_eachBefore(callback) {
  8857. var node = this, nodes = [node], children, i;
  8858. while (node = nodes.pop()) {
  8859. callback(node), children = node.children;
  8860. if (children) for (i = children.length - 1; i >= 0; --i) {
  8861. nodes.push(children[i]);
  8862. }
  8863. }
  8864. return this;
  8865. }
  8866. function node_eachAfter(callback) {
  8867. var node = this, nodes = [node], next = [], children, i, n;
  8868. while (node = nodes.pop()) {
  8869. next.push(node), children = node.children;
  8870. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8871. nodes.push(children[i]);
  8872. }
  8873. }
  8874. while (node = next.pop()) {
  8875. callback(node);
  8876. }
  8877. return this;
  8878. }
  8879. function node_sum(value) {
  8880. return this.eachAfter(function(node) {
  8881. var sum = +value(node.data) || 0,
  8882. children = node.children,
  8883. i = children && children.length;
  8884. while (--i >= 0) sum += children[i].value;
  8885. node.value = sum;
  8886. });
  8887. }
  8888. function node_sort(compare) {
  8889. return this.eachBefore(function(node) {
  8890. if (node.children) {
  8891. node.children.sort(compare);
  8892. }
  8893. });
  8894. }
  8895. function node_path(end) {
  8896. var start = this,
  8897. ancestor = leastCommonAncestor(start, end),
  8898. nodes = [start];
  8899. while (start !== ancestor) {
  8900. start = start.parent;
  8901. nodes.push(start);
  8902. }
  8903. var k = nodes.length;
  8904. while (end !== ancestor) {
  8905. nodes.splice(k, 0, end);
  8906. end = end.parent;
  8907. }
  8908. return nodes;
  8909. }
  8910. function leastCommonAncestor(a, b) {
  8911. if (a === b) return a;
  8912. var aNodes = a.ancestors(),
  8913. bNodes = b.ancestors(),
  8914. c = null;
  8915. a = aNodes.pop();
  8916. b = bNodes.pop();
  8917. while (a === b) {
  8918. c = a;
  8919. a = aNodes.pop();
  8920. b = bNodes.pop();
  8921. }
  8922. return c;
  8923. }
  8924. function node_ancestors() {
  8925. var node = this, nodes = [node];
  8926. while (node = node.parent) {
  8927. nodes.push(node);
  8928. }
  8929. return nodes;
  8930. }
  8931. function node_descendants() {
  8932. var nodes = [];
  8933. this.each(function(node) {
  8934. nodes.push(node);
  8935. });
  8936. return nodes;
  8937. }
  8938. function node_leaves() {
  8939. var leaves = [];
  8940. this.eachBefore(function(node) {
  8941. if (!node.children) {
  8942. leaves.push(node);
  8943. }
  8944. });
  8945. return leaves;
  8946. }
  8947. function node_links() {
  8948. var root = this, links = [];
  8949. root.each(function(node) {
  8950. if (node !== root) { // Don’t include the root’s parent, if any.
  8951. links.push({source: node.parent, target: node});
  8952. }
  8953. });
  8954. return links;
  8955. }
  8956. function hierarchy(data, children) {
  8957. var root = new Node(data),
  8958. valued = +data.value && (root.value = data.value),
  8959. node,
  8960. nodes = [root],
  8961. child,
  8962. childs,
  8963. i,
  8964. n;
  8965. if (children == null) children = defaultChildren;
  8966. while (node = nodes.pop()) {
  8967. if (valued) node.value = +node.data.value;
  8968. if ((childs = children(node.data)) && (n = childs.length)) {
  8969. node.children = new Array(n);
  8970. for (i = n - 1; i >= 0; --i) {
  8971. nodes.push(child = node.children[i] = new Node(childs[i]));
  8972. child.parent = node;
  8973. child.depth = node.depth + 1;
  8974. }
  8975. }
  8976. }
  8977. return root.eachBefore(computeHeight);
  8978. }
  8979. function node_copy() {
  8980. return hierarchy(this).eachBefore(copyData);
  8981. }
  8982. function defaultChildren(d) {
  8983. return d.children;
  8984. }
  8985. function copyData(node) {
  8986. node.data = node.data.data;
  8987. }
  8988. function computeHeight(node) {
  8989. var height = 0;
  8990. do node.height = height;
  8991. while ((node = node.parent) && (node.height < ++height));
  8992. }
  8993. function Node(data) {
  8994. this.data = data;
  8995. this.depth =
  8996. this.height = 0;
  8997. this.parent = null;
  8998. }
  8999. Node.prototype = hierarchy.prototype = {
  9000. constructor: Node,
  9001. count: node_count,
  9002. each: node_each,
  9003. eachAfter: node_eachAfter,
  9004. eachBefore: node_eachBefore,
  9005. sum: node_sum,
  9006. sort: node_sort,
  9007. path: node_path,
  9008. ancestors: node_ancestors,
  9009. descendants: node_descendants,
  9010. leaves: node_leaves,
  9011. links: node_links,
  9012. copy: node_copy
  9013. };
  9014. var slice$4 = Array.prototype.slice;
  9015. function shuffle$1(array) {
  9016. var m = array.length,
  9017. t,
  9018. i;
  9019. while (m) {
  9020. i = Math.random() * m-- | 0;
  9021. t = array[m];
  9022. array[m] = array[i];
  9023. array[i] = t;
  9024. }
  9025. return array;
  9026. }
  9027. function enclose(circles) {
  9028. var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
  9029. while (i < n) {
  9030. p = circles[i];
  9031. if (e && enclosesWeak(e, p)) ++i;
  9032. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  9033. }
  9034. return e;
  9035. }
  9036. function extendBasis(B, p) {
  9037. var i, j;
  9038. if (enclosesWeakAll(p, B)) return [p];
  9039. // If we get here then B must have at least one element.
  9040. for (i = 0; i < B.length; ++i) {
  9041. if (enclosesNot(p, B[i])
  9042. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  9043. return [B[i], p];
  9044. }
  9045. }
  9046. // If we get here then B must have at least two elements.
  9047. for (i = 0; i < B.length - 1; ++i) {
  9048. for (j = i + 1; j < B.length; ++j) {
  9049. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  9050. && enclosesNot(encloseBasis2(B[i], p), B[j])
  9051. && enclosesNot(encloseBasis2(B[j], p), B[i])
  9052. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  9053. return [B[i], B[j], p];
  9054. }
  9055. }
  9056. }
  9057. // If we get here then something is very wrong.
  9058. throw new Error;
  9059. }
  9060. function enclosesNot(a, b) {
  9061. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  9062. return dr < 0 || dr * dr < dx * dx + dy * dy;
  9063. }
  9064. function enclosesWeak(a, b) {
  9065. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9066. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9067. }
  9068. function enclosesWeakAll(a, B) {
  9069. for (var i = 0; i < B.length; ++i) {
  9070. if (!enclosesWeak(a, B[i])) {
  9071. return false;
  9072. }
  9073. }
  9074. return true;
  9075. }
  9076. function encloseBasis(B) {
  9077. switch (B.length) {
  9078. case 1: return encloseBasis1(B[0]);
  9079. case 2: return encloseBasis2(B[0], B[1]);
  9080. case 3: return encloseBasis3(B[0], B[1], B[2]);
  9081. }
  9082. }
  9083. function encloseBasis1(a) {
  9084. return {
  9085. x: a.x,
  9086. y: a.y,
  9087. r: a.r
  9088. };
  9089. }
  9090. function encloseBasis2(a, b) {
  9091. var x1 = a.x, y1 = a.y, r1 = a.r,
  9092. x2 = b.x, y2 = b.y, r2 = b.r,
  9093. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  9094. l = Math.sqrt(x21 * x21 + y21 * y21);
  9095. return {
  9096. x: (x1 + x2 + x21 / l * r21) / 2,
  9097. y: (y1 + y2 + y21 / l * r21) / 2,
  9098. r: (l + r1 + r2) / 2
  9099. };
  9100. }
  9101. function encloseBasis3(a, b, c) {
  9102. var x1 = a.x, y1 = a.y, r1 = a.r,
  9103. x2 = b.x, y2 = b.y, r2 = b.r,
  9104. x3 = c.x, y3 = c.y, r3 = c.r,
  9105. a2 = x1 - x2,
  9106. a3 = x1 - x3,
  9107. b2 = y1 - y2,
  9108. b3 = y1 - y3,
  9109. c2 = r2 - r1,
  9110. c3 = r3 - r1,
  9111. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  9112. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  9113. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  9114. ab = a3 * b2 - a2 * b3,
  9115. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  9116. xb = (b3 * c2 - b2 * c3) / ab,
  9117. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  9118. yb = (a2 * c3 - a3 * c2) / ab,
  9119. A = xb * xb + yb * yb - 1,
  9120. B = 2 * (r1 + xa * xb + ya * yb),
  9121. C = xa * xa + ya * ya - r1 * r1,
  9122. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  9123. return {
  9124. x: x1 + xa + xb * r,
  9125. y: y1 + ya + yb * r,
  9126. r: r
  9127. };
  9128. }
  9129. function place(b, a, c) {
  9130. var dx = b.x - a.x, x, a2,
  9131. dy = b.y - a.y, y, b2,
  9132. d2 = dx * dx + dy * dy;
  9133. if (d2) {
  9134. a2 = a.r + c.r, a2 *= a2;
  9135. b2 = b.r + c.r, b2 *= b2;
  9136. if (a2 > b2) {
  9137. x = (d2 + b2 - a2) / (2 * d2);
  9138. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  9139. c.x = b.x - x * dx - y * dy;
  9140. c.y = b.y - x * dy + y * dx;
  9141. } else {
  9142. x = (d2 + a2 - b2) / (2 * d2);
  9143. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  9144. c.x = a.x + x * dx - y * dy;
  9145. c.y = a.y + x * dy + y * dx;
  9146. }
  9147. } else {
  9148. c.x = a.x + c.r;
  9149. c.y = a.y;
  9150. }
  9151. }
  9152. function intersects(a, b) {
  9153. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9154. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9155. }
  9156. function score(node) {
  9157. var a = node._,
  9158. b = node.next._,
  9159. ab = a.r + b.r,
  9160. dx = (a.x * b.r + b.x * a.r) / ab,
  9161. dy = (a.y * b.r + b.y * a.r) / ab;
  9162. return dx * dx + dy * dy;
  9163. }
  9164. function Node$1(circle) {
  9165. this._ = circle;
  9166. this.next = null;
  9167. this.previous = null;
  9168. }
  9169. function packEnclose(circles) {
  9170. if (!(n = circles.length)) return 0;
  9171. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  9172. // Place the first circle.
  9173. a = circles[0], a.x = 0, a.y = 0;
  9174. if (!(n > 1)) return a.r;
  9175. // Place the second circle.
  9176. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  9177. if (!(n > 2)) return a.r + b.r;
  9178. // Place the third circle.
  9179. place(b, a, c = circles[2]);
  9180. // Initialize the front-chain using the first three circles a, b and c.
  9181. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  9182. a.next = c.previous = b;
  9183. b.next = a.previous = c;
  9184. c.next = b.previous = a;
  9185. // Attempt to place each remaining circle…
  9186. pack: for (i = 3; i < n; ++i) {
  9187. place(a._, b._, c = circles[i]), c = new Node$1(c);
  9188. // Find the closest intersecting circle on the front-chain, if any.
  9189. // “Closeness” is determined by linear distance along the front-chain.
  9190. // “Ahead” or “behind” is likewise determined by linear distance.
  9191. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  9192. do {
  9193. if (sj <= sk) {
  9194. if (intersects(j._, c._)) {
  9195. b = j, a.next = b, b.previous = a, --i;
  9196. continue pack;
  9197. }
  9198. sj += j._.r, j = j.next;
  9199. } else {
  9200. if (intersects(k._, c._)) {
  9201. a = k, a.next = b, b.previous = a, --i;
  9202. continue pack;
  9203. }
  9204. sk += k._.r, k = k.previous;
  9205. }
  9206. } while (j !== k.next);
  9207. // Success! Insert the new circle c between a and b.
  9208. c.previous = a, c.next = b, a.next = b.previous = b = c;
  9209. // Compute the new closest circle pair to the centroid.
  9210. aa = score(a);
  9211. while ((c = c.next) !== b) {
  9212. if ((ca = score(c)) < aa) {
  9213. a = c, aa = ca;
  9214. }
  9215. }
  9216. b = a.next;
  9217. }
  9218. // Compute the enclosing circle of the front chain.
  9219. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  9220. // Translate the circles to put the enclosing circle around the origin.
  9221. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  9222. return c.r;
  9223. }
  9224. function siblings(circles) {
  9225. packEnclose(circles);
  9226. return circles;
  9227. }
  9228. function optional(f) {
  9229. return f == null ? null : required(f);
  9230. }
  9231. function required(f) {
  9232. if (typeof f !== "function") throw new Error;
  9233. return f;
  9234. }
  9235. function constantZero() {
  9236. return 0;
  9237. }
  9238. function constant$9(x) {
  9239. return function() {
  9240. return x;
  9241. };
  9242. }
  9243. function defaultRadius$1(d) {
  9244. return Math.sqrt(d.value);
  9245. }
  9246. function index$2() {
  9247. var radius = null,
  9248. dx = 1,
  9249. dy = 1,
  9250. padding = constantZero;
  9251. function pack(root) {
  9252. root.x = dx / 2, root.y = dy / 2;
  9253. if (radius) {
  9254. root.eachBefore(radiusLeaf(radius))
  9255. .eachAfter(packChildren(padding, 0.5))
  9256. .eachBefore(translateChild(1));
  9257. } else {
  9258. root.eachBefore(radiusLeaf(defaultRadius$1))
  9259. .eachAfter(packChildren(constantZero, 1))
  9260. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  9261. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  9262. }
  9263. return root;
  9264. }
  9265. pack.radius = function(x) {
  9266. return arguments.length ? (radius = optional(x), pack) : radius;
  9267. };
  9268. pack.size = function(x) {
  9269. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  9270. };
  9271. pack.padding = function(x) {
  9272. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  9273. };
  9274. return pack;
  9275. }
  9276. function radiusLeaf(radius) {
  9277. return function(node) {
  9278. if (!node.children) {
  9279. node.r = Math.max(0, +radius(node) || 0);
  9280. }
  9281. };
  9282. }
  9283. function packChildren(padding, k) {
  9284. return function(node) {
  9285. if (children = node.children) {
  9286. var children,
  9287. i,
  9288. n = children.length,
  9289. r = padding(node) * k || 0,
  9290. e;
  9291. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  9292. e = packEnclose(children);
  9293. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  9294. node.r = e + r;
  9295. }
  9296. };
  9297. }
  9298. function translateChild(k) {
  9299. return function(node) {
  9300. var parent = node.parent;
  9301. node.r *= k;
  9302. if (parent) {
  9303. node.x = parent.x + k * node.x;
  9304. node.y = parent.y + k * node.y;
  9305. }
  9306. };
  9307. }
  9308. function roundNode(node) {
  9309. node.x0 = Math.round(node.x0);
  9310. node.y0 = Math.round(node.y0);
  9311. node.x1 = Math.round(node.x1);
  9312. node.y1 = Math.round(node.y1);
  9313. }
  9314. function treemapDice(parent, x0, y0, x1, y1) {
  9315. var nodes = parent.children,
  9316. node,
  9317. i = -1,
  9318. n = nodes.length,
  9319. k = parent.value && (x1 - x0) / parent.value;
  9320. while (++i < n) {
  9321. node = nodes[i], node.y0 = y0, node.y1 = y1;
  9322. node.x0 = x0, node.x1 = x0 += node.value * k;
  9323. }
  9324. }
  9325. function partition() {
  9326. var dx = 1,
  9327. dy = 1,
  9328. padding = 0,
  9329. round = false;
  9330. function partition(root) {
  9331. var n = root.height + 1;
  9332. root.x0 =
  9333. root.y0 = padding;
  9334. root.x1 = dx;
  9335. root.y1 = dy / n;
  9336. root.eachBefore(positionNode(dy, n));
  9337. if (round) root.eachBefore(roundNode);
  9338. return root;
  9339. }
  9340. function positionNode(dy, n) {
  9341. return function(node) {
  9342. if (node.children) {
  9343. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  9344. }
  9345. var x0 = node.x0,
  9346. y0 = node.y0,
  9347. x1 = node.x1 - padding,
  9348. y1 = node.y1 - padding;
  9349. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9350. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9351. node.x0 = x0;
  9352. node.y0 = y0;
  9353. node.x1 = x1;
  9354. node.y1 = y1;
  9355. };
  9356. }
  9357. partition.round = function(x) {
  9358. return arguments.length ? (round = !!x, partition) : round;
  9359. };
  9360. partition.size = function(x) {
  9361. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  9362. };
  9363. partition.padding = function(x) {
  9364. return arguments.length ? (padding = +x, partition) : padding;
  9365. };
  9366. return partition;
  9367. }
  9368. var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
  9369. preroot = {depth: -1},
  9370. ambiguous = {};
  9371. function defaultId(d) {
  9372. return d.id;
  9373. }
  9374. function defaultParentId(d) {
  9375. return d.parentId;
  9376. }
  9377. function stratify() {
  9378. var id = defaultId,
  9379. parentId = defaultParentId;
  9380. function stratify(data) {
  9381. var d,
  9382. i,
  9383. n = data.length,
  9384. root,
  9385. parent,
  9386. node,
  9387. nodes = new Array(n),
  9388. nodeId,
  9389. nodeKey,
  9390. nodeByKey = {};
  9391. for (i = 0; i < n; ++i) {
  9392. d = data[i], node = nodes[i] = new Node(d);
  9393. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  9394. nodeKey = keyPrefix$1 + (node.id = nodeId);
  9395. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  9396. }
  9397. }
  9398. for (i = 0; i < n; ++i) {
  9399. node = nodes[i], nodeId = parentId(data[i], i, data);
  9400. if (nodeId == null || !(nodeId += "")) {
  9401. if (root) throw new Error("multiple roots");
  9402. root = node;
  9403. } else {
  9404. parent = nodeByKey[keyPrefix$1 + nodeId];
  9405. if (!parent) throw new Error("missing: " + nodeId);
  9406. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  9407. if (parent.children) parent.children.push(node);
  9408. else parent.children = [node];
  9409. node.parent = parent;
  9410. }
  9411. }
  9412. if (!root) throw new Error("no root");
  9413. root.parent = preroot;
  9414. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  9415. root.parent = null;
  9416. if (n > 0) throw new Error("cycle");
  9417. return root;
  9418. }
  9419. stratify.id = function(x) {
  9420. return arguments.length ? (id = required(x), stratify) : id;
  9421. };
  9422. stratify.parentId = function(x) {
  9423. return arguments.length ? (parentId = required(x), stratify) : parentId;
  9424. };
  9425. return stratify;
  9426. }
  9427. function defaultSeparation$1(a, b) {
  9428. return a.parent === b.parent ? 1 : 2;
  9429. }
  9430. // function radialSeparation(a, b) {
  9431. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  9432. // }
  9433. // This function is used to traverse the left contour of a subtree (or
  9434. // subforest). It returns the successor of v on this contour. This successor is
  9435. // either given by the leftmost child of v or by the thread of v. The function
  9436. // returns null if and only if v is on the highest level of its subtree.
  9437. function nextLeft(v) {
  9438. var children = v.children;
  9439. return children ? children[0] : v.t;
  9440. }
  9441. // This function works analogously to nextLeft.
  9442. function nextRight(v) {
  9443. var children = v.children;
  9444. return children ? children[children.length - 1] : v.t;
  9445. }
  9446. // Shifts the current subtree rooted at w+. This is done by increasing
  9447. // prelim(w+) and mod(w+) by shift.
  9448. function moveSubtree(wm, wp, shift) {
  9449. var change = shift / (wp.i - wm.i);
  9450. wp.c -= change;
  9451. wp.s += shift;
  9452. wm.c += change;
  9453. wp.z += shift;
  9454. wp.m += shift;
  9455. }
  9456. // All other shifts, applied to the smaller subtrees between w- and w+, are
  9457. // performed by this function. To prepare the shifts, we have to adjust
  9458. // change(w+), shift(w+), and change(w-).
  9459. function executeShifts(v) {
  9460. var shift = 0,
  9461. change = 0,
  9462. children = v.children,
  9463. i = children.length,
  9464. w;
  9465. while (--i >= 0) {
  9466. w = children[i];
  9467. w.z += shift;
  9468. w.m += shift;
  9469. shift += w.s + (change += w.c);
  9470. }
  9471. }
  9472. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9473. // returns the specified (default) ancestor.
  9474. function nextAncestor(vim, v, ancestor) {
  9475. return vim.a.parent === v.parent ? vim.a : ancestor;
  9476. }
  9477. function TreeNode(node, i) {
  9478. this._ = node;
  9479. this.parent = null;
  9480. this.children = null;
  9481. this.A = null; // default ancestor
  9482. this.a = this; // ancestor
  9483. this.z = 0; // prelim
  9484. this.m = 0; // mod
  9485. this.c = 0; // change
  9486. this.s = 0; // shift
  9487. this.t = null; // thread
  9488. this.i = i; // number
  9489. }
  9490. TreeNode.prototype = Object.create(Node.prototype);
  9491. function treeRoot(root) {
  9492. var tree = new TreeNode(root, 0),
  9493. node,
  9494. nodes = [tree],
  9495. child,
  9496. children,
  9497. i,
  9498. n;
  9499. while (node = nodes.pop()) {
  9500. if (children = node._.children) {
  9501. node.children = new Array(n = children.length);
  9502. for (i = n - 1; i >= 0; --i) {
  9503. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9504. child.parent = node;
  9505. }
  9506. }
  9507. }
  9508. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9509. return tree;
  9510. }
  9511. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9512. function tree() {
  9513. var separation = defaultSeparation$1,
  9514. dx = 1,
  9515. dy = 1,
  9516. nodeSize = null;
  9517. function tree(root) {
  9518. var t = treeRoot(root);
  9519. // Compute the layout using Buchheim et al.’s algorithm.
  9520. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9521. t.eachBefore(secondWalk);
  9522. // If a fixed node size is specified, scale x and y.
  9523. if (nodeSize) root.eachBefore(sizeNode);
  9524. // If a fixed tree size is specified, scale x and y based on the extent.
  9525. // Compute the left-most, right-most, and depth-most nodes for extents.
  9526. else {
  9527. var left = root,
  9528. right = root,
  9529. bottom = root;
  9530. root.eachBefore(function(node) {
  9531. if (node.x < left.x) left = node;
  9532. if (node.x > right.x) right = node;
  9533. if (node.depth > bottom.depth) bottom = node;
  9534. });
  9535. var s = left === right ? 1 : separation(left, right) / 2,
  9536. tx = s - left.x,
  9537. kx = dx / (right.x + s + tx),
  9538. ky = dy / (bottom.depth || 1);
  9539. root.eachBefore(function(node) {
  9540. node.x = (node.x + tx) * kx;
  9541. node.y = node.depth * ky;
  9542. });
  9543. }
  9544. return root;
  9545. }
  9546. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9547. // applied recursively to the children of v, as well as the function
  9548. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9549. // node v is placed to the midpoint of its outermost children.
  9550. function firstWalk(v) {
  9551. var children = v.children,
  9552. siblings = v.parent.children,
  9553. w = v.i ? siblings[v.i - 1] : null;
  9554. if (children) {
  9555. executeShifts(v);
  9556. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9557. if (w) {
  9558. v.z = w.z + separation(v._, w._);
  9559. v.m = v.z - midpoint;
  9560. } else {
  9561. v.z = midpoint;
  9562. }
  9563. } else if (w) {
  9564. v.z = w.z + separation(v._, w._);
  9565. }
  9566. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9567. }
  9568. // Computes all real x-coordinates by summing up the modifiers recursively.
  9569. function secondWalk(v) {
  9570. v._.x = v.z + v.parent.m;
  9571. v.m += v.parent.m;
  9572. }
  9573. // The core of the algorithm. Here, a new subtree is combined with the
  9574. // previous subtrees. Threads are used to traverse the inside and outside
  9575. // contours of the left and right subtree up to the highest common level. The
  9576. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9577. // superscript o means outside and i means inside, the subscript - means left
  9578. // subtree and + means right subtree. For summing up the modifiers along the
  9579. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9580. // nodes of the inside contours conflict, we compute the left one of the
  9581. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9582. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9583. // Finally, we add a new thread (if necessary).
  9584. function apportion(v, w, ancestor) {
  9585. if (w) {
  9586. var vip = v,
  9587. vop = v,
  9588. vim = w,
  9589. vom = vip.parent.children[0],
  9590. sip = vip.m,
  9591. sop = vop.m,
  9592. sim = vim.m,
  9593. som = vom.m,
  9594. shift;
  9595. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9596. vom = nextLeft(vom);
  9597. vop = nextRight(vop);
  9598. vop.a = v;
  9599. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9600. if (shift > 0) {
  9601. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9602. sip += shift;
  9603. sop += shift;
  9604. }
  9605. sim += vim.m;
  9606. sip += vip.m;
  9607. som += vom.m;
  9608. sop += vop.m;
  9609. }
  9610. if (vim && !nextRight(vop)) {
  9611. vop.t = vim;
  9612. vop.m += sim - sop;
  9613. }
  9614. if (vip && !nextLeft(vom)) {
  9615. vom.t = vip;
  9616. vom.m += sip - som;
  9617. ancestor = v;
  9618. }
  9619. }
  9620. return ancestor;
  9621. }
  9622. function sizeNode(node) {
  9623. node.x *= dx;
  9624. node.y = node.depth * dy;
  9625. }
  9626. tree.separation = function(x) {
  9627. return arguments.length ? (separation = x, tree) : separation;
  9628. };
  9629. tree.size = function(x) {
  9630. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9631. };
  9632. tree.nodeSize = function(x) {
  9633. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9634. };
  9635. return tree;
  9636. }
  9637. function treemapSlice(parent, x0, y0, x1, y1) {
  9638. var nodes = parent.children,
  9639. node,
  9640. i = -1,
  9641. n = nodes.length,
  9642. k = parent.value && (y1 - y0) / parent.value;
  9643. while (++i < n) {
  9644. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9645. node.y0 = y0, node.y1 = y0 += node.value * k;
  9646. }
  9647. }
  9648. var phi = (1 + Math.sqrt(5)) / 2;
  9649. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9650. var rows = [],
  9651. nodes = parent.children,
  9652. row,
  9653. nodeValue,
  9654. i0 = 0,
  9655. i1 = 0,
  9656. n = nodes.length,
  9657. dx, dy,
  9658. value = parent.value,
  9659. sumValue,
  9660. minValue,
  9661. maxValue,
  9662. newRatio,
  9663. minRatio,
  9664. alpha,
  9665. beta;
  9666. while (i0 < n) {
  9667. dx = x1 - x0, dy = y1 - y0;
  9668. // Find the next non-empty node.
  9669. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9670. minValue = maxValue = sumValue;
  9671. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9672. beta = sumValue * sumValue * alpha;
  9673. minRatio = Math.max(maxValue / beta, beta / minValue);
  9674. // Keep adding nodes while the aspect ratio maintains or improves.
  9675. for (; i1 < n; ++i1) {
  9676. sumValue += nodeValue = nodes[i1].value;
  9677. if (nodeValue < minValue) minValue = nodeValue;
  9678. if (nodeValue > maxValue) maxValue = nodeValue;
  9679. beta = sumValue * sumValue * alpha;
  9680. newRatio = Math.max(maxValue / beta, beta / minValue);
  9681. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9682. minRatio = newRatio;
  9683. }
  9684. // Position and record the row orientation.
  9685. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9686. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9687. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9688. value -= sumValue, i0 = i1;
  9689. }
  9690. return rows;
  9691. }
  9692. var squarify = (function custom(ratio) {
  9693. function squarify(parent, x0, y0, x1, y1) {
  9694. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9695. }
  9696. squarify.ratio = function(x) {
  9697. return custom((x = +x) > 1 ? x : 1);
  9698. };
  9699. return squarify;
  9700. })(phi);
  9701. function index$3() {
  9702. var tile = squarify,
  9703. round = false,
  9704. dx = 1,
  9705. dy = 1,
  9706. paddingStack = [0],
  9707. paddingInner = constantZero,
  9708. paddingTop = constantZero,
  9709. paddingRight = constantZero,
  9710. paddingBottom = constantZero,
  9711. paddingLeft = constantZero;
  9712. function treemap(root) {
  9713. root.x0 =
  9714. root.y0 = 0;
  9715. root.x1 = dx;
  9716. root.y1 = dy;
  9717. root.eachBefore(positionNode);
  9718. paddingStack = [0];
  9719. if (round) root.eachBefore(roundNode);
  9720. return root;
  9721. }
  9722. function positionNode(node) {
  9723. var p = paddingStack[node.depth],
  9724. x0 = node.x0 + p,
  9725. y0 = node.y0 + p,
  9726. x1 = node.x1 - p,
  9727. y1 = node.y1 - p;
  9728. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9729. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9730. node.x0 = x0;
  9731. node.y0 = y0;
  9732. node.x1 = x1;
  9733. node.y1 = y1;
  9734. if (node.children) {
  9735. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9736. x0 += paddingLeft(node) - p;
  9737. y0 += paddingTop(node) - p;
  9738. x1 -= paddingRight(node) - p;
  9739. y1 -= paddingBottom(node) - p;
  9740. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9741. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9742. tile(node, x0, y0, x1, y1);
  9743. }
  9744. }
  9745. treemap.round = function(x) {
  9746. return arguments.length ? (round = !!x, treemap) : round;
  9747. };
  9748. treemap.size = function(x) {
  9749. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9750. };
  9751. treemap.tile = function(x) {
  9752. return arguments.length ? (tile = required(x), treemap) : tile;
  9753. };
  9754. treemap.padding = function(x) {
  9755. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9756. };
  9757. treemap.paddingInner = function(x) {
  9758. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  9759. };
  9760. treemap.paddingOuter = function(x) {
  9761. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9762. };
  9763. treemap.paddingTop = function(x) {
  9764. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  9765. };
  9766. treemap.paddingRight = function(x) {
  9767. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  9768. };
  9769. treemap.paddingBottom = function(x) {
  9770. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  9771. };
  9772. treemap.paddingLeft = function(x) {
  9773. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  9774. };
  9775. return treemap;
  9776. }
  9777. function binary(parent, x0, y0, x1, y1) {
  9778. var nodes = parent.children,
  9779. i, n = nodes.length,
  9780. sum, sums = new Array(n + 1);
  9781. for (sums[0] = sum = i = 0; i < n; ++i) {
  9782. sums[i + 1] = sum += nodes[i].value;
  9783. }
  9784. partition(0, n, parent.value, x0, y0, x1, y1);
  9785. function partition(i, j, value, x0, y0, x1, y1) {
  9786. if (i >= j - 1) {
  9787. var node = nodes[i];
  9788. node.x0 = x0, node.y0 = y0;
  9789. node.x1 = x1, node.y1 = y1;
  9790. return;
  9791. }
  9792. var valueOffset = sums[i],
  9793. valueTarget = (value / 2) + valueOffset,
  9794. k = i + 1,
  9795. hi = j - 1;
  9796. while (k < hi) {
  9797. var mid = k + hi >>> 1;
  9798. if (sums[mid] < valueTarget) k = mid + 1;
  9799. else hi = mid;
  9800. }
  9801. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  9802. var valueLeft = sums[k] - valueOffset,
  9803. valueRight = value - valueLeft;
  9804. if ((x1 - x0) > (y1 - y0)) {
  9805. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  9806. partition(i, k, valueLeft, x0, y0, xk, y1);
  9807. partition(k, j, valueRight, xk, y0, x1, y1);
  9808. } else {
  9809. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  9810. partition(i, k, valueLeft, x0, y0, x1, yk);
  9811. partition(k, j, valueRight, x0, yk, x1, y1);
  9812. }
  9813. }
  9814. }
  9815. function sliceDice(parent, x0, y0, x1, y1) {
  9816. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  9817. }
  9818. var resquarify = (function custom(ratio) {
  9819. function resquarify(parent, x0, y0, x1, y1) {
  9820. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  9821. var rows,
  9822. row,
  9823. nodes,
  9824. i,
  9825. j = -1,
  9826. n,
  9827. m = rows.length,
  9828. value = parent.value;
  9829. while (++j < m) {
  9830. row = rows[j], nodes = row.children;
  9831. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  9832. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  9833. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  9834. value -= row.value;
  9835. }
  9836. } else {
  9837. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9838. rows.ratio = ratio;
  9839. }
  9840. }
  9841. resquarify.ratio = function(x) {
  9842. return custom((x = +x) > 1 ? x : 1);
  9843. };
  9844. return resquarify;
  9845. })(phi);
  9846. function area$2(polygon) {
  9847. var i = -1,
  9848. n = polygon.length,
  9849. a,
  9850. b = polygon[n - 1],
  9851. area = 0;
  9852. while (++i < n) {
  9853. a = b;
  9854. b = polygon[i];
  9855. area += a[1] * b[0] - a[0] * b[1];
  9856. }
  9857. return area / 2;
  9858. }
  9859. function centroid$1(polygon) {
  9860. var i = -1,
  9861. n = polygon.length,
  9862. x = 0,
  9863. y = 0,
  9864. a,
  9865. b = polygon[n - 1],
  9866. c,
  9867. k = 0;
  9868. while (++i < n) {
  9869. a = b;
  9870. b = polygon[i];
  9871. k += c = a[0] * b[1] - b[0] * a[1];
  9872. x += (a[0] + b[0]) * c;
  9873. y += (a[1] + b[1]) * c;
  9874. }
  9875. return k *= 3, [x / k, y / k];
  9876. }
  9877. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  9878. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  9879. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  9880. // negative if clockwise, and zero if the points are collinear.
  9881. function cross$1(a, b, c) {
  9882. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  9883. }
  9884. function lexicographicOrder(a, b) {
  9885. return a[0] - b[0] || a[1] - b[1];
  9886. }
  9887. // Computes the upper convex hull per the monotone chain algorithm.
  9888. // Assumes points.length >= 3, is sorted by x, unique in y.
  9889. // Returns an array of indices into points in left-to-right order.
  9890. function computeUpperHullIndexes(points) {
  9891. var n = points.length,
  9892. indexes = [0, 1],
  9893. size = 2;
  9894. for (var i = 2; i < n; ++i) {
  9895. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  9896. indexes[size++] = i;
  9897. }
  9898. return indexes.slice(0, size); // remove popped points
  9899. }
  9900. function hull(points) {
  9901. if ((n = points.length) < 3) return null;
  9902. var i,
  9903. n,
  9904. sortedPoints = new Array(n),
  9905. flippedPoints = new Array(n);
  9906. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  9907. sortedPoints.sort(lexicographicOrder);
  9908. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  9909. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  9910. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  9911. // Construct the hull polygon, removing possible duplicate endpoints.
  9912. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  9913. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  9914. hull = [];
  9915. // Add upper hull in right-to-l order.
  9916. // Then add lower hull in left-to-right order.
  9917. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  9918. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  9919. return hull;
  9920. }
  9921. function contains$2(polygon, point) {
  9922. var n = polygon.length,
  9923. p = polygon[n - 1],
  9924. x = point[0], y = point[1],
  9925. x0 = p[0], y0 = p[1],
  9926. x1, y1,
  9927. inside = false;
  9928. for (var i = 0; i < n; ++i) {
  9929. p = polygon[i], x1 = p[0], y1 = p[1];
  9930. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  9931. x0 = x1, y0 = y1;
  9932. }
  9933. return inside;
  9934. }
  9935. function length$2(polygon) {
  9936. var i = -1,
  9937. n = polygon.length,
  9938. b = polygon[n - 1],
  9939. xa,
  9940. ya,
  9941. xb = b[0],
  9942. yb = b[1],
  9943. perimeter = 0;
  9944. while (++i < n) {
  9945. xa = xb;
  9946. ya = yb;
  9947. b = polygon[i];
  9948. xb = b[0];
  9949. yb = b[1];
  9950. xa -= xb;
  9951. ya -= yb;
  9952. perimeter += Math.sqrt(xa * xa + ya * ya);
  9953. }
  9954. return perimeter;
  9955. }
  9956. function defaultSource$1() {
  9957. return Math.random();
  9958. }
  9959. var uniform = (function sourceRandomUniform(source) {
  9960. function randomUniform(min, max) {
  9961. min = min == null ? 0 : +min;
  9962. max = max == null ? 1 : +max;
  9963. if (arguments.length === 1) max = min, min = 0;
  9964. else max -= min;
  9965. return function() {
  9966. return source() * max + min;
  9967. };
  9968. }
  9969. randomUniform.source = sourceRandomUniform;
  9970. return randomUniform;
  9971. })(defaultSource$1);
  9972. var normal = (function sourceRandomNormal(source) {
  9973. function randomNormal(mu, sigma) {
  9974. var x, r;
  9975. mu = mu == null ? 0 : +mu;
  9976. sigma = sigma == null ? 1 : +sigma;
  9977. return function() {
  9978. var y;
  9979. // If available, use the second previously-generated uniform random.
  9980. if (x != null) y = x, x = null;
  9981. // Otherwise, generate a new x and y.
  9982. else do {
  9983. x = source() * 2 - 1;
  9984. y = source() * 2 - 1;
  9985. r = x * x + y * y;
  9986. } while (!r || r > 1);
  9987. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  9988. };
  9989. }
  9990. randomNormal.source = sourceRandomNormal;
  9991. return randomNormal;
  9992. })(defaultSource$1);
  9993. var logNormal = (function sourceRandomLogNormal(source) {
  9994. function randomLogNormal() {
  9995. var randomNormal = normal.source(source).apply(this, arguments);
  9996. return function() {
  9997. return Math.exp(randomNormal());
  9998. };
  9999. }
  10000. randomLogNormal.source = sourceRandomLogNormal;
  10001. return randomLogNormal;
  10002. })(defaultSource$1);
  10003. var irwinHall = (function sourceRandomIrwinHall(source) {
  10004. function randomIrwinHall(n) {
  10005. return function() {
  10006. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  10007. return sum;
  10008. };
  10009. }
  10010. randomIrwinHall.source = sourceRandomIrwinHall;
  10011. return randomIrwinHall;
  10012. })(defaultSource$1);
  10013. var bates = (function sourceRandomBates(source) {
  10014. function randomBates(n) {
  10015. var randomIrwinHall = irwinHall.source(source)(n);
  10016. return function() {
  10017. return randomIrwinHall() / n;
  10018. };
  10019. }
  10020. randomBates.source = sourceRandomBates;
  10021. return randomBates;
  10022. })(defaultSource$1);
  10023. var exponential$1 = (function sourceRandomExponential(source) {
  10024. function randomExponential(lambda) {
  10025. return function() {
  10026. return -Math.log(1 - source()) / lambda;
  10027. };
  10028. }
  10029. randomExponential.source = sourceRandomExponential;
  10030. return randomExponential;
  10031. })(defaultSource$1);
  10032. var array$3 = Array.prototype;
  10033. var map$2 = array$3.map;
  10034. var slice$5 = array$3.slice;
  10035. var implicit = {name: "implicit"};
  10036. function ordinal(range) {
  10037. var index = map$1(),
  10038. domain = [],
  10039. unknown = implicit;
  10040. range = range == null ? [] : slice$5.call(range);
  10041. function scale(d) {
  10042. var key = d + "", i = index.get(key);
  10043. if (!i) {
  10044. if (unknown !== implicit) return unknown;
  10045. index.set(key, i = domain.push(d));
  10046. }
  10047. return range[(i - 1) % range.length];
  10048. }
  10049. scale.domain = function(_) {
  10050. if (!arguments.length) return domain.slice();
  10051. domain = [], index = map$1();
  10052. var i = -1, n = _.length, d, key;
  10053. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  10054. return scale;
  10055. };
  10056. scale.range = function(_) {
  10057. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  10058. };
  10059. scale.unknown = function(_) {
  10060. return arguments.length ? (unknown = _, scale) : unknown;
  10061. };
  10062. scale.copy = function() {
  10063. return ordinal()
  10064. .domain(domain)
  10065. .range(range)
  10066. .unknown(unknown);
  10067. };
  10068. return scale;
  10069. }
  10070. function band() {
  10071. var scale = ordinal().unknown(undefined),
  10072. domain = scale.domain,
  10073. ordinalRange = scale.range,
  10074. range$$1 = [0, 1],
  10075. step,
  10076. bandwidth,
  10077. round = false,
  10078. paddingInner = 0,
  10079. paddingOuter = 0,
  10080. align = 0.5;
  10081. delete scale.unknown;
  10082. function rescale() {
  10083. var n = domain().length,
  10084. reverse = range$$1[1] < range$$1[0],
  10085. start = range$$1[reverse - 0],
  10086. stop = range$$1[1 - reverse];
  10087. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  10088. if (round) step = Math.floor(step);
  10089. start += (stop - start - step * (n - paddingInner)) * align;
  10090. bandwidth = step * (1 - paddingInner);
  10091. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  10092. var values = sequence(n).map(function(i) { return start + step * i; });
  10093. return ordinalRange(reverse ? values.reverse() : values);
  10094. }
  10095. scale.domain = function(_) {
  10096. return arguments.length ? (domain(_), rescale()) : domain();
  10097. };
  10098. scale.range = function(_) {
  10099. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  10100. };
  10101. scale.rangeRound = function(_) {
  10102. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  10103. };
  10104. scale.bandwidth = function() {
  10105. return bandwidth;
  10106. };
  10107. scale.step = function() {
  10108. return step;
  10109. };
  10110. scale.round = function(_) {
  10111. return arguments.length ? (round = !!_, rescale()) : round;
  10112. };
  10113. scale.padding = function(_) {
  10114. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10115. };
  10116. scale.paddingInner = function(_) {
  10117. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10118. };
  10119. scale.paddingOuter = function(_) {
  10120. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  10121. };
  10122. scale.align = function(_) {
  10123. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  10124. };
  10125. scale.copy = function() {
  10126. return band()
  10127. .domain(domain())
  10128. .range(range$$1)
  10129. .round(round)
  10130. .paddingInner(paddingInner)
  10131. .paddingOuter(paddingOuter)
  10132. .align(align);
  10133. };
  10134. return rescale();
  10135. }
  10136. function pointish(scale) {
  10137. var copy = scale.copy;
  10138. scale.padding = scale.paddingOuter;
  10139. delete scale.paddingInner;
  10140. delete scale.paddingOuter;
  10141. scale.copy = function() {
  10142. return pointish(copy());
  10143. };
  10144. return scale;
  10145. }
  10146. function point$1() {
  10147. return pointish(band().paddingInner(1));
  10148. }
  10149. function constant$a(x) {
  10150. return function() {
  10151. return x;
  10152. };
  10153. }
  10154. function number$2(x) {
  10155. return +x;
  10156. }
  10157. var unit = [0, 1];
  10158. function deinterpolateLinear(a, b) {
  10159. return (b -= (a = +a))
  10160. ? function(x) { return (x - a) / b; }
  10161. : constant$a(b);
  10162. }
  10163. function deinterpolateClamp(deinterpolate) {
  10164. return function(a, b) {
  10165. var d = deinterpolate(a = +a, b = +b);
  10166. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  10167. };
  10168. }
  10169. function reinterpolateClamp(reinterpolate) {
  10170. return function(a, b) {
  10171. var r = reinterpolate(a = +a, b = +b);
  10172. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  10173. };
  10174. }
  10175. function bimap(domain, range, deinterpolate, reinterpolate) {
  10176. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  10177. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
  10178. else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
  10179. return function(x) { return r0(d0(x)); };
  10180. }
  10181. function polymap(domain, range, deinterpolate, reinterpolate) {
  10182. var j = Math.min(domain.length, range.length) - 1,
  10183. d = new Array(j),
  10184. r = new Array(j),
  10185. i = -1;
  10186. // Reverse descending domains.
  10187. if (domain[j] < domain[0]) {
  10188. domain = domain.slice().reverse();
  10189. range = range.slice().reverse();
  10190. }
  10191. while (++i < j) {
  10192. d[i] = deinterpolate(domain[i], domain[i + 1]);
  10193. r[i] = reinterpolate(range[i], range[i + 1]);
  10194. }
  10195. return function(x) {
  10196. var i = bisectRight(domain, x, 1, j) - 1;
  10197. return r[i](d[i](x));
  10198. };
  10199. }
  10200. function copy(source, target) {
  10201. return target
  10202. .domain(source.domain())
  10203. .range(source.range())
  10204. .interpolate(source.interpolate())
  10205. .clamp(source.clamp());
  10206. }
  10207. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10208. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  10209. function continuous(deinterpolate, reinterpolate) {
  10210. var domain = unit,
  10211. range = unit,
  10212. interpolate$$1 = interpolateValue,
  10213. clamp = false,
  10214. piecewise$$1,
  10215. output,
  10216. input;
  10217. function rescale() {
  10218. piecewise$$1 = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10219. output = input = null;
  10220. return scale;
  10221. }
  10222. function scale(x) {
  10223. return (output || (output = piecewise$$1(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  10224. }
  10225. scale.invert = function(y) {
  10226. return (input || (input = piecewise$$1(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
  10227. };
  10228. scale.domain = function(_) {
  10229. return arguments.length ? (domain = map$2.call(_, number$2), rescale()) : domain.slice();
  10230. };
  10231. scale.range = function(_) {
  10232. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10233. };
  10234. scale.rangeRound = function(_) {
  10235. return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
  10236. };
  10237. scale.clamp = function(_) {
  10238. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  10239. };
  10240. scale.interpolate = function(_) {
  10241. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  10242. };
  10243. return rescale();
  10244. }
  10245. function tickFormat(domain, count, specifier) {
  10246. var start = domain[0],
  10247. stop = domain[domain.length - 1],
  10248. step = tickStep(start, stop, count == null ? 10 : count),
  10249. precision;
  10250. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10251. switch (specifier.type) {
  10252. case "s": {
  10253. var value = Math.max(Math.abs(start), Math.abs(stop));
  10254. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10255. return exports.formatPrefix(specifier, value);
  10256. }
  10257. case "":
  10258. case "e":
  10259. case "g":
  10260. case "p":
  10261. case "r": {
  10262. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10263. break;
  10264. }
  10265. case "f":
  10266. case "%": {
  10267. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10268. break;
  10269. }
  10270. }
  10271. return exports.format(specifier);
  10272. }
  10273. function linearish(scale) {
  10274. var domain = scale.domain;
  10275. scale.ticks = function(count) {
  10276. var d = domain();
  10277. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10278. };
  10279. scale.tickFormat = function(count, specifier) {
  10280. return tickFormat(domain(), count, specifier);
  10281. };
  10282. scale.nice = function(count) {
  10283. if (count == null) count = 10;
  10284. var d = domain(),
  10285. i0 = 0,
  10286. i1 = d.length - 1,
  10287. start = d[i0],
  10288. stop = d[i1],
  10289. step;
  10290. if (stop < start) {
  10291. step = start, start = stop, stop = step;
  10292. step = i0, i0 = i1, i1 = step;
  10293. }
  10294. step = tickIncrement(start, stop, count);
  10295. if (step > 0) {
  10296. start = Math.floor(start / step) * step;
  10297. stop = Math.ceil(stop / step) * step;
  10298. step = tickIncrement(start, stop, count);
  10299. } else if (step < 0) {
  10300. start = Math.ceil(start * step) / step;
  10301. stop = Math.floor(stop * step) / step;
  10302. step = tickIncrement(start, stop, count);
  10303. }
  10304. if (step > 0) {
  10305. d[i0] = Math.floor(start / step) * step;
  10306. d[i1] = Math.ceil(stop / step) * step;
  10307. domain(d);
  10308. } else if (step < 0) {
  10309. d[i0] = Math.ceil(start * step) / step;
  10310. d[i1] = Math.floor(stop * step) / step;
  10311. domain(d);
  10312. }
  10313. return scale;
  10314. };
  10315. return scale;
  10316. }
  10317. function linear$2() {
  10318. var scale = continuous(deinterpolateLinear, interpolateNumber);
  10319. scale.copy = function() {
  10320. return copy(scale, linear$2());
  10321. };
  10322. return linearish(scale);
  10323. }
  10324. function identity$6() {
  10325. var domain = [0, 1];
  10326. function scale(x) {
  10327. return +x;
  10328. }
  10329. scale.invert = scale;
  10330. scale.domain = scale.range = function(_) {
  10331. return arguments.length ? (domain = map$2.call(_, number$2), scale) : domain.slice();
  10332. };
  10333. scale.copy = function() {
  10334. return identity$6().domain(domain);
  10335. };
  10336. return linearish(scale);
  10337. }
  10338. function nice(domain, interval) {
  10339. domain = domain.slice();
  10340. var i0 = 0,
  10341. i1 = domain.length - 1,
  10342. x0 = domain[i0],
  10343. x1 = domain[i1],
  10344. t;
  10345. if (x1 < x0) {
  10346. t = i0, i0 = i1, i1 = t;
  10347. t = x0, x0 = x1, x1 = t;
  10348. }
  10349. domain[i0] = interval.floor(x0);
  10350. domain[i1] = interval.ceil(x1);
  10351. return domain;
  10352. }
  10353. function deinterpolate(a, b) {
  10354. return (b = Math.log(b / a))
  10355. ? function(x) { return Math.log(x / a) / b; }
  10356. : constant$a(b);
  10357. }
  10358. function reinterpolate(a, b) {
  10359. return a < 0
  10360. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  10361. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  10362. }
  10363. function pow10(x) {
  10364. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10365. }
  10366. function powp(base) {
  10367. return base === 10 ? pow10
  10368. : base === Math.E ? Math.exp
  10369. : function(x) { return Math.pow(base, x); };
  10370. }
  10371. function logp(base) {
  10372. return base === Math.E ? Math.log
  10373. : base === 10 && Math.log10
  10374. || base === 2 && Math.log2
  10375. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10376. }
  10377. function reflect(f) {
  10378. return function(x) {
  10379. return -f(-x);
  10380. };
  10381. }
  10382. function log$1() {
  10383. var scale = continuous(deinterpolate, reinterpolate).domain([1, 10]),
  10384. domain = scale.domain,
  10385. base = 10,
  10386. logs = logp(10),
  10387. pows = powp(10);
  10388. function rescale() {
  10389. logs = logp(base), pows = powp(base);
  10390. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  10391. return scale;
  10392. }
  10393. scale.base = function(_) {
  10394. return arguments.length ? (base = +_, rescale()) : base;
  10395. };
  10396. scale.domain = function(_) {
  10397. return arguments.length ? (domain(_), rescale()) : domain();
  10398. };
  10399. scale.ticks = function(count) {
  10400. var d = domain(),
  10401. u = d[0],
  10402. v = d[d.length - 1],
  10403. r;
  10404. if (r = v < u) i = u, u = v, v = i;
  10405. var i = logs(u),
  10406. j = logs(v),
  10407. p,
  10408. k,
  10409. t,
  10410. n = count == null ? 10 : +count,
  10411. z = [];
  10412. if (!(base % 1) && j - i < n) {
  10413. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10414. if (u > 0) for (; i < j; ++i) {
  10415. for (k = 1, p = pows(i); k < base; ++k) {
  10416. t = p * k;
  10417. if (t < u) continue;
  10418. if (t > v) break;
  10419. z.push(t);
  10420. }
  10421. } else for (; i < j; ++i) {
  10422. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10423. t = p * k;
  10424. if (t < u) continue;
  10425. if (t > v) break;
  10426. z.push(t);
  10427. }
  10428. }
  10429. } else {
  10430. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10431. }
  10432. return r ? z.reverse() : z;
  10433. };
  10434. scale.tickFormat = function(count, specifier) {
  10435. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10436. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10437. if (count === Infinity) return specifier;
  10438. if (count == null) count = 10;
  10439. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10440. return function(d) {
  10441. var i = d / pows(Math.round(logs(d)));
  10442. if (i * base < base - 0.5) i *= base;
  10443. return i <= k ? specifier(d) : "";
  10444. };
  10445. };
  10446. scale.nice = function() {
  10447. return domain(nice(domain(), {
  10448. floor: function(x) { return pows(Math.floor(logs(x))); },
  10449. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10450. }));
  10451. };
  10452. scale.copy = function() {
  10453. return copy(scale, log$1().base(base));
  10454. };
  10455. return scale;
  10456. }
  10457. function raise$1(x, exponent) {
  10458. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10459. }
  10460. function pow$1() {
  10461. var exponent = 1,
  10462. scale = continuous(deinterpolate, reinterpolate),
  10463. domain = scale.domain;
  10464. function deinterpolate(a, b) {
  10465. return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
  10466. ? function(x) { return (raise$1(x, exponent) - a) / b; }
  10467. : constant$a(b);
  10468. }
  10469. function reinterpolate(a, b) {
  10470. b = raise$1(b, exponent) - (a = raise$1(a, exponent));
  10471. return function(t) { return raise$1(a + b * t, 1 / exponent); };
  10472. }
  10473. scale.exponent = function(_) {
  10474. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  10475. };
  10476. scale.copy = function() {
  10477. return copy(scale, pow$1().exponent(exponent));
  10478. };
  10479. return linearish(scale);
  10480. }
  10481. function sqrt$1() {
  10482. return pow$1().exponent(0.5);
  10483. }
  10484. function quantile$$1() {
  10485. var domain = [],
  10486. range = [],
  10487. thresholds = [];
  10488. function rescale() {
  10489. var i = 0, n = Math.max(1, range.length);
  10490. thresholds = new Array(n - 1);
  10491. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10492. return scale;
  10493. }
  10494. function scale(x) {
  10495. if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
  10496. }
  10497. scale.invertExtent = function(y) {
  10498. var i = range.indexOf(y);
  10499. return i < 0 ? [NaN, NaN] : [
  10500. i > 0 ? thresholds[i - 1] : domain[0],
  10501. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10502. ];
  10503. };
  10504. scale.domain = function(_) {
  10505. if (!arguments.length) return domain.slice();
  10506. domain = [];
  10507. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10508. domain.sort(ascending);
  10509. return rescale();
  10510. };
  10511. scale.range = function(_) {
  10512. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10513. };
  10514. scale.quantiles = function() {
  10515. return thresholds.slice();
  10516. };
  10517. scale.copy = function() {
  10518. return quantile$$1()
  10519. .domain(domain)
  10520. .range(range);
  10521. };
  10522. return scale;
  10523. }
  10524. function quantize$1() {
  10525. var x0 = 0,
  10526. x1 = 1,
  10527. n = 1,
  10528. domain = [0.5],
  10529. range = [0, 1];
  10530. function scale(x) {
  10531. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10532. }
  10533. function rescale() {
  10534. var i = -1;
  10535. domain = new Array(n);
  10536. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10537. return scale;
  10538. }
  10539. scale.domain = function(_) {
  10540. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10541. };
  10542. scale.range = function(_) {
  10543. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10544. };
  10545. scale.invertExtent = function(y) {
  10546. var i = range.indexOf(y);
  10547. return i < 0 ? [NaN, NaN]
  10548. : i < 1 ? [x0, domain[0]]
  10549. : i >= n ? [domain[n - 1], x1]
  10550. : [domain[i - 1], domain[i]];
  10551. };
  10552. scale.copy = function() {
  10553. return quantize$1()
  10554. .domain([x0, x1])
  10555. .range(range);
  10556. };
  10557. return linearish(scale);
  10558. }
  10559. function threshold$1() {
  10560. var domain = [0.5],
  10561. range = [0, 1],
  10562. n = 1;
  10563. function scale(x) {
  10564. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10565. }
  10566. scale.domain = function(_) {
  10567. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10568. };
  10569. scale.range = function(_) {
  10570. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10571. };
  10572. scale.invertExtent = function(y) {
  10573. var i = range.indexOf(y);
  10574. return [domain[i - 1], domain[i]];
  10575. };
  10576. scale.copy = function() {
  10577. return threshold$1()
  10578. .domain(domain)
  10579. .range(range);
  10580. };
  10581. return scale;
  10582. }
  10583. var t0$1 = new Date,
  10584. t1$1 = new Date;
  10585. function newInterval(floori, offseti, count, field) {
  10586. function interval(date) {
  10587. return floori(date = new Date(+date)), date;
  10588. }
  10589. interval.floor = interval;
  10590. interval.ceil = function(date) {
  10591. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10592. };
  10593. interval.round = function(date) {
  10594. var d0 = interval(date),
  10595. d1 = interval.ceil(date);
  10596. return date - d0 < d1 - date ? d0 : d1;
  10597. };
  10598. interval.offset = function(date, step) {
  10599. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10600. };
  10601. interval.range = function(start, stop, step) {
  10602. var range = [], previous;
  10603. start = interval.ceil(start);
  10604. step = step == null ? 1 : Math.floor(step);
  10605. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10606. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  10607. while (previous < start && start < stop);
  10608. return range;
  10609. };
  10610. interval.filter = function(test) {
  10611. return newInterval(function(date) {
  10612. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10613. }, function(date, step) {
  10614. if (date >= date) {
  10615. if (step < 0) while (++step <= 0) {
  10616. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10617. } else while (--step >= 0) {
  10618. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10619. }
  10620. }
  10621. });
  10622. };
  10623. if (count) {
  10624. interval.count = function(start, end) {
  10625. t0$1.setTime(+start), t1$1.setTime(+end);
  10626. floori(t0$1), floori(t1$1);
  10627. return Math.floor(count(t0$1, t1$1));
  10628. };
  10629. interval.every = function(step) {
  10630. step = Math.floor(step);
  10631. return !isFinite(step) || !(step > 0) ? null
  10632. : !(step > 1) ? interval
  10633. : interval.filter(field
  10634. ? function(d) { return field(d) % step === 0; }
  10635. : function(d) { return interval.count(0, d) % step === 0; });
  10636. };
  10637. }
  10638. return interval;
  10639. }
  10640. var millisecond = newInterval(function() {
  10641. // noop
  10642. }, function(date, step) {
  10643. date.setTime(+date + step);
  10644. }, function(start, end) {
  10645. return end - start;
  10646. });
  10647. // An optimized implementation for this simple case.
  10648. millisecond.every = function(k) {
  10649. k = Math.floor(k);
  10650. if (!isFinite(k) || !(k > 0)) return null;
  10651. if (!(k > 1)) return millisecond;
  10652. return newInterval(function(date) {
  10653. date.setTime(Math.floor(date / k) * k);
  10654. }, function(date, step) {
  10655. date.setTime(+date + step * k);
  10656. }, function(start, end) {
  10657. return (end - start) / k;
  10658. });
  10659. };
  10660. var milliseconds = millisecond.range;
  10661. var durationSecond = 1e3;
  10662. var durationMinute = 6e4;
  10663. var durationHour = 36e5;
  10664. var durationDay = 864e5;
  10665. var durationWeek = 6048e5;
  10666. var second = newInterval(function(date) {
  10667. date.setTime(Math.floor(date / durationSecond) * durationSecond);
  10668. }, function(date, step) {
  10669. date.setTime(+date + step * durationSecond);
  10670. }, function(start, end) {
  10671. return (end - start) / durationSecond;
  10672. }, function(date) {
  10673. return date.getUTCSeconds();
  10674. });
  10675. var seconds = second.range;
  10676. var minute = newInterval(function(date) {
  10677. date.setTime(Math.floor(date / durationMinute) * durationMinute);
  10678. }, function(date, step) {
  10679. date.setTime(+date + step * durationMinute);
  10680. }, function(start, end) {
  10681. return (end - start) / durationMinute;
  10682. }, function(date) {
  10683. return date.getMinutes();
  10684. });
  10685. var minutes = minute.range;
  10686. var hour = newInterval(function(date) {
  10687. var offset = date.getTimezoneOffset() * durationMinute % durationHour;
  10688. if (offset < 0) offset += durationHour;
  10689. date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
  10690. }, function(date, step) {
  10691. date.setTime(+date + step * durationHour);
  10692. }, function(start, end) {
  10693. return (end - start) / durationHour;
  10694. }, function(date) {
  10695. return date.getHours();
  10696. });
  10697. var hours = hour.range;
  10698. var day = newInterval(function(date) {
  10699. date.setHours(0, 0, 0, 0);
  10700. }, function(date, step) {
  10701. date.setDate(date.getDate() + step);
  10702. }, function(start, end) {
  10703. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  10704. }, function(date) {
  10705. return date.getDate() - 1;
  10706. });
  10707. var days = day.range;
  10708. function weekday(i) {
  10709. return newInterval(function(date) {
  10710. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  10711. date.setHours(0, 0, 0, 0);
  10712. }, function(date, step) {
  10713. date.setDate(date.getDate() + step * 7);
  10714. }, function(start, end) {
  10715. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  10716. });
  10717. }
  10718. var sunday = weekday(0);
  10719. var monday = weekday(1);
  10720. var tuesday = weekday(2);
  10721. var wednesday = weekday(3);
  10722. var thursday = weekday(4);
  10723. var friday = weekday(5);
  10724. var saturday = weekday(6);
  10725. var sundays = sunday.range;
  10726. var mondays = monday.range;
  10727. var tuesdays = tuesday.range;
  10728. var wednesdays = wednesday.range;
  10729. var thursdays = thursday.range;
  10730. var fridays = friday.range;
  10731. var saturdays = saturday.range;
  10732. var month = newInterval(function(date) {
  10733. date.setDate(1);
  10734. date.setHours(0, 0, 0, 0);
  10735. }, function(date, step) {
  10736. date.setMonth(date.getMonth() + step);
  10737. }, function(start, end) {
  10738. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  10739. }, function(date) {
  10740. return date.getMonth();
  10741. });
  10742. var months = month.range;
  10743. var year = newInterval(function(date) {
  10744. date.setMonth(0, 1);
  10745. date.setHours(0, 0, 0, 0);
  10746. }, function(date, step) {
  10747. date.setFullYear(date.getFullYear() + step);
  10748. }, function(start, end) {
  10749. return end.getFullYear() - start.getFullYear();
  10750. }, function(date) {
  10751. return date.getFullYear();
  10752. });
  10753. // An optimized implementation for this simple case.
  10754. year.every = function(k) {
  10755. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10756. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  10757. date.setMonth(0, 1);
  10758. date.setHours(0, 0, 0, 0);
  10759. }, function(date, step) {
  10760. date.setFullYear(date.getFullYear() + step * k);
  10761. });
  10762. };
  10763. var years = year.range;
  10764. var utcMinute = newInterval(function(date) {
  10765. date.setUTCSeconds(0, 0);
  10766. }, function(date, step) {
  10767. date.setTime(+date + step * durationMinute);
  10768. }, function(start, end) {
  10769. return (end - start) / durationMinute;
  10770. }, function(date) {
  10771. return date.getUTCMinutes();
  10772. });
  10773. var utcMinutes = utcMinute.range;
  10774. var utcHour = newInterval(function(date) {
  10775. date.setUTCMinutes(0, 0, 0);
  10776. }, function(date, step) {
  10777. date.setTime(+date + step * durationHour);
  10778. }, function(start, end) {
  10779. return (end - start) / durationHour;
  10780. }, function(date) {
  10781. return date.getUTCHours();
  10782. });
  10783. var utcHours = utcHour.range;
  10784. var utcDay = newInterval(function(date) {
  10785. date.setUTCHours(0, 0, 0, 0);
  10786. }, function(date, step) {
  10787. date.setUTCDate(date.getUTCDate() + step);
  10788. }, function(start, end) {
  10789. return (end - start) / durationDay;
  10790. }, function(date) {
  10791. return date.getUTCDate() - 1;
  10792. });
  10793. var utcDays = utcDay.range;
  10794. function utcWeekday(i) {
  10795. return newInterval(function(date) {
  10796. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  10797. date.setUTCHours(0, 0, 0, 0);
  10798. }, function(date, step) {
  10799. date.setUTCDate(date.getUTCDate() + step * 7);
  10800. }, function(start, end) {
  10801. return (end - start) / durationWeek;
  10802. });
  10803. }
  10804. var utcSunday = utcWeekday(0);
  10805. var utcMonday = utcWeekday(1);
  10806. var utcTuesday = utcWeekday(2);
  10807. var utcWednesday = utcWeekday(3);
  10808. var utcThursday = utcWeekday(4);
  10809. var utcFriday = utcWeekday(5);
  10810. var utcSaturday = utcWeekday(6);
  10811. var utcSundays = utcSunday.range;
  10812. var utcMondays = utcMonday.range;
  10813. var utcTuesdays = utcTuesday.range;
  10814. var utcWednesdays = utcWednesday.range;
  10815. var utcThursdays = utcThursday.range;
  10816. var utcFridays = utcFriday.range;
  10817. var utcSaturdays = utcSaturday.range;
  10818. var utcMonth = newInterval(function(date) {
  10819. date.setUTCDate(1);
  10820. date.setUTCHours(0, 0, 0, 0);
  10821. }, function(date, step) {
  10822. date.setUTCMonth(date.getUTCMonth() + step);
  10823. }, function(start, end) {
  10824. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  10825. }, function(date) {
  10826. return date.getUTCMonth();
  10827. });
  10828. var utcMonths = utcMonth.range;
  10829. var utcYear = newInterval(function(date) {
  10830. date.setUTCMonth(0, 1);
  10831. date.setUTCHours(0, 0, 0, 0);
  10832. }, function(date, step) {
  10833. date.setUTCFullYear(date.getUTCFullYear() + step);
  10834. }, function(start, end) {
  10835. return end.getUTCFullYear() - start.getUTCFullYear();
  10836. }, function(date) {
  10837. return date.getUTCFullYear();
  10838. });
  10839. // An optimized implementation for this simple case.
  10840. utcYear.every = function(k) {
  10841. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10842. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  10843. date.setUTCMonth(0, 1);
  10844. date.setUTCHours(0, 0, 0, 0);
  10845. }, function(date, step) {
  10846. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  10847. });
  10848. };
  10849. var utcYears = utcYear.range;
  10850. function localDate(d) {
  10851. if (0 <= d.y && d.y < 100) {
  10852. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  10853. date.setFullYear(d.y);
  10854. return date;
  10855. }
  10856. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  10857. }
  10858. function utcDate(d) {
  10859. if (0 <= d.y && d.y < 100) {
  10860. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  10861. date.setUTCFullYear(d.y);
  10862. return date;
  10863. }
  10864. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  10865. }
  10866. function newYear(y) {
  10867. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  10868. }
  10869. function formatLocale$1(locale) {
  10870. var locale_dateTime = locale.dateTime,
  10871. locale_date = locale.date,
  10872. locale_time = locale.time,
  10873. locale_periods = locale.periods,
  10874. locale_weekdays = locale.days,
  10875. locale_shortWeekdays = locale.shortDays,
  10876. locale_months = locale.months,
  10877. locale_shortMonths = locale.shortMonths;
  10878. var periodRe = formatRe(locale_periods),
  10879. periodLookup = formatLookup(locale_periods),
  10880. weekdayRe = formatRe(locale_weekdays),
  10881. weekdayLookup = formatLookup(locale_weekdays),
  10882. shortWeekdayRe = formatRe(locale_shortWeekdays),
  10883. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  10884. monthRe = formatRe(locale_months),
  10885. monthLookup = formatLookup(locale_months),
  10886. shortMonthRe = formatRe(locale_shortMonths),
  10887. shortMonthLookup = formatLookup(locale_shortMonths);
  10888. var formats = {
  10889. "a": formatShortWeekday,
  10890. "A": formatWeekday,
  10891. "b": formatShortMonth,
  10892. "B": formatMonth,
  10893. "c": null,
  10894. "d": formatDayOfMonth,
  10895. "e": formatDayOfMonth,
  10896. "f": formatMicroseconds,
  10897. "H": formatHour24,
  10898. "I": formatHour12,
  10899. "j": formatDayOfYear,
  10900. "L": formatMilliseconds,
  10901. "m": formatMonthNumber,
  10902. "M": formatMinutes,
  10903. "p": formatPeriod,
  10904. "Q": formatUnixTimestamp,
  10905. "s": formatUnixTimestampSeconds,
  10906. "S": formatSeconds,
  10907. "u": formatWeekdayNumberMonday,
  10908. "U": formatWeekNumberSunday,
  10909. "V": formatWeekNumberISO,
  10910. "w": formatWeekdayNumberSunday,
  10911. "W": formatWeekNumberMonday,
  10912. "x": null,
  10913. "X": null,
  10914. "y": formatYear,
  10915. "Y": formatFullYear,
  10916. "Z": formatZone,
  10917. "%": formatLiteralPercent
  10918. };
  10919. var utcFormats = {
  10920. "a": formatUTCShortWeekday,
  10921. "A": formatUTCWeekday,
  10922. "b": formatUTCShortMonth,
  10923. "B": formatUTCMonth,
  10924. "c": null,
  10925. "d": formatUTCDayOfMonth,
  10926. "e": formatUTCDayOfMonth,
  10927. "f": formatUTCMicroseconds,
  10928. "H": formatUTCHour24,
  10929. "I": formatUTCHour12,
  10930. "j": formatUTCDayOfYear,
  10931. "L": formatUTCMilliseconds,
  10932. "m": formatUTCMonthNumber,
  10933. "M": formatUTCMinutes,
  10934. "p": formatUTCPeriod,
  10935. "Q": formatUnixTimestamp,
  10936. "s": formatUnixTimestampSeconds,
  10937. "S": formatUTCSeconds,
  10938. "u": formatUTCWeekdayNumberMonday,
  10939. "U": formatUTCWeekNumberSunday,
  10940. "V": formatUTCWeekNumberISO,
  10941. "w": formatUTCWeekdayNumberSunday,
  10942. "W": formatUTCWeekNumberMonday,
  10943. "x": null,
  10944. "X": null,
  10945. "y": formatUTCYear,
  10946. "Y": formatUTCFullYear,
  10947. "Z": formatUTCZone,
  10948. "%": formatLiteralPercent
  10949. };
  10950. var parses = {
  10951. "a": parseShortWeekday,
  10952. "A": parseWeekday,
  10953. "b": parseShortMonth,
  10954. "B": parseMonth,
  10955. "c": parseLocaleDateTime,
  10956. "d": parseDayOfMonth,
  10957. "e": parseDayOfMonth,
  10958. "f": parseMicroseconds,
  10959. "H": parseHour24,
  10960. "I": parseHour24,
  10961. "j": parseDayOfYear,
  10962. "L": parseMilliseconds,
  10963. "m": parseMonthNumber,
  10964. "M": parseMinutes,
  10965. "p": parsePeriod,
  10966. "Q": parseUnixTimestamp,
  10967. "s": parseUnixTimestampSeconds,
  10968. "S": parseSeconds,
  10969. "u": parseWeekdayNumberMonday,
  10970. "U": parseWeekNumberSunday,
  10971. "V": parseWeekNumberISO,
  10972. "w": parseWeekdayNumberSunday,
  10973. "W": parseWeekNumberMonday,
  10974. "x": parseLocaleDate,
  10975. "X": parseLocaleTime,
  10976. "y": parseYear,
  10977. "Y": parseFullYear,
  10978. "Z": parseZone,
  10979. "%": parseLiteralPercent
  10980. };
  10981. // These recursive directive definitions must be deferred.
  10982. formats.x = newFormat(locale_date, formats);
  10983. formats.X = newFormat(locale_time, formats);
  10984. formats.c = newFormat(locale_dateTime, formats);
  10985. utcFormats.x = newFormat(locale_date, utcFormats);
  10986. utcFormats.X = newFormat(locale_time, utcFormats);
  10987. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  10988. function newFormat(specifier, formats) {
  10989. return function(date) {
  10990. var string = [],
  10991. i = -1,
  10992. j = 0,
  10993. n = specifier.length,
  10994. c,
  10995. pad,
  10996. format;
  10997. if (!(date instanceof Date)) date = new Date(+date);
  10998. while (++i < n) {
  10999. if (specifier.charCodeAt(i) === 37) {
  11000. string.push(specifier.slice(j, i));
  11001. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  11002. else pad = c === "e" ? " " : "0";
  11003. if (format = formats[c]) c = format(date, pad);
  11004. string.push(c);
  11005. j = i + 1;
  11006. }
  11007. }
  11008. string.push(specifier.slice(j, i));
  11009. return string.join("");
  11010. };
  11011. }
  11012. function newParse(specifier, newDate) {
  11013. return function(string) {
  11014. var d = newYear(1900),
  11015. i = parseSpecifier(d, specifier, string += "", 0),
  11016. week, day$$1;
  11017. if (i != string.length) return null;
  11018. // If a UNIX timestamp is specified, return it.
  11019. if ("Q" in d) return new Date(d.Q);
  11020. // The am-pm flag is 0 for AM, and 1 for PM.
  11021. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  11022. // Convert day-of-week and week-of-year to day-of-year.
  11023. if ("V" in d) {
  11024. if (d.V < 1 || d.V > 53) return null;
  11025. if (!("w" in d)) d.w = 1;
  11026. if ("Z" in d) {
  11027. week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
  11028. week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  11029. week = utcDay.offset(week, (d.V - 1) * 7);
  11030. d.y = week.getUTCFullYear();
  11031. d.m = week.getUTCMonth();
  11032. d.d = week.getUTCDate() + (d.w + 6) % 7;
  11033. } else {
  11034. week = newDate(newYear(d.y)), day$$1 = week.getDay();
  11035. week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
  11036. week = day.offset(week, (d.V - 1) * 7);
  11037. d.y = week.getFullYear();
  11038. d.m = week.getMonth();
  11039. d.d = week.getDate() + (d.w + 6) % 7;
  11040. }
  11041. } else if ("W" in d || "U" in d) {
  11042. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  11043. day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  11044. d.m = 0;
  11045. 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;
  11046. }
  11047. // If a time zone is specified, all fields are interpreted as UTC and then
  11048. // offset according to the specified time zone.
  11049. if ("Z" in d) {
  11050. d.H += d.Z / 100 | 0;
  11051. d.M += d.Z % 100;
  11052. return utcDate(d);
  11053. }
  11054. // Otherwise, all fields are in local time.
  11055. return newDate(d);
  11056. };
  11057. }
  11058. function parseSpecifier(d, specifier, string, j) {
  11059. var i = 0,
  11060. n = specifier.length,
  11061. m = string.length,
  11062. c,
  11063. parse;
  11064. while (i < n) {
  11065. if (j >= m) return -1;
  11066. c = specifier.charCodeAt(i++);
  11067. if (c === 37) {
  11068. c = specifier.charAt(i++);
  11069. parse = parses[c in pads ? specifier.charAt(i++) : c];
  11070. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  11071. } else if (c != string.charCodeAt(j++)) {
  11072. return -1;
  11073. }
  11074. }
  11075. return j;
  11076. }
  11077. function parsePeriod(d, string, i) {
  11078. var n = periodRe.exec(string.slice(i));
  11079. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11080. }
  11081. function parseShortWeekday(d, string, i) {
  11082. var n = shortWeekdayRe.exec(string.slice(i));
  11083. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11084. }
  11085. function parseWeekday(d, string, i) {
  11086. var n = weekdayRe.exec(string.slice(i));
  11087. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11088. }
  11089. function parseShortMonth(d, string, i) {
  11090. var n = shortMonthRe.exec(string.slice(i));
  11091. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11092. }
  11093. function parseMonth(d, string, i) {
  11094. var n = monthRe.exec(string.slice(i));
  11095. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11096. }
  11097. function parseLocaleDateTime(d, string, i) {
  11098. return parseSpecifier(d, locale_dateTime, string, i);
  11099. }
  11100. function parseLocaleDate(d, string, i) {
  11101. return parseSpecifier(d, locale_date, string, i);
  11102. }
  11103. function parseLocaleTime(d, string, i) {
  11104. return parseSpecifier(d, locale_time, string, i);
  11105. }
  11106. function formatShortWeekday(d) {
  11107. return locale_shortWeekdays[d.getDay()];
  11108. }
  11109. function formatWeekday(d) {
  11110. return locale_weekdays[d.getDay()];
  11111. }
  11112. function formatShortMonth(d) {
  11113. return locale_shortMonths[d.getMonth()];
  11114. }
  11115. function formatMonth(d) {
  11116. return locale_months[d.getMonth()];
  11117. }
  11118. function formatPeriod(d) {
  11119. return locale_periods[+(d.getHours() >= 12)];
  11120. }
  11121. function formatUTCShortWeekday(d) {
  11122. return locale_shortWeekdays[d.getUTCDay()];
  11123. }
  11124. function formatUTCWeekday(d) {
  11125. return locale_weekdays[d.getUTCDay()];
  11126. }
  11127. function formatUTCShortMonth(d) {
  11128. return locale_shortMonths[d.getUTCMonth()];
  11129. }
  11130. function formatUTCMonth(d) {
  11131. return locale_months[d.getUTCMonth()];
  11132. }
  11133. function formatUTCPeriod(d) {
  11134. return locale_periods[+(d.getUTCHours() >= 12)];
  11135. }
  11136. return {
  11137. format: function(specifier) {
  11138. var f = newFormat(specifier += "", formats);
  11139. f.toString = function() { return specifier; };
  11140. return f;
  11141. },
  11142. parse: function(specifier) {
  11143. var p = newParse(specifier += "", localDate);
  11144. p.toString = function() { return specifier; };
  11145. return p;
  11146. },
  11147. utcFormat: function(specifier) {
  11148. var f = newFormat(specifier += "", utcFormats);
  11149. f.toString = function() { return specifier; };
  11150. return f;
  11151. },
  11152. utcParse: function(specifier) {
  11153. var p = newParse(specifier, utcDate);
  11154. p.toString = function() { return specifier; };
  11155. return p;
  11156. }
  11157. };
  11158. }
  11159. var pads = {"-": "", "_": " ", "0": "0"},
  11160. numberRe = /^\s*\d+/, // note: ignores next directive
  11161. percentRe = /^%/,
  11162. requoteRe = /[\\^$*+?|[\]().{}]/g;
  11163. function pad(value, fill, width) {
  11164. var sign = value < 0 ? "-" : "",
  11165. string = (sign ? -value : value) + "",
  11166. length = string.length;
  11167. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  11168. }
  11169. function requote(s) {
  11170. return s.replace(requoteRe, "\\$&");
  11171. }
  11172. function formatRe(names) {
  11173. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  11174. }
  11175. function formatLookup(names) {
  11176. var map = {}, i = -1, n = names.length;
  11177. while (++i < n) map[names[i].toLowerCase()] = i;
  11178. return map;
  11179. }
  11180. function parseWeekdayNumberSunday(d, string, i) {
  11181. var n = numberRe.exec(string.slice(i, i + 1));
  11182. return n ? (d.w = +n[0], i + n[0].length) : -1;
  11183. }
  11184. function parseWeekdayNumberMonday(d, string, i) {
  11185. var n = numberRe.exec(string.slice(i, i + 1));
  11186. return n ? (d.u = +n[0], i + n[0].length) : -1;
  11187. }
  11188. function parseWeekNumberSunday(d, string, i) {
  11189. var n = numberRe.exec(string.slice(i, i + 2));
  11190. return n ? (d.U = +n[0], i + n[0].length) : -1;
  11191. }
  11192. function parseWeekNumberISO(d, string, i) {
  11193. var n = numberRe.exec(string.slice(i, i + 2));
  11194. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11195. }
  11196. function parseWeekNumberMonday(d, string, i) {
  11197. var n = numberRe.exec(string.slice(i, i + 2));
  11198. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11199. }
  11200. function parseFullYear(d, string, i) {
  11201. var n = numberRe.exec(string.slice(i, i + 4));
  11202. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11203. }
  11204. function parseYear(d, string, i) {
  11205. var n = numberRe.exec(string.slice(i, i + 2));
  11206. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11207. }
  11208. function parseZone(d, string, i) {
  11209. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11210. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11211. }
  11212. function parseMonthNumber(d, string, i) {
  11213. var n = numberRe.exec(string.slice(i, i + 2));
  11214. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11215. }
  11216. function parseDayOfMonth(d, string, i) {
  11217. var n = numberRe.exec(string.slice(i, i + 2));
  11218. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11219. }
  11220. function parseDayOfYear(d, string, i) {
  11221. var n = numberRe.exec(string.slice(i, i + 3));
  11222. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11223. }
  11224. function parseHour24(d, string, i) {
  11225. var n = numberRe.exec(string.slice(i, i + 2));
  11226. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11227. }
  11228. function parseMinutes(d, string, i) {
  11229. var n = numberRe.exec(string.slice(i, i + 2));
  11230. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11231. }
  11232. function parseSeconds(d, string, i) {
  11233. var n = numberRe.exec(string.slice(i, i + 2));
  11234. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11235. }
  11236. function parseMilliseconds(d, string, i) {
  11237. var n = numberRe.exec(string.slice(i, i + 3));
  11238. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11239. }
  11240. function parseMicroseconds(d, string, i) {
  11241. var n = numberRe.exec(string.slice(i, i + 6));
  11242. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11243. }
  11244. function parseLiteralPercent(d, string, i) {
  11245. var n = percentRe.exec(string.slice(i, i + 1));
  11246. return n ? i + n[0].length : -1;
  11247. }
  11248. function parseUnixTimestamp(d, string, i) {
  11249. var n = numberRe.exec(string.slice(i));
  11250. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11251. }
  11252. function parseUnixTimestampSeconds(d, string, i) {
  11253. var n = numberRe.exec(string.slice(i));
  11254. return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
  11255. }
  11256. function formatDayOfMonth(d, p) {
  11257. return pad(d.getDate(), p, 2);
  11258. }
  11259. function formatHour24(d, p) {
  11260. return pad(d.getHours(), p, 2);
  11261. }
  11262. function formatHour12(d, p) {
  11263. return pad(d.getHours() % 12 || 12, p, 2);
  11264. }
  11265. function formatDayOfYear(d, p) {
  11266. return pad(1 + day.count(year(d), d), p, 3);
  11267. }
  11268. function formatMilliseconds(d, p) {
  11269. return pad(d.getMilliseconds(), p, 3);
  11270. }
  11271. function formatMicroseconds(d, p) {
  11272. return formatMilliseconds(d, p) + "000";
  11273. }
  11274. function formatMonthNumber(d, p) {
  11275. return pad(d.getMonth() + 1, p, 2);
  11276. }
  11277. function formatMinutes(d, p) {
  11278. return pad(d.getMinutes(), p, 2);
  11279. }
  11280. function formatSeconds(d, p) {
  11281. return pad(d.getSeconds(), p, 2);
  11282. }
  11283. function formatWeekdayNumberMonday(d) {
  11284. var day$$1 = d.getDay();
  11285. return day$$1 === 0 ? 7 : day$$1;
  11286. }
  11287. function formatWeekNumberSunday(d, p) {
  11288. return pad(sunday.count(year(d), d), p, 2);
  11289. }
  11290. function formatWeekNumberISO(d, p) {
  11291. var day$$1 = d.getDay();
  11292. d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
  11293. return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11294. }
  11295. function formatWeekdayNumberSunday(d) {
  11296. return d.getDay();
  11297. }
  11298. function formatWeekNumberMonday(d, p) {
  11299. return pad(monday.count(year(d), d), p, 2);
  11300. }
  11301. function formatYear(d, p) {
  11302. return pad(d.getFullYear() % 100, p, 2);
  11303. }
  11304. function formatFullYear(d, p) {
  11305. return pad(d.getFullYear() % 10000, p, 4);
  11306. }
  11307. function formatZone(d) {
  11308. var z = d.getTimezoneOffset();
  11309. return (z > 0 ? "-" : (z *= -1, "+"))
  11310. + pad(z / 60 | 0, "0", 2)
  11311. + pad(z % 60, "0", 2);
  11312. }
  11313. function formatUTCDayOfMonth(d, p) {
  11314. return pad(d.getUTCDate(), p, 2);
  11315. }
  11316. function formatUTCHour24(d, p) {
  11317. return pad(d.getUTCHours(), p, 2);
  11318. }
  11319. function formatUTCHour12(d, p) {
  11320. return pad(d.getUTCHours() % 12 || 12, p, 2);
  11321. }
  11322. function formatUTCDayOfYear(d, p) {
  11323. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  11324. }
  11325. function formatUTCMilliseconds(d, p) {
  11326. return pad(d.getUTCMilliseconds(), p, 3);
  11327. }
  11328. function formatUTCMicroseconds(d, p) {
  11329. return formatUTCMilliseconds(d, p) + "000";
  11330. }
  11331. function formatUTCMonthNumber(d, p) {
  11332. return pad(d.getUTCMonth() + 1, p, 2);
  11333. }
  11334. function formatUTCMinutes(d, p) {
  11335. return pad(d.getUTCMinutes(), p, 2);
  11336. }
  11337. function formatUTCSeconds(d, p) {
  11338. return pad(d.getUTCSeconds(), p, 2);
  11339. }
  11340. function formatUTCWeekdayNumberMonday(d) {
  11341. var dow = d.getUTCDay();
  11342. return dow === 0 ? 7 : dow;
  11343. }
  11344. function formatUTCWeekNumberSunday(d, p) {
  11345. return pad(utcSunday.count(utcYear(d), d), p, 2);
  11346. }
  11347. function formatUTCWeekNumberISO(d, p) {
  11348. var day$$1 = d.getUTCDay();
  11349. d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11350. return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11351. }
  11352. function formatUTCWeekdayNumberSunday(d) {
  11353. return d.getUTCDay();
  11354. }
  11355. function formatUTCWeekNumberMonday(d, p) {
  11356. return pad(utcMonday.count(utcYear(d), d), p, 2);
  11357. }
  11358. function formatUTCYear(d, p) {
  11359. return pad(d.getUTCFullYear() % 100, p, 2);
  11360. }
  11361. function formatUTCFullYear(d, p) {
  11362. return pad(d.getUTCFullYear() % 10000, p, 4);
  11363. }
  11364. function formatUTCZone() {
  11365. return "+0000";
  11366. }
  11367. function formatLiteralPercent() {
  11368. return "%";
  11369. }
  11370. function formatUnixTimestamp(d) {
  11371. return +d;
  11372. }
  11373. function formatUnixTimestampSeconds(d) {
  11374. return Math.floor(+d / 1000);
  11375. }
  11376. var locale$1;
  11377. defaultLocale$1({
  11378. dateTime: "%x, %X",
  11379. date: "%-m/%-d/%Y",
  11380. time: "%-I:%M:%S %p",
  11381. periods: ["AM", "PM"],
  11382. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11383. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11384. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11385. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11386. });
  11387. function defaultLocale$1(definition) {
  11388. locale$1 = formatLocale$1(definition);
  11389. exports.timeFormat = locale$1.format;
  11390. exports.timeParse = locale$1.parse;
  11391. exports.utcFormat = locale$1.utcFormat;
  11392. exports.utcParse = locale$1.utcParse;
  11393. return locale$1;
  11394. }
  11395. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11396. function formatIsoNative(date) {
  11397. return date.toISOString();
  11398. }
  11399. var formatIso = Date.prototype.toISOString
  11400. ? formatIsoNative
  11401. : exports.utcFormat(isoSpecifier);
  11402. function parseIsoNative(string) {
  11403. var date = new Date(string);
  11404. return isNaN(date) ? null : date;
  11405. }
  11406. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11407. ? parseIsoNative
  11408. : exports.utcParse(isoSpecifier);
  11409. var durationSecond$1 = 1000,
  11410. durationMinute$1 = durationSecond$1 * 60,
  11411. durationHour$1 = durationMinute$1 * 60,
  11412. durationDay$1 = durationHour$1 * 24,
  11413. durationWeek$1 = durationDay$1 * 7,
  11414. durationMonth = durationDay$1 * 30,
  11415. durationYear = durationDay$1 * 365;
  11416. function date$1(t) {
  11417. return new Date(t);
  11418. }
  11419. function number$3(t) {
  11420. return t instanceof Date ? +t : +new Date(+t);
  11421. }
  11422. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  11423. var scale = continuous(deinterpolateLinear, interpolateNumber),
  11424. invert = scale.invert,
  11425. domain = scale.domain;
  11426. var formatMillisecond = format(".%L"),
  11427. formatSecond = format(":%S"),
  11428. formatMinute = format("%I:%M"),
  11429. formatHour = format("%I %p"),
  11430. formatDay = format("%a %d"),
  11431. formatWeek = format("%b %d"),
  11432. formatMonth = format("%B"),
  11433. formatYear = format("%Y");
  11434. var tickIntervals = [
  11435. [second$$1, 1, durationSecond$1],
  11436. [second$$1, 5, 5 * durationSecond$1],
  11437. [second$$1, 15, 15 * durationSecond$1],
  11438. [second$$1, 30, 30 * durationSecond$1],
  11439. [minute$$1, 1, durationMinute$1],
  11440. [minute$$1, 5, 5 * durationMinute$1],
  11441. [minute$$1, 15, 15 * durationMinute$1],
  11442. [minute$$1, 30, 30 * durationMinute$1],
  11443. [ hour$$1, 1, durationHour$1 ],
  11444. [ hour$$1, 3, 3 * durationHour$1 ],
  11445. [ hour$$1, 6, 6 * durationHour$1 ],
  11446. [ hour$$1, 12, 12 * durationHour$1 ],
  11447. [ day$$1, 1, durationDay$1 ],
  11448. [ day$$1, 2, 2 * durationDay$1 ],
  11449. [ week, 1, durationWeek$1 ],
  11450. [ month$$1, 1, durationMonth ],
  11451. [ month$$1, 3, 3 * durationMonth ],
  11452. [ year$$1, 1, durationYear ]
  11453. ];
  11454. function tickFormat(date$$1) {
  11455. return (second$$1(date$$1) < date$$1 ? formatMillisecond
  11456. : minute$$1(date$$1) < date$$1 ? formatSecond
  11457. : hour$$1(date$$1) < date$$1 ? formatMinute
  11458. : day$$1(date$$1) < date$$1 ? formatHour
  11459. : month$$1(date$$1) < date$$1 ? (week(date$$1) < date$$1 ? formatDay : formatWeek)
  11460. : year$$1(date$$1) < date$$1 ? formatMonth
  11461. : formatYear)(date$$1);
  11462. }
  11463. function tickInterval(interval, start, stop, step) {
  11464. if (interval == null) interval = 10;
  11465. // If a desired tick count is specified, pick a reasonable tick interval
  11466. // based on the extent of the domain and a rough estimate of tick size.
  11467. // Otherwise, assume interval is already a time interval and use it.
  11468. if (typeof interval === "number") {
  11469. var target = Math.abs(stop - start) / interval,
  11470. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11471. if (i === tickIntervals.length) {
  11472. step = tickStep(start / durationYear, stop / durationYear, interval);
  11473. interval = year$$1;
  11474. } else if (i) {
  11475. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11476. step = i[1];
  11477. interval = i[0];
  11478. } else {
  11479. step = Math.max(tickStep(start, stop, interval), 1);
  11480. interval = millisecond$$1;
  11481. }
  11482. }
  11483. return step == null ? interval : interval.every(step);
  11484. }
  11485. scale.invert = function(y) {
  11486. return new Date(invert(y));
  11487. };
  11488. scale.domain = function(_) {
  11489. return arguments.length ? domain(map$2.call(_, number$3)) : domain().map(date$1);
  11490. };
  11491. scale.ticks = function(interval, step) {
  11492. var d = domain(),
  11493. t0 = d[0],
  11494. t1 = d[d.length - 1],
  11495. r = t1 < t0,
  11496. t;
  11497. if (r) t = t0, t0 = t1, t1 = t;
  11498. t = tickInterval(interval, t0, t1, step);
  11499. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11500. return r ? t.reverse() : t;
  11501. };
  11502. scale.tickFormat = function(count, specifier) {
  11503. return specifier == null ? tickFormat : format(specifier);
  11504. };
  11505. scale.nice = function(interval, step) {
  11506. var d = domain();
  11507. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11508. ? domain(nice(d, interval))
  11509. : scale;
  11510. };
  11511. scale.copy = function() {
  11512. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  11513. };
  11514. return scale;
  11515. }
  11516. function time() {
  11517. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  11518. }
  11519. function utcTime() {
  11520. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  11521. }
  11522. function sequential(interpolator) {
  11523. var x0 = 0,
  11524. x1 = 1,
  11525. k10 = 1,
  11526. clamp = false;
  11527. function scale(x) {
  11528. var t = (x - x0) * k10;
  11529. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11530. }
  11531. scale.domain = function(_) {
  11532. return arguments.length ? (x0 = +_[0], x1 = +_[1], k10 = x0 === x1 ? 0 : 1 / (x1 - x0), scale) : [x0, x1];
  11533. };
  11534. scale.clamp = function(_) {
  11535. return arguments.length ? (clamp = !!_, scale) : clamp;
  11536. };
  11537. scale.interpolator = function(_) {
  11538. return arguments.length ? (interpolator = _, scale) : interpolator;
  11539. };
  11540. scale.copy = function() {
  11541. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  11542. };
  11543. return linearish(scale);
  11544. }
  11545. function diverging(interpolator) {
  11546. var x0 = 0,
  11547. x1 = 0.5,
  11548. x2 = 1,
  11549. k10 = 1,
  11550. k21 = 1,
  11551. clamp = false;
  11552. function scale(x) {
  11553. var t = 0.5 + ((x = +x) - x1) * (x < x1 ? k10 : k21);
  11554. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11555. }
  11556. scale.domain = function(_) {
  11557. return arguments.length ? (x0 = +_[0], x1 = +_[1], x2 = +_[2], k10 = x0 === x1 ? 0 : 0.5 / (x1 - x0), k21 = x1 === x2 ? 0 : 0.5 / (x2 - x1), scale) : [x0, x1, x2];
  11558. };
  11559. scale.clamp = function(_) {
  11560. return arguments.length ? (clamp = !!_, scale) : clamp;
  11561. };
  11562. scale.interpolator = function(_) {
  11563. return arguments.length ? (interpolator = _, scale) : interpolator;
  11564. };
  11565. scale.copy = function() {
  11566. return diverging(interpolator).domain([x0, x1, x2]).clamp(clamp);
  11567. };
  11568. return linearish(scale);
  11569. }
  11570. function colors(specifier) {
  11571. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  11572. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  11573. return colors;
  11574. }
  11575. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11576. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  11577. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  11578. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  11579. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  11580. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  11581. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  11582. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  11583. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  11584. function ramp(scheme) {
  11585. return rgbBasis(scheme[scheme.length - 1]);
  11586. }
  11587. var scheme = new Array(3).concat(
  11588. "d8b365f5f5f55ab4ac",
  11589. "a6611adfc27d80cdc1018571",
  11590. "a6611adfc27df5f5f580cdc1018571",
  11591. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  11592. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  11593. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  11594. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  11595. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  11596. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  11597. ).map(colors);
  11598. var BrBG = ramp(scheme);
  11599. var scheme$1 = new Array(3).concat(
  11600. "af8dc3f7f7f77fbf7b",
  11601. "7b3294c2a5cfa6dba0008837",
  11602. "7b3294c2a5cff7f7f7a6dba0008837",
  11603. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  11604. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  11605. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  11606. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  11607. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  11608. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  11609. ).map(colors);
  11610. var PRGn = ramp(scheme$1);
  11611. var scheme$2 = new Array(3).concat(
  11612. "e9a3c9f7f7f7a1d76a",
  11613. "d01c8bf1b6dab8e1864dac26",
  11614. "d01c8bf1b6daf7f7f7b8e1864dac26",
  11615. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  11616. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  11617. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  11618. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  11619. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  11620. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  11621. ).map(colors);
  11622. var PiYG = ramp(scheme$2);
  11623. var scheme$3 = new Array(3).concat(
  11624. "998ec3f7f7f7f1a340",
  11625. "5e3c99b2abd2fdb863e66101",
  11626. "5e3c99b2abd2f7f7f7fdb863e66101",
  11627. "542788998ec3d8daebfee0b6f1a340b35806",
  11628. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  11629. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  11630. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  11631. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  11632. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  11633. ).map(colors);
  11634. var PuOr = ramp(scheme$3);
  11635. var scheme$4 = new Array(3).concat(
  11636. "ef8a62f7f7f767a9cf",
  11637. "ca0020f4a58292c5de0571b0",
  11638. "ca0020f4a582f7f7f792c5de0571b0",
  11639. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  11640. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  11641. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  11642. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  11643. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  11644. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  11645. ).map(colors);
  11646. var RdBu = ramp(scheme$4);
  11647. var scheme$5 = new Array(3).concat(
  11648. "ef8a62ffffff999999",
  11649. "ca0020f4a582bababa404040",
  11650. "ca0020f4a582ffffffbababa404040",
  11651. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  11652. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  11653. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  11654. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  11655. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  11656. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  11657. ).map(colors);
  11658. var RdGy = ramp(scheme$5);
  11659. var scheme$6 = new Array(3).concat(
  11660. "fc8d59ffffbf91bfdb",
  11661. "d7191cfdae61abd9e92c7bb6",
  11662. "d7191cfdae61ffffbfabd9e92c7bb6",
  11663. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  11664. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  11665. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  11666. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  11667. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  11668. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  11669. ).map(colors);
  11670. var RdYlBu = ramp(scheme$6);
  11671. var scheme$7 = new Array(3).concat(
  11672. "fc8d59ffffbf91cf60",
  11673. "d7191cfdae61a6d96a1a9641",
  11674. "d7191cfdae61ffffbfa6d96a1a9641",
  11675. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  11676. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  11677. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  11678. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  11679. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  11680. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  11681. ).map(colors);
  11682. var RdYlGn = ramp(scheme$7);
  11683. var scheme$8 = new Array(3).concat(
  11684. "fc8d59ffffbf99d594",
  11685. "d7191cfdae61abdda42b83ba",
  11686. "d7191cfdae61ffffbfabdda42b83ba",
  11687. "d53e4ffc8d59fee08be6f59899d5943288bd",
  11688. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  11689. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  11690. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  11691. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  11692. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  11693. ).map(colors);
  11694. var Spectral = ramp(scheme$8);
  11695. var scheme$9 = new Array(3).concat(
  11696. "e5f5f999d8c92ca25f",
  11697. "edf8fbb2e2e266c2a4238b45",
  11698. "edf8fbb2e2e266c2a42ca25f006d2c",
  11699. "edf8fbccece699d8c966c2a42ca25f006d2c",
  11700. "edf8fbccece699d8c966c2a441ae76238b45005824",
  11701. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  11702. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  11703. ).map(colors);
  11704. var BuGn = ramp(scheme$9);
  11705. var scheme$a = new Array(3).concat(
  11706. "e0ecf49ebcda8856a7",
  11707. "edf8fbb3cde38c96c688419d",
  11708. "edf8fbb3cde38c96c68856a7810f7c",
  11709. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  11710. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  11711. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  11712. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  11713. ).map(colors);
  11714. var BuPu = ramp(scheme$a);
  11715. var scheme$b = new Array(3).concat(
  11716. "e0f3dba8ddb543a2ca",
  11717. "f0f9e8bae4bc7bccc42b8cbe",
  11718. "f0f9e8bae4bc7bccc443a2ca0868ac",
  11719. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  11720. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11721. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11722. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  11723. ).map(colors);
  11724. var GnBu = ramp(scheme$b);
  11725. var scheme$c = new Array(3).concat(
  11726. "fee8c8fdbb84e34a33",
  11727. "fef0d9fdcc8afc8d59d7301f",
  11728. "fef0d9fdcc8afc8d59e34a33b30000",
  11729. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  11730. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  11731. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  11732. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  11733. ).map(colors);
  11734. var OrRd = ramp(scheme$c);
  11735. var scheme$d = new Array(3).concat(
  11736. "ece2f0a6bddb1c9099",
  11737. "f6eff7bdc9e167a9cf02818a",
  11738. "f6eff7bdc9e167a9cf1c9099016c59",
  11739. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  11740. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  11741. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  11742. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  11743. ).map(colors);
  11744. var PuBuGn = ramp(scheme$d);
  11745. var scheme$e = new Array(3).concat(
  11746. "ece7f2a6bddb2b8cbe",
  11747. "f1eef6bdc9e174a9cf0570b0",
  11748. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  11749. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  11750. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11751. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11752. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  11753. ).map(colors);
  11754. var PuBu = ramp(scheme$e);
  11755. var scheme$f = new Array(3).concat(
  11756. "e7e1efc994c7dd1c77",
  11757. "f1eef6d7b5d8df65b0ce1256",
  11758. "f1eef6d7b5d8df65b0dd1c77980043",
  11759. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  11760. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  11761. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  11762. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  11763. ).map(colors);
  11764. var PuRd = ramp(scheme$f);
  11765. var scheme$g = new Array(3).concat(
  11766. "fde0ddfa9fb5c51b8a",
  11767. "feebe2fbb4b9f768a1ae017e",
  11768. "feebe2fbb4b9f768a1c51b8a7a0177",
  11769. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  11770. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11771. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11772. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  11773. ).map(colors);
  11774. var RdPu = ramp(scheme$g);
  11775. var scheme$h = new Array(3).concat(
  11776. "edf8b17fcdbb2c7fb8",
  11777. "ffffcca1dab441b6c4225ea8",
  11778. "ffffcca1dab441b6c42c7fb8253494",
  11779. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  11780. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11781. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11782. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  11783. ).map(colors);
  11784. var YlGnBu = ramp(scheme$h);
  11785. var scheme$i = new Array(3).concat(
  11786. "f7fcb9addd8e31a354",
  11787. "ffffccc2e69978c679238443",
  11788. "ffffccc2e69978c67931a354006837",
  11789. "ffffccd9f0a3addd8e78c67931a354006837",
  11790. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  11791. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  11792. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  11793. ).map(colors);
  11794. var YlGn = ramp(scheme$i);
  11795. var scheme$j = new Array(3).concat(
  11796. "fff7bcfec44fd95f0e",
  11797. "ffffd4fed98efe9929cc4c02",
  11798. "ffffd4fed98efe9929d95f0e993404",
  11799. "ffffd4fee391fec44ffe9929d95f0e993404",
  11800. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  11801. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  11802. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  11803. ).map(colors);
  11804. var YlOrBr = ramp(scheme$j);
  11805. var scheme$k = new Array(3).concat(
  11806. "ffeda0feb24cf03b20",
  11807. "ffffb2fecc5cfd8d3ce31a1c",
  11808. "ffffb2fecc5cfd8d3cf03b20bd0026",
  11809. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  11810. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11811. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11812. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  11813. ).map(colors);
  11814. var YlOrRd = ramp(scheme$k);
  11815. var scheme$l = new Array(3).concat(
  11816. "deebf79ecae13182bd",
  11817. "eff3ffbdd7e76baed62171b5",
  11818. "eff3ffbdd7e76baed63182bd08519c",
  11819. "eff3ffc6dbef9ecae16baed63182bd08519c",
  11820. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  11821. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  11822. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  11823. ).map(colors);
  11824. var Blues = ramp(scheme$l);
  11825. var scheme$m = new Array(3).concat(
  11826. "e5f5e0a1d99b31a354",
  11827. "edf8e9bae4b374c476238b45",
  11828. "edf8e9bae4b374c47631a354006d2c",
  11829. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  11830. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  11831. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  11832. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  11833. ).map(colors);
  11834. var Greens = ramp(scheme$m);
  11835. var scheme$n = new Array(3).concat(
  11836. "f0f0f0bdbdbd636363",
  11837. "f7f7f7cccccc969696525252",
  11838. "f7f7f7cccccc969696636363252525",
  11839. "f7f7f7d9d9d9bdbdbd969696636363252525",
  11840. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  11841. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  11842. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  11843. ).map(colors);
  11844. var Greys = ramp(scheme$n);
  11845. var scheme$o = new Array(3).concat(
  11846. "efedf5bcbddc756bb1",
  11847. "f2f0f7cbc9e29e9ac86a51a3",
  11848. "f2f0f7cbc9e29e9ac8756bb154278f",
  11849. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  11850. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11851. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11852. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  11853. ).map(colors);
  11854. var Purples = ramp(scheme$o);
  11855. var scheme$p = new Array(3).concat(
  11856. "fee0d2fc9272de2d26",
  11857. "fee5d9fcae91fb6a4acb181d",
  11858. "fee5d9fcae91fb6a4ade2d26a50f15",
  11859. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  11860. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11861. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11862. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  11863. ).map(colors);
  11864. var Reds = ramp(scheme$p);
  11865. var scheme$q = new Array(3).concat(
  11866. "fee6cefdae6be6550d",
  11867. "feeddefdbe85fd8d3cd94701",
  11868. "feeddefdbe85fd8d3ce6550da63603",
  11869. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  11870. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11871. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11872. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  11873. ).map(colors);
  11874. var Oranges = ramp(scheme$q);
  11875. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  11876. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11877. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11878. var c = cubehelix();
  11879. function rainbow(t) {
  11880. if (t < 0 || t > 1) t -= Math.floor(t);
  11881. var ts = Math.abs(t - 0.5);
  11882. c.h = 360 * t - 100;
  11883. c.s = 1.5 - 1.5 * ts;
  11884. c.l = 0.8 - 0.9 * ts;
  11885. return c + "";
  11886. }
  11887. var c$1 = rgb(),
  11888. pi_1_3 = Math.PI / 3,
  11889. pi_2_3 = Math.PI * 2 / 3;
  11890. function sinebow(t) {
  11891. var x;
  11892. t = (0.5 - t) * Math.PI;
  11893. c$1.r = 255 * (x = Math.sin(t)) * x;
  11894. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  11895. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  11896. return c$1 + "";
  11897. }
  11898. function ramp$1(range) {
  11899. var n = range.length;
  11900. return function(t) {
  11901. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  11902. };
  11903. }
  11904. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  11905. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  11906. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  11907. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  11908. function constant$b(x) {
  11909. return function constant() {
  11910. return x;
  11911. };
  11912. }
  11913. var abs$1 = Math.abs;
  11914. var atan2$1 = Math.atan2;
  11915. var cos$2 = Math.cos;
  11916. var max$2 = Math.max;
  11917. var min$1 = Math.min;
  11918. var sin$2 = Math.sin;
  11919. var sqrt$2 = Math.sqrt;
  11920. var epsilon$3 = 1e-12;
  11921. var pi$4 = Math.PI;
  11922. var halfPi$3 = pi$4 / 2;
  11923. var tau$4 = 2 * pi$4;
  11924. function acos$1(x) {
  11925. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11926. }
  11927. function asin$1(x) {
  11928. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  11929. }
  11930. function arcInnerRadius(d) {
  11931. return d.innerRadius;
  11932. }
  11933. function arcOuterRadius(d) {
  11934. return d.outerRadius;
  11935. }
  11936. function arcStartAngle(d) {
  11937. return d.startAngle;
  11938. }
  11939. function arcEndAngle(d) {
  11940. return d.endAngle;
  11941. }
  11942. function arcPadAngle(d) {
  11943. return d && d.padAngle; // Note: optional!
  11944. }
  11945. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11946. var x10 = x1 - x0, y10 = y1 - y0,
  11947. x32 = x3 - x2, y32 = y3 - y2,
  11948. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  11949. return [x0 + t * x10, y0 + t * y10];
  11950. }
  11951. // Compute perpendicular offset line of length rc.
  11952. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  11953. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  11954. var x01 = x0 - x1,
  11955. y01 = y0 - y1,
  11956. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  11957. ox = lo * y01,
  11958. oy = -lo * x01,
  11959. x11 = x0 + ox,
  11960. y11 = y0 + oy,
  11961. x10 = x1 + ox,
  11962. y10 = y1 + oy,
  11963. x00 = (x11 + x10) / 2,
  11964. y00 = (y11 + y10) / 2,
  11965. dx = x10 - x11,
  11966. dy = y10 - y11,
  11967. d2 = dx * dx + dy * dy,
  11968. r = r1 - rc,
  11969. D = x11 * y10 - x10 * y11,
  11970. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  11971. cx0 = (D * dy - dx * d) / d2,
  11972. cy0 = (-D * dx - dy * d) / d2,
  11973. cx1 = (D * dy + dx * d) / d2,
  11974. cy1 = (-D * dx + dy * d) / d2,
  11975. dx0 = cx0 - x00,
  11976. dy0 = cy0 - y00,
  11977. dx1 = cx1 - x00,
  11978. dy1 = cy1 - y00;
  11979. // Pick the closer of the two intersection points.
  11980. // TODO Is there a faster way to determine which intersection to use?
  11981. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  11982. return {
  11983. cx: cx0,
  11984. cy: cy0,
  11985. x01: -ox,
  11986. y01: -oy,
  11987. x11: cx0 * (r1 / r - 1),
  11988. y11: cy0 * (r1 / r - 1)
  11989. };
  11990. }
  11991. function arc() {
  11992. var innerRadius = arcInnerRadius,
  11993. outerRadius = arcOuterRadius,
  11994. cornerRadius = constant$b(0),
  11995. padRadius = null,
  11996. startAngle = arcStartAngle,
  11997. endAngle = arcEndAngle,
  11998. padAngle = arcPadAngle,
  11999. context = null;
  12000. function arc() {
  12001. var buffer,
  12002. r,
  12003. r0 = +innerRadius.apply(this, arguments),
  12004. r1 = +outerRadius.apply(this, arguments),
  12005. a0 = startAngle.apply(this, arguments) - halfPi$3,
  12006. a1 = endAngle.apply(this, arguments) - halfPi$3,
  12007. da = abs$1(a1 - a0),
  12008. cw = a1 > a0;
  12009. if (!context) context = buffer = path();
  12010. // Ensure that the outer radius is always larger than the inner radius.
  12011. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  12012. // Is it a point?
  12013. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  12014. // Or is it a circle or annulus?
  12015. else if (da > tau$4 - epsilon$3) {
  12016. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  12017. context.arc(0, 0, r1, a0, a1, !cw);
  12018. if (r0 > epsilon$3) {
  12019. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  12020. context.arc(0, 0, r0, a1, a0, cw);
  12021. }
  12022. }
  12023. // Or is it a circular or annular sector?
  12024. else {
  12025. var a01 = a0,
  12026. a11 = a1,
  12027. a00 = a0,
  12028. a10 = a1,
  12029. da0 = da,
  12030. da1 = da,
  12031. ap = padAngle.apply(this, arguments) / 2,
  12032. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  12033. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  12034. rc0 = rc,
  12035. rc1 = rc,
  12036. t0,
  12037. t1;
  12038. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  12039. if (rp > epsilon$3) {
  12040. var p0 = asin$1(rp / r0 * sin$2(ap)),
  12041. p1 = asin$1(rp / r1 * sin$2(ap));
  12042. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  12043. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  12044. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  12045. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  12046. }
  12047. var x01 = r1 * cos$2(a01),
  12048. y01 = r1 * sin$2(a01),
  12049. x10 = r0 * cos$2(a10),
  12050. y10 = r0 * sin$2(a10);
  12051. // Apply rounded corners?
  12052. if (rc > epsilon$3) {
  12053. var x11 = r1 * cos$2(a11),
  12054. y11 = r1 * sin$2(a11),
  12055. x00 = r0 * cos$2(a00),
  12056. y00 = r0 * sin$2(a00);
  12057. // Restrict the corner radius according to the sector angle.
  12058. if (da < pi$4) {
  12059. var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  12060. ax = x01 - oc[0],
  12061. ay = y01 - oc[1],
  12062. bx = x11 - oc[0],
  12063. by = y11 - oc[1],
  12064. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  12065. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  12066. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  12067. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  12068. }
  12069. }
  12070. // Is the sector collapsed to a line?
  12071. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  12072. // Does the sector’s outer ring have rounded corners?
  12073. else if (rc1 > epsilon$3) {
  12074. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  12075. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  12076. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12077. // Have the corners merged?
  12078. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12079. // Otherwise, draw the two corners and the ring.
  12080. else {
  12081. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12082. 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);
  12083. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12084. }
  12085. }
  12086. // Or is the outer ring just a circular arc?
  12087. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  12088. // Is there no inner ring, and it’s a circular sector?
  12089. // Or perhaps it’s an annular sector collapsed due to padding?
  12090. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  12091. // Does the sector’s inner ring (or point) have rounded corners?
  12092. else if (rc0 > epsilon$3) {
  12093. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  12094. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  12095. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12096. // Have the corners merged?
  12097. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12098. // Otherwise, draw the two corners and the ring.
  12099. else {
  12100. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12101. 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);
  12102. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12103. }
  12104. }
  12105. // Or is the inner ring just a circular arc?
  12106. else context.arc(0, 0, r0, a10, a00, cw);
  12107. }
  12108. context.closePath();
  12109. if (buffer) return context = null, buffer + "" || null;
  12110. }
  12111. arc.centroid = function() {
  12112. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  12113. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  12114. return [cos$2(a) * r, sin$2(a) * r];
  12115. };
  12116. arc.innerRadius = function(_) {
  12117. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : innerRadius;
  12118. };
  12119. arc.outerRadius = function(_) {
  12120. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : outerRadius;
  12121. };
  12122. arc.cornerRadius = function(_) {
  12123. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : cornerRadius;
  12124. };
  12125. arc.padRadius = function(_) {
  12126. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), arc) : padRadius;
  12127. };
  12128. arc.startAngle = function(_) {
  12129. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : startAngle;
  12130. };
  12131. arc.endAngle = function(_) {
  12132. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : endAngle;
  12133. };
  12134. arc.padAngle = function(_) {
  12135. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : padAngle;
  12136. };
  12137. arc.context = function(_) {
  12138. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  12139. };
  12140. return arc;
  12141. }
  12142. function Linear(context) {
  12143. this._context = context;
  12144. }
  12145. Linear.prototype = {
  12146. areaStart: function() {
  12147. this._line = 0;
  12148. },
  12149. areaEnd: function() {
  12150. this._line = NaN;
  12151. },
  12152. lineStart: function() {
  12153. this._point = 0;
  12154. },
  12155. lineEnd: function() {
  12156. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12157. this._line = 1 - this._line;
  12158. },
  12159. point: function(x, y) {
  12160. x = +x, y = +y;
  12161. switch (this._point) {
  12162. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12163. case 1: this._point = 2; // proceed
  12164. default: this._context.lineTo(x, y); break;
  12165. }
  12166. }
  12167. };
  12168. function curveLinear(context) {
  12169. return new Linear(context);
  12170. }
  12171. function x$3(p) {
  12172. return p[0];
  12173. }
  12174. function y$3(p) {
  12175. return p[1];
  12176. }
  12177. function line() {
  12178. var x$$1 = x$3,
  12179. y$$1 = y$3,
  12180. defined = constant$b(true),
  12181. context = null,
  12182. curve = curveLinear,
  12183. output = null;
  12184. function line(data) {
  12185. var i,
  12186. n = data.length,
  12187. d,
  12188. defined0 = false,
  12189. buffer;
  12190. if (context == null) output = curve(buffer = path());
  12191. for (i = 0; i <= n; ++i) {
  12192. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12193. if (defined0 = !defined0) output.lineStart();
  12194. else output.lineEnd();
  12195. }
  12196. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  12197. }
  12198. if (buffer) return output = null, buffer + "" || null;
  12199. }
  12200. line.x = function(_) {
  12201. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$b(+_), line) : x$$1;
  12202. };
  12203. line.y = function(_) {
  12204. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$b(+_), line) : y$$1;
  12205. };
  12206. line.defined = function(_) {
  12207. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), line) : defined;
  12208. };
  12209. line.curve = function(_) {
  12210. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  12211. };
  12212. line.context = function(_) {
  12213. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  12214. };
  12215. return line;
  12216. }
  12217. function area$3() {
  12218. var x0 = x$3,
  12219. x1 = null,
  12220. y0 = constant$b(0),
  12221. y1 = y$3,
  12222. defined = constant$b(true),
  12223. context = null,
  12224. curve = curveLinear,
  12225. output = null;
  12226. function area(data) {
  12227. var i,
  12228. j,
  12229. k,
  12230. n = data.length,
  12231. d,
  12232. defined0 = false,
  12233. buffer,
  12234. x0z = new Array(n),
  12235. y0z = new Array(n);
  12236. if (context == null) output = curve(buffer = path());
  12237. for (i = 0; i <= n; ++i) {
  12238. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12239. if (defined0 = !defined0) {
  12240. j = i;
  12241. output.areaStart();
  12242. output.lineStart();
  12243. } else {
  12244. output.lineEnd();
  12245. output.lineStart();
  12246. for (k = i - 1; k >= j; --k) {
  12247. output.point(x0z[k], y0z[k]);
  12248. }
  12249. output.lineEnd();
  12250. output.areaEnd();
  12251. }
  12252. }
  12253. if (defined0) {
  12254. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  12255. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  12256. }
  12257. }
  12258. if (buffer) return output = null, buffer + "" || null;
  12259. }
  12260. function arealine() {
  12261. return line().defined(defined).curve(curve).context(context);
  12262. }
  12263. area.x = function(_) {
  12264. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), x1 = null, area) : x0;
  12265. };
  12266. area.x0 = function(_) {
  12267. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), area) : x0;
  12268. };
  12269. area.x1 = function(_) {
  12270. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : x1;
  12271. };
  12272. area.y = function(_) {
  12273. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), y1 = null, area) : y0;
  12274. };
  12275. area.y0 = function(_) {
  12276. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), area) : y0;
  12277. };
  12278. area.y1 = function(_) {
  12279. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : y1;
  12280. };
  12281. area.lineX0 =
  12282. area.lineY0 = function() {
  12283. return arealine().x(x0).y(y0);
  12284. };
  12285. area.lineY1 = function() {
  12286. return arealine().x(x0).y(y1);
  12287. };
  12288. area.lineX1 = function() {
  12289. return arealine().x(x1).y(y0);
  12290. };
  12291. area.defined = function(_) {
  12292. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), area) : defined;
  12293. };
  12294. area.curve = function(_) {
  12295. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  12296. };
  12297. area.context = function(_) {
  12298. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  12299. };
  12300. return area;
  12301. }
  12302. function descending$1(a, b) {
  12303. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  12304. }
  12305. function identity$7(d) {
  12306. return d;
  12307. }
  12308. function pie() {
  12309. var value = identity$7,
  12310. sortValues = descending$1,
  12311. sort = null,
  12312. startAngle = constant$b(0),
  12313. endAngle = constant$b(tau$4),
  12314. padAngle = constant$b(0);
  12315. function pie(data) {
  12316. var i,
  12317. n = data.length,
  12318. j,
  12319. k,
  12320. sum = 0,
  12321. index = new Array(n),
  12322. arcs = new Array(n),
  12323. a0 = +startAngle.apply(this, arguments),
  12324. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  12325. a1,
  12326. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  12327. pa = p * (da < 0 ? -1 : 1),
  12328. v;
  12329. for (i = 0; i < n; ++i) {
  12330. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  12331. sum += v;
  12332. }
  12333. }
  12334. // Optionally sort the arcs by previously-computed values or by data.
  12335. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  12336. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  12337. // Compute the arcs! They are stored in the original data's order.
  12338. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  12339. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  12340. data: data[j],
  12341. index: i,
  12342. value: v,
  12343. startAngle: a0,
  12344. endAngle: a1,
  12345. padAngle: p
  12346. };
  12347. }
  12348. return arcs;
  12349. }
  12350. pie.value = function(_) {
  12351. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), pie) : value;
  12352. };
  12353. pie.sortValues = function(_) {
  12354. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  12355. };
  12356. pie.sort = function(_) {
  12357. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  12358. };
  12359. pie.startAngle = function(_) {
  12360. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : startAngle;
  12361. };
  12362. pie.endAngle = function(_) {
  12363. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : endAngle;
  12364. };
  12365. pie.padAngle = function(_) {
  12366. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : padAngle;
  12367. };
  12368. return pie;
  12369. }
  12370. var curveRadialLinear = curveRadial(curveLinear);
  12371. function Radial(curve) {
  12372. this._curve = curve;
  12373. }
  12374. Radial.prototype = {
  12375. areaStart: function() {
  12376. this._curve.areaStart();
  12377. },
  12378. areaEnd: function() {
  12379. this._curve.areaEnd();
  12380. },
  12381. lineStart: function() {
  12382. this._curve.lineStart();
  12383. },
  12384. lineEnd: function() {
  12385. this._curve.lineEnd();
  12386. },
  12387. point: function(a, r) {
  12388. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  12389. }
  12390. };
  12391. function curveRadial(curve) {
  12392. function radial(context) {
  12393. return new Radial(curve(context));
  12394. }
  12395. radial._curve = curve;
  12396. return radial;
  12397. }
  12398. function lineRadial(l) {
  12399. var c = l.curve;
  12400. l.angle = l.x, delete l.x;
  12401. l.radius = l.y, delete l.y;
  12402. l.curve = function(_) {
  12403. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12404. };
  12405. return l;
  12406. }
  12407. function lineRadial$1() {
  12408. return lineRadial(line().curve(curveRadialLinear));
  12409. }
  12410. function areaRadial() {
  12411. var a = area$3().curve(curveRadialLinear),
  12412. c = a.curve,
  12413. x0 = a.lineX0,
  12414. x1 = a.lineX1,
  12415. y0 = a.lineY0,
  12416. y1 = a.lineY1;
  12417. a.angle = a.x, delete a.x;
  12418. a.startAngle = a.x0, delete a.x0;
  12419. a.endAngle = a.x1, delete a.x1;
  12420. a.radius = a.y, delete a.y;
  12421. a.innerRadius = a.y0, delete a.y0;
  12422. a.outerRadius = a.y1, delete a.y1;
  12423. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  12424. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  12425. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  12426. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  12427. a.curve = function(_) {
  12428. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12429. };
  12430. return a;
  12431. }
  12432. function pointRadial(x, y) {
  12433. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  12434. }
  12435. var slice$6 = Array.prototype.slice;
  12436. function linkSource(d) {
  12437. return d.source;
  12438. }
  12439. function linkTarget(d) {
  12440. return d.target;
  12441. }
  12442. function link$2(curve) {
  12443. var source = linkSource,
  12444. target = linkTarget,
  12445. x$$1 = x$3,
  12446. y$$1 = y$3,
  12447. context = null;
  12448. function link() {
  12449. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  12450. if (!context) context = buffer = path();
  12451. 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));
  12452. if (buffer) return context = null, buffer + "" || null;
  12453. }
  12454. link.source = function(_) {
  12455. return arguments.length ? (source = _, link) : source;
  12456. };
  12457. link.target = function(_) {
  12458. return arguments.length ? (target = _, link) : target;
  12459. };
  12460. link.x = function(_) {
  12461. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$b(+_), link) : x$$1;
  12462. };
  12463. link.y = function(_) {
  12464. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$b(+_), link) : y$$1;
  12465. };
  12466. link.context = function(_) {
  12467. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  12468. };
  12469. return link;
  12470. }
  12471. function curveHorizontal(context, x0, y0, x1, y1) {
  12472. context.moveTo(x0, y0);
  12473. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  12474. }
  12475. function curveVertical(context, x0, y0, x1, y1) {
  12476. context.moveTo(x0, y0);
  12477. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  12478. }
  12479. function curveRadial$1(context, x0, y0, x1, y1) {
  12480. var p0 = pointRadial(x0, y0),
  12481. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  12482. p2 = pointRadial(x1, y0),
  12483. p3 = pointRadial(x1, y1);
  12484. context.moveTo(p0[0], p0[1]);
  12485. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  12486. }
  12487. function linkHorizontal() {
  12488. return link$2(curveHorizontal);
  12489. }
  12490. function linkVertical() {
  12491. return link$2(curveVertical);
  12492. }
  12493. function linkRadial() {
  12494. var l = link$2(curveRadial$1);
  12495. l.angle = l.x, delete l.x;
  12496. l.radius = l.y, delete l.y;
  12497. return l;
  12498. }
  12499. var circle$2 = {
  12500. draw: function(context, size) {
  12501. var r = Math.sqrt(size / pi$4);
  12502. context.moveTo(r, 0);
  12503. context.arc(0, 0, r, 0, tau$4);
  12504. }
  12505. };
  12506. var cross$2 = {
  12507. draw: function(context, size) {
  12508. var r = Math.sqrt(size / 5) / 2;
  12509. context.moveTo(-3 * r, -r);
  12510. context.lineTo(-r, -r);
  12511. context.lineTo(-r, -3 * r);
  12512. context.lineTo(r, -3 * r);
  12513. context.lineTo(r, -r);
  12514. context.lineTo(3 * r, -r);
  12515. context.lineTo(3 * r, r);
  12516. context.lineTo(r, r);
  12517. context.lineTo(r, 3 * r);
  12518. context.lineTo(-r, 3 * r);
  12519. context.lineTo(-r, r);
  12520. context.lineTo(-3 * r, r);
  12521. context.closePath();
  12522. }
  12523. };
  12524. var tan30 = Math.sqrt(1 / 3),
  12525. tan30_2 = tan30 * 2;
  12526. var diamond = {
  12527. draw: function(context, size) {
  12528. var y = Math.sqrt(size / tan30_2),
  12529. x = y * tan30;
  12530. context.moveTo(0, -y);
  12531. context.lineTo(x, 0);
  12532. context.lineTo(0, y);
  12533. context.lineTo(-x, 0);
  12534. context.closePath();
  12535. }
  12536. };
  12537. var ka = 0.89081309152928522810,
  12538. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  12539. kx = Math.sin(tau$4 / 10) * kr,
  12540. ky = -Math.cos(tau$4 / 10) * kr;
  12541. var star = {
  12542. draw: function(context, size) {
  12543. var r = Math.sqrt(size * ka),
  12544. x = kx * r,
  12545. y = ky * r;
  12546. context.moveTo(0, -r);
  12547. context.lineTo(x, y);
  12548. for (var i = 1; i < 5; ++i) {
  12549. var a = tau$4 * i / 5,
  12550. c = Math.cos(a),
  12551. s = Math.sin(a);
  12552. context.lineTo(s * r, -c * r);
  12553. context.lineTo(c * x - s * y, s * x + c * y);
  12554. }
  12555. context.closePath();
  12556. }
  12557. };
  12558. var square = {
  12559. draw: function(context, size) {
  12560. var w = Math.sqrt(size),
  12561. x = -w / 2;
  12562. context.rect(x, x, w, w);
  12563. }
  12564. };
  12565. var sqrt3 = Math.sqrt(3);
  12566. var triangle = {
  12567. draw: function(context, size) {
  12568. var y = -Math.sqrt(size / (sqrt3 * 3));
  12569. context.moveTo(0, y * 2);
  12570. context.lineTo(-sqrt3 * y, -y);
  12571. context.lineTo(sqrt3 * y, -y);
  12572. context.closePath();
  12573. }
  12574. };
  12575. var c$2 = -0.5,
  12576. s = Math.sqrt(3) / 2,
  12577. k = 1 / Math.sqrt(12),
  12578. a = (k / 2 + 1) * 3;
  12579. var wye = {
  12580. draw: function(context, size) {
  12581. var r = Math.sqrt(size / a),
  12582. x0 = r / 2,
  12583. y0 = r * k,
  12584. x1 = x0,
  12585. y1 = r * k + r,
  12586. x2 = -x1,
  12587. y2 = y1;
  12588. context.moveTo(x0, y0);
  12589. context.lineTo(x1, y1);
  12590. context.lineTo(x2, y2);
  12591. context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
  12592. context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
  12593. context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
  12594. context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
  12595. context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
  12596. context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
  12597. context.closePath();
  12598. }
  12599. };
  12600. var symbols = [
  12601. circle$2,
  12602. cross$2,
  12603. diamond,
  12604. square,
  12605. star,
  12606. triangle,
  12607. wye
  12608. ];
  12609. function symbol() {
  12610. var type = constant$b(circle$2),
  12611. size = constant$b(64),
  12612. context = null;
  12613. function symbol() {
  12614. var buffer;
  12615. if (!context) context = buffer = path();
  12616. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  12617. if (buffer) return context = null, buffer + "" || null;
  12618. }
  12619. symbol.type = function(_) {
  12620. return arguments.length ? (type = typeof _ === "function" ? _ : constant$b(_), symbol) : type;
  12621. };
  12622. symbol.size = function(_) {
  12623. return arguments.length ? (size = typeof _ === "function" ? _ : constant$b(+_), symbol) : size;
  12624. };
  12625. symbol.context = function(_) {
  12626. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  12627. };
  12628. return symbol;
  12629. }
  12630. function noop$3() {}
  12631. function point$2(that, x, y) {
  12632. that._context.bezierCurveTo(
  12633. (2 * that._x0 + that._x1) / 3,
  12634. (2 * that._y0 + that._y1) / 3,
  12635. (that._x0 + 2 * that._x1) / 3,
  12636. (that._y0 + 2 * that._y1) / 3,
  12637. (that._x0 + 4 * that._x1 + x) / 6,
  12638. (that._y0 + 4 * that._y1 + y) / 6
  12639. );
  12640. }
  12641. function Basis(context) {
  12642. this._context = context;
  12643. }
  12644. Basis.prototype = {
  12645. areaStart: function() {
  12646. this._line = 0;
  12647. },
  12648. areaEnd: function() {
  12649. this._line = NaN;
  12650. },
  12651. lineStart: function() {
  12652. this._x0 = this._x1 =
  12653. this._y0 = this._y1 = NaN;
  12654. this._point = 0;
  12655. },
  12656. lineEnd: function() {
  12657. switch (this._point) {
  12658. case 3: point$2(this, this._x1, this._y1); // proceed
  12659. case 2: this._context.lineTo(this._x1, this._y1); break;
  12660. }
  12661. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12662. this._line = 1 - this._line;
  12663. },
  12664. point: function(x, y) {
  12665. x = +x, y = +y;
  12666. switch (this._point) {
  12667. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12668. case 1: this._point = 2; break;
  12669. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  12670. default: point$2(this, x, y); break;
  12671. }
  12672. this._x0 = this._x1, this._x1 = x;
  12673. this._y0 = this._y1, this._y1 = y;
  12674. }
  12675. };
  12676. function basis$2(context) {
  12677. return new Basis(context);
  12678. }
  12679. function BasisClosed(context) {
  12680. this._context = context;
  12681. }
  12682. BasisClosed.prototype = {
  12683. areaStart: noop$3,
  12684. areaEnd: noop$3,
  12685. lineStart: function() {
  12686. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  12687. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  12688. this._point = 0;
  12689. },
  12690. lineEnd: function() {
  12691. switch (this._point) {
  12692. case 1: {
  12693. this._context.moveTo(this._x2, this._y2);
  12694. this._context.closePath();
  12695. break;
  12696. }
  12697. case 2: {
  12698. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  12699. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  12700. this._context.closePath();
  12701. break;
  12702. }
  12703. case 3: {
  12704. this.point(this._x2, this._y2);
  12705. this.point(this._x3, this._y3);
  12706. this.point(this._x4, this._y4);
  12707. break;
  12708. }
  12709. }
  12710. },
  12711. point: function(x, y) {
  12712. x = +x, y = +y;
  12713. switch (this._point) {
  12714. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  12715. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  12716. 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;
  12717. default: point$2(this, x, y); break;
  12718. }
  12719. this._x0 = this._x1, this._x1 = x;
  12720. this._y0 = this._y1, this._y1 = y;
  12721. }
  12722. };
  12723. function basisClosed$1(context) {
  12724. return new BasisClosed(context);
  12725. }
  12726. function BasisOpen(context) {
  12727. this._context = context;
  12728. }
  12729. BasisOpen.prototype = {
  12730. areaStart: function() {
  12731. this._line = 0;
  12732. },
  12733. areaEnd: function() {
  12734. this._line = NaN;
  12735. },
  12736. lineStart: function() {
  12737. this._x0 = this._x1 =
  12738. this._y0 = this._y1 = NaN;
  12739. this._point = 0;
  12740. },
  12741. lineEnd: function() {
  12742. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12743. this._line = 1 - this._line;
  12744. },
  12745. point: function(x, y) {
  12746. x = +x, y = +y;
  12747. switch (this._point) {
  12748. case 0: this._point = 1; break;
  12749. case 1: this._point = 2; break;
  12750. 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;
  12751. case 3: this._point = 4; // proceed
  12752. default: point$2(this, x, y); break;
  12753. }
  12754. this._x0 = this._x1, this._x1 = x;
  12755. this._y0 = this._y1, this._y1 = y;
  12756. }
  12757. };
  12758. function basisOpen(context) {
  12759. return new BasisOpen(context);
  12760. }
  12761. function Bundle(context, beta) {
  12762. this._basis = new Basis(context);
  12763. this._beta = beta;
  12764. }
  12765. Bundle.prototype = {
  12766. lineStart: function() {
  12767. this._x = [];
  12768. this._y = [];
  12769. this._basis.lineStart();
  12770. },
  12771. lineEnd: function() {
  12772. var x = this._x,
  12773. y = this._y,
  12774. j = x.length - 1;
  12775. if (j > 0) {
  12776. var x0 = x[0],
  12777. y0 = y[0],
  12778. dx = x[j] - x0,
  12779. dy = y[j] - y0,
  12780. i = -1,
  12781. t;
  12782. while (++i <= j) {
  12783. t = i / j;
  12784. this._basis.point(
  12785. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  12786. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  12787. );
  12788. }
  12789. }
  12790. this._x = this._y = null;
  12791. this._basis.lineEnd();
  12792. },
  12793. point: function(x, y) {
  12794. this._x.push(+x);
  12795. this._y.push(+y);
  12796. }
  12797. };
  12798. var bundle = (function custom(beta) {
  12799. function bundle(context) {
  12800. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  12801. }
  12802. bundle.beta = function(beta) {
  12803. return custom(+beta);
  12804. };
  12805. return bundle;
  12806. })(0.85);
  12807. function point$3(that, x, y) {
  12808. that._context.bezierCurveTo(
  12809. that._x1 + that._k * (that._x2 - that._x0),
  12810. that._y1 + that._k * (that._y2 - that._y0),
  12811. that._x2 + that._k * (that._x1 - x),
  12812. that._y2 + that._k * (that._y1 - y),
  12813. that._x2,
  12814. that._y2
  12815. );
  12816. }
  12817. function Cardinal(context, tension) {
  12818. this._context = context;
  12819. this._k = (1 - tension) / 6;
  12820. }
  12821. Cardinal.prototype = {
  12822. areaStart: function() {
  12823. this._line = 0;
  12824. },
  12825. areaEnd: function() {
  12826. this._line = NaN;
  12827. },
  12828. lineStart: function() {
  12829. this._x0 = this._x1 = this._x2 =
  12830. this._y0 = this._y1 = this._y2 = NaN;
  12831. this._point = 0;
  12832. },
  12833. lineEnd: function() {
  12834. switch (this._point) {
  12835. case 2: this._context.lineTo(this._x2, this._y2); break;
  12836. case 3: point$3(this, this._x1, this._y1); break;
  12837. }
  12838. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12839. this._line = 1 - this._line;
  12840. },
  12841. point: function(x, y) {
  12842. x = +x, y = +y;
  12843. switch (this._point) {
  12844. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12845. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  12846. case 2: this._point = 3; // proceed
  12847. default: point$3(this, x, y); break;
  12848. }
  12849. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12850. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12851. }
  12852. };
  12853. var cardinal = (function custom(tension) {
  12854. function cardinal(context) {
  12855. return new Cardinal(context, tension);
  12856. }
  12857. cardinal.tension = function(tension) {
  12858. return custom(+tension);
  12859. };
  12860. return cardinal;
  12861. })(0);
  12862. function CardinalClosed(context, tension) {
  12863. this._context = context;
  12864. this._k = (1 - tension) / 6;
  12865. }
  12866. CardinalClosed.prototype = {
  12867. areaStart: noop$3,
  12868. areaEnd: noop$3,
  12869. lineStart: function() {
  12870. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12871. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12872. this._point = 0;
  12873. },
  12874. lineEnd: function() {
  12875. switch (this._point) {
  12876. case 1: {
  12877. this._context.moveTo(this._x3, this._y3);
  12878. this._context.closePath();
  12879. break;
  12880. }
  12881. case 2: {
  12882. this._context.lineTo(this._x3, this._y3);
  12883. this._context.closePath();
  12884. break;
  12885. }
  12886. case 3: {
  12887. this.point(this._x3, this._y3);
  12888. this.point(this._x4, this._y4);
  12889. this.point(this._x5, this._y5);
  12890. break;
  12891. }
  12892. }
  12893. },
  12894. point: function(x, y) {
  12895. x = +x, y = +y;
  12896. switch (this._point) {
  12897. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12898. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12899. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12900. default: point$3(this, x, y); break;
  12901. }
  12902. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12903. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12904. }
  12905. };
  12906. var cardinalClosed = (function custom(tension) {
  12907. function cardinal$$1(context) {
  12908. return new CardinalClosed(context, tension);
  12909. }
  12910. cardinal$$1.tension = function(tension) {
  12911. return custom(+tension);
  12912. };
  12913. return cardinal$$1;
  12914. })(0);
  12915. function CardinalOpen(context, tension) {
  12916. this._context = context;
  12917. this._k = (1 - tension) / 6;
  12918. }
  12919. CardinalOpen.prototype = {
  12920. areaStart: function() {
  12921. this._line = 0;
  12922. },
  12923. areaEnd: function() {
  12924. this._line = NaN;
  12925. },
  12926. lineStart: function() {
  12927. this._x0 = this._x1 = this._x2 =
  12928. this._y0 = this._y1 = this._y2 = NaN;
  12929. this._point = 0;
  12930. },
  12931. lineEnd: function() {
  12932. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12933. this._line = 1 - this._line;
  12934. },
  12935. point: function(x, y) {
  12936. x = +x, y = +y;
  12937. switch (this._point) {
  12938. case 0: this._point = 1; break;
  12939. case 1: this._point = 2; break;
  12940. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12941. case 3: this._point = 4; // proceed
  12942. default: point$3(this, x, y); break;
  12943. }
  12944. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12945. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12946. }
  12947. };
  12948. var cardinalOpen = (function custom(tension) {
  12949. function cardinal$$1(context) {
  12950. return new CardinalOpen(context, tension);
  12951. }
  12952. cardinal$$1.tension = function(tension) {
  12953. return custom(+tension);
  12954. };
  12955. return cardinal$$1;
  12956. })(0);
  12957. function point$4(that, x, y) {
  12958. var x1 = that._x1,
  12959. y1 = that._y1,
  12960. x2 = that._x2,
  12961. y2 = that._y2;
  12962. if (that._l01_a > epsilon$3) {
  12963. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  12964. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  12965. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  12966. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  12967. }
  12968. if (that._l23_a > epsilon$3) {
  12969. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  12970. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  12971. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  12972. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  12973. }
  12974. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  12975. }
  12976. function CatmullRom(context, alpha) {
  12977. this._context = context;
  12978. this._alpha = alpha;
  12979. }
  12980. CatmullRom.prototype = {
  12981. areaStart: function() {
  12982. this._line = 0;
  12983. },
  12984. areaEnd: function() {
  12985. this._line = NaN;
  12986. },
  12987. lineStart: function() {
  12988. this._x0 = this._x1 = this._x2 =
  12989. this._y0 = this._y1 = this._y2 = NaN;
  12990. this._l01_a = this._l12_a = this._l23_a =
  12991. this._l01_2a = this._l12_2a = this._l23_2a =
  12992. this._point = 0;
  12993. },
  12994. lineEnd: function() {
  12995. switch (this._point) {
  12996. case 2: this._context.lineTo(this._x2, this._y2); break;
  12997. case 3: this.point(this._x2, this._y2); break;
  12998. }
  12999. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13000. this._line = 1 - this._line;
  13001. },
  13002. point: function(x, y) {
  13003. x = +x, y = +y;
  13004. if (this._point) {
  13005. var x23 = this._x2 - x,
  13006. y23 = this._y2 - y;
  13007. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13008. }
  13009. switch (this._point) {
  13010. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13011. case 1: this._point = 2; break;
  13012. case 2: this._point = 3; // proceed
  13013. default: point$4(this, x, y); break;
  13014. }
  13015. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13016. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13017. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13018. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13019. }
  13020. };
  13021. var catmullRom = (function custom(alpha) {
  13022. function catmullRom(context) {
  13023. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  13024. }
  13025. catmullRom.alpha = function(alpha) {
  13026. return custom(+alpha);
  13027. };
  13028. return catmullRom;
  13029. })(0.5);
  13030. function CatmullRomClosed(context, alpha) {
  13031. this._context = context;
  13032. this._alpha = alpha;
  13033. }
  13034. CatmullRomClosed.prototype = {
  13035. areaStart: noop$3,
  13036. areaEnd: noop$3,
  13037. lineStart: function() {
  13038. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13039. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13040. this._l01_a = this._l12_a = this._l23_a =
  13041. this._l01_2a = this._l12_2a = this._l23_2a =
  13042. this._point = 0;
  13043. },
  13044. lineEnd: function() {
  13045. switch (this._point) {
  13046. case 1: {
  13047. this._context.moveTo(this._x3, this._y3);
  13048. this._context.closePath();
  13049. break;
  13050. }
  13051. case 2: {
  13052. this._context.lineTo(this._x3, this._y3);
  13053. this._context.closePath();
  13054. break;
  13055. }
  13056. case 3: {
  13057. this.point(this._x3, this._y3);
  13058. this.point(this._x4, this._y4);
  13059. this.point(this._x5, this._y5);
  13060. break;
  13061. }
  13062. }
  13063. },
  13064. point: function(x, y) {
  13065. x = +x, y = +y;
  13066. if (this._point) {
  13067. var x23 = this._x2 - x,
  13068. y23 = this._y2 - y;
  13069. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13070. }
  13071. switch (this._point) {
  13072. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13073. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13074. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13075. default: point$4(this, x, y); break;
  13076. }
  13077. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13078. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13079. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13080. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13081. }
  13082. };
  13083. var catmullRomClosed = (function custom(alpha) {
  13084. function catmullRom$$1(context) {
  13085. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  13086. }
  13087. catmullRom$$1.alpha = function(alpha) {
  13088. return custom(+alpha);
  13089. };
  13090. return catmullRom$$1;
  13091. })(0.5);
  13092. function CatmullRomOpen(context, alpha) {
  13093. this._context = context;
  13094. this._alpha = alpha;
  13095. }
  13096. CatmullRomOpen.prototype = {
  13097. areaStart: function() {
  13098. this._line = 0;
  13099. },
  13100. areaEnd: function() {
  13101. this._line = NaN;
  13102. },
  13103. lineStart: function() {
  13104. this._x0 = this._x1 = this._x2 =
  13105. this._y0 = this._y1 = this._y2 = NaN;
  13106. this._l01_a = this._l12_a = this._l23_a =
  13107. this._l01_2a = this._l12_2a = this._l23_2a =
  13108. this._point = 0;
  13109. },
  13110. lineEnd: function() {
  13111. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13112. this._line = 1 - this._line;
  13113. },
  13114. point: function(x, y) {
  13115. x = +x, y = +y;
  13116. if (this._point) {
  13117. var x23 = this._x2 - x,
  13118. y23 = this._y2 - y;
  13119. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13120. }
  13121. switch (this._point) {
  13122. case 0: this._point = 1; break;
  13123. case 1: this._point = 2; break;
  13124. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13125. case 3: this._point = 4; // proceed
  13126. default: point$4(this, x, y); break;
  13127. }
  13128. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13129. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13130. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13131. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13132. }
  13133. };
  13134. var catmullRomOpen = (function custom(alpha) {
  13135. function catmullRom$$1(context) {
  13136. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  13137. }
  13138. catmullRom$$1.alpha = function(alpha) {
  13139. return custom(+alpha);
  13140. };
  13141. return catmullRom$$1;
  13142. })(0.5);
  13143. function LinearClosed(context) {
  13144. this._context = context;
  13145. }
  13146. LinearClosed.prototype = {
  13147. areaStart: noop$3,
  13148. areaEnd: noop$3,
  13149. lineStart: function() {
  13150. this._point = 0;
  13151. },
  13152. lineEnd: function() {
  13153. if (this._point) this._context.closePath();
  13154. },
  13155. point: function(x, y) {
  13156. x = +x, y = +y;
  13157. if (this._point) this._context.lineTo(x, y);
  13158. else this._point = 1, this._context.moveTo(x, y);
  13159. }
  13160. };
  13161. function linearClosed(context) {
  13162. return new LinearClosed(context);
  13163. }
  13164. function sign$1(x) {
  13165. return x < 0 ? -1 : 1;
  13166. }
  13167. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  13168. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  13169. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  13170. // NOV(II), P. 443, 1990.
  13171. function slope3(that, x2, y2) {
  13172. var h0 = that._x1 - that._x0,
  13173. h1 = x2 - that._x1,
  13174. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  13175. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  13176. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  13177. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  13178. }
  13179. // Calculate a one-sided slope.
  13180. function slope2(that, t) {
  13181. var h = that._x1 - that._x0;
  13182. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  13183. }
  13184. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  13185. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  13186. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  13187. function point$5(that, t0, t1) {
  13188. var x0 = that._x0,
  13189. y0 = that._y0,
  13190. x1 = that._x1,
  13191. y1 = that._y1,
  13192. dx = (x1 - x0) / 3;
  13193. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  13194. }
  13195. function MonotoneX(context) {
  13196. this._context = context;
  13197. }
  13198. MonotoneX.prototype = {
  13199. areaStart: function() {
  13200. this._line = 0;
  13201. },
  13202. areaEnd: function() {
  13203. this._line = NaN;
  13204. },
  13205. lineStart: function() {
  13206. this._x0 = this._x1 =
  13207. this._y0 = this._y1 =
  13208. this._t0 = NaN;
  13209. this._point = 0;
  13210. },
  13211. lineEnd: function() {
  13212. switch (this._point) {
  13213. case 2: this._context.lineTo(this._x1, this._y1); break;
  13214. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  13215. }
  13216. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13217. this._line = 1 - this._line;
  13218. },
  13219. point: function(x, y) {
  13220. var t1 = NaN;
  13221. x = +x, y = +y;
  13222. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  13223. switch (this._point) {
  13224. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13225. case 1: this._point = 2; break;
  13226. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  13227. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  13228. }
  13229. this._x0 = this._x1, this._x1 = x;
  13230. this._y0 = this._y1, this._y1 = y;
  13231. this._t0 = t1;
  13232. }
  13233. };
  13234. function MonotoneY(context) {
  13235. this._context = new ReflectContext(context);
  13236. }
  13237. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  13238. MonotoneX.prototype.point.call(this, y, x);
  13239. };
  13240. function ReflectContext(context) {
  13241. this._context = context;
  13242. }
  13243. ReflectContext.prototype = {
  13244. moveTo: function(x, y) { this._context.moveTo(y, x); },
  13245. closePath: function() { this._context.closePath(); },
  13246. lineTo: function(x, y) { this._context.lineTo(y, x); },
  13247. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  13248. };
  13249. function monotoneX(context) {
  13250. return new MonotoneX(context);
  13251. }
  13252. function monotoneY(context) {
  13253. return new MonotoneY(context);
  13254. }
  13255. function Natural(context) {
  13256. this._context = context;
  13257. }
  13258. Natural.prototype = {
  13259. areaStart: function() {
  13260. this._line = 0;
  13261. },
  13262. areaEnd: function() {
  13263. this._line = NaN;
  13264. },
  13265. lineStart: function() {
  13266. this._x = [];
  13267. this._y = [];
  13268. },
  13269. lineEnd: function() {
  13270. var x = this._x,
  13271. y = this._y,
  13272. n = x.length;
  13273. if (n) {
  13274. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  13275. if (n === 2) {
  13276. this._context.lineTo(x[1], y[1]);
  13277. } else {
  13278. var px = controlPoints(x),
  13279. py = controlPoints(y);
  13280. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  13281. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  13282. }
  13283. }
  13284. }
  13285. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  13286. this._line = 1 - this._line;
  13287. this._x = this._y = null;
  13288. },
  13289. point: function(x, y) {
  13290. this._x.push(+x);
  13291. this._y.push(+y);
  13292. }
  13293. };
  13294. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  13295. function controlPoints(x) {
  13296. var i,
  13297. n = x.length - 1,
  13298. m,
  13299. a = new Array(n),
  13300. b = new Array(n),
  13301. r = new Array(n);
  13302. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  13303. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  13304. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  13305. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  13306. a[n - 1] = r[n - 1] / b[n - 1];
  13307. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  13308. b[n - 1] = (x[n] + a[n - 1]) / 2;
  13309. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  13310. return [a, b];
  13311. }
  13312. function natural(context) {
  13313. return new Natural(context);
  13314. }
  13315. function Step(context, t) {
  13316. this._context = context;
  13317. this._t = t;
  13318. }
  13319. Step.prototype = {
  13320. areaStart: function() {
  13321. this._line = 0;
  13322. },
  13323. areaEnd: function() {
  13324. this._line = NaN;
  13325. },
  13326. lineStart: function() {
  13327. this._x = this._y = NaN;
  13328. this._point = 0;
  13329. },
  13330. lineEnd: function() {
  13331. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  13332. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13333. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  13334. },
  13335. point: function(x, y) {
  13336. x = +x, y = +y;
  13337. switch (this._point) {
  13338. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13339. case 1: this._point = 2; // proceed
  13340. default: {
  13341. if (this._t <= 0) {
  13342. this._context.lineTo(this._x, y);
  13343. this._context.lineTo(x, y);
  13344. } else {
  13345. var x1 = this._x * (1 - this._t) + x * this._t;
  13346. this._context.lineTo(x1, this._y);
  13347. this._context.lineTo(x1, y);
  13348. }
  13349. break;
  13350. }
  13351. }
  13352. this._x = x, this._y = y;
  13353. }
  13354. };
  13355. function step(context) {
  13356. return new Step(context, 0.5);
  13357. }
  13358. function stepBefore(context) {
  13359. return new Step(context, 0);
  13360. }
  13361. function stepAfter(context) {
  13362. return new Step(context, 1);
  13363. }
  13364. function none$1(series, order) {
  13365. if (!((n = series.length) > 1)) return;
  13366. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  13367. s0 = s1, s1 = series[order[i]];
  13368. for (j = 0; j < m; ++j) {
  13369. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  13370. }
  13371. }
  13372. }
  13373. function none$2(series) {
  13374. var n = series.length, o = new Array(n);
  13375. while (--n >= 0) o[n] = n;
  13376. return o;
  13377. }
  13378. function stackValue(d, key) {
  13379. return d[key];
  13380. }
  13381. function stack() {
  13382. var keys = constant$b([]),
  13383. order = none$2,
  13384. offset = none$1,
  13385. value = stackValue;
  13386. function stack(data) {
  13387. var kz = keys.apply(this, arguments),
  13388. i,
  13389. m = data.length,
  13390. n = kz.length,
  13391. sz = new Array(n),
  13392. oz;
  13393. for (i = 0; i < n; ++i) {
  13394. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  13395. si[j] = sij = [0, +value(data[j], ki, j, data)];
  13396. sij.data = data[j];
  13397. }
  13398. si.key = ki;
  13399. }
  13400. for (i = 0, oz = order(sz); i < n; ++i) {
  13401. sz[oz[i]].index = i;
  13402. }
  13403. offset(sz, oz);
  13404. return sz;
  13405. }
  13406. stack.keys = function(_) {
  13407. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : keys;
  13408. };
  13409. stack.value = function(_) {
  13410. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), stack) : value;
  13411. };
  13412. stack.order = function(_) {
  13413. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : order;
  13414. };
  13415. stack.offset = function(_) {
  13416. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  13417. };
  13418. return stack;
  13419. }
  13420. function expand(series, order) {
  13421. if (!((n = series.length) > 0)) return;
  13422. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  13423. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  13424. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  13425. }
  13426. none$1(series, order);
  13427. }
  13428. function diverging$1(series, order) {
  13429. if (!((n = series.length) > 1)) return;
  13430. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  13431. for (yp = yn = 0, i = 0; i < n; ++i) {
  13432. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  13433. d[0] = yp, d[1] = yp += dy;
  13434. } else if (dy < 0) {
  13435. d[1] = yn, d[0] = yn += dy;
  13436. } else {
  13437. d[0] = yp;
  13438. }
  13439. }
  13440. }
  13441. }
  13442. function silhouette(series, order) {
  13443. if (!((n = series.length) > 0)) return;
  13444. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  13445. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  13446. s0[j][1] += s0[j][0] = -y / 2;
  13447. }
  13448. none$1(series, order);
  13449. }
  13450. function wiggle(series, order) {
  13451. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  13452. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  13453. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  13454. var si = series[order[i]],
  13455. sij0 = si[j][1] || 0,
  13456. sij1 = si[j - 1][1] || 0,
  13457. s3 = (sij0 - sij1) / 2;
  13458. for (var k = 0; k < i; ++k) {
  13459. var sk = series[order[k]],
  13460. skj0 = sk[j][1] || 0,
  13461. skj1 = sk[j - 1][1] || 0;
  13462. s3 += skj0 - skj1;
  13463. }
  13464. s1 += sij0, s2 += s3 * sij0;
  13465. }
  13466. s0[j - 1][1] += s0[j - 1][0] = y;
  13467. if (s1) y -= s2 / s1;
  13468. }
  13469. s0[j - 1][1] += s0[j - 1][0] = y;
  13470. none$1(series, order);
  13471. }
  13472. function ascending$3(series) {
  13473. var sums = series.map(sum$2);
  13474. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  13475. }
  13476. function sum$2(series) {
  13477. var s = 0, i = -1, n = series.length, v;
  13478. while (++i < n) if (v = +series[i][1]) s += v;
  13479. return s;
  13480. }
  13481. function descending$2(series) {
  13482. return ascending$3(series).reverse();
  13483. }
  13484. function insideOut(series) {
  13485. var n = series.length,
  13486. i,
  13487. j,
  13488. sums = series.map(sum$2),
  13489. order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  13490. top = 0,
  13491. bottom = 0,
  13492. tops = [],
  13493. bottoms = [];
  13494. for (i = 0; i < n; ++i) {
  13495. j = order[i];
  13496. if (top < bottom) {
  13497. top += sums[j];
  13498. tops.push(j);
  13499. } else {
  13500. bottom += sums[j];
  13501. bottoms.push(j);
  13502. }
  13503. }
  13504. return bottoms.reverse().concat(tops);
  13505. }
  13506. function reverse(series) {
  13507. return none$2(series).reverse();
  13508. }
  13509. function constant$c(x) {
  13510. return function() {
  13511. return x;
  13512. };
  13513. }
  13514. function x$4(d) {
  13515. return d[0];
  13516. }
  13517. function y$4(d) {
  13518. return d[1];
  13519. }
  13520. function RedBlackTree() {
  13521. this._ = null; // root node
  13522. }
  13523. function RedBlackNode(node) {
  13524. node.U = // parent node
  13525. node.C = // color - true for red, false for black
  13526. node.L = // left node
  13527. node.R = // right node
  13528. node.P = // previous node
  13529. node.N = null; // next node
  13530. }
  13531. RedBlackTree.prototype = {
  13532. constructor: RedBlackTree,
  13533. insert: function(after, node) {
  13534. var parent, grandpa, uncle;
  13535. if (after) {
  13536. node.P = after;
  13537. node.N = after.N;
  13538. if (after.N) after.N.P = node;
  13539. after.N = node;
  13540. if (after.R) {
  13541. after = after.R;
  13542. while (after.L) after = after.L;
  13543. after.L = node;
  13544. } else {
  13545. after.R = node;
  13546. }
  13547. parent = after;
  13548. } else if (this._) {
  13549. after = RedBlackFirst(this._);
  13550. node.P = null;
  13551. node.N = after;
  13552. after.P = after.L = node;
  13553. parent = after;
  13554. } else {
  13555. node.P = node.N = null;
  13556. this._ = node;
  13557. parent = null;
  13558. }
  13559. node.L = node.R = null;
  13560. node.U = parent;
  13561. node.C = true;
  13562. after = node;
  13563. while (parent && parent.C) {
  13564. grandpa = parent.U;
  13565. if (parent === grandpa.L) {
  13566. uncle = grandpa.R;
  13567. if (uncle && uncle.C) {
  13568. parent.C = uncle.C = false;
  13569. grandpa.C = true;
  13570. after = grandpa;
  13571. } else {
  13572. if (after === parent.R) {
  13573. RedBlackRotateLeft(this, parent);
  13574. after = parent;
  13575. parent = after.U;
  13576. }
  13577. parent.C = false;
  13578. grandpa.C = true;
  13579. RedBlackRotateRight(this, grandpa);
  13580. }
  13581. } else {
  13582. uncle = grandpa.L;
  13583. if (uncle && uncle.C) {
  13584. parent.C = uncle.C = false;
  13585. grandpa.C = true;
  13586. after = grandpa;
  13587. } else {
  13588. if (after === parent.L) {
  13589. RedBlackRotateRight(this, parent);
  13590. after = parent;
  13591. parent = after.U;
  13592. }
  13593. parent.C = false;
  13594. grandpa.C = true;
  13595. RedBlackRotateLeft(this, grandpa);
  13596. }
  13597. }
  13598. parent = after.U;
  13599. }
  13600. this._.C = false;
  13601. },
  13602. remove: function(node) {
  13603. if (node.N) node.N.P = node.P;
  13604. if (node.P) node.P.N = node.N;
  13605. node.N = node.P = null;
  13606. var parent = node.U,
  13607. sibling,
  13608. left = node.L,
  13609. right = node.R,
  13610. next,
  13611. red;
  13612. if (!left) next = right;
  13613. else if (!right) next = left;
  13614. else next = RedBlackFirst(right);
  13615. if (parent) {
  13616. if (parent.L === node) parent.L = next;
  13617. else parent.R = next;
  13618. } else {
  13619. this._ = next;
  13620. }
  13621. if (left && right) {
  13622. red = next.C;
  13623. next.C = node.C;
  13624. next.L = left;
  13625. left.U = next;
  13626. if (next !== right) {
  13627. parent = next.U;
  13628. next.U = node.U;
  13629. node = next.R;
  13630. parent.L = node;
  13631. next.R = right;
  13632. right.U = next;
  13633. } else {
  13634. next.U = parent;
  13635. parent = next;
  13636. node = next.R;
  13637. }
  13638. } else {
  13639. red = node.C;
  13640. node = next;
  13641. }
  13642. if (node) node.U = parent;
  13643. if (red) return;
  13644. if (node && node.C) { node.C = false; return; }
  13645. do {
  13646. if (node === this._) break;
  13647. if (node === parent.L) {
  13648. sibling = parent.R;
  13649. if (sibling.C) {
  13650. sibling.C = false;
  13651. parent.C = true;
  13652. RedBlackRotateLeft(this, parent);
  13653. sibling = parent.R;
  13654. }
  13655. if ((sibling.L && sibling.L.C)
  13656. || (sibling.R && sibling.R.C)) {
  13657. if (!sibling.R || !sibling.R.C) {
  13658. sibling.L.C = false;
  13659. sibling.C = true;
  13660. RedBlackRotateRight(this, sibling);
  13661. sibling = parent.R;
  13662. }
  13663. sibling.C = parent.C;
  13664. parent.C = sibling.R.C = false;
  13665. RedBlackRotateLeft(this, parent);
  13666. node = this._;
  13667. break;
  13668. }
  13669. } else {
  13670. sibling = parent.L;
  13671. if (sibling.C) {
  13672. sibling.C = false;
  13673. parent.C = true;
  13674. RedBlackRotateRight(this, parent);
  13675. sibling = parent.L;
  13676. }
  13677. if ((sibling.L && sibling.L.C)
  13678. || (sibling.R && sibling.R.C)) {
  13679. if (!sibling.L || !sibling.L.C) {
  13680. sibling.R.C = false;
  13681. sibling.C = true;
  13682. RedBlackRotateLeft(this, sibling);
  13683. sibling = parent.L;
  13684. }
  13685. sibling.C = parent.C;
  13686. parent.C = sibling.L.C = false;
  13687. RedBlackRotateRight(this, parent);
  13688. node = this._;
  13689. break;
  13690. }
  13691. }
  13692. sibling.C = true;
  13693. node = parent;
  13694. parent = parent.U;
  13695. } while (!node.C);
  13696. if (node) node.C = false;
  13697. }
  13698. };
  13699. function RedBlackRotateLeft(tree, node) {
  13700. var p = node,
  13701. q = node.R,
  13702. parent = p.U;
  13703. if (parent) {
  13704. if (parent.L === p) parent.L = q;
  13705. else parent.R = q;
  13706. } else {
  13707. tree._ = q;
  13708. }
  13709. q.U = parent;
  13710. p.U = q;
  13711. p.R = q.L;
  13712. if (p.R) p.R.U = p;
  13713. q.L = p;
  13714. }
  13715. function RedBlackRotateRight(tree, node) {
  13716. var p = node,
  13717. q = node.L,
  13718. parent = p.U;
  13719. if (parent) {
  13720. if (parent.L === p) parent.L = q;
  13721. else parent.R = q;
  13722. } else {
  13723. tree._ = q;
  13724. }
  13725. q.U = parent;
  13726. p.U = q;
  13727. p.L = q.R;
  13728. if (p.L) p.L.U = p;
  13729. q.R = p;
  13730. }
  13731. function RedBlackFirst(node) {
  13732. while (node.L) node = node.L;
  13733. return node;
  13734. }
  13735. function createEdge(left, right, v0, v1) {
  13736. var edge = [null, null],
  13737. index = edges.push(edge) - 1;
  13738. edge.left = left;
  13739. edge.right = right;
  13740. if (v0) setEdgeEnd(edge, left, right, v0);
  13741. if (v1) setEdgeEnd(edge, right, left, v1);
  13742. cells[left.index].halfedges.push(index);
  13743. cells[right.index].halfedges.push(index);
  13744. return edge;
  13745. }
  13746. function createBorderEdge(left, v0, v1) {
  13747. var edge = [v0, v1];
  13748. edge.left = left;
  13749. return edge;
  13750. }
  13751. function setEdgeEnd(edge, left, right, vertex) {
  13752. if (!edge[0] && !edge[1]) {
  13753. edge[0] = vertex;
  13754. edge.left = left;
  13755. edge.right = right;
  13756. } else if (edge.left === right) {
  13757. edge[1] = vertex;
  13758. } else {
  13759. edge[0] = vertex;
  13760. }
  13761. }
  13762. // Liang–Barsky line clipping.
  13763. function clipEdge(edge, x0, y0, x1, y1) {
  13764. var a = edge[0],
  13765. b = edge[1],
  13766. ax = a[0],
  13767. ay = a[1],
  13768. bx = b[0],
  13769. by = b[1],
  13770. t0 = 0,
  13771. t1 = 1,
  13772. dx = bx - ax,
  13773. dy = by - ay,
  13774. r;
  13775. r = x0 - ax;
  13776. if (!dx && r > 0) return;
  13777. r /= dx;
  13778. if (dx < 0) {
  13779. if (r < t0) return;
  13780. if (r < t1) t1 = r;
  13781. } else if (dx > 0) {
  13782. if (r > t1) return;
  13783. if (r > t0) t0 = r;
  13784. }
  13785. r = x1 - ax;
  13786. if (!dx && r < 0) return;
  13787. r /= dx;
  13788. if (dx < 0) {
  13789. if (r > t1) return;
  13790. if (r > t0) t0 = r;
  13791. } else if (dx > 0) {
  13792. if (r < t0) return;
  13793. if (r < t1) t1 = r;
  13794. }
  13795. r = y0 - ay;
  13796. if (!dy && r > 0) return;
  13797. r /= dy;
  13798. if (dy < 0) {
  13799. if (r < t0) return;
  13800. if (r < t1) t1 = r;
  13801. } else if (dy > 0) {
  13802. if (r > t1) return;
  13803. if (r > t0) t0 = r;
  13804. }
  13805. r = y1 - ay;
  13806. if (!dy && r < 0) return;
  13807. r /= dy;
  13808. if (dy < 0) {
  13809. if (r > t1) return;
  13810. if (r > t0) t0 = r;
  13811. } else if (dy > 0) {
  13812. if (r < t0) return;
  13813. if (r < t1) t1 = r;
  13814. }
  13815. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  13816. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  13817. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  13818. return true;
  13819. }
  13820. function connectEdge(edge, x0, y0, x1, y1) {
  13821. var v1 = edge[1];
  13822. if (v1) return true;
  13823. var v0 = edge[0],
  13824. left = edge.left,
  13825. right = edge.right,
  13826. lx = left[0],
  13827. ly = left[1],
  13828. rx = right[0],
  13829. ry = right[1],
  13830. fx = (lx + rx) / 2,
  13831. fy = (ly + ry) / 2,
  13832. fm,
  13833. fb;
  13834. if (ry === ly) {
  13835. if (fx < x0 || fx >= x1) return;
  13836. if (lx > rx) {
  13837. if (!v0) v0 = [fx, y0];
  13838. else if (v0[1] >= y1) return;
  13839. v1 = [fx, y1];
  13840. } else {
  13841. if (!v0) v0 = [fx, y1];
  13842. else if (v0[1] < y0) return;
  13843. v1 = [fx, y0];
  13844. }
  13845. } else {
  13846. fm = (lx - rx) / (ry - ly);
  13847. fb = fy - fm * fx;
  13848. if (fm < -1 || fm > 1) {
  13849. if (lx > rx) {
  13850. if (!v0) v0 = [(y0 - fb) / fm, y0];
  13851. else if (v0[1] >= y1) return;
  13852. v1 = [(y1 - fb) / fm, y1];
  13853. } else {
  13854. if (!v0) v0 = [(y1 - fb) / fm, y1];
  13855. else if (v0[1] < y0) return;
  13856. v1 = [(y0 - fb) / fm, y0];
  13857. }
  13858. } else {
  13859. if (ly < ry) {
  13860. if (!v0) v0 = [x0, fm * x0 + fb];
  13861. else if (v0[0] >= x1) return;
  13862. v1 = [x1, fm * x1 + fb];
  13863. } else {
  13864. if (!v0) v0 = [x1, fm * x1 + fb];
  13865. else if (v0[0] < x0) return;
  13866. v1 = [x0, fm * x0 + fb];
  13867. }
  13868. }
  13869. }
  13870. edge[0] = v0;
  13871. edge[1] = v1;
  13872. return true;
  13873. }
  13874. function clipEdges(x0, y0, x1, y1) {
  13875. var i = edges.length,
  13876. edge;
  13877. while (i--) {
  13878. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  13879. || !clipEdge(edge, x0, y0, x1, y1)
  13880. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  13881. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  13882. delete edges[i];
  13883. }
  13884. }
  13885. }
  13886. function createCell(site) {
  13887. return cells[site.index] = {
  13888. site: site,
  13889. halfedges: []
  13890. };
  13891. }
  13892. function cellHalfedgeAngle(cell, edge) {
  13893. var site = cell.site,
  13894. va = edge.left,
  13895. vb = edge.right;
  13896. if (site === vb) vb = va, va = site;
  13897. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  13898. if (site === va) va = edge[1], vb = edge[0];
  13899. else va = edge[0], vb = edge[1];
  13900. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  13901. }
  13902. function cellHalfedgeStart(cell, edge) {
  13903. return edge[+(edge.left !== cell.site)];
  13904. }
  13905. function cellHalfedgeEnd(cell, edge) {
  13906. return edge[+(edge.left === cell.site)];
  13907. }
  13908. function sortCellHalfedges() {
  13909. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  13910. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  13911. var index = new Array(m),
  13912. array = new Array(m);
  13913. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  13914. index.sort(function(i, j) { return array[j] - array[i]; });
  13915. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  13916. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  13917. }
  13918. }
  13919. }
  13920. function clipCells(x0, y0, x1, y1) {
  13921. var nCells = cells.length,
  13922. iCell,
  13923. cell,
  13924. site,
  13925. iHalfedge,
  13926. halfedges,
  13927. nHalfedges,
  13928. start,
  13929. startX,
  13930. startY,
  13931. end,
  13932. endX,
  13933. endY,
  13934. cover = true;
  13935. for (iCell = 0; iCell < nCells; ++iCell) {
  13936. if (cell = cells[iCell]) {
  13937. site = cell.site;
  13938. halfedges = cell.halfedges;
  13939. iHalfedge = halfedges.length;
  13940. // Remove any dangling clipped edges.
  13941. while (iHalfedge--) {
  13942. if (!edges[halfedges[iHalfedge]]) {
  13943. halfedges.splice(iHalfedge, 1);
  13944. }
  13945. }
  13946. // Insert any border edges as necessary.
  13947. iHalfedge = 0, nHalfedges = halfedges.length;
  13948. while (iHalfedge < nHalfedges) {
  13949. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  13950. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  13951. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  13952. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  13953. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  13954. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  13955. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  13956. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  13957. : null)) - 1);
  13958. ++nHalfedges;
  13959. }
  13960. }
  13961. if (nHalfedges) cover = false;
  13962. }
  13963. }
  13964. // If there weren’t any edges, have the closest site cover the extent.
  13965. // It doesn’t matter which corner of the extent we measure!
  13966. if (cover) {
  13967. var dx, dy, d2, dc = Infinity;
  13968. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  13969. if (cell = cells[iCell]) {
  13970. site = cell.site;
  13971. dx = site[0] - x0;
  13972. dy = site[1] - y0;
  13973. d2 = dx * dx + dy * dy;
  13974. if (d2 < dc) dc = d2, cover = cell;
  13975. }
  13976. }
  13977. if (cover) {
  13978. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  13979. cover.halfedges.push(
  13980. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  13981. edges.push(createBorderEdge(site, v01, v11)) - 1,
  13982. edges.push(createBorderEdge(site, v11, v10)) - 1,
  13983. edges.push(createBorderEdge(site, v10, v00)) - 1
  13984. );
  13985. }
  13986. }
  13987. // Lastly delete any cells with no edges; these were entirely clipped.
  13988. for (iCell = 0; iCell < nCells; ++iCell) {
  13989. if (cell = cells[iCell]) {
  13990. if (!cell.halfedges.length) {
  13991. delete cells[iCell];
  13992. }
  13993. }
  13994. }
  13995. }
  13996. var circlePool = [];
  13997. var firstCircle;
  13998. function Circle() {
  13999. RedBlackNode(this);
  14000. this.x =
  14001. this.y =
  14002. this.arc =
  14003. this.site =
  14004. this.cy = null;
  14005. }
  14006. function attachCircle(arc) {
  14007. var lArc = arc.P,
  14008. rArc = arc.N;
  14009. if (!lArc || !rArc) return;
  14010. var lSite = lArc.site,
  14011. cSite = arc.site,
  14012. rSite = rArc.site;
  14013. if (lSite === rSite) return;
  14014. var bx = cSite[0],
  14015. by = cSite[1],
  14016. ax = lSite[0] - bx,
  14017. ay = lSite[1] - by,
  14018. cx = rSite[0] - bx,
  14019. cy = rSite[1] - by;
  14020. var d = 2 * (ax * cy - ay * cx);
  14021. if (d >= -epsilon2$2) return;
  14022. var ha = ax * ax + ay * ay,
  14023. hc = cx * cx + cy * cy,
  14024. x = (cy * ha - ay * hc) / d,
  14025. y = (ax * hc - cx * ha) / d;
  14026. var circle = circlePool.pop() || new Circle;
  14027. circle.arc = arc;
  14028. circle.site = cSite;
  14029. circle.x = x + bx;
  14030. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  14031. arc.circle = circle;
  14032. var before = null,
  14033. node = circles._;
  14034. while (node) {
  14035. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  14036. if (node.L) node = node.L;
  14037. else { before = node.P; break; }
  14038. } else {
  14039. if (node.R) node = node.R;
  14040. else { before = node; break; }
  14041. }
  14042. }
  14043. circles.insert(before, circle);
  14044. if (!before) firstCircle = circle;
  14045. }
  14046. function detachCircle(arc) {
  14047. var circle = arc.circle;
  14048. if (circle) {
  14049. if (!circle.P) firstCircle = circle.N;
  14050. circles.remove(circle);
  14051. circlePool.push(circle);
  14052. RedBlackNode(circle);
  14053. arc.circle = null;
  14054. }
  14055. }
  14056. var beachPool = [];
  14057. function Beach() {
  14058. RedBlackNode(this);
  14059. this.edge =
  14060. this.site =
  14061. this.circle = null;
  14062. }
  14063. function createBeach(site) {
  14064. var beach = beachPool.pop() || new Beach;
  14065. beach.site = site;
  14066. return beach;
  14067. }
  14068. function detachBeach(beach) {
  14069. detachCircle(beach);
  14070. beaches.remove(beach);
  14071. beachPool.push(beach);
  14072. RedBlackNode(beach);
  14073. }
  14074. function removeBeach(beach) {
  14075. var circle = beach.circle,
  14076. x = circle.x,
  14077. y = circle.cy,
  14078. vertex = [x, y],
  14079. previous = beach.P,
  14080. next = beach.N,
  14081. disappearing = [beach];
  14082. detachBeach(beach);
  14083. var lArc = previous;
  14084. while (lArc.circle
  14085. && Math.abs(x - lArc.circle.x) < epsilon$4
  14086. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  14087. previous = lArc.P;
  14088. disappearing.unshift(lArc);
  14089. detachBeach(lArc);
  14090. lArc = previous;
  14091. }
  14092. disappearing.unshift(lArc);
  14093. detachCircle(lArc);
  14094. var rArc = next;
  14095. while (rArc.circle
  14096. && Math.abs(x - rArc.circle.x) < epsilon$4
  14097. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  14098. next = rArc.N;
  14099. disappearing.push(rArc);
  14100. detachBeach(rArc);
  14101. rArc = next;
  14102. }
  14103. disappearing.push(rArc);
  14104. detachCircle(rArc);
  14105. var nArcs = disappearing.length,
  14106. iArc;
  14107. for (iArc = 1; iArc < nArcs; ++iArc) {
  14108. rArc = disappearing[iArc];
  14109. lArc = disappearing[iArc - 1];
  14110. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  14111. }
  14112. lArc = disappearing[0];
  14113. rArc = disappearing[nArcs - 1];
  14114. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  14115. attachCircle(lArc);
  14116. attachCircle(rArc);
  14117. }
  14118. function addBeach(site) {
  14119. var x = site[0],
  14120. directrix = site[1],
  14121. lArc,
  14122. rArc,
  14123. dxl,
  14124. dxr,
  14125. node = beaches._;
  14126. while (node) {
  14127. dxl = leftBreakPoint(node, directrix) - x;
  14128. if (dxl > epsilon$4) node = node.L; else {
  14129. dxr = x - rightBreakPoint(node, directrix);
  14130. if (dxr > epsilon$4) {
  14131. if (!node.R) {
  14132. lArc = node;
  14133. break;
  14134. }
  14135. node = node.R;
  14136. } else {
  14137. if (dxl > -epsilon$4) {
  14138. lArc = node.P;
  14139. rArc = node;
  14140. } else if (dxr > -epsilon$4) {
  14141. lArc = node;
  14142. rArc = node.N;
  14143. } else {
  14144. lArc = rArc = node;
  14145. }
  14146. break;
  14147. }
  14148. }
  14149. }
  14150. createCell(site);
  14151. var newArc = createBeach(site);
  14152. beaches.insert(lArc, newArc);
  14153. if (!lArc && !rArc) return;
  14154. if (lArc === rArc) {
  14155. detachCircle(lArc);
  14156. rArc = createBeach(lArc.site);
  14157. beaches.insert(newArc, rArc);
  14158. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  14159. attachCircle(lArc);
  14160. attachCircle(rArc);
  14161. return;
  14162. }
  14163. if (!rArc) { // && lArc
  14164. newArc.edge = createEdge(lArc.site, newArc.site);
  14165. return;
  14166. }
  14167. // else lArc !== rArc
  14168. detachCircle(lArc);
  14169. detachCircle(rArc);
  14170. var lSite = lArc.site,
  14171. ax = lSite[0],
  14172. ay = lSite[1],
  14173. bx = site[0] - ax,
  14174. by = site[1] - ay,
  14175. rSite = rArc.site,
  14176. cx = rSite[0] - ax,
  14177. cy = rSite[1] - ay,
  14178. d = 2 * (bx * cy - by * cx),
  14179. hb = bx * bx + by * by,
  14180. hc = cx * cx + cy * cy,
  14181. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  14182. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  14183. newArc.edge = createEdge(lSite, site, null, vertex);
  14184. rArc.edge = createEdge(site, rSite, null, vertex);
  14185. attachCircle(lArc);
  14186. attachCircle(rArc);
  14187. }
  14188. function leftBreakPoint(arc, directrix) {
  14189. var site = arc.site,
  14190. rfocx = site[0],
  14191. rfocy = site[1],
  14192. pby2 = rfocy - directrix;
  14193. if (!pby2) return rfocx;
  14194. var lArc = arc.P;
  14195. if (!lArc) return -Infinity;
  14196. site = lArc.site;
  14197. var lfocx = site[0],
  14198. lfocy = site[1],
  14199. plby2 = lfocy - directrix;
  14200. if (!plby2) return lfocx;
  14201. var hl = lfocx - rfocx,
  14202. aby2 = 1 / pby2 - 1 / plby2,
  14203. b = hl / plby2;
  14204. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  14205. return (rfocx + lfocx) / 2;
  14206. }
  14207. function rightBreakPoint(arc, directrix) {
  14208. var rArc = arc.N;
  14209. if (rArc) return leftBreakPoint(rArc, directrix);
  14210. var site = arc.site;
  14211. return site[1] === directrix ? site[0] : Infinity;
  14212. }
  14213. var epsilon$4 = 1e-6;
  14214. var epsilon2$2 = 1e-12;
  14215. var beaches;
  14216. var cells;
  14217. var circles;
  14218. var edges;
  14219. function triangleArea(a, b, c) {
  14220. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  14221. }
  14222. function lexicographic(a, b) {
  14223. return b[1] - a[1]
  14224. || b[0] - a[0];
  14225. }
  14226. function Diagram(sites, extent) {
  14227. var site = sites.sort(lexicographic).pop(),
  14228. x,
  14229. y,
  14230. circle;
  14231. edges = [];
  14232. cells = new Array(sites.length);
  14233. beaches = new RedBlackTree;
  14234. circles = new RedBlackTree;
  14235. while (true) {
  14236. circle = firstCircle;
  14237. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  14238. if (site[0] !== x || site[1] !== y) {
  14239. addBeach(site);
  14240. x = site[0], y = site[1];
  14241. }
  14242. site = sites.pop();
  14243. } else if (circle) {
  14244. removeBeach(circle.arc);
  14245. } else {
  14246. break;
  14247. }
  14248. }
  14249. sortCellHalfedges();
  14250. if (extent) {
  14251. var x0 = +extent[0][0],
  14252. y0 = +extent[0][1],
  14253. x1 = +extent[1][0],
  14254. y1 = +extent[1][1];
  14255. clipEdges(x0, y0, x1, y1);
  14256. clipCells(x0, y0, x1, y1);
  14257. }
  14258. this.edges = edges;
  14259. this.cells = cells;
  14260. beaches =
  14261. circles =
  14262. edges =
  14263. cells = null;
  14264. }
  14265. Diagram.prototype = {
  14266. constructor: Diagram,
  14267. polygons: function() {
  14268. var edges = this.edges;
  14269. return this.cells.map(function(cell) {
  14270. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  14271. polygon.data = cell.site.data;
  14272. return polygon;
  14273. });
  14274. },
  14275. triangles: function() {
  14276. var triangles = [],
  14277. edges = this.edges;
  14278. this.cells.forEach(function(cell, i) {
  14279. if (!(m = (halfedges = cell.halfedges).length)) return;
  14280. var site = cell.site,
  14281. halfedges,
  14282. j = -1,
  14283. m,
  14284. s0,
  14285. e1 = edges[halfedges[m - 1]],
  14286. s1 = e1.left === site ? e1.right : e1.left;
  14287. while (++j < m) {
  14288. s0 = s1;
  14289. e1 = edges[halfedges[j]];
  14290. s1 = e1.left === site ? e1.right : e1.left;
  14291. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  14292. triangles.push([site.data, s0.data, s1.data]);
  14293. }
  14294. }
  14295. });
  14296. return triangles;
  14297. },
  14298. links: function() {
  14299. return this.edges.filter(function(edge) {
  14300. return edge.right;
  14301. }).map(function(edge) {
  14302. return {
  14303. source: edge.left.data,
  14304. target: edge.right.data
  14305. };
  14306. });
  14307. },
  14308. find: function(x, y, radius) {
  14309. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  14310. // Use the previously-found cell, or start with an arbitrary one.
  14311. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  14312. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  14313. // Traverse the half-edges to find a closer cell, if any.
  14314. do {
  14315. cell = that.cells[i0 = i1], i1 = null;
  14316. cell.halfedges.forEach(function(e) {
  14317. var edge = that.edges[e], v = edge.left;
  14318. if ((v === cell.site || !v) && !(v = edge.right)) return;
  14319. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  14320. if (v2 < d2) d2 = v2, i1 = v.index;
  14321. });
  14322. } while (i1 !== null);
  14323. that._found = i0;
  14324. return radius == null || d2 <= radius * radius ? cell.site : null;
  14325. }
  14326. };
  14327. function voronoi() {
  14328. var x$$1 = x$4,
  14329. y$$1 = y$4,
  14330. extent = null;
  14331. function voronoi(data) {
  14332. return new Diagram(data.map(function(d, i) {
  14333. var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
  14334. s.index = i;
  14335. s.data = d;
  14336. return s;
  14337. }), extent);
  14338. }
  14339. voronoi.polygons = function(data) {
  14340. return voronoi(data).polygons();
  14341. };
  14342. voronoi.links = function(data) {
  14343. return voronoi(data).links();
  14344. };
  14345. voronoi.triangles = function(data) {
  14346. return voronoi(data).triangles();
  14347. };
  14348. voronoi.x = function(_) {
  14349. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$c(+_), voronoi) : x$$1;
  14350. };
  14351. voronoi.y = function(_) {
  14352. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$c(+_), voronoi) : y$$1;
  14353. };
  14354. voronoi.extent = function(_) {
  14355. 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]]];
  14356. };
  14357. voronoi.size = function(_) {
  14358. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  14359. };
  14360. return voronoi;
  14361. }
  14362. function constant$d(x) {
  14363. return function() {
  14364. return x;
  14365. };
  14366. }
  14367. function ZoomEvent(target, type, transform) {
  14368. this.target = target;
  14369. this.type = type;
  14370. this.transform = transform;
  14371. }
  14372. function Transform(k, x, y) {
  14373. this.k = k;
  14374. this.x = x;
  14375. this.y = y;
  14376. }
  14377. Transform.prototype = {
  14378. constructor: Transform,
  14379. scale: function(k) {
  14380. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  14381. },
  14382. translate: function(x, y) {
  14383. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  14384. },
  14385. apply: function(point) {
  14386. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  14387. },
  14388. applyX: function(x) {
  14389. return x * this.k + this.x;
  14390. },
  14391. applyY: function(y) {
  14392. return y * this.k + this.y;
  14393. },
  14394. invert: function(location) {
  14395. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  14396. },
  14397. invertX: function(x) {
  14398. return (x - this.x) / this.k;
  14399. },
  14400. invertY: function(y) {
  14401. return (y - this.y) / this.k;
  14402. },
  14403. rescaleX: function(x) {
  14404. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  14405. },
  14406. rescaleY: function(y) {
  14407. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  14408. },
  14409. toString: function() {
  14410. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  14411. }
  14412. };
  14413. var identity$8 = new Transform(1, 0, 0);
  14414. transform$1.prototype = Transform.prototype;
  14415. function transform$1(node) {
  14416. return node.__zoom || identity$8;
  14417. }
  14418. function nopropagation$2() {
  14419. exports.event.stopImmediatePropagation();
  14420. }
  14421. function noevent$2() {
  14422. exports.event.preventDefault();
  14423. exports.event.stopImmediatePropagation();
  14424. }
  14425. // Ignore right-click, since that should open the context menu.
  14426. function defaultFilter$2() {
  14427. return !exports.event.button;
  14428. }
  14429. function defaultExtent$1() {
  14430. var e = this, w, h;
  14431. if (e instanceof SVGElement) {
  14432. e = e.ownerSVGElement || e;
  14433. w = e.width.baseVal.value;
  14434. h = e.height.baseVal.value;
  14435. } else {
  14436. w = e.clientWidth;
  14437. h = e.clientHeight;
  14438. }
  14439. return [[0, 0], [w, h]];
  14440. }
  14441. function defaultTransform() {
  14442. return this.__zoom || identity$8;
  14443. }
  14444. function defaultWheelDelta() {
  14445. return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
  14446. }
  14447. function defaultTouchable$1() {
  14448. return "ontouchstart" in this;
  14449. }
  14450. function defaultConstrain(transform, extent, translateExtent) {
  14451. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  14452. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  14453. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  14454. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  14455. return transform.translate(
  14456. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  14457. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  14458. );
  14459. }
  14460. function zoom() {
  14461. var filter = defaultFilter$2,
  14462. extent = defaultExtent$1,
  14463. constrain = defaultConstrain,
  14464. wheelDelta = defaultWheelDelta,
  14465. touchable = defaultTouchable$1,
  14466. scaleExtent = [0, Infinity],
  14467. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  14468. duration = 250,
  14469. interpolate = interpolateZoom,
  14470. gestures = [],
  14471. listeners = dispatch("start", "zoom", "end"),
  14472. touchstarting,
  14473. touchending,
  14474. touchDelay = 500,
  14475. wheelDelay = 150,
  14476. clickDistance2 = 0;
  14477. function zoom(selection$$1) {
  14478. selection$$1
  14479. .property("__zoom", defaultTransform)
  14480. .on("wheel.zoom", wheeled)
  14481. .on("mousedown.zoom", mousedowned)
  14482. .on("dblclick.zoom", dblclicked)
  14483. .filter(touchable)
  14484. .on("touchstart.zoom", touchstarted)
  14485. .on("touchmove.zoom", touchmoved)
  14486. .on("touchend.zoom touchcancel.zoom", touchended)
  14487. .style("touch-action", "none")
  14488. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  14489. }
  14490. zoom.transform = function(collection, transform) {
  14491. var selection$$1 = collection.selection ? collection.selection() : collection;
  14492. selection$$1.property("__zoom", defaultTransform);
  14493. if (collection !== selection$$1) {
  14494. schedule(collection, transform);
  14495. } else {
  14496. selection$$1.interrupt().each(function() {
  14497. gesture(this, arguments)
  14498. .start()
  14499. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  14500. .end();
  14501. });
  14502. }
  14503. };
  14504. zoom.scaleBy = function(selection$$1, k) {
  14505. zoom.scaleTo(selection$$1, function() {
  14506. var k0 = this.__zoom.k,
  14507. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14508. return k0 * k1;
  14509. });
  14510. };
  14511. zoom.scaleTo = function(selection$$1, k) {
  14512. zoom.transform(selection$$1, function() {
  14513. var e = extent.apply(this, arguments),
  14514. t0 = this.__zoom,
  14515. p0 = centroid(e),
  14516. p1 = t0.invert(p0),
  14517. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14518. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  14519. });
  14520. };
  14521. zoom.translateBy = function(selection$$1, x, y) {
  14522. zoom.transform(selection$$1, function() {
  14523. return constrain(this.__zoom.translate(
  14524. typeof x === "function" ? x.apply(this, arguments) : x,
  14525. typeof y === "function" ? y.apply(this, arguments) : y
  14526. ), extent.apply(this, arguments), translateExtent);
  14527. });
  14528. };
  14529. zoom.translateTo = function(selection$$1, x, y) {
  14530. zoom.transform(selection$$1, function() {
  14531. var e = extent.apply(this, arguments),
  14532. t = this.__zoom,
  14533. p = centroid(e);
  14534. return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
  14535. typeof x === "function" ? -x.apply(this, arguments) : -x,
  14536. typeof y === "function" ? -y.apply(this, arguments) : -y
  14537. ), e, translateExtent);
  14538. });
  14539. };
  14540. function scale(transform, k) {
  14541. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  14542. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  14543. }
  14544. function translate(transform, p0, p1) {
  14545. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  14546. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  14547. }
  14548. function centroid(extent) {
  14549. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  14550. }
  14551. function schedule(transition$$1, transform, center) {
  14552. transition$$1
  14553. .on("start.zoom", function() { gesture(this, arguments).start(); })
  14554. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  14555. .tween("zoom", function() {
  14556. var that = this,
  14557. args = arguments,
  14558. g = gesture(that, args),
  14559. e = extent.apply(that, args),
  14560. p = center || centroid(e),
  14561. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  14562. a = that.__zoom,
  14563. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  14564. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  14565. return function(t) {
  14566. if (t === 1) t = b; // Avoid rounding error on end.
  14567. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  14568. g.zoom(null, t);
  14569. };
  14570. });
  14571. }
  14572. function gesture(that, args) {
  14573. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  14574. if ((g = gestures[i]).that === that) {
  14575. return g;
  14576. }
  14577. }
  14578. return new Gesture(that, args);
  14579. }
  14580. function Gesture(that, args) {
  14581. this.that = that;
  14582. this.args = args;
  14583. this.index = -1;
  14584. this.active = 0;
  14585. this.extent = extent.apply(that, args);
  14586. }
  14587. Gesture.prototype = {
  14588. start: function() {
  14589. if (++this.active === 1) {
  14590. this.index = gestures.push(this) - 1;
  14591. this.emit("start");
  14592. }
  14593. return this;
  14594. },
  14595. zoom: function(key, transform) {
  14596. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  14597. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  14598. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  14599. this.that.__zoom = transform;
  14600. this.emit("zoom");
  14601. return this;
  14602. },
  14603. end: function() {
  14604. if (--this.active === 0) {
  14605. gestures.splice(this.index, 1);
  14606. this.index = -1;
  14607. this.emit("end");
  14608. }
  14609. return this;
  14610. },
  14611. emit: function(type) {
  14612. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  14613. }
  14614. };
  14615. function wheeled() {
  14616. if (!filter.apply(this, arguments)) return;
  14617. var g = gesture(this, arguments),
  14618. t = this.__zoom,
  14619. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  14620. p = mouse(this);
  14621. // If the mouse is in the same location as before, reuse it.
  14622. // If there were recent wheel events, reset the wheel idle timeout.
  14623. if (g.wheel) {
  14624. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  14625. g.mouse[1] = t.invert(g.mouse[0] = p);
  14626. }
  14627. clearTimeout(g.wheel);
  14628. }
  14629. // If this wheel event won’t trigger a transform change, ignore it.
  14630. else if (t.k === k) return;
  14631. // Otherwise, capture the mouse point and location at the start.
  14632. else {
  14633. g.mouse = [p, t.invert(p)];
  14634. interrupt(this);
  14635. g.start();
  14636. }
  14637. noevent$2();
  14638. g.wheel = setTimeout(wheelidled, wheelDelay);
  14639. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  14640. function wheelidled() {
  14641. g.wheel = null;
  14642. g.end();
  14643. }
  14644. }
  14645. function mousedowned() {
  14646. if (touchending || !filter.apply(this, arguments)) return;
  14647. var g = gesture(this, arguments),
  14648. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  14649. p = mouse(this),
  14650. x0 = exports.event.clientX,
  14651. y0 = exports.event.clientY;
  14652. dragDisable(exports.event.view);
  14653. nopropagation$2();
  14654. g.mouse = [p, this.__zoom.invert(p)];
  14655. interrupt(this);
  14656. g.start();
  14657. function mousemoved() {
  14658. noevent$2();
  14659. if (!g.moved) {
  14660. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  14661. g.moved = dx * dx + dy * dy > clickDistance2;
  14662. }
  14663. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  14664. }
  14665. function mouseupped() {
  14666. v.on("mousemove.zoom mouseup.zoom", null);
  14667. yesdrag(exports.event.view, g.moved);
  14668. noevent$2();
  14669. g.end();
  14670. }
  14671. }
  14672. function dblclicked() {
  14673. if (!filter.apply(this, arguments)) return;
  14674. var t0 = this.__zoom,
  14675. p0 = mouse(this),
  14676. p1 = t0.invert(p0),
  14677. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  14678. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  14679. noevent$2();
  14680. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  14681. else select(this).call(zoom.transform, t1);
  14682. }
  14683. function touchstarted() {
  14684. if (!filter.apply(this, arguments)) return;
  14685. var g = gesture(this, arguments),
  14686. touches$$1 = exports.event.changedTouches,
  14687. started,
  14688. n = touches$$1.length, i, t, p;
  14689. nopropagation$2();
  14690. for (i = 0; i < n; ++i) {
  14691. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14692. p = [p, this.__zoom.invert(p), t.identifier];
  14693. if (!g.touch0) g.touch0 = p, started = true;
  14694. else if (!g.touch1) g.touch1 = p;
  14695. }
  14696. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  14697. if (touchstarting) {
  14698. touchstarting = clearTimeout(touchstarting);
  14699. if (!g.touch1) {
  14700. g.end();
  14701. p = select(this).on("dblclick.zoom");
  14702. if (p) p.apply(this, arguments);
  14703. return;
  14704. }
  14705. }
  14706. if (started) {
  14707. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  14708. interrupt(this);
  14709. g.start();
  14710. }
  14711. }
  14712. function touchmoved() {
  14713. var g = gesture(this, arguments),
  14714. touches$$1 = exports.event.changedTouches,
  14715. n = touches$$1.length, i, t, p, l;
  14716. noevent$2();
  14717. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  14718. for (i = 0; i < n; ++i) {
  14719. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14720. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  14721. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  14722. }
  14723. t = g.that.__zoom;
  14724. if (g.touch1) {
  14725. var p0 = g.touch0[0], l0 = g.touch0[1],
  14726. p1 = g.touch1[0], l1 = g.touch1[1],
  14727. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  14728. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  14729. t = scale(t, Math.sqrt(dp / dl));
  14730. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  14731. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  14732. }
  14733. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  14734. else return;
  14735. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  14736. }
  14737. function touchended() {
  14738. var g = gesture(this, arguments),
  14739. touches$$1 = exports.event.changedTouches,
  14740. n = touches$$1.length, i, t;
  14741. nopropagation$2();
  14742. if (touchending) clearTimeout(touchending);
  14743. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  14744. for (i = 0; i < n; ++i) {
  14745. t = touches$$1[i];
  14746. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  14747. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  14748. }
  14749. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  14750. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  14751. else g.end();
  14752. }
  14753. zoom.wheelDelta = function(_) {
  14754. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$d(+_), zoom) : wheelDelta;
  14755. };
  14756. zoom.filter = function(_) {
  14757. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$d(!!_), zoom) : filter;
  14758. };
  14759. zoom.touchable = function(_) {
  14760. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$d(!!_), zoom) : touchable;
  14761. };
  14762. zoom.extent = function(_) {
  14763. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$d([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  14764. };
  14765. zoom.scaleExtent = function(_) {
  14766. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  14767. };
  14768. zoom.translateExtent = function(_) {
  14769. return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
  14770. };
  14771. zoom.constrain = function(_) {
  14772. return arguments.length ? (constrain = _, zoom) : constrain;
  14773. };
  14774. zoom.duration = function(_) {
  14775. return arguments.length ? (duration = +_, zoom) : duration;
  14776. };
  14777. zoom.interpolate = function(_) {
  14778. return arguments.length ? (interpolate = _, zoom) : interpolate;
  14779. };
  14780. zoom.on = function() {
  14781. var value = listeners.on.apply(listeners, arguments);
  14782. return value === listeners ? zoom : value;
  14783. };
  14784. zoom.clickDistance = function(_) {
  14785. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  14786. };
  14787. return zoom;
  14788. }
  14789. exports.version = version;
  14790. exports.bisect = bisectRight;
  14791. exports.bisectRight = bisectRight;
  14792. exports.bisectLeft = bisectLeft;
  14793. exports.ascending = ascending;
  14794. exports.bisector = bisector;
  14795. exports.cross = cross;
  14796. exports.descending = descending;
  14797. exports.deviation = deviation;
  14798. exports.extent = extent;
  14799. exports.histogram = histogram;
  14800. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  14801. exports.thresholdScott = scott;
  14802. exports.thresholdSturges = thresholdSturges;
  14803. exports.max = max;
  14804. exports.mean = mean;
  14805. exports.median = median;
  14806. exports.merge = merge;
  14807. exports.min = min;
  14808. exports.pairs = pairs;
  14809. exports.permute = permute;
  14810. exports.quantile = threshold;
  14811. exports.range = sequence;
  14812. exports.scan = scan;
  14813. exports.shuffle = shuffle;
  14814. exports.sum = sum;
  14815. exports.ticks = ticks;
  14816. exports.tickIncrement = tickIncrement;
  14817. exports.tickStep = tickStep;
  14818. exports.transpose = transpose;
  14819. exports.variance = variance;
  14820. exports.zip = zip;
  14821. exports.axisTop = axisTop;
  14822. exports.axisRight = axisRight;
  14823. exports.axisBottom = axisBottom;
  14824. exports.axisLeft = axisLeft;
  14825. exports.brush = brush;
  14826. exports.brushX = brushX;
  14827. exports.brushY = brushY;
  14828. exports.brushSelection = brushSelection;
  14829. exports.chord = chord;
  14830. exports.ribbon = ribbon;
  14831. exports.nest = nest;
  14832. exports.set = set$2;
  14833. exports.map = map$1;
  14834. exports.keys = keys;
  14835. exports.values = values;
  14836. exports.entries = entries;
  14837. exports.color = color;
  14838. exports.rgb = rgb;
  14839. exports.hsl = hsl;
  14840. exports.lab = lab;
  14841. exports.hcl = hcl;
  14842. exports.lch = lch;
  14843. exports.gray = gray;
  14844. exports.cubehelix = cubehelix;
  14845. exports.contours = contours;
  14846. exports.contourDensity = density;
  14847. exports.dispatch = dispatch;
  14848. exports.drag = drag;
  14849. exports.dragDisable = dragDisable;
  14850. exports.dragEnable = yesdrag;
  14851. exports.dsvFormat = dsv;
  14852. exports.csvParse = csvParse;
  14853. exports.csvParseRows = csvParseRows;
  14854. exports.csvFormat = csvFormat;
  14855. exports.csvFormatRows = csvFormatRows;
  14856. exports.tsvParse = tsvParse;
  14857. exports.tsvParseRows = tsvParseRows;
  14858. exports.tsvFormat = tsvFormat;
  14859. exports.tsvFormatRows = tsvFormatRows;
  14860. exports.easeLinear = linear$1;
  14861. exports.easeQuad = quadInOut;
  14862. exports.easeQuadIn = quadIn;
  14863. exports.easeQuadOut = quadOut;
  14864. exports.easeQuadInOut = quadInOut;
  14865. exports.easeCubic = cubicInOut;
  14866. exports.easeCubicIn = cubicIn;
  14867. exports.easeCubicOut = cubicOut;
  14868. exports.easeCubicInOut = cubicInOut;
  14869. exports.easePoly = polyInOut;
  14870. exports.easePolyIn = polyIn;
  14871. exports.easePolyOut = polyOut;
  14872. exports.easePolyInOut = polyInOut;
  14873. exports.easeSin = sinInOut;
  14874. exports.easeSinIn = sinIn;
  14875. exports.easeSinOut = sinOut;
  14876. exports.easeSinInOut = sinInOut;
  14877. exports.easeExp = expInOut;
  14878. exports.easeExpIn = expIn;
  14879. exports.easeExpOut = expOut;
  14880. exports.easeExpInOut = expInOut;
  14881. exports.easeCircle = circleInOut;
  14882. exports.easeCircleIn = circleIn;
  14883. exports.easeCircleOut = circleOut;
  14884. exports.easeCircleInOut = circleInOut;
  14885. exports.easeBounce = bounceOut;
  14886. exports.easeBounceIn = bounceIn;
  14887. exports.easeBounceOut = bounceOut;
  14888. exports.easeBounceInOut = bounceInOut;
  14889. exports.easeBack = backInOut;
  14890. exports.easeBackIn = backIn;
  14891. exports.easeBackOut = backOut;
  14892. exports.easeBackInOut = backInOut;
  14893. exports.easeElastic = elasticOut;
  14894. exports.easeElasticIn = elasticIn;
  14895. exports.easeElasticOut = elasticOut;
  14896. exports.easeElasticInOut = elasticInOut;
  14897. exports.blob = blob;
  14898. exports.buffer = buffer;
  14899. exports.dsv = dsv$1;
  14900. exports.csv = csv$1;
  14901. exports.tsv = tsv$1;
  14902. exports.image = image;
  14903. exports.json = json;
  14904. exports.text = text;
  14905. exports.xml = xml;
  14906. exports.html = html;
  14907. exports.svg = svg;
  14908. exports.forceCenter = center$1;
  14909. exports.forceCollide = collide;
  14910. exports.forceLink = link;
  14911. exports.forceManyBody = manyBody;
  14912. exports.forceRadial = radial;
  14913. exports.forceSimulation = simulation;
  14914. exports.forceX = x$2;
  14915. exports.forceY = y$2;
  14916. exports.formatDefaultLocale = defaultLocale;
  14917. exports.formatLocale = formatLocale;
  14918. exports.formatSpecifier = formatSpecifier;
  14919. exports.precisionFixed = precisionFixed;
  14920. exports.precisionPrefix = precisionPrefix;
  14921. exports.precisionRound = precisionRound;
  14922. exports.geoArea = area$1;
  14923. exports.geoBounds = bounds;
  14924. exports.geoCentroid = centroid;
  14925. exports.geoCircle = circle;
  14926. exports.geoClipAntimeridian = clipAntimeridian;
  14927. exports.geoClipCircle = clipCircle;
  14928. exports.geoClipExtent = extent$1;
  14929. exports.geoClipRectangle = clipRectangle;
  14930. exports.geoContains = contains$1;
  14931. exports.geoDistance = distance;
  14932. exports.geoGraticule = graticule;
  14933. exports.geoGraticule10 = graticule10;
  14934. exports.geoInterpolate = interpolate$1;
  14935. exports.geoLength = length$1;
  14936. exports.geoPath = index$1;
  14937. exports.geoAlbers = albers;
  14938. exports.geoAlbersUsa = albersUsa;
  14939. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  14940. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  14941. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  14942. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  14943. exports.geoConicConformal = conicConformal;
  14944. exports.geoConicConformalRaw = conicConformalRaw;
  14945. exports.geoConicEqualArea = conicEqualArea;
  14946. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  14947. exports.geoConicEquidistant = conicEquidistant;
  14948. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  14949. exports.geoEquirectangular = equirectangular;
  14950. exports.geoEquirectangularRaw = equirectangularRaw;
  14951. exports.geoGnomonic = gnomonic;
  14952. exports.geoGnomonicRaw = gnomonicRaw;
  14953. exports.geoIdentity = identity$5;
  14954. exports.geoProjection = projection;
  14955. exports.geoProjectionMutator = projectionMutator;
  14956. exports.geoMercator = mercator;
  14957. exports.geoMercatorRaw = mercatorRaw;
  14958. exports.geoNaturalEarth1 = naturalEarth1;
  14959. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  14960. exports.geoOrthographic = orthographic;
  14961. exports.geoOrthographicRaw = orthographicRaw;
  14962. exports.geoStereographic = stereographic;
  14963. exports.geoStereographicRaw = stereographicRaw;
  14964. exports.geoTransverseMercator = transverseMercator;
  14965. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  14966. exports.geoRotation = rotation;
  14967. exports.geoStream = geoStream;
  14968. exports.geoTransform = transform;
  14969. exports.cluster = cluster;
  14970. exports.hierarchy = hierarchy;
  14971. exports.pack = index$2;
  14972. exports.packSiblings = siblings;
  14973. exports.packEnclose = enclose;
  14974. exports.partition = partition;
  14975. exports.stratify = stratify;
  14976. exports.tree = tree;
  14977. exports.treemap = index$3;
  14978. exports.treemapBinary = binary;
  14979. exports.treemapDice = treemapDice;
  14980. exports.treemapSlice = treemapSlice;
  14981. exports.treemapSliceDice = sliceDice;
  14982. exports.treemapSquarify = squarify;
  14983. exports.treemapResquarify = resquarify;
  14984. exports.interpolate = interpolateValue;
  14985. exports.interpolateArray = array$1;
  14986. exports.interpolateBasis = basis$1;
  14987. exports.interpolateBasisClosed = basisClosed;
  14988. exports.interpolateDate = date;
  14989. exports.interpolateNumber = interpolateNumber;
  14990. exports.interpolateObject = object;
  14991. exports.interpolateRound = interpolateRound;
  14992. exports.interpolateString = interpolateString;
  14993. exports.interpolateTransformCss = interpolateTransformCss;
  14994. exports.interpolateTransformSvg = interpolateTransformSvg;
  14995. exports.interpolateZoom = interpolateZoom;
  14996. exports.interpolateRgb = interpolateRgb;
  14997. exports.interpolateRgbBasis = rgbBasis;
  14998. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  14999. exports.interpolateHsl = hsl$2;
  15000. exports.interpolateHslLong = hslLong;
  15001. exports.interpolateLab = lab$1;
  15002. exports.interpolateHcl = hcl$2;
  15003. exports.interpolateHclLong = hclLong;
  15004. exports.interpolateCubehelix = cubehelix$2;
  15005. exports.interpolateCubehelixLong = cubehelixLong;
  15006. exports.piecewise = piecewise;
  15007. exports.quantize = quantize;
  15008. exports.path = path;
  15009. exports.polygonArea = area$2;
  15010. exports.polygonCentroid = centroid$1;
  15011. exports.polygonHull = hull;
  15012. exports.polygonContains = contains$2;
  15013. exports.polygonLength = length$2;
  15014. exports.quadtree = quadtree;
  15015. exports.randomUniform = uniform;
  15016. exports.randomNormal = normal;
  15017. exports.randomLogNormal = logNormal;
  15018. exports.randomBates = bates;
  15019. exports.randomIrwinHall = irwinHall;
  15020. exports.randomExponential = exponential$1;
  15021. exports.scaleBand = band;
  15022. exports.scalePoint = point$1;
  15023. exports.scaleIdentity = identity$6;
  15024. exports.scaleLinear = linear$2;
  15025. exports.scaleLog = log$1;
  15026. exports.scaleOrdinal = ordinal;
  15027. exports.scaleImplicit = implicit;
  15028. exports.scalePow = pow$1;
  15029. exports.scaleSqrt = sqrt$1;
  15030. exports.scaleQuantile = quantile$$1;
  15031. exports.scaleQuantize = quantize$1;
  15032. exports.scaleThreshold = threshold$1;
  15033. exports.scaleTime = time;
  15034. exports.scaleUtc = utcTime;
  15035. exports.scaleSequential = sequential;
  15036. exports.scaleDiverging = diverging;
  15037. exports.schemeCategory10 = category10;
  15038. exports.schemeAccent = Accent;
  15039. exports.schemeDark2 = Dark2;
  15040. exports.schemePaired = Paired;
  15041. exports.schemePastel1 = Pastel1;
  15042. exports.schemePastel2 = Pastel2;
  15043. exports.schemeSet1 = Set1;
  15044. exports.schemeSet2 = Set2;
  15045. exports.schemeSet3 = Set3;
  15046. exports.interpolateBrBG = BrBG;
  15047. exports.schemeBrBG = scheme;
  15048. exports.interpolatePRGn = PRGn;
  15049. exports.schemePRGn = scheme$1;
  15050. exports.interpolatePiYG = PiYG;
  15051. exports.schemePiYG = scheme$2;
  15052. exports.interpolatePuOr = PuOr;
  15053. exports.schemePuOr = scheme$3;
  15054. exports.interpolateRdBu = RdBu;
  15055. exports.schemeRdBu = scheme$4;
  15056. exports.interpolateRdGy = RdGy;
  15057. exports.schemeRdGy = scheme$5;
  15058. exports.interpolateRdYlBu = RdYlBu;
  15059. exports.schemeRdYlBu = scheme$6;
  15060. exports.interpolateRdYlGn = RdYlGn;
  15061. exports.schemeRdYlGn = scheme$7;
  15062. exports.interpolateSpectral = Spectral;
  15063. exports.schemeSpectral = scheme$8;
  15064. exports.interpolateBuGn = BuGn;
  15065. exports.schemeBuGn = scheme$9;
  15066. exports.interpolateBuPu = BuPu;
  15067. exports.schemeBuPu = scheme$a;
  15068. exports.interpolateGnBu = GnBu;
  15069. exports.schemeGnBu = scheme$b;
  15070. exports.interpolateOrRd = OrRd;
  15071. exports.schemeOrRd = scheme$c;
  15072. exports.interpolatePuBuGn = PuBuGn;
  15073. exports.schemePuBuGn = scheme$d;
  15074. exports.interpolatePuBu = PuBu;
  15075. exports.schemePuBu = scheme$e;
  15076. exports.interpolatePuRd = PuRd;
  15077. exports.schemePuRd = scheme$f;
  15078. exports.interpolateRdPu = RdPu;
  15079. exports.schemeRdPu = scheme$g;
  15080. exports.interpolateYlGnBu = YlGnBu;
  15081. exports.schemeYlGnBu = scheme$h;
  15082. exports.interpolateYlGn = YlGn;
  15083. exports.schemeYlGn = scheme$i;
  15084. exports.interpolateYlOrBr = YlOrBr;
  15085. exports.schemeYlOrBr = scheme$j;
  15086. exports.interpolateYlOrRd = YlOrRd;
  15087. exports.schemeYlOrRd = scheme$k;
  15088. exports.interpolateBlues = Blues;
  15089. exports.schemeBlues = scheme$l;
  15090. exports.interpolateGreens = Greens;
  15091. exports.schemeGreens = scheme$m;
  15092. exports.interpolateGreys = Greys;
  15093. exports.schemeGreys = scheme$n;
  15094. exports.interpolatePurples = Purples;
  15095. exports.schemePurples = scheme$o;
  15096. exports.interpolateReds = Reds;
  15097. exports.schemeReds = scheme$p;
  15098. exports.interpolateOranges = Oranges;
  15099. exports.schemeOranges = scheme$q;
  15100. exports.interpolateCubehelixDefault = cubehelix$3;
  15101. exports.interpolateRainbow = rainbow;
  15102. exports.interpolateWarm = warm;
  15103. exports.interpolateCool = cool;
  15104. exports.interpolateSinebow = sinebow;
  15105. exports.interpolateViridis = viridis;
  15106. exports.interpolateMagma = magma;
  15107. exports.interpolateInferno = inferno;
  15108. exports.interpolatePlasma = plasma;
  15109. exports.create = create;
  15110. exports.creator = creator;
  15111. exports.local = local;
  15112. exports.matcher = matcher$1;
  15113. exports.mouse = mouse;
  15114. exports.namespace = namespace;
  15115. exports.namespaces = namespaces;
  15116. exports.clientPoint = point;
  15117. exports.select = select;
  15118. exports.selectAll = selectAll;
  15119. exports.selection = selection;
  15120. exports.selector = selector;
  15121. exports.selectorAll = selectorAll;
  15122. exports.style = styleValue;
  15123. exports.touch = touch;
  15124. exports.touches = touches;
  15125. exports.window = defaultView;
  15126. exports.customEvent = customEvent;
  15127. exports.arc = arc;
  15128. exports.area = area$3;
  15129. exports.line = line;
  15130. exports.pie = pie;
  15131. exports.areaRadial = areaRadial;
  15132. exports.radialArea = areaRadial;
  15133. exports.lineRadial = lineRadial$1;
  15134. exports.radialLine = lineRadial$1;
  15135. exports.pointRadial = pointRadial;
  15136. exports.linkHorizontal = linkHorizontal;
  15137. exports.linkVertical = linkVertical;
  15138. exports.linkRadial = linkRadial;
  15139. exports.symbol = symbol;
  15140. exports.symbols = symbols;
  15141. exports.symbolCircle = circle$2;
  15142. exports.symbolCross = cross$2;
  15143. exports.symbolDiamond = diamond;
  15144. exports.symbolSquare = square;
  15145. exports.symbolStar = star;
  15146. exports.symbolTriangle = triangle;
  15147. exports.symbolWye = wye;
  15148. exports.curveBasisClosed = basisClosed$1;
  15149. exports.curveBasisOpen = basisOpen;
  15150. exports.curveBasis = basis$2;
  15151. exports.curveBundle = bundle;
  15152. exports.curveCardinalClosed = cardinalClosed;
  15153. exports.curveCardinalOpen = cardinalOpen;
  15154. exports.curveCardinal = cardinal;
  15155. exports.curveCatmullRomClosed = catmullRomClosed;
  15156. exports.curveCatmullRomOpen = catmullRomOpen;
  15157. exports.curveCatmullRom = catmullRom;
  15158. exports.curveLinearClosed = linearClosed;
  15159. exports.curveLinear = curveLinear;
  15160. exports.curveMonotoneX = monotoneX;
  15161. exports.curveMonotoneY = monotoneY;
  15162. exports.curveNatural = natural;
  15163. exports.curveStep = step;
  15164. exports.curveStepAfter = stepAfter;
  15165. exports.curveStepBefore = stepBefore;
  15166. exports.stack = stack;
  15167. exports.stackOffsetExpand = expand;
  15168. exports.stackOffsetDiverging = diverging$1;
  15169. exports.stackOffsetNone = none$1;
  15170. exports.stackOffsetSilhouette = silhouette;
  15171. exports.stackOffsetWiggle = wiggle;
  15172. exports.stackOrderAscending = ascending$3;
  15173. exports.stackOrderDescending = descending$2;
  15174. exports.stackOrderInsideOut = insideOut;
  15175. exports.stackOrderNone = none$2;
  15176. exports.stackOrderReverse = reverse;
  15177. exports.timeInterval = newInterval;
  15178. exports.timeMillisecond = millisecond;
  15179. exports.timeMilliseconds = milliseconds;
  15180. exports.utcMillisecond = millisecond;
  15181. exports.utcMilliseconds = milliseconds;
  15182. exports.timeSecond = second;
  15183. exports.timeSeconds = seconds;
  15184. exports.utcSecond = second;
  15185. exports.utcSeconds = seconds;
  15186. exports.timeMinute = minute;
  15187. exports.timeMinutes = minutes;
  15188. exports.timeHour = hour;
  15189. exports.timeHours = hours;
  15190. exports.timeDay = day;
  15191. exports.timeDays = days;
  15192. exports.timeWeek = sunday;
  15193. exports.timeWeeks = sundays;
  15194. exports.timeSunday = sunday;
  15195. exports.timeSundays = sundays;
  15196. exports.timeMonday = monday;
  15197. exports.timeMondays = mondays;
  15198. exports.timeTuesday = tuesday;
  15199. exports.timeTuesdays = tuesdays;
  15200. exports.timeWednesday = wednesday;
  15201. exports.timeWednesdays = wednesdays;
  15202. exports.timeThursday = thursday;
  15203. exports.timeThursdays = thursdays;
  15204. exports.timeFriday = friday;
  15205. exports.timeFridays = fridays;
  15206. exports.timeSaturday = saturday;
  15207. exports.timeSaturdays = saturdays;
  15208. exports.timeMonth = month;
  15209. exports.timeMonths = months;
  15210. exports.timeYear = year;
  15211. exports.timeYears = years;
  15212. exports.utcMinute = utcMinute;
  15213. exports.utcMinutes = utcMinutes;
  15214. exports.utcHour = utcHour;
  15215. exports.utcHours = utcHours;
  15216. exports.utcDay = utcDay;
  15217. exports.utcDays = utcDays;
  15218. exports.utcWeek = utcSunday;
  15219. exports.utcWeeks = utcSundays;
  15220. exports.utcSunday = utcSunday;
  15221. exports.utcSundays = utcSundays;
  15222. exports.utcMonday = utcMonday;
  15223. exports.utcMondays = utcMondays;
  15224. exports.utcTuesday = utcTuesday;
  15225. exports.utcTuesdays = utcTuesdays;
  15226. exports.utcWednesday = utcWednesday;
  15227. exports.utcWednesdays = utcWednesdays;
  15228. exports.utcThursday = utcThursday;
  15229. exports.utcThursdays = utcThursdays;
  15230. exports.utcFriday = utcFriday;
  15231. exports.utcFridays = utcFridays;
  15232. exports.utcSaturday = utcSaturday;
  15233. exports.utcSaturdays = utcSaturdays;
  15234. exports.utcMonth = utcMonth;
  15235. exports.utcMonths = utcMonths;
  15236. exports.utcYear = utcYear;
  15237. exports.utcYears = utcYears;
  15238. exports.timeFormatDefaultLocale = defaultLocale$1;
  15239. exports.timeFormatLocale = formatLocale$1;
  15240. exports.isoFormat = formatIso;
  15241. exports.isoParse = parseIso;
  15242. exports.now = now;
  15243. exports.timer = timer;
  15244. exports.timerFlush = timerFlush;
  15245. exports.timeout = timeout$1;
  15246. exports.interval = interval$1;
  15247. exports.transition = transition;
  15248. exports.active = active;
  15249. exports.interrupt = interrupt;
  15250. exports.voronoi = voronoi;
  15251. exports.zoom = zoom;
  15252. exports.zoomTransform = transform$1;
  15253. exports.zoomIdentity = identity$8;
  15254. Object.defineProperty(exports, '__esModule', { value: true });
  15255. })));