d3.js 484 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848
  1. // https://d3js.org Version 5.5.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.5.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", "#000"));
  524. tick = tick.merge(tickEnter);
  525. line = line.merge(tickEnter.append("line")
  526. .attr("stroke", "#000")
  527. .attr(x + "2", k * tickSizeInner));
  528. text = text.merge(tickEnter.append("text")
  529. .attr("fill", "#000")
  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 reinterpolate(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: reinterpolate(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" ? reinterpolate
  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. : reinterpolate)(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: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(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: reinterpolate(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: reinterpolate(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: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(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" ? reinterpolate
  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 density() {
  4750. var x = defaultX,
  4751. y = defaultY,
  4752. dx = 960,
  4753. dy = 500,
  4754. r = 20, // blur radius
  4755. k = 2, // log2(grid cell size)
  4756. o = r * 3, // grid offset, to pad for blur
  4757. n = (dx + o * 2) >> k, // grid width
  4758. m = (dy + o * 2) >> k, // grid height
  4759. threshold$$1 = constant$6(20);
  4760. function density(data) {
  4761. var values0 = new Float32Array(n * m),
  4762. values1 = new Float32Array(n * m);
  4763. data.forEach(function(d, i, data) {
  4764. var xi = (x(d, i, data) + o) >> k,
  4765. yi = (y(d, i, data) + o) >> k;
  4766. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  4767. ++values0[xi + yi * n];
  4768. }
  4769. });
  4770. // TODO Optimize.
  4771. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4772. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4773. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4774. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4775. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4776. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4777. var tz = threshold$$1(values0);
  4778. // Convert number of thresholds into uniform thresholds.
  4779. if (!Array.isArray(tz)) {
  4780. var stop = max(values0);
  4781. tz = tickStep(0, stop, tz);
  4782. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  4783. tz.shift();
  4784. }
  4785. return contours()
  4786. .thresholds(tz)
  4787. .size([n, m])
  4788. (values0)
  4789. .map(transform);
  4790. }
  4791. function transform(geometry) {
  4792. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  4793. geometry.coordinates.forEach(transformPolygon);
  4794. return geometry;
  4795. }
  4796. function transformPolygon(coordinates) {
  4797. coordinates.forEach(transformRing);
  4798. }
  4799. function transformRing(coordinates) {
  4800. coordinates.forEach(transformPoint);
  4801. }
  4802. // TODO Optimize.
  4803. function transformPoint(coordinates) {
  4804. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  4805. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  4806. }
  4807. function resize() {
  4808. o = r * 3;
  4809. n = (dx + o * 2) >> k;
  4810. m = (dy + o * 2) >> k;
  4811. return density;
  4812. }
  4813. density.x = function(_) {
  4814. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  4815. };
  4816. density.y = function(_) {
  4817. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  4818. };
  4819. density.size = function(_) {
  4820. if (!arguments.length) return [dx, dy];
  4821. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4822. if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
  4823. return dx = _0, dy = _1, resize();
  4824. };
  4825. density.cellSize = function(_) {
  4826. if (!arguments.length) return 1 << k;
  4827. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  4828. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  4829. };
  4830. density.thresholds = function(_) {
  4831. return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold$$1;
  4832. };
  4833. density.bandwidth = function(_) {
  4834. if (!arguments.length) return Math.sqrt(r * (r + 1));
  4835. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  4836. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  4837. };
  4838. return density;
  4839. }
  4840. var EOL = {},
  4841. EOF = {},
  4842. QUOTE = 34,
  4843. NEWLINE = 10,
  4844. RETURN = 13;
  4845. function objectConverter(columns) {
  4846. return new Function("d", "return {" + columns.map(function(name, i) {
  4847. return JSON.stringify(name) + ": d[" + i + "]";
  4848. }).join(",") + "}");
  4849. }
  4850. function customConverter(columns, f) {
  4851. var object = objectConverter(columns);
  4852. return function(row, i) {
  4853. return f(object(row), i, columns);
  4854. };
  4855. }
  4856. // Compute unique columns in order of discovery.
  4857. function inferColumns(rows) {
  4858. var columnSet = Object.create(null),
  4859. columns = [];
  4860. rows.forEach(function(row) {
  4861. for (var column in row) {
  4862. if (!(column in columnSet)) {
  4863. columns.push(columnSet[column] = column);
  4864. }
  4865. }
  4866. });
  4867. return columns;
  4868. }
  4869. function dsvFormat(delimiter) {
  4870. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  4871. DELIMITER = delimiter.charCodeAt(0);
  4872. function parse(text, f) {
  4873. var convert, columns, rows = parseRows(text, function(row, i) {
  4874. if (convert) return convert(row, i - 1);
  4875. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  4876. });
  4877. rows.columns = columns || [];
  4878. return rows;
  4879. }
  4880. function parseRows(text, f) {
  4881. var rows = [], // output rows
  4882. N = text.length,
  4883. I = 0, // current character index
  4884. n = 0, // current line number
  4885. t, // current token
  4886. eof = N <= 0, // current token followed by EOF?
  4887. eol = false; // current token followed by EOL?
  4888. // Strip the trailing newline.
  4889. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  4890. if (text.charCodeAt(N - 1) === RETURN) --N;
  4891. function token() {
  4892. if (eof) return EOF;
  4893. if (eol) return eol = false, EOL;
  4894. // Unescape quotes.
  4895. var i, j = I, c;
  4896. if (text.charCodeAt(j) === QUOTE) {
  4897. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  4898. if ((i = I) >= N) eof = true;
  4899. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  4900. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4901. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  4902. }
  4903. // Find next delimiter or newline.
  4904. while (I < N) {
  4905. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  4906. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4907. else if (c !== DELIMITER) continue;
  4908. return text.slice(j, i);
  4909. }
  4910. // Return last token before EOF.
  4911. return eof = true, text.slice(j, N);
  4912. }
  4913. while ((t = token()) !== EOF) {
  4914. var row = [];
  4915. while (t !== EOL && t !== EOF) row.push(t), t = token();
  4916. if (f && (row = f(row, n++)) == null) continue;
  4917. rows.push(row);
  4918. }
  4919. return rows;
  4920. }
  4921. function format(rows, columns) {
  4922. if (columns == null) columns = inferColumns(rows);
  4923. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4924. return columns.map(function(column) {
  4925. return formatValue(row[column]);
  4926. }).join(delimiter);
  4927. })).join("\n");
  4928. }
  4929. function formatRows(rows) {
  4930. return rows.map(formatRow).join("\n");
  4931. }
  4932. function formatRow(row) {
  4933. return row.map(formatValue).join(delimiter);
  4934. }
  4935. function formatValue(text) {
  4936. return text == null ? ""
  4937. : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
  4938. : text;
  4939. }
  4940. return {
  4941. parse: parse,
  4942. parseRows: parseRows,
  4943. format: format,
  4944. formatRows: formatRows
  4945. };
  4946. }
  4947. var csv = dsvFormat(",");
  4948. var csvParse = csv.parse;
  4949. var csvParseRows = csv.parseRows;
  4950. var csvFormat = csv.format;
  4951. var csvFormatRows = csv.formatRows;
  4952. var tsv = dsvFormat("\t");
  4953. var tsvParse = tsv.parse;
  4954. var tsvParseRows = tsv.parseRows;
  4955. var tsvFormat = tsv.format;
  4956. var tsvFormatRows = tsv.formatRows;
  4957. function responseBlob(response) {
  4958. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4959. return response.blob();
  4960. }
  4961. function blob(input, init) {
  4962. return fetch(input, init).then(responseBlob);
  4963. }
  4964. function responseArrayBuffer(response) {
  4965. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4966. return response.arrayBuffer();
  4967. }
  4968. function buffer(input, init) {
  4969. return fetch(input, init).then(responseArrayBuffer);
  4970. }
  4971. function responseText(response) {
  4972. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4973. return response.text();
  4974. }
  4975. function text(input, init) {
  4976. return fetch(input, init).then(responseText);
  4977. }
  4978. function dsvParse(parse) {
  4979. return function(input, init, row) {
  4980. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  4981. return text(input, init).then(function(response) {
  4982. return parse(response, row);
  4983. });
  4984. };
  4985. }
  4986. function dsv(delimiter, input, init, row) {
  4987. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  4988. var format = dsvFormat(delimiter);
  4989. return text(input, init).then(function(response) {
  4990. return format.parse(response, row);
  4991. });
  4992. }
  4993. var csv$1 = dsvParse(csvParse);
  4994. var tsv$1 = dsvParse(tsvParse);
  4995. function image(input, init) {
  4996. return new Promise(function(resolve, reject) {
  4997. var image = new Image;
  4998. for (var key in init) image[key] = init[key];
  4999. image.onerror = reject;
  5000. image.onload = function() { resolve(image); };
  5001. image.src = input;
  5002. });
  5003. }
  5004. function responseJson(response) {
  5005. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5006. return response.json();
  5007. }
  5008. function json(input, init) {
  5009. return fetch(input, init).then(responseJson);
  5010. }
  5011. function parser(type) {
  5012. return function(input, init) {
  5013. return text(input, init).then(function(text$$1) {
  5014. return (new DOMParser).parseFromString(text$$1, type);
  5015. });
  5016. };
  5017. }
  5018. var xml = parser("application/xml");
  5019. var html = parser("text/html");
  5020. var svg = parser("image/svg+xml");
  5021. function center$1(x, y) {
  5022. var nodes;
  5023. if (x == null) x = 0;
  5024. if (y == null) y = 0;
  5025. function force() {
  5026. var i,
  5027. n = nodes.length,
  5028. node,
  5029. sx = 0,
  5030. sy = 0;
  5031. for (i = 0; i < n; ++i) {
  5032. node = nodes[i], sx += node.x, sy += node.y;
  5033. }
  5034. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  5035. node = nodes[i], node.x -= sx, node.y -= sy;
  5036. }
  5037. }
  5038. force.initialize = function(_) {
  5039. nodes = _;
  5040. };
  5041. force.x = function(_) {
  5042. return arguments.length ? (x = +_, force) : x;
  5043. };
  5044. force.y = function(_) {
  5045. return arguments.length ? (y = +_, force) : y;
  5046. };
  5047. return force;
  5048. }
  5049. function constant$7(x) {
  5050. return function() {
  5051. return x;
  5052. };
  5053. }
  5054. function jiggle() {
  5055. return (Math.random() - 0.5) * 1e-6;
  5056. }
  5057. function tree_add(d) {
  5058. var x = +this._x.call(null, d),
  5059. y = +this._y.call(null, d);
  5060. return add(this.cover(x, y), x, y, d);
  5061. }
  5062. function add(tree, x, y, d) {
  5063. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  5064. var parent,
  5065. node = tree._root,
  5066. leaf = {data: d},
  5067. x0 = tree._x0,
  5068. y0 = tree._y0,
  5069. x1 = tree._x1,
  5070. y1 = tree._y1,
  5071. xm,
  5072. ym,
  5073. xp,
  5074. yp,
  5075. right,
  5076. bottom,
  5077. i,
  5078. j;
  5079. // If the tree is empty, initialize the root as a leaf.
  5080. if (!node) return tree._root = leaf, tree;
  5081. // Find the existing leaf for the new point, or add it.
  5082. while (node.length) {
  5083. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5084. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5085. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  5086. }
  5087. // Is the new point is exactly coincident with the existing point?
  5088. xp = +tree._x.call(null, node.data);
  5089. yp = +tree._y.call(null, node.data);
  5090. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  5091. // Otherwise, split the leaf node until the old and new point are separated.
  5092. do {
  5093. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  5094. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5095. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5096. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  5097. return parent[j] = node, parent[i] = leaf, tree;
  5098. }
  5099. function addAll(data) {
  5100. var d, i, n = data.length,
  5101. x,
  5102. y,
  5103. xz = new Array(n),
  5104. yz = new Array(n),
  5105. x0 = Infinity,
  5106. y0 = Infinity,
  5107. x1 = -Infinity,
  5108. y1 = -Infinity;
  5109. // Compute the points and their extent.
  5110. for (i = 0; i < n; ++i) {
  5111. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  5112. xz[i] = x;
  5113. yz[i] = y;
  5114. if (x < x0) x0 = x;
  5115. if (x > x1) x1 = x;
  5116. if (y < y0) y0 = y;
  5117. if (y > y1) y1 = y;
  5118. }
  5119. // If there were no (valid) points, inherit the existing extent.
  5120. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  5121. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  5122. // Expand the tree to cover the new points.
  5123. this.cover(x0, y0).cover(x1, y1);
  5124. // Add the new points.
  5125. for (i = 0; i < n; ++i) {
  5126. add(this, xz[i], yz[i], data[i]);
  5127. }
  5128. return this;
  5129. }
  5130. function tree_cover(x, y) {
  5131. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  5132. var x0 = this._x0,
  5133. y0 = this._y0,
  5134. x1 = this._x1,
  5135. y1 = this._y1;
  5136. // If the quadtree has no extent, initialize them.
  5137. // Integer extent are necessary so that if we later double the extent,
  5138. // the existing quadrant boundaries don’t change due to floating point error!
  5139. if (isNaN(x0)) {
  5140. x1 = (x0 = Math.floor(x)) + 1;
  5141. y1 = (y0 = Math.floor(y)) + 1;
  5142. }
  5143. // Otherwise, double repeatedly to cover.
  5144. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  5145. var z = x1 - x0,
  5146. node = this._root,
  5147. parent,
  5148. i;
  5149. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  5150. case 0: {
  5151. do parent = new Array(4), parent[i] = node, node = parent;
  5152. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  5153. break;
  5154. }
  5155. case 1: {
  5156. do parent = new Array(4), parent[i] = node, node = parent;
  5157. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  5158. break;
  5159. }
  5160. case 2: {
  5161. do parent = new Array(4), parent[i] = node, node = parent;
  5162. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  5163. break;
  5164. }
  5165. case 3: {
  5166. do parent = new Array(4), parent[i] = node, node = parent;
  5167. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  5168. break;
  5169. }
  5170. }
  5171. if (this._root && this._root.length) this._root = node;
  5172. }
  5173. // If the quadtree covers the point already, just return.
  5174. else return this;
  5175. this._x0 = x0;
  5176. this._y0 = y0;
  5177. this._x1 = x1;
  5178. this._y1 = y1;
  5179. return this;
  5180. }
  5181. function tree_data() {
  5182. var data = [];
  5183. this.visit(function(node) {
  5184. if (!node.length) do data.push(node.data); while (node = node.next)
  5185. });
  5186. return data;
  5187. }
  5188. function tree_extent(_) {
  5189. return arguments.length
  5190. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  5191. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  5192. }
  5193. function Quad(node, x0, y0, x1, y1) {
  5194. this.node = node;
  5195. this.x0 = x0;
  5196. this.y0 = y0;
  5197. this.x1 = x1;
  5198. this.y1 = y1;
  5199. }
  5200. function tree_find(x, y, radius) {
  5201. var data,
  5202. x0 = this._x0,
  5203. y0 = this._y0,
  5204. x1,
  5205. y1,
  5206. x2,
  5207. y2,
  5208. x3 = this._x1,
  5209. y3 = this._y1,
  5210. quads = [],
  5211. node = this._root,
  5212. q,
  5213. i;
  5214. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  5215. if (radius == null) radius = Infinity;
  5216. else {
  5217. x0 = x - radius, y0 = y - radius;
  5218. x3 = x + radius, y3 = y + radius;
  5219. radius *= radius;
  5220. }
  5221. while (q = quads.pop()) {
  5222. // Stop searching if this quadrant can’t contain a closer node.
  5223. if (!(node = q.node)
  5224. || (x1 = q.x0) > x3
  5225. || (y1 = q.y0) > y3
  5226. || (x2 = q.x1) < x0
  5227. || (y2 = q.y1) < y0) continue;
  5228. // Bisect the current quadrant.
  5229. if (node.length) {
  5230. var xm = (x1 + x2) / 2,
  5231. ym = (y1 + y2) / 2;
  5232. quads.push(
  5233. new Quad(node[3], xm, ym, x2, y2),
  5234. new Quad(node[2], x1, ym, xm, y2),
  5235. new Quad(node[1], xm, y1, x2, ym),
  5236. new Quad(node[0], x1, y1, xm, ym)
  5237. );
  5238. // Visit the closest quadrant first.
  5239. if (i = (y >= ym) << 1 | (x >= xm)) {
  5240. q = quads[quads.length - 1];
  5241. quads[quads.length - 1] = quads[quads.length - 1 - i];
  5242. quads[quads.length - 1 - i] = q;
  5243. }
  5244. }
  5245. // Visit this point. (Visiting coincident points isn’t necessary!)
  5246. else {
  5247. var dx = x - +this._x.call(null, node.data),
  5248. dy = y - +this._y.call(null, node.data),
  5249. d2 = dx * dx + dy * dy;
  5250. if (d2 < radius) {
  5251. var d = Math.sqrt(radius = d2);
  5252. x0 = x - d, y0 = y - d;
  5253. x3 = x + d, y3 = y + d;
  5254. data = node.data;
  5255. }
  5256. }
  5257. }
  5258. return data;
  5259. }
  5260. function tree_remove(d) {
  5261. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  5262. var parent,
  5263. node = this._root,
  5264. retainer,
  5265. previous,
  5266. next,
  5267. x0 = this._x0,
  5268. y0 = this._y0,
  5269. x1 = this._x1,
  5270. y1 = this._y1,
  5271. x,
  5272. y,
  5273. xm,
  5274. ym,
  5275. right,
  5276. bottom,
  5277. i,
  5278. j;
  5279. // If the tree is empty, initialize the root as a leaf.
  5280. if (!node) return this;
  5281. // Find the leaf node for the point.
  5282. // While descending, also retain the deepest parent with a non-removed sibling.
  5283. if (node.length) while (true) {
  5284. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5285. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5286. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  5287. if (!node.length) break;
  5288. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  5289. }
  5290. // Find the point to remove.
  5291. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  5292. if (next = node.next) delete node.next;
  5293. // If there are multiple coincident points, remove just the point.
  5294. if (previous) return next ? previous.next = next : delete previous.next, this;
  5295. // If this is the root point, remove it.
  5296. if (!parent) return this._root = next, this;
  5297. // Remove this leaf.
  5298. next ? parent[i] = next : delete parent[i];
  5299. // If the parent now contains exactly one leaf, collapse superfluous parents.
  5300. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  5301. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  5302. && !node.length) {
  5303. if (retainer) retainer[j] = node;
  5304. else this._root = node;
  5305. }
  5306. return this;
  5307. }
  5308. function removeAll(data) {
  5309. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  5310. return this;
  5311. }
  5312. function tree_root() {
  5313. return this._root;
  5314. }
  5315. function tree_size() {
  5316. var size = 0;
  5317. this.visit(function(node) {
  5318. if (!node.length) do ++size; while (node = node.next)
  5319. });
  5320. return size;
  5321. }
  5322. function tree_visit(callback) {
  5323. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  5324. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  5325. while (q = quads.pop()) {
  5326. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  5327. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5328. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5329. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5330. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5331. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5332. }
  5333. }
  5334. return this;
  5335. }
  5336. function tree_visitAfter(callback) {
  5337. var quads = [], next = [], q;
  5338. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  5339. while (q = quads.pop()) {
  5340. var node = q.node;
  5341. if (node.length) {
  5342. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5343. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5344. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5345. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5346. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5347. }
  5348. next.push(q);
  5349. }
  5350. while (q = next.pop()) {
  5351. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  5352. }
  5353. return this;
  5354. }
  5355. function defaultX$1(d) {
  5356. return d[0];
  5357. }
  5358. function tree_x(_) {
  5359. return arguments.length ? (this._x = _, this) : this._x;
  5360. }
  5361. function defaultY$1(d) {
  5362. return d[1];
  5363. }
  5364. function tree_y(_) {
  5365. return arguments.length ? (this._y = _, this) : this._y;
  5366. }
  5367. function quadtree(nodes, x, y) {
  5368. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  5369. return nodes == null ? tree : tree.addAll(nodes);
  5370. }
  5371. function Quadtree(x, y, x0, y0, x1, y1) {
  5372. this._x = x;
  5373. this._y = y;
  5374. this._x0 = x0;
  5375. this._y0 = y0;
  5376. this._x1 = x1;
  5377. this._y1 = y1;
  5378. this._root = undefined;
  5379. }
  5380. function leaf_copy(leaf) {
  5381. var copy = {data: leaf.data}, next = copy;
  5382. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  5383. return copy;
  5384. }
  5385. var treeProto = quadtree.prototype = Quadtree.prototype;
  5386. treeProto.copy = function() {
  5387. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  5388. node = this._root,
  5389. nodes,
  5390. child;
  5391. if (!node) return copy;
  5392. if (!node.length) return copy._root = leaf_copy(node), copy;
  5393. nodes = [{source: node, target: copy._root = new Array(4)}];
  5394. while (node = nodes.pop()) {
  5395. for (var i = 0; i < 4; ++i) {
  5396. if (child = node.source[i]) {
  5397. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  5398. else node.target[i] = leaf_copy(child);
  5399. }
  5400. }
  5401. }
  5402. return copy;
  5403. };
  5404. treeProto.add = tree_add;
  5405. treeProto.addAll = addAll;
  5406. treeProto.cover = tree_cover;
  5407. treeProto.data = tree_data;
  5408. treeProto.extent = tree_extent;
  5409. treeProto.find = tree_find;
  5410. treeProto.remove = tree_remove;
  5411. treeProto.removeAll = removeAll;
  5412. treeProto.root = tree_root;
  5413. treeProto.size = tree_size;
  5414. treeProto.visit = tree_visit;
  5415. treeProto.visitAfter = tree_visitAfter;
  5416. treeProto.x = tree_x;
  5417. treeProto.y = tree_y;
  5418. function x(d) {
  5419. return d.x + d.vx;
  5420. }
  5421. function y(d) {
  5422. return d.y + d.vy;
  5423. }
  5424. function collide(radius) {
  5425. var nodes,
  5426. radii,
  5427. strength = 1,
  5428. iterations = 1;
  5429. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  5430. function force() {
  5431. var i, n = nodes.length,
  5432. tree,
  5433. node,
  5434. xi,
  5435. yi,
  5436. ri,
  5437. ri2;
  5438. for (var k = 0; k < iterations; ++k) {
  5439. tree = quadtree(nodes, x, y).visitAfter(prepare);
  5440. for (i = 0; i < n; ++i) {
  5441. node = nodes[i];
  5442. ri = radii[node.index], ri2 = ri * ri;
  5443. xi = node.x + node.vx;
  5444. yi = node.y + node.vy;
  5445. tree.visit(apply);
  5446. }
  5447. }
  5448. function apply(quad, x0, y0, x1, y1) {
  5449. var data = quad.data, rj = quad.r, r = ri + rj;
  5450. if (data) {
  5451. if (data.index > node.index) {
  5452. var x = xi - data.x - data.vx,
  5453. y = yi - data.y - data.vy,
  5454. l = x * x + y * y;
  5455. if (l < r * r) {
  5456. if (x === 0) x = jiggle(), l += x * x;
  5457. if (y === 0) y = jiggle(), l += y * y;
  5458. l = (r - (l = Math.sqrt(l))) / l * strength;
  5459. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5460. node.vy += (y *= l) * r;
  5461. data.vx -= x * (r = 1 - r);
  5462. data.vy -= y * r;
  5463. }
  5464. }
  5465. return;
  5466. }
  5467. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5468. }
  5469. }
  5470. function prepare(quad) {
  5471. if (quad.data) return quad.r = radii[quad.data.index];
  5472. for (var i = quad.r = 0; i < 4; ++i) {
  5473. if (quad[i] && quad[i].r > quad.r) {
  5474. quad.r = quad[i].r;
  5475. }
  5476. }
  5477. }
  5478. function initialize() {
  5479. if (!nodes) return;
  5480. var i, n = nodes.length, node;
  5481. radii = new Array(n);
  5482. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5483. }
  5484. force.initialize = function(_) {
  5485. nodes = _;
  5486. initialize();
  5487. };
  5488. force.iterations = function(_) {
  5489. return arguments.length ? (iterations = +_, force) : iterations;
  5490. };
  5491. force.strength = function(_) {
  5492. return arguments.length ? (strength = +_, force) : strength;
  5493. };
  5494. force.radius = function(_) {
  5495. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5496. };
  5497. return force;
  5498. }
  5499. function index(d) {
  5500. return d.index;
  5501. }
  5502. function find(nodeById, nodeId) {
  5503. var node = nodeById.get(nodeId);
  5504. if (!node) throw new Error("missing: " + nodeId);
  5505. return node;
  5506. }
  5507. function link(links) {
  5508. var id = index,
  5509. strength = defaultStrength,
  5510. strengths,
  5511. distance = constant$7(30),
  5512. distances,
  5513. nodes,
  5514. count,
  5515. bias,
  5516. iterations = 1;
  5517. if (links == null) links = [];
  5518. function defaultStrength(link) {
  5519. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5520. }
  5521. function force(alpha) {
  5522. for (var k = 0, n = links.length; k < iterations; ++k) {
  5523. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5524. link = links[i], source = link.source, target = link.target;
  5525. x = target.x + target.vx - source.x - source.vx || jiggle();
  5526. y = target.y + target.vy - source.y - source.vy || jiggle();
  5527. l = Math.sqrt(x * x + y * y);
  5528. l = (l - distances[i]) / l * alpha * strengths[i];
  5529. x *= l, y *= l;
  5530. target.vx -= x * (b = bias[i]);
  5531. target.vy -= y * b;
  5532. source.vx += x * (b = 1 - b);
  5533. source.vy += y * b;
  5534. }
  5535. }
  5536. }
  5537. function initialize() {
  5538. if (!nodes) return;
  5539. var i,
  5540. n = nodes.length,
  5541. m = links.length,
  5542. nodeById = map$1(nodes, id),
  5543. link;
  5544. for (i = 0, count = new Array(n); i < m; ++i) {
  5545. link = links[i], link.index = i;
  5546. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5547. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5548. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5549. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5550. }
  5551. for (i = 0, bias = new Array(m); i < m; ++i) {
  5552. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5553. }
  5554. strengths = new Array(m), initializeStrength();
  5555. distances = new Array(m), initializeDistance();
  5556. }
  5557. function initializeStrength() {
  5558. if (!nodes) return;
  5559. for (var i = 0, n = links.length; i < n; ++i) {
  5560. strengths[i] = +strength(links[i], i, links);
  5561. }
  5562. }
  5563. function initializeDistance() {
  5564. if (!nodes) return;
  5565. for (var i = 0, n = links.length; i < n; ++i) {
  5566. distances[i] = +distance(links[i], i, links);
  5567. }
  5568. }
  5569. force.initialize = function(_) {
  5570. nodes = _;
  5571. initialize();
  5572. };
  5573. force.links = function(_) {
  5574. return arguments.length ? (links = _, initialize(), force) : links;
  5575. };
  5576. force.id = function(_) {
  5577. return arguments.length ? (id = _, force) : id;
  5578. };
  5579. force.iterations = function(_) {
  5580. return arguments.length ? (iterations = +_, force) : iterations;
  5581. };
  5582. force.strength = function(_) {
  5583. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  5584. };
  5585. force.distance = function(_) {
  5586. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  5587. };
  5588. return force;
  5589. }
  5590. function x$1(d) {
  5591. return d.x;
  5592. }
  5593. function y$1(d) {
  5594. return d.y;
  5595. }
  5596. var initialRadius = 10,
  5597. initialAngle = Math.PI * (3 - Math.sqrt(5));
  5598. function simulation(nodes) {
  5599. var simulation,
  5600. alpha = 1,
  5601. alphaMin = 0.001,
  5602. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5603. alphaTarget = 0,
  5604. velocityDecay = 0.6,
  5605. forces = map$1(),
  5606. stepper = timer(step),
  5607. event = dispatch("tick", "end");
  5608. if (nodes == null) nodes = [];
  5609. function step() {
  5610. tick();
  5611. event.call("tick", simulation);
  5612. if (alpha < alphaMin) {
  5613. stepper.stop();
  5614. event.call("end", simulation);
  5615. }
  5616. }
  5617. function tick() {
  5618. var i, n = nodes.length, node;
  5619. alpha += (alphaTarget - alpha) * alphaDecay;
  5620. forces.each(function(force) {
  5621. force(alpha);
  5622. });
  5623. for (i = 0; i < n; ++i) {
  5624. node = nodes[i];
  5625. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5626. else node.x = node.fx, node.vx = 0;
  5627. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5628. else node.y = node.fy, node.vy = 0;
  5629. }
  5630. }
  5631. function initializeNodes() {
  5632. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5633. node = nodes[i], node.index = i;
  5634. if (isNaN(node.x) || isNaN(node.y)) {
  5635. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5636. node.x = radius * Math.cos(angle);
  5637. node.y = radius * Math.sin(angle);
  5638. }
  5639. if (isNaN(node.vx) || isNaN(node.vy)) {
  5640. node.vx = node.vy = 0;
  5641. }
  5642. }
  5643. }
  5644. function initializeForce(force) {
  5645. if (force.initialize) force.initialize(nodes);
  5646. return force;
  5647. }
  5648. initializeNodes();
  5649. return simulation = {
  5650. tick: tick,
  5651. restart: function() {
  5652. return stepper.restart(step), simulation;
  5653. },
  5654. stop: function() {
  5655. return stepper.stop(), simulation;
  5656. },
  5657. nodes: function(_) {
  5658. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5659. },
  5660. alpha: function(_) {
  5661. return arguments.length ? (alpha = +_, simulation) : alpha;
  5662. },
  5663. alphaMin: function(_) {
  5664. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5665. },
  5666. alphaDecay: function(_) {
  5667. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5668. },
  5669. alphaTarget: function(_) {
  5670. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5671. },
  5672. velocityDecay: function(_) {
  5673. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5674. },
  5675. force: function(name, _) {
  5676. return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
  5677. },
  5678. find: function(x, y, radius) {
  5679. var i = 0,
  5680. n = nodes.length,
  5681. dx,
  5682. dy,
  5683. d2,
  5684. node,
  5685. closest;
  5686. if (radius == null) radius = Infinity;
  5687. else radius *= radius;
  5688. for (i = 0; i < n; ++i) {
  5689. node = nodes[i];
  5690. dx = x - node.x;
  5691. dy = y - node.y;
  5692. d2 = dx * dx + dy * dy;
  5693. if (d2 < radius) closest = node, radius = d2;
  5694. }
  5695. return closest;
  5696. },
  5697. on: function(name, _) {
  5698. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5699. }
  5700. };
  5701. }
  5702. function manyBody() {
  5703. var nodes,
  5704. node,
  5705. alpha,
  5706. strength = constant$7(-30),
  5707. strengths,
  5708. distanceMin2 = 1,
  5709. distanceMax2 = Infinity,
  5710. theta2 = 0.81;
  5711. function force(_) {
  5712. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5713. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5714. }
  5715. function initialize() {
  5716. if (!nodes) return;
  5717. var i, n = nodes.length, node;
  5718. strengths = new Array(n);
  5719. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5720. }
  5721. function accumulate(quad) {
  5722. var strength = 0, q, c, weight = 0, x, y, i;
  5723. // For internal nodes, accumulate forces from child quadrants.
  5724. if (quad.length) {
  5725. for (x = y = i = 0; i < 4; ++i) {
  5726. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5727. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5728. }
  5729. }
  5730. quad.x = x / weight;
  5731. quad.y = y / weight;
  5732. }
  5733. // For leaf nodes, accumulate forces from coincident quadrants.
  5734. else {
  5735. q = quad;
  5736. q.x = q.data.x;
  5737. q.y = q.data.y;
  5738. do strength += strengths[q.data.index];
  5739. while (q = q.next);
  5740. }
  5741. quad.value = strength;
  5742. }
  5743. function apply(quad, x1, _, x2) {
  5744. if (!quad.value) return true;
  5745. var x = quad.x - node.x,
  5746. y = quad.y - node.y,
  5747. w = x2 - x1,
  5748. l = x * x + y * y;
  5749. // Apply the Barnes-Hut approximation if possible.
  5750. // Limit forces for very close nodes; randomize direction if coincident.
  5751. if (w * w / theta2 < l) {
  5752. if (l < distanceMax2) {
  5753. if (x === 0) x = jiggle(), l += x * x;
  5754. if (y === 0) y = jiggle(), l += y * y;
  5755. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5756. node.vx += x * quad.value * alpha / l;
  5757. node.vy += y * quad.value * alpha / l;
  5758. }
  5759. return true;
  5760. }
  5761. // Otherwise, process points directly.
  5762. else if (quad.length || l >= distanceMax2) return;
  5763. // Limit forces for very close nodes; randomize direction if coincident.
  5764. if (quad.data !== node || quad.next) {
  5765. if (x === 0) x = jiggle(), l += x * x;
  5766. if (y === 0) y = jiggle(), l += y * y;
  5767. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5768. }
  5769. do if (quad.data !== node) {
  5770. w = strengths[quad.data.index] * alpha / l;
  5771. node.vx += x * w;
  5772. node.vy += y * w;
  5773. } while (quad = quad.next);
  5774. }
  5775. force.initialize = function(_) {
  5776. nodes = _;
  5777. initialize();
  5778. };
  5779. force.strength = function(_) {
  5780. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5781. };
  5782. force.distanceMin = function(_) {
  5783. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5784. };
  5785. force.distanceMax = function(_) {
  5786. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5787. };
  5788. force.theta = function(_) {
  5789. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5790. };
  5791. return force;
  5792. }
  5793. function radial(radius, x, y) {
  5794. var nodes,
  5795. strength = constant$7(0.1),
  5796. strengths,
  5797. radiuses;
  5798. if (typeof radius !== "function") radius = constant$7(+radius);
  5799. if (x == null) x = 0;
  5800. if (y == null) y = 0;
  5801. function force(alpha) {
  5802. for (var i = 0, n = nodes.length; i < n; ++i) {
  5803. var node = nodes[i],
  5804. dx = node.x - x || 1e-6,
  5805. dy = node.y - y || 1e-6,
  5806. r = Math.sqrt(dx * dx + dy * dy),
  5807. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  5808. node.vx += dx * k;
  5809. node.vy += dy * k;
  5810. }
  5811. }
  5812. function initialize() {
  5813. if (!nodes) return;
  5814. var i, n = nodes.length;
  5815. strengths = new Array(n);
  5816. radiuses = new Array(n);
  5817. for (i = 0; i < n; ++i) {
  5818. radiuses[i] = +radius(nodes[i], i, nodes);
  5819. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  5820. }
  5821. }
  5822. force.initialize = function(_) {
  5823. nodes = _, initialize();
  5824. };
  5825. force.strength = function(_) {
  5826. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5827. };
  5828. force.radius = function(_) {
  5829. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5830. };
  5831. force.x = function(_) {
  5832. return arguments.length ? (x = +_, force) : x;
  5833. };
  5834. force.y = function(_) {
  5835. return arguments.length ? (y = +_, force) : y;
  5836. };
  5837. return force;
  5838. }
  5839. function x$2(x) {
  5840. var strength = constant$7(0.1),
  5841. nodes,
  5842. strengths,
  5843. xz;
  5844. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  5845. function force(alpha) {
  5846. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5847. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  5848. }
  5849. }
  5850. function initialize() {
  5851. if (!nodes) return;
  5852. var i, n = nodes.length;
  5853. strengths = new Array(n);
  5854. xz = new Array(n);
  5855. for (i = 0; i < n; ++i) {
  5856. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5857. }
  5858. }
  5859. force.initialize = function(_) {
  5860. nodes = _;
  5861. initialize();
  5862. };
  5863. force.strength = function(_) {
  5864. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5865. };
  5866. force.x = function(_) {
  5867. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  5868. };
  5869. return force;
  5870. }
  5871. function y$2(y) {
  5872. var strength = constant$7(0.1),
  5873. nodes,
  5874. strengths,
  5875. yz;
  5876. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  5877. function force(alpha) {
  5878. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5879. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  5880. }
  5881. }
  5882. function initialize() {
  5883. if (!nodes) return;
  5884. var i, n = nodes.length;
  5885. strengths = new Array(n);
  5886. yz = new Array(n);
  5887. for (i = 0; i < n; ++i) {
  5888. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5889. }
  5890. }
  5891. force.initialize = function(_) {
  5892. nodes = _;
  5893. initialize();
  5894. };
  5895. force.strength = function(_) {
  5896. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5897. };
  5898. force.y = function(_) {
  5899. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  5900. };
  5901. return force;
  5902. }
  5903. // Computes the decimal coefficient and exponent of the specified number x with
  5904. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  5905. // For example, formatDecimal(1.23) returns ["123", 0].
  5906. function formatDecimal(x, p) {
  5907. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  5908. var i, coefficient = x.slice(0, i);
  5909. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  5910. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  5911. return [
  5912. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  5913. +x.slice(i + 1)
  5914. ];
  5915. }
  5916. function exponent$1(x) {
  5917. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  5918. }
  5919. function formatGroup(grouping, thousands) {
  5920. return function(value, width) {
  5921. var i = value.length,
  5922. t = [],
  5923. j = 0,
  5924. g = grouping[0],
  5925. length = 0;
  5926. while (i > 0 && g > 0) {
  5927. if (length + g + 1 > width) g = Math.max(1, width - length);
  5928. t.push(value.substring(i -= g, i + g));
  5929. if ((length += g + 1) > width) break;
  5930. g = grouping[j = (j + 1) % grouping.length];
  5931. }
  5932. return t.reverse().join(thousands);
  5933. };
  5934. }
  5935. function formatNumerals(numerals) {
  5936. return function(value) {
  5937. return value.replace(/[0-9]/g, function(i) {
  5938. return numerals[+i];
  5939. });
  5940. };
  5941. }
  5942. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  5943. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  5944. function formatSpecifier(specifier) {
  5945. return new FormatSpecifier(specifier);
  5946. }
  5947. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  5948. function FormatSpecifier(specifier) {
  5949. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  5950. var match;
  5951. this.fill = match[1] || " ";
  5952. this.align = match[2] || ">";
  5953. this.sign = match[3] || "-";
  5954. this.symbol = match[4] || "";
  5955. this.zero = !!match[5];
  5956. this.width = match[6] && +match[6];
  5957. this.comma = !!match[7];
  5958. this.precision = match[8] && +match[8].slice(1);
  5959. this.trim = !!match[9];
  5960. this.type = match[10] || "";
  5961. }
  5962. FormatSpecifier.prototype.toString = function() {
  5963. return this.fill
  5964. + this.align
  5965. + this.sign
  5966. + this.symbol
  5967. + (this.zero ? "0" : "")
  5968. + (this.width == null ? "" : Math.max(1, this.width | 0))
  5969. + (this.comma ? "," : "")
  5970. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  5971. + (this.trim ? "~" : "")
  5972. + this.type;
  5973. };
  5974. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  5975. function formatTrim(s) {
  5976. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  5977. switch (s[i]) {
  5978. case ".": i0 = i1 = i; break;
  5979. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  5980. default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
  5981. }
  5982. }
  5983. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  5984. }
  5985. var prefixExponent;
  5986. function formatPrefixAuto(x, p) {
  5987. var d = formatDecimal(x, p);
  5988. if (!d) return x + "";
  5989. var coefficient = d[0],
  5990. exponent = d[1],
  5991. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  5992. n = coefficient.length;
  5993. return i === n ? coefficient
  5994. : i > n ? coefficient + new Array(i - n + 1).join("0")
  5995. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  5996. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  5997. }
  5998. function formatRounded(x, p) {
  5999. var d = formatDecimal(x, p);
  6000. if (!d) return x + "";
  6001. var coefficient = d[0],
  6002. exponent = d[1];
  6003. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  6004. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  6005. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  6006. }
  6007. var formatTypes = {
  6008. "%": function(x, p) { return (x * 100).toFixed(p); },
  6009. "b": function(x) { return Math.round(x).toString(2); },
  6010. "c": function(x) { return x + ""; },
  6011. "d": function(x) { return Math.round(x).toString(10); },
  6012. "e": function(x, p) { return x.toExponential(p); },
  6013. "f": function(x, p) { return x.toFixed(p); },
  6014. "g": function(x, p) { return x.toPrecision(p); },
  6015. "o": function(x) { return Math.round(x).toString(8); },
  6016. "p": function(x, p) { return formatRounded(x * 100, p); },
  6017. "r": formatRounded,
  6018. "s": formatPrefixAuto,
  6019. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  6020. "x": function(x) { return Math.round(x).toString(16); }
  6021. };
  6022. function identity$3(x) {
  6023. return x;
  6024. }
  6025. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  6026. function formatLocale(locale) {
  6027. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  6028. currency = locale.currency,
  6029. decimal = locale.decimal,
  6030. numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
  6031. percent = locale.percent || "%";
  6032. function newFormat(specifier) {
  6033. specifier = formatSpecifier(specifier);
  6034. var fill = specifier.fill,
  6035. align = specifier.align,
  6036. sign = specifier.sign,
  6037. symbol = specifier.symbol,
  6038. zero = specifier.zero,
  6039. width = specifier.width,
  6040. comma = specifier.comma,
  6041. precision = specifier.precision,
  6042. trim = specifier.trim,
  6043. type = specifier.type;
  6044. // The "n" type is an alias for ",g".
  6045. if (type === "n") comma = true, type = "g";
  6046. // The "" type, and any invalid type, is an alias for ".12~g".
  6047. else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
  6048. // If zero fill is specified, padding goes after sign and before digits.
  6049. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  6050. // Compute the prefix and suffix.
  6051. // For SI-prefix, the suffix is lazily computed.
  6052. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  6053. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
  6054. // What format function should we use?
  6055. // Is this an integer type?
  6056. // Can this type generate exponential notation?
  6057. var formatType = formatTypes[type],
  6058. maybeSuffix = /[defgprs%]/.test(type);
  6059. // Set the default precision if not specified,
  6060. // or clamp the specified precision to the supported range.
  6061. // For significant precision, it must be in [1, 21].
  6062. // For fixed precision, it must be in [0, 20].
  6063. precision = precision == null ? 6
  6064. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  6065. : Math.max(0, Math.min(20, precision));
  6066. function format(value) {
  6067. var valuePrefix = prefix,
  6068. valueSuffix = suffix,
  6069. i, n, c;
  6070. if (type === "c") {
  6071. valueSuffix = formatType(value) + valueSuffix;
  6072. value = "";
  6073. } else {
  6074. value = +value;
  6075. // Perform the initial formatting.
  6076. var valueNegative = value < 0;
  6077. value = formatType(Math.abs(value), precision);
  6078. // Trim insignificant zeros.
  6079. if (trim) value = formatTrim(value);
  6080. // If a negative value rounds to zero during formatting, treat as positive.
  6081. if (valueNegative && +value === 0) valueNegative = false;
  6082. // Compute the prefix and suffix.
  6083. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  6084. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  6085. // Break the formatted value into the integer “value” part that can be
  6086. // grouped, and fractional or exponential “suffix” part that is not.
  6087. if (maybeSuffix) {
  6088. i = -1, n = value.length;
  6089. while (++i < n) {
  6090. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  6091. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  6092. value = value.slice(0, i);
  6093. break;
  6094. }
  6095. }
  6096. }
  6097. }
  6098. // If the fill character is not "0", grouping is applied before padding.
  6099. if (comma && !zero) value = group(value, Infinity);
  6100. // Compute the padding.
  6101. var length = valuePrefix.length + value.length + valueSuffix.length,
  6102. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  6103. // If the fill character is "0", grouping is applied after padding.
  6104. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  6105. // Reconstruct the final output based on the desired alignment.
  6106. switch (align) {
  6107. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  6108. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  6109. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  6110. default: value = padding + valuePrefix + value + valueSuffix; break;
  6111. }
  6112. return numerals(value);
  6113. }
  6114. format.toString = function() {
  6115. return specifier + "";
  6116. };
  6117. return format;
  6118. }
  6119. function formatPrefix(specifier, value) {
  6120. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  6121. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  6122. k = Math.pow(10, -e),
  6123. prefix = prefixes[8 + e / 3];
  6124. return function(value) {
  6125. return f(k * value) + prefix;
  6126. };
  6127. }
  6128. return {
  6129. format: newFormat,
  6130. formatPrefix: formatPrefix
  6131. };
  6132. }
  6133. var locale;
  6134. defaultLocale({
  6135. decimal: ".",
  6136. thousands: ",",
  6137. grouping: [3],
  6138. currency: ["$", ""]
  6139. });
  6140. function defaultLocale(definition) {
  6141. locale = formatLocale(definition);
  6142. exports.format = locale.format;
  6143. exports.formatPrefix = locale.formatPrefix;
  6144. return locale;
  6145. }
  6146. function precisionFixed(step) {
  6147. return Math.max(0, -exponent$1(Math.abs(step)));
  6148. }
  6149. function precisionPrefix(step, value) {
  6150. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  6151. }
  6152. function precisionRound(step, max) {
  6153. step = Math.abs(step), max = Math.abs(max) - step;
  6154. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  6155. }
  6156. // Adds floating point numbers with twice the normal precision.
  6157. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  6158. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  6159. // 305–363 (1997).
  6160. // Code adapted from GeographicLib by Charles F. F. Karney,
  6161. // http://geographiclib.sourceforge.net/
  6162. function adder() {
  6163. return new Adder;
  6164. }
  6165. function Adder() {
  6166. this.reset();
  6167. }
  6168. Adder.prototype = {
  6169. constructor: Adder,
  6170. reset: function() {
  6171. this.s = // rounded value
  6172. this.t = 0; // exact error
  6173. },
  6174. add: function(y) {
  6175. add$1(temp, y, this.t);
  6176. add$1(this, temp.s, this.s);
  6177. if (this.s) this.t += temp.t;
  6178. else this.s = temp.t;
  6179. },
  6180. valueOf: function() {
  6181. return this.s;
  6182. }
  6183. };
  6184. var temp = new Adder;
  6185. function add$1(adder, a, b) {
  6186. var x = adder.s = a + b,
  6187. bv = x - a,
  6188. av = x - bv;
  6189. adder.t = (a - av) + (b - bv);
  6190. }
  6191. var epsilon$2 = 1e-6;
  6192. var epsilon2$1 = 1e-12;
  6193. var pi$3 = Math.PI;
  6194. var halfPi$2 = pi$3 / 2;
  6195. var quarterPi = pi$3 / 4;
  6196. var tau$3 = pi$3 * 2;
  6197. var degrees$1 = 180 / pi$3;
  6198. var radians = pi$3 / 180;
  6199. var abs = Math.abs;
  6200. var atan = Math.atan;
  6201. var atan2 = Math.atan2;
  6202. var cos$1 = Math.cos;
  6203. var ceil = Math.ceil;
  6204. var exp = Math.exp;
  6205. var log = Math.log;
  6206. var pow = Math.pow;
  6207. var sin$1 = Math.sin;
  6208. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  6209. var sqrt = Math.sqrt;
  6210. var tan = Math.tan;
  6211. function acos(x) {
  6212. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  6213. }
  6214. function asin(x) {
  6215. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  6216. }
  6217. function haversin(x) {
  6218. return (x = sin$1(x / 2)) * x;
  6219. }
  6220. function noop$2() {}
  6221. function streamGeometry(geometry, stream) {
  6222. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  6223. streamGeometryType[geometry.type](geometry, stream);
  6224. }
  6225. }
  6226. var streamObjectType = {
  6227. Feature: function(object, stream) {
  6228. streamGeometry(object.geometry, stream);
  6229. },
  6230. FeatureCollection: function(object, stream) {
  6231. var features = object.features, i = -1, n = features.length;
  6232. while (++i < n) streamGeometry(features[i].geometry, stream);
  6233. }
  6234. };
  6235. var streamGeometryType = {
  6236. Sphere: function(object, stream) {
  6237. stream.sphere();
  6238. },
  6239. Point: function(object, stream) {
  6240. object = object.coordinates;
  6241. stream.point(object[0], object[1], object[2]);
  6242. },
  6243. MultiPoint: function(object, stream) {
  6244. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6245. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  6246. },
  6247. LineString: function(object, stream) {
  6248. streamLine(object.coordinates, stream, 0);
  6249. },
  6250. MultiLineString: function(object, stream) {
  6251. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6252. while (++i < n) streamLine(coordinates[i], stream, 0);
  6253. },
  6254. Polygon: function(object, stream) {
  6255. streamPolygon(object.coordinates, stream);
  6256. },
  6257. MultiPolygon: function(object, stream) {
  6258. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6259. while (++i < n) streamPolygon(coordinates[i], stream);
  6260. },
  6261. GeometryCollection: function(object, stream) {
  6262. var geometries = object.geometries, i = -1, n = geometries.length;
  6263. while (++i < n) streamGeometry(geometries[i], stream);
  6264. }
  6265. };
  6266. function streamLine(coordinates, stream, closed) {
  6267. var i = -1, n = coordinates.length - closed, coordinate;
  6268. stream.lineStart();
  6269. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  6270. stream.lineEnd();
  6271. }
  6272. function streamPolygon(coordinates, stream) {
  6273. var i = -1, n = coordinates.length;
  6274. stream.polygonStart();
  6275. while (++i < n) streamLine(coordinates[i], stream, 1);
  6276. stream.polygonEnd();
  6277. }
  6278. function geoStream(object, stream) {
  6279. if (object && streamObjectType.hasOwnProperty(object.type)) {
  6280. streamObjectType[object.type](object, stream);
  6281. } else {
  6282. streamGeometry(object, stream);
  6283. }
  6284. }
  6285. var areaRingSum = adder();
  6286. var areaSum = adder(),
  6287. lambda00,
  6288. phi00,
  6289. lambda0,
  6290. cosPhi0,
  6291. sinPhi0;
  6292. var areaStream = {
  6293. point: noop$2,
  6294. lineStart: noop$2,
  6295. lineEnd: noop$2,
  6296. polygonStart: function() {
  6297. areaRingSum.reset();
  6298. areaStream.lineStart = areaRingStart;
  6299. areaStream.lineEnd = areaRingEnd;
  6300. },
  6301. polygonEnd: function() {
  6302. var areaRing = +areaRingSum;
  6303. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  6304. this.lineStart = this.lineEnd = this.point = noop$2;
  6305. },
  6306. sphere: function() {
  6307. areaSum.add(tau$3);
  6308. }
  6309. };
  6310. function areaRingStart() {
  6311. areaStream.point = areaPointFirst;
  6312. }
  6313. function areaRingEnd() {
  6314. areaPoint(lambda00, phi00);
  6315. }
  6316. function areaPointFirst(lambda, phi) {
  6317. areaStream.point = areaPoint;
  6318. lambda00 = lambda, phi00 = phi;
  6319. lambda *= radians, phi *= radians;
  6320. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  6321. }
  6322. function areaPoint(lambda, phi) {
  6323. lambda *= radians, phi *= radians;
  6324. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  6325. // Spherical excess E for a spherical triangle with vertices: south pole,
  6326. // previous point, current point. Uses a formula derived from Cagnoli’s
  6327. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  6328. var dLambda = lambda - lambda0,
  6329. sdLambda = dLambda >= 0 ? 1 : -1,
  6330. adLambda = sdLambda * dLambda,
  6331. cosPhi = cos$1(phi),
  6332. sinPhi = sin$1(phi),
  6333. k = sinPhi0 * sinPhi,
  6334. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  6335. v = k * sdLambda * sin$1(adLambda);
  6336. areaRingSum.add(atan2(v, u));
  6337. // Advance the previous points.
  6338. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  6339. }
  6340. function area$1(object) {
  6341. areaSum.reset();
  6342. geoStream(object, areaStream);
  6343. return areaSum * 2;
  6344. }
  6345. function spherical(cartesian) {
  6346. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  6347. }
  6348. function cartesian(spherical) {
  6349. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  6350. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  6351. }
  6352. function cartesianDot(a, b) {
  6353. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6354. }
  6355. function cartesianCross(a, b) {
  6356. 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]];
  6357. }
  6358. // TODO return a
  6359. function cartesianAddInPlace(a, b) {
  6360. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  6361. }
  6362. function cartesianScale(vector, k) {
  6363. return [vector[0] * k, vector[1] * k, vector[2] * k];
  6364. }
  6365. // TODO return d
  6366. function cartesianNormalizeInPlace(d) {
  6367. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  6368. d[0] /= l, d[1] /= l, d[2] /= l;
  6369. }
  6370. var lambda0$1, phi0, lambda1, phi1, // bounds
  6371. lambda2, // previous lambda-coordinate
  6372. lambda00$1, phi00$1, // first point
  6373. p0, // previous 3D point
  6374. deltaSum = adder(),
  6375. ranges,
  6376. range;
  6377. var boundsStream = {
  6378. point: boundsPoint,
  6379. lineStart: boundsLineStart,
  6380. lineEnd: boundsLineEnd,
  6381. polygonStart: function() {
  6382. boundsStream.point = boundsRingPoint;
  6383. boundsStream.lineStart = boundsRingStart;
  6384. boundsStream.lineEnd = boundsRingEnd;
  6385. deltaSum.reset();
  6386. areaStream.polygonStart();
  6387. },
  6388. polygonEnd: function() {
  6389. areaStream.polygonEnd();
  6390. boundsStream.point = boundsPoint;
  6391. boundsStream.lineStart = boundsLineStart;
  6392. boundsStream.lineEnd = boundsLineEnd;
  6393. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6394. else if (deltaSum > epsilon$2) phi1 = 90;
  6395. else if (deltaSum < -epsilon$2) phi0 = -90;
  6396. range[0] = lambda0$1, range[1] = lambda1;
  6397. }
  6398. };
  6399. function boundsPoint(lambda, phi) {
  6400. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6401. if (phi < phi0) phi0 = phi;
  6402. if (phi > phi1) phi1 = phi;
  6403. }
  6404. function linePoint(lambda, phi) {
  6405. var p = cartesian([lambda * radians, phi * radians]);
  6406. if (p0) {
  6407. var normal = cartesianCross(p0, p),
  6408. equatorial = [normal[1], -normal[0], 0],
  6409. inflection = cartesianCross(equatorial, normal);
  6410. cartesianNormalizeInPlace(inflection);
  6411. inflection = spherical(inflection);
  6412. var delta = lambda - lambda2,
  6413. sign$$1 = delta > 0 ? 1 : -1,
  6414. lambdai = inflection[0] * degrees$1 * sign$$1,
  6415. phii,
  6416. antimeridian = abs(delta) > 180;
  6417. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6418. phii = inflection[1] * degrees$1;
  6419. if (phii > phi1) phi1 = phii;
  6420. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6421. phii = -inflection[1] * degrees$1;
  6422. if (phii < phi0) phi0 = phii;
  6423. } else {
  6424. if (phi < phi0) phi0 = phi;
  6425. if (phi > phi1) phi1 = phi;
  6426. }
  6427. if (antimeridian) {
  6428. if (lambda < lambda2) {
  6429. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6430. } else {
  6431. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6432. }
  6433. } else {
  6434. if (lambda1 >= lambda0$1) {
  6435. if (lambda < lambda0$1) lambda0$1 = lambda;
  6436. if (lambda > lambda1) lambda1 = lambda;
  6437. } else {
  6438. if (lambda > lambda2) {
  6439. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6440. } else {
  6441. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6442. }
  6443. }
  6444. }
  6445. } else {
  6446. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6447. }
  6448. if (phi < phi0) phi0 = phi;
  6449. if (phi > phi1) phi1 = phi;
  6450. p0 = p, lambda2 = lambda;
  6451. }
  6452. function boundsLineStart() {
  6453. boundsStream.point = linePoint;
  6454. }
  6455. function boundsLineEnd() {
  6456. range[0] = lambda0$1, range[1] = lambda1;
  6457. boundsStream.point = boundsPoint;
  6458. p0 = null;
  6459. }
  6460. function boundsRingPoint(lambda, phi) {
  6461. if (p0) {
  6462. var delta = lambda - lambda2;
  6463. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6464. } else {
  6465. lambda00$1 = lambda, phi00$1 = phi;
  6466. }
  6467. areaStream.point(lambda, phi);
  6468. linePoint(lambda, phi);
  6469. }
  6470. function boundsRingStart() {
  6471. areaStream.lineStart();
  6472. }
  6473. function boundsRingEnd() {
  6474. boundsRingPoint(lambda00$1, phi00$1);
  6475. areaStream.lineEnd();
  6476. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6477. range[0] = lambda0$1, range[1] = lambda1;
  6478. p0 = null;
  6479. }
  6480. // Finds the left-right distance between two longitudes.
  6481. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6482. // the distance between ±180° to be 360°.
  6483. function angle(lambda0, lambda1) {
  6484. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6485. }
  6486. function rangeCompare(a, b) {
  6487. return a[0] - b[0];
  6488. }
  6489. function rangeContains(range, x) {
  6490. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6491. }
  6492. function bounds(feature) {
  6493. var i, n, a, b, merged, deltaMax, delta;
  6494. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6495. ranges = [];
  6496. geoStream(feature, boundsStream);
  6497. // First, sort ranges by their minimum longitudes.
  6498. if (n = ranges.length) {
  6499. ranges.sort(rangeCompare);
  6500. // Then, merge any ranges that overlap.
  6501. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6502. b = ranges[i];
  6503. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6504. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6505. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6506. } else {
  6507. merged.push(a = b);
  6508. }
  6509. }
  6510. // Finally, find the largest gap between the merged ranges.
  6511. // The final bounding box will be the inverse of this gap.
  6512. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6513. b = merged[i];
  6514. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6515. }
  6516. }
  6517. ranges = range = null;
  6518. return lambda0$1 === Infinity || phi0 === Infinity
  6519. ? [[NaN, NaN], [NaN, NaN]]
  6520. : [[lambda0$1, phi0], [lambda1, phi1]];
  6521. }
  6522. var W0, W1,
  6523. X0, Y0, Z0,
  6524. X1, Y1, Z1,
  6525. X2, Y2, Z2,
  6526. lambda00$2, phi00$2, // first point
  6527. x0, y0, z0; // previous point
  6528. var centroidStream = {
  6529. sphere: noop$2,
  6530. point: centroidPoint,
  6531. lineStart: centroidLineStart,
  6532. lineEnd: centroidLineEnd,
  6533. polygonStart: function() {
  6534. centroidStream.lineStart = centroidRingStart;
  6535. centroidStream.lineEnd = centroidRingEnd;
  6536. },
  6537. polygonEnd: function() {
  6538. centroidStream.lineStart = centroidLineStart;
  6539. centroidStream.lineEnd = centroidLineEnd;
  6540. }
  6541. };
  6542. // Arithmetic mean of Cartesian vectors.
  6543. function centroidPoint(lambda, phi) {
  6544. lambda *= radians, phi *= radians;
  6545. var cosPhi = cos$1(phi);
  6546. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6547. }
  6548. function centroidPointCartesian(x, y, z) {
  6549. ++W0;
  6550. X0 += (x - X0) / W0;
  6551. Y0 += (y - Y0) / W0;
  6552. Z0 += (z - Z0) / W0;
  6553. }
  6554. function centroidLineStart() {
  6555. centroidStream.point = centroidLinePointFirst;
  6556. }
  6557. function centroidLinePointFirst(lambda, phi) {
  6558. lambda *= radians, phi *= radians;
  6559. var cosPhi = cos$1(phi);
  6560. x0 = cosPhi * cos$1(lambda);
  6561. y0 = cosPhi * sin$1(lambda);
  6562. z0 = sin$1(phi);
  6563. centroidStream.point = centroidLinePoint;
  6564. centroidPointCartesian(x0, y0, z0);
  6565. }
  6566. function centroidLinePoint(lambda, phi) {
  6567. lambda *= radians, phi *= radians;
  6568. var cosPhi = cos$1(phi),
  6569. x = cosPhi * cos$1(lambda),
  6570. y = cosPhi * sin$1(lambda),
  6571. z = sin$1(phi),
  6572. 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);
  6573. W1 += w;
  6574. X1 += w * (x0 + (x0 = x));
  6575. Y1 += w * (y0 + (y0 = y));
  6576. Z1 += w * (z0 + (z0 = z));
  6577. centroidPointCartesian(x0, y0, z0);
  6578. }
  6579. function centroidLineEnd() {
  6580. centroidStream.point = centroidPoint;
  6581. }
  6582. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6583. // J. Applied Mechanics 42, 239 (1975).
  6584. function centroidRingStart() {
  6585. centroidStream.point = centroidRingPointFirst;
  6586. }
  6587. function centroidRingEnd() {
  6588. centroidRingPoint(lambda00$2, phi00$2);
  6589. centroidStream.point = centroidPoint;
  6590. }
  6591. function centroidRingPointFirst(lambda, phi) {
  6592. lambda00$2 = lambda, phi00$2 = phi;
  6593. lambda *= radians, phi *= radians;
  6594. centroidStream.point = centroidRingPoint;
  6595. var cosPhi = cos$1(phi);
  6596. x0 = cosPhi * cos$1(lambda);
  6597. y0 = cosPhi * sin$1(lambda);
  6598. z0 = sin$1(phi);
  6599. centroidPointCartesian(x0, y0, z0);
  6600. }
  6601. function centroidRingPoint(lambda, phi) {
  6602. lambda *= radians, phi *= radians;
  6603. var cosPhi = cos$1(phi),
  6604. x = cosPhi * cos$1(lambda),
  6605. y = cosPhi * sin$1(lambda),
  6606. z = sin$1(phi),
  6607. cx = y0 * z - z0 * y,
  6608. cy = z0 * x - x0 * z,
  6609. cz = x0 * y - y0 * x,
  6610. m = sqrt(cx * cx + cy * cy + cz * cz),
  6611. w = asin(m), // line weight = angle
  6612. v = m && -w / m; // area weight multiplier
  6613. X2 += v * cx;
  6614. Y2 += v * cy;
  6615. Z2 += v * cz;
  6616. W1 += w;
  6617. X1 += w * (x0 + (x0 = x));
  6618. Y1 += w * (y0 + (y0 = y));
  6619. Z1 += w * (z0 + (z0 = z));
  6620. centroidPointCartesian(x0, y0, z0);
  6621. }
  6622. function centroid(object) {
  6623. W0 = W1 =
  6624. X0 = Y0 = Z0 =
  6625. X1 = Y1 = Z1 =
  6626. X2 = Y2 = Z2 = 0;
  6627. geoStream(object, centroidStream);
  6628. var x = X2,
  6629. y = Y2,
  6630. z = Z2,
  6631. m = x * x + y * y + z * z;
  6632. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6633. if (m < epsilon2$1) {
  6634. x = X1, y = Y1, z = Z1;
  6635. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6636. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6637. m = x * x + y * y + z * z;
  6638. // If the feature still has an undefined ccentroid, then return.
  6639. if (m < epsilon2$1) return [NaN, NaN];
  6640. }
  6641. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6642. }
  6643. function constant$8(x) {
  6644. return function() {
  6645. return x;
  6646. };
  6647. }
  6648. function compose(a, b) {
  6649. function compose(x, y) {
  6650. return x = a(x, y), b(x[0], x[1]);
  6651. }
  6652. if (a.invert && b.invert) compose.invert = function(x, y) {
  6653. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6654. };
  6655. return compose;
  6656. }
  6657. function rotationIdentity(lambda, phi) {
  6658. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6659. }
  6660. rotationIdentity.invert = rotationIdentity;
  6661. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6662. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6663. : rotationLambda(deltaLambda))
  6664. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6665. : rotationIdentity);
  6666. }
  6667. function forwardRotationLambda(deltaLambda) {
  6668. return function(lambda, phi) {
  6669. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6670. };
  6671. }
  6672. function rotationLambda(deltaLambda) {
  6673. var rotation = forwardRotationLambda(deltaLambda);
  6674. rotation.invert = forwardRotationLambda(-deltaLambda);
  6675. return rotation;
  6676. }
  6677. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6678. var cosDeltaPhi = cos$1(deltaPhi),
  6679. sinDeltaPhi = sin$1(deltaPhi),
  6680. cosDeltaGamma = cos$1(deltaGamma),
  6681. sinDeltaGamma = sin$1(deltaGamma);
  6682. function rotation(lambda, phi) {
  6683. var cosPhi = cos$1(phi),
  6684. x = cos$1(lambda) * cosPhi,
  6685. y = sin$1(lambda) * cosPhi,
  6686. z = sin$1(phi),
  6687. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6688. return [
  6689. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6690. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6691. ];
  6692. }
  6693. rotation.invert = function(lambda, phi) {
  6694. var cosPhi = cos$1(phi),
  6695. x = cos$1(lambda) * cosPhi,
  6696. y = sin$1(lambda) * cosPhi,
  6697. z = sin$1(phi),
  6698. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6699. return [
  6700. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6701. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6702. ];
  6703. };
  6704. return rotation;
  6705. }
  6706. function rotation(rotate) {
  6707. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6708. function forward(coordinates) {
  6709. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6710. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6711. }
  6712. forward.invert = function(coordinates) {
  6713. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6714. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6715. };
  6716. return forward;
  6717. }
  6718. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6719. function circleStream(stream, radius, delta, direction, t0, t1) {
  6720. if (!delta) return;
  6721. var cosRadius = cos$1(radius),
  6722. sinRadius = sin$1(radius),
  6723. step = direction * delta;
  6724. if (t0 == null) {
  6725. t0 = radius + direction * tau$3;
  6726. t1 = radius - step / 2;
  6727. } else {
  6728. t0 = circleRadius(cosRadius, t0);
  6729. t1 = circleRadius(cosRadius, t1);
  6730. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6731. }
  6732. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6733. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6734. stream.point(point[0], point[1]);
  6735. }
  6736. }
  6737. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6738. function circleRadius(cosRadius, point) {
  6739. point = cartesian(point), point[0] -= cosRadius;
  6740. cartesianNormalizeInPlace(point);
  6741. var radius = acos(-point[1]);
  6742. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6743. }
  6744. function circle() {
  6745. var center = constant$8([0, 0]),
  6746. radius = constant$8(90),
  6747. precision = constant$8(6),
  6748. ring,
  6749. rotate,
  6750. stream = {point: point};
  6751. function point(x, y) {
  6752. ring.push(x = rotate(x, y));
  6753. x[0] *= degrees$1, x[1] *= degrees$1;
  6754. }
  6755. function circle() {
  6756. var c = center.apply(this, arguments),
  6757. r = radius.apply(this, arguments) * radians,
  6758. p = precision.apply(this, arguments) * radians;
  6759. ring = [];
  6760. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6761. circleStream(stream, r, p, 1);
  6762. c = {type: "Polygon", coordinates: [ring]};
  6763. ring = rotate = null;
  6764. return c;
  6765. }
  6766. circle.center = function(_) {
  6767. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  6768. };
  6769. circle.radius = function(_) {
  6770. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  6771. };
  6772. circle.precision = function(_) {
  6773. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  6774. };
  6775. return circle;
  6776. }
  6777. function clipBuffer() {
  6778. var lines = [],
  6779. line;
  6780. return {
  6781. point: function(x, y) {
  6782. line.push([x, y]);
  6783. },
  6784. lineStart: function() {
  6785. lines.push(line = []);
  6786. },
  6787. lineEnd: noop$2,
  6788. rejoin: function() {
  6789. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6790. },
  6791. result: function() {
  6792. var result = lines;
  6793. lines = [];
  6794. line = null;
  6795. return result;
  6796. }
  6797. };
  6798. }
  6799. function pointEqual(a, b) {
  6800. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6801. }
  6802. function Intersection(point, points, other, entry) {
  6803. this.x = point;
  6804. this.z = points;
  6805. this.o = other; // another intersection
  6806. this.e = entry; // is an entry?
  6807. this.v = false; // visited
  6808. this.n = this.p = null; // next & previous
  6809. }
  6810. // A generalized polygon clipping algorithm: given a polygon that has been cut
  6811. // into its visible line segments, and rejoins the segments by interpolating
  6812. // along the clip edge.
  6813. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  6814. var subject = [],
  6815. clip = [],
  6816. i,
  6817. n;
  6818. segments.forEach(function(segment) {
  6819. if ((n = segment.length - 1) <= 0) return;
  6820. var n, p0 = segment[0], p1 = segment[n], x;
  6821. // If the first and last points of a segment are coincident, then treat as a
  6822. // closed ring. TODO if all rings are closed, then the winding order of the
  6823. // exterior ring should be checked.
  6824. if (pointEqual(p0, p1)) {
  6825. stream.lineStart();
  6826. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  6827. stream.lineEnd();
  6828. return;
  6829. }
  6830. subject.push(x = new Intersection(p0, segment, null, true));
  6831. clip.push(x.o = new Intersection(p0, null, x, false));
  6832. subject.push(x = new Intersection(p1, segment, null, false));
  6833. clip.push(x.o = new Intersection(p1, null, x, true));
  6834. });
  6835. if (!subject.length) return;
  6836. clip.sort(compareIntersection);
  6837. link$1(subject);
  6838. link$1(clip);
  6839. for (i = 0, n = clip.length; i < n; ++i) {
  6840. clip[i].e = startInside = !startInside;
  6841. }
  6842. var start = subject[0],
  6843. points,
  6844. point;
  6845. while (1) {
  6846. // Find first unvisited intersection.
  6847. var current = start,
  6848. isSubject = true;
  6849. while (current.v) if ((current = current.n) === start) return;
  6850. points = current.z;
  6851. stream.lineStart();
  6852. do {
  6853. current.v = current.o.v = true;
  6854. if (current.e) {
  6855. if (isSubject) {
  6856. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  6857. } else {
  6858. interpolate(current.x, current.n.x, 1, stream);
  6859. }
  6860. current = current.n;
  6861. } else {
  6862. if (isSubject) {
  6863. points = current.p.z;
  6864. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  6865. } else {
  6866. interpolate(current.x, current.p.x, -1, stream);
  6867. }
  6868. current = current.p;
  6869. }
  6870. current = current.o;
  6871. points = current.z;
  6872. isSubject = !isSubject;
  6873. } while (!current.v);
  6874. stream.lineEnd();
  6875. }
  6876. }
  6877. function link$1(array) {
  6878. if (!(n = array.length)) return;
  6879. var n,
  6880. i = 0,
  6881. a = array[0],
  6882. b;
  6883. while (++i < n) {
  6884. a.n = b = array[i];
  6885. b.p = a;
  6886. a = b;
  6887. }
  6888. a.n = b = array[0];
  6889. b.p = a;
  6890. }
  6891. var sum$1 = adder();
  6892. function polygonContains(polygon, point) {
  6893. var lambda = point[0],
  6894. phi = point[1],
  6895. sinPhi = sin$1(phi),
  6896. normal = [sin$1(lambda), -cos$1(lambda), 0],
  6897. angle = 0,
  6898. winding = 0;
  6899. sum$1.reset();
  6900. if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
  6901. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
  6902. for (var i = 0, n = polygon.length; i < n; ++i) {
  6903. if (!(m = (ring = polygon[i]).length)) continue;
  6904. var ring,
  6905. m,
  6906. point0 = ring[m - 1],
  6907. lambda0 = point0[0],
  6908. phi0 = point0[1] / 2 + quarterPi,
  6909. sinPhi0 = sin$1(phi0),
  6910. cosPhi0 = cos$1(phi0);
  6911. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  6912. var point1 = ring[j],
  6913. lambda1 = point1[0],
  6914. phi1 = point1[1] / 2 + quarterPi,
  6915. sinPhi1 = sin$1(phi1),
  6916. cosPhi1 = cos$1(phi1),
  6917. delta = lambda1 - lambda0,
  6918. sign$$1 = delta >= 0 ? 1 : -1,
  6919. absDelta = sign$$1 * delta,
  6920. antimeridian = absDelta > pi$3,
  6921. k = sinPhi0 * sinPhi1;
  6922. sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  6923. angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
  6924. // Are the longitudes either side of the point’s meridian (lambda),
  6925. // and are the latitudes smaller than the parallel (phi)?
  6926. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  6927. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  6928. cartesianNormalizeInPlace(arc);
  6929. var intersection = cartesianCross(normal, arc);
  6930. cartesianNormalizeInPlace(intersection);
  6931. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  6932. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  6933. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  6934. }
  6935. }
  6936. }
  6937. }
  6938. // First, determine whether the South pole is inside or outside:
  6939. //
  6940. // It is inside if:
  6941. // * the polygon winds around it in a clockwise direction.
  6942. // * the polygon does not (cumulatively) wind around it, but has a negative
  6943. // (counter-clockwise) area.
  6944. //
  6945. // Second, count the (signed) number of times a segment crosses a lambda
  6946. // from the point to the South pole. If it is zero, then the point is the
  6947. // same side as the South pole.
  6948. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  6949. }
  6950. function clip(pointVisible, clipLine, interpolate, start) {
  6951. return function(sink) {
  6952. var line = clipLine(sink),
  6953. ringBuffer = clipBuffer(),
  6954. ringSink = clipLine(ringBuffer),
  6955. polygonStarted = false,
  6956. polygon,
  6957. segments,
  6958. ring;
  6959. var clip = {
  6960. point: point,
  6961. lineStart: lineStart,
  6962. lineEnd: lineEnd,
  6963. polygonStart: function() {
  6964. clip.point = pointRing;
  6965. clip.lineStart = ringStart;
  6966. clip.lineEnd = ringEnd;
  6967. segments = [];
  6968. polygon = [];
  6969. },
  6970. polygonEnd: function() {
  6971. clip.point = point;
  6972. clip.lineStart = lineStart;
  6973. clip.lineEnd = lineEnd;
  6974. segments = merge(segments);
  6975. var startInside = polygonContains(polygon, start);
  6976. if (segments.length) {
  6977. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6978. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  6979. } else if (startInside) {
  6980. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6981. sink.lineStart();
  6982. interpolate(null, null, 1, sink);
  6983. sink.lineEnd();
  6984. }
  6985. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  6986. segments = polygon = null;
  6987. },
  6988. sphere: function() {
  6989. sink.polygonStart();
  6990. sink.lineStart();
  6991. interpolate(null, null, 1, sink);
  6992. sink.lineEnd();
  6993. sink.polygonEnd();
  6994. }
  6995. };
  6996. function point(lambda, phi) {
  6997. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  6998. }
  6999. function pointLine(lambda, phi) {
  7000. line.point(lambda, phi);
  7001. }
  7002. function lineStart() {
  7003. clip.point = pointLine;
  7004. line.lineStart();
  7005. }
  7006. function lineEnd() {
  7007. clip.point = point;
  7008. line.lineEnd();
  7009. }
  7010. function pointRing(lambda, phi) {
  7011. ring.push([lambda, phi]);
  7012. ringSink.point(lambda, phi);
  7013. }
  7014. function ringStart() {
  7015. ringSink.lineStart();
  7016. ring = [];
  7017. }
  7018. function ringEnd() {
  7019. pointRing(ring[0][0], ring[0][1]);
  7020. ringSink.lineEnd();
  7021. var clean = ringSink.clean(),
  7022. ringSegments = ringBuffer.result(),
  7023. i, n = ringSegments.length, m,
  7024. segment,
  7025. point;
  7026. ring.pop();
  7027. polygon.push(ring);
  7028. ring = null;
  7029. if (!n) return;
  7030. // No intersections.
  7031. if (clean & 1) {
  7032. segment = ringSegments[0];
  7033. if ((m = segment.length - 1) > 0) {
  7034. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7035. sink.lineStart();
  7036. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7037. sink.lineEnd();
  7038. }
  7039. return;
  7040. }
  7041. // Rejoin connected segments.
  7042. // TODO reuse ringBuffer.rejoin()?
  7043. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7044. segments.push(ringSegments.filter(validSegment));
  7045. }
  7046. return clip;
  7047. };
  7048. }
  7049. function validSegment(segment) {
  7050. return segment.length > 1;
  7051. }
  7052. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7053. // and circle clipping, the same comparison is used.
  7054. function compareIntersection(a, b) {
  7055. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7056. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7057. }
  7058. var clipAntimeridian = clip(
  7059. function() { return true; },
  7060. clipAntimeridianLine,
  7061. clipAntimeridianInterpolate,
  7062. [-pi$3, -halfPi$2]
  7063. );
  7064. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7065. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7066. // intersections, and the first and last segments should be rejoined.
  7067. function clipAntimeridianLine(stream) {
  7068. var lambda0 = NaN,
  7069. phi0 = NaN,
  7070. sign0 = NaN,
  7071. clean; // no intersections
  7072. return {
  7073. lineStart: function() {
  7074. stream.lineStart();
  7075. clean = 1;
  7076. },
  7077. point: function(lambda1, phi1) {
  7078. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7079. delta = abs(lambda1 - lambda0);
  7080. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7081. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7082. stream.point(sign0, phi0);
  7083. stream.lineEnd();
  7084. stream.lineStart();
  7085. stream.point(sign1, phi0);
  7086. stream.point(lambda1, phi0);
  7087. clean = 0;
  7088. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7089. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7090. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7091. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7092. stream.point(sign0, phi0);
  7093. stream.lineEnd();
  7094. stream.lineStart();
  7095. stream.point(sign1, phi0);
  7096. clean = 0;
  7097. }
  7098. stream.point(lambda0 = lambda1, phi0 = phi1);
  7099. sign0 = sign1;
  7100. },
  7101. lineEnd: function() {
  7102. stream.lineEnd();
  7103. lambda0 = phi0 = NaN;
  7104. },
  7105. clean: function() {
  7106. return 2 - clean; // if intersections, rejoin first and last segments
  7107. }
  7108. };
  7109. }
  7110. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7111. var cosPhi0,
  7112. cosPhi1,
  7113. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7114. return abs(sinLambda0Lambda1) > epsilon$2
  7115. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7116. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7117. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7118. : (phi0 + phi1) / 2;
  7119. }
  7120. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7121. var phi;
  7122. if (from == null) {
  7123. phi = direction * halfPi$2;
  7124. stream.point(-pi$3, phi);
  7125. stream.point(0, phi);
  7126. stream.point(pi$3, phi);
  7127. stream.point(pi$3, 0);
  7128. stream.point(pi$3, -phi);
  7129. stream.point(0, -phi);
  7130. stream.point(-pi$3, -phi);
  7131. stream.point(-pi$3, 0);
  7132. stream.point(-pi$3, phi);
  7133. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7134. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7135. phi = direction * lambda / 2;
  7136. stream.point(-lambda, phi);
  7137. stream.point(0, phi);
  7138. stream.point(lambda, phi);
  7139. } else {
  7140. stream.point(to[0], to[1]);
  7141. }
  7142. }
  7143. function clipCircle(radius) {
  7144. var cr = cos$1(radius),
  7145. delta = 6 * radians,
  7146. smallRadius = cr > 0,
  7147. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7148. function interpolate(from, to, direction, stream) {
  7149. circleStream(stream, radius, delta, direction, from, to);
  7150. }
  7151. function visible(lambda, phi) {
  7152. return cos$1(lambda) * cos$1(phi) > cr;
  7153. }
  7154. // Takes a line and cuts into visible segments. Return values used for polygon
  7155. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7156. // intersections 2 - there were intersections, and the first and last segments
  7157. // should be rejoined.
  7158. function clipLine(stream) {
  7159. var point0, // previous point
  7160. c0, // code for previous point
  7161. v0, // visibility of previous point
  7162. v00, // visibility of first point
  7163. clean; // no intersections
  7164. return {
  7165. lineStart: function() {
  7166. v00 = v0 = false;
  7167. clean = 1;
  7168. },
  7169. point: function(lambda, phi) {
  7170. var point1 = [lambda, phi],
  7171. point2,
  7172. v = visible(lambda, phi),
  7173. c = smallRadius
  7174. ? v ? 0 : code(lambda, phi)
  7175. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7176. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7177. // Handle degeneracies.
  7178. // TODO ignore if not clipping polygons.
  7179. if (v !== v0) {
  7180. point2 = intersect(point0, point1);
  7181. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7182. point1[0] += epsilon$2;
  7183. point1[1] += epsilon$2;
  7184. v = visible(point1[0], point1[1]);
  7185. }
  7186. }
  7187. if (v !== v0) {
  7188. clean = 0;
  7189. if (v) {
  7190. // outside going in
  7191. stream.lineStart();
  7192. point2 = intersect(point1, point0);
  7193. stream.point(point2[0], point2[1]);
  7194. } else {
  7195. // inside going out
  7196. point2 = intersect(point0, point1);
  7197. stream.point(point2[0], point2[1]);
  7198. stream.lineEnd();
  7199. }
  7200. point0 = point2;
  7201. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7202. var t;
  7203. // If the codes for two points are different, or are both zero,
  7204. // and there this segment intersects with the small circle.
  7205. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7206. clean = 0;
  7207. if (smallRadius) {
  7208. stream.lineStart();
  7209. stream.point(t[0][0], t[0][1]);
  7210. stream.point(t[1][0], t[1][1]);
  7211. stream.lineEnd();
  7212. } else {
  7213. stream.point(t[1][0], t[1][1]);
  7214. stream.lineEnd();
  7215. stream.lineStart();
  7216. stream.point(t[0][0], t[0][1]);
  7217. }
  7218. }
  7219. }
  7220. if (v && (!point0 || !pointEqual(point0, point1))) {
  7221. stream.point(point1[0], point1[1]);
  7222. }
  7223. point0 = point1, v0 = v, c0 = c;
  7224. },
  7225. lineEnd: function() {
  7226. if (v0) stream.lineEnd();
  7227. point0 = null;
  7228. },
  7229. // Rejoin first and last segments if there were intersections and the first
  7230. // and last points were visible.
  7231. clean: function() {
  7232. return clean | ((v00 && v0) << 1);
  7233. }
  7234. };
  7235. }
  7236. // Intersects the great circle between a and b with the clip circle.
  7237. function intersect(a, b, two) {
  7238. var pa = cartesian(a),
  7239. pb = cartesian(b);
  7240. // We have two planes, n1.p = d1 and n2.p = d2.
  7241. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7242. var n1 = [1, 0, 0], // normal
  7243. n2 = cartesianCross(pa, pb),
  7244. n2n2 = cartesianDot(n2, n2),
  7245. n1n2 = n2[0], // cartesianDot(n1, n2),
  7246. determinant = n2n2 - n1n2 * n1n2;
  7247. // Two polar points.
  7248. if (!determinant) return !two && a;
  7249. var c1 = cr * n2n2 / determinant,
  7250. c2 = -cr * n1n2 / determinant,
  7251. n1xn2 = cartesianCross(n1, n2),
  7252. A = cartesianScale(n1, c1),
  7253. B = cartesianScale(n2, c2);
  7254. cartesianAddInPlace(A, B);
  7255. // Solve |p(t)|^2 = 1.
  7256. var u = n1xn2,
  7257. w = cartesianDot(A, u),
  7258. uu = cartesianDot(u, u),
  7259. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7260. if (t2 < 0) return;
  7261. var t = sqrt(t2),
  7262. q = cartesianScale(u, (-w - t) / uu);
  7263. cartesianAddInPlace(q, A);
  7264. q = spherical(q);
  7265. if (!two) return q;
  7266. // Two intersection points.
  7267. var lambda0 = a[0],
  7268. lambda1 = b[0],
  7269. phi0 = a[1],
  7270. phi1 = b[1],
  7271. z;
  7272. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7273. var delta = lambda1 - lambda0,
  7274. polar = abs(delta - pi$3) < epsilon$2,
  7275. meridian = polar || delta < epsilon$2;
  7276. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7277. // Check that the first point is between a and b.
  7278. if (meridian
  7279. ? polar
  7280. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7281. : phi0 <= q[1] && q[1] <= phi1
  7282. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7283. var q1 = cartesianScale(u, (-w + t) / uu);
  7284. cartesianAddInPlace(q1, A);
  7285. return [q, spherical(q1)];
  7286. }
  7287. }
  7288. // Generates a 4-bit vector representing the location of a point relative to
  7289. // the small circle's bounding box.
  7290. function code(lambda, phi) {
  7291. var r = smallRadius ? radius : pi$3 - radius,
  7292. code = 0;
  7293. if (lambda < -r) code |= 1; // left
  7294. else if (lambda > r) code |= 2; // right
  7295. if (phi < -r) code |= 4; // below
  7296. else if (phi > r) code |= 8; // above
  7297. return code;
  7298. }
  7299. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7300. }
  7301. function clipLine(a, b, x0, y0, x1, y1) {
  7302. var ax = a[0],
  7303. ay = a[1],
  7304. bx = b[0],
  7305. by = b[1],
  7306. t0 = 0,
  7307. t1 = 1,
  7308. dx = bx - ax,
  7309. dy = by - ay,
  7310. r;
  7311. r = x0 - ax;
  7312. if (!dx && r > 0) return;
  7313. r /= dx;
  7314. if (dx < 0) {
  7315. if (r < t0) return;
  7316. if (r < t1) t1 = r;
  7317. } else if (dx > 0) {
  7318. if (r > t1) return;
  7319. if (r > t0) t0 = r;
  7320. }
  7321. r = x1 - ax;
  7322. if (!dx && r < 0) return;
  7323. r /= dx;
  7324. if (dx < 0) {
  7325. if (r > t1) return;
  7326. if (r > t0) t0 = r;
  7327. } else if (dx > 0) {
  7328. if (r < t0) return;
  7329. if (r < t1) t1 = r;
  7330. }
  7331. r = y0 - ay;
  7332. if (!dy && r > 0) return;
  7333. r /= dy;
  7334. if (dy < 0) {
  7335. if (r < t0) return;
  7336. if (r < t1) t1 = r;
  7337. } else if (dy > 0) {
  7338. if (r > t1) return;
  7339. if (r > t0) t0 = r;
  7340. }
  7341. r = y1 - ay;
  7342. if (!dy && r < 0) return;
  7343. r /= dy;
  7344. if (dy < 0) {
  7345. if (r > t1) return;
  7346. if (r > t0) t0 = r;
  7347. } else if (dy > 0) {
  7348. if (r < t0) return;
  7349. if (r < t1) t1 = r;
  7350. }
  7351. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  7352. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  7353. return true;
  7354. }
  7355. var clipMax = 1e9, clipMin = -clipMax;
  7356. // TODO Use d3-polygon’s polygonContains here for the ring check?
  7357. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  7358. function clipRectangle(x0, y0, x1, y1) {
  7359. function visible(x, y) {
  7360. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  7361. }
  7362. function interpolate(from, to, direction, stream) {
  7363. var a = 0, a1 = 0;
  7364. if (from == null
  7365. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  7366. || comparePoint(from, to) < 0 ^ direction > 0) {
  7367. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  7368. while ((a = (a + direction + 4) % 4) !== a1);
  7369. } else {
  7370. stream.point(to[0], to[1]);
  7371. }
  7372. }
  7373. function corner(p, direction) {
  7374. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  7375. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  7376. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  7377. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  7378. }
  7379. function compareIntersection(a, b) {
  7380. return comparePoint(a.x, b.x);
  7381. }
  7382. function comparePoint(a, b) {
  7383. var ca = corner(a, 1),
  7384. cb = corner(b, 1);
  7385. return ca !== cb ? ca - cb
  7386. : ca === 0 ? b[1] - a[1]
  7387. : ca === 1 ? a[0] - b[0]
  7388. : ca === 2 ? a[1] - b[1]
  7389. : b[0] - a[0];
  7390. }
  7391. return function(stream) {
  7392. var activeStream = stream,
  7393. bufferStream = clipBuffer(),
  7394. segments,
  7395. polygon,
  7396. ring,
  7397. x__, y__, v__, // first point
  7398. x_, y_, v_, // previous point
  7399. first,
  7400. clean;
  7401. var clipStream = {
  7402. point: point,
  7403. lineStart: lineStart,
  7404. lineEnd: lineEnd,
  7405. polygonStart: polygonStart,
  7406. polygonEnd: polygonEnd
  7407. };
  7408. function point(x, y) {
  7409. if (visible(x, y)) activeStream.point(x, y);
  7410. }
  7411. function polygonInside() {
  7412. var winding = 0;
  7413. for (var i = 0, n = polygon.length; i < n; ++i) {
  7414. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  7415. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  7416. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  7417. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  7418. }
  7419. }
  7420. return winding;
  7421. }
  7422. // Buffer geometry within a polygon and then clip it en masse.
  7423. function polygonStart() {
  7424. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  7425. }
  7426. function polygonEnd() {
  7427. var startInside = polygonInside(),
  7428. cleanInside = clean && startInside,
  7429. visible = (segments = merge(segments)).length;
  7430. if (cleanInside || visible) {
  7431. stream.polygonStart();
  7432. if (cleanInside) {
  7433. stream.lineStart();
  7434. interpolate(null, null, 1, stream);
  7435. stream.lineEnd();
  7436. }
  7437. if (visible) {
  7438. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7439. }
  7440. stream.polygonEnd();
  7441. }
  7442. activeStream = stream, segments = polygon = ring = null;
  7443. }
  7444. function lineStart() {
  7445. clipStream.point = linePoint;
  7446. if (polygon) polygon.push(ring = []);
  7447. first = true;
  7448. v_ = false;
  7449. x_ = y_ = NaN;
  7450. }
  7451. // TODO rather than special-case polygons, simply handle them separately.
  7452. // Ideally, coincident intersection points should be jittered to avoid
  7453. // clipping issues.
  7454. function lineEnd() {
  7455. if (segments) {
  7456. linePoint(x__, y__);
  7457. if (v__ && v_) bufferStream.rejoin();
  7458. segments.push(bufferStream.result());
  7459. }
  7460. clipStream.point = point;
  7461. if (v_) activeStream.lineEnd();
  7462. }
  7463. function linePoint(x, y) {
  7464. var v = visible(x, y);
  7465. if (polygon) ring.push([x, y]);
  7466. if (first) {
  7467. x__ = x, y__ = y, v__ = v;
  7468. first = false;
  7469. if (v) {
  7470. activeStream.lineStart();
  7471. activeStream.point(x, y);
  7472. }
  7473. } else {
  7474. if (v && v_) activeStream.point(x, y);
  7475. else {
  7476. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7477. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7478. if (clipLine(a, b, x0, y0, x1, y1)) {
  7479. if (!v_) {
  7480. activeStream.lineStart();
  7481. activeStream.point(a[0], a[1]);
  7482. }
  7483. activeStream.point(b[0], b[1]);
  7484. if (!v) activeStream.lineEnd();
  7485. clean = false;
  7486. } else if (v) {
  7487. activeStream.lineStart();
  7488. activeStream.point(x, y);
  7489. clean = false;
  7490. }
  7491. }
  7492. }
  7493. x_ = x, y_ = y, v_ = v;
  7494. }
  7495. return clipStream;
  7496. };
  7497. }
  7498. function extent$1() {
  7499. var x0 = 0,
  7500. y0 = 0,
  7501. x1 = 960,
  7502. y1 = 500,
  7503. cache,
  7504. cacheStream,
  7505. clip;
  7506. return clip = {
  7507. stream: function(stream) {
  7508. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7509. },
  7510. extent: function(_) {
  7511. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7512. }
  7513. };
  7514. }
  7515. var lengthSum = adder(),
  7516. lambda0$2,
  7517. sinPhi0$1,
  7518. cosPhi0$1;
  7519. var lengthStream = {
  7520. sphere: noop$2,
  7521. point: noop$2,
  7522. lineStart: lengthLineStart,
  7523. lineEnd: noop$2,
  7524. polygonStart: noop$2,
  7525. polygonEnd: noop$2
  7526. };
  7527. function lengthLineStart() {
  7528. lengthStream.point = lengthPointFirst;
  7529. lengthStream.lineEnd = lengthLineEnd;
  7530. }
  7531. function lengthLineEnd() {
  7532. lengthStream.point = lengthStream.lineEnd = noop$2;
  7533. }
  7534. function lengthPointFirst(lambda, phi) {
  7535. lambda *= radians, phi *= radians;
  7536. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7537. lengthStream.point = lengthPoint;
  7538. }
  7539. function lengthPoint(lambda, phi) {
  7540. lambda *= radians, phi *= radians;
  7541. var sinPhi = sin$1(phi),
  7542. cosPhi = cos$1(phi),
  7543. delta = abs(lambda - lambda0$2),
  7544. cosDelta = cos$1(delta),
  7545. sinDelta = sin$1(delta),
  7546. x = cosPhi * sinDelta,
  7547. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7548. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7549. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7550. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7551. }
  7552. function length$1(object) {
  7553. lengthSum.reset();
  7554. geoStream(object, lengthStream);
  7555. return +lengthSum;
  7556. }
  7557. var coordinates = [null, null],
  7558. object$1 = {type: "LineString", coordinates: coordinates};
  7559. function distance(a, b) {
  7560. coordinates[0] = a;
  7561. coordinates[1] = b;
  7562. return length$1(object$1);
  7563. }
  7564. var containsObjectType = {
  7565. Feature: function(object, point) {
  7566. return containsGeometry(object.geometry, point);
  7567. },
  7568. FeatureCollection: function(object, point) {
  7569. var features = object.features, i = -1, n = features.length;
  7570. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7571. return false;
  7572. }
  7573. };
  7574. var containsGeometryType = {
  7575. Sphere: function() {
  7576. return true;
  7577. },
  7578. Point: function(object, point) {
  7579. return containsPoint(object.coordinates, point);
  7580. },
  7581. MultiPoint: function(object, point) {
  7582. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7583. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7584. return false;
  7585. },
  7586. LineString: function(object, point) {
  7587. return containsLine(object.coordinates, point);
  7588. },
  7589. MultiLineString: function(object, point) {
  7590. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7591. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7592. return false;
  7593. },
  7594. Polygon: function(object, point) {
  7595. return containsPolygon(object.coordinates, point);
  7596. },
  7597. MultiPolygon: function(object, point) {
  7598. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7599. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7600. return false;
  7601. },
  7602. GeometryCollection: function(object, point) {
  7603. var geometries = object.geometries, i = -1, n = geometries.length;
  7604. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7605. return false;
  7606. }
  7607. };
  7608. function containsGeometry(geometry, point) {
  7609. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7610. ? containsGeometryType[geometry.type](geometry, point)
  7611. : false;
  7612. }
  7613. function containsPoint(coordinates, point) {
  7614. return distance(coordinates, point) === 0;
  7615. }
  7616. function containsLine(coordinates, point) {
  7617. var ab = distance(coordinates[0], coordinates[1]),
  7618. ao = distance(coordinates[0], point),
  7619. ob = distance(point, coordinates[1]);
  7620. return ao + ob <= ab + epsilon$2;
  7621. }
  7622. function containsPolygon(coordinates, point) {
  7623. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7624. }
  7625. function ringRadians(ring) {
  7626. return ring = ring.map(pointRadians), ring.pop(), ring;
  7627. }
  7628. function pointRadians(point) {
  7629. return [point[0] * radians, point[1] * radians];
  7630. }
  7631. function contains$1(object, point) {
  7632. return (object && containsObjectType.hasOwnProperty(object.type)
  7633. ? containsObjectType[object.type]
  7634. : containsGeometry)(object, point);
  7635. }
  7636. function graticuleX(y0, y1, dy) {
  7637. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7638. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7639. }
  7640. function graticuleY(x0, x1, dx) {
  7641. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7642. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7643. }
  7644. function graticule() {
  7645. var x1, x0, X1, X0,
  7646. y1, y0, Y1, Y0,
  7647. dx = 10, dy = dx, DX = 90, DY = 360,
  7648. x, y, X, Y,
  7649. precision = 2.5;
  7650. function graticule() {
  7651. return {type: "MultiLineString", coordinates: lines()};
  7652. }
  7653. function lines() {
  7654. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7655. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7656. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7657. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7658. }
  7659. graticule.lines = function() {
  7660. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7661. };
  7662. graticule.outline = function() {
  7663. return {
  7664. type: "Polygon",
  7665. coordinates: [
  7666. X(X0).concat(
  7667. Y(Y1).slice(1),
  7668. X(X1).reverse().slice(1),
  7669. Y(Y0).reverse().slice(1))
  7670. ]
  7671. };
  7672. };
  7673. graticule.extent = function(_) {
  7674. if (!arguments.length) return graticule.extentMinor();
  7675. return graticule.extentMajor(_).extentMinor(_);
  7676. };
  7677. graticule.extentMajor = function(_) {
  7678. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7679. X0 = +_[0][0], X1 = +_[1][0];
  7680. Y0 = +_[0][1], Y1 = +_[1][1];
  7681. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7682. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7683. return graticule.precision(precision);
  7684. };
  7685. graticule.extentMinor = 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.step = function(_) {
  7694. if (!arguments.length) return graticule.stepMinor();
  7695. return graticule.stepMajor(_).stepMinor(_);
  7696. };
  7697. graticule.stepMajor = function(_) {
  7698. if (!arguments.length) return [DX, DY];
  7699. DX = +_[0], DY = +_[1];
  7700. return graticule;
  7701. };
  7702. graticule.stepMinor = function(_) {
  7703. if (!arguments.length) return [dx, dy];
  7704. dx = +_[0], dy = +_[1];
  7705. return graticule;
  7706. };
  7707. graticule.precision = function(_) {
  7708. if (!arguments.length) return precision;
  7709. precision = +_;
  7710. x = graticuleX(y0, y1, 90);
  7711. y = graticuleY(x0, x1, precision);
  7712. X = graticuleX(Y0, Y1, 90);
  7713. Y = graticuleY(X0, X1, precision);
  7714. return graticule;
  7715. };
  7716. return graticule
  7717. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7718. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7719. }
  7720. function graticule10() {
  7721. return graticule()();
  7722. }
  7723. function interpolate$1(a, b) {
  7724. var x0 = a[0] * radians,
  7725. y0 = a[1] * radians,
  7726. x1 = b[0] * radians,
  7727. y1 = b[1] * radians,
  7728. cy0 = cos$1(y0),
  7729. sy0 = sin$1(y0),
  7730. cy1 = cos$1(y1),
  7731. sy1 = sin$1(y1),
  7732. kx0 = cy0 * cos$1(x0),
  7733. ky0 = cy0 * sin$1(x0),
  7734. kx1 = cy1 * cos$1(x1),
  7735. ky1 = cy1 * sin$1(x1),
  7736. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  7737. k = sin$1(d);
  7738. var interpolate = d ? function(t) {
  7739. var B = sin$1(t *= d) / k,
  7740. A = sin$1(d - t) / k,
  7741. x = A * kx0 + B * kx1,
  7742. y = A * ky0 + B * ky1,
  7743. z = A * sy0 + B * sy1;
  7744. return [
  7745. atan2(y, x) * degrees$1,
  7746. atan2(z, sqrt(x * x + y * y)) * degrees$1
  7747. ];
  7748. } : function() {
  7749. return [x0 * degrees$1, y0 * degrees$1];
  7750. };
  7751. interpolate.distance = d;
  7752. return interpolate;
  7753. }
  7754. function identity$4(x) {
  7755. return x;
  7756. }
  7757. var areaSum$1 = adder(),
  7758. areaRingSum$1 = adder(),
  7759. x00,
  7760. y00,
  7761. x0$1,
  7762. y0$1;
  7763. var areaStream$1 = {
  7764. point: noop$2,
  7765. lineStart: noop$2,
  7766. lineEnd: noop$2,
  7767. polygonStart: function() {
  7768. areaStream$1.lineStart = areaRingStart$1;
  7769. areaStream$1.lineEnd = areaRingEnd$1;
  7770. },
  7771. polygonEnd: function() {
  7772. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  7773. areaSum$1.add(abs(areaRingSum$1));
  7774. areaRingSum$1.reset();
  7775. },
  7776. result: function() {
  7777. var area = areaSum$1 / 2;
  7778. areaSum$1.reset();
  7779. return area;
  7780. }
  7781. };
  7782. function areaRingStart$1() {
  7783. areaStream$1.point = areaPointFirst$1;
  7784. }
  7785. function areaPointFirst$1(x, y) {
  7786. areaStream$1.point = areaPoint$1;
  7787. x00 = x0$1 = x, y00 = y0$1 = y;
  7788. }
  7789. function areaPoint$1(x, y) {
  7790. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  7791. x0$1 = x, y0$1 = y;
  7792. }
  7793. function areaRingEnd$1() {
  7794. areaPoint$1(x00, y00);
  7795. }
  7796. var x0$2 = Infinity,
  7797. y0$2 = x0$2,
  7798. x1 = -x0$2,
  7799. y1 = x1;
  7800. var boundsStream$1 = {
  7801. point: boundsPoint$1,
  7802. lineStart: noop$2,
  7803. lineEnd: noop$2,
  7804. polygonStart: noop$2,
  7805. polygonEnd: noop$2,
  7806. result: function() {
  7807. var bounds = [[x0$2, y0$2], [x1, y1]];
  7808. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  7809. return bounds;
  7810. }
  7811. };
  7812. function boundsPoint$1(x, y) {
  7813. if (x < x0$2) x0$2 = x;
  7814. if (x > x1) x1 = x;
  7815. if (y < y0$2) y0$2 = y;
  7816. if (y > y1) y1 = y;
  7817. }
  7818. // TODO Enforce positive area for exterior, negative area for interior?
  7819. var X0$1 = 0,
  7820. Y0$1 = 0,
  7821. Z0$1 = 0,
  7822. X1$1 = 0,
  7823. Y1$1 = 0,
  7824. Z1$1 = 0,
  7825. X2$1 = 0,
  7826. Y2$1 = 0,
  7827. Z2$1 = 0,
  7828. x00$1,
  7829. y00$1,
  7830. x0$3,
  7831. y0$3;
  7832. var centroidStream$1 = {
  7833. point: centroidPoint$1,
  7834. lineStart: centroidLineStart$1,
  7835. lineEnd: centroidLineEnd$1,
  7836. polygonStart: function() {
  7837. centroidStream$1.lineStart = centroidRingStart$1;
  7838. centroidStream$1.lineEnd = centroidRingEnd$1;
  7839. },
  7840. polygonEnd: function() {
  7841. centroidStream$1.point = centroidPoint$1;
  7842. centroidStream$1.lineStart = centroidLineStart$1;
  7843. centroidStream$1.lineEnd = centroidLineEnd$1;
  7844. },
  7845. result: function() {
  7846. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  7847. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  7848. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  7849. : [NaN, NaN];
  7850. X0$1 = Y0$1 = Z0$1 =
  7851. X1$1 = Y1$1 = Z1$1 =
  7852. X2$1 = Y2$1 = Z2$1 = 0;
  7853. return centroid;
  7854. }
  7855. };
  7856. function centroidPoint$1(x, y) {
  7857. X0$1 += x;
  7858. Y0$1 += y;
  7859. ++Z0$1;
  7860. }
  7861. function centroidLineStart$1() {
  7862. centroidStream$1.point = centroidPointFirstLine;
  7863. }
  7864. function centroidPointFirstLine(x, y) {
  7865. centroidStream$1.point = centroidPointLine;
  7866. centroidPoint$1(x0$3 = x, y0$3 = y);
  7867. }
  7868. function centroidPointLine(x, y) {
  7869. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  7870. X1$1 += z * (x0$3 + x) / 2;
  7871. Y1$1 += z * (y0$3 + y) / 2;
  7872. Z1$1 += z;
  7873. centroidPoint$1(x0$3 = x, y0$3 = y);
  7874. }
  7875. function centroidLineEnd$1() {
  7876. centroidStream$1.point = centroidPoint$1;
  7877. }
  7878. function centroidRingStart$1() {
  7879. centroidStream$1.point = centroidPointFirstRing;
  7880. }
  7881. function centroidRingEnd$1() {
  7882. centroidPointRing(x00$1, y00$1);
  7883. }
  7884. function centroidPointFirstRing(x, y) {
  7885. centroidStream$1.point = centroidPointRing;
  7886. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  7887. }
  7888. function centroidPointRing(x, y) {
  7889. var dx = x - x0$3,
  7890. dy = y - y0$3,
  7891. z = sqrt(dx * dx + dy * dy);
  7892. X1$1 += z * (x0$3 + x) / 2;
  7893. Y1$1 += z * (y0$3 + y) / 2;
  7894. Z1$1 += z;
  7895. z = y0$3 * x - x0$3 * y;
  7896. X2$1 += z * (x0$3 + x);
  7897. Y2$1 += z * (y0$3 + y);
  7898. Z2$1 += z * 3;
  7899. centroidPoint$1(x0$3 = x, y0$3 = y);
  7900. }
  7901. function PathContext(context) {
  7902. this._context = context;
  7903. }
  7904. PathContext.prototype = {
  7905. _radius: 4.5,
  7906. pointRadius: function(_) {
  7907. return this._radius = _, this;
  7908. },
  7909. polygonStart: function() {
  7910. this._line = 0;
  7911. },
  7912. polygonEnd: function() {
  7913. this._line = NaN;
  7914. },
  7915. lineStart: function() {
  7916. this._point = 0;
  7917. },
  7918. lineEnd: function() {
  7919. if (this._line === 0) this._context.closePath();
  7920. this._point = NaN;
  7921. },
  7922. point: function(x, y) {
  7923. switch (this._point) {
  7924. case 0: {
  7925. this._context.moveTo(x, y);
  7926. this._point = 1;
  7927. break;
  7928. }
  7929. case 1: {
  7930. this._context.lineTo(x, y);
  7931. break;
  7932. }
  7933. default: {
  7934. this._context.moveTo(x + this._radius, y);
  7935. this._context.arc(x, y, this._radius, 0, tau$3);
  7936. break;
  7937. }
  7938. }
  7939. },
  7940. result: noop$2
  7941. };
  7942. var lengthSum$1 = adder(),
  7943. lengthRing,
  7944. x00$2,
  7945. y00$2,
  7946. x0$4,
  7947. y0$4;
  7948. var lengthStream$1 = {
  7949. point: noop$2,
  7950. lineStart: function() {
  7951. lengthStream$1.point = lengthPointFirst$1;
  7952. },
  7953. lineEnd: function() {
  7954. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  7955. lengthStream$1.point = noop$2;
  7956. },
  7957. polygonStart: function() {
  7958. lengthRing = true;
  7959. },
  7960. polygonEnd: function() {
  7961. lengthRing = null;
  7962. },
  7963. result: function() {
  7964. var length = +lengthSum$1;
  7965. lengthSum$1.reset();
  7966. return length;
  7967. }
  7968. };
  7969. function lengthPointFirst$1(x, y) {
  7970. lengthStream$1.point = lengthPoint$1;
  7971. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  7972. }
  7973. function lengthPoint$1(x, y) {
  7974. x0$4 -= x, y0$4 -= y;
  7975. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  7976. x0$4 = x, y0$4 = y;
  7977. }
  7978. function PathString() {
  7979. this._string = [];
  7980. }
  7981. PathString.prototype = {
  7982. _radius: 4.5,
  7983. _circle: circle$1(4.5),
  7984. pointRadius: function(_) {
  7985. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  7986. return this;
  7987. },
  7988. polygonStart: function() {
  7989. this._line = 0;
  7990. },
  7991. polygonEnd: function() {
  7992. this._line = NaN;
  7993. },
  7994. lineStart: function() {
  7995. this._point = 0;
  7996. },
  7997. lineEnd: function() {
  7998. if (this._line === 0) this._string.push("Z");
  7999. this._point = NaN;
  8000. },
  8001. point: function(x, y) {
  8002. switch (this._point) {
  8003. case 0: {
  8004. this._string.push("M", x, ",", y);
  8005. this._point = 1;
  8006. break;
  8007. }
  8008. case 1: {
  8009. this._string.push("L", x, ",", y);
  8010. break;
  8011. }
  8012. default: {
  8013. if (this._circle == null) this._circle = circle$1(this._radius);
  8014. this._string.push("M", x, ",", y, this._circle);
  8015. break;
  8016. }
  8017. }
  8018. },
  8019. result: function() {
  8020. if (this._string.length) {
  8021. var result = this._string.join("");
  8022. this._string = [];
  8023. return result;
  8024. } else {
  8025. return null;
  8026. }
  8027. }
  8028. };
  8029. function circle$1(radius) {
  8030. return "m0," + radius
  8031. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  8032. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  8033. + "z";
  8034. }
  8035. function index$1(projection, context) {
  8036. var pointRadius = 4.5,
  8037. projectionStream,
  8038. contextStream;
  8039. function path(object) {
  8040. if (object) {
  8041. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  8042. geoStream(object, projectionStream(contextStream));
  8043. }
  8044. return contextStream.result();
  8045. }
  8046. path.area = function(object) {
  8047. geoStream(object, projectionStream(areaStream$1));
  8048. return areaStream$1.result();
  8049. };
  8050. path.measure = function(object) {
  8051. geoStream(object, projectionStream(lengthStream$1));
  8052. return lengthStream$1.result();
  8053. };
  8054. path.bounds = function(object) {
  8055. geoStream(object, projectionStream(boundsStream$1));
  8056. return boundsStream$1.result();
  8057. };
  8058. path.centroid = function(object) {
  8059. geoStream(object, projectionStream(centroidStream$1));
  8060. return centroidStream$1.result();
  8061. };
  8062. path.projection = function(_) {
  8063. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  8064. };
  8065. path.context = function(_) {
  8066. if (!arguments.length) return context;
  8067. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  8068. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  8069. return path;
  8070. };
  8071. path.pointRadius = function(_) {
  8072. if (!arguments.length) return pointRadius;
  8073. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  8074. return path;
  8075. };
  8076. return path.projection(projection).context(context);
  8077. }
  8078. function transform(methods) {
  8079. return {
  8080. stream: transformer(methods)
  8081. };
  8082. }
  8083. function transformer(methods) {
  8084. return function(stream) {
  8085. var s = new TransformStream;
  8086. for (var key in methods) s[key] = methods[key];
  8087. s.stream = stream;
  8088. return s;
  8089. };
  8090. }
  8091. function TransformStream() {}
  8092. TransformStream.prototype = {
  8093. constructor: TransformStream,
  8094. point: function(x, y) { this.stream.point(x, y); },
  8095. sphere: function() { this.stream.sphere(); },
  8096. lineStart: function() { this.stream.lineStart(); },
  8097. lineEnd: function() { this.stream.lineEnd(); },
  8098. polygonStart: function() { this.stream.polygonStart(); },
  8099. polygonEnd: function() { this.stream.polygonEnd(); }
  8100. };
  8101. function fit(projection, fitBounds, object) {
  8102. var clip = projection.clipExtent && projection.clipExtent();
  8103. projection.scale(150).translate([0, 0]);
  8104. if (clip != null) projection.clipExtent(null);
  8105. geoStream(object, projection.stream(boundsStream$1));
  8106. fitBounds(boundsStream$1.result());
  8107. if (clip != null) projection.clipExtent(clip);
  8108. return projection;
  8109. }
  8110. function fitExtent(projection, extent, object) {
  8111. return fit(projection, function(b) {
  8112. var w = extent[1][0] - extent[0][0],
  8113. h = extent[1][1] - extent[0][1],
  8114. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  8115. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  8116. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  8117. projection.scale(150 * k).translate([x, y]);
  8118. }, object);
  8119. }
  8120. function fitSize(projection, size, object) {
  8121. return fitExtent(projection, [[0, 0], size], object);
  8122. }
  8123. function fitWidth(projection, width, object) {
  8124. return fit(projection, function(b) {
  8125. var w = +width,
  8126. k = w / (b[1][0] - b[0][0]),
  8127. x = (w - k * (b[1][0] + b[0][0])) / 2,
  8128. y = -k * b[0][1];
  8129. projection.scale(150 * k).translate([x, y]);
  8130. }, object);
  8131. }
  8132. function fitHeight(projection, height, object) {
  8133. return fit(projection, function(b) {
  8134. var h = +height,
  8135. k = h / (b[1][1] - b[0][1]),
  8136. x = -k * b[0][0],
  8137. y = (h - k * (b[1][1] + b[0][1])) / 2;
  8138. projection.scale(150 * k).translate([x, y]);
  8139. }, object);
  8140. }
  8141. var maxDepth = 16, // maximum depth of subdivision
  8142. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  8143. function resample(project, delta2) {
  8144. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  8145. }
  8146. function resampleNone(project) {
  8147. return transformer({
  8148. point: function(x, y) {
  8149. x = project(x, y);
  8150. this.stream.point(x[0], x[1]);
  8151. }
  8152. });
  8153. }
  8154. function resample$1(project, delta2) {
  8155. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  8156. var dx = x1 - x0,
  8157. dy = y1 - y0,
  8158. d2 = dx * dx + dy * dy;
  8159. if (d2 > 4 * delta2 && depth--) {
  8160. var a = a0 + a1,
  8161. b = b0 + b1,
  8162. c = c0 + c1,
  8163. m = sqrt(a * a + b * b + c * c),
  8164. phi2 = asin(c /= m),
  8165. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  8166. p = project(lambda2, phi2),
  8167. x2 = p[0],
  8168. y2 = p[1],
  8169. dx2 = x2 - x0,
  8170. dy2 = y2 - y0,
  8171. dz = dy * dx2 - dx * dy2;
  8172. if (dz * dz / d2 > delta2 // perpendicular projected distance
  8173. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  8174. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  8175. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  8176. stream.point(x2, y2);
  8177. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  8178. }
  8179. }
  8180. }
  8181. return function(stream) {
  8182. var lambda00, x00, y00, a00, b00, c00, // first point
  8183. lambda0, x0, y0, a0, b0, c0; // previous point
  8184. var resampleStream = {
  8185. point: point,
  8186. lineStart: lineStart,
  8187. lineEnd: lineEnd,
  8188. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  8189. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  8190. };
  8191. function point(x, y) {
  8192. x = project(x, y);
  8193. stream.point(x[0], x[1]);
  8194. }
  8195. function lineStart() {
  8196. x0 = NaN;
  8197. resampleStream.point = linePoint;
  8198. stream.lineStart();
  8199. }
  8200. function linePoint(lambda, phi) {
  8201. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  8202. 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);
  8203. stream.point(x0, y0);
  8204. }
  8205. function lineEnd() {
  8206. resampleStream.point = point;
  8207. stream.lineEnd();
  8208. }
  8209. function ringStart() {
  8210. lineStart();
  8211. resampleStream.point = ringPoint;
  8212. resampleStream.lineEnd = ringEnd;
  8213. }
  8214. function ringPoint(lambda, phi) {
  8215. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  8216. resampleStream.point = linePoint;
  8217. }
  8218. function ringEnd() {
  8219. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  8220. resampleStream.lineEnd = lineEnd;
  8221. lineEnd();
  8222. }
  8223. return resampleStream;
  8224. };
  8225. }
  8226. var transformRadians = transformer({
  8227. point: function(x, y) {
  8228. this.stream.point(x * radians, y * radians);
  8229. }
  8230. });
  8231. function transformRotate(rotate) {
  8232. return transformer({
  8233. point: function(x, y) {
  8234. var r = rotate(x, y);
  8235. return this.stream.point(r[0], r[1]);
  8236. }
  8237. });
  8238. }
  8239. function scaleTranslate(k, dx, dy) {
  8240. function transform$$1(x, y) {
  8241. return [dx + k * x, dy - k * y];
  8242. }
  8243. transform$$1.invert = function(x, y) {
  8244. return [(x - dx) / k, (dy - y) / k];
  8245. };
  8246. return transform$$1;
  8247. }
  8248. function scaleTranslateRotate(k, dx, dy, alpha) {
  8249. var cosAlpha = cos$1(alpha),
  8250. sinAlpha = sin$1(alpha),
  8251. a = cosAlpha * k,
  8252. b = sinAlpha * k,
  8253. ai = cosAlpha / k,
  8254. bi = sinAlpha / k,
  8255. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  8256. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  8257. function transform$$1(x, y) {
  8258. return [a * x - b * y + dx, dy - b * x - a * y];
  8259. }
  8260. transform$$1.invert = function(x, y) {
  8261. return [ai * x - bi * y + ci, fi - bi * x - ai * y];
  8262. };
  8263. return transform$$1;
  8264. }
  8265. function projection(project) {
  8266. return projectionMutator(function() { return project; })();
  8267. }
  8268. function projectionMutator(projectAt) {
  8269. var project,
  8270. k = 150, // scale
  8271. x = 480, y = 250, // translate
  8272. lambda = 0, phi = 0, // center
  8273. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  8274. alpha = 0, // post-rotate
  8275. theta = null, preclip = clipAntimeridian, // pre-clip angle
  8276. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  8277. delta2 = 0.5, // precision
  8278. projectResample,
  8279. projectTransform,
  8280. projectRotateTransform,
  8281. cache,
  8282. cacheStream;
  8283. function projection(point) {
  8284. return projectRotateTransform(point[0] * radians, point[1] * radians);
  8285. }
  8286. function invert(point) {
  8287. point = projectRotateTransform.invert(point[0], point[1]);
  8288. return point && [point[0] * degrees$1, point[1] * degrees$1];
  8289. }
  8290. projection.stream = function(stream) {
  8291. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  8292. };
  8293. projection.preclip = function(_) {
  8294. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  8295. };
  8296. projection.postclip = function(_) {
  8297. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8298. };
  8299. projection.clipAngle = function(_) {
  8300. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  8301. };
  8302. projection.clipExtent = function(_) {
  8303. 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]];
  8304. };
  8305. projection.scale = function(_) {
  8306. return arguments.length ? (k = +_, recenter()) : k;
  8307. };
  8308. projection.translate = function(_) {
  8309. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  8310. };
  8311. projection.center = function(_) {
  8312. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  8313. };
  8314. projection.rotate = function(_) {
  8315. 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];
  8316. };
  8317. projection.angle = function(_) {
  8318. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
  8319. };
  8320. projection.precision = function(_) {
  8321. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  8322. };
  8323. projection.fitExtent = function(extent, object) {
  8324. return fitExtent(projection, extent, object);
  8325. };
  8326. projection.fitSize = function(size, object) {
  8327. return fitSize(projection, size, object);
  8328. };
  8329. projection.fitWidth = function(width, object) {
  8330. return fitWidth(projection, width, object);
  8331. };
  8332. projection.fitHeight = function(height, object) {
  8333. return fitHeight(projection, height, object);
  8334. };
  8335. function recenter() {
  8336. var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
  8337. transform$$1 = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
  8338. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  8339. projectTransform = compose(project, transform$$1);
  8340. projectRotateTransform = compose(rotate, projectTransform);
  8341. projectResample = resample(projectTransform, delta2);
  8342. return reset();
  8343. }
  8344. function reset() {
  8345. cache = cacheStream = null;
  8346. return projection;
  8347. }
  8348. return function() {
  8349. project = projectAt.apply(this, arguments);
  8350. projection.invert = project.invert && invert;
  8351. return recenter();
  8352. };
  8353. }
  8354. function conicProjection(projectAt) {
  8355. var phi0 = 0,
  8356. phi1 = pi$3 / 3,
  8357. m = projectionMutator(projectAt),
  8358. p = m(phi0, phi1);
  8359. p.parallels = function(_) {
  8360. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  8361. };
  8362. return p;
  8363. }
  8364. function cylindricalEqualAreaRaw(phi0) {
  8365. var cosPhi0 = cos$1(phi0);
  8366. function forward(lambda, phi) {
  8367. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  8368. }
  8369. forward.invert = function(x, y) {
  8370. return [x / cosPhi0, asin(y * cosPhi0)];
  8371. };
  8372. return forward;
  8373. }
  8374. function conicEqualAreaRaw(y0, y1) {
  8375. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  8376. // Are the parallels symmetrical around the Equator?
  8377. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  8378. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  8379. function project(x, y) {
  8380. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  8381. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  8382. }
  8383. project.invert = function(x, y) {
  8384. var r0y = r0 - y;
  8385. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  8386. };
  8387. return project;
  8388. }
  8389. function conicEqualArea() {
  8390. return conicProjection(conicEqualAreaRaw)
  8391. .scale(155.424)
  8392. .center([0, 33.6442]);
  8393. }
  8394. function albers() {
  8395. return conicEqualArea()
  8396. .parallels([29.5, 45.5])
  8397. .scale(1070)
  8398. .translate([480, 250])
  8399. .rotate([96, 0])
  8400. .center([-0.6, 38.7]);
  8401. }
  8402. // The projections must have mutually exclusive clip regions on the sphere,
  8403. // as this will avoid emitting interleaving lines and polygons.
  8404. function multiplex(streams) {
  8405. var n = streams.length;
  8406. return {
  8407. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  8408. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  8409. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  8410. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  8411. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  8412. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  8413. };
  8414. }
  8415. // A composite projection for the United States, configured by default for
  8416. // 960×500. The projection also works quite well at 960×600 if you change the
  8417. // scale to 1285 and adjust the translate accordingly. The set of standard
  8418. // parallels for each region comes from USGS, which is published here:
  8419. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  8420. function albersUsa() {
  8421. var cache,
  8422. cacheStream,
  8423. lower48 = albers(), lower48Point,
  8424. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  8425. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  8426. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  8427. function albersUsa(coordinates) {
  8428. var x = coordinates[0], y = coordinates[1];
  8429. return point = null, (lower48Point.point(x, y), point)
  8430. || (alaskaPoint.point(x, y), point)
  8431. || (hawaiiPoint.point(x, y), point);
  8432. }
  8433. albersUsa.invert = function(coordinates) {
  8434. var k = lower48.scale(),
  8435. t = lower48.translate(),
  8436. x = (coordinates[0] - t[0]) / k,
  8437. y = (coordinates[1] - t[1]) / k;
  8438. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  8439. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  8440. : lower48).invert(coordinates);
  8441. };
  8442. albersUsa.stream = function(stream) {
  8443. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  8444. };
  8445. albersUsa.precision = function(_) {
  8446. if (!arguments.length) return lower48.precision();
  8447. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  8448. return reset();
  8449. };
  8450. albersUsa.scale = function(_) {
  8451. if (!arguments.length) return lower48.scale();
  8452. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  8453. return albersUsa.translate(lower48.translate());
  8454. };
  8455. albersUsa.translate = function(_) {
  8456. if (!arguments.length) return lower48.translate();
  8457. var k = lower48.scale(), x = +_[0], y = +_[1];
  8458. lower48Point = lower48
  8459. .translate(_)
  8460. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8461. .stream(pointStream);
  8462. alaskaPoint = alaska
  8463. .translate([x - 0.307 * k, y + 0.201 * k])
  8464. .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]])
  8465. .stream(pointStream);
  8466. hawaiiPoint = hawaii
  8467. .translate([x - 0.205 * k, y + 0.212 * k])
  8468. .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]])
  8469. .stream(pointStream);
  8470. return reset();
  8471. };
  8472. albersUsa.fitExtent = function(extent, object) {
  8473. return fitExtent(albersUsa, extent, object);
  8474. };
  8475. albersUsa.fitSize = function(size, object) {
  8476. return fitSize(albersUsa, size, object);
  8477. };
  8478. albersUsa.fitWidth = function(width, object) {
  8479. return fitWidth(albersUsa, width, object);
  8480. };
  8481. albersUsa.fitHeight = function(height, object) {
  8482. return fitHeight(albersUsa, height, object);
  8483. };
  8484. function reset() {
  8485. cache = cacheStream = null;
  8486. return albersUsa;
  8487. }
  8488. return albersUsa.scale(1070);
  8489. }
  8490. function azimuthalRaw(scale) {
  8491. return function(x, y) {
  8492. var cx = cos$1(x),
  8493. cy = cos$1(y),
  8494. k = scale(cx * cy);
  8495. return [
  8496. k * cy * sin$1(x),
  8497. k * sin$1(y)
  8498. ];
  8499. }
  8500. }
  8501. function azimuthalInvert(angle) {
  8502. return function(x, y) {
  8503. var z = sqrt(x * x + y * y),
  8504. c = angle(z),
  8505. sc = sin$1(c),
  8506. cc = cos$1(c);
  8507. return [
  8508. atan2(x * sc, z * cc),
  8509. asin(z && y * sc / z)
  8510. ];
  8511. }
  8512. }
  8513. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8514. return sqrt(2 / (1 + cxcy));
  8515. });
  8516. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8517. return 2 * asin(z / 2);
  8518. });
  8519. function azimuthalEqualArea() {
  8520. return projection(azimuthalEqualAreaRaw)
  8521. .scale(124.75)
  8522. .clipAngle(180 - 1e-3);
  8523. }
  8524. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8525. return (c = acos(c)) && c / sin$1(c);
  8526. });
  8527. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8528. return z;
  8529. });
  8530. function azimuthalEquidistant() {
  8531. return projection(azimuthalEquidistantRaw)
  8532. .scale(79.4188)
  8533. .clipAngle(180 - 1e-3);
  8534. }
  8535. function mercatorRaw(lambda, phi) {
  8536. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8537. }
  8538. mercatorRaw.invert = function(x, y) {
  8539. return [x, 2 * atan(exp(y)) - halfPi$2];
  8540. };
  8541. function mercator() {
  8542. return mercatorProjection(mercatorRaw)
  8543. .scale(961 / tau$3);
  8544. }
  8545. function mercatorProjection(project) {
  8546. var m = projection(project),
  8547. center = m.center,
  8548. scale = m.scale,
  8549. translate = m.translate,
  8550. clipExtent = m.clipExtent,
  8551. x0 = null, y0, x1, y1; // clip extent
  8552. m.scale = function(_) {
  8553. return arguments.length ? (scale(_), reclip()) : scale();
  8554. };
  8555. m.translate = function(_) {
  8556. return arguments.length ? (translate(_), reclip()) : translate();
  8557. };
  8558. m.center = function(_) {
  8559. return arguments.length ? (center(_), reclip()) : center();
  8560. };
  8561. m.clipExtent = function(_) {
  8562. 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]];
  8563. };
  8564. function reclip() {
  8565. var k = pi$3 * scale(),
  8566. t = m(rotation(m.rotate()).invert([0, 0]));
  8567. return clipExtent(x0 == null
  8568. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8569. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8570. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8571. }
  8572. return reclip();
  8573. }
  8574. function tany(y) {
  8575. return tan((halfPi$2 + y) / 2);
  8576. }
  8577. function conicConformalRaw(y0, y1) {
  8578. var cy0 = cos$1(y0),
  8579. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8580. f = cy0 * pow(tany(y0), n) / n;
  8581. if (!n) return mercatorRaw;
  8582. function project(x, y) {
  8583. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8584. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8585. var r = f / pow(tany(y), n);
  8586. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8587. }
  8588. project.invert = function(x, y) {
  8589. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8590. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8591. };
  8592. return project;
  8593. }
  8594. function conicConformal() {
  8595. return conicProjection(conicConformalRaw)
  8596. .scale(109.5)
  8597. .parallels([30, 30]);
  8598. }
  8599. function equirectangularRaw(lambda, phi) {
  8600. return [lambda, phi];
  8601. }
  8602. equirectangularRaw.invert = equirectangularRaw;
  8603. function equirectangular() {
  8604. return projection(equirectangularRaw)
  8605. .scale(152.63);
  8606. }
  8607. function conicEquidistantRaw(y0, y1) {
  8608. var cy0 = cos$1(y0),
  8609. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8610. g = cy0 / n + y0;
  8611. if (abs(n) < epsilon$2) return equirectangularRaw;
  8612. function project(x, y) {
  8613. var gy = g - y, nx = n * x;
  8614. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8615. }
  8616. project.invert = function(x, y) {
  8617. var gy = g - y;
  8618. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8619. };
  8620. return project;
  8621. }
  8622. function conicEquidistant() {
  8623. return conicProjection(conicEquidistantRaw)
  8624. .scale(131.154)
  8625. .center([0, 13.9389]);
  8626. }
  8627. function gnomonicRaw(x, y) {
  8628. var cy = cos$1(y), k = cos$1(x) * cy;
  8629. return [cy * sin$1(x) / k, sin$1(y) / k];
  8630. }
  8631. gnomonicRaw.invert = azimuthalInvert(atan);
  8632. function gnomonic() {
  8633. return projection(gnomonicRaw)
  8634. .scale(144.049)
  8635. .clipAngle(60);
  8636. }
  8637. function scaleTranslate$1(kx, ky, tx, ty) {
  8638. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8639. point: function(x, y) {
  8640. this.stream.point(x * kx + tx, y * ky + ty);
  8641. }
  8642. });
  8643. }
  8644. function identity$5() {
  8645. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
  8646. x0 = null, y0, x1, y1, // clip extent
  8647. postclip = identity$4,
  8648. cache,
  8649. cacheStream,
  8650. projection;
  8651. function reset() {
  8652. cache = cacheStream = null;
  8653. return projection;
  8654. }
  8655. return projection = {
  8656. stream: function(stream) {
  8657. return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
  8658. },
  8659. postclip: function(_) {
  8660. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8661. },
  8662. clipExtent: function(_) {
  8663. 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]];
  8664. },
  8665. scale: function(_) {
  8666. return arguments.length ? (transform$$1 = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8667. },
  8668. translate: function(_) {
  8669. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8670. },
  8671. reflectX: function(_) {
  8672. return arguments.length ? (transform$$1 = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8673. },
  8674. reflectY: function(_) {
  8675. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8676. },
  8677. fitExtent: function(extent, object) {
  8678. return fitExtent(projection, extent, object);
  8679. },
  8680. fitSize: function(size, object) {
  8681. return fitSize(projection, size, object);
  8682. },
  8683. fitWidth: function(width, object) {
  8684. return fitWidth(projection, width, object);
  8685. },
  8686. fitHeight: function(height, object) {
  8687. return fitHeight(projection, height, object);
  8688. }
  8689. };
  8690. }
  8691. function naturalEarth1Raw(lambda, phi) {
  8692. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8693. return [
  8694. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8695. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8696. ];
  8697. }
  8698. naturalEarth1Raw.invert = function(x, y) {
  8699. var phi = y, i = 25, delta;
  8700. do {
  8701. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8702. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  8703. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  8704. } while (abs(delta) > epsilon$2 && --i > 0);
  8705. return [
  8706. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  8707. phi
  8708. ];
  8709. };
  8710. function naturalEarth1() {
  8711. return projection(naturalEarth1Raw)
  8712. .scale(175.295);
  8713. }
  8714. function orthographicRaw(x, y) {
  8715. return [cos$1(y) * sin$1(x), sin$1(y)];
  8716. }
  8717. orthographicRaw.invert = azimuthalInvert(asin);
  8718. function orthographic() {
  8719. return projection(orthographicRaw)
  8720. .scale(249.5)
  8721. .clipAngle(90 + epsilon$2);
  8722. }
  8723. function stereographicRaw(x, y) {
  8724. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8725. return [cy * sin$1(x) / k, sin$1(y) / k];
  8726. }
  8727. stereographicRaw.invert = azimuthalInvert(function(z) {
  8728. return 2 * atan(z);
  8729. });
  8730. function stereographic() {
  8731. return projection(stereographicRaw)
  8732. .scale(250)
  8733. .clipAngle(142);
  8734. }
  8735. function transverseMercatorRaw(lambda, phi) {
  8736. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8737. }
  8738. transverseMercatorRaw.invert = function(x, y) {
  8739. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8740. };
  8741. function transverseMercator() {
  8742. var m = mercatorProjection(transverseMercatorRaw),
  8743. center = m.center,
  8744. rotate = m.rotate;
  8745. m.center = function(_) {
  8746. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8747. };
  8748. m.rotate = function(_) {
  8749. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8750. };
  8751. return rotate([0, 0, 90])
  8752. .scale(159.155);
  8753. }
  8754. function defaultSeparation(a, b) {
  8755. return a.parent === b.parent ? 1 : 2;
  8756. }
  8757. function meanX(children) {
  8758. return children.reduce(meanXReduce, 0) / children.length;
  8759. }
  8760. function meanXReduce(x, c) {
  8761. return x + c.x;
  8762. }
  8763. function maxY(children) {
  8764. return 1 + children.reduce(maxYReduce, 0);
  8765. }
  8766. function maxYReduce(y, c) {
  8767. return Math.max(y, c.y);
  8768. }
  8769. function leafLeft(node) {
  8770. var children;
  8771. while (children = node.children) node = children[0];
  8772. return node;
  8773. }
  8774. function leafRight(node) {
  8775. var children;
  8776. while (children = node.children) node = children[children.length - 1];
  8777. return node;
  8778. }
  8779. function cluster() {
  8780. var separation = defaultSeparation,
  8781. dx = 1,
  8782. dy = 1,
  8783. nodeSize = false;
  8784. function cluster(root) {
  8785. var previousNode,
  8786. x = 0;
  8787. // First walk, computing the initial x & y values.
  8788. root.eachAfter(function(node) {
  8789. var children = node.children;
  8790. if (children) {
  8791. node.x = meanX(children);
  8792. node.y = maxY(children);
  8793. } else {
  8794. node.x = previousNode ? x += separation(node, previousNode) : 0;
  8795. node.y = 0;
  8796. previousNode = node;
  8797. }
  8798. });
  8799. var left = leafLeft(root),
  8800. right = leafRight(root),
  8801. x0 = left.x - separation(left, right) / 2,
  8802. x1 = right.x + separation(right, left) / 2;
  8803. // Second walk, normalizing x & y to the desired size.
  8804. return root.eachAfter(nodeSize ? function(node) {
  8805. node.x = (node.x - root.x) * dx;
  8806. node.y = (root.y - node.y) * dy;
  8807. } : function(node) {
  8808. node.x = (node.x - x0) / (x1 - x0) * dx;
  8809. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  8810. });
  8811. }
  8812. cluster.separation = function(x) {
  8813. return arguments.length ? (separation = x, cluster) : separation;
  8814. };
  8815. cluster.size = function(x) {
  8816. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  8817. };
  8818. cluster.nodeSize = function(x) {
  8819. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  8820. };
  8821. return cluster;
  8822. }
  8823. function count(node) {
  8824. var sum = 0,
  8825. children = node.children,
  8826. i = children && children.length;
  8827. if (!i) sum = 1;
  8828. else while (--i >= 0) sum += children[i].value;
  8829. node.value = sum;
  8830. }
  8831. function node_count() {
  8832. return this.eachAfter(count);
  8833. }
  8834. function node_each(callback) {
  8835. var node = this, current, next = [node], children, i, n;
  8836. do {
  8837. current = next.reverse(), next = [];
  8838. while (node = current.pop()) {
  8839. callback(node), children = node.children;
  8840. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8841. next.push(children[i]);
  8842. }
  8843. }
  8844. } while (next.length);
  8845. return this;
  8846. }
  8847. function node_eachBefore(callback) {
  8848. var node = this, nodes = [node], children, i;
  8849. while (node = nodes.pop()) {
  8850. callback(node), children = node.children;
  8851. if (children) for (i = children.length - 1; i >= 0; --i) {
  8852. nodes.push(children[i]);
  8853. }
  8854. }
  8855. return this;
  8856. }
  8857. function node_eachAfter(callback) {
  8858. var node = this, nodes = [node], next = [], children, i, n;
  8859. while (node = nodes.pop()) {
  8860. next.push(node), children = node.children;
  8861. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8862. nodes.push(children[i]);
  8863. }
  8864. }
  8865. while (node = next.pop()) {
  8866. callback(node);
  8867. }
  8868. return this;
  8869. }
  8870. function node_sum(value) {
  8871. return this.eachAfter(function(node) {
  8872. var sum = +value(node.data) || 0,
  8873. children = node.children,
  8874. i = children && children.length;
  8875. while (--i >= 0) sum += children[i].value;
  8876. node.value = sum;
  8877. });
  8878. }
  8879. function node_sort(compare) {
  8880. return this.eachBefore(function(node) {
  8881. if (node.children) {
  8882. node.children.sort(compare);
  8883. }
  8884. });
  8885. }
  8886. function node_path(end) {
  8887. var start = this,
  8888. ancestor = leastCommonAncestor(start, end),
  8889. nodes = [start];
  8890. while (start !== ancestor) {
  8891. start = start.parent;
  8892. nodes.push(start);
  8893. }
  8894. var k = nodes.length;
  8895. while (end !== ancestor) {
  8896. nodes.splice(k, 0, end);
  8897. end = end.parent;
  8898. }
  8899. return nodes;
  8900. }
  8901. function leastCommonAncestor(a, b) {
  8902. if (a === b) return a;
  8903. var aNodes = a.ancestors(),
  8904. bNodes = b.ancestors(),
  8905. c = null;
  8906. a = aNodes.pop();
  8907. b = bNodes.pop();
  8908. while (a === b) {
  8909. c = a;
  8910. a = aNodes.pop();
  8911. b = bNodes.pop();
  8912. }
  8913. return c;
  8914. }
  8915. function node_ancestors() {
  8916. var node = this, nodes = [node];
  8917. while (node = node.parent) {
  8918. nodes.push(node);
  8919. }
  8920. return nodes;
  8921. }
  8922. function node_descendants() {
  8923. var nodes = [];
  8924. this.each(function(node) {
  8925. nodes.push(node);
  8926. });
  8927. return nodes;
  8928. }
  8929. function node_leaves() {
  8930. var leaves = [];
  8931. this.eachBefore(function(node) {
  8932. if (!node.children) {
  8933. leaves.push(node);
  8934. }
  8935. });
  8936. return leaves;
  8937. }
  8938. function node_links() {
  8939. var root = this, links = [];
  8940. root.each(function(node) {
  8941. if (node !== root) { // Don’t include the root’s parent, if any.
  8942. links.push({source: node.parent, target: node});
  8943. }
  8944. });
  8945. return links;
  8946. }
  8947. function hierarchy(data, children) {
  8948. var root = new Node(data),
  8949. valued = +data.value && (root.value = data.value),
  8950. node,
  8951. nodes = [root],
  8952. child,
  8953. childs,
  8954. i,
  8955. n;
  8956. if (children == null) children = defaultChildren;
  8957. while (node = nodes.pop()) {
  8958. if (valued) node.value = +node.data.value;
  8959. if ((childs = children(node.data)) && (n = childs.length)) {
  8960. node.children = new Array(n);
  8961. for (i = n - 1; i >= 0; --i) {
  8962. nodes.push(child = node.children[i] = new Node(childs[i]));
  8963. child.parent = node;
  8964. child.depth = node.depth + 1;
  8965. }
  8966. }
  8967. }
  8968. return root.eachBefore(computeHeight);
  8969. }
  8970. function node_copy() {
  8971. return hierarchy(this).eachBefore(copyData);
  8972. }
  8973. function defaultChildren(d) {
  8974. return d.children;
  8975. }
  8976. function copyData(node) {
  8977. node.data = node.data.data;
  8978. }
  8979. function computeHeight(node) {
  8980. var height = 0;
  8981. do node.height = height;
  8982. while ((node = node.parent) && (node.height < ++height));
  8983. }
  8984. function Node(data) {
  8985. this.data = data;
  8986. this.depth =
  8987. this.height = 0;
  8988. this.parent = null;
  8989. }
  8990. Node.prototype = hierarchy.prototype = {
  8991. constructor: Node,
  8992. count: node_count,
  8993. each: node_each,
  8994. eachAfter: node_eachAfter,
  8995. eachBefore: node_eachBefore,
  8996. sum: node_sum,
  8997. sort: node_sort,
  8998. path: node_path,
  8999. ancestors: node_ancestors,
  9000. descendants: node_descendants,
  9001. leaves: node_leaves,
  9002. links: node_links,
  9003. copy: node_copy
  9004. };
  9005. var slice$4 = Array.prototype.slice;
  9006. function shuffle$1(array) {
  9007. var m = array.length,
  9008. t,
  9009. i;
  9010. while (m) {
  9011. i = Math.random() * m-- | 0;
  9012. t = array[m];
  9013. array[m] = array[i];
  9014. array[i] = t;
  9015. }
  9016. return array;
  9017. }
  9018. function enclose(circles) {
  9019. var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
  9020. while (i < n) {
  9021. p = circles[i];
  9022. if (e && enclosesWeak(e, p)) ++i;
  9023. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  9024. }
  9025. return e;
  9026. }
  9027. function extendBasis(B, p) {
  9028. var i, j;
  9029. if (enclosesWeakAll(p, B)) return [p];
  9030. // If we get here then B must have at least one element.
  9031. for (i = 0; i < B.length; ++i) {
  9032. if (enclosesNot(p, B[i])
  9033. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  9034. return [B[i], p];
  9035. }
  9036. }
  9037. // If we get here then B must have at least two elements.
  9038. for (i = 0; i < B.length - 1; ++i) {
  9039. for (j = i + 1; j < B.length; ++j) {
  9040. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  9041. && enclosesNot(encloseBasis2(B[i], p), B[j])
  9042. && enclosesNot(encloseBasis2(B[j], p), B[i])
  9043. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  9044. return [B[i], B[j], p];
  9045. }
  9046. }
  9047. }
  9048. // If we get here then something is very wrong.
  9049. throw new Error;
  9050. }
  9051. function enclosesNot(a, b) {
  9052. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  9053. return dr < 0 || dr * dr < dx * dx + dy * dy;
  9054. }
  9055. function enclosesWeak(a, b) {
  9056. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9057. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9058. }
  9059. function enclosesWeakAll(a, B) {
  9060. for (var i = 0; i < B.length; ++i) {
  9061. if (!enclosesWeak(a, B[i])) {
  9062. return false;
  9063. }
  9064. }
  9065. return true;
  9066. }
  9067. function encloseBasis(B) {
  9068. switch (B.length) {
  9069. case 1: return encloseBasis1(B[0]);
  9070. case 2: return encloseBasis2(B[0], B[1]);
  9071. case 3: return encloseBasis3(B[0], B[1], B[2]);
  9072. }
  9073. }
  9074. function encloseBasis1(a) {
  9075. return {
  9076. x: a.x,
  9077. y: a.y,
  9078. r: a.r
  9079. };
  9080. }
  9081. function encloseBasis2(a, b) {
  9082. var x1 = a.x, y1 = a.y, r1 = a.r,
  9083. x2 = b.x, y2 = b.y, r2 = b.r,
  9084. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  9085. l = Math.sqrt(x21 * x21 + y21 * y21);
  9086. return {
  9087. x: (x1 + x2 + x21 / l * r21) / 2,
  9088. y: (y1 + y2 + y21 / l * r21) / 2,
  9089. r: (l + r1 + r2) / 2
  9090. };
  9091. }
  9092. function encloseBasis3(a, b, c) {
  9093. var x1 = a.x, y1 = a.y, r1 = a.r,
  9094. x2 = b.x, y2 = b.y, r2 = b.r,
  9095. x3 = c.x, y3 = c.y, r3 = c.r,
  9096. a2 = x1 - x2,
  9097. a3 = x1 - x3,
  9098. b2 = y1 - y2,
  9099. b3 = y1 - y3,
  9100. c2 = r2 - r1,
  9101. c3 = r3 - r1,
  9102. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  9103. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  9104. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  9105. ab = a3 * b2 - a2 * b3,
  9106. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  9107. xb = (b3 * c2 - b2 * c3) / ab,
  9108. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  9109. yb = (a2 * c3 - a3 * c2) / ab,
  9110. A = xb * xb + yb * yb - 1,
  9111. B = 2 * (r1 + xa * xb + ya * yb),
  9112. C = xa * xa + ya * ya - r1 * r1,
  9113. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  9114. return {
  9115. x: x1 + xa + xb * r,
  9116. y: y1 + ya + yb * r,
  9117. r: r
  9118. };
  9119. }
  9120. function place(b, a, c) {
  9121. var dx = b.x - a.x, x, a2,
  9122. dy = b.y - a.y, y, b2,
  9123. d2 = dx * dx + dy * dy;
  9124. if (d2) {
  9125. a2 = a.r + c.r, a2 *= a2;
  9126. b2 = b.r + c.r, b2 *= b2;
  9127. if (a2 > b2) {
  9128. x = (d2 + b2 - a2) / (2 * d2);
  9129. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  9130. c.x = b.x - x * dx - y * dy;
  9131. c.y = b.y - x * dy + y * dx;
  9132. } else {
  9133. x = (d2 + a2 - b2) / (2 * d2);
  9134. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  9135. c.x = a.x + x * dx - y * dy;
  9136. c.y = a.y + x * dy + y * dx;
  9137. }
  9138. } else {
  9139. c.x = a.x + c.r;
  9140. c.y = a.y;
  9141. }
  9142. }
  9143. function intersects(a, b) {
  9144. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9145. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9146. }
  9147. function score(node) {
  9148. var a = node._,
  9149. b = node.next._,
  9150. ab = a.r + b.r,
  9151. dx = (a.x * b.r + b.x * a.r) / ab,
  9152. dy = (a.y * b.r + b.y * a.r) / ab;
  9153. return dx * dx + dy * dy;
  9154. }
  9155. function Node$1(circle) {
  9156. this._ = circle;
  9157. this.next = null;
  9158. this.previous = null;
  9159. }
  9160. function packEnclose(circles) {
  9161. if (!(n = circles.length)) return 0;
  9162. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  9163. // Place the first circle.
  9164. a = circles[0], a.x = 0, a.y = 0;
  9165. if (!(n > 1)) return a.r;
  9166. // Place the second circle.
  9167. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  9168. if (!(n > 2)) return a.r + b.r;
  9169. // Place the third circle.
  9170. place(b, a, c = circles[2]);
  9171. // Initialize the front-chain using the first three circles a, b and c.
  9172. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  9173. a.next = c.previous = b;
  9174. b.next = a.previous = c;
  9175. c.next = b.previous = a;
  9176. // Attempt to place each remaining circle…
  9177. pack: for (i = 3; i < n; ++i) {
  9178. place(a._, b._, c = circles[i]), c = new Node$1(c);
  9179. // Find the closest intersecting circle on the front-chain, if any.
  9180. // “Closeness” is determined by linear distance along the front-chain.
  9181. // “Ahead” or “behind” is likewise determined by linear distance.
  9182. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  9183. do {
  9184. if (sj <= sk) {
  9185. if (intersects(j._, c._)) {
  9186. b = j, a.next = b, b.previous = a, --i;
  9187. continue pack;
  9188. }
  9189. sj += j._.r, j = j.next;
  9190. } else {
  9191. if (intersects(k._, c._)) {
  9192. a = k, a.next = b, b.previous = a, --i;
  9193. continue pack;
  9194. }
  9195. sk += k._.r, k = k.previous;
  9196. }
  9197. } while (j !== k.next);
  9198. // Success! Insert the new circle c between a and b.
  9199. c.previous = a, c.next = b, a.next = b.previous = b = c;
  9200. // Compute the new closest circle pair to the centroid.
  9201. aa = score(a);
  9202. while ((c = c.next) !== b) {
  9203. if ((ca = score(c)) < aa) {
  9204. a = c, aa = ca;
  9205. }
  9206. }
  9207. b = a.next;
  9208. }
  9209. // Compute the enclosing circle of the front chain.
  9210. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  9211. // Translate the circles to put the enclosing circle around the origin.
  9212. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  9213. return c.r;
  9214. }
  9215. function siblings(circles) {
  9216. packEnclose(circles);
  9217. return circles;
  9218. }
  9219. function optional(f) {
  9220. return f == null ? null : required(f);
  9221. }
  9222. function required(f) {
  9223. if (typeof f !== "function") throw new Error;
  9224. return f;
  9225. }
  9226. function constantZero() {
  9227. return 0;
  9228. }
  9229. function constant$9(x) {
  9230. return function() {
  9231. return x;
  9232. };
  9233. }
  9234. function defaultRadius$1(d) {
  9235. return Math.sqrt(d.value);
  9236. }
  9237. function index$2() {
  9238. var radius = null,
  9239. dx = 1,
  9240. dy = 1,
  9241. padding = constantZero;
  9242. function pack(root) {
  9243. root.x = dx / 2, root.y = dy / 2;
  9244. if (radius) {
  9245. root.eachBefore(radiusLeaf(radius))
  9246. .eachAfter(packChildren(padding, 0.5))
  9247. .eachBefore(translateChild(1));
  9248. } else {
  9249. root.eachBefore(radiusLeaf(defaultRadius$1))
  9250. .eachAfter(packChildren(constantZero, 1))
  9251. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  9252. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  9253. }
  9254. return root;
  9255. }
  9256. pack.radius = function(x) {
  9257. return arguments.length ? (radius = optional(x), pack) : radius;
  9258. };
  9259. pack.size = function(x) {
  9260. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  9261. };
  9262. pack.padding = function(x) {
  9263. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  9264. };
  9265. return pack;
  9266. }
  9267. function radiusLeaf(radius) {
  9268. return function(node) {
  9269. if (!node.children) {
  9270. node.r = Math.max(0, +radius(node) || 0);
  9271. }
  9272. };
  9273. }
  9274. function packChildren(padding, k) {
  9275. return function(node) {
  9276. if (children = node.children) {
  9277. var children,
  9278. i,
  9279. n = children.length,
  9280. r = padding(node) * k || 0,
  9281. e;
  9282. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  9283. e = packEnclose(children);
  9284. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  9285. node.r = e + r;
  9286. }
  9287. };
  9288. }
  9289. function translateChild(k) {
  9290. return function(node) {
  9291. var parent = node.parent;
  9292. node.r *= k;
  9293. if (parent) {
  9294. node.x = parent.x + k * node.x;
  9295. node.y = parent.y + k * node.y;
  9296. }
  9297. };
  9298. }
  9299. function roundNode(node) {
  9300. node.x0 = Math.round(node.x0);
  9301. node.y0 = Math.round(node.y0);
  9302. node.x1 = Math.round(node.x1);
  9303. node.y1 = Math.round(node.y1);
  9304. }
  9305. function treemapDice(parent, x0, y0, x1, y1) {
  9306. var nodes = parent.children,
  9307. node,
  9308. i = -1,
  9309. n = nodes.length,
  9310. k = parent.value && (x1 - x0) / parent.value;
  9311. while (++i < n) {
  9312. node = nodes[i], node.y0 = y0, node.y1 = y1;
  9313. node.x0 = x0, node.x1 = x0 += node.value * k;
  9314. }
  9315. }
  9316. function partition() {
  9317. var dx = 1,
  9318. dy = 1,
  9319. padding = 0,
  9320. round = false;
  9321. function partition(root) {
  9322. var n = root.height + 1;
  9323. root.x0 =
  9324. root.y0 = padding;
  9325. root.x1 = dx;
  9326. root.y1 = dy / n;
  9327. root.eachBefore(positionNode(dy, n));
  9328. if (round) root.eachBefore(roundNode);
  9329. return root;
  9330. }
  9331. function positionNode(dy, n) {
  9332. return function(node) {
  9333. if (node.children) {
  9334. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  9335. }
  9336. var x0 = node.x0,
  9337. y0 = node.y0,
  9338. x1 = node.x1 - padding,
  9339. y1 = node.y1 - padding;
  9340. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9341. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9342. node.x0 = x0;
  9343. node.y0 = y0;
  9344. node.x1 = x1;
  9345. node.y1 = y1;
  9346. };
  9347. }
  9348. partition.round = function(x) {
  9349. return arguments.length ? (round = !!x, partition) : round;
  9350. };
  9351. partition.size = function(x) {
  9352. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  9353. };
  9354. partition.padding = function(x) {
  9355. return arguments.length ? (padding = +x, partition) : padding;
  9356. };
  9357. return partition;
  9358. }
  9359. var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
  9360. preroot = {depth: -1},
  9361. ambiguous = {};
  9362. function defaultId(d) {
  9363. return d.id;
  9364. }
  9365. function defaultParentId(d) {
  9366. return d.parentId;
  9367. }
  9368. function stratify() {
  9369. var id = defaultId,
  9370. parentId = defaultParentId;
  9371. function stratify(data) {
  9372. var d,
  9373. i,
  9374. n = data.length,
  9375. root,
  9376. parent,
  9377. node,
  9378. nodes = new Array(n),
  9379. nodeId,
  9380. nodeKey,
  9381. nodeByKey = {};
  9382. for (i = 0; i < n; ++i) {
  9383. d = data[i], node = nodes[i] = new Node(d);
  9384. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  9385. nodeKey = keyPrefix$1 + (node.id = nodeId);
  9386. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  9387. }
  9388. }
  9389. for (i = 0; i < n; ++i) {
  9390. node = nodes[i], nodeId = parentId(data[i], i, data);
  9391. if (nodeId == null || !(nodeId += "")) {
  9392. if (root) throw new Error("multiple roots");
  9393. root = node;
  9394. } else {
  9395. parent = nodeByKey[keyPrefix$1 + nodeId];
  9396. if (!parent) throw new Error("missing: " + nodeId);
  9397. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  9398. if (parent.children) parent.children.push(node);
  9399. else parent.children = [node];
  9400. node.parent = parent;
  9401. }
  9402. }
  9403. if (!root) throw new Error("no root");
  9404. root.parent = preroot;
  9405. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  9406. root.parent = null;
  9407. if (n > 0) throw new Error("cycle");
  9408. return root;
  9409. }
  9410. stratify.id = function(x) {
  9411. return arguments.length ? (id = required(x), stratify) : id;
  9412. };
  9413. stratify.parentId = function(x) {
  9414. return arguments.length ? (parentId = required(x), stratify) : parentId;
  9415. };
  9416. return stratify;
  9417. }
  9418. function defaultSeparation$1(a, b) {
  9419. return a.parent === b.parent ? 1 : 2;
  9420. }
  9421. // function radialSeparation(a, b) {
  9422. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  9423. // }
  9424. // This function is used to traverse the left contour of a subtree (or
  9425. // subforest). It returns the successor of v on this contour. This successor is
  9426. // either given by the leftmost child of v or by the thread of v. The function
  9427. // returns null if and only if v is on the highest level of its subtree.
  9428. function nextLeft(v) {
  9429. var children = v.children;
  9430. return children ? children[0] : v.t;
  9431. }
  9432. // This function works analogously to nextLeft.
  9433. function nextRight(v) {
  9434. var children = v.children;
  9435. return children ? children[children.length - 1] : v.t;
  9436. }
  9437. // Shifts the current subtree rooted at w+. This is done by increasing
  9438. // prelim(w+) and mod(w+) by shift.
  9439. function moveSubtree(wm, wp, shift) {
  9440. var change = shift / (wp.i - wm.i);
  9441. wp.c -= change;
  9442. wp.s += shift;
  9443. wm.c += change;
  9444. wp.z += shift;
  9445. wp.m += shift;
  9446. }
  9447. // All other shifts, applied to the smaller subtrees between w- and w+, are
  9448. // performed by this function. To prepare the shifts, we have to adjust
  9449. // change(w+), shift(w+), and change(w-).
  9450. function executeShifts(v) {
  9451. var shift = 0,
  9452. change = 0,
  9453. children = v.children,
  9454. i = children.length,
  9455. w;
  9456. while (--i >= 0) {
  9457. w = children[i];
  9458. w.z += shift;
  9459. w.m += shift;
  9460. shift += w.s + (change += w.c);
  9461. }
  9462. }
  9463. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9464. // returns the specified (default) ancestor.
  9465. function nextAncestor(vim, v, ancestor) {
  9466. return vim.a.parent === v.parent ? vim.a : ancestor;
  9467. }
  9468. function TreeNode(node, i) {
  9469. this._ = node;
  9470. this.parent = null;
  9471. this.children = null;
  9472. this.A = null; // default ancestor
  9473. this.a = this; // ancestor
  9474. this.z = 0; // prelim
  9475. this.m = 0; // mod
  9476. this.c = 0; // change
  9477. this.s = 0; // shift
  9478. this.t = null; // thread
  9479. this.i = i; // number
  9480. }
  9481. TreeNode.prototype = Object.create(Node.prototype);
  9482. function treeRoot(root) {
  9483. var tree = new TreeNode(root, 0),
  9484. node,
  9485. nodes = [tree],
  9486. child,
  9487. children,
  9488. i,
  9489. n;
  9490. while (node = nodes.pop()) {
  9491. if (children = node._.children) {
  9492. node.children = new Array(n = children.length);
  9493. for (i = n - 1; i >= 0; --i) {
  9494. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9495. child.parent = node;
  9496. }
  9497. }
  9498. }
  9499. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9500. return tree;
  9501. }
  9502. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9503. function tree() {
  9504. var separation = defaultSeparation$1,
  9505. dx = 1,
  9506. dy = 1,
  9507. nodeSize = null;
  9508. function tree(root) {
  9509. var t = treeRoot(root);
  9510. // Compute the layout using Buchheim et al.’s algorithm.
  9511. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9512. t.eachBefore(secondWalk);
  9513. // If a fixed node size is specified, scale x and y.
  9514. if (nodeSize) root.eachBefore(sizeNode);
  9515. // If a fixed tree size is specified, scale x and y based on the extent.
  9516. // Compute the left-most, right-most, and depth-most nodes for extents.
  9517. else {
  9518. var left = root,
  9519. right = root,
  9520. bottom = root;
  9521. root.eachBefore(function(node) {
  9522. if (node.x < left.x) left = node;
  9523. if (node.x > right.x) right = node;
  9524. if (node.depth > bottom.depth) bottom = node;
  9525. });
  9526. var s = left === right ? 1 : separation(left, right) / 2,
  9527. tx = s - left.x,
  9528. kx = dx / (right.x + s + tx),
  9529. ky = dy / (bottom.depth || 1);
  9530. root.eachBefore(function(node) {
  9531. node.x = (node.x + tx) * kx;
  9532. node.y = node.depth * ky;
  9533. });
  9534. }
  9535. return root;
  9536. }
  9537. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9538. // applied recursively to the children of v, as well as the function
  9539. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9540. // node v is placed to the midpoint of its outermost children.
  9541. function firstWalk(v) {
  9542. var children = v.children,
  9543. siblings = v.parent.children,
  9544. w = v.i ? siblings[v.i - 1] : null;
  9545. if (children) {
  9546. executeShifts(v);
  9547. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9548. if (w) {
  9549. v.z = w.z + separation(v._, w._);
  9550. v.m = v.z - midpoint;
  9551. } else {
  9552. v.z = midpoint;
  9553. }
  9554. } else if (w) {
  9555. v.z = w.z + separation(v._, w._);
  9556. }
  9557. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9558. }
  9559. // Computes all real x-coordinates by summing up the modifiers recursively.
  9560. function secondWalk(v) {
  9561. v._.x = v.z + v.parent.m;
  9562. v.m += v.parent.m;
  9563. }
  9564. // The core of the algorithm. Here, a new subtree is combined with the
  9565. // previous subtrees. Threads are used to traverse the inside and outside
  9566. // contours of the left and right subtree up to the highest common level. The
  9567. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9568. // superscript o means outside and i means inside, the subscript - means left
  9569. // subtree and + means right subtree. For summing up the modifiers along the
  9570. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9571. // nodes of the inside contours conflict, we compute the left one of the
  9572. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9573. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9574. // Finally, we add a new thread (if necessary).
  9575. function apportion(v, w, ancestor) {
  9576. if (w) {
  9577. var vip = v,
  9578. vop = v,
  9579. vim = w,
  9580. vom = vip.parent.children[0],
  9581. sip = vip.m,
  9582. sop = vop.m,
  9583. sim = vim.m,
  9584. som = vom.m,
  9585. shift;
  9586. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9587. vom = nextLeft(vom);
  9588. vop = nextRight(vop);
  9589. vop.a = v;
  9590. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9591. if (shift > 0) {
  9592. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9593. sip += shift;
  9594. sop += shift;
  9595. }
  9596. sim += vim.m;
  9597. sip += vip.m;
  9598. som += vom.m;
  9599. sop += vop.m;
  9600. }
  9601. if (vim && !nextRight(vop)) {
  9602. vop.t = vim;
  9603. vop.m += sim - sop;
  9604. }
  9605. if (vip && !nextLeft(vom)) {
  9606. vom.t = vip;
  9607. vom.m += sip - som;
  9608. ancestor = v;
  9609. }
  9610. }
  9611. return ancestor;
  9612. }
  9613. function sizeNode(node) {
  9614. node.x *= dx;
  9615. node.y = node.depth * dy;
  9616. }
  9617. tree.separation = function(x) {
  9618. return arguments.length ? (separation = x, tree) : separation;
  9619. };
  9620. tree.size = function(x) {
  9621. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9622. };
  9623. tree.nodeSize = function(x) {
  9624. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9625. };
  9626. return tree;
  9627. }
  9628. function treemapSlice(parent, x0, y0, x1, y1) {
  9629. var nodes = parent.children,
  9630. node,
  9631. i = -1,
  9632. n = nodes.length,
  9633. k = parent.value && (y1 - y0) / parent.value;
  9634. while (++i < n) {
  9635. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9636. node.y0 = y0, node.y1 = y0 += node.value * k;
  9637. }
  9638. }
  9639. var phi = (1 + Math.sqrt(5)) / 2;
  9640. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9641. var rows = [],
  9642. nodes = parent.children,
  9643. row,
  9644. nodeValue,
  9645. i0 = 0,
  9646. i1 = 0,
  9647. n = nodes.length,
  9648. dx, dy,
  9649. value = parent.value,
  9650. sumValue,
  9651. minValue,
  9652. maxValue,
  9653. newRatio,
  9654. minRatio,
  9655. alpha,
  9656. beta;
  9657. while (i0 < n) {
  9658. dx = x1 - x0, dy = y1 - y0;
  9659. // Find the next non-empty node.
  9660. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9661. minValue = maxValue = sumValue;
  9662. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9663. beta = sumValue * sumValue * alpha;
  9664. minRatio = Math.max(maxValue / beta, beta / minValue);
  9665. // Keep adding nodes while the aspect ratio maintains or improves.
  9666. for (; i1 < n; ++i1) {
  9667. sumValue += nodeValue = nodes[i1].value;
  9668. if (nodeValue < minValue) minValue = nodeValue;
  9669. if (nodeValue > maxValue) maxValue = nodeValue;
  9670. beta = sumValue * sumValue * alpha;
  9671. newRatio = Math.max(maxValue / beta, beta / minValue);
  9672. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9673. minRatio = newRatio;
  9674. }
  9675. // Position and record the row orientation.
  9676. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9677. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9678. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9679. value -= sumValue, i0 = i1;
  9680. }
  9681. return rows;
  9682. }
  9683. var squarify = (function custom(ratio) {
  9684. function squarify(parent, x0, y0, x1, y1) {
  9685. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9686. }
  9687. squarify.ratio = function(x) {
  9688. return custom((x = +x) > 1 ? x : 1);
  9689. };
  9690. return squarify;
  9691. })(phi);
  9692. function index$3() {
  9693. var tile = squarify,
  9694. round = false,
  9695. dx = 1,
  9696. dy = 1,
  9697. paddingStack = [0],
  9698. paddingInner = constantZero,
  9699. paddingTop = constantZero,
  9700. paddingRight = constantZero,
  9701. paddingBottom = constantZero,
  9702. paddingLeft = constantZero;
  9703. function treemap(root) {
  9704. root.x0 =
  9705. root.y0 = 0;
  9706. root.x1 = dx;
  9707. root.y1 = dy;
  9708. root.eachBefore(positionNode);
  9709. paddingStack = [0];
  9710. if (round) root.eachBefore(roundNode);
  9711. return root;
  9712. }
  9713. function positionNode(node) {
  9714. var p = paddingStack[node.depth],
  9715. x0 = node.x0 + p,
  9716. y0 = node.y0 + p,
  9717. x1 = node.x1 - p,
  9718. y1 = node.y1 - p;
  9719. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9720. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9721. node.x0 = x0;
  9722. node.y0 = y0;
  9723. node.x1 = x1;
  9724. node.y1 = y1;
  9725. if (node.children) {
  9726. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9727. x0 += paddingLeft(node) - p;
  9728. y0 += paddingTop(node) - p;
  9729. x1 -= paddingRight(node) - p;
  9730. y1 -= paddingBottom(node) - p;
  9731. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9732. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9733. tile(node, x0, y0, x1, y1);
  9734. }
  9735. }
  9736. treemap.round = function(x) {
  9737. return arguments.length ? (round = !!x, treemap) : round;
  9738. };
  9739. treemap.size = function(x) {
  9740. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9741. };
  9742. treemap.tile = function(x) {
  9743. return arguments.length ? (tile = required(x), treemap) : tile;
  9744. };
  9745. treemap.padding = function(x) {
  9746. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9747. };
  9748. treemap.paddingInner = function(x) {
  9749. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  9750. };
  9751. treemap.paddingOuter = function(x) {
  9752. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9753. };
  9754. treemap.paddingTop = function(x) {
  9755. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  9756. };
  9757. treemap.paddingRight = function(x) {
  9758. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  9759. };
  9760. treemap.paddingBottom = function(x) {
  9761. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  9762. };
  9763. treemap.paddingLeft = function(x) {
  9764. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  9765. };
  9766. return treemap;
  9767. }
  9768. function binary(parent, x0, y0, x1, y1) {
  9769. var nodes = parent.children,
  9770. i, n = nodes.length,
  9771. sum, sums = new Array(n + 1);
  9772. for (sums[0] = sum = i = 0; i < n; ++i) {
  9773. sums[i + 1] = sum += nodes[i].value;
  9774. }
  9775. partition(0, n, parent.value, x0, y0, x1, y1);
  9776. function partition(i, j, value, x0, y0, x1, y1) {
  9777. if (i >= j - 1) {
  9778. var node = nodes[i];
  9779. node.x0 = x0, node.y0 = y0;
  9780. node.x1 = x1, node.y1 = y1;
  9781. return;
  9782. }
  9783. var valueOffset = sums[i],
  9784. valueTarget = (value / 2) + valueOffset,
  9785. k = i + 1,
  9786. hi = j - 1;
  9787. while (k < hi) {
  9788. var mid = k + hi >>> 1;
  9789. if (sums[mid] < valueTarget) k = mid + 1;
  9790. else hi = mid;
  9791. }
  9792. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  9793. var valueLeft = sums[k] - valueOffset,
  9794. valueRight = value - valueLeft;
  9795. if ((x1 - x0) > (y1 - y0)) {
  9796. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  9797. partition(i, k, valueLeft, x0, y0, xk, y1);
  9798. partition(k, j, valueRight, xk, y0, x1, y1);
  9799. } else {
  9800. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  9801. partition(i, k, valueLeft, x0, y0, x1, yk);
  9802. partition(k, j, valueRight, x0, yk, x1, y1);
  9803. }
  9804. }
  9805. }
  9806. function sliceDice(parent, x0, y0, x1, y1) {
  9807. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  9808. }
  9809. var resquarify = (function custom(ratio) {
  9810. function resquarify(parent, x0, y0, x1, y1) {
  9811. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  9812. var rows,
  9813. row,
  9814. nodes,
  9815. i,
  9816. j = -1,
  9817. n,
  9818. m = rows.length,
  9819. value = parent.value;
  9820. while (++j < m) {
  9821. row = rows[j], nodes = row.children;
  9822. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  9823. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  9824. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  9825. value -= row.value;
  9826. }
  9827. } else {
  9828. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9829. rows.ratio = ratio;
  9830. }
  9831. }
  9832. resquarify.ratio = function(x) {
  9833. return custom((x = +x) > 1 ? x : 1);
  9834. };
  9835. return resquarify;
  9836. })(phi);
  9837. function area$2(polygon) {
  9838. var i = -1,
  9839. n = polygon.length,
  9840. a,
  9841. b = polygon[n - 1],
  9842. area = 0;
  9843. while (++i < n) {
  9844. a = b;
  9845. b = polygon[i];
  9846. area += a[1] * b[0] - a[0] * b[1];
  9847. }
  9848. return area / 2;
  9849. }
  9850. function centroid$1(polygon) {
  9851. var i = -1,
  9852. n = polygon.length,
  9853. x = 0,
  9854. y = 0,
  9855. a,
  9856. b = polygon[n - 1],
  9857. c,
  9858. k = 0;
  9859. while (++i < n) {
  9860. a = b;
  9861. b = polygon[i];
  9862. k += c = a[0] * b[1] - b[0] * a[1];
  9863. x += (a[0] + b[0]) * c;
  9864. y += (a[1] + b[1]) * c;
  9865. }
  9866. return k *= 3, [x / k, y / k];
  9867. }
  9868. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  9869. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  9870. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  9871. // negative if clockwise, and zero if the points are collinear.
  9872. function cross$1(a, b, c) {
  9873. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  9874. }
  9875. function lexicographicOrder(a, b) {
  9876. return a[0] - b[0] || a[1] - b[1];
  9877. }
  9878. // Computes the upper convex hull per the monotone chain algorithm.
  9879. // Assumes points.length >= 3, is sorted by x, unique in y.
  9880. // Returns an array of indices into points in left-to-right order.
  9881. function computeUpperHullIndexes(points) {
  9882. var n = points.length,
  9883. indexes = [0, 1],
  9884. size = 2;
  9885. for (var i = 2; i < n; ++i) {
  9886. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  9887. indexes[size++] = i;
  9888. }
  9889. return indexes.slice(0, size); // remove popped points
  9890. }
  9891. function hull(points) {
  9892. if ((n = points.length) < 3) return null;
  9893. var i,
  9894. n,
  9895. sortedPoints = new Array(n),
  9896. flippedPoints = new Array(n);
  9897. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  9898. sortedPoints.sort(lexicographicOrder);
  9899. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  9900. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  9901. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  9902. // Construct the hull polygon, removing possible duplicate endpoints.
  9903. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  9904. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  9905. hull = [];
  9906. // Add upper hull in right-to-l order.
  9907. // Then add lower hull in left-to-right order.
  9908. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  9909. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  9910. return hull;
  9911. }
  9912. function contains$2(polygon, point) {
  9913. var n = polygon.length,
  9914. p = polygon[n - 1],
  9915. x = point[0], y = point[1],
  9916. x0 = p[0], y0 = p[1],
  9917. x1, y1,
  9918. inside = false;
  9919. for (var i = 0; i < n; ++i) {
  9920. p = polygon[i], x1 = p[0], y1 = p[1];
  9921. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  9922. x0 = x1, y0 = y1;
  9923. }
  9924. return inside;
  9925. }
  9926. function length$2(polygon) {
  9927. var i = -1,
  9928. n = polygon.length,
  9929. b = polygon[n - 1],
  9930. xa,
  9931. ya,
  9932. xb = b[0],
  9933. yb = b[1],
  9934. perimeter = 0;
  9935. while (++i < n) {
  9936. xa = xb;
  9937. ya = yb;
  9938. b = polygon[i];
  9939. xb = b[0];
  9940. yb = b[1];
  9941. xa -= xb;
  9942. ya -= yb;
  9943. perimeter += Math.sqrt(xa * xa + ya * ya);
  9944. }
  9945. return perimeter;
  9946. }
  9947. function defaultSource$1() {
  9948. return Math.random();
  9949. }
  9950. var uniform = (function sourceRandomUniform(source) {
  9951. function randomUniform(min, max) {
  9952. min = min == null ? 0 : +min;
  9953. max = max == null ? 1 : +max;
  9954. if (arguments.length === 1) max = min, min = 0;
  9955. else max -= min;
  9956. return function() {
  9957. return source() * max + min;
  9958. };
  9959. }
  9960. randomUniform.source = sourceRandomUniform;
  9961. return randomUniform;
  9962. })(defaultSource$1);
  9963. var normal = (function sourceRandomNormal(source) {
  9964. function randomNormal(mu, sigma) {
  9965. var x, r;
  9966. mu = mu == null ? 0 : +mu;
  9967. sigma = sigma == null ? 1 : +sigma;
  9968. return function() {
  9969. var y;
  9970. // If available, use the second previously-generated uniform random.
  9971. if (x != null) y = x, x = null;
  9972. // Otherwise, generate a new x and y.
  9973. else do {
  9974. x = source() * 2 - 1;
  9975. y = source() * 2 - 1;
  9976. r = x * x + y * y;
  9977. } while (!r || r > 1);
  9978. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  9979. };
  9980. }
  9981. randomNormal.source = sourceRandomNormal;
  9982. return randomNormal;
  9983. })(defaultSource$1);
  9984. var logNormal = (function sourceRandomLogNormal(source) {
  9985. function randomLogNormal() {
  9986. var randomNormal = normal.source(source).apply(this, arguments);
  9987. return function() {
  9988. return Math.exp(randomNormal());
  9989. };
  9990. }
  9991. randomLogNormal.source = sourceRandomLogNormal;
  9992. return randomLogNormal;
  9993. })(defaultSource$1);
  9994. var irwinHall = (function sourceRandomIrwinHall(source) {
  9995. function randomIrwinHall(n) {
  9996. return function() {
  9997. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  9998. return sum;
  9999. };
  10000. }
  10001. randomIrwinHall.source = sourceRandomIrwinHall;
  10002. return randomIrwinHall;
  10003. })(defaultSource$1);
  10004. var bates = (function sourceRandomBates(source) {
  10005. function randomBates(n) {
  10006. var randomIrwinHall = irwinHall.source(source)(n);
  10007. return function() {
  10008. return randomIrwinHall() / n;
  10009. };
  10010. }
  10011. randomBates.source = sourceRandomBates;
  10012. return randomBates;
  10013. })(defaultSource$1);
  10014. var exponential$1 = (function sourceRandomExponential(source) {
  10015. function randomExponential(lambda) {
  10016. return function() {
  10017. return -Math.log(1 - source()) / lambda;
  10018. };
  10019. }
  10020. randomExponential.source = sourceRandomExponential;
  10021. return randomExponential;
  10022. })(defaultSource$1);
  10023. var array$3 = Array.prototype;
  10024. var map$2 = array$3.map;
  10025. var slice$5 = array$3.slice;
  10026. var implicit = {name: "implicit"};
  10027. function ordinal(range) {
  10028. var index = map$1(),
  10029. domain = [],
  10030. unknown = implicit;
  10031. range = range == null ? [] : slice$5.call(range);
  10032. function scale(d) {
  10033. var key = d + "", i = index.get(key);
  10034. if (!i) {
  10035. if (unknown !== implicit) return unknown;
  10036. index.set(key, i = domain.push(d));
  10037. }
  10038. return range[(i - 1) % range.length];
  10039. }
  10040. scale.domain = function(_) {
  10041. if (!arguments.length) return domain.slice();
  10042. domain = [], index = map$1();
  10043. var i = -1, n = _.length, d, key;
  10044. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  10045. return scale;
  10046. };
  10047. scale.range = function(_) {
  10048. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  10049. };
  10050. scale.unknown = function(_) {
  10051. return arguments.length ? (unknown = _, scale) : unknown;
  10052. };
  10053. scale.copy = function() {
  10054. return ordinal()
  10055. .domain(domain)
  10056. .range(range)
  10057. .unknown(unknown);
  10058. };
  10059. return scale;
  10060. }
  10061. function band() {
  10062. var scale = ordinal().unknown(undefined),
  10063. domain = scale.domain,
  10064. ordinalRange = scale.range,
  10065. range$$1 = [0, 1],
  10066. step,
  10067. bandwidth,
  10068. round = false,
  10069. paddingInner = 0,
  10070. paddingOuter = 0,
  10071. align = 0.5;
  10072. delete scale.unknown;
  10073. function rescale() {
  10074. var n = domain().length,
  10075. reverse = range$$1[1] < range$$1[0],
  10076. start = range$$1[reverse - 0],
  10077. stop = range$$1[1 - reverse];
  10078. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  10079. if (round) step = Math.floor(step);
  10080. start += (stop - start - step * (n - paddingInner)) * align;
  10081. bandwidth = step * (1 - paddingInner);
  10082. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  10083. var values = sequence(n).map(function(i) { return start + step * i; });
  10084. return ordinalRange(reverse ? values.reverse() : values);
  10085. }
  10086. scale.domain = function(_) {
  10087. return arguments.length ? (domain(_), rescale()) : domain();
  10088. };
  10089. scale.range = function(_) {
  10090. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  10091. };
  10092. scale.rangeRound = function(_) {
  10093. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  10094. };
  10095. scale.bandwidth = function() {
  10096. return bandwidth;
  10097. };
  10098. scale.step = function() {
  10099. return step;
  10100. };
  10101. scale.round = function(_) {
  10102. return arguments.length ? (round = !!_, rescale()) : round;
  10103. };
  10104. scale.padding = function(_) {
  10105. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10106. };
  10107. scale.paddingInner = function(_) {
  10108. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10109. };
  10110. scale.paddingOuter = function(_) {
  10111. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  10112. };
  10113. scale.align = function(_) {
  10114. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  10115. };
  10116. scale.copy = function() {
  10117. return band()
  10118. .domain(domain())
  10119. .range(range$$1)
  10120. .round(round)
  10121. .paddingInner(paddingInner)
  10122. .paddingOuter(paddingOuter)
  10123. .align(align);
  10124. };
  10125. return rescale();
  10126. }
  10127. function pointish(scale) {
  10128. var copy = scale.copy;
  10129. scale.padding = scale.paddingOuter;
  10130. delete scale.paddingInner;
  10131. delete scale.paddingOuter;
  10132. scale.copy = function() {
  10133. return pointish(copy());
  10134. };
  10135. return scale;
  10136. }
  10137. function point$1() {
  10138. return pointish(band().paddingInner(1));
  10139. }
  10140. function constant$10(x) {
  10141. return function() {
  10142. return x;
  10143. };
  10144. }
  10145. function number$2(x) {
  10146. return +x;
  10147. }
  10148. var unit = [0, 1];
  10149. function deinterpolateLinear(a, b) {
  10150. return (b -= (a = +a))
  10151. ? function(x) { return (x - a) / b; }
  10152. : constant$10(b);
  10153. }
  10154. function deinterpolateClamp(deinterpolate) {
  10155. return function(a, b) {
  10156. var d = deinterpolate(a = +a, b = +b);
  10157. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  10158. };
  10159. }
  10160. function reinterpolateClamp(reinterpolate$$1) {
  10161. return function(a, b) {
  10162. var r = reinterpolate$$1(a = +a, b = +b);
  10163. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  10164. };
  10165. }
  10166. function bimap(domain, range, deinterpolate, reinterpolate$$1) {
  10167. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  10168. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate$$1(r1, r0);
  10169. else d0 = deinterpolate(d0, d1), r0 = reinterpolate$$1(r0, r1);
  10170. return function(x) { return r0(d0(x)); };
  10171. }
  10172. function polymap(domain, range, deinterpolate, reinterpolate$$1) {
  10173. var j = Math.min(domain.length, range.length) - 1,
  10174. d = new Array(j),
  10175. r = new Array(j),
  10176. i = -1;
  10177. // Reverse descending domains.
  10178. if (domain[j] < domain[0]) {
  10179. domain = domain.slice().reverse();
  10180. range = range.slice().reverse();
  10181. }
  10182. while (++i < j) {
  10183. d[i] = deinterpolate(domain[i], domain[i + 1]);
  10184. r[i] = reinterpolate$$1(range[i], range[i + 1]);
  10185. }
  10186. return function(x) {
  10187. var i = bisectRight(domain, x, 1, j) - 1;
  10188. return r[i](d[i](x));
  10189. };
  10190. }
  10191. function copy(source, target) {
  10192. return target
  10193. .domain(source.domain())
  10194. .range(source.range())
  10195. .interpolate(source.interpolate())
  10196. .clamp(source.clamp());
  10197. }
  10198. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10199. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  10200. function continuous(deinterpolate, reinterpolate$$1) {
  10201. var domain = unit,
  10202. range = unit,
  10203. interpolate$$1 = interpolateValue,
  10204. clamp = false,
  10205. piecewise$$1,
  10206. output,
  10207. input;
  10208. function rescale() {
  10209. piecewise$$1 = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10210. output = input = null;
  10211. return scale;
  10212. }
  10213. function scale(x) {
  10214. return (output || (output = piecewise$$1(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  10215. }
  10216. scale.invert = function(y) {
  10217. return (input || (input = piecewise$$1(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate$$1) : reinterpolate$$1)))(+y);
  10218. };
  10219. scale.domain = function(_) {
  10220. return arguments.length ? (domain = map$2.call(_, number$2), rescale()) : domain.slice();
  10221. };
  10222. scale.range = function(_) {
  10223. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10224. };
  10225. scale.rangeRound = function(_) {
  10226. return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
  10227. };
  10228. scale.clamp = function(_) {
  10229. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  10230. };
  10231. scale.interpolate = function(_) {
  10232. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  10233. };
  10234. return rescale();
  10235. }
  10236. function tickFormat(domain, count, specifier) {
  10237. var start = domain[0],
  10238. stop = domain[domain.length - 1],
  10239. step = tickStep(start, stop, count == null ? 10 : count),
  10240. precision;
  10241. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10242. switch (specifier.type) {
  10243. case "s": {
  10244. var value = Math.max(Math.abs(start), Math.abs(stop));
  10245. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10246. return exports.formatPrefix(specifier, value);
  10247. }
  10248. case "":
  10249. case "e":
  10250. case "g":
  10251. case "p":
  10252. case "r": {
  10253. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10254. break;
  10255. }
  10256. case "f":
  10257. case "%": {
  10258. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10259. break;
  10260. }
  10261. }
  10262. return exports.format(specifier);
  10263. }
  10264. function linearish(scale) {
  10265. var domain = scale.domain;
  10266. scale.ticks = function(count) {
  10267. var d = domain();
  10268. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10269. };
  10270. scale.tickFormat = function(count, specifier) {
  10271. return tickFormat(domain(), count, specifier);
  10272. };
  10273. scale.nice = function(count) {
  10274. if (count == null) count = 10;
  10275. var d = domain(),
  10276. i0 = 0,
  10277. i1 = d.length - 1,
  10278. start = d[i0],
  10279. stop = d[i1],
  10280. step;
  10281. if (stop < start) {
  10282. step = start, start = stop, stop = step;
  10283. step = i0, i0 = i1, i1 = step;
  10284. }
  10285. step = tickIncrement(start, stop, count);
  10286. if (step > 0) {
  10287. start = Math.floor(start / step) * step;
  10288. stop = Math.ceil(stop / step) * step;
  10289. step = tickIncrement(start, stop, count);
  10290. } else if (step < 0) {
  10291. start = Math.ceil(start * step) / step;
  10292. stop = Math.floor(stop * step) / step;
  10293. step = tickIncrement(start, stop, count);
  10294. }
  10295. if (step > 0) {
  10296. d[i0] = Math.floor(start / step) * step;
  10297. d[i1] = Math.ceil(stop / step) * step;
  10298. domain(d);
  10299. } else if (step < 0) {
  10300. d[i0] = Math.ceil(start * step) / step;
  10301. d[i1] = Math.floor(stop * step) / step;
  10302. domain(d);
  10303. }
  10304. return scale;
  10305. };
  10306. return scale;
  10307. }
  10308. function linear$2() {
  10309. var scale = continuous(deinterpolateLinear, reinterpolate);
  10310. scale.copy = function() {
  10311. return copy(scale, linear$2());
  10312. };
  10313. return linearish(scale);
  10314. }
  10315. function identity$6() {
  10316. var domain = [0, 1];
  10317. function scale(x) {
  10318. return +x;
  10319. }
  10320. scale.invert = scale;
  10321. scale.domain = scale.range = function(_) {
  10322. return arguments.length ? (domain = map$2.call(_, number$2), scale) : domain.slice();
  10323. };
  10324. scale.copy = function() {
  10325. return identity$6().domain(domain);
  10326. };
  10327. return linearish(scale);
  10328. }
  10329. function nice(domain, interval) {
  10330. domain = domain.slice();
  10331. var i0 = 0,
  10332. i1 = domain.length - 1,
  10333. x0 = domain[i0],
  10334. x1 = domain[i1],
  10335. t;
  10336. if (x1 < x0) {
  10337. t = i0, i0 = i1, i1 = t;
  10338. t = x0, x0 = x1, x1 = t;
  10339. }
  10340. domain[i0] = interval.floor(x0);
  10341. domain[i1] = interval.ceil(x1);
  10342. return domain;
  10343. }
  10344. function deinterpolate(a, b) {
  10345. return (b = Math.log(b / a))
  10346. ? function(x) { return Math.log(x / a) / b; }
  10347. : constant$10(b);
  10348. }
  10349. function reinterpolate$1(a, b) {
  10350. return a < 0
  10351. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  10352. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  10353. }
  10354. function pow10(x) {
  10355. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10356. }
  10357. function powp(base) {
  10358. return base === 10 ? pow10
  10359. : base === Math.E ? Math.exp
  10360. : function(x) { return Math.pow(base, x); };
  10361. }
  10362. function logp(base) {
  10363. return base === Math.E ? Math.log
  10364. : base === 10 && Math.log10
  10365. || base === 2 && Math.log2
  10366. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10367. }
  10368. function reflect(f) {
  10369. return function(x) {
  10370. return -f(-x);
  10371. };
  10372. }
  10373. function log$1() {
  10374. var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
  10375. domain = scale.domain,
  10376. base = 10,
  10377. logs = logp(10),
  10378. pows = powp(10);
  10379. function rescale() {
  10380. logs = logp(base), pows = powp(base);
  10381. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  10382. return scale;
  10383. }
  10384. scale.base = function(_) {
  10385. return arguments.length ? (base = +_, rescale()) : base;
  10386. };
  10387. scale.domain = function(_) {
  10388. return arguments.length ? (domain(_), rescale()) : domain();
  10389. };
  10390. scale.ticks = function(count) {
  10391. var d = domain(),
  10392. u = d[0],
  10393. v = d[d.length - 1],
  10394. r;
  10395. if (r = v < u) i = u, u = v, v = i;
  10396. var i = logs(u),
  10397. j = logs(v),
  10398. p,
  10399. k,
  10400. t,
  10401. n = count == null ? 10 : +count,
  10402. z = [];
  10403. if (!(base % 1) && j - i < n) {
  10404. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10405. if (u > 0) for (; i < j; ++i) {
  10406. for (k = 1, p = pows(i); k < base; ++k) {
  10407. t = p * k;
  10408. if (t < u) continue;
  10409. if (t > v) break;
  10410. z.push(t);
  10411. }
  10412. } else for (; i < j; ++i) {
  10413. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10414. t = p * k;
  10415. if (t < u) continue;
  10416. if (t > v) break;
  10417. z.push(t);
  10418. }
  10419. }
  10420. } else {
  10421. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10422. }
  10423. return r ? z.reverse() : z;
  10424. };
  10425. scale.tickFormat = function(count, specifier) {
  10426. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10427. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10428. if (count === Infinity) return specifier;
  10429. if (count == null) count = 10;
  10430. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10431. return function(d) {
  10432. var i = d / pows(Math.round(logs(d)));
  10433. if (i * base < base - 0.5) i *= base;
  10434. return i <= k ? specifier(d) : "";
  10435. };
  10436. };
  10437. scale.nice = function() {
  10438. return domain(nice(domain(), {
  10439. floor: function(x) { return pows(Math.floor(logs(x))); },
  10440. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10441. }));
  10442. };
  10443. scale.copy = function() {
  10444. return copy(scale, log$1().base(base));
  10445. };
  10446. return scale;
  10447. }
  10448. function raise$1(x, exponent) {
  10449. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10450. }
  10451. function pow$1() {
  10452. var exponent = 1,
  10453. scale = continuous(deinterpolate, reinterpolate),
  10454. domain = scale.domain;
  10455. function deinterpolate(a, b) {
  10456. return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
  10457. ? function(x) { return (raise$1(x, exponent) - a) / b; }
  10458. : constant$10(b);
  10459. }
  10460. function reinterpolate(a, b) {
  10461. b = raise$1(b, exponent) - (a = raise$1(a, exponent));
  10462. return function(t) { return raise$1(a + b * t, 1 / exponent); };
  10463. }
  10464. scale.exponent = function(_) {
  10465. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  10466. };
  10467. scale.copy = function() {
  10468. return copy(scale, pow$1().exponent(exponent));
  10469. };
  10470. return linearish(scale);
  10471. }
  10472. function sqrt$1() {
  10473. return pow$1().exponent(0.5);
  10474. }
  10475. function quantile$$1() {
  10476. var domain = [],
  10477. range = [],
  10478. thresholds = [];
  10479. function rescale() {
  10480. var i = 0, n = Math.max(1, range.length);
  10481. thresholds = new Array(n - 1);
  10482. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10483. return scale;
  10484. }
  10485. function scale(x) {
  10486. if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
  10487. }
  10488. scale.invertExtent = function(y) {
  10489. var i = range.indexOf(y);
  10490. return i < 0 ? [NaN, NaN] : [
  10491. i > 0 ? thresholds[i - 1] : domain[0],
  10492. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10493. ];
  10494. };
  10495. scale.domain = function(_) {
  10496. if (!arguments.length) return domain.slice();
  10497. domain = [];
  10498. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10499. domain.sort(ascending);
  10500. return rescale();
  10501. };
  10502. scale.range = function(_) {
  10503. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10504. };
  10505. scale.quantiles = function() {
  10506. return thresholds.slice();
  10507. };
  10508. scale.copy = function() {
  10509. return quantile$$1()
  10510. .domain(domain)
  10511. .range(range);
  10512. };
  10513. return scale;
  10514. }
  10515. function quantize$1() {
  10516. var x0 = 0,
  10517. x1 = 1,
  10518. n = 1,
  10519. domain = [0.5],
  10520. range = [0, 1];
  10521. function scale(x) {
  10522. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10523. }
  10524. function rescale() {
  10525. var i = -1;
  10526. domain = new Array(n);
  10527. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10528. return scale;
  10529. }
  10530. scale.domain = function(_) {
  10531. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10532. };
  10533. scale.range = function(_) {
  10534. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10535. };
  10536. scale.invertExtent = function(y) {
  10537. var i = range.indexOf(y);
  10538. return i < 0 ? [NaN, NaN]
  10539. : i < 1 ? [x0, domain[0]]
  10540. : i >= n ? [domain[n - 1], x1]
  10541. : [domain[i - 1], domain[i]];
  10542. };
  10543. scale.copy = function() {
  10544. return quantize$1()
  10545. .domain([x0, x1])
  10546. .range(range);
  10547. };
  10548. return linearish(scale);
  10549. }
  10550. function threshold$1() {
  10551. var domain = [0.5],
  10552. range = [0, 1],
  10553. n = 1;
  10554. function scale(x) {
  10555. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10556. }
  10557. scale.domain = function(_) {
  10558. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10559. };
  10560. scale.range = function(_) {
  10561. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10562. };
  10563. scale.invertExtent = function(y) {
  10564. var i = range.indexOf(y);
  10565. return [domain[i - 1], domain[i]];
  10566. };
  10567. scale.copy = function() {
  10568. return threshold$1()
  10569. .domain(domain)
  10570. .range(range);
  10571. };
  10572. return scale;
  10573. }
  10574. var t0$1 = new Date,
  10575. t1$1 = new Date;
  10576. function newInterval(floori, offseti, count, field) {
  10577. function interval(date) {
  10578. return floori(date = new Date(+date)), date;
  10579. }
  10580. interval.floor = interval;
  10581. interval.ceil = function(date) {
  10582. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10583. };
  10584. interval.round = function(date) {
  10585. var d0 = interval(date),
  10586. d1 = interval.ceil(date);
  10587. return date - d0 < d1 - date ? d0 : d1;
  10588. };
  10589. interval.offset = function(date, step) {
  10590. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10591. };
  10592. interval.range = function(start, stop, step) {
  10593. var range = [], previous;
  10594. start = interval.ceil(start);
  10595. step = step == null ? 1 : Math.floor(step);
  10596. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10597. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  10598. while (previous < start && start < stop);
  10599. return range;
  10600. };
  10601. interval.filter = function(test) {
  10602. return newInterval(function(date) {
  10603. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10604. }, function(date, step) {
  10605. if (date >= date) {
  10606. if (step < 0) while (++step <= 0) {
  10607. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10608. } else while (--step >= 0) {
  10609. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10610. }
  10611. }
  10612. });
  10613. };
  10614. if (count) {
  10615. interval.count = function(start, end) {
  10616. t0$1.setTime(+start), t1$1.setTime(+end);
  10617. floori(t0$1), floori(t1$1);
  10618. return Math.floor(count(t0$1, t1$1));
  10619. };
  10620. interval.every = function(step) {
  10621. step = Math.floor(step);
  10622. return !isFinite(step) || !(step > 0) ? null
  10623. : !(step > 1) ? interval
  10624. : interval.filter(field
  10625. ? function(d) { return field(d) % step === 0; }
  10626. : function(d) { return interval.count(0, d) % step === 0; });
  10627. };
  10628. }
  10629. return interval;
  10630. }
  10631. var millisecond = newInterval(function() {
  10632. // noop
  10633. }, function(date, step) {
  10634. date.setTime(+date + step);
  10635. }, function(start, end) {
  10636. return end - start;
  10637. });
  10638. // An optimized implementation for this simple case.
  10639. millisecond.every = function(k) {
  10640. k = Math.floor(k);
  10641. if (!isFinite(k) || !(k > 0)) return null;
  10642. if (!(k > 1)) return millisecond;
  10643. return newInterval(function(date) {
  10644. date.setTime(Math.floor(date / k) * k);
  10645. }, function(date, step) {
  10646. date.setTime(+date + step * k);
  10647. }, function(start, end) {
  10648. return (end - start) / k;
  10649. });
  10650. };
  10651. var milliseconds = millisecond.range;
  10652. var durationSecond = 1e3;
  10653. var durationMinute = 6e4;
  10654. var durationHour = 36e5;
  10655. var durationDay = 864e5;
  10656. var durationWeek = 6048e5;
  10657. var second = newInterval(function(date) {
  10658. date.setTime(Math.floor(date / durationSecond) * durationSecond);
  10659. }, function(date, step) {
  10660. date.setTime(+date + step * durationSecond);
  10661. }, function(start, end) {
  10662. return (end - start) / durationSecond;
  10663. }, function(date) {
  10664. return date.getUTCSeconds();
  10665. });
  10666. var seconds = second.range;
  10667. var minute = newInterval(function(date) {
  10668. date.setTime(Math.floor(date / durationMinute) * durationMinute);
  10669. }, function(date, step) {
  10670. date.setTime(+date + step * durationMinute);
  10671. }, function(start, end) {
  10672. return (end - start) / durationMinute;
  10673. }, function(date) {
  10674. return date.getMinutes();
  10675. });
  10676. var minutes = minute.range;
  10677. var hour = newInterval(function(date) {
  10678. var offset = date.getTimezoneOffset() * durationMinute % durationHour;
  10679. if (offset < 0) offset += durationHour;
  10680. date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
  10681. }, function(date, step) {
  10682. date.setTime(+date + step * durationHour);
  10683. }, function(start, end) {
  10684. return (end - start) / durationHour;
  10685. }, function(date) {
  10686. return date.getHours();
  10687. });
  10688. var hours = hour.range;
  10689. var day = newInterval(function(date) {
  10690. date.setHours(0, 0, 0, 0);
  10691. }, function(date, step) {
  10692. date.setDate(date.getDate() + step);
  10693. }, function(start, end) {
  10694. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  10695. }, function(date) {
  10696. return date.getDate() - 1;
  10697. });
  10698. var days = day.range;
  10699. function weekday(i) {
  10700. return newInterval(function(date) {
  10701. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  10702. date.setHours(0, 0, 0, 0);
  10703. }, function(date, step) {
  10704. date.setDate(date.getDate() + step * 7);
  10705. }, function(start, end) {
  10706. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  10707. });
  10708. }
  10709. var sunday = weekday(0);
  10710. var monday = weekday(1);
  10711. var tuesday = weekday(2);
  10712. var wednesday = weekday(3);
  10713. var thursday = weekday(4);
  10714. var friday = weekday(5);
  10715. var saturday = weekday(6);
  10716. var sundays = sunday.range;
  10717. var mondays = monday.range;
  10718. var tuesdays = tuesday.range;
  10719. var wednesdays = wednesday.range;
  10720. var thursdays = thursday.range;
  10721. var fridays = friday.range;
  10722. var saturdays = saturday.range;
  10723. var month = newInterval(function(date) {
  10724. date.setDate(1);
  10725. date.setHours(0, 0, 0, 0);
  10726. }, function(date, step) {
  10727. date.setMonth(date.getMonth() + step);
  10728. }, function(start, end) {
  10729. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  10730. }, function(date) {
  10731. return date.getMonth();
  10732. });
  10733. var months = month.range;
  10734. var year = newInterval(function(date) {
  10735. date.setMonth(0, 1);
  10736. date.setHours(0, 0, 0, 0);
  10737. }, function(date, step) {
  10738. date.setFullYear(date.getFullYear() + step);
  10739. }, function(start, end) {
  10740. return end.getFullYear() - start.getFullYear();
  10741. }, function(date) {
  10742. return date.getFullYear();
  10743. });
  10744. // An optimized implementation for this simple case.
  10745. year.every = function(k) {
  10746. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10747. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  10748. date.setMonth(0, 1);
  10749. date.setHours(0, 0, 0, 0);
  10750. }, function(date, step) {
  10751. date.setFullYear(date.getFullYear() + step * k);
  10752. });
  10753. };
  10754. var years = year.range;
  10755. var utcMinute = newInterval(function(date) {
  10756. date.setUTCSeconds(0, 0);
  10757. }, function(date, step) {
  10758. date.setTime(+date + step * durationMinute);
  10759. }, function(start, end) {
  10760. return (end - start) / durationMinute;
  10761. }, function(date) {
  10762. return date.getUTCMinutes();
  10763. });
  10764. var utcMinutes = utcMinute.range;
  10765. var utcHour = newInterval(function(date) {
  10766. date.setUTCMinutes(0, 0, 0);
  10767. }, function(date, step) {
  10768. date.setTime(+date + step * durationHour);
  10769. }, function(start, end) {
  10770. return (end - start) / durationHour;
  10771. }, function(date) {
  10772. return date.getUTCHours();
  10773. });
  10774. var utcHours = utcHour.range;
  10775. var utcDay = newInterval(function(date) {
  10776. date.setUTCHours(0, 0, 0, 0);
  10777. }, function(date, step) {
  10778. date.setUTCDate(date.getUTCDate() + step);
  10779. }, function(start, end) {
  10780. return (end - start) / durationDay;
  10781. }, function(date) {
  10782. return date.getUTCDate() - 1;
  10783. });
  10784. var utcDays = utcDay.range;
  10785. function utcWeekday(i) {
  10786. return newInterval(function(date) {
  10787. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  10788. date.setUTCHours(0, 0, 0, 0);
  10789. }, function(date, step) {
  10790. date.setUTCDate(date.getUTCDate() + step * 7);
  10791. }, function(start, end) {
  10792. return (end - start) / durationWeek;
  10793. });
  10794. }
  10795. var utcSunday = utcWeekday(0);
  10796. var utcMonday = utcWeekday(1);
  10797. var utcTuesday = utcWeekday(2);
  10798. var utcWednesday = utcWeekday(3);
  10799. var utcThursday = utcWeekday(4);
  10800. var utcFriday = utcWeekday(5);
  10801. var utcSaturday = utcWeekday(6);
  10802. var utcSundays = utcSunday.range;
  10803. var utcMondays = utcMonday.range;
  10804. var utcTuesdays = utcTuesday.range;
  10805. var utcWednesdays = utcWednesday.range;
  10806. var utcThursdays = utcThursday.range;
  10807. var utcFridays = utcFriday.range;
  10808. var utcSaturdays = utcSaturday.range;
  10809. var utcMonth = newInterval(function(date) {
  10810. date.setUTCDate(1);
  10811. date.setUTCHours(0, 0, 0, 0);
  10812. }, function(date, step) {
  10813. date.setUTCMonth(date.getUTCMonth() + step);
  10814. }, function(start, end) {
  10815. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  10816. }, function(date) {
  10817. return date.getUTCMonth();
  10818. });
  10819. var utcMonths = utcMonth.range;
  10820. var utcYear = newInterval(function(date) {
  10821. date.setUTCMonth(0, 1);
  10822. date.setUTCHours(0, 0, 0, 0);
  10823. }, function(date, step) {
  10824. date.setUTCFullYear(date.getUTCFullYear() + step);
  10825. }, function(start, end) {
  10826. return end.getUTCFullYear() - start.getUTCFullYear();
  10827. }, function(date) {
  10828. return date.getUTCFullYear();
  10829. });
  10830. // An optimized implementation for this simple case.
  10831. utcYear.every = function(k) {
  10832. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10833. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  10834. date.setUTCMonth(0, 1);
  10835. date.setUTCHours(0, 0, 0, 0);
  10836. }, function(date, step) {
  10837. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  10838. });
  10839. };
  10840. var utcYears = utcYear.range;
  10841. function localDate(d) {
  10842. if (0 <= d.y && d.y < 100) {
  10843. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  10844. date.setFullYear(d.y);
  10845. return date;
  10846. }
  10847. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  10848. }
  10849. function utcDate(d) {
  10850. if (0 <= d.y && d.y < 100) {
  10851. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  10852. date.setUTCFullYear(d.y);
  10853. return date;
  10854. }
  10855. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  10856. }
  10857. function newYear(y) {
  10858. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  10859. }
  10860. function formatLocale$1(locale) {
  10861. var locale_dateTime = locale.dateTime,
  10862. locale_date = locale.date,
  10863. locale_time = locale.time,
  10864. locale_periods = locale.periods,
  10865. locale_weekdays = locale.days,
  10866. locale_shortWeekdays = locale.shortDays,
  10867. locale_months = locale.months,
  10868. locale_shortMonths = locale.shortMonths;
  10869. var periodRe = formatRe(locale_periods),
  10870. periodLookup = formatLookup(locale_periods),
  10871. weekdayRe = formatRe(locale_weekdays),
  10872. weekdayLookup = formatLookup(locale_weekdays),
  10873. shortWeekdayRe = formatRe(locale_shortWeekdays),
  10874. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  10875. monthRe = formatRe(locale_months),
  10876. monthLookup = formatLookup(locale_months),
  10877. shortMonthRe = formatRe(locale_shortMonths),
  10878. shortMonthLookup = formatLookup(locale_shortMonths);
  10879. var formats = {
  10880. "a": formatShortWeekday,
  10881. "A": formatWeekday,
  10882. "b": formatShortMonth,
  10883. "B": formatMonth,
  10884. "c": null,
  10885. "d": formatDayOfMonth,
  10886. "e": formatDayOfMonth,
  10887. "f": formatMicroseconds,
  10888. "H": formatHour24,
  10889. "I": formatHour12,
  10890. "j": formatDayOfYear,
  10891. "L": formatMilliseconds,
  10892. "m": formatMonthNumber,
  10893. "M": formatMinutes,
  10894. "p": formatPeriod,
  10895. "Q": formatUnixTimestamp,
  10896. "s": formatUnixTimestampSeconds,
  10897. "S": formatSeconds,
  10898. "u": formatWeekdayNumberMonday,
  10899. "U": formatWeekNumberSunday,
  10900. "V": formatWeekNumberISO,
  10901. "w": formatWeekdayNumberSunday,
  10902. "W": formatWeekNumberMonday,
  10903. "x": null,
  10904. "X": null,
  10905. "y": formatYear,
  10906. "Y": formatFullYear,
  10907. "Z": formatZone,
  10908. "%": formatLiteralPercent
  10909. };
  10910. var utcFormats = {
  10911. "a": formatUTCShortWeekday,
  10912. "A": formatUTCWeekday,
  10913. "b": formatUTCShortMonth,
  10914. "B": formatUTCMonth,
  10915. "c": null,
  10916. "d": formatUTCDayOfMonth,
  10917. "e": formatUTCDayOfMonth,
  10918. "f": formatUTCMicroseconds,
  10919. "H": formatUTCHour24,
  10920. "I": formatUTCHour12,
  10921. "j": formatUTCDayOfYear,
  10922. "L": formatUTCMilliseconds,
  10923. "m": formatUTCMonthNumber,
  10924. "M": formatUTCMinutes,
  10925. "p": formatUTCPeriod,
  10926. "Q": formatUnixTimestamp,
  10927. "s": formatUnixTimestampSeconds,
  10928. "S": formatUTCSeconds,
  10929. "u": formatUTCWeekdayNumberMonday,
  10930. "U": formatUTCWeekNumberSunday,
  10931. "V": formatUTCWeekNumberISO,
  10932. "w": formatUTCWeekdayNumberSunday,
  10933. "W": formatUTCWeekNumberMonday,
  10934. "x": null,
  10935. "X": null,
  10936. "y": formatUTCYear,
  10937. "Y": formatUTCFullYear,
  10938. "Z": formatUTCZone,
  10939. "%": formatLiteralPercent
  10940. };
  10941. var parses = {
  10942. "a": parseShortWeekday,
  10943. "A": parseWeekday,
  10944. "b": parseShortMonth,
  10945. "B": parseMonth,
  10946. "c": parseLocaleDateTime,
  10947. "d": parseDayOfMonth,
  10948. "e": parseDayOfMonth,
  10949. "f": parseMicroseconds,
  10950. "H": parseHour24,
  10951. "I": parseHour24,
  10952. "j": parseDayOfYear,
  10953. "L": parseMilliseconds,
  10954. "m": parseMonthNumber,
  10955. "M": parseMinutes,
  10956. "p": parsePeriod,
  10957. "Q": parseUnixTimestamp,
  10958. "s": parseUnixTimestampSeconds,
  10959. "S": parseSeconds,
  10960. "u": parseWeekdayNumberMonday,
  10961. "U": parseWeekNumberSunday,
  10962. "V": parseWeekNumberISO,
  10963. "w": parseWeekdayNumberSunday,
  10964. "W": parseWeekNumberMonday,
  10965. "x": parseLocaleDate,
  10966. "X": parseLocaleTime,
  10967. "y": parseYear,
  10968. "Y": parseFullYear,
  10969. "Z": parseZone,
  10970. "%": parseLiteralPercent
  10971. };
  10972. // These recursive directive definitions must be deferred.
  10973. formats.x = newFormat(locale_date, formats);
  10974. formats.X = newFormat(locale_time, formats);
  10975. formats.c = newFormat(locale_dateTime, formats);
  10976. utcFormats.x = newFormat(locale_date, utcFormats);
  10977. utcFormats.X = newFormat(locale_time, utcFormats);
  10978. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  10979. function newFormat(specifier, formats) {
  10980. return function(date) {
  10981. var string = [],
  10982. i = -1,
  10983. j = 0,
  10984. n = specifier.length,
  10985. c,
  10986. pad,
  10987. format;
  10988. if (!(date instanceof Date)) date = new Date(+date);
  10989. while (++i < n) {
  10990. if (specifier.charCodeAt(i) === 37) {
  10991. string.push(specifier.slice(j, i));
  10992. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  10993. else pad = c === "e" ? " " : "0";
  10994. if (format = formats[c]) c = format(date, pad);
  10995. string.push(c);
  10996. j = i + 1;
  10997. }
  10998. }
  10999. string.push(specifier.slice(j, i));
  11000. return string.join("");
  11001. };
  11002. }
  11003. function newParse(specifier, newDate) {
  11004. return function(string) {
  11005. var d = newYear(1900),
  11006. i = parseSpecifier(d, specifier, string += "", 0),
  11007. week, day$$1;
  11008. if (i != string.length) return null;
  11009. // If a UNIX timestamp is specified, return it.
  11010. if ("Q" in d) return new Date(d.Q);
  11011. // The am-pm flag is 0 for AM, and 1 for PM.
  11012. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  11013. // Convert day-of-week and week-of-year to day-of-year.
  11014. if ("V" in d) {
  11015. if (d.V < 1 || d.V > 53) return null;
  11016. if (!("w" in d)) d.w = 1;
  11017. if ("Z" in d) {
  11018. week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
  11019. week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  11020. week = utcDay.offset(week, (d.V - 1) * 7);
  11021. d.y = week.getUTCFullYear();
  11022. d.m = week.getUTCMonth();
  11023. d.d = week.getUTCDate() + (d.w + 6) % 7;
  11024. } else {
  11025. week = newDate(newYear(d.y)), day$$1 = week.getDay();
  11026. week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
  11027. week = day.offset(week, (d.V - 1) * 7);
  11028. d.y = week.getFullYear();
  11029. d.m = week.getMonth();
  11030. d.d = week.getDate() + (d.w + 6) % 7;
  11031. }
  11032. } else if ("W" in d || "U" in d) {
  11033. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  11034. day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  11035. d.m = 0;
  11036. 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;
  11037. }
  11038. // If a time zone is specified, all fields are interpreted as UTC and then
  11039. // offset according to the specified time zone.
  11040. if ("Z" in d) {
  11041. d.H += d.Z / 100 | 0;
  11042. d.M += d.Z % 100;
  11043. return utcDate(d);
  11044. }
  11045. // Otherwise, all fields are in local time.
  11046. return newDate(d);
  11047. };
  11048. }
  11049. function parseSpecifier(d, specifier, string, j) {
  11050. var i = 0,
  11051. n = specifier.length,
  11052. m = string.length,
  11053. c,
  11054. parse;
  11055. while (i < n) {
  11056. if (j >= m) return -1;
  11057. c = specifier.charCodeAt(i++);
  11058. if (c === 37) {
  11059. c = specifier.charAt(i++);
  11060. parse = parses[c in pads ? specifier.charAt(i++) : c];
  11061. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  11062. } else if (c != string.charCodeAt(j++)) {
  11063. return -1;
  11064. }
  11065. }
  11066. return j;
  11067. }
  11068. function parsePeriod(d, string, i) {
  11069. var n = periodRe.exec(string.slice(i));
  11070. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11071. }
  11072. function parseShortWeekday(d, string, i) {
  11073. var n = shortWeekdayRe.exec(string.slice(i));
  11074. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11075. }
  11076. function parseWeekday(d, string, i) {
  11077. var n = weekdayRe.exec(string.slice(i));
  11078. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11079. }
  11080. function parseShortMonth(d, string, i) {
  11081. var n = shortMonthRe.exec(string.slice(i));
  11082. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11083. }
  11084. function parseMonth(d, string, i) {
  11085. var n = monthRe.exec(string.slice(i));
  11086. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11087. }
  11088. function parseLocaleDateTime(d, string, i) {
  11089. return parseSpecifier(d, locale_dateTime, string, i);
  11090. }
  11091. function parseLocaleDate(d, string, i) {
  11092. return parseSpecifier(d, locale_date, string, i);
  11093. }
  11094. function parseLocaleTime(d, string, i) {
  11095. return parseSpecifier(d, locale_time, string, i);
  11096. }
  11097. function formatShortWeekday(d) {
  11098. return locale_shortWeekdays[d.getDay()];
  11099. }
  11100. function formatWeekday(d) {
  11101. return locale_weekdays[d.getDay()];
  11102. }
  11103. function formatShortMonth(d) {
  11104. return locale_shortMonths[d.getMonth()];
  11105. }
  11106. function formatMonth(d) {
  11107. return locale_months[d.getMonth()];
  11108. }
  11109. function formatPeriod(d) {
  11110. return locale_periods[+(d.getHours() >= 12)];
  11111. }
  11112. function formatUTCShortWeekday(d) {
  11113. return locale_shortWeekdays[d.getUTCDay()];
  11114. }
  11115. function formatUTCWeekday(d) {
  11116. return locale_weekdays[d.getUTCDay()];
  11117. }
  11118. function formatUTCShortMonth(d) {
  11119. return locale_shortMonths[d.getUTCMonth()];
  11120. }
  11121. function formatUTCMonth(d) {
  11122. return locale_months[d.getUTCMonth()];
  11123. }
  11124. function formatUTCPeriod(d) {
  11125. return locale_periods[+(d.getUTCHours() >= 12)];
  11126. }
  11127. return {
  11128. format: function(specifier) {
  11129. var f = newFormat(specifier += "", formats);
  11130. f.toString = function() { return specifier; };
  11131. return f;
  11132. },
  11133. parse: function(specifier) {
  11134. var p = newParse(specifier += "", localDate);
  11135. p.toString = function() { return specifier; };
  11136. return p;
  11137. },
  11138. utcFormat: function(specifier) {
  11139. var f = newFormat(specifier += "", utcFormats);
  11140. f.toString = function() { return specifier; };
  11141. return f;
  11142. },
  11143. utcParse: function(specifier) {
  11144. var p = newParse(specifier, utcDate);
  11145. p.toString = function() { return specifier; };
  11146. return p;
  11147. }
  11148. };
  11149. }
  11150. var pads = {"-": "", "_": " ", "0": "0"},
  11151. numberRe = /^\s*\d+/, // note: ignores next directive
  11152. percentRe = /^%/,
  11153. requoteRe = /[\\^$*+?|[\]().{}]/g;
  11154. function pad(value, fill, width) {
  11155. var sign = value < 0 ? "-" : "",
  11156. string = (sign ? -value : value) + "",
  11157. length = string.length;
  11158. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  11159. }
  11160. function requote(s) {
  11161. return s.replace(requoteRe, "\\$&");
  11162. }
  11163. function formatRe(names) {
  11164. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  11165. }
  11166. function formatLookup(names) {
  11167. var map = {}, i = -1, n = names.length;
  11168. while (++i < n) map[names[i].toLowerCase()] = i;
  11169. return map;
  11170. }
  11171. function parseWeekdayNumberSunday(d, string, i) {
  11172. var n = numberRe.exec(string.slice(i, i + 1));
  11173. return n ? (d.w = +n[0], i + n[0].length) : -1;
  11174. }
  11175. function parseWeekdayNumberMonday(d, string, i) {
  11176. var n = numberRe.exec(string.slice(i, i + 1));
  11177. return n ? (d.u = +n[0], i + n[0].length) : -1;
  11178. }
  11179. function parseWeekNumberSunday(d, string, i) {
  11180. var n = numberRe.exec(string.slice(i, i + 2));
  11181. return n ? (d.U = +n[0], i + n[0].length) : -1;
  11182. }
  11183. function parseWeekNumberISO(d, string, i) {
  11184. var n = numberRe.exec(string.slice(i, i + 2));
  11185. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11186. }
  11187. function parseWeekNumberMonday(d, string, i) {
  11188. var n = numberRe.exec(string.slice(i, i + 2));
  11189. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11190. }
  11191. function parseFullYear(d, string, i) {
  11192. var n = numberRe.exec(string.slice(i, i + 4));
  11193. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11194. }
  11195. function parseYear(d, string, i) {
  11196. var n = numberRe.exec(string.slice(i, i + 2));
  11197. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11198. }
  11199. function parseZone(d, string, i) {
  11200. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11201. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11202. }
  11203. function parseMonthNumber(d, string, i) {
  11204. var n = numberRe.exec(string.slice(i, i + 2));
  11205. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11206. }
  11207. function parseDayOfMonth(d, string, i) {
  11208. var n = numberRe.exec(string.slice(i, i + 2));
  11209. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11210. }
  11211. function parseDayOfYear(d, string, i) {
  11212. var n = numberRe.exec(string.slice(i, i + 3));
  11213. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11214. }
  11215. function parseHour24(d, string, i) {
  11216. var n = numberRe.exec(string.slice(i, i + 2));
  11217. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11218. }
  11219. function parseMinutes(d, string, i) {
  11220. var n = numberRe.exec(string.slice(i, i + 2));
  11221. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11222. }
  11223. function parseSeconds(d, string, i) {
  11224. var n = numberRe.exec(string.slice(i, i + 2));
  11225. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11226. }
  11227. function parseMilliseconds(d, string, i) {
  11228. var n = numberRe.exec(string.slice(i, i + 3));
  11229. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11230. }
  11231. function parseMicroseconds(d, string, i) {
  11232. var n = numberRe.exec(string.slice(i, i + 6));
  11233. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11234. }
  11235. function parseLiteralPercent(d, string, i) {
  11236. var n = percentRe.exec(string.slice(i, i + 1));
  11237. return n ? i + n[0].length : -1;
  11238. }
  11239. function parseUnixTimestamp(d, string, i) {
  11240. var n = numberRe.exec(string.slice(i));
  11241. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11242. }
  11243. function parseUnixTimestampSeconds(d, string, i) {
  11244. var n = numberRe.exec(string.slice(i));
  11245. return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
  11246. }
  11247. function formatDayOfMonth(d, p) {
  11248. return pad(d.getDate(), p, 2);
  11249. }
  11250. function formatHour24(d, p) {
  11251. return pad(d.getHours(), p, 2);
  11252. }
  11253. function formatHour12(d, p) {
  11254. return pad(d.getHours() % 12 || 12, p, 2);
  11255. }
  11256. function formatDayOfYear(d, p) {
  11257. return pad(1 + day.count(year(d), d), p, 3);
  11258. }
  11259. function formatMilliseconds(d, p) {
  11260. return pad(d.getMilliseconds(), p, 3);
  11261. }
  11262. function formatMicroseconds(d, p) {
  11263. return formatMilliseconds(d, p) + "000";
  11264. }
  11265. function formatMonthNumber(d, p) {
  11266. return pad(d.getMonth() + 1, p, 2);
  11267. }
  11268. function formatMinutes(d, p) {
  11269. return pad(d.getMinutes(), p, 2);
  11270. }
  11271. function formatSeconds(d, p) {
  11272. return pad(d.getSeconds(), p, 2);
  11273. }
  11274. function formatWeekdayNumberMonday(d) {
  11275. var day$$1 = d.getDay();
  11276. return day$$1 === 0 ? 7 : day$$1;
  11277. }
  11278. function formatWeekNumberSunday(d, p) {
  11279. return pad(sunday.count(year(d), d), p, 2);
  11280. }
  11281. function formatWeekNumberISO(d, p) {
  11282. var day$$1 = d.getDay();
  11283. d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
  11284. return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11285. }
  11286. function formatWeekdayNumberSunday(d) {
  11287. return d.getDay();
  11288. }
  11289. function formatWeekNumberMonday(d, p) {
  11290. return pad(monday.count(year(d), d), p, 2);
  11291. }
  11292. function formatYear(d, p) {
  11293. return pad(d.getFullYear() % 100, p, 2);
  11294. }
  11295. function formatFullYear(d, p) {
  11296. return pad(d.getFullYear() % 10000, p, 4);
  11297. }
  11298. function formatZone(d) {
  11299. var z = d.getTimezoneOffset();
  11300. return (z > 0 ? "-" : (z *= -1, "+"))
  11301. + pad(z / 60 | 0, "0", 2)
  11302. + pad(z % 60, "0", 2);
  11303. }
  11304. function formatUTCDayOfMonth(d, p) {
  11305. return pad(d.getUTCDate(), p, 2);
  11306. }
  11307. function formatUTCHour24(d, p) {
  11308. return pad(d.getUTCHours(), p, 2);
  11309. }
  11310. function formatUTCHour12(d, p) {
  11311. return pad(d.getUTCHours() % 12 || 12, p, 2);
  11312. }
  11313. function formatUTCDayOfYear(d, p) {
  11314. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  11315. }
  11316. function formatUTCMilliseconds(d, p) {
  11317. return pad(d.getUTCMilliseconds(), p, 3);
  11318. }
  11319. function formatUTCMicroseconds(d, p) {
  11320. return formatUTCMilliseconds(d, p) + "000";
  11321. }
  11322. function formatUTCMonthNumber(d, p) {
  11323. return pad(d.getUTCMonth() + 1, p, 2);
  11324. }
  11325. function formatUTCMinutes(d, p) {
  11326. return pad(d.getUTCMinutes(), p, 2);
  11327. }
  11328. function formatUTCSeconds(d, p) {
  11329. return pad(d.getUTCSeconds(), p, 2);
  11330. }
  11331. function formatUTCWeekdayNumberMonday(d) {
  11332. var dow = d.getUTCDay();
  11333. return dow === 0 ? 7 : dow;
  11334. }
  11335. function formatUTCWeekNumberSunday(d, p) {
  11336. return pad(utcSunday.count(utcYear(d), d), p, 2);
  11337. }
  11338. function formatUTCWeekNumberISO(d, p) {
  11339. var day$$1 = d.getUTCDay();
  11340. d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11341. return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11342. }
  11343. function formatUTCWeekdayNumberSunday(d) {
  11344. return d.getUTCDay();
  11345. }
  11346. function formatUTCWeekNumberMonday(d, p) {
  11347. return pad(utcMonday.count(utcYear(d), d), p, 2);
  11348. }
  11349. function formatUTCYear(d, p) {
  11350. return pad(d.getUTCFullYear() % 100, p, 2);
  11351. }
  11352. function formatUTCFullYear(d, p) {
  11353. return pad(d.getUTCFullYear() % 10000, p, 4);
  11354. }
  11355. function formatUTCZone() {
  11356. return "+0000";
  11357. }
  11358. function formatLiteralPercent() {
  11359. return "%";
  11360. }
  11361. function formatUnixTimestamp(d) {
  11362. return +d;
  11363. }
  11364. function formatUnixTimestampSeconds(d) {
  11365. return Math.floor(+d / 1000);
  11366. }
  11367. var locale$1;
  11368. defaultLocale$1({
  11369. dateTime: "%x, %X",
  11370. date: "%-m/%-d/%Y",
  11371. time: "%-I:%M:%S %p",
  11372. periods: ["AM", "PM"],
  11373. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11374. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11375. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11376. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11377. });
  11378. function defaultLocale$1(definition) {
  11379. locale$1 = formatLocale$1(definition);
  11380. exports.timeFormat = locale$1.format;
  11381. exports.timeParse = locale$1.parse;
  11382. exports.utcFormat = locale$1.utcFormat;
  11383. exports.utcParse = locale$1.utcParse;
  11384. return locale$1;
  11385. }
  11386. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11387. function formatIsoNative(date) {
  11388. return date.toISOString();
  11389. }
  11390. var formatIso = Date.prototype.toISOString
  11391. ? formatIsoNative
  11392. : exports.utcFormat(isoSpecifier);
  11393. function parseIsoNative(string) {
  11394. var date = new Date(string);
  11395. return isNaN(date) ? null : date;
  11396. }
  11397. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11398. ? parseIsoNative
  11399. : exports.utcParse(isoSpecifier);
  11400. var durationSecond$1 = 1000,
  11401. durationMinute$1 = durationSecond$1 * 60,
  11402. durationHour$1 = durationMinute$1 * 60,
  11403. durationDay$1 = durationHour$1 * 24,
  11404. durationWeek$1 = durationDay$1 * 7,
  11405. durationMonth = durationDay$1 * 30,
  11406. durationYear = durationDay$1 * 365;
  11407. function date$1(t) {
  11408. return new Date(t);
  11409. }
  11410. function number$3(t) {
  11411. return t instanceof Date ? +t : +new Date(+t);
  11412. }
  11413. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  11414. var scale = continuous(deinterpolateLinear, reinterpolate),
  11415. invert = scale.invert,
  11416. domain = scale.domain;
  11417. var formatMillisecond = format(".%L"),
  11418. formatSecond = format(":%S"),
  11419. formatMinute = format("%I:%M"),
  11420. formatHour = format("%I %p"),
  11421. formatDay = format("%a %d"),
  11422. formatWeek = format("%b %d"),
  11423. formatMonth = format("%B"),
  11424. formatYear = format("%Y");
  11425. var tickIntervals = [
  11426. [second$$1, 1, durationSecond$1],
  11427. [second$$1, 5, 5 * durationSecond$1],
  11428. [second$$1, 15, 15 * durationSecond$1],
  11429. [second$$1, 30, 30 * durationSecond$1],
  11430. [minute$$1, 1, durationMinute$1],
  11431. [minute$$1, 5, 5 * durationMinute$1],
  11432. [minute$$1, 15, 15 * durationMinute$1],
  11433. [minute$$1, 30, 30 * durationMinute$1],
  11434. [ hour$$1, 1, durationHour$1 ],
  11435. [ hour$$1, 3, 3 * durationHour$1 ],
  11436. [ hour$$1, 6, 6 * durationHour$1 ],
  11437. [ hour$$1, 12, 12 * durationHour$1 ],
  11438. [ day$$1, 1, durationDay$1 ],
  11439. [ day$$1, 2, 2 * durationDay$1 ],
  11440. [ week, 1, durationWeek$1 ],
  11441. [ month$$1, 1, durationMonth ],
  11442. [ month$$1, 3, 3 * durationMonth ],
  11443. [ year$$1, 1, durationYear ]
  11444. ];
  11445. function tickFormat(date$$1) {
  11446. return (second$$1(date$$1) < date$$1 ? formatMillisecond
  11447. : minute$$1(date$$1) < date$$1 ? formatSecond
  11448. : hour$$1(date$$1) < date$$1 ? formatMinute
  11449. : day$$1(date$$1) < date$$1 ? formatHour
  11450. : month$$1(date$$1) < date$$1 ? (week(date$$1) < date$$1 ? formatDay : formatWeek)
  11451. : year$$1(date$$1) < date$$1 ? formatMonth
  11452. : formatYear)(date$$1);
  11453. }
  11454. function tickInterval(interval, start, stop, step) {
  11455. if (interval == null) interval = 10;
  11456. // If a desired tick count is specified, pick a reasonable tick interval
  11457. // based on the extent of the domain and a rough estimate of tick size.
  11458. // Otherwise, assume interval is already a time interval and use it.
  11459. if (typeof interval === "number") {
  11460. var target = Math.abs(stop - start) / interval,
  11461. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11462. if (i === tickIntervals.length) {
  11463. step = tickStep(start / durationYear, stop / durationYear, interval);
  11464. interval = year$$1;
  11465. } else if (i) {
  11466. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11467. step = i[1];
  11468. interval = i[0];
  11469. } else {
  11470. step = Math.max(tickStep(start, stop, interval), 1);
  11471. interval = millisecond$$1;
  11472. }
  11473. }
  11474. return step == null ? interval : interval.every(step);
  11475. }
  11476. scale.invert = function(y) {
  11477. return new Date(invert(y));
  11478. };
  11479. scale.domain = function(_) {
  11480. return arguments.length ? domain(map$2.call(_, number$3)) : domain().map(date$1);
  11481. };
  11482. scale.ticks = function(interval, step) {
  11483. var d = domain(),
  11484. t0 = d[0],
  11485. t1 = d[d.length - 1],
  11486. r = t1 < t0,
  11487. t;
  11488. if (r) t = t0, t0 = t1, t1 = t;
  11489. t = tickInterval(interval, t0, t1, step);
  11490. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11491. return r ? t.reverse() : t;
  11492. };
  11493. scale.tickFormat = function(count, specifier) {
  11494. return specifier == null ? tickFormat : format(specifier);
  11495. };
  11496. scale.nice = function(interval, step) {
  11497. var d = domain();
  11498. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11499. ? domain(nice(d, interval))
  11500. : scale;
  11501. };
  11502. scale.copy = function() {
  11503. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  11504. };
  11505. return scale;
  11506. }
  11507. function time() {
  11508. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  11509. }
  11510. function utcTime() {
  11511. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  11512. }
  11513. function sequential(interpolator) {
  11514. var x0 = 0,
  11515. x1 = 1,
  11516. k10 = 1,
  11517. clamp = false;
  11518. function scale(x) {
  11519. var t = (x - x0) * k10;
  11520. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11521. }
  11522. scale.domain = function(_) {
  11523. return arguments.length ? (x0 = +_[0], x1 = +_[1], k10 = x0 === x1 ? 0 : 1 / (x1 - x0), scale) : [x0, x1];
  11524. };
  11525. scale.clamp = function(_) {
  11526. return arguments.length ? (clamp = !!_, scale) : clamp;
  11527. };
  11528. scale.interpolator = function(_) {
  11529. return arguments.length ? (interpolator = _, scale) : interpolator;
  11530. };
  11531. scale.copy = function() {
  11532. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  11533. };
  11534. return linearish(scale);
  11535. }
  11536. function diverging(interpolator) {
  11537. var x0 = 0,
  11538. x1 = 0.5,
  11539. x2 = 1,
  11540. k10 = 1,
  11541. k21 = 1,
  11542. clamp = false;
  11543. function scale(x) {
  11544. var t = 0.5 + ((x = +x) - x1) * (x < x1 ? k10 : k21);
  11545. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11546. }
  11547. scale.domain = function(_) {
  11548. 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];
  11549. };
  11550. scale.clamp = function(_) {
  11551. return arguments.length ? (clamp = !!_, scale) : clamp;
  11552. };
  11553. scale.interpolator = function(_) {
  11554. return arguments.length ? (interpolator = _, scale) : interpolator;
  11555. };
  11556. scale.copy = function() {
  11557. return diverging(interpolator).domain([x0, x1, x2]).clamp(clamp);
  11558. };
  11559. return linearish(scale);
  11560. }
  11561. function colors(specifier) {
  11562. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  11563. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  11564. return colors;
  11565. }
  11566. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11567. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  11568. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  11569. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  11570. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  11571. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  11572. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  11573. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  11574. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  11575. function ramp(scheme) {
  11576. return rgbBasis(scheme[scheme.length - 1]);
  11577. }
  11578. var scheme = new Array(3).concat(
  11579. "d8b365f5f5f55ab4ac",
  11580. "a6611adfc27d80cdc1018571",
  11581. "a6611adfc27df5f5f580cdc1018571",
  11582. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  11583. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  11584. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  11585. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  11586. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  11587. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  11588. ).map(colors);
  11589. var BrBG = ramp(scheme);
  11590. var scheme$1 = new Array(3).concat(
  11591. "af8dc3f7f7f77fbf7b",
  11592. "7b3294c2a5cfa6dba0008837",
  11593. "7b3294c2a5cff7f7f7a6dba0008837",
  11594. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  11595. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  11596. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  11597. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  11598. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  11599. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  11600. ).map(colors);
  11601. var PRGn = ramp(scheme$1);
  11602. var scheme$2 = new Array(3).concat(
  11603. "e9a3c9f7f7f7a1d76a",
  11604. "d01c8bf1b6dab8e1864dac26",
  11605. "d01c8bf1b6daf7f7f7b8e1864dac26",
  11606. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  11607. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  11608. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  11609. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  11610. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  11611. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  11612. ).map(colors);
  11613. var PiYG = ramp(scheme$2);
  11614. var scheme$3 = new Array(3).concat(
  11615. "998ec3f7f7f7f1a340",
  11616. "5e3c99b2abd2fdb863e66101",
  11617. "5e3c99b2abd2f7f7f7fdb863e66101",
  11618. "542788998ec3d8daebfee0b6f1a340b35806",
  11619. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  11620. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  11621. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  11622. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  11623. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  11624. ).map(colors);
  11625. var PuOr = ramp(scheme$3);
  11626. var scheme$4 = new Array(3).concat(
  11627. "ef8a62f7f7f767a9cf",
  11628. "ca0020f4a58292c5de0571b0",
  11629. "ca0020f4a582f7f7f792c5de0571b0",
  11630. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  11631. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  11632. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  11633. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  11634. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  11635. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  11636. ).map(colors);
  11637. var RdBu = ramp(scheme$4);
  11638. var scheme$5 = new Array(3).concat(
  11639. "ef8a62ffffff999999",
  11640. "ca0020f4a582bababa404040",
  11641. "ca0020f4a582ffffffbababa404040",
  11642. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  11643. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  11644. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  11645. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  11646. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  11647. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  11648. ).map(colors);
  11649. var RdGy = ramp(scheme$5);
  11650. var scheme$6 = new Array(3).concat(
  11651. "fc8d59ffffbf91bfdb",
  11652. "d7191cfdae61abd9e92c7bb6",
  11653. "d7191cfdae61ffffbfabd9e92c7bb6",
  11654. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  11655. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  11656. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  11657. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  11658. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  11659. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  11660. ).map(colors);
  11661. var RdYlBu = ramp(scheme$6);
  11662. var scheme$7 = new Array(3).concat(
  11663. "fc8d59ffffbf91cf60",
  11664. "d7191cfdae61a6d96a1a9641",
  11665. "d7191cfdae61ffffbfa6d96a1a9641",
  11666. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  11667. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  11668. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  11669. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  11670. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  11671. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  11672. ).map(colors);
  11673. var RdYlGn = ramp(scheme$7);
  11674. var scheme$8 = new Array(3).concat(
  11675. "fc8d59ffffbf99d594",
  11676. "d7191cfdae61abdda42b83ba",
  11677. "d7191cfdae61ffffbfabdda42b83ba",
  11678. "d53e4ffc8d59fee08be6f59899d5943288bd",
  11679. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  11680. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  11681. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  11682. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  11683. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  11684. ).map(colors);
  11685. var Spectral = ramp(scheme$8);
  11686. var scheme$9 = new Array(3).concat(
  11687. "e5f5f999d8c92ca25f",
  11688. "edf8fbb2e2e266c2a4238b45",
  11689. "edf8fbb2e2e266c2a42ca25f006d2c",
  11690. "edf8fbccece699d8c966c2a42ca25f006d2c",
  11691. "edf8fbccece699d8c966c2a441ae76238b45005824",
  11692. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  11693. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  11694. ).map(colors);
  11695. var BuGn = ramp(scheme$9);
  11696. var scheme$10 = new Array(3).concat(
  11697. "e0ecf49ebcda8856a7",
  11698. "edf8fbb3cde38c96c688419d",
  11699. "edf8fbb3cde38c96c68856a7810f7c",
  11700. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  11701. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  11702. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  11703. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  11704. ).map(colors);
  11705. var BuPu = ramp(scheme$10);
  11706. var scheme$11 = new Array(3).concat(
  11707. "e0f3dba8ddb543a2ca",
  11708. "f0f9e8bae4bc7bccc42b8cbe",
  11709. "f0f9e8bae4bc7bccc443a2ca0868ac",
  11710. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  11711. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11712. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11713. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  11714. ).map(colors);
  11715. var GnBu = ramp(scheme$11);
  11716. var scheme$12 = new Array(3).concat(
  11717. "fee8c8fdbb84e34a33",
  11718. "fef0d9fdcc8afc8d59d7301f",
  11719. "fef0d9fdcc8afc8d59e34a33b30000",
  11720. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  11721. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  11722. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  11723. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  11724. ).map(colors);
  11725. var OrRd = ramp(scheme$12);
  11726. var scheme$13 = new Array(3).concat(
  11727. "ece2f0a6bddb1c9099",
  11728. "f6eff7bdc9e167a9cf02818a",
  11729. "f6eff7bdc9e167a9cf1c9099016c59",
  11730. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  11731. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  11732. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  11733. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  11734. ).map(colors);
  11735. var PuBuGn = ramp(scheme$13);
  11736. var scheme$14 = new Array(3).concat(
  11737. "ece7f2a6bddb2b8cbe",
  11738. "f1eef6bdc9e174a9cf0570b0",
  11739. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  11740. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  11741. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11742. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11743. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  11744. ).map(colors);
  11745. var PuBu = ramp(scheme$14);
  11746. var scheme$15 = new Array(3).concat(
  11747. "e7e1efc994c7dd1c77",
  11748. "f1eef6d7b5d8df65b0ce1256",
  11749. "f1eef6d7b5d8df65b0dd1c77980043",
  11750. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  11751. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  11752. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  11753. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  11754. ).map(colors);
  11755. var PuRd = ramp(scheme$15);
  11756. var scheme$16 = new Array(3).concat(
  11757. "fde0ddfa9fb5c51b8a",
  11758. "feebe2fbb4b9f768a1ae017e",
  11759. "feebe2fbb4b9f768a1c51b8a7a0177",
  11760. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  11761. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11762. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11763. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  11764. ).map(colors);
  11765. var RdPu = ramp(scheme$16);
  11766. var scheme$17 = new Array(3).concat(
  11767. "edf8b17fcdbb2c7fb8",
  11768. "ffffcca1dab441b6c4225ea8",
  11769. "ffffcca1dab441b6c42c7fb8253494",
  11770. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  11771. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11772. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11773. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  11774. ).map(colors);
  11775. var YlGnBu = ramp(scheme$17);
  11776. var scheme$18 = new Array(3).concat(
  11777. "f7fcb9addd8e31a354",
  11778. "ffffccc2e69978c679238443",
  11779. "ffffccc2e69978c67931a354006837",
  11780. "ffffccd9f0a3addd8e78c67931a354006837",
  11781. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  11782. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  11783. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  11784. ).map(colors);
  11785. var YlGn = ramp(scheme$18);
  11786. var scheme$19 = new Array(3).concat(
  11787. "fff7bcfec44fd95f0e",
  11788. "ffffd4fed98efe9929cc4c02",
  11789. "ffffd4fed98efe9929d95f0e993404",
  11790. "ffffd4fee391fec44ffe9929d95f0e993404",
  11791. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  11792. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  11793. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  11794. ).map(colors);
  11795. var YlOrBr = ramp(scheme$19);
  11796. var scheme$20 = new Array(3).concat(
  11797. "ffeda0feb24cf03b20",
  11798. "ffffb2fecc5cfd8d3ce31a1c",
  11799. "ffffb2fecc5cfd8d3cf03b20bd0026",
  11800. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  11801. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11802. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11803. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  11804. ).map(colors);
  11805. var YlOrRd = ramp(scheme$20);
  11806. var scheme$21 = new Array(3).concat(
  11807. "deebf79ecae13182bd",
  11808. "eff3ffbdd7e76baed62171b5",
  11809. "eff3ffbdd7e76baed63182bd08519c",
  11810. "eff3ffc6dbef9ecae16baed63182bd08519c",
  11811. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  11812. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  11813. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  11814. ).map(colors);
  11815. var Blues = ramp(scheme$21);
  11816. var scheme$22 = new Array(3).concat(
  11817. "e5f5e0a1d99b31a354",
  11818. "edf8e9bae4b374c476238b45",
  11819. "edf8e9bae4b374c47631a354006d2c",
  11820. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  11821. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  11822. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  11823. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  11824. ).map(colors);
  11825. var Greens = ramp(scheme$22);
  11826. var scheme$23 = new Array(3).concat(
  11827. "f0f0f0bdbdbd636363",
  11828. "f7f7f7cccccc969696525252",
  11829. "f7f7f7cccccc969696636363252525",
  11830. "f7f7f7d9d9d9bdbdbd969696636363252525",
  11831. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  11832. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  11833. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  11834. ).map(colors);
  11835. var Greys = ramp(scheme$23);
  11836. var scheme$24 = new Array(3).concat(
  11837. "efedf5bcbddc756bb1",
  11838. "f2f0f7cbc9e29e9ac86a51a3",
  11839. "f2f0f7cbc9e29e9ac8756bb154278f",
  11840. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  11841. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11842. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11843. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  11844. ).map(colors);
  11845. var Purples = ramp(scheme$24);
  11846. var scheme$25 = new Array(3).concat(
  11847. "fee0d2fc9272de2d26",
  11848. "fee5d9fcae91fb6a4acb181d",
  11849. "fee5d9fcae91fb6a4ade2d26a50f15",
  11850. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  11851. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11852. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11853. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  11854. ).map(colors);
  11855. var Reds = ramp(scheme$25);
  11856. var scheme$26 = new Array(3).concat(
  11857. "fee6cefdae6be6550d",
  11858. "feeddefdbe85fd8d3cd94701",
  11859. "feeddefdbe85fd8d3ce6550da63603",
  11860. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  11861. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11862. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11863. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  11864. ).map(colors);
  11865. var Oranges = ramp(scheme$26);
  11866. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  11867. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11868. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11869. var c = cubehelix();
  11870. function rainbow(t) {
  11871. if (t < 0 || t > 1) t -= Math.floor(t);
  11872. var ts = Math.abs(t - 0.5);
  11873. c.h = 360 * t - 100;
  11874. c.s = 1.5 - 1.5 * ts;
  11875. c.l = 0.8 - 0.9 * ts;
  11876. return c + "";
  11877. }
  11878. var c$1 = rgb(),
  11879. pi_1_3 = Math.PI / 3,
  11880. pi_2_3 = Math.PI * 2 / 3;
  11881. function sinebow(t) {
  11882. var x;
  11883. t = (0.5 - t) * Math.PI;
  11884. c$1.r = 255 * (x = Math.sin(t)) * x;
  11885. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  11886. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  11887. return c$1 + "";
  11888. }
  11889. function ramp$1(range) {
  11890. var n = range.length;
  11891. return function(t) {
  11892. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  11893. };
  11894. }
  11895. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  11896. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  11897. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  11898. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  11899. function constant$11(x) {
  11900. return function constant() {
  11901. return x;
  11902. };
  11903. }
  11904. var abs$1 = Math.abs;
  11905. var atan2$1 = Math.atan2;
  11906. var cos$2 = Math.cos;
  11907. var max$2 = Math.max;
  11908. var min$1 = Math.min;
  11909. var sin$2 = Math.sin;
  11910. var sqrt$2 = Math.sqrt;
  11911. var epsilon$3 = 1e-12;
  11912. var pi$4 = Math.PI;
  11913. var halfPi$3 = pi$4 / 2;
  11914. var tau$4 = 2 * pi$4;
  11915. function acos$1(x) {
  11916. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11917. }
  11918. function asin$1(x) {
  11919. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  11920. }
  11921. function arcInnerRadius(d) {
  11922. return d.innerRadius;
  11923. }
  11924. function arcOuterRadius(d) {
  11925. return d.outerRadius;
  11926. }
  11927. function arcStartAngle(d) {
  11928. return d.startAngle;
  11929. }
  11930. function arcEndAngle(d) {
  11931. return d.endAngle;
  11932. }
  11933. function arcPadAngle(d) {
  11934. return d && d.padAngle; // Note: optional!
  11935. }
  11936. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11937. var x10 = x1 - x0, y10 = y1 - y0,
  11938. x32 = x3 - x2, y32 = y3 - y2,
  11939. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  11940. return [x0 + t * x10, y0 + t * y10];
  11941. }
  11942. // Compute perpendicular offset line of length rc.
  11943. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  11944. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  11945. var x01 = x0 - x1,
  11946. y01 = y0 - y1,
  11947. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  11948. ox = lo * y01,
  11949. oy = -lo * x01,
  11950. x11 = x0 + ox,
  11951. y11 = y0 + oy,
  11952. x10 = x1 + ox,
  11953. y10 = y1 + oy,
  11954. x00 = (x11 + x10) / 2,
  11955. y00 = (y11 + y10) / 2,
  11956. dx = x10 - x11,
  11957. dy = y10 - y11,
  11958. d2 = dx * dx + dy * dy,
  11959. r = r1 - rc,
  11960. D = x11 * y10 - x10 * y11,
  11961. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  11962. cx0 = (D * dy - dx * d) / d2,
  11963. cy0 = (-D * dx - dy * d) / d2,
  11964. cx1 = (D * dy + dx * d) / d2,
  11965. cy1 = (-D * dx + dy * d) / d2,
  11966. dx0 = cx0 - x00,
  11967. dy0 = cy0 - y00,
  11968. dx1 = cx1 - x00,
  11969. dy1 = cy1 - y00;
  11970. // Pick the closer of the two intersection points.
  11971. // TODO Is there a faster way to determine which intersection to use?
  11972. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  11973. return {
  11974. cx: cx0,
  11975. cy: cy0,
  11976. x01: -ox,
  11977. y01: -oy,
  11978. x11: cx0 * (r1 / r - 1),
  11979. y11: cy0 * (r1 / r - 1)
  11980. };
  11981. }
  11982. function arc() {
  11983. var innerRadius = arcInnerRadius,
  11984. outerRadius = arcOuterRadius,
  11985. cornerRadius = constant$11(0),
  11986. padRadius = null,
  11987. startAngle = arcStartAngle,
  11988. endAngle = arcEndAngle,
  11989. padAngle = arcPadAngle,
  11990. context = null;
  11991. function arc() {
  11992. var buffer,
  11993. r,
  11994. r0 = +innerRadius.apply(this, arguments),
  11995. r1 = +outerRadius.apply(this, arguments),
  11996. a0 = startAngle.apply(this, arguments) - halfPi$3,
  11997. a1 = endAngle.apply(this, arguments) - halfPi$3,
  11998. da = abs$1(a1 - a0),
  11999. cw = a1 > a0;
  12000. if (!context) context = buffer = path();
  12001. // Ensure that the outer radius is always larger than the inner radius.
  12002. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  12003. // Is it a point?
  12004. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  12005. // Or is it a circle or annulus?
  12006. else if (da > tau$4 - epsilon$3) {
  12007. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  12008. context.arc(0, 0, r1, a0, a1, !cw);
  12009. if (r0 > epsilon$3) {
  12010. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  12011. context.arc(0, 0, r0, a1, a0, cw);
  12012. }
  12013. }
  12014. // Or is it a circular or annular sector?
  12015. else {
  12016. var a01 = a0,
  12017. a11 = a1,
  12018. a00 = a0,
  12019. a10 = a1,
  12020. da0 = da,
  12021. da1 = da,
  12022. ap = padAngle.apply(this, arguments) / 2,
  12023. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  12024. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  12025. rc0 = rc,
  12026. rc1 = rc,
  12027. t0,
  12028. t1;
  12029. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  12030. if (rp > epsilon$3) {
  12031. var p0 = asin$1(rp / r0 * sin$2(ap)),
  12032. p1 = asin$1(rp / r1 * sin$2(ap));
  12033. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  12034. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  12035. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  12036. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  12037. }
  12038. var x01 = r1 * cos$2(a01),
  12039. y01 = r1 * sin$2(a01),
  12040. x10 = r0 * cos$2(a10),
  12041. y10 = r0 * sin$2(a10);
  12042. // Apply rounded corners?
  12043. if (rc > epsilon$3) {
  12044. var x11 = r1 * cos$2(a11),
  12045. y11 = r1 * sin$2(a11),
  12046. x00 = r0 * cos$2(a00),
  12047. y00 = r0 * sin$2(a00);
  12048. // Restrict the corner radius according to the sector angle.
  12049. if (da < pi$4) {
  12050. var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  12051. ax = x01 - oc[0],
  12052. ay = y01 - oc[1],
  12053. bx = x11 - oc[0],
  12054. by = y11 - oc[1],
  12055. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  12056. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  12057. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  12058. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  12059. }
  12060. }
  12061. // Is the sector collapsed to a line?
  12062. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  12063. // Does the sector’s outer ring have rounded corners?
  12064. else if (rc1 > epsilon$3) {
  12065. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  12066. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  12067. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12068. // Have the corners merged?
  12069. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12070. // Otherwise, draw the two corners and the ring.
  12071. else {
  12072. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12073. 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);
  12074. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12075. }
  12076. }
  12077. // Or is the outer ring just a circular arc?
  12078. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  12079. // Is there no inner ring, and it’s a circular sector?
  12080. // Or perhaps it’s an annular sector collapsed due to padding?
  12081. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  12082. // Does the sector’s inner ring (or point) have rounded corners?
  12083. else if (rc0 > epsilon$3) {
  12084. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  12085. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  12086. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12087. // Have the corners merged?
  12088. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12089. // Otherwise, draw the two corners and the ring.
  12090. else {
  12091. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12092. 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);
  12093. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12094. }
  12095. }
  12096. // Or is the inner ring just a circular arc?
  12097. else context.arc(0, 0, r0, a10, a00, cw);
  12098. }
  12099. context.closePath();
  12100. if (buffer) return context = null, buffer + "" || null;
  12101. }
  12102. arc.centroid = function() {
  12103. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  12104. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  12105. return [cos$2(a) * r, sin$2(a) * r];
  12106. };
  12107. arc.innerRadius = function(_) {
  12108. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : innerRadius;
  12109. };
  12110. arc.outerRadius = function(_) {
  12111. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : outerRadius;
  12112. };
  12113. arc.cornerRadius = function(_) {
  12114. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : cornerRadius;
  12115. };
  12116. arc.padRadius = function(_) {
  12117. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), arc) : padRadius;
  12118. };
  12119. arc.startAngle = function(_) {
  12120. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : startAngle;
  12121. };
  12122. arc.endAngle = function(_) {
  12123. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : endAngle;
  12124. };
  12125. arc.padAngle = function(_) {
  12126. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : padAngle;
  12127. };
  12128. arc.context = function(_) {
  12129. return arguments.length ? (context = _ == null ? null : _, arc) : context;
  12130. };
  12131. return arc;
  12132. }
  12133. function Linear(context) {
  12134. this._context = context;
  12135. }
  12136. Linear.prototype = {
  12137. areaStart: function() {
  12138. this._line = 0;
  12139. },
  12140. areaEnd: function() {
  12141. this._line = NaN;
  12142. },
  12143. lineStart: function() {
  12144. this._point = 0;
  12145. },
  12146. lineEnd: function() {
  12147. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12148. this._line = 1 - this._line;
  12149. },
  12150. point: function(x, y) {
  12151. x = +x, y = +y;
  12152. switch (this._point) {
  12153. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12154. case 1: this._point = 2; // proceed
  12155. default: this._context.lineTo(x, y); break;
  12156. }
  12157. }
  12158. };
  12159. function curveLinear(context) {
  12160. return new Linear(context);
  12161. }
  12162. function x$3(p) {
  12163. return p[0];
  12164. }
  12165. function y$3(p) {
  12166. return p[1];
  12167. }
  12168. function line() {
  12169. var x$$1 = x$3,
  12170. y$$1 = y$3,
  12171. defined = constant$11(true),
  12172. context = null,
  12173. curve = curveLinear,
  12174. output = null;
  12175. function line(data) {
  12176. var i,
  12177. n = data.length,
  12178. d,
  12179. defined0 = false,
  12180. buffer;
  12181. if (context == null) output = curve(buffer = path());
  12182. for (i = 0; i <= n; ++i) {
  12183. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12184. if (defined0 = !defined0) output.lineStart();
  12185. else output.lineEnd();
  12186. }
  12187. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  12188. }
  12189. if (buffer) return output = null, buffer + "" || null;
  12190. }
  12191. line.x = function(_) {
  12192. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : x$$1;
  12193. };
  12194. line.y = function(_) {
  12195. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : y$$1;
  12196. };
  12197. line.defined = function(_) {
  12198. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), line) : defined;
  12199. };
  12200. line.curve = function(_) {
  12201. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  12202. };
  12203. line.context = function(_) {
  12204. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  12205. };
  12206. return line;
  12207. }
  12208. function area$3() {
  12209. var x0 = x$3,
  12210. x1 = null,
  12211. y0 = constant$11(0),
  12212. y1 = y$3,
  12213. defined = constant$11(true),
  12214. context = null,
  12215. curve = curveLinear,
  12216. output = null;
  12217. function area(data) {
  12218. var i,
  12219. j,
  12220. k,
  12221. n = data.length,
  12222. d,
  12223. defined0 = false,
  12224. buffer,
  12225. x0z = new Array(n),
  12226. y0z = new Array(n);
  12227. if (context == null) output = curve(buffer = path());
  12228. for (i = 0; i <= n; ++i) {
  12229. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12230. if (defined0 = !defined0) {
  12231. j = i;
  12232. output.areaStart();
  12233. output.lineStart();
  12234. } else {
  12235. output.lineEnd();
  12236. output.lineStart();
  12237. for (k = i - 1; k >= j; --k) {
  12238. output.point(x0z[k], y0z[k]);
  12239. }
  12240. output.lineEnd();
  12241. output.areaEnd();
  12242. }
  12243. }
  12244. if (defined0) {
  12245. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  12246. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  12247. }
  12248. }
  12249. if (buffer) return output = null, buffer + "" || null;
  12250. }
  12251. function arealine() {
  12252. return line().defined(defined).curve(curve).context(context);
  12253. }
  12254. area.x = function(_) {
  12255. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), x1 = null, area) : x0;
  12256. };
  12257. area.x0 = function(_) {
  12258. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), area) : x0;
  12259. };
  12260. area.x1 = function(_) {
  12261. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : x1;
  12262. };
  12263. area.y = function(_) {
  12264. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), y1 = null, area) : y0;
  12265. };
  12266. area.y0 = function(_) {
  12267. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), area) : y0;
  12268. };
  12269. area.y1 = function(_) {
  12270. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : y1;
  12271. };
  12272. area.lineX0 =
  12273. area.lineY0 = function() {
  12274. return arealine().x(x0).y(y0);
  12275. };
  12276. area.lineY1 = function() {
  12277. return arealine().x(x0).y(y1);
  12278. };
  12279. area.lineX1 = function() {
  12280. return arealine().x(x1).y(y0);
  12281. };
  12282. area.defined = function(_) {
  12283. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), area) : defined;
  12284. };
  12285. area.curve = function(_) {
  12286. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  12287. };
  12288. area.context = function(_) {
  12289. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  12290. };
  12291. return area;
  12292. }
  12293. function descending$1(a, b) {
  12294. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  12295. }
  12296. function identity$7(d) {
  12297. return d;
  12298. }
  12299. function pie() {
  12300. var value = identity$7,
  12301. sortValues = descending$1,
  12302. sort = null,
  12303. startAngle = constant$11(0),
  12304. endAngle = constant$11(tau$4),
  12305. padAngle = constant$11(0);
  12306. function pie(data) {
  12307. var i,
  12308. n = data.length,
  12309. j,
  12310. k,
  12311. sum = 0,
  12312. index = new Array(n),
  12313. arcs = new Array(n),
  12314. a0 = +startAngle.apply(this, arguments),
  12315. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  12316. a1,
  12317. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  12318. pa = p * (da < 0 ? -1 : 1),
  12319. v;
  12320. for (i = 0; i < n; ++i) {
  12321. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  12322. sum += v;
  12323. }
  12324. }
  12325. // Optionally sort the arcs by previously-computed values or by data.
  12326. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  12327. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  12328. // Compute the arcs! They are stored in the original data's order.
  12329. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  12330. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  12331. data: data[j],
  12332. index: i,
  12333. value: v,
  12334. startAngle: a0,
  12335. endAngle: a1,
  12336. padAngle: p
  12337. };
  12338. }
  12339. return arcs;
  12340. }
  12341. pie.value = function(_) {
  12342. return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), pie) : value;
  12343. };
  12344. pie.sortValues = function(_) {
  12345. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  12346. };
  12347. pie.sort = function(_) {
  12348. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  12349. };
  12350. pie.startAngle = function(_) {
  12351. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : startAngle;
  12352. };
  12353. pie.endAngle = function(_) {
  12354. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : endAngle;
  12355. };
  12356. pie.padAngle = function(_) {
  12357. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : padAngle;
  12358. };
  12359. return pie;
  12360. }
  12361. var curveRadialLinear = curveRadial(curveLinear);
  12362. function Radial(curve) {
  12363. this._curve = curve;
  12364. }
  12365. Radial.prototype = {
  12366. areaStart: function() {
  12367. this._curve.areaStart();
  12368. },
  12369. areaEnd: function() {
  12370. this._curve.areaEnd();
  12371. },
  12372. lineStart: function() {
  12373. this._curve.lineStart();
  12374. },
  12375. lineEnd: function() {
  12376. this._curve.lineEnd();
  12377. },
  12378. point: function(a, r) {
  12379. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  12380. }
  12381. };
  12382. function curveRadial(curve) {
  12383. function radial(context) {
  12384. return new Radial(curve(context));
  12385. }
  12386. radial._curve = curve;
  12387. return radial;
  12388. }
  12389. function lineRadial(l) {
  12390. var c = l.curve;
  12391. l.angle = l.x, delete l.x;
  12392. l.radius = l.y, delete l.y;
  12393. l.curve = function(_) {
  12394. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12395. };
  12396. return l;
  12397. }
  12398. function lineRadial$1() {
  12399. return lineRadial(line().curve(curveRadialLinear));
  12400. }
  12401. function areaRadial() {
  12402. var a = area$3().curve(curveRadialLinear),
  12403. c = a.curve,
  12404. x0 = a.lineX0,
  12405. x1 = a.lineX1,
  12406. y0 = a.lineY0,
  12407. y1 = a.lineY1;
  12408. a.angle = a.x, delete a.x;
  12409. a.startAngle = a.x0, delete a.x0;
  12410. a.endAngle = a.x1, delete a.x1;
  12411. a.radius = a.y, delete a.y;
  12412. a.innerRadius = a.y0, delete a.y0;
  12413. a.outerRadius = a.y1, delete a.y1;
  12414. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  12415. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  12416. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  12417. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  12418. a.curve = function(_) {
  12419. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12420. };
  12421. return a;
  12422. }
  12423. function pointRadial(x, y) {
  12424. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  12425. }
  12426. var slice$6 = Array.prototype.slice;
  12427. function linkSource(d) {
  12428. return d.source;
  12429. }
  12430. function linkTarget(d) {
  12431. return d.target;
  12432. }
  12433. function link$2(curve) {
  12434. var source = linkSource,
  12435. target = linkTarget,
  12436. x$$1 = x$3,
  12437. y$$1 = y$3,
  12438. context = null;
  12439. function link() {
  12440. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  12441. if (!context) context = buffer = path();
  12442. 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));
  12443. if (buffer) return context = null, buffer + "" || null;
  12444. }
  12445. link.source = function(_) {
  12446. return arguments.length ? (source = _, link) : source;
  12447. };
  12448. link.target = function(_) {
  12449. return arguments.length ? (target = _, link) : target;
  12450. };
  12451. link.x = function(_) {
  12452. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : x$$1;
  12453. };
  12454. link.y = function(_) {
  12455. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : y$$1;
  12456. };
  12457. link.context = function(_) {
  12458. return arguments.length ? (context = _ == null ? null : _, link) : context;
  12459. };
  12460. return link;
  12461. }
  12462. function curveHorizontal(context, x0, y0, x1, y1) {
  12463. context.moveTo(x0, y0);
  12464. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  12465. }
  12466. function curveVertical(context, x0, y0, x1, y1) {
  12467. context.moveTo(x0, y0);
  12468. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  12469. }
  12470. function curveRadial$1(context, x0, y0, x1, y1) {
  12471. var p0 = pointRadial(x0, y0),
  12472. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  12473. p2 = pointRadial(x1, y0),
  12474. p3 = pointRadial(x1, y1);
  12475. context.moveTo(p0[0], p0[1]);
  12476. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  12477. }
  12478. function linkHorizontal() {
  12479. return link$2(curveHorizontal);
  12480. }
  12481. function linkVertical() {
  12482. return link$2(curveVertical);
  12483. }
  12484. function linkRadial() {
  12485. var l = link$2(curveRadial$1);
  12486. l.angle = l.x, delete l.x;
  12487. l.radius = l.y, delete l.y;
  12488. return l;
  12489. }
  12490. var circle$2 = {
  12491. draw: function(context, size) {
  12492. var r = Math.sqrt(size / pi$4);
  12493. context.moveTo(r, 0);
  12494. context.arc(0, 0, r, 0, tau$4);
  12495. }
  12496. };
  12497. var cross$2 = {
  12498. draw: function(context, size) {
  12499. var r = Math.sqrt(size / 5) / 2;
  12500. context.moveTo(-3 * r, -r);
  12501. context.lineTo(-r, -r);
  12502. context.lineTo(-r, -3 * r);
  12503. context.lineTo(r, -3 * r);
  12504. context.lineTo(r, -r);
  12505. context.lineTo(3 * r, -r);
  12506. context.lineTo(3 * r, r);
  12507. context.lineTo(r, r);
  12508. context.lineTo(r, 3 * r);
  12509. context.lineTo(-r, 3 * r);
  12510. context.lineTo(-r, r);
  12511. context.lineTo(-3 * r, r);
  12512. context.closePath();
  12513. }
  12514. };
  12515. var tan30 = Math.sqrt(1 / 3),
  12516. tan30_2 = tan30 * 2;
  12517. var diamond = {
  12518. draw: function(context, size) {
  12519. var y = Math.sqrt(size / tan30_2),
  12520. x = y * tan30;
  12521. context.moveTo(0, -y);
  12522. context.lineTo(x, 0);
  12523. context.lineTo(0, y);
  12524. context.lineTo(-x, 0);
  12525. context.closePath();
  12526. }
  12527. };
  12528. var ka = 0.89081309152928522810,
  12529. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  12530. kx = Math.sin(tau$4 / 10) * kr,
  12531. ky = -Math.cos(tau$4 / 10) * kr;
  12532. var star = {
  12533. draw: function(context, size) {
  12534. var r = Math.sqrt(size * ka),
  12535. x = kx * r,
  12536. y = ky * r;
  12537. context.moveTo(0, -r);
  12538. context.lineTo(x, y);
  12539. for (var i = 1; i < 5; ++i) {
  12540. var a = tau$4 * i / 5,
  12541. c = Math.cos(a),
  12542. s = Math.sin(a);
  12543. context.lineTo(s * r, -c * r);
  12544. context.lineTo(c * x - s * y, s * x + c * y);
  12545. }
  12546. context.closePath();
  12547. }
  12548. };
  12549. var square = {
  12550. draw: function(context, size) {
  12551. var w = Math.sqrt(size),
  12552. x = -w / 2;
  12553. context.rect(x, x, w, w);
  12554. }
  12555. };
  12556. var sqrt3 = Math.sqrt(3);
  12557. var triangle = {
  12558. draw: function(context, size) {
  12559. var y = -Math.sqrt(size / (sqrt3 * 3));
  12560. context.moveTo(0, y * 2);
  12561. context.lineTo(-sqrt3 * y, -y);
  12562. context.lineTo(sqrt3 * y, -y);
  12563. context.closePath();
  12564. }
  12565. };
  12566. var c$2 = -0.5,
  12567. s = Math.sqrt(3) / 2,
  12568. k = 1 / Math.sqrt(12),
  12569. a = (k / 2 + 1) * 3;
  12570. var wye = {
  12571. draw: function(context, size) {
  12572. var r = Math.sqrt(size / a),
  12573. x0 = r / 2,
  12574. y0 = r * k,
  12575. x1 = x0,
  12576. y1 = r * k + r,
  12577. x2 = -x1,
  12578. y2 = y1;
  12579. context.moveTo(x0, y0);
  12580. context.lineTo(x1, y1);
  12581. context.lineTo(x2, y2);
  12582. context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
  12583. context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
  12584. context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
  12585. context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
  12586. context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
  12587. context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
  12588. context.closePath();
  12589. }
  12590. };
  12591. var symbols = [
  12592. circle$2,
  12593. cross$2,
  12594. diamond,
  12595. square,
  12596. star,
  12597. triangle,
  12598. wye
  12599. ];
  12600. function symbol() {
  12601. var type = constant$11(circle$2),
  12602. size = constant$11(64),
  12603. context = null;
  12604. function symbol() {
  12605. var buffer;
  12606. if (!context) context = buffer = path();
  12607. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  12608. if (buffer) return context = null, buffer + "" || null;
  12609. }
  12610. symbol.type = function(_) {
  12611. return arguments.length ? (type = typeof _ === "function" ? _ : constant$11(_), symbol) : type;
  12612. };
  12613. symbol.size = function(_) {
  12614. return arguments.length ? (size = typeof _ === "function" ? _ : constant$11(+_), symbol) : size;
  12615. };
  12616. symbol.context = function(_) {
  12617. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  12618. };
  12619. return symbol;
  12620. }
  12621. function noop$3() {}
  12622. function point$2(that, x, y) {
  12623. that._context.bezierCurveTo(
  12624. (2 * that._x0 + that._x1) / 3,
  12625. (2 * that._y0 + that._y1) / 3,
  12626. (that._x0 + 2 * that._x1) / 3,
  12627. (that._y0 + 2 * that._y1) / 3,
  12628. (that._x0 + 4 * that._x1 + x) / 6,
  12629. (that._y0 + 4 * that._y1 + y) / 6
  12630. );
  12631. }
  12632. function Basis(context) {
  12633. this._context = context;
  12634. }
  12635. Basis.prototype = {
  12636. areaStart: function() {
  12637. this._line = 0;
  12638. },
  12639. areaEnd: function() {
  12640. this._line = NaN;
  12641. },
  12642. lineStart: function() {
  12643. this._x0 = this._x1 =
  12644. this._y0 = this._y1 = NaN;
  12645. this._point = 0;
  12646. },
  12647. lineEnd: function() {
  12648. switch (this._point) {
  12649. case 3: point$2(this, this._x1, this._y1); // proceed
  12650. case 2: this._context.lineTo(this._x1, this._y1); break;
  12651. }
  12652. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12653. this._line = 1 - this._line;
  12654. },
  12655. point: function(x, y) {
  12656. x = +x, y = +y;
  12657. switch (this._point) {
  12658. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12659. case 1: this._point = 2; break;
  12660. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  12661. default: point$2(this, x, y); break;
  12662. }
  12663. this._x0 = this._x1, this._x1 = x;
  12664. this._y0 = this._y1, this._y1 = y;
  12665. }
  12666. };
  12667. function basis$2(context) {
  12668. return new Basis(context);
  12669. }
  12670. function BasisClosed(context) {
  12671. this._context = context;
  12672. }
  12673. BasisClosed.prototype = {
  12674. areaStart: noop$3,
  12675. areaEnd: noop$3,
  12676. lineStart: function() {
  12677. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  12678. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  12679. this._point = 0;
  12680. },
  12681. lineEnd: function() {
  12682. switch (this._point) {
  12683. case 1: {
  12684. this._context.moveTo(this._x2, this._y2);
  12685. this._context.closePath();
  12686. break;
  12687. }
  12688. case 2: {
  12689. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  12690. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  12691. this._context.closePath();
  12692. break;
  12693. }
  12694. case 3: {
  12695. this.point(this._x2, this._y2);
  12696. this.point(this._x3, this._y3);
  12697. this.point(this._x4, this._y4);
  12698. break;
  12699. }
  12700. }
  12701. },
  12702. point: function(x, y) {
  12703. x = +x, y = +y;
  12704. switch (this._point) {
  12705. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  12706. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  12707. 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;
  12708. default: point$2(this, x, y); break;
  12709. }
  12710. this._x0 = this._x1, this._x1 = x;
  12711. this._y0 = this._y1, this._y1 = y;
  12712. }
  12713. };
  12714. function basisClosed$1(context) {
  12715. return new BasisClosed(context);
  12716. }
  12717. function BasisOpen(context) {
  12718. this._context = context;
  12719. }
  12720. BasisOpen.prototype = {
  12721. areaStart: function() {
  12722. this._line = 0;
  12723. },
  12724. areaEnd: function() {
  12725. this._line = NaN;
  12726. },
  12727. lineStart: function() {
  12728. this._x0 = this._x1 =
  12729. this._y0 = this._y1 = NaN;
  12730. this._point = 0;
  12731. },
  12732. lineEnd: function() {
  12733. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12734. this._line = 1 - this._line;
  12735. },
  12736. point: function(x, y) {
  12737. x = +x, y = +y;
  12738. switch (this._point) {
  12739. case 0: this._point = 1; break;
  12740. case 1: this._point = 2; break;
  12741. 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;
  12742. case 3: this._point = 4; // proceed
  12743. default: point$2(this, x, y); break;
  12744. }
  12745. this._x0 = this._x1, this._x1 = x;
  12746. this._y0 = this._y1, this._y1 = y;
  12747. }
  12748. };
  12749. function basisOpen(context) {
  12750. return new BasisOpen(context);
  12751. }
  12752. function Bundle(context, beta) {
  12753. this._basis = new Basis(context);
  12754. this._beta = beta;
  12755. }
  12756. Bundle.prototype = {
  12757. lineStart: function() {
  12758. this._x = [];
  12759. this._y = [];
  12760. this._basis.lineStart();
  12761. },
  12762. lineEnd: function() {
  12763. var x = this._x,
  12764. y = this._y,
  12765. j = x.length - 1;
  12766. if (j > 0) {
  12767. var x0 = x[0],
  12768. y0 = y[0],
  12769. dx = x[j] - x0,
  12770. dy = y[j] - y0,
  12771. i = -1,
  12772. t;
  12773. while (++i <= j) {
  12774. t = i / j;
  12775. this._basis.point(
  12776. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  12777. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  12778. );
  12779. }
  12780. }
  12781. this._x = this._y = null;
  12782. this._basis.lineEnd();
  12783. },
  12784. point: function(x, y) {
  12785. this._x.push(+x);
  12786. this._y.push(+y);
  12787. }
  12788. };
  12789. var bundle = (function custom(beta) {
  12790. function bundle(context) {
  12791. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  12792. }
  12793. bundle.beta = function(beta) {
  12794. return custom(+beta);
  12795. };
  12796. return bundle;
  12797. })(0.85);
  12798. function point$3(that, x, y) {
  12799. that._context.bezierCurveTo(
  12800. that._x1 + that._k * (that._x2 - that._x0),
  12801. that._y1 + that._k * (that._y2 - that._y0),
  12802. that._x2 + that._k * (that._x1 - x),
  12803. that._y2 + that._k * (that._y1 - y),
  12804. that._x2,
  12805. that._y2
  12806. );
  12807. }
  12808. function Cardinal(context, tension) {
  12809. this._context = context;
  12810. this._k = (1 - tension) / 6;
  12811. }
  12812. Cardinal.prototype = {
  12813. areaStart: function() {
  12814. this._line = 0;
  12815. },
  12816. areaEnd: function() {
  12817. this._line = NaN;
  12818. },
  12819. lineStart: function() {
  12820. this._x0 = this._x1 = this._x2 =
  12821. this._y0 = this._y1 = this._y2 = NaN;
  12822. this._point = 0;
  12823. },
  12824. lineEnd: function() {
  12825. switch (this._point) {
  12826. case 2: this._context.lineTo(this._x2, this._y2); break;
  12827. case 3: point$3(this, this._x1, this._y1); break;
  12828. }
  12829. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12830. this._line = 1 - this._line;
  12831. },
  12832. point: function(x, y) {
  12833. x = +x, y = +y;
  12834. switch (this._point) {
  12835. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12836. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  12837. case 2: this._point = 3; // proceed
  12838. default: point$3(this, x, y); break;
  12839. }
  12840. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12841. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12842. }
  12843. };
  12844. var cardinal = (function custom(tension) {
  12845. function cardinal(context) {
  12846. return new Cardinal(context, tension);
  12847. }
  12848. cardinal.tension = function(tension) {
  12849. return custom(+tension);
  12850. };
  12851. return cardinal;
  12852. })(0);
  12853. function CardinalClosed(context, tension) {
  12854. this._context = context;
  12855. this._k = (1 - tension) / 6;
  12856. }
  12857. CardinalClosed.prototype = {
  12858. areaStart: noop$3,
  12859. areaEnd: noop$3,
  12860. lineStart: function() {
  12861. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12862. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12863. this._point = 0;
  12864. },
  12865. lineEnd: function() {
  12866. switch (this._point) {
  12867. case 1: {
  12868. this._context.moveTo(this._x3, this._y3);
  12869. this._context.closePath();
  12870. break;
  12871. }
  12872. case 2: {
  12873. this._context.lineTo(this._x3, this._y3);
  12874. this._context.closePath();
  12875. break;
  12876. }
  12877. case 3: {
  12878. this.point(this._x3, this._y3);
  12879. this.point(this._x4, this._y4);
  12880. this.point(this._x5, this._y5);
  12881. break;
  12882. }
  12883. }
  12884. },
  12885. point: function(x, y) {
  12886. x = +x, y = +y;
  12887. switch (this._point) {
  12888. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12889. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12890. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12891. default: point$3(this, x, y); break;
  12892. }
  12893. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12894. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12895. }
  12896. };
  12897. var cardinalClosed = (function custom(tension) {
  12898. function cardinal$$1(context) {
  12899. return new CardinalClosed(context, tension);
  12900. }
  12901. cardinal$$1.tension = function(tension) {
  12902. return custom(+tension);
  12903. };
  12904. return cardinal$$1;
  12905. })(0);
  12906. function CardinalOpen(context, tension) {
  12907. this._context = context;
  12908. this._k = (1 - tension) / 6;
  12909. }
  12910. CardinalOpen.prototype = {
  12911. areaStart: function() {
  12912. this._line = 0;
  12913. },
  12914. areaEnd: function() {
  12915. this._line = NaN;
  12916. },
  12917. lineStart: function() {
  12918. this._x0 = this._x1 = this._x2 =
  12919. this._y0 = this._y1 = this._y2 = NaN;
  12920. this._point = 0;
  12921. },
  12922. lineEnd: function() {
  12923. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12924. this._line = 1 - this._line;
  12925. },
  12926. point: function(x, y) {
  12927. x = +x, y = +y;
  12928. switch (this._point) {
  12929. case 0: this._point = 1; break;
  12930. case 1: this._point = 2; break;
  12931. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12932. case 3: this._point = 4; // proceed
  12933. default: point$3(this, x, y); break;
  12934. }
  12935. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12936. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12937. }
  12938. };
  12939. var cardinalOpen = (function custom(tension) {
  12940. function cardinal$$1(context) {
  12941. return new CardinalOpen(context, tension);
  12942. }
  12943. cardinal$$1.tension = function(tension) {
  12944. return custom(+tension);
  12945. };
  12946. return cardinal$$1;
  12947. })(0);
  12948. function point$4(that, x, y) {
  12949. var x1 = that._x1,
  12950. y1 = that._y1,
  12951. x2 = that._x2,
  12952. y2 = that._y2;
  12953. if (that._l01_a > epsilon$3) {
  12954. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  12955. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  12956. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  12957. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  12958. }
  12959. if (that._l23_a > epsilon$3) {
  12960. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  12961. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  12962. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  12963. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  12964. }
  12965. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  12966. }
  12967. function CatmullRom(context, alpha) {
  12968. this._context = context;
  12969. this._alpha = alpha;
  12970. }
  12971. CatmullRom.prototype = {
  12972. areaStart: function() {
  12973. this._line = 0;
  12974. },
  12975. areaEnd: function() {
  12976. this._line = NaN;
  12977. },
  12978. lineStart: function() {
  12979. this._x0 = this._x1 = this._x2 =
  12980. this._y0 = this._y1 = this._y2 = NaN;
  12981. this._l01_a = this._l12_a = this._l23_a =
  12982. this._l01_2a = this._l12_2a = this._l23_2a =
  12983. this._point = 0;
  12984. },
  12985. lineEnd: function() {
  12986. switch (this._point) {
  12987. case 2: this._context.lineTo(this._x2, this._y2); break;
  12988. case 3: this.point(this._x2, this._y2); break;
  12989. }
  12990. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12991. this._line = 1 - this._line;
  12992. },
  12993. point: function(x, y) {
  12994. x = +x, y = +y;
  12995. if (this._point) {
  12996. var x23 = this._x2 - x,
  12997. y23 = this._y2 - y;
  12998. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12999. }
  13000. switch (this._point) {
  13001. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13002. case 1: this._point = 2; break;
  13003. case 2: this._point = 3; // proceed
  13004. default: point$4(this, x, y); break;
  13005. }
  13006. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13007. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13008. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13009. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13010. }
  13011. };
  13012. var catmullRom = (function custom(alpha) {
  13013. function catmullRom(context) {
  13014. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  13015. }
  13016. catmullRom.alpha = function(alpha) {
  13017. return custom(+alpha);
  13018. };
  13019. return catmullRom;
  13020. })(0.5);
  13021. function CatmullRomClosed(context, alpha) {
  13022. this._context = context;
  13023. this._alpha = alpha;
  13024. }
  13025. CatmullRomClosed.prototype = {
  13026. areaStart: noop$3,
  13027. areaEnd: noop$3,
  13028. lineStart: function() {
  13029. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13030. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13031. this._l01_a = this._l12_a = this._l23_a =
  13032. this._l01_2a = this._l12_2a = this._l23_2a =
  13033. this._point = 0;
  13034. },
  13035. lineEnd: function() {
  13036. switch (this._point) {
  13037. case 1: {
  13038. this._context.moveTo(this._x3, this._y3);
  13039. this._context.closePath();
  13040. break;
  13041. }
  13042. case 2: {
  13043. this._context.lineTo(this._x3, this._y3);
  13044. this._context.closePath();
  13045. break;
  13046. }
  13047. case 3: {
  13048. this.point(this._x3, this._y3);
  13049. this.point(this._x4, this._y4);
  13050. this.point(this._x5, this._y5);
  13051. break;
  13052. }
  13053. }
  13054. },
  13055. point: function(x, y) {
  13056. x = +x, y = +y;
  13057. if (this._point) {
  13058. var x23 = this._x2 - x,
  13059. y23 = this._y2 - y;
  13060. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13061. }
  13062. switch (this._point) {
  13063. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13064. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13065. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13066. default: point$4(this, x, y); break;
  13067. }
  13068. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13069. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13070. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13071. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13072. }
  13073. };
  13074. var catmullRomClosed = (function custom(alpha) {
  13075. function catmullRom$$1(context) {
  13076. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  13077. }
  13078. catmullRom$$1.alpha = function(alpha) {
  13079. return custom(+alpha);
  13080. };
  13081. return catmullRom$$1;
  13082. })(0.5);
  13083. function CatmullRomOpen(context, alpha) {
  13084. this._context = context;
  13085. this._alpha = alpha;
  13086. }
  13087. CatmullRomOpen.prototype = {
  13088. areaStart: function() {
  13089. this._line = 0;
  13090. },
  13091. areaEnd: function() {
  13092. this._line = NaN;
  13093. },
  13094. lineStart: function() {
  13095. this._x0 = this._x1 = this._x2 =
  13096. this._y0 = this._y1 = this._y2 = NaN;
  13097. this._l01_a = this._l12_a = this._l23_a =
  13098. this._l01_2a = this._l12_2a = this._l23_2a =
  13099. this._point = 0;
  13100. },
  13101. lineEnd: function() {
  13102. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13103. this._line = 1 - this._line;
  13104. },
  13105. point: function(x, y) {
  13106. x = +x, y = +y;
  13107. if (this._point) {
  13108. var x23 = this._x2 - x,
  13109. y23 = this._y2 - y;
  13110. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13111. }
  13112. switch (this._point) {
  13113. case 0: this._point = 1; break;
  13114. case 1: this._point = 2; break;
  13115. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13116. case 3: this._point = 4; // proceed
  13117. default: point$4(this, x, y); break;
  13118. }
  13119. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13120. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13121. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13122. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13123. }
  13124. };
  13125. var catmullRomOpen = (function custom(alpha) {
  13126. function catmullRom$$1(context) {
  13127. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  13128. }
  13129. catmullRom$$1.alpha = function(alpha) {
  13130. return custom(+alpha);
  13131. };
  13132. return catmullRom$$1;
  13133. })(0.5);
  13134. function LinearClosed(context) {
  13135. this._context = context;
  13136. }
  13137. LinearClosed.prototype = {
  13138. areaStart: noop$3,
  13139. areaEnd: noop$3,
  13140. lineStart: function() {
  13141. this._point = 0;
  13142. },
  13143. lineEnd: function() {
  13144. if (this._point) this._context.closePath();
  13145. },
  13146. point: function(x, y) {
  13147. x = +x, y = +y;
  13148. if (this._point) this._context.lineTo(x, y);
  13149. else this._point = 1, this._context.moveTo(x, y);
  13150. }
  13151. };
  13152. function linearClosed(context) {
  13153. return new LinearClosed(context);
  13154. }
  13155. function sign$1(x) {
  13156. return x < 0 ? -1 : 1;
  13157. }
  13158. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  13159. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  13160. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  13161. // NOV(II), P. 443, 1990.
  13162. function slope3(that, x2, y2) {
  13163. var h0 = that._x1 - that._x0,
  13164. h1 = x2 - that._x1,
  13165. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  13166. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  13167. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  13168. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  13169. }
  13170. // Calculate a one-sided slope.
  13171. function slope2(that, t) {
  13172. var h = that._x1 - that._x0;
  13173. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  13174. }
  13175. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  13176. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  13177. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  13178. function point$5(that, t0, t1) {
  13179. var x0 = that._x0,
  13180. y0 = that._y0,
  13181. x1 = that._x1,
  13182. y1 = that._y1,
  13183. dx = (x1 - x0) / 3;
  13184. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  13185. }
  13186. function MonotoneX(context) {
  13187. this._context = context;
  13188. }
  13189. MonotoneX.prototype = {
  13190. areaStart: function() {
  13191. this._line = 0;
  13192. },
  13193. areaEnd: function() {
  13194. this._line = NaN;
  13195. },
  13196. lineStart: function() {
  13197. this._x0 = this._x1 =
  13198. this._y0 = this._y1 =
  13199. this._t0 = NaN;
  13200. this._point = 0;
  13201. },
  13202. lineEnd: function() {
  13203. switch (this._point) {
  13204. case 2: this._context.lineTo(this._x1, this._y1); break;
  13205. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  13206. }
  13207. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13208. this._line = 1 - this._line;
  13209. },
  13210. point: function(x, y) {
  13211. var t1 = NaN;
  13212. x = +x, y = +y;
  13213. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  13214. switch (this._point) {
  13215. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13216. case 1: this._point = 2; break;
  13217. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  13218. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  13219. }
  13220. this._x0 = this._x1, this._x1 = x;
  13221. this._y0 = this._y1, this._y1 = y;
  13222. this._t0 = t1;
  13223. }
  13224. };
  13225. function MonotoneY(context) {
  13226. this._context = new ReflectContext(context);
  13227. }
  13228. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  13229. MonotoneX.prototype.point.call(this, y, x);
  13230. };
  13231. function ReflectContext(context) {
  13232. this._context = context;
  13233. }
  13234. ReflectContext.prototype = {
  13235. moveTo: function(x, y) { this._context.moveTo(y, x); },
  13236. closePath: function() { this._context.closePath(); },
  13237. lineTo: function(x, y) { this._context.lineTo(y, x); },
  13238. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  13239. };
  13240. function monotoneX(context) {
  13241. return new MonotoneX(context);
  13242. }
  13243. function monotoneY(context) {
  13244. return new MonotoneY(context);
  13245. }
  13246. function Natural(context) {
  13247. this._context = context;
  13248. }
  13249. Natural.prototype = {
  13250. areaStart: function() {
  13251. this._line = 0;
  13252. },
  13253. areaEnd: function() {
  13254. this._line = NaN;
  13255. },
  13256. lineStart: function() {
  13257. this._x = [];
  13258. this._y = [];
  13259. },
  13260. lineEnd: function() {
  13261. var x = this._x,
  13262. y = this._y,
  13263. n = x.length;
  13264. if (n) {
  13265. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  13266. if (n === 2) {
  13267. this._context.lineTo(x[1], y[1]);
  13268. } else {
  13269. var px = controlPoints(x),
  13270. py = controlPoints(y);
  13271. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  13272. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  13273. }
  13274. }
  13275. }
  13276. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  13277. this._line = 1 - this._line;
  13278. this._x = this._y = null;
  13279. },
  13280. point: function(x, y) {
  13281. this._x.push(+x);
  13282. this._y.push(+y);
  13283. }
  13284. };
  13285. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  13286. function controlPoints(x) {
  13287. var i,
  13288. n = x.length - 1,
  13289. m,
  13290. a = new Array(n),
  13291. b = new Array(n),
  13292. r = new Array(n);
  13293. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  13294. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  13295. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  13296. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  13297. a[n - 1] = r[n - 1] / b[n - 1];
  13298. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  13299. b[n - 1] = (x[n] + a[n - 1]) / 2;
  13300. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  13301. return [a, b];
  13302. }
  13303. function natural(context) {
  13304. return new Natural(context);
  13305. }
  13306. function Step(context, t) {
  13307. this._context = context;
  13308. this._t = t;
  13309. }
  13310. Step.prototype = {
  13311. areaStart: function() {
  13312. this._line = 0;
  13313. },
  13314. areaEnd: function() {
  13315. this._line = NaN;
  13316. },
  13317. lineStart: function() {
  13318. this._x = this._y = NaN;
  13319. this._point = 0;
  13320. },
  13321. lineEnd: function() {
  13322. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  13323. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13324. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  13325. },
  13326. point: function(x, y) {
  13327. x = +x, y = +y;
  13328. switch (this._point) {
  13329. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13330. case 1: this._point = 2; // proceed
  13331. default: {
  13332. if (this._t <= 0) {
  13333. this._context.lineTo(this._x, y);
  13334. this._context.lineTo(x, y);
  13335. } else {
  13336. var x1 = this._x * (1 - this._t) + x * this._t;
  13337. this._context.lineTo(x1, this._y);
  13338. this._context.lineTo(x1, y);
  13339. }
  13340. break;
  13341. }
  13342. }
  13343. this._x = x, this._y = y;
  13344. }
  13345. };
  13346. function step(context) {
  13347. return new Step(context, 0.5);
  13348. }
  13349. function stepBefore(context) {
  13350. return new Step(context, 0);
  13351. }
  13352. function stepAfter(context) {
  13353. return new Step(context, 1);
  13354. }
  13355. function none$1(series, order) {
  13356. if (!((n = series.length) > 1)) return;
  13357. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  13358. s0 = s1, s1 = series[order[i]];
  13359. for (j = 0; j < m; ++j) {
  13360. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  13361. }
  13362. }
  13363. }
  13364. function none$2(series) {
  13365. var n = series.length, o = new Array(n);
  13366. while (--n >= 0) o[n] = n;
  13367. return o;
  13368. }
  13369. function stackValue(d, key) {
  13370. return d[key];
  13371. }
  13372. function stack() {
  13373. var keys = constant$11([]),
  13374. order = none$2,
  13375. offset = none$1,
  13376. value = stackValue;
  13377. function stack(data) {
  13378. var kz = keys.apply(this, arguments),
  13379. i,
  13380. m = data.length,
  13381. n = kz.length,
  13382. sz = new Array(n),
  13383. oz;
  13384. for (i = 0; i < n; ++i) {
  13385. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  13386. si[j] = sij = [0, +value(data[j], ki, j, data)];
  13387. sij.data = data[j];
  13388. }
  13389. si.key = ki;
  13390. }
  13391. for (i = 0, oz = order(sz); i < n; ++i) {
  13392. sz[oz[i]].index = i;
  13393. }
  13394. offset(sz, oz);
  13395. return sz;
  13396. }
  13397. stack.keys = function(_) {
  13398. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : keys;
  13399. };
  13400. stack.value = function(_) {
  13401. return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), stack) : value;
  13402. };
  13403. stack.order = function(_) {
  13404. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : order;
  13405. };
  13406. stack.offset = function(_) {
  13407. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  13408. };
  13409. return stack;
  13410. }
  13411. function expand(series, order) {
  13412. if (!((n = series.length) > 0)) return;
  13413. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  13414. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  13415. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  13416. }
  13417. none$1(series, order);
  13418. }
  13419. function diverging$1(series, order) {
  13420. if (!((n = series.length) > 1)) return;
  13421. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  13422. for (yp = yn = 0, i = 0; i < n; ++i) {
  13423. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  13424. d[0] = yp, d[1] = yp += dy;
  13425. } else if (dy < 0) {
  13426. d[1] = yn, d[0] = yn += dy;
  13427. } else {
  13428. d[0] = yp;
  13429. }
  13430. }
  13431. }
  13432. }
  13433. function silhouette(series, order) {
  13434. if (!((n = series.length) > 0)) return;
  13435. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  13436. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  13437. s0[j][1] += s0[j][0] = -y / 2;
  13438. }
  13439. none$1(series, order);
  13440. }
  13441. function wiggle(series, order) {
  13442. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  13443. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  13444. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  13445. var si = series[order[i]],
  13446. sij0 = si[j][1] || 0,
  13447. sij1 = si[j - 1][1] || 0,
  13448. s3 = (sij0 - sij1) / 2;
  13449. for (var k = 0; k < i; ++k) {
  13450. var sk = series[order[k]],
  13451. skj0 = sk[j][1] || 0,
  13452. skj1 = sk[j - 1][1] || 0;
  13453. s3 += skj0 - skj1;
  13454. }
  13455. s1 += sij0, s2 += s3 * sij0;
  13456. }
  13457. s0[j - 1][1] += s0[j - 1][0] = y;
  13458. if (s1) y -= s2 / s1;
  13459. }
  13460. s0[j - 1][1] += s0[j - 1][0] = y;
  13461. none$1(series, order);
  13462. }
  13463. function ascending$3(series) {
  13464. var sums = series.map(sum$2);
  13465. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  13466. }
  13467. function sum$2(series) {
  13468. var s = 0, i = -1, n = series.length, v;
  13469. while (++i < n) if (v = +series[i][1]) s += v;
  13470. return s;
  13471. }
  13472. function descending$2(series) {
  13473. return ascending$3(series).reverse();
  13474. }
  13475. function insideOut(series) {
  13476. var n = series.length,
  13477. i,
  13478. j,
  13479. sums = series.map(sum$2),
  13480. order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  13481. top = 0,
  13482. bottom = 0,
  13483. tops = [],
  13484. bottoms = [];
  13485. for (i = 0; i < n; ++i) {
  13486. j = order[i];
  13487. if (top < bottom) {
  13488. top += sums[j];
  13489. tops.push(j);
  13490. } else {
  13491. bottom += sums[j];
  13492. bottoms.push(j);
  13493. }
  13494. }
  13495. return bottoms.reverse().concat(tops);
  13496. }
  13497. function reverse(series) {
  13498. return none$2(series).reverse();
  13499. }
  13500. function constant$12(x) {
  13501. return function() {
  13502. return x;
  13503. };
  13504. }
  13505. function x$4(d) {
  13506. return d[0];
  13507. }
  13508. function y$4(d) {
  13509. return d[1];
  13510. }
  13511. function RedBlackTree() {
  13512. this._ = null; // root node
  13513. }
  13514. function RedBlackNode(node) {
  13515. node.U = // parent node
  13516. node.C = // color - true for red, false for black
  13517. node.L = // left node
  13518. node.R = // right node
  13519. node.P = // previous node
  13520. node.N = null; // next node
  13521. }
  13522. RedBlackTree.prototype = {
  13523. constructor: RedBlackTree,
  13524. insert: function(after, node) {
  13525. var parent, grandpa, uncle;
  13526. if (after) {
  13527. node.P = after;
  13528. node.N = after.N;
  13529. if (after.N) after.N.P = node;
  13530. after.N = node;
  13531. if (after.R) {
  13532. after = after.R;
  13533. while (after.L) after = after.L;
  13534. after.L = node;
  13535. } else {
  13536. after.R = node;
  13537. }
  13538. parent = after;
  13539. } else if (this._) {
  13540. after = RedBlackFirst(this._);
  13541. node.P = null;
  13542. node.N = after;
  13543. after.P = after.L = node;
  13544. parent = after;
  13545. } else {
  13546. node.P = node.N = null;
  13547. this._ = node;
  13548. parent = null;
  13549. }
  13550. node.L = node.R = null;
  13551. node.U = parent;
  13552. node.C = true;
  13553. after = node;
  13554. while (parent && parent.C) {
  13555. grandpa = parent.U;
  13556. if (parent === grandpa.L) {
  13557. uncle = grandpa.R;
  13558. if (uncle && uncle.C) {
  13559. parent.C = uncle.C = false;
  13560. grandpa.C = true;
  13561. after = grandpa;
  13562. } else {
  13563. if (after === parent.R) {
  13564. RedBlackRotateLeft(this, parent);
  13565. after = parent;
  13566. parent = after.U;
  13567. }
  13568. parent.C = false;
  13569. grandpa.C = true;
  13570. RedBlackRotateRight(this, grandpa);
  13571. }
  13572. } else {
  13573. uncle = grandpa.L;
  13574. if (uncle && uncle.C) {
  13575. parent.C = uncle.C = false;
  13576. grandpa.C = true;
  13577. after = grandpa;
  13578. } else {
  13579. if (after === parent.L) {
  13580. RedBlackRotateRight(this, parent);
  13581. after = parent;
  13582. parent = after.U;
  13583. }
  13584. parent.C = false;
  13585. grandpa.C = true;
  13586. RedBlackRotateLeft(this, grandpa);
  13587. }
  13588. }
  13589. parent = after.U;
  13590. }
  13591. this._.C = false;
  13592. },
  13593. remove: function(node) {
  13594. if (node.N) node.N.P = node.P;
  13595. if (node.P) node.P.N = node.N;
  13596. node.N = node.P = null;
  13597. var parent = node.U,
  13598. sibling,
  13599. left = node.L,
  13600. right = node.R,
  13601. next,
  13602. red;
  13603. if (!left) next = right;
  13604. else if (!right) next = left;
  13605. else next = RedBlackFirst(right);
  13606. if (parent) {
  13607. if (parent.L === node) parent.L = next;
  13608. else parent.R = next;
  13609. } else {
  13610. this._ = next;
  13611. }
  13612. if (left && right) {
  13613. red = next.C;
  13614. next.C = node.C;
  13615. next.L = left;
  13616. left.U = next;
  13617. if (next !== right) {
  13618. parent = next.U;
  13619. next.U = node.U;
  13620. node = next.R;
  13621. parent.L = node;
  13622. next.R = right;
  13623. right.U = next;
  13624. } else {
  13625. next.U = parent;
  13626. parent = next;
  13627. node = next.R;
  13628. }
  13629. } else {
  13630. red = node.C;
  13631. node = next;
  13632. }
  13633. if (node) node.U = parent;
  13634. if (red) return;
  13635. if (node && node.C) { node.C = false; return; }
  13636. do {
  13637. if (node === this._) break;
  13638. if (node === parent.L) {
  13639. sibling = parent.R;
  13640. if (sibling.C) {
  13641. sibling.C = false;
  13642. parent.C = true;
  13643. RedBlackRotateLeft(this, parent);
  13644. sibling = parent.R;
  13645. }
  13646. if ((sibling.L && sibling.L.C)
  13647. || (sibling.R && sibling.R.C)) {
  13648. if (!sibling.R || !sibling.R.C) {
  13649. sibling.L.C = false;
  13650. sibling.C = true;
  13651. RedBlackRotateRight(this, sibling);
  13652. sibling = parent.R;
  13653. }
  13654. sibling.C = parent.C;
  13655. parent.C = sibling.R.C = false;
  13656. RedBlackRotateLeft(this, parent);
  13657. node = this._;
  13658. break;
  13659. }
  13660. } else {
  13661. sibling = parent.L;
  13662. if (sibling.C) {
  13663. sibling.C = false;
  13664. parent.C = true;
  13665. RedBlackRotateRight(this, parent);
  13666. sibling = parent.L;
  13667. }
  13668. if ((sibling.L && sibling.L.C)
  13669. || (sibling.R && sibling.R.C)) {
  13670. if (!sibling.L || !sibling.L.C) {
  13671. sibling.R.C = false;
  13672. sibling.C = true;
  13673. RedBlackRotateLeft(this, sibling);
  13674. sibling = parent.L;
  13675. }
  13676. sibling.C = parent.C;
  13677. parent.C = sibling.L.C = false;
  13678. RedBlackRotateRight(this, parent);
  13679. node = this._;
  13680. break;
  13681. }
  13682. }
  13683. sibling.C = true;
  13684. node = parent;
  13685. parent = parent.U;
  13686. } while (!node.C);
  13687. if (node) node.C = false;
  13688. }
  13689. };
  13690. function RedBlackRotateLeft(tree, node) {
  13691. var p = node,
  13692. q = node.R,
  13693. parent = p.U;
  13694. if (parent) {
  13695. if (parent.L === p) parent.L = q;
  13696. else parent.R = q;
  13697. } else {
  13698. tree._ = q;
  13699. }
  13700. q.U = parent;
  13701. p.U = q;
  13702. p.R = q.L;
  13703. if (p.R) p.R.U = p;
  13704. q.L = p;
  13705. }
  13706. function RedBlackRotateRight(tree, node) {
  13707. var p = node,
  13708. q = node.L,
  13709. parent = p.U;
  13710. if (parent) {
  13711. if (parent.L === p) parent.L = q;
  13712. else parent.R = q;
  13713. } else {
  13714. tree._ = q;
  13715. }
  13716. q.U = parent;
  13717. p.U = q;
  13718. p.L = q.R;
  13719. if (p.L) p.L.U = p;
  13720. q.R = p;
  13721. }
  13722. function RedBlackFirst(node) {
  13723. while (node.L) node = node.L;
  13724. return node;
  13725. }
  13726. function createEdge(left, right, v0, v1) {
  13727. var edge = [null, null],
  13728. index = edges.push(edge) - 1;
  13729. edge.left = left;
  13730. edge.right = right;
  13731. if (v0) setEdgeEnd(edge, left, right, v0);
  13732. if (v1) setEdgeEnd(edge, right, left, v1);
  13733. cells[left.index].halfedges.push(index);
  13734. cells[right.index].halfedges.push(index);
  13735. return edge;
  13736. }
  13737. function createBorderEdge(left, v0, v1) {
  13738. var edge = [v0, v1];
  13739. edge.left = left;
  13740. return edge;
  13741. }
  13742. function setEdgeEnd(edge, left, right, vertex) {
  13743. if (!edge[0] && !edge[1]) {
  13744. edge[0] = vertex;
  13745. edge.left = left;
  13746. edge.right = right;
  13747. } else if (edge.left === right) {
  13748. edge[1] = vertex;
  13749. } else {
  13750. edge[0] = vertex;
  13751. }
  13752. }
  13753. // Liang–Barsky line clipping.
  13754. function clipEdge(edge, x0, y0, x1, y1) {
  13755. var a = edge[0],
  13756. b = edge[1],
  13757. ax = a[0],
  13758. ay = a[1],
  13759. bx = b[0],
  13760. by = b[1],
  13761. t0 = 0,
  13762. t1 = 1,
  13763. dx = bx - ax,
  13764. dy = by - ay,
  13765. r;
  13766. r = x0 - ax;
  13767. if (!dx && r > 0) return;
  13768. r /= dx;
  13769. if (dx < 0) {
  13770. if (r < t0) return;
  13771. if (r < t1) t1 = r;
  13772. } else if (dx > 0) {
  13773. if (r > t1) return;
  13774. if (r > t0) t0 = r;
  13775. }
  13776. r = x1 - ax;
  13777. if (!dx && r < 0) return;
  13778. r /= dx;
  13779. if (dx < 0) {
  13780. if (r > t1) return;
  13781. if (r > t0) t0 = r;
  13782. } else if (dx > 0) {
  13783. if (r < t0) return;
  13784. if (r < t1) t1 = r;
  13785. }
  13786. r = y0 - ay;
  13787. if (!dy && r > 0) return;
  13788. r /= dy;
  13789. if (dy < 0) {
  13790. if (r < t0) return;
  13791. if (r < t1) t1 = r;
  13792. } else if (dy > 0) {
  13793. if (r > t1) return;
  13794. if (r > t0) t0 = r;
  13795. }
  13796. r = y1 - ay;
  13797. if (!dy && r < 0) return;
  13798. r /= dy;
  13799. if (dy < 0) {
  13800. if (r > t1) return;
  13801. if (r > t0) t0 = r;
  13802. } else if (dy > 0) {
  13803. if (r < t0) return;
  13804. if (r < t1) t1 = r;
  13805. }
  13806. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  13807. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  13808. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  13809. return true;
  13810. }
  13811. function connectEdge(edge, x0, y0, x1, y1) {
  13812. var v1 = edge[1];
  13813. if (v1) return true;
  13814. var v0 = edge[0],
  13815. left = edge.left,
  13816. right = edge.right,
  13817. lx = left[0],
  13818. ly = left[1],
  13819. rx = right[0],
  13820. ry = right[1],
  13821. fx = (lx + rx) / 2,
  13822. fy = (ly + ry) / 2,
  13823. fm,
  13824. fb;
  13825. if (ry === ly) {
  13826. if (fx < x0 || fx >= x1) return;
  13827. if (lx > rx) {
  13828. if (!v0) v0 = [fx, y0];
  13829. else if (v0[1] >= y1) return;
  13830. v1 = [fx, y1];
  13831. } else {
  13832. if (!v0) v0 = [fx, y1];
  13833. else if (v0[1] < y0) return;
  13834. v1 = [fx, y0];
  13835. }
  13836. } else {
  13837. fm = (lx - rx) / (ry - ly);
  13838. fb = fy - fm * fx;
  13839. if (fm < -1 || fm > 1) {
  13840. if (lx > rx) {
  13841. if (!v0) v0 = [(y0 - fb) / fm, y0];
  13842. else if (v0[1] >= y1) return;
  13843. v1 = [(y1 - fb) / fm, y1];
  13844. } else {
  13845. if (!v0) v0 = [(y1 - fb) / fm, y1];
  13846. else if (v0[1] < y0) return;
  13847. v1 = [(y0 - fb) / fm, y0];
  13848. }
  13849. } else {
  13850. if (ly < ry) {
  13851. if (!v0) v0 = [x0, fm * x0 + fb];
  13852. else if (v0[0] >= x1) return;
  13853. v1 = [x1, fm * x1 + fb];
  13854. } else {
  13855. if (!v0) v0 = [x1, fm * x1 + fb];
  13856. else if (v0[0] < x0) return;
  13857. v1 = [x0, fm * x0 + fb];
  13858. }
  13859. }
  13860. }
  13861. edge[0] = v0;
  13862. edge[1] = v1;
  13863. return true;
  13864. }
  13865. function clipEdges(x0, y0, x1, y1) {
  13866. var i = edges.length,
  13867. edge;
  13868. while (i--) {
  13869. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  13870. || !clipEdge(edge, x0, y0, x1, y1)
  13871. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  13872. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  13873. delete edges[i];
  13874. }
  13875. }
  13876. }
  13877. function createCell(site) {
  13878. return cells[site.index] = {
  13879. site: site,
  13880. halfedges: []
  13881. };
  13882. }
  13883. function cellHalfedgeAngle(cell, edge) {
  13884. var site = cell.site,
  13885. va = edge.left,
  13886. vb = edge.right;
  13887. if (site === vb) vb = va, va = site;
  13888. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  13889. if (site === va) va = edge[1], vb = edge[0];
  13890. else va = edge[0], vb = edge[1];
  13891. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  13892. }
  13893. function cellHalfedgeStart(cell, edge) {
  13894. return edge[+(edge.left !== cell.site)];
  13895. }
  13896. function cellHalfedgeEnd(cell, edge) {
  13897. return edge[+(edge.left === cell.site)];
  13898. }
  13899. function sortCellHalfedges() {
  13900. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  13901. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  13902. var index = new Array(m),
  13903. array = new Array(m);
  13904. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  13905. index.sort(function(i, j) { return array[j] - array[i]; });
  13906. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  13907. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  13908. }
  13909. }
  13910. }
  13911. function clipCells(x0, y0, x1, y1) {
  13912. var nCells = cells.length,
  13913. iCell,
  13914. cell,
  13915. site,
  13916. iHalfedge,
  13917. halfedges,
  13918. nHalfedges,
  13919. start,
  13920. startX,
  13921. startY,
  13922. end,
  13923. endX,
  13924. endY,
  13925. cover = true;
  13926. for (iCell = 0; iCell < nCells; ++iCell) {
  13927. if (cell = cells[iCell]) {
  13928. site = cell.site;
  13929. halfedges = cell.halfedges;
  13930. iHalfedge = halfedges.length;
  13931. // Remove any dangling clipped edges.
  13932. while (iHalfedge--) {
  13933. if (!edges[halfedges[iHalfedge]]) {
  13934. halfedges.splice(iHalfedge, 1);
  13935. }
  13936. }
  13937. // Insert any border edges as necessary.
  13938. iHalfedge = 0, nHalfedges = halfedges.length;
  13939. while (iHalfedge < nHalfedges) {
  13940. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  13941. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  13942. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  13943. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  13944. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  13945. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  13946. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  13947. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  13948. : null)) - 1);
  13949. ++nHalfedges;
  13950. }
  13951. }
  13952. if (nHalfedges) cover = false;
  13953. }
  13954. }
  13955. // If there weren’t any edges, have the closest site cover the extent.
  13956. // It doesn’t matter which corner of the extent we measure!
  13957. if (cover) {
  13958. var dx, dy, d2, dc = Infinity;
  13959. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  13960. if (cell = cells[iCell]) {
  13961. site = cell.site;
  13962. dx = site[0] - x0;
  13963. dy = site[1] - y0;
  13964. d2 = dx * dx + dy * dy;
  13965. if (d2 < dc) dc = d2, cover = cell;
  13966. }
  13967. }
  13968. if (cover) {
  13969. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  13970. cover.halfedges.push(
  13971. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  13972. edges.push(createBorderEdge(site, v01, v11)) - 1,
  13973. edges.push(createBorderEdge(site, v11, v10)) - 1,
  13974. edges.push(createBorderEdge(site, v10, v00)) - 1
  13975. );
  13976. }
  13977. }
  13978. // Lastly delete any cells with no edges; these were entirely clipped.
  13979. for (iCell = 0; iCell < nCells; ++iCell) {
  13980. if (cell = cells[iCell]) {
  13981. if (!cell.halfedges.length) {
  13982. delete cells[iCell];
  13983. }
  13984. }
  13985. }
  13986. }
  13987. var circlePool = [];
  13988. var firstCircle;
  13989. function Circle() {
  13990. RedBlackNode(this);
  13991. this.x =
  13992. this.y =
  13993. this.arc =
  13994. this.site =
  13995. this.cy = null;
  13996. }
  13997. function attachCircle(arc) {
  13998. var lArc = arc.P,
  13999. rArc = arc.N;
  14000. if (!lArc || !rArc) return;
  14001. var lSite = lArc.site,
  14002. cSite = arc.site,
  14003. rSite = rArc.site;
  14004. if (lSite === rSite) return;
  14005. var bx = cSite[0],
  14006. by = cSite[1],
  14007. ax = lSite[0] - bx,
  14008. ay = lSite[1] - by,
  14009. cx = rSite[0] - bx,
  14010. cy = rSite[1] - by;
  14011. var d = 2 * (ax * cy - ay * cx);
  14012. if (d >= -epsilon2$2) return;
  14013. var ha = ax * ax + ay * ay,
  14014. hc = cx * cx + cy * cy,
  14015. x = (cy * ha - ay * hc) / d,
  14016. y = (ax * hc - cx * ha) / d;
  14017. var circle = circlePool.pop() || new Circle;
  14018. circle.arc = arc;
  14019. circle.site = cSite;
  14020. circle.x = x + bx;
  14021. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  14022. arc.circle = circle;
  14023. var before = null,
  14024. node = circles._;
  14025. while (node) {
  14026. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  14027. if (node.L) node = node.L;
  14028. else { before = node.P; break; }
  14029. } else {
  14030. if (node.R) node = node.R;
  14031. else { before = node; break; }
  14032. }
  14033. }
  14034. circles.insert(before, circle);
  14035. if (!before) firstCircle = circle;
  14036. }
  14037. function detachCircle(arc) {
  14038. var circle = arc.circle;
  14039. if (circle) {
  14040. if (!circle.P) firstCircle = circle.N;
  14041. circles.remove(circle);
  14042. circlePool.push(circle);
  14043. RedBlackNode(circle);
  14044. arc.circle = null;
  14045. }
  14046. }
  14047. var beachPool = [];
  14048. function Beach() {
  14049. RedBlackNode(this);
  14050. this.edge =
  14051. this.site =
  14052. this.circle = null;
  14053. }
  14054. function createBeach(site) {
  14055. var beach = beachPool.pop() || new Beach;
  14056. beach.site = site;
  14057. return beach;
  14058. }
  14059. function detachBeach(beach) {
  14060. detachCircle(beach);
  14061. beaches.remove(beach);
  14062. beachPool.push(beach);
  14063. RedBlackNode(beach);
  14064. }
  14065. function removeBeach(beach) {
  14066. var circle = beach.circle,
  14067. x = circle.x,
  14068. y = circle.cy,
  14069. vertex = [x, y],
  14070. previous = beach.P,
  14071. next = beach.N,
  14072. disappearing = [beach];
  14073. detachBeach(beach);
  14074. var lArc = previous;
  14075. while (lArc.circle
  14076. && Math.abs(x - lArc.circle.x) < epsilon$4
  14077. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  14078. previous = lArc.P;
  14079. disappearing.unshift(lArc);
  14080. detachBeach(lArc);
  14081. lArc = previous;
  14082. }
  14083. disappearing.unshift(lArc);
  14084. detachCircle(lArc);
  14085. var rArc = next;
  14086. while (rArc.circle
  14087. && Math.abs(x - rArc.circle.x) < epsilon$4
  14088. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  14089. next = rArc.N;
  14090. disappearing.push(rArc);
  14091. detachBeach(rArc);
  14092. rArc = next;
  14093. }
  14094. disappearing.push(rArc);
  14095. detachCircle(rArc);
  14096. var nArcs = disappearing.length,
  14097. iArc;
  14098. for (iArc = 1; iArc < nArcs; ++iArc) {
  14099. rArc = disappearing[iArc];
  14100. lArc = disappearing[iArc - 1];
  14101. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  14102. }
  14103. lArc = disappearing[0];
  14104. rArc = disappearing[nArcs - 1];
  14105. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  14106. attachCircle(lArc);
  14107. attachCircle(rArc);
  14108. }
  14109. function addBeach(site) {
  14110. var x = site[0],
  14111. directrix = site[1],
  14112. lArc,
  14113. rArc,
  14114. dxl,
  14115. dxr,
  14116. node = beaches._;
  14117. while (node) {
  14118. dxl = leftBreakPoint(node, directrix) - x;
  14119. if (dxl > epsilon$4) node = node.L; else {
  14120. dxr = x - rightBreakPoint(node, directrix);
  14121. if (dxr > epsilon$4) {
  14122. if (!node.R) {
  14123. lArc = node;
  14124. break;
  14125. }
  14126. node = node.R;
  14127. } else {
  14128. if (dxl > -epsilon$4) {
  14129. lArc = node.P;
  14130. rArc = node;
  14131. } else if (dxr > -epsilon$4) {
  14132. lArc = node;
  14133. rArc = node.N;
  14134. } else {
  14135. lArc = rArc = node;
  14136. }
  14137. break;
  14138. }
  14139. }
  14140. }
  14141. createCell(site);
  14142. var newArc = createBeach(site);
  14143. beaches.insert(lArc, newArc);
  14144. if (!lArc && !rArc) return;
  14145. if (lArc === rArc) {
  14146. detachCircle(lArc);
  14147. rArc = createBeach(lArc.site);
  14148. beaches.insert(newArc, rArc);
  14149. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  14150. attachCircle(lArc);
  14151. attachCircle(rArc);
  14152. return;
  14153. }
  14154. if (!rArc) { // && lArc
  14155. newArc.edge = createEdge(lArc.site, newArc.site);
  14156. return;
  14157. }
  14158. // else lArc !== rArc
  14159. detachCircle(lArc);
  14160. detachCircle(rArc);
  14161. var lSite = lArc.site,
  14162. ax = lSite[0],
  14163. ay = lSite[1],
  14164. bx = site[0] - ax,
  14165. by = site[1] - ay,
  14166. rSite = rArc.site,
  14167. cx = rSite[0] - ax,
  14168. cy = rSite[1] - ay,
  14169. d = 2 * (bx * cy - by * cx),
  14170. hb = bx * bx + by * by,
  14171. hc = cx * cx + cy * cy,
  14172. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  14173. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  14174. newArc.edge = createEdge(lSite, site, null, vertex);
  14175. rArc.edge = createEdge(site, rSite, null, vertex);
  14176. attachCircle(lArc);
  14177. attachCircle(rArc);
  14178. }
  14179. function leftBreakPoint(arc, directrix) {
  14180. var site = arc.site,
  14181. rfocx = site[0],
  14182. rfocy = site[1],
  14183. pby2 = rfocy - directrix;
  14184. if (!pby2) return rfocx;
  14185. var lArc = arc.P;
  14186. if (!lArc) return -Infinity;
  14187. site = lArc.site;
  14188. var lfocx = site[0],
  14189. lfocy = site[1],
  14190. plby2 = lfocy - directrix;
  14191. if (!plby2) return lfocx;
  14192. var hl = lfocx - rfocx,
  14193. aby2 = 1 / pby2 - 1 / plby2,
  14194. b = hl / plby2;
  14195. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  14196. return (rfocx + lfocx) / 2;
  14197. }
  14198. function rightBreakPoint(arc, directrix) {
  14199. var rArc = arc.N;
  14200. if (rArc) return leftBreakPoint(rArc, directrix);
  14201. var site = arc.site;
  14202. return site[1] === directrix ? site[0] : Infinity;
  14203. }
  14204. var epsilon$4 = 1e-6;
  14205. var epsilon2$2 = 1e-12;
  14206. var beaches;
  14207. var cells;
  14208. var circles;
  14209. var edges;
  14210. function triangleArea(a, b, c) {
  14211. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  14212. }
  14213. function lexicographic(a, b) {
  14214. return b[1] - a[1]
  14215. || b[0] - a[0];
  14216. }
  14217. function Diagram(sites, extent) {
  14218. var site = sites.sort(lexicographic).pop(),
  14219. x,
  14220. y,
  14221. circle;
  14222. edges = [];
  14223. cells = new Array(sites.length);
  14224. beaches = new RedBlackTree;
  14225. circles = new RedBlackTree;
  14226. while (true) {
  14227. circle = firstCircle;
  14228. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  14229. if (site[0] !== x || site[1] !== y) {
  14230. addBeach(site);
  14231. x = site[0], y = site[1];
  14232. }
  14233. site = sites.pop();
  14234. } else if (circle) {
  14235. removeBeach(circle.arc);
  14236. } else {
  14237. break;
  14238. }
  14239. }
  14240. sortCellHalfedges();
  14241. if (extent) {
  14242. var x0 = +extent[0][0],
  14243. y0 = +extent[0][1],
  14244. x1 = +extent[1][0],
  14245. y1 = +extent[1][1];
  14246. clipEdges(x0, y0, x1, y1);
  14247. clipCells(x0, y0, x1, y1);
  14248. }
  14249. this.edges = edges;
  14250. this.cells = cells;
  14251. beaches =
  14252. circles =
  14253. edges =
  14254. cells = null;
  14255. }
  14256. Diagram.prototype = {
  14257. constructor: Diagram,
  14258. polygons: function() {
  14259. var edges = this.edges;
  14260. return this.cells.map(function(cell) {
  14261. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  14262. polygon.data = cell.site.data;
  14263. return polygon;
  14264. });
  14265. },
  14266. triangles: function() {
  14267. var triangles = [],
  14268. edges = this.edges;
  14269. this.cells.forEach(function(cell, i) {
  14270. if (!(m = (halfedges = cell.halfedges).length)) return;
  14271. var site = cell.site,
  14272. halfedges,
  14273. j = -1,
  14274. m,
  14275. s0,
  14276. e1 = edges[halfedges[m - 1]],
  14277. s1 = e1.left === site ? e1.right : e1.left;
  14278. while (++j < m) {
  14279. s0 = s1;
  14280. e1 = edges[halfedges[j]];
  14281. s1 = e1.left === site ? e1.right : e1.left;
  14282. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  14283. triangles.push([site.data, s0.data, s1.data]);
  14284. }
  14285. }
  14286. });
  14287. return triangles;
  14288. },
  14289. links: function() {
  14290. return this.edges.filter(function(edge) {
  14291. return edge.right;
  14292. }).map(function(edge) {
  14293. return {
  14294. source: edge.left.data,
  14295. target: edge.right.data
  14296. };
  14297. });
  14298. },
  14299. find: function(x, y, radius) {
  14300. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  14301. // Use the previously-found cell, or start with an arbitrary one.
  14302. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  14303. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  14304. // Traverse the half-edges to find a closer cell, if any.
  14305. do {
  14306. cell = that.cells[i0 = i1], i1 = null;
  14307. cell.halfedges.forEach(function(e) {
  14308. var edge = that.edges[e], v = edge.left;
  14309. if ((v === cell.site || !v) && !(v = edge.right)) return;
  14310. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  14311. if (v2 < d2) d2 = v2, i1 = v.index;
  14312. });
  14313. } while (i1 !== null);
  14314. that._found = i0;
  14315. return radius == null || d2 <= radius * radius ? cell.site : null;
  14316. }
  14317. };
  14318. function voronoi() {
  14319. var x$$1 = x$4,
  14320. y$$1 = y$4,
  14321. extent = null;
  14322. function voronoi(data) {
  14323. return new Diagram(data.map(function(d, i) {
  14324. var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
  14325. s.index = i;
  14326. s.data = d;
  14327. return s;
  14328. }), extent);
  14329. }
  14330. voronoi.polygons = function(data) {
  14331. return voronoi(data).polygons();
  14332. };
  14333. voronoi.links = function(data) {
  14334. return voronoi(data).links();
  14335. };
  14336. voronoi.triangles = function(data) {
  14337. return voronoi(data).triangles();
  14338. };
  14339. voronoi.x = function(_) {
  14340. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : x$$1;
  14341. };
  14342. voronoi.y = function(_) {
  14343. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : y$$1;
  14344. };
  14345. voronoi.extent = function(_) {
  14346. 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]]];
  14347. };
  14348. voronoi.size = function(_) {
  14349. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  14350. };
  14351. return voronoi;
  14352. }
  14353. function constant$13(x) {
  14354. return function() {
  14355. return x;
  14356. };
  14357. }
  14358. function ZoomEvent(target, type, transform) {
  14359. this.target = target;
  14360. this.type = type;
  14361. this.transform = transform;
  14362. }
  14363. function Transform(k, x, y) {
  14364. this.k = k;
  14365. this.x = x;
  14366. this.y = y;
  14367. }
  14368. Transform.prototype = {
  14369. constructor: Transform,
  14370. scale: function(k) {
  14371. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  14372. },
  14373. translate: function(x, y) {
  14374. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  14375. },
  14376. apply: function(point) {
  14377. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  14378. },
  14379. applyX: function(x) {
  14380. return x * this.k + this.x;
  14381. },
  14382. applyY: function(y) {
  14383. return y * this.k + this.y;
  14384. },
  14385. invert: function(location) {
  14386. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  14387. },
  14388. invertX: function(x) {
  14389. return (x - this.x) / this.k;
  14390. },
  14391. invertY: function(y) {
  14392. return (y - this.y) / this.k;
  14393. },
  14394. rescaleX: function(x) {
  14395. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  14396. },
  14397. rescaleY: function(y) {
  14398. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  14399. },
  14400. toString: function() {
  14401. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  14402. }
  14403. };
  14404. var identity$8 = new Transform(1, 0, 0);
  14405. transform$1.prototype = Transform.prototype;
  14406. function transform$1(node) {
  14407. return node.__zoom || identity$8;
  14408. }
  14409. function nopropagation$2() {
  14410. exports.event.stopImmediatePropagation();
  14411. }
  14412. function noevent$2() {
  14413. exports.event.preventDefault();
  14414. exports.event.stopImmediatePropagation();
  14415. }
  14416. // Ignore right-click, since that should open the context menu.
  14417. function defaultFilter$2() {
  14418. return !exports.event.button;
  14419. }
  14420. function defaultExtent$1() {
  14421. var e = this, w, h;
  14422. if (e instanceof SVGElement) {
  14423. e = e.ownerSVGElement || e;
  14424. w = e.width.baseVal.value;
  14425. h = e.height.baseVal.value;
  14426. } else {
  14427. w = e.clientWidth;
  14428. h = e.clientHeight;
  14429. }
  14430. return [[0, 0], [w, h]];
  14431. }
  14432. function defaultTransform() {
  14433. return this.__zoom || identity$8;
  14434. }
  14435. function defaultWheelDelta() {
  14436. return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
  14437. }
  14438. function defaultTouchable$1() {
  14439. return "ontouchstart" in this;
  14440. }
  14441. function defaultConstrain(transform, extent, translateExtent) {
  14442. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  14443. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  14444. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  14445. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  14446. return transform.translate(
  14447. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  14448. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  14449. );
  14450. }
  14451. function zoom() {
  14452. var filter = defaultFilter$2,
  14453. extent = defaultExtent$1,
  14454. constrain = defaultConstrain,
  14455. wheelDelta = defaultWheelDelta,
  14456. touchable = defaultTouchable$1,
  14457. scaleExtent = [0, Infinity],
  14458. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  14459. duration = 250,
  14460. interpolate = interpolateZoom,
  14461. gestures = [],
  14462. listeners = dispatch("start", "zoom", "end"),
  14463. touchstarting,
  14464. touchending,
  14465. touchDelay = 500,
  14466. wheelDelay = 150,
  14467. clickDistance2 = 0;
  14468. function zoom(selection$$1) {
  14469. selection$$1
  14470. .property("__zoom", defaultTransform)
  14471. .on("wheel.zoom", wheeled)
  14472. .on("mousedown.zoom", mousedowned)
  14473. .on("dblclick.zoom", dblclicked)
  14474. .filter(touchable)
  14475. .on("touchstart.zoom", touchstarted)
  14476. .on("touchmove.zoom", touchmoved)
  14477. .on("touchend.zoom touchcancel.zoom", touchended)
  14478. .style("touch-action", "none")
  14479. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  14480. }
  14481. zoom.transform = function(collection, transform) {
  14482. var selection$$1 = collection.selection ? collection.selection() : collection;
  14483. selection$$1.property("__zoom", defaultTransform);
  14484. if (collection !== selection$$1) {
  14485. schedule(collection, transform);
  14486. } else {
  14487. selection$$1.interrupt().each(function() {
  14488. gesture(this, arguments)
  14489. .start()
  14490. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  14491. .end();
  14492. });
  14493. }
  14494. };
  14495. zoom.scaleBy = function(selection$$1, k) {
  14496. zoom.scaleTo(selection$$1, function() {
  14497. var k0 = this.__zoom.k,
  14498. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14499. return k0 * k1;
  14500. });
  14501. };
  14502. zoom.scaleTo = function(selection$$1, k) {
  14503. zoom.transform(selection$$1, function() {
  14504. var e = extent.apply(this, arguments),
  14505. t0 = this.__zoom,
  14506. p0 = centroid(e),
  14507. p1 = t0.invert(p0),
  14508. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14509. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  14510. });
  14511. };
  14512. zoom.translateBy = function(selection$$1, x, y) {
  14513. zoom.transform(selection$$1, function() {
  14514. return constrain(this.__zoom.translate(
  14515. typeof x === "function" ? x.apply(this, arguments) : x,
  14516. typeof y === "function" ? y.apply(this, arguments) : y
  14517. ), extent.apply(this, arguments), translateExtent);
  14518. });
  14519. };
  14520. zoom.translateTo = function(selection$$1, x, y) {
  14521. zoom.transform(selection$$1, function() {
  14522. var e = extent.apply(this, arguments),
  14523. t = this.__zoom,
  14524. p = centroid(e);
  14525. return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
  14526. typeof x === "function" ? -x.apply(this, arguments) : -x,
  14527. typeof y === "function" ? -y.apply(this, arguments) : -y
  14528. ), e, translateExtent);
  14529. });
  14530. };
  14531. function scale(transform, k) {
  14532. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  14533. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  14534. }
  14535. function translate(transform, p0, p1) {
  14536. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  14537. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  14538. }
  14539. function centroid(extent) {
  14540. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  14541. }
  14542. function schedule(transition$$1, transform, center) {
  14543. transition$$1
  14544. .on("start.zoom", function() { gesture(this, arguments).start(); })
  14545. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  14546. .tween("zoom", function() {
  14547. var that = this,
  14548. args = arguments,
  14549. g = gesture(that, args),
  14550. e = extent.apply(that, args),
  14551. p = center || centroid(e),
  14552. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  14553. a = that.__zoom,
  14554. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  14555. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  14556. return function(t) {
  14557. if (t === 1) t = b; // Avoid rounding error on end.
  14558. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  14559. g.zoom(null, t);
  14560. };
  14561. });
  14562. }
  14563. function gesture(that, args) {
  14564. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  14565. if ((g = gestures[i]).that === that) {
  14566. return g;
  14567. }
  14568. }
  14569. return new Gesture(that, args);
  14570. }
  14571. function Gesture(that, args) {
  14572. this.that = that;
  14573. this.args = args;
  14574. this.index = -1;
  14575. this.active = 0;
  14576. this.extent = extent.apply(that, args);
  14577. }
  14578. Gesture.prototype = {
  14579. start: function() {
  14580. if (++this.active === 1) {
  14581. this.index = gestures.push(this) - 1;
  14582. this.emit("start");
  14583. }
  14584. return this;
  14585. },
  14586. zoom: function(key, transform) {
  14587. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  14588. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  14589. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  14590. this.that.__zoom = transform;
  14591. this.emit("zoom");
  14592. return this;
  14593. },
  14594. end: function() {
  14595. if (--this.active === 0) {
  14596. gestures.splice(this.index, 1);
  14597. this.index = -1;
  14598. this.emit("end");
  14599. }
  14600. return this;
  14601. },
  14602. emit: function(type) {
  14603. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  14604. }
  14605. };
  14606. function wheeled() {
  14607. if (!filter.apply(this, arguments)) return;
  14608. var g = gesture(this, arguments),
  14609. t = this.__zoom,
  14610. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  14611. p = mouse(this);
  14612. // If the mouse is in the same location as before, reuse it.
  14613. // If there were recent wheel events, reset the wheel idle timeout.
  14614. if (g.wheel) {
  14615. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  14616. g.mouse[1] = t.invert(g.mouse[0] = p);
  14617. }
  14618. clearTimeout(g.wheel);
  14619. }
  14620. // If this wheel event won’t trigger a transform change, ignore it.
  14621. else if (t.k === k) return;
  14622. // Otherwise, capture the mouse point and location at the start.
  14623. else {
  14624. g.mouse = [p, t.invert(p)];
  14625. interrupt(this);
  14626. g.start();
  14627. }
  14628. noevent$2();
  14629. g.wheel = setTimeout(wheelidled, wheelDelay);
  14630. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  14631. function wheelidled() {
  14632. g.wheel = null;
  14633. g.end();
  14634. }
  14635. }
  14636. function mousedowned() {
  14637. if (touchending || !filter.apply(this, arguments)) return;
  14638. var g = gesture(this, arguments),
  14639. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  14640. p = mouse(this),
  14641. x0 = exports.event.clientX,
  14642. y0 = exports.event.clientY;
  14643. dragDisable(exports.event.view);
  14644. nopropagation$2();
  14645. g.mouse = [p, this.__zoom.invert(p)];
  14646. interrupt(this);
  14647. g.start();
  14648. function mousemoved() {
  14649. noevent$2();
  14650. if (!g.moved) {
  14651. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  14652. g.moved = dx * dx + dy * dy > clickDistance2;
  14653. }
  14654. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  14655. }
  14656. function mouseupped() {
  14657. v.on("mousemove.zoom mouseup.zoom", null);
  14658. yesdrag(exports.event.view, g.moved);
  14659. noevent$2();
  14660. g.end();
  14661. }
  14662. }
  14663. function dblclicked() {
  14664. if (!filter.apply(this, arguments)) return;
  14665. var t0 = this.__zoom,
  14666. p0 = mouse(this),
  14667. p1 = t0.invert(p0),
  14668. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  14669. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  14670. noevent$2();
  14671. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  14672. else select(this).call(zoom.transform, t1);
  14673. }
  14674. function touchstarted() {
  14675. if (!filter.apply(this, arguments)) return;
  14676. var g = gesture(this, arguments),
  14677. touches$$1 = exports.event.changedTouches,
  14678. started,
  14679. n = touches$$1.length, i, t, p;
  14680. nopropagation$2();
  14681. for (i = 0; i < n; ++i) {
  14682. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14683. p = [p, this.__zoom.invert(p), t.identifier];
  14684. if (!g.touch0) g.touch0 = p, started = true;
  14685. else if (!g.touch1) g.touch1 = p;
  14686. }
  14687. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  14688. if (touchstarting) {
  14689. touchstarting = clearTimeout(touchstarting);
  14690. if (!g.touch1) {
  14691. g.end();
  14692. p = select(this).on("dblclick.zoom");
  14693. if (p) p.apply(this, arguments);
  14694. return;
  14695. }
  14696. }
  14697. if (started) {
  14698. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  14699. interrupt(this);
  14700. g.start();
  14701. }
  14702. }
  14703. function touchmoved() {
  14704. var g = gesture(this, arguments),
  14705. touches$$1 = exports.event.changedTouches,
  14706. n = touches$$1.length, i, t, p, l;
  14707. noevent$2();
  14708. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  14709. for (i = 0; i < n; ++i) {
  14710. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14711. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  14712. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  14713. }
  14714. t = g.that.__zoom;
  14715. if (g.touch1) {
  14716. var p0 = g.touch0[0], l0 = g.touch0[1],
  14717. p1 = g.touch1[0], l1 = g.touch1[1],
  14718. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  14719. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  14720. t = scale(t, Math.sqrt(dp / dl));
  14721. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  14722. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  14723. }
  14724. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  14725. else return;
  14726. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  14727. }
  14728. function touchended() {
  14729. var g = gesture(this, arguments),
  14730. touches$$1 = exports.event.changedTouches,
  14731. n = touches$$1.length, i, t;
  14732. nopropagation$2();
  14733. if (touchending) clearTimeout(touchending);
  14734. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  14735. for (i = 0; i < n; ++i) {
  14736. t = touches$$1[i];
  14737. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  14738. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  14739. }
  14740. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  14741. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  14742. else g.end();
  14743. }
  14744. zoom.wheelDelta = function(_) {
  14745. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$13(+_), zoom) : wheelDelta;
  14746. };
  14747. zoom.filter = function(_) {
  14748. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$13(!!_), zoom) : filter;
  14749. };
  14750. zoom.touchable = function(_) {
  14751. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$13(!!_), zoom) : touchable;
  14752. };
  14753. zoom.extent = function(_) {
  14754. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$13([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  14755. };
  14756. zoom.scaleExtent = function(_) {
  14757. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  14758. };
  14759. zoom.translateExtent = function(_) {
  14760. 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]]];
  14761. };
  14762. zoom.constrain = function(_) {
  14763. return arguments.length ? (constrain = _, zoom) : constrain;
  14764. };
  14765. zoom.duration = function(_) {
  14766. return arguments.length ? (duration = +_, zoom) : duration;
  14767. };
  14768. zoom.interpolate = function(_) {
  14769. return arguments.length ? (interpolate = _, zoom) : interpolate;
  14770. };
  14771. zoom.on = function() {
  14772. var value = listeners.on.apply(listeners, arguments);
  14773. return value === listeners ? zoom : value;
  14774. };
  14775. zoom.clickDistance = function(_) {
  14776. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  14777. };
  14778. return zoom;
  14779. }
  14780. exports.version = version;
  14781. exports.bisect = bisectRight;
  14782. exports.bisectRight = bisectRight;
  14783. exports.bisectLeft = bisectLeft;
  14784. exports.ascending = ascending;
  14785. exports.bisector = bisector;
  14786. exports.cross = cross;
  14787. exports.descending = descending;
  14788. exports.deviation = deviation;
  14789. exports.extent = extent;
  14790. exports.histogram = histogram;
  14791. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  14792. exports.thresholdScott = scott;
  14793. exports.thresholdSturges = thresholdSturges;
  14794. exports.max = max;
  14795. exports.mean = mean;
  14796. exports.median = median;
  14797. exports.merge = merge;
  14798. exports.min = min;
  14799. exports.pairs = pairs;
  14800. exports.permute = permute;
  14801. exports.quantile = threshold;
  14802. exports.range = sequence;
  14803. exports.scan = scan;
  14804. exports.shuffle = shuffle;
  14805. exports.sum = sum;
  14806. exports.ticks = ticks;
  14807. exports.tickIncrement = tickIncrement;
  14808. exports.tickStep = tickStep;
  14809. exports.transpose = transpose;
  14810. exports.variance = variance;
  14811. exports.zip = zip;
  14812. exports.axisTop = axisTop;
  14813. exports.axisRight = axisRight;
  14814. exports.axisBottom = axisBottom;
  14815. exports.axisLeft = axisLeft;
  14816. exports.brush = brush;
  14817. exports.brushX = brushX;
  14818. exports.brushY = brushY;
  14819. exports.brushSelection = brushSelection;
  14820. exports.chord = chord;
  14821. exports.ribbon = ribbon;
  14822. exports.nest = nest;
  14823. exports.set = set$2;
  14824. exports.map = map$1;
  14825. exports.keys = keys;
  14826. exports.values = values;
  14827. exports.entries = entries;
  14828. exports.color = color;
  14829. exports.rgb = rgb;
  14830. exports.hsl = hsl;
  14831. exports.lab = lab;
  14832. exports.hcl = hcl;
  14833. exports.lch = lch;
  14834. exports.gray = gray;
  14835. exports.cubehelix = cubehelix;
  14836. exports.contours = contours;
  14837. exports.contourDensity = density;
  14838. exports.dispatch = dispatch;
  14839. exports.drag = drag;
  14840. exports.dragDisable = dragDisable;
  14841. exports.dragEnable = yesdrag;
  14842. exports.dsvFormat = dsvFormat;
  14843. exports.csvParse = csvParse;
  14844. exports.csvParseRows = csvParseRows;
  14845. exports.csvFormat = csvFormat;
  14846. exports.csvFormatRows = csvFormatRows;
  14847. exports.tsvParse = tsvParse;
  14848. exports.tsvParseRows = tsvParseRows;
  14849. exports.tsvFormat = tsvFormat;
  14850. exports.tsvFormatRows = tsvFormatRows;
  14851. exports.easeLinear = linear$1;
  14852. exports.easeQuad = quadInOut;
  14853. exports.easeQuadIn = quadIn;
  14854. exports.easeQuadOut = quadOut;
  14855. exports.easeQuadInOut = quadInOut;
  14856. exports.easeCubic = cubicInOut;
  14857. exports.easeCubicIn = cubicIn;
  14858. exports.easeCubicOut = cubicOut;
  14859. exports.easeCubicInOut = cubicInOut;
  14860. exports.easePoly = polyInOut;
  14861. exports.easePolyIn = polyIn;
  14862. exports.easePolyOut = polyOut;
  14863. exports.easePolyInOut = polyInOut;
  14864. exports.easeSin = sinInOut;
  14865. exports.easeSinIn = sinIn;
  14866. exports.easeSinOut = sinOut;
  14867. exports.easeSinInOut = sinInOut;
  14868. exports.easeExp = expInOut;
  14869. exports.easeExpIn = expIn;
  14870. exports.easeExpOut = expOut;
  14871. exports.easeExpInOut = expInOut;
  14872. exports.easeCircle = circleInOut;
  14873. exports.easeCircleIn = circleIn;
  14874. exports.easeCircleOut = circleOut;
  14875. exports.easeCircleInOut = circleInOut;
  14876. exports.easeBounce = bounceOut;
  14877. exports.easeBounceIn = bounceIn;
  14878. exports.easeBounceOut = bounceOut;
  14879. exports.easeBounceInOut = bounceInOut;
  14880. exports.easeBack = backInOut;
  14881. exports.easeBackIn = backIn;
  14882. exports.easeBackOut = backOut;
  14883. exports.easeBackInOut = backInOut;
  14884. exports.easeElastic = elasticOut;
  14885. exports.easeElasticIn = elasticIn;
  14886. exports.easeElasticOut = elasticOut;
  14887. exports.easeElasticInOut = elasticInOut;
  14888. exports.blob = blob;
  14889. exports.buffer = buffer;
  14890. exports.dsv = dsv;
  14891. exports.csv = csv$1;
  14892. exports.tsv = tsv$1;
  14893. exports.image = image;
  14894. exports.json = json;
  14895. exports.text = text;
  14896. exports.xml = xml;
  14897. exports.html = html;
  14898. exports.svg = svg;
  14899. exports.forceCenter = center$1;
  14900. exports.forceCollide = collide;
  14901. exports.forceLink = link;
  14902. exports.forceManyBody = manyBody;
  14903. exports.forceRadial = radial;
  14904. exports.forceSimulation = simulation;
  14905. exports.forceX = x$2;
  14906. exports.forceY = y$2;
  14907. exports.formatDefaultLocale = defaultLocale;
  14908. exports.formatLocale = formatLocale;
  14909. exports.formatSpecifier = formatSpecifier;
  14910. exports.precisionFixed = precisionFixed;
  14911. exports.precisionPrefix = precisionPrefix;
  14912. exports.precisionRound = precisionRound;
  14913. exports.geoArea = area$1;
  14914. exports.geoBounds = bounds;
  14915. exports.geoCentroid = centroid;
  14916. exports.geoCircle = circle;
  14917. exports.geoClipAntimeridian = clipAntimeridian;
  14918. exports.geoClipCircle = clipCircle;
  14919. exports.geoClipExtent = extent$1;
  14920. exports.geoClipRectangle = clipRectangle;
  14921. exports.geoContains = contains$1;
  14922. exports.geoDistance = distance;
  14923. exports.geoGraticule = graticule;
  14924. exports.geoGraticule10 = graticule10;
  14925. exports.geoInterpolate = interpolate$1;
  14926. exports.geoLength = length$1;
  14927. exports.geoPath = index$1;
  14928. exports.geoAlbers = albers;
  14929. exports.geoAlbersUsa = albersUsa;
  14930. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  14931. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  14932. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  14933. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  14934. exports.geoConicConformal = conicConformal;
  14935. exports.geoConicConformalRaw = conicConformalRaw;
  14936. exports.geoConicEqualArea = conicEqualArea;
  14937. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  14938. exports.geoConicEquidistant = conicEquidistant;
  14939. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  14940. exports.geoEquirectangular = equirectangular;
  14941. exports.geoEquirectangularRaw = equirectangularRaw;
  14942. exports.geoGnomonic = gnomonic;
  14943. exports.geoGnomonicRaw = gnomonicRaw;
  14944. exports.geoIdentity = identity$5;
  14945. exports.geoProjection = projection;
  14946. exports.geoProjectionMutator = projectionMutator;
  14947. exports.geoMercator = mercator;
  14948. exports.geoMercatorRaw = mercatorRaw;
  14949. exports.geoNaturalEarth1 = naturalEarth1;
  14950. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  14951. exports.geoOrthographic = orthographic;
  14952. exports.geoOrthographicRaw = orthographicRaw;
  14953. exports.geoStereographic = stereographic;
  14954. exports.geoStereographicRaw = stereographicRaw;
  14955. exports.geoTransverseMercator = transverseMercator;
  14956. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  14957. exports.geoRotation = rotation;
  14958. exports.geoStream = geoStream;
  14959. exports.geoTransform = transform;
  14960. exports.cluster = cluster;
  14961. exports.hierarchy = hierarchy;
  14962. exports.pack = index$2;
  14963. exports.packSiblings = siblings;
  14964. exports.packEnclose = enclose;
  14965. exports.partition = partition;
  14966. exports.stratify = stratify;
  14967. exports.tree = tree;
  14968. exports.treemap = index$3;
  14969. exports.treemapBinary = binary;
  14970. exports.treemapDice = treemapDice;
  14971. exports.treemapSlice = treemapSlice;
  14972. exports.treemapSliceDice = sliceDice;
  14973. exports.treemapSquarify = squarify;
  14974. exports.treemapResquarify = resquarify;
  14975. exports.interpolate = interpolateValue;
  14976. exports.interpolateArray = array$1;
  14977. exports.interpolateBasis = basis$1;
  14978. exports.interpolateBasisClosed = basisClosed;
  14979. exports.interpolateDate = date;
  14980. exports.interpolateNumber = reinterpolate;
  14981. exports.interpolateObject = object;
  14982. exports.interpolateRound = interpolateRound;
  14983. exports.interpolateString = interpolateString;
  14984. exports.interpolateTransformCss = interpolateTransformCss;
  14985. exports.interpolateTransformSvg = interpolateTransformSvg;
  14986. exports.interpolateZoom = interpolateZoom;
  14987. exports.interpolateRgb = interpolateRgb;
  14988. exports.interpolateRgbBasis = rgbBasis;
  14989. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  14990. exports.interpolateHsl = hsl$2;
  14991. exports.interpolateHslLong = hslLong;
  14992. exports.interpolateLab = lab$1;
  14993. exports.interpolateHcl = hcl$2;
  14994. exports.interpolateHclLong = hclLong;
  14995. exports.interpolateCubehelix = cubehelix$2;
  14996. exports.interpolateCubehelixLong = cubehelixLong;
  14997. exports.piecewise = piecewise;
  14998. exports.quantize = quantize;
  14999. exports.path = path;
  15000. exports.polygonArea = area$2;
  15001. exports.polygonCentroid = centroid$1;
  15002. exports.polygonHull = hull;
  15003. exports.polygonContains = contains$2;
  15004. exports.polygonLength = length$2;
  15005. exports.quadtree = quadtree;
  15006. exports.randomUniform = uniform;
  15007. exports.randomNormal = normal;
  15008. exports.randomLogNormal = logNormal;
  15009. exports.randomBates = bates;
  15010. exports.randomIrwinHall = irwinHall;
  15011. exports.randomExponential = exponential$1;
  15012. exports.scaleBand = band;
  15013. exports.scalePoint = point$1;
  15014. exports.scaleIdentity = identity$6;
  15015. exports.scaleLinear = linear$2;
  15016. exports.scaleLog = log$1;
  15017. exports.scaleOrdinal = ordinal;
  15018. exports.scaleImplicit = implicit;
  15019. exports.scalePow = pow$1;
  15020. exports.scaleSqrt = sqrt$1;
  15021. exports.scaleQuantile = quantile$$1;
  15022. exports.scaleQuantize = quantize$1;
  15023. exports.scaleThreshold = threshold$1;
  15024. exports.scaleTime = time;
  15025. exports.scaleUtc = utcTime;
  15026. exports.scaleSequential = sequential;
  15027. exports.scaleDiverging = diverging;
  15028. exports.schemeCategory10 = category10;
  15029. exports.schemeAccent = Accent;
  15030. exports.schemeDark2 = Dark2;
  15031. exports.schemePaired = Paired;
  15032. exports.schemePastel1 = Pastel1;
  15033. exports.schemePastel2 = Pastel2;
  15034. exports.schemeSet1 = Set1;
  15035. exports.schemeSet2 = Set2;
  15036. exports.schemeSet3 = Set3;
  15037. exports.interpolateBrBG = BrBG;
  15038. exports.schemeBrBG = scheme;
  15039. exports.interpolatePRGn = PRGn;
  15040. exports.schemePRGn = scheme$1;
  15041. exports.interpolatePiYG = PiYG;
  15042. exports.schemePiYG = scheme$2;
  15043. exports.interpolatePuOr = PuOr;
  15044. exports.schemePuOr = scheme$3;
  15045. exports.interpolateRdBu = RdBu;
  15046. exports.schemeRdBu = scheme$4;
  15047. exports.interpolateRdGy = RdGy;
  15048. exports.schemeRdGy = scheme$5;
  15049. exports.interpolateRdYlBu = RdYlBu;
  15050. exports.schemeRdYlBu = scheme$6;
  15051. exports.interpolateRdYlGn = RdYlGn;
  15052. exports.schemeRdYlGn = scheme$7;
  15053. exports.interpolateSpectral = Spectral;
  15054. exports.schemeSpectral = scheme$8;
  15055. exports.interpolateBuGn = BuGn;
  15056. exports.schemeBuGn = scheme$9;
  15057. exports.interpolateBuPu = BuPu;
  15058. exports.schemeBuPu = scheme$10;
  15059. exports.interpolateGnBu = GnBu;
  15060. exports.schemeGnBu = scheme$11;
  15061. exports.interpolateOrRd = OrRd;
  15062. exports.schemeOrRd = scheme$12;
  15063. exports.interpolatePuBuGn = PuBuGn;
  15064. exports.schemePuBuGn = scheme$13;
  15065. exports.interpolatePuBu = PuBu;
  15066. exports.schemePuBu = scheme$14;
  15067. exports.interpolatePuRd = PuRd;
  15068. exports.schemePuRd = scheme$15;
  15069. exports.interpolateRdPu = RdPu;
  15070. exports.schemeRdPu = scheme$16;
  15071. exports.interpolateYlGnBu = YlGnBu;
  15072. exports.schemeYlGnBu = scheme$17;
  15073. exports.interpolateYlGn = YlGn;
  15074. exports.schemeYlGn = scheme$18;
  15075. exports.interpolateYlOrBr = YlOrBr;
  15076. exports.schemeYlOrBr = scheme$19;
  15077. exports.interpolateYlOrRd = YlOrRd;
  15078. exports.schemeYlOrRd = scheme$20;
  15079. exports.interpolateBlues = Blues;
  15080. exports.schemeBlues = scheme$21;
  15081. exports.interpolateGreens = Greens;
  15082. exports.schemeGreens = scheme$22;
  15083. exports.interpolateGreys = Greys;
  15084. exports.schemeGreys = scheme$23;
  15085. exports.interpolatePurples = Purples;
  15086. exports.schemePurples = scheme$24;
  15087. exports.interpolateReds = Reds;
  15088. exports.schemeReds = scheme$25;
  15089. exports.interpolateOranges = Oranges;
  15090. exports.schemeOranges = scheme$26;
  15091. exports.interpolateCubehelixDefault = cubehelix$3;
  15092. exports.interpolateRainbow = rainbow;
  15093. exports.interpolateWarm = warm;
  15094. exports.interpolateCool = cool;
  15095. exports.interpolateSinebow = sinebow;
  15096. exports.interpolateViridis = viridis;
  15097. exports.interpolateMagma = magma;
  15098. exports.interpolateInferno = inferno;
  15099. exports.interpolatePlasma = plasma;
  15100. exports.create = create;
  15101. exports.creator = creator;
  15102. exports.local = local;
  15103. exports.matcher = matcher$1;
  15104. exports.mouse = mouse;
  15105. exports.namespace = namespace;
  15106. exports.namespaces = namespaces;
  15107. exports.clientPoint = point;
  15108. exports.select = select;
  15109. exports.selectAll = selectAll;
  15110. exports.selection = selection;
  15111. exports.selector = selector;
  15112. exports.selectorAll = selectorAll;
  15113. exports.style = styleValue;
  15114. exports.touch = touch;
  15115. exports.touches = touches;
  15116. exports.window = defaultView;
  15117. exports.customEvent = customEvent;
  15118. exports.arc = arc;
  15119. exports.area = area$3;
  15120. exports.line = line;
  15121. exports.pie = pie;
  15122. exports.areaRadial = areaRadial;
  15123. exports.radialArea = areaRadial;
  15124. exports.lineRadial = lineRadial$1;
  15125. exports.radialLine = lineRadial$1;
  15126. exports.pointRadial = pointRadial;
  15127. exports.linkHorizontal = linkHorizontal;
  15128. exports.linkVertical = linkVertical;
  15129. exports.linkRadial = linkRadial;
  15130. exports.symbol = symbol;
  15131. exports.symbols = symbols;
  15132. exports.symbolCircle = circle$2;
  15133. exports.symbolCross = cross$2;
  15134. exports.symbolDiamond = diamond;
  15135. exports.symbolSquare = square;
  15136. exports.symbolStar = star;
  15137. exports.symbolTriangle = triangle;
  15138. exports.symbolWye = wye;
  15139. exports.curveBasisClosed = basisClosed$1;
  15140. exports.curveBasisOpen = basisOpen;
  15141. exports.curveBasis = basis$2;
  15142. exports.curveBundle = bundle;
  15143. exports.curveCardinalClosed = cardinalClosed;
  15144. exports.curveCardinalOpen = cardinalOpen;
  15145. exports.curveCardinal = cardinal;
  15146. exports.curveCatmullRomClosed = catmullRomClosed;
  15147. exports.curveCatmullRomOpen = catmullRomOpen;
  15148. exports.curveCatmullRom = catmullRom;
  15149. exports.curveLinearClosed = linearClosed;
  15150. exports.curveLinear = curveLinear;
  15151. exports.curveMonotoneX = monotoneX;
  15152. exports.curveMonotoneY = monotoneY;
  15153. exports.curveNatural = natural;
  15154. exports.curveStep = step;
  15155. exports.curveStepAfter = stepAfter;
  15156. exports.curveStepBefore = stepBefore;
  15157. exports.stack = stack;
  15158. exports.stackOffsetExpand = expand;
  15159. exports.stackOffsetDiverging = diverging$1;
  15160. exports.stackOffsetNone = none$1;
  15161. exports.stackOffsetSilhouette = silhouette;
  15162. exports.stackOffsetWiggle = wiggle;
  15163. exports.stackOrderAscending = ascending$3;
  15164. exports.stackOrderDescending = descending$2;
  15165. exports.stackOrderInsideOut = insideOut;
  15166. exports.stackOrderNone = none$2;
  15167. exports.stackOrderReverse = reverse;
  15168. exports.timeInterval = newInterval;
  15169. exports.timeMillisecond = millisecond;
  15170. exports.timeMilliseconds = milliseconds;
  15171. exports.utcMillisecond = millisecond;
  15172. exports.utcMilliseconds = milliseconds;
  15173. exports.timeSecond = second;
  15174. exports.timeSeconds = seconds;
  15175. exports.utcSecond = second;
  15176. exports.utcSeconds = seconds;
  15177. exports.timeMinute = minute;
  15178. exports.timeMinutes = minutes;
  15179. exports.timeHour = hour;
  15180. exports.timeHours = hours;
  15181. exports.timeDay = day;
  15182. exports.timeDays = days;
  15183. exports.timeWeek = sunday;
  15184. exports.timeWeeks = sundays;
  15185. exports.timeSunday = sunday;
  15186. exports.timeSundays = sundays;
  15187. exports.timeMonday = monday;
  15188. exports.timeMondays = mondays;
  15189. exports.timeTuesday = tuesday;
  15190. exports.timeTuesdays = tuesdays;
  15191. exports.timeWednesday = wednesday;
  15192. exports.timeWednesdays = wednesdays;
  15193. exports.timeThursday = thursday;
  15194. exports.timeThursdays = thursdays;
  15195. exports.timeFriday = friday;
  15196. exports.timeFridays = fridays;
  15197. exports.timeSaturday = saturday;
  15198. exports.timeSaturdays = saturdays;
  15199. exports.timeMonth = month;
  15200. exports.timeMonths = months;
  15201. exports.timeYear = year;
  15202. exports.timeYears = years;
  15203. exports.utcMinute = utcMinute;
  15204. exports.utcMinutes = utcMinutes;
  15205. exports.utcHour = utcHour;
  15206. exports.utcHours = utcHours;
  15207. exports.utcDay = utcDay;
  15208. exports.utcDays = utcDays;
  15209. exports.utcWeek = utcSunday;
  15210. exports.utcWeeks = utcSundays;
  15211. exports.utcSunday = utcSunday;
  15212. exports.utcSundays = utcSundays;
  15213. exports.utcMonday = utcMonday;
  15214. exports.utcMondays = utcMondays;
  15215. exports.utcTuesday = utcTuesday;
  15216. exports.utcTuesdays = utcTuesdays;
  15217. exports.utcWednesday = utcWednesday;
  15218. exports.utcWednesdays = utcWednesdays;
  15219. exports.utcThursday = utcThursday;
  15220. exports.utcThursdays = utcThursdays;
  15221. exports.utcFriday = utcFriday;
  15222. exports.utcFridays = utcFridays;
  15223. exports.utcSaturday = utcSaturday;
  15224. exports.utcSaturdays = utcSaturdays;
  15225. exports.utcMonth = utcMonth;
  15226. exports.utcMonths = utcMonths;
  15227. exports.utcYear = utcYear;
  15228. exports.utcYears = utcYears;
  15229. exports.timeFormatDefaultLocale = defaultLocale$1;
  15230. exports.timeFormatLocale = formatLocale$1;
  15231. exports.isoFormat = formatIso;
  15232. exports.isoParse = parseIso;
  15233. exports.now = now;
  15234. exports.timer = timer;
  15235. exports.timerFlush = timerFlush;
  15236. exports.timeout = timeout$1;
  15237. exports.interval = interval$1;
  15238. exports.transition = transition;
  15239. exports.active = active;
  15240. exports.interrupt = interrupt;
  15241. exports.voronoi = voronoi;
  15242. exports.zoom = zoom;
  15243. exports.zoomTransform = transform$1;
  15244. exports.zoomIdentity = identity$8;
  15245. Object.defineProperty(exports, '__esModule', { value: true });
  15246. })));