d3.js 573 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624
  1. // https://d3js.org v7.8.5 Copyright 2010-2023 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. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
  6. })(this, (function (exports) { 'use strict';
  7. var version = "7.8.5";
  8. function ascending$3(a, b) {
  9. return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function descending$2(a, b) {
  12. return a == null || b == null ? NaN
  13. : b < a ? -1
  14. : b > a ? 1
  15. : b >= a ? 0
  16. : NaN;
  17. }
  18. function bisector(f) {
  19. let compare1, compare2, delta;
  20. // If an accessor is specified, promote it to a comparator. In this case we
  21. // can test whether the search value is (self-) comparable. We can’t do this
  22. // for a comparator (except for specific, known comparators) because we can’t
  23. // tell if the comparator is symmetric, and an asymmetric comparator can’t be
  24. // used to test whether a single value is comparable.
  25. if (f.length !== 2) {
  26. compare1 = ascending$3;
  27. compare2 = (d, x) => ascending$3(f(d), x);
  28. delta = (d, x) => f(d) - x;
  29. } else {
  30. compare1 = f === ascending$3 || f === descending$2 ? f : zero$1;
  31. compare2 = f;
  32. delta = f;
  33. }
  34. function left(a, x, lo = 0, hi = a.length) {
  35. if (lo < hi) {
  36. if (compare1(x, x) !== 0) return hi;
  37. do {
  38. const mid = (lo + hi) >>> 1;
  39. if (compare2(a[mid], x) < 0) lo = mid + 1;
  40. else hi = mid;
  41. } while (lo < hi);
  42. }
  43. return lo;
  44. }
  45. function right(a, x, lo = 0, hi = a.length) {
  46. if (lo < hi) {
  47. if (compare1(x, x) !== 0) return hi;
  48. do {
  49. const mid = (lo + hi) >>> 1;
  50. if (compare2(a[mid], x) <= 0) lo = mid + 1;
  51. else hi = mid;
  52. } while (lo < hi);
  53. }
  54. return lo;
  55. }
  56. function center(a, x, lo = 0, hi = a.length) {
  57. const i = left(a, x, lo, hi - 1);
  58. return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
  59. }
  60. return {left, center, right};
  61. }
  62. function zero$1() {
  63. return 0;
  64. }
  65. function number$3(x) {
  66. return x === null ? NaN : +x;
  67. }
  68. function* numbers(values, valueof) {
  69. if (valueof === undefined) {
  70. for (let value of values) {
  71. if (value != null && (value = +value) >= value) {
  72. yield value;
  73. }
  74. }
  75. } else {
  76. let index = -1;
  77. for (let value of values) {
  78. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  79. yield value;
  80. }
  81. }
  82. }
  83. }
  84. const ascendingBisect = bisector(ascending$3);
  85. const bisectRight = ascendingBisect.right;
  86. const bisectLeft = ascendingBisect.left;
  87. const bisectCenter = bisector(number$3).center;
  88. var bisect = bisectRight;
  89. function blur(values, r) {
  90. if (!((r = +r) >= 0)) throw new RangeError("invalid r");
  91. let length = values.length;
  92. if (!((length = Math.floor(length)) >= 0)) throw new RangeError("invalid length");
  93. if (!length || !r) return values;
  94. const blur = blurf(r);
  95. const temp = values.slice();
  96. blur(values, temp, 0, length, 1);
  97. blur(temp, values, 0, length, 1);
  98. blur(values, temp, 0, length, 1);
  99. return values;
  100. }
  101. const blur2 = Blur2(blurf);
  102. const blurImage = Blur2(blurfImage);
  103. function Blur2(blur) {
  104. return function(data, rx, ry = rx) {
  105. if (!((rx = +rx) >= 0)) throw new RangeError("invalid rx");
  106. if (!((ry = +ry) >= 0)) throw new RangeError("invalid ry");
  107. let {data: values, width, height} = data;
  108. if (!((width = Math.floor(width)) >= 0)) throw new RangeError("invalid width");
  109. if (!((height = Math.floor(height !== undefined ? height : values.length / width)) >= 0)) throw new RangeError("invalid height");
  110. if (!width || !height || (!rx && !ry)) return data;
  111. const blurx = rx && blur(rx);
  112. const blury = ry && blur(ry);
  113. const temp = values.slice();
  114. if (blurx && blury) {
  115. blurh(blurx, temp, values, width, height);
  116. blurh(blurx, values, temp, width, height);
  117. blurh(blurx, temp, values, width, height);
  118. blurv(blury, values, temp, width, height);
  119. blurv(blury, temp, values, width, height);
  120. blurv(blury, values, temp, width, height);
  121. } else if (blurx) {
  122. blurh(blurx, values, temp, width, height);
  123. blurh(blurx, temp, values, width, height);
  124. blurh(blurx, values, temp, width, height);
  125. } else if (blury) {
  126. blurv(blury, values, temp, width, height);
  127. blurv(blury, temp, values, width, height);
  128. blurv(blury, values, temp, width, height);
  129. }
  130. return data;
  131. };
  132. }
  133. function blurh(blur, T, S, w, h) {
  134. for (let y = 0, n = w * h; y < n;) {
  135. blur(T, S, y, y += w, 1);
  136. }
  137. }
  138. function blurv(blur, T, S, w, h) {
  139. for (let x = 0, n = w * h; x < w; ++x) {
  140. blur(T, S, x, x + n, w);
  141. }
  142. }
  143. function blurfImage(radius) {
  144. const blur = blurf(radius);
  145. return (T, S, start, stop, step) => {
  146. start <<= 2, stop <<= 2, step <<= 2;
  147. blur(T, S, start + 0, stop + 0, step);
  148. blur(T, S, start + 1, stop + 1, step);
  149. blur(T, S, start + 2, stop + 2, step);
  150. blur(T, S, start + 3, stop + 3, step);
  151. };
  152. }
  153. // Given a target array T, a source array S, sets each value T[i] to the average
  154. // of {S[i - r], …, S[i], …, S[i + r]}, where r = ⌊radius⌋, start <= i < stop,
  155. // for each i, i + step, i + 2 * step, etc., and where S[j] is clamped between
  156. // S[start] (inclusive) and S[stop] (exclusive). If the given radius is not an
  157. // integer, S[i - r - 1] and S[i + r + 1] are added to the sum, each weighted
  158. // according to r - ⌊radius⌋.
  159. function blurf(radius) {
  160. const radius0 = Math.floor(radius);
  161. if (radius0 === radius) return bluri(radius);
  162. const t = radius - radius0;
  163. const w = 2 * radius + 1;
  164. return (T, S, start, stop, step) => { // stop must be aligned!
  165. if (!((stop -= step) >= start)) return; // inclusive stop
  166. let sum = radius0 * S[start];
  167. const s0 = step * radius0;
  168. const s1 = s0 + step;
  169. for (let i = start, j = start + s0; i < j; i += step) {
  170. sum += S[Math.min(stop, i)];
  171. }
  172. for (let i = start, j = stop; i <= j; i += step) {
  173. sum += S[Math.min(stop, i + s0)];
  174. T[i] = (sum + t * (S[Math.max(start, i - s1)] + S[Math.min(stop, i + s1)])) / w;
  175. sum -= S[Math.max(start, i - s0)];
  176. }
  177. };
  178. }
  179. // Like blurf, but optimized for integer radius.
  180. function bluri(radius) {
  181. const w = 2 * radius + 1;
  182. return (T, S, start, stop, step) => { // stop must be aligned!
  183. if (!((stop -= step) >= start)) return; // inclusive stop
  184. let sum = radius * S[start];
  185. const s = step * radius;
  186. for (let i = start, j = start + s; i < j; i += step) {
  187. sum += S[Math.min(stop, i)];
  188. }
  189. for (let i = start, j = stop; i <= j; i += step) {
  190. sum += S[Math.min(stop, i + s)];
  191. T[i] = sum / w;
  192. sum -= S[Math.max(start, i - s)];
  193. }
  194. };
  195. }
  196. function count$1(values, valueof) {
  197. let count = 0;
  198. if (valueof === undefined) {
  199. for (let value of values) {
  200. if (value != null && (value = +value) >= value) {
  201. ++count;
  202. }
  203. }
  204. } else {
  205. let index = -1;
  206. for (let value of values) {
  207. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  208. ++count;
  209. }
  210. }
  211. }
  212. return count;
  213. }
  214. function length$3(array) {
  215. return array.length | 0;
  216. }
  217. function empty$2(length) {
  218. return !(length > 0);
  219. }
  220. function arrayify(values) {
  221. return typeof values !== "object" || "length" in values ? values : Array.from(values);
  222. }
  223. function reducer(reduce) {
  224. return values => reduce(...values);
  225. }
  226. function cross$2(...values) {
  227. const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
  228. values = values.map(arrayify);
  229. const lengths = values.map(length$3);
  230. const j = values.length - 1;
  231. const index = new Array(j + 1).fill(0);
  232. const product = [];
  233. if (j < 0 || lengths.some(empty$2)) return product;
  234. while (true) {
  235. product.push(index.map((j, i) => values[i][j]));
  236. let i = j;
  237. while (++index[i] === lengths[i]) {
  238. if (i === 0) return reduce ? product.map(reduce) : product;
  239. index[i--] = 0;
  240. }
  241. }
  242. }
  243. function cumsum(values, valueof) {
  244. var sum = 0, index = 0;
  245. return Float64Array.from(values, valueof === undefined
  246. ? v => (sum += +v || 0)
  247. : v => (sum += +valueof(v, index++, values) || 0));
  248. }
  249. function variance(values, valueof) {
  250. let count = 0;
  251. let delta;
  252. let mean = 0;
  253. let sum = 0;
  254. if (valueof === undefined) {
  255. for (let value of values) {
  256. if (value != null && (value = +value) >= value) {
  257. delta = value - mean;
  258. mean += delta / ++count;
  259. sum += delta * (value - mean);
  260. }
  261. }
  262. } else {
  263. let index = -1;
  264. for (let value of values) {
  265. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  266. delta = value - mean;
  267. mean += delta / ++count;
  268. sum += delta * (value - mean);
  269. }
  270. }
  271. }
  272. if (count > 1) return sum / (count - 1);
  273. }
  274. function deviation(values, valueof) {
  275. const v = variance(values, valueof);
  276. return v ? Math.sqrt(v) : v;
  277. }
  278. function extent$1(values, valueof) {
  279. let min;
  280. let max;
  281. if (valueof === undefined) {
  282. for (const value of values) {
  283. if (value != null) {
  284. if (min === undefined) {
  285. if (value >= value) min = max = value;
  286. } else {
  287. if (min > value) min = value;
  288. if (max < value) max = value;
  289. }
  290. }
  291. }
  292. } else {
  293. let index = -1;
  294. for (let value of values) {
  295. if ((value = valueof(value, ++index, values)) != null) {
  296. if (min === undefined) {
  297. if (value >= value) min = max = value;
  298. } else {
  299. if (min > value) min = value;
  300. if (max < value) max = value;
  301. }
  302. }
  303. }
  304. }
  305. return [min, max];
  306. }
  307. // https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Modules/mathmodule.c#L1423
  308. class Adder {
  309. constructor() {
  310. this._partials = new Float64Array(32);
  311. this._n = 0;
  312. }
  313. add(x) {
  314. const p = this._partials;
  315. let i = 0;
  316. for (let j = 0; j < this._n && j < 32; j++) {
  317. const y = p[j],
  318. hi = x + y,
  319. lo = Math.abs(x) < Math.abs(y) ? x - (hi - y) : y - (hi - x);
  320. if (lo) p[i++] = lo;
  321. x = hi;
  322. }
  323. p[i] = x;
  324. this._n = i + 1;
  325. return this;
  326. }
  327. valueOf() {
  328. const p = this._partials;
  329. let n = this._n, x, y, lo, hi = 0;
  330. if (n > 0) {
  331. hi = p[--n];
  332. while (n > 0) {
  333. x = hi;
  334. y = p[--n];
  335. hi = x + y;
  336. lo = y - (hi - x);
  337. if (lo) break;
  338. }
  339. if (n > 0 && ((lo < 0 && p[n - 1] < 0) || (lo > 0 && p[n - 1] > 0))) {
  340. y = lo * 2;
  341. x = hi + y;
  342. if (y == x - hi) hi = x;
  343. }
  344. }
  345. return hi;
  346. }
  347. }
  348. function fsum(values, valueof) {
  349. const adder = new Adder();
  350. if (valueof === undefined) {
  351. for (let value of values) {
  352. if (value = +value) {
  353. adder.add(value);
  354. }
  355. }
  356. } else {
  357. let index = -1;
  358. for (let value of values) {
  359. if (value = +valueof(value, ++index, values)) {
  360. adder.add(value);
  361. }
  362. }
  363. }
  364. return +adder;
  365. }
  366. function fcumsum(values, valueof) {
  367. const adder = new Adder();
  368. let index = -1;
  369. return Float64Array.from(values, valueof === undefined
  370. ? v => adder.add(+v || 0)
  371. : v => adder.add(+valueof(v, ++index, values) || 0)
  372. );
  373. }
  374. class InternMap extends Map {
  375. constructor(entries, key = keyof) {
  376. super();
  377. Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
  378. if (entries != null) for (const [key, value] of entries) this.set(key, value);
  379. }
  380. get(key) {
  381. return super.get(intern_get(this, key));
  382. }
  383. has(key) {
  384. return super.has(intern_get(this, key));
  385. }
  386. set(key, value) {
  387. return super.set(intern_set(this, key), value);
  388. }
  389. delete(key) {
  390. return super.delete(intern_delete(this, key));
  391. }
  392. }
  393. class InternSet extends Set {
  394. constructor(values, key = keyof) {
  395. super();
  396. Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
  397. if (values != null) for (const value of values) this.add(value);
  398. }
  399. has(value) {
  400. return super.has(intern_get(this, value));
  401. }
  402. add(value) {
  403. return super.add(intern_set(this, value));
  404. }
  405. delete(value) {
  406. return super.delete(intern_delete(this, value));
  407. }
  408. }
  409. function intern_get({_intern, _key}, value) {
  410. const key = _key(value);
  411. return _intern.has(key) ? _intern.get(key) : value;
  412. }
  413. function intern_set({_intern, _key}, value) {
  414. const key = _key(value);
  415. if (_intern.has(key)) return _intern.get(key);
  416. _intern.set(key, value);
  417. return value;
  418. }
  419. function intern_delete({_intern, _key}, value) {
  420. const key = _key(value);
  421. if (_intern.has(key)) {
  422. value = _intern.get(key);
  423. _intern.delete(key);
  424. }
  425. return value;
  426. }
  427. function keyof(value) {
  428. return value !== null && typeof value === "object" ? value.valueOf() : value;
  429. }
  430. function identity$9(x) {
  431. return x;
  432. }
  433. function group(values, ...keys) {
  434. return nest(values, identity$9, identity$9, keys);
  435. }
  436. function groups(values, ...keys) {
  437. return nest(values, Array.from, identity$9, keys);
  438. }
  439. function flatten$1(groups, keys) {
  440. for (let i = 1, n = keys.length; i < n; ++i) {
  441. groups = groups.flatMap(g => g.pop().map(([key, value]) => [...g, key, value]));
  442. }
  443. return groups;
  444. }
  445. function flatGroup(values, ...keys) {
  446. return flatten$1(groups(values, ...keys), keys);
  447. }
  448. function flatRollup(values, reduce, ...keys) {
  449. return flatten$1(rollups(values, reduce, ...keys), keys);
  450. }
  451. function rollup(values, reduce, ...keys) {
  452. return nest(values, identity$9, reduce, keys);
  453. }
  454. function rollups(values, reduce, ...keys) {
  455. return nest(values, Array.from, reduce, keys);
  456. }
  457. function index$4(values, ...keys) {
  458. return nest(values, identity$9, unique, keys);
  459. }
  460. function indexes(values, ...keys) {
  461. return nest(values, Array.from, unique, keys);
  462. }
  463. function unique(values) {
  464. if (values.length !== 1) throw new Error("duplicate key");
  465. return values[0];
  466. }
  467. function nest(values, map, reduce, keys) {
  468. return (function regroup(values, i) {
  469. if (i >= keys.length) return reduce(values);
  470. const groups = new InternMap();
  471. const keyof = keys[i++];
  472. let index = -1;
  473. for (const value of values) {
  474. const key = keyof(value, ++index, values);
  475. const group = groups.get(key);
  476. if (group) group.push(value);
  477. else groups.set(key, [value]);
  478. }
  479. for (const [key, values] of groups) {
  480. groups.set(key, regroup(values, i));
  481. }
  482. return map(groups);
  483. })(values, 0);
  484. }
  485. function permute(source, keys) {
  486. return Array.from(keys, key => source[key]);
  487. }
  488. function sort(values, ...F) {
  489. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  490. values = Array.from(values);
  491. let [f] = F;
  492. if ((f && f.length !== 2) || F.length > 1) {
  493. const index = Uint32Array.from(values, (d, i) => i);
  494. if (F.length > 1) {
  495. F = F.map(f => values.map(f));
  496. index.sort((i, j) => {
  497. for (const f of F) {
  498. const c = ascendingDefined(f[i], f[j]);
  499. if (c) return c;
  500. }
  501. });
  502. } else {
  503. f = values.map(f);
  504. index.sort((i, j) => ascendingDefined(f[i], f[j]));
  505. }
  506. return permute(values, index);
  507. }
  508. return values.sort(compareDefined(f));
  509. }
  510. function compareDefined(compare = ascending$3) {
  511. if (compare === ascending$3) return ascendingDefined;
  512. if (typeof compare !== "function") throw new TypeError("compare is not a function");
  513. return (a, b) => {
  514. const x = compare(a, b);
  515. if (x || x === 0) return x;
  516. return (compare(b, b) === 0) - (compare(a, a) === 0);
  517. };
  518. }
  519. function ascendingDefined(a, b) {
  520. return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0);
  521. }
  522. function groupSort(values, reduce, key) {
  523. return (reduce.length !== 2
  524. ? sort(rollup(values, reduce, key), (([ak, av], [bk, bv]) => ascending$3(av, bv) || ascending$3(ak, bk)))
  525. : sort(group(values, key), (([ak, av], [bk, bv]) => reduce(av, bv) || ascending$3(ak, bk))))
  526. .map(([key]) => key);
  527. }
  528. var array$5 = Array.prototype;
  529. var slice$3 = array$5.slice;
  530. function constant$b(x) {
  531. return () => x;
  532. }
  533. const e10 = Math.sqrt(50),
  534. e5 = Math.sqrt(10),
  535. e2 = Math.sqrt(2);
  536. function tickSpec(start, stop, count) {
  537. const step = (stop - start) / Math.max(0, count),
  538. power = Math.floor(Math.log10(step)),
  539. error = step / Math.pow(10, power),
  540. factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
  541. let i1, i2, inc;
  542. if (power < 0) {
  543. inc = Math.pow(10, -power) / factor;
  544. i1 = Math.round(start * inc);
  545. i2 = Math.round(stop * inc);
  546. if (i1 / inc < start) ++i1;
  547. if (i2 / inc > stop) --i2;
  548. inc = -inc;
  549. } else {
  550. inc = Math.pow(10, power) * factor;
  551. i1 = Math.round(start / inc);
  552. i2 = Math.round(stop / inc);
  553. if (i1 * inc < start) ++i1;
  554. if (i2 * inc > stop) --i2;
  555. }
  556. if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2);
  557. return [i1, i2, inc];
  558. }
  559. function ticks(start, stop, count) {
  560. stop = +stop, start = +start, count = +count;
  561. if (!(count > 0)) return [];
  562. if (start === stop) return [start];
  563. const reverse = stop < start, [i1, i2, inc] = reverse ? tickSpec(stop, start, count) : tickSpec(start, stop, count);
  564. if (!(i2 >= i1)) return [];
  565. const n = i2 - i1 + 1, ticks = new Array(n);
  566. if (reverse) {
  567. if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) / -inc;
  568. else for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) * inc;
  569. } else {
  570. if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) / -inc;
  571. else for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) * inc;
  572. }
  573. return ticks;
  574. }
  575. function tickIncrement(start, stop, count) {
  576. stop = +stop, start = +start, count = +count;
  577. return tickSpec(start, stop, count)[2];
  578. }
  579. function tickStep(start, stop, count) {
  580. stop = +stop, start = +start, count = +count;
  581. const reverse = stop < start, inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count);
  582. return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc);
  583. }
  584. function nice$1(start, stop, count) {
  585. let prestep;
  586. while (true) {
  587. const step = tickIncrement(start, stop, count);
  588. if (step === prestep || step === 0 || !isFinite(step)) {
  589. return [start, stop];
  590. } else if (step > 0) {
  591. start = Math.floor(start / step) * step;
  592. stop = Math.ceil(stop / step) * step;
  593. } else if (step < 0) {
  594. start = Math.ceil(start * step) / step;
  595. stop = Math.floor(stop * step) / step;
  596. }
  597. prestep = step;
  598. }
  599. }
  600. function thresholdSturges(values) {
  601. return Math.max(1, Math.ceil(Math.log(count$1(values)) / Math.LN2) + 1);
  602. }
  603. function bin() {
  604. var value = identity$9,
  605. domain = extent$1,
  606. threshold = thresholdSturges;
  607. function histogram(data) {
  608. if (!Array.isArray(data)) data = Array.from(data);
  609. var i,
  610. n = data.length,
  611. x,
  612. step,
  613. values = new Array(n);
  614. for (i = 0; i < n; ++i) {
  615. values[i] = value(data[i], i, data);
  616. }
  617. var xz = domain(values),
  618. x0 = xz[0],
  619. x1 = xz[1],
  620. tz = threshold(values, x0, x1);
  621. // Convert number of thresholds into uniform thresholds, and nice the
  622. // default domain accordingly.
  623. if (!Array.isArray(tz)) {
  624. const max = x1, tn = +tz;
  625. if (domain === extent$1) [x0, x1] = nice$1(x0, x1, tn);
  626. tz = ticks(x0, x1, tn);
  627. // If the domain is aligned with the first tick (which it will by
  628. // default), then we can use quantization rather than bisection to bin
  629. // values, which is substantially faster.
  630. if (tz[0] <= x0) step = tickIncrement(x0, x1, tn);
  631. // If the last threshold is coincident with the domain’s upper bound, the
  632. // last bin will be zero-width. If the default domain is used, and this
  633. // last threshold is coincident with the maximum input value, we can
  634. // extend the niced upper bound by one tick to ensure uniform bin widths;
  635. // otherwise, we simply remove the last threshold. Note that we don’t
  636. // coerce values or the domain to numbers, and thus must be careful to
  637. // compare order (>=) rather than strict equality (===)!
  638. if (tz[tz.length - 1] >= x1) {
  639. if (max >= x1 && domain === extent$1) {
  640. const step = tickIncrement(x0, x1, tn);
  641. if (isFinite(step)) {
  642. if (step > 0) {
  643. x1 = (Math.floor(x1 / step) + 1) * step;
  644. } else if (step < 0) {
  645. x1 = (Math.ceil(x1 * -step) + 1) / -step;
  646. }
  647. }
  648. } else {
  649. tz.pop();
  650. }
  651. }
  652. }
  653. // Remove any thresholds outside the domain.
  654. // Be careful not to mutate an array owned by the user!
  655. var m = tz.length, a = 0, b = m;
  656. while (tz[a] <= x0) ++a;
  657. while (tz[b - 1] > x1) --b;
  658. if (a || b < m) tz = tz.slice(a, b), m = b - a;
  659. var bins = new Array(m + 1),
  660. bin;
  661. // Initialize bins.
  662. for (i = 0; i <= m; ++i) {
  663. bin = bins[i] = [];
  664. bin.x0 = i > 0 ? tz[i - 1] : x0;
  665. bin.x1 = i < m ? tz[i] : x1;
  666. }
  667. // Assign data to bins by value, ignoring any outside the domain.
  668. if (isFinite(step)) {
  669. if (step > 0) {
  670. for (i = 0; i < n; ++i) {
  671. if ((x = values[i]) != null && x0 <= x && x <= x1) {
  672. bins[Math.min(m, Math.floor((x - x0) / step))].push(data[i]);
  673. }
  674. }
  675. } else if (step < 0) {
  676. for (i = 0; i < n; ++i) {
  677. if ((x = values[i]) != null && x0 <= x && x <= x1) {
  678. const j = Math.floor((x0 - x) * step);
  679. bins[Math.min(m, j + (tz[j] <= x))].push(data[i]); // handle off-by-one due to rounding
  680. }
  681. }
  682. }
  683. } else {
  684. for (i = 0; i < n; ++i) {
  685. if ((x = values[i]) != null && x0 <= x && x <= x1) {
  686. bins[bisect(tz, x, 0, m)].push(data[i]);
  687. }
  688. }
  689. }
  690. return bins;
  691. }
  692. histogram.value = function(_) {
  693. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(_), histogram) : value;
  694. };
  695. histogram.domain = function(_) {
  696. return arguments.length ? (domain = typeof _ === "function" ? _ : constant$b([_[0], _[1]]), histogram) : domain;
  697. };
  698. histogram.thresholds = function(_) {
  699. return arguments.length ? (threshold = typeof _ === "function" ? _ : constant$b(Array.isArray(_) ? slice$3.call(_) : _), histogram) : threshold;
  700. };
  701. return histogram;
  702. }
  703. function max$3(values, valueof) {
  704. let max;
  705. if (valueof === undefined) {
  706. for (const value of values) {
  707. if (value != null
  708. && (max < value || (max === undefined && value >= value))) {
  709. max = value;
  710. }
  711. }
  712. } else {
  713. let index = -1;
  714. for (let value of values) {
  715. if ((value = valueof(value, ++index, values)) != null
  716. && (max < value || (max === undefined && value >= value))) {
  717. max = value;
  718. }
  719. }
  720. }
  721. return max;
  722. }
  723. function maxIndex(values, valueof) {
  724. let max;
  725. let maxIndex = -1;
  726. let index = -1;
  727. if (valueof === undefined) {
  728. for (const value of values) {
  729. ++index;
  730. if (value != null
  731. && (max < value || (max === undefined && value >= value))) {
  732. max = value, maxIndex = index;
  733. }
  734. }
  735. } else {
  736. for (let value of values) {
  737. if ((value = valueof(value, ++index, values)) != null
  738. && (max < value || (max === undefined && value >= value))) {
  739. max = value, maxIndex = index;
  740. }
  741. }
  742. }
  743. return maxIndex;
  744. }
  745. function min$2(values, valueof) {
  746. let min;
  747. if (valueof === undefined) {
  748. for (const value of values) {
  749. if (value != null
  750. && (min > value || (min === undefined && value >= value))) {
  751. min = value;
  752. }
  753. }
  754. } else {
  755. let index = -1;
  756. for (let value of values) {
  757. if ((value = valueof(value, ++index, values)) != null
  758. && (min > value || (min === undefined && value >= value))) {
  759. min = value;
  760. }
  761. }
  762. }
  763. return min;
  764. }
  765. function minIndex(values, valueof) {
  766. let min;
  767. let minIndex = -1;
  768. let index = -1;
  769. if (valueof === undefined) {
  770. for (const value of values) {
  771. ++index;
  772. if (value != null
  773. && (min > value || (min === undefined && value >= value))) {
  774. min = value, minIndex = index;
  775. }
  776. }
  777. } else {
  778. for (let value of values) {
  779. if ((value = valueof(value, ++index, values)) != null
  780. && (min > value || (min === undefined && value >= value))) {
  781. min = value, minIndex = index;
  782. }
  783. }
  784. }
  785. return minIndex;
  786. }
  787. // Based on https://github.com/mourner/quickselect
  788. // ISC license, Copyright 2018 Vladimir Agafonkin.
  789. function quickselect(array, k, left = 0, right = Infinity, compare) {
  790. k = Math.floor(k);
  791. left = Math.floor(Math.max(0, left));
  792. right = Math.floor(Math.min(array.length - 1, right));
  793. if (!(left <= k && k <= right)) return array;
  794. compare = compare === undefined ? ascendingDefined : compareDefined(compare);
  795. while (right > left) {
  796. if (right - left > 600) {
  797. const n = right - left + 1;
  798. const m = k - left + 1;
  799. const z = Math.log(n);
  800. const s = 0.5 * Math.exp(2 * z / 3);
  801. const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  802. const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  803. const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  804. quickselect(array, k, newLeft, newRight, compare);
  805. }
  806. const t = array[k];
  807. let i = left;
  808. let j = right;
  809. swap$1(array, left, k);
  810. if (compare(array[right], t) > 0) swap$1(array, left, right);
  811. while (i < j) {
  812. swap$1(array, i, j), ++i, --j;
  813. while (compare(array[i], t) < 0) ++i;
  814. while (compare(array[j], t) > 0) --j;
  815. }
  816. if (compare(array[left], t) === 0) swap$1(array, left, j);
  817. else ++j, swap$1(array, j, right);
  818. if (j <= k) left = j + 1;
  819. if (k <= j) right = j - 1;
  820. }
  821. return array;
  822. }
  823. function swap$1(array, i, j) {
  824. const t = array[i];
  825. array[i] = array[j];
  826. array[j] = t;
  827. }
  828. function greatest(values, compare = ascending$3) {
  829. let max;
  830. let defined = false;
  831. if (compare.length === 1) {
  832. let maxValue;
  833. for (const element of values) {
  834. const value = compare(element);
  835. if (defined
  836. ? ascending$3(value, maxValue) > 0
  837. : ascending$3(value, value) === 0) {
  838. max = element;
  839. maxValue = value;
  840. defined = true;
  841. }
  842. }
  843. } else {
  844. for (const value of values) {
  845. if (defined
  846. ? compare(value, max) > 0
  847. : compare(value, value) === 0) {
  848. max = value;
  849. defined = true;
  850. }
  851. }
  852. }
  853. return max;
  854. }
  855. function quantile$1(values, p, valueof) {
  856. values = Float64Array.from(numbers(values, valueof));
  857. if (!(n = values.length) || isNaN(p = +p)) return;
  858. if (p <= 0 || n < 2) return min$2(values);
  859. if (p >= 1) return max$3(values);
  860. var n,
  861. i = (n - 1) * p,
  862. i0 = Math.floor(i),
  863. value0 = max$3(quickselect(values, i0).subarray(0, i0 + 1)),
  864. value1 = min$2(values.subarray(i0 + 1));
  865. return value0 + (value1 - value0) * (i - i0);
  866. }
  867. function quantileSorted(values, p, valueof = number$3) {
  868. if (!(n = values.length) || isNaN(p = +p)) return;
  869. if (p <= 0 || n < 2) return +valueof(values[0], 0, values);
  870. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  871. var n,
  872. i = (n - 1) * p,
  873. i0 = Math.floor(i),
  874. value0 = +valueof(values[i0], i0, values),
  875. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  876. return value0 + (value1 - value0) * (i - i0);
  877. }
  878. function quantileIndex(values, p, valueof = number$3) {
  879. if (isNaN(p = +p)) return;
  880. numbers = Float64Array.from(values, (_, i) => number$3(valueof(values[i], i, values)));
  881. if (p <= 0) return minIndex(numbers);
  882. if (p >= 1) return maxIndex(numbers);
  883. var numbers,
  884. index = Uint32Array.from(values, (_, i) => i),
  885. j = numbers.length - 1,
  886. i = Math.floor(j * p);
  887. quickselect(index, i, 0, j, (i, j) => ascendingDefined(numbers[i], numbers[j]));
  888. i = greatest(index.subarray(0, i + 1), (i) => numbers[i]);
  889. return i >= 0 ? i : -1;
  890. }
  891. function thresholdFreedmanDiaconis(values, min, max) {
  892. const c = count$1(values), d = quantile$1(values, 0.75) - quantile$1(values, 0.25);
  893. return c && d ? Math.ceil((max - min) / (2 * d * Math.pow(c, -1 / 3))) : 1;
  894. }
  895. function thresholdScott(values, min, max) {
  896. const c = count$1(values), d = deviation(values);
  897. return c && d ? Math.ceil((max - min) * Math.cbrt(c) / (3.49 * d)) : 1;
  898. }
  899. function mean(values, valueof) {
  900. let count = 0;
  901. let sum = 0;
  902. if (valueof === undefined) {
  903. for (let value of values) {
  904. if (value != null && (value = +value) >= value) {
  905. ++count, sum += value;
  906. }
  907. }
  908. } else {
  909. let index = -1;
  910. for (let value of values) {
  911. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  912. ++count, sum += value;
  913. }
  914. }
  915. }
  916. if (count) return sum / count;
  917. }
  918. function median(values, valueof) {
  919. return quantile$1(values, 0.5, valueof);
  920. }
  921. function medianIndex(values, valueof) {
  922. return quantileIndex(values, 0.5, valueof);
  923. }
  924. function* flatten(arrays) {
  925. for (const array of arrays) {
  926. yield* array;
  927. }
  928. }
  929. function merge(arrays) {
  930. return Array.from(flatten(arrays));
  931. }
  932. function mode(values, valueof) {
  933. const counts = new InternMap();
  934. if (valueof === undefined) {
  935. for (let value of values) {
  936. if (value != null && value >= value) {
  937. counts.set(value, (counts.get(value) || 0) + 1);
  938. }
  939. }
  940. } else {
  941. let index = -1;
  942. for (let value of values) {
  943. if ((value = valueof(value, ++index, values)) != null && value >= value) {
  944. counts.set(value, (counts.get(value) || 0) + 1);
  945. }
  946. }
  947. }
  948. let modeValue;
  949. let modeCount = 0;
  950. for (const [value, count] of counts) {
  951. if (count > modeCount) {
  952. modeCount = count;
  953. modeValue = value;
  954. }
  955. }
  956. return modeValue;
  957. }
  958. function pairs(values, pairof = pair) {
  959. const pairs = [];
  960. let previous;
  961. let first = false;
  962. for (const value of values) {
  963. if (first) pairs.push(pairof(previous, value));
  964. previous = value;
  965. first = true;
  966. }
  967. return pairs;
  968. }
  969. function pair(a, b) {
  970. return [a, b];
  971. }
  972. function range$2(start, stop, step) {
  973. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  974. var i = -1,
  975. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  976. range = new Array(n);
  977. while (++i < n) {
  978. range[i] = start + i * step;
  979. }
  980. return range;
  981. }
  982. function rank(values, valueof = ascending$3) {
  983. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  984. let V = Array.from(values);
  985. const R = new Float64Array(V.length);
  986. if (valueof.length !== 2) V = V.map(valueof), valueof = ascending$3;
  987. const compareIndex = (i, j) => valueof(V[i], V[j]);
  988. let k, r;
  989. values = Uint32Array.from(V, (_, i) => i);
  990. // Risky chaining due to Safari 14 https://github.com/d3/d3-array/issues/123
  991. values.sort(valueof === ascending$3 ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex));
  992. values.forEach((j, i) => {
  993. const c = compareIndex(j, k === undefined ? j : k);
  994. if (c >= 0) {
  995. if (k === undefined || c > 0) k = j, r = i;
  996. R[j] = r;
  997. } else {
  998. R[j] = NaN;
  999. }
  1000. });
  1001. return R;
  1002. }
  1003. function least(values, compare = ascending$3) {
  1004. let min;
  1005. let defined = false;
  1006. if (compare.length === 1) {
  1007. let minValue;
  1008. for (const element of values) {
  1009. const value = compare(element);
  1010. if (defined
  1011. ? ascending$3(value, minValue) < 0
  1012. : ascending$3(value, value) === 0) {
  1013. min = element;
  1014. minValue = value;
  1015. defined = true;
  1016. }
  1017. }
  1018. } else {
  1019. for (const value of values) {
  1020. if (defined
  1021. ? compare(value, min) < 0
  1022. : compare(value, value) === 0) {
  1023. min = value;
  1024. defined = true;
  1025. }
  1026. }
  1027. }
  1028. return min;
  1029. }
  1030. function leastIndex(values, compare = ascending$3) {
  1031. if (compare.length === 1) return minIndex(values, compare);
  1032. let minValue;
  1033. let min = -1;
  1034. let index = -1;
  1035. for (const value of values) {
  1036. ++index;
  1037. if (min < 0
  1038. ? compare(value, value) === 0
  1039. : compare(value, minValue) < 0) {
  1040. minValue = value;
  1041. min = index;
  1042. }
  1043. }
  1044. return min;
  1045. }
  1046. function greatestIndex(values, compare = ascending$3) {
  1047. if (compare.length === 1) return maxIndex(values, compare);
  1048. let maxValue;
  1049. let max = -1;
  1050. let index = -1;
  1051. for (const value of values) {
  1052. ++index;
  1053. if (max < 0
  1054. ? compare(value, value) === 0
  1055. : compare(value, maxValue) > 0) {
  1056. maxValue = value;
  1057. max = index;
  1058. }
  1059. }
  1060. return max;
  1061. }
  1062. function scan(values, compare) {
  1063. const index = leastIndex(values, compare);
  1064. return index < 0 ? undefined : index;
  1065. }
  1066. var shuffle$1 = shuffler(Math.random);
  1067. function shuffler(random) {
  1068. return function shuffle(array, i0 = 0, i1 = array.length) {
  1069. let m = i1 - (i0 = +i0);
  1070. while (m) {
  1071. const i = random() * m-- | 0, t = array[m + i0];
  1072. array[m + i0] = array[i + i0];
  1073. array[i + i0] = t;
  1074. }
  1075. return array;
  1076. };
  1077. }
  1078. function sum$2(values, valueof) {
  1079. let sum = 0;
  1080. if (valueof === undefined) {
  1081. for (let value of values) {
  1082. if (value = +value) {
  1083. sum += value;
  1084. }
  1085. }
  1086. } else {
  1087. let index = -1;
  1088. for (let value of values) {
  1089. if (value = +valueof(value, ++index, values)) {
  1090. sum += value;
  1091. }
  1092. }
  1093. }
  1094. return sum;
  1095. }
  1096. function transpose(matrix) {
  1097. if (!(n = matrix.length)) return [];
  1098. for (var i = -1, m = min$2(matrix, length$2), transpose = new Array(m); ++i < m;) {
  1099. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  1100. row[j] = matrix[j][i];
  1101. }
  1102. }
  1103. return transpose;
  1104. }
  1105. function length$2(d) {
  1106. return d.length;
  1107. }
  1108. function zip() {
  1109. return transpose(arguments);
  1110. }
  1111. function every(values, test) {
  1112. if (typeof test !== "function") throw new TypeError("test is not a function");
  1113. let index = -1;
  1114. for (const value of values) {
  1115. if (!test(value, ++index, values)) {
  1116. return false;
  1117. }
  1118. }
  1119. return true;
  1120. }
  1121. function some(values, test) {
  1122. if (typeof test !== "function") throw new TypeError("test is not a function");
  1123. let index = -1;
  1124. for (const value of values) {
  1125. if (test(value, ++index, values)) {
  1126. return true;
  1127. }
  1128. }
  1129. return false;
  1130. }
  1131. function filter$1(values, test) {
  1132. if (typeof test !== "function") throw new TypeError("test is not a function");
  1133. const array = [];
  1134. let index = -1;
  1135. for (const value of values) {
  1136. if (test(value, ++index, values)) {
  1137. array.push(value);
  1138. }
  1139. }
  1140. return array;
  1141. }
  1142. function map$1(values, mapper) {
  1143. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  1144. if (typeof mapper !== "function") throw new TypeError("mapper is not a function");
  1145. return Array.from(values, (value, index) => mapper(value, index, values));
  1146. }
  1147. function reduce(values, reducer, value) {
  1148. if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
  1149. const iterator = values[Symbol.iterator]();
  1150. let done, next, index = -1;
  1151. if (arguments.length < 3) {
  1152. ({done, value} = iterator.next());
  1153. if (done) return;
  1154. ++index;
  1155. }
  1156. while (({done, value: next} = iterator.next()), !done) {
  1157. value = reducer(value, next, ++index, values);
  1158. }
  1159. return value;
  1160. }
  1161. function reverse$1(values) {
  1162. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  1163. return Array.from(values).reverse();
  1164. }
  1165. function difference(values, ...others) {
  1166. values = new InternSet(values);
  1167. for (const other of others) {
  1168. for (const value of other) {
  1169. values.delete(value);
  1170. }
  1171. }
  1172. return values;
  1173. }
  1174. function disjoint(values, other) {
  1175. const iterator = other[Symbol.iterator](), set = new InternSet();
  1176. for (const v of values) {
  1177. if (set.has(v)) return false;
  1178. let value, done;
  1179. while (({value, done} = iterator.next())) {
  1180. if (done) break;
  1181. if (Object.is(v, value)) return false;
  1182. set.add(value);
  1183. }
  1184. }
  1185. return true;
  1186. }
  1187. function intersection(values, ...others) {
  1188. values = new InternSet(values);
  1189. others = others.map(set$2);
  1190. out: for (const value of values) {
  1191. for (const other of others) {
  1192. if (!other.has(value)) {
  1193. values.delete(value);
  1194. continue out;
  1195. }
  1196. }
  1197. }
  1198. return values;
  1199. }
  1200. function set$2(values) {
  1201. return values instanceof InternSet ? values : new InternSet(values);
  1202. }
  1203. function superset(values, other) {
  1204. const iterator = values[Symbol.iterator](), set = new Set();
  1205. for (const o of other) {
  1206. const io = intern(o);
  1207. if (set.has(io)) continue;
  1208. let value, done;
  1209. while (({value, done} = iterator.next())) {
  1210. if (done) return false;
  1211. const ivalue = intern(value);
  1212. set.add(ivalue);
  1213. if (Object.is(io, ivalue)) break;
  1214. }
  1215. }
  1216. return true;
  1217. }
  1218. function intern(value) {
  1219. return value !== null && typeof value === "object" ? value.valueOf() : value;
  1220. }
  1221. function subset(values, other) {
  1222. return superset(other, values);
  1223. }
  1224. function union(...others) {
  1225. const set = new InternSet();
  1226. for (const other of others) {
  1227. for (const o of other) {
  1228. set.add(o);
  1229. }
  1230. }
  1231. return set;
  1232. }
  1233. function identity$8(x) {
  1234. return x;
  1235. }
  1236. var top = 1,
  1237. right = 2,
  1238. bottom = 3,
  1239. left = 4,
  1240. epsilon$6 = 1e-6;
  1241. function translateX(x) {
  1242. return "translate(" + x + ",0)";
  1243. }
  1244. function translateY(y) {
  1245. return "translate(0," + y + ")";
  1246. }
  1247. function number$2(scale) {
  1248. return d => +scale(d);
  1249. }
  1250. function center$1(scale, offset) {
  1251. offset = Math.max(0, scale.bandwidth() - offset * 2) / 2;
  1252. if (scale.round()) offset = Math.round(offset);
  1253. return d => +scale(d) + offset;
  1254. }
  1255. function entering() {
  1256. return !this.__axis;
  1257. }
  1258. function axis(orient, scale) {
  1259. var tickArguments = [],
  1260. tickValues = null,
  1261. tickFormat = null,
  1262. tickSizeInner = 6,
  1263. tickSizeOuter = 6,
  1264. tickPadding = 3,
  1265. offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5,
  1266. k = orient === top || orient === left ? -1 : 1,
  1267. x = orient === left || orient === right ? "x" : "y",
  1268. transform = orient === top || orient === bottom ? translateX : translateY;
  1269. function axis(context) {
  1270. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  1271. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$8) : tickFormat,
  1272. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  1273. range = scale.range(),
  1274. range0 = +range[0] + offset,
  1275. range1 = +range[range.length - 1] + offset,
  1276. position = (scale.bandwidth ? center$1 : number$2)(scale.copy(), offset),
  1277. selection = context.selection ? context.selection() : context,
  1278. path = selection.selectAll(".domain").data([null]),
  1279. tick = selection.selectAll(".tick").data(values, scale).order(),
  1280. tickExit = tick.exit(),
  1281. tickEnter = tick.enter().append("g").attr("class", "tick"),
  1282. line = tick.select("line"),
  1283. text = tick.select("text");
  1284. path = path.merge(path.enter().insert("path", ".tick")
  1285. .attr("class", "domain")
  1286. .attr("stroke", "currentColor"));
  1287. tick = tick.merge(tickEnter);
  1288. line = line.merge(tickEnter.append("line")
  1289. .attr("stroke", "currentColor")
  1290. .attr(x + "2", k * tickSizeInner));
  1291. text = text.merge(tickEnter.append("text")
  1292. .attr("fill", "currentColor")
  1293. .attr(x, k * spacing)
  1294. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  1295. if (context !== selection) {
  1296. path = path.transition(context);
  1297. tick = tick.transition(context);
  1298. line = line.transition(context);
  1299. text = text.transition(context);
  1300. tickExit = tickExit.transition(context)
  1301. .attr("opacity", epsilon$6)
  1302. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform"); });
  1303. tickEnter
  1304. .attr("opacity", epsilon$6)
  1305. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset); });
  1306. }
  1307. tickExit.remove();
  1308. path
  1309. .attr("d", orient === left || orient === right
  1310. ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1)
  1311. : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1));
  1312. tick
  1313. .attr("opacity", 1)
  1314. .attr("transform", function(d) { return transform(position(d) + offset); });
  1315. line
  1316. .attr(x + "2", k * tickSizeInner);
  1317. text
  1318. .attr(x, k * spacing)
  1319. .text(format);
  1320. selection.filter(entering)
  1321. .attr("fill", "none")
  1322. .attr("font-size", 10)
  1323. .attr("font-family", "sans-serif")
  1324. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  1325. selection
  1326. .each(function() { this.__axis = position; });
  1327. }
  1328. axis.scale = function(_) {
  1329. return arguments.length ? (scale = _, axis) : scale;
  1330. };
  1331. axis.ticks = function() {
  1332. return tickArguments = Array.from(arguments), axis;
  1333. };
  1334. axis.tickArguments = function(_) {
  1335. return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice();
  1336. };
  1337. axis.tickValues = function(_) {
  1338. return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice();
  1339. };
  1340. axis.tickFormat = function(_) {
  1341. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  1342. };
  1343. axis.tickSize = function(_) {
  1344. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  1345. };
  1346. axis.tickSizeInner = function(_) {
  1347. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  1348. };
  1349. axis.tickSizeOuter = function(_) {
  1350. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  1351. };
  1352. axis.tickPadding = function(_) {
  1353. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  1354. };
  1355. axis.offset = function(_) {
  1356. return arguments.length ? (offset = +_, axis) : offset;
  1357. };
  1358. return axis;
  1359. }
  1360. function axisTop(scale) {
  1361. return axis(top, scale);
  1362. }
  1363. function axisRight(scale) {
  1364. return axis(right, scale);
  1365. }
  1366. function axisBottom(scale) {
  1367. return axis(bottom, scale);
  1368. }
  1369. function axisLeft(scale) {
  1370. return axis(left, scale);
  1371. }
  1372. var noop$3 = {value: () => {}};
  1373. function dispatch() {
  1374. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  1375. if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
  1376. _[t] = [];
  1377. }
  1378. return new Dispatch(_);
  1379. }
  1380. function Dispatch(_) {
  1381. this._ = _;
  1382. }
  1383. function parseTypenames$1(typenames, types) {
  1384. return typenames.trim().split(/^|\s+/).map(function(t) {
  1385. var name = "", i = t.indexOf(".");
  1386. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1387. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  1388. return {type: t, name: name};
  1389. });
  1390. }
  1391. Dispatch.prototype = dispatch.prototype = {
  1392. constructor: Dispatch,
  1393. on: function(typename, callback) {
  1394. var _ = this._,
  1395. T = parseTypenames$1(typename + "", _),
  1396. t,
  1397. i = -1,
  1398. n = T.length;
  1399. // If no callback was specified, return the callback of the given type and name.
  1400. if (arguments.length < 2) {
  1401. while (++i < n) if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t;
  1402. return;
  1403. }
  1404. // If a type was specified, set the callback for the given type and name.
  1405. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  1406. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  1407. while (++i < n) {
  1408. if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
  1409. else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
  1410. }
  1411. return this;
  1412. },
  1413. copy: function() {
  1414. var copy = {}, _ = this._;
  1415. for (var t in _) copy[t] = _[t].slice();
  1416. return new Dispatch(copy);
  1417. },
  1418. call: function(type, that) {
  1419. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  1420. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  1421. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  1422. },
  1423. apply: function(type, that, args) {
  1424. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  1425. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  1426. }
  1427. };
  1428. function get$1(type, name) {
  1429. for (var i = 0, n = type.length, c; i < n; ++i) {
  1430. if ((c = type[i]).name === name) {
  1431. return c.value;
  1432. }
  1433. }
  1434. }
  1435. function set$1(type, name, callback) {
  1436. for (var i = 0, n = type.length; i < n; ++i) {
  1437. if (type[i].name === name) {
  1438. type[i] = noop$3, type = type.slice(0, i).concat(type.slice(i + 1));
  1439. break;
  1440. }
  1441. }
  1442. if (callback != null) type.push({name: name, value: callback});
  1443. return type;
  1444. }
  1445. var xhtml = "http://www.w3.org/1999/xhtml";
  1446. var namespaces = {
  1447. svg: "http://www.w3.org/2000/svg",
  1448. xhtml: xhtml,
  1449. xlink: "http://www.w3.org/1999/xlink",
  1450. xml: "http://www.w3.org/XML/1998/namespace",
  1451. xmlns: "http://www.w3.org/2000/xmlns/"
  1452. };
  1453. function namespace(name) {
  1454. var prefix = name += "", i = prefix.indexOf(":");
  1455. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  1456. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins
  1457. }
  1458. function creatorInherit(name) {
  1459. return function() {
  1460. var document = this.ownerDocument,
  1461. uri = this.namespaceURI;
  1462. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  1463. ? document.createElement(name)
  1464. : document.createElementNS(uri, name);
  1465. };
  1466. }
  1467. function creatorFixed(fullname) {
  1468. return function() {
  1469. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  1470. };
  1471. }
  1472. function creator(name) {
  1473. var fullname = namespace(name);
  1474. return (fullname.local
  1475. ? creatorFixed
  1476. : creatorInherit)(fullname);
  1477. }
  1478. function none$2() {}
  1479. function selector(selector) {
  1480. return selector == null ? none$2 : function() {
  1481. return this.querySelector(selector);
  1482. };
  1483. }
  1484. function selection_select(select) {
  1485. if (typeof select !== "function") select = selector(select);
  1486. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  1487. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  1488. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  1489. if ("__data__" in node) subnode.__data__ = node.__data__;
  1490. subgroup[i] = subnode;
  1491. }
  1492. }
  1493. }
  1494. return new Selection$1(subgroups, this._parents);
  1495. }
  1496. // Given something array like (or null), returns something that is strictly an
  1497. // array. This is used to ensure that array-like objects passed to d3.selectAll
  1498. // or selection.selectAll are converted into proper arrays when creating a
  1499. // selection; we don’t ever want to create a selection backed by a live
  1500. // HTMLCollection or NodeList. However, note that selection.selectAll will use a
  1501. // static NodeList as a group, since it safely derived from querySelectorAll.
  1502. function array$4(x) {
  1503. return x == null ? [] : Array.isArray(x) ? x : Array.from(x);
  1504. }
  1505. function empty$1() {
  1506. return [];
  1507. }
  1508. function selectorAll(selector) {
  1509. return selector == null ? empty$1 : function() {
  1510. return this.querySelectorAll(selector);
  1511. };
  1512. }
  1513. function arrayAll(select) {
  1514. return function() {
  1515. return array$4(select.apply(this, arguments));
  1516. };
  1517. }
  1518. function selection_selectAll(select) {
  1519. if (typeof select === "function") select = arrayAll(select);
  1520. else select = selectorAll(select);
  1521. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  1522. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  1523. if (node = group[i]) {
  1524. subgroups.push(select.call(node, node.__data__, i, group));
  1525. parents.push(node);
  1526. }
  1527. }
  1528. }
  1529. return new Selection$1(subgroups, parents);
  1530. }
  1531. function matcher(selector) {
  1532. return function() {
  1533. return this.matches(selector);
  1534. };
  1535. }
  1536. function childMatcher(selector) {
  1537. return function(node) {
  1538. return node.matches(selector);
  1539. };
  1540. }
  1541. var find$1 = Array.prototype.find;
  1542. function childFind(match) {
  1543. return function() {
  1544. return find$1.call(this.children, match);
  1545. };
  1546. }
  1547. function childFirst() {
  1548. return this.firstElementChild;
  1549. }
  1550. function selection_selectChild(match) {
  1551. return this.select(match == null ? childFirst
  1552. : childFind(typeof match === "function" ? match : childMatcher(match)));
  1553. }
  1554. var filter = Array.prototype.filter;
  1555. function children() {
  1556. return Array.from(this.children);
  1557. }
  1558. function childrenFilter(match) {
  1559. return function() {
  1560. return filter.call(this.children, match);
  1561. };
  1562. }
  1563. function selection_selectChildren(match) {
  1564. return this.selectAll(match == null ? children
  1565. : childrenFilter(typeof match === "function" ? match : childMatcher(match)));
  1566. }
  1567. function selection_filter(match) {
  1568. if (typeof match !== "function") match = matcher(match);
  1569. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  1570. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  1571. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  1572. subgroup.push(node);
  1573. }
  1574. }
  1575. }
  1576. return new Selection$1(subgroups, this._parents);
  1577. }
  1578. function sparse(update) {
  1579. return new Array(update.length);
  1580. }
  1581. function selection_enter() {
  1582. return new Selection$1(this._enter || this._groups.map(sparse), this._parents);
  1583. }
  1584. function EnterNode(parent, datum) {
  1585. this.ownerDocument = parent.ownerDocument;
  1586. this.namespaceURI = parent.namespaceURI;
  1587. this._next = null;
  1588. this._parent = parent;
  1589. this.__data__ = datum;
  1590. }
  1591. EnterNode.prototype = {
  1592. constructor: EnterNode,
  1593. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  1594. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  1595. querySelector: function(selector) { return this._parent.querySelector(selector); },
  1596. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  1597. };
  1598. function constant$a(x) {
  1599. return function() {
  1600. return x;
  1601. };
  1602. }
  1603. function bindIndex(parent, group, enter, update, exit, data) {
  1604. var i = 0,
  1605. node,
  1606. groupLength = group.length,
  1607. dataLength = data.length;
  1608. // Put any non-null nodes that fit into update.
  1609. // Put any null nodes into enter.
  1610. // Put any remaining data into enter.
  1611. for (; i < dataLength; ++i) {
  1612. if (node = group[i]) {
  1613. node.__data__ = data[i];
  1614. update[i] = node;
  1615. } else {
  1616. enter[i] = new EnterNode(parent, data[i]);
  1617. }
  1618. }
  1619. // Put any non-null nodes that don’t fit into exit.
  1620. for (; i < groupLength; ++i) {
  1621. if (node = group[i]) {
  1622. exit[i] = node;
  1623. }
  1624. }
  1625. }
  1626. function bindKey(parent, group, enter, update, exit, data, key) {
  1627. var i,
  1628. node,
  1629. nodeByKeyValue = new Map,
  1630. groupLength = group.length,
  1631. dataLength = data.length,
  1632. keyValues = new Array(groupLength),
  1633. keyValue;
  1634. // Compute the key for each node.
  1635. // If multiple nodes have the same key, the duplicates are added to exit.
  1636. for (i = 0; i < groupLength; ++i) {
  1637. if (node = group[i]) {
  1638. keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
  1639. if (nodeByKeyValue.has(keyValue)) {
  1640. exit[i] = node;
  1641. } else {
  1642. nodeByKeyValue.set(keyValue, node);
  1643. }
  1644. }
  1645. }
  1646. // Compute the key for each datum.
  1647. // If there a node associated with this key, join and add it to update.
  1648. // If there is not (or the key is a duplicate), add it to enter.
  1649. for (i = 0; i < dataLength; ++i) {
  1650. keyValue = key.call(parent, data[i], i, data) + "";
  1651. if (node = nodeByKeyValue.get(keyValue)) {
  1652. update[i] = node;
  1653. node.__data__ = data[i];
  1654. nodeByKeyValue.delete(keyValue);
  1655. } else {
  1656. enter[i] = new EnterNode(parent, data[i]);
  1657. }
  1658. }
  1659. // Add any remaining nodes that were not bound to data to exit.
  1660. for (i = 0; i < groupLength; ++i) {
  1661. if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) {
  1662. exit[i] = node;
  1663. }
  1664. }
  1665. }
  1666. function datum(node) {
  1667. return node.__data__;
  1668. }
  1669. function selection_data(value, key) {
  1670. if (!arguments.length) return Array.from(this, datum);
  1671. var bind = key ? bindKey : bindIndex,
  1672. parents = this._parents,
  1673. groups = this._groups;
  1674. if (typeof value !== "function") value = constant$a(value);
  1675. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  1676. var parent = parents[j],
  1677. group = groups[j],
  1678. groupLength = group.length,
  1679. data = arraylike(value.call(parent, parent && parent.__data__, j, parents)),
  1680. dataLength = data.length,
  1681. enterGroup = enter[j] = new Array(dataLength),
  1682. updateGroup = update[j] = new Array(dataLength),
  1683. exitGroup = exit[j] = new Array(groupLength);
  1684. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  1685. // Now connect the enter nodes to their following update node, such that
  1686. // appendChild can insert the materialized enter node before this node,
  1687. // rather than at the end of the parent node.
  1688. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  1689. if (previous = enterGroup[i0]) {
  1690. if (i0 >= i1) i1 = i0 + 1;
  1691. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  1692. previous._next = next || null;
  1693. }
  1694. }
  1695. }
  1696. update = new Selection$1(update, parents);
  1697. update._enter = enter;
  1698. update._exit = exit;
  1699. return update;
  1700. }
  1701. // Given some data, this returns an array-like view of it: an object that
  1702. // exposes a length property and allows numeric indexing. Note that unlike
  1703. // selectAll, this isn’t worried about “live” collections because the resulting
  1704. // array will only be used briefly while data is being bound. (It is possible to
  1705. // cause the data to change while iterating by using a key function, but please
  1706. // don’t; we’d rather avoid a gratuitous copy.)
  1707. function arraylike(data) {
  1708. return typeof data === "object" && "length" in data
  1709. ? data // Array, TypedArray, NodeList, array-like
  1710. : Array.from(data); // Map, Set, iterable, string, or anything else
  1711. }
  1712. function selection_exit() {
  1713. return new Selection$1(this._exit || this._groups.map(sparse), this._parents);
  1714. }
  1715. function selection_join(onenter, onupdate, onexit) {
  1716. var enter = this.enter(), update = this, exit = this.exit();
  1717. if (typeof onenter === "function") {
  1718. enter = onenter(enter);
  1719. if (enter) enter = enter.selection();
  1720. } else {
  1721. enter = enter.append(onenter + "");
  1722. }
  1723. if (onupdate != null) {
  1724. update = onupdate(update);
  1725. if (update) update = update.selection();
  1726. }
  1727. if (onexit == null) exit.remove(); else onexit(exit);
  1728. return enter && update ? enter.merge(update).order() : update;
  1729. }
  1730. function selection_merge(context) {
  1731. var selection = context.selection ? context.selection() : context;
  1732. for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  1733. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  1734. if (node = group0[i] || group1[i]) {
  1735. merge[i] = node;
  1736. }
  1737. }
  1738. }
  1739. for (; j < m0; ++j) {
  1740. merges[j] = groups0[j];
  1741. }
  1742. return new Selection$1(merges, this._parents);
  1743. }
  1744. function selection_order() {
  1745. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  1746. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  1747. if (node = group[i]) {
  1748. if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
  1749. next = node;
  1750. }
  1751. }
  1752. }
  1753. return this;
  1754. }
  1755. function selection_sort(compare) {
  1756. if (!compare) compare = ascending$2;
  1757. function compareNode(a, b) {
  1758. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  1759. }
  1760. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  1761. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  1762. if (node = group[i]) {
  1763. sortgroup[i] = node;
  1764. }
  1765. }
  1766. sortgroup.sort(compareNode);
  1767. }
  1768. return new Selection$1(sortgroups, this._parents).order();
  1769. }
  1770. function ascending$2(a, b) {
  1771. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  1772. }
  1773. function selection_call() {
  1774. var callback = arguments[0];
  1775. arguments[0] = this;
  1776. callback.apply(null, arguments);
  1777. return this;
  1778. }
  1779. function selection_nodes() {
  1780. return Array.from(this);
  1781. }
  1782. function selection_node() {
  1783. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1784. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  1785. var node = group[i];
  1786. if (node) return node;
  1787. }
  1788. }
  1789. return null;
  1790. }
  1791. function selection_size() {
  1792. let size = 0;
  1793. for (const node of this) ++size; // eslint-disable-line no-unused-vars
  1794. return size;
  1795. }
  1796. function selection_empty() {
  1797. return !this.node();
  1798. }
  1799. function selection_each(callback) {
  1800. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1801. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  1802. if (node = group[i]) callback.call(node, node.__data__, i, group);
  1803. }
  1804. }
  1805. return this;
  1806. }
  1807. function attrRemove$1(name) {
  1808. return function() {
  1809. this.removeAttribute(name);
  1810. };
  1811. }
  1812. function attrRemoveNS$1(fullname) {
  1813. return function() {
  1814. this.removeAttributeNS(fullname.space, fullname.local);
  1815. };
  1816. }
  1817. function attrConstant$1(name, value) {
  1818. return function() {
  1819. this.setAttribute(name, value);
  1820. };
  1821. }
  1822. function attrConstantNS$1(fullname, value) {
  1823. return function() {
  1824. this.setAttributeNS(fullname.space, fullname.local, value);
  1825. };
  1826. }
  1827. function attrFunction$1(name, value) {
  1828. return function() {
  1829. var v = value.apply(this, arguments);
  1830. if (v == null) this.removeAttribute(name);
  1831. else this.setAttribute(name, v);
  1832. };
  1833. }
  1834. function attrFunctionNS$1(fullname, value) {
  1835. return function() {
  1836. var v = value.apply(this, arguments);
  1837. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1838. else this.setAttributeNS(fullname.space, fullname.local, v);
  1839. };
  1840. }
  1841. function selection_attr(name, value) {
  1842. var fullname = namespace(name);
  1843. if (arguments.length < 2) {
  1844. var node = this.node();
  1845. return fullname.local
  1846. ? node.getAttributeNS(fullname.space, fullname.local)
  1847. : node.getAttribute(fullname);
  1848. }
  1849. return this.each((value == null
  1850. ? (fullname.local ? attrRemoveNS$1 : attrRemove$1) : (typeof value === "function"
  1851. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)
  1852. : (fullname.local ? attrConstantNS$1 : attrConstant$1)))(fullname, value));
  1853. }
  1854. function defaultView(node) {
  1855. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1856. || (node.document && node) // node is a Window
  1857. || node.defaultView; // node is a Document
  1858. }
  1859. function styleRemove$1(name) {
  1860. return function() {
  1861. this.style.removeProperty(name);
  1862. };
  1863. }
  1864. function styleConstant$1(name, value, priority) {
  1865. return function() {
  1866. this.style.setProperty(name, value, priority);
  1867. };
  1868. }
  1869. function styleFunction$1(name, value, priority) {
  1870. return function() {
  1871. var v = value.apply(this, arguments);
  1872. if (v == null) this.style.removeProperty(name);
  1873. else this.style.setProperty(name, v, priority);
  1874. };
  1875. }
  1876. function selection_style(name, value, priority) {
  1877. return arguments.length > 1
  1878. ? this.each((value == null
  1879. ? styleRemove$1 : typeof value === "function"
  1880. ? styleFunction$1
  1881. : styleConstant$1)(name, value, priority == null ? "" : priority))
  1882. : styleValue(this.node(), name);
  1883. }
  1884. function styleValue(node, name) {
  1885. return node.style.getPropertyValue(name)
  1886. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1887. }
  1888. function propertyRemove(name) {
  1889. return function() {
  1890. delete this[name];
  1891. };
  1892. }
  1893. function propertyConstant(name, value) {
  1894. return function() {
  1895. this[name] = value;
  1896. };
  1897. }
  1898. function propertyFunction(name, value) {
  1899. return function() {
  1900. var v = value.apply(this, arguments);
  1901. if (v == null) delete this[name];
  1902. else this[name] = v;
  1903. };
  1904. }
  1905. function selection_property(name, value) {
  1906. return arguments.length > 1
  1907. ? this.each((value == null
  1908. ? propertyRemove : typeof value === "function"
  1909. ? propertyFunction
  1910. : propertyConstant)(name, value))
  1911. : this.node()[name];
  1912. }
  1913. function classArray(string) {
  1914. return string.trim().split(/^|\s+/);
  1915. }
  1916. function classList(node) {
  1917. return node.classList || new ClassList(node);
  1918. }
  1919. function ClassList(node) {
  1920. this._node = node;
  1921. this._names = classArray(node.getAttribute("class") || "");
  1922. }
  1923. ClassList.prototype = {
  1924. add: function(name) {
  1925. var i = this._names.indexOf(name);
  1926. if (i < 0) {
  1927. this._names.push(name);
  1928. this._node.setAttribute("class", this._names.join(" "));
  1929. }
  1930. },
  1931. remove: function(name) {
  1932. var i = this._names.indexOf(name);
  1933. if (i >= 0) {
  1934. this._names.splice(i, 1);
  1935. this._node.setAttribute("class", this._names.join(" "));
  1936. }
  1937. },
  1938. contains: function(name) {
  1939. return this._names.indexOf(name) >= 0;
  1940. }
  1941. };
  1942. function classedAdd(node, names) {
  1943. var list = classList(node), i = -1, n = names.length;
  1944. while (++i < n) list.add(names[i]);
  1945. }
  1946. function classedRemove(node, names) {
  1947. var list = classList(node), i = -1, n = names.length;
  1948. while (++i < n) list.remove(names[i]);
  1949. }
  1950. function classedTrue(names) {
  1951. return function() {
  1952. classedAdd(this, names);
  1953. };
  1954. }
  1955. function classedFalse(names) {
  1956. return function() {
  1957. classedRemove(this, names);
  1958. };
  1959. }
  1960. function classedFunction(names, value) {
  1961. return function() {
  1962. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1963. };
  1964. }
  1965. function selection_classed(name, value) {
  1966. var names = classArray(name + "");
  1967. if (arguments.length < 2) {
  1968. var list = classList(this.node()), i = -1, n = names.length;
  1969. while (++i < n) if (!list.contains(names[i])) return false;
  1970. return true;
  1971. }
  1972. return this.each((typeof value === "function"
  1973. ? classedFunction : value
  1974. ? classedTrue
  1975. : classedFalse)(names, value));
  1976. }
  1977. function textRemove() {
  1978. this.textContent = "";
  1979. }
  1980. function textConstant$1(value) {
  1981. return function() {
  1982. this.textContent = value;
  1983. };
  1984. }
  1985. function textFunction$1(value) {
  1986. return function() {
  1987. var v = value.apply(this, arguments);
  1988. this.textContent = v == null ? "" : v;
  1989. };
  1990. }
  1991. function selection_text(value) {
  1992. return arguments.length
  1993. ? this.each(value == null
  1994. ? textRemove : (typeof value === "function"
  1995. ? textFunction$1
  1996. : textConstant$1)(value))
  1997. : this.node().textContent;
  1998. }
  1999. function htmlRemove() {
  2000. this.innerHTML = "";
  2001. }
  2002. function htmlConstant(value) {
  2003. return function() {
  2004. this.innerHTML = value;
  2005. };
  2006. }
  2007. function htmlFunction(value) {
  2008. return function() {
  2009. var v = value.apply(this, arguments);
  2010. this.innerHTML = v == null ? "" : v;
  2011. };
  2012. }
  2013. function selection_html(value) {
  2014. return arguments.length
  2015. ? this.each(value == null
  2016. ? htmlRemove : (typeof value === "function"
  2017. ? htmlFunction
  2018. : htmlConstant)(value))
  2019. : this.node().innerHTML;
  2020. }
  2021. function raise() {
  2022. if (this.nextSibling) this.parentNode.appendChild(this);
  2023. }
  2024. function selection_raise() {
  2025. return this.each(raise);
  2026. }
  2027. function lower() {
  2028. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  2029. }
  2030. function selection_lower() {
  2031. return this.each(lower);
  2032. }
  2033. function selection_append(name) {
  2034. var create = typeof name === "function" ? name : creator(name);
  2035. return this.select(function() {
  2036. return this.appendChild(create.apply(this, arguments));
  2037. });
  2038. }
  2039. function constantNull() {
  2040. return null;
  2041. }
  2042. function selection_insert(name, before) {
  2043. var create = typeof name === "function" ? name : creator(name),
  2044. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  2045. return this.select(function() {
  2046. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  2047. });
  2048. }
  2049. function remove() {
  2050. var parent = this.parentNode;
  2051. if (parent) parent.removeChild(this);
  2052. }
  2053. function selection_remove() {
  2054. return this.each(remove);
  2055. }
  2056. function selection_cloneShallow() {
  2057. var clone = this.cloneNode(false), parent = this.parentNode;
  2058. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  2059. }
  2060. function selection_cloneDeep() {
  2061. var clone = this.cloneNode(true), parent = this.parentNode;
  2062. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  2063. }
  2064. function selection_clone(deep) {
  2065. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  2066. }
  2067. function selection_datum(value) {
  2068. return arguments.length
  2069. ? this.property("__data__", value)
  2070. : this.node().__data__;
  2071. }
  2072. function contextListener(listener) {
  2073. return function(event) {
  2074. listener.call(this, event, this.__data__);
  2075. };
  2076. }
  2077. function parseTypenames(typenames) {
  2078. return typenames.trim().split(/^|\s+/).map(function(t) {
  2079. var name = "", i = t.indexOf(".");
  2080. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  2081. return {type: t, name: name};
  2082. });
  2083. }
  2084. function onRemove(typename) {
  2085. return function() {
  2086. var on = this.__on;
  2087. if (!on) return;
  2088. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  2089. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  2090. this.removeEventListener(o.type, o.listener, o.options);
  2091. } else {
  2092. on[++i] = o;
  2093. }
  2094. }
  2095. if (++i) on.length = i;
  2096. else delete this.__on;
  2097. };
  2098. }
  2099. function onAdd(typename, value, options) {
  2100. return function() {
  2101. var on = this.__on, o, listener = contextListener(value);
  2102. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  2103. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  2104. this.removeEventListener(o.type, o.listener, o.options);
  2105. this.addEventListener(o.type, o.listener = listener, o.options = options);
  2106. o.value = value;
  2107. return;
  2108. }
  2109. }
  2110. this.addEventListener(typename.type, listener, options);
  2111. o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options};
  2112. if (!on) this.__on = [o];
  2113. else on.push(o);
  2114. };
  2115. }
  2116. function selection_on(typename, value, options) {
  2117. var typenames = parseTypenames(typename + ""), i, n = typenames.length, t;
  2118. if (arguments.length < 2) {
  2119. var on = this.node().__on;
  2120. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  2121. for (i = 0, o = on[j]; i < n; ++i) {
  2122. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  2123. return o.value;
  2124. }
  2125. }
  2126. }
  2127. return;
  2128. }
  2129. on = value ? onAdd : onRemove;
  2130. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options));
  2131. return this;
  2132. }
  2133. function dispatchEvent(node, type, params) {
  2134. var window = defaultView(node),
  2135. event = window.CustomEvent;
  2136. if (typeof event === "function") {
  2137. event = new event(type, params);
  2138. } else {
  2139. event = window.document.createEvent("Event");
  2140. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  2141. else event.initEvent(type, false, false);
  2142. }
  2143. node.dispatchEvent(event);
  2144. }
  2145. function dispatchConstant(type, params) {
  2146. return function() {
  2147. return dispatchEvent(this, type, params);
  2148. };
  2149. }
  2150. function dispatchFunction(type, params) {
  2151. return function() {
  2152. return dispatchEvent(this, type, params.apply(this, arguments));
  2153. };
  2154. }
  2155. function selection_dispatch(type, params) {
  2156. return this.each((typeof params === "function"
  2157. ? dispatchFunction
  2158. : dispatchConstant)(type, params));
  2159. }
  2160. function* selection_iterator() {
  2161. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  2162. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  2163. if (node = group[i]) yield node;
  2164. }
  2165. }
  2166. }
  2167. var root$1 = [null];
  2168. function Selection$1(groups, parents) {
  2169. this._groups = groups;
  2170. this._parents = parents;
  2171. }
  2172. function selection() {
  2173. return new Selection$1([[document.documentElement]], root$1);
  2174. }
  2175. function selection_selection() {
  2176. return this;
  2177. }
  2178. Selection$1.prototype = selection.prototype = {
  2179. constructor: Selection$1,
  2180. select: selection_select,
  2181. selectAll: selection_selectAll,
  2182. selectChild: selection_selectChild,
  2183. selectChildren: selection_selectChildren,
  2184. filter: selection_filter,
  2185. data: selection_data,
  2186. enter: selection_enter,
  2187. exit: selection_exit,
  2188. join: selection_join,
  2189. merge: selection_merge,
  2190. selection: selection_selection,
  2191. order: selection_order,
  2192. sort: selection_sort,
  2193. call: selection_call,
  2194. nodes: selection_nodes,
  2195. node: selection_node,
  2196. size: selection_size,
  2197. empty: selection_empty,
  2198. each: selection_each,
  2199. attr: selection_attr,
  2200. style: selection_style,
  2201. property: selection_property,
  2202. classed: selection_classed,
  2203. text: selection_text,
  2204. html: selection_html,
  2205. raise: selection_raise,
  2206. lower: selection_lower,
  2207. append: selection_append,
  2208. insert: selection_insert,
  2209. remove: selection_remove,
  2210. clone: selection_clone,
  2211. datum: selection_datum,
  2212. on: selection_on,
  2213. dispatch: selection_dispatch,
  2214. [Symbol.iterator]: selection_iterator
  2215. };
  2216. function select(selector) {
  2217. return typeof selector === "string"
  2218. ? new Selection$1([[document.querySelector(selector)]], [document.documentElement])
  2219. : new Selection$1([[selector]], root$1);
  2220. }
  2221. function create$1(name) {
  2222. return select(creator(name).call(document.documentElement));
  2223. }
  2224. var nextId = 0;
  2225. function local$1() {
  2226. return new Local;
  2227. }
  2228. function Local() {
  2229. this._ = "@" + (++nextId).toString(36);
  2230. }
  2231. Local.prototype = local$1.prototype = {
  2232. constructor: Local,
  2233. get: function(node) {
  2234. var id = this._;
  2235. while (!(id in node)) if (!(node = node.parentNode)) return;
  2236. return node[id];
  2237. },
  2238. set: function(node, value) {
  2239. return node[this._] = value;
  2240. },
  2241. remove: function(node) {
  2242. return this._ in node && delete node[this._];
  2243. },
  2244. toString: function() {
  2245. return this._;
  2246. }
  2247. };
  2248. function sourceEvent(event) {
  2249. let sourceEvent;
  2250. while (sourceEvent = event.sourceEvent) event = sourceEvent;
  2251. return event;
  2252. }
  2253. function pointer(event, node) {
  2254. event = sourceEvent(event);
  2255. if (node === undefined) node = event.currentTarget;
  2256. if (node) {
  2257. var svg = node.ownerSVGElement || node;
  2258. if (svg.createSVGPoint) {
  2259. var point = svg.createSVGPoint();
  2260. point.x = event.clientX, point.y = event.clientY;
  2261. point = point.matrixTransform(node.getScreenCTM().inverse());
  2262. return [point.x, point.y];
  2263. }
  2264. if (node.getBoundingClientRect) {
  2265. var rect = node.getBoundingClientRect();
  2266. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  2267. }
  2268. }
  2269. return [event.pageX, event.pageY];
  2270. }
  2271. function pointers(events, node) {
  2272. if (events.target) { // i.e., instanceof Event, not TouchList or iterable
  2273. events = sourceEvent(events);
  2274. if (node === undefined) node = events.currentTarget;
  2275. events = events.touches || [events];
  2276. }
  2277. return Array.from(events, event => pointer(event, node));
  2278. }
  2279. function selectAll(selector) {
  2280. return typeof selector === "string"
  2281. ? new Selection$1([document.querySelectorAll(selector)], [document.documentElement])
  2282. : new Selection$1([array$4(selector)], root$1);
  2283. }
  2284. // These are typically used in conjunction with noevent to ensure that we can
  2285. // preventDefault on the event.
  2286. const nonpassive = {passive: false};
  2287. const nonpassivecapture = {capture: true, passive: false};
  2288. function nopropagation$2(event) {
  2289. event.stopImmediatePropagation();
  2290. }
  2291. function noevent$2(event) {
  2292. event.preventDefault();
  2293. event.stopImmediatePropagation();
  2294. }
  2295. function dragDisable(view) {
  2296. var root = view.document.documentElement,
  2297. selection = select(view).on("dragstart.drag", noevent$2, nonpassivecapture);
  2298. if ("onselectstart" in root) {
  2299. selection.on("selectstart.drag", noevent$2, nonpassivecapture);
  2300. } else {
  2301. root.__noselect = root.style.MozUserSelect;
  2302. root.style.MozUserSelect = "none";
  2303. }
  2304. }
  2305. function yesdrag(view, noclick) {
  2306. var root = view.document.documentElement,
  2307. selection = select(view).on("dragstart.drag", null);
  2308. if (noclick) {
  2309. selection.on("click.drag", noevent$2, nonpassivecapture);
  2310. setTimeout(function() { selection.on("click.drag", null); }, 0);
  2311. }
  2312. if ("onselectstart" in root) {
  2313. selection.on("selectstart.drag", null);
  2314. } else {
  2315. root.style.MozUserSelect = root.__noselect;
  2316. delete root.__noselect;
  2317. }
  2318. }
  2319. var constant$9 = x => () => x;
  2320. function DragEvent(type, {
  2321. sourceEvent,
  2322. subject,
  2323. target,
  2324. identifier,
  2325. active,
  2326. x, y, dx, dy,
  2327. dispatch
  2328. }) {
  2329. Object.defineProperties(this, {
  2330. type: {value: type, enumerable: true, configurable: true},
  2331. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  2332. subject: {value: subject, enumerable: true, configurable: true},
  2333. target: {value: target, enumerable: true, configurable: true},
  2334. identifier: {value: identifier, enumerable: true, configurable: true},
  2335. active: {value: active, enumerable: true, configurable: true},
  2336. x: {value: x, enumerable: true, configurable: true},
  2337. y: {value: y, enumerable: true, configurable: true},
  2338. dx: {value: dx, enumerable: true, configurable: true},
  2339. dy: {value: dy, enumerable: true, configurable: true},
  2340. _: {value: dispatch}
  2341. });
  2342. }
  2343. DragEvent.prototype.on = function() {
  2344. var value = this._.on.apply(this._, arguments);
  2345. return value === this._ ? this : value;
  2346. };
  2347. // Ignore right-click, since that should open the context menu.
  2348. function defaultFilter$2(event) {
  2349. return !event.ctrlKey && !event.button;
  2350. }
  2351. function defaultContainer() {
  2352. return this.parentNode;
  2353. }
  2354. function defaultSubject(event, d) {
  2355. return d == null ? {x: event.x, y: event.y} : d;
  2356. }
  2357. function defaultTouchable$2() {
  2358. return navigator.maxTouchPoints || ("ontouchstart" in this);
  2359. }
  2360. function drag() {
  2361. var filter = defaultFilter$2,
  2362. container = defaultContainer,
  2363. subject = defaultSubject,
  2364. touchable = defaultTouchable$2,
  2365. gestures = {},
  2366. listeners = dispatch("start", "drag", "end"),
  2367. active = 0,
  2368. mousedownx,
  2369. mousedowny,
  2370. mousemoving,
  2371. touchending,
  2372. clickDistance2 = 0;
  2373. function drag(selection) {
  2374. selection
  2375. .on("mousedown.drag", mousedowned)
  2376. .filter(touchable)
  2377. .on("touchstart.drag", touchstarted)
  2378. .on("touchmove.drag", touchmoved, nonpassive)
  2379. .on("touchend.drag touchcancel.drag", touchended)
  2380. .style("touch-action", "none")
  2381. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  2382. }
  2383. function mousedowned(event, d) {
  2384. if (touchending || !filter.call(this, event, d)) return;
  2385. var gesture = beforestart(this, container.call(this, event, d), event, d, "mouse");
  2386. if (!gesture) return;
  2387. select(event.view)
  2388. .on("mousemove.drag", mousemoved, nonpassivecapture)
  2389. .on("mouseup.drag", mouseupped, nonpassivecapture);
  2390. dragDisable(event.view);
  2391. nopropagation$2(event);
  2392. mousemoving = false;
  2393. mousedownx = event.clientX;
  2394. mousedowny = event.clientY;
  2395. gesture("start", event);
  2396. }
  2397. function mousemoved(event) {
  2398. noevent$2(event);
  2399. if (!mousemoving) {
  2400. var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
  2401. mousemoving = dx * dx + dy * dy > clickDistance2;
  2402. }
  2403. gestures.mouse("drag", event);
  2404. }
  2405. function mouseupped(event) {
  2406. select(event.view).on("mousemove.drag mouseup.drag", null);
  2407. yesdrag(event.view, mousemoving);
  2408. noevent$2(event);
  2409. gestures.mouse("end", event);
  2410. }
  2411. function touchstarted(event, d) {
  2412. if (!filter.call(this, event, d)) return;
  2413. var touches = event.changedTouches,
  2414. c = container.call(this, event, d),
  2415. n = touches.length, i, gesture;
  2416. for (i = 0; i < n; ++i) {
  2417. if (gesture = beforestart(this, c, event, d, touches[i].identifier, touches[i])) {
  2418. nopropagation$2(event);
  2419. gesture("start", event, touches[i]);
  2420. }
  2421. }
  2422. }
  2423. function touchmoved(event) {
  2424. var touches = event.changedTouches,
  2425. n = touches.length, i, gesture;
  2426. for (i = 0; i < n; ++i) {
  2427. if (gesture = gestures[touches[i].identifier]) {
  2428. noevent$2(event);
  2429. gesture("drag", event, touches[i]);
  2430. }
  2431. }
  2432. }
  2433. function touchended(event) {
  2434. var touches = event.changedTouches,
  2435. n = touches.length, i, gesture;
  2436. if (touchending) clearTimeout(touchending);
  2437. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  2438. for (i = 0; i < n; ++i) {
  2439. if (gesture = gestures[touches[i].identifier]) {
  2440. nopropagation$2(event);
  2441. gesture("end", event, touches[i]);
  2442. }
  2443. }
  2444. }
  2445. function beforestart(that, container, event, d, identifier, touch) {
  2446. var dispatch = listeners.copy(),
  2447. p = pointer(touch || event, container), dx, dy,
  2448. s;
  2449. if ((s = subject.call(that, new DragEvent("beforestart", {
  2450. sourceEvent: event,
  2451. target: drag,
  2452. identifier,
  2453. active,
  2454. x: p[0],
  2455. y: p[1],
  2456. dx: 0,
  2457. dy: 0,
  2458. dispatch
  2459. }), d)) == null) return;
  2460. dx = s.x - p[0] || 0;
  2461. dy = s.y - p[1] || 0;
  2462. return function gesture(type, event, touch) {
  2463. var p0 = p, n;
  2464. switch (type) {
  2465. case "start": gestures[identifier] = gesture, n = active++; break;
  2466. case "end": delete gestures[identifier], --active; // falls through
  2467. case "drag": p = pointer(touch || event, container), n = active; break;
  2468. }
  2469. dispatch.call(
  2470. type,
  2471. that,
  2472. new DragEvent(type, {
  2473. sourceEvent: event,
  2474. subject: s,
  2475. target: drag,
  2476. identifier,
  2477. active: n,
  2478. x: p[0] + dx,
  2479. y: p[1] + dy,
  2480. dx: p[0] - p0[0],
  2481. dy: p[1] - p0[1],
  2482. dispatch
  2483. }),
  2484. d
  2485. );
  2486. };
  2487. }
  2488. drag.filter = function(_) {
  2489. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), drag) : filter;
  2490. };
  2491. drag.container = function(_) {
  2492. return arguments.length ? (container = typeof _ === "function" ? _ : constant$9(_), drag) : container;
  2493. };
  2494. drag.subject = function(_) {
  2495. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$9(_), drag) : subject;
  2496. };
  2497. drag.touchable = function(_) {
  2498. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$9(!!_), drag) : touchable;
  2499. };
  2500. drag.on = function() {
  2501. var value = listeners.on.apply(listeners, arguments);
  2502. return value === listeners ? drag : value;
  2503. };
  2504. drag.clickDistance = function(_) {
  2505. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  2506. };
  2507. return drag;
  2508. }
  2509. function define(constructor, factory, prototype) {
  2510. constructor.prototype = factory.prototype = prototype;
  2511. prototype.constructor = constructor;
  2512. }
  2513. function extend(parent, definition) {
  2514. var prototype = Object.create(parent.prototype);
  2515. for (var key in definition) prototype[key] = definition[key];
  2516. return prototype;
  2517. }
  2518. function Color() {}
  2519. var darker = 0.7;
  2520. var brighter = 1 / darker;
  2521. var reI = "\\s*([+-]?\\d+)\\s*",
  2522. reN = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  2523. reP = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  2524. reHex = /^#([0-9a-f]{3,8})$/,
  2525. reRgbInteger = new RegExp(`^rgb\\(${reI},${reI},${reI}\\)$`),
  2526. reRgbPercent = new RegExp(`^rgb\\(${reP},${reP},${reP}\\)$`),
  2527. reRgbaInteger = new RegExp(`^rgba\\(${reI},${reI},${reI},${reN}\\)$`),
  2528. reRgbaPercent = new RegExp(`^rgba\\(${reP},${reP},${reP},${reN}\\)$`),
  2529. reHslPercent = new RegExp(`^hsl\\(${reN},${reP},${reP}\\)$`),
  2530. reHslaPercent = new RegExp(`^hsla\\(${reN},${reP},${reP},${reN}\\)$`);
  2531. var named = {
  2532. aliceblue: 0xf0f8ff,
  2533. antiquewhite: 0xfaebd7,
  2534. aqua: 0x00ffff,
  2535. aquamarine: 0x7fffd4,
  2536. azure: 0xf0ffff,
  2537. beige: 0xf5f5dc,
  2538. bisque: 0xffe4c4,
  2539. black: 0x000000,
  2540. blanchedalmond: 0xffebcd,
  2541. blue: 0x0000ff,
  2542. blueviolet: 0x8a2be2,
  2543. brown: 0xa52a2a,
  2544. burlywood: 0xdeb887,
  2545. cadetblue: 0x5f9ea0,
  2546. chartreuse: 0x7fff00,
  2547. chocolate: 0xd2691e,
  2548. coral: 0xff7f50,
  2549. cornflowerblue: 0x6495ed,
  2550. cornsilk: 0xfff8dc,
  2551. crimson: 0xdc143c,
  2552. cyan: 0x00ffff,
  2553. darkblue: 0x00008b,
  2554. darkcyan: 0x008b8b,
  2555. darkgoldenrod: 0xb8860b,
  2556. darkgray: 0xa9a9a9,
  2557. darkgreen: 0x006400,
  2558. darkgrey: 0xa9a9a9,
  2559. darkkhaki: 0xbdb76b,
  2560. darkmagenta: 0x8b008b,
  2561. darkolivegreen: 0x556b2f,
  2562. darkorange: 0xff8c00,
  2563. darkorchid: 0x9932cc,
  2564. darkred: 0x8b0000,
  2565. darksalmon: 0xe9967a,
  2566. darkseagreen: 0x8fbc8f,
  2567. darkslateblue: 0x483d8b,
  2568. darkslategray: 0x2f4f4f,
  2569. darkslategrey: 0x2f4f4f,
  2570. darkturquoise: 0x00ced1,
  2571. darkviolet: 0x9400d3,
  2572. deeppink: 0xff1493,
  2573. deepskyblue: 0x00bfff,
  2574. dimgray: 0x696969,
  2575. dimgrey: 0x696969,
  2576. dodgerblue: 0x1e90ff,
  2577. firebrick: 0xb22222,
  2578. floralwhite: 0xfffaf0,
  2579. forestgreen: 0x228b22,
  2580. fuchsia: 0xff00ff,
  2581. gainsboro: 0xdcdcdc,
  2582. ghostwhite: 0xf8f8ff,
  2583. gold: 0xffd700,
  2584. goldenrod: 0xdaa520,
  2585. gray: 0x808080,
  2586. green: 0x008000,
  2587. greenyellow: 0xadff2f,
  2588. grey: 0x808080,
  2589. honeydew: 0xf0fff0,
  2590. hotpink: 0xff69b4,
  2591. indianred: 0xcd5c5c,
  2592. indigo: 0x4b0082,
  2593. ivory: 0xfffff0,
  2594. khaki: 0xf0e68c,
  2595. lavender: 0xe6e6fa,
  2596. lavenderblush: 0xfff0f5,
  2597. lawngreen: 0x7cfc00,
  2598. lemonchiffon: 0xfffacd,
  2599. lightblue: 0xadd8e6,
  2600. lightcoral: 0xf08080,
  2601. lightcyan: 0xe0ffff,
  2602. lightgoldenrodyellow: 0xfafad2,
  2603. lightgray: 0xd3d3d3,
  2604. lightgreen: 0x90ee90,
  2605. lightgrey: 0xd3d3d3,
  2606. lightpink: 0xffb6c1,
  2607. lightsalmon: 0xffa07a,
  2608. lightseagreen: 0x20b2aa,
  2609. lightskyblue: 0x87cefa,
  2610. lightslategray: 0x778899,
  2611. lightslategrey: 0x778899,
  2612. lightsteelblue: 0xb0c4de,
  2613. lightyellow: 0xffffe0,
  2614. lime: 0x00ff00,
  2615. limegreen: 0x32cd32,
  2616. linen: 0xfaf0e6,
  2617. magenta: 0xff00ff,
  2618. maroon: 0x800000,
  2619. mediumaquamarine: 0x66cdaa,
  2620. mediumblue: 0x0000cd,
  2621. mediumorchid: 0xba55d3,
  2622. mediumpurple: 0x9370db,
  2623. mediumseagreen: 0x3cb371,
  2624. mediumslateblue: 0x7b68ee,
  2625. mediumspringgreen: 0x00fa9a,
  2626. mediumturquoise: 0x48d1cc,
  2627. mediumvioletred: 0xc71585,
  2628. midnightblue: 0x191970,
  2629. mintcream: 0xf5fffa,
  2630. mistyrose: 0xffe4e1,
  2631. moccasin: 0xffe4b5,
  2632. navajowhite: 0xffdead,
  2633. navy: 0x000080,
  2634. oldlace: 0xfdf5e6,
  2635. olive: 0x808000,
  2636. olivedrab: 0x6b8e23,
  2637. orange: 0xffa500,
  2638. orangered: 0xff4500,
  2639. orchid: 0xda70d6,
  2640. palegoldenrod: 0xeee8aa,
  2641. palegreen: 0x98fb98,
  2642. paleturquoise: 0xafeeee,
  2643. palevioletred: 0xdb7093,
  2644. papayawhip: 0xffefd5,
  2645. peachpuff: 0xffdab9,
  2646. peru: 0xcd853f,
  2647. pink: 0xffc0cb,
  2648. plum: 0xdda0dd,
  2649. powderblue: 0xb0e0e6,
  2650. purple: 0x800080,
  2651. rebeccapurple: 0x663399,
  2652. red: 0xff0000,
  2653. rosybrown: 0xbc8f8f,
  2654. royalblue: 0x4169e1,
  2655. saddlebrown: 0x8b4513,
  2656. salmon: 0xfa8072,
  2657. sandybrown: 0xf4a460,
  2658. seagreen: 0x2e8b57,
  2659. seashell: 0xfff5ee,
  2660. sienna: 0xa0522d,
  2661. silver: 0xc0c0c0,
  2662. skyblue: 0x87ceeb,
  2663. slateblue: 0x6a5acd,
  2664. slategray: 0x708090,
  2665. slategrey: 0x708090,
  2666. snow: 0xfffafa,
  2667. springgreen: 0x00ff7f,
  2668. steelblue: 0x4682b4,
  2669. tan: 0xd2b48c,
  2670. teal: 0x008080,
  2671. thistle: 0xd8bfd8,
  2672. tomato: 0xff6347,
  2673. turquoise: 0x40e0d0,
  2674. violet: 0xee82ee,
  2675. wheat: 0xf5deb3,
  2676. white: 0xffffff,
  2677. whitesmoke: 0xf5f5f5,
  2678. yellow: 0xffff00,
  2679. yellowgreen: 0x9acd32
  2680. };
  2681. define(Color, color, {
  2682. copy(channels) {
  2683. return Object.assign(new this.constructor, this, channels);
  2684. },
  2685. displayable() {
  2686. return this.rgb().displayable();
  2687. },
  2688. hex: color_formatHex, // Deprecated! Use color.formatHex.
  2689. formatHex: color_formatHex,
  2690. formatHex8: color_formatHex8,
  2691. formatHsl: color_formatHsl,
  2692. formatRgb: color_formatRgb,
  2693. toString: color_formatRgb
  2694. });
  2695. function color_formatHex() {
  2696. return this.rgb().formatHex();
  2697. }
  2698. function color_formatHex8() {
  2699. return this.rgb().formatHex8();
  2700. }
  2701. function color_formatHsl() {
  2702. return hslConvert(this).formatHsl();
  2703. }
  2704. function color_formatRgb() {
  2705. return this.rgb().formatRgb();
  2706. }
  2707. function color(format) {
  2708. var m, l;
  2709. format = (format + "").trim().toLowerCase();
  2710. return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
  2711. : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
  2712. : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
  2713. : l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
  2714. : null) // invalid hex
  2715. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  2716. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  2717. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  2718. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  2719. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  2720. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  2721. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  2722. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  2723. : null;
  2724. }
  2725. function rgbn(n) {
  2726. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  2727. }
  2728. function rgba(r, g, b, a) {
  2729. if (a <= 0) r = g = b = NaN;
  2730. return new Rgb(r, g, b, a);
  2731. }
  2732. function rgbConvert(o) {
  2733. if (!(o instanceof Color)) o = color(o);
  2734. if (!o) return new Rgb;
  2735. o = o.rgb();
  2736. return new Rgb(o.r, o.g, o.b, o.opacity);
  2737. }
  2738. function rgb(r, g, b, opacity) {
  2739. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  2740. }
  2741. function Rgb(r, g, b, opacity) {
  2742. this.r = +r;
  2743. this.g = +g;
  2744. this.b = +b;
  2745. this.opacity = +opacity;
  2746. }
  2747. define(Rgb, rgb, extend(Color, {
  2748. brighter(k) {
  2749. k = k == null ? brighter : Math.pow(brighter, k);
  2750. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  2751. },
  2752. darker(k) {
  2753. k = k == null ? darker : Math.pow(darker, k);
  2754. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  2755. },
  2756. rgb() {
  2757. return this;
  2758. },
  2759. clamp() {
  2760. return new Rgb(clampi(this.r), clampi(this.g), clampi(this.b), clampa(this.opacity));
  2761. },
  2762. displayable() {
  2763. return (-0.5 <= this.r && this.r < 255.5)
  2764. && (-0.5 <= this.g && this.g < 255.5)
  2765. && (-0.5 <= this.b && this.b < 255.5)
  2766. && (0 <= this.opacity && this.opacity <= 1);
  2767. },
  2768. hex: rgb_formatHex, // Deprecated! Use color.formatHex.
  2769. formatHex: rgb_formatHex,
  2770. formatHex8: rgb_formatHex8,
  2771. formatRgb: rgb_formatRgb,
  2772. toString: rgb_formatRgb
  2773. }));
  2774. function rgb_formatHex() {
  2775. return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}`;
  2776. }
  2777. function rgb_formatHex8() {
  2778. return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}${hex((isNaN(this.opacity) ? 1 : this.opacity) * 255)}`;
  2779. }
  2780. function rgb_formatRgb() {
  2781. const a = clampa(this.opacity);
  2782. return `${a === 1 ? "rgb(" : "rgba("}${clampi(this.r)}, ${clampi(this.g)}, ${clampi(this.b)}${a === 1 ? ")" : `, ${a})`}`;
  2783. }
  2784. function clampa(opacity) {
  2785. return isNaN(opacity) ? 1 : Math.max(0, Math.min(1, opacity));
  2786. }
  2787. function clampi(value) {
  2788. return Math.max(0, Math.min(255, Math.round(value) || 0));
  2789. }
  2790. function hex(value) {
  2791. value = clampi(value);
  2792. return (value < 16 ? "0" : "") + value.toString(16);
  2793. }
  2794. function hsla(h, s, l, a) {
  2795. if (a <= 0) h = s = l = NaN;
  2796. else if (l <= 0 || l >= 1) h = s = NaN;
  2797. else if (s <= 0) h = NaN;
  2798. return new Hsl(h, s, l, a);
  2799. }
  2800. function hslConvert(o) {
  2801. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  2802. if (!(o instanceof Color)) o = color(o);
  2803. if (!o) return new Hsl;
  2804. if (o instanceof Hsl) return o;
  2805. o = o.rgb();
  2806. var r = o.r / 255,
  2807. g = o.g / 255,
  2808. b = o.b / 255,
  2809. min = Math.min(r, g, b),
  2810. max = Math.max(r, g, b),
  2811. h = NaN,
  2812. s = max - min,
  2813. l = (max + min) / 2;
  2814. if (s) {
  2815. if (r === max) h = (g - b) / s + (g < b) * 6;
  2816. else if (g === max) h = (b - r) / s + 2;
  2817. else h = (r - g) / s + 4;
  2818. s /= l < 0.5 ? max + min : 2 - max - min;
  2819. h *= 60;
  2820. } else {
  2821. s = l > 0 && l < 1 ? 0 : h;
  2822. }
  2823. return new Hsl(h, s, l, o.opacity);
  2824. }
  2825. function hsl$2(h, s, l, opacity) {
  2826. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  2827. }
  2828. function Hsl(h, s, l, opacity) {
  2829. this.h = +h;
  2830. this.s = +s;
  2831. this.l = +l;
  2832. this.opacity = +opacity;
  2833. }
  2834. define(Hsl, hsl$2, extend(Color, {
  2835. brighter(k) {
  2836. k = k == null ? brighter : Math.pow(brighter, k);
  2837. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  2838. },
  2839. darker(k) {
  2840. k = k == null ? darker : Math.pow(darker, k);
  2841. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  2842. },
  2843. rgb() {
  2844. var h = this.h % 360 + (this.h < 0) * 360,
  2845. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  2846. l = this.l,
  2847. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  2848. m1 = 2 * l - m2;
  2849. return new Rgb(
  2850. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  2851. hsl2rgb(h, m1, m2),
  2852. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  2853. this.opacity
  2854. );
  2855. },
  2856. clamp() {
  2857. return new Hsl(clamph(this.h), clampt(this.s), clampt(this.l), clampa(this.opacity));
  2858. },
  2859. displayable() {
  2860. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  2861. && (0 <= this.l && this.l <= 1)
  2862. && (0 <= this.opacity && this.opacity <= 1);
  2863. },
  2864. formatHsl() {
  2865. const a = clampa(this.opacity);
  2866. return `${a === 1 ? "hsl(" : "hsla("}${clamph(this.h)}, ${clampt(this.s) * 100}%, ${clampt(this.l) * 100}%${a === 1 ? ")" : `, ${a})`}`;
  2867. }
  2868. }));
  2869. function clamph(value) {
  2870. value = (value || 0) % 360;
  2871. return value < 0 ? value + 360 : value;
  2872. }
  2873. function clampt(value) {
  2874. return Math.max(0, Math.min(1, value || 0));
  2875. }
  2876. /* From FvD 13.37, CSS Color Module Level 3 */
  2877. function hsl2rgb(h, m1, m2) {
  2878. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2879. : h < 180 ? m2
  2880. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2881. : m1) * 255;
  2882. }
  2883. const radians$1 = Math.PI / 180;
  2884. const degrees$2 = 180 / Math.PI;
  2885. // https://observablehq.com/@mbostock/lab-and-rgb
  2886. const K = 18,
  2887. Xn = 0.96422,
  2888. Yn = 1,
  2889. Zn = 0.82521,
  2890. t0$1 = 4 / 29,
  2891. t1$1 = 6 / 29,
  2892. t2 = 3 * t1$1 * t1$1,
  2893. t3 = t1$1 * t1$1 * t1$1;
  2894. function labConvert(o) {
  2895. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2896. if (o instanceof Hcl) return hcl2lab(o);
  2897. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2898. var r = rgb2lrgb(o.r),
  2899. g = rgb2lrgb(o.g),
  2900. b = rgb2lrgb(o.b),
  2901. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2902. if (r === g && g === b) x = z = y; else {
  2903. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2904. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2905. }
  2906. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2907. }
  2908. function gray(l, opacity) {
  2909. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2910. }
  2911. function lab$1(l, a, b, opacity) {
  2912. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2913. }
  2914. function Lab(l, a, b, opacity) {
  2915. this.l = +l;
  2916. this.a = +a;
  2917. this.b = +b;
  2918. this.opacity = +opacity;
  2919. }
  2920. define(Lab, lab$1, extend(Color, {
  2921. brighter(k) {
  2922. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2923. },
  2924. darker(k) {
  2925. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2926. },
  2927. rgb() {
  2928. var y = (this.l + 16) / 116,
  2929. x = isNaN(this.a) ? y : y + this.a / 500,
  2930. z = isNaN(this.b) ? y : y - this.b / 200;
  2931. x = Xn * lab2xyz(x);
  2932. y = Yn * lab2xyz(y);
  2933. z = Zn * lab2xyz(z);
  2934. return new Rgb(
  2935. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2936. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2937. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2938. this.opacity
  2939. );
  2940. }
  2941. }));
  2942. function xyz2lab(t) {
  2943. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0$1;
  2944. }
  2945. function lab2xyz(t) {
  2946. return t > t1$1 ? t * t * t : t2 * (t - t0$1);
  2947. }
  2948. function lrgb2rgb(x) {
  2949. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2950. }
  2951. function rgb2lrgb(x) {
  2952. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2953. }
  2954. function hclConvert(o) {
  2955. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2956. if (!(o instanceof Lab)) o = labConvert(o);
  2957. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
  2958. var h = Math.atan2(o.b, o.a) * degrees$2;
  2959. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2960. }
  2961. function lch(l, c, h, opacity) {
  2962. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2963. }
  2964. function hcl$2(h, c, l, opacity) {
  2965. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2966. }
  2967. function Hcl(h, c, l, opacity) {
  2968. this.h = +h;
  2969. this.c = +c;
  2970. this.l = +l;
  2971. this.opacity = +opacity;
  2972. }
  2973. function hcl2lab(o) {
  2974. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2975. var h = o.h * radians$1;
  2976. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2977. }
  2978. define(Hcl, hcl$2, extend(Color, {
  2979. brighter(k) {
  2980. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2981. },
  2982. darker(k) {
  2983. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2984. },
  2985. rgb() {
  2986. return hcl2lab(this).rgb();
  2987. }
  2988. }));
  2989. var A = -0.14861,
  2990. B$1 = +1.78277,
  2991. C = -0.29227,
  2992. D$1 = -0.90649,
  2993. E = +1.97294,
  2994. ED = E * D$1,
  2995. EB = E * B$1,
  2996. BC_DA = B$1 * C - D$1 * A;
  2997. function cubehelixConvert(o) {
  2998. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2999. if (!(o instanceof Rgb)) o = rgbConvert(o);
  3000. var r = o.r / 255,
  3001. g = o.g / 255,
  3002. b = o.b / 255,
  3003. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  3004. bl = b - l,
  3005. k = (E * (g - l) - C * bl) / D$1,
  3006. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  3007. h = s ? Math.atan2(k, bl) * degrees$2 - 120 : NaN;
  3008. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  3009. }
  3010. function cubehelix$3(h, s, l, opacity) {
  3011. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  3012. }
  3013. function Cubehelix(h, s, l, opacity) {
  3014. this.h = +h;
  3015. this.s = +s;
  3016. this.l = +l;
  3017. this.opacity = +opacity;
  3018. }
  3019. define(Cubehelix, cubehelix$3, extend(Color, {
  3020. brighter(k) {
  3021. k = k == null ? brighter : Math.pow(brighter, k);
  3022. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3023. },
  3024. darker(k) {
  3025. k = k == null ? darker : Math.pow(darker, k);
  3026. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3027. },
  3028. rgb() {
  3029. var h = isNaN(this.h) ? 0 : (this.h + 120) * radians$1,
  3030. l = +this.l,
  3031. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  3032. cosh = Math.cos(h),
  3033. sinh = Math.sin(h);
  3034. return new Rgb(
  3035. 255 * (l + a * (A * cosh + B$1 * sinh)),
  3036. 255 * (l + a * (C * cosh + D$1 * sinh)),
  3037. 255 * (l + a * (E * cosh)),
  3038. this.opacity
  3039. );
  3040. }
  3041. }));
  3042. function basis$1(t1, v0, v1, v2, v3) {
  3043. var t2 = t1 * t1, t3 = t2 * t1;
  3044. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  3045. + (4 - 6 * t2 + 3 * t3) * v1
  3046. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  3047. + t3 * v3) / 6;
  3048. }
  3049. function basis$2(values) {
  3050. var n = values.length - 1;
  3051. return function(t) {
  3052. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  3053. v1 = values[i],
  3054. v2 = values[i + 1],
  3055. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  3056. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  3057. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3058. };
  3059. }
  3060. function basisClosed$1(values) {
  3061. var n = values.length;
  3062. return function(t) {
  3063. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  3064. v0 = values[(i + n - 1) % n],
  3065. v1 = values[i % n],
  3066. v2 = values[(i + 1) % n],
  3067. v3 = values[(i + 2) % n];
  3068. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3069. };
  3070. }
  3071. var constant$8 = x => () => x;
  3072. function linear$2(a, d) {
  3073. return function(t) {
  3074. return a + t * d;
  3075. };
  3076. }
  3077. function exponential$1(a, b, y) {
  3078. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  3079. return Math.pow(a + t * b, y);
  3080. };
  3081. }
  3082. function hue$1(a, b) {
  3083. var d = b - a;
  3084. return d ? linear$2(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$8(isNaN(a) ? b : a);
  3085. }
  3086. function gamma$1(y) {
  3087. return (y = +y) === 1 ? nogamma : function(a, b) {
  3088. return b - a ? exponential$1(a, b, y) : constant$8(isNaN(a) ? b : a);
  3089. };
  3090. }
  3091. function nogamma(a, b) {
  3092. var d = b - a;
  3093. return d ? linear$2(a, d) : constant$8(isNaN(a) ? b : a);
  3094. }
  3095. var interpolateRgb = (function rgbGamma(y) {
  3096. var color = gamma$1(y);
  3097. function rgb$1(start, end) {
  3098. var r = color((start = rgb(start)).r, (end = rgb(end)).r),
  3099. g = color(start.g, end.g),
  3100. b = color(start.b, end.b),
  3101. opacity = nogamma(start.opacity, end.opacity);
  3102. return function(t) {
  3103. start.r = r(t);
  3104. start.g = g(t);
  3105. start.b = b(t);
  3106. start.opacity = opacity(t);
  3107. return start + "";
  3108. };
  3109. }
  3110. rgb$1.gamma = rgbGamma;
  3111. return rgb$1;
  3112. })(1);
  3113. function rgbSpline(spline) {
  3114. return function(colors) {
  3115. var n = colors.length,
  3116. r = new Array(n),
  3117. g = new Array(n),
  3118. b = new Array(n),
  3119. i, color;
  3120. for (i = 0; i < n; ++i) {
  3121. color = rgb(colors[i]);
  3122. r[i] = color.r || 0;
  3123. g[i] = color.g || 0;
  3124. b[i] = color.b || 0;
  3125. }
  3126. r = spline(r);
  3127. g = spline(g);
  3128. b = spline(b);
  3129. color.opacity = 1;
  3130. return function(t) {
  3131. color.r = r(t);
  3132. color.g = g(t);
  3133. color.b = b(t);
  3134. return color + "";
  3135. };
  3136. };
  3137. }
  3138. var rgbBasis = rgbSpline(basis$2);
  3139. var rgbBasisClosed = rgbSpline(basisClosed$1);
  3140. function numberArray(a, b) {
  3141. if (!b) b = [];
  3142. var n = a ? Math.min(b.length, a.length) : 0,
  3143. c = b.slice(),
  3144. i;
  3145. return function(t) {
  3146. for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
  3147. return c;
  3148. };
  3149. }
  3150. function isNumberArray(x) {
  3151. return ArrayBuffer.isView(x) && !(x instanceof DataView);
  3152. }
  3153. function array$3(a, b) {
  3154. return (isNumberArray(b) ? numberArray : genericArray)(a, b);
  3155. }
  3156. function genericArray(a, b) {
  3157. var nb = b ? b.length : 0,
  3158. na = a ? Math.min(nb, a.length) : 0,
  3159. x = new Array(na),
  3160. c = new Array(nb),
  3161. i;
  3162. for (i = 0; i < na; ++i) x[i] = interpolate$2(a[i], b[i]);
  3163. for (; i < nb; ++i) c[i] = b[i];
  3164. return function(t) {
  3165. for (i = 0; i < na; ++i) c[i] = x[i](t);
  3166. return c;
  3167. };
  3168. }
  3169. function date$1(a, b) {
  3170. var d = new Date;
  3171. return a = +a, b = +b, function(t) {
  3172. return d.setTime(a * (1 - t) + b * t), d;
  3173. };
  3174. }
  3175. function interpolateNumber(a, b) {
  3176. return a = +a, b = +b, function(t) {
  3177. return a * (1 - t) + b * t;
  3178. };
  3179. }
  3180. function object$1(a, b) {
  3181. var i = {},
  3182. c = {},
  3183. k;
  3184. if (a === null || typeof a !== "object") a = {};
  3185. if (b === null || typeof b !== "object") b = {};
  3186. for (k in b) {
  3187. if (k in a) {
  3188. i[k] = interpolate$2(a[k], b[k]);
  3189. } else {
  3190. c[k] = b[k];
  3191. }
  3192. }
  3193. return function(t) {
  3194. for (k in i) c[k] = i[k](t);
  3195. return c;
  3196. };
  3197. }
  3198. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  3199. reB = new RegExp(reA.source, "g");
  3200. function zero(b) {
  3201. return function() {
  3202. return b;
  3203. };
  3204. }
  3205. function one(b) {
  3206. return function(t) {
  3207. return b(t) + "";
  3208. };
  3209. }
  3210. function interpolateString(a, b) {
  3211. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  3212. am, // current match in a
  3213. bm, // current match in b
  3214. bs, // string preceding current number in b, if any
  3215. i = -1, // index in s
  3216. s = [], // string constants and placeholders
  3217. q = []; // number interpolators
  3218. // Coerce inputs to strings.
  3219. a = a + "", b = b + "";
  3220. // Interpolate pairs of numbers in a & b.
  3221. while ((am = reA.exec(a))
  3222. && (bm = reB.exec(b))) {
  3223. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  3224. bs = b.slice(bi, bs);
  3225. if (s[i]) s[i] += bs; // coalesce with previous string
  3226. else s[++i] = bs;
  3227. }
  3228. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  3229. if (s[i]) s[i] += bm; // coalesce with previous string
  3230. else s[++i] = bm;
  3231. } else { // interpolate non-matching numbers
  3232. s[++i] = null;
  3233. q.push({i: i, x: interpolateNumber(am, bm)});
  3234. }
  3235. bi = reB.lastIndex;
  3236. }
  3237. // Add remains of b.
  3238. if (bi < b.length) {
  3239. bs = b.slice(bi);
  3240. if (s[i]) s[i] += bs; // coalesce with previous string
  3241. else s[++i] = bs;
  3242. }
  3243. // Special optimization for only a single match.
  3244. // Otherwise, interpolate each of the numbers and rejoin the string.
  3245. return s.length < 2 ? (q[0]
  3246. ? one(q[0].x)
  3247. : zero(b))
  3248. : (b = q.length, function(t) {
  3249. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  3250. return s.join("");
  3251. });
  3252. }
  3253. function interpolate$2(a, b) {
  3254. var t = typeof b, c;
  3255. return b == null || t === "boolean" ? constant$8(b)
  3256. : (t === "number" ? interpolateNumber
  3257. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  3258. : b instanceof color ? interpolateRgb
  3259. : b instanceof Date ? date$1
  3260. : isNumberArray(b) ? numberArray
  3261. : Array.isArray(b) ? genericArray
  3262. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object$1
  3263. : interpolateNumber)(a, b);
  3264. }
  3265. function discrete(range) {
  3266. var n = range.length;
  3267. return function(t) {
  3268. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  3269. };
  3270. }
  3271. function hue(a, b) {
  3272. var i = hue$1(+a, +b);
  3273. return function(t) {
  3274. var x = i(t);
  3275. return x - 360 * Math.floor(x / 360);
  3276. };
  3277. }
  3278. function interpolateRound(a, b) {
  3279. return a = +a, b = +b, function(t) {
  3280. return Math.round(a * (1 - t) + b * t);
  3281. };
  3282. }
  3283. var degrees$1 = 180 / Math.PI;
  3284. var identity$7 = {
  3285. translateX: 0,
  3286. translateY: 0,
  3287. rotate: 0,
  3288. skewX: 0,
  3289. scaleX: 1,
  3290. scaleY: 1
  3291. };
  3292. function decompose(a, b, c, d, e, f) {
  3293. var scaleX, scaleY, skewX;
  3294. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  3295. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  3296. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  3297. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  3298. return {
  3299. translateX: e,
  3300. translateY: f,
  3301. rotate: Math.atan2(b, a) * degrees$1,
  3302. skewX: Math.atan(skewX) * degrees$1,
  3303. scaleX: scaleX,
  3304. scaleY: scaleY
  3305. };
  3306. }
  3307. var svgNode;
  3308. /* eslint-disable no-undef */
  3309. function parseCss(value) {
  3310. const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
  3311. return m.isIdentity ? identity$7 : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
  3312. }
  3313. function parseSvg(value) {
  3314. if (value == null) return identity$7;
  3315. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  3316. svgNode.setAttribute("transform", value);
  3317. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$7;
  3318. value = value.matrix;
  3319. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  3320. }
  3321. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  3322. function pop(s) {
  3323. return s.length ? s.pop() + " " : "";
  3324. }
  3325. function translate(xa, ya, xb, yb, s, q) {
  3326. if (xa !== xb || ya !== yb) {
  3327. var i = s.push("translate(", null, pxComma, null, pxParen);
  3328. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3329. } else if (xb || yb) {
  3330. s.push("translate(" + xb + pxComma + yb + pxParen);
  3331. }
  3332. }
  3333. function rotate(a, b, s, q) {
  3334. if (a !== b) {
  3335. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  3336. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3337. } else if (b) {
  3338. s.push(pop(s) + "rotate(" + b + degParen);
  3339. }
  3340. }
  3341. function skewX(a, b, s, q) {
  3342. if (a !== b) {
  3343. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3344. } else if (b) {
  3345. s.push(pop(s) + "skewX(" + b + degParen);
  3346. }
  3347. }
  3348. function scale(xa, ya, xb, yb, s, q) {
  3349. if (xa !== xb || ya !== yb) {
  3350. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  3351. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3352. } else if (xb !== 1 || yb !== 1) {
  3353. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  3354. }
  3355. }
  3356. return function(a, b) {
  3357. var s = [], // string constants and placeholders
  3358. q = []; // number interpolators
  3359. a = parse(a), b = parse(b);
  3360. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  3361. rotate(a.rotate, b.rotate, s, q);
  3362. skewX(a.skewX, b.skewX, s, q);
  3363. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  3364. a = b = null; // gc
  3365. return function(t) {
  3366. var i = -1, n = q.length, o;
  3367. while (++i < n) s[(o = q[i]).i] = o.x(t);
  3368. return s.join("");
  3369. };
  3370. };
  3371. }
  3372. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  3373. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  3374. var epsilon2$1 = 1e-12;
  3375. function cosh(x) {
  3376. return ((x = Math.exp(x)) + 1 / x) / 2;
  3377. }
  3378. function sinh(x) {
  3379. return ((x = Math.exp(x)) - 1 / x) / 2;
  3380. }
  3381. function tanh(x) {
  3382. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  3383. }
  3384. var interpolateZoom = (function zoomRho(rho, rho2, rho4) {
  3385. // p0 = [ux0, uy0, w0]
  3386. // p1 = [ux1, uy1, w1]
  3387. function zoom(p0, p1) {
  3388. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  3389. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  3390. dx = ux1 - ux0,
  3391. dy = uy1 - uy0,
  3392. d2 = dx * dx + dy * dy,
  3393. i,
  3394. S;
  3395. // Special case for u0 ≅ u1.
  3396. if (d2 < epsilon2$1) {
  3397. S = Math.log(w1 / w0) / rho;
  3398. i = function(t) {
  3399. return [
  3400. ux0 + t * dx,
  3401. uy0 + t * dy,
  3402. w0 * Math.exp(rho * t * S)
  3403. ];
  3404. };
  3405. }
  3406. // General case.
  3407. else {
  3408. var d1 = Math.sqrt(d2),
  3409. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  3410. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  3411. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  3412. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  3413. S = (r1 - r0) / rho;
  3414. i = function(t) {
  3415. var s = t * S,
  3416. coshr0 = cosh(r0),
  3417. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  3418. return [
  3419. ux0 + u * dx,
  3420. uy0 + u * dy,
  3421. w0 * coshr0 / cosh(rho * s + r0)
  3422. ];
  3423. };
  3424. }
  3425. i.duration = S * 1000 * rho / Math.SQRT2;
  3426. return i;
  3427. }
  3428. zoom.rho = function(_) {
  3429. var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
  3430. return zoomRho(_1, _2, _4);
  3431. };
  3432. return zoom;
  3433. })(Math.SQRT2, 2, 4);
  3434. function hsl(hue) {
  3435. return function(start, end) {
  3436. var h = hue((start = hsl$2(start)).h, (end = hsl$2(end)).h),
  3437. s = nogamma(start.s, end.s),
  3438. l = nogamma(start.l, end.l),
  3439. opacity = nogamma(start.opacity, end.opacity);
  3440. return function(t) {
  3441. start.h = h(t);
  3442. start.s = s(t);
  3443. start.l = l(t);
  3444. start.opacity = opacity(t);
  3445. return start + "";
  3446. };
  3447. }
  3448. }
  3449. var hsl$1 = hsl(hue$1);
  3450. var hslLong = hsl(nogamma);
  3451. function lab(start, end) {
  3452. var l = nogamma((start = lab$1(start)).l, (end = lab$1(end)).l),
  3453. a = nogamma(start.a, end.a),
  3454. b = nogamma(start.b, end.b),
  3455. opacity = nogamma(start.opacity, end.opacity);
  3456. return function(t) {
  3457. start.l = l(t);
  3458. start.a = a(t);
  3459. start.b = b(t);
  3460. start.opacity = opacity(t);
  3461. return start + "";
  3462. };
  3463. }
  3464. function hcl(hue) {
  3465. return function(start, end) {
  3466. var h = hue((start = hcl$2(start)).h, (end = hcl$2(end)).h),
  3467. c = nogamma(start.c, end.c),
  3468. l = nogamma(start.l, end.l),
  3469. opacity = nogamma(start.opacity, end.opacity);
  3470. return function(t) {
  3471. start.h = h(t);
  3472. start.c = c(t);
  3473. start.l = l(t);
  3474. start.opacity = opacity(t);
  3475. return start + "";
  3476. };
  3477. }
  3478. }
  3479. var hcl$1 = hcl(hue$1);
  3480. var hclLong = hcl(nogamma);
  3481. function cubehelix$1(hue) {
  3482. return (function cubehelixGamma(y) {
  3483. y = +y;
  3484. function cubehelix(start, end) {
  3485. var h = hue((start = cubehelix$3(start)).h, (end = cubehelix$3(end)).h),
  3486. s = nogamma(start.s, end.s),
  3487. l = nogamma(start.l, end.l),
  3488. opacity = nogamma(start.opacity, end.opacity);
  3489. return function(t) {
  3490. start.h = h(t);
  3491. start.s = s(t);
  3492. start.l = l(Math.pow(t, y));
  3493. start.opacity = opacity(t);
  3494. return start + "";
  3495. };
  3496. }
  3497. cubehelix.gamma = cubehelixGamma;
  3498. return cubehelix;
  3499. })(1);
  3500. }
  3501. var cubehelix$2 = cubehelix$1(hue$1);
  3502. var cubehelixLong = cubehelix$1(nogamma);
  3503. function piecewise(interpolate, values) {
  3504. if (values === undefined) values = interpolate, interpolate = interpolate$2;
  3505. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  3506. while (i < n) I[i] = interpolate(v, v = values[++i]);
  3507. return function(t) {
  3508. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  3509. return I[i](t - i);
  3510. };
  3511. }
  3512. function quantize$1(interpolator, n) {
  3513. var samples = new Array(n);
  3514. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  3515. return samples;
  3516. }
  3517. var frame = 0, // is an animation frame pending?
  3518. timeout$1 = 0, // is a timeout pending?
  3519. interval$1 = 0, // are any timers active?
  3520. pokeDelay = 1000, // how frequently we check for clock skew
  3521. taskHead,
  3522. taskTail,
  3523. clockLast = 0,
  3524. clockNow = 0,
  3525. clockSkew = 0,
  3526. clock = typeof performance === "object" && performance.now ? performance : Date,
  3527. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  3528. function now() {
  3529. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  3530. }
  3531. function clearNow() {
  3532. clockNow = 0;
  3533. }
  3534. function Timer() {
  3535. this._call =
  3536. this._time =
  3537. this._next = null;
  3538. }
  3539. Timer.prototype = timer.prototype = {
  3540. constructor: Timer,
  3541. restart: function(callback, delay, time) {
  3542. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  3543. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  3544. if (!this._next && taskTail !== this) {
  3545. if (taskTail) taskTail._next = this;
  3546. else taskHead = this;
  3547. taskTail = this;
  3548. }
  3549. this._call = callback;
  3550. this._time = time;
  3551. sleep();
  3552. },
  3553. stop: function() {
  3554. if (this._call) {
  3555. this._call = null;
  3556. this._time = Infinity;
  3557. sleep();
  3558. }
  3559. }
  3560. };
  3561. function timer(callback, delay, time) {
  3562. var t = new Timer;
  3563. t.restart(callback, delay, time);
  3564. return t;
  3565. }
  3566. function timerFlush() {
  3567. now(); // Get the current time, if not already set.
  3568. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  3569. var t = taskHead, e;
  3570. while (t) {
  3571. if ((e = clockNow - t._time) >= 0) t._call.call(undefined, e);
  3572. t = t._next;
  3573. }
  3574. --frame;
  3575. }
  3576. function wake() {
  3577. clockNow = (clockLast = clock.now()) + clockSkew;
  3578. frame = timeout$1 = 0;
  3579. try {
  3580. timerFlush();
  3581. } finally {
  3582. frame = 0;
  3583. nap();
  3584. clockNow = 0;
  3585. }
  3586. }
  3587. function poke() {
  3588. var now = clock.now(), delay = now - clockLast;
  3589. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  3590. }
  3591. function nap() {
  3592. var t0, t1 = taskHead, t2, time = Infinity;
  3593. while (t1) {
  3594. if (t1._call) {
  3595. if (time > t1._time) time = t1._time;
  3596. t0 = t1, t1 = t1._next;
  3597. } else {
  3598. t2 = t1._next, t1._next = null;
  3599. t1 = t0 ? t0._next = t2 : taskHead = t2;
  3600. }
  3601. }
  3602. taskTail = t0;
  3603. sleep(time);
  3604. }
  3605. function sleep(time) {
  3606. if (frame) return; // Soonest alarm already set, or will be.
  3607. if (timeout$1) timeout$1 = clearTimeout(timeout$1);
  3608. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  3609. if (delay > 24) {
  3610. if (time < Infinity) timeout$1 = setTimeout(wake, time - clock.now() - clockSkew);
  3611. if (interval$1) interval$1 = clearInterval(interval$1);
  3612. } else {
  3613. if (!interval$1) clockLast = clock.now(), interval$1 = setInterval(poke, pokeDelay);
  3614. frame = 1, setFrame(wake);
  3615. }
  3616. }
  3617. function timeout(callback, delay, time) {
  3618. var t = new Timer;
  3619. delay = delay == null ? 0 : +delay;
  3620. t.restart(elapsed => {
  3621. t.stop();
  3622. callback(elapsed + delay);
  3623. }, delay, time);
  3624. return t;
  3625. }
  3626. function interval(callback, delay, time) {
  3627. var t = new Timer, total = delay;
  3628. if (delay == null) return t.restart(callback, delay, time), t;
  3629. t._restart = t.restart;
  3630. t.restart = function(callback, delay, time) {
  3631. delay = +delay, time = time == null ? now() : +time;
  3632. t._restart(function tick(elapsed) {
  3633. elapsed += total;
  3634. t._restart(tick, total += delay, time);
  3635. callback(elapsed);
  3636. }, delay, time);
  3637. };
  3638. t.restart(callback, delay, time);
  3639. return t;
  3640. }
  3641. var emptyOn = dispatch("start", "end", "cancel", "interrupt");
  3642. var emptyTween = [];
  3643. var CREATED = 0;
  3644. var SCHEDULED = 1;
  3645. var STARTING = 2;
  3646. var STARTED = 3;
  3647. var RUNNING = 4;
  3648. var ENDING = 5;
  3649. var ENDED = 6;
  3650. function schedule(node, name, id, index, group, timing) {
  3651. var schedules = node.__transition;
  3652. if (!schedules) node.__transition = {};
  3653. else if (id in schedules) return;
  3654. create(node, id, {
  3655. name: name,
  3656. index: index, // For context during callback.
  3657. group: group, // For context during callback.
  3658. on: emptyOn,
  3659. tween: emptyTween,
  3660. time: timing.time,
  3661. delay: timing.delay,
  3662. duration: timing.duration,
  3663. ease: timing.ease,
  3664. timer: null,
  3665. state: CREATED
  3666. });
  3667. }
  3668. function init(node, id) {
  3669. var schedule = get(node, id);
  3670. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  3671. return schedule;
  3672. }
  3673. function set(node, id) {
  3674. var schedule = get(node, id);
  3675. if (schedule.state > STARTED) throw new Error("too late; already running");
  3676. return schedule;
  3677. }
  3678. function get(node, id) {
  3679. var schedule = node.__transition;
  3680. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  3681. return schedule;
  3682. }
  3683. function create(node, id, self) {
  3684. var schedules = node.__transition,
  3685. tween;
  3686. // Initialize the self timer when the transition is created.
  3687. // Note the actual delay is not known until the first callback!
  3688. schedules[id] = self;
  3689. self.timer = timer(schedule, 0, self.time);
  3690. function schedule(elapsed) {
  3691. self.state = SCHEDULED;
  3692. self.timer.restart(start, self.delay, self.time);
  3693. // If the elapsed delay is less than our first sleep, start immediately.
  3694. if (self.delay <= elapsed) start(elapsed - self.delay);
  3695. }
  3696. function start(elapsed) {
  3697. var i, j, n, o;
  3698. // If the state is not SCHEDULED, then we previously errored on start.
  3699. if (self.state !== SCHEDULED) return stop();
  3700. for (i in schedules) {
  3701. o = schedules[i];
  3702. if (o.name !== self.name) continue;
  3703. // While this element already has a starting transition during this frame,
  3704. // defer starting an interrupting transition until that transition has a
  3705. // chance to tick (and possibly end); see d3/d3-transition#54!
  3706. if (o.state === STARTED) return timeout(start);
  3707. // Interrupt the active transition, if any.
  3708. if (o.state === RUNNING) {
  3709. o.state = ENDED;
  3710. o.timer.stop();
  3711. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  3712. delete schedules[i];
  3713. }
  3714. // Cancel any pre-empted transitions.
  3715. else if (+i < id) {
  3716. o.state = ENDED;
  3717. o.timer.stop();
  3718. o.on.call("cancel", node, node.__data__, o.index, o.group);
  3719. delete schedules[i];
  3720. }
  3721. }
  3722. // Defer the first tick to end of the current frame; see d3/d3#1576.
  3723. // Note the transition may be canceled after start and before the first tick!
  3724. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  3725. // Assuming this is successful, subsequent callbacks go straight to tick.
  3726. timeout(function() {
  3727. if (self.state === STARTED) {
  3728. self.state = RUNNING;
  3729. self.timer.restart(tick, self.delay, self.time);
  3730. tick(elapsed);
  3731. }
  3732. });
  3733. // Dispatch the start event.
  3734. // Note this must be done before the tween are initialized.
  3735. self.state = STARTING;
  3736. self.on.call("start", node, node.__data__, self.index, self.group);
  3737. if (self.state !== STARTING) return; // interrupted
  3738. self.state = STARTED;
  3739. // Initialize the tween, deleting null tween.
  3740. tween = new Array(n = self.tween.length);
  3741. for (i = 0, j = -1; i < n; ++i) {
  3742. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  3743. tween[++j] = o;
  3744. }
  3745. }
  3746. tween.length = j + 1;
  3747. }
  3748. function tick(elapsed) {
  3749. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  3750. i = -1,
  3751. n = tween.length;
  3752. while (++i < n) {
  3753. tween[i].call(node, t);
  3754. }
  3755. // Dispatch the end event.
  3756. if (self.state === ENDING) {
  3757. self.on.call("end", node, node.__data__, self.index, self.group);
  3758. stop();
  3759. }
  3760. }
  3761. function stop() {
  3762. self.state = ENDED;
  3763. self.timer.stop();
  3764. delete schedules[id];
  3765. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  3766. delete node.__transition;
  3767. }
  3768. }
  3769. function interrupt(node, name) {
  3770. var schedules = node.__transition,
  3771. schedule,
  3772. active,
  3773. empty = true,
  3774. i;
  3775. if (!schedules) return;
  3776. name = name == null ? null : name + "";
  3777. for (i in schedules) {
  3778. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  3779. active = schedule.state > STARTING && schedule.state < ENDING;
  3780. schedule.state = ENDED;
  3781. schedule.timer.stop();
  3782. schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
  3783. delete schedules[i];
  3784. }
  3785. if (empty) delete node.__transition;
  3786. }
  3787. function selection_interrupt(name) {
  3788. return this.each(function() {
  3789. interrupt(this, name);
  3790. });
  3791. }
  3792. function tweenRemove(id, name) {
  3793. var tween0, tween1;
  3794. return function() {
  3795. var schedule = set(this, id),
  3796. tween = schedule.tween;
  3797. // If this node shared tween with the previous node,
  3798. // just assign the updated shared tween and we’re done!
  3799. // Otherwise, copy-on-write.
  3800. if (tween !== tween0) {
  3801. tween1 = tween0 = tween;
  3802. for (var i = 0, n = tween1.length; i < n; ++i) {
  3803. if (tween1[i].name === name) {
  3804. tween1 = tween1.slice();
  3805. tween1.splice(i, 1);
  3806. break;
  3807. }
  3808. }
  3809. }
  3810. schedule.tween = tween1;
  3811. };
  3812. }
  3813. function tweenFunction(id, name, value) {
  3814. var tween0, tween1;
  3815. if (typeof value !== "function") throw new Error;
  3816. return function() {
  3817. var schedule = set(this, id),
  3818. tween = schedule.tween;
  3819. // If this node shared tween with the previous node,
  3820. // just assign the updated shared tween and we’re done!
  3821. // Otherwise, copy-on-write.
  3822. if (tween !== tween0) {
  3823. tween1 = (tween0 = tween).slice();
  3824. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  3825. if (tween1[i].name === name) {
  3826. tween1[i] = t;
  3827. break;
  3828. }
  3829. }
  3830. if (i === n) tween1.push(t);
  3831. }
  3832. schedule.tween = tween1;
  3833. };
  3834. }
  3835. function transition_tween(name, value) {
  3836. var id = this._id;
  3837. name += "";
  3838. if (arguments.length < 2) {
  3839. var tween = get(this.node(), id).tween;
  3840. for (var i = 0, n = tween.length, t; i < n; ++i) {
  3841. if ((t = tween[i]).name === name) {
  3842. return t.value;
  3843. }
  3844. }
  3845. return null;
  3846. }
  3847. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  3848. }
  3849. function tweenValue(transition, name, value) {
  3850. var id = transition._id;
  3851. transition.each(function() {
  3852. var schedule = set(this, id);
  3853. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  3854. });
  3855. return function(node) {
  3856. return get(node, id).value[name];
  3857. };
  3858. }
  3859. function interpolate$1(a, b) {
  3860. var c;
  3861. return (typeof b === "number" ? interpolateNumber
  3862. : b instanceof color ? interpolateRgb
  3863. : (c = color(b)) ? (b = c, interpolateRgb)
  3864. : interpolateString)(a, b);
  3865. }
  3866. function attrRemove(name) {
  3867. return function() {
  3868. this.removeAttribute(name);
  3869. };
  3870. }
  3871. function attrRemoveNS(fullname) {
  3872. return function() {
  3873. this.removeAttributeNS(fullname.space, fullname.local);
  3874. };
  3875. }
  3876. function attrConstant(name, interpolate, value1) {
  3877. var string00,
  3878. string1 = value1 + "",
  3879. interpolate0;
  3880. return function() {
  3881. var string0 = this.getAttribute(name);
  3882. return string0 === string1 ? null
  3883. : string0 === string00 ? interpolate0
  3884. : interpolate0 = interpolate(string00 = string0, value1);
  3885. };
  3886. }
  3887. function attrConstantNS(fullname, interpolate, value1) {
  3888. var string00,
  3889. string1 = value1 + "",
  3890. interpolate0;
  3891. return function() {
  3892. var string0 = this.getAttributeNS(fullname.space, fullname.local);
  3893. return string0 === string1 ? null
  3894. : string0 === string00 ? interpolate0
  3895. : interpolate0 = interpolate(string00 = string0, value1);
  3896. };
  3897. }
  3898. function attrFunction(name, interpolate, value) {
  3899. var string00,
  3900. string10,
  3901. interpolate0;
  3902. return function() {
  3903. var string0, value1 = value(this), string1;
  3904. if (value1 == null) return void this.removeAttribute(name);
  3905. string0 = this.getAttribute(name);
  3906. string1 = value1 + "";
  3907. return string0 === string1 ? null
  3908. : string0 === string00 && string1 === string10 ? interpolate0
  3909. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3910. };
  3911. }
  3912. function attrFunctionNS(fullname, interpolate, value) {
  3913. var string00,
  3914. string10,
  3915. interpolate0;
  3916. return function() {
  3917. var string0, value1 = value(this), string1;
  3918. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3919. string0 = this.getAttributeNS(fullname.space, fullname.local);
  3920. string1 = value1 + "";
  3921. return string0 === string1 ? null
  3922. : string0 === string00 && string1 === string10 ? interpolate0
  3923. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3924. };
  3925. }
  3926. function transition_attr(name, value) {
  3927. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
  3928. return this.attrTween(name, typeof value === "function"
  3929. ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value))
  3930. : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname)
  3931. : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value));
  3932. }
  3933. function attrInterpolate(name, i) {
  3934. return function(t) {
  3935. this.setAttribute(name, i.call(this, t));
  3936. };
  3937. }
  3938. function attrInterpolateNS(fullname, i) {
  3939. return function(t) {
  3940. this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
  3941. };
  3942. }
  3943. function attrTweenNS(fullname, value) {
  3944. var t0, i0;
  3945. function tween() {
  3946. var i = value.apply(this, arguments);
  3947. if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
  3948. return t0;
  3949. }
  3950. tween._value = value;
  3951. return tween;
  3952. }
  3953. function attrTween(name, value) {
  3954. var t0, i0;
  3955. function tween() {
  3956. var i = value.apply(this, arguments);
  3957. if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
  3958. return t0;
  3959. }
  3960. tween._value = value;
  3961. return tween;
  3962. }
  3963. function transition_attrTween(name, value) {
  3964. var key = "attr." + name;
  3965. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3966. if (value == null) return this.tween(key, null);
  3967. if (typeof value !== "function") throw new Error;
  3968. var fullname = namespace(name);
  3969. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3970. }
  3971. function delayFunction(id, value) {
  3972. return function() {
  3973. init(this, id).delay = +value.apply(this, arguments);
  3974. };
  3975. }
  3976. function delayConstant(id, value) {
  3977. return value = +value, function() {
  3978. init(this, id).delay = value;
  3979. };
  3980. }
  3981. function transition_delay(value) {
  3982. var id = this._id;
  3983. return arguments.length
  3984. ? this.each((typeof value === "function"
  3985. ? delayFunction
  3986. : delayConstant)(id, value))
  3987. : get(this.node(), id).delay;
  3988. }
  3989. function durationFunction(id, value) {
  3990. return function() {
  3991. set(this, id).duration = +value.apply(this, arguments);
  3992. };
  3993. }
  3994. function durationConstant(id, value) {
  3995. return value = +value, function() {
  3996. set(this, id).duration = value;
  3997. };
  3998. }
  3999. function transition_duration(value) {
  4000. var id = this._id;
  4001. return arguments.length
  4002. ? this.each((typeof value === "function"
  4003. ? durationFunction
  4004. : durationConstant)(id, value))
  4005. : get(this.node(), id).duration;
  4006. }
  4007. function easeConstant(id, value) {
  4008. if (typeof value !== "function") throw new Error;
  4009. return function() {
  4010. set(this, id).ease = value;
  4011. };
  4012. }
  4013. function transition_ease(value) {
  4014. var id = this._id;
  4015. return arguments.length
  4016. ? this.each(easeConstant(id, value))
  4017. : get(this.node(), id).ease;
  4018. }
  4019. function easeVarying(id, value) {
  4020. return function() {
  4021. var v = value.apply(this, arguments);
  4022. if (typeof v !== "function") throw new Error;
  4023. set(this, id).ease = v;
  4024. };
  4025. }
  4026. function transition_easeVarying(value) {
  4027. if (typeof value !== "function") throw new Error;
  4028. return this.each(easeVarying(this._id, value));
  4029. }
  4030. function transition_filter(match) {
  4031. if (typeof match !== "function") match = matcher(match);
  4032. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  4033. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  4034. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  4035. subgroup.push(node);
  4036. }
  4037. }
  4038. }
  4039. return new Transition(subgroups, this._parents, this._name, this._id);
  4040. }
  4041. function transition_merge(transition) {
  4042. if (transition._id !== this._id) throw new Error;
  4043. for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  4044. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  4045. if (node = group0[i] || group1[i]) {
  4046. merge[i] = node;
  4047. }
  4048. }
  4049. }
  4050. for (; j < m0; ++j) {
  4051. merges[j] = groups0[j];
  4052. }
  4053. return new Transition(merges, this._parents, this._name, this._id);
  4054. }
  4055. function start(name) {
  4056. return (name + "").trim().split(/^|\s+/).every(function(t) {
  4057. var i = t.indexOf(".");
  4058. if (i >= 0) t = t.slice(0, i);
  4059. return !t || t === "start";
  4060. });
  4061. }
  4062. function onFunction(id, name, listener) {
  4063. var on0, on1, sit = start(name) ? init : set;
  4064. return function() {
  4065. var schedule = sit(this, id),
  4066. on = schedule.on;
  4067. // If this node shared a dispatch with the previous node,
  4068. // just assign the updated shared dispatch and we’re done!
  4069. // Otherwise, copy-on-write.
  4070. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  4071. schedule.on = on1;
  4072. };
  4073. }
  4074. function transition_on(name, listener) {
  4075. var id = this._id;
  4076. return arguments.length < 2
  4077. ? get(this.node(), id).on.on(name)
  4078. : this.each(onFunction(id, name, listener));
  4079. }
  4080. function removeFunction(id) {
  4081. return function() {
  4082. var parent = this.parentNode;
  4083. for (var i in this.__transition) if (+i !== id) return;
  4084. if (parent) parent.removeChild(this);
  4085. };
  4086. }
  4087. function transition_remove() {
  4088. return this.on("end.remove", removeFunction(this._id));
  4089. }
  4090. function transition_select(select) {
  4091. var name = this._name,
  4092. id = this._id;
  4093. if (typeof select !== "function") select = selector(select);
  4094. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  4095. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  4096. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  4097. if ("__data__" in node) subnode.__data__ = node.__data__;
  4098. subgroup[i] = subnode;
  4099. schedule(subgroup[i], name, id, i, subgroup, get(node, id));
  4100. }
  4101. }
  4102. }
  4103. return new Transition(subgroups, this._parents, name, id);
  4104. }
  4105. function transition_selectAll(select) {
  4106. var name = this._name,
  4107. id = this._id;
  4108. if (typeof select !== "function") select = selectorAll(select);
  4109. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  4110. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4111. if (node = group[i]) {
  4112. for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) {
  4113. if (child = children[k]) {
  4114. schedule(child, name, id, k, children, inherit);
  4115. }
  4116. }
  4117. subgroups.push(children);
  4118. parents.push(node);
  4119. }
  4120. }
  4121. }
  4122. return new Transition(subgroups, parents, name, id);
  4123. }
  4124. var Selection = selection.prototype.constructor;
  4125. function transition_selection() {
  4126. return new Selection(this._groups, this._parents);
  4127. }
  4128. function styleNull(name, interpolate) {
  4129. var string00,
  4130. string10,
  4131. interpolate0;
  4132. return function() {
  4133. var string0 = styleValue(this, name),
  4134. string1 = (this.style.removeProperty(name), styleValue(this, name));
  4135. return string0 === string1 ? null
  4136. : string0 === string00 && string1 === string10 ? interpolate0
  4137. : interpolate0 = interpolate(string00 = string0, string10 = string1);
  4138. };
  4139. }
  4140. function styleRemove(name) {
  4141. return function() {
  4142. this.style.removeProperty(name);
  4143. };
  4144. }
  4145. function styleConstant(name, interpolate, value1) {
  4146. var string00,
  4147. string1 = value1 + "",
  4148. interpolate0;
  4149. return function() {
  4150. var string0 = styleValue(this, name);
  4151. return string0 === string1 ? null
  4152. : string0 === string00 ? interpolate0
  4153. : interpolate0 = interpolate(string00 = string0, value1);
  4154. };
  4155. }
  4156. function styleFunction(name, interpolate, value) {
  4157. var string00,
  4158. string10,
  4159. interpolate0;
  4160. return function() {
  4161. var string0 = styleValue(this, name),
  4162. value1 = value(this),
  4163. string1 = value1 + "";
  4164. if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
  4165. return string0 === string1 ? null
  4166. : string0 === string00 && string1 === string10 ? interpolate0
  4167. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  4168. };
  4169. }
  4170. function styleMaybeRemove(id, name) {
  4171. var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
  4172. return function() {
  4173. var schedule = set(this, id),
  4174. on = schedule.on,
  4175. listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;
  4176. // If this node shared a dispatch with the previous node,
  4177. // just assign the updated shared dispatch and we’re done!
  4178. // Otherwise, copy-on-write.
  4179. if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
  4180. schedule.on = on1;
  4181. };
  4182. }
  4183. function transition_style(name, value, priority) {
  4184. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
  4185. return value == null ? this
  4186. .styleTween(name, styleNull(name, i))
  4187. .on("end.style." + name, styleRemove(name))
  4188. : typeof value === "function" ? this
  4189. .styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value)))
  4190. .each(styleMaybeRemove(this._id, name))
  4191. : this
  4192. .styleTween(name, styleConstant(name, i, value), priority)
  4193. .on("end.style." + name, null);
  4194. }
  4195. function styleInterpolate(name, i, priority) {
  4196. return function(t) {
  4197. this.style.setProperty(name, i.call(this, t), priority);
  4198. };
  4199. }
  4200. function styleTween(name, value, priority) {
  4201. var t, i0;
  4202. function tween() {
  4203. var i = value.apply(this, arguments);
  4204. if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
  4205. return t;
  4206. }
  4207. tween._value = value;
  4208. return tween;
  4209. }
  4210. function transition_styleTween(name, value, priority) {
  4211. var key = "style." + (name += "");
  4212. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  4213. if (value == null) return this.tween(key, null);
  4214. if (typeof value !== "function") throw new Error;
  4215. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  4216. }
  4217. function textConstant(value) {
  4218. return function() {
  4219. this.textContent = value;
  4220. };
  4221. }
  4222. function textFunction(value) {
  4223. return function() {
  4224. var value1 = value(this);
  4225. this.textContent = value1 == null ? "" : value1;
  4226. };
  4227. }
  4228. function transition_text(value) {
  4229. return this.tween("text", typeof value === "function"
  4230. ? textFunction(tweenValue(this, "text", value))
  4231. : textConstant(value == null ? "" : value + ""));
  4232. }
  4233. function textInterpolate(i) {
  4234. return function(t) {
  4235. this.textContent = i.call(this, t);
  4236. };
  4237. }
  4238. function textTween(value) {
  4239. var t0, i0;
  4240. function tween() {
  4241. var i = value.apply(this, arguments);
  4242. if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
  4243. return t0;
  4244. }
  4245. tween._value = value;
  4246. return tween;
  4247. }
  4248. function transition_textTween(value) {
  4249. var key = "text";
  4250. if (arguments.length < 1) return (key = this.tween(key)) && key._value;
  4251. if (value == null) return this.tween(key, null);
  4252. if (typeof value !== "function") throw new Error;
  4253. return this.tween(key, textTween(value));
  4254. }
  4255. function transition_transition() {
  4256. var name = this._name,
  4257. id0 = this._id,
  4258. id1 = newId();
  4259. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  4260. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4261. if (node = group[i]) {
  4262. var inherit = get(node, id0);
  4263. schedule(node, name, id1, i, group, {
  4264. time: inherit.time + inherit.delay + inherit.duration,
  4265. delay: 0,
  4266. duration: inherit.duration,
  4267. ease: inherit.ease
  4268. });
  4269. }
  4270. }
  4271. }
  4272. return new Transition(groups, this._parents, name, id1);
  4273. }
  4274. function transition_end() {
  4275. var on0, on1, that = this, id = that._id, size = that.size();
  4276. return new Promise(function(resolve, reject) {
  4277. var cancel = {value: reject},
  4278. end = {value: function() { if (--size === 0) resolve(); }};
  4279. that.each(function() {
  4280. var schedule = set(this, id),
  4281. on = schedule.on;
  4282. // If this node shared a dispatch with the previous node,
  4283. // just assign the updated shared dispatch and we’re done!
  4284. // Otherwise, copy-on-write.
  4285. if (on !== on0) {
  4286. on1 = (on0 = on).copy();
  4287. on1._.cancel.push(cancel);
  4288. on1._.interrupt.push(cancel);
  4289. on1._.end.push(end);
  4290. }
  4291. schedule.on = on1;
  4292. });
  4293. // The selection was empty, resolve end immediately
  4294. if (size === 0) resolve();
  4295. });
  4296. }
  4297. var id = 0;
  4298. function Transition(groups, parents, name, id) {
  4299. this._groups = groups;
  4300. this._parents = parents;
  4301. this._name = name;
  4302. this._id = id;
  4303. }
  4304. function transition(name) {
  4305. return selection().transition(name);
  4306. }
  4307. function newId() {
  4308. return ++id;
  4309. }
  4310. var selection_prototype = selection.prototype;
  4311. Transition.prototype = transition.prototype = {
  4312. constructor: Transition,
  4313. select: transition_select,
  4314. selectAll: transition_selectAll,
  4315. selectChild: selection_prototype.selectChild,
  4316. selectChildren: selection_prototype.selectChildren,
  4317. filter: transition_filter,
  4318. merge: transition_merge,
  4319. selection: transition_selection,
  4320. transition: transition_transition,
  4321. call: selection_prototype.call,
  4322. nodes: selection_prototype.nodes,
  4323. node: selection_prototype.node,
  4324. size: selection_prototype.size,
  4325. empty: selection_prototype.empty,
  4326. each: selection_prototype.each,
  4327. on: transition_on,
  4328. attr: transition_attr,
  4329. attrTween: transition_attrTween,
  4330. style: transition_style,
  4331. styleTween: transition_styleTween,
  4332. text: transition_text,
  4333. textTween: transition_textTween,
  4334. remove: transition_remove,
  4335. tween: transition_tween,
  4336. delay: transition_delay,
  4337. duration: transition_duration,
  4338. ease: transition_ease,
  4339. easeVarying: transition_easeVarying,
  4340. end: transition_end,
  4341. [Symbol.iterator]: selection_prototype[Symbol.iterator]
  4342. };
  4343. const linear$1 = t => +t;
  4344. function quadIn(t) {
  4345. return t * t;
  4346. }
  4347. function quadOut(t) {
  4348. return t * (2 - t);
  4349. }
  4350. function quadInOut(t) {
  4351. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  4352. }
  4353. function cubicIn(t) {
  4354. return t * t * t;
  4355. }
  4356. function cubicOut(t) {
  4357. return --t * t * t + 1;
  4358. }
  4359. function cubicInOut(t) {
  4360. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  4361. }
  4362. var exponent$1 = 3;
  4363. var polyIn = (function custom(e) {
  4364. e = +e;
  4365. function polyIn(t) {
  4366. return Math.pow(t, e);
  4367. }
  4368. polyIn.exponent = custom;
  4369. return polyIn;
  4370. })(exponent$1);
  4371. var polyOut = (function custom(e) {
  4372. e = +e;
  4373. function polyOut(t) {
  4374. return 1 - Math.pow(1 - t, e);
  4375. }
  4376. polyOut.exponent = custom;
  4377. return polyOut;
  4378. })(exponent$1);
  4379. var polyInOut = (function custom(e) {
  4380. e = +e;
  4381. function polyInOut(t) {
  4382. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  4383. }
  4384. polyInOut.exponent = custom;
  4385. return polyInOut;
  4386. })(exponent$1);
  4387. var pi$4 = Math.PI,
  4388. halfPi$3 = pi$4 / 2;
  4389. function sinIn(t) {
  4390. return (+t === 1) ? 1 : 1 - Math.cos(t * halfPi$3);
  4391. }
  4392. function sinOut(t) {
  4393. return Math.sin(t * halfPi$3);
  4394. }
  4395. function sinInOut(t) {
  4396. return (1 - Math.cos(pi$4 * t)) / 2;
  4397. }
  4398. // tpmt is two power minus ten times t scaled to [0,1]
  4399. function tpmt(x) {
  4400. return (Math.pow(2, -10 * x) - 0.0009765625) * 1.0009775171065494;
  4401. }
  4402. function expIn(t) {
  4403. return tpmt(1 - +t);
  4404. }
  4405. function expOut(t) {
  4406. return 1 - tpmt(t);
  4407. }
  4408. function expInOut(t) {
  4409. return ((t *= 2) <= 1 ? tpmt(1 - t) : 2 - tpmt(t - 1)) / 2;
  4410. }
  4411. function circleIn(t) {
  4412. return 1 - Math.sqrt(1 - t * t);
  4413. }
  4414. function circleOut(t) {
  4415. return Math.sqrt(1 - --t * t);
  4416. }
  4417. function circleInOut(t) {
  4418. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  4419. }
  4420. var b1 = 4 / 11,
  4421. b2 = 6 / 11,
  4422. b3 = 8 / 11,
  4423. b4 = 3 / 4,
  4424. b5 = 9 / 11,
  4425. b6 = 10 / 11,
  4426. b7 = 15 / 16,
  4427. b8 = 21 / 22,
  4428. b9 = 63 / 64,
  4429. b0 = 1 / b1 / b1;
  4430. function bounceIn(t) {
  4431. return 1 - bounceOut(1 - t);
  4432. }
  4433. function bounceOut(t) {
  4434. 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;
  4435. }
  4436. function bounceInOut(t) {
  4437. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  4438. }
  4439. var overshoot = 1.70158;
  4440. var backIn = (function custom(s) {
  4441. s = +s;
  4442. function backIn(t) {
  4443. return (t = +t) * t * (s * (t - 1) + t);
  4444. }
  4445. backIn.overshoot = custom;
  4446. return backIn;
  4447. })(overshoot);
  4448. var backOut = (function custom(s) {
  4449. s = +s;
  4450. function backOut(t) {
  4451. return --t * t * ((t + 1) * s + t) + 1;
  4452. }
  4453. backOut.overshoot = custom;
  4454. return backOut;
  4455. })(overshoot);
  4456. var backInOut = (function custom(s) {
  4457. s = +s;
  4458. function backInOut(t) {
  4459. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  4460. }
  4461. backInOut.overshoot = custom;
  4462. return backInOut;
  4463. })(overshoot);
  4464. var tau$5 = 2 * Math.PI,
  4465. amplitude = 1,
  4466. period = 0.3;
  4467. var elasticIn = (function custom(a, p) {
  4468. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
  4469. function elasticIn(t) {
  4470. return a * tpmt(-(--t)) * Math.sin((s - t) / p);
  4471. }
  4472. elasticIn.amplitude = function(a) { return custom(a, p * tau$5); };
  4473. elasticIn.period = function(p) { return custom(a, p); };
  4474. return elasticIn;
  4475. })(amplitude, period);
  4476. var elasticOut = (function custom(a, p) {
  4477. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
  4478. function elasticOut(t) {
  4479. return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p);
  4480. }
  4481. elasticOut.amplitude = function(a) { return custom(a, p * tau$5); };
  4482. elasticOut.period = function(p) { return custom(a, p); };
  4483. return elasticOut;
  4484. })(amplitude, period);
  4485. var elasticInOut = (function custom(a, p) {
  4486. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
  4487. function elasticInOut(t) {
  4488. return ((t = t * 2 - 1) < 0
  4489. ? a * tpmt(-t) * Math.sin((s - t) / p)
  4490. : 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2;
  4491. }
  4492. elasticInOut.amplitude = function(a) { return custom(a, p * tau$5); };
  4493. elasticInOut.period = function(p) { return custom(a, p); };
  4494. return elasticInOut;
  4495. })(amplitude, period);
  4496. var defaultTiming = {
  4497. time: null, // Set on use.
  4498. delay: 0,
  4499. duration: 250,
  4500. ease: cubicInOut
  4501. };
  4502. function inherit(node, id) {
  4503. var timing;
  4504. while (!(timing = node.__transition) || !(timing = timing[id])) {
  4505. if (!(node = node.parentNode)) {
  4506. throw new Error(`transition ${id} not found`);
  4507. }
  4508. }
  4509. return timing;
  4510. }
  4511. function selection_transition(name) {
  4512. var id,
  4513. timing;
  4514. if (name instanceof Transition) {
  4515. id = name._id, name = name._name;
  4516. } else {
  4517. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  4518. }
  4519. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  4520. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4521. if (node = group[i]) {
  4522. schedule(node, name, id, i, group, timing || inherit(node, id));
  4523. }
  4524. }
  4525. }
  4526. return new Transition(groups, this._parents, name, id);
  4527. }
  4528. selection.prototype.interrupt = selection_interrupt;
  4529. selection.prototype.transition = selection_transition;
  4530. var root = [null];
  4531. function active(node, name) {
  4532. var schedules = node.__transition,
  4533. schedule,
  4534. i;
  4535. if (schedules) {
  4536. name = name == null ? null : name + "";
  4537. for (i in schedules) {
  4538. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  4539. return new Transition([[node]], root, name, +i);
  4540. }
  4541. }
  4542. }
  4543. return null;
  4544. }
  4545. var constant$7 = x => () => x;
  4546. function BrushEvent(type, {
  4547. sourceEvent,
  4548. target,
  4549. selection,
  4550. mode,
  4551. dispatch
  4552. }) {
  4553. Object.defineProperties(this, {
  4554. type: {value: type, enumerable: true, configurable: true},
  4555. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  4556. target: {value: target, enumerable: true, configurable: true},
  4557. selection: {value: selection, enumerable: true, configurable: true},
  4558. mode: {value: mode, enumerable: true, configurable: true},
  4559. _: {value: dispatch}
  4560. });
  4561. }
  4562. function nopropagation$1(event) {
  4563. event.stopImmediatePropagation();
  4564. }
  4565. function noevent$1(event) {
  4566. event.preventDefault();
  4567. event.stopImmediatePropagation();
  4568. }
  4569. var MODE_DRAG = {name: "drag"},
  4570. MODE_SPACE = {name: "space"},
  4571. MODE_HANDLE = {name: "handle"},
  4572. MODE_CENTER = {name: "center"};
  4573. const {abs: abs$3, max: max$2, min: min$1} = Math;
  4574. function number1(e) {
  4575. return [+e[0], +e[1]];
  4576. }
  4577. function number2(e) {
  4578. return [number1(e[0]), number1(e[1])];
  4579. }
  4580. var X = {
  4581. name: "x",
  4582. handles: ["w", "e"].map(type),
  4583. input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
  4584. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  4585. };
  4586. var Y = {
  4587. name: "y",
  4588. handles: ["n", "s"].map(type),
  4589. input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
  4590. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  4591. };
  4592. var XY = {
  4593. name: "xy",
  4594. handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
  4595. input: function(xy) { return xy == null ? null : number2(xy); },
  4596. output: function(xy) { return xy; }
  4597. };
  4598. var cursors = {
  4599. overlay: "crosshair",
  4600. selection: "move",
  4601. n: "ns-resize",
  4602. e: "ew-resize",
  4603. s: "ns-resize",
  4604. w: "ew-resize",
  4605. nw: "nwse-resize",
  4606. ne: "nesw-resize",
  4607. se: "nwse-resize",
  4608. sw: "nesw-resize"
  4609. };
  4610. var flipX = {
  4611. e: "w",
  4612. w: "e",
  4613. nw: "ne",
  4614. ne: "nw",
  4615. se: "sw",
  4616. sw: "se"
  4617. };
  4618. var flipY = {
  4619. n: "s",
  4620. s: "n",
  4621. nw: "sw",
  4622. ne: "se",
  4623. se: "ne",
  4624. sw: "nw"
  4625. };
  4626. var signsX = {
  4627. overlay: +1,
  4628. selection: +1,
  4629. n: null,
  4630. e: +1,
  4631. s: null,
  4632. w: -1,
  4633. nw: -1,
  4634. ne: +1,
  4635. se: +1,
  4636. sw: -1
  4637. };
  4638. var signsY = {
  4639. overlay: +1,
  4640. selection: +1,
  4641. n: -1,
  4642. e: null,
  4643. s: +1,
  4644. w: null,
  4645. nw: -1,
  4646. ne: -1,
  4647. se: +1,
  4648. sw: +1
  4649. };
  4650. function type(t) {
  4651. return {type: t};
  4652. }
  4653. // Ignore right-click, since that should open the context menu.
  4654. function defaultFilter$1(event) {
  4655. return !event.ctrlKey && !event.button;
  4656. }
  4657. function defaultExtent$1() {
  4658. var svg = this.ownerSVGElement || this;
  4659. if (svg.hasAttribute("viewBox")) {
  4660. svg = svg.viewBox.baseVal;
  4661. return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
  4662. }
  4663. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  4664. }
  4665. function defaultTouchable$1() {
  4666. return navigator.maxTouchPoints || ("ontouchstart" in this);
  4667. }
  4668. // Like d3.local, but with the name “__brush” rather than auto-generated.
  4669. function local(node) {
  4670. while (!node.__brush) if (!(node = node.parentNode)) return;
  4671. return node.__brush;
  4672. }
  4673. function empty(extent) {
  4674. return extent[0][0] === extent[1][0]
  4675. || extent[0][1] === extent[1][1];
  4676. }
  4677. function brushSelection(node) {
  4678. var state = node.__brush;
  4679. return state ? state.dim.output(state.selection) : null;
  4680. }
  4681. function brushX() {
  4682. return brush$1(X);
  4683. }
  4684. function brushY() {
  4685. return brush$1(Y);
  4686. }
  4687. function brush() {
  4688. return brush$1(XY);
  4689. }
  4690. function brush$1(dim) {
  4691. var extent = defaultExtent$1,
  4692. filter = defaultFilter$1,
  4693. touchable = defaultTouchable$1,
  4694. keys = true,
  4695. listeners = dispatch("start", "brush", "end"),
  4696. handleSize = 6,
  4697. touchending;
  4698. function brush(group) {
  4699. var overlay = group
  4700. .property("__brush", initialize)
  4701. .selectAll(".overlay")
  4702. .data([type("overlay")]);
  4703. overlay.enter().append("rect")
  4704. .attr("class", "overlay")
  4705. .attr("pointer-events", "all")
  4706. .attr("cursor", cursors.overlay)
  4707. .merge(overlay)
  4708. .each(function() {
  4709. var extent = local(this).extent;
  4710. select(this)
  4711. .attr("x", extent[0][0])
  4712. .attr("y", extent[0][1])
  4713. .attr("width", extent[1][0] - extent[0][0])
  4714. .attr("height", extent[1][1] - extent[0][1]);
  4715. });
  4716. group.selectAll(".selection")
  4717. .data([type("selection")])
  4718. .enter().append("rect")
  4719. .attr("class", "selection")
  4720. .attr("cursor", cursors.selection)
  4721. .attr("fill", "#777")
  4722. .attr("fill-opacity", 0.3)
  4723. .attr("stroke", "#fff")
  4724. .attr("shape-rendering", "crispEdges");
  4725. var handle = group.selectAll(".handle")
  4726. .data(dim.handles, function(d) { return d.type; });
  4727. handle.exit().remove();
  4728. handle.enter().append("rect")
  4729. .attr("class", function(d) { return "handle handle--" + d.type; })
  4730. .attr("cursor", function(d) { return cursors[d.type]; });
  4731. group
  4732. .each(redraw)
  4733. .attr("fill", "none")
  4734. .attr("pointer-events", "all")
  4735. .on("mousedown.brush", started)
  4736. .filter(touchable)
  4737. .on("touchstart.brush", started)
  4738. .on("touchmove.brush", touchmoved)
  4739. .on("touchend.brush touchcancel.brush", touchended)
  4740. .style("touch-action", "none")
  4741. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  4742. }
  4743. brush.move = function(group, selection, event) {
  4744. if (group.tween) {
  4745. group
  4746. .on("start.brush", function(event) { emitter(this, arguments).beforestart().start(event); })
  4747. .on("interrupt.brush end.brush", function(event) { emitter(this, arguments).end(event); })
  4748. .tween("brush", function() {
  4749. var that = this,
  4750. state = that.__brush,
  4751. emit = emitter(that, arguments),
  4752. selection0 = state.selection,
  4753. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  4754. i = interpolate$2(selection0, selection1);
  4755. function tween(t) {
  4756. state.selection = t === 1 && selection1 === null ? null : i(t);
  4757. redraw.call(that);
  4758. emit.brush();
  4759. }
  4760. return selection0 !== null && selection1 !== null ? tween : tween(1);
  4761. });
  4762. } else {
  4763. group
  4764. .each(function() {
  4765. var that = this,
  4766. args = arguments,
  4767. state = that.__brush,
  4768. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  4769. emit = emitter(that, args).beforestart();
  4770. interrupt(that);
  4771. state.selection = selection1 === null ? null : selection1;
  4772. redraw.call(that);
  4773. emit.start(event).brush(event).end(event);
  4774. });
  4775. }
  4776. };
  4777. brush.clear = function(group, event) {
  4778. brush.move(group, null, event);
  4779. };
  4780. function redraw() {
  4781. var group = select(this),
  4782. selection = local(this).selection;
  4783. if (selection) {
  4784. group.selectAll(".selection")
  4785. .style("display", null)
  4786. .attr("x", selection[0][0])
  4787. .attr("y", selection[0][1])
  4788. .attr("width", selection[1][0] - selection[0][0])
  4789. .attr("height", selection[1][1] - selection[0][1]);
  4790. group.selectAll(".handle")
  4791. .style("display", null)
  4792. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  4793. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  4794. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  4795. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  4796. }
  4797. else {
  4798. group.selectAll(".selection,.handle")
  4799. .style("display", "none")
  4800. .attr("x", null)
  4801. .attr("y", null)
  4802. .attr("width", null)
  4803. .attr("height", null);
  4804. }
  4805. }
  4806. function emitter(that, args, clean) {
  4807. var emit = that.__brush.emitter;
  4808. return emit && (!clean || !emit.clean) ? emit : new Emitter(that, args, clean);
  4809. }
  4810. function Emitter(that, args, clean) {
  4811. this.that = that;
  4812. this.args = args;
  4813. this.state = that.__brush;
  4814. this.active = 0;
  4815. this.clean = clean;
  4816. }
  4817. Emitter.prototype = {
  4818. beforestart: function() {
  4819. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  4820. return this;
  4821. },
  4822. start: function(event, mode) {
  4823. if (this.starting) this.starting = false, this.emit("start", event, mode);
  4824. else this.emit("brush", event);
  4825. return this;
  4826. },
  4827. brush: function(event, mode) {
  4828. this.emit("brush", event, mode);
  4829. return this;
  4830. },
  4831. end: function(event, mode) {
  4832. if (--this.active === 0) delete this.state.emitter, this.emit("end", event, mode);
  4833. return this;
  4834. },
  4835. emit: function(type, event, mode) {
  4836. var d = select(this.that).datum();
  4837. listeners.call(
  4838. type,
  4839. this.that,
  4840. new BrushEvent(type, {
  4841. sourceEvent: event,
  4842. target: brush,
  4843. selection: dim.output(this.state.selection),
  4844. mode,
  4845. dispatch: listeners
  4846. }),
  4847. d
  4848. );
  4849. }
  4850. };
  4851. function started(event) {
  4852. if (touchending && !event.touches) return;
  4853. if (!filter.apply(this, arguments)) return;
  4854. var that = this,
  4855. type = event.target.__data__.type,
  4856. mode = (keys && event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && event.altKey ? MODE_CENTER : MODE_HANDLE),
  4857. signX = dim === Y ? null : signsX[type],
  4858. signY = dim === X ? null : signsY[type],
  4859. state = local(that),
  4860. extent = state.extent,
  4861. selection = state.selection,
  4862. W = extent[0][0], w0, w1,
  4863. N = extent[0][1], n0, n1,
  4864. E = extent[1][0], e0, e1,
  4865. S = extent[1][1], s0, s1,
  4866. dx = 0,
  4867. dy = 0,
  4868. moving,
  4869. shifting = signX && signY && keys && event.shiftKey,
  4870. lockX,
  4871. lockY,
  4872. points = Array.from(event.touches || [event], t => {
  4873. const i = t.identifier;
  4874. t = pointer(t, that);
  4875. t.point0 = t.slice();
  4876. t.identifier = i;
  4877. return t;
  4878. });
  4879. interrupt(that);
  4880. var emit = emitter(that, arguments, true).beforestart();
  4881. if (type === "overlay") {
  4882. if (selection) moving = true;
  4883. const pts = [points[0], points[1] || points[0]];
  4884. state.selection = selection = [[
  4885. w0 = dim === Y ? W : min$1(pts[0][0], pts[1][0]),
  4886. n0 = dim === X ? N : min$1(pts[0][1], pts[1][1])
  4887. ], [
  4888. e0 = dim === Y ? E : max$2(pts[0][0], pts[1][0]),
  4889. s0 = dim === X ? S : max$2(pts[0][1], pts[1][1])
  4890. ]];
  4891. if (points.length > 1) move(event);
  4892. } else {
  4893. w0 = selection[0][0];
  4894. n0 = selection[0][1];
  4895. e0 = selection[1][0];
  4896. s0 = selection[1][1];
  4897. }
  4898. w1 = w0;
  4899. n1 = n0;
  4900. e1 = e0;
  4901. s1 = s0;
  4902. var group = select(that)
  4903. .attr("pointer-events", "none");
  4904. var overlay = group.selectAll(".overlay")
  4905. .attr("cursor", cursors[type]);
  4906. if (event.touches) {
  4907. emit.moved = moved;
  4908. emit.ended = ended;
  4909. } else {
  4910. var view = select(event.view)
  4911. .on("mousemove.brush", moved, true)
  4912. .on("mouseup.brush", ended, true);
  4913. if (keys) view
  4914. .on("keydown.brush", keydowned, true)
  4915. .on("keyup.brush", keyupped, true);
  4916. dragDisable(event.view);
  4917. }
  4918. redraw.call(that);
  4919. emit.start(event, mode.name);
  4920. function moved(event) {
  4921. for (const p of event.changedTouches || [event]) {
  4922. for (const d of points)
  4923. if (d.identifier === p.identifier) d.cur = pointer(p, that);
  4924. }
  4925. if (shifting && !lockX && !lockY && points.length === 1) {
  4926. const point = points[0];
  4927. if (abs$3(point.cur[0] - point[0]) > abs$3(point.cur[1] - point[1]))
  4928. lockY = true;
  4929. else
  4930. lockX = true;
  4931. }
  4932. for (const point of points)
  4933. if (point.cur) point[0] = point.cur[0], point[1] = point.cur[1];
  4934. moving = true;
  4935. noevent$1(event);
  4936. move(event);
  4937. }
  4938. function move(event) {
  4939. const point = points[0], point0 = point.point0;
  4940. var t;
  4941. dx = point[0] - point0[0];
  4942. dy = point[1] - point0[1];
  4943. switch (mode) {
  4944. case MODE_SPACE:
  4945. case MODE_DRAG: {
  4946. if (signX) dx = max$2(W - w0, min$1(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  4947. if (signY) dy = max$2(N - n0, min$1(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  4948. break;
  4949. }
  4950. case MODE_HANDLE: {
  4951. if (points[1]) {
  4952. if (signX) w1 = max$2(W, min$1(E, points[0][0])), e1 = max$2(W, min$1(E, points[1][0])), signX = 1;
  4953. if (signY) n1 = max$2(N, min$1(S, points[0][1])), s1 = max$2(N, min$1(S, points[1][1])), signY = 1;
  4954. } else {
  4955. if (signX < 0) dx = max$2(W - w0, min$1(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  4956. else if (signX > 0) dx = max$2(W - e0, min$1(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  4957. if (signY < 0) dy = max$2(N - n0, min$1(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  4958. else if (signY > 0) dy = max$2(N - s0, min$1(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  4959. }
  4960. break;
  4961. }
  4962. case MODE_CENTER: {
  4963. if (signX) w1 = max$2(W, min$1(E, w0 - dx * signX)), e1 = max$2(W, min$1(E, e0 + dx * signX));
  4964. if (signY) n1 = max$2(N, min$1(S, n0 - dy * signY)), s1 = max$2(N, min$1(S, s0 + dy * signY));
  4965. break;
  4966. }
  4967. }
  4968. if (e1 < w1) {
  4969. signX *= -1;
  4970. t = w0, w0 = e0, e0 = t;
  4971. t = w1, w1 = e1, e1 = t;
  4972. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  4973. }
  4974. if (s1 < n1) {
  4975. signY *= -1;
  4976. t = n0, n0 = s0, s0 = t;
  4977. t = n1, n1 = s1, s1 = t;
  4978. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  4979. }
  4980. if (state.selection) selection = state.selection; // May be set by brush.move!
  4981. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  4982. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  4983. if (selection[0][0] !== w1
  4984. || selection[0][1] !== n1
  4985. || selection[1][0] !== e1
  4986. || selection[1][1] !== s1) {
  4987. state.selection = [[w1, n1], [e1, s1]];
  4988. redraw.call(that);
  4989. emit.brush(event, mode.name);
  4990. }
  4991. }
  4992. function ended(event) {
  4993. nopropagation$1(event);
  4994. if (event.touches) {
  4995. if (event.touches.length) return;
  4996. if (touchending) clearTimeout(touchending);
  4997. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  4998. } else {
  4999. yesdrag(event.view, moving);
  5000. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  5001. }
  5002. group.attr("pointer-events", "all");
  5003. overlay.attr("cursor", cursors.overlay);
  5004. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  5005. if (empty(selection)) state.selection = null, redraw.call(that);
  5006. emit.end(event, mode.name);
  5007. }
  5008. function keydowned(event) {
  5009. switch (event.keyCode) {
  5010. case 16: { // SHIFT
  5011. shifting = signX && signY;
  5012. break;
  5013. }
  5014. case 18: { // ALT
  5015. if (mode === MODE_HANDLE) {
  5016. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  5017. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  5018. mode = MODE_CENTER;
  5019. move(event);
  5020. }
  5021. break;
  5022. }
  5023. case 32: { // SPACE; takes priority over ALT
  5024. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  5025. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  5026. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  5027. mode = MODE_SPACE;
  5028. overlay.attr("cursor", cursors.selection);
  5029. move(event);
  5030. }
  5031. break;
  5032. }
  5033. default: return;
  5034. }
  5035. noevent$1(event);
  5036. }
  5037. function keyupped(event) {
  5038. switch (event.keyCode) {
  5039. case 16: { // SHIFT
  5040. if (shifting) {
  5041. lockX = lockY = shifting = false;
  5042. move(event);
  5043. }
  5044. break;
  5045. }
  5046. case 18: { // ALT
  5047. if (mode === MODE_CENTER) {
  5048. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  5049. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  5050. mode = MODE_HANDLE;
  5051. move(event);
  5052. }
  5053. break;
  5054. }
  5055. case 32: { // SPACE
  5056. if (mode === MODE_SPACE) {
  5057. if (event.altKey) {
  5058. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  5059. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  5060. mode = MODE_CENTER;
  5061. } else {
  5062. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  5063. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  5064. mode = MODE_HANDLE;
  5065. }
  5066. overlay.attr("cursor", cursors[type]);
  5067. move(event);
  5068. }
  5069. break;
  5070. }
  5071. default: return;
  5072. }
  5073. noevent$1(event);
  5074. }
  5075. }
  5076. function touchmoved(event) {
  5077. emitter(this, arguments).moved(event);
  5078. }
  5079. function touchended(event) {
  5080. emitter(this, arguments).ended(event);
  5081. }
  5082. function initialize() {
  5083. var state = this.__brush || {selection: null};
  5084. state.extent = number2(extent.apply(this, arguments));
  5085. state.dim = dim;
  5086. return state;
  5087. }
  5088. brush.extent = function(_) {
  5089. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$7(number2(_)), brush) : extent;
  5090. };
  5091. brush.filter = function(_) {
  5092. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), brush) : filter;
  5093. };
  5094. brush.touchable = function(_) {
  5095. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$7(!!_), brush) : touchable;
  5096. };
  5097. brush.handleSize = function(_) {
  5098. return arguments.length ? (handleSize = +_, brush) : handleSize;
  5099. };
  5100. brush.keyModifiers = function(_) {
  5101. return arguments.length ? (keys = !!_, brush) : keys;
  5102. };
  5103. brush.on = function() {
  5104. var value = listeners.on.apply(listeners, arguments);
  5105. return value === listeners ? brush : value;
  5106. };
  5107. return brush;
  5108. }
  5109. var abs$2 = Math.abs;
  5110. var cos$2 = Math.cos;
  5111. var sin$2 = Math.sin;
  5112. var pi$3 = Math.PI;
  5113. var halfPi$2 = pi$3 / 2;
  5114. var tau$4 = pi$3 * 2;
  5115. var max$1 = Math.max;
  5116. var epsilon$5 = 1e-12;
  5117. function range$1(i, j) {
  5118. return Array.from({length: j - i}, (_, k) => i + k);
  5119. }
  5120. function compareValue(compare) {
  5121. return function(a, b) {
  5122. return compare(
  5123. a.source.value + a.target.value,
  5124. b.source.value + b.target.value
  5125. );
  5126. };
  5127. }
  5128. function chord() {
  5129. return chord$1(false, false);
  5130. }
  5131. function chordTranspose() {
  5132. return chord$1(false, true);
  5133. }
  5134. function chordDirected() {
  5135. return chord$1(true, false);
  5136. }
  5137. function chord$1(directed, transpose) {
  5138. var padAngle = 0,
  5139. sortGroups = null,
  5140. sortSubgroups = null,
  5141. sortChords = null;
  5142. function chord(matrix) {
  5143. var n = matrix.length,
  5144. groupSums = new Array(n),
  5145. groupIndex = range$1(0, n),
  5146. chords = new Array(n * n),
  5147. groups = new Array(n),
  5148. k = 0, dx;
  5149. matrix = Float64Array.from({length: n * n}, transpose
  5150. ? (_, i) => matrix[i % n][i / n | 0]
  5151. : (_, i) => matrix[i / n | 0][i % n]);
  5152. // Compute the scaling factor from value to angle in [0, 2pi].
  5153. for (let i = 0; i < n; ++i) {
  5154. let x = 0;
  5155. for (let j = 0; j < n; ++j) x += matrix[i * n + j] + directed * matrix[j * n + i];
  5156. k += groupSums[i] = x;
  5157. }
  5158. k = max$1(0, tau$4 - padAngle * n) / k;
  5159. dx = k ? padAngle : tau$4 / n;
  5160. // Compute the angles for each group and constituent chord.
  5161. {
  5162. let x = 0;
  5163. if (sortGroups) groupIndex.sort((a, b) => sortGroups(groupSums[a], groupSums[b]));
  5164. for (const i of groupIndex) {
  5165. const x0 = x;
  5166. if (directed) {
  5167. const subgroupIndex = range$1(~n + 1, n).filter(j => j < 0 ? matrix[~j * n + i] : matrix[i * n + j]);
  5168. if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(a < 0 ? -matrix[~a * n + i] : matrix[i * n + a], b < 0 ? -matrix[~b * n + i] : matrix[i * n + b]));
  5169. for (const j of subgroupIndex) {
  5170. if (j < 0) {
  5171. const chord = chords[~j * n + i] || (chords[~j * n + i] = {source: null, target: null});
  5172. chord.target = {index: i, startAngle: x, endAngle: x += matrix[~j * n + i] * k, value: matrix[~j * n + i]};
  5173. } else {
  5174. const chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
  5175. chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  5176. }
  5177. }
  5178. groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
  5179. } else {
  5180. const subgroupIndex = range$1(0, n).filter(j => matrix[i * n + j] || matrix[j * n + i]);
  5181. if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(matrix[i * n + a], matrix[i * n + b]));
  5182. for (const j of subgroupIndex) {
  5183. let chord;
  5184. if (i < j) {
  5185. chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
  5186. chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  5187. } else {
  5188. chord = chords[j * n + i] || (chords[j * n + i] = {source: null, target: null});
  5189. chord.target = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  5190. if (i === j) chord.source = chord.target;
  5191. }
  5192. if (chord.source && chord.target && chord.source.value < chord.target.value) {
  5193. const source = chord.source;
  5194. chord.source = chord.target;
  5195. chord.target = source;
  5196. }
  5197. }
  5198. groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
  5199. }
  5200. x += dx;
  5201. }
  5202. }
  5203. // Remove empty chords.
  5204. chords = Object.values(chords);
  5205. chords.groups = groups;
  5206. return sortChords ? chords.sort(sortChords) : chords;
  5207. }
  5208. chord.padAngle = function(_) {
  5209. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  5210. };
  5211. chord.sortGroups = function(_) {
  5212. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  5213. };
  5214. chord.sortSubgroups = function(_) {
  5215. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  5216. };
  5217. chord.sortChords = function(_) {
  5218. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  5219. };
  5220. return chord;
  5221. }
  5222. const pi$2 = Math.PI,
  5223. tau$3 = 2 * pi$2,
  5224. epsilon$4 = 1e-6,
  5225. tauEpsilon = tau$3 - epsilon$4;
  5226. function append$1(strings) {
  5227. this._ += strings[0];
  5228. for (let i = 1, n = strings.length; i < n; ++i) {
  5229. this._ += arguments[i] + strings[i];
  5230. }
  5231. }
  5232. function appendRound$1(digits) {
  5233. let d = Math.floor(digits);
  5234. if (!(d >= 0)) throw new Error(`invalid digits: ${digits}`);
  5235. if (d > 15) return append$1;
  5236. const k = 10 ** d;
  5237. return function(strings) {
  5238. this._ += strings[0];
  5239. for (let i = 1, n = strings.length; i < n; ++i) {
  5240. this._ += Math.round(arguments[i] * k) / k + strings[i];
  5241. }
  5242. };
  5243. }
  5244. let Path$1 = class Path {
  5245. constructor(digits) {
  5246. this._x0 = this._y0 = // start of current subpath
  5247. this._x1 = this._y1 = null; // end of current subpath
  5248. this._ = "";
  5249. this._append = digits == null ? append$1 : appendRound$1(digits);
  5250. }
  5251. moveTo(x, y) {
  5252. this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
  5253. }
  5254. closePath() {
  5255. if (this._x1 !== null) {
  5256. this._x1 = this._x0, this._y1 = this._y0;
  5257. this._append`Z`;
  5258. }
  5259. }
  5260. lineTo(x, y) {
  5261. this._append`L${this._x1 = +x},${this._y1 = +y}`;
  5262. }
  5263. quadraticCurveTo(x1, y1, x, y) {
  5264. this._append`Q${+x1},${+y1},${this._x1 = +x},${this._y1 = +y}`;
  5265. }
  5266. bezierCurveTo(x1, y1, x2, y2, x, y) {
  5267. this._append`C${+x1},${+y1},${+x2},${+y2},${this._x1 = +x},${this._y1 = +y}`;
  5268. }
  5269. arcTo(x1, y1, x2, y2, r) {
  5270. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  5271. // Is the radius negative? Error.
  5272. if (r < 0) throw new Error(`negative radius: ${r}`);
  5273. let x0 = this._x1,
  5274. y0 = this._y1,
  5275. x21 = x2 - x1,
  5276. y21 = y2 - y1,
  5277. x01 = x0 - x1,
  5278. y01 = y0 - y1,
  5279. l01_2 = x01 * x01 + y01 * y01;
  5280. // Is this path empty? Move to (x1,y1).
  5281. if (this._x1 === null) {
  5282. this._append`M${this._x1 = x1},${this._y1 = y1}`;
  5283. }
  5284. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  5285. else if (!(l01_2 > epsilon$4));
  5286. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  5287. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  5288. // Or, is the radius zero? Line to (x1,y1).
  5289. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$4) || !r) {
  5290. this._append`L${this._x1 = x1},${this._y1 = y1}`;
  5291. }
  5292. // Otherwise, draw an arc!
  5293. else {
  5294. let x20 = x2 - x0,
  5295. y20 = y2 - y0,
  5296. l21_2 = x21 * x21 + y21 * y21,
  5297. l20_2 = x20 * x20 + y20 * y20,
  5298. l21 = Math.sqrt(l21_2),
  5299. l01 = Math.sqrt(l01_2),
  5300. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  5301. t01 = l / l01,
  5302. t21 = l / l21;
  5303. // If the start tangent is not coincident with (x0,y0), line to.
  5304. if (Math.abs(t01 - 1) > epsilon$4) {
  5305. this._append`L${x1 + t01 * x01},${y1 + t01 * y01}`;
  5306. }
  5307. this._append`A${r},${r},0,0,${+(y01 * x20 > x01 * y20)},${this._x1 = x1 + t21 * x21},${this._y1 = y1 + t21 * y21}`;
  5308. }
  5309. }
  5310. arc(x, y, r, a0, a1, ccw) {
  5311. x = +x, y = +y, r = +r, ccw = !!ccw;
  5312. // Is the radius negative? Error.
  5313. if (r < 0) throw new Error(`negative radius: ${r}`);
  5314. let dx = r * Math.cos(a0),
  5315. dy = r * Math.sin(a0),
  5316. x0 = x + dx,
  5317. y0 = y + dy,
  5318. cw = 1 ^ ccw,
  5319. da = ccw ? a0 - a1 : a1 - a0;
  5320. // Is this path empty? Move to (x0,y0).
  5321. if (this._x1 === null) {
  5322. this._append`M${x0},${y0}`;
  5323. }
  5324. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  5325. else if (Math.abs(this._x1 - x0) > epsilon$4 || Math.abs(this._y1 - y0) > epsilon$4) {
  5326. this._append`L${x0},${y0}`;
  5327. }
  5328. // Is this arc empty? We’re done.
  5329. if (!r) return;
  5330. // Does the angle go the wrong way? Flip the direction.
  5331. if (da < 0) da = da % tau$3 + tau$3;
  5332. // Is this a complete circle? Draw two arcs to complete the circle.
  5333. if (da > tauEpsilon) {
  5334. this._append`A${r},${r},0,1,${cw},${x - dx},${y - dy}A${r},${r},0,1,${cw},${this._x1 = x0},${this._y1 = y0}`;
  5335. }
  5336. // Is this arc non-empty? Draw an arc!
  5337. else if (da > epsilon$4) {
  5338. this._append`A${r},${r},0,${+(da >= pi$2)},${cw},${this._x1 = x + r * Math.cos(a1)},${this._y1 = y + r * Math.sin(a1)}`;
  5339. }
  5340. }
  5341. rect(x, y, w, h) {
  5342. this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${w = +w}v${+h}h${-w}Z`;
  5343. }
  5344. toString() {
  5345. return this._;
  5346. }
  5347. };
  5348. function path() {
  5349. return new Path$1;
  5350. }
  5351. // Allow instanceof d3.path
  5352. path.prototype = Path$1.prototype;
  5353. function pathRound(digits = 3) {
  5354. return new Path$1(+digits);
  5355. }
  5356. var slice$2 = Array.prototype.slice;
  5357. function constant$6(x) {
  5358. return function() {
  5359. return x;
  5360. };
  5361. }
  5362. function defaultSource$1(d) {
  5363. return d.source;
  5364. }
  5365. function defaultTarget(d) {
  5366. return d.target;
  5367. }
  5368. function defaultRadius$1(d) {
  5369. return d.radius;
  5370. }
  5371. function defaultStartAngle(d) {
  5372. return d.startAngle;
  5373. }
  5374. function defaultEndAngle(d) {
  5375. return d.endAngle;
  5376. }
  5377. function defaultPadAngle() {
  5378. return 0;
  5379. }
  5380. function defaultArrowheadRadius() {
  5381. return 10;
  5382. }
  5383. function ribbon(headRadius) {
  5384. var source = defaultSource$1,
  5385. target = defaultTarget,
  5386. sourceRadius = defaultRadius$1,
  5387. targetRadius = defaultRadius$1,
  5388. startAngle = defaultStartAngle,
  5389. endAngle = defaultEndAngle,
  5390. padAngle = defaultPadAngle,
  5391. context = null;
  5392. function ribbon() {
  5393. var buffer,
  5394. s = source.apply(this, arguments),
  5395. t = target.apply(this, arguments),
  5396. ap = padAngle.apply(this, arguments) / 2,
  5397. argv = slice$2.call(arguments),
  5398. sr = +sourceRadius.apply(this, (argv[0] = s, argv)),
  5399. sa0 = startAngle.apply(this, argv) - halfPi$2,
  5400. sa1 = endAngle.apply(this, argv) - halfPi$2,
  5401. tr = +targetRadius.apply(this, (argv[0] = t, argv)),
  5402. ta0 = startAngle.apply(this, argv) - halfPi$2,
  5403. ta1 = endAngle.apply(this, argv) - halfPi$2;
  5404. if (!context) context = buffer = path();
  5405. if (ap > epsilon$5) {
  5406. if (abs$2(sa1 - sa0) > ap * 2 + epsilon$5) sa1 > sa0 ? (sa0 += ap, sa1 -= ap) : (sa0 -= ap, sa1 += ap);
  5407. else sa0 = sa1 = (sa0 + sa1) / 2;
  5408. if (abs$2(ta1 - ta0) > ap * 2 + epsilon$5) ta1 > ta0 ? (ta0 += ap, ta1 -= ap) : (ta0 -= ap, ta1 += ap);
  5409. else ta0 = ta1 = (ta0 + ta1) / 2;
  5410. }
  5411. context.moveTo(sr * cos$2(sa0), sr * sin$2(sa0));
  5412. context.arc(0, 0, sr, sa0, sa1);
  5413. if (sa0 !== ta0 || sa1 !== ta1) {
  5414. if (headRadius) {
  5415. var hr = +headRadius.apply(this, arguments), tr2 = tr - hr, ta2 = (ta0 + ta1) / 2;
  5416. context.quadraticCurveTo(0, 0, tr2 * cos$2(ta0), tr2 * sin$2(ta0));
  5417. context.lineTo(tr * cos$2(ta2), tr * sin$2(ta2));
  5418. context.lineTo(tr2 * cos$2(ta1), tr2 * sin$2(ta1));
  5419. } else {
  5420. context.quadraticCurveTo(0, 0, tr * cos$2(ta0), tr * sin$2(ta0));
  5421. context.arc(0, 0, tr, ta0, ta1);
  5422. }
  5423. }
  5424. context.quadraticCurveTo(0, 0, sr * cos$2(sa0), sr * sin$2(sa0));
  5425. context.closePath();
  5426. if (buffer) return context = null, buffer + "" || null;
  5427. }
  5428. if (headRadius) ribbon.headRadius = function(_) {
  5429. return arguments.length ? (headRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : headRadius;
  5430. };
  5431. ribbon.radius = function(_) {
  5432. return arguments.length ? (sourceRadius = targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
  5433. };
  5434. ribbon.sourceRadius = function(_) {
  5435. return arguments.length ? (sourceRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
  5436. };
  5437. ribbon.targetRadius = function(_) {
  5438. return arguments.length ? (targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : targetRadius;
  5439. };
  5440. ribbon.startAngle = function(_) {
  5441. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : startAngle;
  5442. };
  5443. ribbon.endAngle = function(_) {
  5444. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : endAngle;
  5445. };
  5446. ribbon.padAngle = function(_) {
  5447. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : padAngle;
  5448. };
  5449. ribbon.source = function(_) {
  5450. return arguments.length ? (source = _, ribbon) : source;
  5451. };
  5452. ribbon.target = function(_) {
  5453. return arguments.length ? (target = _, ribbon) : target;
  5454. };
  5455. ribbon.context = function(_) {
  5456. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  5457. };
  5458. return ribbon;
  5459. }
  5460. function ribbon$1() {
  5461. return ribbon();
  5462. }
  5463. function ribbonArrow() {
  5464. return ribbon(defaultArrowheadRadius);
  5465. }
  5466. var array$2 = Array.prototype;
  5467. var slice$1 = array$2.slice;
  5468. function ascending$1(a, b) {
  5469. return a - b;
  5470. }
  5471. function area$3(ring) {
  5472. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  5473. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  5474. return area;
  5475. }
  5476. var constant$5 = x => () => x;
  5477. function contains$2(ring, hole) {
  5478. var i = -1, n = hole.length, c;
  5479. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  5480. return 0;
  5481. }
  5482. function ringContains(ring, point) {
  5483. var x = point[0], y = point[1], contains = -1;
  5484. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  5485. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  5486. if (segmentContains(pi, pj, point)) return 0;
  5487. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  5488. }
  5489. return contains;
  5490. }
  5491. function segmentContains(a, b, c) {
  5492. var i; return collinear$1(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  5493. }
  5494. function collinear$1(a, b, c) {
  5495. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  5496. }
  5497. function within(p, q, r) {
  5498. return p <= q && q <= r || r <= q && q <= p;
  5499. }
  5500. function noop$2() {}
  5501. var cases = [
  5502. [],
  5503. [[[1.0, 1.5], [0.5, 1.0]]],
  5504. [[[1.5, 1.0], [1.0, 1.5]]],
  5505. [[[1.5, 1.0], [0.5, 1.0]]],
  5506. [[[1.0, 0.5], [1.5, 1.0]]],
  5507. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  5508. [[[1.0, 0.5], [1.0, 1.5]]],
  5509. [[[1.0, 0.5], [0.5, 1.0]]],
  5510. [[[0.5, 1.0], [1.0, 0.5]]],
  5511. [[[1.0, 1.5], [1.0, 0.5]]],
  5512. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  5513. [[[1.5, 1.0], [1.0, 0.5]]],
  5514. [[[0.5, 1.0], [1.5, 1.0]]],
  5515. [[[1.0, 1.5], [1.5, 1.0]]],
  5516. [[[0.5, 1.0], [1.0, 1.5]]],
  5517. []
  5518. ];
  5519. function Contours() {
  5520. var dx = 1,
  5521. dy = 1,
  5522. threshold = thresholdSturges,
  5523. smooth = smoothLinear;
  5524. function contours(values) {
  5525. var tz = threshold(values);
  5526. // Convert number of thresholds into uniform thresholds.
  5527. if (!Array.isArray(tz)) {
  5528. const e = extent$1(values, finite);
  5529. tz = ticks(...nice$1(e[0], e[1], tz), tz);
  5530. while (tz[tz.length - 1] >= e[1]) tz.pop();
  5531. while (tz[1] < e[0]) tz.shift();
  5532. } else {
  5533. tz = tz.slice().sort(ascending$1);
  5534. }
  5535. return tz.map(value => contour(values, value));
  5536. }
  5537. // Accumulate, smooth contour rings, assign holes to exterior rings.
  5538. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  5539. function contour(values, value) {
  5540. const v = value == null ? NaN : +value;
  5541. if (isNaN(v)) throw new Error(`invalid value: ${value}`);
  5542. var polygons = [],
  5543. holes = [];
  5544. isorings(values, v, function(ring) {
  5545. smooth(ring, values, v);
  5546. if (area$3(ring) > 0) polygons.push([ring]);
  5547. else holes.push(ring);
  5548. });
  5549. holes.forEach(function(hole) {
  5550. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  5551. if (contains$2((polygon = polygons[i])[0], hole) !== -1) {
  5552. polygon.push(hole);
  5553. return;
  5554. }
  5555. }
  5556. });
  5557. return {
  5558. type: "MultiPolygon",
  5559. value: value,
  5560. coordinates: polygons
  5561. };
  5562. }
  5563. // Marching squares with isolines stitched into rings.
  5564. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  5565. function isorings(values, value, callback) {
  5566. var fragmentByStart = new Array,
  5567. fragmentByEnd = new Array,
  5568. x, y, t0, t1, t2, t3;
  5569. // Special case for the first row (y = -1, t2 = t3 = 0).
  5570. x = y = -1;
  5571. t1 = above(values[0], value);
  5572. cases[t1 << 1].forEach(stitch);
  5573. while (++x < dx - 1) {
  5574. t0 = t1, t1 = above(values[x + 1], value);
  5575. cases[t0 | t1 << 1].forEach(stitch);
  5576. }
  5577. cases[t1 << 0].forEach(stitch);
  5578. // General case for the intermediate rows.
  5579. while (++y < dy - 1) {
  5580. x = -1;
  5581. t1 = above(values[y * dx + dx], value);
  5582. t2 = above(values[y * dx], value);
  5583. cases[t1 << 1 | t2 << 2].forEach(stitch);
  5584. while (++x < dx - 1) {
  5585. t0 = t1, t1 = above(values[y * dx + dx + x + 1], value);
  5586. t3 = t2, t2 = above(values[y * dx + x + 1], value);
  5587. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  5588. }
  5589. cases[t1 | t2 << 3].forEach(stitch);
  5590. }
  5591. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  5592. x = -1;
  5593. t2 = values[y * dx] >= value;
  5594. cases[t2 << 2].forEach(stitch);
  5595. while (++x < dx - 1) {
  5596. t3 = t2, t2 = above(values[y * dx + x + 1], value);
  5597. cases[t2 << 2 | t3 << 3].forEach(stitch);
  5598. }
  5599. cases[t2 << 3].forEach(stitch);
  5600. function stitch(line) {
  5601. var start = [line[0][0] + x, line[0][1] + y],
  5602. end = [line[1][0] + x, line[1][1] + y],
  5603. startIndex = index(start),
  5604. endIndex = index(end),
  5605. f, g;
  5606. if (f = fragmentByEnd[startIndex]) {
  5607. if (g = fragmentByStart[endIndex]) {
  5608. delete fragmentByEnd[f.end];
  5609. delete fragmentByStart[g.start];
  5610. if (f === g) {
  5611. f.ring.push(end);
  5612. callback(f.ring);
  5613. } else {
  5614. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  5615. }
  5616. } else {
  5617. delete fragmentByEnd[f.end];
  5618. f.ring.push(end);
  5619. fragmentByEnd[f.end = endIndex] = f;
  5620. }
  5621. } else if (f = fragmentByStart[endIndex]) {
  5622. if (g = fragmentByEnd[startIndex]) {
  5623. delete fragmentByStart[f.start];
  5624. delete fragmentByEnd[g.end];
  5625. if (f === g) {
  5626. f.ring.push(end);
  5627. callback(f.ring);
  5628. } else {
  5629. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  5630. }
  5631. } else {
  5632. delete fragmentByStart[f.start];
  5633. f.ring.unshift(start);
  5634. fragmentByStart[f.start = startIndex] = f;
  5635. }
  5636. } else {
  5637. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  5638. }
  5639. }
  5640. }
  5641. function index(point) {
  5642. return point[0] * 2 + point[1] * (dx + 1) * 4;
  5643. }
  5644. function smoothLinear(ring, values, value) {
  5645. ring.forEach(function(point) {
  5646. var x = point[0],
  5647. y = point[1],
  5648. xt = x | 0,
  5649. yt = y | 0,
  5650. v1 = valid(values[yt * dx + xt]);
  5651. if (x > 0 && x < dx && xt === x) {
  5652. point[0] = smooth1(x, valid(values[yt * dx + xt - 1]), v1, value);
  5653. }
  5654. if (y > 0 && y < dy && yt === y) {
  5655. point[1] = smooth1(y, valid(values[(yt - 1) * dx + xt]), v1, value);
  5656. }
  5657. });
  5658. }
  5659. contours.contour = contour;
  5660. contours.size = function(_) {
  5661. if (!arguments.length) return [dx, dy];
  5662. var _0 = Math.floor(_[0]), _1 = Math.floor(_[1]);
  5663. if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
  5664. return dx = _0, dy = _1, contours;
  5665. };
  5666. contours.thresholds = function(_) {
  5667. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), contours) : threshold;
  5668. };
  5669. contours.smooth = function(_) {
  5670. return arguments.length ? (smooth = _ ? smoothLinear : noop$2, contours) : smooth === smoothLinear;
  5671. };
  5672. return contours;
  5673. }
  5674. // When computing the extent, ignore infinite values (as well as invalid ones).
  5675. function finite(x) {
  5676. return isFinite(x) ? x : NaN;
  5677. }
  5678. // Is the (possibly invalid) x greater than or equal to the (known valid) value?
  5679. // Treat any invalid value as below negative infinity.
  5680. function above(x, value) {
  5681. return x == null ? false : +x >= value;
  5682. }
  5683. // During smoothing, treat any invalid value as negative infinity.
  5684. function valid(v) {
  5685. return v == null || isNaN(v = +v) ? -Infinity : v;
  5686. }
  5687. function smooth1(x, v0, v1, value) {
  5688. const a = value - v0;
  5689. const b = v1 - v0;
  5690. const d = isFinite(a) || isFinite(b) ? a / b : Math.sign(a) / Math.sign(b);
  5691. return isNaN(d) ? x : x + d - 0.5;
  5692. }
  5693. function defaultX$1(d) {
  5694. return d[0];
  5695. }
  5696. function defaultY$1(d) {
  5697. return d[1];
  5698. }
  5699. function defaultWeight() {
  5700. return 1;
  5701. }
  5702. function density() {
  5703. var x = defaultX$1,
  5704. y = defaultY$1,
  5705. weight = defaultWeight,
  5706. dx = 960,
  5707. dy = 500,
  5708. r = 20, // blur radius
  5709. k = 2, // log2(grid cell size)
  5710. o = r * 3, // grid offset, to pad for blur
  5711. n = (dx + o * 2) >> k, // grid width
  5712. m = (dy + o * 2) >> k, // grid height
  5713. threshold = constant$5(20);
  5714. function grid(data) {
  5715. var values = new Float32Array(n * m),
  5716. pow2k = Math.pow(2, -k),
  5717. i = -1;
  5718. for (const d of data) {
  5719. var xi = (x(d, ++i, data) + o) * pow2k,
  5720. yi = (y(d, i, data) + o) * pow2k,
  5721. wi = +weight(d, i, data);
  5722. if (wi && xi >= 0 && xi < n && yi >= 0 && yi < m) {
  5723. var x0 = Math.floor(xi),
  5724. y0 = Math.floor(yi),
  5725. xt = xi - x0 - 0.5,
  5726. yt = yi - y0 - 0.5;
  5727. values[x0 + y0 * n] += (1 - xt) * (1 - yt) * wi;
  5728. values[x0 + 1 + y0 * n] += xt * (1 - yt) * wi;
  5729. values[x0 + 1 + (y0 + 1) * n] += xt * yt * wi;
  5730. values[x0 + (y0 + 1) * n] += (1 - xt) * yt * wi;
  5731. }
  5732. }
  5733. blur2({data: values, width: n, height: m}, r * pow2k);
  5734. return values;
  5735. }
  5736. function density(data) {
  5737. var values = grid(data),
  5738. tz = threshold(values),
  5739. pow4k = Math.pow(2, 2 * k);
  5740. // Convert number of thresholds into uniform thresholds.
  5741. if (!Array.isArray(tz)) {
  5742. tz = ticks(Number.MIN_VALUE, max$3(values) / pow4k, tz);
  5743. }
  5744. return Contours()
  5745. .size([n, m])
  5746. .thresholds(tz.map(d => d * pow4k))
  5747. (values)
  5748. .map((c, i) => (c.value = +tz[i], transform(c)));
  5749. }
  5750. density.contours = function(data) {
  5751. var values = grid(data),
  5752. contours = Contours().size([n, m]),
  5753. pow4k = Math.pow(2, 2 * k),
  5754. contour = value => {
  5755. value = +value;
  5756. var c = transform(contours.contour(values, value * pow4k));
  5757. c.value = value; // preserve exact threshold value
  5758. return c;
  5759. };
  5760. Object.defineProperty(contour, "max", {get: () => max$3(values) / pow4k});
  5761. return contour;
  5762. };
  5763. function transform(geometry) {
  5764. geometry.coordinates.forEach(transformPolygon);
  5765. return geometry;
  5766. }
  5767. function transformPolygon(coordinates) {
  5768. coordinates.forEach(transformRing);
  5769. }
  5770. function transformRing(coordinates) {
  5771. coordinates.forEach(transformPoint);
  5772. }
  5773. // TODO Optimize.
  5774. function transformPoint(coordinates) {
  5775. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  5776. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  5777. }
  5778. function resize() {
  5779. o = r * 3;
  5780. n = (dx + o * 2) >> k;
  5781. m = (dy + o * 2) >> k;
  5782. return density;
  5783. }
  5784. density.x = function(_) {
  5785. return arguments.length ? (x = typeof _ === "function" ? _ : constant$5(+_), density) : x;
  5786. };
  5787. density.y = function(_) {
  5788. return arguments.length ? (y = typeof _ === "function" ? _ : constant$5(+_), density) : y;
  5789. };
  5790. density.weight = function(_) {
  5791. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$5(+_), density) : weight;
  5792. };
  5793. density.size = function(_) {
  5794. if (!arguments.length) return [dx, dy];
  5795. var _0 = +_[0], _1 = +_[1];
  5796. if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
  5797. return dx = _0, dy = _1, resize();
  5798. };
  5799. density.cellSize = function(_) {
  5800. if (!arguments.length) return 1 << k;
  5801. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  5802. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  5803. };
  5804. density.thresholds = function(_) {
  5805. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), density) : threshold;
  5806. };
  5807. density.bandwidth = function(_) {
  5808. if (!arguments.length) return Math.sqrt(r * (r + 1));
  5809. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  5810. return r = (Math.sqrt(4 * _ * _ + 1) - 1) / 2, resize();
  5811. };
  5812. return density;
  5813. }
  5814. const epsilon$3 = 1.1102230246251565e-16;
  5815. const splitter = 134217729;
  5816. const resulterrbound = (3 + 8 * epsilon$3) * epsilon$3;
  5817. // fast_expansion_sum_zeroelim routine from oritinal code
  5818. function sum$1(elen, e, flen, f, h) {
  5819. let Q, Qnew, hh, bvirt;
  5820. let enow = e[0];
  5821. let fnow = f[0];
  5822. let eindex = 0;
  5823. let findex = 0;
  5824. if ((fnow > enow) === (fnow > -enow)) {
  5825. Q = enow;
  5826. enow = e[++eindex];
  5827. } else {
  5828. Q = fnow;
  5829. fnow = f[++findex];
  5830. }
  5831. let hindex = 0;
  5832. if (eindex < elen && findex < flen) {
  5833. if ((fnow > enow) === (fnow > -enow)) {
  5834. Qnew = enow + Q;
  5835. hh = Q - (Qnew - enow);
  5836. enow = e[++eindex];
  5837. } else {
  5838. Qnew = fnow + Q;
  5839. hh = Q - (Qnew - fnow);
  5840. fnow = f[++findex];
  5841. }
  5842. Q = Qnew;
  5843. if (hh !== 0) {
  5844. h[hindex++] = hh;
  5845. }
  5846. while (eindex < elen && findex < flen) {
  5847. if ((fnow > enow) === (fnow > -enow)) {
  5848. Qnew = Q + enow;
  5849. bvirt = Qnew - Q;
  5850. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  5851. enow = e[++eindex];
  5852. } else {
  5853. Qnew = Q + fnow;
  5854. bvirt = Qnew - Q;
  5855. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  5856. fnow = f[++findex];
  5857. }
  5858. Q = Qnew;
  5859. if (hh !== 0) {
  5860. h[hindex++] = hh;
  5861. }
  5862. }
  5863. }
  5864. while (eindex < elen) {
  5865. Qnew = Q + enow;
  5866. bvirt = Qnew - Q;
  5867. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  5868. enow = e[++eindex];
  5869. Q = Qnew;
  5870. if (hh !== 0) {
  5871. h[hindex++] = hh;
  5872. }
  5873. }
  5874. while (findex < flen) {
  5875. Qnew = Q + fnow;
  5876. bvirt = Qnew - Q;
  5877. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  5878. fnow = f[++findex];
  5879. Q = Qnew;
  5880. if (hh !== 0) {
  5881. h[hindex++] = hh;
  5882. }
  5883. }
  5884. if (Q !== 0 || hindex === 0) {
  5885. h[hindex++] = Q;
  5886. }
  5887. return hindex;
  5888. }
  5889. function estimate(elen, e) {
  5890. let Q = e[0];
  5891. for (let i = 1; i < elen; i++) Q += e[i];
  5892. return Q;
  5893. }
  5894. function vec(n) {
  5895. return new Float64Array(n);
  5896. }
  5897. const ccwerrboundA = (3 + 16 * epsilon$3) * epsilon$3;
  5898. const ccwerrboundB = (2 + 12 * epsilon$3) * epsilon$3;
  5899. const ccwerrboundC = (9 + 64 * epsilon$3) * epsilon$3 * epsilon$3;
  5900. const B = vec(4);
  5901. const C1 = vec(8);
  5902. const C2 = vec(12);
  5903. const D = vec(16);
  5904. const u = vec(4);
  5905. function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
  5906. let acxtail, acytail, bcxtail, bcytail;
  5907. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  5908. const acx = ax - cx;
  5909. const bcx = bx - cx;
  5910. const acy = ay - cy;
  5911. const bcy = by - cy;
  5912. s1 = acx * bcy;
  5913. c = splitter * acx;
  5914. ahi = c - (c - acx);
  5915. alo = acx - ahi;
  5916. c = splitter * bcy;
  5917. bhi = c - (c - bcy);
  5918. blo = bcy - bhi;
  5919. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  5920. t1 = acy * bcx;
  5921. c = splitter * acy;
  5922. ahi = c - (c - acy);
  5923. alo = acy - ahi;
  5924. c = splitter * bcx;
  5925. bhi = c - (c - bcx);
  5926. blo = bcx - bhi;
  5927. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  5928. _i = s0 - t0;
  5929. bvirt = s0 - _i;
  5930. B[0] = s0 - (_i + bvirt) + (bvirt - t0);
  5931. _j = s1 + _i;
  5932. bvirt = _j - s1;
  5933. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  5934. _i = _0 - t1;
  5935. bvirt = _0 - _i;
  5936. B[1] = _0 - (_i + bvirt) + (bvirt - t1);
  5937. u3 = _j + _i;
  5938. bvirt = u3 - _j;
  5939. B[2] = _j - (u3 - bvirt) + (_i - bvirt);
  5940. B[3] = u3;
  5941. let det = estimate(4, B);
  5942. let errbound = ccwerrboundB * detsum;
  5943. if (det >= errbound || -det >= errbound) {
  5944. return det;
  5945. }
  5946. bvirt = ax - acx;
  5947. acxtail = ax - (acx + bvirt) + (bvirt - cx);
  5948. bvirt = bx - bcx;
  5949. bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
  5950. bvirt = ay - acy;
  5951. acytail = ay - (acy + bvirt) + (bvirt - cy);
  5952. bvirt = by - bcy;
  5953. bcytail = by - (bcy + bvirt) + (bvirt - cy);
  5954. if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
  5955. return det;
  5956. }
  5957. errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
  5958. det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
  5959. if (det >= errbound || -det >= errbound) return det;
  5960. s1 = acxtail * bcy;
  5961. c = splitter * acxtail;
  5962. ahi = c - (c - acxtail);
  5963. alo = acxtail - ahi;
  5964. c = splitter * bcy;
  5965. bhi = c - (c - bcy);
  5966. blo = bcy - bhi;
  5967. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  5968. t1 = acytail * bcx;
  5969. c = splitter * acytail;
  5970. ahi = c - (c - acytail);
  5971. alo = acytail - ahi;
  5972. c = splitter * bcx;
  5973. bhi = c - (c - bcx);
  5974. blo = bcx - bhi;
  5975. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  5976. _i = s0 - t0;
  5977. bvirt = s0 - _i;
  5978. u[0] = s0 - (_i + bvirt) + (bvirt - t0);
  5979. _j = s1 + _i;
  5980. bvirt = _j - s1;
  5981. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  5982. _i = _0 - t1;
  5983. bvirt = _0 - _i;
  5984. u[1] = _0 - (_i + bvirt) + (bvirt - t1);
  5985. u3 = _j + _i;
  5986. bvirt = u3 - _j;
  5987. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  5988. u[3] = u3;
  5989. const C1len = sum$1(4, B, 4, u, C1);
  5990. s1 = acx * bcytail;
  5991. c = splitter * acx;
  5992. ahi = c - (c - acx);
  5993. alo = acx - ahi;
  5994. c = splitter * bcytail;
  5995. bhi = c - (c - bcytail);
  5996. blo = bcytail - bhi;
  5997. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  5998. t1 = acy * bcxtail;
  5999. c = splitter * acy;
  6000. ahi = c - (c - acy);
  6001. alo = acy - ahi;
  6002. c = splitter * bcxtail;
  6003. bhi = c - (c - bcxtail);
  6004. blo = bcxtail - bhi;
  6005. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  6006. _i = s0 - t0;
  6007. bvirt = s0 - _i;
  6008. u[0] = s0 - (_i + bvirt) + (bvirt - t0);
  6009. _j = s1 + _i;
  6010. bvirt = _j - s1;
  6011. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  6012. _i = _0 - t1;
  6013. bvirt = _0 - _i;
  6014. u[1] = _0 - (_i + bvirt) + (bvirt - t1);
  6015. u3 = _j + _i;
  6016. bvirt = u3 - _j;
  6017. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  6018. u[3] = u3;
  6019. const C2len = sum$1(C1len, C1, 4, u, C2);
  6020. s1 = acxtail * bcytail;
  6021. c = splitter * acxtail;
  6022. ahi = c - (c - acxtail);
  6023. alo = acxtail - ahi;
  6024. c = splitter * bcytail;
  6025. bhi = c - (c - bcytail);
  6026. blo = bcytail - bhi;
  6027. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  6028. t1 = acytail * bcxtail;
  6029. c = splitter * acytail;
  6030. ahi = c - (c - acytail);
  6031. alo = acytail - ahi;
  6032. c = splitter * bcxtail;
  6033. bhi = c - (c - bcxtail);
  6034. blo = bcxtail - bhi;
  6035. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  6036. _i = s0 - t0;
  6037. bvirt = s0 - _i;
  6038. u[0] = s0 - (_i + bvirt) + (bvirt - t0);
  6039. _j = s1 + _i;
  6040. bvirt = _j - s1;
  6041. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  6042. _i = _0 - t1;
  6043. bvirt = _0 - _i;
  6044. u[1] = _0 - (_i + bvirt) + (bvirt - t1);
  6045. u3 = _j + _i;
  6046. bvirt = u3 - _j;
  6047. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  6048. u[3] = u3;
  6049. const Dlen = sum$1(C2len, C2, 4, u, D);
  6050. return D[Dlen - 1];
  6051. }
  6052. function orient2d(ax, ay, bx, by, cx, cy) {
  6053. const detleft = (ay - cy) * (bx - cx);
  6054. const detright = (ax - cx) * (by - cy);
  6055. const det = detleft - detright;
  6056. const detsum = Math.abs(detleft + detright);
  6057. if (Math.abs(det) >= ccwerrboundA * detsum) return det;
  6058. return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
  6059. }
  6060. const EPSILON = Math.pow(2, -52);
  6061. const EDGE_STACK = new Uint32Array(512);
  6062. class Delaunator {
  6063. static from(points, getX = defaultGetX, getY = defaultGetY) {
  6064. const n = points.length;
  6065. const coords = new Float64Array(n * 2);
  6066. for (let i = 0; i < n; i++) {
  6067. const p = points[i];
  6068. coords[2 * i] = getX(p);
  6069. coords[2 * i + 1] = getY(p);
  6070. }
  6071. return new Delaunator(coords);
  6072. }
  6073. constructor(coords) {
  6074. const n = coords.length >> 1;
  6075. if (n > 0 && typeof coords[0] !== 'number') throw new Error('Expected coords to contain numbers.');
  6076. this.coords = coords;
  6077. // arrays that will store the triangulation graph
  6078. const maxTriangles = Math.max(2 * n - 5, 0);
  6079. this._triangles = new Uint32Array(maxTriangles * 3);
  6080. this._halfedges = new Int32Array(maxTriangles * 3);
  6081. // temporary arrays for tracking the edges of the advancing convex hull
  6082. this._hashSize = Math.ceil(Math.sqrt(n));
  6083. this._hullPrev = new Uint32Array(n); // edge to prev edge
  6084. this._hullNext = new Uint32Array(n); // edge to next edge
  6085. this._hullTri = new Uint32Array(n); // edge to adjacent triangle
  6086. this._hullHash = new Int32Array(this._hashSize).fill(-1); // angular edge hash
  6087. // temporary arrays for sorting points
  6088. this._ids = new Uint32Array(n);
  6089. this._dists = new Float64Array(n);
  6090. this.update();
  6091. }
  6092. update() {
  6093. const {coords, _hullPrev: hullPrev, _hullNext: hullNext, _hullTri: hullTri, _hullHash: hullHash} = this;
  6094. const n = coords.length >> 1;
  6095. // populate an array of point indices; calculate input data bbox
  6096. let minX = Infinity;
  6097. let minY = Infinity;
  6098. let maxX = -Infinity;
  6099. let maxY = -Infinity;
  6100. for (let i = 0; i < n; i++) {
  6101. const x = coords[2 * i];
  6102. const y = coords[2 * i + 1];
  6103. if (x < minX) minX = x;
  6104. if (y < minY) minY = y;
  6105. if (x > maxX) maxX = x;
  6106. if (y > maxY) maxY = y;
  6107. this._ids[i] = i;
  6108. }
  6109. const cx = (minX + maxX) / 2;
  6110. const cy = (minY + maxY) / 2;
  6111. let minDist = Infinity;
  6112. let i0, i1, i2;
  6113. // pick a seed point close to the center
  6114. for (let i = 0; i < n; i++) {
  6115. const d = dist(cx, cy, coords[2 * i], coords[2 * i + 1]);
  6116. if (d < minDist) {
  6117. i0 = i;
  6118. minDist = d;
  6119. }
  6120. }
  6121. const i0x = coords[2 * i0];
  6122. const i0y = coords[2 * i0 + 1];
  6123. minDist = Infinity;
  6124. // find the point closest to the seed
  6125. for (let i = 0; i < n; i++) {
  6126. if (i === i0) continue;
  6127. const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
  6128. if (d < minDist && d > 0) {
  6129. i1 = i;
  6130. minDist = d;
  6131. }
  6132. }
  6133. let i1x = coords[2 * i1];
  6134. let i1y = coords[2 * i1 + 1];
  6135. let minRadius = Infinity;
  6136. // find the third point which forms the smallest circumcircle with the first two
  6137. for (let i = 0; i < n; i++) {
  6138. if (i === i0 || i === i1) continue;
  6139. const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
  6140. if (r < minRadius) {
  6141. i2 = i;
  6142. minRadius = r;
  6143. }
  6144. }
  6145. let i2x = coords[2 * i2];
  6146. let i2y = coords[2 * i2 + 1];
  6147. if (minRadius === Infinity) {
  6148. // order collinear points by dx (or dy if all x are identical)
  6149. // and return the list as a hull
  6150. for (let i = 0; i < n; i++) {
  6151. this._dists[i] = (coords[2 * i] - coords[0]) || (coords[2 * i + 1] - coords[1]);
  6152. }
  6153. quicksort(this._ids, this._dists, 0, n - 1);
  6154. const hull = new Uint32Array(n);
  6155. let j = 0;
  6156. for (let i = 0, d0 = -Infinity; i < n; i++) {
  6157. const id = this._ids[i];
  6158. if (this._dists[id] > d0) {
  6159. hull[j++] = id;
  6160. d0 = this._dists[id];
  6161. }
  6162. }
  6163. this.hull = hull.subarray(0, j);
  6164. this.triangles = new Uint32Array(0);
  6165. this.halfedges = new Uint32Array(0);
  6166. return;
  6167. }
  6168. // swap the order of the seed points for counter-clockwise orientation
  6169. if (orient2d(i0x, i0y, i1x, i1y, i2x, i2y) < 0) {
  6170. const i = i1;
  6171. const x = i1x;
  6172. const y = i1y;
  6173. i1 = i2;
  6174. i1x = i2x;
  6175. i1y = i2y;
  6176. i2 = i;
  6177. i2x = x;
  6178. i2y = y;
  6179. }
  6180. const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
  6181. this._cx = center.x;
  6182. this._cy = center.y;
  6183. for (let i = 0; i < n; i++) {
  6184. this._dists[i] = dist(coords[2 * i], coords[2 * i + 1], center.x, center.y);
  6185. }
  6186. // sort the points by distance from the seed triangle circumcenter
  6187. quicksort(this._ids, this._dists, 0, n - 1);
  6188. // set up the seed triangle as the starting hull
  6189. this._hullStart = i0;
  6190. let hullSize = 3;
  6191. hullNext[i0] = hullPrev[i2] = i1;
  6192. hullNext[i1] = hullPrev[i0] = i2;
  6193. hullNext[i2] = hullPrev[i1] = i0;
  6194. hullTri[i0] = 0;
  6195. hullTri[i1] = 1;
  6196. hullTri[i2] = 2;
  6197. hullHash.fill(-1);
  6198. hullHash[this._hashKey(i0x, i0y)] = i0;
  6199. hullHash[this._hashKey(i1x, i1y)] = i1;
  6200. hullHash[this._hashKey(i2x, i2y)] = i2;
  6201. this.trianglesLen = 0;
  6202. this._addTriangle(i0, i1, i2, -1, -1, -1);
  6203. for (let k = 0, xp, yp; k < this._ids.length; k++) {
  6204. const i = this._ids[k];
  6205. const x = coords[2 * i];
  6206. const y = coords[2 * i + 1];
  6207. // skip near-duplicate points
  6208. if (k > 0 && Math.abs(x - xp) <= EPSILON && Math.abs(y - yp) <= EPSILON) continue;
  6209. xp = x;
  6210. yp = y;
  6211. // skip seed triangle points
  6212. if (i === i0 || i === i1 || i === i2) continue;
  6213. // find a visible edge on the convex hull using edge hash
  6214. let start = 0;
  6215. for (let j = 0, key = this._hashKey(x, y); j < this._hashSize; j++) {
  6216. start = hullHash[(key + j) % this._hashSize];
  6217. if (start !== -1 && start !== hullNext[start]) break;
  6218. }
  6219. start = hullPrev[start];
  6220. let e = start, q;
  6221. while (q = hullNext[e], orient2d(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1]) >= 0) {
  6222. e = q;
  6223. if (e === start) {
  6224. e = -1;
  6225. break;
  6226. }
  6227. }
  6228. if (e === -1) continue; // likely a near-duplicate point; skip it
  6229. // add the first triangle from the point
  6230. let t = this._addTriangle(e, i, hullNext[e], -1, -1, hullTri[e]);
  6231. // recursively flip triangles from the point until they satisfy the Delaunay condition
  6232. hullTri[i] = this._legalize(t + 2);
  6233. hullTri[e] = t; // keep track of boundary triangles on the hull
  6234. hullSize++;
  6235. // walk forward through the hull, adding more triangles and flipping recursively
  6236. let n = hullNext[e];
  6237. while (q = hullNext[n], orient2d(x, y, coords[2 * n], coords[2 * n + 1], coords[2 * q], coords[2 * q + 1]) < 0) {
  6238. t = this._addTriangle(n, i, q, hullTri[i], -1, hullTri[n]);
  6239. hullTri[i] = this._legalize(t + 2);
  6240. hullNext[n] = n; // mark as removed
  6241. hullSize--;
  6242. n = q;
  6243. }
  6244. // walk backward from the other side, adding more triangles and flipping
  6245. if (e === start) {
  6246. while (q = hullPrev[e], orient2d(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1]) < 0) {
  6247. t = this._addTriangle(q, i, e, -1, hullTri[e], hullTri[q]);
  6248. this._legalize(t + 2);
  6249. hullTri[q] = t;
  6250. hullNext[e] = e; // mark as removed
  6251. hullSize--;
  6252. e = q;
  6253. }
  6254. }
  6255. // update the hull indices
  6256. this._hullStart = hullPrev[i] = e;
  6257. hullNext[e] = hullPrev[n] = i;
  6258. hullNext[i] = n;
  6259. // save the two new edges in the hash table
  6260. hullHash[this._hashKey(x, y)] = i;
  6261. hullHash[this._hashKey(coords[2 * e], coords[2 * e + 1])] = e;
  6262. }
  6263. this.hull = new Uint32Array(hullSize);
  6264. for (let i = 0, e = this._hullStart; i < hullSize; i++) {
  6265. this.hull[i] = e;
  6266. e = hullNext[e];
  6267. }
  6268. // trim typed triangle mesh arrays
  6269. this.triangles = this._triangles.subarray(0, this.trianglesLen);
  6270. this.halfedges = this._halfedges.subarray(0, this.trianglesLen);
  6271. }
  6272. _hashKey(x, y) {
  6273. return Math.floor(pseudoAngle(x - this._cx, y - this._cy) * this._hashSize) % this._hashSize;
  6274. }
  6275. _legalize(a) {
  6276. const {_triangles: triangles, _halfedges: halfedges, coords} = this;
  6277. let i = 0;
  6278. let ar = 0;
  6279. // recursion eliminated with a fixed-size stack
  6280. while (true) {
  6281. const b = halfedges[a];
  6282. /* if the pair of triangles doesn't satisfy the Delaunay condition
  6283. * (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
  6284. * then do the same check/flip recursively for the new pair of triangles
  6285. *
  6286. * pl pl
  6287. * /||\ / \
  6288. * al/ || \bl al/ \a
  6289. * / || \ / \
  6290. * / a||b \ flip /___ar___\
  6291. * p0\ || /p1 => p0\---bl---/p1
  6292. * \ || / \ /
  6293. * ar\ || /br b\ /br
  6294. * \||/ \ /
  6295. * pr pr
  6296. */
  6297. const a0 = a - a % 3;
  6298. ar = a0 + (a + 2) % 3;
  6299. if (b === -1) { // convex hull edge
  6300. if (i === 0) break;
  6301. a = EDGE_STACK[--i];
  6302. continue;
  6303. }
  6304. const b0 = b - b % 3;
  6305. const al = a0 + (a + 1) % 3;
  6306. const bl = b0 + (b + 2) % 3;
  6307. const p0 = triangles[ar];
  6308. const pr = triangles[a];
  6309. const pl = triangles[al];
  6310. const p1 = triangles[bl];
  6311. const illegal = inCircle(
  6312. coords[2 * p0], coords[2 * p0 + 1],
  6313. coords[2 * pr], coords[2 * pr + 1],
  6314. coords[2 * pl], coords[2 * pl + 1],
  6315. coords[2 * p1], coords[2 * p1 + 1]);
  6316. if (illegal) {
  6317. triangles[a] = p1;
  6318. triangles[b] = p0;
  6319. const hbl = halfedges[bl];
  6320. // edge swapped on the other side of the hull (rare); fix the halfedge reference
  6321. if (hbl === -1) {
  6322. let e = this._hullStart;
  6323. do {
  6324. if (this._hullTri[e] === bl) {
  6325. this._hullTri[e] = a;
  6326. break;
  6327. }
  6328. e = this._hullPrev[e];
  6329. } while (e !== this._hullStart);
  6330. }
  6331. this._link(a, hbl);
  6332. this._link(b, halfedges[ar]);
  6333. this._link(ar, bl);
  6334. const br = b0 + (b + 1) % 3;
  6335. // don't worry about hitting the cap: it can only happen on extremely degenerate input
  6336. if (i < EDGE_STACK.length) {
  6337. EDGE_STACK[i++] = br;
  6338. }
  6339. } else {
  6340. if (i === 0) break;
  6341. a = EDGE_STACK[--i];
  6342. }
  6343. }
  6344. return ar;
  6345. }
  6346. _link(a, b) {
  6347. this._halfedges[a] = b;
  6348. if (b !== -1) this._halfedges[b] = a;
  6349. }
  6350. // add a new triangle given vertex indices and adjacent half-edge ids
  6351. _addTriangle(i0, i1, i2, a, b, c) {
  6352. const t = this.trianglesLen;
  6353. this._triangles[t] = i0;
  6354. this._triangles[t + 1] = i1;
  6355. this._triangles[t + 2] = i2;
  6356. this._link(t, a);
  6357. this._link(t + 1, b);
  6358. this._link(t + 2, c);
  6359. this.trianglesLen += 3;
  6360. return t;
  6361. }
  6362. }
  6363. // monotonically increases with real angle, but doesn't need expensive trigonometry
  6364. function pseudoAngle(dx, dy) {
  6365. const p = dx / (Math.abs(dx) + Math.abs(dy));
  6366. return (dy > 0 ? 3 - p : 1 + p) / 4; // [0..1]
  6367. }
  6368. function dist(ax, ay, bx, by) {
  6369. const dx = ax - bx;
  6370. const dy = ay - by;
  6371. return dx * dx + dy * dy;
  6372. }
  6373. function inCircle(ax, ay, bx, by, cx, cy, px, py) {
  6374. const dx = ax - px;
  6375. const dy = ay - py;
  6376. const ex = bx - px;
  6377. const ey = by - py;
  6378. const fx = cx - px;
  6379. const fy = cy - py;
  6380. const ap = dx * dx + dy * dy;
  6381. const bp = ex * ex + ey * ey;
  6382. const cp = fx * fx + fy * fy;
  6383. return dx * (ey * cp - bp * fy) -
  6384. dy * (ex * cp - bp * fx) +
  6385. ap * (ex * fy - ey * fx) < 0;
  6386. }
  6387. function circumradius(ax, ay, bx, by, cx, cy) {
  6388. const dx = bx - ax;
  6389. const dy = by - ay;
  6390. const ex = cx - ax;
  6391. const ey = cy - ay;
  6392. const bl = dx * dx + dy * dy;
  6393. const cl = ex * ex + ey * ey;
  6394. const d = 0.5 / (dx * ey - dy * ex);
  6395. const x = (ey * bl - dy * cl) * d;
  6396. const y = (dx * cl - ex * bl) * d;
  6397. return x * x + y * y;
  6398. }
  6399. function circumcenter(ax, ay, bx, by, cx, cy) {
  6400. const dx = bx - ax;
  6401. const dy = by - ay;
  6402. const ex = cx - ax;
  6403. const ey = cy - ay;
  6404. const bl = dx * dx + dy * dy;
  6405. const cl = ex * ex + ey * ey;
  6406. const d = 0.5 / (dx * ey - dy * ex);
  6407. const x = ax + (ey * bl - dy * cl) * d;
  6408. const y = ay + (dx * cl - ex * bl) * d;
  6409. return {x, y};
  6410. }
  6411. function quicksort(ids, dists, left, right) {
  6412. if (right - left <= 20) {
  6413. for (let i = left + 1; i <= right; i++) {
  6414. const temp = ids[i];
  6415. const tempDist = dists[temp];
  6416. let j = i - 1;
  6417. while (j >= left && dists[ids[j]] > tempDist) ids[j + 1] = ids[j--];
  6418. ids[j + 1] = temp;
  6419. }
  6420. } else {
  6421. const median = (left + right) >> 1;
  6422. let i = left + 1;
  6423. let j = right;
  6424. swap(ids, median, i);
  6425. if (dists[ids[left]] > dists[ids[right]]) swap(ids, left, right);
  6426. if (dists[ids[i]] > dists[ids[right]]) swap(ids, i, right);
  6427. if (dists[ids[left]] > dists[ids[i]]) swap(ids, left, i);
  6428. const temp = ids[i];
  6429. const tempDist = dists[temp];
  6430. while (true) {
  6431. do i++; while (dists[ids[i]] < tempDist);
  6432. do j--; while (dists[ids[j]] > tempDist);
  6433. if (j < i) break;
  6434. swap(ids, i, j);
  6435. }
  6436. ids[left + 1] = ids[j];
  6437. ids[j] = temp;
  6438. if (right - i + 1 >= j - left) {
  6439. quicksort(ids, dists, i, right);
  6440. quicksort(ids, dists, left, j - 1);
  6441. } else {
  6442. quicksort(ids, dists, left, j - 1);
  6443. quicksort(ids, dists, i, right);
  6444. }
  6445. }
  6446. }
  6447. function swap(arr, i, j) {
  6448. const tmp = arr[i];
  6449. arr[i] = arr[j];
  6450. arr[j] = tmp;
  6451. }
  6452. function defaultGetX(p) {
  6453. return p[0];
  6454. }
  6455. function defaultGetY(p) {
  6456. return p[1];
  6457. }
  6458. const epsilon$2 = 1e-6;
  6459. class Path {
  6460. constructor() {
  6461. this._x0 = this._y0 = // start of current subpath
  6462. this._x1 = this._y1 = null; // end of current subpath
  6463. this._ = "";
  6464. }
  6465. moveTo(x, y) {
  6466. this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
  6467. }
  6468. closePath() {
  6469. if (this._x1 !== null) {
  6470. this._x1 = this._x0, this._y1 = this._y0;
  6471. this._ += "Z";
  6472. }
  6473. }
  6474. lineTo(x, y) {
  6475. this._ += `L${this._x1 = +x},${this._y1 = +y}`;
  6476. }
  6477. arc(x, y, r) {
  6478. x = +x, y = +y, r = +r;
  6479. const x0 = x + r;
  6480. const y0 = y;
  6481. if (r < 0) throw new Error("negative radius");
  6482. if (this._x1 === null) this._ += `M${x0},${y0}`;
  6483. else if (Math.abs(this._x1 - x0) > epsilon$2 || Math.abs(this._y1 - y0) > epsilon$2) this._ += "L" + x0 + "," + y0;
  6484. if (!r) return;
  6485. this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`;
  6486. }
  6487. rect(x, y, w, h) {
  6488. this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`;
  6489. }
  6490. value() {
  6491. return this._ || null;
  6492. }
  6493. }
  6494. class Polygon {
  6495. constructor() {
  6496. this._ = [];
  6497. }
  6498. moveTo(x, y) {
  6499. this._.push([x, y]);
  6500. }
  6501. closePath() {
  6502. this._.push(this._[0].slice());
  6503. }
  6504. lineTo(x, y) {
  6505. this._.push([x, y]);
  6506. }
  6507. value() {
  6508. return this._.length ? this._ : null;
  6509. }
  6510. }
  6511. class Voronoi {
  6512. constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) {
  6513. if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds");
  6514. this.delaunay = delaunay;
  6515. this._circumcenters = new Float64Array(delaunay.points.length * 2);
  6516. this.vectors = new Float64Array(delaunay.points.length * 2);
  6517. this.xmax = xmax, this.xmin = xmin;
  6518. this.ymax = ymax, this.ymin = ymin;
  6519. this._init();
  6520. }
  6521. update() {
  6522. this.delaunay.update();
  6523. this._init();
  6524. return this;
  6525. }
  6526. _init() {
  6527. const {delaunay: {points, hull, triangles}, vectors} = this;
  6528. let bx, by; // lazily computed barycenter of the hull
  6529. // Compute circumcenters.
  6530. const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2);
  6531. for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
  6532. const t1 = triangles[i] * 2;
  6533. const t2 = triangles[i + 1] * 2;
  6534. const t3 = triangles[i + 2] * 2;
  6535. const x1 = points[t1];
  6536. const y1 = points[t1 + 1];
  6537. const x2 = points[t2];
  6538. const y2 = points[t2 + 1];
  6539. const x3 = points[t3];
  6540. const y3 = points[t3 + 1];
  6541. const dx = x2 - x1;
  6542. const dy = y2 - y1;
  6543. const ex = x3 - x1;
  6544. const ey = y3 - y1;
  6545. const ab = (dx * ey - dy * ex) * 2;
  6546. if (Math.abs(ab) < 1e-9) {
  6547. // For a degenerate triangle, the circumcenter is at the infinity, in a
  6548. // direction orthogonal to the halfedge and away from the “center” of
  6549. // the diagram <bx, by>, defined as the hull’s barycenter.
  6550. if (bx === undefined) {
  6551. bx = by = 0;
  6552. for (const i of hull) bx += points[i * 2], by += points[i * 2 + 1];
  6553. bx /= hull.length, by /= hull.length;
  6554. }
  6555. const a = 1e9 * Math.sign((bx - x1) * ey - (by - y1) * ex);
  6556. x = (x1 + x3) / 2 - a * ey;
  6557. y = (y1 + y3) / 2 + a * ex;
  6558. } else {
  6559. const d = 1 / ab;
  6560. const bl = dx * dx + dy * dy;
  6561. const cl = ex * ex + ey * ey;
  6562. x = x1 + (ey * bl - dy * cl) * d;
  6563. y = y1 + (dx * cl - ex * bl) * d;
  6564. }
  6565. circumcenters[j] = x;
  6566. circumcenters[j + 1] = y;
  6567. }
  6568. // Compute exterior cell rays.
  6569. let h = hull[hull.length - 1];
  6570. let p0, p1 = h * 4;
  6571. let x0, x1 = points[2 * h];
  6572. let y0, y1 = points[2 * h + 1];
  6573. vectors.fill(0);
  6574. for (let i = 0; i < hull.length; ++i) {
  6575. h = hull[i];
  6576. p0 = p1, x0 = x1, y0 = y1;
  6577. p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1];
  6578. vectors[p0 + 2] = vectors[p1] = y0 - y1;
  6579. vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
  6580. }
  6581. }
  6582. render(context) {
  6583. const buffer = context == null ? context = new Path : undefined;
  6584. const {delaunay: {halfedges, inedges, hull}, circumcenters, vectors} = this;
  6585. if (hull.length <= 1) return null;
  6586. for (let i = 0, n = halfedges.length; i < n; ++i) {
  6587. const j = halfedges[i];
  6588. if (j < i) continue;
  6589. const ti = Math.floor(i / 3) * 2;
  6590. const tj = Math.floor(j / 3) * 2;
  6591. const xi = circumcenters[ti];
  6592. const yi = circumcenters[ti + 1];
  6593. const xj = circumcenters[tj];
  6594. const yj = circumcenters[tj + 1];
  6595. this._renderSegment(xi, yi, xj, yj, context);
  6596. }
  6597. let h0, h1 = hull[hull.length - 1];
  6598. for (let i = 0; i < hull.length; ++i) {
  6599. h0 = h1, h1 = hull[i];
  6600. const t = Math.floor(inedges[h1] / 3) * 2;
  6601. const x = circumcenters[t];
  6602. const y = circumcenters[t + 1];
  6603. const v = h0 * 4;
  6604. const p = this._project(x, y, vectors[v + 2], vectors[v + 3]);
  6605. if (p) this._renderSegment(x, y, p[0], p[1], context);
  6606. }
  6607. return buffer && buffer.value();
  6608. }
  6609. renderBounds(context) {
  6610. const buffer = context == null ? context = new Path : undefined;
  6611. context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin);
  6612. return buffer && buffer.value();
  6613. }
  6614. renderCell(i, context) {
  6615. const buffer = context == null ? context = new Path : undefined;
  6616. const points = this._clip(i);
  6617. if (points === null || !points.length) return;
  6618. context.moveTo(points[0], points[1]);
  6619. let n = points.length;
  6620. while (points[0] === points[n-2] && points[1] === points[n-1] && n > 1) n -= 2;
  6621. for (let i = 2; i < n; i += 2) {
  6622. if (points[i] !== points[i-2] || points[i+1] !== points[i-1])
  6623. context.lineTo(points[i], points[i + 1]);
  6624. }
  6625. context.closePath();
  6626. return buffer && buffer.value();
  6627. }
  6628. *cellPolygons() {
  6629. const {delaunay: {points}} = this;
  6630. for (let i = 0, n = points.length / 2; i < n; ++i) {
  6631. const cell = this.cellPolygon(i);
  6632. if (cell) cell.index = i, yield cell;
  6633. }
  6634. }
  6635. cellPolygon(i) {
  6636. const polygon = new Polygon;
  6637. this.renderCell(i, polygon);
  6638. return polygon.value();
  6639. }
  6640. _renderSegment(x0, y0, x1, y1, context) {
  6641. let S;
  6642. const c0 = this._regioncode(x0, y0);
  6643. const c1 = this._regioncode(x1, y1);
  6644. if (c0 === 0 && c1 === 0) {
  6645. context.moveTo(x0, y0);
  6646. context.lineTo(x1, y1);
  6647. } else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) {
  6648. context.moveTo(S[0], S[1]);
  6649. context.lineTo(S[2], S[3]);
  6650. }
  6651. }
  6652. contains(i, x, y) {
  6653. if ((x = +x, x !== x) || (y = +y, y !== y)) return false;
  6654. return this.delaunay._step(i, x, y) === i;
  6655. }
  6656. *neighbors(i) {
  6657. const ci = this._clip(i);
  6658. if (ci) for (const j of this.delaunay.neighbors(i)) {
  6659. const cj = this._clip(j);
  6660. // find the common edge
  6661. if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) {
  6662. for (let aj = 0, lj = cj.length; aj < lj; aj += 2) {
  6663. if (ci[ai] === cj[aj]
  6664. && ci[ai + 1] === cj[aj + 1]
  6665. && ci[(ai + 2) % li] === cj[(aj + lj - 2) % lj]
  6666. && ci[(ai + 3) % li] === cj[(aj + lj - 1) % lj]) {
  6667. yield j;
  6668. break loop;
  6669. }
  6670. }
  6671. }
  6672. }
  6673. }
  6674. _cell(i) {
  6675. const {circumcenters, delaunay: {inedges, halfedges, triangles}} = this;
  6676. const e0 = inedges[i];
  6677. if (e0 === -1) return null; // coincident point
  6678. const points = [];
  6679. let e = e0;
  6680. do {
  6681. const t = Math.floor(e / 3);
  6682. points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]);
  6683. e = e % 3 === 2 ? e - 2 : e + 1;
  6684. if (triangles[e] !== i) break; // bad triangulation
  6685. e = halfedges[e];
  6686. } while (e !== e0 && e !== -1);
  6687. return points;
  6688. }
  6689. _clip(i) {
  6690. // degenerate case (1 valid point: return the box)
  6691. if (i === 0 && this.delaunay.hull.length === 1) {
  6692. return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
  6693. }
  6694. const points = this._cell(i);
  6695. if (points === null) return null;
  6696. const {vectors: V} = this;
  6697. const v = i * 4;
  6698. return this._simplify(V[v] || V[v + 1]
  6699. ? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3])
  6700. : this._clipFinite(i, points));
  6701. }
  6702. _clipFinite(i, points) {
  6703. const n = points.length;
  6704. let P = null;
  6705. let x0, y0, x1 = points[n - 2], y1 = points[n - 1];
  6706. let c0, c1 = this._regioncode(x1, y1);
  6707. let e0, e1 = 0;
  6708. for (let j = 0; j < n; j += 2) {
  6709. x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1];
  6710. c0 = c1, c1 = this._regioncode(x1, y1);
  6711. if (c0 === 0 && c1 === 0) {
  6712. e0 = e1, e1 = 0;
  6713. if (P) P.push(x1, y1);
  6714. else P = [x1, y1];
  6715. } else {
  6716. let S, sx0, sy0, sx1, sy1;
  6717. if (c0 === 0) {
  6718. if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue;
  6719. [sx0, sy0, sx1, sy1] = S;
  6720. } else {
  6721. if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue;
  6722. [sx1, sy1, sx0, sy0] = S;
  6723. e0 = e1, e1 = this._edgecode(sx0, sy0);
  6724. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6725. if (P) P.push(sx0, sy0);
  6726. else P = [sx0, sy0];
  6727. }
  6728. e0 = e1, e1 = this._edgecode(sx1, sy1);
  6729. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6730. if (P) P.push(sx1, sy1);
  6731. else P = [sx1, sy1];
  6732. }
  6733. }
  6734. if (P) {
  6735. e0 = e1, e1 = this._edgecode(P[0], P[1]);
  6736. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6737. } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
  6738. return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
  6739. }
  6740. return P;
  6741. }
  6742. _clipSegment(x0, y0, x1, y1, c0, c1) {
  6743. // for more robustness, always consider the segment in the same order
  6744. const flip = c0 < c1;
  6745. if (flip) [x0, y0, x1, y1, c0, c1] = [x1, y1, x0, y0, c1, c0];
  6746. while (true) {
  6747. if (c0 === 0 && c1 === 0) return flip ? [x1, y1, x0, y0] : [x0, y0, x1, y1];
  6748. if (c0 & c1) return null;
  6749. let x, y, c = c0 || c1;
  6750. if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax;
  6751. else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin;
  6752. else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax;
  6753. else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin;
  6754. if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0);
  6755. else x1 = x, y1 = y, c1 = this._regioncode(x1, y1);
  6756. }
  6757. }
  6758. _clipInfinite(i, points, vx0, vy0, vxn, vyn) {
  6759. let P = Array.from(points), p;
  6760. if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]);
  6761. if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]);
  6762. if (P = this._clipFinite(i, P)) {
  6763. for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) {
  6764. c0 = c1, c1 = this._edgecode(P[j], P[j + 1]);
  6765. if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length;
  6766. }
  6767. } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
  6768. P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax];
  6769. }
  6770. return P;
  6771. }
  6772. _edge(i, e0, e1, P, j) {
  6773. while (e0 !== e1) {
  6774. let x, y;
  6775. switch (e0) {
  6776. case 0b0101: e0 = 0b0100; continue; // top-left
  6777. case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break; // top
  6778. case 0b0110: e0 = 0b0010; continue; // top-right
  6779. case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break; // right
  6780. case 0b1010: e0 = 0b1000; continue; // bottom-right
  6781. case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break; // bottom
  6782. case 0b1001: e0 = 0b0001; continue; // bottom-left
  6783. case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break; // left
  6784. }
  6785. // Note: this implicitly checks for out of bounds: if P[j] or P[j+1] are
  6786. // undefined, the conditional statement will be executed.
  6787. if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) {
  6788. P.splice(j, 0, x, y), j += 2;
  6789. }
  6790. }
  6791. return j;
  6792. }
  6793. _project(x0, y0, vx, vy) {
  6794. let t = Infinity, c, x, y;
  6795. if (vy < 0) { // top
  6796. if (y0 <= this.ymin) return null;
  6797. if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx;
  6798. } else if (vy > 0) { // bottom
  6799. if (y0 >= this.ymax) return null;
  6800. if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx;
  6801. }
  6802. if (vx > 0) { // right
  6803. if (x0 >= this.xmax) return null;
  6804. if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy;
  6805. } else if (vx < 0) { // left
  6806. if (x0 <= this.xmin) return null;
  6807. if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy;
  6808. }
  6809. return [x, y];
  6810. }
  6811. _edgecode(x, y) {
  6812. return (x === this.xmin ? 0b0001
  6813. : x === this.xmax ? 0b0010 : 0b0000)
  6814. | (y === this.ymin ? 0b0100
  6815. : y === this.ymax ? 0b1000 : 0b0000);
  6816. }
  6817. _regioncode(x, y) {
  6818. return (x < this.xmin ? 0b0001
  6819. : x > this.xmax ? 0b0010 : 0b0000)
  6820. | (y < this.ymin ? 0b0100
  6821. : y > this.ymax ? 0b1000 : 0b0000);
  6822. }
  6823. _simplify(P) {
  6824. if (P && P.length > 4) {
  6825. for (let i = 0; i < P.length; i+= 2) {
  6826. const j = (i + 2) % P.length, k = (i + 4) % P.length;
  6827. if (P[i] === P[j] && P[j] === P[k] || P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1]) {
  6828. P.splice(j, 2), i -= 2;
  6829. }
  6830. }
  6831. if (!P.length) P = null;
  6832. }
  6833. return P;
  6834. }
  6835. }
  6836. const tau$2 = 2 * Math.PI, pow$2 = Math.pow;
  6837. function pointX(p) {
  6838. return p[0];
  6839. }
  6840. function pointY(p) {
  6841. return p[1];
  6842. }
  6843. // A triangulation is collinear if all its triangles have a non-null area
  6844. function collinear(d) {
  6845. const {triangles, coords} = d;
  6846. for (let i = 0; i < triangles.length; i += 3) {
  6847. const a = 2 * triangles[i],
  6848. b = 2 * triangles[i + 1],
  6849. c = 2 * triangles[i + 2],
  6850. cross = (coords[c] - coords[a]) * (coords[b + 1] - coords[a + 1])
  6851. - (coords[b] - coords[a]) * (coords[c + 1] - coords[a + 1]);
  6852. if (cross > 1e-10) return false;
  6853. }
  6854. return true;
  6855. }
  6856. function jitter(x, y, r) {
  6857. return [x + Math.sin(x + y) * r, y + Math.cos(x - y) * r];
  6858. }
  6859. class Delaunay {
  6860. static from(points, fx = pointX, fy = pointY, that) {
  6861. return new Delaunay("length" in points
  6862. ? flatArray(points, fx, fy, that)
  6863. : Float64Array.from(flatIterable(points, fx, fy, that)));
  6864. }
  6865. constructor(points) {
  6866. this._delaunator = new Delaunator(points);
  6867. this.inedges = new Int32Array(points.length / 2);
  6868. this._hullIndex = new Int32Array(points.length / 2);
  6869. this.points = this._delaunator.coords;
  6870. this._init();
  6871. }
  6872. update() {
  6873. this._delaunator.update();
  6874. this._init();
  6875. return this;
  6876. }
  6877. _init() {
  6878. const d = this._delaunator, points = this.points;
  6879. // check for collinear
  6880. if (d.hull && d.hull.length > 2 && collinear(d)) {
  6881. this.collinear = Int32Array.from({length: points.length/2}, (_,i) => i)
  6882. .sort((i, j) => points[2 * i] - points[2 * j] || points[2 * i + 1] - points[2 * j + 1]); // for exact neighbors
  6883. const e = this.collinear[0], f = this.collinear[this.collinear.length - 1],
  6884. bounds = [ points[2 * e], points[2 * e + 1], points[2 * f], points[2 * f + 1] ],
  6885. r = 1e-8 * Math.hypot(bounds[3] - bounds[1], bounds[2] - bounds[0]);
  6886. for (let i = 0, n = points.length / 2; i < n; ++i) {
  6887. const p = jitter(points[2 * i], points[2 * i + 1], r);
  6888. points[2 * i] = p[0];
  6889. points[2 * i + 1] = p[1];
  6890. }
  6891. this._delaunator = new Delaunator(points);
  6892. } else {
  6893. delete this.collinear;
  6894. }
  6895. const halfedges = this.halfedges = this._delaunator.halfedges;
  6896. const hull = this.hull = this._delaunator.hull;
  6897. const triangles = this.triangles = this._delaunator.triangles;
  6898. const inedges = this.inedges.fill(-1);
  6899. const hullIndex = this._hullIndex.fill(-1);
  6900. // Compute an index from each point to an (arbitrary) incoming halfedge
  6901. // Used to give the first neighbor of each point; for this reason,
  6902. // on the hull we give priority to exterior halfedges
  6903. for (let e = 0, n = halfedges.length; e < n; ++e) {
  6904. const p = triangles[e % 3 === 2 ? e - 2 : e + 1];
  6905. if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e;
  6906. }
  6907. for (let i = 0, n = hull.length; i < n; ++i) {
  6908. hullIndex[hull[i]] = i;
  6909. }
  6910. // degenerate case: 1 or 2 (distinct) points
  6911. if (hull.length <= 2 && hull.length > 0) {
  6912. this.triangles = new Int32Array(3).fill(-1);
  6913. this.halfedges = new Int32Array(3).fill(-1);
  6914. this.triangles[0] = hull[0];
  6915. inedges[hull[0]] = 1;
  6916. if (hull.length === 2) {
  6917. inedges[hull[1]] = 0;
  6918. this.triangles[1] = hull[1];
  6919. this.triangles[2] = hull[1];
  6920. }
  6921. }
  6922. }
  6923. voronoi(bounds) {
  6924. return new Voronoi(this, bounds);
  6925. }
  6926. *neighbors(i) {
  6927. const {inedges, hull, _hullIndex, halfedges, triangles, collinear} = this;
  6928. // degenerate case with several collinear points
  6929. if (collinear) {
  6930. const l = collinear.indexOf(i);
  6931. if (l > 0) yield collinear[l - 1];
  6932. if (l < collinear.length - 1) yield collinear[l + 1];
  6933. return;
  6934. }
  6935. const e0 = inedges[i];
  6936. if (e0 === -1) return; // coincident point
  6937. let e = e0, p0 = -1;
  6938. do {
  6939. yield p0 = triangles[e];
  6940. e = e % 3 === 2 ? e - 2 : e + 1;
  6941. if (triangles[e] !== i) return; // bad triangulation
  6942. e = halfedges[e];
  6943. if (e === -1) {
  6944. const p = hull[(_hullIndex[i] + 1) % hull.length];
  6945. if (p !== p0) yield p;
  6946. return;
  6947. }
  6948. } while (e !== e0);
  6949. }
  6950. find(x, y, i = 0) {
  6951. if ((x = +x, x !== x) || (y = +y, y !== y)) return -1;
  6952. const i0 = i;
  6953. let c;
  6954. while ((c = this._step(i, x, y)) >= 0 && c !== i && c !== i0) i = c;
  6955. return c;
  6956. }
  6957. _step(i, x, y) {
  6958. const {inedges, hull, _hullIndex, halfedges, triangles, points} = this;
  6959. if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1);
  6960. let c = i;
  6961. let dc = pow$2(x - points[i * 2], 2) + pow$2(y - points[i * 2 + 1], 2);
  6962. const e0 = inedges[i];
  6963. let e = e0;
  6964. do {
  6965. let t = triangles[e];
  6966. const dt = pow$2(x - points[t * 2], 2) + pow$2(y - points[t * 2 + 1], 2);
  6967. if (dt < dc) dc = dt, c = t;
  6968. e = e % 3 === 2 ? e - 2 : e + 1;
  6969. if (triangles[e] !== i) break; // bad triangulation
  6970. e = halfedges[e];
  6971. if (e === -1) {
  6972. e = hull[(_hullIndex[i] + 1) % hull.length];
  6973. if (e !== t) {
  6974. if (pow$2(x - points[e * 2], 2) + pow$2(y - points[e * 2 + 1], 2) < dc) return e;
  6975. }
  6976. break;
  6977. }
  6978. } while (e !== e0);
  6979. return c;
  6980. }
  6981. render(context) {
  6982. const buffer = context == null ? context = new Path : undefined;
  6983. const {points, halfedges, triangles} = this;
  6984. for (let i = 0, n = halfedges.length; i < n; ++i) {
  6985. const j = halfedges[i];
  6986. if (j < i) continue;
  6987. const ti = triangles[i] * 2;
  6988. const tj = triangles[j] * 2;
  6989. context.moveTo(points[ti], points[ti + 1]);
  6990. context.lineTo(points[tj], points[tj + 1]);
  6991. }
  6992. this.renderHull(context);
  6993. return buffer && buffer.value();
  6994. }
  6995. renderPoints(context, r) {
  6996. if (r === undefined && (!context || typeof context.moveTo !== "function")) r = context, context = null;
  6997. r = r == undefined ? 2 : +r;
  6998. const buffer = context == null ? context = new Path : undefined;
  6999. const {points} = this;
  7000. for (let i = 0, n = points.length; i < n; i += 2) {
  7001. const x = points[i], y = points[i + 1];
  7002. context.moveTo(x + r, y);
  7003. context.arc(x, y, r, 0, tau$2);
  7004. }
  7005. return buffer && buffer.value();
  7006. }
  7007. renderHull(context) {
  7008. const buffer = context == null ? context = new Path : undefined;
  7009. const {hull, points} = this;
  7010. const h = hull[0] * 2, n = hull.length;
  7011. context.moveTo(points[h], points[h + 1]);
  7012. for (let i = 1; i < n; ++i) {
  7013. const h = 2 * hull[i];
  7014. context.lineTo(points[h], points[h + 1]);
  7015. }
  7016. context.closePath();
  7017. return buffer && buffer.value();
  7018. }
  7019. hullPolygon() {
  7020. const polygon = new Polygon;
  7021. this.renderHull(polygon);
  7022. return polygon.value();
  7023. }
  7024. renderTriangle(i, context) {
  7025. const buffer = context == null ? context = new Path : undefined;
  7026. const {points, triangles} = this;
  7027. const t0 = triangles[i *= 3] * 2;
  7028. const t1 = triangles[i + 1] * 2;
  7029. const t2 = triangles[i + 2] * 2;
  7030. context.moveTo(points[t0], points[t0 + 1]);
  7031. context.lineTo(points[t1], points[t1 + 1]);
  7032. context.lineTo(points[t2], points[t2 + 1]);
  7033. context.closePath();
  7034. return buffer && buffer.value();
  7035. }
  7036. *trianglePolygons() {
  7037. const {triangles} = this;
  7038. for (let i = 0, n = triangles.length / 3; i < n; ++i) {
  7039. yield this.trianglePolygon(i);
  7040. }
  7041. }
  7042. trianglePolygon(i) {
  7043. const polygon = new Polygon;
  7044. this.renderTriangle(i, polygon);
  7045. return polygon.value();
  7046. }
  7047. }
  7048. function flatArray(points, fx, fy, that) {
  7049. const n = points.length;
  7050. const array = new Float64Array(n * 2);
  7051. for (let i = 0; i < n; ++i) {
  7052. const p = points[i];
  7053. array[i * 2] = fx.call(that, p, i, points);
  7054. array[i * 2 + 1] = fy.call(that, p, i, points);
  7055. }
  7056. return array;
  7057. }
  7058. function* flatIterable(points, fx, fy, that) {
  7059. let i = 0;
  7060. for (const p of points) {
  7061. yield fx.call(that, p, i, points);
  7062. yield fy.call(that, p, i, points);
  7063. ++i;
  7064. }
  7065. }
  7066. var EOL = {},
  7067. EOF = {},
  7068. QUOTE = 34,
  7069. NEWLINE = 10,
  7070. RETURN = 13;
  7071. function objectConverter(columns) {
  7072. return new Function("d", "return {" + columns.map(function(name, i) {
  7073. return JSON.stringify(name) + ": d[" + i + "] || \"\"";
  7074. }).join(",") + "}");
  7075. }
  7076. function customConverter(columns, f) {
  7077. var object = objectConverter(columns);
  7078. return function(row, i) {
  7079. return f(object(row), i, columns);
  7080. };
  7081. }
  7082. // Compute unique columns in order of discovery.
  7083. function inferColumns(rows) {
  7084. var columnSet = Object.create(null),
  7085. columns = [];
  7086. rows.forEach(function(row) {
  7087. for (var column in row) {
  7088. if (!(column in columnSet)) {
  7089. columns.push(columnSet[column] = column);
  7090. }
  7091. }
  7092. });
  7093. return columns;
  7094. }
  7095. function pad$1(value, width) {
  7096. var s = value + "", length = s.length;
  7097. return length < width ? new Array(width - length + 1).join(0) + s : s;
  7098. }
  7099. function formatYear$1(year) {
  7100. return year < 0 ? "-" + pad$1(-year, 6)
  7101. : year > 9999 ? "+" + pad$1(year, 6)
  7102. : pad$1(year, 4);
  7103. }
  7104. function formatDate(date) {
  7105. var hours = date.getUTCHours(),
  7106. minutes = date.getUTCMinutes(),
  7107. seconds = date.getUTCSeconds(),
  7108. milliseconds = date.getUTCMilliseconds();
  7109. return isNaN(date) ? "Invalid Date"
  7110. : formatYear$1(date.getUTCFullYear()) + "-" + pad$1(date.getUTCMonth() + 1, 2) + "-" + pad$1(date.getUTCDate(), 2)
  7111. + (milliseconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "." + pad$1(milliseconds, 3) + "Z"
  7112. : seconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "Z"
  7113. : minutes || hours ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + "Z"
  7114. : "");
  7115. }
  7116. function dsvFormat(delimiter) {
  7117. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  7118. DELIMITER = delimiter.charCodeAt(0);
  7119. function parse(text, f) {
  7120. var convert, columns, rows = parseRows(text, function(row, i) {
  7121. if (convert) return convert(row, i - 1);
  7122. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  7123. });
  7124. rows.columns = columns || [];
  7125. return rows;
  7126. }
  7127. function parseRows(text, f) {
  7128. var rows = [], // output rows
  7129. N = text.length,
  7130. I = 0, // current character index
  7131. n = 0, // current line number
  7132. t, // current token
  7133. eof = N <= 0, // current token followed by EOF?
  7134. eol = false; // current token followed by EOL?
  7135. // Strip the trailing newline.
  7136. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  7137. if (text.charCodeAt(N - 1) === RETURN) --N;
  7138. function token() {
  7139. if (eof) return EOF;
  7140. if (eol) return eol = false, EOL;
  7141. // Unescape quotes.
  7142. var i, j = I, c;
  7143. if (text.charCodeAt(j) === QUOTE) {
  7144. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  7145. if ((i = I) >= N) eof = true;
  7146. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  7147. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  7148. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  7149. }
  7150. // Find next delimiter or newline.
  7151. while (I < N) {
  7152. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  7153. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  7154. else if (c !== DELIMITER) continue;
  7155. return text.slice(j, i);
  7156. }
  7157. // Return last token before EOF.
  7158. return eof = true, text.slice(j, N);
  7159. }
  7160. while ((t = token()) !== EOF) {
  7161. var row = [];
  7162. while (t !== EOL && t !== EOF) row.push(t), t = token();
  7163. if (f && (row = f(row, n++)) == null) continue;
  7164. rows.push(row);
  7165. }
  7166. return rows;
  7167. }
  7168. function preformatBody(rows, columns) {
  7169. return rows.map(function(row) {
  7170. return columns.map(function(column) {
  7171. return formatValue(row[column]);
  7172. }).join(delimiter);
  7173. });
  7174. }
  7175. function format(rows, columns) {
  7176. if (columns == null) columns = inferColumns(rows);
  7177. return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
  7178. }
  7179. function formatBody(rows, columns) {
  7180. if (columns == null) columns = inferColumns(rows);
  7181. return preformatBody(rows, columns).join("\n");
  7182. }
  7183. function formatRows(rows) {
  7184. return rows.map(formatRow).join("\n");
  7185. }
  7186. function formatRow(row) {
  7187. return row.map(formatValue).join(delimiter);
  7188. }
  7189. function formatValue(value) {
  7190. return value == null ? ""
  7191. : value instanceof Date ? formatDate(value)
  7192. : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
  7193. : value;
  7194. }
  7195. return {
  7196. parse: parse,
  7197. parseRows: parseRows,
  7198. format: format,
  7199. formatBody: formatBody,
  7200. formatRows: formatRows,
  7201. formatRow: formatRow,
  7202. formatValue: formatValue
  7203. };
  7204. }
  7205. var csv$1 = dsvFormat(",");
  7206. var csvParse = csv$1.parse;
  7207. var csvParseRows = csv$1.parseRows;
  7208. var csvFormat = csv$1.format;
  7209. var csvFormatBody = csv$1.formatBody;
  7210. var csvFormatRows = csv$1.formatRows;
  7211. var csvFormatRow = csv$1.formatRow;
  7212. var csvFormatValue = csv$1.formatValue;
  7213. var tsv$1 = dsvFormat("\t");
  7214. var tsvParse = tsv$1.parse;
  7215. var tsvParseRows = tsv$1.parseRows;
  7216. var tsvFormat = tsv$1.format;
  7217. var tsvFormatBody = tsv$1.formatBody;
  7218. var tsvFormatRows = tsv$1.formatRows;
  7219. var tsvFormatRow = tsv$1.formatRow;
  7220. var tsvFormatValue = tsv$1.formatValue;
  7221. function autoType(object) {
  7222. for (var key in object) {
  7223. var value = object[key].trim(), number, m;
  7224. if (!value) value = null;
  7225. else if (value === "true") value = true;
  7226. else if (value === "false") value = false;
  7227. else if (value === "NaN") value = NaN;
  7228. else if (!isNaN(number = +value)) value = number;
  7229. else if (m = value.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)) {
  7230. if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
  7231. value = new Date(value);
  7232. }
  7233. else continue;
  7234. object[key] = value;
  7235. }
  7236. return object;
  7237. }
  7238. // https://github.com/d3/d3-dsv/issues/45
  7239. const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
  7240. function responseBlob(response) {
  7241. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7242. return response.blob();
  7243. }
  7244. function blob(input, init) {
  7245. return fetch(input, init).then(responseBlob);
  7246. }
  7247. function responseArrayBuffer(response) {
  7248. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7249. return response.arrayBuffer();
  7250. }
  7251. function buffer(input, init) {
  7252. return fetch(input, init).then(responseArrayBuffer);
  7253. }
  7254. function responseText(response) {
  7255. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7256. return response.text();
  7257. }
  7258. function text(input, init) {
  7259. return fetch(input, init).then(responseText);
  7260. }
  7261. function dsvParse(parse) {
  7262. return function(input, init, row) {
  7263. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  7264. return text(input, init).then(function(response) {
  7265. return parse(response, row);
  7266. });
  7267. };
  7268. }
  7269. function dsv(delimiter, input, init, row) {
  7270. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  7271. var format = dsvFormat(delimiter);
  7272. return text(input, init).then(function(response) {
  7273. return format.parse(response, row);
  7274. });
  7275. }
  7276. var csv = dsvParse(csvParse);
  7277. var tsv = dsvParse(tsvParse);
  7278. function image(input, init) {
  7279. return new Promise(function(resolve, reject) {
  7280. var image = new Image;
  7281. for (var key in init) image[key] = init[key];
  7282. image.onerror = reject;
  7283. image.onload = function() { resolve(image); };
  7284. image.src = input;
  7285. });
  7286. }
  7287. function responseJson(response) {
  7288. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7289. if (response.status === 204 || response.status === 205) return;
  7290. return response.json();
  7291. }
  7292. function json(input, init) {
  7293. return fetch(input, init).then(responseJson);
  7294. }
  7295. function parser(type) {
  7296. return (input, init) => text(input, init)
  7297. .then(text => (new DOMParser).parseFromString(text, type));
  7298. }
  7299. var xml = parser("application/xml");
  7300. var html = parser("text/html");
  7301. var svg = parser("image/svg+xml");
  7302. function center(x, y) {
  7303. var nodes, strength = 1;
  7304. if (x == null) x = 0;
  7305. if (y == null) y = 0;
  7306. function force() {
  7307. var i,
  7308. n = nodes.length,
  7309. node,
  7310. sx = 0,
  7311. sy = 0;
  7312. for (i = 0; i < n; ++i) {
  7313. node = nodes[i], sx += node.x, sy += node.y;
  7314. }
  7315. for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
  7316. node = nodes[i], node.x -= sx, node.y -= sy;
  7317. }
  7318. }
  7319. force.initialize = function(_) {
  7320. nodes = _;
  7321. };
  7322. force.x = function(_) {
  7323. return arguments.length ? (x = +_, force) : x;
  7324. };
  7325. force.y = function(_) {
  7326. return arguments.length ? (y = +_, force) : y;
  7327. };
  7328. force.strength = function(_) {
  7329. return arguments.length ? (strength = +_, force) : strength;
  7330. };
  7331. return force;
  7332. }
  7333. function tree_add(d) {
  7334. const x = +this._x.call(null, d),
  7335. y = +this._y.call(null, d);
  7336. return add(this.cover(x, y), x, y, d);
  7337. }
  7338. function add(tree, x, y, d) {
  7339. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  7340. var parent,
  7341. node = tree._root,
  7342. leaf = {data: d},
  7343. x0 = tree._x0,
  7344. y0 = tree._y0,
  7345. x1 = tree._x1,
  7346. y1 = tree._y1,
  7347. xm,
  7348. ym,
  7349. xp,
  7350. yp,
  7351. right,
  7352. bottom,
  7353. i,
  7354. j;
  7355. // If the tree is empty, initialize the root as a leaf.
  7356. if (!node) return tree._root = leaf, tree;
  7357. // Find the existing leaf for the new point, or add it.
  7358. while (node.length) {
  7359. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  7360. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  7361. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  7362. }
  7363. // Is the new point is exactly coincident with the existing point?
  7364. xp = +tree._x.call(null, node.data);
  7365. yp = +tree._y.call(null, node.data);
  7366. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  7367. // Otherwise, split the leaf node until the old and new point are separated.
  7368. do {
  7369. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  7370. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  7371. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  7372. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  7373. return parent[j] = node, parent[i] = leaf, tree;
  7374. }
  7375. function addAll(data) {
  7376. var d, i, n = data.length,
  7377. x,
  7378. y,
  7379. xz = new Array(n),
  7380. yz = new Array(n),
  7381. x0 = Infinity,
  7382. y0 = Infinity,
  7383. x1 = -Infinity,
  7384. y1 = -Infinity;
  7385. // Compute the points and their extent.
  7386. for (i = 0; i < n; ++i) {
  7387. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  7388. xz[i] = x;
  7389. yz[i] = y;
  7390. if (x < x0) x0 = x;
  7391. if (x > x1) x1 = x;
  7392. if (y < y0) y0 = y;
  7393. if (y > y1) y1 = y;
  7394. }
  7395. // If there were no (valid) points, abort.
  7396. if (x0 > x1 || y0 > y1) return this;
  7397. // Expand the tree to cover the new points.
  7398. this.cover(x0, y0).cover(x1, y1);
  7399. // Add the new points.
  7400. for (i = 0; i < n; ++i) {
  7401. add(this, xz[i], yz[i], data[i]);
  7402. }
  7403. return this;
  7404. }
  7405. function tree_cover(x, y) {
  7406. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  7407. var x0 = this._x0,
  7408. y0 = this._y0,
  7409. x1 = this._x1,
  7410. y1 = this._y1;
  7411. // If the quadtree has no extent, initialize them.
  7412. // Integer extent are necessary so that if we later double the extent,
  7413. // the existing quadrant boundaries don’t change due to floating point error!
  7414. if (isNaN(x0)) {
  7415. x1 = (x0 = Math.floor(x)) + 1;
  7416. y1 = (y0 = Math.floor(y)) + 1;
  7417. }
  7418. // Otherwise, double repeatedly to cover.
  7419. else {
  7420. var z = x1 - x0 || 1,
  7421. node = this._root,
  7422. parent,
  7423. i;
  7424. while (x0 > x || x >= x1 || y0 > y || y >= y1) {
  7425. i = (y < y0) << 1 | (x < x0);
  7426. parent = new Array(4), parent[i] = node, node = parent, z *= 2;
  7427. switch (i) {
  7428. case 0: x1 = x0 + z, y1 = y0 + z; break;
  7429. case 1: x0 = x1 - z, y1 = y0 + z; break;
  7430. case 2: x1 = x0 + z, y0 = y1 - z; break;
  7431. case 3: x0 = x1 - z, y0 = y1 - z; break;
  7432. }
  7433. }
  7434. if (this._root && this._root.length) this._root = node;
  7435. }
  7436. this._x0 = x0;
  7437. this._y0 = y0;
  7438. this._x1 = x1;
  7439. this._y1 = y1;
  7440. return this;
  7441. }
  7442. function tree_data() {
  7443. var data = [];
  7444. this.visit(function(node) {
  7445. if (!node.length) do data.push(node.data); while (node = node.next)
  7446. });
  7447. return data;
  7448. }
  7449. function tree_extent(_) {
  7450. return arguments.length
  7451. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  7452. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  7453. }
  7454. function Quad(node, x0, y0, x1, y1) {
  7455. this.node = node;
  7456. this.x0 = x0;
  7457. this.y0 = y0;
  7458. this.x1 = x1;
  7459. this.y1 = y1;
  7460. }
  7461. function tree_find(x, y, radius) {
  7462. var data,
  7463. x0 = this._x0,
  7464. y0 = this._y0,
  7465. x1,
  7466. y1,
  7467. x2,
  7468. y2,
  7469. x3 = this._x1,
  7470. y3 = this._y1,
  7471. quads = [],
  7472. node = this._root,
  7473. q,
  7474. i;
  7475. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  7476. if (radius == null) radius = Infinity;
  7477. else {
  7478. x0 = x - radius, y0 = y - radius;
  7479. x3 = x + radius, y3 = y + radius;
  7480. radius *= radius;
  7481. }
  7482. while (q = quads.pop()) {
  7483. // Stop searching if this quadrant can’t contain a closer node.
  7484. if (!(node = q.node)
  7485. || (x1 = q.x0) > x3
  7486. || (y1 = q.y0) > y3
  7487. || (x2 = q.x1) < x0
  7488. || (y2 = q.y1) < y0) continue;
  7489. // Bisect the current quadrant.
  7490. if (node.length) {
  7491. var xm = (x1 + x2) / 2,
  7492. ym = (y1 + y2) / 2;
  7493. quads.push(
  7494. new Quad(node[3], xm, ym, x2, y2),
  7495. new Quad(node[2], x1, ym, xm, y2),
  7496. new Quad(node[1], xm, y1, x2, ym),
  7497. new Quad(node[0], x1, y1, xm, ym)
  7498. );
  7499. // Visit the closest quadrant first.
  7500. if (i = (y >= ym) << 1 | (x >= xm)) {
  7501. q = quads[quads.length - 1];
  7502. quads[quads.length - 1] = quads[quads.length - 1 - i];
  7503. quads[quads.length - 1 - i] = q;
  7504. }
  7505. }
  7506. // Visit this point. (Visiting coincident points isn’t necessary!)
  7507. else {
  7508. var dx = x - +this._x.call(null, node.data),
  7509. dy = y - +this._y.call(null, node.data),
  7510. d2 = dx * dx + dy * dy;
  7511. if (d2 < radius) {
  7512. var d = Math.sqrt(radius = d2);
  7513. x0 = x - d, y0 = y - d;
  7514. x3 = x + d, y3 = y + d;
  7515. data = node.data;
  7516. }
  7517. }
  7518. }
  7519. return data;
  7520. }
  7521. function tree_remove(d) {
  7522. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  7523. var parent,
  7524. node = this._root,
  7525. retainer,
  7526. previous,
  7527. next,
  7528. x0 = this._x0,
  7529. y0 = this._y0,
  7530. x1 = this._x1,
  7531. y1 = this._y1,
  7532. x,
  7533. y,
  7534. xm,
  7535. ym,
  7536. right,
  7537. bottom,
  7538. i,
  7539. j;
  7540. // If the tree is empty, initialize the root as a leaf.
  7541. if (!node) return this;
  7542. // Find the leaf node for the point.
  7543. // While descending, also retain the deepest parent with a non-removed sibling.
  7544. if (node.length) while (true) {
  7545. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  7546. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  7547. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  7548. if (!node.length) break;
  7549. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  7550. }
  7551. // Find the point to remove.
  7552. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  7553. if (next = node.next) delete node.next;
  7554. // If there are multiple coincident points, remove just the point.
  7555. if (previous) return (next ? previous.next = next : delete previous.next), this;
  7556. // If this is the root point, remove it.
  7557. if (!parent) return this._root = next, this;
  7558. // Remove this leaf.
  7559. next ? parent[i] = next : delete parent[i];
  7560. // If the parent now contains exactly one leaf, collapse superfluous parents.
  7561. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  7562. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  7563. && !node.length) {
  7564. if (retainer) retainer[j] = node;
  7565. else this._root = node;
  7566. }
  7567. return this;
  7568. }
  7569. function removeAll(data) {
  7570. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  7571. return this;
  7572. }
  7573. function tree_root() {
  7574. return this._root;
  7575. }
  7576. function tree_size() {
  7577. var size = 0;
  7578. this.visit(function(node) {
  7579. if (!node.length) do ++size; while (node = node.next)
  7580. });
  7581. return size;
  7582. }
  7583. function tree_visit(callback) {
  7584. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  7585. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  7586. while (q = quads.pop()) {
  7587. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  7588. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  7589. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  7590. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  7591. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  7592. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  7593. }
  7594. }
  7595. return this;
  7596. }
  7597. function tree_visitAfter(callback) {
  7598. var quads = [], next = [], q;
  7599. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  7600. while (q = quads.pop()) {
  7601. var node = q.node;
  7602. if (node.length) {
  7603. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  7604. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  7605. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  7606. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  7607. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  7608. }
  7609. next.push(q);
  7610. }
  7611. while (q = next.pop()) {
  7612. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  7613. }
  7614. return this;
  7615. }
  7616. function defaultX(d) {
  7617. return d[0];
  7618. }
  7619. function tree_x(_) {
  7620. return arguments.length ? (this._x = _, this) : this._x;
  7621. }
  7622. function defaultY(d) {
  7623. return d[1];
  7624. }
  7625. function tree_y(_) {
  7626. return arguments.length ? (this._y = _, this) : this._y;
  7627. }
  7628. function quadtree(nodes, x, y) {
  7629. var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
  7630. return nodes == null ? tree : tree.addAll(nodes);
  7631. }
  7632. function Quadtree(x, y, x0, y0, x1, y1) {
  7633. this._x = x;
  7634. this._y = y;
  7635. this._x0 = x0;
  7636. this._y0 = y0;
  7637. this._x1 = x1;
  7638. this._y1 = y1;
  7639. this._root = undefined;
  7640. }
  7641. function leaf_copy(leaf) {
  7642. var copy = {data: leaf.data}, next = copy;
  7643. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  7644. return copy;
  7645. }
  7646. var treeProto = quadtree.prototype = Quadtree.prototype;
  7647. treeProto.copy = function() {
  7648. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  7649. node = this._root,
  7650. nodes,
  7651. child;
  7652. if (!node) return copy;
  7653. if (!node.length) return copy._root = leaf_copy(node), copy;
  7654. nodes = [{source: node, target: copy._root = new Array(4)}];
  7655. while (node = nodes.pop()) {
  7656. for (var i = 0; i < 4; ++i) {
  7657. if (child = node.source[i]) {
  7658. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  7659. else node.target[i] = leaf_copy(child);
  7660. }
  7661. }
  7662. }
  7663. return copy;
  7664. };
  7665. treeProto.add = tree_add;
  7666. treeProto.addAll = addAll;
  7667. treeProto.cover = tree_cover;
  7668. treeProto.data = tree_data;
  7669. treeProto.extent = tree_extent;
  7670. treeProto.find = tree_find;
  7671. treeProto.remove = tree_remove;
  7672. treeProto.removeAll = removeAll;
  7673. treeProto.root = tree_root;
  7674. treeProto.size = tree_size;
  7675. treeProto.visit = tree_visit;
  7676. treeProto.visitAfter = tree_visitAfter;
  7677. treeProto.x = tree_x;
  7678. treeProto.y = tree_y;
  7679. function constant$4(x) {
  7680. return function() {
  7681. return x;
  7682. };
  7683. }
  7684. function jiggle(random) {
  7685. return (random() - 0.5) * 1e-6;
  7686. }
  7687. function x$3(d) {
  7688. return d.x + d.vx;
  7689. }
  7690. function y$3(d) {
  7691. return d.y + d.vy;
  7692. }
  7693. function collide(radius) {
  7694. var nodes,
  7695. radii,
  7696. random,
  7697. strength = 1,
  7698. iterations = 1;
  7699. if (typeof radius !== "function") radius = constant$4(radius == null ? 1 : +radius);
  7700. function force() {
  7701. var i, n = nodes.length,
  7702. tree,
  7703. node,
  7704. xi,
  7705. yi,
  7706. ri,
  7707. ri2;
  7708. for (var k = 0; k < iterations; ++k) {
  7709. tree = quadtree(nodes, x$3, y$3).visitAfter(prepare);
  7710. for (i = 0; i < n; ++i) {
  7711. node = nodes[i];
  7712. ri = radii[node.index], ri2 = ri * ri;
  7713. xi = node.x + node.vx;
  7714. yi = node.y + node.vy;
  7715. tree.visit(apply);
  7716. }
  7717. }
  7718. function apply(quad, x0, y0, x1, y1) {
  7719. var data = quad.data, rj = quad.r, r = ri + rj;
  7720. if (data) {
  7721. if (data.index > node.index) {
  7722. var x = xi - data.x - data.vx,
  7723. y = yi - data.y - data.vy,
  7724. l = x * x + y * y;
  7725. if (l < r * r) {
  7726. if (x === 0) x = jiggle(random), l += x * x;
  7727. if (y === 0) y = jiggle(random), l += y * y;
  7728. l = (r - (l = Math.sqrt(l))) / l * strength;
  7729. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  7730. node.vy += (y *= l) * r;
  7731. data.vx -= x * (r = 1 - r);
  7732. data.vy -= y * r;
  7733. }
  7734. }
  7735. return;
  7736. }
  7737. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  7738. }
  7739. }
  7740. function prepare(quad) {
  7741. if (quad.data) return quad.r = radii[quad.data.index];
  7742. for (var i = quad.r = 0; i < 4; ++i) {
  7743. if (quad[i] && quad[i].r > quad.r) {
  7744. quad.r = quad[i].r;
  7745. }
  7746. }
  7747. }
  7748. function initialize() {
  7749. if (!nodes) return;
  7750. var i, n = nodes.length, node;
  7751. radii = new Array(n);
  7752. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  7753. }
  7754. force.initialize = function(_nodes, _random) {
  7755. nodes = _nodes;
  7756. random = _random;
  7757. initialize();
  7758. };
  7759. force.iterations = function(_) {
  7760. return arguments.length ? (iterations = +_, force) : iterations;
  7761. };
  7762. force.strength = function(_) {
  7763. return arguments.length ? (strength = +_, force) : strength;
  7764. };
  7765. force.radius = function(_) {
  7766. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
  7767. };
  7768. return force;
  7769. }
  7770. function index$3(d) {
  7771. return d.index;
  7772. }
  7773. function find(nodeById, nodeId) {
  7774. var node = nodeById.get(nodeId);
  7775. if (!node) throw new Error("node not found: " + nodeId);
  7776. return node;
  7777. }
  7778. function link$2(links) {
  7779. var id = index$3,
  7780. strength = defaultStrength,
  7781. strengths,
  7782. distance = constant$4(30),
  7783. distances,
  7784. nodes,
  7785. count,
  7786. bias,
  7787. random,
  7788. iterations = 1;
  7789. if (links == null) links = [];
  7790. function defaultStrength(link) {
  7791. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  7792. }
  7793. function force(alpha) {
  7794. for (var k = 0, n = links.length; k < iterations; ++k) {
  7795. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  7796. link = links[i], source = link.source, target = link.target;
  7797. x = target.x + target.vx - source.x - source.vx || jiggle(random);
  7798. y = target.y + target.vy - source.y - source.vy || jiggle(random);
  7799. l = Math.sqrt(x * x + y * y);
  7800. l = (l - distances[i]) / l * alpha * strengths[i];
  7801. x *= l, y *= l;
  7802. target.vx -= x * (b = bias[i]);
  7803. target.vy -= y * b;
  7804. source.vx += x * (b = 1 - b);
  7805. source.vy += y * b;
  7806. }
  7807. }
  7808. }
  7809. function initialize() {
  7810. if (!nodes) return;
  7811. var i,
  7812. n = nodes.length,
  7813. m = links.length,
  7814. nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
  7815. link;
  7816. for (i = 0, count = new Array(n); i < m; ++i) {
  7817. link = links[i], link.index = i;
  7818. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  7819. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  7820. count[link.source.index] = (count[link.source.index] || 0) + 1;
  7821. count[link.target.index] = (count[link.target.index] || 0) + 1;
  7822. }
  7823. for (i = 0, bias = new Array(m); i < m; ++i) {
  7824. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  7825. }
  7826. strengths = new Array(m), initializeStrength();
  7827. distances = new Array(m), initializeDistance();
  7828. }
  7829. function initializeStrength() {
  7830. if (!nodes) return;
  7831. for (var i = 0, n = links.length; i < n; ++i) {
  7832. strengths[i] = +strength(links[i], i, links);
  7833. }
  7834. }
  7835. function initializeDistance() {
  7836. if (!nodes) return;
  7837. for (var i = 0, n = links.length; i < n; ++i) {
  7838. distances[i] = +distance(links[i], i, links);
  7839. }
  7840. }
  7841. force.initialize = function(_nodes, _random) {
  7842. nodes = _nodes;
  7843. random = _random;
  7844. initialize();
  7845. };
  7846. force.links = function(_) {
  7847. return arguments.length ? (links = _, initialize(), force) : links;
  7848. };
  7849. force.id = function(_) {
  7850. return arguments.length ? (id = _, force) : id;
  7851. };
  7852. force.iterations = function(_) {
  7853. return arguments.length ? (iterations = +_, force) : iterations;
  7854. };
  7855. force.strength = function(_) {
  7856. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initializeStrength(), force) : strength;
  7857. };
  7858. force.distance = function(_) {
  7859. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$4(+_), initializeDistance(), force) : distance;
  7860. };
  7861. return force;
  7862. }
  7863. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  7864. const a$2 = 1664525;
  7865. const c$4 = 1013904223;
  7866. const m$1 = 4294967296; // 2^32
  7867. function lcg$2() {
  7868. let s = 1;
  7869. return () => (s = (a$2 * s + c$4) % m$1) / m$1;
  7870. }
  7871. function x$2(d) {
  7872. return d.x;
  7873. }
  7874. function y$2(d) {
  7875. return d.y;
  7876. }
  7877. var initialRadius = 10,
  7878. initialAngle = Math.PI * (3 - Math.sqrt(5));
  7879. function simulation(nodes) {
  7880. var simulation,
  7881. alpha = 1,
  7882. alphaMin = 0.001,
  7883. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  7884. alphaTarget = 0,
  7885. velocityDecay = 0.6,
  7886. forces = new Map(),
  7887. stepper = timer(step),
  7888. event = dispatch("tick", "end"),
  7889. random = lcg$2();
  7890. if (nodes == null) nodes = [];
  7891. function step() {
  7892. tick();
  7893. event.call("tick", simulation);
  7894. if (alpha < alphaMin) {
  7895. stepper.stop();
  7896. event.call("end", simulation);
  7897. }
  7898. }
  7899. function tick(iterations) {
  7900. var i, n = nodes.length, node;
  7901. if (iterations === undefined) iterations = 1;
  7902. for (var k = 0; k < iterations; ++k) {
  7903. alpha += (alphaTarget - alpha) * alphaDecay;
  7904. forces.forEach(function(force) {
  7905. force(alpha);
  7906. });
  7907. for (i = 0; i < n; ++i) {
  7908. node = nodes[i];
  7909. if (node.fx == null) node.x += node.vx *= velocityDecay;
  7910. else node.x = node.fx, node.vx = 0;
  7911. if (node.fy == null) node.y += node.vy *= velocityDecay;
  7912. else node.y = node.fy, node.vy = 0;
  7913. }
  7914. }
  7915. return simulation;
  7916. }
  7917. function initializeNodes() {
  7918. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  7919. node = nodes[i], node.index = i;
  7920. if (node.fx != null) node.x = node.fx;
  7921. if (node.fy != null) node.y = node.fy;
  7922. if (isNaN(node.x) || isNaN(node.y)) {
  7923. var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
  7924. node.x = radius * Math.cos(angle);
  7925. node.y = radius * Math.sin(angle);
  7926. }
  7927. if (isNaN(node.vx) || isNaN(node.vy)) {
  7928. node.vx = node.vy = 0;
  7929. }
  7930. }
  7931. }
  7932. function initializeForce(force) {
  7933. if (force.initialize) force.initialize(nodes, random);
  7934. return force;
  7935. }
  7936. initializeNodes();
  7937. return simulation = {
  7938. tick: tick,
  7939. restart: function() {
  7940. return stepper.restart(step), simulation;
  7941. },
  7942. stop: function() {
  7943. return stepper.stop(), simulation;
  7944. },
  7945. nodes: function(_) {
  7946. return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
  7947. },
  7948. alpha: function(_) {
  7949. return arguments.length ? (alpha = +_, simulation) : alpha;
  7950. },
  7951. alphaMin: function(_) {
  7952. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  7953. },
  7954. alphaDecay: function(_) {
  7955. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  7956. },
  7957. alphaTarget: function(_) {
  7958. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  7959. },
  7960. velocityDecay: function(_) {
  7961. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  7962. },
  7963. randomSource: function(_) {
  7964. return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
  7965. },
  7966. force: function(name, _) {
  7967. return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  7968. },
  7969. find: function(x, y, radius) {
  7970. var i = 0,
  7971. n = nodes.length,
  7972. dx,
  7973. dy,
  7974. d2,
  7975. node,
  7976. closest;
  7977. if (radius == null) radius = Infinity;
  7978. else radius *= radius;
  7979. for (i = 0; i < n; ++i) {
  7980. node = nodes[i];
  7981. dx = x - node.x;
  7982. dy = y - node.y;
  7983. d2 = dx * dx + dy * dy;
  7984. if (d2 < radius) closest = node, radius = d2;
  7985. }
  7986. return closest;
  7987. },
  7988. on: function(name, _) {
  7989. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  7990. }
  7991. };
  7992. }
  7993. function manyBody() {
  7994. var nodes,
  7995. node,
  7996. random,
  7997. alpha,
  7998. strength = constant$4(-30),
  7999. strengths,
  8000. distanceMin2 = 1,
  8001. distanceMax2 = Infinity,
  8002. theta2 = 0.81;
  8003. function force(_) {
  8004. var i, n = nodes.length, tree = quadtree(nodes, x$2, y$2).visitAfter(accumulate);
  8005. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  8006. }
  8007. function initialize() {
  8008. if (!nodes) return;
  8009. var i, n = nodes.length, node;
  8010. strengths = new Array(n);
  8011. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  8012. }
  8013. function accumulate(quad) {
  8014. var strength = 0, q, c, weight = 0, x, y, i;
  8015. // For internal nodes, accumulate forces from child quadrants.
  8016. if (quad.length) {
  8017. for (x = y = i = 0; i < 4; ++i) {
  8018. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  8019. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  8020. }
  8021. }
  8022. quad.x = x / weight;
  8023. quad.y = y / weight;
  8024. }
  8025. // For leaf nodes, accumulate forces from coincident quadrants.
  8026. else {
  8027. q = quad;
  8028. q.x = q.data.x;
  8029. q.y = q.data.y;
  8030. do strength += strengths[q.data.index];
  8031. while (q = q.next);
  8032. }
  8033. quad.value = strength;
  8034. }
  8035. function apply(quad, x1, _, x2) {
  8036. if (!quad.value) return true;
  8037. var x = quad.x - node.x,
  8038. y = quad.y - node.y,
  8039. w = x2 - x1,
  8040. l = x * x + y * y;
  8041. // Apply the Barnes-Hut approximation if possible.
  8042. // Limit forces for very close nodes; randomize direction if coincident.
  8043. if (w * w / theta2 < l) {
  8044. if (l < distanceMax2) {
  8045. if (x === 0) x = jiggle(random), l += x * x;
  8046. if (y === 0) y = jiggle(random), l += y * y;
  8047. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  8048. node.vx += x * quad.value * alpha / l;
  8049. node.vy += y * quad.value * alpha / l;
  8050. }
  8051. return true;
  8052. }
  8053. // Otherwise, process points directly.
  8054. else if (quad.length || l >= distanceMax2) return;
  8055. // Limit forces for very close nodes; randomize direction if coincident.
  8056. if (quad.data !== node || quad.next) {
  8057. if (x === 0) x = jiggle(random), l += x * x;
  8058. if (y === 0) y = jiggle(random), l += y * y;
  8059. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  8060. }
  8061. do if (quad.data !== node) {
  8062. w = strengths[quad.data.index] * alpha / l;
  8063. node.vx += x * w;
  8064. node.vy += y * w;
  8065. } while (quad = quad.next);
  8066. }
  8067. force.initialize = function(_nodes, _random) {
  8068. nodes = _nodes;
  8069. random = _random;
  8070. initialize();
  8071. };
  8072. force.strength = function(_) {
  8073. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8074. };
  8075. force.distanceMin = function(_) {
  8076. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  8077. };
  8078. force.distanceMax = function(_) {
  8079. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  8080. };
  8081. force.theta = function(_) {
  8082. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  8083. };
  8084. return force;
  8085. }
  8086. function radial$1(radius, x, y) {
  8087. var nodes,
  8088. strength = constant$4(0.1),
  8089. strengths,
  8090. radiuses;
  8091. if (typeof radius !== "function") radius = constant$4(+radius);
  8092. if (x == null) x = 0;
  8093. if (y == null) y = 0;
  8094. function force(alpha) {
  8095. for (var i = 0, n = nodes.length; i < n; ++i) {
  8096. var node = nodes[i],
  8097. dx = node.x - x || 1e-6,
  8098. dy = node.y - y || 1e-6,
  8099. r = Math.sqrt(dx * dx + dy * dy),
  8100. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  8101. node.vx += dx * k;
  8102. node.vy += dy * k;
  8103. }
  8104. }
  8105. function initialize() {
  8106. if (!nodes) return;
  8107. var i, n = nodes.length;
  8108. strengths = new Array(n);
  8109. radiuses = new Array(n);
  8110. for (i = 0; i < n; ++i) {
  8111. radiuses[i] = +radius(nodes[i], i, nodes);
  8112. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  8113. }
  8114. }
  8115. force.initialize = function(_) {
  8116. nodes = _, initialize();
  8117. };
  8118. force.strength = function(_) {
  8119. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8120. };
  8121. force.radius = function(_) {
  8122. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
  8123. };
  8124. force.x = function(_) {
  8125. return arguments.length ? (x = +_, force) : x;
  8126. };
  8127. force.y = function(_) {
  8128. return arguments.length ? (y = +_, force) : y;
  8129. };
  8130. return force;
  8131. }
  8132. function x$1(x) {
  8133. var strength = constant$4(0.1),
  8134. nodes,
  8135. strengths,
  8136. xz;
  8137. if (typeof x !== "function") x = constant$4(x == null ? 0 : +x);
  8138. function force(alpha) {
  8139. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  8140. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  8141. }
  8142. }
  8143. function initialize() {
  8144. if (!nodes) return;
  8145. var i, n = nodes.length;
  8146. strengths = new Array(n);
  8147. xz = new Array(n);
  8148. for (i = 0; i < n; ++i) {
  8149. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  8150. }
  8151. }
  8152. force.initialize = function(_) {
  8153. nodes = _;
  8154. initialize();
  8155. };
  8156. force.strength = function(_) {
  8157. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8158. };
  8159. force.x = function(_) {
  8160. return arguments.length ? (x = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : x;
  8161. };
  8162. return force;
  8163. }
  8164. function y$1(y) {
  8165. var strength = constant$4(0.1),
  8166. nodes,
  8167. strengths,
  8168. yz;
  8169. if (typeof y !== "function") y = constant$4(y == null ? 0 : +y);
  8170. function force(alpha) {
  8171. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  8172. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  8173. }
  8174. }
  8175. function initialize() {
  8176. if (!nodes) return;
  8177. var i, n = nodes.length;
  8178. strengths = new Array(n);
  8179. yz = new Array(n);
  8180. for (i = 0; i < n; ++i) {
  8181. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  8182. }
  8183. }
  8184. force.initialize = function(_) {
  8185. nodes = _;
  8186. initialize();
  8187. };
  8188. force.strength = function(_) {
  8189. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8190. };
  8191. force.y = function(_) {
  8192. return arguments.length ? (y = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : y;
  8193. };
  8194. return force;
  8195. }
  8196. function formatDecimal(x) {
  8197. return Math.abs(x = Math.round(x)) >= 1e21
  8198. ? x.toLocaleString("en").replace(/,/g, "")
  8199. : x.toString(10);
  8200. }
  8201. // Computes the decimal coefficient and exponent of the specified number x with
  8202. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  8203. // For example, formatDecimalParts(1.23) returns ["123", 0].
  8204. function formatDecimalParts(x, p) {
  8205. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  8206. var i, coefficient = x.slice(0, i);
  8207. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  8208. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  8209. return [
  8210. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  8211. +x.slice(i + 1)
  8212. ];
  8213. }
  8214. function exponent(x) {
  8215. return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
  8216. }
  8217. function formatGroup(grouping, thousands) {
  8218. return function(value, width) {
  8219. var i = value.length,
  8220. t = [],
  8221. j = 0,
  8222. g = grouping[0],
  8223. length = 0;
  8224. while (i > 0 && g > 0) {
  8225. if (length + g + 1 > width) g = Math.max(1, width - length);
  8226. t.push(value.substring(i -= g, i + g));
  8227. if ((length += g + 1) > width) break;
  8228. g = grouping[j = (j + 1) % grouping.length];
  8229. }
  8230. return t.reverse().join(thousands);
  8231. };
  8232. }
  8233. function formatNumerals(numerals) {
  8234. return function(value) {
  8235. return value.replace(/[0-9]/g, function(i) {
  8236. return numerals[+i];
  8237. });
  8238. };
  8239. }
  8240. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  8241. var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  8242. function formatSpecifier(specifier) {
  8243. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  8244. var match;
  8245. return new FormatSpecifier({
  8246. fill: match[1],
  8247. align: match[2],
  8248. sign: match[3],
  8249. symbol: match[4],
  8250. zero: match[5],
  8251. width: match[6],
  8252. comma: match[7],
  8253. precision: match[8] && match[8].slice(1),
  8254. trim: match[9],
  8255. type: match[10]
  8256. });
  8257. }
  8258. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  8259. function FormatSpecifier(specifier) {
  8260. this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
  8261. this.align = specifier.align === undefined ? ">" : specifier.align + "";
  8262. this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
  8263. this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
  8264. this.zero = !!specifier.zero;
  8265. this.width = specifier.width === undefined ? undefined : +specifier.width;
  8266. this.comma = !!specifier.comma;
  8267. this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
  8268. this.trim = !!specifier.trim;
  8269. this.type = specifier.type === undefined ? "" : specifier.type + "";
  8270. }
  8271. FormatSpecifier.prototype.toString = function() {
  8272. return this.fill
  8273. + this.align
  8274. + this.sign
  8275. + this.symbol
  8276. + (this.zero ? "0" : "")
  8277. + (this.width === undefined ? "" : Math.max(1, this.width | 0))
  8278. + (this.comma ? "," : "")
  8279. + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
  8280. + (this.trim ? "~" : "")
  8281. + this.type;
  8282. };
  8283. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  8284. function formatTrim(s) {
  8285. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  8286. switch (s[i]) {
  8287. case ".": i0 = i1 = i; break;
  8288. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  8289. default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
  8290. }
  8291. }
  8292. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  8293. }
  8294. var prefixExponent;
  8295. function formatPrefixAuto(x, p) {
  8296. var d = formatDecimalParts(x, p);
  8297. if (!d) return x + "";
  8298. var coefficient = d[0],
  8299. exponent = d[1],
  8300. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  8301. n = coefficient.length;
  8302. return i === n ? coefficient
  8303. : i > n ? coefficient + new Array(i - n + 1).join("0")
  8304. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  8305. : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  8306. }
  8307. function formatRounded(x, p) {
  8308. var d = formatDecimalParts(x, p);
  8309. if (!d) return x + "";
  8310. var coefficient = d[0],
  8311. exponent = d[1];
  8312. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  8313. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  8314. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  8315. }
  8316. var formatTypes = {
  8317. "%": (x, p) => (x * 100).toFixed(p),
  8318. "b": (x) => Math.round(x).toString(2),
  8319. "c": (x) => x + "",
  8320. "d": formatDecimal,
  8321. "e": (x, p) => x.toExponential(p),
  8322. "f": (x, p) => x.toFixed(p),
  8323. "g": (x, p) => x.toPrecision(p),
  8324. "o": (x) => Math.round(x).toString(8),
  8325. "p": (x, p) => formatRounded(x * 100, p),
  8326. "r": formatRounded,
  8327. "s": formatPrefixAuto,
  8328. "X": (x) => Math.round(x).toString(16).toUpperCase(),
  8329. "x": (x) => Math.round(x).toString(16)
  8330. };
  8331. function identity$6(x) {
  8332. return x;
  8333. }
  8334. var map = Array.prototype.map,
  8335. prefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];
  8336. function formatLocale$1(locale) {
  8337. var group = locale.grouping === undefined || locale.thousands === undefined ? identity$6 : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""),
  8338. currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
  8339. currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
  8340. decimal = locale.decimal === undefined ? "." : locale.decimal + "",
  8341. numerals = locale.numerals === undefined ? identity$6 : formatNumerals(map.call(locale.numerals, String)),
  8342. percent = locale.percent === undefined ? "%" : locale.percent + "",
  8343. minus = locale.minus === undefined ? "−" : locale.minus + "",
  8344. nan = locale.nan === undefined ? "NaN" : locale.nan + "";
  8345. function newFormat(specifier) {
  8346. specifier = formatSpecifier(specifier);
  8347. var fill = specifier.fill,
  8348. align = specifier.align,
  8349. sign = specifier.sign,
  8350. symbol = specifier.symbol,
  8351. zero = specifier.zero,
  8352. width = specifier.width,
  8353. comma = specifier.comma,
  8354. precision = specifier.precision,
  8355. trim = specifier.trim,
  8356. type = specifier.type;
  8357. // The "n" type is an alias for ",g".
  8358. if (type === "n") comma = true, type = "g";
  8359. // The "" type, and any invalid type, is an alias for ".12~g".
  8360. else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
  8361. // If zero fill is specified, padding goes after sign and before digits.
  8362. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  8363. // Compute the prefix and suffix.
  8364. // For SI-prefix, the suffix is lazily computed.
  8365. var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  8366. suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
  8367. // What format function should we use?
  8368. // Is this an integer type?
  8369. // Can this type generate exponential notation?
  8370. var formatType = formatTypes[type],
  8371. maybeSuffix = /[defgprs%]/.test(type);
  8372. // Set the default precision if not specified,
  8373. // or clamp the specified precision to the supported range.
  8374. // For significant precision, it must be in [1, 21].
  8375. // For fixed precision, it must be in [0, 20].
  8376. precision = precision === undefined ? 6
  8377. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  8378. : Math.max(0, Math.min(20, precision));
  8379. function format(value) {
  8380. var valuePrefix = prefix,
  8381. valueSuffix = suffix,
  8382. i, n, c;
  8383. if (type === "c") {
  8384. valueSuffix = formatType(value) + valueSuffix;
  8385. value = "";
  8386. } else {
  8387. value = +value;
  8388. // Determine the sign. -0 is not less than 0, but 1 / -0 is!
  8389. var valueNegative = value < 0 || 1 / value < 0;
  8390. // Perform the initial formatting.
  8391. value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
  8392. // Trim insignificant zeros.
  8393. if (trim) value = formatTrim(value);
  8394. // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
  8395. if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
  8396. // Compute the prefix and suffix.
  8397. valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  8398. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  8399. // Break the formatted value into the integer “value” part that can be
  8400. // grouped, and fractional or exponential “suffix” part that is not.
  8401. if (maybeSuffix) {
  8402. i = -1, n = value.length;
  8403. while (++i < n) {
  8404. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  8405. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  8406. value = value.slice(0, i);
  8407. break;
  8408. }
  8409. }
  8410. }
  8411. }
  8412. // If the fill character is not "0", grouping is applied before padding.
  8413. if (comma && !zero) value = group(value, Infinity);
  8414. // Compute the padding.
  8415. var length = valuePrefix.length + value.length + valueSuffix.length,
  8416. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  8417. // If the fill character is "0", grouping is applied after padding.
  8418. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  8419. // Reconstruct the final output based on the desired alignment.
  8420. switch (align) {
  8421. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  8422. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  8423. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  8424. default: value = padding + valuePrefix + value + valueSuffix; break;
  8425. }
  8426. return numerals(value);
  8427. }
  8428. format.toString = function() {
  8429. return specifier + "";
  8430. };
  8431. return format;
  8432. }
  8433. function formatPrefix(specifier, value) {
  8434. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  8435. e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
  8436. k = Math.pow(10, -e),
  8437. prefix = prefixes[8 + e / 3];
  8438. return function(value) {
  8439. return f(k * value) + prefix;
  8440. };
  8441. }
  8442. return {
  8443. format: newFormat,
  8444. formatPrefix: formatPrefix
  8445. };
  8446. }
  8447. var locale$1;
  8448. exports.format = void 0;
  8449. exports.formatPrefix = void 0;
  8450. defaultLocale$1({
  8451. thousands: ",",
  8452. grouping: [3],
  8453. currency: ["$", ""]
  8454. });
  8455. function defaultLocale$1(definition) {
  8456. locale$1 = formatLocale$1(definition);
  8457. exports.format = locale$1.format;
  8458. exports.formatPrefix = locale$1.formatPrefix;
  8459. return locale$1;
  8460. }
  8461. function precisionFixed(step) {
  8462. return Math.max(0, -exponent(Math.abs(step)));
  8463. }
  8464. function precisionPrefix(step, value) {
  8465. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
  8466. }
  8467. function precisionRound(step, max) {
  8468. step = Math.abs(step), max = Math.abs(max) - step;
  8469. return Math.max(0, exponent(max) - exponent(step)) + 1;
  8470. }
  8471. var epsilon$1 = 1e-6;
  8472. var epsilon2 = 1e-12;
  8473. var pi$1 = Math.PI;
  8474. var halfPi$1 = pi$1 / 2;
  8475. var quarterPi = pi$1 / 4;
  8476. var tau$1 = pi$1 * 2;
  8477. var degrees = 180 / pi$1;
  8478. var radians = pi$1 / 180;
  8479. var abs$1 = Math.abs;
  8480. var atan = Math.atan;
  8481. var atan2$1 = Math.atan2;
  8482. var cos$1 = Math.cos;
  8483. var ceil = Math.ceil;
  8484. var exp = Math.exp;
  8485. var hypot = Math.hypot;
  8486. var log$1 = Math.log;
  8487. var pow$1 = Math.pow;
  8488. var sin$1 = Math.sin;
  8489. var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  8490. var sqrt$2 = Math.sqrt;
  8491. var tan = Math.tan;
  8492. function acos$1(x) {
  8493. return x > 1 ? 0 : x < -1 ? pi$1 : Math.acos(x);
  8494. }
  8495. function asin$1(x) {
  8496. return x > 1 ? halfPi$1 : x < -1 ? -halfPi$1 : Math.asin(x);
  8497. }
  8498. function haversin(x) {
  8499. return (x = sin$1(x / 2)) * x;
  8500. }
  8501. function noop$1() {}
  8502. function streamGeometry(geometry, stream) {
  8503. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  8504. streamGeometryType[geometry.type](geometry, stream);
  8505. }
  8506. }
  8507. var streamObjectType = {
  8508. Feature: function(object, stream) {
  8509. streamGeometry(object.geometry, stream);
  8510. },
  8511. FeatureCollection: function(object, stream) {
  8512. var features = object.features, i = -1, n = features.length;
  8513. while (++i < n) streamGeometry(features[i].geometry, stream);
  8514. }
  8515. };
  8516. var streamGeometryType = {
  8517. Sphere: function(object, stream) {
  8518. stream.sphere();
  8519. },
  8520. Point: function(object, stream) {
  8521. object = object.coordinates;
  8522. stream.point(object[0], object[1], object[2]);
  8523. },
  8524. MultiPoint: function(object, stream) {
  8525. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  8526. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  8527. },
  8528. LineString: function(object, stream) {
  8529. streamLine(object.coordinates, stream, 0);
  8530. },
  8531. MultiLineString: function(object, stream) {
  8532. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  8533. while (++i < n) streamLine(coordinates[i], stream, 0);
  8534. },
  8535. Polygon: function(object, stream) {
  8536. streamPolygon(object.coordinates, stream);
  8537. },
  8538. MultiPolygon: function(object, stream) {
  8539. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  8540. while (++i < n) streamPolygon(coordinates[i], stream);
  8541. },
  8542. GeometryCollection: function(object, stream) {
  8543. var geometries = object.geometries, i = -1, n = geometries.length;
  8544. while (++i < n) streamGeometry(geometries[i], stream);
  8545. }
  8546. };
  8547. function streamLine(coordinates, stream, closed) {
  8548. var i = -1, n = coordinates.length - closed, coordinate;
  8549. stream.lineStart();
  8550. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  8551. stream.lineEnd();
  8552. }
  8553. function streamPolygon(coordinates, stream) {
  8554. var i = -1, n = coordinates.length;
  8555. stream.polygonStart();
  8556. while (++i < n) streamLine(coordinates[i], stream, 1);
  8557. stream.polygonEnd();
  8558. }
  8559. function geoStream(object, stream) {
  8560. if (object && streamObjectType.hasOwnProperty(object.type)) {
  8561. streamObjectType[object.type](object, stream);
  8562. } else {
  8563. streamGeometry(object, stream);
  8564. }
  8565. }
  8566. var areaRingSum$1 = new Adder();
  8567. // hello?
  8568. var areaSum$1 = new Adder(),
  8569. lambda00$2,
  8570. phi00$2,
  8571. lambda0$2,
  8572. cosPhi0$1,
  8573. sinPhi0$1;
  8574. var areaStream$1 = {
  8575. point: noop$1,
  8576. lineStart: noop$1,
  8577. lineEnd: noop$1,
  8578. polygonStart: function() {
  8579. areaRingSum$1 = new Adder();
  8580. areaStream$1.lineStart = areaRingStart$1;
  8581. areaStream$1.lineEnd = areaRingEnd$1;
  8582. },
  8583. polygonEnd: function() {
  8584. var areaRing = +areaRingSum$1;
  8585. areaSum$1.add(areaRing < 0 ? tau$1 + areaRing : areaRing);
  8586. this.lineStart = this.lineEnd = this.point = noop$1;
  8587. },
  8588. sphere: function() {
  8589. areaSum$1.add(tau$1);
  8590. }
  8591. };
  8592. function areaRingStart$1() {
  8593. areaStream$1.point = areaPointFirst$1;
  8594. }
  8595. function areaRingEnd$1() {
  8596. areaPoint$1(lambda00$2, phi00$2);
  8597. }
  8598. function areaPointFirst$1(lambda, phi) {
  8599. areaStream$1.point = areaPoint$1;
  8600. lambda00$2 = lambda, phi00$2 = phi;
  8601. lambda *= radians, phi *= radians;
  8602. lambda0$2 = lambda, cosPhi0$1 = cos$1(phi = phi / 2 + quarterPi), sinPhi0$1 = sin$1(phi);
  8603. }
  8604. function areaPoint$1(lambda, phi) {
  8605. lambda *= radians, phi *= radians;
  8606. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  8607. // Spherical excess E for a spherical triangle with vertices: south pole,
  8608. // previous point, current point. Uses a formula derived from Cagnoli’s
  8609. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  8610. var dLambda = lambda - lambda0$2,
  8611. sdLambda = dLambda >= 0 ? 1 : -1,
  8612. adLambda = sdLambda * dLambda,
  8613. cosPhi = cos$1(phi),
  8614. sinPhi = sin$1(phi),
  8615. k = sinPhi0$1 * sinPhi,
  8616. u = cosPhi0$1 * cosPhi + k * cos$1(adLambda),
  8617. v = k * sdLambda * sin$1(adLambda);
  8618. areaRingSum$1.add(atan2$1(v, u));
  8619. // Advance the previous points.
  8620. lambda0$2 = lambda, cosPhi0$1 = cosPhi, sinPhi0$1 = sinPhi;
  8621. }
  8622. function area$2(object) {
  8623. areaSum$1 = new Adder();
  8624. geoStream(object, areaStream$1);
  8625. return areaSum$1 * 2;
  8626. }
  8627. function spherical(cartesian) {
  8628. return [atan2$1(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
  8629. }
  8630. function cartesian(spherical) {
  8631. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  8632. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  8633. }
  8634. function cartesianDot(a, b) {
  8635. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  8636. }
  8637. function cartesianCross(a, b) {
  8638. 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]];
  8639. }
  8640. // TODO return a
  8641. function cartesianAddInPlace(a, b) {
  8642. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  8643. }
  8644. function cartesianScale(vector, k) {
  8645. return [vector[0] * k, vector[1] * k, vector[2] * k];
  8646. }
  8647. // TODO return d
  8648. function cartesianNormalizeInPlace(d) {
  8649. var l = sqrt$2(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  8650. d[0] /= l, d[1] /= l, d[2] /= l;
  8651. }
  8652. var lambda0$1, phi0, lambda1, phi1, // bounds
  8653. lambda2, // previous lambda-coordinate
  8654. lambda00$1, phi00$1, // first point
  8655. p0, // previous 3D point
  8656. deltaSum,
  8657. ranges,
  8658. range;
  8659. var boundsStream$2 = {
  8660. point: boundsPoint$1,
  8661. lineStart: boundsLineStart,
  8662. lineEnd: boundsLineEnd,
  8663. polygonStart: function() {
  8664. boundsStream$2.point = boundsRingPoint;
  8665. boundsStream$2.lineStart = boundsRingStart;
  8666. boundsStream$2.lineEnd = boundsRingEnd;
  8667. deltaSum = new Adder();
  8668. areaStream$1.polygonStart();
  8669. },
  8670. polygonEnd: function() {
  8671. areaStream$1.polygonEnd();
  8672. boundsStream$2.point = boundsPoint$1;
  8673. boundsStream$2.lineStart = boundsLineStart;
  8674. boundsStream$2.lineEnd = boundsLineEnd;
  8675. if (areaRingSum$1 < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  8676. else if (deltaSum > epsilon$1) phi1 = 90;
  8677. else if (deltaSum < -epsilon$1) phi0 = -90;
  8678. range[0] = lambda0$1, range[1] = lambda1;
  8679. },
  8680. sphere: function() {
  8681. lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  8682. }
  8683. };
  8684. function boundsPoint$1(lambda, phi) {
  8685. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  8686. if (phi < phi0) phi0 = phi;
  8687. if (phi > phi1) phi1 = phi;
  8688. }
  8689. function linePoint(lambda, phi) {
  8690. var p = cartesian([lambda * radians, phi * radians]);
  8691. if (p0) {
  8692. var normal = cartesianCross(p0, p),
  8693. equatorial = [normal[1], -normal[0], 0],
  8694. inflection = cartesianCross(equatorial, normal);
  8695. cartesianNormalizeInPlace(inflection);
  8696. inflection = spherical(inflection);
  8697. var delta = lambda - lambda2,
  8698. sign = delta > 0 ? 1 : -1,
  8699. lambdai = inflection[0] * degrees * sign,
  8700. phii,
  8701. antimeridian = abs$1(delta) > 180;
  8702. if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  8703. phii = inflection[1] * degrees;
  8704. if (phii > phi1) phi1 = phii;
  8705. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  8706. phii = -inflection[1] * degrees;
  8707. if (phii < phi0) phi0 = phii;
  8708. } else {
  8709. if (phi < phi0) phi0 = phi;
  8710. if (phi > phi1) phi1 = phi;
  8711. }
  8712. if (antimeridian) {
  8713. if (lambda < lambda2) {
  8714. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  8715. } else {
  8716. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  8717. }
  8718. } else {
  8719. if (lambda1 >= lambda0$1) {
  8720. if (lambda < lambda0$1) lambda0$1 = lambda;
  8721. if (lambda > lambda1) lambda1 = lambda;
  8722. } else {
  8723. if (lambda > lambda2) {
  8724. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  8725. } else {
  8726. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  8727. }
  8728. }
  8729. }
  8730. } else {
  8731. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  8732. }
  8733. if (phi < phi0) phi0 = phi;
  8734. if (phi > phi1) phi1 = phi;
  8735. p0 = p, lambda2 = lambda;
  8736. }
  8737. function boundsLineStart() {
  8738. boundsStream$2.point = linePoint;
  8739. }
  8740. function boundsLineEnd() {
  8741. range[0] = lambda0$1, range[1] = lambda1;
  8742. boundsStream$2.point = boundsPoint$1;
  8743. p0 = null;
  8744. }
  8745. function boundsRingPoint(lambda, phi) {
  8746. if (p0) {
  8747. var delta = lambda - lambda2;
  8748. deltaSum.add(abs$1(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  8749. } else {
  8750. lambda00$1 = lambda, phi00$1 = phi;
  8751. }
  8752. areaStream$1.point(lambda, phi);
  8753. linePoint(lambda, phi);
  8754. }
  8755. function boundsRingStart() {
  8756. areaStream$1.lineStart();
  8757. }
  8758. function boundsRingEnd() {
  8759. boundsRingPoint(lambda00$1, phi00$1);
  8760. areaStream$1.lineEnd();
  8761. if (abs$1(deltaSum) > epsilon$1) lambda0$1 = -(lambda1 = 180);
  8762. range[0] = lambda0$1, range[1] = lambda1;
  8763. p0 = null;
  8764. }
  8765. // Finds the left-right distance between two longitudes.
  8766. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  8767. // the distance between ±180° to be 360°.
  8768. function angle(lambda0, lambda1) {
  8769. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  8770. }
  8771. function rangeCompare(a, b) {
  8772. return a[0] - b[0];
  8773. }
  8774. function rangeContains(range, x) {
  8775. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  8776. }
  8777. function bounds(feature) {
  8778. var i, n, a, b, merged, deltaMax, delta;
  8779. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  8780. ranges = [];
  8781. geoStream(feature, boundsStream$2);
  8782. // First, sort ranges by their minimum longitudes.
  8783. if (n = ranges.length) {
  8784. ranges.sort(rangeCompare);
  8785. // Then, merge any ranges that overlap.
  8786. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  8787. b = ranges[i];
  8788. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  8789. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  8790. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  8791. } else {
  8792. merged.push(a = b);
  8793. }
  8794. }
  8795. // Finally, find the largest gap between the merged ranges.
  8796. // The final bounding box will be the inverse of this gap.
  8797. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  8798. b = merged[i];
  8799. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  8800. }
  8801. }
  8802. ranges = range = null;
  8803. return lambda0$1 === Infinity || phi0 === Infinity
  8804. ? [[NaN, NaN], [NaN, NaN]]
  8805. : [[lambda0$1, phi0], [lambda1, phi1]];
  8806. }
  8807. var W0, W1,
  8808. X0$1, Y0$1, Z0$1,
  8809. X1$1, Y1$1, Z1$1,
  8810. X2$1, Y2$1, Z2$1,
  8811. lambda00, phi00, // first point
  8812. x0$4, y0$4, z0; // previous point
  8813. var centroidStream$1 = {
  8814. sphere: noop$1,
  8815. point: centroidPoint$1,
  8816. lineStart: centroidLineStart$1,
  8817. lineEnd: centroidLineEnd$1,
  8818. polygonStart: function() {
  8819. centroidStream$1.lineStart = centroidRingStart$1;
  8820. centroidStream$1.lineEnd = centroidRingEnd$1;
  8821. },
  8822. polygonEnd: function() {
  8823. centroidStream$1.lineStart = centroidLineStart$1;
  8824. centroidStream$1.lineEnd = centroidLineEnd$1;
  8825. }
  8826. };
  8827. // Arithmetic mean of Cartesian vectors.
  8828. function centroidPoint$1(lambda, phi) {
  8829. lambda *= radians, phi *= radians;
  8830. var cosPhi = cos$1(phi);
  8831. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  8832. }
  8833. function centroidPointCartesian(x, y, z) {
  8834. ++W0;
  8835. X0$1 += (x - X0$1) / W0;
  8836. Y0$1 += (y - Y0$1) / W0;
  8837. Z0$1 += (z - Z0$1) / W0;
  8838. }
  8839. function centroidLineStart$1() {
  8840. centroidStream$1.point = centroidLinePointFirst;
  8841. }
  8842. function centroidLinePointFirst(lambda, phi) {
  8843. lambda *= radians, phi *= radians;
  8844. var cosPhi = cos$1(phi);
  8845. x0$4 = cosPhi * cos$1(lambda);
  8846. y0$4 = cosPhi * sin$1(lambda);
  8847. z0 = sin$1(phi);
  8848. centroidStream$1.point = centroidLinePoint;
  8849. centroidPointCartesian(x0$4, y0$4, z0);
  8850. }
  8851. function centroidLinePoint(lambda, phi) {
  8852. lambda *= radians, phi *= radians;
  8853. var cosPhi = cos$1(phi),
  8854. x = cosPhi * cos$1(lambda),
  8855. y = cosPhi * sin$1(lambda),
  8856. z = sin$1(phi),
  8857. w = atan2$1(sqrt$2((w = y0$4 * z - z0 * y) * w + (w = z0 * x - x0$4 * z) * w + (w = x0$4 * y - y0$4 * x) * w), x0$4 * x + y0$4 * y + z0 * z);
  8858. W1 += w;
  8859. X1$1 += w * (x0$4 + (x0$4 = x));
  8860. Y1$1 += w * (y0$4 + (y0$4 = y));
  8861. Z1$1 += w * (z0 + (z0 = z));
  8862. centroidPointCartesian(x0$4, y0$4, z0);
  8863. }
  8864. function centroidLineEnd$1() {
  8865. centroidStream$1.point = centroidPoint$1;
  8866. }
  8867. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  8868. // J. Applied Mechanics 42, 239 (1975).
  8869. function centroidRingStart$1() {
  8870. centroidStream$1.point = centroidRingPointFirst;
  8871. }
  8872. function centroidRingEnd$1() {
  8873. centroidRingPoint(lambda00, phi00);
  8874. centroidStream$1.point = centroidPoint$1;
  8875. }
  8876. function centroidRingPointFirst(lambda, phi) {
  8877. lambda00 = lambda, phi00 = phi;
  8878. lambda *= radians, phi *= radians;
  8879. centroidStream$1.point = centroidRingPoint;
  8880. var cosPhi = cos$1(phi);
  8881. x0$4 = cosPhi * cos$1(lambda);
  8882. y0$4 = cosPhi * sin$1(lambda);
  8883. z0 = sin$1(phi);
  8884. centroidPointCartesian(x0$4, y0$4, z0);
  8885. }
  8886. function centroidRingPoint(lambda, phi) {
  8887. lambda *= radians, phi *= radians;
  8888. var cosPhi = cos$1(phi),
  8889. x = cosPhi * cos$1(lambda),
  8890. y = cosPhi * sin$1(lambda),
  8891. z = sin$1(phi),
  8892. cx = y0$4 * z - z0 * y,
  8893. cy = z0 * x - x0$4 * z,
  8894. cz = x0$4 * y - y0$4 * x,
  8895. m = hypot(cx, cy, cz),
  8896. w = asin$1(m), // line weight = angle
  8897. v = m && -w / m; // area weight multiplier
  8898. X2$1.add(v * cx);
  8899. Y2$1.add(v * cy);
  8900. Z2$1.add(v * cz);
  8901. W1 += w;
  8902. X1$1 += w * (x0$4 + (x0$4 = x));
  8903. Y1$1 += w * (y0$4 + (y0$4 = y));
  8904. Z1$1 += w * (z0 + (z0 = z));
  8905. centroidPointCartesian(x0$4, y0$4, z0);
  8906. }
  8907. function centroid$1(object) {
  8908. W0 = W1 =
  8909. X0$1 = Y0$1 = Z0$1 =
  8910. X1$1 = Y1$1 = Z1$1 = 0;
  8911. X2$1 = new Adder();
  8912. Y2$1 = new Adder();
  8913. Z2$1 = new Adder();
  8914. geoStream(object, centroidStream$1);
  8915. var x = +X2$1,
  8916. y = +Y2$1,
  8917. z = +Z2$1,
  8918. m = hypot(x, y, z);
  8919. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  8920. if (m < epsilon2) {
  8921. x = X1$1, y = Y1$1, z = Z1$1;
  8922. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  8923. if (W1 < epsilon$1) x = X0$1, y = Y0$1, z = Z0$1;
  8924. m = hypot(x, y, z);
  8925. // If the feature still has an undefined ccentroid, then return.
  8926. if (m < epsilon2) return [NaN, NaN];
  8927. }
  8928. return [atan2$1(y, x) * degrees, asin$1(z / m) * degrees];
  8929. }
  8930. function constant$3(x) {
  8931. return function() {
  8932. return x;
  8933. };
  8934. }
  8935. function compose(a, b) {
  8936. function compose(x, y) {
  8937. return x = a(x, y), b(x[0], x[1]);
  8938. }
  8939. if (a.invert && b.invert) compose.invert = function(x, y) {
  8940. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  8941. };
  8942. return compose;
  8943. }
  8944. function rotationIdentity(lambda, phi) {
  8945. if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1;
  8946. return [lambda, phi];
  8947. }
  8948. rotationIdentity.invert = rotationIdentity;
  8949. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  8950. return (deltaLambda %= tau$1) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  8951. : rotationLambda(deltaLambda))
  8952. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  8953. : rotationIdentity);
  8954. }
  8955. function forwardRotationLambda(deltaLambda) {
  8956. return function(lambda, phi) {
  8957. lambda += deltaLambda;
  8958. if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1;
  8959. return [lambda, phi];
  8960. };
  8961. }
  8962. function rotationLambda(deltaLambda) {
  8963. var rotation = forwardRotationLambda(deltaLambda);
  8964. rotation.invert = forwardRotationLambda(-deltaLambda);
  8965. return rotation;
  8966. }
  8967. function rotationPhiGamma(deltaPhi, deltaGamma) {
  8968. var cosDeltaPhi = cos$1(deltaPhi),
  8969. sinDeltaPhi = sin$1(deltaPhi),
  8970. cosDeltaGamma = cos$1(deltaGamma),
  8971. sinDeltaGamma = sin$1(deltaGamma);
  8972. function rotation(lambda, phi) {
  8973. var cosPhi = cos$1(phi),
  8974. x = cos$1(lambda) * cosPhi,
  8975. y = sin$1(lambda) * cosPhi,
  8976. z = sin$1(phi),
  8977. k = z * cosDeltaPhi + x * sinDeltaPhi;
  8978. return [
  8979. atan2$1(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  8980. asin$1(k * cosDeltaGamma + y * sinDeltaGamma)
  8981. ];
  8982. }
  8983. rotation.invert = function(lambda, phi) {
  8984. var cosPhi = cos$1(phi),
  8985. x = cos$1(lambda) * cosPhi,
  8986. y = sin$1(lambda) * cosPhi,
  8987. z = sin$1(phi),
  8988. k = z * cosDeltaGamma - y * sinDeltaGamma;
  8989. return [
  8990. atan2$1(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  8991. asin$1(k * cosDeltaPhi - x * sinDeltaPhi)
  8992. ];
  8993. };
  8994. return rotation;
  8995. }
  8996. function rotation(rotate) {
  8997. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  8998. function forward(coordinates) {
  8999. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  9000. return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
  9001. }
  9002. forward.invert = function(coordinates) {
  9003. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  9004. return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
  9005. };
  9006. return forward;
  9007. }
  9008. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  9009. function circleStream(stream, radius, delta, direction, t0, t1) {
  9010. if (!delta) return;
  9011. var cosRadius = cos$1(radius),
  9012. sinRadius = sin$1(radius),
  9013. step = direction * delta;
  9014. if (t0 == null) {
  9015. t0 = radius + direction * tau$1;
  9016. t1 = radius - step / 2;
  9017. } else {
  9018. t0 = circleRadius(cosRadius, t0);
  9019. t1 = circleRadius(cosRadius, t1);
  9020. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$1;
  9021. }
  9022. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  9023. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  9024. stream.point(point[0], point[1]);
  9025. }
  9026. }
  9027. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  9028. function circleRadius(cosRadius, point) {
  9029. point = cartesian(point), point[0] -= cosRadius;
  9030. cartesianNormalizeInPlace(point);
  9031. var radius = acos$1(-point[1]);
  9032. return ((-point[2] < 0 ? -radius : radius) + tau$1 - epsilon$1) % tau$1;
  9033. }
  9034. function circle$1() {
  9035. var center = constant$3([0, 0]),
  9036. radius = constant$3(90),
  9037. precision = constant$3(6),
  9038. ring,
  9039. rotate,
  9040. stream = {point: point};
  9041. function point(x, y) {
  9042. ring.push(x = rotate(x, y));
  9043. x[0] *= degrees, x[1] *= degrees;
  9044. }
  9045. function circle() {
  9046. var c = center.apply(this, arguments),
  9047. r = radius.apply(this, arguments) * radians,
  9048. p = precision.apply(this, arguments) * radians;
  9049. ring = [];
  9050. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  9051. circleStream(stream, r, p, 1);
  9052. c = {type: "Polygon", coordinates: [ring]};
  9053. ring = rotate = null;
  9054. return c;
  9055. }
  9056. circle.center = function(_) {
  9057. return arguments.length ? (center = typeof _ === "function" ? _ : constant$3([+_[0], +_[1]]), circle) : center;
  9058. };
  9059. circle.radius = function(_) {
  9060. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$3(+_), circle) : radius;
  9061. };
  9062. circle.precision = function(_) {
  9063. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$3(+_), circle) : precision;
  9064. };
  9065. return circle;
  9066. }
  9067. function clipBuffer() {
  9068. var lines = [],
  9069. line;
  9070. return {
  9071. point: function(x, y, m) {
  9072. line.push([x, y, m]);
  9073. },
  9074. lineStart: function() {
  9075. lines.push(line = []);
  9076. },
  9077. lineEnd: noop$1,
  9078. rejoin: function() {
  9079. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  9080. },
  9081. result: function() {
  9082. var result = lines;
  9083. lines = [];
  9084. line = null;
  9085. return result;
  9086. }
  9087. };
  9088. }
  9089. function pointEqual(a, b) {
  9090. return abs$1(a[0] - b[0]) < epsilon$1 && abs$1(a[1] - b[1]) < epsilon$1;
  9091. }
  9092. function Intersection(point, points, other, entry) {
  9093. this.x = point;
  9094. this.z = points;
  9095. this.o = other; // another intersection
  9096. this.e = entry; // is an entry?
  9097. this.v = false; // visited
  9098. this.n = this.p = null; // next & previous
  9099. }
  9100. // A generalized polygon clipping algorithm: given a polygon that has been cut
  9101. // into its visible line segments, and rejoins the segments by interpolating
  9102. // along the clip edge.
  9103. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  9104. var subject = [],
  9105. clip = [],
  9106. i,
  9107. n;
  9108. segments.forEach(function(segment) {
  9109. if ((n = segment.length - 1) <= 0) return;
  9110. var n, p0 = segment[0], p1 = segment[n], x;
  9111. if (pointEqual(p0, p1)) {
  9112. if (!p0[2] && !p1[2]) {
  9113. stream.lineStart();
  9114. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  9115. stream.lineEnd();
  9116. return;
  9117. }
  9118. // handle degenerate cases by moving the point
  9119. p1[0] += 2 * epsilon$1;
  9120. }
  9121. subject.push(x = new Intersection(p0, segment, null, true));
  9122. clip.push(x.o = new Intersection(p0, null, x, false));
  9123. subject.push(x = new Intersection(p1, segment, null, false));
  9124. clip.push(x.o = new Intersection(p1, null, x, true));
  9125. });
  9126. if (!subject.length) return;
  9127. clip.sort(compareIntersection);
  9128. link$1(subject);
  9129. link$1(clip);
  9130. for (i = 0, n = clip.length; i < n; ++i) {
  9131. clip[i].e = startInside = !startInside;
  9132. }
  9133. var start = subject[0],
  9134. points,
  9135. point;
  9136. while (1) {
  9137. // Find first unvisited intersection.
  9138. var current = start,
  9139. isSubject = true;
  9140. while (current.v) if ((current = current.n) === start) return;
  9141. points = current.z;
  9142. stream.lineStart();
  9143. do {
  9144. current.v = current.o.v = true;
  9145. if (current.e) {
  9146. if (isSubject) {
  9147. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  9148. } else {
  9149. interpolate(current.x, current.n.x, 1, stream);
  9150. }
  9151. current = current.n;
  9152. } else {
  9153. if (isSubject) {
  9154. points = current.p.z;
  9155. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  9156. } else {
  9157. interpolate(current.x, current.p.x, -1, stream);
  9158. }
  9159. current = current.p;
  9160. }
  9161. current = current.o;
  9162. points = current.z;
  9163. isSubject = !isSubject;
  9164. } while (!current.v);
  9165. stream.lineEnd();
  9166. }
  9167. }
  9168. function link$1(array) {
  9169. if (!(n = array.length)) return;
  9170. var n,
  9171. i = 0,
  9172. a = array[0],
  9173. b;
  9174. while (++i < n) {
  9175. a.n = b = array[i];
  9176. b.p = a;
  9177. a = b;
  9178. }
  9179. a.n = b = array[0];
  9180. b.p = a;
  9181. }
  9182. function longitude(point) {
  9183. return abs$1(point[0]) <= pi$1 ? point[0] : sign$1(point[0]) * ((abs$1(point[0]) + pi$1) % tau$1 - pi$1);
  9184. }
  9185. function polygonContains(polygon, point) {
  9186. var lambda = longitude(point),
  9187. phi = point[1],
  9188. sinPhi = sin$1(phi),
  9189. normal = [sin$1(lambda), -cos$1(lambda), 0],
  9190. angle = 0,
  9191. winding = 0;
  9192. var sum = new Adder();
  9193. if (sinPhi === 1) phi = halfPi$1 + epsilon$1;
  9194. else if (sinPhi === -1) phi = -halfPi$1 - epsilon$1;
  9195. for (var i = 0, n = polygon.length; i < n; ++i) {
  9196. if (!(m = (ring = polygon[i]).length)) continue;
  9197. var ring,
  9198. m,
  9199. point0 = ring[m - 1],
  9200. lambda0 = longitude(point0),
  9201. phi0 = point0[1] / 2 + quarterPi,
  9202. sinPhi0 = sin$1(phi0),
  9203. cosPhi0 = cos$1(phi0);
  9204. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  9205. var point1 = ring[j],
  9206. lambda1 = longitude(point1),
  9207. phi1 = point1[1] / 2 + quarterPi,
  9208. sinPhi1 = sin$1(phi1),
  9209. cosPhi1 = cos$1(phi1),
  9210. delta = lambda1 - lambda0,
  9211. sign = delta >= 0 ? 1 : -1,
  9212. absDelta = sign * delta,
  9213. antimeridian = absDelta > pi$1,
  9214. k = sinPhi0 * sinPhi1;
  9215. sum.add(atan2$1(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  9216. angle += antimeridian ? delta + sign * tau$1 : delta;
  9217. // Are the longitudes either side of the point’s meridian (lambda),
  9218. // and are the latitudes smaller than the parallel (phi)?
  9219. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  9220. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  9221. cartesianNormalizeInPlace(arc);
  9222. var intersection = cartesianCross(normal, arc);
  9223. cartesianNormalizeInPlace(intersection);
  9224. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
  9225. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  9226. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  9227. }
  9228. }
  9229. }
  9230. }
  9231. // First, determine whether the South pole is inside or outside:
  9232. //
  9233. // It is inside if:
  9234. // * the polygon winds around it in a clockwise direction.
  9235. // * the polygon does not (cumulatively) wind around it, but has a negative
  9236. // (counter-clockwise) area.
  9237. //
  9238. // Second, count the (signed) number of times a segment crosses a lambda
  9239. // from the point to the South pole. If it is zero, then the point is the
  9240. // same side as the South pole.
  9241. return (angle < -epsilon$1 || angle < epsilon$1 && sum < -epsilon2) ^ (winding & 1);
  9242. }
  9243. function clip(pointVisible, clipLine, interpolate, start) {
  9244. return function(sink) {
  9245. var line = clipLine(sink),
  9246. ringBuffer = clipBuffer(),
  9247. ringSink = clipLine(ringBuffer),
  9248. polygonStarted = false,
  9249. polygon,
  9250. segments,
  9251. ring;
  9252. var clip = {
  9253. point: point,
  9254. lineStart: lineStart,
  9255. lineEnd: lineEnd,
  9256. polygonStart: function() {
  9257. clip.point = pointRing;
  9258. clip.lineStart = ringStart;
  9259. clip.lineEnd = ringEnd;
  9260. segments = [];
  9261. polygon = [];
  9262. },
  9263. polygonEnd: function() {
  9264. clip.point = point;
  9265. clip.lineStart = lineStart;
  9266. clip.lineEnd = lineEnd;
  9267. segments = merge(segments);
  9268. var startInside = polygonContains(polygon, start);
  9269. if (segments.length) {
  9270. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  9271. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  9272. } else if (startInside) {
  9273. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  9274. sink.lineStart();
  9275. interpolate(null, null, 1, sink);
  9276. sink.lineEnd();
  9277. }
  9278. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  9279. segments = polygon = null;
  9280. },
  9281. sphere: function() {
  9282. sink.polygonStart();
  9283. sink.lineStart();
  9284. interpolate(null, null, 1, sink);
  9285. sink.lineEnd();
  9286. sink.polygonEnd();
  9287. }
  9288. };
  9289. function point(lambda, phi) {
  9290. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  9291. }
  9292. function pointLine(lambda, phi) {
  9293. line.point(lambda, phi);
  9294. }
  9295. function lineStart() {
  9296. clip.point = pointLine;
  9297. line.lineStart();
  9298. }
  9299. function lineEnd() {
  9300. clip.point = point;
  9301. line.lineEnd();
  9302. }
  9303. function pointRing(lambda, phi) {
  9304. ring.push([lambda, phi]);
  9305. ringSink.point(lambda, phi);
  9306. }
  9307. function ringStart() {
  9308. ringSink.lineStart();
  9309. ring = [];
  9310. }
  9311. function ringEnd() {
  9312. pointRing(ring[0][0], ring[0][1]);
  9313. ringSink.lineEnd();
  9314. var clean = ringSink.clean(),
  9315. ringSegments = ringBuffer.result(),
  9316. i, n = ringSegments.length, m,
  9317. segment,
  9318. point;
  9319. ring.pop();
  9320. polygon.push(ring);
  9321. ring = null;
  9322. if (!n) return;
  9323. // No intersections.
  9324. if (clean & 1) {
  9325. segment = ringSegments[0];
  9326. if ((m = segment.length - 1) > 0) {
  9327. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  9328. sink.lineStart();
  9329. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  9330. sink.lineEnd();
  9331. }
  9332. return;
  9333. }
  9334. // Rejoin connected segments.
  9335. // TODO reuse ringBuffer.rejoin()?
  9336. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  9337. segments.push(ringSegments.filter(validSegment));
  9338. }
  9339. return clip;
  9340. };
  9341. }
  9342. function validSegment(segment) {
  9343. return segment.length > 1;
  9344. }
  9345. // Intersections are sorted along the clip edge. For both antimeridian cutting
  9346. // and circle clipping, the same comparison is used.
  9347. function compareIntersection(a, b) {
  9348. return ((a = a.x)[0] < 0 ? a[1] - halfPi$1 - epsilon$1 : halfPi$1 - a[1])
  9349. - ((b = b.x)[0] < 0 ? b[1] - halfPi$1 - epsilon$1 : halfPi$1 - b[1]);
  9350. }
  9351. var clipAntimeridian = clip(
  9352. function() { return true; },
  9353. clipAntimeridianLine,
  9354. clipAntimeridianInterpolate,
  9355. [-pi$1, -halfPi$1]
  9356. );
  9357. // Takes a line and cuts into visible segments. Return values: 0 - there were
  9358. // intersections or the line was empty; 1 - no intersections; 2 - there were
  9359. // intersections, and the first and last segments should be rejoined.
  9360. function clipAntimeridianLine(stream) {
  9361. var lambda0 = NaN,
  9362. phi0 = NaN,
  9363. sign0 = NaN,
  9364. clean; // no intersections
  9365. return {
  9366. lineStart: function() {
  9367. stream.lineStart();
  9368. clean = 1;
  9369. },
  9370. point: function(lambda1, phi1) {
  9371. var sign1 = lambda1 > 0 ? pi$1 : -pi$1,
  9372. delta = abs$1(lambda1 - lambda0);
  9373. if (abs$1(delta - pi$1) < epsilon$1) { // line crosses a pole
  9374. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$1 : -halfPi$1);
  9375. stream.point(sign0, phi0);
  9376. stream.lineEnd();
  9377. stream.lineStart();
  9378. stream.point(sign1, phi0);
  9379. stream.point(lambda1, phi0);
  9380. clean = 0;
  9381. } else if (sign0 !== sign1 && delta >= pi$1) { // line crosses antimeridian
  9382. if (abs$1(lambda0 - sign0) < epsilon$1) lambda0 -= sign0 * epsilon$1; // handle degeneracies
  9383. if (abs$1(lambda1 - sign1) < epsilon$1) lambda1 -= sign1 * epsilon$1;
  9384. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  9385. stream.point(sign0, phi0);
  9386. stream.lineEnd();
  9387. stream.lineStart();
  9388. stream.point(sign1, phi0);
  9389. clean = 0;
  9390. }
  9391. stream.point(lambda0 = lambda1, phi0 = phi1);
  9392. sign0 = sign1;
  9393. },
  9394. lineEnd: function() {
  9395. stream.lineEnd();
  9396. lambda0 = phi0 = NaN;
  9397. },
  9398. clean: function() {
  9399. return 2 - clean; // if intersections, rejoin first and last segments
  9400. }
  9401. };
  9402. }
  9403. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  9404. var cosPhi0,
  9405. cosPhi1,
  9406. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  9407. return abs$1(sinLambda0Lambda1) > epsilon$1
  9408. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  9409. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  9410. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  9411. : (phi0 + phi1) / 2;
  9412. }
  9413. function clipAntimeridianInterpolate(from, to, direction, stream) {
  9414. var phi;
  9415. if (from == null) {
  9416. phi = direction * halfPi$1;
  9417. stream.point(-pi$1, phi);
  9418. stream.point(0, phi);
  9419. stream.point(pi$1, phi);
  9420. stream.point(pi$1, 0);
  9421. stream.point(pi$1, -phi);
  9422. stream.point(0, -phi);
  9423. stream.point(-pi$1, -phi);
  9424. stream.point(-pi$1, 0);
  9425. stream.point(-pi$1, phi);
  9426. } else if (abs$1(from[0] - to[0]) > epsilon$1) {
  9427. var lambda = from[0] < to[0] ? pi$1 : -pi$1;
  9428. phi = direction * lambda / 2;
  9429. stream.point(-lambda, phi);
  9430. stream.point(0, phi);
  9431. stream.point(lambda, phi);
  9432. } else {
  9433. stream.point(to[0], to[1]);
  9434. }
  9435. }
  9436. function clipCircle(radius) {
  9437. var cr = cos$1(radius),
  9438. delta = 6 * radians,
  9439. smallRadius = cr > 0,
  9440. notHemisphere = abs$1(cr) > epsilon$1; // TODO optimise for this common case
  9441. function interpolate(from, to, direction, stream) {
  9442. circleStream(stream, radius, delta, direction, from, to);
  9443. }
  9444. function visible(lambda, phi) {
  9445. return cos$1(lambda) * cos$1(phi) > cr;
  9446. }
  9447. // Takes a line and cuts into visible segments. Return values used for polygon
  9448. // clipping: 0 - there were intersections or the line was empty; 1 - no
  9449. // intersections 2 - there were intersections, and the first and last segments
  9450. // should be rejoined.
  9451. function clipLine(stream) {
  9452. var point0, // previous point
  9453. c0, // code for previous point
  9454. v0, // visibility of previous point
  9455. v00, // visibility of first point
  9456. clean; // no intersections
  9457. return {
  9458. lineStart: function() {
  9459. v00 = v0 = false;
  9460. clean = 1;
  9461. },
  9462. point: function(lambda, phi) {
  9463. var point1 = [lambda, phi],
  9464. point2,
  9465. v = visible(lambda, phi),
  9466. c = smallRadius
  9467. ? v ? 0 : code(lambda, phi)
  9468. : v ? code(lambda + (lambda < 0 ? pi$1 : -pi$1), phi) : 0;
  9469. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  9470. if (v !== v0) {
  9471. point2 = intersect(point0, point1);
  9472. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2))
  9473. point1[2] = 1;
  9474. }
  9475. if (v !== v0) {
  9476. clean = 0;
  9477. if (v) {
  9478. // outside going in
  9479. stream.lineStart();
  9480. point2 = intersect(point1, point0);
  9481. stream.point(point2[0], point2[1]);
  9482. } else {
  9483. // inside going out
  9484. point2 = intersect(point0, point1);
  9485. stream.point(point2[0], point2[1], 2);
  9486. stream.lineEnd();
  9487. }
  9488. point0 = point2;
  9489. } else if (notHemisphere && point0 && smallRadius ^ v) {
  9490. var t;
  9491. // If the codes for two points are different, or are both zero,
  9492. // and there this segment intersects with the small circle.
  9493. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  9494. clean = 0;
  9495. if (smallRadius) {
  9496. stream.lineStart();
  9497. stream.point(t[0][0], t[0][1]);
  9498. stream.point(t[1][0], t[1][1]);
  9499. stream.lineEnd();
  9500. } else {
  9501. stream.point(t[1][0], t[1][1]);
  9502. stream.lineEnd();
  9503. stream.lineStart();
  9504. stream.point(t[0][0], t[0][1], 3);
  9505. }
  9506. }
  9507. }
  9508. if (v && (!point0 || !pointEqual(point0, point1))) {
  9509. stream.point(point1[0], point1[1]);
  9510. }
  9511. point0 = point1, v0 = v, c0 = c;
  9512. },
  9513. lineEnd: function() {
  9514. if (v0) stream.lineEnd();
  9515. point0 = null;
  9516. },
  9517. // Rejoin first and last segments if there were intersections and the first
  9518. // and last points were visible.
  9519. clean: function() {
  9520. return clean | ((v00 && v0) << 1);
  9521. }
  9522. };
  9523. }
  9524. // Intersects the great circle between a and b with the clip circle.
  9525. function intersect(a, b, two) {
  9526. var pa = cartesian(a),
  9527. pb = cartesian(b);
  9528. // We have two planes, n1.p = d1 and n2.p = d2.
  9529. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  9530. var n1 = [1, 0, 0], // normal
  9531. n2 = cartesianCross(pa, pb),
  9532. n2n2 = cartesianDot(n2, n2),
  9533. n1n2 = n2[0], // cartesianDot(n1, n2),
  9534. determinant = n2n2 - n1n2 * n1n2;
  9535. // Two polar points.
  9536. if (!determinant) return !two && a;
  9537. var c1 = cr * n2n2 / determinant,
  9538. c2 = -cr * n1n2 / determinant,
  9539. n1xn2 = cartesianCross(n1, n2),
  9540. A = cartesianScale(n1, c1),
  9541. B = cartesianScale(n2, c2);
  9542. cartesianAddInPlace(A, B);
  9543. // Solve |p(t)|^2 = 1.
  9544. var u = n1xn2,
  9545. w = cartesianDot(A, u),
  9546. uu = cartesianDot(u, u),
  9547. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  9548. if (t2 < 0) return;
  9549. var t = sqrt$2(t2),
  9550. q = cartesianScale(u, (-w - t) / uu);
  9551. cartesianAddInPlace(q, A);
  9552. q = spherical(q);
  9553. if (!two) return q;
  9554. // Two intersection points.
  9555. var lambda0 = a[0],
  9556. lambda1 = b[0],
  9557. phi0 = a[1],
  9558. phi1 = b[1],
  9559. z;
  9560. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  9561. var delta = lambda1 - lambda0,
  9562. polar = abs$1(delta - pi$1) < epsilon$1,
  9563. meridian = polar || delta < epsilon$1;
  9564. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  9565. // Check that the first point is between a and b.
  9566. if (meridian
  9567. ? polar
  9568. ? phi0 + phi1 > 0 ^ q[1] < (abs$1(q[0] - lambda0) < epsilon$1 ? phi0 : phi1)
  9569. : phi0 <= q[1] && q[1] <= phi1
  9570. : delta > pi$1 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  9571. var q1 = cartesianScale(u, (-w + t) / uu);
  9572. cartesianAddInPlace(q1, A);
  9573. return [q, spherical(q1)];
  9574. }
  9575. }
  9576. // Generates a 4-bit vector representing the location of a point relative to
  9577. // the small circle's bounding box.
  9578. function code(lambda, phi) {
  9579. var r = smallRadius ? radius : pi$1 - radius,
  9580. code = 0;
  9581. if (lambda < -r) code |= 1; // left
  9582. else if (lambda > r) code |= 2; // right
  9583. if (phi < -r) code |= 4; // below
  9584. else if (phi > r) code |= 8; // above
  9585. return code;
  9586. }
  9587. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$1, radius - pi$1]);
  9588. }
  9589. function clipLine(a, b, x0, y0, x1, y1) {
  9590. var ax = a[0],
  9591. ay = a[1],
  9592. bx = b[0],
  9593. by = b[1],
  9594. t0 = 0,
  9595. t1 = 1,
  9596. dx = bx - ax,
  9597. dy = by - ay,
  9598. r;
  9599. r = x0 - ax;
  9600. if (!dx && r > 0) return;
  9601. r /= dx;
  9602. if (dx < 0) {
  9603. if (r < t0) return;
  9604. if (r < t1) t1 = r;
  9605. } else if (dx > 0) {
  9606. if (r > t1) return;
  9607. if (r > t0) t0 = r;
  9608. }
  9609. r = x1 - ax;
  9610. if (!dx && r < 0) return;
  9611. r /= dx;
  9612. if (dx < 0) {
  9613. if (r > t1) return;
  9614. if (r > t0) t0 = r;
  9615. } else if (dx > 0) {
  9616. if (r < t0) return;
  9617. if (r < t1) t1 = r;
  9618. }
  9619. r = y0 - ay;
  9620. if (!dy && r > 0) return;
  9621. r /= dy;
  9622. if (dy < 0) {
  9623. if (r < t0) return;
  9624. if (r < t1) t1 = r;
  9625. } else if (dy > 0) {
  9626. if (r > t1) return;
  9627. if (r > t0) t0 = r;
  9628. }
  9629. r = y1 - ay;
  9630. if (!dy && r < 0) return;
  9631. r /= dy;
  9632. if (dy < 0) {
  9633. if (r > t1) return;
  9634. if (r > t0) t0 = r;
  9635. } else if (dy > 0) {
  9636. if (r < t0) return;
  9637. if (r < t1) t1 = r;
  9638. }
  9639. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  9640. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  9641. return true;
  9642. }
  9643. var clipMax = 1e9, clipMin = -clipMax;
  9644. // TODO Use d3-polygon’s polygonContains here for the ring check?
  9645. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  9646. function clipRectangle(x0, y0, x1, y1) {
  9647. function visible(x, y) {
  9648. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  9649. }
  9650. function interpolate(from, to, direction, stream) {
  9651. var a = 0, a1 = 0;
  9652. if (from == null
  9653. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  9654. || comparePoint(from, to) < 0 ^ direction > 0) {
  9655. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  9656. while ((a = (a + direction + 4) % 4) !== a1);
  9657. } else {
  9658. stream.point(to[0], to[1]);
  9659. }
  9660. }
  9661. function corner(p, direction) {
  9662. return abs$1(p[0] - x0) < epsilon$1 ? direction > 0 ? 0 : 3
  9663. : abs$1(p[0] - x1) < epsilon$1 ? direction > 0 ? 2 : 1
  9664. : abs$1(p[1] - y0) < epsilon$1 ? direction > 0 ? 1 : 0
  9665. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  9666. }
  9667. function compareIntersection(a, b) {
  9668. return comparePoint(a.x, b.x);
  9669. }
  9670. function comparePoint(a, b) {
  9671. var ca = corner(a, 1),
  9672. cb = corner(b, 1);
  9673. return ca !== cb ? ca - cb
  9674. : ca === 0 ? b[1] - a[1]
  9675. : ca === 1 ? a[0] - b[0]
  9676. : ca === 2 ? a[1] - b[1]
  9677. : b[0] - a[0];
  9678. }
  9679. return function(stream) {
  9680. var activeStream = stream,
  9681. bufferStream = clipBuffer(),
  9682. segments,
  9683. polygon,
  9684. ring,
  9685. x__, y__, v__, // first point
  9686. x_, y_, v_, // previous point
  9687. first,
  9688. clean;
  9689. var clipStream = {
  9690. point: point,
  9691. lineStart: lineStart,
  9692. lineEnd: lineEnd,
  9693. polygonStart: polygonStart,
  9694. polygonEnd: polygonEnd
  9695. };
  9696. function point(x, y) {
  9697. if (visible(x, y)) activeStream.point(x, y);
  9698. }
  9699. function polygonInside() {
  9700. var winding = 0;
  9701. for (var i = 0, n = polygon.length; i < n; ++i) {
  9702. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  9703. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  9704. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  9705. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  9706. }
  9707. }
  9708. return winding;
  9709. }
  9710. // Buffer geometry within a polygon and then clip it en masse.
  9711. function polygonStart() {
  9712. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  9713. }
  9714. function polygonEnd() {
  9715. var startInside = polygonInside(),
  9716. cleanInside = clean && startInside,
  9717. visible = (segments = merge(segments)).length;
  9718. if (cleanInside || visible) {
  9719. stream.polygonStart();
  9720. if (cleanInside) {
  9721. stream.lineStart();
  9722. interpolate(null, null, 1, stream);
  9723. stream.lineEnd();
  9724. }
  9725. if (visible) {
  9726. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  9727. }
  9728. stream.polygonEnd();
  9729. }
  9730. activeStream = stream, segments = polygon = ring = null;
  9731. }
  9732. function lineStart() {
  9733. clipStream.point = linePoint;
  9734. if (polygon) polygon.push(ring = []);
  9735. first = true;
  9736. v_ = false;
  9737. x_ = y_ = NaN;
  9738. }
  9739. // TODO rather than special-case polygons, simply handle them separately.
  9740. // Ideally, coincident intersection points should be jittered to avoid
  9741. // clipping issues.
  9742. function lineEnd() {
  9743. if (segments) {
  9744. linePoint(x__, y__);
  9745. if (v__ && v_) bufferStream.rejoin();
  9746. segments.push(bufferStream.result());
  9747. }
  9748. clipStream.point = point;
  9749. if (v_) activeStream.lineEnd();
  9750. }
  9751. function linePoint(x, y) {
  9752. var v = visible(x, y);
  9753. if (polygon) ring.push([x, y]);
  9754. if (first) {
  9755. x__ = x, y__ = y, v__ = v;
  9756. first = false;
  9757. if (v) {
  9758. activeStream.lineStart();
  9759. activeStream.point(x, y);
  9760. }
  9761. } else {
  9762. if (v && v_) activeStream.point(x, y);
  9763. else {
  9764. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  9765. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  9766. if (clipLine(a, b, x0, y0, x1, y1)) {
  9767. if (!v_) {
  9768. activeStream.lineStart();
  9769. activeStream.point(a[0], a[1]);
  9770. }
  9771. activeStream.point(b[0], b[1]);
  9772. if (!v) activeStream.lineEnd();
  9773. clean = false;
  9774. } else if (v) {
  9775. activeStream.lineStart();
  9776. activeStream.point(x, y);
  9777. clean = false;
  9778. }
  9779. }
  9780. }
  9781. x_ = x, y_ = y, v_ = v;
  9782. }
  9783. return clipStream;
  9784. };
  9785. }
  9786. function extent() {
  9787. var x0 = 0,
  9788. y0 = 0,
  9789. x1 = 960,
  9790. y1 = 500,
  9791. cache,
  9792. cacheStream,
  9793. clip;
  9794. return clip = {
  9795. stream: function(stream) {
  9796. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  9797. },
  9798. extent: function(_) {
  9799. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  9800. }
  9801. };
  9802. }
  9803. var lengthSum$1,
  9804. lambda0,
  9805. sinPhi0,
  9806. cosPhi0;
  9807. var lengthStream$1 = {
  9808. sphere: noop$1,
  9809. point: noop$1,
  9810. lineStart: lengthLineStart,
  9811. lineEnd: noop$1,
  9812. polygonStart: noop$1,
  9813. polygonEnd: noop$1
  9814. };
  9815. function lengthLineStart() {
  9816. lengthStream$1.point = lengthPointFirst$1;
  9817. lengthStream$1.lineEnd = lengthLineEnd;
  9818. }
  9819. function lengthLineEnd() {
  9820. lengthStream$1.point = lengthStream$1.lineEnd = noop$1;
  9821. }
  9822. function lengthPointFirst$1(lambda, phi) {
  9823. lambda *= radians, phi *= radians;
  9824. lambda0 = lambda, sinPhi0 = sin$1(phi), cosPhi0 = cos$1(phi);
  9825. lengthStream$1.point = lengthPoint$1;
  9826. }
  9827. function lengthPoint$1(lambda, phi) {
  9828. lambda *= radians, phi *= radians;
  9829. var sinPhi = sin$1(phi),
  9830. cosPhi = cos$1(phi),
  9831. delta = abs$1(lambda - lambda0),
  9832. cosDelta = cos$1(delta),
  9833. sinDelta = sin$1(delta),
  9834. x = cosPhi * sinDelta,
  9835. y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta,
  9836. z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta;
  9837. lengthSum$1.add(atan2$1(sqrt$2(x * x + y * y), z));
  9838. lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi;
  9839. }
  9840. function length$1(object) {
  9841. lengthSum$1 = new Adder();
  9842. geoStream(object, lengthStream$1);
  9843. return +lengthSum$1;
  9844. }
  9845. var coordinates = [null, null],
  9846. object = {type: "LineString", coordinates: coordinates};
  9847. function distance(a, b) {
  9848. coordinates[0] = a;
  9849. coordinates[1] = b;
  9850. return length$1(object);
  9851. }
  9852. var containsObjectType = {
  9853. Feature: function(object, point) {
  9854. return containsGeometry(object.geometry, point);
  9855. },
  9856. FeatureCollection: function(object, point) {
  9857. var features = object.features, i = -1, n = features.length;
  9858. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  9859. return false;
  9860. }
  9861. };
  9862. var containsGeometryType = {
  9863. Sphere: function() {
  9864. return true;
  9865. },
  9866. Point: function(object, point) {
  9867. return containsPoint(object.coordinates, point);
  9868. },
  9869. MultiPoint: function(object, point) {
  9870. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9871. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  9872. return false;
  9873. },
  9874. LineString: function(object, point) {
  9875. return containsLine(object.coordinates, point);
  9876. },
  9877. MultiLineString: function(object, point) {
  9878. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9879. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  9880. return false;
  9881. },
  9882. Polygon: function(object, point) {
  9883. return containsPolygon(object.coordinates, point);
  9884. },
  9885. MultiPolygon: function(object, point) {
  9886. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9887. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  9888. return false;
  9889. },
  9890. GeometryCollection: function(object, point) {
  9891. var geometries = object.geometries, i = -1, n = geometries.length;
  9892. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  9893. return false;
  9894. }
  9895. };
  9896. function containsGeometry(geometry, point) {
  9897. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  9898. ? containsGeometryType[geometry.type](geometry, point)
  9899. : false;
  9900. }
  9901. function containsPoint(coordinates, point) {
  9902. return distance(coordinates, point) === 0;
  9903. }
  9904. function containsLine(coordinates, point) {
  9905. var ao, bo, ab;
  9906. for (var i = 0, n = coordinates.length; i < n; i++) {
  9907. bo = distance(coordinates[i], point);
  9908. if (bo === 0) return true;
  9909. if (i > 0) {
  9910. ab = distance(coordinates[i], coordinates[i - 1]);
  9911. if (
  9912. ab > 0 &&
  9913. ao <= ab &&
  9914. bo <= ab &&
  9915. (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2 * ab
  9916. )
  9917. return true;
  9918. }
  9919. ao = bo;
  9920. }
  9921. return false;
  9922. }
  9923. function containsPolygon(coordinates, point) {
  9924. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  9925. }
  9926. function ringRadians(ring) {
  9927. return ring = ring.map(pointRadians), ring.pop(), ring;
  9928. }
  9929. function pointRadians(point) {
  9930. return [point[0] * radians, point[1] * radians];
  9931. }
  9932. function contains$1(object, point) {
  9933. return (object && containsObjectType.hasOwnProperty(object.type)
  9934. ? containsObjectType[object.type]
  9935. : containsGeometry)(object, point);
  9936. }
  9937. function graticuleX(y0, y1, dy) {
  9938. var y = range$2(y0, y1 - epsilon$1, dy).concat(y1);
  9939. return function(x) { return y.map(function(y) { return [x, y]; }); };
  9940. }
  9941. function graticuleY(x0, x1, dx) {
  9942. var x = range$2(x0, x1 - epsilon$1, dx).concat(x1);
  9943. return function(y) { return x.map(function(x) { return [x, y]; }); };
  9944. }
  9945. function graticule() {
  9946. var x1, x0, X1, X0,
  9947. y1, y0, Y1, Y0,
  9948. dx = 10, dy = dx, DX = 90, DY = 360,
  9949. x, y, X, Y,
  9950. precision = 2.5;
  9951. function graticule() {
  9952. return {type: "MultiLineString", coordinates: lines()};
  9953. }
  9954. function lines() {
  9955. return range$2(ceil(X0 / DX) * DX, X1, DX).map(X)
  9956. .concat(range$2(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  9957. .concat(range$2(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs$1(x % DX) > epsilon$1; }).map(x))
  9958. .concat(range$2(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs$1(y % DY) > epsilon$1; }).map(y));
  9959. }
  9960. graticule.lines = function() {
  9961. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  9962. };
  9963. graticule.outline = function() {
  9964. return {
  9965. type: "Polygon",
  9966. coordinates: [
  9967. X(X0).concat(
  9968. Y(Y1).slice(1),
  9969. X(X1).reverse().slice(1),
  9970. Y(Y0).reverse().slice(1))
  9971. ]
  9972. };
  9973. };
  9974. graticule.extent = function(_) {
  9975. if (!arguments.length) return graticule.extentMinor();
  9976. return graticule.extentMajor(_).extentMinor(_);
  9977. };
  9978. graticule.extentMajor = function(_) {
  9979. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  9980. X0 = +_[0][0], X1 = +_[1][0];
  9981. Y0 = +_[0][1], Y1 = +_[1][1];
  9982. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  9983. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  9984. return graticule.precision(precision);
  9985. };
  9986. graticule.extentMinor = function(_) {
  9987. if (!arguments.length) return [[x0, y0], [x1, y1]];
  9988. x0 = +_[0][0], x1 = +_[1][0];
  9989. y0 = +_[0][1], y1 = +_[1][1];
  9990. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  9991. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  9992. return graticule.precision(precision);
  9993. };
  9994. graticule.step = function(_) {
  9995. if (!arguments.length) return graticule.stepMinor();
  9996. return graticule.stepMajor(_).stepMinor(_);
  9997. };
  9998. graticule.stepMajor = function(_) {
  9999. if (!arguments.length) return [DX, DY];
  10000. DX = +_[0], DY = +_[1];
  10001. return graticule;
  10002. };
  10003. graticule.stepMinor = function(_) {
  10004. if (!arguments.length) return [dx, dy];
  10005. dx = +_[0], dy = +_[1];
  10006. return graticule;
  10007. };
  10008. graticule.precision = function(_) {
  10009. if (!arguments.length) return precision;
  10010. precision = +_;
  10011. x = graticuleX(y0, y1, 90);
  10012. y = graticuleY(x0, x1, precision);
  10013. X = graticuleX(Y0, Y1, 90);
  10014. Y = graticuleY(X0, X1, precision);
  10015. return graticule;
  10016. };
  10017. return graticule
  10018. .extentMajor([[-180, -90 + epsilon$1], [180, 90 - epsilon$1]])
  10019. .extentMinor([[-180, -80 - epsilon$1], [180, 80 + epsilon$1]]);
  10020. }
  10021. function graticule10() {
  10022. return graticule()();
  10023. }
  10024. function interpolate(a, b) {
  10025. var x0 = a[0] * radians,
  10026. y0 = a[1] * radians,
  10027. x1 = b[0] * radians,
  10028. y1 = b[1] * radians,
  10029. cy0 = cos$1(y0),
  10030. sy0 = sin$1(y0),
  10031. cy1 = cos$1(y1),
  10032. sy1 = sin$1(y1),
  10033. kx0 = cy0 * cos$1(x0),
  10034. ky0 = cy0 * sin$1(x0),
  10035. kx1 = cy1 * cos$1(x1),
  10036. ky1 = cy1 * sin$1(x1),
  10037. d = 2 * asin$1(sqrt$2(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  10038. k = sin$1(d);
  10039. var interpolate = d ? function(t) {
  10040. var B = sin$1(t *= d) / k,
  10041. A = sin$1(d - t) / k,
  10042. x = A * kx0 + B * kx1,
  10043. y = A * ky0 + B * ky1,
  10044. z = A * sy0 + B * sy1;
  10045. return [
  10046. atan2$1(y, x) * degrees,
  10047. atan2$1(z, sqrt$2(x * x + y * y)) * degrees
  10048. ];
  10049. } : function() {
  10050. return [x0 * degrees, y0 * degrees];
  10051. };
  10052. interpolate.distance = d;
  10053. return interpolate;
  10054. }
  10055. var identity$5 = x => x;
  10056. var areaSum = new Adder(),
  10057. areaRingSum = new Adder(),
  10058. x00$2,
  10059. y00$2,
  10060. x0$3,
  10061. y0$3;
  10062. var areaStream = {
  10063. point: noop$1,
  10064. lineStart: noop$1,
  10065. lineEnd: noop$1,
  10066. polygonStart: function() {
  10067. areaStream.lineStart = areaRingStart;
  10068. areaStream.lineEnd = areaRingEnd;
  10069. },
  10070. polygonEnd: function() {
  10071. areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop$1;
  10072. areaSum.add(abs$1(areaRingSum));
  10073. areaRingSum = new Adder();
  10074. },
  10075. result: function() {
  10076. var area = areaSum / 2;
  10077. areaSum = new Adder();
  10078. return area;
  10079. }
  10080. };
  10081. function areaRingStart() {
  10082. areaStream.point = areaPointFirst;
  10083. }
  10084. function areaPointFirst(x, y) {
  10085. areaStream.point = areaPoint;
  10086. x00$2 = x0$3 = x, y00$2 = y0$3 = y;
  10087. }
  10088. function areaPoint(x, y) {
  10089. areaRingSum.add(y0$3 * x - x0$3 * y);
  10090. x0$3 = x, y0$3 = y;
  10091. }
  10092. function areaRingEnd() {
  10093. areaPoint(x00$2, y00$2);
  10094. }
  10095. var pathArea = areaStream;
  10096. var x0$2 = Infinity,
  10097. y0$2 = x0$2,
  10098. x1 = -x0$2,
  10099. y1 = x1;
  10100. var boundsStream = {
  10101. point: boundsPoint,
  10102. lineStart: noop$1,
  10103. lineEnd: noop$1,
  10104. polygonStart: noop$1,
  10105. polygonEnd: noop$1,
  10106. result: function() {
  10107. var bounds = [[x0$2, y0$2], [x1, y1]];
  10108. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  10109. return bounds;
  10110. }
  10111. };
  10112. function boundsPoint(x, y) {
  10113. if (x < x0$2) x0$2 = x;
  10114. if (x > x1) x1 = x;
  10115. if (y < y0$2) y0$2 = y;
  10116. if (y > y1) y1 = y;
  10117. }
  10118. var boundsStream$1 = boundsStream;
  10119. // TODO Enforce positive area for exterior, negative area for interior?
  10120. var X0 = 0,
  10121. Y0 = 0,
  10122. Z0 = 0,
  10123. X1 = 0,
  10124. Y1 = 0,
  10125. Z1 = 0,
  10126. X2 = 0,
  10127. Y2 = 0,
  10128. Z2 = 0,
  10129. x00$1,
  10130. y00$1,
  10131. x0$1,
  10132. y0$1;
  10133. var centroidStream = {
  10134. point: centroidPoint,
  10135. lineStart: centroidLineStart,
  10136. lineEnd: centroidLineEnd,
  10137. polygonStart: function() {
  10138. centroidStream.lineStart = centroidRingStart;
  10139. centroidStream.lineEnd = centroidRingEnd;
  10140. },
  10141. polygonEnd: function() {
  10142. centroidStream.point = centroidPoint;
  10143. centroidStream.lineStart = centroidLineStart;
  10144. centroidStream.lineEnd = centroidLineEnd;
  10145. },
  10146. result: function() {
  10147. var centroid = Z2 ? [X2 / Z2, Y2 / Z2]
  10148. : Z1 ? [X1 / Z1, Y1 / Z1]
  10149. : Z0 ? [X0 / Z0, Y0 / Z0]
  10150. : [NaN, NaN];
  10151. X0 = Y0 = Z0 =
  10152. X1 = Y1 = Z1 =
  10153. X2 = Y2 = Z2 = 0;
  10154. return centroid;
  10155. }
  10156. };
  10157. function centroidPoint(x, y) {
  10158. X0 += x;
  10159. Y0 += y;
  10160. ++Z0;
  10161. }
  10162. function centroidLineStart() {
  10163. centroidStream.point = centroidPointFirstLine;
  10164. }
  10165. function centroidPointFirstLine(x, y) {
  10166. centroidStream.point = centroidPointLine;
  10167. centroidPoint(x0$1 = x, y0$1 = y);
  10168. }
  10169. function centroidPointLine(x, y) {
  10170. var dx = x - x0$1, dy = y - y0$1, z = sqrt$2(dx * dx + dy * dy);
  10171. X1 += z * (x0$1 + x) / 2;
  10172. Y1 += z * (y0$1 + y) / 2;
  10173. Z1 += z;
  10174. centroidPoint(x0$1 = x, y0$1 = y);
  10175. }
  10176. function centroidLineEnd() {
  10177. centroidStream.point = centroidPoint;
  10178. }
  10179. function centroidRingStart() {
  10180. centroidStream.point = centroidPointFirstRing;
  10181. }
  10182. function centroidRingEnd() {
  10183. centroidPointRing(x00$1, y00$1);
  10184. }
  10185. function centroidPointFirstRing(x, y) {
  10186. centroidStream.point = centroidPointRing;
  10187. centroidPoint(x00$1 = x0$1 = x, y00$1 = y0$1 = y);
  10188. }
  10189. function centroidPointRing(x, y) {
  10190. var dx = x - x0$1,
  10191. dy = y - y0$1,
  10192. z = sqrt$2(dx * dx + dy * dy);
  10193. X1 += z * (x0$1 + x) / 2;
  10194. Y1 += z * (y0$1 + y) / 2;
  10195. Z1 += z;
  10196. z = y0$1 * x - x0$1 * y;
  10197. X2 += z * (x0$1 + x);
  10198. Y2 += z * (y0$1 + y);
  10199. Z2 += z * 3;
  10200. centroidPoint(x0$1 = x, y0$1 = y);
  10201. }
  10202. var pathCentroid = centroidStream;
  10203. function PathContext(context) {
  10204. this._context = context;
  10205. }
  10206. PathContext.prototype = {
  10207. _radius: 4.5,
  10208. pointRadius: function(_) {
  10209. return this._radius = _, this;
  10210. },
  10211. polygonStart: function() {
  10212. this._line = 0;
  10213. },
  10214. polygonEnd: function() {
  10215. this._line = NaN;
  10216. },
  10217. lineStart: function() {
  10218. this._point = 0;
  10219. },
  10220. lineEnd: function() {
  10221. if (this._line === 0) this._context.closePath();
  10222. this._point = NaN;
  10223. },
  10224. point: function(x, y) {
  10225. switch (this._point) {
  10226. case 0: {
  10227. this._context.moveTo(x, y);
  10228. this._point = 1;
  10229. break;
  10230. }
  10231. case 1: {
  10232. this._context.lineTo(x, y);
  10233. break;
  10234. }
  10235. default: {
  10236. this._context.moveTo(x + this._radius, y);
  10237. this._context.arc(x, y, this._radius, 0, tau$1);
  10238. break;
  10239. }
  10240. }
  10241. },
  10242. result: noop$1
  10243. };
  10244. var lengthSum = new Adder(),
  10245. lengthRing,
  10246. x00,
  10247. y00,
  10248. x0,
  10249. y0;
  10250. var lengthStream = {
  10251. point: noop$1,
  10252. lineStart: function() {
  10253. lengthStream.point = lengthPointFirst;
  10254. },
  10255. lineEnd: function() {
  10256. if (lengthRing) lengthPoint(x00, y00);
  10257. lengthStream.point = noop$1;
  10258. },
  10259. polygonStart: function() {
  10260. lengthRing = true;
  10261. },
  10262. polygonEnd: function() {
  10263. lengthRing = null;
  10264. },
  10265. result: function() {
  10266. var length = +lengthSum;
  10267. lengthSum = new Adder();
  10268. return length;
  10269. }
  10270. };
  10271. function lengthPointFirst(x, y) {
  10272. lengthStream.point = lengthPoint;
  10273. x00 = x0 = x, y00 = y0 = y;
  10274. }
  10275. function lengthPoint(x, y) {
  10276. x0 -= x, y0 -= y;
  10277. lengthSum.add(sqrt$2(x0 * x0 + y0 * y0));
  10278. x0 = x, y0 = y;
  10279. }
  10280. var pathMeasure = lengthStream;
  10281. // Simple caching for constant-radius points.
  10282. let cacheDigits, cacheAppend, cacheRadius, cacheCircle;
  10283. class PathString {
  10284. constructor(digits) {
  10285. this._append = digits == null ? append : appendRound(digits);
  10286. this._radius = 4.5;
  10287. this._ = "";
  10288. }
  10289. pointRadius(_) {
  10290. this._radius = +_;
  10291. return this;
  10292. }
  10293. polygonStart() {
  10294. this._line = 0;
  10295. }
  10296. polygonEnd() {
  10297. this._line = NaN;
  10298. }
  10299. lineStart() {
  10300. this._point = 0;
  10301. }
  10302. lineEnd() {
  10303. if (this._line === 0) this._ += "Z";
  10304. this._point = NaN;
  10305. }
  10306. point(x, y) {
  10307. switch (this._point) {
  10308. case 0: {
  10309. this._append`M${x},${y}`;
  10310. this._point = 1;
  10311. break;
  10312. }
  10313. case 1: {
  10314. this._append`L${x},${y}`;
  10315. break;
  10316. }
  10317. default: {
  10318. this._append`M${x},${y}`;
  10319. if (this._radius !== cacheRadius || this._append !== cacheAppend) {
  10320. const r = this._radius;
  10321. const s = this._;
  10322. this._ = ""; // stash the old string so we can cache the circle path fragment
  10323. this._append`m0,${r}a${r},${r} 0 1,1 0,${-2 * r}a${r},${r} 0 1,1 0,${2 * r}z`;
  10324. cacheRadius = r;
  10325. cacheAppend = this._append;
  10326. cacheCircle = this._;
  10327. this._ = s;
  10328. }
  10329. this._ += cacheCircle;
  10330. break;
  10331. }
  10332. }
  10333. }
  10334. result() {
  10335. const result = this._;
  10336. this._ = "";
  10337. return result.length ? result : null;
  10338. }
  10339. }
  10340. function append(strings) {
  10341. let i = 1;
  10342. this._ += strings[0];
  10343. for (const j = strings.length; i < j; ++i) {
  10344. this._ += arguments[i] + strings[i];
  10345. }
  10346. }
  10347. function appendRound(digits) {
  10348. const d = Math.floor(digits);
  10349. if (!(d >= 0)) throw new RangeError(`invalid digits: ${digits}`);
  10350. if (d > 15) return append;
  10351. if (d !== cacheDigits) {
  10352. const k = 10 ** d;
  10353. cacheDigits = d;
  10354. cacheAppend = function append(strings) {
  10355. let i = 1;
  10356. this._ += strings[0];
  10357. for (const j = strings.length; i < j; ++i) {
  10358. this._ += Math.round(arguments[i] * k) / k + strings[i];
  10359. }
  10360. };
  10361. }
  10362. return cacheAppend;
  10363. }
  10364. function index$2(projection, context) {
  10365. let digits = 3,
  10366. pointRadius = 4.5,
  10367. projectionStream,
  10368. contextStream;
  10369. function path(object) {
  10370. if (object) {
  10371. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  10372. geoStream(object, projectionStream(contextStream));
  10373. }
  10374. return contextStream.result();
  10375. }
  10376. path.area = function(object) {
  10377. geoStream(object, projectionStream(pathArea));
  10378. return pathArea.result();
  10379. };
  10380. path.measure = function(object) {
  10381. geoStream(object, projectionStream(pathMeasure));
  10382. return pathMeasure.result();
  10383. };
  10384. path.bounds = function(object) {
  10385. geoStream(object, projectionStream(boundsStream$1));
  10386. return boundsStream$1.result();
  10387. };
  10388. path.centroid = function(object) {
  10389. geoStream(object, projectionStream(pathCentroid));
  10390. return pathCentroid.result();
  10391. };
  10392. path.projection = function(_) {
  10393. if (!arguments.length) return projection;
  10394. projectionStream = _ == null ? (projection = null, identity$5) : (projection = _).stream;
  10395. return path;
  10396. };
  10397. path.context = function(_) {
  10398. if (!arguments.length) return context;
  10399. contextStream = _ == null ? (context = null, new PathString(digits)) : new PathContext(context = _);
  10400. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  10401. return path;
  10402. };
  10403. path.pointRadius = function(_) {
  10404. if (!arguments.length) return pointRadius;
  10405. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  10406. return path;
  10407. };
  10408. path.digits = function(_) {
  10409. if (!arguments.length) return digits;
  10410. if (_ == null) digits = null;
  10411. else {
  10412. const d = Math.floor(_);
  10413. if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
  10414. digits = d;
  10415. }
  10416. if (context === null) contextStream = new PathString(digits);
  10417. return path;
  10418. };
  10419. return path.projection(projection).digits(digits).context(context);
  10420. }
  10421. function transform$1(methods) {
  10422. return {
  10423. stream: transformer$3(methods)
  10424. };
  10425. }
  10426. function transformer$3(methods) {
  10427. return function(stream) {
  10428. var s = new TransformStream;
  10429. for (var key in methods) s[key] = methods[key];
  10430. s.stream = stream;
  10431. return s;
  10432. };
  10433. }
  10434. function TransformStream() {}
  10435. TransformStream.prototype = {
  10436. constructor: TransformStream,
  10437. point: function(x, y) { this.stream.point(x, y); },
  10438. sphere: function() { this.stream.sphere(); },
  10439. lineStart: function() { this.stream.lineStart(); },
  10440. lineEnd: function() { this.stream.lineEnd(); },
  10441. polygonStart: function() { this.stream.polygonStart(); },
  10442. polygonEnd: function() { this.stream.polygonEnd(); }
  10443. };
  10444. function fit(projection, fitBounds, object) {
  10445. var clip = projection.clipExtent && projection.clipExtent();
  10446. projection.scale(150).translate([0, 0]);
  10447. if (clip != null) projection.clipExtent(null);
  10448. geoStream(object, projection.stream(boundsStream$1));
  10449. fitBounds(boundsStream$1.result());
  10450. if (clip != null) projection.clipExtent(clip);
  10451. return projection;
  10452. }
  10453. function fitExtent(projection, extent, object) {
  10454. return fit(projection, function(b) {
  10455. var w = extent[1][0] - extent[0][0],
  10456. h = extent[1][1] - extent[0][1],
  10457. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  10458. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  10459. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  10460. projection.scale(150 * k).translate([x, y]);
  10461. }, object);
  10462. }
  10463. function fitSize(projection, size, object) {
  10464. return fitExtent(projection, [[0, 0], size], object);
  10465. }
  10466. function fitWidth(projection, width, object) {
  10467. return fit(projection, function(b) {
  10468. var w = +width,
  10469. k = w / (b[1][0] - b[0][0]),
  10470. x = (w - k * (b[1][0] + b[0][0])) / 2,
  10471. y = -k * b[0][1];
  10472. projection.scale(150 * k).translate([x, y]);
  10473. }, object);
  10474. }
  10475. function fitHeight(projection, height, object) {
  10476. return fit(projection, function(b) {
  10477. var h = +height,
  10478. k = h / (b[1][1] - b[0][1]),
  10479. x = -k * b[0][0],
  10480. y = (h - k * (b[1][1] + b[0][1])) / 2;
  10481. projection.scale(150 * k).translate([x, y]);
  10482. }, object);
  10483. }
  10484. var maxDepth = 16, // maximum depth of subdivision
  10485. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  10486. function resample(project, delta2) {
  10487. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  10488. }
  10489. function resampleNone(project) {
  10490. return transformer$3({
  10491. point: function(x, y) {
  10492. x = project(x, y);
  10493. this.stream.point(x[0], x[1]);
  10494. }
  10495. });
  10496. }
  10497. function resample$1(project, delta2) {
  10498. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  10499. var dx = x1 - x0,
  10500. dy = y1 - y0,
  10501. d2 = dx * dx + dy * dy;
  10502. if (d2 > 4 * delta2 && depth--) {
  10503. var a = a0 + a1,
  10504. b = b0 + b1,
  10505. c = c0 + c1,
  10506. m = sqrt$2(a * a + b * b + c * c),
  10507. phi2 = asin$1(c /= m),
  10508. lambda2 = abs$1(abs$1(c) - 1) < epsilon$1 || abs$1(lambda0 - lambda1) < epsilon$1 ? (lambda0 + lambda1) / 2 : atan2$1(b, a),
  10509. p = project(lambda2, phi2),
  10510. x2 = p[0],
  10511. y2 = p[1],
  10512. dx2 = x2 - x0,
  10513. dy2 = y2 - y0,
  10514. dz = dy * dx2 - dx * dy2;
  10515. if (dz * dz / d2 > delta2 // perpendicular projected distance
  10516. || abs$1((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  10517. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  10518. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  10519. stream.point(x2, y2);
  10520. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  10521. }
  10522. }
  10523. }
  10524. return function(stream) {
  10525. var lambda00, x00, y00, a00, b00, c00, // first point
  10526. lambda0, x0, y0, a0, b0, c0; // previous point
  10527. var resampleStream = {
  10528. point: point,
  10529. lineStart: lineStart,
  10530. lineEnd: lineEnd,
  10531. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  10532. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  10533. };
  10534. function point(x, y) {
  10535. x = project(x, y);
  10536. stream.point(x[0], x[1]);
  10537. }
  10538. function lineStart() {
  10539. x0 = NaN;
  10540. resampleStream.point = linePoint;
  10541. stream.lineStart();
  10542. }
  10543. function linePoint(lambda, phi) {
  10544. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  10545. 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);
  10546. stream.point(x0, y0);
  10547. }
  10548. function lineEnd() {
  10549. resampleStream.point = point;
  10550. stream.lineEnd();
  10551. }
  10552. function ringStart() {
  10553. lineStart();
  10554. resampleStream.point = ringPoint;
  10555. resampleStream.lineEnd = ringEnd;
  10556. }
  10557. function ringPoint(lambda, phi) {
  10558. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  10559. resampleStream.point = linePoint;
  10560. }
  10561. function ringEnd() {
  10562. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  10563. resampleStream.lineEnd = lineEnd;
  10564. lineEnd();
  10565. }
  10566. return resampleStream;
  10567. };
  10568. }
  10569. var transformRadians = transformer$3({
  10570. point: function(x, y) {
  10571. this.stream.point(x * radians, y * radians);
  10572. }
  10573. });
  10574. function transformRotate(rotate) {
  10575. return transformer$3({
  10576. point: function(x, y) {
  10577. var r = rotate(x, y);
  10578. return this.stream.point(r[0], r[1]);
  10579. }
  10580. });
  10581. }
  10582. function scaleTranslate(k, dx, dy, sx, sy) {
  10583. function transform(x, y) {
  10584. x *= sx; y *= sy;
  10585. return [dx + k * x, dy - k * y];
  10586. }
  10587. transform.invert = function(x, y) {
  10588. return [(x - dx) / k * sx, (dy - y) / k * sy];
  10589. };
  10590. return transform;
  10591. }
  10592. function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {
  10593. if (!alpha) return scaleTranslate(k, dx, dy, sx, sy);
  10594. var cosAlpha = cos$1(alpha),
  10595. sinAlpha = sin$1(alpha),
  10596. a = cosAlpha * k,
  10597. b = sinAlpha * k,
  10598. ai = cosAlpha / k,
  10599. bi = sinAlpha / k,
  10600. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  10601. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  10602. function transform(x, y) {
  10603. x *= sx; y *= sy;
  10604. return [a * x - b * y + dx, dy - b * x - a * y];
  10605. }
  10606. transform.invert = function(x, y) {
  10607. return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];
  10608. };
  10609. return transform;
  10610. }
  10611. function projection(project) {
  10612. return projectionMutator(function() { return project; })();
  10613. }
  10614. function projectionMutator(projectAt) {
  10615. var project,
  10616. k = 150, // scale
  10617. x = 480, y = 250, // translate
  10618. lambda = 0, phi = 0, // center
  10619. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  10620. alpha = 0, // post-rotate angle
  10621. sx = 1, // reflectX
  10622. sy = 1, // reflectX
  10623. theta = null, preclip = clipAntimeridian, // pre-clip angle
  10624. x0 = null, y0, x1, y1, postclip = identity$5, // post-clip extent
  10625. delta2 = 0.5, // precision
  10626. projectResample,
  10627. projectTransform,
  10628. projectRotateTransform,
  10629. cache,
  10630. cacheStream;
  10631. function projection(point) {
  10632. return projectRotateTransform(point[0] * radians, point[1] * radians);
  10633. }
  10634. function invert(point) {
  10635. point = projectRotateTransform.invert(point[0], point[1]);
  10636. return point && [point[0] * degrees, point[1] * degrees];
  10637. }
  10638. projection.stream = function(stream) {
  10639. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  10640. };
  10641. projection.preclip = function(_) {
  10642. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  10643. };
  10644. projection.postclip = function(_) {
  10645. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  10646. };
  10647. projection.clipAngle = function(_) {
  10648. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees;
  10649. };
  10650. projection.clipExtent = function(_) {
  10651. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  10652. };
  10653. projection.scale = function(_) {
  10654. return arguments.length ? (k = +_, recenter()) : k;
  10655. };
  10656. projection.translate = function(_) {
  10657. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  10658. };
  10659. projection.center = function(_) {
  10660. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees];
  10661. };
  10662. projection.rotate = function(_) {
  10663. return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees, deltaPhi * degrees, deltaGamma * degrees];
  10664. };
  10665. projection.angle = function(_) {
  10666. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees;
  10667. };
  10668. projection.reflectX = function(_) {
  10669. return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;
  10670. };
  10671. projection.reflectY = function(_) {
  10672. return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;
  10673. };
  10674. projection.precision = function(_) {
  10675. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$2(delta2);
  10676. };
  10677. projection.fitExtent = function(extent, object) {
  10678. return fitExtent(projection, extent, object);
  10679. };
  10680. projection.fitSize = function(size, object) {
  10681. return fitSize(projection, size, object);
  10682. };
  10683. projection.fitWidth = function(width, object) {
  10684. return fitWidth(projection, width, object);
  10685. };
  10686. projection.fitHeight = function(height, object) {
  10687. return fitHeight(projection, height, object);
  10688. };
  10689. function recenter() {
  10690. var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),
  10691. transform = scaleTranslateRotate(k, x - center[0], y - center[1], sx, sy, alpha);
  10692. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  10693. projectTransform = compose(project, transform);
  10694. projectRotateTransform = compose(rotate, projectTransform);
  10695. projectResample = resample(projectTransform, delta2);
  10696. return reset();
  10697. }
  10698. function reset() {
  10699. cache = cacheStream = null;
  10700. return projection;
  10701. }
  10702. return function() {
  10703. project = projectAt.apply(this, arguments);
  10704. projection.invert = project.invert && invert;
  10705. return recenter();
  10706. };
  10707. }
  10708. function conicProjection(projectAt) {
  10709. var phi0 = 0,
  10710. phi1 = pi$1 / 3,
  10711. m = projectionMutator(projectAt),
  10712. p = m(phi0, phi1);
  10713. p.parallels = function(_) {
  10714. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees, phi1 * degrees];
  10715. };
  10716. return p;
  10717. }
  10718. function cylindricalEqualAreaRaw(phi0) {
  10719. var cosPhi0 = cos$1(phi0);
  10720. function forward(lambda, phi) {
  10721. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  10722. }
  10723. forward.invert = function(x, y) {
  10724. return [x / cosPhi0, asin$1(y * cosPhi0)];
  10725. };
  10726. return forward;
  10727. }
  10728. function conicEqualAreaRaw(y0, y1) {
  10729. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  10730. // Are the parallels symmetrical around the Equator?
  10731. if (abs$1(n) < epsilon$1) return cylindricalEqualAreaRaw(y0);
  10732. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt$2(c) / n;
  10733. function project(x, y) {
  10734. var r = sqrt$2(c - 2 * n * sin$1(y)) / n;
  10735. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  10736. }
  10737. project.invert = function(x, y) {
  10738. var r0y = r0 - y,
  10739. l = atan2$1(x, abs$1(r0y)) * sign$1(r0y);
  10740. if (r0y * n < 0)
  10741. l -= pi$1 * sign$1(x) * sign$1(r0y);
  10742. return [l / n, asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  10743. };
  10744. return project;
  10745. }
  10746. function conicEqualArea() {
  10747. return conicProjection(conicEqualAreaRaw)
  10748. .scale(155.424)
  10749. .center([0, 33.6442]);
  10750. }
  10751. function albers() {
  10752. return conicEqualArea()
  10753. .parallels([29.5, 45.5])
  10754. .scale(1070)
  10755. .translate([480, 250])
  10756. .rotate([96, 0])
  10757. .center([-0.6, 38.7]);
  10758. }
  10759. // The projections must have mutually exclusive clip regions on the sphere,
  10760. // as this will avoid emitting interleaving lines and polygons.
  10761. function multiplex(streams) {
  10762. var n = streams.length;
  10763. return {
  10764. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  10765. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  10766. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  10767. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  10768. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  10769. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  10770. };
  10771. }
  10772. // A composite projection for the United States, configured by default for
  10773. // 960×500. The projection also works quite well at 960×600 if you change the
  10774. // scale to 1285 and adjust the translate accordingly. The set of standard
  10775. // parallels for each region comes from USGS, which is published here:
  10776. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  10777. function albersUsa() {
  10778. var cache,
  10779. cacheStream,
  10780. lower48 = albers(), lower48Point,
  10781. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  10782. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  10783. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  10784. function albersUsa(coordinates) {
  10785. var x = coordinates[0], y = coordinates[1];
  10786. return point = null,
  10787. (lower48Point.point(x, y), point)
  10788. || (alaskaPoint.point(x, y), point)
  10789. || (hawaiiPoint.point(x, y), point);
  10790. }
  10791. albersUsa.invert = function(coordinates) {
  10792. var k = lower48.scale(),
  10793. t = lower48.translate(),
  10794. x = (coordinates[0] - t[0]) / k,
  10795. y = (coordinates[1] - t[1]) / k;
  10796. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  10797. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  10798. : lower48).invert(coordinates);
  10799. };
  10800. albersUsa.stream = function(stream) {
  10801. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  10802. };
  10803. albersUsa.precision = function(_) {
  10804. if (!arguments.length) return lower48.precision();
  10805. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  10806. return reset();
  10807. };
  10808. albersUsa.scale = function(_) {
  10809. if (!arguments.length) return lower48.scale();
  10810. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  10811. return albersUsa.translate(lower48.translate());
  10812. };
  10813. albersUsa.translate = function(_) {
  10814. if (!arguments.length) return lower48.translate();
  10815. var k = lower48.scale(), x = +_[0], y = +_[1];
  10816. lower48Point = lower48
  10817. .translate(_)
  10818. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  10819. .stream(pointStream);
  10820. alaskaPoint = alaska
  10821. .translate([x - 0.307 * k, y + 0.201 * k])
  10822. .clipExtent([[x - 0.425 * k + epsilon$1, y + 0.120 * k + epsilon$1], [x - 0.214 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
  10823. .stream(pointStream);
  10824. hawaiiPoint = hawaii
  10825. .translate([x - 0.205 * k, y + 0.212 * k])
  10826. .clipExtent([[x - 0.214 * k + epsilon$1, y + 0.166 * k + epsilon$1], [x - 0.115 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
  10827. .stream(pointStream);
  10828. return reset();
  10829. };
  10830. albersUsa.fitExtent = function(extent, object) {
  10831. return fitExtent(albersUsa, extent, object);
  10832. };
  10833. albersUsa.fitSize = function(size, object) {
  10834. return fitSize(albersUsa, size, object);
  10835. };
  10836. albersUsa.fitWidth = function(width, object) {
  10837. return fitWidth(albersUsa, width, object);
  10838. };
  10839. albersUsa.fitHeight = function(height, object) {
  10840. return fitHeight(albersUsa, height, object);
  10841. };
  10842. function reset() {
  10843. cache = cacheStream = null;
  10844. return albersUsa;
  10845. }
  10846. return albersUsa.scale(1070);
  10847. }
  10848. function azimuthalRaw(scale) {
  10849. return function(x, y) {
  10850. var cx = cos$1(x),
  10851. cy = cos$1(y),
  10852. k = scale(cx * cy);
  10853. if (k === Infinity) return [2, 0];
  10854. return [
  10855. k * cy * sin$1(x),
  10856. k * sin$1(y)
  10857. ];
  10858. }
  10859. }
  10860. function azimuthalInvert(angle) {
  10861. return function(x, y) {
  10862. var z = sqrt$2(x * x + y * y),
  10863. c = angle(z),
  10864. sc = sin$1(c),
  10865. cc = cos$1(c);
  10866. return [
  10867. atan2$1(x * sc, z * cc),
  10868. asin$1(z && y * sc / z)
  10869. ];
  10870. }
  10871. }
  10872. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  10873. return sqrt$2(2 / (1 + cxcy));
  10874. });
  10875. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  10876. return 2 * asin$1(z / 2);
  10877. });
  10878. function azimuthalEqualArea() {
  10879. return projection(azimuthalEqualAreaRaw)
  10880. .scale(124.75)
  10881. .clipAngle(180 - 1e-3);
  10882. }
  10883. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  10884. return (c = acos$1(c)) && c / sin$1(c);
  10885. });
  10886. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  10887. return z;
  10888. });
  10889. function azimuthalEquidistant() {
  10890. return projection(azimuthalEquidistantRaw)
  10891. .scale(79.4188)
  10892. .clipAngle(180 - 1e-3);
  10893. }
  10894. function mercatorRaw(lambda, phi) {
  10895. return [lambda, log$1(tan((halfPi$1 + phi) / 2))];
  10896. }
  10897. mercatorRaw.invert = function(x, y) {
  10898. return [x, 2 * atan(exp(y)) - halfPi$1];
  10899. };
  10900. function mercator() {
  10901. return mercatorProjection(mercatorRaw)
  10902. .scale(961 / tau$1);
  10903. }
  10904. function mercatorProjection(project) {
  10905. var m = projection(project),
  10906. center = m.center,
  10907. scale = m.scale,
  10908. translate = m.translate,
  10909. clipExtent = m.clipExtent,
  10910. x0 = null, y0, x1, y1; // clip extent
  10911. m.scale = function(_) {
  10912. return arguments.length ? (scale(_), reclip()) : scale();
  10913. };
  10914. m.translate = function(_) {
  10915. return arguments.length ? (translate(_), reclip()) : translate();
  10916. };
  10917. m.center = function(_) {
  10918. return arguments.length ? (center(_), reclip()) : center();
  10919. };
  10920. m.clipExtent = function(_) {
  10921. 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]];
  10922. };
  10923. function reclip() {
  10924. var k = pi$1 * scale(),
  10925. t = m(rotation(m.rotate()).invert([0, 0]));
  10926. return clipExtent(x0 == null
  10927. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  10928. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  10929. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  10930. }
  10931. return reclip();
  10932. }
  10933. function tany(y) {
  10934. return tan((halfPi$1 + y) / 2);
  10935. }
  10936. function conicConformalRaw(y0, y1) {
  10937. var cy0 = cos$1(y0),
  10938. n = y0 === y1 ? sin$1(y0) : log$1(cy0 / cos$1(y1)) / log$1(tany(y1) / tany(y0)),
  10939. f = cy0 * pow$1(tany(y0), n) / n;
  10940. if (!n) return mercatorRaw;
  10941. function project(x, y) {
  10942. if (f > 0) { if (y < -halfPi$1 + epsilon$1) y = -halfPi$1 + epsilon$1; }
  10943. else { if (y > halfPi$1 - epsilon$1) y = halfPi$1 - epsilon$1; }
  10944. var r = f / pow$1(tany(y), n);
  10945. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  10946. }
  10947. project.invert = function(x, y) {
  10948. var fy = f - y, r = sign$1(n) * sqrt$2(x * x + fy * fy),
  10949. l = atan2$1(x, abs$1(fy)) * sign$1(fy);
  10950. if (fy * n < 0)
  10951. l -= pi$1 * sign$1(x) * sign$1(fy);
  10952. return [l / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$1];
  10953. };
  10954. return project;
  10955. }
  10956. function conicConformal() {
  10957. return conicProjection(conicConformalRaw)
  10958. .scale(109.5)
  10959. .parallels([30, 30]);
  10960. }
  10961. function equirectangularRaw(lambda, phi) {
  10962. return [lambda, phi];
  10963. }
  10964. equirectangularRaw.invert = equirectangularRaw;
  10965. function equirectangular() {
  10966. return projection(equirectangularRaw)
  10967. .scale(152.63);
  10968. }
  10969. function conicEquidistantRaw(y0, y1) {
  10970. var cy0 = cos$1(y0),
  10971. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  10972. g = cy0 / n + y0;
  10973. if (abs$1(n) < epsilon$1) return equirectangularRaw;
  10974. function project(x, y) {
  10975. var gy = g - y, nx = n * x;
  10976. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  10977. }
  10978. project.invert = function(x, y) {
  10979. var gy = g - y,
  10980. l = atan2$1(x, abs$1(gy)) * sign$1(gy);
  10981. if (gy * n < 0)
  10982. l -= pi$1 * sign$1(x) * sign$1(gy);
  10983. return [l / n, g - sign$1(n) * sqrt$2(x * x + gy * gy)];
  10984. };
  10985. return project;
  10986. }
  10987. function conicEquidistant() {
  10988. return conicProjection(conicEquidistantRaw)
  10989. .scale(131.154)
  10990. .center([0, 13.9389]);
  10991. }
  10992. var A1 = 1.340264,
  10993. A2 = -0.081106,
  10994. A3 = 0.000893,
  10995. A4 = 0.003796,
  10996. M = sqrt$2(3) / 2,
  10997. iterations = 12;
  10998. function equalEarthRaw(lambda, phi) {
  10999. var l = asin$1(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
  11000. return [
  11001. lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
  11002. l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
  11003. ];
  11004. }
  11005. equalEarthRaw.invert = function(x, y) {
  11006. var l = y, l2 = l * l, l6 = l2 * l2 * l2;
  11007. for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
  11008. fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
  11009. fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
  11010. l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
  11011. if (abs$1(delta) < epsilon2) break;
  11012. }
  11013. return [
  11014. M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
  11015. asin$1(sin$1(l) / M)
  11016. ];
  11017. };
  11018. function equalEarth() {
  11019. return projection(equalEarthRaw)
  11020. .scale(177.158);
  11021. }
  11022. function gnomonicRaw(x, y) {
  11023. var cy = cos$1(y), k = cos$1(x) * cy;
  11024. return [cy * sin$1(x) / k, sin$1(y) / k];
  11025. }
  11026. gnomonicRaw.invert = azimuthalInvert(atan);
  11027. function gnomonic() {
  11028. return projection(gnomonicRaw)
  11029. .scale(144.049)
  11030. .clipAngle(60);
  11031. }
  11032. function identity$4() {
  11033. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect
  11034. alpha = 0, ca, sa, // angle
  11035. x0 = null, y0, x1, y1, // clip extent
  11036. kx = 1, ky = 1,
  11037. transform = transformer$3({
  11038. point: function(x, y) {
  11039. var p = projection([x, y]);
  11040. this.stream.point(p[0], p[1]);
  11041. }
  11042. }),
  11043. postclip = identity$5,
  11044. cache,
  11045. cacheStream;
  11046. function reset() {
  11047. kx = k * sx;
  11048. ky = k * sy;
  11049. cache = cacheStream = null;
  11050. return projection;
  11051. }
  11052. function projection (p) {
  11053. var x = p[0] * kx, y = p[1] * ky;
  11054. if (alpha) {
  11055. var t = y * ca - x * sa;
  11056. x = x * ca + y * sa;
  11057. y = t;
  11058. }
  11059. return [x + tx, y + ty];
  11060. }
  11061. projection.invert = function(p) {
  11062. var x = p[0] - tx, y = p[1] - ty;
  11063. if (alpha) {
  11064. var t = y * ca + x * sa;
  11065. x = x * ca - y * sa;
  11066. y = t;
  11067. }
  11068. return [x / kx, y / ky];
  11069. };
  11070. projection.stream = function(stream) {
  11071. return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
  11072. };
  11073. projection.postclip = function(_) {
  11074. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  11075. };
  11076. projection.clipExtent = function(_) {
  11077. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  11078. };
  11079. projection.scale = function(_) {
  11080. return arguments.length ? (k = +_, reset()) : k;
  11081. };
  11082. projection.translate = function(_) {
  11083. return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];
  11084. };
  11085. projection.angle = function(_) {
  11086. return arguments.length ? (alpha = _ % 360 * radians, sa = sin$1(alpha), ca = cos$1(alpha), reset()) : alpha * degrees;
  11087. };
  11088. projection.reflectX = function(_) {
  11089. return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;
  11090. };
  11091. projection.reflectY = function(_) {
  11092. return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;
  11093. };
  11094. projection.fitExtent = function(extent, object) {
  11095. return fitExtent(projection, extent, object);
  11096. };
  11097. projection.fitSize = function(size, object) {
  11098. return fitSize(projection, size, object);
  11099. };
  11100. projection.fitWidth = function(width, object) {
  11101. return fitWidth(projection, width, object);
  11102. };
  11103. projection.fitHeight = function(height, object) {
  11104. return fitHeight(projection, height, object);
  11105. };
  11106. return projection;
  11107. }
  11108. function naturalEarth1Raw(lambda, phi) {
  11109. var phi2 = phi * phi, phi4 = phi2 * phi2;
  11110. return [
  11111. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  11112. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  11113. ];
  11114. }
  11115. naturalEarth1Raw.invert = function(x, y) {
  11116. var phi = y, i = 25, delta;
  11117. do {
  11118. var phi2 = phi * phi, phi4 = phi2 * phi2;
  11119. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  11120. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  11121. } while (abs$1(delta) > epsilon$1 && --i > 0);
  11122. return [
  11123. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  11124. phi
  11125. ];
  11126. };
  11127. function naturalEarth1() {
  11128. return projection(naturalEarth1Raw)
  11129. .scale(175.295);
  11130. }
  11131. function orthographicRaw(x, y) {
  11132. return [cos$1(y) * sin$1(x), sin$1(y)];
  11133. }
  11134. orthographicRaw.invert = azimuthalInvert(asin$1);
  11135. function orthographic() {
  11136. return projection(orthographicRaw)
  11137. .scale(249.5)
  11138. .clipAngle(90 + epsilon$1);
  11139. }
  11140. function stereographicRaw(x, y) {
  11141. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  11142. return [cy * sin$1(x) / k, sin$1(y) / k];
  11143. }
  11144. stereographicRaw.invert = azimuthalInvert(function(z) {
  11145. return 2 * atan(z);
  11146. });
  11147. function stereographic() {
  11148. return projection(stereographicRaw)
  11149. .scale(250)
  11150. .clipAngle(142);
  11151. }
  11152. function transverseMercatorRaw(lambda, phi) {
  11153. return [log$1(tan((halfPi$1 + phi) / 2)), -lambda];
  11154. }
  11155. transverseMercatorRaw.invert = function(x, y) {
  11156. return [-y, 2 * atan(exp(x)) - halfPi$1];
  11157. };
  11158. function transverseMercator() {
  11159. var m = mercatorProjection(transverseMercatorRaw),
  11160. center = m.center,
  11161. rotate = m.rotate;
  11162. m.center = function(_) {
  11163. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  11164. };
  11165. m.rotate = function(_) {
  11166. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  11167. };
  11168. return rotate([0, 0, 90])
  11169. .scale(159.155);
  11170. }
  11171. function defaultSeparation$1(a, b) {
  11172. return a.parent === b.parent ? 1 : 2;
  11173. }
  11174. function meanX(children) {
  11175. return children.reduce(meanXReduce, 0) / children.length;
  11176. }
  11177. function meanXReduce(x, c) {
  11178. return x + c.x;
  11179. }
  11180. function maxY(children) {
  11181. return 1 + children.reduce(maxYReduce, 0);
  11182. }
  11183. function maxYReduce(y, c) {
  11184. return Math.max(y, c.y);
  11185. }
  11186. function leafLeft(node) {
  11187. var children;
  11188. while (children = node.children) node = children[0];
  11189. return node;
  11190. }
  11191. function leafRight(node) {
  11192. var children;
  11193. while (children = node.children) node = children[children.length - 1];
  11194. return node;
  11195. }
  11196. function cluster() {
  11197. var separation = defaultSeparation$1,
  11198. dx = 1,
  11199. dy = 1,
  11200. nodeSize = false;
  11201. function cluster(root) {
  11202. var previousNode,
  11203. x = 0;
  11204. // First walk, computing the initial x & y values.
  11205. root.eachAfter(function(node) {
  11206. var children = node.children;
  11207. if (children) {
  11208. node.x = meanX(children);
  11209. node.y = maxY(children);
  11210. } else {
  11211. node.x = previousNode ? x += separation(node, previousNode) : 0;
  11212. node.y = 0;
  11213. previousNode = node;
  11214. }
  11215. });
  11216. var left = leafLeft(root),
  11217. right = leafRight(root),
  11218. x0 = left.x - separation(left, right) / 2,
  11219. x1 = right.x + separation(right, left) / 2;
  11220. // Second walk, normalizing x & y to the desired size.
  11221. return root.eachAfter(nodeSize ? function(node) {
  11222. node.x = (node.x - root.x) * dx;
  11223. node.y = (root.y - node.y) * dy;
  11224. } : function(node) {
  11225. node.x = (node.x - x0) / (x1 - x0) * dx;
  11226. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  11227. });
  11228. }
  11229. cluster.separation = function(x) {
  11230. return arguments.length ? (separation = x, cluster) : separation;
  11231. };
  11232. cluster.size = function(x) {
  11233. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  11234. };
  11235. cluster.nodeSize = function(x) {
  11236. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  11237. };
  11238. return cluster;
  11239. }
  11240. function count(node) {
  11241. var sum = 0,
  11242. children = node.children,
  11243. i = children && children.length;
  11244. if (!i) sum = 1;
  11245. else while (--i >= 0) sum += children[i].value;
  11246. node.value = sum;
  11247. }
  11248. function node_count() {
  11249. return this.eachAfter(count);
  11250. }
  11251. function node_each(callback, that) {
  11252. let index = -1;
  11253. for (const node of this) {
  11254. callback.call(that, node, ++index, this);
  11255. }
  11256. return this;
  11257. }
  11258. function node_eachBefore(callback, that) {
  11259. var node = this, nodes = [node], children, i, index = -1;
  11260. while (node = nodes.pop()) {
  11261. callback.call(that, node, ++index, this);
  11262. if (children = node.children) {
  11263. for (i = children.length - 1; i >= 0; --i) {
  11264. nodes.push(children[i]);
  11265. }
  11266. }
  11267. }
  11268. return this;
  11269. }
  11270. function node_eachAfter(callback, that) {
  11271. var node = this, nodes = [node], next = [], children, i, n, index = -1;
  11272. while (node = nodes.pop()) {
  11273. next.push(node);
  11274. if (children = node.children) {
  11275. for (i = 0, n = children.length; i < n; ++i) {
  11276. nodes.push(children[i]);
  11277. }
  11278. }
  11279. }
  11280. while (node = next.pop()) {
  11281. callback.call(that, node, ++index, this);
  11282. }
  11283. return this;
  11284. }
  11285. function node_find(callback, that) {
  11286. let index = -1;
  11287. for (const node of this) {
  11288. if (callback.call(that, node, ++index, this)) {
  11289. return node;
  11290. }
  11291. }
  11292. }
  11293. function node_sum(value) {
  11294. return this.eachAfter(function(node) {
  11295. var sum = +value(node.data) || 0,
  11296. children = node.children,
  11297. i = children && children.length;
  11298. while (--i >= 0) sum += children[i].value;
  11299. node.value = sum;
  11300. });
  11301. }
  11302. function node_sort(compare) {
  11303. return this.eachBefore(function(node) {
  11304. if (node.children) {
  11305. node.children.sort(compare);
  11306. }
  11307. });
  11308. }
  11309. function node_path(end) {
  11310. var start = this,
  11311. ancestor = leastCommonAncestor(start, end),
  11312. nodes = [start];
  11313. while (start !== ancestor) {
  11314. start = start.parent;
  11315. nodes.push(start);
  11316. }
  11317. var k = nodes.length;
  11318. while (end !== ancestor) {
  11319. nodes.splice(k, 0, end);
  11320. end = end.parent;
  11321. }
  11322. return nodes;
  11323. }
  11324. function leastCommonAncestor(a, b) {
  11325. if (a === b) return a;
  11326. var aNodes = a.ancestors(),
  11327. bNodes = b.ancestors(),
  11328. c = null;
  11329. a = aNodes.pop();
  11330. b = bNodes.pop();
  11331. while (a === b) {
  11332. c = a;
  11333. a = aNodes.pop();
  11334. b = bNodes.pop();
  11335. }
  11336. return c;
  11337. }
  11338. function node_ancestors() {
  11339. var node = this, nodes = [node];
  11340. while (node = node.parent) {
  11341. nodes.push(node);
  11342. }
  11343. return nodes;
  11344. }
  11345. function node_descendants() {
  11346. return Array.from(this);
  11347. }
  11348. function node_leaves() {
  11349. var leaves = [];
  11350. this.eachBefore(function(node) {
  11351. if (!node.children) {
  11352. leaves.push(node);
  11353. }
  11354. });
  11355. return leaves;
  11356. }
  11357. function node_links() {
  11358. var root = this, links = [];
  11359. root.each(function(node) {
  11360. if (node !== root) { // Don’t include the root’s parent, if any.
  11361. links.push({source: node.parent, target: node});
  11362. }
  11363. });
  11364. return links;
  11365. }
  11366. function* node_iterator() {
  11367. var node = this, current, next = [node], children, i, n;
  11368. do {
  11369. current = next.reverse(), next = [];
  11370. while (node = current.pop()) {
  11371. yield node;
  11372. if (children = node.children) {
  11373. for (i = 0, n = children.length; i < n; ++i) {
  11374. next.push(children[i]);
  11375. }
  11376. }
  11377. }
  11378. } while (next.length);
  11379. }
  11380. function hierarchy(data, children) {
  11381. if (data instanceof Map) {
  11382. data = [undefined, data];
  11383. if (children === undefined) children = mapChildren;
  11384. } else if (children === undefined) {
  11385. children = objectChildren;
  11386. }
  11387. var root = new Node$1(data),
  11388. node,
  11389. nodes = [root],
  11390. child,
  11391. childs,
  11392. i,
  11393. n;
  11394. while (node = nodes.pop()) {
  11395. if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
  11396. node.children = childs;
  11397. for (i = n - 1; i >= 0; --i) {
  11398. nodes.push(child = childs[i] = new Node$1(childs[i]));
  11399. child.parent = node;
  11400. child.depth = node.depth + 1;
  11401. }
  11402. }
  11403. }
  11404. return root.eachBefore(computeHeight);
  11405. }
  11406. function node_copy() {
  11407. return hierarchy(this).eachBefore(copyData);
  11408. }
  11409. function objectChildren(d) {
  11410. return d.children;
  11411. }
  11412. function mapChildren(d) {
  11413. return Array.isArray(d) ? d[1] : null;
  11414. }
  11415. function copyData(node) {
  11416. if (node.data.value !== undefined) node.value = node.data.value;
  11417. node.data = node.data.data;
  11418. }
  11419. function computeHeight(node) {
  11420. var height = 0;
  11421. do node.height = height;
  11422. while ((node = node.parent) && (node.height < ++height));
  11423. }
  11424. function Node$1(data) {
  11425. this.data = data;
  11426. this.depth =
  11427. this.height = 0;
  11428. this.parent = null;
  11429. }
  11430. Node$1.prototype = hierarchy.prototype = {
  11431. constructor: Node$1,
  11432. count: node_count,
  11433. each: node_each,
  11434. eachAfter: node_eachAfter,
  11435. eachBefore: node_eachBefore,
  11436. find: node_find,
  11437. sum: node_sum,
  11438. sort: node_sort,
  11439. path: node_path,
  11440. ancestors: node_ancestors,
  11441. descendants: node_descendants,
  11442. leaves: node_leaves,
  11443. links: node_links,
  11444. copy: node_copy,
  11445. [Symbol.iterator]: node_iterator
  11446. };
  11447. function optional(f) {
  11448. return f == null ? null : required(f);
  11449. }
  11450. function required(f) {
  11451. if (typeof f !== "function") throw new Error;
  11452. return f;
  11453. }
  11454. function constantZero() {
  11455. return 0;
  11456. }
  11457. function constant$2(x) {
  11458. return function() {
  11459. return x;
  11460. };
  11461. }
  11462. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  11463. const a$1 = 1664525;
  11464. const c$3 = 1013904223;
  11465. const m = 4294967296; // 2^32
  11466. function lcg$1() {
  11467. let s = 1;
  11468. return () => (s = (a$1 * s + c$3) % m) / m;
  11469. }
  11470. function array$1(x) {
  11471. return typeof x === "object" && "length" in x
  11472. ? x // Array, TypedArray, NodeList, array-like
  11473. : Array.from(x); // Map, Set, iterable, string, or anything else
  11474. }
  11475. function shuffle(array, random) {
  11476. let m = array.length,
  11477. t,
  11478. i;
  11479. while (m) {
  11480. i = random() * m-- | 0;
  11481. t = array[m];
  11482. array[m] = array[i];
  11483. array[i] = t;
  11484. }
  11485. return array;
  11486. }
  11487. function enclose(circles) {
  11488. return packEncloseRandom(circles, lcg$1());
  11489. }
  11490. function packEncloseRandom(circles, random) {
  11491. var i = 0, n = (circles = shuffle(Array.from(circles), random)).length, B = [], p, e;
  11492. while (i < n) {
  11493. p = circles[i];
  11494. if (e && enclosesWeak(e, p)) ++i;
  11495. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  11496. }
  11497. return e;
  11498. }
  11499. function extendBasis(B, p) {
  11500. var i, j;
  11501. if (enclosesWeakAll(p, B)) return [p];
  11502. // If we get here then B must have at least one element.
  11503. for (i = 0; i < B.length; ++i) {
  11504. if (enclosesNot(p, B[i])
  11505. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  11506. return [B[i], p];
  11507. }
  11508. }
  11509. // If we get here then B must have at least two elements.
  11510. for (i = 0; i < B.length - 1; ++i) {
  11511. for (j = i + 1; j < B.length; ++j) {
  11512. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  11513. && enclosesNot(encloseBasis2(B[i], p), B[j])
  11514. && enclosesNot(encloseBasis2(B[j], p), B[i])
  11515. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  11516. return [B[i], B[j], p];
  11517. }
  11518. }
  11519. }
  11520. // If we get here then something is very wrong.
  11521. throw new Error;
  11522. }
  11523. function enclosesNot(a, b) {
  11524. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  11525. return dr < 0 || dr * dr < dx * dx + dy * dy;
  11526. }
  11527. function enclosesWeak(a, b) {
  11528. var dr = a.r - b.r + Math.max(a.r, b.r, 1) * 1e-9, dx = b.x - a.x, dy = b.y - a.y;
  11529. return dr > 0 && dr * dr > dx * dx + dy * dy;
  11530. }
  11531. function enclosesWeakAll(a, B) {
  11532. for (var i = 0; i < B.length; ++i) {
  11533. if (!enclosesWeak(a, B[i])) {
  11534. return false;
  11535. }
  11536. }
  11537. return true;
  11538. }
  11539. function encloseBasis(B) {
  11540. switch (B.length) {
  11541. case 1: return encloseBasis1(B[0]);
  11542. case 2: return encloseBasis2(B[0], B[1]);
  11543. case 3: return encloseBasis3(B[0], B[1], B[2]);
  11544. }
  11545. }
  11546. function encloseBasis1(a) {
  11547. return {
  11548. x: a.x,
  11549. y: a.y,
  11550. r: a.r
  11551. };
  11552. }
  11553. function encloseBasis2(a, b) {
  11554. var x1 = a.x, y1 = a.y, r1 = a.r,
  11555. x2 = b.x, y2 = b.y, r2 = b.r,
  11556. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  11557. l = Math.sqrt(x21 * x21 + y21 * y21);
  11558. return {
  11559. x: (x1 + x2 + x21 / l * r21) / 2,
  11560. y: (y1 + y2 + y21 / l * r21) / 2,
  11561. r: (l + r1 + r2) / 2
  11562. };
  11563. }
  11564. function encloseBasis3(a, b, c) {
  11565. var x1 = a.x, y1 = a.y, r1 = a.r,
  11566. x2 = b.x, y2 = b.y, r2 = b.r,
  11567. x3 = c.x, y3 = c.y, r3 = c.r,
  11568. a2 = x1 - x2,
  11569. a3 = x1 - x3,
  11570. b2 = y1 - y2,
  11571. b3 = y1 - y3,
  11572. c2 = r2 - r1,
  11573. c3 = r3 - r1,
  11574. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  11575. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  11576. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  11577. ab = a3 * b2 - a2 * b3,
  11578. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  11579. xb = (b3 * c2 - b2 * c3) / ab,
  11580. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  11581. yb = (a2 * c3 - a3 * c2) / ab,
  11582. A = xb * xb + yb * yb - 1,
  11583. B = 2 * (r1 + xa * xb + ya * yb),
  11584. C = xa * xa + ya * ya - r1 * r1,
  11585. r = -(Math.abs(A) > 1e-6 ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  11586. return {
  11587. x: x1 + xa + xb * r,
  11588. y: y1 + ya + yb * r,
  11589. r: r
  11590. };
  11591. }
  11592. function place(b, a, c) {
  11593. var dx = b.x - a.x, x, a2,
  11594. dy = b.y - a.y, y, b2,
  11595. d2 = dx * dx + dy * dy;
  11596. if (d2) {
  11597. a2 = a.r + c.r, a2 *= a2;
  11598. b2 = b.r + c.r, b2 *= b2;
  11599. if (a2 > b2) {
  11600. x = (d2 + b2 - a2) / (2 * d2);
  11601. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  11602. c.x = b.x - x * dx - y * dy;
  11603. c.y = b.y - x * dy + y * dx;
  11604. } else {
  11605. x = (d2 + a2 - b2) / (2 * d2);
  11606. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  11607. c.x = a.x + x * dx - y * dy;
  11608. c.y = a.y + x * dy + y * dx;
  11609. }
  11610. } else {
  11611. c.x = a.x + c.r;
  11612. c.y = a.y;
  11613. }
  11614. }
  11615. function intersects(a, b) {
  11616. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  11617. return dr > 0 && dr * dr > dx * dx + dy * dy;
  11618. }
  11619. function score(node) {
  11620. var a = node._,
  11621. b = node.next._,
  11622. ab = a.r + b.r,
  11623. dx = (a.x * b.r + b.x * a.r) / ab,
  11624. dy = (a.y * b.r + b.y * a.r) / ab;
  11625. return dx * dx + dy * dy;
  11626. }
  11627. function Node(circle) {
  11628. this._ = circle;
  11629. this.next = null;
  11630. this.previous = null;
  11631. }
  11632. function packSiblingsRandom(circles, random) {
  11633. if (!(n = (circles = array$1(circles)).length)) return 0;
  11634. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  11635. // Place the first circle.
  11636. a = circles[0], a.x = 0, a.y = 0;
  11637. if (!(n > 1)) return a.r;
  11638. // Place the second circle.
  11639. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  11640. if (!(n > 2)) return a.r + b.r;
  11641. // Place the third circle.
  11642. place(b, a, c = circles[2]);
  11643. // Initialize the front-chain using the first three circles a, b and c.
  11644. a = new Node(a), b = new Node(b), c = new Node(c);
  11645. a.next = c.previous = b;
  11646. b.next = a.previous = c;
  11647. c.next = b.previous = a;
  11648. // Attempt to place each remaining circle…
  11649. pack: for (i = 3; i < n; ++i) {
  11650. place(a._, b._, c = circles[i]), c = new Node(c);
  11651. // Find the closest intersecting circle on the front-chain, if any.
  11652. // “Closeness” is determined by linear distance along the front-chain.
  11653. // “Ahead” or “behind” is likewise determined by linear distance.
  11654. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  11655. do {
  11656. if (sj <= sk) {
  11657. if (intersects(j._, c._)) {
  11658. b = j, a.next = b, b.previous = a, --i;
  11659. continue pack;
  11660. }
  11661. sj += j._.r, j = j.next;
  11662. } else {
  11663. if (intersects(k._, c._)) {
  11664. a = k, a.next = b, b.previous = a, --i;
  11665. continue pack;
  11666. }
  11667. sk += k._.r, k = k.previous;
  11668. }
  11669. } while (j !== k.next);
  11670. // Success! Insert the new circle c between a and b.
  11671. c.previous = a, c.next = b, a.next = b.previous = b = c;
  11672. // Compute the new closest circle pair to the centroid.
  11673. aa = score(a);
  11674. while ((c = c.next) !== b) {
  11675. if ((ca = score(c)) < aa) {
  11676. a = c, aa = ca;
  11677. }
  11678. }
  11679. b = a.next;
  11680. }
  11681. // Compute the enclosing circle of the front chain.
  11682. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = packEncloseRandom(a, random);
  11683. // Translate the circles to put the enclosing circle around the origin.
  11684. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  11685. return c.r;
  11686. }
  11687. function siblings(circles) {
  11688. packSiblingsRandom(circles, lcg$1());
  11689. return circles;
  11690. }
  11691. function defaultRadius(d) {
  11692. return Math.sqrt(d.value);
  11693. }
  11694. function index$1() {
  11695. var radius = null,
  11696. dx = 1,
  11697. dy = 1,
  11698. padding = constantZero;
  11699. function pack(root) {
  11700. const random = lcg$1();
  11701. root.x = dx / 2, root.y = dy / 2;
  11702. if (radius) {
  11703. root.eachBefore(radiusLeaf(radius))
  11704. .eachAfter(packChildrenRandom(padding, 0.5, random))
  11705. .eachBefore(translateChild(1));
  11706. } else {
  11707. root.eachBefore(radiusLeaf(defaultRadius))
  11708. .eachAfter(packChildrenRandom(constantZero, 1, random))
  11709. .eachAfter(packChildrenRandom(padding, root.r / Math.min(dx, dy), random))
  11710. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  11711. }
  11712. return root;
  11713. }
  11714. pack.radius = function(x) {
  11715. return arguments.length ? (radius = optional(x), pack) : radius;
  11716. };
  11717. pack.size = function(x) {
  11718. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  11719. };
  11720. pack.padding = function(x) {
  11721. return arguments.length ? (padding = typeof x === "function" ? x : constant$2(+x), pack) : padding;
  11722. };
  11723. return pack;
  11724. }
  11725. function radiusLeaf(radius) {
  11726. return function(node) {
  11727. if (!node.children) {
  11728. node.r = Math.max(0, +radius(node) || 0);
  11729. }
  11730. };
  11731. }
  11732. function packChildrenRandom(padding, k, random) {
  11733. return function(node) {
  11734. if (children = node.children) {
  11735. var children,
  11736. i,
  11737. n = children.length,
  11738. r = padding(node) * k || 0,
  11739. e;
  11740. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  11741. e = packSiblingsRandom(children, random);
  11742. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  11743. node.r = e + r;
  11744. }
  11745. };
  11746. }
  11747. function translateChild(k) {
  11748. return function(node) {
  11749. var parent = node.parent;
  11750. node.r *= k;
  11751. if (parent) {
  11752. node.x = parent.x + k * node.x;
  11753. node.y = parent.y + k * node.y;
  11754. }
  11755. };
  11756. }
  11757. function roundNode(node) {
  11758. node.x0 = Math.round(node.x0);
  11759. node.y0 = Math.round(node.y0);
  11760. node.x1 = Math.round(node.x1);
  11761. node.y1 = Math.round(node.y1);
  11762. }
  11763. function treemapDice(parent, x0, y0, x1, y1) {
  11764. var nodes = parent.children,
  11765. node,
  11766. i = -1,
  11767. n = nodes.length,
  11768. k = parent.value && (x1 - x0) / parent.value;
  11769. while (++i < n) {
  11770. node = nodes[i], node.y0 = y0, node.y1 = y1;
  11771. node.x0 = x0, node.x1 = x0 += node.value * k;
  11772. }
  11773. }
  11774. function partition() {
  11775. var dx = 1,
  11776. dy = 1,
  11777. padding = 0,
  11778. round = false;
  11779. function partition(root) {
  11780. var n = root.height + 1;
  11781. root.x0 =
  11782. root.y0 = padding;
  11783. root.x1 = dx;
  11784. root.y1 = dy / n;
  11785. root.eachBefore(positionNode(dy, n));
  11786. if (round) root.eachBefore(roundNode);
  11787. return root;
  11788. }
  11789. function positionNode(dy, n) {
  11790. return function(node) {
  11791. if (node.children) {
  11792. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  11793. }
  11794. var x0 = node.x0,
  11795. y0 = node.y0,
  11796. x1 = node.x1 - padding,
  11797. y1 = node.y1 - padding;
  11798. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  11799. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  11800. node.x0 = x0;
  11801. node.y0 = y0;
  11802. node.x1 = x1;
  11803. node.y1 = y1;
  11804. };
  11805. }
  11806. partition.round = function(x) {
  11807. return arguments.length ? (round = !!x, partition) : round;
  11808. };
  11809. partition.size = function(x) {
  11810. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  11811. };
  11812. partition.padding = function(x) {
  11813. return arguments.length ? (padding = +x, partition) : padding;
  11814. };
  11815. return partition;
  11816. }
  11817. var preroot = {depth: -1},
  11818. ambiguous = {},
  11819. imputed = {};
  11820. function defaultId(d) {
  11821. return d.id;
  11822. }
  11823. function defaultParentId(d) {
  11824. return d.parentId;
  11825. }
  11826. function stratify() {
  11827. var id = defaultId,
  11828. parentId = defaultParentId,
  11829. path;
  11830. function stratify(data) {
  11831. var nodes = Array.from(data),
  11832. currentId = id,
  11833. currentParentId = parentId,
  11834. n,
  11835. d,
  11836. i,
  11837. root,
  11838. parent,
  11839. node,
  11840. nodeId,
  11841. nodeKey,
  11842. nodeByKey = new Map;
  11843. if (path != null) {
  11844. const I = nodes.map((d, i) => normalize$1(path(d, i, data)));
  11845. const P = I.map(parentof);
  11846. const S = new Set(I).add("");
  11847. for (const i of P) {
  11848. if (!S.has(i)) {
  11849. S.add(i);
  11850. I.push(i);
  11851. P.push(parentof(i));
  11852. nodes.push(imputed);
  11853. }
  11854. }
  11855. currentId = (_, i) => I[i];
  11856. currentParentId = (_, i) => P[i];
  11857. }
  11858. for (i = 0, n = nodes.length; i < n; ++i) {
  11859. d = nodes[i], node = nodes[i] = new Node$1(d);
  11860. if ((nodeId = currentId(d, i, data)) != null && (nodeId += "")) {
  11861. nodeKey = node.id = nodeId;
  11862. nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
  11863. }
  11864. if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += "")) {
  11865. node.parent = nodeId;
  11866. }
  11867. }
  11868. for (i = 0; i < n; ++i) {
  11869. node = nodes[i];
  11870. if (nodeId = node.parent) {
  11871. parent = nodeByKey.get(nodeId);
  11872. if (!parent) throw new Error("missing: " + nodeId);
  11873. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  11874. if (parent.children) parent.children.push(node);
  11875. else parent.children = [node];
  11876. node.parent = parent;
  11877. } else {
  11878. if (root) throw new Error("multiple roots");
  11879. root = node;
  11880. }
  11881. }
  11882. if (!root) throw new Error("no root");
  11883. // When imputing internal nodes, only introduce roots if needed.
  11884. // Then replace the imputed marker data with null.
  11885. if (path != null) {
  11886. while (root.data === imputed && root.children.length === 1) {
  11887. root = root.children[0], --n;
  11888. }
  11889. for (let i = nodes.length - 1; i >= 0; --i) {
  11890. node = nodes[i];
  11891. if (node.data !== imputed) break;
  11892. node.data = null;
  11893. }
  11894. }
  11895. root.parent = preroot;
  11896. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  11897. root.parent = null;
  11898. if (n > 0) throw new Error("cycle");
  11899. return root;
  11900. }
  11901. stratify.id = function(x) {
  11902. return arguments.length ? (id = optional(x), stratify) : id;
  11903. };
  11904. stratify.parentId = function(x) {
  11905. return arguments.length ? (parentId = optional(x), stratify) : parentId;
  11906. };
  11907. stratify.path = function(x) {
  11908. return arguments.length ? (path = optional(x), stratify) : path;
  11909. };
  11910. return stratify;
  11911. }
  11912. // To normalize a path, we coerce to a string, strip the trailing slash if any
  11913. // (as long as the trailing slash is not immediately preceded by another slash),
  11914. // and add leading slash if missing.
  11915. function normalize$1(path) {
  11916. path = `${path}`;
  11917. let i = path.length;
  11918. if (slash(path, i - 1) && !slash(path, i - 2)) path = path.slice(0, -1);
  11919. return path[0] === "/" ? path : `/${path}`;
  11920. }
  11921. // Walk backwards to find the first slash that is not the leading slash, e.g.:
  11922. // "/foo/bar" ⇥ "/foo", "/foo" ⇥ "/", "/" ↦ "". (The root is special-cased
  11923. // because the id of the root must be a truthy value.)
  11924. function parentof(path) {
  11925. let i = path.length;
  11926. if (i < 2) return "";
  11927. while (--i > 1) if (slash(path, i)) break;
  11928. return path.slice(0, i);
  11929. }
  11930. // Slashes can be escaped; to determine whether a slash is a path delimiter, we
  11931. // count the number of preceding backslashes escaping the forward slash: an odd
  11932. // number indicates an escaped forward slash.
  11933. function slash(path, i) {
  11934. if (path[i] === "/") {
  11935. let k = 0;
  11936. while (i > 0 && path[--i] === "\\") ++k;
  11937. if ((k & 1) === 0) return true;
  11938. }
  11939. return false;
  11940. }
  11941. function defaultSeparation(a, b) {
  11942. return a.parent === b.parent ? 1 : 2;
  11943. }
  11944. // function radialSeparation(a, b) {
  11945. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  11946. // }
  11947. // This function is used to traverse the left contour of a subtree (or
  11948. // subforest). It returns the successor of v on this contour. This successor is
  11949. // either given by the leftmost child of v or by the thread of v. The function
  11950. // returns null if and only if v is on the highest level of its subtree.
  11951. function nextLeft(v) {
  11952. var children = v.children;
  11953. return children ? children[0] : v.t;
  11954. }
  11955. // This function works analogously to nextLeft.
  11956. function nextRight(v) {
  11957. var children = v.children;
  11958. return children ? children[children.length - 1] : v.t;
  11959. }
  11960. // Shifts the current subtree rooted at w+. This is done by increasing
  11961. // prelim(w+) and mod(w+) by shift.
  11962. function moveSubtree(wm, wp, shift) {
  11963. var change = shift / (wp.i - wm.i);
  11964. wp.c -= change;
  11965. wp.s += shift;
  11966. wm.c += change;
  11967. wp.z += shift;
  11968. wp.m += shift;
  11969. }
  11970. // All other shifts, applied to the smaller subtrees between w- and w+, are
  11971. // performed by this function. To prepare the shifts, we have to adjust
  11972. // change(w+), shift(w+), and change(w-).
  11973. function executeShifts(v) {
  11974. var shift = 0,
  11975. change = 0,
  11976. children = v.children,
  11977. i = children.length,
  11978. w;
  11979. while (--i >= 0) {
  11980. w = children[i];
  11981. w.z += shift;
  11982. w.m += shift;
  11983. shift += w.s + (change += w.c);
  11984. }
  11985. }
  11986. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  11987. // returns the specified (default) ancestor.
  11988. function nextAncestor(vim, v, ancestor) {
  11989. return vim.a.parent === v.parent ? vim.a : ancestor;
  11990. }
  11991. function TreeNode(node, i) {
  11992. this._ = node;
  11993. this.parent = null;
  11994. this.children = null;
  11995. this.A = null; // default ancestor
  11996. this.a = this; // ancestor
  11997. this.z = 0; // prelim
  11998. this.m = 0; // mod
  11999. this.c = 0; // change
  12000. this.s = 0; // shift
  12001. this.t = null; // thread
  12002. this.i = i; // number
  12003. }
  12004. TreeNode.prototype = Object.create(Node$1.prototype);
  12005. function treeRoot(root) {
  12006. var tree = new TreeNode(root, 0),
  12007. node,
  12008. nodes = [tree],
  12009. child,
  12010. children,
  12011. i,
  12012. n;
  12013. while (node = nodes.pop()) {
  12014. if (children = node._.children) {
  12015. node.children = new Array(n = children.length);
  12016. for (i = n - 1; i >= 0; --i) {
  12017. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  12018. child.parent = node;
  12019. }
  12020. }
  12021. }
  12022. (tree.parent = new TreeNode(null, 0)).children = [tree];
  12023. return tree;
  12024. }
  12025. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  12026. function tree() {
  12027. var separation = defaultSeparation,
  12028. dx = 1,
  12029. dy = 1,
  12030. nodeSize = null;
  12031. function tree(root) {
  12032. var t = treeRoot(root);
  12033. // Compute the layout using Buchheim et al.’s algorithm.
  12034. t.eachAfter(firstWalk), t.parent.m = -t.z;
  12035. t.eachBefore(secondWalk);
  12036. // If a fixed node size is specified, scale x and y.
  12037. if (nodeSize) root.eachBefore(sizeNode);
  12038. // If a fixed tree size is specified, scale x and y based on the extent.
  12039. // Compute the left-most, right-most, and depth-most nodes for extents.
  12040. else {
  12041. var left = root,
  12042. right = root,
  12043. bottom = root;
  12044. root.eachBefore(function(node) {
  12045. if (node.x < left.x) left = node;
  12046. if (node.x > right.x) right = node;
  12047. if (node.depth > bottom.depth) bottom = node;
  12048. });
  12049. var s = left === right ? 1 : separation(left, right) / 2,
  12050. tx = s - left.x,
  12051. kx = dx / (right.x + s + tx),
  12052. ky = dy / (bottom.depth || 1);
  12053. root.eachBefore(function(node) {
  12054. node.x = (node.x + tx) * kx;
  12055. node.y = node.depth * ky;
  12056. });
  12057. }
  12058. return root;
  12059. }
  12060. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  12061. // applied recursively to the children of v, as well as the function
  12062. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  12063. // node v is placed to the midpoint of its outermost children.
  12064. function firstWalk(v) {
  12065. var children = v.children,
  12066. siblings = v.parent.children,
  12067. w = v.i ? siblings[v.i - 1] : null;
  12068. if (children) {
  12069. executeShifts(v);
  12070. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  12071. if (w) {
  12072. v.z = w.z + separation(v._, w._);
  12073. v.m = v.z - midpoint;
  12074. } else {
  12075. v.z = midpoint;
  12076. }
  12077. } else if (w) {
  12078. v.z = w.z + separation(v._, w._);
  12079. }
  12080. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  12081. }
  12082. // Computes all real x-coordinates by summing up the modifiers recursively.
  12083. function secondWalk(v) {
  12084. v._.x = v.z + v.parent.m;
  12085. v.m += v.parent.m;
  12086. }
  12087. // The core of the algorithm. Here, a new subtree is combined with the
  12088. // previous subtrees. Threads are used to traverse the inside and outside
  12089. // contours of the left and right subtree up to the highest common level. The
  12090. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  12091. // superscript o means outside and i means inside, the subscript - means left
  12092. // subtree and + means right subtree. For summing up the modifiers along the
  12093. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  12094. // nodes of the inside contours conflict, we compute the left one of the
  12095. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  12096. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  12097. // Finally, we add a new thread (if necessary).
  12098. function apportion(v, w, ancestor) {
  12099. if (w) {
  12100. var vip = v,
  12101. vop = v,
  12102. vim = w,
  12103. vom = vip.parent.children[0],
  12104. sip = vip.m,
  12105. sop = vop.m,
  12106. sim = vim.m,
  12107. som = vom.m,
  12108. shift;
  12109. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  12110. vom = nextLeft(vom);
  12111. vop = nextRight(vop);
  12112. vop.a = v;
  12113. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  12114. if (shift > 0) {
  12115. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  12116. sip += shift;
  12117. sop += shift;
  12118. }
  12119. sim += vim.m;
  12120. sip += vip.m;
  12121. som += vom.m;
  12122. sop += vop.m;
  12123. }
  12124. if (vim && !nextRight(vop)) {
  12125. vop.t = vim;
  12126. vop.m += sim - sop;
  12127. }
  12128. if (vip && !nextLeft(vom)) {
  12129. vom.t = vip;
  12130. vom.m += sip - som;
  12131. ancestor = v;
  12132. }
  12133. }
  12134. return ancestor;
  12135. }
  12136. function sizeNode(node) {
  12137. node.x *= dx;
  12138. node.y = node.depth * dy;
  12139. }
  12140. tree.separation = function(x) {
  12141. return arguments.length ? (separation = x, tree) : separation;
  12142. };
  12143. tree.size = function(x) {
  12144. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  12145. };
  12146. tree.nodeSize = function(x) {
  12147. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  12148. };
  12149. return tree;
  12150. }
  12151. function treemapSlice(parent, x0, y0, x1, y1) {
  12152. var nodes = parent.children,
  12153. node,
  12154. i = -1,
  12155. n = nodes.length,
  12156. k = parent.value && (y1 - y0) / parent.value;
  12157. while (++i < n) {
  12158. node = nodes[i], node.x0 = x0, node.x1 = x1;
  12159. node.y0 = y0, node.y1 = y0 += node.value * k;
  12160. }
  12161. }
  12162. var phi = (1 + Math.sqrt(5)) / 2;
  12163. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  12164. var rows = [],
  12165. nodes = parent.children,
  12166. row,
  12167. nodeValue,
  12168. i0 = 0,
  12169. i1 = 0,
  12170. n = nodes.length,
  12171. dx, dy,
  12172. value = parent.value,
  12173. sumValue,
  12174. minValue,
  12175. maxValue,
  12176. newRatio,
  12177. minRatio,
  12178. alpha,
  12179. beta;
  12180. while (i0 < n) {
  12181. dx = x1 - x0, dy = y1 - y0;
  12182. // Find the next non-empty node.
  12183. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  12184. minValue = maxValue = sumValue;
  12185. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  12186. beta = sumValue * sumValue * alpha;
  12187. minRatio = Math.max(maxValue / beta, beta / minValue);
  12188. // Keep adding nodes while the aspect ratio maintains or improves.
  12189. for (; i1 < n; ++i1) {
  12190. sumValue += nodeValue = nodes[i1].value;
  12191. if (nodeValue < minValue) minValue = nodeValue;
  12192. if (nodeValue > maxValue) maxValue = nodeValue;
  12193. beta = sumValue * sumValue * alpha;
  12194. newRatio = Math.max(maxValue / beta, beta / minValue);
  12195. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  12196. minRatio = newRatio;
  12197. }
  12198. // Position and record the row orientation.
  12199. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  12200. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  12201. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  12202. value -= sumValue, i0 = i1;
  12203. }
  12204. return rows;
  12205. }
  12206. var squarify = (function custom(ratio) {
  12207. function squarify(parent, x0, y0, x1, y1) {
  12208. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  12209. }
  12210. squarify.ratio = function(x) {
  12211. return custom((x = +x) > 1 ? x : 1);
  12212. };
  12213. return squarify;
  12214. })(phi);
  12215. function index() {
  12216. var tile = squarify,
  12217. round = false,
  12218. dx = 1,
  12219. dy = 1,
  12220. paddingStack = [0],
  12221. paddingInner = constantZero,
  12222. paddingTop = constantZero,
  12223. paddingRight = constantZero,
  12224. paddingBottom = constantZero,
  12225. paddingLeft = constantZero;
  12226. function treemap(root) {
  12227. root.x0 =
  12228. root.y0 = 0;
  12229. root.x1 = dx;
  12230. root.y1 = dy;
  12231. root.eachBefore(positionNode);
  12232. paddingStack = [0];
  12233. if (round) root.eachBefore(roundNode);
  12234. return root;
  12235. }
  12236. function positionNode(node) {
  12237. var p = paddingStack[node.depth],
  12238. x0 = node.x0 + p,
  12239. y0 = node.y0 + p,
  12240. x1 = node.x1 - p,
  12241. y1 = node.y1 - p;
  12242. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  12243. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  12244. node.x0 = x0;
  12245. node.y0 = y0;
  12246. node.x1 = x1;
  12247. node.y1 = y1;
  12248. if (node.children) {
  12249. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  12250. x0 += paddingLeft(node) - p;
  12251. y0 += paddingTop(node) - p;
  12252. x1 -= paddingRight(node) - p;
  12253. y1 -= paddingBottom(node) - p;
  12254. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  12255. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  12256. tile(node, x0, y0, x1, y1);
  12257. }
  12258. }
  12259. treemap.round = function(x) {
  12260. return arguments.length ? (round = !!x, treemap) : round;
  12261. };
  12262. treemap.size = function(x) {
  12263. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  12264. };
  12265. treemap.tile = function(x) {
  12266. return arguments.length ? (tile = required(x), treemap) : tile;
  12267. };
  12268. treemap.padding = function(x) {
  12269. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  12270. };
  12271. treemap.paddingInner = function(x) {
  12272. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$2(+x), treemap) : paddingInner;
  12273. };
  12274. treemap.paddingOuter = function(x) {
  12275. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  12276. };
  12277. treemap.paddingTop = function(x) {
  12278. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$2(+x), treemap) : paddingTop;
  12279. };
  12280. treemap.paddingRight = function(x) {
  12281. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$2(+x), treemap) : paddingRight;
  12282. };
  12283. treemap.paddingBottom = function(x) {
  12284. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$2(+x), treemap) : paddingBottom;
  12285. };
  12286. treemap.paddingLeft = function(x) {
  12287. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$2(+x), treemap) : paddingLeft;
  12288. };
  12289. return treemap;
  12290. }
  12291. function binary(parent, x0, y0, x1, y1) {
  12292. var nodes = parent.children,
  12293. i, n = nodes.length,
  12294. sum, sums = new Array(n + 1);
  12295. for (sums[0] = sum = i = 0; i < n; ++i) {
  12296. sums[i + 1] = sum += nodes[i].value;
  12297. }
  12298. partition(0, n, parent.value, x0, y0, x1, y1);
  12299. function partition(i, j, value, x0, y0, x1, y1) {
  12300. if (i >= j - 1) {
  12301. var node = nodes[i];
  12302. node.x0 = x0, node.y0 = y0;
  12303. node.x1 = x1, node.y1 = y1;
  12304. return;
  12305. }
  12306. var valueOffset = sums[i],
  12307. valueTarget = (value / 2) + valueOffset,
  12308. k = i + 1,
  12309. hi = j - 1;
  12310. while (k < hi) {
  12311. var mid = k + hi >>> 1;
  12312. if (sums[mid] < valueTarget) k = mid + 1;
  12313. else hi = mid;
  12314. }
  12315. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  12316. var valueLeft = sums[k] - valueOffset,
  12317. valueRight = value - valueLeft;
  12318. if ((x1 - x0) > (y1 - y0)) {
  12319. var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
  12320. partition(i, k, valueLeft, x0, y0, xk, y1);
  12321. partition(k, j, valueRight, xk, y0, x1, y1);
  12322. } else {
  12323. var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
  12324. partition(i, k, valueLeft, x0, y0, x1, yk);
  12325. partition(k, j, valueRight, x0, yk, x1, y1);
  12326. }
  12327. }
  12328. }
  12329. function sliceDice(parent, x0, y0, x1, y1) {
  12330. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  12331. }
  12332. var resquarify = (function custom(ratio) {
  12333. function resquarify(parent, x0, y0, x1, y1) {
  12334. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  12335. var rows,
  12336. row,
  12337. nodes,
  12338. i,
  12339. j = -1,
  12340. n,
  12341. m = rows.length,
  12342. value = parent.value;
  12343. while (++j < m) {
  12344. row = rows[j], nodes = row.children;
  12345. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  12346. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1);
  12347. else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1);
  12348. value -= row.value;
  12349. }
  12350. } else {
  12351. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  12352. rows.ratio = ratio;
  12353. }
  12354. }
  12355. resquarify.ratio = function(x) {
  12356. return custom((x = +x) > 1 ? x : 1);
  12357. };
  12358. return resquarify;
  12359. })(phi);
  12360. function area$1(polygon) {
  12361. var i = -1,
  12362. n = polygon.length,
  12363. a,
  12364. b = polygon[n - 1],
  12365. area = 0;
  12366. while (++i < n) {
  12367. a = b;
  12368. b = polygon[i];
  12369. area += a[1] * b[0] - a[0] * b[1];
  12370. }
  12371. return area / 2;
  12372. }
  12373. function centroid(polygon) {
  12374. var i = -1,
  12375. n = polygon.length,
  12376. x = 0,
  12377. y = 0,
  12378. a,
  12379. b = polygon[n - 1],
  12380. c,
  12381. k = 0;
  12382. while (++i < n) {
  12383. a = b;
  12384. b = polygon[i];
  12385. k += c = a[0] * b[1] - b[0] * a[1];
  12386. x += (a[0] + b[0]) * c;
  12387. y += (a[1] + b[1]) * c;
  12388. }
  12389. return k *= 3, [x / k, y / k];
  12390. }
  12391. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  12392. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  12393. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  12394. // negative if clockwise, and zero if the points are collinear.
  12395. function cross$1(a, b, c) {
  12396. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  12397. }
  12398. function lexicographicOrder(a, b) {
  12399. return a[0] - b[0] || a[1] - b[1];
  12400. }
  12401. // Computes the upper convex hull per the monotone chain algorithm.
  12402. // Assumes points.length >= 3, is sorted by x, unique in y.
  12403. // Returns an array of indices into points in left-to-right order.
  12404. function computeUpperHullIndexes(points) {
  12405. const n = points.length,
  12406. indexes = [0, 1];
  12407. let size = 2, i;
  12408. for (i = 2; i < n; ++i) {
  12409. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  12410. indexes[size++] = i;
  12411. }
  12412. return indexes.slice(0, size); // remove popped points
  12413. }
  12414. function hull(points) {
  12415. if ((n = points.length) < 3) return null;
  12416. var i,
  12417. n,
  12418. sortedPoints = new Array(n),
  12419. flippedPoints = new Array(n);
  12420. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  12421. sortedPoints.sort(lexicographicOrder);
  12422. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  12423. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  12424. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  12425. // Construct the hull polygon, removing possible duplicate endpoints.
  12426. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  12427. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  12428. hull = [];
  12429. // Add upper hull in right-to-l order.
  12430. // Then add lower hull in left-to-right order.
  12431. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  12432. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  12433. return hull;
  12434. }
  12435. function contains(polygon, point) {
  12436. var n = polygon.length,
  12437. p = polygon[n - 1],
  12438. x = point[0], y = point[1],
  12439. x0 = p[0], y0 = p[1],
  12440. x1, y1,
  12441. inside = false;
  12442. for (var i = 0; i < n; ++i) {
  12443. p = polygon[i], x1 = p[0], y1 = p[1];
  12444. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  12445. x0 = x1, y0 = y1;
  12446. }
  12447. return inside;
  12448. }
  12449. function length(polygon) {
  12450. var i = -1,
  12451. n = polygon.length,
  12452. b = polygon[n - 1],
  12453. xa,
  12454. ya,
  12455. xb = b[0],
  12456. yb = b[1],
  12457. perimeter = 0;
  12458. while (++i < n) {
  12459. xa = xb;
  12460. ya = yb;
  12461. b = polygon[i];
  12462. xb = b[0];
  12463. yb = b[1];
  12464. xa -= xb;
  12465. ya -= yb;
  12466. perimeter += Math.hypot(xa, ya);
  12467. }
  12468. return perimeter;
  12469. }
  12470. var defaultSource = Math.random;
  12471. var uniform = (function sourceRandomUniform(source) {
  12472. function randomUniform(min, max) {
  12473. min = min == null ? 0 : +min;
  12474. max = max == null ? 1 : +max;
  12475. if (arguments.length === 1) max = min, min = 0;
  12476. else max -= min;
  12477. return function() {
  12478. return source() * max + min;
  12479. };
  12480. }
  12481. randomUniform.source = sourceRandomUniform;
  12482. return randomUniform;
  12483. })(defaultSource);
  12484. var int = (function sourceRandomInt(source) {
  12485. function randomInt(min, max) {
  12486. if (arguments.length < 2) max = min, min = 0;
  12487. min = Math.floor(min);
  12488. max = Math.floor(max) - min;
  12489. return function() {
  12490. return Math.floor(source() * max + min);
  12491. };
  12492. }
  12493. randomInt.source = sourceRandomInt;
  12494. return randomInt;
  12495. })(defaultSource);
  12496. var normal = (function sourceRandomNormal(source) {
  12497. function randomNormal(mu, sigma) {
  12498. var x, r;
  12499. mu = mu == null ? 0 : +mu;
  12500. sigma = sigma == null ? 1 : +sigma;
  12501. return function() {
  12502. var y;
  12503. // If available, use the second previously-generated uniform random.
  12504. if (x != null) y = x, x = null;
  12505. // Otherwise, generate a new x and y.
  12506. else do {
  12507. x = source() * 2 - 1;
  12508. y = source() * 2 - 1;
  12509. r = x * x + y * y;
  12510. } while (!r || r > 1);
  12511. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  12512. };
  12513. }
  12514. randomNormal.source = sourceRandomNormal;
  12515. return randomNormal;
  12516. })(defaultSource);
  12517. var logNormal = (function sourceRandomLogNormal(source) {
  12518. var N = normal.source(source);
  12519. function randomLogNormal() {
  12520. var randomNormal = N.apply(this, arguments);
  12521. return function() {
  12522. return Math.exp(randomNormal());
  12523. };
  12524. }
  12525. randomLogNormal.source = sourceRandomLogNormal;
  12526. return randomLogNormal;
  12527. })(defaultSource);
  12528. var irwinHall = (function sourceRandomIrwinHall(source) {
  12529. function randomIrwinHall(n) {
  12530. if ((n = +n) <= 0) return () => 0;
  12531. return function() {
  12532. for (var sum = 0, i = n; i > 1; --i) sum += source();
  12533. return sum + i * source();
  12534. };
  12535. }
  12536. randomIrwinHall.source = sourceRandomIrwinHall;
  12537. return randomIrwinHall;
  12538. })(defaultSource);
  12539. var bates = (function sourceRandomBates(source) {
  12540. var I = irwinHall.source(source);
  12541. function randomBates(n) {
  12542. // use limiting distribution at n === 0
  12543. if ((n = +n) === 0) return source;
  12544. var randomIrwinHall = I(n);
  12545. return function() {
  12546. return randomIrwinHall() / n;
  12547. };
  12548. }
  12549. randomBates.source = sourceRandomBates;
  12550. return randomBates;
  12551. })(defaultSource);
  12552. var exponential = (function sourceRandomExponential(source) {
  12553. function randomExponential(lambda) {
  12554. return function() {
  12555. return -Math.log1p(-source()) / lambda;
  12556. };
  12557. }
  12558. randomExponential.source = sourceRandomExponential;
  12559. return randomExponential;
  12560. })(defaultSource);
  12561. var pareto = (function sourceRandomPareto(source) {
  12562. function randomPareto(alpha) {
  12563. if ((alpha = +alpha) < 0) throw new RangeError("invalid alpha");
  12564. alpha = 1 / -alpha;
  12565. return function() {
  12566. return Math.pow(1 - source(), alpha);
  12567. };
  12568. }
  12569. randomPareto.source = sourceRandomPareto;
  12570. return randomPareto;
  12571. })(defaultSource);
  12572. var bernoulli = (function sourceRandomBernoulli(source) {
  12573. function randomBernoulli(p) {
  12574. if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
  12575. return function() {
  12576. return Math.floor(source() + p);
  12577. };
  12578. }
  12579. randomBernoulli.source = sourceRandomBernoulli;
  12580. return randomBernoulli;
  12581. })(defaultSource);
  12582. var geometric = (function sourceRandomGeometric(source) {
  12583. function randomGeometric(p) {
  12584. if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
  12585. if (p === 0) return () => Infinity;
  12586. if (p === 1) return () => 1;
  12587. p = Math.log1p(-p);
  12588. return function() {
  12589. return 1 + Math.floor(Math.log1p(-source()) / p);
  12590. };
  12591. }
  12592. randomGeometric.source = sourceRandomGeometric;
  12593. return randomGeometric;
  12594. })(defaultSource);
  12595. var gamma = (function sourceRandomGamma(source) {
  12596. var randomNormal = normal.source(source)();
  12597. function randomGamma(k, theta) {
  12598. if ((k = +k) < 0) throw new RangeError("invalid k");
  12599. // degenerate distribution if k === 0
  12600. if (k === 0) return () => 0;
  12601. theta = theta == null ? 1 : +theta;
  12602. // exponential distribution if k === 1
  12603. if (k === 1) return () => -Math.log1p(-source()) * theta;
  12604. var d = (k < 1 ? k + 1 : k) - 1 / 3,
  12605. c = 1 / (3 * Math.sqrt(d)),
  12606. multiplier = k < 1 ? () => Math.pow(source(), 1 / k) : () => 1;
  12607. return function() {
  12608. do {
  12609. do {
  12610. var x = randomNormal(),
  12611. v = 1 + c * x;
  12612. } while (v <= 0);
  12613. v *= v * v;
  12614. var u = 1 - source();
  12615. } while (u >= 1 - 0.0331 * x * x * x * x && Math.log(u) >= 0.5 * x * x + d * (1 - v + Math.log(v)));
  12616. return d * v * multiplier() * theta;
  12617. };
  12618. }
  12619. randomGamma.source = sourceRandomGamma;
  12620. return randomGamma;
  12621. })(defaultSource);
  12622. var beta = (function sourceRandomBeta(source) {
  12623. var G = gamma.source(source);
  12624. function randomBeta(alpha, beta) {
  12625. var X = G(alpha),
  12626. Y = G(beta);
  12627. return function() {
  12628. var x = X();
  12629. return x === 0 ? 0 : x / (x + Y());
  12630. };
  12631. }
  12632. randomBeta.source = sourceRandomBeta;
  12633. return randomBeta;
  12634. })(defaultSource);
  12635. var binomial = (function sourceRandomBinomial(source) {
  12636. var G = geometric.source(source),
  12637. B = beta.source(source);
  12638. function randomBinomial(n, p) {
  12639. n = +n;
  12640. if ((p = +p) >= 1) return () => n;
  12641. if (p <= 0) return () => 0;
  12642. return function() {
  12643. var acc = 0, nn = n, pp = p;
  12644. while (nn * pp > 16 && nn * (1 - pp) > 16) {
  12645. var i = Math.floor((nn + 1) * pp),
  12646. y = B(i, nn - i + 1)();
  12647. if (y <= pp) {
  12648. acc += i;
  12649. nn -= i;
  12650. pp = (pp - y) / (1 - y);
  12651. } else {
  12652. nn = i - 1;
  12653. pp /= y;
  12654. }
  12655. }
  12656. var sign = pp < 0.5,
  12657. pFinal = sign ? pp : 1 - pp,
  12658. g = G(pFinal);
  12659. for (var s = g(), k = 0; s <= nn; ++k) s += g();
  12660. return acc + (sign ? k : nn - k);
  12661. };
  12662. }
  12663. randomBinomial.source = sourceRandomBinomial;
  12664. return randomBinomial;
  12665. })(defaultSource);
  12666. var weibull = (function sourceRandomWeibull(source) {
  12667. function randomWeibull(k, a, b) {
  12668. var outerFunc;
  12669. if ((k = +k) === 0) {
  12670. outerFunc = x => -Math.log(x);
  12671. } else {
  12672. k = 1 / k;
  12673. outerFunc = x => Math.pow(x, k);
  12674. }
  12675. a = a == null ? 0 : +a;
  12676. b = b == null ? 1 : +b;
  12677. return function() {
  12678. return a + b * outerFunc(-Math.log1p(-source()));
  12679. };
  12680. }
  12681. randomWeibull.source = sourceRandomWeibull;
  12682. return randomWeibull;
  12683. })(defaultSource);
  12684. var cauchy = (function sourceRandomCauchy(source) {
  12685. function randomCauchy(a, b) {
  12686. a = a == null ? 0 : +a;
  12687. b = b == null ? 1 : +b;
  12688. return function() {
  12689. return a + b * Math.tan(Math.PI * source());
  12690. };
  12691. }
  12692. randomCauchy.source = sourceRandomCauchy;
  12693. return randomCauchy;
  12694. })(defaultSource);
  12695. var logistic = (function sourceRandomLogistic(source) {
  12696. function randomLogistic(a, b) {
  12697. a = a == null ? 0 : +a;
  12698. b = b == null ? 1 : +b;
  12699. return function() {
  12700. var u = source();
  12701. return a + b * Math.log(u / (1 - u));
  12702. };
  12703. }
  12704. randomLogistic.source = sourceRandomLogistic;
  12705. return randomLogistic;
  12706. })(defaultSource);
  12707. var poisson = (function sourceRandomPoisson(source) {
  12708. var G = gamma.source(source),
  12709. B = binomial.source(source);
  12710. function randomPoisson(lambda) {
  12711. return function() {
  12712. var acc = 0, l = lambda;
  12713. while (l > 16) {
  12714. var n = Math.floor(0.875 * l),
  12715. t = G(n)();
  12716. if (t > l) return acc + B(n - 1, l / t)();
  12717. acc += n;
  12718. l -= t;
  12719. }
  12720. for (var s = -Math.log1p(-source()), k = 0; s <= l; ++k) s -= Math.log1p(-source());
  12721. return acc + k;
  12722. };
  12723. }
  12724. randomPoisson.source = sourceRandomPoisson;
  12725. return randomPoisson;
  12726. })(defaultSource);
  12727. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  12728. const mul = 0x19660D;
  12729. const inc = 0x3C6EF35F;
  12730. const eps = 1 / 0x100000000;
  12731. function lcg(seed = Math.random()) {
  12732. let state = (0 <= seed && seed < 1 ? seed / eps : Math.abs(seed)) | 0;
  12733. return () => (state = mul * state + inc | 0, eps * (state >>> 0));
  12734. }
  12735. function initRange(domain, range) {
  12736. switch (arguments.length) {
  12737. case 0: break;
  12738. case 1: this.range(domain); break;
  12739. default: this.range(range).domain(domain); break;
  12740. }
  12741. return this;
  12742. }
  12743. function initInterpolator(domain, interpolator) {
  12744. switch (arguments.length) {
  12745. case 0: break;
  12746. case 1: {
  12747. if (typeof domain === "function") this.interpolator(domain);
  12748. else this.range(domain);
  12749. break;
  12750. }
  12751. default: {
  12752. this.domain(domain);
  12753. if (typeof interpolator === "function") this.interpolator(interpolator);
  12754. else this.range(interpolator);
  12755. break;
  12756. }
  12757. }
  12758. return this;
  12759. }
  12760. const implicit = Symbol("implicit");
  12761. function ordinal() {
  12762. var index = new InternMap(),
  12763. domain = [],
  12764. range = [],
  12765. unknown = implicit;
  12766. function scale(d) {
  12767. let i = index.get(d);
  12768. if (i === undefined) {
  12769. if (unknown !== implicit) return unknown;
  12770. index.set(d, i = domain.push(d) - 1);
  12771. }
  12772. return range[i % range.length];
  12773. }
  12774. scale.domain = function(_) {
  12775. if (!arguments.length) return domain.slice();
  12776. domain = [], index = new InternMap();
  12777. for (const value of _) {
  12778. if (index.has(value)) continue;
  12779. index.set(value, domain.push(value) - 1);
  12780. }
  12781. return scale;
  12782. };
  12783. scale.range = function(_) {
  12784. return arguments.length ? (range = Array.from(_), scale) : range.slice();
  12785. };
  12786. scale.unknown = function(_) {
  12787. return arguments.length ? (unknown = _, scale) : unknown;
  12788. };
  12789. scale.copy = function() {
  12790. return ordinal(domain, range).unknown(unknown);
  12791. };
  12792. initRange.apply(scale, arguments);
  12793. return scale;
  12794. }
  12795. function band() {
  12796. var scale = ordinal().unknown(undefined),
  12797. domain = scale.domain,
  12798. ordinalRange = scale.range,
  12799. r0 = 0,
  12800. r1 = 1,
  12801. step,
  12802. bandwidth,
  12803. round = false,
  12804. paddingInner = 0,
  12805. paddingOuter = 0,
  12806. align = 0.5;
  12807. delete scale.unknown;
  12808. function rescale() {
  12809. var n = domain().length,
  12810. reverse = r1 < r0,
  12811. start = reverse ? r1 : r0,
  12812. stop = reverse ? r0 : r1;
  12813. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  12814. if (round) step = Math.floor(step);
  12815. start += (stop - start - step * (n - paddingInner)) * align;
  12816. bandwidth = step * (1 - paddingInner);
  12817. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  12818. var values = range$2(n).map(function(i) { return start + step * i; });
  12819. return ordinalRange(reverse ? values.reverse() : values);
  12820. }
  12821. scale.domain = function(_) {
  12822. return arguments.length ? (domain(_), rescale()) : domain();
  12823. };
  12824. scale.range = function(_) {
  12825. return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
  12826. };
  12827. scale.rangeRound = function(_) {
  12828. return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
  12829. };
  12830. scale.bandwidth = function() {
  12831. return bandwidth;
  12832. };
  12833. scale.step = function() {
  12834. return step;
  12835. };
  12836. scale.round = function(_) {
  12837. return arguments.length ? (round = !!_, rescale()) : round;
  12838. };
  12839. scale.padding = function(_) {
  12840. return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
  12841. };
  12842. scale.paddingInner = function(_) {
  12843. return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
  12844. };
  12845. scale.paddingOuter = function(_) {
  12846. return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
  12847. };
  12848. scale.align = function(_) {
  12849. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  12850. };
  12851. scale.copy = function() {
  12852. return band(domain(), [r0, r1])
  12853. .round(round)
  12854. .paddingInner(paddingInner)
  12855. .paddingOuter(paddingOuter)
  12856. .align(align);
  12857. };
  12858. return initRange.apply(rescale(), arguments);
  12859. }
  12860. function pointish(scale) {
  12861. var copy = scale.copy;
  12862. scale.padding = scale.paddingOuter;
  12863. delete scale.paddingInner;
  12864. delete scale.paddingOuter;
  12865. scale.copy = function() {
  12866. return pointish(copy());
  12867. };
  12868. return scale;
  12869. }
  12870. function point$4() {
  12871. return pointish(band.apply(null, arguments).paddingInner(1));
  12872. }
  12873. function constants(x) {
  12874. return function() {
  12875. return x;
  12876. };
  12877. }
  12878. function number$1(x) {
  12879. return +x;
  12880. }
  12881. var unit = [0, 1];
  12882. function identity$3(x) {
  12883. return x;
  12884. }
  12885. function normalize(a, b) {
  12886. return (b -= (a = +a))
  12887. ? function(x) { return (x - a) / b; }
  12888. : constants(isNaN(b) ? NaN : 0.5);
  12889. }
  12890. function clamper(a, b) {
  12891. var t;
  12892. if (a > b) t = a, a = b, b = t;
  12893. return function(x) { return Math.max(a, Math.min(b, x)); };
  12894. }
  12895. // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  12896. // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
  12897. function bimap(domain, range, interpolate) {
  12898. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  12899. if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
  12900. else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
  12901. return function(x) { return r0(d0(x)); };
  12902. }
  12903. function polymap(domain, range, interpolate) {
  12904. var j = Math.min(domain.length, range.length) - 1,
  12905. d = new Array(j),
  12906. r = new Array(j),
  12907. i = -1;
  12908. // Reverse descending domains.
  12909. if (domain[j] < domain[0]) {
  12910. domain = domain.slice().reverse();
  12911. range = range.slice().reverse();
  12912. }
  12913. while (++i < j) {
  12914. d[i] = normalize(domain[i], domain[i + 1]);
  12915. r[i] = interpolate(range[i], range[i + 1]);
  12916. }
  12917. return function(x) {
  12918. var i = bisect(domain, x, 1, j) - 1;
  12919. return r[i](d[i](x));
  12920. };
  12921. }
  12922. function copy$1(source, target) {
  12923. return target
  12924. .domain(source.domain())
  12925. .range(source.range())
  12926. .interpolate(source.interpolate())
  12927. .clamp(source.clamp())
  12928. .unknown(source.unknown());
  12929. }
  12930. function transformer$2() {
  12931. var domain = unit,
  12932. range = unit,
  12933. interpolate = interpolate$2,
  12934. transform,
  12935. untransform,
  12936. unknown,
  12937. clamp = identity$3,
  12938. piecewise,
  12939. output,
  12940. input;
  12941. function rescale() {
  12942. var n = Math.min(domain.length, range.length);
  12943. if (clamp !== identity$3) clamp = clamper(domain[0], domain[n - 1]);
  12944. piecewise = n > 2 ? polymap : bimap;
  12945. output = input = null;
  12946. return scale;
  12947. }
  12948. function scale(x) {
  12949. return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
  12950. }
  12951. scale.invert = function(y) {
  12952. return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
  12953. };
  12954. scale.domain = function(_) {
  12955. return arguments.length ? (domain = Array.from(_, number$1), rescale()) : domain.slice();
  12956. };
  12957. scale.range = function(_) {
  12958. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  12959. };
  12960. scale.rangeRound = function(_) {
  12961. return range = Array.from(_), interpolate = interpolateRound, rescale();
  12962. };
  12963. scale.clamp = function(_) {
  12964. return arguments.length ? (clamp = _ ? true : identity$3, rescale()) : clamp !== identity$3;
  12965. };
  12966. scale.interpolate = function(_) {
  12967. return arguments.length ? (interpolate = _, rescale()) : interpolate;
  12968. };
  12969. scale.unknown = function(_) {
  12970. return arguments.length ? (unknown = _, scale) : unknown;
  12971. };
  12972. return function(t, u) {
  12973. transform = t, untransform = u;
  12974. return rescale();
  12975. };
  12976. }
  12977. function continuous() {
  12978. return transformer$2()(identity$3, identity$3);
  12979. }
  12980. function tickFormat(start, stop, count, specifier) {
  12981. var step = tickStep(start, stop, count),
  12982. precision;
  12983. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  12984. switch (specifier.type) {
  12985. case "s": {
  12986. var value = Math.max(Math.abs(start), Math.abs(stop));
  12987. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  12988. return exports.formatPrefix(specifier, value);
  12989. }
  12990. case "":
  12991. case "e":
  12992. case "g":
  12993. case "p":
  12994. case "r": {
  12995. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  12996. break;
  12997. }
  12998. case "f":
  12999. case "%": {
  13000. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  13001. break;
  13002. }
  13003. }
  13004. return exports.format(specifier);
  13005. }
  13006. function linearish(scale) {
  13007. var domain = scale.domain;
  13008. scale.ticks = function(count) {
  13009. var d = domain();
  13010. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  13011. };
  13012. scale.tickFormat = function(count, specifier) {
  13013. var d = domain();
  13014. return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
  13015. };
  13016. scale.nice = function(count) {
  13017. if (count == null) count = 10;
  13018. var d = domain();
  13019. var i0 = 0;
  13020. var i1 = d.length - 1;
  13021. var start = d[i0];
  13022. var stop = d[i1];
  13023. var prestep;
  13024. var step;
  13025. var maxIter = 10;
  13026. if (stop < start) {
  13027. step = start, start = stop, stop = step;
  13028. step = i0, i0 = i1, i1 = step;
  13029. }
  13030. while (maxIter-- > 0) {
  13031. step = tickIncrement(start, stop, count);
  13032. if (step === prestep) {
  13033. d[i0] = start;
  13034. d[i1] = stop;
  13035. return domain(d);
  13036. } else if (step > 0) {
  13037. start = Math.floor(start / step) * step;
  13038. stop = Math.ceil(stop / step) * step;
  13039. } else if (step < 0) {
  13040. start = Math.ceil(start * step) / step;
  13041. stop = Math.floor(stop * step) / step;
  13042. } else {
  13043. break;
  13044. }
  13045. prestep = step;
  13046. }
  13047. return scale;
  13048. };
  13049. return scale;
  13050. }
  13051. function linear() {
  13052. var scale = continuous();
  13053. scale.copy = function() {
  13054. return copy$1(scale, linear());
  13055. };
  13056. initRange.apply(scale, arguments);
  13057. return linearish(scale);
  13058. }
  13059. function identity$2(domain) {
  13060. var unknown;
  13061. function scale(x) {
  13062. return x == null || isNaN(x = +x) ? unknown : x;
  13063. }
  13064. scale.invert = scale;
  13065. scale.domain = scale.range = function(_) {
  13066. return arguments.length ? (domain = Array.from(_, number$1), scale) : domain.slice();
  13067. };
  13068. scale.unknown = function(_) {
  13069. return arguments.length ? (unknown = _, scale) : unknown;
  13070. };
  13071. scale.copy = function() {
  13072. return identity$2(domain).unknown(unknown);
  13073. };
  13074. domain = arguments.length ? Array.from(domain, number$1) : [0, 1];
  13075. return linearish(scale);
  13076. }
  13077. function nice(domain, interval) {
  13078. domain = domain.slice();
  13079. var i0 = 0,
  13080. i1 = domain.length - 1,
  13081. x0 = domain[i0],
  13082. x1 = domain[i1],
  13083. t;
  13084. if (x1 < x0) {
  13085. t = i0, i0 = i1, i1 = t;
  13086. t = x0, x0 = x1, x1 = t;
  13087. }
  13088. domain[i0] = interval.floor(x0);
  13089. domain[i1] = interval.ceil(x1);
  13090. return domain;
  13091. }
  13092. function transformLog(x) {
  13093. return Math.log(x);
  13094. }
  13095. function transformExp(x) {
  13096. return Math.exp(x);
  13097. }
  13098. function transformLogn(x) {
  13099. return -Math.log(-x);
  13100. }
  13101. function transformExpn(x) {
  13102. return -Math.exp(-x);
  13103. }
  13104. function pow10(x) {
  13105. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  13106. }
  13107. function powp(base) {
  13108. return base === 10 ? pow10
  13109. : base === Math.E ? Math.exp
  13110. : x => Math.pow(base, x);
  13111. }
  13112. function logp(base) {
  13113. return base === Math.E ? Math.log
  13114. : base === 10 && Math.log10
  13115. || base === 2 && Math.log2
  13116. || (base = Math.log(base), x => Math.log(x) / base);
  13117. }
  13118. function reflect(f) {
  13119. return (x, k) => -f(-x, k);
  13120. }
  13121. function loggish(transform) {
  13122. const scale = transform(transformLog, transformExp);
  13123. const domain = scale.domain;
  13124. let base = 10;
  13125. let logs;
  13126. let pows;
  13127. function rescale() {
  13128. logs = logp(base), pows = powp(base);
  13129. if (domain()[0] < 0) {
  13130. logs = reflect(logs), pows = reflect(pows);
  13131. transform(transformLogn, transformExpn);
  13132. } else {
  13133. transform(transformLog, transformExp);
  13134. }
  13135. return scale;
  13136. }
  13137. scale.base = function(_) {
  13138. return arguments.length ? (base = +_, rescale()) : base;
  13139. };
  13140. scale.domain = function(_) {
  13141. return arguments.length ? (domain(_), rescale()) : domain();
  13142. };
  13143. scale.ticks = count => {
  13144. const d = domain();
  13145. let u = d[0];
  13146. let v = d[d.length - 1];
  13147. const r = v < u;
  13148. if (r) ([u, v] = [v, u]);
  13149. let i = logs(u);
  13150. let j = logs(v);
  13151. let k;
  13152. let t;
  13153. const n = count == null ? 10 : +count;
  13154. let z = [];
  13155. if (!(base % 1) && j - i < n) {
  13156. i = Math.floor(i), j = Math.ceil(j);
  13157. if (u > 0) for (; i <= j; ++i) {
  13158. for (k = 1; k < base; ++k) {
  13159. t = i < 0 ? k / pows(-i) : k * pows(i);
  13160. if (t < u) continue;
  13161. if (t > v) break;
  13162. z.push(t);
  13163. }
  13164. } else for (; i <= j; ++i) {
  13165. for (k = base - 1; k >= 1; --k) {
  13166. t = i > 0 ? k / pows(-i) : k * pows(i);
  13167. if (t < u) continue;
  13168. if (t > v) break;
  13169. z.push(t);
  13170. }
  13171. }
  13172. if (z.length * 2 < n) z = ticks(u, v, n);
  13173. } else {
  13174. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  13175. }
  13176. return r ? z.reverse() : z;
  13177. };
  13178. scale.tickFormat = (count, specifier) => {
  13179. if (count == null) count = 10;
  13180. if (specifier == null) specifier = base === 10 ? "s" : ",";
  13181. if (typeof specifier !== "function") {
  13182. if (!(base % 1) && (specifier = formatSpecifier(specifier)).precision == null) specifier.trim = true;
  13183. specifier = exports.format(specifier);
  13184. }
  13185. if (count === Infinity) return specifier;
  13186. const k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  13187. return d => {
  13188. let i = d / pows(Math.round(logs(d)));
  13189. if (i * base < base - 0.5) i *= base;
  13190. return i <= k ? specifier(d) : "";
  13191. };
  13192. };
  13193. scale.nice = () => {
  13194. return domain(nice(domain(), {
  13195. floor: x => pows(Math.floor(logs(x))),
  13196. ceil: x => pows(Math.ceil(logs(x)))
  13197. }));
  13198. };
  13199. return scale;
  13200. }
  13201. function log() {
  13202. const scale = loggish(transformer$2()).domain([1, 10]);
  13203. scale.copy = () => copy$1(scale, log()).base(scale.base());
  13204. initRange.apply(scale, arguments);
  13205. return scale;
  13206. }
  13207. function transformSymlog(c) {
  13208. return function(x) {
  13209. return Math.sign(x) * Math.log1p(Math.abs(x / c));
  13210. };
  13211. }
  13212. function transformSymexp(c) {
  13213. return function(x) {
  13214. return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
  13215. };
  13216. }
  13217. function symlogish(transform) {
  13218. var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
  13219. scale.constant = function(_) {
  13220. return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
  13221. };
  13222. return linearish(scale);
  13223. }
  13224. function symlog() {
  13225. var scale = symlogish(transformer$2());
  13226. scale.copy = function() {
  13227. return copy$1(scale, symlog()).constant(scale.constant());
  13228. };
  13229. return initRange.apply(scale, arguments);
  13230. }
  13231. function transformPow(exponent) {
  13232. return function(x) {
  13233. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  13234. };
  13235. }
  13236. function transformSqrt(x) {
  13237. return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
  13238. }
  13239. function transformSquare(x) {
  13240. return x < 0 ? -x * x : x * x;
  13241. }
  13242. function powish(transform) {
  13243. var scale = transform(identity$3, identity$3),
  13244. exponent = 1;
  13245. function rescale() {
  13246. return exponent === 1 ? transform(identity$3, identity$3)
  13247. : exponent === 0.5 ? transform(transformSqrt, transformSquare)
  13248. : transform(transformPow(exponent), transformPow(1 / exponent));
  13249. }
  13250. scale.exponent = function(_) {
  13251. return arguments.length ? (exponent = +_, rescale()) : exponent;
  13252. };
  13253. return linearish(scale);
  13254. }
  13255. function pow() {
  13256. var scale = powish(transformer$2());
  13257. scale.copy = function() {
  13258. return copy$1(scale, pow()).exponent(scale.exponent());
  13259. };
  13260. initRange.apply(scale, arguments);
  13261. return scale;
  13262. }
  13263. function sqrt$1() {
  13264. return pow.apply(null, arguments).exponent(0.5);
  13265. }
  13266. function square$1(x) {
  13267. return Math.sign(x) * x * x;
  13268. }
  13269. function unsquare(x) {
  13270. return Math.sign(x) * Math.sqrt(Math.abs(x));
  13271. }
  13272. function radial() {
  13273. var squared = continuous(),
  13274. range = [0, 1],
  13275. round = false,
  13276. unknown;
  13277. function scale(x) {
  13278. var y = unsquare(squared(x));
  13279. return isNaN(y) ? unknown : round ? Math.round(y) : y;
  13280. }
  13281. scale.invert = function(y) {
  13282. return squared.invert(square$1(y));
  13283. };
  13284. scale.domain = function(_) {
  13285. return arguments.length ? (squared.domain(_), scale) : squared.domain();
  13286. };
  13287. scale.range = function(_) {
  13288. return arguments.length ? (squared.range((range = Array.from(_, number$1)).map(square$1)), scale) : range.slice();
  13289. };
  13290. scale.rangeRound = function(_) {
  13291. return scale.range(_).round(true);
  13292. };
  13293. scale.round = function(_) {
  13294. return arguments.length ? (round = !!_, scale) : round;
  13295. };
  13296. scale.clamp = function(_) {
  13297. return arguments.length ? (squared.clamp(_), scale) : squared.clamp();
  13298. };
  13299. scale.unknown = function(_) {
  13300. return arguments.length ? (unknown = _, scale) : unknown;
  13301. };
  13302. scale.copy = function() {
  13303. return radial(squared.domain(), range)
  13304. .round(round)
  13305. .clamp(squared.clamp())
  13306. .unknown(unknown);
  13307. };
  13308. initRange.apply(scale, arguments);
  13309. return linearish(scale);
  13310. }
  13311. function quantile() {
  13312. var domain = [],
  13313. range = [],
  13314. thresholds = [],
  13315. unknown;
  13316. function rescale() {
  13317. var i = 0, n = Math.max(1, range.length);
  13318. thresholds = new Array(n - 1);
  13319. while (++i < n) thresholds[i - 1] = quantileSorted(domain, i / n);
  13320. return scale;
  13321. }
  13322. function scale(x) {
  13323. return x == null || isNaN(x = +x) ? unknown : range[bisect(thresholds, x)];
  13324. }
  13325. scale.invertExtent = function(y) {
  13326. var i = range.indexOf(y);
  13327. return i < 0 ? [NaN, NaN] : [
  13328. i > 0 ? thresholds[i - 1] : domain[0],
  13329. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  13330. ];
  13331. };
  13332. scale.domain = function(_) {
  13333. if (!arguments.length) return domain.slice();
  13334. domain = [];
  13335. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  13336. domain.sort(ascending$3);
  13337. return rescale();
  13338. };
  13339. scale.range = function(_) {
  13340. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  13341. };
  13342. scale.unknown = function(_) {
  13343. return arguments.length ? (unknown = _, scale) : unknown;
  13344. };
  13345. scale.quantiles = function() {
  13346. return thresholds.slice();
  13347. };
  13348. scale.copy = function() {
  13349. return quantile()
  13350. .domain(domain)
  13351. .range(range)
  13352. .unknown(unknown);
  13353. };
  13354. return initRange.apply(scale, arguments);
  13355. }
  13356. function quantize() {
  13357. var x0 = 0,
  13358. x1 = 1,
  13359. n = 1,
  13360. domain = [0.5],
  13361. range = [0, 1],
  13362. unknown;
  13363. function scale(x) {
  13364. return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
  13365. }
  13366. function rescale() {
  13367. var i = -1;
  13368. domain = new Array(n);
  13369. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  13370. return scale;
  13371. }
  13372. scale.domain = function(_) {
  13373. return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
  13374. };
  13375. scale.range = function(_) {
  13376. return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
  13377. };
  13378. scale.invertExtent = function(y) {
  13379. var i = range.indexOf(y);
  13380. return i < 0 ? [NaN, NaN]
  13381. : i < 1 ? [x0, domain[0]]
  13382. : i >= n ? [domain[n - 1], x1]
  13383. : [domain[i - 1], domain[i]];
  13384. };
  13385. scale.unknown = function(_) {
  13386. return arguments.length ? (unknown = _, scale) : scale;
  13387. };
  13388. scale.thresholds = function() {
  13389. return domain.slice();
  13390. };
  13391. scale.copy = function() {
  13392. return quantize()
  13393. .domain([x0, x1])
  13394. .range(range)
  13395. .unknown(unknown);
  13396. };
  13397. return initRange.apply(linearish(scale), arguments);
  13398. }
  13399. function threshold() {
  13400. var domain = [0.5],
  13401. range = [0, 1],
  13402. unknown,
  13403. n = 1;
  13404. function scale(x) {
  13405. return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
  13406. }
  13407. scale.domain = function(_) {
  13408. return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  13409. };
  13410. scale.range = function(_) {
  13411. return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  13412. };
  13413. scale.invertExtent = function(y) {
  13414. var i = range.indexOf(y);
  13415. return [domain[i - 1], domain[i]];
  13416. };
  13417. scale.unknown = function(_) {
  13418. return arguments.length ? (unknown = _, scale) : unknown;
  13419. };
  13420. scale.copy = function() {
  13421. return threshold()
  13422. .domain(domain)
  13423. .range(range)
  13424. .unknown(unknown);
  13425. };
  13426. return initRange.apply(scale, arguments);
  13427. }
  13428. const t0 = new Date, t1 = new Date;
  13429. function timeInterval(floori, offseti, count, field) {
  13430. function interval(date) {
  13431. return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
  13432. }
  13433. interval.floor = (date) => {
  13434. return floori(date = new Date(+date)), date;
  13435. };
  13436. interval.ceil = (date) => {
  13437. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  13438. };
  13439. interval.round = (date) => {
  13440. const d0 = interval(date), d1 = interval.ceil(date);
  13441. return date - d0 < d1 - date ? d0 : d1;
  13442. };
  13443. interval.offset = (date, step) => {
  13444. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  13445. };
  13446. interval.range = (start, stop, step) => {
  13447. const range = [];
  13448. start = interval.ceil(start);
  13449. step = step == null ? 1 : Math.floor(step);
  13450. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  13451. let previous;
  13452. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  13453. while (previous < start && start < stop);
  13454. return range;
  13455. };
  13456. interval.filter = (test) => {
  13457. return timeInterval((date) => {
  13458. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  13459. }, (date, step) => {
  13460. if (date >= date) {
  13461. if (step < 0) while (++step <= 0) {
  13462. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  13463. } else while (--step >= 0) {
  13464. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  13465. }
  13466. }
  13467. });
  13468. };
  13469. if (count) {
  13470. interval.count = (start, end) => {
  13471. t0.setTime(+start), t1.setTime(+end);
  13472. floori(t0), floori(t1);
  13473. return Math.floor(count(t0, t1));
  13474. };
  13475. interval.every = (step) => {
  13476. step = Math.floor(step);
  13477. return !isFinite(step) || !(step > 0) ? null
  13478. : !(step > 1) ? interval
  13479. : interval.filter(field
  13480. ? (d) => field(d) % step === 0
  13481. : (d) => interval.count(0, d) % step === 0);
  13482. };
  13483. }
  13484. return interval;
  13485. }
  13486. const millisecond = timeInterval(() => {
  13487. // noop
  13488. }, (date, step) => {
  13489. date.setTime(+date + step);
  13490. }, (start, end) => {
  13491. return end - start;
  13492. });
  13493. // An optimized implementation for this simple case.
  13494. millisecond.every = (k) => {
  13495. k = Math.floor(k);
  13496. if (!isFinite(k) || !(k > 0)) return null;
  13497. if (!(k > 1)) return millisecond;
  13498. return timeInterval((date) => {
  13499. date.setTime(Math.floor(date / k) * k);
  13500. }, (date, step) => {
  13501. date.setTime(+date + step * k);
  13502. }, (start, end) => {
  13503. return (end - start) / k;
  13504. });
  13505. };
  13506. const milliseconds = millisecond.range;
  13507. const durationSecond = 1000;
  13508. const durationMinute = durationSecond * 60;
  13509. const durationHour = durationMinute * 60;
  13510. const durationDay = durationHour * 24;
  13511. const durationWeek = durationDay * 7;
  13512. const durationMonth = durationDay * 30;
  13513. const durationYear = durationDay * 365;
  13514. const second = timeInterval((date) => {
  13515. date.setTime(date - date.getMilliseconds());
  13516. }, (date, step) => {
  13517. date.setTime(+date + step * durationSecond);
  13518. }, (start, end) => {
  13519. return (end - start) / durationSecond;
  13520. }, (date) => {
  13521. return date.getUTCSeconds();
  13522. });
  13523. const seconds = second.range;
  13524. const timeMinute = timeInterval((date) => {
  13525. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
  13526. }, (date, step) => {
  13527. date.setTime(+date + step * durationMinute);
  13528. }, (start, end) => {
  13529. return (end - start) / durationMinute;
  13530. }, (date) => {
  13531. return date.getMinutes();
  13532. });
  13533. const timeMinutes = timeMinute.range;
  13534. const utcMinute = timeInterval((date) => {
  13535. date.setUTCSeconds(0, 0);
  13536. }, (date, step) => {
  13537. date.setTime(+date + step * durationMinute);
  13538. }, (start, end) => {
  13539. return (end - start) / durationMinute;
  13540. }, (date) => {
  13541. return date.getUTCMinutes();
  13542. });
  13543. const utcMinutes = utcMinute.range;
  13544. const timeHour = timeInterval((date) => {
  13545. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
  13546. }, (date, step) => {
  13547. date.setTime(+date + step * durationHour);
  13548. }, (start, end) => {
  13549. return (end - start) / durationHour;
  13550. }, (date) => {
  13551. return date.getHours();
  13552. });
  13553. const timeHours = timeHour.range;
  13554. const utcHour = timeInterval((date) => {
  13555. date.setUTCMinutes(0, 0, 0);
  13556. }, (date, step) => {
  13557. date.setTime(+date + step * durationHour);
  13558. }, (start, end) => {
  13559. return (end - start) / durationHour;
  13560. }, (date) => {
  13561. return date.getUTCHours();
  13562. });
  13563. const utcHours = utcHour.range;
  13564. const timeDay = timeInterval(
  13565. date => date.setHours(0, 0, 0, 0),
  13566. (date, step) => date.setDate(date.getDate() + step),
  13567. (start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay,
  13568. date => date.getDate() - 1
  13569. );
  13570. const timeDays = timeDay.range;
  13571. const utcDay = timeInterval((date) => {
  13572. date.setUTCHours(0, 0, 0, 0);
  13573. }, (date, step) => {
  13574. date.setUTCDate(date.getUTCDate() + step);
  13575. }, (start, end) => {
  13576. return (end - start) / durationDay;
  13577. }, (date) => {
  13578. return date.getUTCDate() - 1;
  13579. });
  13580. const utcDays = utcDay.range;
  13581. const unixDay = timeInterval((date) => {
  13582. date.setUTCHours(0, 0, 0, 0);
  13583. }, (date, step) => {
  13584. date.setUTCDate(date.getUTCDate() + step);
  13585. }, (start, end) => {
  13586. return (end - start) / durationDay;
  13587. }, (date) => {
  13588. return Math.floor(date / durationDay);
  13589. });
  13590. const unixDays = unixDay.range;
  13591. function timeWeekday(i) {
  13592. return timeInterval((date) => {
  13593. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  13594. date.setHours(0, 0, 0, 0);
  13595. }, (date, step) => {
  13596. date.setDate(date.getDate() + step * 7);
  13597. }, (start, end) => {
  13598. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  13599. });
  13600. }
  13601. const timeSunday = timeWeekday(0);
  13602. const timeMonday = timeWeekday(1);
  13603. const timeTuesday = timeWeekday(2);
  13604. const timeWednesday = timeWeekday(3);
  13605. const timeThursday = timeWeekday(4);
  13606. const timeFriday = timeWeekday(5);
  13607. const timeSaturday = timeWeekday(6);
  13608. const timeSundays = timeSunday.range;
  13609. const timeMondays = timeMonday.range;
  13610. const timeTuesdays = timeTuesday.range;
  13611. const timeWednesdays = timeWednesday.range;
  13612. const timeThursdays = timeThursday.range;
  13613. const timeFridays = timeFriday.range;
  13614. const timeSaturdays = timeSaturday.range;
  13615. function utcWeekday(i) {
  13616. return timeInterval((date) => {
  13617. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  13618. date.setUTCHours(0, 0, 0, 0);
  13619. }, (date, step) => {
  13620. date.setUTCDate(date.getUTCDate() + step * 7);
  13621. }, (start, end) => {
  13622. return (end - start) / durationWeek;
  13623. });
  13624. }
  13625. const utcSunday = utcWeekday(0);
  13626. const utcMonday = utcWeekday(1);
  13627. const utcTuesday = utcWeekday(2);
  13628. const utcWednesday = utcWeekday(3);
  13629. const utcThursday = utcWeekday(4);
  13630. const utcFriday = utcWeekday(5);
  13631. const utcSaturday = utcWeekday(6);
  13632. const utcSundays = utcSunday.range;
  13633. const utcMondays = utcMonday.range;
  13634. const utcTuesdays = utcTuesday.range;
  13635. const utcWednesdays = utcWednesday.range;
  13636. const utcThursdays = utcThursday.range;
  13637. const utcFridays = utcFriday.range;
  13638. const utcSaturdays = utcSaturday.range;
  13639. const timeMonth = timeInterval((date) => {
  13640. date.setDate(1);
  13641. date.setHours(0, 0, 0, 0);
  13642. }, (date, step) => {
  13643. date.setMonth(date.getMonth() + step);
  13644. }, (start, end) => {
  13645. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  13646. }, (date) => {
  13647. return date.getMonth();
  13648. });
  13649. const timeMonths = timeMonth.range;
  13650. const utcMonth = timeInterval((date) => {
  13651. date.setUTCDate(1);
  13652. date.setUTCHours(0, 0, 0, 0);
  13653. }, (date, step) => {
  13654. date.setUTCMonth(date.getUTCMonth() + step);
  13655. }, (start, end) => {
  13656. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  13657. }, (date) => {
  13658. return date.getUTCMonth();
  13659. });
  13660. const utcMonths = utcMonth.range;
  13661. const timeYear = timeInterval((date) => {
  13662. date.setMonth(0, 1);
  13663. date.setHours(0, 0, 0, 0);
  13664. }, (date, step) => {
  13665. date.setFullYear(date.getFullYear() + step);
  13666. }, (start, end) => {
  13667. return end.getFullYear() - start.getFullYear();
  13668. }, (date) => {
  13669. return date.getFullYear();
  13670. });
  13671. // An optimized implementation for this simple case.
  13672. timeYear.every = (k) => {
  13673. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
  13674. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  13675. date.setMonth(0, 1);
  13676. date.setHours(0, 0, 0, 0);
  13677. }, (date, step) => {
  13678. date.setFullYear(date.getFullYear() + step * k);
  13679. });
  13680. };
  13681. const timeYears = timeYear.range;
  13682. const utcYear = timeInterval((date) => {
  13683. date.setUTCMonth(0, 1);
  13684. date.setUTCHours(0, 0, 0, 0);
  13685. }, (date, step) => {
  13686. date.setUTCFullYear(date.getUTCFullYear() + step);
  13687. }, (start, end) => {
  13688. return end.getUTCFullYear() - start.getUTCFullYear();
  13689. }, (date) => {
  13690. return date.getUTCFullYear();
  13691. });
  13692. // An optimized implementation for this simple case.
  13693. utcYear.every = (k) => {
  13694. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
  13695. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  13696. date.setUTCMonth(0, 1);
  13697. date.setUTCHours(0, 0, 0, 0);
  13698. }, (date, step) => {
  13699. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  13700. });
  13701. };
  13702. const utcYears = utcYear.range;
  13703. function ticker(year, month, week, day, hour, minute) {
  13704. const tickIntervals = [
  13705. [second, 1, durationSecond],
  13706. [second, 5, 5 * durationSecond],
  13707. [second, 15, 15 * durationSecond],
  13708. [second, 30, 30 * durationSecond],
  13709. [minute, 1, durationMinute],
  13710. [minute, 5, 5 * durationMinute],
  13711. [minute, 15, 15 * durationMinute],
  13712. [minute, 30, 30 * durationMinute],
  13713. [ hour, 1, durationHour ],
  13714. [ hour, 3, 3 * durationHour ],
  13715. [ hour, 6, 6 * durationHour ],
  13716. [ hour, 12, 12 * durationHour ],
  13717. [ day, 1, durationDay ],
  13718. [ day, 2, 2 * durationDay ],
  13719. [ week, 1, durationWeek ],
  13720. [ month, 1, durationMonth ],
  13721. [ month, 3, 3 * durationMonth ],
  13722. [ year, 1, durationYear ]
  13723. ];
  13724. function ticks(start, stop, count) {
  13725. const reverse = stop < start;
  13726. if (reverse) [start, stop] = [stop, start];
  13727. const interval = count && typeof count.range === "function" ? count : tickInterval(start, stop, count);
  13728. const ticks = interval ? interval.range(start, +stop + 1) : []; // inclusive stop
  13729. return reverse ? ticks.reverse() : ticks;
  13730. }
  13731. function tickInterval(start, stop, count) {
  13732. const target = Math.abs(stop - start) / count;
  13733. const i = bisector(([,, step]) => step).right(tickIntervals, target);
  13734. if (i === tickIntervals.length) return year.every(tickStep(start / durationYear, stop / durationYear, count));
  13735. if (i === 0) return millisecond.every(Math.max(tickStep(start, stop, count), 1));
  13736. const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  13737. return t.every(step);
  13738. }
  13739. return [ticks, tickInterval];
  13740. }
  13741. const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute);
  13742. const [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);
  13743. function localDate(d) {
  13744. if (0 <= d.y && d.y < 100) {
  13745. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  13746. date.setFullYear(d.y);
  13747. return date;
  13748. }
  13749. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  13750. }
  13751. function utcDate(d) {
  13752. if (0 <= d.y && d.y < 100) {
  13753. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  13754. date.setUTCFullYear(d.y);
  13755. return date;
  13756. }
  13757. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  13758. }
  13759. function newDate(y, m, d) {
  13760. return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
  13761. }
  13762. function formatLocale(locale) {
  13763. var locale_dateTime = locale.dateTime,
  13764. locale_date = locale.date,
  13765. locale_time = locale.time,
  13766. locale_periods = locale.periods,
  13767. locale_weekdays = locale.days,
  13768. locale_shortWeekdays = locale.shortDays,
  13769. locale_months = locale.months,
  13770. locale_shortMonths = locale.shortMonths;
  13771. var periodRe = formatRe(locale_periods),
  13772. periodLookup = formatLookup(locale_periods),
  13773. weekdayRe = formatRe(locale_weekdays),
  13774. weekdayLookup = formatLookup(locale_weekdays),
  13775. shortWeekdayRe = formatRe(locale_shortWeekdays),
  13776. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  13777. monthRe = formatRe(locale_months),
  13778. monthLookup = formatLookup(locale_months),
  13779. shortMonthRe = formatRe(locale_shortMonths),
  13780. shortMonthLookup = formatLookup(locale_shortMonths);
  13781. var formats = {
  13782. "a": formatShortWeekday,
  13783. "A": formatWeekday,
  13784. "b": formatShortMonth,
  13785. "B": formatMonth,
  13786. "c": null,
  13787. "d": formatDayOfMonth,
  13788. "e": formatDayOfMonth,
  13789. "f": formatMicroseconds,
  13790. "g": formatYearISO,
  13791. "G": formatFullYearISO,
  13792. "H": formatHour24,
  13793. "I": formatHour12,
  13794. "j": formatDayOfYear,
  13795. "L": formatMilliseconds,
  13796. "m": formatMonthNumber,
  13797. "M": formatMinutes,
  13798. "p": formatPeriod,
  13799. "q": formatQuarter,
  13800. "Q": formatUnixTimestamp,
  13801. "s": formatUnixTimestampSeconds,
  13802. "S": formatSeconds,
  13803. "u": formatWeekdayNumberMonday,
  13804. "U": formatWeekNumberSunday,
  13805. "V": formatWeekNumberISO,
  13806. "w": formatWeekdayNumberSunday,
  13807. "W": formatWeekNumberMonday,
  13808. "x": null,
  13809. "X": null,
  13810. "y": formatYear,
  13811. "Y": formatFullYear,
  13812. "Z": formatZone,
  13813. "%": formatLiteralPercent
  13814. };
  13815. var utcFormats = {
  13816. "a": formatUTCShortWeekday,
  13817. "A": formatUTCWeekday,
  13818. "b": formatUTCShortMonth,
  13819. "B": formatUTCMonth,
  13820. "c": null,
  13821. "d": formatUTCDayOfMonth,
  13822. "e": formatUTCDayOfMonth,
  13823. "f": formatUTCMicroseconds,
  13824. "g": formatUTCYearISO,
  13825. "G": formatUTCFullYearISO,
  13826. "H": formatUTCHour24,
  13827. "I": formatUTCHour12,
  13828. "j": formatUTCDayOfYear,
  13829. "L": formatUTCMilliseconds,
  13830. "m": formatUTCMonthNumber,
  13831. "M": formatUTCMinutes,
  13832. "p": formatUTCPeriod,
  13833. "q": formatUTCQuarter,
  13834. "Q": formatUnixTimestamp,
  13835. "s": formatUnixTimestampSeconds,
  13836. "S": formatUTCSeconds,
  13837. "u": formatUTCWeekdayNumberMonday,
  13838. "U": formatUTCWeekNumberSunday,
  13839. "V": formatUTCWeekNumberISO,
  13840. "w": formatUTCWeekdayNumberSunday,
  13841. "W": formatUTCWeekNumberMonday,
  13842. "x": null,
  13843. "X": null,
  13844. "y": formatUTCYear,
  13845. "Y": formatUTCFullYear,
  13846. "Z": formatUTCZone,
  13847. "%": formatLiteralPercent
  13848. };
  13849. var parses = {
  13850. "a": parseShortWeekday,
  13851. "A": parseWeekday,
  13852. "b": parseShortMonth,
  13853. "B": parseMonth,
  13854. "c": parseLocaleDateTime,
  13855. "d": parseDayOfMonth,
  13856. "e": parseDayOfMonth,
  13857. "f": parseMicroseconds,
  13858. "g": parseYear,
  13859. "G": parseFullYear,
  13860. "H": parseHour24,
  13861. "I": parseHour24,
  13862. "j": parseDayOfYear,
  13863. "L": parseMilliseconds,
  13864. "m": parseMonthNumber,
  13865. "M": parseMinutes,
  13866. "p": parsePeriod,
  13867. "q": parseQuarter,
  13868. "Q": parseUnixTimestamp,
  13869. "s": parseUnixTimestampSeconds,
  13870. "S": parseSeconds,
  13871. "u": parseWeekdayNumberMonday,
  13872. "U": parseWeekNumberSunday,
  13873. "V": parseWeekNumberISO,
  13874. "w": parseWeekdayNumberSunday,
  13875. "W": parseWeekNumberMonday,
  13876. "x": parseLocaleDate,
  13877. "X": parseLocaleTime,
  13878. "y": parseYear,
  13879. "Y": parseFullYear,
  13880. "Z": parseZone,
  13881. "%": parseLiteralPercent
  13882. };
  13883. // These recursive directive definitions must be deferred.
  13884. formats.x = newFormat(locale_date, formats);
  13885. formats.X = newFormat(locale_time, formats);
  13886. formats.c = newFormat(locale_dateTime, formats);
  13887. utcFormats.x = newFormat(locale_date, utcFormats);
  13888. utcFormats.X = newFormat(locale_time, utcFormats);
  13889. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  13890. function newFormat(specifier, formats) {
  13891. return function(date) {
  13892. var string = [],
  13893. i = -1,
  13894. j = 0,
  13895. n = specifier.length,
  13896. c,
  13897. pad,
  13898. format;
  13899. if (!(date instanceof Date)) date = new Date(+date);
  13900. while (++i < n) {
  13901. if (specifier.charCodeAt(i) === 37) {
  13902. string.push(specifier.slice(j, i));
  13903. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  13904. else pad = c === "e" ? " " : "0";
  13905. if (format = formats[c]) c = format(date, pad);
  13906. string.push(c);
  13907. j = i + 1;
  13908. }
  13909. }
  13910. string.push(specifier.slice(j, i));
  13911. return string.join("");
  13912. };
  13913. }
  13914. function newParse(specifier, Z) {
  13915. return function(string) {
  13916. var d = newDate(1900, undefined, 1),
  13917. i = parseSpecifier(d, specifier, string += "", 0),
  13918. week, day;
  13919. if (i != string.length) return null;
  13920. // If a UNIX timestamp is specified, return it.
  13921. if ("Q" in d) return new Date(d.Q);
  13922. if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
  13923. // If this is utcParse, never use the local timezone.
  13924. if (Z && !("Z" in d)) d.Z = 0;
  13925. // The am-pm flag is 0 for AM, and 1 for PM.
  13926. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  13927. // If the month was not specified, inherit from the quarter.
  13928. if (d.m === undefined) d.m = "q" in d ? d.q : 0;
  13929. // Convert day-of-week and week-of-year to day-of-year.
  13930. if ("V" in d) {
  13931. if (d.V < 1 || d.V > 53) return null;
  13932. if (!("w" in d)) d.w = 1;
  13933. if ("Z" in d) {
  13934. week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
  13935. week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
  13936. week = utcDay.offset(week, (d.V - 1) * 7);
  13937. d.y = week.getUTCFullYear();
  13938. d.m = week.getUTCMonth();
  13939. d.d = week.getUTCDate() + (d.w + 6) % 7;
  13940. } else {
  13941. week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
  13942. week = day > 4 || day === 0 ? timeMonday.ceil(week) : timeMonday(week);
  13943. week = timeDay.offset(week, (d.V - 1) * 7);
  13944. d.y = week.getFullYear();
  13945. d.m = week.getMonth();
  13946. d.d = week.getDate() + (d.w + 6) % 7;
  13947. }
  13948. } else if ("W" in d || "U" in d) {
  13949. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  13950. day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
  13951. d.m = 0;
  13952. d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
  13953. }
  13954. // If a time zone is specified, all fields are interpreted as UTC and then
  13955. // offset according to the specified time zone.
  13956. if ("Z" in d) {
  13957. d.H += d.Z / 100 | 0;
  13958. d.M += d.Z % 100;
  13959. return utcDate(d);
  13960. }
  13961. // Otherwise, all fields are in local time.
  13962. return localDate(d);
  13963. };
  13964. }
  13965. function parseSpecifier(d, specifier, string, j) {
  13966. var i = 0,
  13967. n = specifier.length,
  13968. m = string.length,
  13969. c,
  13970. parse;
  13971. while (i < n) {
  13972. if (j >= m) return -1;
  13973. c = specifier.charCodeAt(i++);
  13974. if (c === 37) {
  13975. c = specifier.charAt(i++);
  13976. parse = parses[c in pads ? specifier.charAt(i++) : c];
  13977. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  13978. } else if (c != string.charCodeAt(j++)) {
  13979. return -1;
  13980. }
  13981. }
  13982. return j;
  13983. }
  13984. function parsePeriod(d, string, i) {
  13985. var n = periodRe.exec(string.slice(i));
  13986. return n ? (d.p = periodLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13987. }
  13988. function parseShortWeekday(d, string, i) {
  13989. var n = shortWeekdayRe.exec(string.slice(i));
  13990. return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13991. }
  13992. function parseWeekday(d, string, i) {
  13993. var n = weekdayRe.exec(string.slice(i));
  13994. return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13995. }
  13996. function parseShortMonth(d, string, i) {
  13997. var n = shortMonthRe.exec(string.slice(i));
  13998. return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13999. }
  14000. function parseMonth(d, string, i) {
  14001. var n = monthRe.exec(string.slice(i));
  14002. return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  14003. }
  14004. function parseLocaleDateTime(d, string, i) {
  14005. return parseSpecifier(d, locale_dateTime, string, i);
  14006. }
  14007. function parseLocaleDate(d, string, i) {
  14008. return parseSpecifier(d, locale_date, string, i);
  14009. }
  14010. function parseLocaleTime(d, string, i) {
  14011. return parseSpecifier(d, locale_time, string, i);
  14012. }
  14013. function formatShortWeekday(d) {
  14014. return locale_shortWeekdays[d.getDay()];
  14015. }
  14016. function formatWeekday(d) {
  14017. return locale_weekdays[d.getDay()];
  14018. }
  14019. function formatShortMonth(d) {
  14020. return locale_shortMonths[d.getMonth()];
  14021. }
  14022. function formatMonth(d) {
  14023. return locale_months[d.getMonth()];
  14024. }
  14025. function formatPeriod(d) {
  14026. return locale_periods[+(d.getHours() >= 12)];
  14027. }
  14028. function formatQuarter(d) {
  14029. return 1 + ~~(d.getMonth() / 3);
  14030. }
  14031. function formatUTCShortWeekday(d) {
  14032. return locale_shortWeekdays[d.getUTCDay()];
  14033. }
  14034. function formatUTCWeekday(d) {
  14035. return locale_weekdays[d.getUTCDay()];
  14036. }
  14037. function formatUTCShortMonth(d) {
  14038. return locale_shortMonths[d.getUTCMonth()];
  14039. }
  14040. function formatUTCMonth(d) {
  14041. return locale_months[d.getUTCMonth()];
  14042. }
  14043. function formatUTCPeriod(d) {
  14044. return locale_periods[+(d.getUTCHours() >= 12)];
  14045. }
  14046. function formatUTCQuarter(d) {
  14047. return 1 + ~~(d.getUTCMonth() / 3);
  14048. }
  14049. return {
  14050. format: function(specifier) {
  14051. var f = newFormat(specifier += "", formats);
  14052. f.toString = function() { return specifier; };
  14053. return f;
  14054. },
  14055. parse: function(specifier) {
  14056. var p = newParse(specifier += "", false);
  14057. p.toString = function() { return specifier; };
  14058. return p;
  14059. },
  14060. utcFormat: function(specifier) {
  14061. var f = newFormat(specifier += "", utcFormats);
  14062. f.toString = function() { return specifier; };
  14063. return f;
  14064. },
  14065. utcParse: function(specifier) {
  14066. var p = newParse(specifier += "", true);
  14067. p.toString = function() { return specifier; };
  14068. return p;
  14069. }
  14070. };
  14071. }
  14072. var pads = {"-": "", "_": " ", "0": "0"},
  14073. numberRe = /^\s*\d+/, // note: ignores next directive
  14074. percentRe = /^%/,
  14075. requoteRe = /[\\^$*+?|[\]().{}]/g;
  14076. function pad(value, fill, width) {
  14077. var sign = value < 0 ? "-" : "",
  14078. string = (sign ? -value : value) + "",
  14079. length = string.length;
  14080. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  14081. }
  14082. function requote(s) {
  14083. return s.replace(requoteRe, "\\$&");
  14084. }
  14085. function formatRe(names) {
  14086. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  14087. }
  14088. function formatLookup(names) {
  14089. return new Map(names.map((name, i) => [name.toLowerCase(), i]));
  14090. }
  14091. function parseWeekdayNumberSunday(d, string, i) {
  14092. var n = numberRe.exec(string.slice(i, i + 1));
  14093. return n ? (d.w = +n[0], i + n[0].length) : -1;
  14094. }
  14095. function parseWeekdayNumberMonday(d, string, i) {
  14096. var n = numberRe.exec(string.slice(i, i + 1));
  14097. return n ? (d.u = +n[0], i + n[0].length) : -1;
  14098. }
  14099. function parseWeekNumberSunday(d, string, i) {
  14100. var n = numberRe.exec(string.slice(i, i + 2));
  14101. return n ? (d.U = +n[0], i + n[0].length) : -1;
  14102. }
  14103. function parseWeekNumberISO(d, string, i) {
  14104. var n = numberRe.exec(string.slice(i, i + 2));
  14105. return n ? (d.V = +n[0], i + n[0].length) : -1;
  14106. }
  14107. function parseWeekNumberMonday(d, string, i) {
  14108. var n = numberRe.exec(string.slice(i, i + 2));
  14109. return n ? (d.W = +n[0], i + n[0].length) : -1;
  14110. }
  14111. function parseFullYear(d, string, i) {
  14112. var n = numberRe.exec(string.slice(i, i + 4));
  14113. return n ? (d.y = +n[0], i + n[0].length) : -1;
  14114. }
  14115. function parseYear(d, string, i) {
  14116. var n = numberRe.exec(string.slice(i, i + 2));
  14117. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  14118. }
  14119. function parseZone(d, string, i) {
  14120. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  14121. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  14122. }
  14123. function parseQuarter(d, string, i) {
  14124. var n = numberRe.exec(string.slice(i, i + 1));
  14125. return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
  14126. }
  14127. function parseMonthNumber(d, string, i) {
  14128. var n = numberRe.exec(string.slice(i, i + 2));
  14129. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  14130. }
  14131. function parseDayOfMonth(d, string, i) {
  14132. var n = numberRe.exec(string.slice(i, i + 2));
  14133. return n ? (d.d = +n[0], i + n[0].length) : -1;
  14134. }
  14135. function parseDayOfYear(d, string, i) {
  14136. var n = numberRe.exec(string.slice(i, i + 3));
  14137. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  14138. }
  14139. function parseHour24(d, string, i) {
  14140. var n = numberRe.exec(string.slice(i, i + 2));
  14141. return n ? (d.H = +n[0], i + n[0].length) : -1;
  14142. }
  14143. function parseMinutes(d, string, i) {
  14144. var n = numberRe.exec(string.slice(i, i + 2));
  14145. return n ? (d.M = +n[0], i + n[0].length) : -1;
  14146. }
  14147. function parseSeconds(d, string, i) {
  14148. var n = numberRe.exec(string.slice(i, i + 2));
  14149. return n ? (d.S = +n[0], i + n[0].length) : -1;
  14150. }
  14151. function parseMilliseconds(d, string, i) {
  14152. var n = numberRe.exec(string.slice(i, i + 3));
  14153. return n ? (d.L = +n[0], i + n[0].length) : -1;
  14154. }
  14155. function parseMicroseconds(d, string, i) {
  14156. var n = numberRe.exec(string.slice(i, i + 6));
  14157. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  14158. }
  14159. function parseLiteralPercent(d, string, i) {
  14160. var n = percentRe.exec(string.slice(i, i + 1));
  14161. return n ? i + n[0].length : -1;
  14162. }
  14163. function parseUnixTimestamp(d, string, i) {
  14164. var n = numberRe.exec(string.slice(i));
  14165. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  14166. }
  14167. function parseUnixTimestampSeconds(d, string, i) {
  14168. var n = numberRe.exec(string.slice(i));
  14169. return n ? (d.s = +n[0], i + n[0].length) : -1;
  14170. }
  14171. function formatDayOfMonth(d, p) {
  14172. return pad(d.getDate(), p, 2);
  14173. }
  14174. function formatHour24(d, p) {
  14175. return pad(d.getHours(), p, 2);
  14176. }
  14177. function formatHour12(d, p) {
  14178. return pad(d.getHours() % 12 || 12, p, 2);
  14179. }
  14180. function formatDayOfYear(d, p) {
  14181. return pad(1 + timeDay.count(timeYear(d), d), p, 3);
  14182. }
  14183. function formatMilliseconds(d, p) {
  14184. return pad(d.getMilliseconds(), p, 3);
  14185. }
  14186. function formatMicroseconds(d, p) {
  14187. return formatMilliseconds(d, p) + "000";
  14188. }
  14189. function formatMonthNumber(d, p) {
  14190. return pad(d.getMonth() + 1, p, 2);
  14191. }
  14192. function formatMinutes(d, p) {
  14193. return pad(d.getMinutes(), p, 2);
  14194. }
  14195. function formatSeconds(d, p) {
  14196. return pad(d.getSeconds(), p, 2);
  14197. }
  14198. function formatWeekdayNumberMonday(d) {
  14199. var day = d.getDay();
  14200. return day === 0 ? 7 : day;
  14201. }
  14202. function formatWeekNumberSunday(d, p) {
  14203. return pad(timeSunday.count(timeYear(d) - 1, d), p, 2);
  14204. }
  14205. function dISO(d) {
  14206. var day = d.getDay();
  14207. return (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d);
  14208. }
  14209. function formatWeekNumberISO(d, p) {
  14210. d = dISO(d);
  14211. return pad(timeThursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2);
  14212. }
  14213. function formatWeekdayNumberSunday(d) {
  14214. return d.getDay();
  14215. }
  14216. function formatWeekNumberMonday(d, p) {
  14217. return pad(timeMonday.count(timeYear(d) - 1, d), p, 2);
  14218. }
  14219. function formatYear(d, p) {
  14220. return pad(d.getFullYear() % 100, p, 2);
  14221. }
  14222. function formatYearISO(d, p) {
  14223. d = dISO(d);
  14224. return pad(d.getFullYear() % 100, p, 2);
  14225. }
  14226. function formatFullYear(d, p) {
  14227. return pad(d.getFullYear() % 10000, p, 4);
  14228. }
  14229. function formatFullYearISO(d, p) {
  14230. var day = d.getDay();
  14231. d = (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d);
  14232. return pad(d.getFullYear() % 10000, p, 4);
  14233. }
  14234. function formatZone(d) {
  14235. var z = d.getTimezoneOffset();
  14236. return (z > 0 ? "-" : (z *= -1, "+"))
  14237. + pad(z / 60 | 0, "0", 2)
  14238. + pad(z % 60, "0", 2);
  14239. }
  14240. function formatUTCDayOfMonth(d, p) {
  14241. return pad(d.getUTCDate(), p, 2);
  14242. }
  14243. function formatUTCHour24(d, p) {
  14244. return pad(d.getUTCHours(), p, 2);
  14245. }
  14246. function formatUTCHour12(d, p) {
  14247. return pad(d.getUTCHours() % 12 || 12, p, 2);
  14248. }
  14249. function formatUTCDayOfYear(d, p) {
  14250. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  14251. }
  14252. function formatUTCMilliseconds(d, p) {
  14253. return pad(d.getUTCMilliseconds(), p, 3);
  14254. }
  14255. function formatUTCMicroseconds(d, p) {
  14256. return formatUTCMilliseconds(d, p) + "000";
  14257. }
  14258. function formatUTCMonthNumber(d, p) {
  14259. return pad(d.getUTCMonth() + 1, p, 2);
  14260. }
  14261. function formatUTCMinutes(d, p) {
  14262. return pad(d.getUTCMinutes(), p, 2);
  14263. }
  14264. function formatUTCSeconds(d, p) {
  14265. return pad(d.getUTCSeconds(), p, 2);
  14266. }
  14267. function formatUTCWeekdayNumberMonday(d) {
  14268. var dow = d.getUTCDay();
  14269. return dow === 0 ? 7 : dow;
  14270. }
  14271. function formatUTCWeekNumberSunday(d, p) {
  14272. return pad(utcSunday.count(utcYear(d) - 1, d), p, 2);
  14273. }
  14274. function UTCdISO(d) {
  14275. var day = d.getUTCDay();
  14276. return (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  14277. }
  14278. function formatUTCWeekNumberISO(d, p) {
  14279. d = UTCdISO(d);
  14280. return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  14281. }
  14282. function formatUTCWeekdayNumberSunday(d) {
  14283. return d.getUTCDay();
  14284. }
  14285. function formatUTCWeekNumberMonday(d, p) {
  14286. return pad(utcMonday.count(utcYear(d) - 1, d), p, 2);
  14287. }
  14288. function formatUTCYear(d, p) {
  14289. return pad(d.getUTCFullYear() % 100, p, 2);
  14290. }
  14291. function formatUTCYearISO(d, p) {
  14292. d = UTCdISO(d);
  14293. return pad(d.getUTCFullYear() % 100, p, 2);
  14294. }
  14295. function formatUTCFullYear(d, p) {
  14296. return pad(d.getUTCFullYear() % 10000, p, 4);
  14297. }
  14298. function formatUTCFullYearISO(d, p) {
  14299. var day = d.getUTCDay();
  14300. d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  14301. return pad(d.getUTCFullYear() % 10000, p, 4);
  14302. }
  14303. function formatUTCZone() {
  14304. return "+0000";
  14305. }
  14306. function formatLiteralPercent() {
  14307. return "%";
  14308. }
  14309. function formatUnixTimestamp(d) {
  14310. return +d;
  14311. }
  14312. function formatUnixTimestampSeconds(d) {
  14313. return Math.floor(+d / 1000);
  14314. }
  14315. var locale;
  14316. exports.timeFormat = void 0;
  14317. exports.timeParse = void 0;
  14318. exports.utcFormat = void 0;
  14319. exports.utcParse = void 0;
  14320. defaultLocale({
  14321. dateTime: "%x, %X",
  14322. date: "%-m/%-d/%Y",
  14323. time: "%-I:%M:%S %p",
  14324. periods: ["AM", "PM"],
  14325. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  14326. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  14327. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  14328. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  14329. });
  14330. function defaultLocale(definition) {
  14331. locale = formatLocale(definition);
  14332. exports.timeFormat = locale.format;
  14333. exports.timeParse = locale.parse;
  14334. exports.utcFormat = locale.utcFormat;
  14335. exports.utcParse = locale.utcParse;
  14336. return locale;
  14337. }
  14338. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  14339. function formatIsoNative(date) {
  14340. return date.toISOString();
  14341. }
  14342. var formatIso = Date.prototype.toISOString
  14343. ? formatIsoNative
  14344. : exports.utcFormat(isoSpecifier);
  14345. var formatIso$1 = formatIso;
  14346. function parseIsoNative(string) {
  14347. var date = new Date(string);
  14348. return isNaN(date) ? null : date;
  14349. }
  14350. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  14351. ? parseIsoNative
  14352. : exports.utcParse(isoSpecifier);
  14353. var parseIso$1 = parseIso;
  14354. function date(t) {
  14355. return new Date(t);
  14356. }
  14357. function number(t) {
  14358. return t instanceof Date ? +t : +new Date(+t);
  14359. }
  14360. function calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format) {
  14361. var scale = continuous(),
  14362. invert = scale.invert,
  14363. domain = scale.domain;
  14364. var formatMillisecond = format(".%L"),
  14365. formatSecond = format(":%S"),
  14366. formatMinute = format("%I:%M"),
  14367. formatHour = format("%I %p"),
  14368. formatDay = format("%a %d"),
  14369. formatWeek = format("%b %d"),
  14370. formatMonth = format("%B"),
  14371. formatYear = format("%Y");
  14372. function tickFormat(date) {
  14373. return (second(date) < date ? formatMillisecond
  14374. : minute(date) < date ? formatSecond
  14375. : hour(date) < date ? formatMinute
  14376. : day(date) < date ? formatHour
  14377. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  14378. : year(date) < date ? formatMonth
  14379. : formatYear)(date);
  14380. }
  14381. scale.invert = function(y) {
  14382. return new Date(invert(y));
  14383. };
  14384. scale.domain = function(_) {
  14385. return arguments.length ? domain(Array.from(_, number)) : domain().map(date);
  14386. };
  14387. scale.ticks = function(interval) {
  14388. var d = domain();
  14389. return ticks(d[0], d[d.length - 1], interval == null ? 10 : interval);
  14390. };
  14391. scale.tickFormat = function(count, specifier) {
  14392. return specifier == null ? tickFormat : format(specifier);
  14393. };
  14394. scale.nice = function(interval) {
  14395. var d = domain();
  14396. if (!interval || typeof interval.range !== "function") interval = tickInterval(d[0], d[d.length - 1], interval == null ? 10 : interval);
  14397. return interval ? domain(nice(d, interval)) : scale;
  14398. };
  14399. scale.copy = function() {
  14400. return copy$1(scale, calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format));
  14401. };
  14402. return scale;
  14403. }
  14404. function time() {
  14405. return initRange.apply(calendar(timeTicks, timeTickInterval, timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute, second, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
  14406. }
  14407. function utcTime() {
  14408. return initRange.apply(calendar(utcTicks, utcTickInterval, utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
  14409. }
  14410. function transformer$1() {
  14411. var x0 = 0,
  14412. x1 = 1,
  14413. t0,
  14414. t1,
  14415. k10,
  14416. transform,
  14417. interpolator = identity$3,
  14418. clamp = false,
  14419. unknown;
  14420. function scale(x) {
  14421. return x == null || isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
  14422. }
  14423. scale.domain = function(_) {
  14424. return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
  14425. };
  14426. scale.clamp = function(_) {
  14427. return arguments.length ? (clamp = !!_, scale) : clamp;
  14428. };
  14429. scale.interpolator = function(_) {
  14430. return arguments.length ? (interpolator = _, scale) : interpolator;
  14431. };
  14432. function range(interpolate) {
  14433. return function(_) {
  14434. var r0, r1;
  14435. return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)];
  14436. };
  14437. }
  14438. scale.range = range(interpolate$2);
  14439. scale.rangeRound = range(interpolateRound);
  14440. scale.unknown = function(_) {
  14441. return arguments.length ? (unknown = _, scale) : unknown;
  14442. };
  14443. return function(t) {
  14444. transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
  14445. return scale;
  14446. };
  14447. }
  14448. function copy(source, target) {
  14449. return target
  14450. .domain(source.domain())
  14451. .interpolator(source.interpolator())
  14452. .clamp(source.clamp())
  14453. .unknown(source.unknown());
  14454. }
  14455. function sequential() {
  14456. var scale = linearish(transformer$1()(identity$3));
  14457. scale.copy = function() {
  14458. return copy(scale, sequential());
  14459. };
  14460. return initInterpolator.apply(scale, arguments);
  14461. }
  14462. function sequentialLog() {
  14463. var scale = loggish(transformer$1()).domain([1, 10]);
  14464. scale.copy = function() {
  14465. return copy(scale, sequentialLog()).base(scale.base());
  14466. };
  14467. return initInterpolator.apply(scale, arguments);
  14468. }
  14469. function sequentialSymlog() {
  14470. var scale = symlogish(transformer$1());
  14471. scale.copy = function() {
  14472. return copy(scale, sequentialSymlog()).constant(scale.constant());
  14473. };
  14474. return initInterpolator.apply(scale, arguments);
  14475. }
  14476. function sequentialPow() {
  14477. var scale = powish(transformer$1());
  14478. scale.copy = function() {
  14479. return copy(scale, sequentialPow()).exponent(scale.exponent());
  14480. };
  14481. return initInterpolator.apply(scale, arguments);
  14482. }
  14483. function sequentialSqrt() {
  14484. return sequentialPow.apply(null, arguments).exponent(0.5);
  14485. }
  14486. function sequentialQuantile() {
  14487. var domain = [],
  14488. interpolator = identity$3;
  14489. function scale(x) {
  14490. if (x != null && !isNaN(x = +x)) return interpolator((bisect(domain, x, 1) - 1) / (domain.length - 1));
  14491. }
  14492. scale.domain = function(_) {
  14493. if (!arguments.length) return domain.slice();
  14494. domain = [];
  14495. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  14496. domain.sort(ascending$3);
  14497. return scale;
  14498. };
  14499. scale.interpolator = function(_) {
  14500. return arguments.length ? (interpolator = _, scale) : interpolator;
  14501. };
  14502. scale.range = function() {
  14503. return domain.map((d, i) => interpolator(i / (domain.length - 1)));
  14504. };
  14505. scale.quantiles = function(n) {
  14506. return Array.from({length: n + 1}, (_, i) => quantile$1(domain, i / n));
  14507. };
  14508. scale.copy = function() {
  14509. return sequentialQuantile(interpolator).domain(domain);
  14510. };
  14511. return initInterpolator.apply(scale, arguments);
  14512. }
  14513. function transformer() {
  14514. var x0 = 0,
  14515. x1 = 0.5,
  14516. x2 = 1,
  14517. s = 1,
  14518. t0,
  14519. t1,
  14520. t2,
  14521. k10,
  14522. k21,
  14523. interpolator = identity$3,
  14524. transform,
  14525. clamp = false,
  14526. unknown;
  14527. function scale(x) {
  14528. return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (s * x < s * t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
  14529. }
  14530. scale.domain = function(_) {
  14531. return arguments.length ? ([x0, x1, x2] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), t2 = transform(x2 = +x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1, scale) : [x0, x1, x2];
  14532. };
  14533. scale.clamp = function(_) {
  14534. return arguments.length ? (clamp = !!_, scale) : clamp;
  14535. };
  14536. scale.interpolator = function(_) {
  14537. return arguments.length ? (interpolator = _, scale) : interpolator;
  14538. };
  14539. function range(interpolate) {
  14540. return function(_) {
  14541. var r0, r1, r2;
  14542. return arguments.length ? ([r0, r1, r2] = _, interpolator = piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)];
  14543. };
  14544. }
  14545. scale.range = range(interpolate$2);
  14546. scale.rangeRound = range(interpolateRound);
  14547. scale.unknown = function(_) {
  14548. return arguments.length ? (unknown = _, scale) : unknown;
  14549. };
  14550. return function(t) {
  14551. transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1;
  14552. return scale;
  14553. };
  14554. }
  14555. function diverging$1() {
  14556. var scale = linearish(transformer()(identity$3));
  14557. scale.copy = function() {
  14558. return copy(scale, diverging$1());
  14559. };
  14560. return initInterpolator.apply(scale, arguments);
  14561. }
  14562. function divergingLog() {
  14563. var scale = loggish(transformer()).domain([0.1, 1, 10]);
  14564. scale.copy = function() {
  14565. return copy(scale, divergingLog()).base(scale.base());
  14566. };
  14567. return initInterpolator.apply(scale, arguments);
  14568. }
  14569. function divergingSymlog() {
  14570. var scale = symlogish(transformer());
  14571. scale.copy = function() {
  14572. return copy(scale, divergingSymlog()).constant(scale.constant());
  14573. };
  14574. return initInterpolator.apply(scale, arguments);
  14575. }
  14576. function divergingPow() {
  14577. var scale = powish(transformer());
  14578. scale.copy = function() {
  14579. return copy(scale, divergingPow()).exponent(scale.exponent());
  14580. };
  14581. return initInterpolator.apply(scale, arguments);
  14582. }
  14583. function divergingSqrt() {
  14584. return divergingPow.apply(null, arguments).exponent(0.5);
  14585. }
  14586. function colors(specifier) {
  14587. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  14588. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  14589. return colors;
  14590. }
  14591. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  14592. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  14593. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  14594. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  14595. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  14596. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  14597. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  14598. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  14599. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  14600. var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
  14601. var ramp$1 = scheme => rgbBasis(scheme[scheme.length - 1]);
  14602. var scheme$q = new Array(3).concat(
  14603. "d8b365f5f5f55ab4ac",
  14604. "a6611adfc27d80cdc1018571",
  14605. "a6611adfc27df5f5f580cdc1018571",
  14606. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  14607. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  14608. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  14609. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  14610. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  14611. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  14612. ).map(colors);
  14613. var BrBG = ramp$1(scheme$q);
  14614. var scheme$p = new Array(3).concat(
  14615. "af8dc3f7f7f77fbf7b",
  14616. "7b3294c2a5cfa6dba0008837",
  14617. "7b3294c2a5cff7f7f7a6dba0008837",
  14618. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  14619. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  14620. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  14621. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  14622. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  14623. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  14624. ).map(colors);
  14625. var PRGn = ramp$1(scheme$p);
  14626. var scheme$o = new Array(3).concat(
  14627. "e9a3c9f7f7f7a1d76a",
  14628. "d01c8bf1b6dab8e1864dac26",
  14629. "d01c8bf1b6daf7f7f7b8e1864dac26",
  14630. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  14631. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  14632. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  14633. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  14634. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  14635. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  14636. ).map(colors);
  14637. var PiYG = ramp$1(scheme$o);
  14638. var scheme$n = new Array(3).concat(
  14639. "998ec3f7f7f7f1a340",
  14640. "5e3c99b2abd2fdb863e66101",
  14641. "5e3c99b2abd2f7f7f7fdb863e66101",
  14642. "542788998ec3d8daebfee0b6f1a340b35806",
  14643. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  14644. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  14645. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  14646. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  14647. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  14648. ).map(colors);
  14649. var PuOr = ramp$1(scheme$n);
  14650. var scheme$m = new Array(3).concat(
  14651. "ef8a62f7f7f767a9cf",
  14652. "ca0020f4a58292c5de0571b0",
  14653. "ca0020f4a582f7f7f792c5de0571b0",
  14654. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  14655. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  14656. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  14657. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  14658. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  14659. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  14660. ).map(colors);
  14661. var RdBu = ramp$1(scheme$m);
  14662. var scheme$l = new Array(3).concat(
  14663. "ef8a62ffffff999999",
  14664. "ca0020f4a582bababa404040",
  14665. "ca0020f4a582ffffffbababa404040",
  14666. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  14667. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  14668. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  14669. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  14670. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  14671. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  14672. ).map(colors);
  14673. var RdGy = ramp$1(scheme$l);
  14674. var scheme$k = new Array(3).concat(
  14675. "fc8d59ffffbf91bfdb",
  14676. "d7191cfdae61abd9e92c7bb6",
  14677. "d7191cfdae61ffffbfabd9e92c7bb6",
  14678. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  14679. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  14680. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  14681. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  14682. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  14683. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  14684. ).map(colors);
  14685. var RdYlBu = ramp$1(scheme$k);
  14686. var scheme$j = new Array(3).concat(
  14687. "fc8d59ffffbf91cf60",
  14688. "d7191cfdae61a6d96a1a9641",
  14689. "d7191cfdae61ffffbfa6d96a1a9641",
  14690. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  14691. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  14692. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  14693. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  14694. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  14695. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  14696. ).map(colors);
  14697. var RdYlGn = ramp$1(scheme$j);
  14698. var scheme$i = new Array(3).concat(
  14699. "fc8d59ffffbf99d594",
  14700. "d7191cfdae61abdda42b83ba",
  14701. "d7191cfdae61ffffbfabdda42b83ba",
  14702. "d53e4ffc8d59fee08be6f59899d5943288bd",
  14703. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  14704. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  14705. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  14706. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  14707. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  14708. ).map(colors);
  14709. var Spectral = ramp$1(scheme$i);
  14710. var scheme$h = new Array(3).concat(
  14711. "e5f5f999d8c92ca25f",
  14712. "edf8fbb2e2e266c2a4238b45",
  14713. "edf8fbb2e2e266c2a42ca25f006d2c",
  14714. "edf8fbccece699d8c966c2a42ca25f006d2c",
  14715. "edf8fbccece699d8c966c2a441ae76238b45005824",
  14716. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  14717. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  14718. ).map(colors);
  14719. var BuGn = ramp$1(scheme$h);
  14720. var scheme$g = new Array(3).concat(
  14721. "e0ecf49ebcda8856a7",
  14722. "edf8fbb3cde38c96c688419d",
  14723. "edf8fbb3cde38c96c68856a7810f7c",
  14724. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  14725. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  14726. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  14727. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  14728. ).map(colors);
  14729. var BuPu = ramp$1(scheme$g);
  14730. var scheme$f = new Array(3).concat(
  14731. "e0f3dba8ddb543a2ca",
  14732. "f0f9e8bae4bc7bccc42b8cbe",
  14733. "f0f9e8bae4bc7bccc443a2ca0868ac",
  14734. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  14735. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  14736. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  14737. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  14738. ).map(colors);
  14739. var GnBu = ramp$1(scheme$f);
  14740. var scheme$e = new Array(3).concat(
  14741. "fee8c8fdbb84e34a33",
  14742. "fef0d9fdcc8afc8d59d7301f",
  14743. "fef0d9fdcc8afc8d59e34a33b30000",
  14744. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  14745. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  14746. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  14747. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  14748. ).map(colors);
  14749. var OrRd = ramp$1(scheme$e);
  14750. var scheme$d = new Array(3).concat(
  14751. "ece2f0a6bddb1c9099",
  14752. "f6eff7bdc9e167a9cf02818a",
  14753. "f6eff7bdc9e167a9cf1c9099016c59",
  14754. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  14755. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  14756. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  14757. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  14758. ).map(colors);
  14759. var PuBuGn = ramp$1(scheme$d);
  14760. var scheme$c = new Array(3).concat(
  14761. "ece7f2a6bddb2b8cbe",
  14762. "f1eef6bdc9e174a9cf0570b0",
  14763. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  14764. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  14765. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  14766. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  14767. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  14768. ).map(colors);
  14769. var PuBu = ramp$1(scheme$c);
  14770. var scheme$b = new Array(3).concat(
  14771. "e7e1efc994c7dd1c77",
  14772. "f1eef6d7b5d8df65b0ce1256",
  14773. "f1eef6d7b5d8df65b0dd1c77980043",
  14774. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  14775. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  14776. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  14777. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  14778. ).map(colors);
  14779. var PuRd = ramp$1(scheme$b);
  14780. var scheme$a = new Array(3).concat(
  14781. "fde0ddfa9fb5c51b8a",
  14782. "feebe2fbb4b9f768a1ae017e",
  14783. "feebe2fbb4b9f768a1c51b8a7a0177",
  14784. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  14785. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  14786. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  14787. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  14788. ).map(colors);
  14789. var RdPu = ramp$1(scheme$a);
  14790. var scheme$9 = new Array(3).concat(
  14791. "edf8b17fcdbb2c7fb8",
  14792. "ffffcca1dab441b6c4225ea8",
  14793. "ffffcca1dab441b6c42c7fb8253494",
  14794. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  14795. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  14796. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  14797. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  14798. ).map(colors);
  14799. var YlGnBu = ramp$1(scheme$9);
  14800. var scheme$8 = new Array(3).concat(
  14801. "f7fcb9addd8e31a354",
  14802. "ffffccc2e69978c679238443",
  14803. "ffffccc2e69978c67931a354006837",
  14804. "ffffccd9f0a3addd8e78c67931a354006837",
  14805. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  14806. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  14807. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  14808. ).map(colors);
  14809. var YlGn = ramp$1(scheme$8);
  14810. var scheme$7 = new Array(3).concat(
  14811. "fff7bcfec44fd95f0e",
  14812. "ffffd4fed98efe9929cc4c02",
  14813. "ffffd4fed98efe9929d95f0e993404",
  14814. "ffffd4fee391fec44ffe9929d95f0e993404",
  14815. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  14816. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  14817. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  14818. ).map(colors);
  14819. var YlOrBr = ramp$1(scheme$7);
  14820. var scheme$6 = new Array(3).concat(
  14821. "ffeda0feb24cf03b20",
  14822. "ffffb2fecc5cfd8d3ce31a1c",
  14823. "ffffb2fecc5cfd8d3cf03b20bd0026",
  14824. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  14825. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  14826. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  14827. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  14828. ).map(colors);
  14829. var YlOrRd = ramp$1(scheme$6);
  14830. var scheme$5 = new Array(3).concat(
  14831. "deebf79ecae13182bd",
  14832. "eff3ffbdd7e76baed62171b5",
  14833. "eff3ffbdd7e76baed63182bd08519c",
  14834. "eff3ffc6dbef9ecae16baed63182bd08519c",
  14835. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  14836. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  14837. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  14838. ).map(colors);
  14839. var Blues = ramp$1(scheme$5);
  14840. var scheme$4 = new Array(3).concat(
  14841. "e5f5e0a1d99b31a354",
  14842. "edf8e9bae4b374c476238b45",
  14843. "edf8e9bae4b374c47631a354006d2c",
  14844. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  14845. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  14846. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  14847. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  14848. ).map(colors);
  14849. var Greens = ramp$1(scheme$4);
  14850. var scheme$3 = new Array(3).concat(
  14851. "f0f0f0bdbdbd636363",
  14852. "f7f7f7cccccc969696525252",
  14853. "f7f7f7cccccc969696636363252525",
  14854. "f7f7f7d9d9d9bdbdbd969696636363252525",
  14855. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  14856. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  14857. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  14858. ).map(colors);
  14859. var Greys = ramp$1(scheme$3);
  14860. var scheme$2 = new Array(3).concat(
  14861. "efedf5bcbddc756bb1",
  14862. "f2f0f7cbc9e29e9ac86a51a3",
  14863. "f2f0f7cbc9e29e9ac8756bb154278f",
  14864. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  14865. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  14866. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  14867. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  14868. ).map(colors);
  14869. var Purples = ramp$1(scheme$2);
  14870. var scheme$1 = new Array(3).concat(
  14871. "fee0d2fc9272de2d26",
  14872. "fee5d9fcae91fb6a4acb181d",
  14873. "fee5d9fcae91fb6a4ade2d26a50f15",
  14874. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  14875. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  14876. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  14877. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  14878. ).map(colors);
  14879. var Reds = ramp$1(scheme$1);
  14880. var scheme = new Array(3).concat(
  14881. "fee6cefdae6be6550d",
  14882. "feeddefdbe85fd8d3cd94701",
  14883. "feeddefdbe85fd8d3ce6550da63603",
  14884. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  14885. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  14886. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  14887. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  14888. ).map(colors);
  14889. var Oranges = ramp$1(scheme);
  14890. function cividis(t) {
  14891. t = Math.max(0, Math.min(1, t));
  14892. return "rgb("
  14893. + Math.max(0, Math.min(255, Math.round(-4.54 - t * (35.34 - t * (2381.73 - t * (6402.7 - t * (7024.72 - t * 2710.57))))))) + ", "
  14894. + Math.max(0, Math.min(255, Math.round(32.49 + t * (170.73 + t * (52.82 - t * (131.46 - t * (176.58 - t * 67.37))))))) + ", "
  14895. + Math.max(0, Math.min(255, Math.round(81.24 + t * (442.36 - t * (2482.43 - t * (6167.24 - t * (6614.94 - t * 2475.67)))))))
  14896. + ")";
  14897. }
  14898. var cubehelix = cubehelixLong(cubehelix$3(300, 0.5, 0.0), cubehelix$3(-240, 0.5, 1.0));
  14899. var warm = cubehelixLong(cubehelix$3(-100, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
  14900. var cool = cubehelixLong(cubehelix$3(260, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
  14901. var c$2 = cubehelix$3();
  14902. function rainbow(t) {
  14903. if (t < 0 || t > 1) t -= Math.floor(t);
  14904. var ts = Math.abs(t - 0.5);
  14905. c$2.h = 360 * t - 100;
  14906. c$2.s = 1.5 - 1.5 * ts;
  14907. c$2.l = 0.8 - 0.9 * ts;
  14908. return c$2 + "";
  14909. }
  14910. var c$1 = rgb(),
  14911. pi_1_3 = Math.PI / 3,
  14912. pi_2_3 = Math.PI * 2 / 3;
  14913. function sinebow(t) {
  14914. var x;
  14915. t = (0.5 - t) * Math.PI;
  14916. c$1.r = 255 * (x = Math.sin(t)) * x;
  14917. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  14918. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  14919. return c$1 + "";
  14920. }
  14921. function turbo(t) {
  14922. t = Math.max(0, Math.min(1, t));
  14923. return "rgb("
  14924. + Math.max(0, Math.min(255, Math.round(34.61 + t * (1172.33 - t * (10793.56 - t * (33300.12 - t * (38394.49 - t * 14825.05))))))) + ", "
  14925. + Math.max(0, Math.min(255, Math.round(23.31 + t * (557.33 + t * (1225.33 - t * (3574.96 - t * (1073.77 + t * 707.56))))))) + ", "
  14926. + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
  14927. + ")";
  14928. }
  14929. function ramp(range) {
  14930. var n = range.length;
  14931. return function(t) {
  14932. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  14933. };
  14934. }
  14935. var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  14936. var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  14937. var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  14938. var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  14939. function constant$1(x) {
  14940. return function constant() {
  14941. return x;
  14942. };
  14943. }
  14944. const abs = Math.abs;
  14945. const atan2 = Math.atan2;
  14946. const cos = Math.cos;
  14947. const max = Math.max;
  14948. const min = Math.min;
  14949. const sin = Math.sin;
  14950. const sqrt = Math.sqrt;
  14951. const epsilon = 1e-12;
  14952. const pi = Math.PI;
  14953. const halfPi = pi / 2;
  14954. const tau = 2 * pi;
  14955. function acos(x) {
  14956. return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
  14957. }
  14958. function asin(x) {
  14959. return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
  14960. }
  14961. function withPath(shape) {
  14962. let digits = 3;
  14963. shape.digits = function(_) {
  14964. if (!arguments.length) return digits;
  14965. if (_ == null) {
  14966. digits = null;
  14967. } else {
  14968. const d = Math.floor(_);
  14969. if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
  14970. digits = d;
  14971. }
  14972. return shape;
  14973. };
  14974. return () => new Path$1(digits);
  14975. }
  14976. function arcInnerRadius(d) {
  14977. return d.innerRadius;
  14978. }
  14979. function arcOuterRadius(d) {
  14980. return d.outerRadius;
  14981. }
  14982. function arcStartAngle(d) {
  14983. return d.startAngle;
  14984. }
  14985. function arcEndAngle(d) {
  14986. return d.endAngle;
  14987. }
  14988. function arcPadAngle(d) {
  14989. return d && d.padAngle; // Note: optional!
  14990. }
  14991. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  14992. var x10 = x1 - x0, y10 = y1 - y0,
  14993. x32 = x3 - x2, y32 = y3 - y2,
  14994. t = y32 * x10 - x32 * y10;
  14995. if (t * t < epsilon) return;
  14996. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  14997. return [x0 + t * x10, y0 + t * y10];
  14998. }
  14999. // Compute perpendicular offset line of length rc.
  15000. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  15001. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  15002. var x01 = x0 - x1,
  15003. y01 = y0 - y1,
  15004. lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),
  15005. ox = lo * y01,
  15006. oy = -lo * x01,
  15007. x11 = x0 + ox,
  15008. y11 = y0 + oy,
  15009. x10 = x1 + ox,
  15010. y10 = y1 + oy,
  15011. x00 = (x11 + x10) / 2,
  15012. y00 = (y11 + y10) / 2,
  15013. dx = x10 - x11,
  15014. dy = y10 - y11,
  15015. d2 = dx * dx + dy * dy,
  15016. r = r1 - rc,
  15017. D = x11 * y10 - x10 * y11,
  15018. d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),
  15019. cx0 = (D * dy - dx * d) / d2,
  15020. cy0 = (-D * dx - dy * d) / d2,
  15021. cx1 = (D * dy + dx * d) / d2,
  15022. cy1 = (-D * dx + dy * d) / d2,
  15023. dx0 = cx0 - x00,
  15024. dy0 = cy0 - y00,
  15025. dx1 = cx1 - x00,
  15026. dy1 = cy1 - y00;
  15027. // Pick the closer of the two intersection points.
  15028. // TODO Is there a faster way to determine which intersection to use?
  15029. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  15030. return {
  15031. cx: cx0,
  15032. cy: cy0,
  15033. x01: -ox,
  15034. y01: -oy,
  15035. x11: cx0 * (r1 / r - 1),
  15036. y11: cy0 * (r1 / r - 1)
  15037. };
  15038. }
  15039. function arc() {
  15040. var innerRadius = arcInnerRadius,
  15041. outerRadius = arcOuterRadius,
  15042. cornerRadius = constant$1(0),
  15043. padRadius = null,
  15044. startAngle = arcStartAngle,
  15045. endAngle = arcEndAngle,
  15046. padAngle = arcPadAngle,
  15047. context = null,
  15048. path = withPath(arc);
  15049. function arc() {
  15050. var buffer,
  15051. r,
  15052. r0 = +innerRadius.apply(this, arguments),
  15053. r1 = +outerRadius.apply(this, arguments),
  15054. a0 = startAngle.apply(this, arguments) - halfPi,
  15055. a1 = endAngle.apply(this, arguments) - halfPi,
  15056. da = abs(a1 - a0),
  15057. cw = a1 > a0;
  15058. if (!context) context = buffer = path();
  15059. // Ensure that the outer radius is always larger than the inner radius.
  15060. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  15061. // Is it a point?
  15062. if (!(r1 > epsilon)) context.moveTo(0, 0);
  15063. // Or is it a circle or annulus?
  15064. else if (da > tau - epsilon) {
  15065. context.moveTo(r1 * cos(a0), r1 * sin(a0));
  15066. context.arc(0, 0, r1, a0, a1, !cw);
  15067. if (r0 > epsilon) {
  15068. context.moveTo(r0 * cos(a1), r0 * sin(a1));
  15069. context.arc(0, 0, r0, a1, a0, cw);
  15070. }
  15071. }
  15072. // Or is it a circular or annular sector?
  15073. else {
  15074. var a01 = a0,
  15075. a11 = a1,
  15076. a00 = a0,
  15077. a10 = a1,
  15078. da0 = da,
  15079. da1 = da,
  15080. ap = padAngle.apply(this, arguments) / 2,
  15081. rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),
  15082. rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  15083. rc0 = rc,
  15084. rc1 = rc,
  15085. t0,
  15086. t1;
  15087. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  15088. if (rp > epsilon) {
  15089. var p0 = asin(rp / r0 * sin(ap)),
  15090. p1 = asin(rp / r1 * sin(ap));
  15091. if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  15092. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  15093. if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  15094. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  15095. }
  15096. var x01 = r1 * cos(a01),
  15097. y01 = r1 * sin(a01),
  15098. x10 = r0 * cos(a10),
  15099. y10 = r0 * sin(a10);
  15100. // Apply rounded corners?
  15101. if (rc > epsilon) {
  15102. var x11 = r1 * cos(a11),
  15103. y11 = r1 * sin(a11),
  15104. x00 = r0 * cos(a00),
  15105. y00 = r0 * sin(a00),
  15106. oc;
  15107. // Restrict the corner radius according to the sector angle. If this
  15108. // intersection fails, it’s probably because the arc is too small, so
  15109. // disable the corner radius entirely.
  15110. if (da < pi) {
  15111. if (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10)) {
  15112. var ax = x01 - oc[0],
  15113. ay = y01 - oc[1],
  15114. bx = x11 - oc[0],
  15115. by = y11 - oc[1],
  15116. kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),
  15117. lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  15118. rc0 = min(rc, (r0 - lc) / (kc - 1));
  15119. rc1 = min(rc, (r1 - lc) / (kc + 1));
  15120. } else {
  15121. rc0 = rc1 = 0;
  15122. }
  15123. }
  15124. }
  15125. // Is the sector collapsed to a line?
  15126. if (!(da1 > epsilon)) context.moveTo(x01, y01);
  15127. // Does the sector’s outer ring have rounded corners?
  15128. else if (rc1 > epsilon) {
  15129. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  15130. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  15131. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  15132. // Have the corners merged?
  15133. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
  15134. // Otherwise, draw the two corners and the ring.
  15135. else {
  15136. context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
  15137. context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  15138. context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
  15139. }
  15140. }
  15141. // Or is the outer ring just a circular arc?
  15142. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  15143. // Is there no inner ring, and it’s a circular sector?
  15144. // Or perhaps it’s an annular sector collapsed due to padding?
  15145. if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);
  15146. // Does the sector’s inner ring (or point) have rounded corners?
  15147. else if (rc0 > epsilon) {
  15148. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  15149. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  15150. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  15151. // Have the corners merged?
  15152. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
  15153. // Otherwise, draw the two corners and the ring.
  15154. else {
  15155. context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
  15156. context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  15157. context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
  15158. }
  15159. }
  15160. // Or is the inner ring just a circular arc?
  15161. else context.arc(0, 0, r0, a10, a00, cw);
  15162. }
  15163. context.closePath();
  15164. if (buffer) return context = null, buffer + "" || null;
  15165. }
  15166. arc.centroid = function() {
  15167. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  15168. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
  15169. return [cos(a) * r, sin(a) * r];
  15170. };
  15171. arc.innerRadius = function(_) {
  15172. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : innerRadius;
  15173. };
  15174. arc.outerRadius = function(_) {
  15175. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : outerRadius;
  15176. };
  15177. arc.cornerRadius = function(_) {
  15178. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : cornerRadius;
  15179. };
  15180. arc.padRadius = function(_) {
  15181. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), arc) : padRadius;
  15182. };
  15183. arc.startAngle = function(_) {
  15184. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : startAngle;
  15185. };
  15186. arc.endAngle = function(_) {
  15187. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : endAngle;
  15188. };
  15189. arc.padAngle = function(_) {
  15190. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : padAngle;
  15191. };
  15192. arc.context = function(_) {
  15193. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  15194. };
  15195. return arc;
  15196. }
  15197. var slice = Array.prototype.slice;
  15198. function array(x) {
  15199. return typeof x === "object" && "length" in x
  15200. ? x // Array, TypedArray, NodeList, array-like
  15201. : Array.from(x); // Map, Set, iterable, string, or anything else
  15202. }
  15203. function Linear(context) {
  15204. this._context = context;
  15205. }
  15206. Linear.prototype = {
  15207. areaStart: function() {
  15208. this._line = 0;
  15209. },
  15210. areaEnd: function() {
  15211. this._line = NaN;
  15212. },
  15213. lineStart: function() {
  15214. this._point = 0;
  15215. },
  15216. lineEnd: function() {
  15217. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15218. this._line = 1 - this._line;
  15219. },
  15220. point: function(x, y) {
  15221. x = +x, y = +y;
  15222. switch (this._point) {
  15223. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15224. case 1: this._point = 2; // falls through
  15225. default: this._context.lineTo(x, y); break;
  15226. }
  15227. }
  15228. };
  15229. function curveLinear(context) {
  15230. return new Linear(context);
  15231. }
  15232. function x(p) {
  15233. return p[0];
  15234. }
  15235. function y(p) {
  15236. return p[1];
  15237. }
  15238. function line(x$1, y$1) {
  15239. var defined = constant$1(true),
  15240. context = null,
  15241. curve = curveLinear,
  15242. output = null,
  15243. path = withPath(line);
  15244. x$1 = typeof x$1 === "function" ? x$1 : (x$1 === undefined) ? x : constant$1(x$1);
  15245. y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant$1(y$1);
  15246. function line(data) {
  15247. var i,
  15248. n = (data = array(data)).length,
  15249. d,
  15250. defined0 = false,
  15251. buffer;
  15252. if (context == null) output = curve(buffer = path());
  15253. for (i = 0; i <= n; ++i) {
  15254. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  15255. if (defined0 = !defined0) output.lineStart();
  15256. else output.lineEnd();
  15257. }
  15258. if (defined0) output.point(+x$1(d, i, data), +y$1(d, i, data));
  15259. }
  15260. if (buffer) return output = null, buffer + "" || null;
  15261. }
  15262. line.x = function(_) {
  15263. return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), line) : x$1;
  15264. };
  15265. line.y = function(_) {
  15266. return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), line) : y$1;
  15267. };
  15268. line.defined = function(_) {
  15269. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), line) : defined;
  15270. };
  15271. line.curve = function(_) {
  15272. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  15273. };
  15274. line.context = function(_) {
  15275. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  15276. };
  15277. return line;
  15278. }
  15279. function area(x0, y0, y1) {
  15280. var x1 = null,
  15281. defined = constant$1(true),
  15282. context = null,
  15283. curve = curveLinear,
  15284. output = null,
  15285. path = withPath(area);
  15286. x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x : constant$1(+x0);
  15287. y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant$1(0) : constant$1(+y0);
  15288. y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant$1(+y1);
  15289. function area(data) {
  15290. var i,
  15291. j,
  15292. k,
  15293. n = (data = array(data)).length,
  15294. d,
  15295. defined0 = false,
  15296. buffer,
  15297. x0z = new Array(n),
  15298. y0z = new Array(n);
  15299. if (context == null) output = curve(buffer = path());
  15300. for (i = 0; i <= n; ++i) {
  15301. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  15302. if (defined0 = !defined0) {
  15303. j = i;
  15304. output.areaStart();
  15305. output.lineStart();
  15306. } else {
  15307. output.lineEnd();
  15308. output.lineStart();
  15309. for (k = i - 1; k >= j; --k) {
  15310. output.point(x0z[k], y0z[k]);
  15311. }
  15312. output.lineEnd();
  15313. output.areaEnd();
  15314. }
  15315. }
  15316. if (defined0) {
  15317. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  15318. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  15319. }
  15320. }
  15321. if (buffer) return output = null, buffer + "" || null;
  15322. }
  15323. function arealine() {
  15324. return line().defined(defined).curve(curve).context(context);
  15325. }
  15326. area.x = function(_) {
  15327. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), x1 = null, area) : x0;
  15328. };
  15329. area.x0 = function(_) {
  15330. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), area) : x0;
  15331. };
  15332. area.x1 = function(_) {
  15333. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : x1;
  15334. };
  15335. area.y = function(_) {
  15336. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), y1 = null, area) : y0;
  15337. };
  15338. area.y0 = function(_) {
  15339. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), area) : y0;
  15340. };
  15341. area.y1 = function(_) {
  15342. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : y1;
  15343. };
  15344. area.lineX0 =
  15345. area.lineY0 = function() {
  15346. return arealine().x(x0).y(y0);
  15347. };
  15348. area.lineY1 = function() {
  15349. return arealine().x(x0).y(y1);
  15350. };
  15351. area.lineX1 = function() {
  15352. return arealine().x(x1).y(y0);
  15353. };
  15354. area.defined = function(_) {
  15355. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), area) : defined;
  15356. };
  15357. area.curve = function(_) {
  15358. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  15359. };
  15360. area.context = function(_) {
  15361. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  15362. };
  15363. return area;
  15364. }
  15365. function descending$1(a, b) {
  15366. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  15367. }
  15368. function identity$1(d) {
  15369. return d;
  15370. }
  15371. function pie() {
  15372. var value = identity$1,
  15373. sortValues = descending$1,
  15374. sort = null,
  15375. startAngle = constant$1(0),
  15376. endAngle = constant$1(tau),
  15377. padAngle = constant$1(0);
  15378. function pie(data) {
  15379. var i,
  15380. n = (data = array(data)).length,
  15381. j,
  15382. k,
  15383. sum = 0,
  15384. index = new Array(n),
  15385. arcs = new Array(n),
  15386. a0 = +startAngle.apply(this, arguments),
  15387. da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),
  15388. a1,
  15389. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  15390. pa = p * (da < 0 ? -1 : 1),
  15391. v;
  15392. for (i = 0; i < n; ++i) {
  15393. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  15394. sum += v;
  15395. }
  15396. }
  15397. // Optionally sort the arcs by previously-computed values or by data.
  15398. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  15399. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  15400. // Compute the arcs! They are stored in the original data's order.
  15401. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  15402. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  15403. data: data[j],
  15404. index: i,
  15405. value: v,
  15406. startAngle: a0,
  15407. endAngle: a1,
  15408. padAngle: p
  15409. };
  15410. }
  15411. return arcs;
  15412. }
  15413. pie.value = function(_) {
  15414. return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value;
  15415. };
  15416. pie.sortValues = function(_) {
  15417. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  15418. };
  15419. pie.sort = function(_) {
  15420. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  15421. };
  15422. pie.startAngle = function(_) {
  15423. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : startAngle;
  15424. };
  15425. pie.endAngle = function(_) {
  15426. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : endAngle;
  15427. };
  15428. pie.padAngle = function(_) {
  15429. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : padAngle;
  15430. };
  15431. return pie;
  15432. }
  15433. var curveRadialLinear = curveRadial(curveLinear);
  15434. function Radial(curve) {
  15435. this._curve = curve;
  15436. }
  15437. Radial.prototype = {
  15438. areaStart: function() {
  15439. this._curve.areaStart();
  15440. },
  15441. areaEnd: function() {
  15442. this._curve.areaEnd();
  15443. },
  15444. lineStart: function() {
  15445. this._curve.lineStart();
  15446. },
  15447. lineEnd: function() {
  15448. this._curve.lineEnd();
  15449. },
  15450. point: function(a, r) {
  15451. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  15452. }
  15453. };
  15454. function curveRadial(curve) {
  15455. function radial(context) {
  15456. return new Radial(curve(context));
  15457. }
  15458. radial._curve = curve;
  15459. return radial;
  15460. }
  15461. function lineRadial(l) {
  15462. var c = l.curve;
  15463. l.angle = l.x, delete l.x;
  15464. l.radius = l.y, delete l.y;
  15465. l.curve = function(_) {
  15466. return arguments.length ? c(curveRadial(_)) : c()._curve;
  15467. };
  15468. return l;
  15469. }
  15470. function lineRadial$1() {
  15471. return lineRadial(line().curve(curveRadialLinear));
  15472. }
  15473. function areaRadial() {
  15474. var a = area().curve(curveRadialLinear),
  15475. c = a.curve,
  15476. x0 = a.lineX0,
  15477. x1 = a.lineX1,
  15478. y0 = a.lineY0,
  15479. y1 = a.lineY1;
  15480. a.angle = a.x, delete a.x;
  15481. a.startAngle = a.x0, delete a.x0;
  15482. a.endAngle = a.x1, delete a.x1;
  15483. a.radius = a.y, delete a.y;
  15484. a.innerRadius = a.y0, delete a.y0;
  15485. a.outerRadius = a.y1, delete a.y1;
  15486. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  15487. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  15488. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  15489. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  15490. a.curve = function(_) {
  15491. return arguments.length ? c(curveRadial(_)) : c()._curve;
  15492. };
  15493. return a;
  15494. }
  15495. function pointRadial(x, y) {
  15496. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  15497. }
  15498. class Bump {
  15499. constructor(context, x) {
  15500. this._context = context;
  15501. this._x = x;
  15502. }
  15503. areaStart() {
  15504. this._line = 0;
  15505. }
  15506. areaEnd() {
  15507. this._line = NaN;
  15508. }
  15509. lineStart() {
  15510. this._point = 0;
  15511. }
  15512. lineEnd() {
  15513. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15514. this._line = 1 - this._line;
  15515. }
  15516. point(x, y) {
  15517. x = +x, y = +y;
  15518. switch (this._point) {
  15519. case 0: {
  15520. this._point = 1;
  15521. if (this._line) this._context.lineTo(x, y);
  15522. else this._context.moveTo(x, y);
  15523. break;
  15524. }
  15525. case 1: this._point = 2; // falls through
  15526. default: {
  15527. if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
  15528. else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
  15529. break;
  15530. }
  15531. }
  15532. this._x0 = x, this._y0 = y;
  15533. }
  15534. }
  15535. class BumpRadial {
  15536. constructor(context) {
  15537. this._context = context;
  15538. }
  15539. lineStart() {
  15540. this._point = 0;
  15541. }
  15542. lineEnd() {}
  15543. point(x, y) {
  15544. x = +x, y = +y;
  15545. if (this._point === 0) {
  15546. this._point = 1;
  15547. } else {
  15548. const p0 = pointRadial(this._x0, this._y0);
  15549. const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2);
  15550. const p2 = pointRadial(x, this._y0);
  15551. const p3 = pointRadial(x, y);
  15552. this._context.moveTo(...p0);
  15553. this._context.bezierCurveTo(...p1, ...p2, ...p3);
  15554. }
  15555. this._x0 = x, this._y0 = y;
  15556. }
  15557. }
  15558. function bumpX(context) {
  15559. return new Bump(context, true);
  15560. }
  15561. function bumpY(context) {
  15562. return new Bump(context, false);
  15563. }
  15564. function bumpRadial(context) {
  15565. return new BumpRadial(context);
  15566. }
  15567. function linkSource(d) {
  15568. return d.source;
  15569. }
  15570. function linkTarget(d) {
  15571. return d.target;
  15572. }
  15573. function link(curve) {
  15574. let source = linkSource,
  15575. target = linkTarget,
  15576. x$1 = x,
  15577. y$1 = y,
  15578. context = null,
  15579. output = null,
  15580. path = withPath(link);
  15581. function link() {
  15582. let buffer;
  15583. const argv = slice.call(arguments);
  15584. const s = source.apply(this, argv);
  15585. const t = target.apply(this, argv);
  15586. if (context == null) output = curve(buffer = path());
  15587. output.lineStart();
  15588. argv[0] = s, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
  15589. argv[0] = t, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
  15590. output.lineEnd();
  15591. if (buffer) return output = null, buffer + "" || null;
  15592. }
  15593. link.source = function(_) {
  15594. return arguments.length ? (source = _, link) : source;
  15595. };
  15596. link.target = function(_) {
  15597. return arguments.length ? (target = _, link) : target;
  15598. };
  15599. link.x = function(_) {
  15600. return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), link) : x$1;
  15601. };
  15602. link.y = function(_) {
  15603. return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), link) : y$1;
  15604. };
  15605. link.context = function(_) {
  15606. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), link) : context;
  15607. };
  15608. return link;
  15609. }
  15610. function linkHorizontal() {
  15611. return link(bumpX);
  15612. }
  15613. function linkVertical() {
  15614. return link(bumpY);
  15615. }
  15616. function linkRadial() {
  15617. const l = link(bumpRadial);
  15618. l.angle = l.x, delete l.x;
  15619. l.radius = l.y, delete l.y;
  15620. return l;
  15621. }
  15622. const sqrt3$2 = sqrt(3);
  15623. var asterisk = {
  15624. draw(context, size) {
  15625. const r = sqrt(size + min(size / 28, 0.75)) * 0.59436;
  15626. const t = r / 2;
  15627. const u = t * sqrt3$2;
  15628. context.moveTo(0, r);
  15629. context.lineTo(0, -r);
  15630. context.moveTo(-u, -t);
  15631. context.lineTo(u, t);
  15632. context.moveTo(-u, t);
  15633. context.lineTo(u, -t);
  15634. }
  15635. };
  15636. var circle = {
  15637. draw(context, size) {
  15638. const r = sqrt(size / pi);
  15639. context.moveTo(r, 0);
  15640. context.arc(0, 0, r, 0, tau);
  15641. }
  15642. };
  15643. var cross = {
  15644. draw(context, size) {
  15645. const r = sqrt(size / 5) / 2;
  15646. context.moveTo(-3 * r, -r);
  15647. context.lineTo(-r, -r);
  15648. context.lineTo(-r, -3 * r);
  15649. context.lineTo(r, -3 * r);
  15650. context.lineTo(r, -r);
  15651. context.lineTo(3 * r, -r);
  15652. context.lineTo(3 * r, r);
  15653. context.lineTo(r, r);
  15654. context.lineTo(r, 3 * r);
  15655. context.lineTo(-r, 3 * r);
  15656. context.lineTo(-r, r);
  15657. context.lineTo(-3 * r, r);
  15658. context.closePath();
  15659. }
  15660. };
  15661. const tan30 = sqrt(1 / 3);
  15662. const tan30_2 = tan30 * 2;
  15663. var diamond = {
  15664. draw(context, size) {
  15665. const y = sqrt(size / tan30_2);
  15666. const x = y * tan30;
  15667. context.moveTo(0, -y);
  15668. context.lineTo(x, 0);
  15669. context.lineTo(0, y);
  15670. context.lineTo(-x, 0);
  15671. context.closePath();
  15672. }
  15673. };
  15674. var diamond2 = {
  15675. draw(context, size) {
  15676. const r = sqrt(size) * 0.62625;
  15677. context.moveTo(0, -r);
  15678. context.lineTo(r, 0);
  15679. context.lineTo(0, r);
  15680. context.lineTo(-r, 0);
  15681. context.closePath();
  15682. }
  15683. };
  15684. var plus = {
  15685. draw(context, size) {
  15686. const r = sqrt(size - min(size / 7, 2)) * 0.87559;
  15687. context.moveTo(-r, 0);
  15688. context.lineTo(r, 0);
  15689. context.moveTo(0, r);
  15690. context.lineTo(0, -r);
  15691. }
  15692. };
  15693. var square = {
  15694. draw(context, size) {
  15695. const w = sqrt(size);
  15696. const x = -w / 2;
  15697. context.rect(x, x, w, w);
  15698. }
  15699. };
  15700. var square2 = {
  15701. draw(context, size) {
  15702. const r = sqrt(size) * 0.4431;
  15703. context.moveTo(r, r);
  15704. context.lineTo(r, -r);
  15705. context.lineTo(-r, -r);
  15706. context.lineTo(-r, r);
  15707. context.closePath();
  15708. }
  15709. };
  15710. const ka = 0.89081309152928522810;
  15711. const kr = sin(pi / 10) / sin(7 * pi / 10);
  15712. const kx = sin(tau / 10) * kr;
  15713. const ky = -cos(tau / 10) * kr;
  15714. var star = {
  15715. draw(context, size) {
  15716. const r = sqrt(size * ka);
  15717. const x = kx * r;
  15718. const y = ky * r;
  15719. context.moveTo(0, -r);
  15720. context.lineTo(x, y);
  15721. for (let i = 1; i < 5; ++i) {
  15722. const a = tau * i / 5;
  15723. const c = cos(a);
  15724. const s = sin(a);
  15725. context.lineTo(s * r, -c * r);
  15726. context.lineTo(c * x - s * y, s * x + c * y);
  15727. }
  15728. context.closePath();
  15729. }
  15730. };
  15731. const sqrt3$1 = sqrt(3);
  15732. var triangle = {
  15733. draw(context, size) {
  15734. const y = -sqrt(size / (sqrt3$1 * 3));
  15735. context.moveTo(0, y * 2);
  15736. context.lineTo(-sqrt3$1 * y, -y);
  15737. context.lineTo(sqrt3$1 * y, -y);
  15738. context.closePath();
  15739. }
  15740. };
  15741. const sqrt3 = sqrt(3);
  15742. var triangle2 = {
  15743. draw(context, size) {
  15744. const s = sqrt(size) * 0.6824;
  15745. const t = s / 2;
  15746. const u = (s * sqrt3) / 2; // cos(Math.PI / 6)
  15747. context.moveTo(0, -s);
  15748. context.lineTo(u, t);
  15749. context.lineTo(-u, t);
  15750. context.closePath();
  15751. }
  15752. };
  15753. const c = -0.5;
  15754. const s = sqrt(3) / 2;
  15755. const k = 1 / sqrt(12);
  15756. const a = (k / 2 + 1) * 3;
  15757. var wye = {
  15758. draw(context, size) {
  15759. const r = sqrt(size / a);
  15760. const x0 = r / 2, y0 = r * k;
  15761. const x1 = x0, y1 = r * k + r;
  15762. const x2 = -x1, y2 = y1;
  15763. context.moveTo(x0, y0);
  15764. context.lineTo(x1, y1);
  15765. context.lineTo(x2, y2);
  15766. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  15767. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  15768. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  15769. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  15770. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  15771. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  15772. context.closePath();
  15773. }
  15774. };
  15775. var times = {
  15776. draw(context, size) {
  15777. const r = sqrt(size - min(size / 6, 1.7)) * 0.6189;
  15778. context.moveTo(-r, -r);
  15779. context.lineTo(r, r);
  15780. context.moveTo(-r, r);
  15781. context.lineTo(r, -r);
  15782. }
  15783. };
  15784. // These symbols are designed to be filled.
  15785. const symbolsFill = [
  15786. circle,
  15787. cross,
  15788. diamond,
  15789. square,
  15790. star,
  15791. triangle,
  15792. wye
  15793. ];
  15794. // These symbols are designed to be stroked (with a width of 1.5px and round caps).
  15795. const symbolsStroke = [
  15796. circle,
  15797. plus,
  15798. times,
  15799. triangle2,
  15800. asterisk,
  15801. square2,
  15802. diamond2
  15803. ];
  15804. function Symbol$1(type, size) {
  15805. let context = null,
  15806. path = withPath(symbol);
  15807. type = typeof type === "function" ? type : constant$1(type || circle);
  15808. size = typeof size === "function" ? size : constant$1(size === undefined ? 64 : +size);
  15809. function symbol() {
  15810. let buffer;
  15811. if (!context) context = buffer = path();
  15812. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  15813. if (buffer) return context = null, buffer + "" || null;
  15814. }
  15815. symbol.type = function(_) {
  15816. return arguments.length ? (type = typeof _ === "function" ? _ : constant$1(_), symbol) : type;
  15817. };
  15818. symbol.size = function(_) {
  15819. return arguments.length ? (size = typeof _ === "function" ? _ : constant$1(+_), symbol) : size;
  15820. };
  15821. symbol.context = function(_) {
  15822. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  15823. };
  15824. return symbol;
  15825. }
  15826. function noop() {}
  15827. function point$3(that, x, y) {
  15828. that._context.bezierCurveTo(
  15829. (2 * that._x0 + that._x1) / 3,
  15830. (2 * that._y0 + that._y1) / 3,
  15831. (that._x0 + 2 * that._x1) / 3,
  15832. (that._y0 + 2 * that._y1) / 3,
  15833. (that._x0 + 4 * that._x1 + x) / 6,
  15834. (that._y0 + 4 * that._y1 + y) / 6
  15835. );
  15836. }
  15837. function Basis(context) {
  15838. this._context = context;
  15839. }
  15840. Basis.prototype = {
  15841. areaStart: function() {
  15842. this._line = 0;
  15843. },
  15844. areaEnd: function() {
  15845. this._line = NaN;
  15846. },
  15847. lineStart: function() {
  15848. this._x0 = this._x1 =
  15849. this._y0 = this._y1 = NaN;
  15850. this._point = 0;
  15851. },
  15852. lineEnd: function() {
  15853. switch (this._point) {
  15854. case 3: point$3(this, this._x1, this._y1); // falls through
  15855. case 2: this._context.lineTo(this._x1, this._y1); break;
  15856. }
  15857. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15858. this._line = 1 - this._line;
  15859. },
  15860. point: function(x, y) {
  15861. x = +x, y = +y;
  15862. switch (this._point) {
  15863. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15864. case 1: this._point = 2; break;
  15865. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through
  15866. default: point$3(this, x, y); break;
  15867. }
  15868. this._x0 = this._x1, this._x1 = x;
  15869. this._y0 = this._y1, this._y1 = y;
  15870. }
  15871. };
  15872. function basis(context) {
  15873. return new Basis(context);
  15874. }
  15875. function BasisClosed(context) {
  15876. this._context = context;
  15877. }
  15878. BasisClosed.prototype = {
  15879. areaStart: noop,
  15880. areaEnd: noop,
  15881. lineStart: function() {
  15882. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  15883. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  15884. this._point = 0;
  15885. },
  15886. lineEnd: function() {
  15887. switch (this._point) {
  15888. case 1: {
  15889. this._context.moveTo(this._x2, this._y2);
  15890. this._context.closePath();
  15891. break;
  15892. }
  15893. case 2: {
  15894. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  15895. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  15896. this._context.closePath();
  15897. break;
  15898. }
  15899. case 3: {
  15900. this.point(this._x2, this._y2);
  15901. this.point(this._x3, this._y3);
  15902. this.point(this._x4, this._y4);
  15903. break;
  15904. }
  15905. }
  15906. },
  15907. point: function(x, y) {
  15908. x = +x, y = +y;
  15909. switch (this._point) {
  15910. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  15911. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  15912. 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;
  15913. default: point$3(this, x, y); break;
  15914. }
  15915. this._x0 = this._x1, this._x1 = x;
  15916. this._y0 = this._y1, this._y1 = y;
  15917. }
  15918. };
  15919. function basisClosed(context) {
  15920. return new BasisClosed(context);
  15921. }
  15922. function BasisOpen(context) {
  15923. this._context = context;
  15924. }
  15925. BasisOpen.prototype = {
  15926. areaStart: function() {
  15927. this._line = 0;
  15928. },
  15929. areaEnd: function() {
  15930. this._line = NaN;
  15931. },
  15932. lineStart: function() {
  15933. this._x0 = this._x1 =
  15934. this._y0 = this._y1 = NaN;
  15935. this._point = 0;
  15936. },
  15937. lineEnd: function() {
  15938. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  15939. this._line = 1 - this._line;
  15940. },
  15941. point: function(x, y) {
  15942. x = +x, y = +y;
  15943. switch (this._point) {
  15944. case 0: this._point = 1; break;
  15945. case 1: this._point = 2; break;
  15946. 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;
  15947. case 3: this._point = 4; // falls through
  15948. default: point$3(this, x, y); break;
  15949. }
  15950. this._x0 = this._x1, this._x1 = x;
  15951. this._y0 = this._y1, this._y1 = y;
  15952. }
  15953. };
  15954. function basisOpen(context) {
  15955. return new BasisOpen(context);
  15956. }
  15957. function Bundle(context, beta) {
  15958. this._basis = new Basis(context);
  15959. this._beta = beta;
  15960. }
  15961. Bundle.prototype = {
  15962. lineStart: function() {
  15963. this._x = [];
  15964. this._y = [];
  15965. this._basis.lineStart();
  15966. },
  15967. lineEnd: function() {
  15968. var x = this._x,
  15969. y = this._y,
  15970. j = x.length - 1;
  15971. if (j > 0) {
  15972. var x0 = x[0],
  15973. y0 = y[0],
  15974. dx = x[j] - x0,
  15975. dy = y[j] - y0,
  15976. i = -1,
  15977. t;
  15978. while (++i <= j) {
  15979. t = i / j;
  15980. this._basis.point(
  15981. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  15982. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  15983. );
  15984. }
  15985. }
  15986. this._x = this._y = null;
  15987. this._basis.lineEnd();
  15988. },
  15989. point: function(x, y) {
  15990. this._x.push(+x);
  15991. this._y.push(+y);
  15992. }
  15993. };
  15994. var bundle = (function custom(beta) {
  15995. function bundle(context) {
  15996. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  15997. }
  15998. bundle.beta = function(beta) {
  15999. return custom(+beta);
  16000. };
  16001. return bundle;
  16002. })(0.85);
  16003. function point$2(that, x, y) {
  16004. that._context.bezierCurveTo(
  16005. that._x1 + that._k * (that._x2 - that._x0),
  16006. that._y1 + that._k * (that._y2 - that._y0),
  16007. that._x2 + that._k * (that._x1 - x),
  16008. that._y2 + that._k * (that._y1 - y),
  16009. that._x2,
  16010. that._y2
  16011. );
  16012. }
  16013. function Cardinal(context, tension) {
  16014. this._context = context;
  16015. this._k = (1 - tension) / 6;
  16016. }
  16017. Cardinal.prototype = {
  16018. areaStart: function() {
  16019. this._line = 0;
  16020. },
  16021. areaEnd: function() {
  16022. this._line = NaN;
  16023. },
  16024. lineStart: function() {
  16025. this._x0 = this._x1 = this._x2 =
  16026. this._y0 = this._y1 = this._y2 = NaN;
  16027. this._point = 0;
  16028. },
  16029. lineEnd: function() {
  16030. switch (this._point) {
  16031. case 2: this._context.lineTo(this._x2, this._y2); break;
  16032. case 3: point$2(this, this._x1, this._y1); break;
  16033. }
  16034. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16035. this._line = 1 - this._line;
  16036. },
  16037. point: function(x, y) {
  16038. x = +x, y = +y;
  16039. switch (this._point) {
  16040. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16041. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  16042. case 2: this._point = 3; // falls through
  16043. default: point$2(this, x, y); break;
  16044. }
  16045. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16046. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16047. }
  16048. };
  16049. var cardinal = (function custom(tension) {
  16050. function cardinal(context) {
  16051. return new Cardinal(context, tension);
  16052. }
  16053. cardinal.tension = function(tension) {
  16054. return custom(+tension);
  16055. };
  16056. return cardinal;
  16057. })(0);
  16058. function CardinalClosed(context, tension) {
  16059. this._context = context;
  16060. this._k = (1 - tension) / 6;
  16061. }
  16062. CardinalClosed.prototype = {
  16063. areaStart: noop,
  16064. areaEnd: noop,
  16065. lineStart: function() {
  16066. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  16067. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  16068. this._point = 0;
  16069. },
  16070. lineEnd: function() {
  16071. switch (this._point) {
  16072. case 1: {
  16073. this._context.moveTo(this._x3, this._y3);
  16074. this._context.closePath();
  16075. break;
  16076. }
  16077. case 2: {
  16078. this._context.lineTo(this._x3, this._y3);
  16079. this._context.closePath();
  16080. break;
  16081. }
  16082. case 3: {
  16083. this.point(this._x3, this._y3);
  16084. this.point(this._x4, this._y4);
  16085. this.point(this._x5, this._y5);
  16086. break;
  16087. }
  16088. }
  16089. },
  16090. point: function(x, y) {
  16091. x = +x, y = +y;
  16092. switch (this._point) {
  16093. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  16094. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  16095. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  16096. default: point$2(this, x, y); break;
  16097. }
  16098. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16099. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16100. }
  16101. };
  16102. var cardinalClosed = (function custom(tension) {
  16103. function cardinal(context) {
  16104. return new CardinalClosed(context, tension);
  16105. }
  16106. cardinal.tension = function(tension) {
  16107. return custom(+tension);
  16108. };
  16109. return cardinal;
  16110. })(0);
  16111. function CardinalOpen(context, tension) {
  16112. this._context = context;
  16113. this._k = (1 - tension) / 6;
  16114. }
  16115. CardinalOpen.prototype = {
  16116. areaStart: function() {
  16117. this._line = 0;
  16118. },
  16119. areaEnd: function() {
  16120. this._line = NaN;
  16121. },
  16122. lineStart: function() {
  16123. this._x0 = this._x1 = this._x2 =
  16124. this._y0 = this._y1 = this._y2 = NaN;
  16125. this._point = 0;
  16126. },
  16127. lineEnd: function() {
  16128. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  16129. this._line = 1 - this._line;
  16130. },
  16131. point: function(x, y) {
  16132. x = +x, y = +y;
  16133. switch (this._point) {
  16134. case 0: this._point = 1; break;
  16135. case 1: this._point = 2; break;
  16136. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  16137. case 3: this._point = 4; // falls through
  16138. default: point$2(this, x, y); break;
  16139. }
  16140. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16141. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16142. }
  16143. };
  16144. var cardinalOpen = (function custom(tension) {
  16145. function cardinal(context) {
  16146. return new CardinalOpen(context, tension);
  16147. }
  16148. cardinal.tension = function(tension) {
  16149. return custom(+tension);
  16150. };
  16151. return cardinal;
  16152. })(0);
  16153. function point$1(that, x, y) {
  16154. var x1 = that._x1,
  16155. y1 = that._y1,
  16156. x2 = that._x2,
  16157. y2 = that._y2;
  16158. if (that._l01_a > epsilon) {
  16159. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  16160. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  16161. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  16162. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  16163. }
  16164. if (that._l23_a > epsilon) {
  16165. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  16166. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  16167. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  16168. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  16169. }
  16170. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  16171. }
  16172. function CatmullRom(context, alpha) {
  16173. this._context = context;
  16174. this._alpha = alpha;
  16175. }
  16176. CatmullRom.prototype = {
  16177. areaStart: function() {
  16178. this._line = 0;
  16179. },
  16180. areaEnd: function() {
  16181. this._line = NaN;
  16182. },
  16183. lineStart: function() {
  16184. this._x0 = this._x1 = this._x2 =
  16185. this._y0 = this._y1 = this._y2 = NaN;
  16186. this._l01_a = this._l12_a = this._l23_a =
  16187. this._l01_2a = this._l12_2a = this._l23_2a =
  16188. this._point = 0;
  16189. },
  16190. lineEnd: function() {
  16191. switch (this._point) {
  16192. case 2: this._context.lineTo(this._x2, this._y2); break;
  16193. case 3: this.point(this._x2, this._y2); break;
  16194. }
  16195. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16196. this._line = 1 - this._line;
  16197. },
  16198. point: function(x, y) {
  16199. x = +x, y = +y;
  16200. if (this._point) {
  16201. var x23 = this._x2 - x,
  16202. y23 = this._y2 - y;
  16203. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  16204. }
  16205. switch (this._point) {
  16206. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16207. case 1: this._point = 2; break;
  16208. case 2: this._point = 3; // falls through
  16209. default: point$1(this, x, y); break;
  16210. }
  16211. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  16212. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  16213. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16214. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16215. }
  16216. };
  16217. var catmullRom = (function custom(alpha) {
  16218. function catmullRom(context) {
  16219. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  16220. }
  16221. catmullRom.alpha = function(alpha) {
  16222. return custom(+alpha);
  16223. };
  16224. return catmullRom;
  16225. })(0.5);
  16226. function CatmullRomClosed(context, alpha) {
  16227. this._context = context;
  16228. this._alpha = alpha;
  16229. }
  16230. CatmullRomClosed.prototype = {
  16231. areaStart: noop,
  16232. areaEnd: noop,
  16233. lineStart: function() {
  16234. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  16235. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  16236. this._l01_a = this._l12_a = this._l23_a =
  16237. this._l01_2a = this._l12_2a = this._l23_2a =
  16238. this._point = 0;
  16239. },
  16240. lineEnd: function() {
  16241. switch (this._point) {
  16242. case 1: {
  16243. this._context.moveTo(this._x3, this._y3);
  16244. this._context.closePath();
  16245. break;
  16246. }
  16247. case 2: {
  16248. this._context.lineTo(this._x3, this._y3);
  16249. this._context.closePath();
  16250. break;
  16251. }
  16252. case 3: {
  16253. this.point(this._x3, this._y3);
  16254. this.point(this._x4, this._y4);
  16255. this.point(this._x5, this._y5);
  16256. break;
  16257. }
  16258. }
  16259. },
  16260. point: function(x, y) {
  16261. x = +x, y = +y;
  16262. if (this._point) {
  16263. var x23 = this._x2 - x,
  16264. y23 = this._y2 - y;
  16265. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  16266. }
  16267. switch (this._point) {
  16268. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  16269. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  16270. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  16271. default: point$1(this, x, y); break;
  16272. }
  16273. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  16274. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  16275. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16276. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16277. }
  16278. };
  16279. var catmullRomClosed = (function custom(alpha) {
  16280. function catmullRom(context) {
  16281. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  16282. }
  16283. catmullRom.alpha = function(alpha) {
  16284. return custom(+alpha);
  16285. };
  16286. return catmullRom;
  16287. })(0.5);
  16288. function CatmullRomOpen(context, alpha) {
  16289. this._context = context;
  16290. this._alpha = alpha;
  16291. }
  16292. CatmullRomOpen.prototype = {
  16293. areaStart: function() {
  16294. this._line = 0;
  16295. },
  16296. areaEnd: function() {
  16297. this._line = NaN;
  16298. },
  16299. lineStart: function() {
  16300. this._x0 = this._x1 = this._x2 =
  16301. this._y0 = this._y1 = this._y2 = NaN;
  16302. this._l01_a = this._l12_a = this._l23_a =
  16303. this._l01_2a = this._l12_2a = this._l23_2a =
  16304. this._point = 0;
  16305. },
  16306. lineEnd: function() {
  16307. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  16308. this._line = 1 - this._line;
  16309. },
  16310. point: function(x, y) {
  16311. x = +x, y = +y;
  16312. if (this._point) {
  16313. var x23 = this._x2 - x,
  16314. y23 = this._y2 - y;
  16315. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  16316. }
  16317. switch (this._point) {
  16318. case 0: this._point = 1; break;
  16319. case 1: this._point = 2; break;
  16320. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  16321. case 3: this._point = 4; // falls through
  16322. default: point$1(this, x, y); break;
  16323. }
  16324. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  16325. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  16326. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16327. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16328. }
  16329. };
  16330. var catmullRomOpen = (function custom(alpha) {
  16331. function catmullRom(context) {
  16332. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  16333. }
  16334. catmullRom.alpha = function(alpha) {
  16335. return custom(+alpha);
  16336. };
  16337. return catmullRom;
  16338. })(0.5);
  16339. function LinearClosed(context) {
  16340. this._context = context;
  16341. }
  16342. LinearClosed.prototype = {
  16343. areaStart: noop,
  16344. areaEnd: noop,
  16345. lineStart: function() {
  16346. this._point = 0;
  16347. },
  16348. lineEnd: function() {
  16349. if (this._point) this._context.closePath();
  16350. },
  16351. point: function(x, y) {
  16352. x = +x, y = +y;
  16353. if (this._point) this._context.lineTo(x, y);
  16354. else this._point = 1, this._context.moveTo(x, y);
  16355. }
  16356. };
  16357. function linearClosed(context) {
  16358. return new LinearClosed(context);
  16359. }
  16360. function sign(x) {
  16361. return x < 0 ? -1 : 1;
  16362. }
  16363. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  16364. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  16365. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  16366. // NOV(II), P. 443, 1990.
  16367. function slope3(that, x2, y2) {
  16368. var h0 = that._x1 - that._x0,
  16369. h1 = x2 - that._x1,
  16370. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  16371. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  16372. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  16373. return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  16374. }
  16375. // Calculate a one-sided slope.
  16376. function slope2(that, t) {
  16377. var h = that._x1 - that._x0;
  16378. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  16379. }
  16380. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  16381. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  16382. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  16383. function point(that, t0, t1) {
  16384. var x0 = that._x0,
  16385. y0 = that._y0,
  16386. x1 = that._x1,
  16387. y1 = that._y1,
  16388. dx = (x1 - x0) / 3;
  16389. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  16390. }
  16391. function MonotoneX(context) {
  16392. this._context = context;
  16393. }
  16394. MonotoneX.prototype = {
  16395. areaStart: function() {
  16396. this._line = 0;
  16397. },
  16398. areaEnd: function() {
  16399. this._line = NaN;
  16400. },
  16401. lineStart: function() {
  16402. this._x0 = this._x1 =
  16403. this._y0 = this._y1 =
  16404. this._t0 = NaN;
  16405. this._point = 0;
  16406. },
  16407. lineEnd: function() {
  16408. switch (this._point) {
  16409. case 2: this._context.lineTo(this._x1, this._y1); break;
  16410. case 3: point(this, this._t0, slope2(this, this._t0)); break;
  16411. }
  16412. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16413. this._line = 1 - this._line;
  16414. },
  16415. point: function(x, y) {
  16416. var t1 = NaN;
  16417. x = +x, y = +y;
  16418. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  16419. switch (this._point) {
  16420. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16421. case 1: this._point = 2; break;
  16422. case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  16423. default: point(this, this._t0, t1 = slope3(this, x, y)); break;
  16424. }
  16425. this._x0 = this._x1, this._x1 = x;
  16426. this._y0 = this._y1, this._y1 = y;
  16427. this._t0 = t1;
  16428. }
  16429. };
  16430. function MonotoneY(context) {
  16431. this._context = new ReflectContext(context);
  16432. }
  16433. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  16434. MonotoneX.prototype.point.call(this, y, x);
  16435. };
  16436. function ReflectContext(context) {
  16437. this._context = context;
  16438. }
  16439. ReflectContext.prototype = {
  16440. moveTo: function(x, y) { this._context.moveTo(y, x); },
  16441. closePath: function() { this._context.closePath(); },
  16442. lineTo: function(x, y) { this._context.lineTo(y, x); },
  16443. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  16444. };
  16445. function monotoneX(context) {
  16446. return new MonotoneX(context);
  16447. }
  16448. function monotoneY(context) {
  16449. return new MonotoneY(context);
  16450. }
  16451. function Natural(context) {
  16452. this._context = context;
  16453. }
  16454. Natural.prototype = {
  16455. areaStart: function() {
  16456. this._line = 0;
  16457. },
  16458. areaEnd: function() {
  16459. this._line = NaN;
  16460. },
  16461. lineStart: function() {
  16462. this._x = [];
  16463. this._y = [];
  16464. },
  16465. lineEnd: function() {
  16466. var x = this._x,
  16467. y = this._y,
  16468. n = x.length;
  16469. if (n) {
  16470. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  16471. if (n === 2) {
  16472. this._context.lineTo(x[1], y[1]);
  16473. } else {
  16474. var px = controlPoints(x),
  16475. py = controlPoints(y);
  16476. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  16477. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  16478. }
  16479. }
  16480. }
  16481. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  16482. this._line = 1 - this._line;
  16483. this._x = this._y = null;
  16484. },
  16485. point: function(x, y) {
  16486. this._x.push(+x);
  16487. this._y.push(+y);
  16488. }
  16489. };
  16490. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  16491. function controlPoints(x) {
  16492. var i,
  16493. n = x.length - 1,
  16494. m,
  16495. a = new Array(n),
  16496. b = new Array(n),
  16497. r = new Array(n);
  16498. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  16499. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  16500. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  16501. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  16502. a[n - 1] = r[n - 1] / b[n - 1];
  16503. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  16504. b[n - 1] = (x[n] + a[n - 1]) / 2;
  16505. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  16506. return [a, b];
  16507. }
  16508. function natural(context) {
  16509. return new Natural(context);
  16510. }
  16511. function Step(context, t) {
  16512. this._context = context;
  16513. this._t = t;
  16514. }
  16515. Step.prototype = {
  16516. areaStart: function() {
  16517. this._line = 0;
  16518. },
  16519. areaEnd: function() {
  16520. this._line = NaN;
  16521. },
  16522. lineStart: function() {
  16523. this._x = this._y = NaN;
  16524. this._point = 0;
  16525. },
  16526. lineEnd: function() {
  16527. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  16528. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16529. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  16530. },
  16531. point: function(x, y) {
  16532. x = +x, y = +y;
  16533. switch (this._point) {
  16534. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16535. case 1: this._point = 2; // falls through
  16536. default: {
  16537. if (this._t <= 0) {
  16538. this._context.lineTo(this._x, y);
  16539. this._context.lineTo(x, y);
  16540. } else {
  16541. var x1 = this._x * (1 - this._t) + x * this._t;
  16542. this._context.lineTo(x1, this._y);
  16543. this._context.lineTo(x1, y);
  16544. }
  16545. break;
  16546. }
  16547. }
  16548. this._x = x, this._y = y;
  16549. }
  16550. };
  16551. function step(context) {
  16552. return new Step(context, 0.5);
  16553. }
  16554. function stepBefore(context) {
  16555. return new Step(context, 0);
  16556. }
  16557. function stepAfter(context) {
  16558. return new Step(context, 1);
  16559. }
  16560. function none$1(series, order) {
  16561. if (!((n = series.length) > 1)) return;
  16562. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  16563. s0 = s1, s1 = series[order[i]];
  16564. for (j = 0; j < m; ++j) {
  16565. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  16566. }
  16567. }
  16568. }
  16569. function none(series) {
  16570. var n = series.length, o = new Array(n);
  16571. while (--n >= 0) o[n] = n;
  16572. return o;
  16573. }
  16574. function stackValue(d, key) {
  16575. return d[key];
  16576. }
  16577. function stackSeries(key) {
  16578. const series = [];
  16579. series.key = key;
  16580. return series;
  16581. }
  16582. function stack() {
  16583. var keys = constant$1([]),
  16584. order = none,
  16585. offset = none$1,
  16586. value = stackValue;
  16587. function stack(data) {
  16588. var sz = Array.from(keys.apply(this, arguments), stackSeries),
  16589. i, n = sz.length, j = -1,
  16590. oz;
  16591. for (const d of data) {
  16592. for (i = 0, ++j; i < n; ++i) {
  16593. (sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
  16594. }
  16595. }
  16596. for (i = 0, oz = array(order(sz)); i < n; ++i) {
  16597. sz[oz[i]].index = i;
  16598. }
  16599. offset(sz, oz);
  16600. return sz;
  16601. }
  16602. stack.keys = function(_) {
  16603. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : keys;
  16604. };
  16605. stack.value = function(_) {
  16606. return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), stack) : value;
  16607. };
  16608. stack.order = function(_) {
  16609. return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : order;
  16610. };
  16611. stack.offset = function(_) {
  16612. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  16613. };
  16614. return stack;
  16615. }
  16616. function expand(series, order) {
  16617. if (!((n = series.length) > 0)) return;
  16618. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  16619. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  16620. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  16621. }
  16622. none$1(series, order);
  16623. }
  16624. function diverging(series, order) {
  16625. if (!((n = series.length) > 0)) return;
  16626. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  16627. for (yp = yn = 0, i = 0; i < n; ++i) {
  16628. if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
  16629. d[0] = yp, d[1] = yp += dy;
  16630. } else if (dy < 0) {
  16631. d[1] = yn, d[0] = yn += dy;
  16632. } else {
  16633. d[0] = 0, d[1] = dy;
  16634. }
  16635. }
  16636. }
  16637. }
  16638. function silhouette(series, order) {
  16639. if (!((n = series.length) > 0)) return;
  16640. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  16641. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  16642. s0[j][1] += s0[j][0] = -y / 2;
  16643. }
  16644. none$1(series, order);
  16645. }
  16646. function wiggle(series, order) {
  16647. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  16648. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  16649. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  16650. var si = series[order[i]],
  16651. sij0 = si[j][1] || 0,
  16652. sij1 = si[j - 1][1] || 0,
  16653. s3 = (sij0 - sij1) / 2;
  16654. for (var k = 0; k < i; ++k) {
  16655. var sk = series[order[k]],
  16656. skj0 = sk[j][1] || 0,
  16657. skj1 = sk[j - 1][1] || 0;
  16658. s3 += skj0 - skj1;
  16659. }
  16660. s1 += sij0, s2 += s3 * sij0;
  16661. }
  16662. s0[j - 1][1] += s0[j - 1][0] = y;
  16663. if (s1) y -= s2 / s1;
  16664. }
  16665. s0[j - 1][1] += s0[j - 1][0] = y;
  16666. none$1(series, order);
  16667. }
  16668. function appearance(series) {
  16669. var peaks = series.map(peak);
  16670. return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
  16671. }
  16672. function peak(series) {
  16673. var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
  16674. while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
  16675. return j;
  16676. }
  16677. function ascending(series) {
  16678. var sums = series.map(sum);
  16679. return none(series).sort(function(a, b) { return sums[a] - sums[b]; });
  16680. }
  16681. function sum(series) {
  16682. var s = 0, i = -1, n = series.length, v;
  16683. while (++i < n) if (v = +series[i][1]) s += v;
  16684. return s;
  16685. }
  16686. function descending(series) {
  16687. return ascending(series).reverse();
  16688. }
  16689. function insideOut(series) {
  16690. var n = series.length,
  16691. i,
  16692. j,
  16693. sums = series.map(sum),
  16694. order = appearance(series),
  16695. top = 0,
  16696. bottom = 0,
  16697. tops = [],
  16698. bottoms = [];
  16699. for (i = 0; i < n; ++i) {
  16700. j = order[i];
  16701. if (top < bottom) {
  16702. top += sums[j];
  16703. tops.push(j);
  16704. } else {
  16705. bottom += sums[j];
  16706. bottoms.push(j);
  16707. }
  16708. }
  16709. return bottoms.reverse().concat(tops);
  16710. }
  16711. function reverse(series) {
  16712. return none(series).reverse();
  16713. }
  16714. var constant = x => () => x;
  16715. function ZoomEvent(type, {
  16716. sourceEvent,
  16717. target,
  16718. transform,
  16719. dispatch
  16720. }) {
  16721. Object.defineProperties(this, {
  16722. type: {value: type, enumerable: true, configurable: true},
  16723. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  16724. target: {value: target, enumerable: true, configurable: true},
  16725. transform: {value: transform, enumerable: true, configurable: true},
  16726. _: {value: dispatch}
  16727. });
  16728. }
  16729. function Transform(k, x, y) {
  16730. this.k = k;
  16731. this.x = x;
  16732. this.y = y;
  16733. }
  16734. Transform.prototype = {
  16735. constructor: Transform,
  16736. scale: function(k) {
  16737. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  16738. },
  16739. translate: function(x, y) {
  16740. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  16741. },
  16742. apply: function(point) {
  16743. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  16744. },
  16745. applyX: function(x) {
  16746. return x * this.k + this.x;
  16747. },
  16748. applyY: function(y) {
  16749. return y * this.k + this.y;
  16750. },
  16751. invert: function(location) {
  16752. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  16753. },
  16754. invertX: function(x) {
  16755. return (x - this.x) / this.k;
  16756. },
  16757. invertY: function(y) {
  16758. return (y - this.y) / this.k;
  16759. },
  16760. rescaleX: function(x) {
  16761. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  16762. },
  16763. rescaleY: function(y) {
  16764. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  16765. },
  16766. toString: function() {
  16767. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  16768. }
  16769. };
  16770. var identity = new Transform(1, 0, 0);
  16771. transform.prototype = Transform.prototype;
  16772. function transform(node) {
  16773. while (!node.__zoom) if (!(node = node.parentNode)) return identity;
  16774. return node.__zoom;
  16775. }
  16776. function nopropagation(event) {
  16777. event.stopImmediatePropagation();
  16778. }
  16779. function noevent(event) {
  16780. event.preventDefault();
  16781. event.stopImmediatePropagation();
  16782. }
  16783. // Ignore right-click, since that should open the context menu.
  16784. // except for pinch-to-zoom, which is sent as a wheel+ctrlKey event
  16785. function defaultFilter(event) {
  16786. return (!event.ctrlKey || event.type === 'wheel') && !event.button;
  16787. }
  16788. function defaultExtent() {
  16789. var e = this;
  16790. if (e instanceof SVGElement) {
  16791. e = e.ownerSVGElement || e;
  16792. if (e.hasAttribute("viewBox")) {
  16793. e = e.viewBox.baseVal;
  16794. return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
  16795. }
  16796. return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
  16797. }
  16798. return [[0, 0], [e.clientWidth, e.clientHeight]];
  16799. }
  16800. function defaultTransform() {
  16801. return this.__zoom || identity;
  16802. }
  16803. function defaultWheelDelta(event) {
  16804. return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1);
  16805. }
  16806. function defaultTouchable() {
  16807. return navigator.maxTouchPoints || ("ontouchstart" in this);
  16808. }
  16809. function defaultConstrain(transform, extent, translateExtent) {
  16810. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  16811. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  16812. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  16813. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  16814. return transform.translate(
  16815. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  16816. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  16817. );
  16818. }
  16819. function zoom() {
  16820. var filter = defaultFilter,
  16821. extent = defaultExtent,
  16822. constrain = defaultConstrain,
  16823. wheelDelta = defaultWheelDelta,
  16824. touchable = defaultTouchable,
  16825. scaleExtent = [0, Infinity],
  16826. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  16827. duration = 250,
  16828. interpolate = interpolateZoom,
  16829. listeners = dispatch("start", "zoom", "end"),
  16830. touchstarting,
  16831. touchfirst,
  16832. touchending,
  16833. touchDelay = 500,
  16834. wheelDelay = 150,
  16835. clickDistance2 = 0,
  16836. tapDistance = 10;
  16837. function zoom(selection) {
  16838. selection
  16839. .property("__zoom", defaultTransform)
  16840. .on("wheel.zoom", wheeled, {passive: false})
  16841. .on("mousedown.zoom", mousedowned)
  16842. .on("dblclick.zoom", dblclicked)
  16843. .filter(touchable)
  16844. .on("touchstart.zoom", touchstarted)
  16845. .on("touchmove.zoom", touchmoved)
  16846. .on("touchend.zoom touchcancel.zoom", touchended)
  16847. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  16848. }
  16849. zoom.transform = function(collection, transform, point, event) {
  16850. var selection = collection.selection ? collection.selection() : collection;
  16851. selection.property("__zoom", defaultTransform);
  16852. if (collection !== selection) {
  16853. schedule(collection, transform, point, event);
  16854. } else {
  16855. selection.interrupt().each(function() {
  16856. gesture(this, arguments)
  16857. .event(event)
  16858. .start()
  16859. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  16860. .end();
  16861. });
  16862. }
  16863. };
  16864. zoom.scaleBy = function(selection, k, p, event) {
  16865. zoom.scaleTo(selection, function() {
  16866. var k0 = this.__zoom.k,
  16867. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  16868. return k0 * k1;
  16869. }, p, event);
  16870. };
  16871. zoom.scaleTo = function(selection, k, p, event) {
  16872. zoom.transform(selection, function() {
  16873. var e = extent.apply(this, arguments),
  16874. t0 = this.__zoom,
  16875. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
  16876. p1 = t0.invert(p0),
  16877. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  16878. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  16879. }, p, event);
  16880. };
  16881. zoom.translateBy = function(selection, x, y, event) {
  16882. zoom.transform(selection, function() {
  16883. return constrain(this.__zoom.translate(
  16884. typeof x === "function" ? x.apply(this, arguments) : x,
  16885. typeof y === "function" ? y.apply(this, arguments) : y
  16886. ), extent.apply(this, arguments), translateExtent);
  16887. }, null, event);
  16888. };
  16889. zoom.translateTo = function(selection, x, y, p, event) {
  16890. zoom.transform(selection, function() {
  16891. var e = extent.apply(this, arguments),
  16892. t = this.__zoom,
  16893. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
  16894. return constrain(identity.translate(p0[0], p0[1]).scale(t.k).translate(
  16895. typeof x === "function" ? -x.apply(this, arguments) : -x,
  16896. typeof y === "function" ? -y.apply(this, arguments) : -y
  16897. ), e, translateExtent);
  16898. }, p, event);
  16899. };
  16900. function scale(transform, k) {
  16901. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  16902. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  16903. }
  16904. function translate(transform, p0, p1) {
  16905. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  16906. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  16907. }
  16908. function centroid(extent) {
  16909. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  16910. }
  16911. function schedule(transition, transform, point, event) {
  16912. transition
  16913. .on("start.zoom", function() { gesture(this, arguments).event(event).start(); })
  16914. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).event(event).end(); })
  16915. .tween("zoom", function() {
  16916. var that = this,
  16917. args = arguments,
  16918. g = gesture(that, args).event(event),
  16919. e = extent.apply(that, args),
  16920. p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
  16921. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  16922. a = that.__zoom,
  16923. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  16924. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  16925. return function(t) {
  16926. if (t === 1) t = b; // Avoid rounding error on end.
  16927. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  16928. g.zoom(null, t);
  16929. };
  16930. });
  16931. }
  16932. function gesture(that, args, clean) {
  16933. return (!clean && that.__zooming) || new Gesture(that, args);
  16934. }
  16935. function Gesture(that, args) {
  16936. this.that = that;
  16937. this.args = args;
  16938. this.active = 0;
  16939. this.sourceEvent = null;
  16940. this.extent = extent.apply(that, args);
  16941. this.taps = 0;
  16942. }
  16943. Gesture.prototype = {
  16944. event: function(event) {
  16945. if (event) this.sourceEvent = event;
  16946. return this;
  16947. },
  16948. start: function() {
  16949. if (++this.active === 1) {
  16950. this.that.__zooming = this;
  16951. this.emit("start");
  16952. }
  16953. return this;
  16954. },
  16955. zoom: function(key, transform) {
  16956. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  16957. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  16958. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  16959. this.that.__zoom = transform;
  16960. this.emit("zoom");
  16961. return this;
  16962. },
  16963. end: function() {
  16964. if (--this.active === 0) {
  16965. delete this.that.__zooming;
  16966. this.emit("end");
  16967. }
  16968. return this;
  16969. },
  16970. emit: function(type) {
  16971. var d = select(this.that).datum();
  16972. listeners.call(
  16973. type,
  16974. this.that,
  16975. new ZoomEvent(type, {
  16976. sourceEvent: this.sourceEvent,
  16977. target: zoom,
  16978. type,
  16979. transform: this.that.__zoom,
  16980. dispatch: listeners
  16981. }),
  16982. d
  16983. );
  16984. }
  16985. };
  16986. function wheeled(event, ...args) {
  16987. if (!filter.apply(this, arguments)) return;
  16988. var g = gesture(this, args).event(event),
  16989. t = this.__zoom,
  16990. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  16991. p = pointer(event);
  16992. // If the mouse is in the same location as before, reuse it.
  16993. // If there were recent wheel events, reset the wheel idle timeout.
  16994. if (g.wheel) {
  16995. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  16996. g.mouse[1] = t.invert(g.mouse[0] = p);
  16997. }
  16998. clearTimeout(g.wheel);
  16999. }
  17000. // If this wheel event won’t trigger a transform change, ignore it.
  17001. else if (t.k === k) return;
  17002. // Otherwise, capture the mouse point and location at the start.
  17003. else {
  17004. g.mouse = [p, t.invert(p)];
  17005. interrupt(this);
  17006. g.start();
  17007. }
  17008. noevent(event);
  17009. g.wheel = setTimeout(wheelidled, wheelDelay);
  17010. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  17011. function wheelidled() {
  17012. g.wheel = null;
  17013. g.end();
  17014. }
  17015. }
  17016. function mousedowned(event, ...args) {
  17017. if (touchending || !filter.apply(this, arguments)) return;
  17018. var currentTarget = event.currentTarget,
  17019. g = gesture(this, args, true).event(event),
  17020. v = select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  17021. p = pointer(event, currentTarget),
  17022. x0 = event.clientX,
  17023. y0 = event.clientY;
  17024. dragDisable(event.view);
  17025. nopropagation(event);
  17026. g.mouse = [p, this.__zoom.invert(p)];
  17027. interrupt(this);
  17028. g.start();
  17029. function mousemoved(event) {
  17030. noevent(event);
  17031. if (!g.moved) {
  17032. var dx = event.clientX - x0, dy = event.clientY - y0;
  17033. g.moved = dx * dx + dy * dy > clickDistance2;
  17034. }
  17035. g.event(event)
  17036. .zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = pointer(event, currentTarget), g.mouse[1]), g.extent, translateExtent));
  17037. }
  17038. function mouseupped(event) {
  17039. v.on("mousemove.zoom mouseup.zoom", null);
  17040. yesdrag(event.view, g.moved);
  17041. noevent(event);
  17042. g.event(event).end();
  17043. }
  17044. }
  17045. function dblclicked(event, ...args) {
  17046. if (!filter.apply(this, arguments)) return;
  17047. var t0 = this.__zoom,
  17048. p0 = pointer(event.changedTouches ? event.changedTouches[0] : event, this),
  17049. p1 = t0.invert(p0),
  17050. k1 = t0.k * (event.shiftKey ? 0.5 : 2),
  17051. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, args), translateExtent);
  17052. noevent(event);
  17053. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0, event);
  17054. else select(this).call(zoom.transform, t1, p0, event);
  17055. }
  17056. function touchstarted(event, ...args) {
  17057. if (!filter.apply(this, arguments)) return;
  17058. var touches = event.touches,
  17059. n = touches.length,
  17060. g = gesture(this, args, event.changedTouches.length === n).event(event),
  17061. started, i, t, p;
  17062. nopropagation(event);
  17063. for (i = 0; i < n; ++i) {
  17064. t = touches[i], p = pointer(t, this);
  17065. p = [p, this.__zoom.invert(p), t.identifier];
  17066. if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
  17067. else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
  17068. }
  17069. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  17070. if (started) {
  17071. if (g.taps < 2) touchfirst = p[0], touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  17072. interrupt(this);
  17073. g.start();
  17074. }
  17075. }
  17076. function touchmoved(event, ...args) {
  17077. if (!this.__zooming) return;
  17078. var g = gesture(this, args).event(event),
  17079. touches = event.changedTouches,
  17080. n = touches.length, i, t, p, l;
  17081. noevent(event);
  17082. for (i = 0; i < n; ++i) {
  17083. t = touches[i], p = pointer(t, this);
  17084. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  17085. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  17086. }
  17087. t = g.that.__zoom;
  17088. if (g.touch1) {
  17089. var p0 = g.touch0[0], l0 = g.touch0[1],
  17090. p1 = g.touch1[0], l1 = g.touch1[1],
  17091. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  17092. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  17093. t = scale(t, Math.sqrt(dp / dl));
  17094. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  17095. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  17096. }
  17097. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  17098. else return;
  17099. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  17100. }
  17101. function touchended(event, ...args) {
  17102. if (!this.__zooming) return;
  17103. var g = gesture(this, args).event(event),
  17104. touches = event.changedTouches,
  17105. n = touches.length, i, t;
  17106. nopropagation(event);
  17107. if (touchending) clearTimeout(touchending);
  17108. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  17109. for (i = 0; i < n; ++i) {
  17110. t = touches[i];
  17111. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  17112. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  17113. }
  17114. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  17115. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  17116. else {
  17117. g.end();
  17118. // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
  17119. if (g.taps === 2) {
  17120. t = pointer(t, this);
  17121. if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) {
  17122. var p = select(this).on("dblclick.zoom");
  17123. if (p) p.apply(this, arguments);
  17124. }
  17125. }
  17126. }
  17127. }
  17128. zoom.wheelDelta = function(_) {
  17129. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant(+_), zoom) : wheelDelta;
  17130. };
  17131. zoom.filter = function(_) {
  17132. return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter;
  17133. };
  17134. zoom.touchable = function(_) {
  17135. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), zoom) : touchable;
  17136. };
  17137. zoom.extent = function(_) {
  17138. return arguments.length ? (extent = typeof _ === "function" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  17139. };
  17140. zoom.scaleExtent = function(_) {
  17141. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  17142. };
  17143. zoom.translateExtent = function(_) {
  17144. 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]]];
  17145. };
  17146. zoom.constrain = function(_) {
  17147. return arguments.length ? (constrain = _, zoom) : constrain;
  17148. };
  17149. zoom.duration = function(_) {
  17150. return arguments.length ? (duration = +_, zoom) : duration;
  17151. };
  17152. zoom.interpolate = function(_) {
  17153. return arguments.length ? (interpolate = _, zoom) : interpolate;
  17154. };
  17155. zoom.on = function() {
  17156. var value = listeners.on.apply(listeners, arguments);
  17157. return value === listeners ? zoom : value;
  17158. };
  17159. zoom.clickDistance = function(_) {
  17160. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  17161. };
  17162. zoom.tapDistance = function(_) {
  17163. return arguments.length ? (tapDistance = +_, zoom) : tapDistance;
  17164. };
  17165. return zoom;
  17166. }
  17167. exports.Adder = Adder;
  17168. exports.Delaunay = Delaunay;
  17169. exports.FormatSpecifier = FormatSpecifier;
  17170. exports.InternMap = InternMap;
  17171. exports.InternSet = InternSet;
  17172. exports.Node = Node$1;
  17173. exports.Path = Path$1;
  17174. exports.Voronoi = Voronoi;
  17175. exports.ZoomTransform = Transform;
  17176. exports.active = active;
  17177. exports.arc = arc;
  17178. exports.area = area;
  17179. exports.areaRadial = areaRadial;
  17180. exports.ascending = ascending$3;
  17181. exports.autoType = autoType;
  17182. exports.axisBottom = axisBottom;
  17183. exports.axisLeft = axisLeft;
  17184. exports.axisRight = axisRight;
  17185. exports.axisTop = axisTop;
  17186. exports.bin = bin;
  17187. exports.bisect = bisect;
  17188. exports.bisectCenter = bisectCenter;
  17189. exports.bisectLeft = bisectLeft;
  17190. exports.bisectRight = bisectRight;
  17191. exports.bisector = bisector;
  17192. exports.blob = blob;
  17193. exports.blur = blur;
  17194. exports.blur2 = blur2;
  17195. exports.blurImage = blurImage;
  17196. exports.brush = brush;
  17197. exports.brushSelection = brushSelection;
  17198. exports.brushX = brushX;
  17199. exports.brushY = brushY;
  17200. exports.buffer = buffer;
  17201. exports.chord = chord;
  17202. exports.chordDirected = chordDirected;
  17203. exports.chordTranspose = chordTranspose;
  17204. exports.cluster = cluster;
  17205. exports.color = color;
  17206. exports.contourDensity = density;
  17207. exports.contours = Contours;
  17208. exports.count = count$1;
  17209. exports.create = create$1;
  17210. exports.creator = creator;
  17211. exports.cross = cross$2;
  17212. exports.csv = csv;
  17213. exports.csvFormat = csvFormat;
  17214. exports.csvFormatBody = csvFormatBody;
  17215. exports.csvFormatRow = csvFormatRow;
  17216. exports.csvFormatRows = csvFormatRows;
  17217. exports.csvFormatValue = csvFormatValue;
  17218. exports.csvParse = csvParse;
  17219. exports.csvParseRows = csvParseRows;
  17220. exports.cubehelix = cubehelix$3;
  17221. exports.cumsum = cumsum;
  17222. exports.curveBasis = basis;
  17223. exports.curveBasisClosed = basisClosed;
  17224. exports.curveBasisOpen = basisOpen;
  17225. exports.curveBumpX = bumpX;
  17226. exports.curveBumpY = bumpY;
  17227. exports.curveBundle = bundle;
  17228. exports.curveCardinal = cardinal;
  17229. exports.curveCardinalClosed = cardinalClosed;
  17230. exports.curveCardinalOpen = cardinalOpen;
  17231. exports.curveCatmullRom = catmullRom;
  17232. exports.curveCatmullRomClosed = catmullRomClosed;
  17233. exports.curveCatmullRomOpen = catmullRomOpen;
  17234. exports.curveLinear = curveLinear;
  17235. exports.curveLinearClosed = linearClosed;
  17236. exports.curveMonotoneX = monotoneX;
  17237. exports.curveMonotoneY = monotoneY;
  17238. exports.curveNatural = natural;
  17239. exports.curveStep = step;
  17240. exports.curveStepAfter = stepAfter;
  17241. exports.curveStepBefore = stepBefore;
  17242. exports.descending = descending$2;
  17243. exports.deviation = deviation;
  17244. exports.difference = difference;
  17245. exports.disjoint = disjoint;
  17246. exports.dispatch = dispatch;
  17247. exports.drag = drag;
  17248. exports.dragDisable = dragDisable;
  17249. exports.dragEnable = yesdrag;
  17250. exports.dsv = dsv;
  17251. exports.dsvFormat = dsvFormat;
  17252. exports.easeBack = backInOut;
  17253. exports.easeBackIn = backIn;
  17254. exports.easeBackInOut = backInOut;
  17255. exports.easeBackOut = backOut;
  17256. exports.easeBounce = bounceOut;
  17257. exports.easeBounceIn = bounceIn;
  17258. exports.easeBounceInOut = bounceInOut;
  17259. exports.easeBounceOut = bounceOut;
  17260. exports.easeCircle = circleInOut;
  17261. exports.easeCircleIn = circleIn;
  17262. exports.easeCircleInOut = circleInOut;
  17263. exports.easeCircleOut = circleOut;
  17264. exports.easeCubic = cubicInOut;
  17265. exports.easeCubicIn = cubicIn;
  17266. exports.easeCubicInOut = cubicInOut;
  17267. exports.easeCubicOut = cubicOut;
  17268. exports.easeElastic = elasticOut;
  17269. exports.easeElasticIn = elasticIn;
  17270. exports.easeElasticInOut = elasticInOut;
  17271. exports.easeElasticOut = elasticOut;
  17272. exports.easeExp = expInOut;
  17273. exports.easeExpIn = expIn;
  17274. exports.easeExpInOut = expInOut;
  17275. exports.easeExpOut = expOut;
  17276. exports.easeLinear = linear$1;
  17277. exports.easePoly = polyInOut;
  17278. exports.easePolyIn = polyIn;
  17279. exports.easePolyInOut = polyInOut;
  17280. exports.easePolyOut = polyOut;
  17281. exports.easeQuad = quadInOut;
  17282. exports.easeQuadIn = quadIn;
  17283. exports.easeQuadInOut = quadInOut;
  17284. exports.easeQuadOut = quadOut;
  17285. exports.easeSin = sinInOut;
  17286. exports.easeSinIn = sinIn;
  17287. exports.easeSinInOut = sinInOut;
  17288. exports.easeSinOut = sinOut;
  17289. exports.every = every;
  17290. exports.extent = extent$1;
  17291. exports.fcumsum = fcumsum;
  17292. exports.filter = filter$1;
  17293. exports.flatGroup = flatGroup;
  17294. exports.flatRollup = flatRollup;
  17295. exports.forceCenter = center;
  17296. exports.forceCollide = collide;
  17297. exports.forceLink = link$2;
  17298. exports.forceManyBody = manyBody;
  17299. exports.forceRadial = radial$1;
  17300. exports.forceSimulation = simulation;
  17301. exports.forceX = x$1;
  17302. exports.forceY = y$1;
  17303. exports.formatDefaultLocale = defaultLocale$1;
  17304. exports.formatLocale = formatLocale$1;
  17305. exports.formatSpecifier = formatSpecifier;
  17306. exports.fsum = fsum;
  17307. exports.geoAlbers = albers;
  17308. exports.geoAlbersUsa = albersUsa;
  17309. exports.geoArea = area$2;
  17310. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  17311. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  17312. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  17313. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  17314. exports.geoBounds = bounds;
  17315. exports.geoCentroid = centroid$1;
  17316. exports.geoCircle = circle$1;
  17317. exports.geoClipAntimeridian = clipAntimeridian;
  17318. exports.geoClipCircle = clipCircle;
  17319. exports.geoClipExtent = extent;
  17320. exports.geoClipRectangle = clipRectangle;
  17321. exports.geoConicConformal = conicConformal;
  17322. exports.geoConicConformalRaw = conicConformalRaw;
  17323. exports.geoConicEqualArea = conicEqualArea;
  17324. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  17325. exports.geoConicEquidistant = conicEquidistant;
  17326. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  17327. exports.geoContains = contains$1;
  17328. exports.geoDistance = distance;
  17329. exports.geoEqualEarth = equalEarth;
  17330. exports.geoEqualEarthRaw = equalEarthRaw;
  17331. exports.geoEquirectangular = equirectangular;
  17332. exports.geoEquirectangularRaw = equirectangularRaw;
  17333. exports.geoGnomonic = gnomonic;
  17334. exports.geoGnomonicRaw = gnomonicRaw;
  17335. exports.geoGraticule = graticule;
  17336. exports.geoGraticule10 = graticule10;
  17337. exports.geoIdentity = identity$4;
  17338. exports.geoInterpolate = interpolate;
  17339. exports.geoLength = length$1;
  17340. exports.geoMercator = mercator;
  17341. exports.geoMercatorRaw = mercatorRaw;
  17342. exports.geoNaturalEarth1 = naturalEarth1;
  17343. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  17344. exports.geoOrthographic = orthographic;
  17345. exports.geoOrthographicRaw = orthographicRaw;
  17346. exports.geoPath = index$2;
  17347. exports.geoProjection = projection;
  17348. exports.geoProjectionMutator = projectionMutator;
  17349. exports.geoRotation = rotation;
  17350. exports.geoStereographic = stereographic;
  17351. exports.geoStereographicRaw = stereographicRaw;
  17352. exports.geoStream = geoStream;
  17353. exports.geoTransform = transform$1;
  17354. exports.geoTransverseMercator = transverseMercator;
  17355. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  17356. exports.gray = gray;
  17357. exports.greatest = greatest;
  17358. exports.greatestIndex = greatestIndex;
  17359. exports.group = group;
  17360. exports.groupSort = groupSort;
  17361. exports.groups = groups;
  17362. exports.hcl = hcl$2;
  17363. exports.hierarchy = hierarchy;
  17364. exports.histogram = bin;
  17365. exports.hsl = hsl$2;
  17366. exports.html = html;
  17367. exports.image = image;
  17368. exports.index = index$4;
  17369. exports.indexes = indexes;
  17370. exports.interpolate = interpolate$2;
  17371. exports.interpolateArray = array$3;
  17372. exports.interpolateBasis = basis$2;
  17373. exports.interpolateBasisClosed = basisClosed$1;
  17374. exports.interpolateBlues = Blues;
  17375. exports.interpolateBrBG = BrBG;
  17376. exports.interpolateBuGn = BuGn;
  17377. exports.interpolateBuPu = BuPu;
  17378. exports.interpolateCividis = cividis;
  17379. exports.interpolateCool = cool;
  17380. exports.interpolateCubehelix = cubehelix$2;
  17381. exports.interpolateCubehelixDefault = cubehelix;
  17382. exports.interpolateCubehelixLong = cubehelixLong;
  17383. exports.interpolateDate = date$1;
  17384. exports.interpolateDiscrete = discrete;
  17385. exports.interpolateGnBu = GnBu;
  17386. exports.interpolateGreens = Greens;
  17387. exports.interpolateGreys = Greys;
  17388. exports.interpolateHcl = hcl$1;
  17389. exports.interpolateHclLong = hclLong;
  17390. exports.interpolateHsl = hsl$1;
  17391. exports.interpolateHslLong = hslLong;
  17392. exports.interpolateHue = hue;
  17393. exports.interpolateInferno = inferno;
  17394. exports.interpolateLab = lab;
  17395. exports.interpolateMagma = magma;
  17396. exports.interpolateNumber = interpolateNumber;
  17397. exports.interpolateNumberArray = numberArray;
  17398. exports.interpolateObject = object$1;
  17399. exports.interpolateOrRd = OrRd;
  17400. exports.interpolateOranges = Oranges;
  17401. exports.interpolatePRGn = PRGn;
  17402. exports.interpolatePiYG = PiYG;
  17403. exports.interpolatePlasma = plasma;
  17404. exports.interpolatePuBu = PuBu;
  17405. exports.interpolatePuBuGn = PuBuGn;
  17406. exports.interpolatePuOr = PuOr;
  17407. exports.interpolatePuRd = PuRd;
  17408. exports.interpolatePurples = Purples;
  17409. exports.interpolateRainbow = rainbow;
  17410. exports.interpolateRdBu = RdBu;
  17411. exports.interpolateRdGy = RdGy;
  17412. exports.interpolateRdPu = RdPu;
  17413. exports.interpolateRdYlBu = RdYlBu;
  17414. exports.interpolateRdYlGn = RdYlGn;
  17415. exports.interpolateReds = Reds;
  17416. exports.interpolateRgb = interpolateRgb;
  17417. exports.interpolateRgbBasis = rgbBasis;
  17418. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  17419. exports.interpolateRound = interpolateRound;
  17420. exports.interpolateSinebow = sinebow;
  17421. exports.interpolateSpectral = Spectral;
  17422. exports.interpolateString = interpolateString;
  17423. exports.interpolateTransformCss = interpolateTransformCss;
  17424. exports.interpolateTransformSvg = interpolateTransformSvg;
  17425. exports.interpolateTurbo = turbo;
  17426. exports.interpolateViridis = viridis;
  17427. exports.interpolateWarm = warm;
  17428. exports.interpolateYlGn = YlGn;
  17429. exports.interpolateYlGnBu = YlGnBu;
  17430. exports.interpolateYlOrBr = YlOrBr;
  17431. exports.interpolateYlOrRd = YlOrRd;
  17432. exports.interpolateZoom = interpolateZoom;
  17433. exports.interrupt = interrupt;
  17434. exports.intersection = intersection;
  17435. exports.interval = interval;
  17436. exports.isoFormat = formatIso$1;
  17437. exports.isoParse = parseIso$1;
  17438. exports.json = json;
  17439. exports.lab = lab$1;
  17440. exports.lch = lch;
  17441. exports.least = least;
  17442. exports.leastIndex = leastIndex;
  17443. exports.line = line;
  17444. exports.lineRadial = lineRadial$1;
  17445. exports.link = link;
  17446. exports.linkHorizontal = linkHorizontal;
  17447. exports.linkRadial = linkRadial;
  17448. exports.linkVertical = linkVertical;
  17449. exports.local = local$1;
  17450. exports.map = map$1;
  17451. exports.matcher = matcher;
  17452. exports.max = max$3;
  17453. exports.maxIndex = maxIndex;
  17454. exports.mean = mean;
  17455. exports.median = median;
  17456. exports.medianIndex = medianIndex;
  17457. exports.merge = merge;
  17458. exports.min = min$2;
  17459. exports.minIndex = minIndex;
  17460. exports.mode = mode;
  17461. exports.namespace = namespace;
  17462. exports.namespaces = namespaces;
  17463. exports.nice = nice$1;
  17464. exports.now = now;
  17465. exports.pack = index$1;
  17466. exports.packEnclose = enclose;
  17467. exports.packSiblings = siblings;
  17468. exports.pairs = pairs;
  17469. exports.partition = partition;
  17470. exports.path = path;
  17471. exports.pathRound = pathRound;
  17472. exports.permute = permute;
  17473. exports.pie = pie;
  17474. exports.piecewise = piecewise;
  17475. exports.pointRadial = pointRadial;
  17476. exports.pointer = pointer;
  17477. exports.pointers = pointers;
  17478. exports.polygonArea = area$1;
  17479. exports.polygonCentroid = centroid;
  17480. exports.polygonContains = contains;
  17481. exports.polygonHull = hull;
  17482. exports.polygonLength = length;
  17483. exports.precisionFixed = precisionFixed;
  17484. exports.precisionPrefix = precisionPrefix;
  17485. exports.precisionRound = precisionRound;
  17486. exports.quadtree = quadtree;
  17487. exports.quantile = quantile$1;
  17488. exports.quantileIndex = quantileIndex;
  17489. exports.quantileSorted = quantileSorted;
  17490. exports.quantize = quantize$1;
  17491. exports.quickselect = quickselect;
  17492. exports.radialArea = areaRadial;
  17493. exports.radialLine = lineRadial$1;
  17494. exports.randomBates = bates;
  17495. exports.randomBernoulli = bernoulli;
  17496. exports.randomBeta = beta;
  17497. exports.randomBinomial = binomial;
  17498. exports.randomCauchy = cauchy;
  17499. exports.randomExponential = exponential;
  17500. exports.randomGamma = gamma;
  17501. exports.randomGeometric = geometric;
  17502. exports.randomInt = int;
  17503. exports.randomIrwinHall = irwinHall;
  17504. exports.randomLcg = lcg;
  17505. exports.randomLogNormal = logNormal;
  17506. exports.randomLogistic = logistic;
  17507. exports.randomNormal = normal;
  17508. exports.randomPareto = pareto;
  17509. exports.randomPoisson = poisson;
  17510. exports.randomUniform = uniform;
  17511. exports.randomWeibull = weibull;
  17512. exports.range = range$2;
  17513. exports.rank = rank;
  17514. exports.reduce = reduce;
  17515. exports.reverse = reverse$1;
  17516. exports.rgb = rgb;
  17517. exports.ribbon = ribbon$1;
  17518. exports.ribbonArrow = ribbonArrow;
  17519. exports.rollup = rollup;
  17520. exports.rollups = rollups;
  17521. exports.scaleBand = band;
  17522. exports.scaleDiverging = diverging$1;
  17523. exports.scaleDivergingLog = divergingLog;
  17524. exports.scaleDivergingPow = divergingPow;
  17525. exports.scaleDivergingSqrt = divergingSqrt;
  17526. exports.scaleDivergingSymlog = divergingSymlog;
  17527. exports.scaleIdentity = identity$2;
  17528. exports.scaleImplicit = implicit;
  17529. exports.scaleLinear = linear;
  17530. exports.scaleLog = log;
  17531. exports.scaleOrdinal = ordinal;
  17532. exports.scalePoint = point$4;
  17533. exports.scalePow = pow;
  17534. exports.scaleQuantile = quantile;
  17535. exports.scaleQuantize = quantize;
  17536. exports.scaleRadial = radial;
  17537. exports.scaleSequential = sequential;
  17538. exports.scaleSequentialLog = sequentialLog;
  17539. exports.scaleSequentialPow = sequentialPow;
  17540. exports.scaleSequentialQuantile = sequentialQuantile;
  17541. exports.scaleSequentialSqrt = sequentialSqrt;
  17542. exports.scaleSequentialSymlog = sequentialSymlog;
  17543. exports.scaleSqrt = sqrt$1;
  17544. exports.scaleSymlog = symlog;
  17545. exports.scaleThreshold = threshold;
  17546. exports.scaleTime = time;
  17547. exports.scaleUtc = utcTime;
  17548. exports.scan = scan;
  17549. exports.schemeAccent = Accent;
  17550. exports.schemeBlues = scheme$5;
  17551. exports.schemeBrBG = scheme$q;
  17552. exports.schemeBuGn = scheme$h;
  17553. exports.schemeBuPu = scheme$g;
  17554. exports.schemeCategory10 = category10;
  17555. exports.schemeDark2 = Dark2;
  17556. exports.schemeGnBu = scheme$f;
  17557. exports.schemeGreens = scheme$4;
  17558. exports.schemeGreys = scheme$3;
  17559. exports.schemeOrRd = scheme$e;
  17560. exports.schemeOranges = scheme;
  17561. exports.schemePRGn = scheme$p;
  17562. exports.schemePaired = Paired;
  17563. exports.schemePastel1 = Pastel1;
  17564. exports.schemePastel2 = Pastel2;
  17565. exports.schemePiYG = scheme$o;
  17566. exports.schemePuBu = scheme$c;
  17567. exports.schemePuBuGn = scheme$d;
  17568. exports.schemePuOr = scheme$n;
  17569. exports.schemePuRd = scheme$b;
  17570. exports.schemePurples = scheme$2;
  17571. exports.schemeRdBu = scheme$m;
  17572. exports.schemeRdGy = scheme$l;
  17573. exports.schemeRdPu = scheme$a;
  17574. exports.schemeRdYlBu = scheme$k;
  17575. exports.schemeRdYlGn = scheme$j;
  17576. exports.schemeReds = scheme$1;
  17577. exports.schemeSet1 = Set1;
  17578. exports.schemeSet2 = Set2;
  17579. exports.schemeSet3 = Set3;
  17580. exports.schemeSpectral = scheme$i;
  17581. exports.schemeTableau10 = Tableau10;
  17582. exports.schemeYlGn = scheme$8;
  17583. exports.schemeYlGnBu = scheme$9;
  17584. exports.schemeYlOrBr = scheme$7;
  17585. exports.schemeYlOrRd = scheme$6;
  17586. exports.select = select;
  17587. exports.selectAll = selectAll;
  17588. exports.selection = selection;
  17589. exports.selector = selector;
  17590. exports.selectorAll = selectorAll;
  17591. exports.shuffle = shuffle$1;
  17592. exports.shuffler = shuffler;
  17593. exports.some = some;
  17594. exports.sort = sort;
  17595. exports.stack = stack;
  17596. exports.stackOffsetDiverging = diverging;
  17597. exports.stackOffsetExpand = expand;
  17598. exports.stackOffsetNone = none$1;
  17599. exports.stackOffsetSilhouette = silhouette;
  17600. exports.stackOffsetWiggle = wiggle;
  17601. exports.stackOrderAppearance = appearance;
  17602. exports.stackOrderAscending = ascending;
  17603. exports.stackOrderDescending = descending;
  17604. exports.stackOrderInsideOut = insideOut;
  17605. exports.stackOrderNone = none;
  17606. exports.stackOrderReverse = reverse;
  17607. exports.stratify = stratify;
  17608. exports.style = styleValue;
  17609. exports.subset = subset;
  17610. exports.sum = sum$2;
  17611. exports.superset = superset;
  17612. exports.svg = svg;
  17613. exports.symbol = Symbol$1;
  17614. exports.symbolAsterisk = asterisk;
  17615. exports.symbolCircle = circle;
  17616. exports.symbolCross = cross;
  17617. exports.symbolDiamond = diamond;
  17618. exports.symbolDiamond2 = diamond2;
  17619. exports.symbolPlus = plus;
  17620. exports.symbolSquare = square;
  17621. exports.symbolSquare2 = square2;
  17622. exports.symbolStar = star;
  17623. exports.symbolTimes = times;
  17624. exports.symbolTriangle = triangle;
  17625. exports.symbolTriangle2 = triangle2;
  17626. exports.symbolWye = wye;
  17627. exports.symbolX = times;
  17628. exports.symbols = symbolsFill;
  17629. exports.symbolsFill = symbolsFill;
  17630. exports.symbolsStroke = symbolsStroke;
  17631. exports.text = text;
  17632. exports.thresholdFreedmanDiaconis = thresholdFreedmanDiaconis;
  17633. exports.thresholdScott = thresholdScott;
  17634. exports.thresholdSturges = thresholdSturges;
  17635. exports.tickFormat = tickFormat;
  17636. exports.tickIncrement = tickIncrement;
  17637. exports.tickStep = tickStep;
  17638. exports.ticks = ticks;
  17639. exports.timeDay = timeDay;
  17640. exports.timeDays = timeDays;
  17641. exports.timeFormatDefaultLocale = defaultLocale;
  17642. exports.timeFormatLocale = formatLocale;
  17643. exports.timeFriday = timeFriday;
  17644. exports.timeFridays = timeFridays;
  17645. exports.timeHour = timeHour;
  17646. exports.timeHours = timeHours;
  17647. exports.timeInterval = timeInterval;
  17648. exports.timeMillisecond = millisecond;
  17649. exports.timeMilliseconds = milliseconds;
  17650. exports.timeMinute = timeMinute;
  17651. exports.timeMinutes = timeMinutes;
  17652. exports.timeMonday = timeMonday;
  17653. exports.timeMondays = timeMondays;
  17654. exports.timeMonth = timeMonth;
  17655. exports.timeMonths = timeMonths;
  17656. exports.timeSaturday = timeSaturday;
  17657. exports.timeSaturdays = timeSaturdays;
  17658. exports.timeSecond = second;
  17659. exports.timeSeconds = seconds;
  17660. exports.timeSunday = timeSunday;
  17661. exports.timeSundays = timeSundays;
  17662. exports.timeThursday = timeThursday;
  17663. exports.timeThursdays = timeThursdays;
  17664. exports.timeTickInterval = timeTickInterval;
  17665. exports.timeTicks = timeTicks;
  17666. exports.timeTuesday = timeTuesday;
  17667. exports.timeTuesdays = timeTuesdays;
  17668. exports.timeWednesday = timeWednesday;
  17669. exports.timeWednesdays = timeWednesdays;
  17670. exports.timeWeek = timeSunday;
  17671. exports.timeWeeks = timeSundays;
  17672. exports.timeYear = timeYear;
  17673. exports.timeYears = timeYears;
  17674. exports.timeout = timeout;
  17675. exports.timer = timer;
  17676. exports.timerFlush = timerFlush;
  17677. exports.transition = transition;
  17678. exports.transpose = transpose;
  17679. exports.tree = tree;
  17680. exports.treemap = index;
  17681. exports.treemapBinary = binary;
  17682. exports.treemapDice = treemapDice;
  17683. exports.treemapResquarify = resquarify;
  17684. exports.treemapSlice = treemapSlice;
  17685. exports.treemapSliceDice = sliceDice;
  17686. exports.treemapSquarify = squarify;
  17687. exports.tsv = tsv;
  17688. exports.tsvFormat = tsvFormat;
  17689. exports.tsvFormatBody = tsvFormatBody;
  17690. exports.tsvFormatRow = tsvFormatRow;
  17691. exports.tsvFormatRows = tsvFormatRows;
  17692. exports.tsvFormatValue = tsvFormatValue;
  17693. exports.tsvParse = tsvParse;
  17694. exports.tsvParseRows = tsvParseRows;
  17695. exports.union = union;
  17696. exports.unixDay = unixDay;
  17697. exports.unixDays = unixDays;
  17698. exports.utcDay = utcDay;
  17699. exports.utcDays = utcDays;
  17700. exports.utcFriday = utcFriday;
  17701. exports.utcFridays = utcFridays;
  17702. exports.utcHour = utcHour;
  17703. exports.utcHours = utcHours;
  17704. exports.utcMillisecond = millisecond;
  17705. exports.utcMilliseconds = milliseconds;
  17706. exports.utcMinute = utcMinute;
  17707. exports.utcMinutes = utcMinutes;
  17708. exports.utcMonday = utcMonday;
  17709. exports.utcMondays = utcMondays;
  17710. exports.utcMonth = utcMonth;
  17711. exports.utcMonths = utcMonths;
  17712. exports.utcSaturday = utcSaturday;
  17713. exports.utcSaturdays = utcSaturdays;
  17714. exports.utcSecond = second;
  17715. exports.utcSeconds = seconds;
  17716. exports.utcSunday = utcSunday;
  17717. exports.utcSundays = utcSundays;
  17718. exports.utcThursday = utcThursday;
  17719. exports.utcThursdays = utcThursdays;
  17720. exports.utcTickInterval = utcTickInterval;
  17721. exports.utcTicks = utcTicks;
  17722. exports.utcTuesday = utcTuesday;
  17723. exports.utcTuesdays = utcTuesdays;
  17724. exports.utcWednesday = utcWednesday;
  17725. exports.utcWednesdays = utcWednesdays;
  17726. exports.utcWeek = utcSunday;
  17727. exports.utcWeeks = utcSundays;
  17728. exports.utcYear = utcYear;
  17729. exports.utcYears = utcYears;
  17730. exports.variance = variance;
  17731. exports.version = version;
  17732. exports.window = defaultView;
  17733. exports.xml = xml;
  17734. exports.zip = zip;
  17735. exports.zoom = zoom;
  17736. exports.zoomIdentity = identity;
  17737. exports.zoomTransform = transform;
  17738. }));