d3.v6.js 543 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567
  1. // https://d3js.org v6.3.1 Copyright 2020 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 = "6.3.1";
  8. function ascending(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function bisector(f) {
  12. let delta = f;
  13. let compare = f;
  14. if (f.length === 1) {
  15. delta = (d, x) => f(d) - x;
  16. compare = ascendingComparator(f);
  17. }
  18. function left(a, x, lo, hi) {
  19. if (lo == null) lo = 0;
  20. if (hi == null) hi = a.length;
  21. while (lo < hi) {
  22. const mid = (lo + hi) >>> 1;
  23. if (compare(a[mid], x) < 0) lo = mid + 1;
  24. else hi = mid;
  25. }
  26. return lo;
  27. }
  28. function right(a, x, lo, hi) {
  29. if (lo == null) lo = 0;
  30. if (hi == null) hi = a.length;
  31. while (lo < hi) {
  32. const mid = (lo + hi) >>> 1;
  33. if (compare(a[mid], x) > 0) hi = mid;
  34. else lo = mid + 1;
  35. }
  36. return lo;
  37. }
  38. function center(a, x, lo, hi) {
  39. if (lo == null) lo = 0;
  40. if (hi == null) hi = a.length;
  41. const i = left(a, x, lo, hi - 1);
  42. return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
  43. }
  44. return {left, center, right};
  45. }
  46. function ascendingComparator(f) {
  47. return (d, x) => ascending(f(d), x);
  48. }
  49. function number(x) {
  50. return x === null ? NaN : +x;
  51. }
  52. function* numbers(values, valueof) {
  53. if (valueof === undefined) {
  54. for (let value of values) {
  55. if (value != null && (value = +value) >= value) {
  56. yield value;
  57. }
  58. }
  59. } else {
  60. let index = -1;
  61. for (let value of values) {
  62. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  63. yield value;
  64. }
  65. }
  66. }
  67. }
  68. const ascendingBisect = bisector(ascending);
  69. const bisectRight = ascendingBisect.right;
  70. const bisectLeft = ascendingBisect.left;
  71. const bisectCenter = bisector(number).center;
  72. function count(values, valueof) {
  73. let count = 0;
  74. if (valueof === undefined) {
  75. for (let value of values) {
  76. if (value != null && (value = +value) >= value) {
  77. ++count;
  78. }
  79. }
  80. } else {
  81. let index = -1;
  82. for (let value of values) {
  83. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  84. ++count;
  85. }
  86. }
  87. }
  88. return count;
  89. }
  90. function length(array) {
  91. return array.length | 0;
  92. }
  93. function empty(length) {
  94. return !(length > 0);
  95. }
  96. function arrayify(values) {
  97. return typeof values !== "object" || "length" in values ? values : Array.from(values);
  98. }
  99. function reducer(reduce) {
  100. return values => reduce(...values);
  101. }
  102. function cross(...values) {
  103. const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
  104. values = values.map(arrayify);
  105. const lengths = values.map(length);
  106. const j = values.length - 1;
  107. const index = new Array(j + 1).fill(0);
  108. const product = [];
  109. if (j < 0 || lengths.some(empty)) return product;
  110. while (true) {
  111. product.push(index.map((j, i) => values[i][j]));
  112. let i = j;
  113. while (++index[i] === lengths[i]) {
  114. if (i === 0) return reduce ? product.map(reduce) : product;
  115. index[i--] = 0;
  116. }
  117. }
  118. }
  119. function cumsum(values, valueof) {
  120. var sum = 0, index = 0;
  121. return Float64Array.from(values, valueof === undefined
  122. ? v => (sum += +v || 0)
  123. : v => (sum += +valueof(v, index++, values) || 0));
  124. }
  125. function descending(a, b) {
  126. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  127. }
  128. function variance(values, valueof) {
  129. let count = 0;
  130. let delta;
  131. let mean = 0;
  132. let sum = 0;
  133. if (valueof === undefined) {
  134. for (let value of values) {
  135. if (value != null && (value = +value) >= value) {
  136. delta = value - mean;
  137. mean += delta / ++count;
  138. sum += delta * (value - mean);
  139. }
  140. }
  141. } else {
  142. let index = -1;
  143. for (let value of values) {
  144. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  145. delta = value - mean;
  146. mean += delta / ++count;
  147. sum += delta * (value - mean);
  148. }
  149. }
  150. }
  151. if (count > 1) return sum / (count - 1);
  152. }
  153. function deviation(values, valueof) {
  154. const v = variance(values, valueof);
  155. return v ? Math.sqrt(v) : v;
  156. }
  157. function extent(values, valueof) {
  158. let min;
  159. let max;
  160. if (valueof === undefined) {
  161. for (const value of values) {
  162. if (value != null) {
  163. if (min === undefined) {
  164. if (value >= value) min = max = value;
  165. } else {
  166. if (min > value) min = value;
  167. if (max < value) max = value;
  168. }
  169. }
  170. }
  171. } else {
  172. let index = -1;
  173. for (let value of values) {
  174. if ((value = valueof(value, ++index, values)) != null) {
  175. if (min === undefined) {
  176. if (value >= value) min = max = value;
  177. } else {
  178. if (min > value) min = value;
  179. if (max < value) max = value;
  180. }
  181. }
  182. }
  183. }
  184. return [min, max];
  185. }
  186. // https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Modules/mathmodule.c#L1423
  187. class Adder {
  188. constructor() {
  189. this._partials = new Float64Array(32);
  190. this._n = 0;
  191. }
  192. add(x) {
  193. const p = this._partials;
  194. let i = 0;
  195. for (let j = 0; j < this._n && j < 32; j++) {
  196. const y = p[j],
  197. hi = x + y,
  198. lo = Math.abs(x) < Math.abs(y) ? x - (hi - y) : y - (hi - x);
  199. if (lo) p[i++] = lo;
  200. x = hi;
  201. }
  202. p[i] = x;
  203. this._n = i + 1;
  204. return this;
  205. }
  206. valueOf() {
  207. const p = this._partials;
  208. let n = this._n, x, y, lo, hi = 0;
  209. if (n > 0) {
  210. hi = p[--n];
  211. while (n > 0) {
  212. x = hi;
  213. y = p[--n];
  214. hi = x + y;
  215. lo = y - (hi - x);
  216. if (lo) break;
  217. }
  218. if (n > 0 && ((lo < 0 && p[n - 1] < 0) || (lo > 0 && p[n - 1] > 0))) {
  219. y = lo * 2;
  220. x = hi + y;
  221. if (y == x - hi) hi = x;
  222. }
  223. }
  224. return hi;
  225. }
  226. }
  227. function fsum(values, valueof) {
  228. const adder = new Adder();
  229. if (valueof === undefined) {
  230. for (let value of values) {
  231. if (value = +value) {
  232. adder.add(value);
  233. }
  234. }
  235. } else {
  236. let index = -1;
  237. for (let value of values) {
  238. if (value = +valueof(value, ++index, values)) {
  239. adder.add(value);
  240. }
  241. }
  242. }
  243. return +adder;
  244. }
  245. function identity(x) {
  246. return x;
  247. }
  248. function group(values, ...keys) {
  249. return nest(values, identity, identity, keys);
  250. }
  251. function groups(values, ...keys) {
  252. return nest(values, Array.from, identity, keys);
  253. }
  254. function rollup(values, reduce, ...keys) {
  255. return nest(values, identity, reduce, keys);
  256. }
  257. function rollups(values, reduce, ...keys) {
  258. return nest(values, Array.from, reduce, keys);
  259. }
  260. function index(values, ...keys) {
  261. return nest(values, identity, unique, keys);
  262. }
  263. function indexes(values, ...keys) {
  264. return nest(values, Array.from, unique, keys);
  265. }
  266. function unique(values) {
  267. if (values.length !== 1) throw new Error("duplicate key");
  268. return values[0];
  269. }
  270. function nest(values, map, reduce, keys) {
  271. return (function regroup(values, i) {
  272. if (i >= keys.length) return reduce(values);
  273. const groups = new Map();
  274. const keyof = keys[i++];
  275. let index = -1;
  276. for (const value of values) {
  277. const key = keyof(value, ++index, values);
  278. const group = groups.get(key);
  279. if (group) group.push(value);
  280. else groups.set(key, [value]);
  281. }
  282. for (const [key, values] of groups) {
  283. groups.set(key, regroup(values, i));
  284. }
  285. return map(groups);
  286. })(values, 0);
  287. }
  288. var array = Array.prototype;
  289. var slice = array.slice;
  290. function constant(x) {
  291. return function() {
  292. return x;
  293. };
  294. }
  295. var e10 = Math.sqrt(50),
  296. e5 = Math.sqrt(10),
  297. e2 = Math.sqrt(2);
  298. function ticks(start, stop, count) {
  299. var reverse,
  300. i = -1,
  301. n,
  302. ticks,
  303. step;
  304. stop = +stop, start = +start, count = +count;
  305. if (start === stop && count > 0) return [start];
  306. if (reverse = stop < start) n = start, start = stop, stop = n;
  307. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  308. if (step > 0) {
  309. start = Math.ceil(start / step);
  310. stop = Math.floor(stop / step);
  311. ticks = new Array(n = Math.ceil(stop - start + 1));
  312. while (++i < n) ticks[i] = (start + i) * step;
  313. } else {
  314. step = -step;
  315. start = Math.ceil(start * step);
  316. stop = Math.floor(stop * step);
  317. ticks = new Array(n = Math.ceil(stop - start + 1));
  318. while (++i < n) ticks[i] = (start + i) / step;
  319. }
  320. if (reverse) ticks.reverse();
  321. return ticks;
  322. }
  323. function tickIncrement(start, stop, count) {
  324. var step = (stop - start) / Math.max(0, count),
  325. power = Math.floor(Math.log(step) / Math.LN10),
  326. error = step / Math.pow(10, power);
  327. return power >= 0
  328. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  329. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  330. }
  331. function tickStep(start, stop, count) {
  332. var step0 = Math.abs(stop - start) / Math.max(0, count),
  333. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  334. error = step0 / step1;
  335. if (error >= e10) step1 *= 10;
  336. else if (error >= e5) step1 *= 5;
  337. else if (error >= e2) step1 *= 2;
  338. return stop < start ? -step1 : step1;
  339. }
  340. function nice(start, stop, count) {
  341. let prestep;
  342. while (true) {
  343. const step = tickIncrement(start, stop, count);
  344. if (step === prestep || step === 0 || !isFinite(step)) {
  345. return [start, stop];
  346. } else if (step > 0) {
  347. start = Math.floor(start / step) * step;
  348. stop = Math.ceil(stop / step) * step;
  349. } else if (step < 0) {
  350. start = Math.ceil(start * step) / step;
  351. stop = Math.floor(stop * step) / step;
  352. }
  353. prestep = step;
  354. }
  355. }
  356. function thresholdSturges(values) {
  357. return Math.ceil(Math.log(count(values)) / Math.LN2) + 1;
  358. }
  359. function bin() {
  360. var value = identity,
  361. domain = extent,
  362. threshold = thresholdSturges;
  363. function histogram(data) {
  364. if (!Array.isArray(data)) data = Array.from(data);
  365. var i,
  366. n = data.length,
  367. x,
  368. values = new Array(n);
  369. for (i = 0; i < n; ++i) {
  370. values[i] = value(data[i], i, data);
  371. }
  372. var xz = domain(values),
  373. x0 = xz[0],
  374. x1 = xz[1],
  375. tz = threshold(values, x0, x1);
  376. // Convert number of thresholds into uniform thresholds, and nice the
  377. // default domain accordingly.
  378. if (!Array.isArray(tz)) {
  379. const max = x1, tn = +tz;
  380. if (domain === extent) [x0, x1] = nice(x0, x1, tn);
  381. tz = ticks(x0, x1, tn);
  382. // If the last threshold is coincident with the domain’s upper bound, the
  383. // last bin will be zero-width. If the default domain is used, and this
  384. // last threshold is coincident with the maximum input value, we can
  385. // extend the niced upper bound by one tick to ensure uniform bin widths;
  386. // otherwise, we simply remove the last threshold. Note that we don’t
  387. // coerce values or the domain to numbers, and thus must be careful to
  388. // compare order (>=) rather than strict equality (===)!
  389. if (tz[tz.length - 1] >= x1) {
  390. if (max >= x1 && domain === extent) {
  391. const step = tickIncrement(x0, x1, tn);
  392. if (isFinite(step)) {
  393. if (step > 0) {
  394. x1 = (Math.floor(x1 / step) + 1) * step;
  395. } else if (step < 0) {
  396. x1 = (Math.ceil(x1 * -step) + 1) / -step;
  397. }
  398. }
  399. } else {
  400. tz.pop();
  401. }
  402. }
  403. }
  404. // Remove any thresholds outside the domain.
  405. var m = tz.length;
  406. while (tz[0] <= x0) tz.shift(), --m;
  407. while (tz[m - 1] > x1) tz.pop(), --m;
  408. var bins = new Array(m + 1),
  409. bin;
  410. // Initialize bins.
  411. for (i = 0; i <= m; ++i) {
  412. bin = bins[i] = [];
  413. bin.x0 = i > 0 ? tz[i - 1] : x0;
  414. bin.x1 = i < m ? tz[i] : x1;
  415. }
  416. // Assign data to bins by value, ignoring any outside the domain.
  417. for (i = 0; i < n; ++i) {
  418. x = values[i];
  419. if (x0 <= x && x <= x1) {
  420. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  421. }
  422. }
  423. return bins;
  424. }
  425. histogram.value = function(_) {
  426. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  427. };
  428. histogram.domain = function(_) {
  429. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  430. };
  431. histogram.thresholds = function(_) {
  432. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  433. };
  434. return histogram;
  435. }
  436. function max(values, valueof) {
  437. let max;
  438. if (valueof === undefined) {
  439. for (const value of values) {
  440. if (value != null
  441. && (max < value || (max === undefined && value >= value))) {
  442. max = value;
  443. }
  444. }
  445. } else {
  446. let index = -1;
  447. for (let value of values) {
  448. if ((value = valueof(value, ++index, values)) != null
  449. && (max < value || (max === undefined && value >= value))) {
  450. max = value;
  451. }
  452. }
  453. }
  454. return max;
  455. }
  456. function min(values, valueof) {
  457. let min;
  458. if (valueof === undefined) {
  459. for (const value of values) {
  460. if (value != null
  461. && (min > value || (min === undefined && value >= value))) {
  462. min = value;
  463. }
  464. }
  465. } else {
  466. let index = -1;
  467. for (let value of values) {
  468. if ((value = valueof(value, ++index, values)) != null
  469. && (min > value || (min === undefined && value >= value))) {
  470. min = value;
  471. }
  472. }
  473. }
  474. return min;
  475. }
  476. // Based on https://github.com/mourner/quickselect
  477. // ISC license, Copyright 2018 Vladimir Agafonkin.
  478. function quickselect(array, k, left = 0, right = array.length - 1, compare = ascending) {
  479. while (right > left) {
  480. if (right - left > 600) {
  481. const n = right - left + 1;
  482. const m = k - left + 1;
  483. const z = Math.log(n);
  484. const s = 0.5 * Math.exp(2 * z / 3);
  485. const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  486. const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  487. const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  488. quickselect(array, k, newLeft, newRight, compare);
  489. }
  490. const t = array[k];
  491. let i = left;
  492. let j = right;
  493. swap(array, left, k);
  494. if (compare(array[right], t) > 0) swap(array, left, right);
  495. while (i < j) {
  496. swap(array, i, j), ++i, --j;
  497. while (compare(array[i], t) < 0) ++i;
  498. while (compare(array[j], t) > 0) --j;
  499. }
  500. if (compare(array[left], t) === 0) swap(array, left, j);
  501. else ++j, swap(array, j, right);
  502. if (j <= k) left = j + 1;
  503. if (k <= j) right = j - 1;
  504. }
  505. return array;
  506. }
  507. function swap(array, i, j) {
  508. const t = array[i];
  509. array[i] = array[j];
  510. array[j] = t;
  511. }
  512. function quantile(values, p, valueof) {
  513. values = Float64Array.from(numbers(values, valueof));
  514. if (!(n = values.length)) return;
  515. if ((p = +p) <= 0 || n < 2) return min(values);
  516. if (p >= 1) return max(values);
  517. var n,
  518. i = (n - 1) * p,
  519. i0 = Math.floor(i),
  520. value0 = max(quickselect(values, i0).subarray(0, i0 + 1)),
  521. value1 = min(values.subarray(i0 + 1));
  522. return value0 + (value1 - value0) * (i - i0);
  523. }
  524. function quantileSorted(values, p, valueof = number) {
  525. if (!(n = values.length)) return;
  526. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  527. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  528. var n,
  529. i = (n - 1) * p,
  530. i0 = Math.floor(i),
  531. value0 = +valueof(values[i0], i0, values),
  532. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  533. return value0 + (value1 - value0) * (i - i0);
  534. }
  535. function freedmanDiaconis(values, min, max) {
  536. return Math.ceil((max - min) / (2 * (quantile(values, 0.75) - quantile(values, 0.25)) * Math.pow(count(values), -1 / 3)));
  537. }
  538. function scott(values, min, max) {
  539. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(count(values), -1 / 3)));
  540. }
  541. function maxIndex(values, valueof) {
  542. let max;
  543. let maxIndex = -1;
  544. let index = -1;
  545. if (valueof === undefined) {
  546. for (const value of values) {
  547. ++index;
  548. if (value != null
  549. && (max < value || (max === undefined && value >= value))) {
  550. max = value, maxIndex = index;
  551. }
  552. }
  553. } else {
  554. for (let value of values) {
  555. if ((value = valueof(value, ++index, values)) != null
  556. && (max < value || (max === undefined && value >= value))) {
  557. max = value, maxIndex = index;
  558. }
  559. }
  560. }
  561. return maxIndex;
  562. }
  563. function mean(values, valueof) {
  564. let count = 0;
  565. let sum = 0;
  566. if (valueof === undefined) {
  567. for (let value of values) {
  568. if (value != null && (value = +value) >= value) {
  569. ++count, sum += value;
  570. }
  571. }
  572. } else {
  573. let index = -1;
  574. for (let value of values) {
  575. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  576. ++count, sum += value;
  577. }
  578. }
  579. }
  580. if (count) return sum / count;
  581. }
  582. function median(values, valueof) {
  583. return quantile(values, 0.5, valueof);
  584. }
  585. function* flatten(arrays) {
  586. for (const array of arrays) {
  587. yield* array;
  588. }
  589. }
  590. function merge(arrays) {
  591. return Array.from(flatten(arrays));
  592. }
  593. function minIndex(values, valueof) {
  594. let min;
  595. let minIndex = -1;
  596. let index = -1;
  597. if (valueof === undefined) {
  598. for (const value of values) {
  599. ++index;
  600. if (value != null
  601. && (min > value || (min === undefined && value >= value))) {
  602. min = value, minIndex = index;
  603. }
  604. }
  605. } else {
  606. for (let value of values) {
  607. if ((value = valueof(value, ++index, values)) != null
  608. && (min > value || (min === undefined && value >= value))) {
  609. min = value, minIndex = index;
  610. }
  611. }
  612. }
  613. return minIndex;
  614. }
  615. function pairs(values, pairof = pair) {
  616. const pairs = [];
  617. let previous;
  618. let first = false;
  619. for (const value of values) {
  620. if (first) pairs.push(pairof(previous, value));
  621. previous = value;
  622. first = true;
  623. }
  624. return pairs;
  625. }
  626. function pair(a, b) {
  627. return [a, b];
  628. }
  629. function permute(source, keys) {
  630. return Array.from(keys, key => source[key]);
  631. }
  632. function sequence(start, stop, step) {
  633. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  634. var i = -1,
  635. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  636. range = new Array(n);
  637. while (++i < n) {
  638. range[i] = start + i * step;
  639. }
  640. return range;
  641. }
  642. function least(values, compare = ascending) {
  643. let min;
  644. let defined = false;
  645. if (compare.length === 1) {
  646. let minValue;
  647. for (const element of values) {
  648. const value = compare(element);
  649. if (defined
  650. ? ascending(value, minValue) < 0
  651. : ascending(value, value) === 0) {
  652. min = element;
  653. minValue = value;
  654. defined = true;
  655. }
  656. }
  657. } else {
  658. for (const value of values) {
  659. if (defined
  660. ? compare(value, min) < 0
  661. : compare(value, value) === 0) {
  662. min = value;
  663. defined = true;
  664. }
  665. }
  666. }
  667. return min;
  668. }
  669. function leastIndex(values, compare = ascending) {
  670. if (compare.length === 1) return minIndex(values, compare);
  671. let minValue;
  672. let min = -1;
  673. let index = -1;
  674. for (const value of values) {
  675. ++index;
  676. if (min < 0
  677. ? compare(value, value) === 0
  678. : compare(value, minValue) < 0) {
  679. minValue = value;
  680. min = index;
  681. }
  682. }
  683. return min;
  684. }
  685. function greatest(values, compare = ascending) {
  686. let max;
  687. let defined = false;
  688. if (compare.length === 1) {
  689. let maxValue;
  690. for (const element of values) {
  691. const value = compare(element);
  692. if (defined
  693. ? ascending(value, maxValue) > 0
  694. : ascending(value, value) === 0) {
  695. max = element;
  696. maxValue = value;
  697. defined = true;
  698. }
  699. }
  700. } else {
  701. for (const value of values) {
  702. if (defined
  703. ? compare(value, max) > 0
  704. : compare(value, value) === 0) {
  705. max = value;
  706. defined = true;
  707. }
  708. }
  709. }
  710. return max;
  711. }
  712. function greatestIndex(values, compare = ascending) {
  713. if (compare.length === 1) return maxIndex(values, compare);
  714. let maxValue;
  715. let max = -1;
  716. let index = -1;
  717. for (const value of values) {
  718. ++index;
  719. if (max < 0
  720. ? compare(value, value) === 0
  721. : compare(value, maxValue) > 0) {
  722. maxValue = value;
  723. max = index;
  724. }
  725. }
  726. return max;
  727. }
  728. function scan(values, compare) {
  729. const index = leastIndex(values, compare);
  730. return index < 0 ? undefined : index;
  731. }
  732. var shuffle = shuffler(Math.random);
  733. function shuffler(random) {
  734. return function shuffle(array, i0 = 0, i1 = array.length) {
  735. let m = i1 - (i0 = +i0);
  736. while (m) {
  737. const i = random() * m-- | 0, t = array[m + i0];
  738. array[m + i0] = array[i + i0];
  739. array[i + i0] = t;
  740. }
  741. return array;
  742. };
  743. }
  744. function sum(values, valueof) {
  745. let sum = 0;
  746. if (valueof === undefined) {
  747. for (let value of values) {
  748. if (value = +value) {
  749. sum += value;
  750. }
  751. }
  752. } else {
  753. let index = -1;
  754. for (let value of values) {
  755. if (value = +valueof(value, ++index, values)) {
  756. sum += value;
  757. }
  758. }
  759. }
  760. return sum;
  761. }
  762. function transpose(matrix) {
  763. if (!(n = matrix.length)) return [];
  764. for (var i = -1, m = min(matrix, length$1), transpose = new Array(m); ++i < m;) {
  765. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  766. row[j] = matrix[j][i];
  767. }
  768. }
  769. return transpose;
  770. }
  771. function length$1(d) {
  772. return d.length;
  773. }
  774. function zip() {
  775. return transpose(arguments);
  776. }
  777. function every(values, test) {
  778. if (typeof test !== "function") throw new TypeError("test is not a function");
  779. let index = -1;
  780. for (const value of values) {
  781. if (!test(value, ++index, values)) {
  782. return false;
  783. }
  784. }
  785. return true;
  786. }
  787. function some(values, test) {
  788. if (typeof test !== "function") throw new TypeError("test is not a function");
  789. let index = -1;
  790. for (const value of values) {
  791. if (test(value, ++index, values)) {
  792. return true;
  793. }
  794. }
  795. return false;
  796. }
  797. function filter(values, test) {
  798. if (typeof test !== "function") throw new TypeError("test is not a function");
  799. const array = [];
  800. let index = -1;
  801. for (const value of values) {
  802. if (test(value, ++index, values)) {
  803. array.push(value);
  804. }
  805. }
  806. return array;
  807. }
  808. function map(values, mapper) {
  809. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  810. if (typeof mapper !== "function") throw new TypeError("mapper is not a function");
  811. return Array.from(values, (value, index) => mapper(value, index, values));
  812. }
  813. function reduce(values, reducer, value) {
  814. if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
  815. const iterator = values[Symbol.iterator]();
  816. let done, next, index = -1;
  817. if (arguments.length < 3) {
  818. ({done, value} = iterator.next());
  819. if (done) return;
  820. ++index;
  821. }
  822. while (({done, value: next} = iterator.next()), !done) {
  823. value = reducer(value, next, ++index, values);
  824. }
  825. return value;
  826. }
  827. function reverse(values) {
  828. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  829. return Array.from(values).reverse();
  830. }
  831. function sort(values, f = ascending) {
  832. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  833. values = Array.from(values);
  834. if (f.length === 1) {
  835. f = values.map(f);
  836. return permute(values, values.map((d, i) => i).sort((i, j) => ascending(f[i], f[j])));
  837. }
  838. return values.sort(f);
  839. }
  840. function difference(values, ...others) {
  841. values = new Set(values);
  842. for (const other of others) {
  843. for (const value of other) {
  844. values.delete(value);
  845. }
  846. }
  847. return values;
  848. }
  849. function disjoint(values, other) {
  850. const iterator = other[Symbol.iterator](), set = new Set();
  851. for (const v of values) {
  852. if (set.has(v)) return false;
  853. let value, done;
  854. while (({value, done} = iterator.next())) {
  855. if (done) break;
  856. if (Object.is(v, value)) return false;
  857. set.add(value);
  858. }
  859. }
  860. return true;
  861. }
  862. function set(values) {
  863. return values instanceof Set ? values : new Set(values);
  864. }
  865. function intersection(values, ...others) {
  866. values = new Set(values);
  867. others = others.map(set);
  868. out: for (const value of values) {
  869. for (const other of others) {
  870. if (!other.has(value)) {
  871. values.delete(value);
  872. continue out;
  873. }
  874. }
  875. }
  876. return values;
  877. }
  878. function superset(values, other) {
  879. const iterator = values[Symbol.iterator](), set = new Set();
  880. for (const o of other) {
  881. if (set.has(o)) continue;
  882. let value, done;
  883. while (({value, done} = iterator.next())) {
  884. if (done) return false;
  885. set.add(value);
  886. if (Object.is(o, value)) break;
  887. }
  888. }
  889. return true;
  890. }
  891. function subset(values, other) {
  892. return superset(other, values);
  893. }
  894. function union(...others) {
  895. const set = new Set();
  896. for (const other of others) {
  897. for (const o of other) {
  898. set.add(o);
  899. }
  900. }
  901. return set;
  902. }
  903. var slice$1 = Array.prototype.slice;
  904. function identity$1(x) {
  905. return x;
  906. }
  907. var top = 1,
  908. right = 2,
  909. bottom = 3,
  910. left = 4,
  911. epsilon = 1e-6;
  912. function translateX(x) {
  913. return "translate(" + (x + 0.5) + ",0)";
  914. }
  915. function translateY(y) {
  916. return "translate(0," + (y + 0.5) + ")";
  917. }
  918. function number$1(scale) {
  919. return d => +scale(d);
  920. }
  921. function center(scale) {
  922. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  923. if (scale.round()) offset = Math.round(offset);
  924. return function(d) {
  925. return +scale(d) + offset;
  926. };
  927. }
  928. function entering() {
  929. return !this.__axis;
  930. }
  931. function axis(orient, scale) {
  932. var tickArguments = [],
  933. tickValues = null,
  934. tickFormat = null,
  935. tickSizeInner = 6,
  936. tickSizeOuter = 6,
  937. tickPadding = 3,
  938. k = orient === top || orient === left ? -1 : 1,
  939. x = orient === left || orient === right ? "x" : "y",
  940. transform = orient === top || orient === bottom ? translateX : translateY;
  941. function axis(context) {
  942. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  943. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  944. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  945. range = scale.range(),
  946. range0 = +range[0] + 0.5,
  947. range1 = +range[range.length - 1] + 0.5,
  948. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  949. selection = context.selection ? context.selection() : context,
  950. path = selection.selectAll(".domain").data([null]),
  951. tick = selection.selectAll(".tick").data(values, scale).order(),
  952. tickExit = tick.exit(),
  953. tickEnter = tick.enter().append("g").attr("class", "tick"),
  954. line = tick.select("line"),
  955. text = tick.select("text");
  956. path = path.merge(path.enter().insert("path", ".tick")
  957. .attr("class", "domain")
  958. .attr("stroke", "currentColor"));
  959. tick = tick.merge(tickEnter);
  960. line = line.merge(tickEnter.append("line")
  961. .attr("stroke", "currentColor")
  962. .attr(x + "2", k * tickSizeInner));
  963. text = text.merge(tickEnter.append("text")
  964. .attr("fill", "currentColor")
  965. .attr(x, k * spacing)
  966. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  967. if (context !== selection) {
  968. path = path.transition(context);
  969. tick = tick.transition(context);
  970. line = line.transition(context);
  971. text = text.transition(context);
  972. tickExit = tickExit.transition(context)
  973. .attr("opacity", epsilon)
  974. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  975. tickEnter
  976. .attr("opacity", epsilon)
  977. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  978. }
  979. tickExit.remove();
  980. path
  981. .attr("d", orient === left || orient == right
  982. ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M0.5," + range0 + "V" + range1)
  983. : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + ",0.5H" + range1));
  984. tick
  985. .attr("opacity", 1)
  986. .attr("transform", function(d) { return transform(position(d)); });
  987. line
  988. .attr(x + "2", k * tickSizeInner);
  989. text
  990. .attr(x, k * spacing)
  991. .text(format);
  992. selection.filter(entering)
  993. .attr("fill", "none")
  994. .attr("font-size", 10)
  995. .attr("font-family", "sans-serif")
  996. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  997. selection
  998. .each(function() { this.__axis = position; });
  999. }
  1000. axis.scale = function(_) {
  1001. return arguments.length ? (scale = _, axis) : scale;
  1002. };
  1003. axis.ticks = function() {
  1004. return tickArguments = slice$1.call(arguments), axis;
  1005. };
  1006. axis.tickArguments = function(_) {
  1007. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  1008. };
  1009. axis.tickValues = function(_) {
  1010. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  1011. };
  1012. axis.tickFormat = function(_) {
  1013. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  1014. };
  1015. axis.tickSize = function(_) {
  1016. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  1017. };
  1018. axis.tickSizeInner = function(_) {
  1019. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  1020. };
  1021. axis.tickSizeOuter = function(_) {
  1022. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  1023. };
  1024. axis.tickPadding = function(_) {
  1025. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  1026. };
  1027. return axis;
  1028. }
  1029. function axisTop(scale) {
  1030. return axis(top, scale);
  1031. }
  1032. function axisRight(scale) {
  1033. return axis(right, scale);
  1034. }
  1035. function axisBottom(scale) {
  1036. return axis(bottom, scale);
  1037. }
  1038. function axisLeft(scale) {
  1039. return axis(left, scale);
  1040. }
  1041. var noop = {value: () => {}};
  1042. function dispatch() {
  1043. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  1044. if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
  1045. _[t] = [];
  1046. }
  1047. return new Dispatch(_);
  1048. }
  1049. function Dispatch(_) {
  1050. this._ = _;
  1051. }
  1052. function parseTypenames(typenames, types) {
  1053. return typenames.trim().split(/^|\s+/).map(function(t) {
  1054. var name = "", i = t.indexOf(".");
  1055. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1056. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  1057. return {type: t, name: name};
  1058. });
  1059. }
  1060. Dispatch.prototype = dispatch.prototype = {
  1061. constructor: Dispatch,
  1062. on: function(typename, callback) {
  1063. var _ = this._,
  1064. T = parseTypenames(typename + "", _),
  1065. t,
  1066. i = -1,
  1067. n = T.length;
  1068. // If no callback was specified, return the callback of the given type and name.
  1069. if (arguments.length < 2) {
  1070. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  1071. return;
  1072. }
  1073. // If a type was specified, set the callback for the given type and name.
  1074. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  1075. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  1076. while (++i < n) {
  1077. if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
  1078. else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
  1079. }
  1080. return this;
  1081. },
  1082. copy: function() {
  1083. var copy = {}, _ = this._;
  1084. for (var t in _) copy[t] = _[t].slice();
  1085. return new Dispatch(copy);
  1086. },
  1087. call: function(type, that) {
  1088. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  1089. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  1090. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  1091. },
  1092. apply: function(type, that, args) {
  1093. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  1094. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  1095. }
  1096. };
  1097. function get(type, name) {
  1098. for (var i = 0, n = type.length, c; i < n; ++i) {
  1099. if ((c = type[i]).name === name) {
  1100. return c.value;
  1101. }
  1102. }
  1103. }
  1104. function set$1(type, name, callback) {
  1105. for (var i = 0, n = type.length; i < n; ++i) {
  1106. if (type[i].name === name) {
  1107. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  1108. break;
  1109. }
  1110. }
  1111. if (callback != null) type.push({name: name, value: callback});
  1112. return type;
  1113. }
  1114. var xhtml = "http://www.w3.org/1999/xhtml";
  1115. var namespaces = {
  1116. svg: "http://www.w3.org/2000/svg",
  1117. xhtml: xhtml,
  1118. xlink: "http://www.w3.org/1999/xlink",
  1119. xml: "http://www.w3.org/XML/1998/namespace",
  1120. xmlns: "http://www.w3.org/2000/xmlns/"
  1121. };
  1122. function namespace(name) {
  1123. var prefix = name += "", i = prefix.indexOf(":");
  1124. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  1125. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins
  1126. }
  1127. function creatorInherit(name) {
  1128. return function() {
  1129. var document = this.ownerDocument,
  1130. uri = this.namespaceURI;
  1131. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  1132. ? document.createElement(name)
  1133. : document.createElementNS(uri, name);
  1134. };
  1135. }
  1136. function creatorFixed(fullname) {
  1137. return function() {
  1138. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  1139. };
  1140. }
  1141. function creator(name) {
  1142. var fullname = namespace(name);
  1143. return (fullname.local
  1144. ? creatorFixed
  1145. : creatorInherit)(fullname);
  1146. }
  1147. function none() {}
  1148. function selector(selector) {
  1149. return selector == null ? none : function() {
  1150. return this.querySelector(selector);
  1151. };
  1152. }
  1153. function selection_select(select) {
  1154. if (typeof select !== "function") select = selector(select);
  1155. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  1156. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  1157. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  1158. if ("__data__" in node) subnode.__data__ = node.__data__;
  1159. subgroup[i] = subnode;
  1160. }
  1161. }
  1162. }
  1163. return new Selection(subgroups, this._parents);
  1164. }
  1165. function array$1(x) {
  1166. return typeof x === "object" && "length" in x
  1167. ? x // Array, TypedArray, NodeList, array-like
  1168. : Array.from(x); // Map, Set, iterable, string, or anything else
  1169. }
  1170. function empty$1() {
  1171. return [];
  1172. }
  1173. function selectorAll(selector) {
  1174. return selector == null ? empty$1 : function() {
  1175. return this.querySelectorAll(selector);
  1176. };
  1177. }
  1178. function arrayAll(select) {
  1179. return function() {
  1180. var group = select.apply(this, arguments);
  1181. return group == null ? [] : array$1(group);
  1182. };
  1183. }
  1184. function selection_selectAll(select) {
  1185. if (typeof select === "function") select = arrayAll(select);
  1186. else select = selectorAll(select);
  1187. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  1188. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  1189. if (node = group[i]) {
  1190. subgroups.push(select.call(node, node.__data__, i, group));
  1191. parents.push(node);
  1192. }
  1193. }
  1194. }
  1195. return new Selection(subgroups, parents);
  1196. }
  1197. function matcher(selector) {
  1198. return function() {
  1199. return this.matches(selector);
  1200. };
  1201. }
  1202. function childMatcher(selector) {
  1203. return function(node) {
  1204. return node.matches(selector);
  1205. };
  1206. }
  1207. var find = Array.prototype.find;
  1208. function childFind(match) {
  1209. return function() {
  1210. return find.call(this.children, match);
  1211. };
  1212. }
  1213. function childFirst() {
  1214. return this.firstElementChild;
  1215. }
  1216. function selection_selectChild(match) {
  1217. return this.select(match == null ? childFirst
  1218. : childFind(typeof match === "function" ? match : childMatcher(match)));
  1219. }
  1220. var filter$1 = Array.prototype.filter;
  1221. function children() {
  1222. return this.children;
  1223. }
  1224. function childrenFilter(match) {
  1225. return function() {
  1226. return filter$1.call(this.children, match);
  1227. };
  1228. }
  1229. function selection_selectChildren(match) {
  1230. return this.selectAll(match == null ? children
  1231. : childrenFilter(typeof match === "function" ? match : childMatcher(match)));
  1232. }
  1233. function selection_filter(match) {
  1234. if (typeof match !== "function") match = matcher(match);
  1235. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  1236. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  1237. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  1238. subgroup.push(node);
  1239. }
  1240. }
  1241. }
  1242. return new Selection(subgroups, this._parents);
  1243. }
  1244. function sparse(update) {
  1245. return new Array(update.length);
  1246. }
  1247. function selection_enter() {
  1248. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  1249. }
  1250. function EnterNode(parent, datum) {
  1251. this.ownerDocument = parent.ownerDocument;
  1252. this.namespaceURI = parent.namespaceURI;
  1253. this._next = null;
  1254. this._parent = parent;
  1255. this.__data__ = datum;
  1256. }
  1257. EnterNode.prototype = {
  1258. constructor: EnterNode,
  1259. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  1260. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  1261. querySelector: function(selector) { return this._parent.querySelector(selector); },
  1262. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  1263. };
  1264. function constant$1(x) {
  1265. return function() {
  1266. return x;
  1267. };
  1268. }
  1269. function bindIndex(parent, group, enter, update, exit, data) {
  1270. var i = 0,
  1271. node,
  1272. groupLength = group.length,
  1273. dataLength = data.length;
  1274. // Put any non-null nodes that fit into update.
  1275. // Put any null nodes into enter.
  1276. // Put any remaining data into enter.
  1277. for (; i < dataLength; ++i) {
  1278. if (node = group[i]) {
  1279. node.__data__ = data[i];
  1280. update[i] = node;
  1281. } else {
  1282. enter[i] = new EnterNode(parent, data[i]);
  1283. }
  1284. }
  1285. // Put any non-null nodes that don’t fit into exit.
  1286. for (; i < groupLength; ++i) {
  1287. if (node = group[i]) {
  1288. exit[i] = node;
  1289. }
  1290. }
  1291. }
  1292. function bindKey(parent, group, enter, update, exit, data, key) {
  1293. var i,
  1294. node,
  1295. nodeByKeyValue = new Map,
  1296. groupLength = group.length,
  1297. dataLength = data.length,
  1298. keyValues = new Array(groupLength),
  1299. keyValue;
  1300. // Compute the key for each node.
  1301. // If multiple nodes have the same key, the duplicates are added to exit.
  1302. for (i = 0; i < groupLength; ++i) {
  1303. if (node = group[i]) {
  1304. keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
  1305. if (nodeByKeyValue.has(keyValue)) {
  1306. exit[i] = node;
  1307. } else {
  1308. nodeByKeyValue.set(keyValue, node);
  1309. }
  1310. }
  1311. }
  1312. // Compute the key for each datum.
  1313. // If there a node associated with this key, join and add it to update.
  1314. // If there is not (or the key is a duplicate), add it to enter.
  1315. for (i = 0; i < dataLength; ++i) {
  1316. keyValue = key.call(parent, data[i], i, data) + "";
  1317. if (node = nodeByKeyValue.get(keyValue)) {
  1318. update[i] = node;
  1319. node.__data__ = data[i];
  1320. nodeByKeyValue.delete(keyValue);
  1321. } else {
  1322. enter[i] = new EnterNode(parent, data[i]);
  1323. }
  1324. }
  1325. // Add any remaining nodes that were not bound to data to exit.
  1326. for (i = 0; i < groupLength; ++i) {
  1327. if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) {
  1328. exit[i] = node;
  1329. }
  1330. }
  1331. }
  1332. function datum(node) {
  1333. return node.__data__;
  1334. }
  1335. function selection_data(value, key) {
  1336. if (!arguments.length) return Array.from(this, datum);
  1337. var bind = key ? bindKey : bindIndex,
  1338. parents = this._parents,
  1339. groups = this._groups;
  1340. if (typeof value !== "function") value = constant$1(value);
  1341. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  1342. var parent = parents[j],
  1343. group = groups[j],
  1344. groupLength = group.length,
  1345. data = array$1(value.call(parent, parent && parent.__data__, j, parents)),
  1346. dataLength = data.length,
  1347. enterGroup = enter[j] = new Array(dataLength),
  1348. updateGroup = update[j] = new Array(dataLength),
  1349. exitGroup = exit[j] = new Array(groupLength);
  1350. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  1351. // Now connect the enter nodes to their following update node, such that
  1352. // appendChild can insert the materialized enter node before this node,
  1353. // rather than at the end of the parent node.
  1354. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  1355. if (previous = enterGroup[i0]) {
  1356. if (i0 >= i1) i1 = i0 + 1;
  1357. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  1358. previous._next = next || null;
  1359. }
  1360. }
  1361. }
  1362. update = new Selection(update, parents);
  1363. update._enter = enter;
  1364. update._exit = exit;
  1365. return update;
  1366. }
  1367. function selection_exit() {
  1368. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  1369. }
  1370. function selection_join(onenter, onupdate, onexit) {
  1371. var enter = this.enter(), update = this, exit = this.exit();
  1372. enter = typeof onenter === "function" ? onenter(enter) : enter.append(onenter + "");
  1373. if (onupdate != null) update = onupdate(update);
  1374. if (onexit == null) exit.remove(); else onexit(exit);
  1375. return enter && update ? enter.merge(update).order() : update;
  1376. }
  1377. function selection_merge(selection) {
  1378. if (!(selection instanceof Selection)) throw new Error("invalid merge");
  1379. 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) {
  1380. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  1381. if (node = group0[i] || group1[i]) {
  1382. merge[i] = node;
  1383. }
  1384. }
  1385. }
  1386. for (; j < m0; ++j) {
  1387. merges[j] = groups0[j];
  1388. }
  1389. return new Selection(merges, this._parents);
  1390. }
  1391. function selection_order() {
  1392. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  1393. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  1394. if (node = group[i]) {
  1395. if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
  1396. next = node;
  1397. }
  1398. }
  1399. }
  1400. return this;
  1401. }
  1402. function selection_sort(compare) {
  1403. if (!compare) compare = ascending$1;
  1404. function compareNode(a, b) {
  1405. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  1406. }
  1407. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  1408. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  1409. if (node = group[i]) {
  1410. sortgroup[i] = node;
  1411. }
  1412. }
  1413. sortgroup.sort(compareNode);
  1414. }
  1415. return new Selection(sortgroups, this._parents).order();
  1416. }
  1417. function ascending$1(a, b) {
  1418. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  1419. }
  1420. function selection_call() {
  1421. var callback = arguments[0];
  1422. arguments[0] = this;
  1423. callback.apply(null, arguments);
  1424. return this;
  1425. }
  1426. function selection_nodes() {
  1427. return Array.from(this);
  1428. }
  1429. function selection_node() {
  1430. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1431. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  1432. var node = group[i];
  1433. if (node) return node;
  1434. }
  1435. }
  1436. return null;
  1437. }
  1438. function selection_size() {
  1439. let size = 0;
  1440. for (const node of this) ++size; // eslint-disable-line no-unused-vars
  1441. return size;
  1442. }
  1443. function selection_empty() {
  1444. return !this.node();
  1445. }
  1446. function selection_each(callback) {
  1447. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1448. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  1449. if (node = group[i]) callback.call(node, node.__data__, i, group);
  1450. }
  1451. }
  1452. return this;
  1453. }
  1454. function attrRemove(name) {
  1455. return function() {
  1456. this.removeAttribute(name);
  1457. };
  1458. }
  1459. function attrRemoveNS(fullname) {
  1460. return function() {
  1461. this.removeAttributeNS(fullname.space, fullname.local);
  1462. };
  1463. }
  1464. function attrConstant(name, value) {
  1465. return function() {
  1466. this.setAttribute(name, value);
  1467. };
  1468. }
  1469. function attrConstantNS(fullname, value) {
  1470. return function() {
  1471. this.setAttributeNS(fullname.space, fullname.local, value);
  1472. };
  1473. }
  1474. function attrFunction(name, value) {
  1475. return function() {
  1476. var v = value.apply(this, arguments);
  1477. if (v == null) this.removeAttribute(name);
  1478. else this.setAttribute(name, v);
  1479. };
  1480. }
  1481. function attrFunctionNS(fullname, value) {
  1482. return function() {
  1483. var v = value.apply(this, arguments);
  1484. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1485. else this.setAttributeNS(fullname.space, fullname.local, v);
  1486. };
  1487. }
  1488. function selection_attr(name, value) {
  1489. var fullname = namespace(name);
  1490. if (arguments.length < 2) {
  1491. var node = this.node();
  1492. return fullname.local
  1493. ? node.getAttributeNS(fullname.space, fullname.local)
  1494. : node.getAttribute(fullname);
  1495. }
  1496. return this.each((value == null
  1497. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1498. ? (fullname.local ? attrFunctionNS : attrFunction)
  1499. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1500. }
  1501. function defaultView(node) {
  1502. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1503. || (node.document && node) // node is a Window
  1504. || node.defaultView; // node is a Document
  1505. }
  1506. function styleRemove(name) {
  1507. return function() {
  1508. this.style.removeProperty(name);
  1509. };
  1510. }
  1511. function styleConstant(name, value, priority) {
  1512. return function() {
  1513. this.style.setProperty(name, value, priority);
  1514. };
  1515. }
  1516. function styleFunction(name, value, priority) {
  1517. return function() {
  1518. var v = value.apply(this, arguments);
  1519. if (v == null) this.style.removeProperty(name);
  1520. else this.style.setProperty(name, v, priority);
  1521. };
  1522. }
  1523. function selection_style(name, value, priority) {
  1524. return arguments.length > 1
  1525. ? this.each((value == null
  1526. ? styleRemove : typeof value === "function"
  1527. ? styleFunction
  1528. : styleConstant)(name, value, priority == null ? "" : priority))
  1529. : styleValue(this.node(), name);
  1530. }
  1531. function styleValue(node, name) {
  1532. return node.style.getPropertyValue(name)
  1533. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1534. }
  1535. function propertyRemove(name) {
  1536. return function() {
  1537. delete this[name];
  1538. };
  1539. }
  1540. function propertyConstant(name, value) {
  1541. return function() {
  1542. this[name] = value;
  1543. };
  1544. }
  1545. function propertyFunction(name, value) {
  1546. return function() {
  1547. var v = value.apply(this, arguments);
  1548. if (v == null) delete this[name];
  1549. else this[name] = v;
  1550. };
  1551. }
  1552. function selection_property(name, value) {
  1553. return arguments.length > 1
  1554. ? this.each((value == null
  1555. ? propertyRemove : typeof value === "function"
  1556. ? propertyFunction
  1557. : propertyConstant)(name, value))
  1558. : this.node()[name];
  1559. }
  1560. function classArray(string) {
  1561. return string.trim().split(/^|\s+/);
  1562. }
  1563. function classList(node) {
  1564. return node.classList || new ClassList(node);
  1565. }
  1566. function ClassList(node) {
  1567. this._node = node;
  1568. this._names = classArray(node.getAttribute("class") || "");
  1569. }
  1570. ClassList.prototype = {
  1571. add: function(name) {
  1572. var i = this._names.indexOf(name);
  1573. if (i < 0) {
  1574. this._names.push(name);
  1575. this._node.setAttribute("class", this._names.join(" "));
  1576. }
  1577. },
  1578. remove: function(name) {
  1579. var i = this._names.indexOf(name);
  1580. if (i >= 0) {
  1581. this._names.splice(i, 1);
  1582. this._node.setAttribute("class", this._names.join(" "));
  1583. }
  1584. },
  1585. contains: function(name) {
  1586. return this._names.indexOf(name) >= 0;
  1587. }
  1588. };
  1589. function classedAdd(node, names) {
  1590. var list = classList(node), i = -1, n = names.length;
  1591. while (++i < n) list.add(names[i]);
  1592. }
  1593. function classedRemove(node, names) {
  1594. var list = classList(node), i = -1, n = names.length;
  1595. while (++i < n) list.remove(names[i]);
  1596. }
  1597. function classedTrue(names) {
  1598. return function() {
  1599. classedAdd(this, names);
  1600. };
  1601. }
  1602. function classedFalse(names) {
  1603. return function() {
  1604. classedRemove(this, names);
  1605. };
  1606. }
  1607. function classedFunction(names, value) {
  1608. return function() {
  1609. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1610. };
  1611. }
  1612. function selection_classed(name, value) {
  1613. var names = classArray(name + "");
  1614. if (arguments.length < 2) {
  1615. var list = classList(this.node()), i = -1, n = names.length;
  1616. while (++i < n) if (!list.contains(names[i])) return false;
  1617. return true;
  1618. }
  1619. return this.each((typeof value === "function"
  1620. ? classedFunction : value
  1621. ? classedTrue
  1622. : classedFalse)(names, value));
  1623. }
  1624. function textRemove() {
  1625. this.textContent = "";
  1626. }
  1627. function textConstant(value) {
  1628. return function() {
  1629. this.textContent = value;
  1630. };
  1631. }
  1632. function textFunction(value) {
  1633. return function() {
  1634. var v = value.apply(this, arguments);
  1635. this.textContent = v == null ? "" : v;
  1636. };
  1637. }
  1638. function selection_text(value) {
  1639. return arguments.length
  1640. ? this.each(value == null
  1641. ? textRemove : (typeof value === "function"
  1642. ? textFunction
  1643. : textConstant)(value))
  1644. : this.node().textContent;
  1645. }
  1646. function htmlRemove() {
  1647. this.innerHTML = "";
  1648. }
  1649. function htmlConstant(value) {
  1650. return function() {
  1651. this.innerHTML = value;
  1652. };
  1653. }
  1654. function htmlFunction(value) {
  1655. return function() {
  1656. var v = value.apply(this, arguments);
  1657. this.innerHTML = v == null ? "" : v;
  1658. };
  1659. }
  1660. function selection_html(value) {
  1661. return arguments.length
  1662. ? this.each(value == null
  1663. ? htmlRemove : (typeof value === "function"
  1664. ? htmlFunction
  1665. : htmlConstant)(value))
  1666. : this.node().innerHTML;
  1667. }
  1668. function raise() {
  1669. if (this.nextSibling) this.parentNode.appendChild(this);
  1670. }
  1671. function selection_raise() {
  1672. return this.each(raise);
  1673. }
  1674. function lower() {
  1675. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1676. }
  1677. function selection_lower() {
  1678. return this.each(lower);
  1679. }
  1680. function selection_append(name) {
  1681. var create = typeof name === "function" ? name : creator(name);
  1682. return this.select(function() {
  1683. return this.appendChild(create.apply(this, arguments));
  1684. });
  1685. }
  1686. function constantNull() {
  1687. return null;
  1688. }
  1689. function selection_insert(name, before) {
  1690. var create = typeof name === "function" ? name : creator(name),
  1691. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1692. return this.select(function() {
  1693. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1694. });
  1695. }
  1696. function remove() {
  1697. var parent = this.parentNode;
  1698. if (parent) parent.removeChild(this);
  1699. }
  1700. function selection_remove() {
  1701. return this.each(remove);
  1702. }
  1703. function selection_cloneShallow() {
  1704. var clone = this.cloneNode(false), parent = this.parentNode;
  1705. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  1706. }
  1707. function selection_cloneDeep() {
  1708. var clone = this.cloneNode(true), parent = this.parentNode;
  1709. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  1710. }
  1711. function selection_clone(deep) {
  1712. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  1713. }
  1714. function selection_datum(value) {
  1715. return arguments.length
  1716. ? this.property("__data__", value)
  1717. : this.node().__data__;
  1718. }
  1719. function contextListener(listener) {
  1720. return function(event) {
  1721. listener.call(this, event, this.__data__);
  1722. };
  1723. }
  1724. function parseTypenames$1(typenames) {
  1725. return typenames.trim().split(/^|\s+/).map(function(t) {
  1726. var name = "", i = t.indexOf(".");
  1727. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1728. return {type: t, name: name};
  1729. });
  1730. }
  1731. function onRemove(typename) {
  1732. return function() {
  1733. var on = this.__on;
  1734. if (!on) return;
  1735. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  1736. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  1737. this.removeEventListener(o.type, o.listener, o.options);
  1738. } else {
  1739. on[++i] = o;
  1740. }
  1741. }
  1742. if (++i) on.length = i;
  1743. else delete this.__on;
  1744. };
  1745. }
  1746. function onAdd(typename, value, options) {
  1747. return function() {
  1748. var on = this.__on, o, listener = contextListener(value);
  1749. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  1750. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  1751. this.removeEventListener(o.type, o.listener, o.options);
  1752. this.addEventListener(o.type, o.listener = listener, o.options = options);
  1753. o.value = value;
  1754. return;
  1755. }
  1756. }
  1757. this.addEventListener(typename.type, listener, options);
  1758. o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options};
  1759. if (!on) this.__on = [o];
  1760. else on.push(o);
  1761. };
  1762. }
  1763. function selection_on(typename, value, options) {
  1764. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  1765. if (arguments.length < 2) {
  1766. var on = this.node().__on;
  1767. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  1768. for (i = 0, o = on[j]; i < n; ++i) {
  1769. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  1770. return o.value;
  1771. }
  1772. }
  1773. }
  1774. return;
  1775. }
  1776. on = value ? onAdd : onRemove;
  1777. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options));
  1778. return this;
  1779. }
  1780. function dispatchEvent(node, type, params) {
  1781. var window = defaultView(node),
  1782. event = window.CustomEvent;
  1783. if (typeof event === "function") {
  1784. event = new event(type, params);
  1785. } else {
  1786. event = window.document.createEvent("Event");
  1787. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1788. else event.initEvent(type, false, false);
  1789. }
  1790. node.dispatchEvent(event);
  1791. }
  1792. function dispatchConstant(type, params) {
  1793. return function() {
  1794. return dispatchEvent(this, type, params);
  1795. };
  1796. }
  1797. function dispatchFunction(type, params) {
  1798. return function() {
  1799. return dispatchEvent(this, type, params.apply(this, arguments));
  1800. };
  1801. }
  1802. function selection_dispatch(type, params) {
  1803. return this.each((typeof params === "function"
  1804. ? dispatchFunction
  1805. : dispatchConstant)(type, params));
  1806. }
  1807. function* selection_iterator() {
  1808. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1809. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  1810. if (node = group[i]) yield node;
  1811. }
  1812. }
  1813. }
  1814. var root = [null];
  1815. function Selection(groups, parents) {
  1816. this._groups = groups;
  1817. this._parents = parents;
  1818. }
  1819. function selection() {
  1820. return new Selection([[document.documentElement]], root);
  1821. }
  1822. function selection_selection() {
  1823. return this;
  1824. }
  1825. Selection.prototype = selection.prototype = {
  1826. constructor: Selection,
  1827. select: selection_select,
  1828. selectAll: selection_selectAll,
  1829. selectChild: selection_selectChild,
  1830. selectChildren: selection_selectChildren,
  1831. filter: selection_filter,
  1832. data: selection_data,
  1833. enter: selection_enter,
  1834. exit: selection_exit,
  1835. join: selection_join,
  1836. merge: selection_merge,
  1837. selection: selection_selection,
  1838. order: selection_order,
  1839. sort: selection_sort,
  1840. call: selection_call,
  1841. nodes: selection_nodes,
  1842. node: selection_node,
  1843. size: selection_size,
  1844. empty: selection_empty,
  1845. each: selection_each,
  1846. attr: selection_attr,
  1847. style: selection_style,
  1848. property: selection_property,
  1849. classed: selection_classed,
  1850. text: selection_text,
  1851. html: selection_html,
  1852. raise: selection_raise,
  1853. lower: selection_lower,
  1854. append: selection_append,
  1855. insert: selection_insert,
  1856. remove: selection_remove,
  1857. clone: selection_clone,
  1858. datum: selection_datum,
  1859. on: selection_on,
  1860. dispatch: selection_dispatch,
  1861. [Symbol.iterator]: selection_iterator
  1862. };
  1863. function select(selector) {
  1864. return typeof selector === "string"
  1865. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1866. : new Selection([[selector]], root);
  1867. }
  1868. function create(name) {
  1869. return select(creator(name).call(document.documentElement));
  1870. }
  1871. var nextId = 0;
  1872. function local() {
  1873. return new Local;
  1874. }
  1875. function Local() {
  1876. this._ = "@" + (++nextId).toString(36);
  1877. }
  1878. Local.prototype = local.prototype = {
  1879. constructor: Local,
  1880. get: function(node) {
  1881. var id = this._;
  1882. while (!(id in node)) if (!(node = node.parentNode)) return;
  1883. return node[id];
  1884. },
  1885. set: function(node, value) {
  1886. return node[this._] = value;
  1887. },
  1888. remove: function(node) {
  1889. return this._ in node && delete node[this._];
  1890. },
  1891. toString: function() {
  1892. return this._;
  1893. }
  1894. };
  1895. function sourceEvent(event) {
  1896. let sourceEvent;
  1897. while (sourceEvent = event.sourceEvent) event = sourceEvent;
  1898. return event;
  1899. }
  1900. function pointer(event, node) {
  1901. event = sourceEvent(event);
  1902. if (node === undefined) node = event.currentTarget;
  1903. if (node) {
  1904. var svg = node.ownerSVGElement || node;
  1905. if (svg.createSVGPoint) {
  1906. var point = svg.createSVGPoint();
  1907. point.x = event.clientX, point.y = event.clientY;
  1908. point = point.matrixTransform(node.getScreenCTM().inverse());
  1909. return [point.x, point.y];
  1910. }
  1911. if (node.getBoundingClientRect) {
  1912. var rect = node.getBoundingClientRect();
  1913. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  1914. }
  1915. }
  1916. return [event.pageX, event.pageY];
  1917. }
  1918. function pointers(events, node) {
  1919. if (events.target) { // i.e., instanceof Event, not TouchList or iterable
  1920. events = sourceEvent(events);
  1921. if (node === undefined) node = events.currentTarget;
  1922. events = events.touches || [events];
  1923. }
  1924. return Array.from(events, event => pointer(event, node));
  1925. }
  1926. function selectAll(selector) {
  1927. return typeof selector === "string"
  1928. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1929. : new Selection([selector == null ? [] : array$1(selector)], root);
  1930. }
  1931. function nopropagation(event) {
  1932. event.stopImmediatePropagation();
  1933. }
  1934. function noevent(event) {
  1935. event.preventDefault();
  1936. event.stopImmediatePropagation();
  1937. }
  1938. function dragDisable(view) {
  1939. var root = view.document.documentElement,
  1940. selection = select(view).on("dragstart.drag", noevent, true);
  1941. if ("onselectstart" in root) {
  1942. selection.on("selectstart.drag", noevent, true);
  1943. } else {
  1944. root.__noselect = root.style.MozUserSelect;
  1945. root.style.MozUserSelect = "none";
  1946. }
  1947. }
  1948. function yesdrag(view, noclick) {
  1949. var root = view.document.documentElement,
  1950. selection = select(view).on("dragstart.drag", null);
  1951. if (noclick) {
  1952. selection.on("click.drag", noevent, true);
  1953. setTimeout(function() { selection.on("click.drag", null); }, 0);
  1954. }
  1955. if ("onselectstart" in root) {
  1956. selection.on("selectstart.drag", null);
  1957. } else {
  1958. root.style.MozUserSelect = root.__noselect;
  1959. delete root.__noselect;
  1960. }
  1961. }
  1962. var constant$2 = x => () => x;
  1963. function DragEvent(type, {
  1964. sourceEvent,
  1965. subject,
  1966. target,
  1967. identifier,
  1968. active,
  1969. x, y, dx, dy,
  1970. dispatch
  1971. }) {
  1972. Object.defineProperties(this, {
  1973. type: {value: type, enumerable: true, configurable: true},
  1974. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  1975. subject: {value: subject, enumerable: true, configurable: true},
  1976. target: {value: target, enumerable: true, configurable: true},
  1977. identifier: {value: identifier, enumerable: true, configurable: true},
  1978. active: {value: active, enumerable: true, configurable: true},
  1979. x: {value: x, enumerable: true, configurable: true},
  1980. y: {value: y, enumerable: true, configurable: true},
  1981. dx: {value: dx, enumerable: true, configurable: true},
  1982. dy: {value: dy, enumerable: true, configurable: true},
  1983. _: {value: dispatch}
  1984. });
  1985. }
  1986. DragEvent.prototype.on = function() {
  1987. var value = this._.on.apply(this._, arguments);
  1988. return value === this._ ? this : value;
  1989. };
  1990. // Ignore right-click, since that should open the context menu.
  1991. function defaultFilter(event) {
  1992. return !event.ctrlKey && !event.button;
  1993. }
  1994. function defaultContainer() {
  1995. return this.parentNode;
  1996. }
  1997. function defaultSubject(event, d) {
  1998. return d == null ? {x: event.x, y: event.y} : d;
  1999. }
  2000. function defaultTouchable() {
  2001. return navigator.maxTouchPoints || ("ontouchstart" in this);
  2002. }
  2003. function drag() {
  2004. var filter = defaultFilter,
  2005. container = defaultContainer,
  2006. subject = defaultSubject,
  2007. touchable = defaultTouchable,
  2008. gestures = {},
  2009. listeners = dispatch("start", "drag", "end"),
  2010. active = 0,
  2011. mousedownx,
  2012. mousedowny,
  2013. mousemoving,
  2014. touchending,
  2015. clickDistance2 = 0;
  2016. function drag(selection) {
  2017. selection
  2018. .on("mousedown.drag", mousedowned)
  2019. .filter(touchable)
  2020. .on("touchstart.drag", touchstarted)
  2021. .on("touchmove.drag", touchmoved)
  2022. .on("touchend.drag touchcancel.drag", touchended)
  2023. .style("touch-action", "none")
  2024. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  2025. }
  2026. function mousedowned(event, d) {
  2027. if (touchending || !filter.call(this, event, d)) return;
  2028. var gesture = beforestart(this, container.call(this, event, d), event, d, "mouse");
  2029. if (!gesture) return;
  2030. select(event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  2031. dragDisable(event.view);
  2032. nopropagation(event);
  2033. mousemoving = false;
  2034. mousedownx = event.clientX;
  2035. mousedowny = event.clientY;
  2036. gesture("start", event);
  2037. }
  2038. function mousemoved(event) {
  2039. noevent(event);
  2040. if (!mousemoving) {
  2041. var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
  2042. mousemoving = dx * dx + dy * dy > clickDistance2;
  2043. }
  2044. gestures.mouse("drag", event);
  2045. }
  2046. function mouseupped(event) {
  2047. select(event.view).on("mousemove.drag mouseup.drag", null);
  2048. yesdrag(event.view, mousemoving);
  2049. noevent(event);
  2050. gestures.mouse("end", event);
  2051. }
  2052. function touchstarted(event, d) {
  2053. if (!filter.call(this, event, d)) return;
  2054. var touches = event.changedTouches,
  2055. c = container.call(this, event, d),
  2056. n = touches.length, i, gesture;
  2057. for (i = 0; i < n; ++i) {
  2058. if (gesture = beforestart(this, c, event, d, touches[i].identifier, touches[i])) {
  2059. nopropagation(event);
  2060. gesture("start", event, touches[i]);
  2061. }
  2062. }
  2063. }
  2064. function touchmoved(event) {
  2065. var touches = event.changedTouches,
  2066. n = touches.length, i, gesture;
  2067. for (i = 0; i < n; ++i) {
  2068. if (gesture = gestures[touches[i].identifier]) {
  2069. noevent(event);
  2070. gesture("drag", event, touches[i]);
  2071. }
  2072. }
  2073. }
  2074. function touchended(event) {
  2075. var touches = event.changedTouches,
  2076. n = touches.length, i, gesture;
  2077. if (touchending) clearTimeout(touchending);
  2078. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  2079. for (i = 0; i < n; ++i) {
  2080. if (gesture = gestures[touches[i].identifier]) {
  2081. nopropagation(event);
  2082. gesture("end", event, touches[i]);
  2083. }
  2084. }
  2085. }
  2086. function beforestart(that, container, event, d, identifier, touch) {
  2087. var dispatch = listeners.copy(),
  2088. p = pointer(touch || event, container), dx, dy,
  2089. s;
  2090. if ((s = subject.call(that, new DragEvent("beforestart", {
  2091. sourceEvent: event,
  2092. target: drag,
  2093. identifier,
  2094. active,
  2095. x: p[0],
  2096. y: p[1],
  2097. dx: 0,
  2098. dy: 0,
  2099. dispatch
  2100. }), d)) == null) return;
  2101. dx = s.x - p[0] || 0;
  2102. dy = s.y - p[1] || 0;
  2103. return function gesture(type, event, touch) {
  2104. var p0 = p, n;
  2105. switch (type) {
  2106. case "start": gestures[identifier] = gesture, n = active++; break;
  2107. case "end": delete gestures[identifier], --active; // nobreak
  2108. case "drag": p = pointer(touch || event, container), n = active; break;
  2109. }
  2110. dispatch.call(
  2111. type,
  2112. that,
  2113. new DragEvent(type, {
  2114. sourceEvent: event,
  2115. subject: s,
  2116. target: drag,
  2117. identifier,
  2118. active: n,
  2119. x: p[0] + dx,
  2120. y: p[1] + dy,
  2121. dx: p[0] - p0[0],
  2122. dy: p[1] - p0[1],
  2123. dispatch
  2124. }),
  2125. d
  2126. );
  2127. };
  2128. }
  2129. drag.filter = function(_) {
  2130. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  2131. };
  2132. drag.container = function(_) {
  2133. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  2134. };
  2135. drag.subject = function(_) {
  2136. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  2137. };
  2138. drag.touchable = function(_) {
  2139. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  2140. };
  2141. drag.on = function() {
  2142. var value = listeners.on.apply(listeners, arguments);
  2143. return value === listeners ? drag : value;
  2144. };
  2145. drag.clickDistance = function(_) {
  2146. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  2147. };
  2148. return drag;
  2149. }
  2150. function define(constructor, factory, prototype) {
  2151. constructor.prototype = factory.prototype = prototype;
  2152. prototype.constructor = constructor;
  2153. }
  2154. function extend(parent, definition) {
  2155. var prototype = Object.create(parent.prototype);
  2156. for (var key in definition) prototype[key] = definition[key];
  2157. return prototype;
  2158. }
  2159. function Color() {}
  2160. var darker = 0.7;
  2161. var brighter = 1 / darker;
  2162. var reI = "\\s*([+-]?\\d+)\\s*",
  2163. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  2164. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  2165. reHex = /^#([0-9a-f]{3,8})$/,
  2166. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  2167. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  2168. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  2169. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  2170. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  2171. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  2172. var named = {
  2173. aliceblue: 0xf0f8ff,
  2174. antiquewhite: 0xfaebd7,
  2175. aqua: 0x00ffff,
  2176. aquamarine: 0x7fffd4,
  2177. azure: 0xf0ffff,
  2178. beige: 0xf5f5dc,
  2179. bisque: 0xffe4c4,
  2180. black: 0x000000,
  2181. blanchedalmond: 0xffebcd,
  2182. blue: 0x0000ff,
  2183. blueviolet: 0x8a2be2,
  2184. brown: 0xa52a2a,
  2185. burlywood: 0xdeb887,
  2186. cadetblue: 0x5f9ea0,
  2187. chartreuse: 0x7fff00,
  2188. chocolate: 0xd2691e,
  2189. coral: 0xff7f50,
  2190. cornflowerblue: 0x6495ed,
  2191. cornsilk: 0xfff8dc,
  2192. crimson: 0xdc143c,
  2193. cyan: 0x00ffff,
  2194. darkblue: 0x00008b,
  2195. darkcyan: 0x008b8b,
  2196. darkgoldenrod: 0xb8860b,
  2197. darkgray: 0xa9a9a9,
  2198. darkgreen: 0x006400,
  2199. darkgrey: 0xa9a9a9,
  2200. darkkhaki: 0xbdb76b,
  2201. darkmagenta: 0x8b008b,
  2202. darkolivegreen: 0x556b2f,
  2203. darkorange: 0xff8c00,
  2204. darkorchid: 0x9932cc,
  2205. darkred: 0x8b0000,
  2206. darksalmon: 0xe9967a,
  2207. darkseagreen: 0x8fbc8f,
  2208. darkslateblue: 0x483d8b,
  2209. darkslategray: 0x2f4f4f,
  2210. darkslategrey: 0x2f4f4f,
  2211. darkturquoise: 0x00ced1,
  2212. darkviolet: 0x9400d3,
  2213. deeppink: 0xff1493,
  2214. deepskyblue: 0x00bfff,
  2215. dimgray: 0x696969,
  2216. dimgrey: 0x696969,
  2217. dodgerblue: 0x1e90ff,
  2218. firebrick: 0xb22222,
  2219. floralwhite: 0xfffaf0,
  2220. forestgreen: 0x228b22,
  2221. fuchsia: 0xff00ff,
  2222. gainsboro: 0xdcdcdc,
  2223. ghostwhite: 0xf8f8ff,
  2224. gold: 0xffd700,
  2225. goldenrod: 0xdaa520,
  2226. gray: 0x808080,
  2227. green: 0x008000,
  2228. greenyellow: 0xadff2f,
  2229. grey: 0x808080,
  2230. honeydew: 0xf0fff0,
  2231. hotpink: 0xff69b4,
  2232. indianred: 0xcd5c5c,
  2233. indigo: 0x4b0082,
  2234. ivory: 0xfffff0,
  2235. khaki: 0xf0e68c,
  2236. lavender: 0xe6e6fa,
  2237. lavenderblush: 0xfff0f5,
  2238. lawngreen: 0x7cfc00,
  2239. lemonchiffon: 0xfffacd,
  2240. lightblue: 0xadd8e6,
  2241. lightcoral: 0xf08080,
  2242. lightcyan: 0xe0ffff,
  2243. lightgoldenrodyellow: 0xfafad2,
  2244. lightgray: 0xd3d3d3,
  2245. lightgreen: 0x90ee90,
  2246. lightgrey: 0xd3d3d3,
  2247. lightpink: 0xffb6c1,
  2248. lightsalmon: 0xffa07a,
  2249. lightseagreen: 0x20b2aa,
  2250. lightskyblue: 0x87cefa,
  2251. lightslategray: 0x778899,
  2252. lightslategrey: 0x778899,
  2253. lightsteelblue: 0xb0c4de,
  2254. lightyellow: 0xffffe0,
  2255. lime: 0x00ff00,
  2256. limegreen: 0x32cd32,
  2257. linen: 0xfaf0e6,
  2258. magenta: 0xff00ff,
  2259. maroon: 0x800000,
  2260. mediumaquamarine: 0x66cdaa,
  2261. mediumblue: 0x0000cd,
  2262. mediumorchid: 0xba55d3,
  2263. mediumpurple: 0x9370db,
  2264. mediumseagreen: 0x3cb371,
  2265. mediumslateblue: 0x7b68ee,
  2266. mediumspringgreen: 0x00fa9a,
  2267. mediumturquoise: 0x48d1cc,
  2268. mediumvioletred: 0xc71585,
  2269. midnightblue: 0x191970,
  2270. mintcream: 0xf5fffa,
  2271. mistyrose: 0xffe4e1,
  2272. moccasin: 0xffe4b5,
  2273. navajowhite: 0xffdead,
  2274. navy: 0x000080,
  2275. oldlace: 0xfdf5e6,
  2276. olive: 0x808000,
  2277. olivedrab: 0x6b8e23,
  2278. orange: 0xffa500,
  2279. orangered: 0xff4500,
  2280. orchid: 0xda70d6,
  2281. palegoldenrod: 0xeee8aa,
  2282. palegreen: 0x98fb98,
  2283. paleturquoise: 0xafeeee,
  2284. palevioletred: 0xdb7093,
  2285. papayawhip: 0xffefd5,
  2286. peachpuff: 0xffdab9,
  2287. peru: 0xcd853f,
  2288. pink: 0xffc0cb,
  2289. plum: 0xdda0dd,
  2290. powderblue: 0xb0e0e6,
  2291. purple: 0x800080,
  2292. rebeccapurple: 0x663399,
  2293. red: 0xff0000,
  2294. rosybrown: 0xbc8f8f,
  2295. royalblue: 0x4169e1,
  2296. saddlebrown: 0x8b4513,
  2297. salmon: 0xfa8072,
  2298. sandybrown: 0xf4a460,
  2299. seagreen: 0x2e8b57,
  2300. seashell: 0xfff5ee,
  2301. sienna: 0xa0522d,
  2302. silver: 0xc0c0c0,
  2303. skyblue: 0x87ceeb,
  2304. slateblue: 0x6a5acd,
  2305. slategray: 0x708090,
  2306. slategrey: 0x708090,
  2307. snow: 0xfffafa,
  2308. springgreen: 0x00ff7f,
  2309. steelblue: 0x4682b4,
  2310. tan: 0xd2b48c,
  2311. teal: 0x008080,
  2312. thistle: 0xd8bfd8,
  2313. tomato: 0xff6347,
  2314. turquoise: 0x40e0d0,
  2315. violet: 0xee82ee,
  2316. wheat: 0xf5deb3,
  2317. white: 0xffffff,
  2318. whitesmoke: 0xf5f5f5,
  2319. yellow: 0xffff00,
  2320. yellowgreen: 0x9acd32
  2321. };
  2322. define(Color, color, {
  2323. copy: function(channels) {
  2324. return Object.assign(new this.constructor, this, channels);
  2325. },
  2326. displayable: function() {
  2327. return this.rgb().displayable();
  2328. },
  2329. hex: color_formatHex, // Deprecated! Use color.formatHex.
  2330. formatHex: color_formatHex,
  2331. formatHsl: color_formatHsl,
  2332. formatRgb: color_formatRgb,
  2333. toString: color_formatRgb
  2334. });
  2335. function color_formatHex() {
  2336. return this.rgb().formatHex();
  2337. }
  2338. function color_formatHsl() {
  2339. return hslConvert(this).formatHsl();
  2340. }
  2341. function color_formatRgb() {
  2342. return this.rgb().formatRgb();
  2343. }
  2344. function color(format) {
  2345. var m, l;
  2346. format = (format + "").trim().toLowerCase();
  2347. return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
  2348. : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
  2349. : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
  2350. : 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
  2351. : null) // invalid hex
  2352. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  2353. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  2354. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  2355. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  2356. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  2357. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  2358. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  2359. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  2360. : null;
  2361. }
  2362. function rgbn(n) {
  2363. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  2364. }
  2365. function rgba(r, g, b, a) {
  2366. if (a <= 0) r = g = b = NaN;
  2367. return new Rgb(r, g, b, a);
  2368. }
  2369. function rgbConvert(o) {
  2370. if (!(o instanceof Color)) o = color(o);
  2371. if (!o) return new Rgb;
  2372. o = o.rgb();
  2373. return new Rgb(o.r, o.g, o.b, o.opacity);
  2374. }
  2375. function rgb(r, g, b, opacity) {
  2376. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  2377. }
  2378. function Rgb(r, g, b, opacity) {
  2379. this.r = +r;
  2380. this.g = +g;
  2381. this.b = +b;
  2382. this.opacity = +opacity;
  2383. }
  2384. define(Rgb, rgb, extend(Color, {
  2385. brighter: function(k) {
  2386. k = k == null ? brighter : Math.pow(brighter, k);
  2387. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  2388. },
  2389. darker: function(k) {
  2390. k = k == null ? darker : Math.pow(darker, k);
  2391. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  2392. },
  2393. rgb: function() {
  2394. return this;
  2395. },
  2396. displayable: function() {
  2397. return (-0.5 <= this.r && this.r < 255.5)
  2398. && (-0.5 <= this.g && this.g < 255.5)
  2399. && (-0.5 <= this.b && this.b < 255.5)
  2400. && (0 <= this.opacity && this.opacity <= 1);
  2401. },
  2402. hex: rgb_formatHex, // Deprecated! Use color.formatHex.
  2403. formatHex: rgb_formatHex,
  2404. formatRgb: rgb_formatRgb,
  2405. toString: rgb_formatRgb
  2406. }));
  2407. function rgb_formatHex() {
  2408. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  2409. }
  2410. function rgb_formatRgb() {
  2411. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  2412. return (a === 1 ? "rgb(" : "rgba(")
  2413. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  2414. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  2415. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  2416. + (a === 1 ? ")" : ", " + a + ")");
  2417. }
  2418. function hex(value) {
  2419. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  2420. return (value < 16 ? "0" : "") + value.toString(16);
  2421. }
  2422. function hsla(h, s, l, a) {
  2423. if (a <= 0) h = s = l = NaN;
  2424. else if (l <= 0 || l >= 1) h = s = NaN;
  2425. else if (s <= 0) h = NaN;
  2426. return new Hsl(h, s, l, a);
  2427. }
  2428. function hslConvert(o) {
  2429. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  2430. if (!(o instanceof Color)) o = color(o);
  2431. if (!o) return new Hsl;
  2432. if (o instanceof Hsl) return o;
  2433. o = o.rgb();
  2434. var r = o.r / 255,
  2435. g = o.g / 255,
  2436. b = o.b / 255,
  2437. min = Math.min(r, g, b),
  2438. max = Math.max(r, g, b),
  2439. h = NaN,
  2440. s = max - min,
  2441. l = (max + min) / 2;
  2442. if (s) {
  2443. if (r === max) h = (g - b) / s + (g < b) * 6;
  2444. else if (g === max) h = (b - r) / s + 2;
  2445. else h = (r - g) / s + 4;
  2446. s /= l < 0.5 ? max + min : 2 - max - min;
  2447. h *= 60;
  2448. } else {
  2449. s = l > 0 && l < 1 ? 0 : h;
  2450. }
  2451. return new Hsl(h, s, l, o.opacity);
  2452. }
  2453. function hsl(h, s, l, opacity) {
  2454. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  2455. }
  2456. function Hsl(h, s, l, opacity) {
  2457. this.h = +h;
  2458. this.s = +s;
  2459. this.l = +l;
  2460. this.opacity = +opacity;
  2461. }
  2462. define(Hsl, hsl, extend(Color, {
  2463. brighter: function(k) {
  2464. k = k == null ? brighter : Math.pow(brighter, k);
  2465. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  2466. },
  2467. darker: function(k) {
  2468. k = k == null ? darker : Math.pow(darker, k);
  2469. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  2470. },
  2471. rgb: function() {
  2472. var h = this.h % 360 + (this.h < 0) * 360,
  2473. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  2474. l = this.l,
  2475. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  2476. m1 = 2 * l - m2;
  2477. return new Rgb(
  2478. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  2479. hsl2rgb(h, m1, m2),
  2480. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  2481. this.opacity
  2482. );
  2483. },
  2484. displayable: function() {
  2485. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  2486. && (0 <= this.l && this.l <= 1)
  2487. && (0 <= this.opacity && this.opacity <= 1);
  2488. },
  2489. formatHsl: function() {
  2490. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  2491. return (a === 1 ? "hsl(" : "hsla(")
  2492. + (this.h || 0) + ", "
  2493. + (this.s || 0) * 100 + "%, "
  2494. + (this.l || 0) * 100 + "%"
  2495. + (a === 1 ? ")" : ", " + a + ")");
  2496. }
  2497. }));
  2498. /* From FvD 13.37, CSS Color Module Level 3 */
  2499. function hsl2rgb(h, m1, m2) {
  2500. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2501. : h < 180 ? m2
  2502. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2503. : m1) * 255;
  2504. }
  2505. const radians = Math.PI / 180;
  2506. const degrees = 180 / Math.PI;
  2507. // https://observablehq.com/@mbostock/lab-and-rgb
  2508. const K = 18,
  2509. Xn = 0.96422,
  2510. Yn = 1,
  2511. Zn = 0.82521,
  2512. t0 = 4 / 29,
  2513. t1 = 6 / 29,
  2514. t2 = 3 * t1 * t1,
  2515. t3 = t1 * t1 * t1;
  2516. function labConvert(o) {
  2517. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2518. if (o instanceof Hcl) return hcl2lab(o);
  2519. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2520. var r = rgb2lrgb(o.r),
  2521. g = rgb2lrgb(o.g),
  2522. b = rgb2lrgb(o.b),
  2523. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2524. if (r === g && g === b) x = z = y; else {
  2525. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2526. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2527. }
  2528. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2529. }
  2530. function gray(l, opacity) {
  2531. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2532. }
  2533. function lab(l, a, b, opacity) {
  2534. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2535. }
  2536. function Lab(l, a, b, opacity) {
  2537. this.l = +l;
  2538. this.a = +a;
  2539. this.b = +b;
  2540. this.opacity = +opacity;
  2541. }
  2542. define(Lab, lab, extend(Color, {
  2543. brighter: function(k) {
  2544. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2545. },
  2546. darker: function(k) {
  2547. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2548. },
  2549. rgb: function() {
  2550. var y = (this.l + 16) / 116,
  2551. x = isNaN(this.a) ? y : y + this.a / 500,
  2552. z = isNaN(this.b) ? y : y - this.b / 200;
  2553. x = Xn * lab2xyz(x);
  2554. y = Yn * lab2xyz(y);
  2555. z = Zn * lab2xyz(z);
  2556. return new Rgb(
  2557. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2558. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2559. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2560. this.opacity
  2561. );
  2562. }
  2563. }));
  2564. function xyz2lab(t) {
  2565. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2566. }
  2567. function lab2xyz(t) {
  2568. return t > t1 ? t * t * t : t2 * (t - t0);
  2569. }
  2570. function lrgb2rgb(x) {
  2571. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2572. }
  2573. function rgb2lrgb(x) {
  2574. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2575. }
  2576. function hclConvert(o) {
  2577. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2578. if (!(o instanceof Lab)) o = labConvert(o);
  2579. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
  2580. var h = Math.atan2(o.b, o.a) * degrees;
  2581. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2582. }
  2583. function lch(l, c, h, opacity) {
  2584. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2585. }
  2586. function hcl(h, c, l, opacity) {
  2587. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2588. }
  2589. function Hcl(h, c, l, opacity) {
  2590. this.h = +h;
  2591. this.c = +c;
  2592. this.l = +l;
  2593. this.opacity = +opacity;
  2594. }
  2595. function hcl2lab(o) {
  2596. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2597. var h = o.h * radians;
  2598. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2599. }
  2600. define(Hcl, hcl, extend(Color, {
  2601. brighter: function(k) {
  2602. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2603. },
  2604. darker: function(k) {
  2605. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2606. },
  2607. rgb: function() {
  2608. return hcl2lab(this).rgb();
  2609. }
  2610. }));
  2611. var A = -0.14861,
  2612. B = +1.78277,
  2613. C = -0.29227,
  2614. D = -0.90649,
  2615. E = +1.97294,
  2616. ED = E * D,
  2617. EB = E * B,
  2618. BC_DA = B * C - D * A;
  2619. function cubehelixConvert(o) {
  2620. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2621. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2622. var r = o.r / 255,
  2623. g = o.g / 255,
  2624. b = o.b / 255,
  2625. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2626. bl = b - l,
  2627. k = (E * (g - l) - C * bl) / D,
  2628. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2629. h = s ? Math.atan2(k, bl) * degrees - 120 : NaN;
  2630. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2631. }
  2632. function cubehelix(h, s, l, opacity) {
  2633. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2634. }
  2635. function Cubehelix(h, s, l, opacity) {
  2636. this.h = +h;
  2637. this.s = +s;
  2638. this.l = +l;
  2639. this.opacity = +opacity;
  2640. }
  2641. define(Cubehelix, cubehelix, extend(Color, {
  2642. brighter: function(k) {
  2643. k = k == null ? brighter : Math.pow(brighter, k);
  2644. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2645. },
  2646. darker: function(k) {
  2647. k = k == null ? darker : Math.pow(darker, k);
  2648. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2649. },
  2650. rgb: function() {
  2651. var h = isNaN(this.h) ? 0 : (this.h + 120) * radians,
  2652. l = +this.l,
  2653. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2654. cosh = Math.cos(h),
  2655. sinh = Math.sin(h);
  2656. return new Rgb(
  2657. 255 * (l + a * (A * cosh + B * sinh)),
  2658. 255 * (l + a * (C * cosh + D * sinh)),
  2659. 255 * (l + a * (E * cosh)),
  2660. this.opacity
  2661. );
  2662. }
  2663. }));
  2664. function basis(t1, v0, v1, v2, v3) {
  2665. var t2 = t1 * t1, t3 = t2 * t1;
  2666. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2667. + (4 - 6 * t2 + 3 * t3) * v1
  2668. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2669. + t3 * v3) / 6;
  2670. }
  2671. function basis$1(values) {
  2672. var n = values.length - 1;
  2673. return function(t) {
  2674. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2675. v1 = values[i],
  2676. v2 = values[i + 1],
  2677. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2678. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2679. return basis((t - i / n) * n, v0, v1, v2, v3);
  2680. };
  2681. }
  2682. function basisClosed(values) {
  2683. var n = values.length;
  2684. return function(t) {
  2685. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2686. v0 = values[(i + n - 1) % n],
  2687. v1 = values[i % n],
  2688. v2 = values[(i + 1) % n],
  2689. v3 = values[(i + 2) % n];
  2690. return basis((t - i / n) * n, v0, v1, v2, v3);
  2691. };
  2692. }
  2693. var constant$3 = x => () => x;
  2694. function linear(a, d) {
  2695. return function(t) {
  2696. return a + t * d;
  2697. };
  2698. }
  2699. function exponential(a, b, y) {
  2700. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2701. return Math.pow(a + t * b, y);
  2702. };
  2703. }
  2704. function hue(a, b) {
  2705. var d = b - a;
  2706. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2707. }
  2708. function gamma(y) {
  2709. return (y = +y) === 1 ? nogamma : function(a, b) {
  2710. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2711. };
  2712. }
  2713. function nogamma(a, b) {
  2714. var d = b - a;
  2715. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2716. }
  2717. var interpolateRgb = (function rgbGamma(y) {
  2718. var color = gamma(y);
  2719. function rgb$1(start, end) {
  2720. var r = color((start = rgb(start)).r, (end = rgb(end)).r),
  2721. g = color(start.g, end.g),
  2722. b = color(start.b, end.b),
  2723. opacity = nogamma(start.opacity, end.opacity);
  2724. return function(t) {
  2725. start.r = r(t);
  2726. start.g = g(t);
  2727. start.b = b(t);
  2728. start.opacity = opacity(t);
  2729. return start + "";
  2730. };
  2731. }
  2732. rgb$1.gamma = rgbGamma;
  2733. return rgb$1;
  2734. })(1);
  2735. function rgbSpline(spline) {
  2736. return function(colors) {
  2737. var n = colors.length,
  2738. r = new Array(n),
  2739. g = new Array(n),
  2740. b = new Array(n),
  2741. i, color;
  2742. for (i = 0; i < n; ++i) {
  2743. color = rgb(colors[i]);
  2744. r[i] = color.r || 0;
  2745. g[i] = color.g || 0;
  2746. b[i] = color.b || 0;
  2747. }
  2748. r = spline(r);
  2749. g = spline(g);
  2750. b = spline(b);
  2751. color.opacity = 1;
  2752. return function(t) {
  2753. color.r = r(t);
  2754. color.g = g(t);
  2755. color.b = b(t);
  2756. return color + "";
  2757. };
  2758. };
  2759. }
  2760. var rgbBasis = rgbSpline(basis$1);
  2761. var rgbBasisClosed = rgbSpline(basisClosed);
  2762. function numberArray(a, b) {
  2763. if (!b) b = [];
  2764. var n = a ? Math.min(b.length, a.length) : 0,
  2765. c = b.slice(),
  2766. i;
  2767. return function(t) {
  2768. for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
  2769. return c;
  2770. };
  2771. }
  2772. function isNumberArray(x) {
  2773. return ArrayBuffer.isView(x) && !(x instanceof DataView);
  2774. }
  2775. function array$2(a, b) {
  2776. return (isNumberArray(b) ? numberArray : genericArray)(a, b);
  2777. }
  2778. function genericArray(a, b) {
  2779. var nb = b ? b.length : 0,
  2780. na = a ? Math.min(nb, a.length) : 0,
  2781. x = new Array(na),
  2782. c = new Array(nb),
  2783. i;
  2784. for (i = 0; i < na; ++i) x[i] = interpolate(a[i], b[i]);
  2785. for (; i < nb; ++i) c[i] = b[i];
  2786. return function(t) {
  2787. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2788. return c;
  2789. };
  2790. }
  2791. function date(a, b) {
  2792. var d = new Date;
  2793. return a = +a, b = +b, function(t) {
  2794. return d.setTime(a * (1 - t) + b * t), d;
  2795. };
  2796. }
  2797. function interpolateNumber(a, b) {
  2798. return a = +a, b = +b, function(t) {
  2799. return a * (1 - t) + b * t;
  2800. };
  2801. }
  2802. function object(a, b) {
  2803. var i = {},
  2804. c = {},
  2805. k;
  2806. if (a === null || typeof a !== "object") a = {};
  2807. if (b === null || typeof b !== "object") b = {};
  2808. for (k in b) {
  2809. if (k in a) {
  2810. i[k] = interpolate(a[k], b[k]);
  2811. } else {
  2812. c[k] = b[k];
  2813. }
  2814. }
  2815. return function(t) {
  2816. for (k in i) c[k] = i[k](t);
  2817. return c;
  2818. };
  2819. }
  2820. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  2821. reB = new RegExp(reA.source, "g");
  2822. function zero(b) {
  2823. return function() {
  2824. return b;
  2825. };
  2826. }
  2827. function one(b) {
  2828. return function(t) {
  2829. return b(t) + "";
  2830. };
  2831. }
  2832. function interpolateString(a, b) {
  2833. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2834. am, // current match in a
  2835. bm, // current match in b
  2836. bs, // string preceding current number in b, if any
  2837. i = -1, // index in s
  2838. s = [], // string constants and placeholders
  2839. q = []; // number interpolators
  2840. // Coerce inputs to strings.
  2841. a = a + "", b = b + "";
  2842. // Interpolate pairs of numbers in a & b.
  2843. while ((am = reA.exec(a))
  2844. && (bm = reB.exec(b))) {
  2845. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2846. bs = b.slice(bi, bs);
  2847. if (s[i]) s[i] += bs; // coalesce with previous string
  2848. else s[++i] = bs;
  2849. }
  2850. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2851. if (s[i]) s[i] += bm; // coalesce with previous string
  2852. else s[++i] = bm;
  2853. } else { // interpolate non-matching numbers
  2854. s[++i] = null;
  2855. q.push({i: i, x: interpolateNumber(am, bm)});
  2856. }
  2857. bi = reB.lastIndex;
  2858. }
  2859. // Add remains of b.
  2860. if (bi < b.length) {
  2861. bs = b.slice(bi);
  2862. if (s[i]) s[i] += bs; // coalesce with previous string
  2863. else s[++i] = bs;
  2864. }
  2865. // Special optimization for only a single match.
  2866. // Otherwise, interpolate each of the numbers and rejoin the string.
  2867. return s.length < 2 ? (q[0]
  2868. ? one(q[0].x)
  2869. : zero(b))
  2870. : (b = q.length, function(t) {
  2871. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2872. return s.join("");
  2873. });
  2874. }
  2875. function interpolate(a, b) {
  2876. var t = typeof b, c;
  2877. return b == null || t === "boolean" ? constant$3(b)
  2878. : (t === "number" ? interpolateNumber
  2879. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2880. : b instanceof color ? interpolateRgb
  2881. : b instanceof Date ? date
  2882. : isNumberArray(b) ? numberArray
  2883. : Array.isArray(b) ? genericArray
  2884. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2885. : interpolateNumber)(a, b);
  2886. }
  2887. function discrete(range) {
  2888. var n = range.length;
  2889. return function(t) {
  2890. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  2891. };
  2892. }
  2893. function hue$1(a, b) {
  2894. var i = hue(+a, +b);
  2895. return function(t) {
  2896. var x = i(t);
  2897. return x - 360 * Math.floor(x / 360);
  2898. };
  2899. }
  2900. function interpolateRound(a, b) {
  2901. return a = +a, b = +b, function(t) {
  2902. return Math.round(a * (1 - t) + b * t);
  2903. };
  2904. }
  2905. var degrees$1 = 180 / Math.PI;
  2906. var identity$2 = {
  2907. translateX: 0,
  2908. translateY: 0,
  2909. rotate: 0,
  2910. skewX: 0,
  2911. scaleX: 1,
  2912. scaleY: 1
  2913. };
  2914. function decompose(a, b, c, d, e, f) {
  2915. var scaleX, scaleY, skewX;
  2916. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2917. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2918. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2919. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2920. return {
  2921. translateX: e,
  2922. translateY: f,
  2923. rotate: Math.atan2(b, a) * degrees$1,
  2924. skewX: Math.atan(skewX) * degrees$1,
  2925. scaleX: scaleX,
  2926. scaleY: scaleY
  2927. };
  2928. }
  2929. var svgNode;
  2930. /* eslint-disable no-undef */
  2931. function parseCss(value) {
  2932. const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
  2933. return m.isIdentity ? identity$2 : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
  2934. }
  2935. function parseSvg(value) {
  2936. if (value == null) return identity$2;
  2937. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2938. svgNode.setAttribute("transform", value);
  2939. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2940. value = value.matrix;
  2941. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2942. }
  2943. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2944. function pop(s) {
  2945. return s.length ? s.pop() + " " : "";
  2946. }
  2947. function translate(xa, ya, xb, yb, s, q) {
  2948. if (xa !== xb || ya !== yb) {
  2949. var i = s.push("translate(", null, pxComma, null, pxParen);
  2950. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2951. } else if (xb || yb) {
  2952. s.push("translate(" + xb + pxComma + yb + pxParen);
  2953. }
  2954. }
  2955. function rotate(a, b, s, q) {
  2956. if (a !== b) {
  2957. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2958. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2959. } else if (b) {
  2960. s.push(pop(s) + "rotate(" + b + degParen);
  2961. }
  2962. }
  2963. function skewX(a, b, s, q) {
  2964. if (a !== b) {
  2965. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2966. } else if (b) {
  2967. s.push(pop(s) + "skewX(" + b + degParen);
  2968. }
  2969. }
  2970. function scale(xa, ya, xb, yb, s, q) {
  2971. if (xa !== xb || ya !== yb) {
  2972. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2973. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2974. } else if (xb !== 1 || yb !== 1) {
  2975. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2976. }
  2977. }
  2978. return function(a, b) {
  2979. var s = [], // string constants and placeholders
  2980. q = []; // number interpolators
  2981. a = parse(a), b = parse(b);
  2982. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2983. rotate(a.rotate, b.rotate, s, q);
  2984. skewX(a.skewX, b.skewX, s, q);
  2985. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2986. a = b = null; // gc
  2987. return function(t) {
  2988. var i = -1, n = q.length, o;
  2989. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2990. return s.join("");
  2991. };
  2992. };
  2993. }
  2994. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2995. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2996. var epsilon2 = 1e-12;
  2997. function cosh(x) {
  2998. return ((x = Math.exp(x)) + 1 / x) / 2;
  2999. }
  3000. function sinh(x) {
  3001. return ((x = Math.exp(x)) - 1 / x) / 2;
  3002. }
  3003. function tanh(x) {
  3004. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  3005. }
  3006. var interpolateZoom = (function zoomRho(rho, rho2, rho4) {
  3007. // p0 = [ux0, uy0, w0]
  3008. // p1 = [ux1, uy1, w1]
  3009. function zoom(p0, p1) {
  3010. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  3011. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  3012. dx = ux1 - ux0,
  3013. dy = uy1 - uy0,
  3014. d2 = dx * dx + dy * dy,
  3015. i,
  3016. S;
  3017. // Special case for u0 ≅ u1.
  3018. if (d2 < epsilon2) {
  3019. S = Math.log(w1 / w0) / rho;
  3020. i = function(t) {
  3021. return [
  3022. ux0 + t * dx,
  3023. uy0 + t * dy,
  3024. w0 * Math.exp(rho * t * S)
  3025. ];
  3026. };
  3027. }
  3028. // General case.
  3029. else {
  3030. var d1 = Math.sqrt(d2),
  3031. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  3032. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  3033. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  3034. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  3035. S = (r1 - r0) / rho;
  3036. i = function(t) {
  3037. var s = t * S,
  3038. coshr0 = cosh(r0),
  3039. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  3040. return [
  3041. ux0 + u * dx,
  3042. uy0 + u * dy,
  3043. w0 * coshr0 / cosh(rho * s + r0)
  3044. ];
  3045. };
  3046. }
  3047. i.duration = S * 1000 * rho / Math.SQRT2;
  3048. return i;
  3049. }
  3050. zoom.rho = function(_) {
  3051. var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
  3052. return zoomRho(_1, _2, _4);
  3053. };
  3054. return zoom;
  3055. })(Math.SQRT2, 2, 4);
  3056. function hsl$1(hue) {
  3057. return function(start, end) {
  3058. var h = hue((start = hsl(start)).h, (end = hsl(end)).h),
  3059. s = nogamma(start.s, end.s),
  3060. l = nogamma(start.l, end.l),
  3061. opacity = nogamma(start.opacity, end.opacity);
  3062. return function(t) {
  3063. start.h = h(t);
  3064. start.s = s(t);
  3065. start.l = l(t);
  3066. start.opacity = opacity(t);
  3067. return start + "";
  3068. };
  3069. }
  3070. }
  3071. var hsl$2 = hsl$1(hue);
  3072. var hslLong = hsl$1(nogamma);
  3073. function lab$1(start, end) {
  3074. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  3075. a = nogamma(start.a, end.a),
  3076. b = nogamma(start.b, end.b),
  3077. opacity = nogamma(start.opacity, end.opacity);
  3078. return function(t) {
  3079. start.l = l(t);
  3080. start.a = a(t);
  3081. start.b = b(t);
  3082. start.opacity = opacity(t);
  3083. return start + "";
  3084. };
  3085. }
  3086. function hcl$1(hue) {
  3087. return function(start, end) {
  3088. var h = hue((start = hcl(start)).h, (end = hcl(end)).h),
  3089. c = nogamma(start.c, end.c),
  3090. l = nogamma(start.l, end.l),
  3091. opacity = nogamma(start.opacity, end.opacity);
  3092. return function(t) {
  3093. start.h = h(t);
  3094. start.c = c(t);
  3095. start.l = l(t);
  3096. start.opacity = opacity(t);
  3097. return start + "";
  3098. };
  3099. }
  3100. }
  3101. var hcl$2 = hcl$1(hue);
  3102. var hclLong = hcl$1(nogamma);
  3103. function cubehelix$1(hue) {
  3104. return (function cubehelixGamma(y) {
  3105. y = +y;
  3106. function cubehelix$1(start, end) {
  3107. var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  3108. s = nogamma(start.s, end.s),
  3109. l = nogamma(start.l, end.l),
  3110. opacity = nogamma(start.opacity, end.opacity);
  3111. return function(t) {
  3112. start.h = h(t);
  3113. start.s = s(t);
  3114. start.l = l(Math.pow(t, y));
  3115. start.opacity = opacity(t);
  3116. return start + "";
  3117. };
  3118. }
  3119. cubehelix$1.gamma = cubehelixGamma;
  3120. return cubehelix$1;
  3121. })(1);
  3122. }
  3123. var cubehelix$2 = cubehelix$1(hue);
  3124. var cubehelixLong = cubehelix$1(nogamma);
  3125. function piecewise(interpolate$1, values) {
  3126. if (values === undefined) values = interpolate$1, interpolate$1 = interpolate;
  3127. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  3128. while (i < n) I[i] = interpolate$1(v, v = values[++i]);
  3129. return function(t) {
  3130. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  3131. return I[i](t - i);
  3132. };
  3133. }
  3134. function quantize(interpolator, n) {
  3135. var samples = new Array(n);
  3136. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  3137. return samples;
  3138. }
  3139. var frame = 0, // is an animation frame pending?
  3140. timeout = 0, // is a timeout pending?
  3141. interval = 0, // are any timers active?
  3142. pokeDelay = 1000, // how frequently we check for clock skew
  3143. taskHead,
  3144. taskTail,
  3145. clockLast = 0,
  3146. clockNow = 0,
  3147. clockSkew = 0,
  3148. clock = typeof performance === "object" && performance.now ? performance : Date,
  3149. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  3150. function now() {
  3151. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  3152. }
  3153. function clearNow() {
  3154. clockNow = 0;
  3155. }
  3156. function Timer() {
  3157. this._call =
  3158. this._time =
  3159. this._next = null;
  3160. }
  3161. Timer.prototype = timer.prototype = {
  3162. constructor: Timer,
  3163. restart: function(callback, delay, time) {
  3164. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  3165. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  3166. if (!this._next && taskTail !== this) {
  3167. if (taskTail) taskTail._next = this;
  3168. else taskHead = this;
  3169. taskTail = this;
  3170. }
  3171. this._call = callback;
  3172. this._time = time;
  3173. sleep();
  3174. },
  3175. stop: function() {
  3176. if (this._call) {
  3177. this._call = null;
  3178. this._time = Infinity;
  3179. sleep();
  3180. }
  3181. }
  3182. };
  3183. function timer(callback, delay, time) {
  3184. var t = new Timer;
  3185. t.restart(callback, delay, time);
  3186. return t;
  3187. }
  3188. function timerFlush() {
  3189. now(); // Get the current time, if not already set.
  3190. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  3191. var t = taskHead, e;
  3192. while (t) {
  3193. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  3194. t = t._next;
  3195. }
  3196. --frame;
  3197. }
  3198. function wake() {
  3199. clockNow = (clockLast = clock.now()) + clockSkew;
  3200. frame = timeout = 0;
  3201. try {
  3202. timerFlush();
  3203. } finally {
  3204. frame = 0;
  3205. nap();
  3206. clockNow = 0;
  3207. }
  3208. }
  3209. function poke() {
  3210. var now = clock.now(), delay = now - clockLast;
  3211. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  3212. }
  3213. function nap() {
  3214. var t0, t1 = taskHead, t2, time = Infinity;
  3215. while (t1) {
  3216. if (t1._call) {
  3217. if (time > t1._time) time = t1._time;
  3218. t0 = t1, t1 = t1._next;
  3219. } else {
  3220. t2 = t1._next, t1._next = null;
  3221. t1 = t0 ? t0._next = t2 : taskHead = t2;
  3222. }
  3223. }
  3224. taskTail = t0;
  3225. sleep(time);
  3226. }
  3227. function sleep(time) {
  3228. if (frame) return; // Soonest alarm already set, or will be.
  3229. if (timeout) timeout = clearTimeout(timeout);
  3230. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  3231. if (delay > 24) {
  3232. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  3233. if (interval) interval = clearInterval(interval);
  3234. } else {
  3235. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  3236. frame = 1, setFrame(wake);
  3237. }
  3238. }
  3239. function timeout$1(callback, delay, time) {
  3240. var t = new Timer;
  3241. delay = delay == null ? 0 : +delay;
  3242. t.restart(elapsed => {
  3243. t.stop();
  3244. callback(elapsed + delay);
  3245. }, delay, time);
  3246. return t;
  3247. }
  3248. function interval$1(callback, delay, time) {
  3249. var t = new Timer, total = delay;
  3250. if (delay == null) return t.restart(callback, delay, time), t;
  3251. t._restart = t.restart;
  3252. t.restart = function(callback, delay, time) {
  3253. delay = +delay, time = time == null ? now() : +time;
  3254. t._restart(function tick(elapsed) {
  3255. elapsed += total;
  3256. t._restart(tick, total += delay, time);
  3257. callback(elapsed);
  3258. }, delay, time);
  3259. };
  3260. t.restart(callback, delay, time);
  3261. return t;
  3262. }
  3263. var emptyOn = dispatch("start", "end", "cancel", "interrupt");
  3264. var emptyTween = [];
  3265. var CREATED = 0;
  3266. var SCHEDULED = 1;
  3267. var STARTING = 2;
  3268. var STARTED = 3;
  3269. var RUNNING = 4;
  3270. var ENDING = 5;
  3271. var ENDED = 6;
  3272. function schedule(node, name, id, index, group, timing) {
  3273. var schedules = node.__transition;
  3274. if (!schedules) node.__transition = {};
  3275. else if (id in schedules) return;
  3276. create$1(node, id, {
  3277. name: name,
  3278. index: index, // For context during callback.
  3279. group: group, // For context during callback.
  3280. on: emptyOn,
  3281. tween: emptyTween,
  3282. time: timing.time,
  3283. delay: timing.delay,
  3284. duration: timing.duration,
  3285. ease: timing.ease,
  3286. timer: null,
  3287. state: CREATED
  3288. });
  3289. }
  3290. function init(node, id) {
  3291. var schedule = get$1(node, id);
  3292. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  3293. return schedule;
  3294. }
  3295. function set$2(node, id) {
  3296. var schedule = get$1(node, id);
  3297. if (schedule.state > STARTED) throw new Error("too late; already running");
  3298. return schedule;
  3299. }
  3300. function get$1(node, id) {
  3301. var schedule = node.__transition;
  3302. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  3303. return schedule;
  3304. }
  3305. function create$1(node, id, self) {
  3306. var schedules = node.__transition,
  3307. tween;
  3308. // Initialize the self timer when the transition is created.
  3309. // Note the actual delay is not known until the first callback!
  3310. schedules[id] = self;
  3311. self.timer = timer(schedule, 0, self.time);
  3312. function schedule(elapsed) {
  3313. self.state = SCHEDULED;
  3314. self.timer.restart(start, self.delay, self.time);
  3315. // If the elapsed delay is less than our first sleep, start immediately.
  3316. if (self.delay <= elapsed) start(elapsed - self.delay);
  3317. }
  3318. function start(elapsed) {
  3319. var i, j, n, o;
  3320. // If the state is not SCHEDULED, then we previously errored on start.
  3321. if (self.state !== SCHEDULED) return stop();
  3322. for (i in schedules) {
  3323. o = schedules[i];
  3324. if (o.name !== self.name) continue;
  3325. // While this element already has a starting transition during this frame,
  3326. // defer starting an interrupting transition until that transition has a
  3327. // chance to tick (and possibly end); see d3/d3-transition#54!
  3328. if (o.state === STARTED) return timeout$1(start);
  3329. // Interrupt the active transition, if any.
  3330. if (o.state === RUNNING) {
  3331. o.state = ENDED;
  3332. o.timer.stop();
  3333. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  3334. delete schedules[i];
  3335. }
  3336. // Cancel any pre-empted transitions.
  3337. else if (+i < id) {
  3338. o.state = ENDED;
  3339. o.timer.stop();
  3340. o.on.call("cancel", node, node.__data__, o.index, o.group);
  3341. delete schedules[i];
  3342. }
  3343. }
  3344. // Defer the first tick to end of the current frame; see d3/d3#1576.
  3345. // Note the transition may be canceled after start and before the first tick!
  3346. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  3347. // Assuming this is successful, subsequent callbacks go straight to tick.
  3348. timeout$1(function() {
  3349. if (self.state === STARTED) {
  3350. self.state = RUNNING;
  3351. self.timer.restart(tick, self.delay, self.time);
  3352. tick(elapsed);
  3353. }
  3354. });
  3355. // Dispatch the start event.
  3356. // Note this must be done before the tween are initialized.
  3357. self.state = STARTING;
  3358. self.on.call("start", node, node.__data__, self.index, self.group);
  3359. if (self.state !== STARTING) return; // interrupted
  3360. self.state = STARTED;
  3361. // Initialize the tween, deleting null tween.
  3362. tween = new Array(n = self.tween.length);
  3363. for (i = 0, j = -1; i < n; ++i) {
  3364. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  3365. tween[++j] = o;
  3366. }
  3367. }
  3368. tween.length = j + 1;
  3369. }
  3370. function tick(elapsed) {
  3371. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  3372. i = -1,
  3373. n = tween.length;
  3374. while (++i < n) {
  3375. tween[i].call(node, t);
  3376. }
  3377. // Dispatch the end event.
  3378. if (self.state === ENDING) {
  3379. self.on.call("end", node, node.__data__, self.index, self.group);
  3380. stop();
  3381. }
  3382. }
  3383. function stop() {
  3384. self.state = ENDED;
  3385. self.timer.stop();
  3386. delete schedules[id];
  3387. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  3388. delete node.__transition;
  3389. }
  3390. }
  3391. function interrupt(node, name) {
  3392. var schedules = node.__transition,
  3393. schedule,
  3394. active,
  3395. empty = true,
  3396. i;
  3397. if (!schedules) return;
  3398. name = name == null ? null : name + "";
  3399. for (i in schedules) {
  3400. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  3401. active = schedule.state > STARTING && schedule.state < ENDING;
  3402. schedule.state = ENDED;
  3403. schedule.timer.stop();
  3404. schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
  3405. delete schedules[i];
  3406. }
  3407. if (empty) delete node.__transition;
  3408. }
  3409. function selection_interrupt(name) {
  3410. return this.each(function() {
  3411. interrupt(this, name);
  3412. });
  3413. }
  3414. function tweenRemove(id, name) {
  3415. var tween0, tween1;
  3416. return function() {
  3417. var schedule = set$2(this, id),
  3418. tween = schedule.tween;
  3419. // If this node shared tween with the previous node,
  3420. // just assign the updated shared tween and we’re done!
  3421. // Otherwise, copy-on-write.
  3422. if (tween !== tween0) {
  3423. tween1 = tween0 = tween;
  3424. for (var i = 0, n = tween1.length; i < n; ++i) {
  3425. if (tween1[i].name === name) {
  3426. tween1 = tween1.slice();
  3427. tween1.splice(i, 1);
  3428. break;
  3429. }
  3430. }
  3431. }
  3432. schedule.tween = tween1;
  3433. };
  3434. }
  3435. function tweenFunction(id, name, value) {
  3436. var tween0, tween1;
  3437. if (typeof value !== "function") throw new Error;
  3438. return function() {
  3439. var schedule = set$2(this, id),
  3440. tween = schedule.tween;
  3441. // If this node shared tween with the previous node,
  3442. // just assign the updated shared tween and we’re done!
  3443. // Otherwise, copy-on-write.
  3444. if (tween !== tween0) {
  3445. tween1 = (tween0 = tween).slice();
  3446. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  3447. if (tween1[i].name === name) {
  3448. tween1[i] = t;
  3449. break;
  3450. }
  3451. }
  3452. if (i === n) tween1.push(t);
  3453. }
  3454. schedule.tween = tween1;
  3455. };
  3456. }
  3457. function transition_tween(name, value) {
  3458. var id = this._id;
  3459. name += "";
  3460. if (arguments.length < 2) {
  3461. var tween = get$1(this.node(), id).tween;
  3462. for (var i = 0, n = tween.length, t; i < n; ++i) {
  3463. if ((t = tween[i]).name === name) {
  3464. return t.value;
  3465. }
  3466. }
  3467. return null;
  3468. }
  3469. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  3470. }
  3471. function tweenValue(transition, name, value) {
  3472. var id = transition._id;
  3473. transition.each(function() {
  3474. var schedule = set$2(this, id);
  3475. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  3476. });
  3477. return function(node) {
  3478. return get$1(node, id).value[name];
  3479. };
  3480. }
  3481. function interpolate$1(a, b) {
  3482. var c;
  3483. return (typeof b === "number" ? interpolateNumber
  3484. : b instanceof color ? interpolateRgb
  3485. : (c = color(b)) ? (b = c, interpolateRgb)
  3486. : interpolateString)(a, b);
  3487. }
  3488. function attrRemove$1(name) {
  3489. return function() {
  3490. this.removeAttribute(name);
  3491. };
  3492. }
  3493. function attrRemoveNS$1(fullname) {
  3494. return function() {
  3495. this.removeAttributeNS(fullname.space, fullname.local);
  3496. };
  3497. }
  3498. function attrConstant$1(name, interpolate, value1) {
  3499. var string00,
  3500. string1 = value1 + "",
  3501. interpolate0;
  3502. return function() {
  3503. var string0 = this.getAttribute(name);
  3504. return string0 === string1 ? null
  3505. : string0 === string00 ? interpolate0
  3506. : interpolate0 = interpolate(string00 = string0, value1);
  3507. };
  3508. }
  3509. function attrConstantNS$1(fullname, interpolate, value1) {
  3510. var string00,
  3511. string1 = value1 + "",
  3512. interpolate0;
  3513. return function() {
  3514. var string0 = this.getAttributeNS(fullname.space, fullname.local);
  3515. return string0 === string1 ? null
  3516. : string0 === string00 ? interpolate0
  3517. : interpolate0 = interpolate(string00 = string0, value1);
  3518. };
  3519. }
  3520. function attrFunction$1(name, interpolate, value) {
  3521. var string00,
  3522. string10,
  3523. interpolate0;
  3524. return function() {
  3525. var string0, value1 = value(this), string1;
  3526. if (value1 == null) return void this.removeAttribute(name);
  3527. string0 = this.getAttribute(name);
  3528. string1 = value1 + "";
  3529. return string0 === string1 ? null
  3530. : string0 === string00 && string1 === string10 ? interpolate0
  3531. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3532. };
  3533. }
  3534. function attrFunctionNS$1(fullname, interpolate, value) {
  3535. var string00,
  3536. string10,
  3537. interpolate0;
  3538. return function() {
  3539. var string0, value1 = value(this), string1;
  3540. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3541. string0 = this.getAttributeNS(fullname.space, fullname.local);
  3542. string1 = value1 + "";
  3543. return string0 === string1 ? null
  3544. : string0 === string00 && string1 === string10 ? interpolate0
  3545. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3546. };
  3547. }
  3548. function transition_attr(name, value) {
  3549. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
  3550. return this.attrTween(name, typeof value === "function"
  3551. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  3552. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  3553. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
  3554. }
  3555. function attrInterpolate(name, i) {
  3556. return function(t) {
  3557. this.setAttribute(name, i.call(this, t));
  3558. };
  3559. }
  3560. function attrInterpolateNS(fullname, i) {
  3561. return function(t) {
  3562. this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
  3563. };
  3564. }
  3565. function attrTweenNS(fullname, value) {
  3566. var t0, i0;
  3567. function tween() {
  3568. var i = value.apply(this, arguments);
  3569. if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
  3570. return t0;
  3571. }
  3572. tween._value = value;
  3573. return tween;
  3574. }
  3575. function attrTween(name, value) {
  3576. var t0, i0;
  3577. function tween() {
  3578. var i = value.apply(this, arguments);
  3579. if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
  3580. return t0;
  3581. }
  3582. tween._value = value;
  3583. return tween;
  3584. }
  3585. function transition_attrTween(name, value) {
  3586. var key = "attr." + name;
  3587. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3588. if (value == null) return this.tween(key, null);
  3589. if (typeof value !== "function") throw new Error;
  3590. var fullname = namespace(name);
  3591. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3592. }
  3593. function delayFunction(id, value) {
  3594. return function() {
  3595. init(this, id).delay = +value.apply(this, arguments);
  3596. };
  3597. }
  3598. function delayConstant(id, value) {
  3599. return value = +value, function() {
  3600. init(this, id).delay = value;
  3601. };
  3602. }
  3603. function transition_delay(value) {
  3604. var id = this._id;
  3605. return arguments.length
  3606. ? this.each((typeof value === "function"
  3607. ? delayFunction
  3608. : delayConstant)(id, value))
  3609. : get$1(this.node(), id).delay;
  3610. }
  3611. function durationFunction(id, value) {
  3612. return function() {
  3613. set$2(this, id).duration = +value.apply(this, arguments);
  3614. };
  3615. }
  3616. function durationConstant(id, value) {
  3617. return value = +value, function() {
  3618. set$2(this, id).duration = value;
  3619. };
  3620. }
  3621. function transition_duration(value) {
  3622. var id = this._id;
  3623. return arguments.length
  3624. ? this.each((typeof value === "function"
  3625. ? durationFunction
  3626. : durationConstant)(id, value))
  3627. : get$1(this.node(), id).duration;
  3628. }
  3629. function easeConstant(id, value) {
  3630. if (typeof value !== "function") throw new Error;
  3631. return function() {
  3632. set$2(this, id).ease = value;
  3633. };
  3634. }
  3635. function transition_ease(value) {
  3636. var id = this._id;
  3637. return arguments.length
  3638. ? this.each(easeConstant(id, value))
  3639. : get$1(this.node(), id).ease;
  3640. }
  3641. function easeVarying(id, value) {
  3642. return function() {
  3643. var v = value.apply(this, arguments);
  3644. if (typeof v !== "function") throw new Error;
  3645. set$2(this, id).ease = v;
  3646. };
  3647. }
  3648. function transition_easeVarying(value) {
  3649. if (typeof value !== "function") throw new Error;
  3650. return this.each(easeVarying(this._id, value));
  3651. }
  3652. function transition_filter(match) {
  3653. if (typeof match !== "function") match = matcher(match);
  3654. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3655. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3656. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3657. subgroup.push(node);
  3658. }
  3659. }
  3660. }
  3661. return new Transition(subgroups, this._parents, this._name, this._id);
  3662. }
  3663. function transition_merge(transition) {
  3664. if (transition._id !== this._id) throw new Error;
  3665. 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) {
  3666. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3667. if (node = group0[i] || group1[i]) {
  3668. merge[i] = node;
  3669. }
  3670. }
  3671. }
  3672. for (; j < m0; ++j) {
  3673. merges[j] = groups0[j];
  3674. }
  3675. return new Transition(merges, this._parents, this._name, this._id);
  3676. }
  3677. function start(name) {
  3678. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3679. var i = t.indexOf(".");
  3680. if (i >= 0) t = t.slice(0, i);
  3681. return !t || t === "start";
  3682. });
  3683. }
  3684. function onFunction(id, name, listener) {
  3685. var on0, on1, sit = start(name) ? init : set$2;
  3686. return function() {
  3687. var schedule = sit(this, id),
  3688. on = schedule.on;
  3689. // If this node shared a dispatch with the previous node,
  3690. // just assign the updated shared dispatch and we’re done!
  3691. // Otherwise, copy-on-write.
  3692. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3693. schedule.on = on1;
  3694. };
  3695. }
  3696. function transition_on(name, listener) {
  3697. var id = this._id;
  3698. return arguments.length < 2
  3699. ? get$1(this.node(), id).on.on(name)
  3700. : this.each(onFunction(id, name, listener));
  3701. }
  3702. function removeFunction(id) {
  3703. return function() {
  3704. var parent = this.parentNode;
  3705. for (var i in this.__transition) if (+i !== id) return;
  3706. if (parent) parent.removeChild(this);
  3707. };
  3708. }
  3709. function transition_remove() {
  3710. return this.on("end.remove", removeFunction(this._id));
  3711. }
  3712. function transition_select(select) {
  3713. var name = this._name,
  3714. id = this._id;
  3715. if (typeof select !== "function") select = selector(select);
  3716. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3717. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3718. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  3719. if ("__data__" in node) subnode.__data__ = node.__data__;
  3720. subgroup[i] = subnode;
  3721. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3722. }
  3723. }
  3724. }
  3725. return new Transition(subgroups, this._parents, name, id);
  3726. }
  3727. function transition_selectAll(select) {
  3728. var name = this._name,
  3729. id = this._id;
  3730. if (typeof select !== "function") select = selectorAll(select);
  3731. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3732. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3733. if (node = group[i]) {
  3734. for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3735. if (child = children[k]) {
  3736. schedule(child, name, id, k, children, inherit);
  3737. }
  3738. }
  3739. subgroups.push(children);
  3740. parents.push(node);
  3741. }
  3742. }
  3743. }
  3744. return new Transition(subgroups, parents, name, id);
  3745. }
  3746. var Selection$1 = selection.prototype.constructor;
  3747. function transition_selection() {
  3748. return new Selection$1(this._groups, this._parents);
  3749. }
  3750. function styleNull(name, interpolate) {
  3751. var string00,
  3752. string10,
  3753. interpolate0;
  3754. return function() {
  3755. var string0 = styleValue(this, name),
  3756. string1 = (this.style.removeProperty(name), styleValue(this, name));
  3757. return string0 === string1 ? null
  3758. : string0 === string00 && string1 === string10 ? interpolate0
  3759. : interpolate0 = interpolate(string00 = string0, string10 = string1);
  3760. };
  3761. }
  3762. function styleRemove$1(name) {
  3763. return function() {
  3764. this.style.removeProperty(name);
  3765. };
  3766. }
  3767. function styleConstant$1(name, interpolate, value1) {
  3768. var string00,
  3769. string1 = value1 + "",
  3770. interpolate0;
  3771. return function() {
  3772. var string0 = styleValue(this, name);
  3773. return string0 === string1 ? null
  3774. : string0 === string00 ? interpolate0
  3775. : interpolate0 = interpolate(string00 = string0, value1);
  3776. };
  3777. }
  3778. function styleFunction$1(name, interpolate, value) {
  3779. var string00,
  3780. string10,
  3781. interpolate0;
  3782. return function() {
  3783. var string0 = styleValue(this, name),
  3784. value1 = value(this),
  3785. string1 = value1 + "";
  3786. if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
  3787. return string0 === string1 ? null
  3788. : string0 === string00 && string1 === string10 ? interpolate0
  3789. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3790. };
  3791. }
  3792. function styleMaybeRemove(id, name) {
  3793. var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
  3794. return function() {
  3795. var schedule = set$2(this, id),
  3796. on = schedule.on,
  3797. listener = schedule.value[key] == null ? remove || (remove = styleRemove$1(name)) : undefined;
  3798. // If this node shared a dispatch with the previous node,
  3799. // just assign the updated shared dispatch and we’re done!
  3800. // Otherwise, copy-on-write.
  3801. if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
  3802. schedule.on = on1;
  3803. };
  3804. }
  3805. function transition_style(name, value, priority) {
  3806. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
  3807. return value == null ? this
  3808. .styleTween(name, styleNull(name, i))
  3809. .on("end.style." + name, styleRemove$1(name))
  3810. : typeof value === "function" ? this
  3811. .styleTween(name, styleFunction$1(name, i, tweenValue(this, "style." + name, value)))
  3812. .each(styleMaybeRemove(this._id, name))
  3813. : this
  3814. .styleTween(name, styleConstant$1(name, i, value), priority)
  3815. .on("end.style." + name, null);
  3816. }
  3817. function styleInterpolate(name, i, priority) {
  3818. return function(t) {
  3819. this.style.setProperty(name, i.call(this, t), priority);
  3820. };
  3821. }
  3822. function styleTween(name, value, priority) {
  3823. var t, i0;
  3824. function tween() {
  3825. var i = value.apply(this, arguments);
  3826. if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
  3827. return t;
  3828. }
  3829. tween._value = value;
  3830. return tween;
  3831. }
  3832. function transition_styleTween(name, value, priority) {
  3833. var key = "style." + (name += "");
  3834. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3835. if (value == null) return this.tween(key, null);
  3836. if (typeof value !== "function") throw new Error;
  3837. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3838. }
  3839. function textConstant$1(value) {
  3840. return function() {
  3841. this.textContent = value;
  3842. };
  3843. }
  3844. function textFunction$1(value) {
  3845. return function() {
  3846. var value1 = value(this);
  3847. this.textContent = value1 == null ? "" : value1;
  3848. };
  3849. }
  3850. function transition_text(value) {
  3851. return this.tween("text", typeof value === "function"
  3852. ? textFunction$1(tweenValue(this, "text", value))
  3853. : textConstant$1(value == null ? "" : value + ""));
  3854. }
  3855. function textInterpolate(i) {
  3856. return function(t) {
  3857. this.textContent = i.call(this, t);
  3858. };
  3859. }
  3860. function textTween(value) {
  3861. var t0, i0;
  3862. function tween() {
  3863. var i = value.apply(this, arguments);
  3864. if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
  3865. return t0;
  3866. }
  3867. tween._value = value;
  3868. return tween;
  3869. }
  3870. function transition_textTween(value) {
  3871. var key = "text";
  3872. if (arguments.length < 1) return (key = this.tween(key)) && key._value;
  3873. if (value == null) return this.tween(key, null);
  3874. if (typeof value !== "function") throw new Error;
  3875. return this.tween(key, textTween(value));
  3876. }
  3877. function transition_transition() {
  3878. var name = this._name,
  3879. id0 = this._id,
  3880. id1 = newId();
  3881. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3882. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3883. if (node = group[i]) {
  3884. var inherit = get$1(node, id0);
  3885. schedule(node, name, id1, i, group, {
  3886. time: inherit.time + inherit.delay + inherit.duration,
  3887. delay: 0,
  3888. duration: inherit.duration,
  3889. ease: inherit.ease
  3890. });
  3891. }
  3892. }
  3893. }
  3894. return new Transition(groups, this._parents, name, id1);
  3895. }
  3896. function transition_end() {
  3897. var on0, on1, that = this, id = that._id, size = that.size();
  3898. return new Promise(function(resolve, reject) {
  3899. var cancel = {value: reject},
  3900. end = {value: function() { if (--size === 0) resolve(); }};
  3901. that.each(function() {
  3902. var schedule = set$2(this, id),
  3903. on = schedule.on;
  3904. // If this node shared a dispatch with the previous node,
  3905. // just assign the updated shared dispatch and we’re done!
  3906. // Otherwise, copy-on-write.
  3907. if (on !== on0) {
  3908. on1 = (on0 = on).copy();
  3909. on1._.cancel.push(cancel);
  3910. on1._.interrupt.push(cancel);
  3911. on1._.end.push(end);
  3912. }
  3913. schedule.on = on1;
  3914. });
  3915. // The selection was empty, resolve end immediately
  3916. if (size === 0) resolve();
  3917. });
  3918. }
  3919. var id = 0;
  3920. function Transition(groups, parents, name, id) {
  3921. this._groups = groups;
  3922. this._parents = parents;
  3923. this._name = name;
  3924. this._id = id;
  3925. }
  3926. function transition(name) {
  3927. return selection().transition(name);
  3928. }
  3929. function newId() {
  3930. return ++id;
  3931. }
  3932. var selection_prototype = selection.prototype;
  3933. Transition.prototype = transition.prototype = {
  3934. constructor: Transition,
  3935. select: transition_select,
  3936. selectAll: transition_selectAll,
  3937. filter: transition_filter,
  3938. merge: transition_merge,
  3939. selection: transition_selection,
  3940. transition: transition_transition,
  3941. call: selection_prototype.call,
  3942. nodes: selection_prototype.nodes,
  3943. node: selection_prototype.node,
  3944. size: selection_prototype.size,
  3945. empty: selection_prototype.empty,
  3946. each: selection_prototype.each,
  3947. on: transition_on,
  3948. attr: transition_attr,
  3949. attrTween: transition_attrTween,
  3950. style: transition_style,
  3951. styleTween: transition_styleTween,
  3952. text: transition_text,
  3953. textTween: transition_textTween,
  3954. remove: transition_remove,
  3955. tween: transition_tween,
  3956. delay: transition_delay,
  3957. duration: transition_duration,
  3958. ease: transition_ease,
  3959. easeVarying: transition_easeVarying,
  3960. end: transition_end,
  3961. [Symbol.iterator]: selection_prototype[Symbol.iterator]
  3962. };
  3963. const linear$1 = t => +t;
  3964. function quadIn(t) {
  3965. return t * t;
  3966. }
  3967. function quadOut(t) {
  3968. return t * (2 - t);
  3969. }
  3970. function quadInOut(t) {
  3971. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3972. }
  3973. function cubicIn(t) {
  3974. return t * t * t;
  3975. }
  3976. function cubicOut(t) {
  3977. return --t * t * t + 1;
  3978. }
  3979. function cubicInOut(t) {
  3980. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3981. }
  3982. var exponent = 3;
  3983. var polyIn = (function custom(e) {
  3984. e = +e;
  3985. function polyIn(t) {
  3986. return Math.pow(t, e);
  3987. }
  3988. polyIn.exponent = custom;
  3989. return polyIn;
  3990. })(exponent);
  3991. var polyOut = (function custom(e) {
  3992. e = +e;
  3993. function polyOut(t) {
  3994. return 1 - Math.pow(1 - t, e);
  3995. }
  3996. polyOut.exponent = custom;
  3997. return polyOut;
  3998. })(exponent);
  3999. var polyInOut = (function custom(e) {
  4000. e = +e;
  4001. function polyInOut(t) {
  4002. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  4003. }
  4004. polyInOut.exponent = custom;
  4005. return polyInOut;
  4006. })(exponent);
  4007. var pi = Math.PI,
  4008. halfPi = pi / 2;
  4009. function sinIn(t) {
  4010. return (+t === 1) ? 1 : 1 - Math.cos(t * halfPi);
  4011. }
  4012. function sinOut(t) {
  4013. return Math.sin(t * halfPi);
  4014. }
  4015. function sinInOut(t) {
  4016. return (1 - Math.cos(pi * t)) / 2;
  4017. }
  4018. // tpmt is two power minus ten times t scaled to [0,1]
  4019. function tpmt(x) {
  4020. return (Math.pow(2, -10 * x) - 0.0009765625) * 1.0009775171065494;
  4021. }
  4022. function expIn(t) {
  4023. return tpmt(1 - +t);
  4024. }
  4025. function expOut(t) {
  4026. return 1 - tpmt(t);
  4027. }
  4028. function expInOut(t) {
  4029. return ((t *= 2) <= 1 ? tpmt(1 - t) : 2 - tpmt(t - 1)) / 2;
  4030. }
  4031. function circleIn(t) {
  4032. return 1 - Math.sqrt(1 - t * t);
  4033. }
  4034. function circleOut(t) {
  4035. return Math.sqrt(1 - --t * t);
  4036. }
  4037. function circleInOut(t) {
  4038. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  4039. }
  4040. var b1 = 4 / 11,
  4041. b2 = 6 / 11,
  4042. b3 = 8 / 11,
  4043. b4 = 3 / 4,
  4044. b5 = 9 / 11,
  4045. b6 = 10 / 11,
  4046. b7 = 15 / 16,
  4047. b8 = 21 / 22,
  4048. b9 = 63 / 64,
  4049. b0 = 1 / b1 / b1;
  4050. function bounceIn(t) {
  4051. return 1 - bounceOut(1 - t);
  4052. }
  4053. function bounceOut(t) {
  4054. 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;
  4055. }
  4056. function bounceInOut(t) {
  4057. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  4058. }
  4059. var overshoot = 1.70158;
  4060. var backIn = (function custom(s) {
  4061. s = +s;
  4062. function backIn(t) {
  4063. return (t = +t) * t * (s * (t - 1) + t);
  4064. }
  4065. backIn.overshoot = custom;
  4066. return backIn;
  4067. })(overshoot);
  4068. var backOut = (function custom(s) {
  4069. s = +s;
  4070. function backOut(t) {
  4071. return --t * t * ((t + 1) * s + t) + 1;
  4072. }
  4073. backOut.overshoot = custom;
  4074. return backOut;
  4075. })(overshoot);
  4076. var backInOut = (function custom(s) {
  4077. s = +s;
  4078. function backInOut(t) {
  4079. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  4080. }
  4081. backInOut.overshoot = custom;
  4082. return backInOut;
  4083. })(overshoot);
  4084. var tau = 2 * Math.PI,
  4085. amplitude = 1,
  4086. period = 0.3;
  4087. var elasticIn = (function custom(a, p) {
  4088. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  4089. function elasticIn(t) {
  4090. return a * tpmt(-(--t)) * Math.sin((s - t) / p);
  4091. }
  4092. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  4093. elasticIn.period = function(p) { return custom(a, p); };
  4094. return elasticIn;
  4095. })(amplitude, period);
  4096. var elasticOut = (function custom(a, p) {
  4097. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  4098. function elasticOut(t) {
  4099. return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p);
  4100. }
  4101. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  4102. elasticOut.period = function(p) { return custom(a, p); };
  4103. return elasticOut;
  4104. })(amplitude, period);
  4105. var elasticInOut = (function custom(a, p) {
  4106. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  4107. function elasticInOut(t) {
  4108. return ((t = t * 2 - 1) < 0
  4109. ? a * tpmt(-t) * Math.sin((s - t) / p)
  4110. : 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2;
  4111. }
  4112. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  4113. elasticInOut.period = function(p) { return custom(a, p); };
  4114. return elasticInOut;
  4115. })(amplitude, period);
  4116. var defaultTiming = {
  4117. time: null, // Set on use.
  4118. delay: 0,
  4119. duration: 250,
  4120. ease: cubicInOut
  4121. };
  4122. function inherit(node, id) {
  4123. var timing;
  4124. while (!(timing = node.__transition) || !(timing = timing[id])) {
  4125. if (!(node = node.parentNode)) {
  4126. throw new Error(`transition ${id} not found`);
  4127. }
  4128. }
  4129. return timing;
  4130. }
  4131. function selection_transition(name) {
  4132. var id,
  4133. timing;
  4134. if (name instanceof Transition) {
  4135. id = name._id, name = name._name;
  4136. } else {
  4137. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  4138. }
  4139. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  4140. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4141. if (node = group[i]) {
  4142. schedule(node, name, id, i, group, timing || inherit(node, id));
  4143. }
  4144. }
  4145. }
  4146. return new Transition(groups, this._parents, name, id);
  4147. }
  4148. selection.prototype.interrupt = selection_interrupt;
  4149. selection.prototype.transition = selection_transition;
  4150. var root$1 = [null];
  4151. function active(node, name) {
  4152. var schedules = node.__transition,
  4153. schedule,
  4154. i;
  4155. if (schedules) {
  4156. name = name == null ? null : name + "";
  4157. for (i in schedules) {
  4158. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  4159. return new Transition([[node]], root$1, name, +i);
  4160. }
  4161. }
  4162. }
  4163. return null;
  4164. }
  4165. var constant$4 = x => () => x;
  4166. function BrushEvent(type, {
  4167. sourceEvent,
  4168. target,
  4169. selection,
  4170. mode,
  4171. dispatch
  4172. }) {
  4173. Object.defineProperties(this, {
  4174. type: {value: type, enumerable: true, configurable: true},
  4175. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  4176. target: {value: target, enumerable: true, configurable: true},
  4177. selection: {value: selection, enumerable: true, configurable: true},
  4178. mode: {value: mode, enumerable: true, configurable: true},
  4179. _: {value: dispatch}
  4180. });
  4181. }
  4182. function nopropagation$1(event) {
  4183. event.stopImmediatePropagation();
  4184. }
  4185. function noevent$1(event) {
  4186. event.preventDefault();
  4187. event.stopImmediatePropagation();
  4188. }
  4189. var MODE_DRAG = {name: "drag"},
  4190. MODE_SPACE = {name: "space"},
  4191. MODE_HANDLE = {name: "handle"},
  4192. MODE_CENTER = {name: "center"};
  4193. const {abs, max: max$1, min: min$1} = Math;
  4194. function number1(e) {
  4195. return [+e[0], +e[1]];
  4196. }
  4197. function number2(e) {
  4198. return [number1(e[0]), number1(e[1])];
  4199. }
  4200. var X = {
  4201. name: "x",
  4202. handles: ["w", "e"].map(type),
  4203. input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
  4204. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  4205. };
  4206. var Y = {
  4207. name: "y",
  4208. handles: ["n", "s"].map(type),
  4209. input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
  4210. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  4211. };
  4212. var XY = {
  4213. name: "xy",
  4214. handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
  4215. input: function(xy) { return xy == null ? null : number2(xy); },
  4216. output: function(xy) { return xy; }
  4217. };
  4218. var cursors = {
  4219. overlay: "crosshair",
  4220. selection: "move",
  4221. n: "ns-resize",
  4222. e: "ew-resize",
  4223. s: "ns-resize",
  4224. w: "ew-resize",
  4225. nw: "nwse-resize",
  4226. ne: "nesw-resize",
  4227. se: "nwse-resize",
  4228. sw: "nesw-resize"
  4229. };
  4230. var flipX = {
  4231. e: "w",
  4232. w: "e",
  4233. nw: "ne",
  4234. ne: "nw",
  4235. se: "sw",
  4236. sw: "se"
  4237. };
  4238. var flipY = {
  4239. n: "s",
  4240. s: "n",
  4241. nw: "sw",
  4242. ne: "se",
  4243. se: "ne",
  4244. sw: "nw"
  4245. };
  4246. var signsX = {
  4247. overlay: +1,
  4248. selection: +1,
  4249. n: null,
  4250. e: +1,
  4251. s: null,
  4252. w: -1,
  4253. nw: -1,
  4254. ne: +1,
  4255. se: +1,
  4256. sw: -1
  4257. };
  4258. var signsY = {
  4259. overlay: +1,
  4260. selection: +1,
  4261. n: -1,
  4262. e: null,
  4263. s: +1,
  4264. w: null,
  4265. nw: -1,
  4266. ne: -1,
  4267. se: +1,
  4268. sw: +1
  4269. };
  4270. function type(t) {
  4271. return {type: t};
  4272. }
  4273. // Ignore right-click, since that should open the context menu.
  4274. function defaultFilter$1(event) {
  4275. return !event.ctrlKey && !event.button;
  4276. }
  4277. function defaultExtent() {
  4278. var svg = this.ownerSVGElement || this;
  4279. if (svg.hasAttribute("viewBox")) {
  4280. svg = svg.viewBox.baseVal;
  4281. return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
  4282. }
  4283. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  4284. }
  4285. function defaultTouchable$1() {
  4286. return navigator.maxTouchPoints || ("ontouchstart" in this);
  4287. }
  4288. // Like d3.local, but with the name “__brush” rather than auto-generated.
  4289. function local$1(node) {
  4290. while (!node.__brush) if (!(node = node.parentNode)) return;
  4291. return node.__brush;
  4292. }
  4293. function empty$2(extent) {
  4294. return extent[0][0] === extent[1][0]
  4295. || extent[0][1] === extent[1][1];
  4296. }
  4297. function brushSelection(node) {
  4298. var state = node.__brush;
  4299. return state ? state.dim.output(state.selection) : null;
  4300. }
  4301. function brushX() {
  4302. return brush$1(X);
  4303. }
  4304. function brushY() {
  4305. return brush$1(Y);
  4306. }
  4307. function brush() {
  4308. return brush$1(XY);
  4309. }
  4310. function brush$1(dim) {
  4311. var extent = defaultExtent,
  4312. filter = defaultFilter$1,
  4313. touchable = defaultTouchable$1,
  4314. keys = true,
  4315. listeners = dispatch("start", "brush", "end"),
  4316. handleSize = 6,
  4317. touchending;
  4318. function brush(group) {
  4319. var overlay = group
  4320. .property("__brush", initialize)
  4321. .selectAll(".overlay")
  4322. .data([type("overlay")]);
  4323. overlay.enter().append("rect")
  4324. .attr("class", "overlay")
  4325. .attr("pointer-events", "all")
  4326. .attr("cursor", cursors.overlay)
  4327. .merge(overlay)
  4328. .each(function() {
  4329. var extent = local$1(this).extent;
  4330. select(this)
  4331. .attr("x", extent[0][0])
  4332. .attr("y", extent[0][1])
  4333. .attr("width", extent[1][0] - extent[0][0])
  4334. .attr("height", extent[1][1] - extent[0][1]);
  4335. });
  4336. group.selectAll(".selection")
  4337. .data([type("selection")])
  4338. .enter().append("rect")
  4339. .attr("class", "selection")
  4340. .attr("cursor", cursors.selection)
  4341. .attr("fill", "#777")
  4342. .attr("fill-opacity", 0.3)
  4343. .attr("stroke", "#fff")
  4344. .attr("shape-rendering", "crispEdges");
  4345. var handle = group.selectAll(".handle")
  4346. .data(dim.handles, function(d) { return d.type; });
  4347. handle.exit().remove();
  4348. handle.enter().append("rect")
  4349. .attr("class", function(d) { return "handle handle--" + d.type; })
  4350. .attr("cursor", function(d) { return cursors[d.type]; });
  4351. group
  4352. .each(redraw)
  4353. .attr("fill", "none")
  4354. .attr("pointer-events", "all")
  4355. .on("mousedown.brush", started)
  4356. .filter(touchable)
  4357. .on("touchstart.brush", started)
  4358. .on("touchmove.brush", touchmoved)
  4359. .on("touchend.brush touchcancel.brush", touchended)
  4360. .style("touch-action", "none")
  4361. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  4362. }
  4363. brush.move = function(group, selection) {
  4364. if (group.tween) {
  4365. group
  4366. .on("start.brush", function(event) { emitter(this, arguments).beforestart().start(event); })
  4367. .on("interrupt.brush end.brush", function(event) { emitter(this, arguments).end(event); })
  4368. .tween("brush", function() {
  4369. var that = this,
  4370. state = that.__brush,
  4371. emit = emitter(that, arguments),
  4372. selection0 = state.selection,
  4373. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  4374. i = interpolate(selection0, selection1);
  4375. function tween(t) {
  4376. state.selection = t === 1 && selection1 === null ? null : i(t);
  4377. redraw.call(that);
  4378. emit.brush();
  4379. }
  4380. return selection0 !== null && selection1 !== null ? tween : tween(1);
  4381. });
  4382. } else {
  4383. group
  4384. .each(function() {
  4385. var that = this,
  4386. args = arguments,
  4387. state = that.__brush,
  4388. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  4389. emit = emitter(that, args).beforestart();
  4390. interrupt(that);
  4391. state.selection = selection1 === null ? null : selection1;
  4392. redraw.call(that);
  4393. emit.start().brush().end();
  4394. });
  4395. }
  4396. };
  4397. brush.clear = function(group) {
  4398. brush.move(group, null);
  4399. };
  4400. function redraw() {
  4401. var group = select(this),
  4402. selection = local$1(this).selection;
  4403. if (selection) {
  4404. group.selectAll(".selection")
  4405. .style("display", null)
  4406. .attr("x", selection[0][0])
  4407. .attr("y", selection[0][1])
  4408. .attr("width", selection[1][0] - selection[0][0])
  4409. .attr("height", selection[1][1] - selection[0][1]);
  4410. group.selectAll(".handle")
  4411. .style("display", null)
  4412. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  4413. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  4414. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  4415. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  4416. }
  4417. else {
  4418. group.selectAll(".selection,.handle")
  4419. .style("display", "none")
  4420. .attr("x", null)
  4421. .attr("y", null)
  4422. .attr("width", null)
  4423. .attr("height", null);
  4424. }
  4425. }
  4426. function emitter(that, args, clean) {
  4427. var emit = that.__brush.emitter;
  4428. return emit && (!clean || !emit.clean) ? emit : new Emitter(that, args, clean);
  4429. }
  4430. function Emitter(that, args, clean) {
  4431. this.that = that;
  4432. this.args = args;
  4433. this.state = that.__brush;
  4434. this.active = 0;
  4435. this.clean = clean;
  4436. }
  4437. Emitter.prototype = {
  4438. beforestart: function() {
  4439. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  4440. return this;
  4441. },
  4442. start: function(event, mode) {
  4443. if (this.starting) this.starting = false, this.emit("start", event, mode);
  4444. else this.emit("brush", event);
  4445. return this;
  4446. },
  4447. brush: function(event, mode) {
  4448. this.emit("brush", event, mode);
  4449. return this;
  4450. },
  4451. end: function(event, mode) {
  4452. if (--this.active === 0) delete this.state.emitter, this.emit("end", event, mode);
  4453. return this;
  4454. },
  4455. emit: function(type, event, mode) {
  4456. var d = select(this.that).datum();
  4457. listeners.call(
  4458. type,
  4459. this.that,
  4460. new BrushEvent(type, {
  4461. sourceEvent: event,
  4462. target: brush,
  4463. selection: dim.output(this.state.selection),
  4464. mode,
  4465. dispatch: listeners
  4466. }),
  4467. d
  4468. );
  4469. }
  4470. };
  4471. function started(event) {
  4472. if (touchending && !event.touches) return;
  4473. if (!filter.apply(this, arguments)) return;
  4474. var that = this,
  4475. type = event.target.__data__.type,
  4476. mode = (keys && event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && event.altKey ? MODE_CENTER : MODE_HANDLE),
  4477. signX = dim === Y ? null : signsX[type],
  4478. signY = dim === X ? null : signsY[type],
  4479. state = local$1(that),
  4480. extent = state.extent,
  4481. selection = state.selection,
  4482. W = extent[0][0], w0, w1,
  4483. N = extent[0][1], n0, n1,
  4484. E = extent[1][0], e0, e1,
  4485. S = extent[1][1], s0, s1,
  4486. dx = 0,
  4487. dy = 0,
  4488. moving,
  4489. shifting = signX && signY && keys && event.shiftKey,
  4490. lockX,
  4491. lockY,
  4492. points = Array.from(event.touches || [event], t => {
  4493. const i = t.identifier;
  4494. t = pointer(t, that);
  4495. t.point0 = t.slice();
  4496. t.identifier = i;
  4497. return t;
  4498. });
  4499. if (type === "overlay") {
  4500. if (selection) moving = true;
  4501. const pts = [points[0], points[1] || points[0]];
  4502. state.selection = selection = [[
  4503. w0 = dim === Y ? W : min$1(pts[0][0], pts[1][0]),
  4504. n0 = dim === X ? N : min$1(pts[0][1], pts[1][1])
  4505. ], [
  4506. e0 = dim === Y ? E : max$1(pts[0][0], pts[1][0]),
  4507. s0 = dim === X ? S : max$1(pts[0][1], pts[1][1])
  4508. ]];
  4509. if (points.length > 1) move();
  4510. } else {
  4511. w0 = selection[0][0];
  4512. n0 = selection[0][1];
  4513. e0 = selection[1][0];
  4514. s0 = selection[1][1];
  4515. }
  4516. w1 = w0;
  4517. n1 = n0;
  4518. e1 = e0;
  4519. s1 = s0;
  4520. var group = select(that)
  4521. .attr("pointer-events", "none");
  4522. var overlay = group.selectAll(".overlay")
  4523. .attr("cursor", cursors[type]);
  4524. interrupt(that);
  4525. var emit = emitter(that, arguments, true).beforestart();
  4526. if (event.touches) {
  4527. emit.moved = moved;
  4528. emit.ended = ended;
  4529. } else {
  4530. var view = select(event.view)
  4531. .on("mousemove.brush", moved, true)
  4532. .on("mouseup.brush", ended, true);
  4533. if (keys) view
  4534. .on("keydown.brush", keydowned, true)
  4535. .on("keyup.brush", keyupped, true);
  4536. dragDisable(event.view);
  4537. }
  4538. redraw.call(that);
  4539. emit.start(event, mode.name);
  4540. function moved(event) {
  4541. for (const p of event.changedTouches || [event]) {
  4542. for (const d of points)
  4543. if (d.identifier === p.identifier) d.cur = pointer(p, that);
  4544. }
  4545. if (shifting && !lockX && !lockY && points.length === 1) {
  4546. const point = points[0];
  4547. if (abs(point.cur[0] - point[0]) > abs(point.cur[1] - point[1]))
  4548. lockY = true;
  4549. else
  4550. lockX = true;
  4551. }
  4552. for (const point of points)
  4553. if (point.cur) point[0] = point.cur[0], point[1] = point.cur[1];
  4554. moving = true;
  4555. noevent$1(event);
  4556. move(event);
  4557. }
  4558. function move(event) {
  4559. const point = points[0], point0 = point.point0;
  4560. var t;
  4561. dx = point[0] - point0[0];
  4562. dy = point[1] - point0[1];
  4563. switch (mode) {
  4564. case MODE_SPACE:
  4565. case MODE_DRAG: {
  4566. if (signX) dx = max$1(W - w0, min$1(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  4567. if (signY) dy = max$1(N - n0, min$1(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  4568. break;
  4569. }
  4570. case MODE_HANDLE: {
  4571. if (points[1]) {
  4572. if (signX) w1 = max$1(W, min$1(E, points[0][0])), e1 = max$1(W, min$1(E, points[1][0])), signX = 1;
  4573. if (signY) n1 = max$1(N, min$1(S, points[0][1])), s1 = max$1(N, min$1(S, points[1][1])), signY = 1;
  4574. } else {
  4575. if (signX < 0) dx = max$1(W - w0, min$1(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  4576. else if (signX > 0) dx = max$1(W - e0, min$1(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  4577. if (signY < 0) dy = max$1(N - n0, min$1(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  4578. else if (signY > 0) dy = max$1(N - s0, min$1(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  4579. }
  4580. break;
  4581. }
  4582. case MODE_CENTER: {
  4583. if (signX) w1 = max$1(W, min$1(E, w0 - dx * signX)), e1 = max$1(W, min$1(E, e0 + dx * signX));
  4584. if (signY) n1 = max$1(N, min$1(S, n0 - dy * signY)), s1 = max$1(N, min$1(S, s0 + dy * signY));
  4585. break;
  4586. }
  4587. }
  4588. if (e1 < w1) {
  4589. signX *= -1;
  4590. t = w0, w0 = e0, e0 = t;
  4591. t = w1, w1 = e1, e1 = t;
  4592. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  4593. }
  4594. if (s1 < n1) {
  4595. signY *= -1;
  4596. t = n0, n0 = s0, s0 = t;
  4597. t = n1, n1 = s1, s1 = t;
  4598. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  4599. }
  4600. if (state.selection) selection = state.selection; // May be set by brush.move!
  4601. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  4602. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  4603. if (selection[0][0] !== w1
  4604. || selection[0][1] !== n1
  4605. || selection[1][0] !== e1
  4606. || selection[1][1] !== s1) {
  4607. state.selection = [[w1, n1], [e1, s1]];
  4608. redraw.call(that);
  4609. emit.brush(event, mode.name);
  4610. }
  4611. }
  4612. function ended(event) {
  4613. nopropagation$1(event);
  4614. if (event.touches) {
  4615. if (event.touches.length) return;
  4616. if (touchending) clearTimeout(touchending);
  4617. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  4618. } else {
  4619. yesdrag(event.view, moving);
  4620. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  4621. }
  4622. group.attr("pointer-events", "all");
  4623. overlay.attr("cursor", cursors.overlay);
  4624. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  4625. if (empty$2(selection)) state.selection = null, redraw.call(that);
  4626. emit.end(event, mode.name);
  4627. }
  4628. function keydowned(event) {
  4629. switch (event.keyCode) {
  4630. case 16: { // SHIFT
  4631. shifting = signX && signY;
  4632. break;
  4633. }
  4634. case 18: { // ALT
  4635. if (mode === MODE_HANDLE) {
  4636. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4637. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4638. mode = MODE_CENTER;
  4639. move();
  4640. }
  4641. break;
  4642. }
  4643. case 32: { // SPACE; takes priority over ALT
  4644. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  4645. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  4646. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  4647. mode = MODE_SPACE;
  4648. overlay.attr("cursor", cursors.selection);
  4649. move();
  4650. }
  4651. break;
  4652. }
  4653. default: return;
  4654. }
  4655. noevent$1(event);
  4656. }
  4657. function keyupped(event) {
  4658. switch (event.keyCode) {
  4659. case 16: { // SHIFT
  4660. if (shifting) {
  4661. lockX = lockY = shifting = false;
  4662. move();
  4663. }
  4664. break;
  4665. }
  4666. case 18: { // ALT
  4667. if (mode === MODE_CENTER) {
  4668. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4669. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4670. mode = MODE_HANDLE;
  4671. move();
  4672. }
  4673. break;
  4674. }
  4675. case 32: { // SPACE
  4676. if (mode === MODE_SPACE) {
  4677. if (event.altKey) {
  4678. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4679. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4680. mode = MODE_CENTER;
  4681. } else {
  4682. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4683. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4684. mode = MODE_HANDLE;
  4685. }
  4686. overlay.attr("cursor", cursors[type]);
  4687. move();
  4688. }
  4689. break;
  4690. }
  4691. default: return;
  4692. }
  4693. noevent$1(event);
  4694. }
  4695. }
  4696. function touchmoved(event) {
  4697. emitter(this, arguments).moved(event);
  4698. }
  4699. function touchended(event) {
  4700. emitter(this, arguments).ended(event);
  4701. }
  4702. function initialize() {
  4703. var state = this.__brush || {selection: null};
  4704. state.extent = number2(extent.apply(this, arguments));
  4705. state.dim = dim;
  4706. return state;
  4707. }
  4708. brush.extent = function(_) {
  4709. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4(number2(_)), brush) : extent;
  4710. };
  4711. brush.filter = function(_) {
  4712. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  4713. };
  4714. brush.touchable = function(_) {
  4715. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$4(!!_), brush) : touchable;
  4716. };
  4717. brush.handleSize = function(_) {
  4718. return arguments.length ? (handleSize = +_, brush) : handleSize;
  4719. };
  4720. brush.keyModifiers = function(_) {
  4721. return arguments.length ? (keys = !!_, brush) : keys;
  4722. };
  4723. brush.on = function() {
  4724. var value = listeners.on.apply(listeners, arguments);
  4725. return value === listeners ? brush : value;
  4726. };
  4727. return brush;
  4728. }
  4729. var abs$1 = Math.abs;
  4730. var cos = Math.cos;
  4731. var sin = Math.sin;
  4732. var pi$1 = Math.PI;
  4733. var halfPi$1 = pi$1 / 2;
  4734. var tau$1 = pi$1 * 2;
  4735. var max$2 = Math.max;
  4736. var epsilon$1 = 1e-12;
  4737. function range(i, j) {
  4738. return Array.from({length: j - i}, (_, k) => i + k);
  4739. }
  4740. function compareValue(compare) {
  4741. return function(a, b) {
  4742. return compare(
  4743. a.source.value + a.target.value,
  4744. b.source.value + b.target.value
  4745. );
  4746. };
  4747. }
  4748. function chord() {
  4749. return chord$1(false, false);
  4750. }
  4751. function chordTranspose() {
  4752. return chord$1(false, true);
  4753. }
  4754. function chordDirected() {
  4755. return chord$1(true, false);
  4756. }
  4757. function chord$1(directed, transpose) {
  4758. var padAngle = 0,
  4759. sortGroups = null,
  4760. sortSubgroups = null,
  4761. sortChords = null;
  4762. function chord(matrix) {
  4763. var n = matrix.length,
  4764. groupSums = new Array(n),
  4765. groupIndex = range(0, n),
  4766. chords = new Array(n * n),
  4767. groups = new Array(n),
  4768. k = 0, dx;
  4769. matrix = Float64Array.from({length: n * n}, transpose
  4770. ? (_, i) => matrix[i % n][i / n | 0]
  4771. : (_, i) => matrix[i / n | 0][i % n]);
  4772. // Compute the scaling factor from value to angle in [0, 2pi].
  4773. for (let i = 0; i < n; ++i) {
  4774. let x = 0;
  4775. for (let j = 0; j < n; ++j) x += matrix[i * n + j] + directed * matrix[j * n + i];
  4776. k += groupSums[i] = x;
  4777. }
  4778. k = max$2(0, tau$1 - padAngle * n) / k;
  4779. dx = k ? padAngle : tau$1 / n;
  4780. // Compute the angles for each group and constituent chord.
  4781. {
  4782. let x = 0;
  4783. if (sortGroups) groupIndex.sort((a, b) => sortGroups(groupSums[a], groupSums[b]));
  4784. for (const i of groupIndex) {
  4785. const x0 = x;
  4786. if (directed) {
  4787. const subgroupIndex = range(~n + 1, n).filter(j => j < 0 ? matrix[~j * n + i] : matrix[i * n + j]);
  4788. 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]));
  4789. for (const j of subgroupIndex) {
  4790. if (j < 0) {
  4791. const chord = chords[~j * n + i] || (chords[~j * n + i] = {source: null, target: null});
  4792. chord.target = {index: i, startAngle: x, endAngle: x += matrix[~j * n + i] * k, value: matrix[~j * n + i]};
  4793. } else {
  4794. const chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
  4795. chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  4796. }
  4797. }
  4798. groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
  4799. } else {
  4800. const subgroupIndex = range(0, n).filter(j => matrix[i * n + j] || matrix[j * n + i]);
  4801. if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(matrix[i * n + a], matrix[i * n + b]));
  4802. for (const j of subgroupIndex) {
  4803. let chord;
  4804. if (i < j) {
  4805. chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
  4806. chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  4807. } else {
  4808. chord = chords[j * n + i] || (chords[j * n + i] = {source: null, target: null});
  4809. chord.target = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  4810. if (i === j) chord.source = chord.target;
  4811. }
  4812. if (chord.source && chord.target && chord.source.value < chord.target.value) {
  4813. const source = chord.source;
  4814. chord.source = chord.target;
  4815. chord.target = source;
  4816. }
  4817. }
  4818. groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
  4819. }
  4820. x += dx;
  4821. }
  4822. }
  4823. // Remove empty chords.
  4824. chords = Object.values(chords);
  4825. chords.groups = groups;
  4826. return sortChords ? chords.sort(sortChords) : chords;
  4827. }
  4828. chord.padAngle = function(_) {
  4829. return arguments.length ? (padAngle = max$2(0, _), chord) : padAngle;
  4830. };
  4831. chord.sortGroups = function(_) {
  4832. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4833. };
  4834. chord.sortSubgroups = function(_) {
  4835. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4836. };
  4837. chord.sortChords = function(_) {
  4838. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4839. };
  4840. return chord;
  4841. }
  4842. const pi$2 = Math.PI,
  4843. tau$2 = 2 * pi$2,
  4844. epsilon$2 = 1e-6,
  4845. tauEpsilon = tau$2 - epsilon$2;
  4846. function Path() {
  4847. this._x0 = this._y0 = // start of current subpath
  4848. this._x1 = this._y1 = null; // end of current subpath
  4849. this._ = "";
  4850. }
  4851. function path() {
  4852. return new Path;
  4853. }
  4854. Path.prototype = path.prototype = {
  4855. constructor: Path,
  4856. moveTo: function(x, y) {
  4857. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4858. },
  4859. closePath: function() {
  4860. if (this._x1 !== null) {
  4861. this._x1 = this._x0, this._y1 = this._y0;
  4862. this._ += "Z";
  4863. }
  4864. },
  4865. lineTo: function(x, y) {
  4866. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4867. },
  4868. quadraticCurveTo: function(x1, y1, x, y) {
  4869. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4870. },
  4871. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4872. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4873. },
  4874. arcTo: function(x1, y1, x2, y2, r) {
  4875. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4876. var x0 = this._x1,
  4877. y0 = this._y1,
  4878. x21 = x2 - x1,
  4879. y21 = y2 - y1,
  4880. x01 = x0 - x1,
  4881. y01 = y0 - y1,
  4882. l01_2 = x01 * x01 + y01 * y01;
  4883. // Is the radius negative? Error.
  4884. if (r < 0) throw new Error("negative radius: " + r);
  4885. // Is this path empty? Move to (x1,y1).
  4886. if (this._x1 === null) {
  4887. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4888. }
  4889. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4890. else if (!(l01_2 > epsilon$2));
  4891. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4892. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4893. // Or, is the radius zero? Line to (x1,y1).
  4894. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$2) || !r) {
  4895. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4896. }
  4897. // Otherwise, draw an arc!
  4898. else {
  4899. var x20 = x2 - x0,
  4900. y20 = y2 - y0,
  4901. l21_2 = x21 * x21 + y21 * y21,
  4902. l20_2 = x20 * x20 + y20 * y20,
  4903. l21 = Math.sqrt(l21_2),
  4904. l01 = Math.sqrt(l01_2),
  4905. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4906. t01 = l / l01,
  4907. t21 = l / l21;
  4908. // If the start tangent is not coincident with (x0,y0), line to.
  4909. if (Math.abs(t01 - 1) > epsilon$2) {
  4910. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4911. }
  4912. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4913. }
  4914. },
  4915. arc: function(x, y, r, a0, a1, ccw) {
  4916. x = +x, y = +y, r = +r, ccw = !!ccw;
  4917. var dx = r * Math.cos(a0),
  4918. dy = r * Math.sin(a0),
  4919. x0 = x + dx,
  4920. y0 = y + dy,
  4921. cw = 1 ^ ccw,
  4922. da = ccw ? a0 - a1 : a1 - a0;
  4923. // Is the radius negative? Error.
  4924. if (r < 0) throw new Error("negative radius: " + r);
  4925. // Is this path empty? Move to (x0,y0).
  4926. if (this._x1 === null) {
  4927. this._ += "M" + x0 + "," + y0;
  4928. }
  4929. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4930. else if (Math.abs(this._x1 - x0) > epsilon$2 || Math.abs(this._y1 - y0) > epsilon$2) {
  4931. this._ += "L" + x0 + "," + y0;
  4932. }
  4933. // Is this arc empty? We’re done.
  4934. if (!r) return;
  4935. // Does the angle go the wrong way? Flip the direction.
  4936. if (da < 0) da = da % tau$2 + tau$2;
  4937. // Is this a complete circle? Draw two arcs to complete the circle.
  4938. if (da > tauEpsilon) {
  4939. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4940. }
  4941. // Is this arc non-empty? Draw an arc!
  4942. else if (da > epsilon$2) {
  4943. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4944. }
  4945. },
  4946. rect: function(x, y, w, h) {
  4947. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4948. },
  4949. toString: function() {
  4950. return this._;
  4951. }
  4952. };
  4953. var slice$2 = Array.prototype.slice;
  4954. function constant$5(x) {
  4955. return function() {
  4956. return x;
  4957. };
  4958. }
  4959. function defaultSource(d) {
  4960. return d.source;
  4961. }
  4962. function defaultTarget(d) {
  4963. return d.target;
  4964. }
  4965. function defaultRadius(d) {
  4966. return d.radius;
  4967. }
  4968. function defaultStartAngle(d) {
  4969. return d.startAngle;
  4970. }
  4971. function defaultEndAngle(d) {
  4972. return d.endAngle;
  4973. }
  4974. function defaultPadAngle() {
  4975. return 0;
  4976. }
  4977. function defaultArrowheadRadius() {
  4978. return 10;
  4979. }
  4980. function ribbon(headRadius) {
  4981. var source = defaultSource,
  4982. target = defaultTarget,
  4983. sourceRadius = defaultRadius,
  4984. targetRadius = defaultRadius,
  4985. startAngle = defaultStartAngle,
  4986. endAngle = defaultEndAngle,
  4987. padAngle = defaultPadAngle,
  4988. context = null;
  4989. function ribbon() {
  4990. var buffer,
  4991. s = source.apply(this, arguments),
  4992. t = target.apply(this, arguments),
  4993. ap = padAngle.apply(this, arguments) / 2,
  4994. argv = slice$2.call(arguments),
  4995. sr = +sourceRadius.apply(this, (argv[0] = s, argv)),
  4996. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4997. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4998. tr = +targetRadius.apply(this, (argv[0] = t, argv)),
  4999. ta0 = startAngle.apply(this, argv) - halfPi$1,
  5000. ta1 = endAngle.apply(this, argv) - halfPi$1;
  5001. if (!context) context = buffer = path();
  5002. if (ap > epsilon$1) {
  5003. if (abs$1(sa1 - sa0) > ap * 2 + epsilon$1) sa1 > sa0 ? (sa0 += ap, sa1 -= ap) : (sa0 -= ap, sa1 += ap);
  5004. else sa0 = sa1 = (sa0 + sa1) / 2;
  5005. if (abs$1(ta1 - ta0) > ap * 2 + epsilon$1) ta1 > ta0 ? (ta0 += ap, ta1 -= ap) : (ta0 -= ap, ta1 += ap);
  5006. else ta0 = ta1 = (ta0 + ta1) / 2;
  5007. }
  5008. context.moveTo(sr * cos(sa0), sr * sin(sa0));
  5009. context.arc(0, 0, sr, sa0, sa1);
  5010. if (sa0 !== ta0 || sa1 !== ta1) {
  5011. if (headRadius) {
  5012. var hr = +headRadius.apply(this, arguments), tr2 = tr - hr, ta2 = (ta0 + ta1) / 2;
  5013. context.quadraticCurveTo(0, 0, tr2 * cos(ta0), tr2 * sin(ta0));
  5014. context.lineTo(tr * cos(ta2), tr * sin(ta2));
  5015. context.lineTo(tr2 * cos(ta1), tr2 * sin(ta1));
  5016. } else {
  5017. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  5018. context.arc(0, 0, tr, ta0, ta1);
  5019. }
  5020. }
  5021. context.quadraticCurveTo(0, 0, sr * cos(sa0), sr * sin(sa0));
  5022. context.closePath();
  5023. if (buffer) return context = null, buffer + "" || null;
  5024. }
  5025. if (headRadius) ribbon.headRadius = function(_) {
  5026. return arguments.length ? (headRadius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : headRadius;
  5027. };
  5028. ribbon.radius = function(_) {
  5029. return arguments.length ? (sourceRadius = targetRadius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : sourceRadius;
  5030. };
  5031. ribbon.sourceRadius = function(_) {
  5032. return arguments.length ? (sourceRadius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : sourceRadius;
  5033. };
  5034. ribbon.targetRadius = function(_) {
  5035. return arguments.length ? (targetRadius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : targetRadius;
  5036. };
  5037. ribbon.startAngle = function(_) {
  5038. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  5039. };
  5040. ribbon.endAngle = function(_) {
  5041. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  5042. };
  5043. ribbon.padAngle = function(_) {
  5044. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : padAngle;
  5045. };
  5046. ribbon.source = function(_) {
  5047. return arguments.length ? (source = _, ribbon) : source;
  5048. };
  5049. ribbon.target = function(_) {
  5050. return arguments.length ? (target = _, ribbon) : target;
  5051. };
  5052. ribbon.context = function(_) {
  5053. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  5054. };
  5055. return ribbon;
  5056. }
  5057. function ribbon$1() {
  5058. return ribbon();
  5059. }
  5060. function ribbonArrow() {
  5061. return ribbon(defaultArrowheadRadius);
  5062. }
  5063. var array$3 = Array.prototype;
  5064. var slice$3 = array$3.slice;
  5065. function ascending$2(a, b) {
  5066. return a - b;
  5067. }
  5068. function area(ring) {
  5069. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  5070. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  5071. return area;
  5072. }
  5073. var constant$6 = x => () => x;
  5074. function contains(ring, hole) {
  5075. var i = -1, n = hole.length, c;
  5076. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  5077. return 0;
  5078. }
  5079. function ringContains(ring, point) {
  5080. var x = point[0], y = point[1], contains = -1;
  5081. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  5082. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  5083. if (segmentContains(pi, pj, point)) return 0;
  5084. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  5085. }
  5086. return contains;
  5087. }
  5088. function segmentContains(a, b, c) {
  5089. var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  5090. }
  5091. function collinear(a, b, c) {
  5092. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  5093. }
  5094. function within(p, q, r) {
  5095. return p <= q && q <= r || r <= q && q <= p;
  5096. }
  5097. function noop$1() {}
  5098. var cases = [
  5099. [],
  5100. [[[1.0, 1.5], [0.5, 1.0]]],
  5101. [[[1.5, 1.0], [1.0, 1.5]]],
  5102. [[[1.5, 1.0], [0.5, 1.0]]],
  5103. [[[1.0, 0.5], [1.5, 1.0]]],
  5104. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  5105. [[[1.0, 0.5], [1.0, 1.5]]],
  5106. [[[1.0, 0.5], [0.5, 1.0]]],
  5107. [[[0.5, 1.0], [1.0, 0.5]]],
  5108. [[[1.0, 1.5], [1.0, 0.5]]],
  5109. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  5110. [[[1.5, 1.0], [1.0, 0.5]]],
  5111. [[[0.5, 1.0], [1.5, 1.0]]],
  5112. [[[1.0, 1.5], [1.5, 1.0]]],
  5113. [[[0.5, 1.0], [1.0, 1.5]]],
  5114. []
  5115. ];
  5116. function contours() {
  5117. var dx = 1,
  5118. dy = 1,
  5119. threshold = thresholdSturges,
  5120. smooth = smoothLinear;
  5121. function contours(values) {
  5122. var tz = threshold(values);
  5123. // Convert number of thresholds into uniform thresholds.
  5124. if (!Array.isArray(tz)) {
  5125. var domain = extent(values), start = domain[0], stop = domain[1];
  5126. tz = tickStep(start, stop, tz);
  5127. tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
  5128. } else {
  5129. tz = tz.slice().sort(ascending$2);
  5130. }
  5131. return tz.map(function(value) {
  5132. return contour(values, value);
  5133. });
  5134. }
  5135. // Accumulate, smooth contour rings, assign holes to exterior rings.
  5136. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  5137. function contour(values, value) {
  5138. var polygons = [],
  5139. holes = [];
  5140. isorings(values, value, function(ring) {
  5141. smooth(ring, values, value);
  5142. if (area(ring) > 0) polygons.push([ring]);
  5143. else holes.push(ring);
  5144. });
  5145. holes.forEach(function(hole) {
  5146. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  5147. if (contains((polygon = polygons[i])[0], hole) !== -1) {
  5148. polygon.push(hole);
  5149. return;
  5150. }
  5151. }
  5152. });
  5153. return {
  5154. type: "MultiPolygon",
  5155. value: value,
  5156. coordinates: polygons
  5157. };
  5158. }
  5159. // Marching squares with isolines stitched into rings.
  5160. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  5161. function isorings(values, value, callback) {
  5162. var fragmentByStart = new Array,
  5163. fragmentByEnd = new Array,
  5164. x, y, t0, t1, t2, t3;
  5165. // Special case for the first row (y = -1, t2 = t3 = 0).
  5166. x = y = -1;
  5167. t1 = values[0] >= value;
  5168. cases[t1 << 1].forEach(stitch);
  5169. while (++x < dx - 1) {
  5170. t0 = t1, t1 = values[x + 1] >= value;
  5171. cases[t0 | t1 << 1].forEach(stitch);
  5172. }
  5173. cases[t1 << 0].forEach(stitch);
  5174. // General case for the intermediate rows.
  5175. while (++y < dy - 1) {
  5176. x = -1;
  5177. t1 = values[y * dx + dx] >= value;
  5178. t2 = values[y * dx] >= value;
  5179. cases[t1 << 1 | t2 << 2].forEach(stitch);
  5180. while (++x < dx - 1) {
  5181. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  5182. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  5183. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  5184. }
  5185. cases[t1 | t2 << 3].forEach(stitch);
  5186. }
  5187. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  5188. x = -1;
  5189. t2 = values[y * dx] >= value;
  5190. cases[t2 << 2].forEach(stitch);
  5191. while (++x < dx - 1) {
  5192. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  5193. cases[t2 << 2 | t3 << 3].forEach(stitch);
  5194. }
  5195. cases[t2 << 3].forEach(stitch);
  5196. function stitch(line) {
  5197. var start = [line[0][0] + x, line[0][1] + y],
  5198. end = [line[1][0] + x, line[1][1] + y],
  5199. startIndex = index(start),
  5200. endIndex = index(end),
  5201. f, g;
  5202. if (f = fragmentByEnd[startIndex]) {
  5203. if (g = fragmentByStart[endIndex]) {
  5204. delete fragmentByEnd[f.end];
  5205. delete fragmentByStart[g.start];
  5206. if (f === g) {
  5207. f.ring.push(end);
  5208. callback(f.ring);
  5209. } else {
  5210. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  5211. }
  5212. } else {
  5213. delete fragmentByEnd[f.end];
  5214. f.ring.push(end);
  5215. fragmentByEnd[f.end = endIndex] = f;
  5216. }
  5217. } else if (f = fragmentByStart[endIndex]) {
  5218. if (g = fragmentByEnd[startIndex]) {
  5219. delete fragmentByStart[f.start];
  5220. delete fragmentByEnd[g.end];
  5221. if (f === g) {
  5222. f.ring.push(end);
  5223. callback(f.ring);
  5224. } else {
  5225. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  5226. }
  5227. } else {
  5228. delete fragmentByStart[f.start];
  5229. f.ring.unshift(start);
  5230. fragmentByStart[f.start = startIndex] = f;
  5231. }
  5232. } else {
  5233. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  5234. }
  5235. }
  5236. }
  5237. function index(point) {
  5238. return point[0] * 2 + point[1] * (dx + 1) * 4;
  5239. }
  5240. function smoothLinear(ring, values, value) {
  5241. ring.forEach(function(point) {
  5242. var x = point[0],
  5243. y = point[1],
  5244. xt = x | 0,
  5245. yt = y | 0,
  5246. v0,
  5247. v1 = values[yt * dx + xt];
  5248. if (x > 0 && x < dx && xt === x) {
  5249. v0 = values[yt * dx + xt - 1];
  5250. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  5251. }
  5252. if (y > 0 && y < dy && yt === y) {
  5253. v0 = values[(yt - 1) * dx + xt];
  5254. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  5255. }
  5256. });
  5257. }
  5258. contours.contour = contour;
  5259. contours.size = function(_) {
  5260. if (!arguments.length) return [dx, dy];
  5261. var _0 = Math.floor(_[0]), _1 = Math.floor(_[1]);
  5262. if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
  5263. return dx = _0, dy = _1, contours;
  5264. };
  5265. contours.thresholds = function(_) {
  5266. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold;
  5267. };
  5268. contours.smooth = function(_) {
  5269. return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
  5270. };
  5271. return contours;
  5272. }
  5273. // TODO Optimize edge cases.
  5274. // TODO Optimize index calculation.
  5275. // TODO Optimize arguments.
  5276. function blurX(source, target, r) {
  5277. var n = source.width,
  5278. m = source.height,
  5279. w = (r << 1) + 1;
  5280. for (var j = 0; j < m; ++j) {
  5281. for (var i = 0, sr = 0; i < n + r; ++i) {
  5282. if (i < n) {
  5283. sr += source.data[i + j * n];
  5284. }
  5285. if (i >= r) {
  5286. if (i >= w) {
  5287. sr -= source.data[i - w + j * n];
  5288. }
  5289. target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
  5290. }
  5291. }
  5292. }
  5293. }
  5294. // TODO Optimize edge cases.
  5295. // TODO Optimize index calculation.
  5296. // TODO Optimize arguments.
  5297. function blurY(source, target, r) {
  5298. var n = source.width,
  5299. m = source.height,
  5300. w = (r << 1) + 1;
  5301. for (var i = 0; i < n; ++i) {
  5302. for (var j = 0, sr = 0; j < m + r; ++j) {
  5303. if (j < m) {
  5304. sr += source.data[i + j * n];
  5305. }
  5306. if (j >= r) {
  5307. if (j >= w) {
  5308. sr -= source.data[i + (j - w) * n];
  5309. }
  5310. target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
  5311. }
  5312. }
  5313. }
  5314. }
  5315. function defaultX(d) {
  5316. return d[0];
  5317. }
  5318. function defaultY(d) {
  5319. return d[1];
  5320. }
  5321. function defaultWeight() {
  5322. return 1;
  5323. }
  5324. function density() {
  5325. var x = defaultX,
  5326. y = defaultY,
  5327. weight = defaultWeight,
  5328. dx = 960,
  5329. dy = 500,
  5330. r = 20, // blur radius
  5331. k = 2, // log2(grid cell size)
  5332. o = r * 3, // grid offset, to pad for blur
  5333. n = (dx + o * 2) >> k, // grid width
  5334. m = (dy + o * 2) >> k, // grid height
  5335. threshold = constant$6(20);
  5336. function density(data) {
  5337. var values0 = new Float32Array(n * m),
  5338. values1 = new Float32Array(n * m);
  5339. data.forEach(function(d, i, data) {
  5340. var xi = (+x(d, i, data) + o) >> k,
  5341. yi = (+y(d, i, data) + o) >> k,
  5342. wi = +weight(d, i, data);
  5343. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  5344. values0[xi + yi * n] += wi;
  5345. }
  5346. });
  5347. // TODO Optimize.
  5348. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  5349. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  5350. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  5351. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  5352. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  5353. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  5354. var tz = threshold(values0);
  5355. // Convert number of thresholds into uniform thresholds.
  5356. if (!Array.isArray(tz)) {
  5357. var stop = max(values0);
  5358. tz = tickStep(0, stop, tz);
  5359. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  5360. tz.shift();
  5361. }
  5362. return contours()
  5363. .thresholds(tz)
  5364. .size([n, m])
  5365. (values0)
  5366. .map(transform);
  5367. }
  5368. function transform(geometry) {
  5369. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  5370. geometry.coordinates.forEach(transformPolygon);
  5371. return geometry;
  5372. }
  5373. function transformPolygon(coordinates) {
  5374. coordinates.forEach(transformRing);
  5375. }
  5376. function transformRing(coordinates) {
  5377. coordinates.forEach(transformPoint);
  5378. }
  5379. // TODO Optimize.
  5380. function transformPoint(coordinates) {
  5381. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  5382. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  5383. }
  5384. function resize() {
  5385. o = r * 3;
  5386. n = (dx + o * 2) >> k;
  5387. m = (dy + o * 2) >> k;
  5388. return density;
  5389. }
  5390. density.x = function(_) {
  5391. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  5392. };
  5393. density.y = function(_) {
  5394. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  5395. };
  5396. density.weight = function(_) {
  5397. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
  5398. };
  5399. density.size = function(_) {
  5400. if (!arguments.length) return [dx, dy];
  5401. var _0 = +_[0], _1 = +_[1];
  5402. if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
  5403. return dx = _0, dy = _1, resize();
  5404. };
  5405. density.cellSize = function(_) {
  5406. if (!arguments.length) return 1 << k;
  5407. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  5408. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  5409. };
  5410. density.thresholds = function(_) {
  5411. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold;
  5412. };
  5413. density.bandwidth = function(_) {
  5414. if (!arguments.length) return Math.sqrt(r * (r + 1));
  5415. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  5416. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  5417. };
  5418. return density;
  5419. }
  5420. const EPSILON = Math.pow(2, -52);
  5421. const EDGE_STACK = new Uint32Array(512);
  5422. class Delaunator {
  5423. static from(points, getX = defaultGetX, getY = defaultGetY) {
  5424. const n = points.length;
  5425. const coords = new Float64Array(n * 2);
  5426. for (let i = 0; i < n; i++) {
  5427. const p = points[i];
  5428. coords[2 * i] = getX(p);
  5429. coords[2 * i + 1] = getY(p);
  5430. }
  5431. return new Delaunator(coords);
  5432. }
  5433. constructor(coords) {
  5434. const n = coords.length >> 1;
  5435. if (n > 0 && typeof coords[0] !== 'number') throw new Error('Expected coords to contain numbers.');
  5436. this.coords = coords;
  5437. // arrays that will store the triangulation graph
  5438. const maxTriangles = Math.max(2 * n - 5, 0);
  5439. this._triangles = new Uint32Array(maxTriangles * 3);
  5440. this._halfedges = new Int32Array(maxTriangles * 3);
  5441. // temporary arrays for tracking the edges of the advancing convex hull
  5442. this._hashSize = Math.ceil(Math.sqrt(n));
  5443. this._hullPrev = new Uint32Array(n); // edge to prev edge
  5444. this._hullNext = new Uint32Array(n); // edge to next edge
  5445. this._hullTri = new Uint32Array(n); // edge to adjacent triangle
  5446. this._hullHash = new Int32Array(this._hashSize).fill(-1); // angular edge hash
  5447. // temporary arrays for sorting points
  5448. this._ids = new Uint32Array(n);
  5449. this._dists = new Float64Array(n);
  5450. this.update();
  5451. }
  5452. update() {
  5453. const {coords, _hullPrev: hullPrev, _hullNext: hullNext, _hullTri: hullTri, _hullHash: hullHash} = this;
  5454. const n = coords.length >> 1;
  5455. // populate an array of point indices; calculate input data bbox
  5456. let minX = Infinity;
  5457. let minY = Infinity;
  5458. let maxX = -Infinity;
  5459. let maxY = -Infinity;
  5460. for (let i = 0; i < n; i++) {
  5461. const x = coords[2 * i];
  5462. const y = coords[2 * i + 1];
  5463. if (x < minX) minX = x;
  5464. if (y < minY) minY = y;
  5465. if (x > maxX) maxX = x;
  5466. if (y > maxY) maxY = y;
  5467. this._ids[i] = i;
  5468. }
  5469. const cx = (minX + maxX) / 2;
  5470. const cy = (minY + maxY) / 2;
  5471. let minDist = Infinity;
  5472. let i0, i1, i2;
  5473. // pick a seed point close to the center
  5474. for (let i = 0; i < n; i++) {
  5475. const d = dist(cx, cy, coords[2 * i], coords[2 * i + 1]);
  5476. if (d < minDist) {
  5477. i0 = i;
  5478. minDist = d;
  5479. }
  5480. }
  5481. const i0x = coords[2 * i0];
  5482. const i0y = coords[2 * i0 + 1];
  5483. minDist = Infinity;
  5484. // find the point closest to the seed
  5485. for (let i = 0; i < n; i++) {
  5486. if (i === i0) continue;
  5487. const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
  5488. if (d < minDist && d > 0) {
  5489. i1 = i;
  5490. minDist = d;
  5491. }
  5492. }
  5493. let i1x = coords[2 * i1];
  5494. let i1y = coords[2 * i1 + 1];
  5495. let minRadius = Infinity;
  5496. // find the third point which forms the smallest circumcircle with the first two
  5497. for (let i = 0; i < n; i++) {
  5498. if (i === i0 || i === i1) continue;
  5499. const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
  5500. if (r < minRadius) {
  5501. i2 = i;
  5502. minRadius = r;
  5503. }
  5504. }
  5505. let i2x = coords[2 * i2];
  5506. let i2y = coords[2 * i2 + 1];
  5507. if (minRadius === Infinity) {
  5508. // order collinear points by dx (or dy if all x are identical)
  5509. // and return the list as a hull
  5510. for (let i = 0; i < n; i++) {
  5511. this._dists[i] = (coords[2 * i] - coords[0]) || (coords[2 * i + 1] - coords[1]);
  5512. }
  5513. quicksort(this._ids, this._dists, 0, n - 1);
  5514. const hull = new Uint32Array(n);
  5515. let j = 0;
  5516. for (let i = 0, d0 = -Infinity; i < n; i++) {
  5517. const id = this._ids[i];
  5518. if (this._dists[id] > d0) {
  5519. hull[j++] = id;
  5520. d0 = this._dists[id];
  5521. }
  5522. }
  5523. this.hull = hull.subarray(0, j);
  5524. this.triangles = new Uint32Array(0);
  5525. this.halfedges = new Uint32Array(0);
  5526. return;
  5527. }
  5528. // swap the order of the seed points for counter-clockwise orientation
  5529. if (orient(i0x, i0y, i1x, i1y, i2x, i2y)) {
  5530. const i = i1;
  5531. const x = i1x;
  5532. const y = i1y;
  5533. i1 = i2;
  5534. i1x = i2x;
  5535. i1y = i2y;
  5536. i2 = i;
  5537. i2x = x;
  5538. i2y = y;
  5539. }
  5540. const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
  5541. this._cx = center.x;
  5542. this._cy = center.y;
  5543. for (let i = 0; i < n; i++) {
  5544. this._dists[i] = dist(coords[2 * i], coords[2 * i + 1], center.x, center.y);
  5545. }
  5546. // sort the points by distance from the seed triangle circumcenter
  5547. quicksort(this._ids, this._dists, 0, n - 1);
  5548. // set up the seed triangle as the starting hull
  5549. this._hullStart = i0;
  5550. let hullSize = 3;
  5551. hullNext[i0] = hullPrev[i2] = i1;
  5552. hullNext[i1] = hullPrev[i0] = i2;
  5553. hullNext[i2] = hullPrev[i1] = i0;
  5554. hullTri[i0] = 0;
  5555. hullTri[i1] = 1;
  5556. hullTri[i2] = 2;
  5557. hullHash.fill(-1);
  5558. hullHash[this._hashKey(i0x, i0y)] = i0;
  5559. hullHash[this._hashKey(i1x, i1y)] = i1;
  5560. hullHash[this._hashKey(i2x, i2y)] = i2;
  5561. this.trianglesLen = 0;
  5562. this._addTriangle(i0, i1, i2, -1, -1, -1);
  5563. for (let k = 0, xp, yp; k < this._ids.length; k++) {
  5564. const i = this._ids[k];
  5565. const x = coords[2 * i];
  5566. const y = coords[2 * i + 1];
  5567. // skip near-duplicate points
  5568. if (k > 0 && Math.abs(x - xp) <= EPSILON && Math.abs(y - yp) <= EPSILON) continue;
  5569. xp = x;
  5570. yp = y;
  5571. // skip seed triangle points
  5572. if (i === i0 || i === i1 || i === i2) continue;
  5573. // find a visible edge on the convex hull using edge hash
  5574. let start = 0;
  5575. for (let j = 0, key = this._hashKey(x, y); j < this._hashSize; j++) {
  5576. start = hullHash[(key + j) % this._hashSize];
  5577. if (start !== -1 && start !== hullNext[start]) break;
  5578. }
  5579. start = hullPrev[start];
  5580. let e = start, q;
  5581. while (q = hullNext[e], !orient(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1])) {
  5582. e = q;
  5583. if (e === start) {
  5584. e = -1;
  5585. break;
  5586. }
  5587. }
  5588. if (e === -1) continue; // likely a near-duplicate point; skip it
  5589. // add the first triangle from the point
  5590. let t = this._addTriangle(e, i, hullNext[e], -1, -1, hullTri[e]);
  5591. // recursively flip triangles from the point until they satisfy the Delaunay condition
  5592. hullTri[i] = this._legalize(t + 2);
  5593. hullTri[e] = t; // keep track of boundary triangles on the hull
  5594. hullSize++;
  5595. // walk forward through the hull, adding more triangles and flipping recursively
  5596. let n = hullNext[e];
  5597. while (q = hullNext[n], orient(x, y, coords[2 * n], coords[2 * n + 1], coords[2 * q], coords[2 * q + 1])) {
  5598. t = this._addTriangle(n, i, q, hullTri[i], -1, hullTri[n]);
  5599. hullTri[i] = this._legalize(t + 2);
  5600. hullNext[n] = n; // mark as removed
  5601. hullSize--;
  5602. n = q;
  5603. }
  5604. // walk backward from the other side, adding more triangles and flipping
  5605. if (e === start) {
  5606. while (q = hullPrev[e], orient(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1])) {
  5607. t = this._addTriangle(q, i, e, -1, hullTri[e], hullTri[q]);
  5608. this._legalize(t + 2);
  5609. hullTri[q] = t;
  5610. hullNext[e] = e; // mark as removed
  5611. hullSize--;
  5612. e = q;
  5613. }
  5614. }
  5615. // update the hull indices
  5616. this._hullStart = hullPrev[i] = e;
  5617. hullNext[e] = hullPrev[n] = i;
  5618. hullNext[i] = n;
  5619. // save the two new edges in the hash table
  5620. hullHash[this._hashKey(x, y)] = i;
  5621. hullHash[this._hashKey(coords[2 * e], coords[2 * e + 1])] = e;
  5622. }
  5623. this.hull = new Uint32Array(hullSize);
  5624. for (let i = 0, e = this._hullStart; i < hullSize; i++) {
  5625. this.hull[i] = e;
  5626. e = hullNext[e];
  5627. }
  5628. // trim typed triangle mesh arrays
  5629. this.triangles = this._triangles.subarray(0, this.trianglesLen);
  5630. this.halfedges = this._halfedges.subarray(0, this.trianglesLen);
  5631. }
  5632. _hashKey(x, y) {
  5633. return Math.floor(pseudoAngle(x - this._cx, y - this._cy) * this._hashSize) % this._hashSize;
  5634. }
  5635. _legalize(a) {
  5636. const {_triangles: triangles, _halfedges: halfedges, coords} = this;
  5637. let i = 0;
  5638. let ar = 0;
  5639. // recursion eliminated with a fixed-size stack
  5640. while (true) {
  5641. const b = halfedges[a];
  5642. /* if the pair of triangles doesn't satisfy the Delaunay condition
  5643. * (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
  5644. * then do the same check/flip recursively for the new pair of triangles
  5645. *
  5646. * pl pl
  5647. * /||\ / \
  5648. * al/ || \bl al/ \a
  5649. * / || \ / \
  5650. * / a||b \ flip /___ar___\
  5651. * p0\ || /p1 => p0\---bl---/p1
  5652. * \ || / \ /
  5653. * ar\ || /br b\ /br
  5654. * \||/ \ /
  5655. * pr pr
  5656. */
  5657. const a0 = a - a % 3;
  5658. ar = a0 + (a + 2) % 3;
  5659. if (b === -1) { // convex hull edge
  5660. if (i === 0) break;
  5661. a = EDGE_STACK[--i];
  5662. continue;
  5663. }
  5664. const b0 = b - b % 3;
  5665. const al = a0 + (a + 1) % 3;
  5666. const bl = b0 + (b + 2) % 3;
  5667. const p0 = triangles[ar];
  5668. const pr = triangles[a];
  5669. const pl = triangles[al];
  5670. const p1 = triangles[bl];
  5671. const illegal = inCircle(
  5672. coords[2 * p0], coords[2 * p0 + 1],
  5673. coords[2 * pr], coords[2 * pr + 1],
  5674. coords[2 * pl], coords[2 * pl + 1],
  5675. coords[2 * p1], coords[2 * p1 + 1]);
  5676. if (illegal) {
  5677. triangles[a] = p1;
  5678. triangles[b] = p0;
  5679. const hbl = halfedges[bl];
  5680. // edge swapped on the other side of the hull (rare); fix the halfedge reference
  5681. if (hbl === -1) {
  5682. let e = this._hullStart;
  5683. do {
  5684. if (this._hullTri[e] === bl) {
  5685. this._hullTri[e] = a;
  5686. break;
  5687. }
  5688. e = this._hullPrev[e];
  5689. } while (e !== this._hullStart);
  5690. }
  5691. this._link(a, hbl);
  5692. this._link(b, halfedges[ar]);
  5693. this._link(ar, bl);
  5694. const br = b0 + (b + 1) % 3;
  5695. // don't worry about hitting the cap: it can only happen on extremely degenerate input
  5696. if (i < EDGE_STACK.length) {
  5697. EDGE_STACK[i++] = br;
  5698. }
  5699. } else {
  5700. if (i === 0) break;
  5701. a = EDGE_STACK[--i];
  5702. }
  5703. }
  5704. return ar;
  5705. }
  5706. _link(a, b) {
  5707. this._halfedges[a] = b;
  5708. if (b !== -1) this._halfedges[b] = a;
  5709. }
  5710. // add a new triangle given vertex indices and adjacent half-edge ids
  5711. _addTriangle(i0, i1, i2, a, b, c) {
  5712. const t = this.trianglesLen;
  5713. this._triangles[t] = i0;
  5714. this._triangles[t + 1] = i1;
  5715. this._triangles[t + 2] = i2;
  5716. this._link(t, a);
  5717. this._link(t + 1, b);
  5718. this._link(t + 2, c);
  5719. this.trianglesLen += 3;
  5720. return t;
  5721. }
  5722. }
  5723. // monotonically increases with real angle, but doesn't need expensive trigonometry
  5724. function pseudoAngle(dx, dy) {
  5725. const p = dx / (Math.abs(dx) + Math.abs(dy));
  5726. return (dy > 0 ? 3 - p : 1 + p) / 4; // [0..1]
  5727. }
  5728. function dist(ax, ay, bx, by) {
  5729. const dx = ax - bx;
  5730. const dy = ay - by;
  5731. return dx * dx + dy * dy;
  5732. }
  5733. // return 2d orientation sign if we're confident in it through J. Shewchuk's error bound check
  5734. function orientIfSure(px, py, rx, ry, qx, qy) {
  5735. const l = (ry - py) * (qx - px);
  5736. const r = (rx - px) * (qy - py);
  5737. return Math.abs(l - r) >= 3.3306690738754716e-16 * Math.abs(l + r) ? l - r : 0;
  5738. }
  5739. // a more robust orientation test that's stable in a given triangle (to fix robustness issues)
  5740. function orient(rx, ry, qx, qy, px, py) {
  5741. const sign = orientIfSure(px, py, rx, ry, qx, qy) ||
  5742. orientIfSure(rx, ry, qx, qy, px, py) ||
  5743. orientIfSure(qx, qy, px, py, rx, ry);
  5744. return sign < 0;
  5745. }
  5746. function inCircle(ax, ay, bx, by, cx, cy, px, py) {
  5747. const dx = ax - px;
  5748. const dy = ay - py;
  5749. const ex = bx - px;
  5750. const ey = by - py;
  5751. const fx = cx - px;
  5752. const fy = cy - py;
  5753. const ap = dx * dx + dy * dy;
  5754. const bp = ex * ex + ey * ey;
  5755. const cp = fx * fx + fy * fy;
  5756. return dx * (ey * cp - bp * fy) -
  5757. dy * (ex * cp - bp * fx) +
  5758. ap * (ex * fy - ey * fx) < 0;
  5759. }
  5760. function circumradius(ax, ay, bx, by, cx, cy) {
  5761. const dx = bx - ax;
  5762. const dy = by - ay;
  5763. const ex = cx - ax;
  5764. const ey = cy - ay;
  5765. const bl = dx * dx + dy * dy;
  5766. const cl = ex * ex + ey * ey;
  5767. const d = 0.5 / (dx * ey - dy * ex);
  5768. const x = (ey * bl - dy * cl) * d;
  5769. const y = (dx * cl - ex * bl) * d;
  5770. return x * x + y * y;
  5771. }
  5772. function circumcenter(ax, ay, bx, by, cx, cy) {
  5773. const dx = bx - ax;
  5774. const dy = by - ay;
  5775. const ex = cx - ax;
  5776. const ey = cy - ay;
  5777. const bl = dx * dx + dy * dy;
  5778. const cl = ex * ex + ey * ey;
  5779. const d = 0.5 / (dx * ey - dy * ex);
  5780. const x = ax + (ey * bl - dy * cl) * d;
  5781. const y = ay + (dx * cl - ex * bl) * d;
  5782. return {x, y};
  5783. }
  5784. function quicksort(ids, dists, left, right) {
  5785. if (right - left <= 20) {
  5786. for (let i = left + 1; i <= right; i++) {
  5787. const temp = ids[i];
  5788. const tempDist = dists[temp];
  5789. let j = i - 1;
  5790. while (j >= left && dists[ids[j]] > tempDist) ids[j + 1] = ids[j--];
  5791. ids[j + 1] = temp;
  5792. }
  5793. } else {
  5794. const median = (left + right) >> 1;
  5795. let i = left + 1;
  5796. let j = right;
  5797. swap$1(ids, median, i);
  5798. if (dists[ids[left]] > dists[ids[right]]) swap$1(ids, left, right);
  5799. if (dists[ids[i]] > dists[ids[right]]) swap$1(ids, i, right);
  5800. if (dists[ids[left]] > dists[ids[i]]) swap$1(ids, left, i);
  5801. const temp = ids[i];
  5802. const tempDist = dists[temp];
  5803. while (true) {
  5804. do i++; while (dists[ids[i]] < tempDist);
  5805. do j--; while (dists[ids[j]] > tempDist);
  5806. if (j < i) break;
  5807. swap$1(ids, i, j);
  5808. }
  5809. ids[left + 1] = ids[j];
  5810. ids[j] = temp;
  5811. if (right - i + 1 >= j - left) {
  5812. quicksort(ids, dists, i, right);
  5813. quicksort(ids, dists, left, j - 1);
  5814. } else {
  5815. quicksort(ids, dists, left, j - 1);
  5816. quicksort(ids, dists, i, right);
  5817. }
  5818. }
  5819. }
  5820. function swap$1(arr, i, j) {
  5821. const tmp = arr[i];
  5822. arr[i] = arr[j];
  5823. arr[j] = tmp;
  5824. }
  5825. function defaultGetX(p) {
  5826. return p[0];
  5827. }
  5828. function defaultGetY(p) {
  5829. return p[1];
  5830. }
  5831. const epsilon$3 = 1e-6;
  5832. class Path$1 {
  5833. constructor() {
  5834. this._x0 = this._y0 = // start of current subpath
  5835. this._x1 = this._y1 = null; // end of current subpath
  5836. this._ = "";
  5837. }
  5838. moveTo(x, y) {
  5839. this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
  5840. }
  5841. closePath() {
  5842. if (this._x1 !== null) {
  5843. this._x1 = this._x0, this._y1 = this._y0;
  5844. this._ += "Z";
  5845. }
  5846. }
  5847. lineTo(x, y) {
  5848. this._ += `L${this._x1 = +x},${this._y1 = +y}`;
  5849. }
  5850. arc(x, y, r) {
  5851. x = +x, y = +y, r = +r;
  5852. const x0 = x + r;
  5853. const y0 = y;
  5854. if (r < 0) throw new Error("negative radius");
  5855. if (this._x1 === null) this._ += `M${x0},${y0}`;
  5856. else if (Math.abs(this._x1 - x0) > epsilon$3 || Math.abs(this._y1 - y0) > epsilon$3) this._ += "L" + x0 + "," + y0;
  5857. if (!r) return;
  5858. this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`;
  5859. }
  5860. rect(x, y, w, h) {
  5861. this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`;
  5862. }
  5863. value() {
  5864. return this._ || null;
  5865. }
  5866. }
  5867. class Polygon {
  5868. constructor() {
  5869. this._ = [];
  5870. }
  5871. moveTo(x, y) {
  5872. this._.push([x, y]);
  5873. }
  5874. closePath() {
  5875. this._.push(this._[0].slice());
  5876. }
  5877. lineTo(x, y) {
  5878. this._.push([x, y]);
  5879. }
  5880. value() {
  5881. return this._.length ? this._ : null;
  5882. }
  5883. }
  5884. class Voronoi {
  5885. constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) {
  5886. if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds");
  5887. this.delaunay = delaunay;
  5888. this._circumcenters = new Float64Array(delaunay.points.length * 2);
  5889. this.vectors = new Float64Array(delaunay.points.length * 2);
  5890. this.xmax = xmax, this.xmin = xmin;
  5891. this.ymax = ymax, this.ymin = ymin;
  5892. this._init();
  5893. }
  5894. update() {
  5895. this.delaunay.update();
  5896. this._init();
  5897. return this;
  5898. }
  5899. _init() {
  5900. const {delaunay: {points, hull, triangles}, vectors} = this;
  5901. // Compute circumcenters.
  5902. const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2);
  5903. for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
  5904. const t1 = triangles[i] * 2;
  5905. const t2 = triangles[i + 1] * 2;
  5906. const t3 = triangles[i + 2] * 2;
  5907. const x1 = points[t1];
  5908. const y1 = points[t1 + 1];
  5909. const x2 = points[t2];
  5910. const y2 = points[t2 + 1];
  5911. const x3 = points[t3];
  5912. const y3 = points[t3 + 1];
  5913. const dx = x2 - x1;
  5914. const dy = y2 - y1;
  5915. const ex = x3 - x1;
  5916. const ey = y3 - y1;
  5917. const bl = dx * dx + dy * dy;
  5918. const cl = ex * ex + ey * ey;
  5919. const ab = (dx * ey - dy * ex) * 2;
  5920. if (!ab) {
  5921. // degenerate case (collinear diagram)
  5922. x = (x1 + x3) / 2 - 1e8 * ey;
  5923. y = (y1 + y3) / 2 + 1e8 * ex;
  5924. }
  5925. else if (Math.abs(ab) < 1e-8) {
  5926. // almost equal points (degenerate triangle)
  5927. x = (x1 + x3) / 2;
  5928. y = (y1 + y3) / 2;
  5929. } else {
  5930. const d = 1 / ab;
  5931. x = x1 + (ey * bl - dy * cl) * d;
  5932. y = y1 + (dx * cl - ex * bl) * d;
  5933. }
  5934. circumcenters[j] = x;
  5935. circumcenters[j + 1] = y;
  5936. }
  5937. // Compute exterior cell rays.
  5938. let h = hull[hull.length - 1];
  5939. let p0, p1 = h * 4;
  5940. let x0, x1 = points[2 * h];
  5941. let y0, y1 = points[2 * h + 1];
  5942. vectors.fill(0);
  5943. for (let i = 0; i < hull.length; ++i) {
  5944. h = hull[i];
  5945. p0 = p1, x0 = x1, y0 = y1;
  5946. p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1];
  5947. vectors[p0 + 2] = vectors[p1] = y0 - y1;
  5948. vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
  5949. }
  5950. }
  5951. render(context) {
  5952. const buffer = context == null ? context = new Path$1 : undefined;
  5953. const {delaunay: {halfedges, inedges, hull}, circumcenters, vectors} = this;
  5954. if (hull.length <= 1) return null;
  5955. for (let i = 0, n = halfedges.length; i < n; ++i) {
  5956. const j = halfedges[i];
  5957. if (j < i) continue;
  5958. const ti = Math.floor(i / 3) * 2;
  5959. const tj = Math.floor(j / 3) * 2;
  5960. const xi = circumcenters[ti];
  5961. const yi = circumcenters[ti + 1];
  5962. const xj = circumcenters[tj];
  5963. const yj = circumcenters[tj + 1];
  5964. this._renderSegment(xi, yi, xj, yj, context);
  5965. }
  5966. let h0, h1 = hull[hull.length - 1];
  5967. for (let i = 0; i < hull.length; ++i) {
  5968. h0 = h1, h1 = hull[i];
  5969. const t = Math.floor(inedges[h1] / 3) * 2;
  5970. const x = circumcenters[t];
  5971. const y = circumcenters[t + 1];
  5972. const v = h0 * 4;
  5973. const p = this._project(x, y, vectors[v + 2], vectors[v + 3]);
  5974. if (p) this._renderSegment(x, y, p[0], p[1], context);
  5975. }
  5976. return buffer && buffer.value();
  5977. }
  5978. renderBounds(context) {
  5979. const buffer = context == null ? context = new Path$1 : undefined;
  5980. context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin);
  5981. return buffer && buffer.value();
  5982. }
  5983. renderCell(i, context) {
  5984. const buffer = context == null ? context = new Path$1 : undefined;
  5985. const points = this._clip(i);
  5986. if (points === null || !points.length) return;
  5987. context.moveTo(points[0], points[1]);
  5988. let n = points.length;
  5989. while (points[0] === points[n-2] && points[1] === points[n-1] && n > 1) n -= 2;
  5990. for (let i = 2; i < n; i += 2) {
  5991. if (points[i] !== points[i-2] || points[i+1] !== points[i-1])
  5992. context.lineTo(points[i], points[i + 1]);
  5993. }
  5994. context.closePath();
  5995. return buffer && buffer.value();
  5996. }
  5997. *cellPolygons() {
  5998. const {delaunay: {points}} = this;
  5999. for (let i = 0, n = points.length / 2; i < n; ++i) {
  6000. const cell = this.cellPolygon(i);
  6001. if (cell) cell.index = i, yield cell;
  6002. }
  6003. }
  6004. cellPolygon(i) {
  6005. const polygon = new Polygon;
  6006. this.renderCell(i, polygon);
  6007. return polygon.value();
  6008. }
  6009. _renderSegment(x0, y0, x1, y1, context) {
  6010. let S;
  6011. const c0 = this._regioncode(x0, y0);
  6012. const c1 = this._regioncode(x1, y1);
  6013. if (c0 === 0 && c1 === 0) {
  6014. context.moveTo(x0, y0);
  6015. context.lineTo(x1, y1);
  6016. } else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) {
  6017. context.moveTo(S[0], S[1]);
  6018. context.lineTo(S[2], S[3]);
  6019. }
  6020. }
  6021. contains(i, x, y) {
  6022. if ((x = +x, x !== x) || (y = +y, y !== y)) return false;
  6023. return this.delaunay._step(i, x, y) === i;
  6024. }
  6025. *neighbors(i) {
  6026. const ci = this._clip(i);
  6027. if (ci) for (const j of this.delaunay.neighbors(i)) {
  6028. const cj = this._clip(j);
  6029. // find the common edge
  6030. if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) {
  6031. for (let aj = 0, lj = cj.length; aj < lj; aj += 2) {
  6032. if (ci[ai] == cj[aj]
  6033. && ci[ai + 1] == cj[aj + 1]
  6034. && ci[(ai + 2) % li] == cj[(aj + lj - 2) % lj]
  6035. && ci[(ai + 3) % li] == cj[(aj + lj - 1) % lj]
  6036. ) {
  6037. yield j;
  6038. break loop;
  6039. }
  6040. }
  6041. }
  6042. }
  6043. }
  6044. _cell(i) {
  6045. const {circumcenters, delaunay: {inedges, halfedges, triangles}} = this;
  6046. const e0 = inedges[i];
  6047. if (e0 === -1) return null; // coincident point
  6048. const points = [];
  6049. let e = e0;
  6050. do {
  6051. const t = Math.floor(e / 3);
  6052. points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]);
  6053. e = e % 3 === 2 ? e - 2 : e + 1;
  6054. if (triangles[e] !== i) break; // bad triangulation
  6055. e = halfedges[e];
  6056. } while (e !== e0 && e !== -1);
  6057. return points;
  6058. }
  6059. _clip(i) {
  6060. // degenerate case (1 valid point: return the box)
  6061. if (i === 0 && this.delaunay.hull.length === 1) {
  6062. return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
  6063. }
  6064. const points = this._cell(i);
  6065. if (points === null) return null;
  6066. const {vectors: V} = this;
  6067. const v = i * 4;
  6068. return V[v] || V[v + 1]
  6069. ? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3])
  6070. : this._clipFinite(i, points);
  6071. }
  6072. _clipFinite(i, points) {
  6073. const n = points.length;
  6074. let P = null;
  6075. let x0, y0, x1 = points[n - 2], y1 = points[n - 1];
  6076. let c0, c1 = this._regioncode(x1, y1);
  6077. let e0, e1;
  6078. for (let j = 0; j < n; j += 2) {
  6079. x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1];
  6080. c0 = c1, c1 = this._regioncode(x1, y1);
  6081. if (c0 === 0 && c1 === 0) {
  6082. e0 = e1, e1 = 0;
  6083. if (P) P.push(x1, y1);
  6084. else P = [x1, y1];
  6085. } else {
  6086. let S, sx0, sy0, sx1, sy1;
  6087. if (c0 === 0) {
  6088. if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue;
  6089. [sx0, sy0, sx1, sy1] = S;
  6090. } else {
  6091. if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue;
  6092. [sx1, sy1, sx0, sy0] = S;
  6093. e0 = e1, e1 = this._edgecode(sx0, sy0);
  6094. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6095. if (P) P.push(sx0, sy0);
  6096. else P = [sx0, sy0];
  6097. }
  6098. e0 = e1, e1 = this._edgecode(sx1, sy1);
  6099. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6100. if (P) P.push(sx1, sy1);
  6101. else P = [sx1, sy1];
  6102. }
  6103. }
  6104. if (P) {
  6105. e0 = e1, e1 = this._edgecode(P[0], P[1]);
  6106. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6107. } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
  6108. return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
  6109. }
  6110. return P;
  6111. }
  6112. _clipSegment(x0, y0, x1, y1, c0, c1) {
  6113. while (true) {
  6114. if (c0 === 0 && c1 === 0) return [x0, y0, x1, y1];
  6115. if (c0 & c1) return null;
  6116. let x, y, c = c0 || c1;
  6117. if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax;
  6118. else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin;
  6119. else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax;
  6120. else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin;
  6121. if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0);
  6122. else x1 = x, y1 = y, c1 = this._regioncode(x1, y1);
  6123. }
  6124. }
  6125. _clipInfinite(i, points, vx0, vy0, vxn, vyn) {
  6126. let P = Array.from(points), p;
  6127. if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]);
  6128. if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]);
  6129. if (P = this._clipFinite(i, P)) {
  6130. for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) {
  6131. c0 = c1, c1 = this._edgecode(P[j], P[j + 1]);
  6132. if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length;
  6133. }
  6134. } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
  6135. P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax];
  6136. }
  6137. return P;
  6138. }
  6139. _edge(i, e0, e1, P, j) {
  6140. while (e0 !== e1) {
  6141. let x, y;
  6142. switch (e0) {
  6143. case 0b0101: e0 = 0b0100; continue; // top-left
  6144. case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break; // top
  6145. case 0b0110: e0 = 0b0010; continue; // top-right
  6146. case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break; // right
  6147. case 0b1010: e0 = 0b1000; continue; // bottom-right
  6148. case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break; // bottom
  6149. case 0b1001: e0 = 0b0001; continue; // bottom-left
  6150. case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break; // left
  6151. }
  6152. if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) {
  6153. P.splice(j, 0, x, y), j += 2;
  6154. }
  6155. }
  6156. if (P.length > 4) {
  6157. for (let i = 0; i < P.length; i+= 2) {
  6158. const j = (i + 2) % P.length, k = (i + 4) % P.length;
  6159. if (P[i] === P[j] && P[j] === P[k]
  6160. || P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1])
  6161. P.splice(j, 2), i -= 2;
  6162. }
  6163. }
  6164. return j;
  6165. }
  6166. _project(x0, y0, vx, vy) {
  6167. let t = Infinity, c, x, y;
  6168. if (vy < 0) { // top
  6169. if (y0 <= this.ymin) return null;
  6170. if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx;
  6171. } else if (vy > 0) { // bottom
  6172. if (y0 >= this.ymax) return null;
  6173. if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx;
  6174. }
  6175. if (vx > 0) { // right
  6176. if (x0 >= this.xmax) return null;
  6177. if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy;
  6178. } else if (vx < 0) { // left
  6179. if (x0 <= this.xmin) return null;
  6180. if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy;
  6181. }
  6182. return [x, y];
  6183. }
  6184. _edgecode(x, y) {
  6185. return (x === this.xmin ? 0b0001
  6186. : x === this.xmax ? 0b0010 : 0b0000)
  6187. | (y === this.ymin ? 0b0100
  6188. : y === this.ymax ? 0b1000 : 0b0000);
  6189. }
  6190. _regioncode(x, y) {
  6191. return (x < this.xmin ? 0b0001
  6192. : x > this.xmax ? 0b0010 : 0b0000)
  6193. | (y < this.ymin ? 0b0100
  6194. : y > this.ymax ? 0b1000 : 0b0000);
  6195. }
  6196. }
  6197. const tau$3 = 2 * Math.PI, pow = Math.pow;
  6198. function pointX(p) {
  6199. return p[0];
  6200. }
  6201. function pointY(p) {
  6202. return p[1];
  6203. }
  6204. // A triangulation is collinear if all its triangles have a non-null area
  6205. function collinear$1(d) {
  6206. const {triangles, coords} = d;
  6207. for (let i = 0; i < triangles.length; i += 3) {
  6208. const a = 2 * triangles[i],
  6209. b = 2 * triangles[i + 1],
  6210. c = 2 * triangles[i + 2],
  6211. cross = (coords[c] - coords[a]) * (coords[b + 1] - coords[a + 1])
  6212. - (coords[b] - coords[a]) * (coords[c + 1] - coords[a + 1]);
  6213. if (cross > 1e-10) return false;
  6214. }
  6215. return true;
  6216. }
  6217. function jitter(x, y, r) {
  6218. return [x + Math.sin(x + y) * r, y + Math.cos(x - y) * r];
  6219. }
  6220. class Delaunay {
  6221. static from(points, fx = pointX, fy = pointY, that) {
  6222. return new Delaunay("length" in points
  6223. ? flatArray(points, fx, fy, that)
  6224. : Float64Array.from(flatIterable(points, fx, fy, that)));
  6225. }
  6226. constructor(points) {
  6227. this._delaunator = new Delaunator(points);
  6228. this.inedges = new Int32Array(points.length / 2);
  6229. this._hullIndex = new Int32Array(points.length / 2);
  6230. this.points = this._delaunator.coords;
  6231. this._init();
  6232. }
  6233. update() {
  6234. this._delaunator.update();
  6235. this._init();
  6236. return this;
  6237. }
  6238. _init() {
  6239. const d = this._delaunator, points = this.points;
  6240. // check for collinear
  6241. if (d.hull && d.hull.length > 2 && collinear$1(d)) {
  6242. this.collinear = Int32Array.from({length: points.length/2}, (_,i) => i)
  6243. .sort((i, j) => points[2 * i] - points[2 * j] || points[2 * i + 1] - points[2 * j + 1]); // for exact neighbors
  6244. const e = this.collinear[0], f = this.collinear[this.collinear.length - 1],
  6245. bounds = [ points[2 * e], points[2 * e + 1], points[2 * f], points[2 * f + 1] ],
  6246. r = 1e-8 * Math.hypot(bounds[3] - bounds[1], bounds[2] - bounds[0]);
  6247. for (let i = 0, n = points.length / 2; i < n; ++i) {
  6248. const p = jitter(points[2 * i], points[2 * i + 1], r);
  6249. points[2 * i] = p[0];
  6250. points[2 * i + 1] = p[1];
  6251. }
  6252. this._delaunator = new Delaunator(points);
  6253. } else {
  6254. delete this.collinear;
  6255. }
  6256. const halfedges = this.halfedges = this._delaunator.halfedges;
  6257. const hull = this.hull = this._delaunator.hull;
  6258. const triangles = this.triangles = this._delaunator.triangles;
  6259. const inedges = this.inedges.fill(-1);
  6260. const hullIndex = this._hullIndex.fill(-1);
  6261. // Compute an index from each point to an (arbitrary) incoming halfedge
  6262. // Used to give the first neighbor of each point; for this reason,
  6263. // on the hull we give priority to exterior halfedges
  6264. for (let e = 0, n = halfedges.length; e < n; ++e) {
  6265. const p = triangles[e % 3 === 2 ? e - 2 : e + 1];
  6266. if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e;
  6267. }
  6268. for (let i = 0, n = hull.length; i < n; ++i) {
  6269. hullIndex[hull[i]] = i;
  6270. }
  6271. // degenerate case: 1 or 2 (distinct) points
  6272. if (hull.length <= 2 && hull.length > 0) {
  6273. this.triangles = new Int32Array(3).fill(-1);
  6274. this.halfedges = new Int32Array(3).fill(-1);
  6275. this.triangles[0] = hull[0];
  6276. this.triangles[1] = hull[1];
  6277. this.triangles[2] = hull[1];
  6278. inedges[hull[0]] = 1;
  6279. if (hull.length === 2) inedges[hull[1]] = 0;
  6280. }
  6281. }
  6282. voronoi(bounds) {
  6283. return new Voronoi(this, bounds);
  6284. }
  6285. *neighbors(i) {
  6286. const {inedges, hull, _hullIndex, halfedges, triangles, collinear} = this;
  6287. // degenerate case with several collinear points
  6288. if (collinear) {
  6289. const l = collinear.indexOf(i);
  6290. if (l > 0) yield collinear[l - 1];
  6291. if (l < collinear.length - 1) yield collinear[l + 1];
  6292. return;
  6293. }
  6294. const e0 = inedges[i];
  6295. if (e0 === -1) return; // coincident point
  6296. let e = e0, p0 = -1;
  6297. do {
  6298. yield p0 = triangles[e];
  6299. e = e % 3 === 2 ? e - 2 : e + 1;
  6300. if (triangles[e] !== i) return; // bad triangulation
  6301. e = halfedges[e];
  6302. if (e === -1) {
  6303. const p = hull[(_hullIndex[i] + 1) % hull.length];
  6304. if (p !== p0) yield p;
  6305. return;
  6306. }
  6307. } while (e !== e0);
  6308. }
  6309. find(x, y, i = 0) {
  6310. if ((x = +x, x !== x) || (y = +y, y !== y)) return -1;
  6311. const i0 = i;
  6312. let c;
  6313. while ((c = this._step(i, x, y)) >= 0 && c !== i && c !== i0) i = c;
  6314. return c;
  6315. }
  6316. _step(i, x, y) {
  6317. const {inedges, hull, _hullIndex, halfedges, triangles, points} = this;
  6318. if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1);
  6319. let c = i;
  6320. let dc = pow(x - points[i * 2], 2) + pow(y - points[i * 2 + 1], 2);
  6321. const e0 = inedges[i];
  6322. let e = e0;
  6323. do {
  6324. let t = triangles[e];
  6325. const dt = pow(x - points[t * 2], 2) + pow(y - points[t * 2 + 1], 2);
  6326. if (dt < dc) dc = dt, c = t;
  6327. e = e % 3 === 2 ? e - 2 : e + 1;
  6328. if (triangles[e] !== i) break; // bad triangulation
  6329. e = halfedges[e];
  6330. if (e === -1) {
  6331. e = hull[(_hullIndex[i] + 1) % hull.length];
  6332. if (e !== t) {
  6333. if (pow(x - points[e * 2], 2) + pow(y - points[e * 2 + 1], 2) < dc) return e;
  6334. }
  6335. break;
  6336. }
  6337. } while (e !== e0);
  6338. return c;
  6339. }
  6340. render(context) {
  6341. const buffer = context == null ? context = new Path$1 : undefined;
  6342. const {points, halfedges, triangles} = this;
  6343. for (let i = 0, n = halfedges.length; i < n; ++i) {
  6344. const j = halfedges[i];
  6345. if (j < i) continue;
  6346. const ti = triangles[i] * 2;
  6347. const tj = triangles[j] * 2;
  6348. context.moveTo(points[ti], points[ti + 1]);
  6349. context.lineTo(points[tj], points[tj + 1]);
  6350. }
  6351. this.renderHull(context);
  6352. return buffer && buffer.value();
  6353. }
  6354. renderPoints(context, r = 2) {
  6355. const buffer = context == null ? context = new Path$1 : undefined;
  6356. const {points} = this;
  6357. for (let i = 0, n = points.length; i < n; i += 2) {
  6358. const x = points[i], y = points[i + 1];
  6359. context.moveTo(x + r, y);
  6360. context.arc(x, y, r, 0, tau$3);
  6361. }
  6362. return buffer && buffer.value();
  6363. }
  6364. renderHull(context) {
  6365. const buffer = context == null ? context = new Path$1 : undefined;
  6366. const {hull, points} = this;
  6367. const h = hull[0] * 2, n = hull.length;
  6368. context.moveTo(points[h], points[h + 1]);
  6369. for (let i = 1; i < n; ++i) {
  6370. const h = 2 * hull[i];
  6371. context.lineTo(points[h], points[h + 1]);
  6372. }
  6373. context.closePath();
  6374. return buffer && buffer.value();
  6375. }
  6376. hullPolygon() {
  6377. const polygon = new Polygon;
  6378. this.renderHull(polygon);
  6379. return polygon.value();
  6380. }
  6381. renderTriangle(i, context) {
  6382. const buffer = context == null ? context = new Path$1 : undefined;
  6383. const {points, triangles} = this;
  6384. const t0 = triangles[i *= 3] * 2;
  6385. const t1 = triangles[i + 1] * 2;
  6386. const t2 = triangles[i + 2] * 2;
  6387. context.moveTo(points[t0], points[t0 + 1]);
  6388. context.lineTo(points[t1], points[t1 + 1]);
  6389. context.lineTo(points[t2], points[t2 + 1]);
  6390. context.closePath();
  6391. return buffer && buffer.value();
  6392. }
  6393. *trianglePolygons() {
  6394. const {triangles} = this;
  6395. for (let i = 0, n = triangles.length / 3; i < n; ++i) {
  6396. yield this.trianglePolygon(i);
  6397. }
  6398. }
  6399. trianglePolygon(i) {
  6400. const polygon = new Polygon;
  6401. this.renderTriangle(i, polygon);
  6402. return polygon.value();
  6403. }
  6404. }
  6405. function flatArray(points, fx, fy, that) {
  6406. const n = points.length;
  6407. const array = new Float64Array(n * 2);
  6408. for (let i = 0; i < n; ++i) {
  6409. const p = points[i];
  6410. array[i * 2] = fx.call(that, p, i, points);
  6411. array[i * 2 + 1] = fy.call(that, p, i, points);
  6412. }
  6413. return array;
  6414. }
  6415. function* flatIterable(points, fx, fy, that) {
  6416. let i = 0;
  6417. for (const p of points) {
  6418. yield fx.call(that, p, i, points);
  6419. yield fy.call(that, p, i, points);
  6420. ++i;
  6421. }
  6422. }
  6423. var EOL = {},
  6424. EOF = {},
  6425. QUOTE = 34,
  6426. NEWLINE = 10,
  6427. RETURN = 13;
  6428. function objectConverter(columns) {
  6429. return new Function("d", "return {" + columns.map(function(name, i) {
  6430. return JSON.stringify(name) + ": d[" + i + "] || \"\"";
  6431. }).join(",") + "}");
  6432. }
  6433. function customConverter(columns, f) {
  6434. var object = objectConverter(columns);
  6435. return function(row, i) {
  6436. return f(object(row), i, columns);
  6437. };
  6438. }
  6439. // Compute unique columns in order of discovery.
  6440. function inferColumns(rows) {
  6441. var columnSet = Object.create(null),
  6442. columns = [];
  6443. rows.forEach(function(row) {
  6444. for (var column in row) {
  6445. if (!(column in columnSet)) {
  6446. columns.push(columnSet[column] = column);
  6447. }
  6448. }
  6449. });
  6450. return columns;
  6451. }
  6452. function pad(value, width) {
  6453. var s = value + "", length = s.length;
  6454. return length < width ? new Array(width - length + 1).join(0) + s : s;
  6455. }
  6456. function formatYear(year) {
  6457. return year < 0 ? "-" + pad(-year, 6)
  6458. : year > 9999 ? "+" + pad(year, 6)
  6459. : pad(year, 4);
  6460. }
  6461. function formatDate(date) {
  6462. var hours = date.getUTCHours(),
  6463. minutes = date.getUTCMinutes(),
  6464. seconds = date.getUTCSeconds(),
  6465. milliseconds = date.getUTCMilliseconds();
  6466. return isNaN(date) ? "Invalid Date"
  6467. : formatYear(date.getUTCFullYear()) + "-" + pad(date.getUTCMonth() + 1, 2) + "-" + pad(date.getUTCDate(), 2)
  6468. + (milliseconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "." + pad(milliseconds, 3) + "Z"
  6469. : seconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "Z"
  6470. : minutes || hours ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + "Z"
  6471. : "");
  6472. }
  6473. function dsvFormat(delimiter) {
  6474. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  6475. DELIMITER = delimiter.charCodeAt(0);
  6476. function parse(text, f) {
  6477. var convert, columns, rows = parseRows(text, function(row, i) {
  6478. if (convert) return convert(row, i - 1);
  6479. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  6480. });
  6481. rows.columns = columns || [];
  6482. return rows;
  6483. }
  6484. function parseRows(text, f) {
  6485. var rows = [], // output rows
  6486. N = text.length,
  6487. I = 0, // current character index
  6488. n = 0, // current line number
  6489. t, // current token
  6490. eof = N <= 0, // current token followed by EOF?
  6491. eol = false; // current token followed by EOL?
  6492. // Strip the trailing newline.
  6493. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  6494. if (text.charCodeAt(N - 1) === RETURN) --N;
  6495. function token() {
  6496. if (eof) return EOF;
  6497. if (eol) return eol = false, EOL;
  6498. // Unescape quotes.
  6499. var i, j = I, c;
  6500. if (text.charCodeAt(j) === QUOTE) {
  6501. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  6502. if ((i = I) >= N) eof = true;
  6503. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  6504. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  6505. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  6506. }
  6507. // Find next delimiter or newline.
  6508. while (I < N) {
  6509. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  6510. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  6511. else if (c !== DELIMITER) continue;
  6512. return text.slice(j, i);
  6513. }
  6514. // Return last token before EOF.
  6515. return eof = true, text.slice(j, N);
  6516. }
  6517. while ((t = token()) !== EOF) {
  6518. var row = [];
  6519. while (t !== EOL && t !== EOF) row.push(t), t = token();
  6520. if (f && (row = f(row, n++)) == null) continue;
  6521. rows.push(row);
  6522. }
  6523. return rows;
  6524. }
  6525. function preformatBody(rows, columns) {
  6526. return rows.map(function(row) {
  6527. return columns.map(function(column) {
  6528. return formatValue(row[column]);
  6529. }).join(delimiter);
  6530. });
  6531. }
  6532. function format(rows, columns) {
  6533. if (columns == null) columns = inferColumns(rows);
  6534. return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
  6535. }
  6536. function formatBody(rows, columns) {
  6537. if (columns == null) columns = inferColumns(rows);
  6538. return preformatBody(rows, columns).join("\n");
  6539. }
  6540. function formatRows(rows) {
  6541. return rows.map(formatRow).join("\n");
  6542. }
  6543. function formatRow(row) {
  6544. return row.map(formatValue).join(delimiter);
  6545. }
  6546. function formatValue(value) {
  6547. return value == null ? ""
  6548. : value instanceof Date ? formatDate(value)
  6549. : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
  6550. : value;
  6551. }
  6552. return {
  6553. parse: parse,
  6554. parseRows: parseRows,
  6555. format: format,
  6556. formatBody: formatBody,
  6557. formatRows: formatRows,
  6558. formatRow: formatRow,
  6559. formatValue: formatValue
  6560. };
  6561. }
  6562. var csv = dsvFormat(",");
  6563. var csvParse = csv.parse;
  6564. var csvParseRows = csv.parseRows;
  6565. var csvFormat = csv.format;
  6566. var csvFormatBody = csv.formatBody;
  6567. var csvFormatRows = csv.formatRows;
  6568. var csvFormatRow = csv.formatRow;
  6569. var csvFormatValue = csv.formatValue;
  6570. var tsv = dsvFormat("\t");
  6571. var tsvParse = tsv.parse;
  6572. var tsvParseRows = tsv.parseRows;
  6573. var tsvFormat = tsv.format;
  6574. var tsvFormatBody = tsv.formatBody;
  6575. var tsvFormatRows = tsv.formatRows;
  6576. var tsvFormatRow = tsv.formatRow;
  6577. var tsvFormatValue = tsv.formatValue;
  6578. function autoType(object) {
  6579. for (var key in object) {
  6580. var value = object[key].trim(), number, m;
  6581. if (!value) value = null;
  6582. else if (value === "true") value = true;
  6583. else if (value === "false") value = false;
  6584. else if (value === "NaN") value = NaN;
  6585. else if (!isNaN(number = +value)) value = number;
  6586. 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})?)?$/)) {
  6587. if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
  6588. value = new Date(value);
  6589. }
  6590. else continue;
  6591. object[key] = value;
  6592. }
  6593. return object;
  6594. }
  6595. // https://github.com/d3/d3-dsv/issues/45
  6596. const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
  6597. function responseBlob(response) {
  6598. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  6599. return response.blob();
  6600. }
  6601. function blob(input, init) {
  6602. return fetch(input, init).then(responseBlob);
  6603. }
  6604. function responseArrayBuffer(response) {
  6605. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  6606. return response.arrayBuffer();
  6607. }
  6608. function buffer(input, init) {
  6609. return fetch(input, init).then(responseArrayBuffer);
  6610. }
  6611. function responseText(response) {
  6612. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  6613. return response.text();
  6614. }
  6615. function text(input, init) {
  6616. return fetch(input, init).then(responseText);
  6617. }
  6618. function dsvParse(parse) {
  6619. return function(input, init, row) {
  6620. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  6621. return text(input, init).then(function(response) {
  6622. return parse(response, row);
  6623. });
  6624. };
  6625. }
  6626. function dsv(delimiter, input, init, row) {
  6627. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  6628. var format = dsvFormat(delimiter);
  6629. return text(input, init).then(function(response) {
  6630. return format.parse(response, row);
  6631. });
  6632. }
  6633. var csv$1 = dsvParse(csvParse);
  6634. var tsv$1 = dsvParse(tsvParse);
  6635. function image(input, init) {
  6636. return new Promise(function(resolve, reject) {
  6637. var image = new Image;
  6638. for (var key in init) image[key] = init[key];
  6639. image.onerror = reject;
  6640. image.onload = function() { resolve(image); };
  6641. image.src = input;
  6642. });
  6643. }
  6644. function responseJson(response) {
  6645. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  6646. if (response.status === 204 || response.status === 205) return;
  6647. return response.json();
  6648. }
  6649. function json(input, init) {
  6650. return fetch(input, init).then(responseJson);
  6651. }
  6652. function parser(type) {
  6653. return (input, init) => text(input, init)
  6654. .then(text => (new DOMParser).parseFromString(text, type));
  6655. }
  6656. var xml = parser("application/xml");
  6657. var html = parser("text/html");
  6658. var svg = parser("image/svg+xml");
  6659. function center$1(x, y) {
  6660. var nodes, strength = 1;
  6661. if (x == null) x = 0;
  6662. if (y == null) y = 0;
  6663. function force() {
  6664. var i,
  6665. n = nodes.length,
  6666. node,
  6667. sx = 0,
  6668. sy = 0;
  6669. for (i = 0; i < n; ++i) {
  6670. node = nodes[i], sx += node.x, sy += node.y;
  6671. }
  6672. for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
  6673. node = nodes[i], node.x -= sx, node.y -= sy;
  6674. }
  6675. }
  6676. force.initialize = function(_) {
  6677. nodes = _;
  6678. };
  6679. force.x = function(_) {
  6680. return arguments.length ? (x = +_, force) : x;
  6681. };
  6682. force.y = function(_) {
  6683. return arguments.length ? (y = +_, force) : y;
  6684. };
  6685. force.strength = function(_) {
  6686. return arguments.length ? (strength = +_, force) : strength;
  6687. };
  6688. return force;
  6689. }
  6690. function tree_add(d) {
  6691. const x = +this._x.call(null, d),
  6692. y = +this._y.call(null, d);
  6693. return add(this.cover(x, y), x, y, d);
  6694. }
  6695. function add(tree, x, y, d) {
  6696. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  6697. var parent,
  6698. node = tree._root,
  6699. leaf = {data: d},
  6700. x0 = tree._x0,
  6701. y0 = tree._y0,
  6702. x1 = tree._x1,
  6703. y1 = tree._y1,
  6704. xm,
  6705. ym,
  6706. xp,
  6707. yp,
  6708. right,
  6709. bottom,
  6710. i,
  6711. j;
  6712. // If the tree is empty, initialize the root as a leaf.
  6713. if (!node) return tree._root = leaf, tree;
  6714. // Find the existing leaf for the new point, or add it.
  6715. while (node.length) {
  6716. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  6717. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  6718. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  6719. }
  6720. // Is the new point is exactly coincident with the existing point?
  6721. xp = +tree._x.call(null, node.data);
  6722. yp = +tree._y.call(null, node.data);
  6723. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  6724. // Otherwise, split the leaf node until the old and new point are separated.
  6725. do {
  6726. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  6727. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  6728. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  6729. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  6730. return parent[j] = node, parent[i] = leaf, tree;
  6731. }
  6732. function addAll(data) {
  6733. var d, i, n = data.length,
  6734. x,
  6735. y,
  6736. xz = new Array(n),
  6737. yz = new Array(n),
  6738. x0 = Infinity,
  6739. y0 = Infinity,
  6740. x1 = -Infinity,
  6741. y1 = -Infinity;
  6742. // Compute the points and their extent.
  6743. for (i = 0; i < n; ++i) {
  6744. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  6745. xz[i] = x;
  6746. yz[i] = y;
  6747. if (x < x0) x0 = x;
  6748. if (x > x1) x1 = x;
  6749. if (y < y0) y0 = y;
  6750. if (y > y1) y1 = y;
  6751. }
  6752. // If there were no (valid) points, abort.
  6753. if (x0 > x1 || y0 > y1) return this;
  6754. // Expand the tree to cover the new points.
  6755. this.cover(x0, y0).cover(x1, y1);
  6756. // Add the new points.
  6757. for (i = 0; i < n; ++i) {
  6758. add(this, xz[i], yz[i], data[i]);
  6759. }
  6760. return this;
  6761. }
  6762. function tree_cover(x, y) {
  6763. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  6764. var x0 = this._x0,
  6765. y0 = this._y0,
  6766. x1 = this._x1,
  6767. y1 = this._y1;
  6768. // If the quadtree has no extent, initialize them.
  6769. // Integer extent are necessary so that if we later double the extent,
  6770. // the existing quadrant boundaries don’t change due to floating point error!
  6771. if (isNaN(x0)) {
  6772. x1 = (x0 = Math.floor(x)) + 1;
  6773. y1 = (y0 = Math.floor(y)) + 1;
  6774. }
  6775. // Otherwise, double repeatedly to cover.
  6776. else {
  6777. var z = x1 - x0 || 1,
  6778. node = this._root,
  6779. parent,
  6780. i;
  6781. while (x0 > x || x >= x1 || y0 > y || y >= y1) {
  6782. i = (y < y0) << 1 | (x < x0);
  6783. parent = new Array(4), parent[i] = node, node = parent, z *= 2;
  6784. switch (i) {
  6785. case 0: x1 = x0 + z, y1 = y0 + z; break;
  6786. case 1: x0 = x1 - z, y1 = y0 + z; break;
  6787. case 2: x1 = x0 + z, y0 = y1 - z; break;
  6788. case 3: x0 = x1 - z, y0 = y1 - z; break;
  6789. }
  6790. }
  6791. if (this._root && this._root.length) this._root = node;
  6792. }
  6793. this._x0 = x0;
  6794. this._y0 = y0;
  6795. this._x1 = x1;
  6796. this._y1 = y1;
  6797. return this;
  6798. }
  6799. function tree_data() {
  6800. var data = [];
  6801. this.visit(function(node) {
  6802. if (!node.length) do data.push(node.data); while (node = node.next)
  6803. });
  6804. return data;
  6805. }
  6806. function tree_extent(_) {
  6807. return arguments.length
  6808. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  6809. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  6810. }
  6811. function Quad(node, x0, y0, x1, y1) {
  6812. this.node = node;
  6813. this.x0 = x0;
  6814. this.y0 = y0;
  6815. this.x1 = x1;
  6816. this.y1 = y1;
  6817. }
  6818. function tree_find(x, y, radius) {
  6819. var data,
  6820. x0 = this._x0,
  6821. y0 = this._y0,
  6822. x1,
  6823. y1,
  6824. x2,
  6825. y2,
  6826. x3 = this._x1,
  6827. y3 = this._y1,
  6828. quads = [],
  6829. node = this._root,
  6830. q,
  6831. i;
  6832. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  6833. if (radius == null) radius = Infinity;
  6834. else {
  6835. x0 = x - radius, y0 = y - radius;
  6836. x3 = x + radius, y3 = y + radius;
  6837. radius *= radius;
  6838. }
  6839. while (q = quads.pop()) {
  6840. // Stop searching if this quadrant can’t contain a closer node.
  6841. if (!(node = q.node)
  6842. || (x1 = q.x0) > x3
  6843. || (y1 = q.y0) > y3
  6844. || (x2 = q.x1) < x0
  6845. || (y2 = q.y1) < y0) continue;
  6846. // Bisect the current quadrant.
  6847. if (node.length) {
  6848. var xm = (x1 + x2) / 2,
  6849. ym = (y1 + y2) / 2;
  6850. quads.push(
  6851. new Quad(node[3], xm, ym, x2, y2),
  6852. new Quad(node[2], x1, ym, xm, y2),
  6853. new Quad(node[1], xm, y1, x2, ym),
  6854. new Quad(node[0], x1, y1, xm, ym)
  6855. );
  6856. // Visit the closest quadrant first.
  6857. if (i = (y >= ym) << 1 | (x >= xm)) {
  6858. q = quads[quads.length - 1];
  6859. quads[quads.length - 1] = quads[quads.length - 1 - i];
  6860. quads[quads.length - 1 - i] = q;
  6861. }
  6862. }
  6863. // Visit this point. (Visiting coincident points isn’t necessary!)
  6864. else {
  6865. var dx = x - +this._x.call(null, node.data),
  6866. dy = y - +this._y.call(null, node.data),
  6867. d2 = dx * dx + dy * dy;
  6868. if (d2 < radius) {
  6869. var d = Math.sqrt(radius = d2);
  6870. x0 = x - d, y0 = y - d;
  6871. x3 = x + d, y3 = y + d;
  6872. data = node.data;
  6873. }
  6874. }
  6875. }
  6876. return data;
  6877. }
  6878. function tree_remove(d) {
  6879. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  6880. var parent,
  6881. node = this._root,
  6882. retainer,
  6883. previous,
  6884. next,
  6885. x0 = this._x0,
  6886. y0 = this._y0,
  6887. x1 = this._x1,
  6888. y1 = this._y1,
  6889. x,
  6890. y,
  6891. xm,
  6892. ym,
  6893. right,
  6894. bottom,
  6895. i,
  6896. j;
  6897. // If the tree is empty, initialize the root as a leaf.
  6898. if (!node) return this;
  6899. // Find the leaf node for the point.
  6900. // While descending, also retain the deepest parent with a non-removed sibling.
  6901. if (node.length) while (true) {
  6902. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  6903. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  6904. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  6905. if (!node.length) break;
  6906. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  6907. }
  6908. // Find the point to remove.
  6909. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  6910. if (next = node.next) delete node.next;
  6911. // If there are multiple coincident points, remove just the point.
  6912. if (previous) return (next ? previous.next = next : delete previous.next), this;
  6913. // If this is the root point, remove it.
  6914. if (!parent) return this._root = next, this;
  6915. // Remove this leaf.
  6916. next ? parent[i] = next : delete parent[i];
  6917. // If the parent now contains exactly one leaf, collapse superfluous parents.
  6918. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  6919. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  6920. && !node.length) {
  6921. if (retainer) retainer[j] = node;
  6922. else this._root = node;
  6923. }
  6924. return this;
  6925. }
  6926. function removeAll(data) {
  6927. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  6928. return this;
  6929. }
  6930. function tree_root() {
  6931. return this._root;
  6932. }
  6933. function tree_size() {
  6934. var size = 0;
  6935. this.visit(function(node) {
  6936. if (!node.length) do ++size; while (node = node.next)
  6937. });
  6938. return size;
  6939. }
  6940. function tree_visit(callback) {
  6941. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  6942. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  6943. while (q = quads.pop()) {
  6944. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  6945. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  6946. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  6947. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  6948. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  6949. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  6950. }
  6951. }
  6952. return this;
  6953. }
  6954. function tree_visitAfter(callback) {
  6955. var quads = [], next = [], q;
  6956. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  6957. while (q = quads.pop()) {
  6958. var node = q.node;
  6959. if (node.length) {
  6960. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  6961. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  6962. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  6963. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  6964. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  6965. }
  6966. next.push(q);
  6967. }
  6968. while (q = next.pop()) {
  6969. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  6970. }
  6971. return this;
  6972. }
  6973. function defaultX$1(d) {
  6974. return d[0];
  6975. }
  6976. function tree_x(_) {
  6977. return arguments.length ? (this._x = _, this) : this._x;
  6978. }
  6979. function defaultY$1(d) {
  6980. return d[1];
  6981. }
  6982. function tree_y(_) {
  6983. return arguments.length ? (this._y = _, this) : this._y;
  6984. }
  6985. function quadtree(nodes, x, y) {
  6986. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  6987. return nodes == null ? tree : tree.addAll(nodes);
  6988. }
  6989. function Quadtree(x, y, x0, y0, x1, y1) {
  6990. this._x = x;
  6991. this._y = y;
  6992. this._x0 = x0;
  6993. this._y0 = y0;
  6994. this._x1 = x1;
  6995. this._y1 = y1;
  6996. this._root = undefined;
  6997. }
  6998. function leaf_copy(leaf) {
  6999. var copy = {data: leaf.data}, next = copy;
  7000. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  7001. return copy;
  7002. }
  7003. var treeProto = quadtree.prototype = Quadtree.prototype;
  7004. treeProto.copy = function() {
  7005. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  7006. node = this._root,
  7007. nodes,
  7008. child;
  7009. if (!node) return copy;
  7010. if (!node.length) return copy._root = leaf_copy(node), copy;
  7011. nodes = [{source: node, target: copy._root = new Array(4)}];
  7012. while (node = nodes.pop()) {
  7013. for (var i = 0; i < 4; ++i) {
  7014. if (child = node.source[i]) {
  7015. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  7016. else node.target[i] = leaf_copy(child);
  7017. }
  7018. }
  7019. }
  7020. return copy;
  7021. };
  7022. treeProto.add = tree_add;
  7023. treeProto.addAll = addAll;
  7024. treeProto.cover = tree_cover;
  7025. treeProto.data = tree_data;
  7026. treeProto.extent = tree_extent;
  7027. treeProto.find = tree_find;
  7028. treeProto.remove = tree_remove;
  7029. treeProto.removeAll = removeAll;
  7030. treeProto.root = tree_root;
  7031. treeProto.size = tree_size;
  7032. treeProto.visit = tree_visit;
  7033. treeProto.visitAfter = tree_visitAfter;
  7034. treeProto.x = tree_x;
  7035. treeProto.y = tree_y;
  7036. function constant$7(x) {
  7037. return function() {
  7038. return x;
  7039. };
  7040. }
  7041. function jiggle(random) {
  7042. return (random() - 0.5) * 1e-6;
  7043. }
  7044. function x(d) {
  7045. return d.x + d.vx;
  7046. }
  7047. function y(d) {
  7048. return d.y + d.vy;
  7049. }
  7050. function collide(radius) {
  7051. var nodes,
  7052. radii,
  7053. random,
  7054. strength = 1,
  7055. iterations = 1;
  7056. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  7057. function force() {
  7058. var i, n = nodes.length,
  7059. tree,
  7060. node,
  7061. xi,
  7062. yi,
  7063. ri,
  7064. ri2;
  7065. for (var k = 0; k < iterations; ++k) {
  7066. tree = quadtree(nodes, x, y).visitAfter(prepare);
  7067. for (i = 0; i < n; ++i) {
  7068. node = nodes[i];
  7069. ri = radii[node.index], ri2 = ri * ri;
  7070. xi = node.x + node.vx;
  7071. yi = node.y + node.vy;
  7072. tree.visit(apply);
  7073. }
  7074. }
  7075. function apply(quad, x0, y0, x1, y1) {
  7076. var data = quad.data, rj = quad.r, r = ri + rj;
  7077. if (data) {
  7078. if (data.index > node.index) {
  7079. var x = xi - data.x - data.vx,
  7080. y = yi - data.y - data.vy,
  7081. l = x * x + y * y;
  7082. if (l < r * r) {
  7083. if (x === 0) x = jiggle(random), l += x * x;
  7084. if (y === 0) y = jiggle(random), l += y * y;
  7085. l = (r - (l = Math.sqrt(l))) / l * strength;
  7086. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  7087. node.vy += (y *= l) * r;
  7088. data.vx -= x * (r = 1 - r);
  7089. data.vy -= y * r;
  7090. }
  7091. }
  7092. return;
  7093. }
  7094. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  7095. }
  7096. }
  7097. function prepare(quad) {
  7098. if (quad.data) return quad.r = radii[quad.data.index];
  7099. for (var i = quad.r = 0; i < 4; ++i) {
  7100. if (quad[i] && quad[i].r > quad.r) {
  7101. quad.r = quad[i].r;
  7102. }
  7103. }
  7104. }
  7105. function initialize() {
  7106. if (!nodes) return;
  7107. var i, n = nodes.length, node;
  7108. radii = new Array(n);
  7109. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  7110. }
  7111. force.initialize = function(_nodes, _random) {
  7112. nodes = _nodes;
  7113. random = _random;
  7114. initialize();
  7115. };
  7116. force.iterations = function(_) {
  7117. return arguments.length ? (iterations = +_, force) : iterations;
  7118. };
  7119. force.strength = function(_) {
  7120. return arguments.length ? (strength = +_, force) : strength;
  7121. };
  7122. force.radius = function(_) {
  7123. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  7124. };
  7125. return force;
  7126. }
  7127. function index$1(d) {
  7128. return d.index;
  7129. }
  7130. function find$1(nodeById, nodeId) {
  7131. var node = nodeById.get(nodeId);
  7132. if (!node) throw new Error("node not found: " + nodeId);
  7133. return node;
  7134. }
  7135. function link(links) {
  7136. var id = index$1,
  7137. strength = defaultStrength,
  7138. strengths,
  7139. distance = constant$7(30),
  7140. distances,
  7141. nodes,
  7142. count,
  7143. bias,
  7144. random,
  7145. iterations = 1;
  7146. if (links == null) links = [];
  7147. function defaultStrength(link) {
  7148. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  7149. }
  7150. function force(alpha) {
  7151. for (var k = 0, n = links.length; k < iterations; ++k) {
  7152. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  7153. link = links[i], source = link.source, target = link.target;
  7154. x = target.x + target.vx - source.x - source.vx || jiggle(random);
  7155. y = target.y + target.vy - source.y - source.vy || jiggle(random);
  7156. l = Math.sqrt(x * x + y * y);
  7157. l = (l - distances[i]) / l * alpha * strengths[i];
  7158. x *= l, y *= l;
  7159. target.vx -= x * (b = bias[i]);
  7160. target.vy -= y * b;
  7161. source.vx += x * (b = 1 - b);
  7162. source.vy += y * b;
  7163. }
  7164. }
  7165. }
  7166. function initialize() {
  7167. if (!nodes) return;
  7168. var i,
  7169. n = nodes.length,
  7170. m = links.length,
  7171. nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
  7172. link;
  7173. for (i = 0, count = new Array(n); i < m; ++i) {
  7174. link = links[i], link.index = i;
  7175. if (typeof link.source !== "object") link.source = find$1(nodeById, link.source);
  7176. if (typeof link.target !== "object") link.target = find$1(nodeById, link.target);
  7177. count[link.source.index] = (count[link.source.index] || 0) + 1;
  7178. count[link.target.index] = (count[link.target.index] || 0) + 1;
  7179. }
  7180. for (i = 0, bias = new Array(m); i < m; ++i) {
  7181. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  7182. }
  7183. strengths = new Array(m), initializeStrength();
  7184. distances = new Array(m), initializeDistance();
  7185. }
  7186. function initializeStrength() {
  7187. if (!nodes) return;
  7188. for (var i = 0, n = links.length; i < n; ++i) {
  7189. strengths[i] = +strength(links[i], i, links);
  7190. }
  7191. }
  7192. function initializeDistance() {
  7193. if (!nodes) return;
  7194. for (var i = 0, n = links.length; i < n; ++i) {
  7195. distances[i] = +distance(links[i], i, links);
  7196. }
  7197. }
  7198. force.initialize = function(_nodes, _random) {
  7199. nodes = _nodes;
  7200. random = _random;
  7201. initialize();
  7202. };
  7203. force.links = function(_) {
  7204. return arguments.length ? (links = _, initialize(), force) : links;
  7205. };
  7206. force.id = function(_) {
  7207. return arguments.length ? (id = _, force) : id;
  7208. };
  7209. force.iterations = function(_) {
  7210. return arguments.length ? (iterations = +_, force) : iterations;
  7211. };
  7212. force.strength = function(_) {
  7213. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  7214. };
  7215. force.distance = function(_) {
  7216. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  7217. };
  7218. return force;
  7219. }
  7220. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  7221. const a = 1664525;
  7222. const c = 1013904223;
  7223. const m = 4294967296; // 2^32
  7224. function lcg() {
  7225. let s = 1;
  7226. return () => (s = (a * s + c) % m) / m;
  7227. }
  7228. function x$1(d) {
  7229. return d.x;
  7230. }
  7231. function y$1(d) {
  7232. return d.y;
  7233. }
  7234. var initialRadius = 10,
  7235. initialAngle = Math.PI * (3 - Math.sqrt(5));
  7236. function simulation(nodes) {
  7237. var simulation,
  7238. alpha = 1,
  7239. alphaMin = 0.001,
  7240. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  7241. alphaTarget = 0,
  7242. velocityDecay = 0.6,
  7243. forces = new Map(),
  7244. stepper = timer(step),
  7245. event = dispatch("tick", "end"),
  7246. random = lcg();
  7247. if (nodes == null) nodes = [];
  7248. function step() {
  7249. tick();
  7250. event.call("tick", simulation);
  7251. if (alpha < alphaMin) {
  7252. stepper.stop();
  7253. event.call("end", simulation);
  7254. }
  7255. }
  7256. function tick(iterations) {
  7257. var i, n = nodes.length, node;
  7258. if (iterations === undefined) iterations = 1;
  7259. for (var k = 0; k < iterations; ++k) {
  7260. alpha += (alphaTarget - alpha) * alphaDecay;
  7261. forces.forEach(function(force) {
  7262. force(alpha);
  7263. });
  7264. for (i = 0; i < n; ++i) {
  7265. node = nodes[i];
  7266. if (node.fx == null) node.x += node.vx *= velocityDecay;
  7267. else node.x = node.fx, node.vx = 0;
  7268. if (node.fy == null) node.y += node.vy *= velocityDecay;
  7269. else node.y = node.fy, node.vy = 0;
  7270. }
  7271. }
  7272. return simulation;
  7273. }
  7274. function initializeNodes() {
  7275. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  7276. node = nodes[i], node.index = i;
  7277. if (node.fx != null) node.x = node.fx;
  7278. if (node.fy != null) node.y = node.fy;
  7279. if (isNaN(node.x) || isNaN(node.y)) {
  7280. var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
  7281. node.x = radius * Math.cos(angle);
  7282. node.y = radius * Math.sin(angle);
  7283. }
  7284. if (isNaN(node.vx) || isNaN(node.vy)) {
  7285. node.vx = node.vy = 0;
  7286. }
  7287. }
  7288. }
  7289. function initializeForce(force) {
  7290. if (force.initialize) force.initialize(nodes, random);
  7291. return force;
  7292. }
  7293. initializeNodes();
  7294. return simulation = {
  7295. tick: tick,
  7296. restart: function() {
  7297. return stepper.restart(step), simulation;
  7298. },
  7299. stop: function() {
  7300. return stepper.stop(), simulation;
  7301. },
  7302. nodes: function(_) {
  7303. return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
  7304. },
  7305. alpha: function(_) {
  7306. return arguments.length ? (alpha = +_, simulation) : alpha;
  7307. },
  7308. alphaMin: function(_) {
  7309. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  7310. },
  7311. alphaDecay: function(_) {
  7312. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  7313. },
  7314. alphaTarget: function(_) {
  7315. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  7316. },
  7317. velocityDecay: function(_) {
  7318. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  7319. },
  7320. randomSource: function(_) {
  7321. return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
  7322. },
  7323. force: function(name, _) {
  7324. return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  7325. },
  7326. find: function(x, y, radius) {
  7327. var i = 0,
  7328. n = nodes.length,
  7329. dx,
  7330. dy,
  7331. d2,
  7332. node,
  7333. closest;
  7334. if (radius == null) radius = Infinity;
  7335. else radius *= radius;
  7336. for (i = 0; i < n; ++i) {
  7337. node = nodes[i];
  7338. dx = x - node.x;
  7339. dy = y - node.y;
  7340. d2 = dx * dx + dy * dy;
  7341. if (d2 < radius) closest = node, radius = d2;
  7342. }
  7343. return closest;
  7344. },
  7345. on: function(name, _) {
  7346. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  7347. }
  7348. };
  7349. }
  7350. function manyBody() {
  7351. var nodes,
  7352. node,
  7353. random,
  7354. alpha,
  7355. strength = constant$7(-30),
  7356. strengths,
  7357. distanceMin2 = 1,
  7358. distanceMax2 = Infinity,
  7359. theta2 = 0.81;
  7360. function force(_) {
  7361. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  7362. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  7363. }
  7364. function initialize() {
  7365. if (!nodes) return;
  7366. var i, n = nodes.length, node;
  7367. strengths = new Array(n);
  7368. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  7369. }
  7370. function accumulate(quad) {
  7371. var strength = 0, q, c, weight = 0, x, y, i;
  7372. // For internal nodes, accumulate forces from child quadrants.
  7373. if (quad.length) {
  7374. for (x = y = i = 0; i < 4; ++i) {
  7375. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  7376. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  7377. }
  7378. }
  7379. quad.x = x / weight;
  7380. quad.y = y / weight;
  7381. }
  7382. // For leaf nodes, accumulate forces from coincident quadrants.
  7383. else {
  7384. q = quad;
  7385. q.x = q.data.x;
  7386. q.y = q.data.y;
  7387. do strength += strengths[q.data.index];
  7388. while (q = q.next);
  7389. }
  7390. quad.value = strength;
  7391. }
  7392. function apply(quad, x1, _, x2) {
  7393. if (!quad.value) return true;
  7394. var x = quad.x - node.x,
  7395. y = quad.y - node.y,
  7396. w = x2 - x1,
  7397. l = x * x + y * y;
  7398. // Apply the Barnes-Hut approximation if possible.
  7399. // Limit forces for very close nodes; randomize direction if coincident.
  7400. if (w * w / theta2 < l) {
  7401. if (l < distanceMax2) {
  7402. if (x === 0) x = jiggle(random), l += x * x;
  7403. if (y === 0) y = jiggle(random), l += y * y;
  7404. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  7405. node.vx += x * quad.value * alpha / l;
  7406. node.vy += y * quad.value * alpha / l;
  7407. }
  7408. return true;
  7409. }
  7410. // Otherwise, process points directly.
  7411. else if (quad.length || l >= distanceMax2) return;
  7412. // Limit forces for very close nodes; randomize direction if coincident.
  7413. if (quad.data !== node || quad.next) {
  7414. if (x === 0) x = jiggle(random), l += x * x;
  7415. if (y === 0) y = jiggle(random), l += y * y;
  7416. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  7417. }
  7418. do if (quad.data !== node) {
  7419. w = strengths[quad.data.index] * alpha / l;
  7420. node.vx += x * w;
  7421. node.vy += y * w;
  7422. } while (quad = quad.next);
  7423. }
  7424. force.initialize = function(_nodes, _random) {
  7425. nodes = _nodes;
  7426. random = _random;
  7427. initialize();
  7428. };
  7429. force.strength = function(_) {
  7430. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  7431. };
  7432. force.distanceMin = function(_) {
  7433. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  7434. };
  7435. force.distanceMax = function(_) {
  7436. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  7437. };
  7438. force.theta = function(_) {
  7439. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  7440. };
  7441. return force;
  7442. }
  7443. function radial(radius, x, y) {
  7444. var nodes,
  7445. strength = constant$7(0.1),
  7446. strengths,
  7447. radiuses;
  7448. if (typeof radius !== "function") radius = constant$7(+radius);
  7449. if (x == null) x = 0;
  7450. if (y == null) y = 0;
  7451. function force(alpha) {
  7452. for (var i = 0, n = nodes.length; i < n; ++i) {
  7453. var node = nodes[i],
  7454. dx = node.x - x || 1e-6,
  7455. dy = node.y - y || 1e-6,
  7456. r = Math.sqrt(dx * dx + dy * dy),
  7457. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  7458. node.vx += dx * k;
  7459. node.vy += dy * k;
  7460. }
  7461. }
  7462. function initialize() {
  7463. if (!nodes) return;
  7464. var i, n = nodes.length;
  7465. strengths = new Array(n);
  7466. radiuses = new Array(n);
  7467. for (i = 0; i < n; ++i) {
  7468. radiuses[i] = +radius(nodes[i], i, nodes);
  7469. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  7470. }
  7471. }
  7472. force.initialize = function(_) {
  7473. nodes = _, initialize();
  7474. };
  7475. force.strength = function(_) {
  7476. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  7477. };
  7478. force.radius = function(_) {
  7479. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  7480. };
  7481. force.x = function(_) {
  7482. return arguments.length ? (x = +_, force) : x;
  7483. };
  7484. force.y = function(_) {
  7485. return arguments.length ? (y = +_, force) : y;
  7486. };
  7487. return force;
  7488. }
  7489. function x$2(x) {
  7490. var strength = constant$7(0.1),
  7491. nodes,
  7492. strengths,
  7493. xz;
  7494. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  7495. function force(alpha) {
  7496. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  7497. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  7498. }
  7499. }
  7500. function initialize() {
  7501. if (!nodes) return;
  7502. var i, n = nodes.length;
  7503. strengths = new Array(n);
  7504. xz = new Array(n);
  7505. for (i = 0; i < n; ++i) {
  7506. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  7507. }
  7508. }
  7509. force.initialize = function(_) {
  7510. nodes = _;
  7511. initialize();
  7512. };
  7513. force.strength = function(_) {
  7514. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  7515. };
  7516. force.x = function(_) {
  7517. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  7518. };
  7519. return force;
  7520. }
  7521. function y$2(y) {
  7522. var strength = constant$7(0.1),
  7523. nodes,
  7524. strengths,
  7525. yz;
  7526. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  7527. function force(alpha) {
  7528. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  7529. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  7530. }
  7531. }
  7532. function initialize() {
  7533. if (!nodes) return;
  7534. var i, n = nodes.length;
  7535. strengths = new Array(n);
  7536. yz = new Array(n);
  7537. for (i = 0; i < n; ++i) {
  7538. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  7539. }
  7540. }
  7541. force.initialize = function(_) {
  7542. nodes = _;
  7543. initialize();
  7544. };
  7545. force.strength = function(_) {
  7546. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  7547. };
  7548. force.y = function(_) {
  7549. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  7550. };
  7551. return force;
  7552. }
  7553. function formatDecimal(x) {
  7554. return Math.abs(x = Math.round(x)) >= 1e21
  7555. ? x.toLocaleString("en").replace(/,/g, "")
  7556. : x.toString(10);
  7557. }
  7558. // Computes the decimal coefficient and exponent of the specified number x with
  7559. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  7560. // For example, formatDecimalParts(1.23) returns ["123", 0].
  7561. function formatDecimalParts(x, p) {
  7562. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  7563. var i, coefficient = x.slice(0, i);
  7564. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  7565. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  7566. return [
  7567. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  7568. +x.slice(i + 1)
  7569. ];
  7570. }
  7571. function exponent$1(x) {
  7572. return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
  7573. }
  7574. function formatGroup(grouping, thousands) {
  7575. return function(value, width) {
  7576. var i = value.length,
  7577. t = [],
  7578. j = 0,
  7579. g = grouping[0],
  7580. length = 0;
  7581. while (i > 0 && g > 0) {
  7582. if (length + g + 1 > width) g = Math.max(1, width - length);
  7583. t.push(value.substring(i -= g, i + g));
  7584. if ((length += g + 1) > width) break;
  7585. g = grouping[j = (j + 1) % grouping.length];
  7586. }
  7587. return t.reverse().join(thousands);
  7588. };
  7589. }
  7590. function formatNumerals(numerals) {
  7591. return function(value) {
  7592. return value.replace(/[0-9]/g, function(i) {
  7593. return numerals[+i];
  7594. });
  7595. };
  7596. }
  7597. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  7598. var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  7599. function formatSpecifier(specifier) {
  7600. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  7601. var match;
  7602. return new FormatSpecifier({
  7603. fill: match[1],
  7604. align: match[2],
  7605. sign: match[3],
  7606. symbol: match[4],
  7607. zero: match[5],
  7608. width: match[6],
  7609. comma: match[7],
  7610. precision: match[8] && match[8].slice(1),
  7611. trim: match[9],
  7612. type: match[10]
  7613. });
  7614. }
  7615. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  7616. function FormatSpecifier(specifier) {
  7617. this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
  7618. this.align = specifier.align === undefined ? ">" : specifier.align + "";
  7619. this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
  7620. this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
  7621. this.zero = !!specifier.zero;
  7622. this.width = specifier.width === undefined ? undefined : +specifier.width;
  7623. this.comma = !!specifier.comma;
  7624. this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
  7625. this.trim = !!specifier.trim;
  7626. this.type = specifier.type === undefined ? "" : specifier.type + "";
  7627. }
  7628. FormatSpecifier.prototype.toString = function() {
  7629. return this.fill
  7630. + this.align
  7631. + this.sign
  7632. + this.symbol
  7633. + (this.zero ? "0" : "")
  7634. + (this.width === undefined ? "" : Math.max(1, this.width | 0))
  7635. + (this.comma ? "," : "")
  7636. + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
  7637. + (this.trim ? "~" : "")
  7638. + this.type;
  7639. };
  7640. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  7641. function formatTrim(s) {
  7642. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  7643. switch (s[i]) {
  7644. case ".": i0 = i1 = i; break;
  7645. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  7646. default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
  7647. }
  7648. }
  7649. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  7650. }
  7651. var prefixExponent;
  7652. function formatPrefixAuto(x, p) {
  7653. var d = formatDecimalParts(x, p);
  7654. if (!d) return x + "";
  7655. var coefficient = d[0],
  7656. exponent = d[1],
  7657. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  7658. n = coefficient.length;
  7659. return i === n ? coefficient
  7660. : i > n ? coefficient + new Array(i - n + 1).join("0")
  7661. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  7662. : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  7663. }
  7664. function formatRounded(x, p) {
  7665. var d = formatDecimalParts(x, p);
  7666. if (!d) return x + "";
  7667. var coefficient = d[0],
  7668. exponent = d[1];
  7669. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  7670. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  7671. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  7672. }
  7673. var formatTypes = {
  7674. "%": (x, p) => (x * 100).toFixed(p),
  7675. "b": (x) => Math.round(x).toString(2),
  7676. "c": (x) => x + "",
  7677. "d": formatDecimal,
  7678. "e": (x, p) => x.toExponential(p),
  7679. "f": (x, p) => x.toFixed(p),
  7680. "g": (x, p) => x.toPrecision(p),
  7681. "o": (x) => Math.round(x).toString(8),
  7682. "p": (x, p) => formatRounded(x * 100, p),
  7683. "r": formatRounded,
  7684. "s": formatPrefixAuto,
  7685. "X": (x) => Math.round(x).toString(16).toUpperCase(),
  7686. "x": (x) => Math.round(x).toString(16)
  7687. };
  7688. function identity$3(x) {
  7689. return x;
  7690. }
  7691. var map$1 = Array.prototype.map,
  7692. prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  7693. function formatLocale(locale) {
  7694. var group = locale.grouping === undefined || locale.thousands === undefined ? identity$3 : formatGroup(map$1.call(locale.grouping, Number), locale.thousands + ""),
  7695. currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
  7696. currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
  7697. decimal = locale.decimal === undefined ? "." : locale.decimal + "",
  7698. numerals = locale.numerals === undefined ? identity$3 : formatNumerals(map$1.call(locale.numerals, String)),
  7699. percent = locale.percent === undefined ? "%" : locale.percent + "",
  7700. minus = locale.minus === undefined ? "\u2212" : locale.minus + "",
  7701. nan = locale.nan === undefined ? "NaN" : locale.nan + "";
  7702. function newFormat(specifier) {
  7703. specifier = formatSpecifier(specifier);
  7704. var fill = specifier.fill,
  7705. align = specifier.align,
  7706. sign = specifier.sign,
  7707. symbol = specifier.symbol,
  7708. zero = specifier.zero,
  7709. width = specifier.width,
  7710. comma = specifier.comma,
  7711. precision = specifier.precision,
  7712. trim = specifier.trim,
  7713. type = specifier.type;
  7714. // The "n" type is an alias for ",g".
  7715. if (type === "n") comma = true, type = "g";
  7716. // The "" type, and any invalid type, is an alias for ".12~g".
  7717. else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
  7718. // If zero fill is specified, padding goes after sign and before digits.
  7719. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  7720. // Compute the prefix and suffix.
  7721. // For SI-prefix, the suffix is lazily computed.
  7722. var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  7723. suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
  7724. // What format function should we use?
  7725. // Is this an integer type?
  7726. // Can this type generate exponential notation?
  7727. var formatType = formatTypes[type],
  7728. maybeSuffix = /[defgprs%]/.test(type);
  7729. // Set the default precision if not specified,
  7730. // or clamp the specified precision to the supported range.
  7731. // For significant precision, it must be in [1, 21].
  7732. // For fixed precision, it must be in [0, 20].
  7733. precision = precision === undefined ? 6
  7734. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  7735. : Math.max(0, Math.min(20, precision));
  7736. function format(value) {
  7737. var valuePrefix = prefix,
  7738. valueSuffix = suffix,
  7739. i, n, c;
  7740. if (type === "c") {
  7741. valueSuffix = formatType(value) + valueSuffix;
  7742. value = "";
  7743. } else {
  7744. value = +value;
  7745. // Determine the sign. -0 is not less than 0, but 1 / -0 is!
  7746. var valueNegative = value < 0 || 1 / value < 0;
  7747. // Perform the initial formatting.
  7748. value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
  7749. // Trim insignificant zeros.
  7750. if (trim) value = formatTrim(value);
  7751. // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
  7752. if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
  7753. // Compute the prefix and suffix.
  7754. valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  7755. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  7756. // Break the formatted value into the integer “value” part that can be
  7757. // grouped, and fractional or exponential “suffix” part that is not.
  7758. if (maybeSuffix) {
  7759. i = -1, n = value.length;
  7760. while (++i < n) {
  7761. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  7762. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  7763. value = value.slice(0, i);
  7764. break;
  7765. }
  7766. }
  7767. }
  7768. }
  7769. // If the fill character is not "0", grouping is applied before padding.
  7770. if (comma && !zero) value = group(value, Infinity);
  7771. // Compute the padding.
  7772. var length = valuePrefix.length + value.length + valueSuffix.length,
  7773. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  7774. // If the fill character is "0", grouping is applied after padding.
  7775. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  7776. // Reconstruct the final output based on the desired alignment.
  7777. switch (align) {
  7778. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  7779. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  7780. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  7781. default: value = padding + valuePrefix + value + valueSuffix; break;
  7782. }
  7783. return numerals(value);
  7784. }
  7785. format.toString = function() {
  7786. return specifier + "";
  7787. };
  7788. return format;
  7789. }
  7790. function formatPrefix(specifier, value) {
  7791. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  7792. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  7793. k = Math.pow(10, -e),
  7794. prefix = prefixes[8 + e / 3];
  7795. return function(value) {
  7796. return f(k * value) + prefix;
  7797. };
  7798. }
  7799. return {
  7800. format: newFormat,
  7801. formatPrefix: formatPrefix
  7802. };
  7803. }
  7804. var locale;
  7805. defaultLocale({
  7806. thousands: ",",
  7807. grouping: [3],
  7808. currency: ["$", ""]
  7809. });
  7810. function defaultLocale(definition) {
  7811. locale = formatLocale(definition);
  7812. exports.format = locale.format;
  7813. exports.formatPrefix = locale.formatPrefix;
  7814. return locale;
  7815. }
  7816. function precisionFixed(step) {
  7817. return Math.max(0, -exponent$1(Math.abs(step)));
  7818. }
  7819. function precisionPrefix(step, value) {
  7820. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  7821. }
  7822. function precisionRound(step, max) {
  7823. step = Math.abs(step), max = Math.abs(max) - step;
  7824. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  7825. }
  7826. var epsilon$4 = 1e-6;
  7827. var epsilon2$1 = 1e-12;
  7828. var pi$3 = Math.PI;
  7829. var halfPi$2 = pi$3 / 2;
  7830. var quarterPi = pi$3 / 4;
  7831. var tau$4 = pi$3 * 2;
  7832. var degrees$2 = 180 / pi$3;
  7833. var radians$1 = pi$3 / 180;
  7834. var abs$2 = Math.abs;
  7835. var atan = Math.atan;
  7836. var atan2 = Math.atan2;
  7837. var cos$1 = Math.cos;
  7838. var ceil = Math.ceil;
  7839. var exp = Math.exp;
  7840. var hypot = Math.hypot;
  7841. var log = Math.log;
  7842. var pow$1 = Math.pow;
  7843. var sin$1 = Math.sin;
  7844. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  7845. var sqrt = Math.sqrt;
  7846. var tan = Math.tan;
  7847. function acos(x) {
  7848. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  7849. }
  7850. function asin(x) {
  7851. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  7852. }
  7853. function haversin(x) {
  7854. return (x = sin$1(x / 2)) * x;
  7855. }
  7856. function noop$2() {}
  7857. function streamGeometry(geometry, stream) {
  7858. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  7859. streamGeometryType[geometry.type](geometry, stream);
  7860. }
  7861. }
  7862. var streamObjectType = {
  7863. Feature: function(object, stream) {
  7864. streamGeometry(object.geometry, stream);
  7865. },
  7866. FeatureCollection: function(object, stream) {
  7867. var features = object.features, i = -1, n = features.length;
  7868. while (++i < n) streamGeometry(features[i].geometry, stream);
  7869. }
  7870. };
  7871. var streamGeometryType = {
  7872. Sphere: function(object, stream) {
  7873. stream.sphere();
  7874. },
  7875. Point: function(object, stream) {
  7876. object = object.coordinates;
  7877. stream.point(object[0], object[1], object[2]);
  7878. },
  7879. MultiPoint: function(object, stream) {
  7880. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7881. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  7882. },
  7883. LineString: function(object, stream) {
  7884. streamLine(object.coordinates, stream, 0);
  7885. },
  7886. MultiLineString: function(object, stream) {
  7887. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7888. while (++i < n) streamLine(coordinates[i], stream, 0);
  7889. },
  7890. Polygon: function(object, stream) {
  7891. streamPolygon(object.coordinates, stream);
  7892. },
  7893. MultiPolygon: function(object, stream) {
  7894. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7895. while (++i < n) streamPolygon(coordinates[i], stream);
  7896. },
  7897. GeometryCollection: function(object, stream) {
  7898. var geometries = object.geometries, i = -1, n = geometries.length;
  7899. while (++i < n) streamGeometry(geometries[i], stream);
  7900. }
  7901. };
  7902. function streamLine(coordinates, stream, closed) {
  7903. var i = -1, n = coordinates.length - closed, coordinate;
  7904. stream.lineStart();
  7905. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  7906. stream.lineEnd();
  7907. }
  7908. function streamPolygon(coordinates, stream) {
  7909. var i = -1, n = coordinates.length;
  7910. stream.polygonStart();
  7911. while (++i < n) streamLine(coordinates[i], stream, 1);
  7912. stream.polygonEnd();
  7913. }
  7914. function geoStream(object, stream) {
  7915. if (object && streamObjectType.hasOwnProperty(object.type)) {
  7916. streamObjectType[object.type](object, stream);
  7917. } else {
  7918. streamGeometry(object, stream);
  7919. }
  7920. }
  7921. var areaRingSum = new Adder();
  7922. // hello?
  7923. var areaSum = new Adder(),
  7924. lambda00,
  7925. phi00,
  7926. lambda0,
  7927. cosPhi0,
  7928. sinPhi0;
  7929. var areaStream = {
  7930. point: noop$2,
  7931. lineStart: noop$2,
  7932. lineEnd: noop$2,
  7933. polygonStart: function() {
  7934. areaRingSum = new Adder();
  7935. areaStream.lineStart = areaRingStart;
  7936. areaStream.lineEnd = areaRingEnd;
  7937. },
  7938. polygonEnd: function() {
  7939. var areaRing = +areaRingSum;
  7940. areaSum.add(areaRing < 0 ? tau$4 + areaRing : areaRing);
  7941. this.lineStart = this.lineEnd = this.point = noop$2;
  7942. },
  7943. sphere: function() {
  7944. areaSum.add(tau$4);
  7945. }
  7946. };
  7947. function areaRingStart() {
  7948. areaStream.point = areaPointFirst;
  7949. }
  7950. function areaRingEnd() {
  7951. areaPoint(lambda00, phi00);
  7952. }
  7953. function areaPointFirst(lambda, phi) {
  7954. areaStream.point = areaPoint;
  7955. lambda00 = lambda, phi00 = phi;
  7956. lambda *= radians$1, phi *= radians$1;
  7957. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  7958. }
  7959. function areaPoint(lambda, phi) {
  7960. lambda *= radians$1, phi *= radians$1;
  7961. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  7962. // Spherical excess E for a spherical triangle with vertices: south pole,
  7963. // previous point, current point. Uses a formula derived from Cagnoli’s
  7964. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  7965. var dLambda = lambda - lambda0,
  7966. sdLambda = dLambda >= 0 ? 1 : -1,
  7967. adLambda = sdLambda * dLambda,
  7968. cosPhi = cos$1(phi),
  7969. sinPhi = sin$1(phi),
  7970. k = sinPhi0 * sinPhi,
  7971. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  7972. v = k * sdLambda * sin$1(adLambda);
  7973. areaRingSum.add(atan2(v, u));
  7974. // Advance the previous points.
  7975. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  7976. }
  7977. function area$1(object) {
  7978. areaSum = new Adder();
  7979. geoStream(object, areaStream);
  7980. return areaSum * 2;
  7981. }
  7982. function spherical(cartesian) {
  7983. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  7984. }
  7985. function cartesian(spherical) {
  7986. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  7987. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  7988. }
  7989. function cartesianDot(a, b) {
  7990. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  7991. }
  7992. function cartesianCross(a, b) {
  7993. 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]];
  7994. }
  7995. // TODO return a
  7996. function cartesianAddInPlace(a, b) {
  7997. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  7998. }
  7999. function cartesianScale(vector, k) {
  8000. return [vector[0] * k, vector[1] * k, vector[2] * k];
  8001. }
  8002. // TODO return d
  8003. function cartesianNormalizeInPlace(d) {
  8004. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  8005. d[0] /= l, d[1] /= l, d[2] /= l;
  8006. }
  8007. var lambda0$1, phi0, lambda1, phi1, // bounds
  8008. lambda2, // previous lambda-coordinate
  8009. lambda00$1, phi00$1, // first point
  8010. p0, // previous 3D point
  8011. deltaSum,
  8012. ranges,
  8013. range$1;
  8014. var boundsStream = {
  8015. point: boundsPoint,
  8016. lineStart: boundsLineStart,
  8017. lineEnd: boundsLineEnd,
  8018. polygonStart: function() {
  8019. boundsStream.point = boundsRingPoint;
  8020. boundsStream.lineStart = boundsRingStart;
  8021. boundsStream.lineEnd = boundsRingEnd;
  8022. deltaSum = new Adder();
  8023. areaStream.polygonStart();
  8024. },
  8025. polygonEnd: function() {
  8026. areaStream.polygonEnd();
  8027. boundsStream.point = boundsPoint;
  8028. boundsStream.lineStart = boundsLineStart;
  8029. boundsStream.lineEnd = boundsLineEnd;
  8030. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  8031. else if (deltaSum > epsilon$4) phi1 = 90;
  8032. else if (deltaSum < -epsilon$4) phi0 = -90;
  8033. range$1[0] = lambda0$1, range$1[1] = lambda1;
  8034. },
  8035. sphere: function() {
  8036. lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  8037. }
  8038. };
  8039. function boundsPoint(lambda, phi) {
  8040. ranges.push(range$1 = [lambda0$1 = lambda, lambda1 = lambda]);
  8041. if (phi < phi0) phi0 = phi;
  8042. if (phi > phi1) phi1 = phi;
  8043. }
  8044. function linePoint(lambda, phi) {
  8045. var p = cartesian([lambda * radians$1, phi * radians$1]);
  8046. if (p0) {
  8047. var normal = cartesianCross(p0, p),
  8048. equatorial = [normal[1], -normal[0], 0],
  8049. inflection = cartesianCross(equatorial, normal);
  8050. cartesianNormalizeInPlace(inflection);
  8051. inflection = spherical(inflection);
  8052. var delta = lambda - lambda2,
  8053. sign = delta > 0 ? 1 : -1,
  8054. lambdai = inflection[0] * degrees$2 * sign,
  8055. phii,
  8056. antimeridian = abs$2(delta) > 180;
  8057. if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  8058. phii = inflection[1] * degrees$2;
  8059. if (phii > phi1) phi1 = phii;
  8060. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  8061. phii = -inflection[1] * degrees$2;
  8062. if (phii < phi0) phi0 = phii;
  8063. } else {
  8064. if (phi < phi0) phi0 = phi;
  8065. if (phi > phi1) phi1 = phi;
  8066. }
  8067. if (antimeridian) {
  8068. if (lambda < lambda2) {
  8069. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  8070. } else {
  8071. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  8072. }
  8073. } else {
  8074. if (lambda1 >= lambda0$1) {
  8075. if (lambda < lambda0$1) lambda0$1 = lambda;
  8076. if (lambda > lambda1) lambda1 = lambda;
  8077. } else {
  8078. if (lambda > lambda2) {
  8079. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  8080. } else {
  8081. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  8082. }
  8083. }
  8084. }
  8085. } else {
  8086. ranges.push(range$1 = [lambda0$1 = lambda, lambda1 = lambda]);
  8087. }
  8088. if (phi < phi0) phi0 = phi;
  8089. if (phi > phi1) phi1 = phi;
  8090. p0 = p, lambda2 = lambda;
  8091. }
  8092. function boundsLineStart() {
  8093. boundsStream.point = linePoint;
  8094. }
  8095. function boundsLineEnd() {
  8096. range$1[0] = lambda0$1, range$1[1] = lambda1;
  8097. boundsStream.point = boundsPoint;
  8098. p0 = null;
  8099. }
  8100. function boundsRingPoint(lambda, phi) {
  8101. if (p0) {
  8102. var delta = lambda - lambda2;
  8103. deltaSum.add(abs$2(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  8104. } else {
  8105. lambda00$1 = lambda, phi00$1 = phi;
  8106. }
  8107. areaStream.point(lambda, phi);
  8108. linePoint(lambda, phi);
  8109. }
  8110. function boundsRingStart() {
  8111. areaStream.lineStart();
  8112. }
  8113. function boundsRingEnd() {
  8114. boundsRingPoint(lambda00$1, phi00$1);
  8115. areaStream.lineEnd();
  8116. if (abs$2(deltaSum) > epsilon$4) lambda0$1 = -(lambda1 = 180);
  8117. range$1[0] = lambda0$1, range$1[1] = lambda1;
  8118. p0 = null;
  8119. }
  8120. // Finds the left-right distance between two longitudes.
  8121. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  8122. // the distance between ±180° to be 360°.
  8123. function angle(lambda0, lambda1) {
  8124. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  8125. }
  8126. function rangeCompare(a, b) {
  8127. return a[0] - b[0];
  8128. }
  8129. function rangeContains(range, x) {
  8130. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  8131. }
  8132. function bounds(feature) {
  8133. var i, n, a, b, merged, deltaMax, delta;
  8134. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  8135. ranges = [];
  8136. geoStream(feature, boundsStream);
  8137. // First, sort ranges by their minimum longitudes.
  8138. if (n = ranges.length) {
  8139. ranges.sort(rangeCompare);
  8140. // Then, merge any ranges that overlap.
  8141. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  8142. b = ranges[i];
  8143. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  8144. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  8145. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  8146. } else {
  8147. merged.push(a = b);
  8148. }
  8149. }
  8150. // Finally, find the largest gap between the merged ranges.
  8151. // The final bounding box will be the inverse of this gap.
  8152. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  8153. b = merged[i];
  8154. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  8155. }
  8156. }
  8157. ranges = range$1 = null;
  8158. return lambda0$1 === Infinity || phi0 === Infinity
  8159. ? [[NaN, NaN], [NaN, NaN]]
  8160. : [[lambda0$1, phi0], [lambda1, phi1]];
  8161. }
  8162. var W0, W1,
  8163. X0, Y0, Z0,
  8164. X1, Y1, Z1,
  8165. X2, Y2, Z2,
  8166. lambda00$2, phi00$2, // first point
  8167. x0, y0, z0; // previous point
  8168. var centroidStream = {
  8169. sphere: noop$2,
  8170. point: centroidPoint,
  8171. lineStart: centroidLineStart,
  8172. lineEnd: centroidLineEnd,
  8173. polygonStart: function() {
  8174. centroidStream.lineStart = centroidRingStart;
  8175. centroidStream.lineEnd = centroidRingEnd;
  8176. },
  8177. polygonEnd: function() {
  8178. centroidStream.lineStart = centroidLineStart;
  8179. centroidStream.lineEnd = centroidLineEnd;
  8180. }
  8181. };
  8182. // Arithmetic mean of Cartesian vectors.
  8183. function centroidPoint(lambda, phi) {
  8184. lambda *= radians$1, phi *= radians$1;
  8185. var cosPhi = cos$1(phi);
  8186. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  8187. }
  8188. function centroidPointCartesian(x, y, z) {
  8189. ++W0;
  8190. X0 += (x - X0) / W0;
  8191. Y0 += (y - Y0) / W0;
  8192. Z0 += (z - Z0) / W0;
  8193. }
  8194. function centroidLineStart() {
  8195. centroidStream.point = centroidLinePointFirst;
  8196. }
  8197. function centroidLinePointFirst(lambda, phi) {
  8198. lambda *= radians$1, phi *= radians$1;
  8199. var cosPhi = cos$1(phi);
  8200. x0 = cosPhi * cos$1(lambda);
  8201. y0 = cosPhi * sin$1(lambda);
  8202. z0 = sin$1(phi);
  8203. centroidStream.point = centroidLinePoint;
  8204. centroidPointCartesian(x0, y0, z0);
  8205. }
  8206. function centroidLinePoint(lambda, phi) {
  8207. lambda *= radians$1, phi *= radians$1;
  8208. var cosPhi = cos$1(phi),
  8209. x = cosPhi * cos$1(lambda),
  8210. y = cosPhi * sin$1(lambda),
  8211. z = sin$1(phi),
  8212. w = atan2(sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
  8213. W1 += w;
  8214. X1 += w * (x0 + (x0 = x));
  8215. Y1 += w * (y0 + (y0 = y));
  8216. Z1 += w * (z0 + (z0 = z));
  8217. centroidPointCartesian(x0, y0, z0);
  8218. }
  8219. function centroidLineEnd() {
  8220. centroidStream.point = centroidPoint;
  8221. }
  8222. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  8223. // J. Applied Mechanics 42, 239 (1975).
  8224. function centroidRingStart() {
  8225. centroidStream.point = centroidRingPointFirst;
  8226. }
  8227. function centroidRingEnd() {
  8228. centroidRingPoint(lambda00$2, phi00$2);
  8229. centroidStream.point = centroidPoint;
  8230. }
  8231. function centroidRingPointFirst(lambda, phi) {
  8232. lambda00$2 = lambda, phi00$2 = phi;
  8233. lambda *= radians$1, phi *= radians$1;
  8234. centroidStream.point = centroidRingPoint;
  8235. var cosPhi = cos$1(phi);
  8236. x0 = cosPhi * cos$1(lambda);
  8237. y0 = cosPhi * sin$1(lambda);
  8238. z0 = sin$1(phi);
  8239. centroidPointCartesian(x0, y0, z0);
  8240. }
  8241. function centroidRingPoint(lambda, phi) {
  8242. lambda *= radians$1, phi *= radians$1;
  8243. var cosPhi = cos$1(phi),
  8244. x = cosPhi * cos$1(lambda),
  8245. y = cosPhi * sin$1(lambda),
  8246. z = sin$1(phi),
  8247. cx = y0 * z - z0 * y,
  8248. cy = z0 * x - x0 * z,
  8249. cz = x0 * y - y0 * x,
  8250. m = hypot(cx, cy, cz),
  8251. w = asin(m), // line weight = angle
  8252. v = m && -w / m; // area weight multiplier
  8253. X2.add(v * cx);
  8254. Y2.add(v * cy);
  8255. Z2.add(v * cz);
  8256. W1 += w;
  8257. X1 += w * (x0 + (x0 = x));
  8258. Y1 += w * (y0 + (y0 = y));
  8259. Z1 += w * (z0 + (z0 = z));
  8260. centroidPointCartesian(x0, y0, z0);
  8261. }
  8262. function centroid(object) {
  8263. W0 = W1 =
  8264. X0 = Y0 = Z0 =
  8265. X1 = Y1 = Z1 = 0;
  8266. X2 = new Adder();
  8267. Y2 = new Adder();
  8268. Z2 = new Adder();
  8269. geoStream(object, centroidStream);
  8270. var x = +X2,
  8271. y = +Y2,
  8272. z = +Z2,
  8273. m = hypot(x, y, z);
  8274. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  8275. if (m < epsilon2$1) {
  8276. x = X1, y = Y1, z = Z1;
  8277. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  8278. if (W1 < epsilon$4) x = X0, y = Y0, z = Z0;
  8279. m = hypot(x, y, z);
  8280. // If the feature still has an undefined ccentroid, then return.
  8281. if (m < epsilon2$1) return [NaN, NaN];
  8282. }
  8283. return [atan2(y, x) * degrees$2, asin(z / m) * degrees$2];
  8284. }
  8285. function constant$8(x) {
  8286. return function() {
  8287. return x;
  8288. };
  8289. }
  8290. function compose(a, b) {
  8291. function compose(x, y) {
  8292. return x = a(x, y), b(x[0], x[1]);
  8293. }
  8294. if (a.invert && b.invert) compose.invert = function(x, y) {
  8295. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  8296. };
  8297. return compose;
  8298. }
  8299. function rotationIdentity(lambda, phi) {
  8300. return [abs$2(lambda) > pi$3 ? lambda + Math.round(-lambda / tau$4) * tau$4 : lambda, phi];
  8301. }
  8302. rotationIdentity.invert = rotationIdentity;
  8303. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  8304. return (deltaLambda %= tau$4) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  8305. : rotationLambda(deltaLambda))
  8306. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  8307. : rotationIdentity);
  8308. }
  8309. function forwardRotationLambda(deltaLambda) {
  8310. return function(lambda, phi) {
  8311. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$4 : lambda < -pi$3 ? lambda + tau$4 : lambda, phi];
  8312. };
  8313. }
  8314. function rotationLambda(deltaLambda) {
  8315. var rotation = forwardRotationLambda(deltaLambda);
  8316. rotation.invert = forwardRotationLambda(-deltaLambda);
  8317. return rotation;
  8318. }
  8319. function rotationPhiGamma(deltaPhi, deltaGamma) {
  8320. var cosDeltaPhi = cos$1(deltaPhi),
  8321. sinDeltaPhi = sin$1(deltaPhi),
  8322. cosDeltaGamma = cos$1(deltaGamma),
  8323. sinDeltaGamma = sin$1(deltaGamma);
  8324. function rotation(lambda, phi) {
  8325. var cosPhi = cos$1(phi),
  8326. x = cos$1(lambda) * cosPhi,
  8327. y = sin$1(lambda) * cosPhi,
  8328. z = sin$1(phi),
  8329. k = z * cosDeltaPhi + x * sinDeltaPhi;
  8330. return [
  8331. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  8332. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  8333. ];
  8334. }
  8335. rotation.invert = function(lambda, phi) {
  8336. var cosPhi = cos$1(phi),
  8337. x = cos$1(lambda) * cosPhi,
  8338. y = sin$1(lambda) * cosPhi,
  8339. z = sin$1(phi),
  8340. k = z * cosDeltaGamma - y * sinDeltaGamma;
  8341. return [
  8342. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  8343. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  8344. ];
  8345. };
  8346. return rotation;
  8347. }
  8348. function rotation(rotate) {
  8349. rotate = rotateRadians(rotate[0] * radians$1, rotate[1] * radians$1, rotate.length > 2 ? rotate[2] * radians$1 : 0);
  8350. function forward(coordinates) {
  8351. coordinates = rotate(coordinates[0] * radians$1, coordinates[1] * radians$1);
  8352. return coordinates[0] *= degrees$2, coordinates[1] *= degrees$2, coordinates;
  8353. }
  8354. forward.invert = function(coordinates) {
  8355. coordinates = rotate.invert(coordinates[0] * radians$1, coordinates[1] * radians$1);
  8356. return coordinates[0] *= degrees$2, coordinates[1] *= degrees$2, coordinates;
  8357. };
  8358. return forward;
  8359. }
  8360. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  8361. function circleStream(stream, radius, delta, direction, t0, t1) {
  8362. if (!delta) return;
  8363. var cosRadius = cos$1(radius),
  8364. sinRadius = sin$1(radius),
  8365. step = direction * delta;
  8366. if (t0 == null) {
  8367. t0 = radius + direction * tau$4;
  8368. t1 = radius - step / 2;
  8369. } else {
  8370. t0 = circleRadius(cosRadius, t0);
  8371. t1 = circleRadius(cosRadius, t1);
  8372. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$4;
  8373. }
  8374. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  8375. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  8376. stream.point(point[0], point[1]);
  8377. }
  8378. }
  8379. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  8380. function circleRadius(cosRadius, point) {
  8381. point = cartesian(point), point[0] -= cosRadius;
  8382. cartesianNormalizeInPlace(point);
  8383. var radius = acos(-point[1]);
  8384. return ((-point[2] < 0 ? -radius : radius) + tau$4 - epsilon$4) % tau$4;
  8385. }
  8386. function circle() {
  8387. var center = constant$8([0, 0]),
  8388. radius = constant$8(90),
  8389. precision = constant$8(6),
  8390. ring,
  8391. rotate,
  8392. stream = {point: point};
  8393. function point(x, y) {
  8394. ring.push(x = rotate(x, y));
  8395. x[0] *= degrees$2, x[1] *= degrees$2;
  8396. }
  8397. function circle() {
  8398. var c = center.apply(this, arguments),
  8399. r = radius.apply(this, arguments) * radians$1,
  8400. p = precision.apply(this, arguments) * radians$1;
  8401. ring = [];
  8402. rotate = rotateRadians(-c[0] * radians$1, -c[1] * radians$1, 0).invert;
  8403. circleStream(stream, r, p, 1);
  8404. c = {type: "Polygon", coordinates: [ring]};
  8405. ring = rotate = null;
  8406. return c;
  8407. }
  8408. circle.center = function(_) {
  8409. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  8410. };
  8411. circle.radius = function(_) {
  8412. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  8413. };
  8414. circle.precision = function(_) {
  8415. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  8416. };
  8417. return circle;
  8418. }
  8419. function clipBuffer() {
  8420. var lines = [],
  8421. line;
  8422. return {
  8423. point: function(x, y, m) {
  8424. line.push([x, y, m]);
  8425. },
  8426. lineStart: function() {
  8427. lines.push(line = []);
  8428. },
  8429. lineEnd: noop$2,
  8430. rejoin: function() {
  8431. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  8432. },
  8433. result: function() {
  8434. var result = lines;
  8435. lines = [];
  8436. line = null;
  8437. return result;
  8438. }
  8439. };
  8440. }
  8441. function pointEqual(a, b) {
  8442. return abs$2(a[0] - b[0]) < epsilon$4 && abs$2(a[1] - b[1]) < epsilon$4;
  8443. }
  8444. function Intersection(point, points, other, entry) {
  8445. this.x = point;
  8446. this.z = points;
  8447. this.o = other; // another intersection
  8448. this.e = entry; // is an entry?
  8449. this.v = false; // visited
  8450. this.n = this.p = null; // next & previous
  8451. }
  8452. // A generalized polygon clipping algorithm: given a polygon that has been cut
  8453. // into its visible line segments, and rejoins the segments by interpolating
  8454. // along the clip edge.
  8455. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  8456. var subject = [],
  8457. clip = [],
  8458. i,
  8459. n;
  8460. segments.forEach(function(segment) {
  8461. if ((n = segment.length - 1) <= 0) return;
  8462. var n, p0 = segment[0], p1 = segment[n], x;
  8463. if (pointEqual(p0, p1)) {
  8464. if (!p0[2] && !p1[2]) {
  8465. stream.lineStart();
  8466. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  8467. stream.lineEnd();
  8468. return;
  8469. }
  8470. // handle degenerate cases by moving the point
  8471. p1[0] += 2 * epsilon$4;
  8472. }
  8473. subject.push(x = new Intersection(p0, segment, null, true));
  8474. clip.push(x.o = new Intersection(p0, null, x, false));
  8475. subject.push(x = new Intersection(p1, segment, null, false));
  8476. clip.push(x.o = new Intersection(p1, null, x, true));
  8477. });
  8478. if (!subject.length) return;
  8479. clip.sort(compareIntersection);
  8480. link$1(subject);
  8481. link$1(clip);
  8482. for (i = 0, n = clip.length; i < n; ++i) {
  8483. clip[i].e = startInside = !startInside;
  8484. }
  8485. var start = subject[0],
  8486. points,
  8487. point;
  8488. while (1) {
  8489. // Find first unvisited intersection.
  8490. var current = start,
  8491. isSubject = true;
  8492. while (current.v) if ((current = current.n) === start) return;
  8493. points = current.z;
  8494. stream.lineStart();
  8495. do {
  8496. current.v = current.o.v = true;
  8497. if (current.e) {
  8498. if (isSubject) {
  8499. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  8500. } else {
  8501. interpolate(current.x, current.n.x, 1, stream);
  8502. }
  8503. current = current.n;
  8504. } else {
  8505. if (isSubject) {
  8506. points = current.p.z;
  8507. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  8508. } else {
  8509. interpolate(current.x, current.p.x, -1, stream);
  8510. }
  8511. current = current.p;
  8512. }
  8513. current = current.o;
  8514. points = current.z;
  8515. isSubject = !isSubject;
  8516. } while (!current.v);
  8517. stream.lineEnd();
  8518. }
  8519. }
  8520. function link$1(array) {
  8521. if (!(n = array.length)) return;
  8522. var n,
  8523. i = 0,
  8524. a = array[0],
  8525. b;
  8526. while (++i < n) {
  8527. a.n = b = array[i];
  8528. b.p = a;
  8529. a = b;
  8530. }
  8531. a.n = b = array[0];
  8532. b.p = a;
  8533. }
  8534. function longitude(point) {
  8535. if (abs$2(point[0]) <= pi$3)
  8536. return point[0];
  8537. else
  8538. return sign(point[0]) * ((abs$2(point[0]) + pi$3) % tau$4 - pi$3);
  8539. }
  8540. function polygonContains(polygon, point) {
  8541. var lambda = longitude(point),
  8542. phi = point[1],
  8543. sinPhi = sin$1(phi),
  8544. normal = [sin$1(lambda), -cos$1(lambda), 0],
  8545. angle = 0,
  8546. winding = 0;
  8547. var sum = new Adder();
  8548. if (sinPhi === 1) phi = halfPi$2 + epsilon$4;
  8549. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$4;
  8550. for (var i = 0, n = polygon.length; i < n; ++i) {
  8551. if (!(m = (ring = polygon[i]).length)) continue;
  8552. var ring,
  8553. m,
  8554. point0 = ring[m - 1],
  8555. lambda0 = longitude(point0),
  8556. phi0 = point0[1] / 2 + quarterPi,
  8557. sinPhi0 = sin$1(phi0),
  8558. cosPhi0 = cos$1(phi0);
  8559. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  8560. var point1 = ring[j],
  8561. lambda1 = longitude(point1),
  8562. phi1 = point1[1] / 2 + quarterPi,
  8563. sinPhi1 = sin$1(phi1),
  8564. cosPhi1 = cos$1(phi1),
  8565. delta = lambda1 - lambda0,
  8566. sign = delta >= 0 ? 1 : -1,
  8567. absDelta = sign * delta,
  8568. antimeridian = absDelta > pi$3,
  8569. k = sinPhi0 * sinPhi1;
  8570. sum.add(atan2(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  8571. angle += antimeridian ? delta + sign * tau$4 : delta;
  8572. // Are the longitudes either side of the point’s meridian (lambda),
  8573. // and are the latitudes smaller than the parallel (phi)?
  8574. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  8575. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  8576. cartesianNormalizeInPlace(arc);
  8577. var intersection = cartesianCross(normal, arc);
  8578. cartesianNormalizeInPlace(intersection);
  8579. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  8580. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  8581. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  8582. }
  8583. }
  8584. }
  8585. }
  8586. // First, determine whether the South pole is inside or outside:
  8587. //
  8588. // It is inside if:
  8589. // * the polygon winds around it in a clockwise direction.
  8590. // * the polygon does not (cumulatively) wind around it, but has a negative
  8591. // (counter-clockwise) area.
  8592. //
  8593. // Second, count the (signed) number of times a segment crosses a lambda
  8594. // from the point to the South pole. If it is zero, then the point is the
  8595. // same side as the South pole.
  8596. return (angle < -epsilon$4 || angle < epsilon$4 && sum < -epsilon2$1) ^ (winding & 1);
  8597. }
  8598. function clip(pointVisible, clipLine, interpolate, start) {
  8599. return function(sink) {
  8600. var line = clipLine(sink),
  8601. ringBuffer = clipBuffer(),
  8602. ringSink = clipLine(ringBuffer),
  8603. polygonStarted = false,
  8604. polygon,
  8605. segments,
  8606. ring;
  8607. var clip = {
  8608. point: point,
  8609. lineStart: lineStart,
  8610. lineEnd: lineEnd,
  8611. polygonStart: function() {
  8612. clip.point = pointRing;
  8613. clip.lineStart = ringStart;
  8614. clip.lineEnd = ringEnd;
  8615. segments = [];
  8616. polygon = [];
  8617. },
  8618. polygonEnd: function() {
  8619. clip.point = point;
  8620. clip.lineStart = lineStart;
  8621. clip.lineEnd = lineEnd;
  8622. segments = merge(segments);
  8623. var startInside = polygonContains(polygon, start);
  8624. if (segments.length) {
  8625. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  8626. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  8627. } else if (startInside) {
  8628. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  8629. sink.lineStart();
  8630. interpolate(null, null, 1, sink);
  8631. sink.lineEnd();
  8632. }
  8633. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  8634. segments = polygon = null;
  8635. },
  8636. sphere: function() {
  8637. sink.polygonStart();
  8638. sink.lineStart();
  8639. interpolate(null, null, 1, sink);
  8640. sink.lineEnd();
  8641. sink.polygonEnd();
  8642. }
  8643. };
  8644. function point(lambda, phi) {
  8645. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  8646. }
  8647. function pointLine(lambda, phi) {
  8648. line.point(lambda, phi);
  8649. }
  8650. function lineStart() {
  8651. clip.point = pointLine;
  8652. line.lineStart();
  8653. }
  8654. function lineEnd() {
  8655. clip.point = point;
  8656. line.lineEnd();
  8657. }
  8658. function pointRing(lambda, phi) {
  8659. ring.push([lambda, phi]);
  8660. ringSink.point(lambda, phi);
  8661. }
  8662. function ringStart() {
  8663. ringSink.lineStart();
  8664. ring = [];
  8665. }
  8666. function ringEnd() {
  8667. pointRing(ring[0][0], ring[0][1]);
  8668. ringSink.lineEnd();
  8669. var clean = ringSink.clean(),
  8670. ringSegments = ringBuffer.result(),
  8671. i, n = ringSegments.length, m,
  8672. segment,
  8673. point;
  8674. ring.pop();
  8675. polygon.push(ring);
  8676. ring = null;
  8677. if (!n) return;
  8678. // No intersections.
  8679. if (clean & 1) {
  8680. segment = ringSegments[0];
  8681. if ((m = segment.length - 1) > 0) {
  8682. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  8683. sink.lineStart();
  8684. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  8685. sink.lineEnd();
  8686. }
  8687. return;
  8688. }
  8689. // Rejoin connected segments.
  8690. // TODO reuse ringBuffer.rejoin()?
  8691. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  8692. segments.push(ringSegments.filter(validSegment));
  8693. }
  8694. return clip;
  8695. };
  8696. }
  8697. function validSegment(segment) {
  8698. return segment.length > 1;
  8699. }
  8700. // Intersections are sorted along the clip edge. For both antimeridian cutting
  8701. // and circle clipping, the same comparison is used.
  8702. function compareIntersection(a, b) {
  8703. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$4 : halfPi$2 - a[1])
  8704. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$4 : halfPi$2 - b[1]);
  8705. }
  8706. var clipAntimeridian = clip(
  8707. function() { return true; },
  8708. clipAntimeridianLine,
  8709. clipAntimeridianInterpolate,
  8710. [-pi$3, -halfPi$2]
  8711. );
  8712. // Takes a line and cuts into visible segments. Return values: 0 - there were
  8713. // intersections or the line was empty; 1 - no intersections; 2 - there were
  8714. // intersections, and the first and last segments should be rejoined.
  8715. function clipAntimeridianLine(stream) {
  8716. var lambda0 = NaN,
  8717. phi0 = NaN,
  8718. sign0 = NaN,
  8719. clean; // no intersections
  8720. return {
  8721. lineStart: function() {
  8722. stream.lineStart();
  8723. clean = 1;
  8724. },
  8725. point: function(lambda1, phi1) {
  8726. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  8727. delta = abs$2(lambda1 - lambda0);
  8728. if (abs$2(delta - pi$3) < epsilon$4) { // line crosses a pole
  8729. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  8730. stream.point(sign0, phi0);
  8731. stream.lineEnd();
  8732. stream.lineStart();
  8733. stream.point(sign1, phi0);
  8734. stream.point(lambda1, phi0);
  8735. clean = 0;
  8736. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  8737. if (abs$2(lambda0 - sign0) < epsilon$4) lambda0 -= sign0 * epsilon$4; // handle degeneracies
  8738. if (abs$2(lambda1 - sign1) < epsilon$4) lambda1 -= sign1 * epsilon$4;
  8739. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  8740. stream.point(sign0, phi0);
  8741. stream.lineEnd();
  8742. stream.lineStart();
  8743. stream.point(sign1, phi0);
  8744. clean = 0;
  8745. }
  8746. stream.point(lambda0 = lambda1, phi0 = phi1);
  8747. sign0 = sign1;
  8748. },
  8749. lineEnd: function() {
  8750. stream.lineEnd();
  8751. lambda0 = phi0 = NaN;
  8752. },
  8753. clean: function() {
  8754. return 2 - clean; // if intersections, rejoin first and last segments
  8755. }
  8756. };
  8757. }
  8758. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  8759. var cosPhi0,
  8760. cosPhi1,
  8761. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  8762. return abs$2(sinLambda0Lambda1) > epsilon$4
  8763. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  8764. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  8765. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  8766. : (phi0 + phi1) / 2;
  8767. }
  8768. function clipAntimeridianInterpolate(from, to, direction, stream) {
  8769. var phi;
  8770. if (from == null) {
  8771. phi = direction * halfPi$2;
  8772. stream.point(-pi$3, phi);
  8773. stream.point(0, phi);
  8774. stream.point(pi$3, phi);
  8775. stream.point(pi$3, 0);
  8776. stream.point(pi$3, -phi);
  8777. stream.point(0, -phi);
  8778. stream.point(-pi$3, -phi);
  8779. stream.point(-pi$3, 0);
  8780. stream.point(-pi$3, phi);
  8781. } else if (abs$2(from[0] - to[0]) > epsilon$4) {
  8782. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  8783. phi = direction * lambda / 2;
  8784. stream.point(-lambda, phi);
  8785. stream.point(0, phi);
  8786. stream.point(lambda, phi);
  8787. } else {
  8788. stream.point(to[0], to[1]);
  8789. }
  8790. }
  8791. function clipCircle(radius) {
  8792. var cr = cos$1(radius),
  8793. delta = 6 * radians$1,
  8794. smallRadius = cr > 0,
  8795. notHemisphere = abs$2(cr) > epsilon$4; // TODO optimise for this common case
  8796. function interpolate(from, to, direction, stream) {
  8797. circleStream(stream, radius, delta, direction, from, to);
  8798. }
  8799. function visible(lambda, phi) {
  8800. return cos$1(lambda) * cos$1(phi) > cr;
  8801. }
  8802. // Takes a line and cuts into visible segments. Return values used for polygon
  8803. // clipping: 0 - there were intersections or the line was empty; 1 - no
  8804. // intersections 2 - there were intersections, and the first and last segments
  8805. // should be rejoined.
  8806. function clipLine(stream) {
  8807. var point0, // previous point
  8808. c0, // code for previous point
  8809. v0, // visibility of previous point
  8810. v00, // visibility of first point
  8811. clean; // no intersections
  8812. return {
  8813. lineStart: function() {
  8814. v00 = v0 = false;
  8815. clean = 1;
  8816. },
  8817. point: function(lambda, phi) {
  8818. var point1 = [lambda, phi],
  8819. point2,
  8820. v = visible(lambda, phi),
  8821. c = smallRadius
  8822. ? v ? 0 : code(lambda, phi)
  8823. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  8824. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  8825. if (v !== v0) {
  8826. point2 = intersect(point0, point1);
  8827. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2))
  8828. point1[2] = 1;
  8829. }
  8830. if (v !== v0) {
  8831. clean = 0;
  8832. if (v) {
  8833. // outside going in
  8834. stream.lineStart();
  8835. point2 = intersect(point1, point0);
  8836. stream.point(point2[0], point2[1]);
  8837. } else {
  8838. // inside going out
  8839. point2 = intersect(point0, point1);
  8840. stream.point(point2[0], point2[1], 2);
  8841. stream.lineEnd();
  8842. }
  8843. point0 = point2;
  8844. } else if (notHemisphere && point0 && smallRadius ^ v) {
  8845. var t;
  8846. // If the codes for two points are different, or are both zero,
  8847. // and there this segment intersects with the small circle.
  8848. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  8849. clean = 0;
  8850. if (smallRadius) {
  8851. stream.lineStart();
  8852. stream.point(t[0][0], t[0][1]);
  8853. stream.point(t[1][0], t[1][1]);
  8854. stream.lineEnd();
  8855. } else {
  8856. stream.point(t[1][0], t[1][1]);
  8857. stream.lineEnd();
  8858. stream.lineStart();
  8859. stream.point(t[0][0], t[0][1], 3);
  8860. }
  8861. }
  8862. }
  8863. if (v && (!point0 || !pointEqual(point0, point1))) {
  8864. stream.point(point1[0], point1[1]);
  8865. }
  8866. point0 = point1, v0 = v, c0 = c;
  8867. },
  8868. lineEnd: function() {
  8869. if (v0) stream.lineEnd();
  8870. point0 = null;
  8871. },
  8872. // Rejoin first and last segments if there were intersections and the first
  8873. // and last points were visible.
  8874. clean: function() {
  8875. return clean | ((v00 && v0) << 1);
  8876. }
  8877. };
  8878. }
  8879. // Intersects the great circle between a and b with the clip circle.
  8880. function intersect(a, b, two) {
  8881. var pa = cartesian(a),
  8882. pb = cartesian(b);
  8883. // We have two planes, n1.p = d1 and n2.p = d2.
  8884. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  8885. var n1 = [1, 0, 0], // normal
  8886. n2 = cartesianCross(pa, pb),
  8887. n2n2 = cartesianDot(n2, n2),
  8888. n1n2 = n2[0], // cartesianDot(n1, n2),
  8889. determinant = n2n2 - n1n2 * n1n2;
  8890. // Two polar points.
  8891. if (!determinant) return !two && a;
  8892. var c1 = cr * n2n2 / determinant,
  8893. c2 = -cr * n1n2 / determinant,
  8894. n1xn2 = cartesianCross(n1, n2),
  8895. A = cartesianScale(n1, c1),
  8896. B = cartesianScale(n2, c2);
  8897. cartesianAddInPlace(A, B);
  8898. // Solve |p(t)|^2 = 1.
  8899. var u = n1xn2,
  8900. w = cartesianDot(A, u),
  8901. uu = cartesianDot(u, u),
  8902. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  8903. if (t2 < 0) return;
  8904. var t = sqrt(t2),
  8905. q = cartesianScale(u, (-w - t) / uu);
  8906. cartesianAddInPlace(q, A);
  8907. q = spherical(q);
  8908. if (!two) return q;
  8909. // Two intersection points.
  8910. var lambda0 = a[0],
  8911. lambda1 = b[0],
  8912. phi0 = a[1],
  8913. phi1 = b[1],
  8914. z;
  8915. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  8916. var delta = lambda1 - lambda0,
  8917. polar = abs$2(delta - pi$3) < epsilon$4,
  8918. meridian = polar || delta < epsilon$4;
  8919. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  8920. // Check that the first point is between a and b.
  8921. if (meridian
  8922. ? polar
  8923. ? phi0 + phi1 > 0 ^ q[1] < (abs$2(q[0] - lambda0) < epsilon$4 ? phi0 : phi1)
  8924. : phi0 <= q[1] && q[1] <= phi1
  8925. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  8926. var q1 = cartesianScale(u, (-w + t) / uu);
  8927. cartesianAddInPlace(q1, A);
  8928. return [q, spherical(q1)];
  8929. }
  8930. }
  8931. // Generates a 4-bit vector representing the location of a point relative to
  8932. // the small circle's bounding box.
  8933. function code(lambda, phi) {
  8934. var r = smallRadius ? radius : pi$3 - radius,
  8935. code = 0;
  8936. if (lambda < -r) code |= 1; // left
  8937. else if (lambda > r) code |= 2; // right
  8938. if (phi < -r) code |= 4; // below
  8939. else if (phi > r) code |= 8; // above
  8940. return code;
  8941. }
  8942. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  8943. }
  8944. function clipLine(a, b, x0, y0, x1, y1) {
  8945. var ax = a[0],
  8946. ay = a[1],
  8947. bx = b[0],
  8948. by = b[1],
  8949. t0 = 0,
  8950. t1 = 1,
  8951. dx = bx - ax,
  8952. dy = by - ay,
  8953. r;
  8954. r = x0 - ax;
  8955. if (!dx && r > 0) return;
  8956. r /= dx;
  8957. if (dx < 0) {
  8958. if (r < t0) return;
  8959. if (r < t1) t1 = r;
  8960. } else if (dx > 0) {
  8961. if (r > t1) return;
  8962. if (r > t0) t0 = r;
  8963. }
  8964. r = x1 - ax;
  8965. if (!dx && r < 0) return;
  8966. r /= dx;
  8967. if (dx < 0) {
  8968. if (r > t1) return;
  8969. if (r > t0) t0 = r;
  8970. } else if (dx > 0) {
  8971. if (r < t0) return;
  8972. if (r < t1) t1 = r;
  8973. }
  8974. r = y0 - ay;
  8975. if (!dy && r > 0) return;
  8976. r /= dy;
  8977. if (dy < 0) {
  8978. if (r < t0) return;
  8979. if (r < t1) t1 = r;
  8980. } else if (dy > 0) {
  8981. if (r > t1) return;
  8982. if (r > t0) t0 = r;
  8983. }
  8984. r = y1 - ay;
  8985. if (!dy && r < 0) return;
  8986. r /= dy;
  8987. if (dy < 0) {
  8988. if (r > t1) return;
  8989. if (r > t0) t0 = r;
  8990. } else if (dy > 0) {
  8991. if (r < t0) return;
  8992. if (r < t1) t1 = r;
  8993. }
  8994. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  8995. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  8996. return true;
  8997. }
  8998. var clipMax = 1e9, clipMin = -clipMax;
  8999. // TODO Use d3-polygon’s polygonContains here for the ring check?
  9000. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  9001. function clipRectangle(x0, y0, x1, y1) {
  9002. function visible(x, y) {
  9003. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  9004. }
  9005. function interpolate(from, to, direction, stream) {
  9006. var a = 0, a1 = 0;
  9007. if (from == null
  9008. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  9009. || comparePoint(from, to) < 0 ^ direction > 0) {
  9010. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  9011. while ((a = (a + direction + 4) % 4) !== a1);
  9012. } else {
  9013. stream.point(to[0], to[1]);
  9014. }
  9015. }
  9016. function corner(p, direction) {
  9017. return abs$2(p[0] - x0) < epsilon$4 ? direction > 0 ? 0 : 3
  9018. : abs$2(p[0] - x1) < epsilon$4 ? direction > 0 ? 2 : 1
  9019. : abs$2(p[1] - y0) < epsilon$4 ? direction > 0 ? 1 : 0
  9020. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  9021. }
  9022. function compareIntersection(a, b) {
  9023. return comparePoint(a.x, b.x);
  9024. }
  9025. function comparePoint(a, b) {
  9026. var ca = corner(a, 1),
  9027. cb = corner(b, 1);
  9028. return ca !== cb ? ca - cb
  9029. : ca === 0 ? b[1] - a[1]
  9030. : ca === 1 ? a[0] - b[0]
  9031. : ca === 2 ? a[1] - b[1]
  9032. : b[0] - a[0];
  9033. }
  9034. return function(stream) {
  9035. var activeStream = stream,
  9036. bufferStream = clipBuffer(),
  9037. segments,
  9038. polygon,
  9039. ring,
  9040. x__, y__, v__, // first point
  9041. x_, y_, v_, // previous point
  9042. first,
  9043. clean;
  9044. var clipStream = {
  9045. point: point,
  9046. lineStart: lineStart,
  9047. lineEnd: lineEnd,
  9048. polygonStart: polygonStart,
  9049. polygonEnd: polygonEnd
  9050. };
  9051. function point(x, y) {
  9052. if (visible(x, y)) activeStream.point(x, y);
  9053. }
  9054. function polygonInside() {
  9055. var winding = 0;
  9056. for (var i = 0, n = polygon.length; i < n; ++i) {
  9057. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  9058. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  9059. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  9060. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  9061. }
  9062. }
  9063. return winding;
  9064. }
  9065. // Buffer geometry within a polygon and then clip it en masse.
  9066. function polygonStart() {
  9067. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  9068. }
  9069. function polygonEnd() {
  9070. var startInside = polygonInside(),
  9071. cleanInside = clean && startInside,
  9072. visible = (segments = merge(segments)).length;
  9073. if (cleanInside || visible) {
  9074. stream.polygonStart();
  9075. if (cleanInside) {
  9076. stream.lineStart();
  9077. interpolate(null, null, 1, stream);
  9078. stream.lineEnd();
  9079. }
  9080. if (visible) {
  9081. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  9082. }
  9083. stream.polygonEnd();
  9084. }
  9085. activeStream = stream, segments = polygon = ring = null;
  9086. }
  9087. function lineStart() {
  9088. clipStream.point = linePoint;
  9089. if (polygon) polygon.push(ring = []);
  9090. first = true;
  9091. v_ = false;
  9092. x_ = y_ = NaN;
  9093. }
  9094. // TODO rather than special-case polygons, simply handle them separately.
  9095. // Ideally, coincident intersection points should be jittered to avoid
  9096. // clipping issues.
  9097. function lineEnd() {
  9098. if (segments) {
  9099. linePoint(x__, y__);
  9100. if (v__ && v_) bufferStream.rejoin();
  9101. segments.push(bufferStream.result());
  9102. }
  9103. clipStream.point = point;
  9104. if (v_) activeStream.lineEnd();
  9105. }
  9106. function linePoint(x, y) {
  9107. var v = visible(x, y);
  9108. if (polygon) ring.push([x, y]);
  9109. if (first) {
  9110. x__ = x, y__ = y, v__ = v;
  9111. first = false;
  9112. if (v) {
  9113. activeStream.lineStart();
  9114. activeStream.point(x, y);
  9115. }
  9116. } else {
  9117. if (v && v_) activeStream.point(x, y);
  9118. else {
  9119. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  9120. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  9121. if (clipLine(a, b, x0, y0, x1, y1)) {
  9122. if (!v_) {
  9123. activeStream.lineStart();
  9124. activeStream.point(a[0], a[1]);
  9125. }
  9126. activeStream.point(b[0], b[1]);
  9127. if (!v) activeStream.lineEnd();
  9128. clean = false;
  9129. } else if (v) {
  9130. activeStream.lineStart();
  9131. activeStream.point(x, y);
  9132. clean = false;
  9133. }
  9134. }
  9135. }
  9136. x_ = x, y_ = y, v_ = v;
  9137. }
  9138. return clipStream;
  9139. };
  9140. }
  9141. function extent$1() {
  9142. var x0 = 0,
  9143. y0 = 0,
  9144. x1 = 960,
  9145. y1 = 500,
  9146. cache,
  9147. cacheStream,
  9148. clip;
  9149. return clip = {
  9150. stream: function(stream) {
  9151. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  9152. },
  9153. extent: function(_) {
  9154. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  9155. }
  9156. };
  9157. }
  9158. var lengthSum,
  9159. lambda0$2,
  9160. sinPhi0$1,
  9161. cosPhi0$1;
  9162. var lengthStream = {
  9163. sphere: noop$2,
  9164. point: noop$2,
  9165. lineStart: lengthLineStart,
  9166. lineEnd: noop$2,
  9167. polygonStart: noop$2,
  9168. polygonEnd: noop$2
  9169. };
  9170. function lengthLineStart() {
  9171. lengthStream.point = lengthPointFirst;
  9172. lengthStream.lineEnd = lengthLineEnd;
  9173. }
  9174. function lengthLineEnd() {
  9175. lengthStream.point = lengthStream.lineEnd = noop$2;
  9176. }
  9177. function lengthPointFirst(lambda, phi) {
  9178. lambda *= radians$1, phi *= radians$1;
  9179. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  9180. lengthStream.point = lengthPoint;
  9181. }
  9182. function lengthPoint(lambda, phi) {
  9183. lambda *= radians$1, phi *= radians$1;
  9184. var sinPhi = sin$1(phi),
  9185. cosPhi = cos$1(phi),
  9186. delta = abs$2(lambda - lambda0$2),
  9187. cosDelta = cos$1(delta),
  9188. sinDelta = sin$1(delta),
  9189. x = cosPhi * sinDelta,
  9190. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  9191. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  9192. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  9193. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  9194. }
  9195. function length$2(object) {
  9196. lengthSum = new Adder();
  9197. geoStream(object, lengthStream);
  9198. return +lengthSum;
  9199. }
  9200. var coordinates = [null, null],
  9201. object$1 = {type: "LineString", coordinates: coordinates};
  9202. function distance(a, b) {
  9203. coordinates[0] = a;
  9204. coordinates[1] = b;
  9205. return length$2(object$1);
  9206. }
  9207. var containsObjectType = {
  9208. Feature: function(object, point) {
  9209. return containsGeometry(object.geometry, point);
  9210. },
  9211. FeatureCollection: function(object, point) {
  9212. var features = object.features, i = -1, n = features.length;
  9213. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  9214. return false;
  9215. }
  9216. };
  9217. var containsGeometryType = {
  9218. Sphere: function() {
  9219. return true;
  9220. },
  9221. Point: function(object, point) {
  9222. return containsPoint(object.coordinates, point);
  9223. },
  9224. MultiPoint: function(object, point) {
  9225. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9226. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  9227. return false;
  9228. },
  9229. LineString: function(object, point) {
  9230. return containsLine(object.coordinates, point);
  9231. },
  9232. MultiLineString: function(object, point) {
  9233. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9234. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  9235. return false;
  9236. },
  9237. Polygon: function(object, point) {
  9238. return containsPolygon(object.coordinates, point);
  9239. },
  9240. MultiPolygon: function(object, point) {
  9241. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9242. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  9243. return false;
  9244. },
  9245. GeometryCollection: function(object, point) {
  9246. var geometries = object.geometries, i = -1, n = geometries.length;
  9247. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  9248. return false;
  9249. }
  9250. };
  9251. function containsGeometry(geometry, point) {
  9252. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  9253. ? containsGeometryType[geometry.type](geometry, point)
  9254. : false;
  9255. }
  9256. function containsPoint(coordinates, point) {
  9257. return distance(coordinates, point) === 0;
  9258. }
  9259. function containsLine(coordinates, point) {
  9260. var ao, bo, ab;
  9261. for (var i = 0, n = coordinates.length; i < n; i++) {
  9262. bo = distance(coordinates[i], point);
  9263. if (bo === 0) return true;
  9264. if (i > 0) {
  9265. ab = distance(coordinates[i], coordinates[i - 1]);
  9266. if (
  9267. ab > 0 &&
  9268. ao <= ab &&
  9269. bo <= ab &&
  9270. (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2$1 * ab
  9271. )
  9272. return true;
  9273. }
  9274. ao = bo;
  9275. }
  9276. return false;
  9277. }
  9278. function containsPolygon(coordinates, point) {
  9279. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  9280. }
  9281. function ringRadians(ring) {
  9282. return ring = ring.map(pointRadians), ring.pop(), ring;
  9283. }
  9284. function pointRadians(point) {
  9285. return [point[0] * radians$1, point[1] * radians$1];
  9286. }
  9287. function contains$1(object, point) {
  9288. return (object && containsObjectType.hasOwnProperty(object.type)
  9289. ? containsObjectType[object.type]
  9290. : containsGeometry)(object, point);
  9291. }
  9292. function graticuleX(y0, y1, dy) {
  9293. var y = sequence(y0, y1 - epsilon$4, dy).concat(y1);
  9294. return function(x) { return y.map(function(y) { return [x, y]; }); };
  9295. }
  9296. function graticuleY(x0, x1, dx) {
  9297. var x = sequence(x0, x1 - epsilon$4, dx).concat(x1);
  9298. return function(y) { return x.map(function(x) { return [x, y]; }); };
  9299. }
  9300. function graticule() {
  9301. var x1, x0, X1, X0,
  9302. y1, y0, Y1, Y0,
  9303. dx = 10, dy = dx, DX = 90, DY = 360,
  9304. x, y, X, Y,
  9305. precision = 2.5;
  9306. function graticule() {
  9307. return {type: "MultiLineString", coordinates: lines()};
  9308. }
  9309. function lines() {
  9310. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  9311. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  9312. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs$2(x % DX) > epsilon$4; }).map(x))
  9313. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs$2(y % DY) > epsilon$4; }).map(y));
  9314. }
  9315. graticule.lines = function() {
  9316. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  9317. };
  9318. graticule.outline = function() {
  9319. return {
  9320. type: "Polygon",
  9321. coordinates: [
  9322. X(X0).concat(
  9323. Y(Y1).slice(1),
  9324. X(X1).reverse().slice(1),
  9325. Y(Y0).reverse().slice(1))
  9326. ]
  9327. };
  9328. };
  9329. graticule.extent = function(_) {
  9330. if (!arguments.length) return graticule.extentMinor();
  9331. return graticule.extentMajor(_).extentMinor(_);
  9332. };
  9333. graticule.extentMajor = function(_) {
  9334. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  9335. X0 = +_[0][0], X1 = +_[1][0];
  9336. Y0 = +_[0][1], Y1 = +_[1][1];
  9337. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  9338. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  9339. return graticule.precision(precision);
  9340. };
  9341. graticule.extentMinor = function(_) {
  9342. if (!arguments.length) return [[x0, y0], [x1, y1]];
  9343. x0 = +_[0][0], x1 = +_[1][0];
  9344. y0 = +_[0][1], y1 = +_[1][1];
  9345. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  9346. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  9347. return graticule.precision(precision);
  9348. };
  9349. graticule.step = function(_) {
  9350. if (!arguments.length) return graticule.stepMinor();
  9351. return graticule.stepMajor(_).stepMinor(_);
  9352. };
  9353. graticule.stepMajor = function(_) {
  9354. if (!arguments.length) return [DX, DY];
  9355. DX = +_[0], DY = +_[1];
  9356. return graticule;
  9357. };
  9358. graticule.stepMinor = function(_) {
  9359. if (!arguments.length) return [dx, dy];
  9360. dx = +_[0], dy = +_[1];
  9361. return graticule;
  9362. };
  9363. graticule.precision = function(_) {
  9364. if (!arguments.length) return precision;
  9365. precision = +_;
  9366. x = graticuleX(y0, y1, 90);
  9367. y = graticuleY(x0, x1, precision);
  9368. X = graticuleX(Y0, Y1, 90);
  9369. Y = graticuleY(X0, X1, precision);
  9370. return graticule;
  9371. };
  9372. return graticule
  9373. .extentMajor([[-180, -90 + epsilon$4], [180, 90 - epsilon$4]])
  9374. .extentMinor([[-180, -80 - epsilon$4], [180, 80 + epsilon$4]]);
  9375. }
  9376. function graticule10() {
  9377. return graticule()();
  9378. }
  9379. function interpolate$2(a, b) {
  9380. var x0 = a[0] * radians$1,
  9381. y0 = a[1] * radians$1,
  9382. x1 = b[0] * radians$1,
  9383. y1 = b[1] * radians$1,
  9384. cy0 = cos$1(y0),
  9385. sy0 = sin$1(y0),
  9386. cy1 = cos$1(y1),
  9387. sy1 = sin$1(y1),
  9388. kx0 = cy0 * cos$1(x0),
  9389. ky0 = cy0 * sin$1(x0),
  9390. kx1 = cy1 * cos$1(x1),
  9391. ky1 = cy1 * sin$1(x1),
  9392. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  9393. k = sin$1(d);
  9394. var interpolate = d ? function(t) {
  9395. var B = sin$1(t *= d) / k,
  9396. A = sin$1(d - t) / k,
  9397. x = A * kx0 + B * kx1,
  9398. y = A * ky0 + B * ky1,
  9399. z = A * sy0 + B * sy1;
  9400. return [
  9401. atan2(y, x) * degrees$2,
  9402. atan2(z, sqrt(x * x + y * y)) * degrees$2
  9403. ];
  9404. } : function() {
  9405. return [x0 * degrees$2, y0 * degrees$2];
  9406. };
  9407. interpolate.distance = d;
  9408. return interpolate;
  9409. }
  9410. var identity$4 = x => x;
  9411. var areaSum$1 = new Adder(),
  9412. areaRingSum$1 = new Adder(),
  9413. x00,
  9414. y00,
  9415. x0$1,
  9416. y0$1;
  9417. var areaStream$1 = {
  9418. point: noop$2,
  9419. lineStart: noop$2,
  9420. lineEnd: noop$2,
  9421. polygonStart: function() {
  9422. areaStream$1.lineStart = areaRingStart$1;
  9423. areaStream$1.lineEnd = areaRingEnd$1;
  9424. },
  9425. polygonEnd: function() {
  9426. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  9427. areaSum$1.add(abs$2(areaRingSum$1));
  9428. areaRingSum$1 = new Adder();
  9429. },
  9430. result: function() {
  9431. var area = areaSum$1 / 2;
  9432. areaSum$1 = new Adder();
  9433. return area;
  9434. }
  9435. };
  9436. function areaRingStart$1() {
  9437. areaStream$1.point = areaPointFirst$1;
  9438. }
  9439. function areaPointFirst$1(x, y) {
  9440. areaStream$1.point = areaPoint$1;
  9441. x00 = x0$1 = x, y00 = y0$1 = y;
  9442. }
  9443. function areaPoint$1(x, y) {
  9444. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  9445. x0$1 = x, y0$1 = y;
  9446. }
  9447. function areaRingEnd$1() {
  9448. areaPoint$1(x00, y00);
  9449. }
  9450. var x0$2 = Infinity,
  9451. y0$2 = x0$2,
  9452. x1 = -x0$2,
  9453. y1 = x1;
  9454. var boundsStream$1 = {
  9455. point: boundsPoint$1,
  9456. lineStart: noop$2,
  9457. lineEnd: noop$2,
  9458. polygonStart: noop$2,
  9459. polygonEnd: noop$2,
  9460. result: function() {
  9461. var bounds = [[x0$2, y0$2], [x1, y1]];
  9462. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  9463. return bounds;
  9464. }
  9465. };
  9466. function boundsPoint$1(x, y) {
  9467. if (x < x0$2) x0$2 = x;
  9468. if (x > x1) x1 = x;
  9469. if (y < y0$2) y0$2 = y;
  9470. if (y > y1) y1 = y;
  9471. }
  9472. // TODO Enforce positive area for exterior, negative area for interior?
  9473. var X0$1 = 0,
  9474. Y0$1 = 0,
  9475. Z0$1 = 0,
  9476. X1$1 = 0,
  9477. Y1$1 = 0,
  9478. Z1$1 = 0,
  9479. X2$1 = 0,
  9480. Y2$1 = 0,
  9481. Z2$1 = 0,
  9482. x00$1,
  9483. y00$1,
  9484. x0$3,
  9485. y0$3;
  9486. var centroidStream$1 = {
  9487. point: centroidPoint$1,
  9488. lineStart: centroidLineStart$1,
  9489. lineEnd: centroidLineEnd$1,
  9490. polygonStart: function() {
  9491. centroidStream$1.lineStart = centroidRingStart$1;
  9492. centroidStream$1.lineEnd = centroidRingEnd$1;
  9493. },
  9494. polygonEnd: function() {
  9495. centroidStream$1.point = centroidPoint$1;
  9496. centroidStream$1.lineStart = centroidLineStart$1;
  9497. centroidStream$1.lineEnd = centroidLineEnd$1;
  9498. },
  9499. result: function() {
  9500. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  9501. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  9502. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  9503. : [NaN, NaN];
  9504. X0$1 = Y0$1 = Z0$1 =
  9505. X1$1 = Y1$1 = Z1$1 =
  9506. X2$1 = Y2$1 = Z2$1 = 0;
  9507. return centroid;
  9508. }
  9509. };
  9510. function centroidPoint$1(x, y) {
  9511. X0$1 += x;
  9512. Y0$1 += y;
  9513. ++Z0$1;
  9514. }
  9515. function centroidLineStart$1() {
  9516. centroidStream$1.point = centroidPointFirstLine;
  9517. }
  9518. function centroidPointFirstLine(x, y) {
  9519. centroidStream$1.point = centroidPointLine;
  9520. centroidPoint$1(x0$3 = x, y0$3 = y);
  9521. }
  9522. function centroidPointLine(x, y) {
  9523. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  9524. X1$1 += z * (x0$3 + x) / 2;
  9525. Y1$1 += z * (y0$3 + y) / 2;
  9526. Z1$1 += z;
  9527. centroidPoint$1(x0$3 = x, y0$3 = y);
  9528. }
  9529. function centroidLineEnd$1() {
  9530. centroidStream$1.point = centroidPoint$1;
  9531. }
  9532. function centroidRingStart$1() {
  9533. centroidStream$1.point = centroidPointFirstRing;
  9534. }
  9535. function centroidRingEnd$1() {
  9536. centroidPointRing(x00$1, y00$1);
  9537. }
  9538. function centroidPointFirstRing(x, y) {
  9539. centroidStream$1.point = centroidPointRing;
  9540. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  9541. }
  9542. function centroidPointRing(x, y) {
  9543. var dx = x - x0$3,
  9544. dy = y - y0$3,
  9545. z = sqrt(dx * dx + dy * dy);
  9546. X1$1 += z * (x0$3 + x) / 2;
  9547. Y1$1 += z * (y0$3 + y) / 2;
  9548. Z1$1 += z;
  9549. z = y0$3 * x - x0$3 * y;
  9550. X2$1 += z * (x0$3 + x);
  9551. Y2$1 += z * (y0$3 + y);
  9552. Z2$1 += z * 3;
  9553. centroidPoint$1(x0$3 = x, y0$3 = y);
  9554. }
  9555. function PathContext(context) {
  9556. this._context = context;
  9557. }
  9558. PathContext.prototype = {
  9559. _radius: 4.5,
  9560. pointRadius: function(_) {
  9561. return this._radius = _, this;
  9562. },
  9563. polygonStart: function() {
  9564. this._line = 0;
  9565. },
  9566. polygonEnd: function() {
  9567. this._line = NaN;
  9568. },
  9569. lineStart: function() {
  9570. this._point = 0;
  9571. },
  9572. lineEnd: function() {
  9573. if (this._line === 0) this._context.closePath();
  9574. this._point = NaN;
  9575. },
  9576. point: function(x, y) {
  9577. switch (this._point) {
  9578. case 0: {
  9579. this._context.moveTo(x, y);
  9580. this._point = 1;
  9581. break;
  9582. }
  9583. case 1: {
  9584. this._context.lineTo(x, y);
  9585. break;
  9586. }
  9587. default: {
  9588. this._context.moveTo(x + this._radius, y);
  9589. this._context.arc(x, y, this._radius, 0, tau$4);
  9590. break;
  9591. }
  9592. }
  9593. },
  9594. result: noop$2
  9595. };
  9596. var lengthSum$1 = new Adder(),
  9597. lengthRing,
  9598. x00$2,
  9599. y00$2,
  9600. x0$4,
  9601. y0$4;
  9602. var lengthStream$1 = {
  9603. point: noop$2,
  9604. lineStart: function() {
  9605. lengthStream$1.point = lengthPointFirst$1;
  9606. },
  9607. lineEnd: function() {
  9608. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  9609. lengthStream$1.point = noop$2;
  9610. },
  9611. polygonStart: function() {
  9612. lengthRing = true;
  9613. },
  9614. polygonEnd: function() {
  9615. lengthRing = null;
  9616. },
  9617. result: function() {
  9618. var length = +lengthSum$1;
  9619. lengthSum$1 = new Adder();
  9620. return length;
  9621. }
  9622. };
  9623. function lengthPointFirst$1(x, y) {
  9624. lengthStream$1.point = lengthPoint$1;
  9625. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  9626. }
  9627. function lengthPoint$1(x, y) {
  9628. x0$4 -= x, y0$4 -= y;
  9629. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  9630. x0$4 = x, y0$4 = y;
  9631. }
  9632. function PathString() {
  9633. this._string = [];
  9634. }
  9635. PathString.prototype = {
  9636. _radius: 4.5,
  9637. _circle: circle$1(4.5),
  9638. pointRadius: function(_) {
  9639. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  9640. return this;
  9641. },
  9642. polygonStart: function() {
  9643. this._line = 0;
  9644. },
  9645. polygonEnd: function() {
  9646. this._line = NaN;
  9647. },
  9648. lineStart: function() {
  9649. this._point = 0;
  9650. },
  9651. lineEnd: function() {
  9652. if (this._line === 0) this._string.push("Z");
  9653. this._point = NaN;
  9654. },
  9655. point: function(x, y) {
  9656. switch (this._point) {
  9657. case 0: {
  9658. this._string.push("M", x, ",", y);
  9659. this._point = 1;
  9660. break;
  9661. }
  9662. case 1: {
  9663. this._string.push("L", x, ",", y);
  9664. break;
  9665. }
  9666. default: {
  9667. if (this._circle == null) this._circle = circle$1(this._radius);
  9668. this._string.push("M", x, ",", y, this._circle);
  9669. break;
  9670. }
  9671. }
  9672. },
  9673. result: function() {
  9674. if (this._string.length) {
  9675. var result = this._string.join("");
  9676. this._string = [];
  9677. return result;
  9678. } else {
  9679. return null;
  9680. }
  9681. }
  9682. };
  9683. function circle$1(radius) {
  9684. return "m0," + radius
  9685. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  9686. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  9687. + "z";
  9688. }
  9689. function index$2(projection, context) {
  9690. var pointRadius = 4.5,
  9691. projectionStream,
  9692. contextStream;
  9693. function path(object) {
  9694. if (object) {
  9695. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  9696. geoStream(object, projectionStream(contextStream));
  9697. }
  9698. return contextStream.result();
  9699. }
  9700. path.area = function(object) {
  9701. geoStream(object, projectionStream(areaStream$1));
  9702. return areaStream$1.result();
  9703. };
  9704. path.measure = function(object) {
  9705. geoStream(object, projectionStream(lengthStream$1));
  9706. return lengthStream$1.result();
  9707. };
  9708. path.bounds = function(object) {
  9709. geoStream(object, projectionStream(boundsStream$1));
  9710. return boundsStream$1.result();
  9711. };
  9712. path.centroid = function(object) {
  9713. geoStream(object, projectionStream(centroidStream$1));
  9714. return centroidStream$1.result();
  9715. };
  9716. path.projection = function(_) {
  9717. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  9718. };
  9719. path.context = function(_) {
  9720. if (!arguments.length) return context;
  9721. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  9722. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  9723. return path;
  9724. };
  9725. path.pointRadius = function(_) {
  9726. if (!arguments.length) return pointRadius;
  9727. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  9728. return path;
  9729. };
  9730. return path.projection(projection).context(context);
  9731. }
  9732. function transform(methods) {
  9733. return {
  9734. stream: transformer(methods)
  9735. };
  9736. }
  9737. function transformer(methods) {
  9738. return function(stream) {
  9739. var s = new TransformStream;
  9740. for (var key in methods) s[key] = methods[key];
  9741. s.stream = stream;
  9742. return s;
  9743. };
  9744. }
  9745. function TransformStream() {}
  9746. TransformStream.prototype = {
  9747. constructor: TransformStream,
  9748. point: function(x, y) { this.stream.point(x, y); },
  9749. sphere: function() { this.stream.sphere(); },
  9750. lineStart: function() { this.stream.lineStart(); },
  9751. lineEnd: function() { this.stream.lineEnd(); },
  9752. polygonStart: function() { this.stream.polygonStart(); },
  9753. polygonEnd: function() { this.stream.polygonEnd(); }
  9754. };
  9755. function fit(projection, fitBounds, object) {
  9756. var clip = projection.clipExtent && projection.clipExtent();
  9757. projection.scale(150).translate([0, 0]);
  9758. if (clip != null) projection.clipExtent(null);
  9759. geoStream(object, projection.stream(boundsStream$1));
  9760. fitBounds(boundsStream$1.result());
  9761. if (clip != null) projection.clipExtent(clip);
  9762. return projection;
  9763. }
  9764. function fitExtent(projection, extent, object) {
  9765. return fit(projection, function(b) {
  9766. var w = extent[1][0] - extent[0][0],
  9767. h = extent[1][1] - extent[0][1],
  9768. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  9769. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  9770. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  9771. projection.scale(150 * k).translate([x, y]);
  9772. }, object);
  9773. }
  9774. function fitSize(projection, size, object) {
  9775. return fitExtent(projection, [[0, 0], size], object);
  9776. }
  9777. function fitWidth(projection, width, object) {
  9778. return fit(projection, function(b) {
  9779. var w = +width,
  9780. k = w / (b[1][0] - b[0][0]),
  9781. x = (w - k * (b[1][0] + b[0][0])) / 2,
  9782. y = -k * b[0][1];
  9783. projection.scale(150 * k).translate([x, y]);
  9784. }, object);
  9785. }
  9786. function fitHeight(projection, height, object) {
  9787. return fit(projection, function(b) {
  9788. var h = +height,
  9789. k = h / (b[1][1] - b[0][1]),
  9790. x = -k * b[0][0],
  9791. y = (h - k * (b[1][1] + b[0][1])) / 2;
  9792. projection.scale(150 * k).translate([x, y]);
  9793. }, object);
  9794. }
  9795. var maxDepth = 16, // maximum depth of subdivision
  9796. cosMinDistance = cos$1(30 * radians$1); // cos(minimum angular distance)
  9797. function resample(project, delta2) {
  9798. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  9799. }
  9800. function resampleNone(project) {
  9801. return transformer({
  9802. point: function(x, y) {
  9803. x = project(x, y);
  9804. this.stream.point(x[0], x[1]);
  9805. }
  9806. });
  9807. }
  9808. function resample$1(project, delta2) {
  9809. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  9810. var dx = x1 - x0,
  9811. dy = y1 - y0,
  9812. d2 = dx * dx + dy * dy;
  9813. if (d2 > 4 * delta2 && depth--) {
  9814. var a = a0 + a1,
  9815. b = b0 + b1,
  9816. c = c0 + c1,
  9817. m = sqrt(a * a + b * b + c * c),
  9818. phi2 = asin(c /= m),
  9819. lambda2 = abs$2(abs$2(c) - 1) < epsilon$4 || abs$2(lambda0 - lambda1) < epsilon$4 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  9820. p = project(lambda2, phi2),
  9821. x2 = p[0],
  9822. y2 = p[1],
  9823. dx2 = x2 - x0,
  9824. dy2 = y2 - y0,
  9825. dz = dy * dx2 - dx * dy2;
  9826. if (dz * dz / d2 > delta2 // perpendicular projected distance
  9827. || abs$2((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  9828. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  9829. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  9830. stream.point(x2, y2);
  9831. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  9832. }
  9833. }
  9834. }
  9835. return function(stream) {
  9836. var lambda00, x00, y00, a00, b00, c00, // first point
  9837. lambda0, x0, y0, a0, b0, c0; // previous point
  9838. var resampleStream = {
  9839. point: point,
  9840. lineStart: lineStart,
  9841. lineEnd: lineEnd,
  9842. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  9843. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  9844. };
  9845. function point(x, y) {
  9846. x = project(x, y);
  9847. stream.point(x[0], x[1]);
  9848. }
  9849. function lineStart() {
  9850. x0 = NaN;
  9851. resampleStream.point = linePoint;
  9852. stream.lineStart();
  9853. }
  9854. function linePoint(lambda, phi) {
  9855. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  9856. 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);
  9857. stream.point(x0, y0);
  9858. }
  9859. function lineEnd() {
  9860. resampleStream.point = point;
  9861. stream.lineEnd();
  9862. }
  9863. function ringStart() {
  9864. lineStart();
  9865. resampleStream.point = ringPoint;
  9866. resampleStream.lineEnd = ringEnd;
  9867. }
  9868. function ringPoint(lambda, phi) {
  9869. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  9870. resampleStream.point = linePoint;
  9871. }
  9872. function ringEnd() {
  9873. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  9874. resampleStream.lineEnd = lineEnd;
  9875. lineEnd();
  9876. }
  9877. return resampleStream;
  9878. };
  9879. }
  9880. var transformRadians = transformer({
  9881. point: function(x, y) {
  9882. this.stream.point(x * radians$1, y * radians$1);
  9883. }
  9884. });
  9885. function transformRotate(rotate) {
  9886. return transformer({
  9887. point: function(x, y) {
  9888. var r = rotate(x, y);
  9889. return this.stream.point(r[0], r[1]);
  9890. }
  9891. });
  9892. }
  9893. function scaleTranslate(k, dx, dy, sx, sy) {
  9894. function transform(x, y) {
  9895. x *= sx; y *= sy;
  9896. return [dx + k * x, dy - k * y];
  9897. }
  9898. transform.invert = function(x, y) {
  9899. return [(x - dx) / k * sx, (dy - y) / k * sy];
  9900. };
  9901. return transform;
  9902. }
  9903. function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {
  9904. if (!alpha) return scaleTranslate(k, dx, dy, sx, sy);
  9905. var cosAlpha = cos$1(alpha),
  9906. sinAlpha = sin$1(alpha),
  9907. a = cosAlpha * k,
  9908. b = sinAlpha * k,
  9909. ai = cosAlpha / k,
  9910. bi = sinAlpha / k,
  9911. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  9912. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  9913. function transform(x, y) {
  9914. x *= sx; y *= sy;
  9915. return [a * x - b * y + dx, dy - b * x - a * y];
  9916. }
  9917. transform.invert = function(x, y) {
  9918. return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];
  9919. };
  9920. return transform;
  9921. }
  9922. function projection(project) {
  9923. return projectionMutator(function() { return project; })();
  9924. }
  9925. function projectionMutator(projectAt) {
  9926. var project,
  9927. k = 150, // scale
  9928. x = 480, y = 250, // translate
  9929. lambda = 0, phi = 0, // center
  9930. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  9931. alpha = 0, // post-rotate angle
  9932. sx = 1, // reflectX
  9933. sy = 1, // reflectX
  9934. theta = null, preclip = clipAntimeridian, // pre-clip angle
  9935. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  9936. delta2 = 0.5, // precision
  9937. projectResample,
  9938. projectTransform,
  9939. projectRotateTransform,
  9940. cache,
  9941. cacheStream;
  9942. function projection(point) {
  9943. return projectRotateTransform(point[0] * radians$1, point[1] * radians$1);
  9944. }
  9945. function invert(point) {
  9946. point = projectRotateTransform.invert(point[0], point[1]);
  9947. return point && [point[0] * degrees$2, point[1] * degrees$2];
  9948. }
  9949. projection.stream = function(stream) {
  9950. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  9951. };
  9952. projection.preclip = function(_) {
  9953. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  9954. };
  9955. projection.postclip = function(_) {
  9956. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  9957. };
  9958. projection.clipAngle = function(_) {
  9959. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians$1) : (theta = null, clipAntimeridian), reset()) : theta * degrees$2;
  9960. };
  9961. projection.clipExtent = function(_) {
  9962. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  9963. };
  9964. projection.scale = function(_) {
  9965. return arguments.length ? (k = +_, recenter()) : k;
  9966. };
  9967. projection.translate = function(_) {
  9968. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  9969. };
  9970. projection.center = function(_) {
  9971. return arguments.length ? (lambda = _[0] % 360 * radians$1, phi = _[1] % 360 * radians$1, recenter()) : [lambda * degrees$2, phi * degrees$2];
  9972. };
  9973. projection.rotate = function(_) {
  9974. return arguments.length ? (deltaLambda = _[0] % 360 * radians$1, deltaPhi = _[1] % 360 * radians$1, deltaGamma = _.length > 2 ? _[2] % 360 * radians$1 : 0, recenter()) : [deltaLambda * degrees$2, deltaPhi * degrees$2, deltaGamma * degrees$2];
  9975. };
  9976. projection.angle = function(_) {
  9977. return arguments.length ? (alpha = _ % 360 * radians$1, recenter()) : alpha * degrees$2;
  9978. };
  9979. projection.reflectX = function(_) {
  9980. return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;
  9981. };
  9982. projection.reflectY = function(_) {
  9983. return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;
  9984. };
  9985. projection.precision = function(_) {
  9986. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  9987. };
  9988. projection.fitExtent = function(extent, object) {
  9989. return fitExtent(projection, extent, object);
  9990. };
  9991. projection.fitSize = function(size, object) {
  9992. return fitSize(projection, size, object);
  9993. };
  9994. projection.fitWidth = function(width, object) {
  9995. return fitWidth(projection, width, object);
  9996. };
  9997. projection.fitHeight = function(height, object) {
  9998. return fitHeight(projection, height, object);
  9999. };
  10000. function recenter() {
  10001. var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),
  10002. transform = scaleTranslateRotate(k, x - center[0], y - center[1], sx, sy, alpha);
  10003. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  10004. projectTransform = compose(project, transform);
  10005. projectRotateTransform = compose(rotate, projectTransform);
  10006. projectResample = resample(projectTransform, delta2);
  10007. return reset();
  10008. }
  10009. function reset() {
  10010. cache = cacheStream = null;
  10011. return projection;
  10012. }
  10013. return function() {
  10014. project = projectAt.apply(this, arguments);
  10015. projection.invert = project.invert && invert;
  10016. return recenter();
  10017. };
  10018. }
  10019. function conicProjection(projectAt) {
  10020. var phi0 = 0,
  10021. phi1 = pi$3 / 3,
  10022. m = projectionMutator(projectAt),
  10023. p = m(phi0, phi1);
  10024. p.parallels = function(_) {
  10025. return arguments.length ? m(phi0 = _[0] * radians$1, phi1 = _[1] * radians$1) : [phi0 * degrees$2, phi1 * degrees$2];
  10026. };
  10027. return p;
  10028. }
  10029. function cylindricalEqualAreaRaw(phi0) {
  10030. var cosPhi0 = cos$1(phi0);
  10031. function forward(lambda, phi) {
  10032. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  10033. }
  10034. forward.invert = function(x, y) {
  10035. return [x / cosPhi0, asin(y * cosPhi0)];
  10036. };
  10037. return forward;
  10038. }
  10039. function conicEqualAreaRaw(y0, y1) {
  10040. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  10041. // Are the parallels symmetrical around the Equator?
  10042. if (abs$2(n) < epsilon$4) return cylindricalEqualAreaRaw(y0);
  10043. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  10044. function project(x, y) {
  10045. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  10046. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  10047. }
  10048. project.invert = function(x, y) {
  10049. var r0y = r0 - y,
  10050. l = atan2(x, abs$2(r0y)) * sign(r0y);
  10051. if (r0y * n < 0)
  10052. l -= pi$3 * sign(x) * sign(r0y);
  10053. return [l / n, asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  10054. };
  10055. return project;
  10056. }
  10057. function conicEqualArea() {
  10058. return conicProjection(conicEqualAreaRaw)
  10059. .scale(155.424)
  10060. .center([0, 33.6442]);
  10061. }
  10062. function albers() {
  10063. return conicEqualArea()
  10064. .parallels([29.5, 45.5])
  10065. .scale(1070)
  10066. .translate([480, 250])
  10067. .rotate([96, 0])
  10068. .center([-0.6, 38.7]);
  10069. }
  10070. // The projections must have mutually exclusive clip regions on the sphere,
  10071. // as this will avoid emitting interleaving lines and polygons.
  10072. function multiplex(streams) {
  10073. var n = streams.length;
  10074. return {
  10075. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  10076. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  10077. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  10078. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  10079. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  10080. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  10081. };
  10082. }
  10083. // A composite projection for the United States, configured by default for
  10084. // 960×500. The projection also works quite well at 960×600 if you change the
  10085. // scale to 1285 and adjust the translate accordingly. The set of standard
  10086. // parallels for each region comes from USGS, which is published here:
  10087. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  10088. function albersUsa() {
  10089. var cache,
  10090. cacheStream,
  10091. lower48 = albers(), lower48Point,
  10092. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  10093. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  10094. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  10095. function albersUsa(coordinates) {
  10096. var x = coordinates[0], y = coordinates[1];
  10097. return point = null,
  10098. (lower48Point.point(x, y), point)
  10099. || (alaskaPoint.point(x, y), point)
  10100. || (hawaiiPoint.point(x, y), point);
  10101. }
  10102. albersUsa.invert = function(coordinates) {
  10103. var k = lower48.scale(),
  10104. t = lower48.translate(),
  10105. x = (coordinates[0] - t[0]) / k,
  10106. y = (coordinates[1] - t[1]) / k;
  10107. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  10108. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  10109. : lower48).invert(coordinates);
  10110. };
  10111. albersUsa.stream = function(stream) {
  10112. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  10113. };
  10114. albersUsa.precision = function(_) {
  10115. if (!arguments.length) return lower48.precision();
  10116. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  10117. return reset();
  10118. };
  10119. albersUsa.scale = function(_) {
  10120. if (!arguments.length) return lower48.scale();
  10121. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  10122. return albersUsa.translate(lower48.translate());
  10123. };
  10124. albersUsa.translate = function(_) {
  10125. if (!arguments.length) return lower48.translate();
  10126. var k = lower48.scale(), x = +_[0], y = +_[1];
  10127. lower48Point = lower48
  10128. .translate(_)
  10129. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  10130. .stream(pointStream);
  10131. alaskaPoint = alaska
  10132. .translate([x - 0.307 * k, y + 0.201 * k])
  10133. .clipExtent([[x - 0.425 * k + epsilon$4, y + 0.120 * k + epsilon$4], [x - 0.214 * k - epsilon$4, y + 0.234 * k - epsilon$4]])
  10134. .stream(pointStream);
  10135. hawaiiPoint = hawaii
  10136. .translate([x - 0.205 * k, y + 0.212 * k])
  10137. .clipExtent([[x - 0.214 * k + epsilon$4, y + 0.166 * k + epsilon$4], [x - 0.115 * k - epsilon$4, y + 0.234 * k - epsilon$4]])
  10138. .stream(pointStream);
  10139. return reset();
  10140. };
  10141. albersUsa.fitExtent = function(extent, object) {
  10142. return fitExtent(albersUsa, extent, object);
  10143. };
  10144. albersUsa.fitSize = function(size, object) {
  10145. return fitSize(albersUsa, size, object);
  10146. };
  10147. albersUsa.fitWidth = function(width, object) {
  10148. return fitWidth(albersUsa, width, object);
  10149. };
  10150. albersUsa.fitHeight = function(height, object) {
  10151. return fitHeight(albersUsa, height, object);
  10152. };
  10153. function reset() {
  10154. cache = cacheStream = null;
  10155. return albersUsa;
  10156. }
  10157. return albersUsa.scale(1070);
  10158. }
  10159. function azimuthalRaw(scale) {
  10160. return function(x, y) {
  10161. var cx = cos$1(x),
  10162. cy = cos$1(y),
  10163. k = scale(cx * cy);
  10164. if (k === Infinity) return [2, 0];
  10165. return [
  10166. k * cy * sin$1(x),
  10167. k * sin$1(y)
  10168. ];
  10169. }
  10170. }
  10171. function azimuthalInvert(angle) {
  10172. return function(x, y) {
  10173. var z = sqrt(x * x + y * y),
  10174. c = angle(z),
  10175. sc = sin$1(c),
  10176. cc = cos$1(c);
  10177. return [
  10178. atan2(x * sc, z * cc),
  10179. asin(z && y * sc / z)
  10180. ];
  10181. }
  10182. }
  10183. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  10184. return sqrt(2 / (1 + cxcy));
  10185. });
  10186. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  10187. return 2 * asin(z / 2);
  10188. });
  10189. function azimuthalEqualArea() {
  10190. return projection(azimuthalEqualAreaRaw)
  10191. .scale(124.75)
  10192. .clipAngle(180 - 1e-3);
  10193. }
  10194. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  10195. return (c = acos(c)) && c / sin$1(c);
  10196. });
  10197. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  10198. return z;
  10199. });
  10200. function azimuthalEquidistant() {
  10201. return projection(azimuthalEquidistantRaw)
  10202. .scale(79.4188)
  10203. .clipAngle(180 - 1e-3);
  10204. }
  10205. function mercatorRaw(lambda, phi) {
  10206. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  10207. }
  10208. mercatorRaw.invert = function(x, y) {
  10209. return [x, 2 * atan(exp(y)) - halfPi$2];
  10210. };
  10211. function mercator() {
  10212. return mercatorProjection(mercatorRaw)
  10213. .scale(961 / tau$4);
  10214. }
  10215. function mercatorProjection(project) {
  10216. var m = projection(project),
  10217. center = m.center,
  10218. scale = m.scale,
  10219. translate = m.translate,
  10220. clipExtent = m.clipExtent,
  10221. x0 = null, y0, x1, y1; // clip extent
  10222. m.scale = function(_) {
  10223. return arguments.length ? (scale(_), reclip()) : scale();
  10224. };
  10225. m.translate = function(_) {
  10226. return arguments.length ? (translate(_), reclip()) : translate();
  10227. };
  10228. m.center = function(_) {
  10229. return arguments.length ? (center(_), reclip()) : center();
  10230. };
  10231. m.clipExtent = function(_) {
  10232. 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]];
  10233. };
  10234. function reclip() {
  10235. var k = pi$3 * scale(),
  10236. t = m(rotation(m.rotate()).invert([0, 0]));
  10237. return clipExtent(x0 == null
  10238. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  10239. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  10240. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  10241. }
  10242. return reclip();
  10243. }
  10244. function tany(y) {
  10245. return tan((halfPi$2 + y) / 2);
  10246. }
  10247. function conicConformalRaw(y0, y1) {
  10248. var cy0 = cos$1(y0),
  10249. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  10250. f = cy0 * pow$1(tany(y0), n) / n;
  10251. if (!n) return mercatorRaw;
  10252. function project(x, y) {
  10253. if (f > 0) { if (y < -halfPi$2 + epsilon$4) y = -halfPi$2 + epsilon$4; }
  10254. else { if (y > halfPi$2 - epsilon$4) y = halfPi$2 - epsilon$4; }
  10255. var r = f / pow$1(tany(y), n);
  10256. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  10257. }
  10258. project.invert = function(x, y) {
  10259. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy),
  10260. l = atan2(x, abs$2(fy)) * sign(fy);
  10261. if (fy * n < 0)
  10262. l -= pi$3 * sign(x) * sign(fy);
  10263. return [l / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$2];
  10264. };
  10265. return project;
  10266. }
  10267. function conicConformal() {
  10268. return conicProjection(conicConformalRaw)
  10269. .scale(109.5)
  10270. .parallels([30, 30]);
  10271. }
  10272. function equirectangularRaw(lambda, phi) {
  10273. return [lambda, phi];
  10274. }
  10275. equirectangularRaw.invert = equirectangularRaw;
  10276. function equirectangular() {
  10277. return projection(equirectangularRaw)
  10278. .scale(152.63);
  10279. }
  10280. function conicEquidistantRaw(y0, y1) {
  10281. var cy0 = cos$1(y0),
  10282. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  10283. g = cy0 / n + y0;
  10284. if (abs$2(n) < epsilon$4) return equirectangularRaw;
  10285. function project(x, y) {
  10286. var gy = g - y, nx = n * x;
  10287. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  10288. }
  10289. project.invert = function(x, y) {
  10290. var gy = g - y,
  10291. l = atan2(x, abs$2(gy)) * sign(gy);
  10292. if (gy * n < 0)
  10293. l -= pi$3 * sign(x) * sign(gy);
  10294. return [l / n, g - sign(n) * sqrt(x * x + gy * gy)];
  10295. };
  10296. return project;
  10297. }
  10298. function conicEquidistant() {
  10299. return conicProjection(conicEquidistantRaw)
  10300. .scale(131.154)
  10301. .center([0, 13.9389]);
  10302. }
  10303. var A1 = 1.340264,
  10304. A2 = -0.081106,
  10305. A3 = 0.000893,
  10306. A4 = 0.003796,
  10307. M = sqrt(3) / 2,
  10308. iterations = 12;
  10309. function equalEarthRaw(lambda, phi) {
  10310. var l = asin(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
  10311. return [
  10312. lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
  10313. l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
  10314. ];
  10315. }
  10316. equalEarthRaw.invert = function(x, y) {
  10317. var l = y, l2 = l * l, l6 = l2 * l2 * l2;
  10318. for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
  10319. fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
  10320. fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
  10321. l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
  10322. if (abs$2(delta) < epsilon2$1) break;
  10323. }
  10324. return [
  10325. M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
  10326. asin(sin$1(l) / M)
  10327. ];
  10328. };
  10329. function equalEarth() {
  10330. return projection(equalEarthRaw)
  10331. .scale(177.158);
  10332. }
  10333. function gnomonicRaw(x, y) {
  10334. var cy = cos$1(y), k = cos$1(x) * cy;
  10335. return [cy * sin$1(x) / k, sin$1(y) / k];
  10336. }
  10337. gnomonicRaw.invert = azimuthalInvert(atan);
  10338. function gnomonic() {
  10339. return projection(gnomonicRaw)
  10340. .scale(144.049)
  10341. .clipAngle(60);
  10342. }
  10343. function identity$5() {
  10344. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect
  10345. alpha = 0, ca, sa, // angle
  10346. x0 = null, y0, x1, y1, // clip extent
  10347. kx = 1, ky = 1,
  10348. transform = transformer({
  10349. point: function(x, y) {
  10350. var p = projection([x, y]);
  10351. this.stream.point(p[0], p[1]);
  10352. }
  10353. }),
  10354. postclip = identity$4,
  10355. cache,
  10356. cacheStream;
  10357. function reset() {
  10358. kx = k * sx;
  10359. ky = k * sy;
  10360. cache = cacheStream = null;
  10361. return projection;
  10362. }
  10363. function projection (p) {
  10364. var x = p[0] * kx, y = p[1] * ky;
  10365. if (alpha) {
  10366. var t = y * ca - x * sa;
  10367. x = x * ca + y * sa;
  10368. y = t;
  10369. }
  10370. return [x + tx, y + ty];
  10371. }
  10372. projection.invert = function(p) {
  10373. var x = p[0] - tx, y = p[1] - ty;
  10374. if (alpha) {
  10375. var t = y * ca + x * sa;
  10376. x = x * ca - y * sa;
  10377. y = t;
  10378. }
  10379. return [x / kx, y / ky];
  10380. };
  10381. projection.stream = function(stream) {
  10382. return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
  10383. };
  10384. projection.postclip = function(_) {
  10385. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  10386. };
  10387. projection.clipExtent = function(_) {
  10388. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  10389. };
  10390. projection.scale = function(_) {
  10391. return arguments.length ? (k = +_, reset()) : k;
  10392. };
  10393. projection.translate = function(_) {
  10394. return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];
  10395. };
  10396. projection.angle = function(_) {
  10397. return arguments.length ? (alpha = _ % 360 * radians$1, sa = sin$1(alpha), ca = cos$1(alpha), reset()) : alpha * degrees$2;
  10398. };
  10399. projection.reflectX = function(_) {
  10400. return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;
  10401. };
  10402. projection.reflectY = function(_) {
  10403. return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;
  10404. };
  10405. projection.fitExtent = function(extent, object) {
  10406. return fitExtent(projection, extent, object);
  10407. };
  10408. projection.fitSize = function(size, object) {
  10409. return fitSize(projection, size, object);
  10410. };
  10411. projection.fitWidth = function(width, object) {
  10412. return fitWidth(projection, width, object);
  10413. };
  10414. projection.fitHeight = function(height, object) {
  10415. return fitHeight(projection, height, object);
  10416. };
  10417. return projection;
  10418. }
  10419. function naturalEarth1Raw(lambda, phi) {
  10420. var phi2 = phi * phi, phi4 = phi2 * phi2;
  10421. return [
  10422. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  10423. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  10424. ];
  10425. }
  10426. naturalEarth1Raw.invert = function(x, y) {
  10427. var phi = y, i = 25, delta;
  10428. do {
  10429. var phi2 = phi * phi, phi4 = phi2 * phi2;
  10430. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  10431. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  10432. } while (abs$2(delta) > epsilon$4 && --i > 0);
  10433. return [
  10434. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  10435. phi
  10436. ];
  10437. };
  10438. function naturalEarth1() {
  10439. return projection(naturalEarth1Raw)
  10440. .scale(175.295);
  10441. }
  10442. function orthographicRaw(x, y) {
  10443. return [cos$1(y) * sin$1(x), sin$1(y)];
  10444. }
  10445. orthographicRaw.invert = azimuthalInvert(asin);
  10446. function orthographic() {
  10447. return projection(orthographicRaw)
  10448. .scale(249.5)
  10449. .clipAngle(90 + epsilon$4);
  10450. }
  10451. function stereographicRaw(x, y) {
  10452. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  10453. return [cy * sin$1(x) / k, sin$1(y) / k];
  10454. }
  10455. stereographicRaw.invert = azimuthalInvert(function(z) {
  10456. return 2 * atan(z);
  10457. });
  10458. function stereographic() {
  10459. return projection(stereographicRaw)
  10460. .scale(250)
  10461. .clipAngle(142);
  10462. }
  10463. function transverseMercatorRaw(lambda, phi) {
  10464. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  10465. }
  10466. transverseMercatorRaw.invert = function(x, y) {
  10467. return [-y, 2 * atan(exp(x)) - halfPi$2];
  10468. };
  10469. function transverseMercator() {
  10470. var m = mercatorProjection(transverseMercatorRaw),
  10471. center = m.center,
  10472. rotate = m.rotate;
  10473. m.center = function(_) {
  10474. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  10475. };
  10476. m.rotate = function(_) {
  10477. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  10478. };
  10479. return rotate([0, 0, 90])
  10480. .scale(159.155);
  10481. }
  10482. function defaultSeparation(a, b) {
  10483. return a.parent === b.parent ? 1 : 2;
  10484. }
  10485. function meanX(children) {
  10486. return children.reduce(meanXReduce, 0) / children.length;
  10487. }
  10488. function meanXReduce(x, c) {
  10489. return x + c.x;
  10490. }
  10491. function maxY(children) {
  10492. return 1 + children.reduce(maxYReduce, 0);
  10493. }
  10494. function maxYReduce(y, c) {
  10495. return Math.max(y, c.y);
  10496. }
  10497. function leafLeft(node) {
  10498. var children;
  10499. while (children = node.children) node = children[0];
  10500. return node;
  10501. }
  10502. function leafRight(node) {
  10503. var children;
  10504. while (children = node.children) node = children[children.length - 1];
  10505. return node;
  10506. }
  10507. function cluster() {
  10508. var separation = defaultSeparation,
  10509. dx = 1,
  10510. dy = 1,
  10511. nodeSize = false;
  10512. function cluster(root) {
  10513. var previousNode,
  10514. x = 0;
  10515. // First walk, computing the initial x & y values.
  10516. root.eachAfter(function(node) {
  10517. var children = node.children;
  10518. if (children) {
  10519. node.x = meanX(children);
  10520. node.y = maxY(children);
  10521. } else {
  10522. node.x = previousNode ? x += separation(node, previousNode) : 0;
  10523. node.y = 0;
  10524. previousNode = node;
  10525. }
  10526. });
  10527. var left = leafLeft(root),
  10528. right = leafRight(root),
  10529. x0 = left.x - separation(left, right) / 2,
  10530. x1 = right.x + separation(right, left) / 2;
  10531. // Second walk, normalizing x & y to the desired size.
  10532. return root.eachAfter(nodeSize ? function(node) {
  10533. node.x = (node.x - root.x) * dx;
  10534. node.y = (root.y - node.y) * dy;
  10535. } : function(node) {
  10536. node.x = (node.x - x0) / (x1 - x0) * dx;
  10537. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  10538. });
  10539. }
  10540. cluster.separation = function(x) {
  10541. return arguments.length ? (separation = x, cluster) : separation;
  10542. };
  10543. cluster.size = function(x) {
  10544. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  10545. };
  10546. cluster.nodeSize = function(x) {
  10547. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  10548. };
  10549. return cluster;
  10550. }
  10551. function count$1(node) {
  10552. var sum = 0,
  10553. children = node.children,
  10554. i = children && children.length;
  10555. if (!i) sum = 1;
  10556. else while (--i >= 0) sum += children[i].value;
  10557. node.value = sum;
  10558. }
  10559. function node_count() {
  10560. return this.eachAfter(count$1);
  10561. }
  10562. function node_each(callback, that) {
  10563. let index = -1;
  10564. for (const node of this) {
  10565. callback.call(that, node, ++index, this);
  10566. }
  10567. return this;
  10568. }
  10569. function node_eachBefore(callback, that) {
  10570. var node = this, nodes = [node], children, i, index = -1;
  10571. while (node = nodes.pop()) {
  10572. callback.call(that, node, ++index, this);
  10573. if (children = node.children) {
  10574. for (i = children.length - 1; i >= 0; --i) {
  10575. nodes.push(children[i]);
  10576. }
  10577. }
  10578. }
  10579. return this;
  10580. }
  10581. function node_eachAfter(callback, that) {
  10582. var node = this, nodes = [node], next = [], children, i, n, index = -1;
  10583. while (node = nodes.pop()) {
  10584. next.push(node);
  10585. if (children = node.children) {
  10586. for (i = 0, n = children.length; i < n; ++i) {
  10587. nodes.push(children[i]);
  10588. }
  10589. }
  10590. }
  10591. while (node = next.pop()) {
  10592. callback.call(that, node, ++index, this);
  10593. }
  10594. return this;
  10595. }
  10596. function node_find(callback, that) {
  10597. let index = -1;
  10598. for (const node of this) {
  10599. if (callback.call(that, node, ++index, this)) {
  10600. return node;
  10601. }
  10602. }
  10603. }
  10604. function node_sum(value) {
  10605. return this.eachAfter(function(node) {
  10606. var sum = +value(node.data) || 0,
  10607. children = node.children,
  10608. i = children && children.length;
  10609. while (--i >= 0) sum += children[i].value;
  10610. node.value = sum;
  10611. });
  10612. }
  10613. function node_sort(compare) {
  10614. return this.eachBefore(function(node) {
  10615. if (node.children) {
  10616. node.children.sort(compare);
  10617. }
  10618. });
  10619. }
  10620. function node_path(end) {
  10621. var start = this,
  10622. ancestor = leastCommonAncestor(start, end),
  10623. nodes = [start];
  10624. while (start !== ancestor) {
  10625. start = start.parent;
  10626. nodes.push(start);
  10627. }
  10628. var k = nodes.length;
  10629. while (end !== ancestor) {
  10630. nodes.splice(k, 0, end);
  10631. end = end.parent;
  10632. }
  10633. return nodes;
  10634. }
  10635. function leastCommonAncestor(a, b) {
  10636. if (a === b) return a;
  10637. var aNodes = a.ancestors(),
  10638. bNodes = b.ancestors(),
  10639. c = null;
  10640. a = aNodes.pop();
  10641. b = bNodes.pop();
  10642. while (a === b) {
  10643. c = a;
  10644. a = aNodes.pop();
  10645. b = bNodes.pop();
  10646. }
  10647. return c;
  10648. }
  10649. function node_ancestors() {
  10650. var node = this, nodes = [node];
  10651. while (node = node.parent) {
  10652. nodes.push(node);
  10653. }
  10654. return nodes;
  10655. }
  10656. function node_descendants() {
  10657. return Array.from(this);
  10658. }
  10659. function node_leaves() {
  10660. var leaves = [];
  10661. this.eachBefore(function(node) {
  10662. if (!node.children) {
  10663. leaves.push(node);
  10664. }
  10665. });
  10666. return leaves;
  10667. }
  10668. function node_links() {
  10669. var root = this, links = [];
  10670. root.each(function(node) {
  10671. if (node !== root) { // Don’t include the root’s parent, if any.
  10672. links.push({source: node.parent, target: node});
  10673. }
  10674. });
  10675. return links;
  10676. }
  10677. function* node_iterator() {
  10678. var node = this, current, next = [node], children, i, n;
  10679. do {
  10680. current = next.reverse(), next = [];
  10681. while (node = current.pop()) {
  10682. yield node;
  10683. if (children = node.children) {
  10684. for (i = 0, n = children.length; i < n; ++i) {
  10685. next.push(children[i]);
  10686. }
  10687. }
  10688. }
  10689. } while (next.length);
  10690. }
  10691. function hierarchy(data, children) {
  10692. if (data instanceof Map) {
  10693. data = [undefined, data];
  10694. if (children === undefined) children = mapChildren;
  10695. } else if (children === undefined) {
  10696. children = objectChildren;
  10697. }
  10698. var root = new Node(data),
  10699. node,
  10700. nodes = [root],
  10701. child,
  10702. childs,
  10703. i,
  10704. n;
  10705. while (node = nodes.pop()) {
  10706. if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
  10707. node.children = childs;
  10708. for (i = n - 1; i >= 0; --i) {
  10709. nodes.push(child = childs[i] = new Node(childs[i]));
  10710. child.parent = node;
  10711. child.depth = node.depth + 1;
  10712. }
  10713. }
  10714. }
  10715. return root.eachBefore(computeHeight);
  10716. }
  10717. function node_copy() {
  10718. return hierarchy(this).eachBefore(copyData);
  10719. }
  10720. function objectChildren(d) {
  10721. return d.children;
  10722. }
  10723. function mapChildren(d) {
  10724. return Array.isArray(d) ? d[1] : null;
  10725. }
  10726. function copyData(node) {
  10727. if (node.data.value !== undefined) node.value = node.data.value;
  10728. node.data = node.data.data;
  10729. }
  10730. function computeHeight(node) {
  10731. var height = 0;
  10732. do node.height = height;
  10733. while ((node = node.parent) && (node.height < ++height));
  10734. }
  10735. function Node(data) {
  10736. this.data = data;
  10737. this.depth =
  10738. this.height = 0;
  10739. this.parent = null;
  10740. }
  10741. Node.prototype = hierarchy.prototype = {
  10742. constructor: Node,
  10743. count: node_count,
  10744. each: node_each,
  10745. eachAfter: node_eachAfter,
  10746. eachBefore: node_eachBefore,
  10747. find: node_find,
  10748. sum: node_sum,
  10749. sort: node_sort,
  10750. path: node_path,
  10751. ancestors: node_ancestors,
  10752. descendants: node_descendants,
  10753. leaves: node_leaves,
  10754. links: node_links,
  10755. copy: node_copy,
  10756. [Symbol.iterator]: node_iterator
  10757. };
  10758. function array$4(x) {
  10759. return typeof x === "object" && "length" in x
  10760. ? x // Array, TypedArray, NodeList, array-like
  10761. : Array.from(x); // Map, Set, iterable, string, or anything else
  10762. }
  10763. function shuffle$1(array) {
  10764. var m = array.length,
  10765. t,
  10766. i;
  10767. while (m) {
  10768. i = Math.random() * m-- | 0;
  10769. t = array[m];
  10770. array[m] = array[i];
  10771. array[i] = t;
  10772. }
  10773. return array;
  10774. }
  10775. function enclose(circles) {
  10776. var i = 0, n = (circles = shuffle$1(Array.from(circles))).length, B = [], p, e;
  10777. while (i < n) {
  10778. p = circles[i];
  10779. if (e && enclosesWeak(e, p)) ++i;
  10780. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  10781. }
  10782. return e;
  10783. }
  10784. function extendBasis(B, p) {
  10785. var i, j;
  10786. if (enclosesWeakAll(p, B)) return [p];
  10787. // If we get here then B must have at least one element.
  10788. for (i = 0; i < B.length; ++i) {
  10789. if (enclosesNot(p, B[i])
  10790. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  10791. return [B[i], p];
  10792. }
  10793. }
  10794. // If we get here then B must have at least two elements.
  10795. for (i = 0; i < B.length - 1; ++i) {
  10796. for (j = i + 1; j < B.length; ++j) {
  10797. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  10798. && enclosesNot(encloseBasis2(B[i], p), B[j])
  10799. && enclosesNot(encloseBasis2(B[j], p), B[i])
  10800. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  10801. return [B[i], B[j], p];
  10802. }
  10803. }
  10804. }
  10805. // If we get here then something is very wrong.
  10806. throw new Error;
  10807. }
  10808. function enclosesNot(a, b) {
  10809. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  10810. return dr < 0 || dr * dr < dx * dx + dy * dy;
  10811. }
  10812. function enclosesWeak(a, b) {
  10813. 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;
  10814. return dr > 0 && dr * dr > dx * dx + dy * dy;
  10815. }
  10816. function enclosesWeakAll(a, B) {
  10817. for (var i = 0; i < B.length; ++i) {
  10818. if (!enclosesWeak(a, B[i])) {
  10819. return false;
  10820. }
  10821. }
  10822. return true;
  10823. }
  10824. function encloseBasis(B) {
  10825. switch (B.length) {
  10826. case 1: return encloseBasis1(B[0]);
  10827. case 2: return encloseBasis2(B[0], B[1]);
  10828. case 3: return encloseBasis3(B[0], B[1], B[2]);
  10829. }
  10830. }
  10831. function encloseBasis1(a) {
  10832. return {
  10833. x: a.x,
  10834. y: a.y,
  10835. r: a.r
  10836. };
  10837. }
  10838. function encloseBasis2(a, b) {
  10839. var x1 = a.x, y1 = a.y, r1 = a.r,
  10840. x2 = b.x, y2 = b.y, r2 = b.r,
  10841. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  10842. l = Math.sqrt(x21 * x21 + y21 * y21);
  10843. return {
  10844. x: (x1 + x2 + x21 / l * r21) / 2,
  10845. y: (y1 + y2 + y21 / l * r21) / 2,
  10846. r: (l + r1 + r2) / 2
  10847. };
  10848. }
  10849. function encloseBasis3(a, b, c) {
  10850. var x1 = a.x, y1 = a.y, r1 = a.r,
  10851. x2 = b.x, y2 = b.y, r2 = b.r,
  10852. x3 = c.x, y3 = c.y, r3 = c.r,
  10853. a2 = x1 - x2,
  10854. a3 = x1 - x3,
  10855. b2 = y1 - y2,
  10856. b3 = y1 - y3,
  10857. c2 = r2 - r1,
  10858. c3 = r3 - r1,
  10859. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  10860. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  10861. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  10862. ab = a3 * b2 - a2 * b3,
  10863. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  10864. xb = (b3 * c2 - b2 * c3) / ab,
  10865. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  10866. yb = (a2 * c3 - a3 * c2) / ab,
  10867. A = xb * xb + yb * yb - 1,
  10868. B = 2 * (r1 + xa * xb + ya * yb),
  10869. C = xa * xa + ya * ya - r1 * r1,
  10870. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  10871. return {
  10872. x: x1 + xa + xb * r,
  10873. y: y1 + ya + yb * r,
  10874. r: r
  10875. };
  10876. }
  10877. function place(b, a, c) {
  10878. var dx = b.x - a.x, x, a2,
  10879. dy = b.y - a.y, y, b2,
  10880. d2 = dx * dx + dy * dy;
  10881. if (d2) {
  10882. a2 = a.r + c.r, a2 *= a2;
  10883. b2 = b.r + c.r, b2 *= b2;
  10884. if (a2 > b2) {
  10885. x = (d2 + b2 - a2) / (2 * d2);
  10886. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  10887. c.x = b.x - x * dx - y * dy;
  10888. c.y = b.y - x * dy + y * dx;
  10889. } else {
  10890. x = (d2 + a2 - b2) / (2 * d2);
  10891. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  10892. c.x = a.x + x * dx - y * dy;
  10893. c.y = a.y + x * dy + y * dx;
  10894. }
  10895. } else {
  10896. c.x = a.x + c.r;
  10897. c.y = a.y;
  10898. }
  10899. }
  10900. function intersects(a, b) {
  10901. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  10902. return dr > 0 && dr * dr > dx * dx + dy * dy;
  10903. }
  10904. function score(node) {
  10905. var a = node._,
  10906. b = node.next._,
  10907. ab = a.r + b.r,
  10908. dx = (a.x * b.r + b.x * a.r) / ab,
  10909. dy = (a.y * b.r + b.y * a.r) / ab;
  10910. return dx * dx + dy * dy;
  10911. }
  10912. function Node$1(circle) {
  10913. this._ = circle;
  10914. this.next = null;
  10915. this.previous = null;
  10916. }
  10917. function packEnclose(circles) {
  10918. if (!(n = (circles = array$4(circles)).length)) return 0;
  10919. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  10920. // Place the first circle.
  10921. a = circles[0], a.x = 0, a.y = 0;
  10922. if (!(n > 1)) return a.r;
  10923. // Place the second circle.
  10924. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  10925. if (!(n > 2)) return a.r + b.r;
  10926. // Place the third circle.
  10927. place(b, a, c = circles[2]);
  10928. // Initialize the front-chain using the first three circles a, b and c.
  10929. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  10930. a.next = c.previous = b;
  10931. b.next = a.previous = c;
  10932. c.next = b.previous = a;
  10933. // Attempt to place each remaining circle…
  10934. pack: for (i = 3; i < n; ++i) {
  10935. place(a._, b._, c = circles[i]), c = new Node$1(c);
  10936. // Find the closest intersecting circle on the front-chain, if any.
  10937. // “Closeness” is determined by linear distance along the front-chain.
  10938. // “Ahead” or “behind” is likewise determined by linear distance.
  10939. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  10940. do {
  10941. if (sj <= sk) {
  10942. if (intersects(j._, c._)) {
  10943. b = j, a.next = b, b.previous = a, --i;
  10944. continue pack;
  10945. }
  10946. sj += j._.r, j = j.next;
  10947. } else {
  10948. if (intersects(k._, c._)) {
  10949. a = k, a.next = b, b.previous = a, --i;
  10950. continue pack;
  10951. }
  10952. sk += k._.r, k = k.previous;
  10953. }
  10954. } while (j !== k.next);
  10955. // Success! Insert the new circle c between a and b.
  10956. c.previous = a, c.next = b, a.next = b.previous = b = c;
  10957. // Compute the new closest circle pair to the centroid.
  10958. aa = score(a);
  10959. while ((c = c.next) !== b) {
  10960. if ((ca = score(c)) < aa) {
  10961. a = c, aa = ca;
  10962. }
  10963. }
  10964. b = a.next;
  10965. }
  10966. // Compute the enclosing circle of the front chain.
  10967. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  10968. // Translate the circles to put the enclosing circle around the origin.
  10969. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  10970. return c.r;
  10971. }
  10972. function siblings(circles) {
  10973. packEnclose(circles);
  10974. return circles;
  10975. }
  10976. function optional(f) {
  10977. return f == null ? null : required(f);
  10978. }
  10979. function required(f) {
  10980. if (typeof f !== "function") throw new Error;
  10981. return f;
  10982. }
  10983. function constantZero() {
  10984. return 0;
  10985. }
  10986. function constant$9(x) {
  10987. return function() {
  10988. return x;
  10989. };
  10990. }
  10991. function defaultRadius$1(d) {
  10992. return Math.sqrt(d.value);
  10993. }
  10994. function index$3() {
  10995. var radius = null,
  10996. dx = 1,
  10997. dy = 1,
  10998. padding = constantZero;
  10999. function pack(root) {
  11000. root.x = dx / 2, root.y = dy / 2;
  11001. if (radius) {
  11002. root.eachBefore(radiusLeaf(radius))
  11003. .eachAfter(packChildren(padding, 0.5))
  11004. .eachBefore(translateChild(1));
  11005. } else {
  11006. root.eachBefore(radiusLeaf(defaultRadius$1))
  11007. .eachAfter(packChildren(constantZero, 1))
  11008. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  11009. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  11010. }
  11011. return root;
  11012. }
  11013. pack.radius = function(x) {
  11014. return arguments.length ? (radius = optional(x), pack) : radius;
  11015. };
  11016. pack.size = function(x) {
  11017. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  11018. };
  11019. pack.padding = function(x) {
  11020. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  11021. };
  11022. return pack;
  11023. }
  11024. function radiusLeaf(radius) {
  11025. return function(node) {
  11026. if (!node.children) {
  11027. node.r = Math.max(0, +radius(node) || 0);
  11028. }
  11029. };
  11030. }
  11031. function packChildren(padding, k) {
  11032. return function(node) {
  11033. if (children = node.children) {
  11034. var children,
  11035. i,
  11036. n = children.length,
  11037. r = padding(node) * k || 0,
  11038. e;
  11039. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  11040. e = packEnclose(children);
  11041. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  11042. node.r = e + r;
  11043. }
  11044. };
  11045. }
  11046. function translateChild(k) {
  11047. return function(node) {
  11048. var parent = node.parent;
  11049. node.r *= k;
  11050. if (parent) {
  11051. node.x = parent.x + k * node.x;
  11052. node.y = parent.y + k * node.y;
  11053. }
  11054. };
  11055. }
  11056. function roundNode(node) {
  11057. node.x0 = Math.round(node.x0);
  11058. node.y0 = Math.round(node.y0);
  11059. node.x1 = Math.round(node.x1);
  11060. node.y1 = Math.round(node.y1);
  11061. }
  11062. function treemapDice(parent, x0, y0, x1, y1) {
  11063. var nodes = parent.children,
  11064. node,
  11065. i = -1,
  11066. n = nodes.length,
  11067. k = parent.value && (x1 - x0) / parent.value;
  11068. while (++i < n) {
  11069. node = nodes[i], node.y0 = y0, node.y1 = y1;
  11070. node.x0 = x0, node.x1 = x0 += node.value * k;
  11071. }
  11072. }
  11073. function partition() {
  11074. var dx = 1,
  11075. dy = 1,
  11076. padding = 0,
  11077. round = false;
  11078. function partition(root) {
  11079. var n = root.height + 1;
  11080. root.x0 =
  11081. root.y0 = padding;
  11082. root.x1 = dx;
  11083. root.y1 = dy / n;
  11084. root.eachBefore(positionNode(dy, n));
  11085. if (round) root.eachBefore(roundNode);
  11086. return root;
  11087. }
  11088. function positionNode(dy, n) {
  11089. return function(node) {
  11090. if (node.children) {
  11091. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  11092. }
  11093. var x0 = node.x0,
  11094. y0 = node.y0,
  11095. x1 = node.x1 - padding,
  11096. y1 = node.y1 - padding;
  11097. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  11098. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  11099. node.x0 = x0;
  11100. node.y0 = y0;
  11101. node.x1 = x1;
  11102. node.y1 = y1;
  11103. };
  11104. }
  11105. partition.round = function(x) {
  11106. return arguments.length ? (round = !!x, partition) : round;
  11107. };
  11108. partition.size = function(x) {
  11109. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  11110. };
  11111. partition.padding = function(x) {
  11112. return arguments.length ? (padding = +x, partition) : padding;
  11113. };
  11114. return partition;
  11115. }
  11116. var preroot = {depth: -1},
  11117. ambiguous = {};
  11118. function defaultId(d) {
  11119. return d.id;
  11120. }
  11121. function defaultParentId(d) {
  11122. return d.parentId;
  11123. }
  11124. function stratify() {
  11125. var id = defaultId,
  11126. parentId = defaultParentId;
  11127. function stratify(data) {
  11128. var nodes = Array.from(data),
  11129. n = nodes.length,
  11130. d,
  11131. i,
  11132. root,
  11133. parent,
  11134. node,
  11135. nodeId,
  11136. nodeKey,
  11137. nodeByKey = new Map;
  11138. for (i = 0; i < n; ++i) {
  11139. d = nodes[i], node = nodes[i] = new Node(d);
  11140. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  11141. nodeKey = node.id = nodeId;
  11142. nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
  11143. }
  11144. if ((nodeId = parentId(d, i, data)) != null && (nodeId += "")) {
  11145. node.parent = nodeId;
  11146. }
  11147. }
  11148. for (i = 0; i < n; ++i) {
  11149. node = nodes[i];
  11150. if (nodeId = node.parent) {
  11151. parent = nodeByKey.get(nodeId);
  11152. if (!parent) throw new Error("missing: " + nodeId);
  11153. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  11154. if (parent.children) parent.children.push(node);
  11155. else parent.children = [node];
  11156. node.parent = parent;
  11157. } else {
  11158. if (root) throw new Error("multiple roots");
  11159. root = node;
  11160. }
  11161. }
  11162. if (!root) throw new Error("no root");
  11163. root.parent = preroot;
  11164. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  11165. root.parent = null;
  11166. if (n > 0) throw new Error("cycle");
  11167. return root;
  11168. }
  11169. stratify.id = function(x) {
  11170. return arguments.length ? (id = required(x), stratify) : id;
  11171. };
  11172. stratify.parentId = function(x) {
  11173. return arguments.length ? (parentId = required(x), stratify) : parentId;
  11174. };
  11175. return stratify;
  11176. }
  11177. function defaultSeparation$1(a, b) {
  11178. return a.parent === b.parent ? 1 : 2;
  11179. }
  11180. // function radialSeparation(a, b) {
  11181. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  11182. // }
  11183. // This function is used to traverse the left contour of a subtree (or
  11184. // subforest). It returns the successor of v on this contour. This successor is
  11185. // either given by the leftmost child of v or by the thread of v. The function
  11186. // returns null if and only if v is on the highest level of its subtree.
  11187. function nextLeft(v) {
  11188. var children = v.children;
  11189. return children ? children[0] : v.t;
  11190. }
  11191. // This function works analogously to nextLeft.
  11192. function nextRight(v) {
  11193. var children = v.children;
  11194. return children ? children[children.length - 1] : v.t;
  11195. }
  11196. // Shifts the current subtree rooted at w+. This is done by increasing
  11197. // prelim(w+) and mod(w+) by shift.
  11198. function moveSubtree(wm, wp, shift) {
  11199. var change = shift / (wp.i - wm.i);
  11200. wp.c -= change;
  11201. wp.s += shift;
  11202. wm.c += change;
  11203. wp.z += shift;
  11204. wp.m += shift;
  11205. }
  11206. // All other shifts, applied to the smaller subtrees between w- and w+, are
  11207. // performed by this function. To prepare the shifts, we have to adjust
  11208. // change(w+), shift(w+), and change(w-).
  11209. function executeShifts(v) {
  11210. var shift = 0,
  11211. change = 0,
  11212. children = v.children,
  11213. i = children.length,
  11214. w;
  11215. while (--i >= 0) {
  11216. w = children[i];
  11217. w.z += shift;
  11218. w.m += shift;
  11219. shift += w.s + (change += w.c);
  11220. }
  11221. }
  11222. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  11223. // returns the specified (default) ancestor.
  11224. function nextAncestor(vim, v, ancestor) {
  11225. return vim.a.parent === v.parent ? vim.a : ancestor;
  11226. }
  11227. function TreeNode(node, i) {
  11228. this._ = node;
  11229. this.parent = null;
  11230. this.children = null;
  11231. this.A = null; // default ancestor
  11232. this.a = this; // ancestor
  11233. this.z = 0; // prelim
  11234. this.m = 0; // mod
  11235. this.c = 0; // change
  11236. this.s = 0; // shift
  11237. this.t = null; // thread
  11238. this.i = i; // number
  11239. }
  11240. TreeNode.prototype = Object.create(Node.prototype);
  11241. function treeRoot(root) {
  11242. var tree = new TreeNode(root, 0),
  11243. node,
  11244. nodes = [tree],
  11245. child,
  11246. children,
  11247. i,
  11248. n;
  11249. while (node = nodes.pop()) {
  11250. if (children = node._.children) {
  11251. node.children = new Array(n = children.length);
  11252. for (i = n - 1; i >= 0; --i) {
  11253. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  11254. child.parent = node;
  11255. }
  11256. }
  11257. }
  11258. (tree.parent = new TreeNode(null, 0)).children = [tree];
  11259. return tree;
  11260. }
  11261. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  11262. function tree() {
  11263. var separation = defaultSeparation$1,
  11264. dx = 1,
  11265. dy = 1,
  11266. nodeSize = null;
  11267. function tree(root) {
  11268. var t = treeRoot(root);
  11269. // Compute the layout using Buchheim et al.’s algorithm.
  11270. t.eachAfter(firstWalk), t.parent.m = -t.z;
  11271. t.eachBefore(secondWalk);
  11272. // If a fixed node size is specified, scale x and y.
  11273. if (nodeSize) root.eachBefore(sizeNode);
  11274. // If a fixed tree size is specified, scale x and y based on the extent.
  11275. // Compute the left-most, right-most, and depth-most nodes for extents.
  11276. else {
  11277. var left = root,
  11278. right = root,
  11279. bottom = root;
  11280. root.eachBefore(function(node) {
  11281. if (node.x < left.x) left = node;
  11282. if (node.x > right.x) right = node;
  11283. if (node.depth > bottom.depth) bottom = node;
  11284. });
  11285. var s = left === right ? 1 : separation(left, right) / 2,
  11286. tx = s - left.x,
  11287. kx = dx / (right.x + s + tx),
  11288. ky = dy / (bottom.depth || 1);
  11289. root.eachBefore(function(node) {
  11290. node.x = (node.x + tx) * kx;
  11291. node.y = node.depth * ky;
  11292. });
  11293. }
  11294. return root;
  11295. }
  11296. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  11297. // applied recursively to the children of v, as well as the function
  11298. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  11299. // node v is placed to the midpoint of its outermost children.
  11300. function firstWalk(v) {
  11301. var children = v.children,
  11302. siblings = v.parent.children,
  11303. w = v.i ? siblings[v.i - 1] : null;
  11304. if (children) {
  11305. executeShifts(v);
  11306. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  11307. if (w) {
  11308. v.z = w.z + separation(v._, w._);
  11309. v.m = v.z - midpoint;
  11310. } else {
  11311. v.z = midpoint;
  11312. }
  11313. } else if (w) {
  11314. v.z = w.z + separation(v._, w._);
  11315. }
  11316. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  11317. }
  11318. // Computes all real x-coordinates by summing up the modifiers recursively.
  11319. function secondWalk(v) {
  11320. v._.x = v.z + v.parent.m;
  11321. v.m += v.parent.m;
  11322. }
  11323. // The core of the algorithm. Here, a new subtree is combined with the
  11324. // previous subtrees. Threads are used to traverse the inside and outside
  11325. // contours of the left and right subtree up to the highest common level. The
  11326. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  11327. // superscript o means outside and i means inside, the subscript - means left
  11328. // subtree and + means right subtree. For summing up the modifiers along the
  11329. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  11330. // nodes of the inside contours conflict, we compute the left one of the
  11331. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  11332. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  11333. // Finally, we add a new thread (if necessary).
  11334. function apportion(v, w, ancestor) {
  11335. if (w) {
  11336. var vip = v,
  11337. vop = v,
  11338. vim = w,
  11339. vom = vip.parent.children[0],
  11340. sip = vip.m,
  11341. sop = vop.m,
  11342. sim = vim.m,
  11343. som = vom.m,
  11344. shift;
  11345. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  11346. vom = nextLeft(vom);
  11347. vop = nextRight(vop);
  11348. vop.a = v;
  11349. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  11350. if (shift > 0) {
  11351. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  11352. sip += shift;
  11353. sop += shift;
  11354. }
  11355. sim += vim.m;
  11356. sip += vip.m;
  11357. som += vom.m;
  11358. sop += vop.m;
  11359. }
  11360. if (vim && !nextRight(vop)) {
  11361. vop.t = vim;
  11362. vop.m += sim - sop;
  11363. }
  11364. if (vip && !nextLeft(vom)) {
  11365. vom.t = vip;
  11366. vom.m += sip - som;
  11367. ancestor = v;
  11368. }
  11369. }
  11370. return ancestor;
  11371. }
  11372. function sizeNode(node) {
  11373. node.x *= dx;
  11374. node.y = node.depth * dy;
  11375. }
  11376. tree.separation = function(x) {
  11377. return arguments.length ? (separation = x, tree) : separation;
  11378. };
  11379. tree.size = function(x) {
  11380. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  11381. };
  11382. tree.nodeSize = function(x) {
  11383. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  11384. };
  11385. return tree;
  11386. }
  11387. function treemapSlice(parent, x0, y0, x1, y1) {
  11388. var nodes = parent.children,
  11389. node,
  11390. i = -1,
  11391. n = nodes.length,
  11392. k = parent.value && (y1 - y0) / parent.value;
  11393. while (++i < n) {
  11394. node = nodes[i], node.x0 = x0, node.x1 = x1;
  11395. node.y0 = y0, node.y1 = y0 += node.value * k;
  11396. }
  11397. }
  11398. var phi = (1 + Math.sqrt(5)) / 2;
  11399. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  11400. var rows = [],
  11401. nodes = parent.children,
  11402. row,
  11403. nodeValue,
  11404. i0 = 0,
  11405. i1 = 0,
  11406. n = nodes.length,
  11407. dx, dy,
  11408. value = parent.value,
  11409. sumValue,
  11410. minValue,
  11411. maxValue,
  11412. newRatio,
  11413. minRatio,
  11414. alpha,
  11415. beta;
  11416. while (i0 < n) {
  11417. dx = x1 - x0, dy = y1 - y0;
  11418. // Find the next non-empty node.
  11419. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  11420. minValue = maxValue = sumValue;
  11421. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  11422. beta = sumValue * sumValue * alpha;
  11423. minRatio = Math.max(maxValue / beta, beta / minValue);
  11424. // Keep adding nodes while the aspect ratio maintains or improves.
  11425. for (; i1 < n; ++i1) {
  11426. sumValue += nodeValue = nodes[i1].value;
  11427. if (nodeValue < minValue) minValue = nodeValue;
  11428. if (nodeValue > maxValue) maxValue = nodeValue;
  11429. beta = sumValue * sumValue * alpha;
  11430. newRatio = Math.max(maxValue / beta, beta / minValue);
  11431. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  11432. minRatio = newRatio;
  11433. }
  11434. // Position and record the row orientation.
  11435. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  11436. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  11437. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  11438. value -= sumValue, i0 = i1;
  11439. }
  11440. return rows;
  11441. }
  11442. var squarify = (function custom(ratio) {
  11443. function squarify(parent, x0, y0, x1, y1) {
  11444. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  11445. }
  11446. squarify.ratio = function(x) {
  11447. return custom((x = +x) > 1 ? x : 1);
  11448. };
  11449. return squarify;
  11450. })(phi);
  11451. function index$4() {
  11452. var tile = squarify,
  11453. round = false,
  11454. dx = 1,
  11455. dy = 1,
  11456. paddingStack = [0],
  11457. paddingInner = constantZero,
  11458. paddingTop = constantZero,
  11459. paddingRight = constantZero,
  11460. paddingBottom = constantZero,
  11461. paddingLeft = constantZero;
  11462. function treemap(root) {
  11463. root.x0 =
  11464. root.y0 = 0;
  11465. root.x1 = dx;
  11466. root.y1 = dy;
  11467. root.eachBefore(positionNode);
  11468. paddingStack = [0];
  11469. if (round) root.eachBefore(roundNode);
  11470. return root;
  11471. }
  11472. function positionNode(node) {
  11473. var p = paddingStack[node.depth],
  11474. x0 = node.x0 + p,
  11475. y0 = node.y0 + p,
  11476. x1 = node.x1 - p,
  11477. y1 = node.y1 - p;
  11478. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  11479. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  11480. node.x0 = x0;
  11481. node.y0 = y0;
  11482. node.x1 = x1;
  11483. node.y1 = y1;
  11484. if (node.children) {
  11485. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  11486. x0 += paddingLeft(node) - p;
  11487. y0 += paddingTop(node) - p;
  11488. x1 -= paddingRight(node) - p;
  11489. y1 -= paddingBottom(node) - p;
  11490. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  11491. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  11492. tile(node, x0, y0, x1, y1);
  11493. }
  11494. }
  11495. treemap.round = function(x) {
  11496. return arguments.length ? (round = !!x, treemap) : round;
  11497. };
  11498. treemap.size = function(x) {
  11499. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  11500. };
  11501. treemap.tile = function(x) {
  11502. return arguments.length ? (tile = required(x), treemap) : tile;
  11503. };
  11504. treemap.padding = function(x) {
  11505. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  11506. };
  11507. treemap.paddingInner = function(x) {
  11508. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  11509. };
  11510. treemap.paddingOuter = function(x) {
  11511. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  11512. };
  11513. treemap.paddingTop = function(x) {
  11514. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  11515. };
  11516. treemap.paddingRight = function(x) {
  11517. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  11518. };
  11519. treemap.paddingBottom = function(x) {
  11520. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  11521. };
  11522. treemap.paddingLeft = function(x) {
  11523. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  11524. };
  11525. return treemap;
  11526. }
  11527. function binary(parent, x0, y0, x1, y1) {
  11528. var nodes = parent.children,
  11529. i, n = nodes.length,
  11530. sum, sums = new Array(n + 1);
  11531. for (sums[0] = sum = i = 0; i < n; ++i) {
  11532. sums[i + 1] = sum += nodes[i].value;
  11533. }
  11534. partition(0, n, parent.value, x0, y0, x1, y1);
  11535. function partition(i, j, value, x0, y0, x1, y1) {
  11536. if (i >= j - 1) {
  11537. var node = nodes[i];
  11538. node.x0 = x0, node.y0 = y0;
  11539. node.x1 = x1, node.y1 = y1;
  11540. return;
  11541. }
  11542. var valueOffset = sums[i],
  11543. valueTarget = (value / 2) + valueOffset,
  11544. k = i + 1,
  11545. hi = j - 1;
  11546. while (k < hi) {
  11547. var mid = k + hi >>> 1;
  11548. if (sums[mid] < valueTarget) k = mid + 1;
  11549. else hi = mid;
  11550. }
  11551. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  11552. var valueLeft = sums[k] - valueOffset,
  11553. valueRight = value - valueLeft;
  11554. if ((x1 - x0) > (y1 - y0)) {
  11555. var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
  11556. partition(i, k, valueLeft, x0, y0, xk, y1);
  11557. partition(k, j, valueRight, xk, y0, x1, y1);
  11558. } else {
  11559. var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
  11560. partition(i, k, valueLeft, x0, y0, x1, yk);
  11561. partition(k, j, valueRight, x0, yk, x1, y1);
  11562. }
  11563. }
  11564. }
  11565. function sliceDice(parent, x0, y0, x1, y1) {
  11566. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  11567. }
  11568. var resquarify = (function custom(ratio) {
  11569. function resquarify(parent, x0, y0, x1, y1) {
  11570. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  11571. var rows,
  11572. row,
  11573. nodes,
  11574. i,
  11575. j = -1,
  11576. n,
  11577. m = rows.length,
  11578. value = parent.value;
  11579. while (++j < m) {
  11580. row = rows[j], nodes = row.children;
  11581. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  11582. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1);
  11583. else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1);
  11584. value -= row.value;
  11585. }
  11586. } else {
  11587. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  11588. rows.ratio = ratio;
  11589. }
  11590. }
  11591. resquarify.ratio = function(x) {
  11592. return custom((x = +x) > 1 ? x : 1);
  11593. };
  11594. return resquarify;
  11595. })(phi);
  11596. function area$2(polygon) {
  11597. var i = -1,
  11598. n = polygon.length,
  11599. a,
  11600. b = polygon[n - 1],
  11601. area = 0;
  11602. while (++i < n) {
  11603. a = b;
  11604. b = polygon[i];
  11605. area += a[1] * b[0] - a[0] * b[1];
  11606. }
  11607. return area / 2;
  11608. }
  11609. function centroid$1(polygon) {
  11610. var i = -1,
  11611. n = polygon.length,
  11612. x = 0,
  11613. y = 0,
  11614. a,
  11615. b = polygon[n - 1],
  11616. c,
  11617. k = 0;
  11618. while (++i < n) {
  11619. a = b;
  11620. b = polygon[i];
  11621. k += c = a[0] * b[1] - b[0] * a[1];
  11622. x += (a[0] + b[0]) * c;
  11623. y += (a[1] + b[1]) * c;
  11624. }
  11625. return k *= 3, [x / k, y / k];
  11626. }
  11627. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  11628. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  11629. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  11630. // negative if clockwise, and zero if the points are collinear.
  11631. function cross$1(a, b, c) {
  11632. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  11633. }
  11634. function lexicographicOrder(a, b) {
  11635. return a[0] - b[0] || a[1] - b[1];
  11636. }
  11637. // Computes the upper convex hull per the monotone chain algorithm.
  11638. // Assumes points.length >= 3, is sorted by x, unique in y.
  11639. // Returns an array of indices into points in left-to-right order.
  11640. function computeUpperHullIndexes(points) {
  11641. const n = points.length,
  11642. indexes = [0, 1];
  11643. let size = 2, i;
  11644. for (i = 2; i < n; ++i) {
  11645. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  11646. indexes[size++] = i;
  11647. }
  11648. return indexes.slice(0, size); // remove popped points
  11649. }
  11650. function hull(points) {
  11651. if ((n = points.length) < 3) return null;
  11652. var i,
  11653. n,
  11654. sortedPoints = new Array(n),
  11655. flippedPoints = new Array(n);
  11656. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  11657. sortedPoints.sort(lexicographicOrder);
  11658. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  11659. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  11660. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  11661. // Construct the hull polygon, removing possible duplicate endpoints.
  11662. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  11663. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  11664. hull = [];
  11665. // Add upper hull in right-to-l order.
  11666. // Then add lower hull in left-to-right order.
  11667. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  11668. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  11669. return hull;
  11670. }
  11671. function contains$2(polygon, point) {
  11672. var n = polygon.length,
  11673. p = polygon[n - 1],
  11674. x = point[0], y = point[1],
  11675. x0 = p[0], y0 = p[1],
  11676. x1, y1,
  11677. inside = false;
  11678. for (var i = 0; i < n; ++i) {
  11679. p = polygon[i], x1 = p[0], y1 = p[1];
  11680. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  11681. x0 = x1, y0 = y1;
  11682. }
  11683. return inside;
  11684. }
  11685. function length$3(polygon) {
  11686. var i = -1,
  11687. n = polygon.length,
  11688. b = polygon[n - 1],
  11689. xa,
  11690. ya,
  11691. xb = b[0],
  11692. yb = b[1],
  11693. perimeter = 0;
  11694. while (++i < n) {
  11695. xa = xb;
  11696. ya = yb;
  11697. b = polygon[i];
  11698. xb = b[0];
  11699. yb = b[1];
  11700. xa -= xb;
  11701. ya -= yb;
  11702. perimeter += Math.hypot(xa, ya);
  11703. }
  11704. return perimeter;
  11705. }
  11706. var defaultSource$1 = Math.random;
  11707. var uniform = (function sourceRandomUniform(source) {
  11708. function randomUniform(min, max) {
  11709. min = min == null ? 0 : +min;
  11710. max = max == null ? 1 : +max;
  11711. if (arguments.length === 1) max = min, min = 0;
  11712. else max -= min;
  11713. return function() {
  11714. return source() * max + min;
  11715. };
  11716. }
  11717. randomUniform.source = sourceRandomUniform;
  11718. return randomUniform;
  11719. })(defaultSource$1);
  11720. var int = (function sourceRandomInt(source) {
  11721. function randomInt(min, max) {
  11722. if (arguments.length < 2) max = min, min = 0;
  11723. min = Math.floor(min);
  11724. max = Math.floor(max) - min;
  11725. return function() {
  11726. return Math.floor(source() * max + min);
  11727. };
  11728. }
  11729. randomInt.source = sourceRandomInt;
  11730. return randomInt;
  11731. })(defaultSource$1);
  11732. var normal = (function sourceRandomNormal(source) {
  11733. function randomNormal(mu, sigma) {
  11734. var x, r;
  11735. mu = mu == null ? 0 : +mu;
  11736. sigma = sigma == null ? 1 : +sigma;
  11737. return function() {
  11738. var y;
  11739. // If available, use the second previously-generated uniform random.
  11740. if (x != null) y = x, x = null;
  11741. // Otherwise, generate a new x and y.
  11742. else do {
  11743. x = source() * 2 - 1;
  11744. y = source() * 2 - 1;
  11745. r = x * x + y * y;
  11746. } while (!r || r > 1);
  11747. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  11748. };
  11749. }
  11750. randomNormal.source = sourceRandomNormal;
  11751. return randomNormal;
  11752. })(defaultSource$1);
  11753. var logNormal = (function sourceRandomLogNormal(source) {
  11754. var N = normal.source(source);
  11755. function randomLogNormal() {
  11756. var randomNormal = N.apply(this, arguments);
  11757. return function() {
  11758. return Math.exp(randomNormal());
  11759. };
  11760. }
  11761. randomLogNormal.source = sourceRandomLogNormal;
  11762. return randomLogNormal;
  11763. })(defaultSource$1);
  11764. var irwinHall = (function sourceRandomIrwinHall(source) {
  11765. function randomIrwinHall(n) {
  11766. if ((n = +n) <= 0) return () => 0;
  11767. return function() {
  11768. for (var sum = 0, i = n; i > 1; --i) sum += source();
  11769. return sum + i * source();
  11770. };
  11771. }
  11772. randomIrwinHall.source = sourceRandomIrwinHall;
  11773. return randomIrwinHall;
  11774. })(defaultSource$1);
  11775. var bates = (function sourceRandomBates(source) {
  11776. var I = irwinHall.source(source);
  11777. function randomBates(n) {
  11778. // use limiting distribution at n === 0
  11779. if ((n = +n) === 0) return source;
  11780. var randomIrwinHall = I(n);
  11781. return function() {
  11782. return randomIrwinHall() / n;
  11783. };
  11784. }
  11785. randomBates.source = sourceRandomBates;
  11786. return randomBates;
  11787. })(defaultSource$1);
  11788. var exponential$1 = (function sourceRandomExponential(source) {
  11789. function randomExponential(lambda) {
  11790. return function() {
  11791. return -Math.log1p(-source()) / lambda;
  11792. };
  11793. }
  11794. randomExponential.source = sourceRandomExponential;
  11795. return randomExponential;
  11796. })(defaultSource$1);
  11797. var pareto = (function sourceRandomPareto(source) {
  11798. function randomPareto(alpha) {
  11799. if ((alpha = +alpha) < 0) throw new RangeError("invalid alpha");
  11800. alpha = 1 / -alpha;
  11801. return function() {
  11802. return Math.pow(1 - source(), alpha);
  11803. };
  11804. }
  11805. randomPareto.source = sourceRandomPareto;
  11806. return randomPareto;
  11807. })(defaultSource$1);
  11808. var bernoulli = (function sourceRandomBernoulli(source) {
  11809. function randomBernoulli(p) {
  11810. if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
  11811. return function() {
  11812. return Math.floor(source() + p);
  11813. };
  11814. }
  11815. randomBernoulli.source = sourceRandomBernoulli;
  11816. return randomBernoulli;
  11817. })(defaultSource$1);
  11818. var geometric = (function sourceRandomGeometric(source) {
  11819. function randomGeometric(p) {
  11820. if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
  11821. if (p === 0) return () => Infinity;
  11822. if (p === 1) return () => 1;
  11823. p = Math.log1p(-p);
  11824. return function() {
  11825. return 1 + Math.floor(Math.log1p(-source()) / p);
  11826. };
  11827. }
  11828. randomGeometric.source = sourceRandomGeometric;
  11829. return randomGeometric;
  11830. })(defaultSource$1);
  11831. var gamma$1 = (function sourceRandomGamma(source) {
  11832. var randomNormal = normal.source(source)();
  11833. function randomGamma(k, theta) {
  11834. if ((k = +k) < 0) throw new RangeError("invalid k");
  11835. // degenerate distribution if k === 0
  11836. if (k === 0) return () => 0;
  11837. theta = theta == null ? 1 : +theta;
  11838. // exponential distribution if k === 1
  11839. if (k === 1) return () => -Math.log1p(-source()) * theta;
  11840. var d = (k < 1 ? k + 1 : k) - 1 / 3,
  11841. c = 1 / (3 * Math.sqrt(d)),
  11842. multiplier = k < 1 ? () => Math.pow(source(), 1 / k) : () => 1;
  11843. return function() {
  11844. do {
  11845. do {
  11846. var x = randomNormal(),
  11847. v = 1 + c * x;
  11848. } while (v <= 0);
  11849. v *= v * v;
  11850. var u = 1 - source();
  11851. } while (u >= 1 - 0.0331 * x * x * x * x && Math.log(u) >= 0.5 * x * x + d * (1 - v + Math.log(v)));
  11852. return d * v * multiplier() * theta;
  11853. };
  11854. }
  11855. randomGamma.source = sourceRandomGamma;
  11856. return randomGamma;
  11857. })(defaultSource$1);
  11858. var beta = (function sourceRandomBeta(source) {
  11859. var G = gamma$1.source(source);
  11860. function randomBeta(alpha, beta) {
  11861. var X = G(alpha),
  11862. Y = G(beta);
  11863. return function() {
  11864. var x = X();
  11865. return x === 0 ? 0 : x / (x + Y());
  11866. };
  11867. }
  11868. randomBeta.source = sourceRandomBeta;
  11869. return randomBeta;
  11870. })(defaultSource$1);
  11871. var binomial = (function sourceRandomBinomial(source) {
  11872. var G = geometric.source(source),
  11873. B = beta.source(source);
  11874. function randomBinomial(n, p) {
  11875. n = +n;
  11876. if ((p = +p) >= 1) return () => n;
  11877. if (p <= 0) return () => 0;
  11878. return function() {
  11879. var acc = 0, nn = n, pp = p;
  11880. while (nn * pp > 16 && nn * (1 - pp) > 16) {
  11881. var i = Math.floor((nn + 1) * pp),
  11882. y = B(i, nn - i + 1)();
  11883. if (y <= pp) {
  11884. acc += i;
  11885. nn -= i;
  11886. pp = (pp - y) / (1 - y);
  11887. } else {
  11888. nn = i - 1;
  11889. pp /= y;
  11890. }
  11891. }
  11892. var sign = pp < 0.5,
  11893. pFinal = sign ? pp : 1 - pp,
  11894. g = G(pFinal);
  11895. for (var s = g(), k = 0; s <= nn; ++k) s += g();
  11896. return acc + (sign ? k : nn - k);
  11897. };
  11898. }
  11899. randomBinomial.source = sourceRandomBinomial;
  11900. return randomBinomial;
  11901. })(defaultSource$1);
  11902. var weibull = (function sourceRandomWeibull(source) {
  11903. function randomWeibull(k, a, b) {
  11904. var outerFunc;
  11905. if ((k = +k) === 0) {
  11906. outerFunc = x => -Math.log(x);
  11907. } else {
  11908. k = 1 / k;
  11909. outerFunc = x => Math.pow(x, k);
  11910. }
  11911. a = a == null ? 0 : +a;
  11912. b = b == null ? 1 : +b;
  11913. return function() {
  11914. return a + b * outerFunc(-Math.log1p(-source()));
  11915. };
  11916. }
  11917. randomWeibull.source = sourceRandomWeibull;
  11918. return randomWeibull;
  11919. })(defaultSource$1);
  11920. var cauchy = (function sourceRandomCauchy(source) {
  11921. function randomCauchy(a, b) {
  11922. a = a == null ? 0 : +a;
  11923. b = b == null ? 1 : +b;
  11924. return function() {
  11925. return a + b * Math.tan(Math.PI * source());
  11926. };
  11927. }
  11928. randomCauchy.source = sourceRandomCauchy;
  11929. return randomCauchy;
  11930. })(defaultSource$1);
  11931. var logistic = (function sourceRandomLogistic(source) {
  11932. function randomLogistic(a, b) {
  11933. a = a == null ? 0 : +a;
  11934. b = b == null ? 1 : +b;
  11935. return function() {
  11936. var u = source();
  11937. return a + b * Math.log(u / (1 - u));
  11938. };
  11939. }
  11940. randomLogistic.source = sourceRandomLogistic;
  11941. return randomLogistic;
  11942. })(defaultSource$1);
  11943. var poisson = (function sourceRandomPoisson(source) {
  11944. var G = gamma$1.source(source),
  11945. B = binomial.source(source);
  11946. function randomPoisson(lambda) {
  11947. return function() {
  11948. var acc = 0, l = lambda;
  11949. while (l > 16) {
  11950. var n = Math.floor(0.875 * l),
  11951. t = G(n)();
  11952. if (t > l) return acc + B(n - 1, l / t)();
  11953. acc += n;
  11954. l -= t;
  11955. }
  11956. for (var s = -Math.log1p(-source()), k = 0; s <= l; ++k) s -= Math.log1p(-source());
  11957. return acc + k;
  11958. };
  11959. }
  11960. randomPoisson.source = sourceRandomPoisson;
  11961. return randomPoisson;
  11962. })(defaultSource$1);
  11963. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  11964. const mul = 0x19660D;
  11965. const inc = 0x3C6EF35F;
  11966. const eps = 1 / 0x100000000;
  11967. function lcg$1(seed = Math.random()) {
  11968. let state = (0 <= seed && seed < 1 ? seed / eps : Math.abs(seed)) | 0;
  11969. return () => (state = mul * state + inc | 0, eps * (state >>> 0));
  11970. }
  11971. function initRange(domain, range) {
  11972. switch (arguments.length) {
  11973. case 0: break;
  11974. case 1: this.range(domain); break;
  11975. default: this.range(range).domain(domain); break;
  11976. }
  11977. return this;
  11978. }
  11979. function initInterpolator(domain, interpolator) {
  11980. switch (arguments.length) {
  11981. case 0: break;
  11982. case 1: {
  11983. if (typeof domain === "function") this.interpolator(domain);
  11984. else this.range(domain);
  11985. break;
  11986. }
  11987. default: {
  11988. this.domain(domain);
  11989. if (typeof interpolator === "function") this.interpolator(interpolator);
  11990. else this.range(interpolator);
  11991. break;
  11992. }
  11993. }
  11994. return this;
  11995. }
  11996. const implicit = Symbol("implicit");
  11997. function ordinal() {
  11998. var index = new Map(),
  11999. domain = [],
  12000. range = [],
  12001. unknown = implicit;
  12002. function scale(d) {
  12003. var key = d + "", i = index.get(key);
  12004. if (!i) {
  12005. if (unknown !== implicit) return unknown;
  12006. index.set(key, i = domain.push(d));
  12007. }
  12008. return range[(i - 1) % range.length];
  12009. }
  12010. scale.domain = function(_) {
  12011. if (!arguments.length) return domain.slice();
  12012. domain = [], index = new Map();
  12013. for (const value of _) {
  12014. const key = value + "";
  12015. if (index.has(key)) continue;
  12016. index.set(key, domain.push(value));
  12017. }
  12018. return scale;
  12019. };
  12020. scale.range = function(_) {
  12021. return arguments.length ? (range = Array.from(_), scale) : range.slice();
  12022. };
  12023. scale.unknown = function(_) {
  12024. return arguments.length ? (unknown = _, scale) : unknown;
  12025. };
  12026. scale.copy = function() {
  12027. return ordinal(domain, range).unknown(unknown);
  12028. };
  12029. initRange.apply(scale, arguments);
  12030. return scale;
  12031. }
  12032. function band() {
  12033. var scale = ordinal().unknown(undefined),
  12034. domain = scale.domain,
  12035. ordinalRange = scale.range,
  12036. r0 = 0,
  12037. r1 = 1,
  12038. step,
  12039. bandwidth,
  12040. round = false,
  12041. paddingInner = 0,
  12042. paddingOuter = 0,
  12043. align = 0.5;
  12044. delete scale.unknown;
  12045. function rescale() {
  12046. var n = domain().length,
  12047. reverse = r1 < r0,
  12048. start = reverse ? r1 : r0,
  12049. stop = reverse ? r0 : r1;
  12050. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  12051. if (round) step = Math.floor(step);
  12052. start += (stop - start - step * (n - paddingInner)) * align;
  12053. bandwidth = step * (1 - paddingInner);
  12054. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  12055. var values = sequence(n).map(function(i) { return start + step * i; });
  12056. return ordinalRange(reverse ? values.reverse() : values);
  12057. }
  12058. scale.domain = function(_) {
  12059. return arguments.length ? (domain(_), rescale()) : domain();
  12060. };
  12061. scale.range = function(_) {
  12062. return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
  12063. };
  12064. scale.rangeRound = function(_) {
  12065. return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
  12066. };
  12067. scale.bandwidth = function() {
  12068. return bandwidth;
  12069. };
  12070. scale.step = function() {
  12071. return step;
  12072. };
  12073. scale.round = function(_) {
  12074. return arguments.length ? (round = !!_, rescale()) : round;
  12075. };
  12076. scale.padding = function(_) {
  12077. return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
  12078. };
  12079. scale.paddingInner = function(_) {
  12080. return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
  12081. };
  12082. scale.paddingOuter = function(_) {
  12083. return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
  12084. };
  12085. scale.align = function(_) {
  12086. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  12087. };
  12088. scale.copy = function() {
  12089. return band(domain(), [r0, r1])
  12090. .round(round)
  12091. .paddingInner(paddingInner)
  12092. .paddingOuter(paddingOuter)
  12093. .align(align);
  12094. };
  12095. return initRange.apply(rescale(), arguments);
  12096. }
  12097. function pointish(scale) {
  12098. var copy = scale.copy;
  12099. scale.padding = scale.paddingOuter;
  12100. delete scale.paddingInner;
  12101. delete scale.paddingOuter;
  12102. scale.copy = function() {
  12103. return pointish(copy());
  12104. };
  12105. return scale;
  12106. }
  12107. function point() {
  12108. return pointish(band.apply(null, arguments).paddingInner(1));
  12109. }
  12110. function constants(x) {
  12111. return function() {
  12112. return x;
  12113. };
  12114. }
  12115. function number$2(x) {
  12116. return +x;
  12117. }
  12118. var unit = [0, 1];
  12119. function identity$6(x) {
  12120. return x;
  12121. }
  12122. function normalize(a, b) {
  12123. return (b -= (a = +a))
  12124. ? function(x) { return (x - a) / b; }
  12125. : constants(isNaN(b) ? NaN : 0.5);
  12126. }
  12127. function clamper(a, b) {
  12128. var t;
  12129. if (a > b) t = a, a = b, b = t;
  12130. return function(x) { return Math.max(a, Math.min(b, x)); };
  12131. }
  12132. // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  12133. // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
  12134. function bimap(domain, range, interpolate) {
  12135. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  12136. if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
  12137. else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
  12138. return function(x) { return r0(d0(x)); };
  12139. }
  12140. function polymap(domain, range, interpolate) {
  12141. var j = Math.min(domain.length, range.length) - 1,
  12142. d = new Array(j),
  12143. r = new Array(j),
  12144. i = -1;
  12145. // Reverse descending domains.
  12146. if (domain[j] < domain[0]) {
  12147. domain = domain.slice().reverse();
  12148. range = range.slice().reverse();
  12149. }
  12150. while (++i < j) {
  12151. d[i] = normalize(domain[i], domain[i + 1]);
  12152. r[i] = interpolate(range[i], range[i + 1]);
  12153. }
  12154. return function(x) {
  12155. var i = bisectRight(domain, x, 1, j) - 1;
  12156. return r[i](d[i](x));
  12157. };
  12158. }
  12159. function copy(source, target) {
  12160. return target
  12161. .domain(source.domain())
  12162. .range(source.range())
  12163. .interpolate(source.interpolate())
  12164. .clamp(source.clamp())
  12165. .unknown(source.unknown());
  12166. }
  12167. function transformer$1() {
  12168. var domain = unit,
  12169. range = unit,
  12170. interpolate$1 = interpolate,
  12171. transform,
  12172. untransform,
  12173. unknown,
  12174. clamp = identity$6,
  12175. piecewise,
  12176. output,
  12177. input;
  12178. function rescale() {
  12179. var n = Math.min(domain.length, range.length);
  12180. if (clamp !== identity$6) clamp = clamper(domain[0], domain[n - 1]);
  12181. piecewise = n > 2 ? polymap : bimap;
  12182. output = input = null;
  12183. return scale;
  12184. }
  12185. function scale(x) {
  12186. return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate$1)))(transform(clamp(x)));
  12187. }
  12188. scale.invert = function(y) {
  12189. return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
  12190. };
  12191. scale.domain = function(_) {
  12192. return arguments.length ? (domain = Array.from(_, number$2), rescale()) : domain.slice();
  12193. };
  12194. scale.range = function(_) {
  12195. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  12196. };
  12197. scale.rangeRound = function(_) {
  12198. return range = Array.from(_), interpolate$1 = interpolateRound, rescale();
  12199. };
  12200. scale.clamp = function(_) {
  12201. return arguments.length ? (clamp = _ ? true : identity$6, rescale()) : clamp !== identity$6;
  12202. };
  12203. scale.interpolate = function(_) {
  12204. return arguments.length ? (interpolate$1 = _, rescale()) : interpolate$1;
  12205. };
  12206. scale.unknown = function(_) {
  12207. return arguments.length ? (unknown = _, scale) : unknown;
  12208. };
  12209. return function(t, u) {
  12210. transform = t, untransform = u;
  12211. return rescale();
  12212. };
  12213. }
  12214. function continuous() {
  12215. return transformer$1()(identity$6, identity$6);
  12216. }
  12217. function tickFormat(start, stop, count, specifier) {
  12218. var step = tickStep(start, stop, count),
  12219. precision;
  12220. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  12221. switch (specifier.type) {
  12222. case "s": {
  12223. var value = Math.max(Math.abs(start), Math.abs(stop));
  12224. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  12225. return exports.formatPrefix(specifier, value);
  12226. }
  12227. case "":
  12228. case "e":
  12229. case "g":
  12230. case "p":
  12231. case "r": {
  12232. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  12233. break;
  12234. }
  12235. case "f":
  12236. case "%": {
  12237. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  12238. break;
  12239. }
  12240. }
  12241. return exports.format(specifier);
  12242. }
  12243. function linearish(scale) {
  12244. var domain = scale.domain;
  12245. scale.ticks = function(count) {
  12246. var d = domain();
  12247. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  12248. };
  12249. scale.tickFormat = function(count, specifier) {
  12250. var d = domain();
  12251. return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
  12252. };
  12253. scale.nice = function(count) {
  12254. if (count == null) count = 10;
  12255. var d = domain();
  12256. var i0 = 0;
  12257. var i1 = d.length - 1;
  12258. var start = d[i0];
  12259. var stop = d[i1];
  12260. var prestep;
  12261. var step;
  12262. var maxIter = 10;
  12263. if (stop < start) {
  12264. step = start, start = stop, stop = step;
  12265. step = i0, i0 = i1, i1 = step;
  12266. }
  12267. while (maxIter-- > 0) {
  12268. step = tickIncrement(start, stop, count);
  12269. if (step === prestep) {
  12270. d[i0] = start;
  12271. d[i1] = stop;
  12272. return domain(d);
  12273. } else if (step > 0) {
  12274. start = Math.floor(start / step) * step;
  12275. stop = Math.ceil(stop / step) * step;
  12276. } else if (step < 0) {
  12277. start = Math.ceil(start * step) / step;
  12278. stop = Math.floor(stop * step) / step;
  12279. } else {
  12280. break;
  12281. }
  12282. prestep = step;
  12283. }
  12284. return scale;
  12285. };
  12286. return scale;
  12287. }
  12288. function linear$2() {
  12289. var scale = continuous();
  12290. scale.copy = function() {
  12291. return copy(scale, linear$2());
  12292. };
  12293. initRange.apply(scale, arguments);
  12294. return linearish(scale);
  12295. }
  12296. function identity$7(domain) {
  12297. var unknown;
  12298. function scale(x) {
  12299. return isNaN(x = +x) ? unknown : x;
  12300. }
  12301. scale.invert = scale;
  12302. scale.domain = scale.range = function(_) {
  12303. return arguments.length ? (domain = Array.from(_, number$2), scale) : domain.slice();
  12304. };
  12305. scale.unknown = function(_) {
  12306. return arguments.length ? (unknown = _, scale) : unknown;
  12307. };
  12308. scale.copy = function() {
  12309. return identity$7(domain).unknown(unknown);
  12310. };
  12311. domain = arguments.length ? Array.from(domain, number$2) : [0, 1];
  12312. return linearish(scale);
  12313. }
  12314. function nice$1(domain, interval) {
  12315. domain = domain.slice();
  12316. var i0 = 0,
  12317. i1 = domain.length - 1,
  12318. x0 = domain[i0],
  12319. x1 = domain[i1],
  12320. t;
  12321. if (x1 < x0) {
  12322. t = i0, i0 = i1, i1 = t;
  12323. t = x0, x0 = x1, x1 = t;
  12324. }
  12325. domain[i0] = interval.floor(x0);
  12326. domain[i1] = interval.ceil(x1);
  12327. return domain;
  12328. }
  12329. function transformLog(x) {
  12330. return Math.log(x);
  12331. }
  12332. function transformExp(x) {
  12333. return Math.exp(x);
  12334. }
  12335. function transformLogn(x) {
  12336. return -Math.log(-x);
  12337. }
  12338. function transformExpn(x) {
  12339. return -Math.exp(-x);
  12340. }
  12341. function pow10(x) {
  12342. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  12343. }
  12344. function powp(base) {
  12345. return base === 10 ? pow10
  12346. : base === Math.E ? Math.exp
  12347. : function(x) { return Math.pow(base, x); };
  12348. }
  12349. function logp(base) {
  12350. return base === Math.E ? Math.log
  12351. : base === 10 && Math.log10
  12352. || base === 2 && Math.log2
  12353. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  12354. }
  12355. function reflect(f) {
  12356. return function(x) {
  12357. return -f(-x);
  12358. };
  12359. }
  12360. function loggish(transform) {
  12361. var scale = transform(transformLog, transformExp),
  12362. domain = scale.domain,
  12363. base = 10,
  12364. logs,
  12365. pows;
  12366. function rescale() {
  12367. logs = logp(base), pows = powp(base);
  12368. if (domain()[0] < 0) {
  12369. logs = reflect(logs), pows = reflect(pows);
  12370. transform(transformLogn, transformExpn);
  12371. } else {
  12372. transform(transformLog, transformExp);
  12373. }
  12374. return scale;
  12375. }
  12376. scale.base = function(_) {
  12377. return arguments.length ? (base = +_, rescale()) : base;
  12378. };
  12379. scale.domain = function(_) {
  12380. return arguments.length ? (domain(_), rescale()) : domain();
  12381. };
  12382. scale.ticks = function(count) {
  12383. var d = domain(),
  12384. u = d[0],
  12385. v = d[d.length - 1],
  12386. r;
  12387. if (r = v < u) i = u, u = v, v = i;
  12388. var i = logs(u),
  12389. j = logs(v),
  12390. p,
  12391. k,
  12392. t,
  12393. n = count == null ? 10 : +count,
  12394. z = [];
  12395. if (!(base % 1) && j - i < n) {
  12396. i = Math.floor(i), j = Math.ceil(j);
  12397. if (u > 0) for (; i <= j; ++i) {
  12398. for (k = 1, p = pows(i); k < base; ++k) {
  12399. t = p * k;
  12400. if (t < u) continue;
  12401. if (t > v) break;
  12402. z.push(t);
  12403. }
  12404. } else for (; i <= j; ++i) {
  12405. for (k = base - 1, p = pows(i); k >= 1; --k) {
  12406. t = p * k;
  12407. if (t < u) continue;
  12408. if (t > v) break;
  12409. z.push(t);
  12410. }
  12411. }
  12412. if (z.length * 2 < n) z = ticks(u, v, n);
  12413. } else {
  12414. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  12415. }
  12416. return r ? z.reverse() : z;
  12417. };
  12418. scale.tickFormat = function(count, specifier) {
  12419. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  12420. if (typeof specifier !== "function") specifier = exports.format(specifier);
  12421. if (count === Infinity) return specifier;
  12422. if (count == null) count = 10;
  12423. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  12424. return function(d) {
  12425. var i = d / pows(Math.round(logs(d)));
  12426. if (i * base < base - 0.5) i *= base;
  12427. return i <= k ? specifier(d) : "";
  12428. };
  12429. };
  12430. scale.nice = function() {
  12431. return domain(nice$1(domain(), {
  12432. floor: function(x) { return pows(Math.floor(logs(x))); },
  12433. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  12434. }));
  12435. };
  12436. return scale;
  12437. }
  12438. function log$1() {
  12439. var scale = loggish(transformer$1()).domain([1, 10]);
  12440. scale.copy = function() {
  12441. return copy(scale, log$1()).base(scale.base());
  12442. };
  12443. initRange.apply(scale, arguments);
  12444. return scale;
  12445. }
  12446. function transformSymlog(c) {
  12447. return function(x) {
  12448. return Math.sign(x) * Math.log1p(Math.abs(x / c));
  12449. };
  12450. }
  12451. function transformSymexp(c) {
  12452. return function(x) {
  12453. return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
  12454. };
  12455. }
  12456. function symlogish(transform) {
  12457. var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
  12458. scale.constant = function(_) {
  12459. return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
  12460. };
  12461. return linearish(scale);
  12462. }
  12463. function symlog() {
  12464. var scale = symlogish(transformer$1());
  12465. scale.copy = function() {
  12466. return copy(scale, symlog()).constant(scale.constant());
  12467. };
  12468. return initRange.apply(scale, arguments);
  12469. }
  12470. function transformPow(exponent) {
  12471. return function(x) {
  12472. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  12473. };
  12474. }
  12475. function transformSqrt(x) {
  12476. return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
  12477. }
  12478. function transformSquare(x) {
  12479. return x < 0 ? -x * x : x * x;
  12480. }
  12481. function powish(transform) {
  12482. var scale = transform(identity$6, identity$6),
  12483. exponent = 1;
  12484. function rescale() {
  12485. return exponent === 1 ? transform(identity$6, identity$6)
  12486. : exponent === 0.5 ? transform(transformSqrt, transformSquare)
  12487. : transform(transformPow(exponent), transformPow(1 / exponent));
  12488. }
  12489. scale.exponent = function(_) {
  12490. return arguments.length ? (exponent = +_, rescale()) : exponent;
  12491. };
  12492. return linearish(scale);
  12493. }
  12494. function pow$2() {
  12495. var scale = powish(transformer$1());
  12496. scale.copy = function() {
  12497. return copy(scale, pow$2()).exponent(scale.exponent());
  12498. };
  12499. initRange.apply(scale, arguments);
  12500. return scale;
  12501. }
  12502. function sqrt$1() {
  12503. return pow$2.apply(null, arguments).exponent(0.5);
  12504. }
  12505. function square(x) {
  12506. return Math.sign(x) * x * x;
  12507. }
  12508. function unsquare(x) {
  12509. return Math.sign(x) * Math.sqrt(Math.abs(x));
  12510. }
  12511. function radial$1() {
  12512. var squared = continuous(),
  12513. range = [0, 1],
  12514. round = false,
  12515. unknown;
  12516. function scale(x) {
  12517. var y = unsquare(squared(x));
  12518. return isNaN(y) ? unknown : round ? Math.round(y) : y;
  12519. }
  12520. scale.invert = function(y) {
  12521. return squared.invert(square(y));
  12522. };
  12523. scale.domain = function(_) {
  12524. return arguments.length ? (squared.domain(_), scale) : squared.domain();
  12525. };
  12526. scale.range = function(_) {
  12527. return arguments.length ? (squared.range((range = Array.from(_, number$2)).map(square)), scale) : range.slice();
  12528. };
  12529. scale.rangeRound = function(_) {
  12530. return scale.range(_).round(true);
  12531. };
  12532. scale.round = function(_) {
  12533. return arguments.length ? (round = !!_, scale) : round;
  12534. };
  12535. scale.clamp = function(_) {
  12536. return arguments.length ? (squared.clamp(_), scale) : squared.clamp();
  12537. };
  12538. scale.unknown = function(_) {
  12539. return arguments.length ? (unknown = _, scale) : unknown;
  12540. };
  12541. scale.copy = function() {
  12542. return radial$1(squared.domain(), range)
  12543. .round(round)
  12544. .clamp(squared.clamp())
  12545. .unknown(unknown);
  12546. };
  12547. initRange.apply(scale, arguments);
  12548. return linearish(scale);
  12549. }
  12550. function quantile$1() {
  12551. var domain = [],
  12552. range = [],
  12553. thresholds = [],
  12554. unknown;
  12555. function rescale() {
  12556. var i = 0, n = Math.max(1, range.length);
  12557. thresholds = new Array(n - 1);
  12558. while (++i < n) thresholds[i - 1] = quantileSorted(domain, i / n);
  12559. return scale;
  12560. }
  12561. function scale(x) {
  12562. return isNaN(x = +x) ? unknown : range[bisectRight(thresholds, x)];
  12563. }
  12564. scale.invertExtent = function(y) {
  12565. var i = range.indexOf(y);
  12566. return i < 0 ? [NaN, NaN] : [
  12567. i > 0 ? thresholds[i - 1] : domain[0],
  12568. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  12569. ];
  12570. };
  12571. scale.domain = function(_) {
  12572. if (!arguments.length) return domain.slice();
  12573. domain = [];
  12574. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  12575. domain.sort(ascending);
  12576. return rescale();
  12577. };
  12578. scale.range = function(_) {
  12579. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  12580. };
  12581. scale.unknown = function(_) {
  12582. return arguments.length ? (unknown = _, scale) : unknown;
  12583. };
  12584. scale.quantiles = function() {
  12585. return thresholds.slice();
  12586. };
  12587. scale.copy = function() {
  12588. return quantile$1()
  12589. .domain(domain)
  12590. .range(range)
  12591. .unknown(unknown);
  12592. };
  12593. return initRange.apply(scale, arguments);
  12594. }
  12595. function quantize$1() {
  12596. var x0 = 0,
  12597. x1 = 1,
  12598. n = 1,
  12599. domain = [0.5],
  12600. range = [0, 1],
  12601. unknown;
  12602. function scale(x) {
  12603. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  12604. }
  12605. function rescale() {
  12606. var i = -1;
  12607. domain = new Array(n);
  12608. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  12609. return scale;
  12610. }
  12611. scale.domain = function(_) {
  12612. return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
  12613. };
  12614. scale.range = function(_) {
  12615. return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
  12616. };
  12617. scale.invertExtent = function(y) {
  12618. var i = range.indexOf(y);
  12619. return i < 0 ? [NaN, NaN]
  12620. : i < 1 ? [x0, domain[0]]
  12621. : i >= n ? [domain[n - 1], x1]
  12622. : [domain[i - 1], domain[i]];
  12623. };
  12624. scale.unknown = function(_) {
  12625. return arguments.length ? (unknown = _, scale) : scale;
  12626. };
  12627. scale.thresholds = function() {
  12628. return domain.slice();
  12629. };
  12630. scale.copy = function() {
  12631. return quantize$1()
  12632. .domain([x0, x1])
  12633. .range(range)
  12634. .unknown(unknown);
  12635. };
  12636. return initRange.apply(linearish(scale), arguments);
  12637. }
  12638. function threshold() {
  12639. var domain = [0.5],
  12640. range = [0, 1],
  12641. unknown,
  12642. n = 1;
  12643. function scale(x) {
  12644. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  12645. }
  12646. scale.domain = function(_) {
  12647. return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  12648. };
  12649. scale.range = function(_) {
  12650. return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  12651. };
  12652. scale.invertExtent = function(y) {
  12653. var i = range.indexOf(y);
  12654. return [domain[i - 1], domain[i]];
  12655. };
  12656. scale.unknown = function(_) {
  12657. return arguments.length ? (unknown = _, scale) : unknown;
  12658. };
  12659. scale.copy = function() {
  12660. return threshold()
  12661. .domain(domain)
  12662. .range(range)
  12663. .unknown(unknown);
  12664. };
  12665. return initRange.apply(scale, arguments);
  12666. }
  12667. var t0$1 = new Date,
  12668. t1$1 = new Date;
  12669. function newInterval(floori, offseti, count, field) {
  12670. function interval(date) {
  12671. return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
  12672. }
  12673. interval.floor = function(date) {
  12674. return floori(date = new Date(+date)), date;
  12675. };
  12676. interval.ceil = function(date) {
  12677. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  12678. };
  12679. interval.round = function(date) {
  12680. var d0 = interval(date),
  12681. d1 = interval.ceil(date);
  12682. return date - d0 < d1 - date ? d0 : d1;
  12683. };
  12684. interval.offset = function(date, step) {
  12685. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  12686. };
  12687. interval.range = function(start, stop, step) {
  12688. var range = [], previous;
  12689. start = interval.ceil(start);
  12690. step = step == null ? 1 : Math.floor(step);
  12691. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  12692. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  12693. while (previous < start && start < stop);
  12694. return range;
  12695. };
  12696. interval.filter = function(test) {
  12697. return newInterval(function(date) {
  12698. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  12699. }, function(date, step) {
  12700. if (date >= date) {
  12701. if (step < 0) while (++step <= 0) {
  12702. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  12703. } else while (--step >= 0) {
  12704. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  12705. }
  12706. }
  12707. });
  12708. };
  12709. if (count) {
  12710. interval.count = function(start, end) {
  12711. t0$1.setTime(+start), t1$1.setTime(+end);
  12712. floori(t0$1), floori(t1$1);
  12713. return Math.floor(count(t0$1, t1$1));
  12714. };
  12715. interval.every = function(step) {
  12716. step = Math.floor(step);
  12717. return !isFinite(step) || !(step > 0) ? null
  12718. : !(step > 1) ? interval
  12719. : interval.filter(field
  12720. ? function(d) { return field(d) % step === 0; }
  12721. : function(d) { return interval.count(0, d) % step === 0; });
  12722. };
  12723. }
  12724. return interval;
  12725. }
  12726. var millisecond = newInterval(function() {
  12727. // noop
  12728. }, function(date, step) {
  12729. date.setTime(+date + step);
  12730. }, function(start, end) {
  12731. return end - start;
  12732. });
  12733. // An optimized implementation for this simple case.
  12734. millisecond.every = function(k) {
  12735. k = Math.floor(k);
  12736. if (!isFinite(k) || !(k > 0)) return null;
  12737. if (!(k > 1)) return millisecond;
  12738. return newInterval(function(date) {
  12739. date.setTime(Math.floor(date / k) * k);
  12740. }, function(date, step) {
  12741. date.setTime(+date + step * k);
  12742. }, function(start, end) {
  12743. return (end - start) / k;
  12744. });
  12745. };
  12746. var milliseconds = millisecond.range;
  12747. var durationSecond = 1e3;
  12748. var durationMinute = 6e4;
  12749. var durationHour = 36e5;
  12750. var durationDay = 864e5;
  12751. var durationWeek = 6048e5;
  12752. var second = newInterval(function(date) {
  12753. date.setTime(date - date.getMilliseconds());
  12754. }, function(date, step) {
  12755. date.setTime(+date + step * durationSecond);
  12756. }, function(start, end) {
  12757. return (end - start) / durationSecond;
  12758. }, function(date) {
  12759. return date.getUTCSeconds();
  12760. });
  12761. var seconds = second.range;
  12762. var minute = newInterval(function(date) {
  12763. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
  12764. }, function(date, step) {
  12765. date.setTime(+date + step * durationMinute);
  12766. }, function(start, end) {
  12767. return (end - start) / durationMinute;
  12768. }, function(date) {
  12769. return date.getMinutes();
  12770. });
  12771. var minutes = minute.range;
  12772. var hour = newInterval(function(date) {
  12773. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
  12774. }, function(date, step) {
  12775. date.setTime(+date + step * durationHour);
  12776. }, function(start, end) {
  12777. return (end - start) / durationHour;
  12778. }, function(date) {
  12779. return date.getHours();
  12780. });
  12781. var hours = hour.range;
  12782. var day = newInterval(
  12783. date => date.setHours(0, 0, 0, 0),
  12784. (date, step) => date.setDate(date.getDate() + step),
  12785. (start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay,
  12786. date => date.getDate() - 1
  12787. );
  12788. var days = day.range;
  12789. function weekday(i) {
  12790. return newInterval(function(date) {
  12791. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  12792. date.setHours(0, 0, 0, 0);
  12793. }, function(date, step) {
  12794. date.setDate(date.getDate() + step * 7);
  12795. }, function(start, end) {
  12796. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  12797. });
  12798. }
  12799. var sunday = weekday(0);
  12800. var monday = weekday(1);
  12801. var tuesday = weekday(2);
  12802. var wednesday = weekday(3);
  12803. var thursday = weekday(4);
  12804. var friday = weekday(5);
  12805. var saturday = weekday(6);
  12806. var sundays = sunday.range;
  12807. var mondays = monday.range;
  12808. var tuesdays = tuesday.range;
  12809. var wednesdays = wednesday.range;
  12810. var thursdays = thursday.range;
  12811. var fridays = friday.range;
  12812. var saturdays = saturday.range;
  12813. var month = newInterval(function(date) {
  12814. date.setDate(1);
  12815. date.setHours(0, 0, 0, 0);
  12816. }, function(date, step) {
  12817. date.setMonth(date.getMonth() + step);
  12818. }, function(start, end) {
  12819. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  12820. }, function(date) {
  12821. return date.getMonth();
  12822. });
  12823. var months = month.range;
  12824. var year = newInterval(function(date) {
  12825. date.setMonth(0, 1);
  12826. date.setHours(0, 0, 0, 0);
  12827. }, function(date, step) {
  12828. date.setFullYear(date.getFullYear() + step);
  12829. }, function(start, end) {
  12830. return end.getFullYear() - start.getFullYear();
  12831. }, function(date) {
  12832. return date.getFullYear();
  12833. });
  12834. // An optimized implementation for this simple case.
  12835. year.every = function(k) {
  12836. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  12837. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  12838. date.setMonth(0, 1);
  12839. date.setHours(0, 0, 0, 0);
  12840. }, function(date, step) {
  12841. date.setFullYear(date.getFullYear() + step * k);
  12842. });
  12843. };
  12844. var years = year.range;
  12845. var utcMinute = newInterval(function(date) {
  12846. date.setUTCSeconds(0, 0);
  12847. }, function(date, step) {
  12848. date.setTime(+date + step * durationMinute);
  12849. }, function(start, end) {
  12850. return (end - start) / durationMinute;
  12851. }, function(date) {
  12852. return date.getUTCMinutes();
  12853. });
  12854. var utcMinutes = utcMinute.range;
  12855. var utcHour = newInterval(function(date) {
  12856. date.setUTCMinutes(0, 0, 0);
  12857. }, function(date, step) {
  12858. date.setTime(+date + step * durationHour);
  12859. }, function(start, end) {
  12860. return (end - start) / durationHour;
  12861. }, function(date) {
  12862. return date.getUTCHours();
  12863. });
  12864. var utcHours = utcHour.range;
  12865. var utcDay = newInterval(function(date) {
  12866. date.setUTCHours(0, 0, 0, 0);
  12867. }, function(date, step) {
  12868. date.setUTCDate(date.getUTCDate() + step);
  12869. }, function(start, end) {
  12870. return (end - start) / durationDay;
  12871. }, function(date) {
  12872. return date.getUTCDate() - 1;
  12873. });
  12874. var utcDays = utcDay.range;
  12875. function utcWeekday(i) {
  12876. return newInterval(function(date) {
  12877. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  12878. date.setUTCHours(0, 0, 0, 0);
  12879. }, function(date, step) {
  12880. date.setUTCDate(date.getUTCDate() + step * 7);
  12881. }, function(start, end) {
  12882. return (end - start) / durationWeek;
  12883. });
  12884. }
  12885. var utcSunday = utcWeekday(0);
  12886. var utcMonday = utcWeekday(1);
  12887. var utcTuesday = utcWeekday(2);
  12888. var utcWednesday = utcWeekday(3);
  12889. var utcThursday = utcWeekday(4);
  12890. var utcFriday = utcWeekday(5);
  12891. var utcSaturday = utcWeekday(6);
  12892. var utcSundays = utcSunday.range;
  12893. var utcMondays = utcMonday.range;
  12894. var utcTuesdays = utcTuesday.range;
  12895. var utcWednesdays = utcWednesday.range;
  12896. var utcThursdays = utcThursday.range;
  12897. var utcFridays = utcFriday.range;
  12898. var utcSaturdays = utcSaturday.range;
  12899. var utcMonth = newInterval(function(date) {
  12900. date.setUTCDate(1);
  12901. date.setUTCHours(0, 0, 0, 0);
  12902. }, function(date, step) {
  12903. date.setUTCMonth(date.getUTCMonth() + step);
  12904. }, function(start, end) {
  12905. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  12906. }, function(date) {
  12907. return date.getUTCMonth();
  12908. });
  12909. var utcMonths = utcMonth.range;
  12910. var utcYear = newInterval(function(date) {
  12911. date.setUTCMonth(0, 1);
  12912. date.setUTCHours(0, 0, 0, 0);
  12913. }, function(date, step) {
  12914. date.setUTCFullYear(date.getUTCFullYear() + step);
  12915. }, function(start, end) {
  12916. return end.getUTCFullYear() - start.getUTCFullYear();
  12917. }, function(date) {
  12918. return date.getUTCFullYear();
  12919. });
  12920. // An optimized implementation for this simple case.
  12921. utcYear.every = function(k) {
  12922. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  12923. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  12924. date.setUTCMonth(0, 1);
  12925. date.setUTCHours(0, 0, 0, 0);
  12926. }, function(date, step) {
  12927. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  12928. });
  12929. };
  12930. var utcYears = utcYear.range;
  12931. function localDate(d) {
  12932. if (0 <= d.y && d.y < 100) {
  12933. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  12934. date.setFullYear(d.y);
  12935. return date;
  12936. }
  12937. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  12938. }
  12939. function utcDate(d) {
  12940. if (0 <= d.y && d.y < 100) {
  12941. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  12942. date.setUTCFullYear(d.y);
  12943. return date;
  12944. }
  12945. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  12946. }
  12947. function newDate(y, m, d) {
  12948. return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
  12949. }
  12950. function formatLocale$1(locale) {
  12951. var locale_dateTime = locale.dateTime,
  12952. locale_date = locale.date,
  12953. locale_time = locale.time,
  12954. locale_periods = locale.periods,
  12955. locale_weekdays = locale.days,
  12956. locale_shortWeekdays = locale.shortDays,
  12957. locale_months = locale.months,
  12958. locale_shortMonths = locale.shortMonths;
  12959. var periodRe = formatRe(locale_periods),
  12960. periodLookup = formatLookup(locale_periods),
  12961. weekdayRe = formatRe(locale_weekdays),
  12962. weekdayLookup = formatLookup(locale_weekdays),
  12963. shortWeekdayRe = formatRe(locale_shortWeekdays),
  12964. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  12965. monthRe = formatRe(locale_months),
  12966. monthLookup = formatLookup(locale_months),
  12967. shortMonthRe = formatRe(locale_shortMonths),
  12968. shortMonthLookup = formatLookup(locale_shortMonths);
  12969. var formats = {
  12970. "a": formatShortWeekday,
  12971. "A": formatWeekday,
  12972. "b": formatShortMonth,
  12973. "B": formatMonth,
  12974. "c": null,
  12975. "d": formatDayOfMonth,
  12976. "e": formatDayOfMonth,
  12977. "f": formatMicroseconds,
  12978. "g": formatYearISO,
  12979. "G": formatFullYearISO,
  12980. "H": formatHour24,
  12981. "I": formatHour12,
  12982. "j": formatDayOfYear,
  12983. "L": formatMilliseconds,
  12984. "m": formatMonthNumber,
  12985. "M": formatMinutes,
  12986. "p": formatPeriod,
  12987. "q": formatQuarter,
  12988. "Q": formatUnixTimestamp,
  12989. "s": formatUnixTimestampSeconds,
  12990. "S": formatSeconds,
  12991. "u": formatWeekdayNumberMonday,
  12992. "U": formatWeekNumberSunday,
  12993. "V": formatWeekNumberISO,
  12994. "w": formatWeekdayNumberSunday,
  12995. "W": formatWeekNumberMonday,
  12996. "x": null,
  12997. "X": null,
  12998. "y": formatYear$1,
  12999. "Y": formatFullYear,
  13000. "Z": formatZone,
  13001. "%": formatLiteralPercent
  13002. };
  13003. var utcFormats = {
  13004. "a": formatUTCShortWeekday,
  13005. "A": formatUTCWeekday,
  13006. "b": formatUTCShortMonth,
  13007. "B": formatUTCMonth,
  13008. "c": null,
  13009. "d": formatUTCDayOfMonth,
  13010. "e": formatUTCDayOfMonth,
  13011. "f": formatUTCMicroseconds,
  13012. "g": formatUTCYearISO,
  13013. "G": formatUTCFullYearISO,
  13014. "H": formatUTCHour24,
  13015. "I": formatUTCHour12,
  13016. "j": formatUTCDayOfYear,
  13017. "L": formatUTCMilliseconds,
  13018. "m": formatUTCMonthNumber,
  13019. "M": formatUTCMinutes,
  13020. "p": formatUTCPeriod,
  13021. "q": formatUTCQuarter,
  13022. "Q": formatUnixTimestamp,
  13023. "s": formatUnixTimestampSeconds,
  13024. "S": formatUTCSeconds,
  13025. "u": formatUTCWeekdayNumberMonday,
  13026. "U": formatUTCWeekNumberSunday,
  13027. "V": formatUTCWeekNumberISO,
  13028. "w": formatUTCWeekdayNumberSunday,
  13029. "W": formatUTCWeekNumberMonday,
  13030. "x": null,
  13031. "X": null,
  13032. "y": formatUTCYear,
  13033. "Y": formatUTCFullYear,
  13034. "Z": formatUTCZone,
  13035. "%": formatLiteralPercent
  13036. };
  13037. var parses = {
  13038. "a": parseShortWeekday,
  13039. "A": parseWeekday,
  13040. "b": parseShortMonth,
  13041. "B": parseMonth,
  13042. "c": parseLocaleDateTime,
  13043. "d": parseDayOfMonth,
  13044. "e": parseDayOfMonth,
  13045. "f": parseMicroseconds,
  13046. "g": parseYear,
  13047. "G": parseFullYear,
  13048. "H": parseHour24,
  13049. "I": parseHour24,
  13050. "j": parseDayOfYear,
  13051. "L": parseMilliseconds,
  13052. "m": parseMonthNumber,
  13053. "M": parseMinutes,
  13054. "p": parsePeriod,
  13055. "q": parseQuarter,
  13056. "Q": parseUnixTimestamp,
  13057. "s": parseUnixTimestampSeconds,
  13058. "S": parseSeconds,
  13059. "u": parseWeekdayNumberMonday,
  13060. "U": parseWeekNumberSunday,
  13061. "V": parseWeekNumberISO,
  13062. "w": parseWeekdayNumberSunday,
  13063. "W": parseWeekNumberMonday,
  13064. "x": parseLocaleDate,
  13065. "X": parseLocaleTime,
  13066. "y": parseYear,
  13067. "Y": parseFullYear,
  13068. "Z": parseZone,
  13069. "%": parseLiteralPercent
  13070. };
  13071. // These recursive directive definitions must be deferred.
  13072. formats.x = newFormat(locale_date, formats);
  13073. formats.X = newFormat(locale_time, formats);
  13074. formats.c = newFormat(locale_dateTime, formats);
  13075. utcFormats.x = newFormat(locale_date, utcFormats);
  13076. utcFormats.X = newFormat(locale_time, utcFormats);
  13077. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  13078. function newFormat(specifier, formats) {
  13079. return function(date) {
  13080. var string = [],
  13081. i = -1,
  13082. j = 0,
  13083. n = specifier.length,
  13084. c,
  13085. pad,
  13086. format;
  13087. if (!(date instanceof Date)) date = new Date(+date);
  13088. while (++i < n) {
  13089. if (specifier.charCodeAt(i) === 37) {
  13090. string.push(specifier.slice(j, i));
  13091. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  13092. else pad = c === "e" ? " " : "0";
  13093. if (format = formats[c]) c = format(date, pad);
  13094. string.push(c);
  13095. j = i + 1;
  13096. }
  13097. }
  13098. string.push(specifier.slice(j, i));
  13099. return string.join("");
  13100. };
  13101. }
  13102. function newParse(specifier, Z) {
  13103. return function(string) {
  13104. var d = newDate(1900, undefined, 1),
  13105. i = parseSpecifier(d, specifier, string += "", 0),
  13106. week, day$1;
  13107. if (i != string.length) return null;
  13108. // If a UNIX timestamp is specified, return it.
  13109. if ("Q" in d) return new Date(d.Q);
  13110. if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
  13111. // If this is utcParse, never use the local timezone.
  13112. if (Z && !("Z" in d)) d.Z = 0;
  13113. // The am-pm flag is 0 for AM, and 1 for PM.
  13114. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  13115. // If the month was not specified, inherit from the quarter.
  13116. if (d.m === undefined) d.m = "q" in d ? d.q : 0;
  13117. // Convert day-of-week and week-of-year to day-of-year.
  13118. if ("V" in d) {
  13119. if (d.V < 1 || d.V > 53) return null;
  13120. if (!("w" in d)) d.w = 1;
  13121. if ("Z" in d) {
  13122. week = utcDate(newDate(d.y, 0, 1)), day$1 = week.getUTCDay();
  13123. week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  13124. week = utcDay.offset(week, (d.V - 1) * 7);
  13125. d.y = week.getUTCFullYear();
  13126. d.m = week.getUTCMonth();
  13127. d.d = week.getUTCDate() + (d.w + 6) % 7;
  13128. } else {
  13129. week = localDate(newDate(d.y, 0, 1)), day$1 = week.getDay();
  13130. week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
  13131. week = day.offset(week, (d.V - 1) * 7);
  13132. d.y = week.getFullYear();
  13133. d.m = week.getMonth();
  13134. d.d = week.getDate() + (d.w + 6) % 7;
  13135. }
  13136. } else if ("W" in d || "U" in d) {
  13137. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  13138. day$1 = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
  13139. d.m = 0;
  13140. d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$1 + 5) % 7 : d.w + d.U * 7 - (day$1 + 6) % 7;
  13141. }
  13142. // If a time zone is specified, all fields are interpreted as UTC and then
  13143. // offset according to the specified time zone.
  13144. if ("Z" in d) {
  13145. d.H += d.Z / 100 | 0;
  13146. d.M += d.Z % 100;
  13147. return utcDate(d);
  13148. }
  13149. // Otherwise, all fields are in local time.
  13150. return localDate(d);
  13151. };
  13152. }
  13153. function parseSpecifier(d, specifier, string, j) {
  13154. var i = 0,
  13155. n = specifier.length,
  13156. m = string.length,
  13157. c,
  13158. parse;
  13159. while (i < n) {
  13160. if (j >= m) return -1;
  13161. c = specifier.charCodeAt(i++);
  13162. if (c === 37) {
  13163. c = specifier.charAt(i++);
  13164. parse = parses[c in pads ? specifier.charAt(i++) : c];
  13165. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  13166. } else if (c != string.charCodeAt(j++)) {
  13167. return -1;
  13168. }
  13169. }
  13170. return j;
  13171. }
  13172. function parsePeriod(d, string, i) {
  13173. var n = periodRe.exec(string.slice(i));
  13174. return n ? (d.p = periodLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13175. }
  13176. function parseShortWeekday(d, string, i) {
  13177. var n = shortWeekdayRe.exec(string.slice(i));
  13178. return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13179. }
  13180. function parseWeekday(d, string, i) {
  13181. var n = weekdayRe.exec(string.slice(i));
  13182. return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13183. }
  13184. function parseShortMonth(d, string, i) {
  13185. var n = shortMonthRe.exec(string.slice(i));
  13186. return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13187. }
  13188. function parseMonth(d, string, i) {
  13189. var n = monthRe.exec(string.slice(i));
  13190. return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13191. }
  13192. function parseLocaleDateTime(d, string, i) {
  13193. return parseSpecifier(d, locale_dateTime, string, i);
  13194. }
  13195. function parseLocaleDate(d, string, i) {
  13196. return parseSpecifier(d, locale_date, string, i);
  13197. }
  13198. function parseLocaleTime(d, string, i) {
  13199. return parseSpecifier(d, locale_time, string, i);
  13200. }
  13201. function formatShortWeekday(d) {
  13202. return locale_shortWeekdays[d.getDay()];
  13203. }
  13204. function formatWeekday(d) {
  13205. return locale_weekdays[d.getDay()];
  13206. }
  13207. function formatShortMonth(d) {
  13208. return locale_shortMonths[d.getMonth()];
  13209. }
  13210. function formatMonth(d) {
  13211. return locale_months[d.getMonth()];
  13212. }
  13213. function formatPeriod(d) {
  13214. return locale_periods[+(d.getHours() >= 12)];
  13215. }
  13216. function formatQuarter(d) {
  13217. return 1 + ~~(d.getMonth() / 3);
  13218. }
  13219. function formatUTCShortWeekday(d) {
  13220. return locale_shortWeekdays[d.getUTCDay()];
  13221. }
  13222. function formatUTCWeekday(d) {
  13223. return locale_weekdays[d.getUTCDay()];
  13224. }
  13225. function formatUTCShortMonth(d) {
  13226. return locale_shortMonths[d.getUTCMonth()];
  13227. }
  13228. function formatUTCMonth(d) {
  13229. return locale_months[d.getUTCMonth()];
  13230. }
  13231. function formatUTCPeriod(d) {
  13232. return locale_periods[+(d.getUTCHours() >= 12)];
  13233. }
  13234. function formatUTCQuarter(d) {
  13235. return 1 + ~~(d.getUTCMonth() / 3);
  13236. }
  13237. return {
  13238. format: function(specifier) {
  13239. var f = newFormat(specifier += "", formats);
  13240. f.toString = function() { return specifier; };
  13241. return f;
  13242. },
  13243. parse: function(specifier) {
  13244. var p = newParse(specifier += "", false);
  13245. p.toString = function() { return specifier; };
  13246. return p;
  13247. },
  13248. utcFormat: function(specifier) {
  13249. var f = newFormat(specifier += "", utcFormats);
  13250. f.toString = function() { return specifier; };
  13251. return f;
  13252. },
  13253. utcParse: function(specifier) {
  13254. var p = newParse(specifier += "", true);
  13255. p.toString = function() { return specifier; };
  13256. return p;
  13257. }
  13258. };
  13259. }
  13260. var pads = {"-": "", "_": " ", "0": "0"},
  13261. numberRe = /^\s*\d+/, // note: ignores next directive
  13262. percentRe = /^%/,
  13263. requoteRe = /[\\^$*+?|[\]().{}]/g;
  13264. function pad$1(value, fill, width) {
  13265. var sign = value < 0 ? "-" : "",
  13266. string = (sign ? -value : value) + "",
  13267. length = string.length;
  13268. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  13269. }
  13270. function requote(s) {
  13271. return s.replace(requoteRe, "\\$&");
  13272. }
  13273. function formatRe(names) {
  13274. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  13275. }
  13276. function formatLookup(names) {
  13277. return new Map(names.map((name, i) => [name.toLowerCase(), i]));
  13278. }
  13279. function parseWeekdayNumberSunday(d, string, i) {
  13280. var n = numberRe.exec(string.slice(i, i + 1));
  13281. return n ? (d.w = +n[0], i + n[0].length) : -1;
  13282. }
  13283. function parseWeekdayNumberMonday(d, string, i) {
  13284. var n = numberRe.exec(string.slice(i, i + 1));
  13285. return n ? (d.u = +n[0], i + n[0].length) : -1;
  13286. }
  13287. function parseWeekNumberSunday(d, string, i) {
  13288. var n = numberRe.exec(string.slice(i, i + 2));
  13289. return n ? (d.U = +n[0], i + n[0].length) : -1;
  13290. }
  13291. function parseWeekNumberISO(d, string, i) {
  13292. var n = numberRe.exec(string.slice(i, i + 2));
  13293. return n ? (d.V = +n[0], i + n[0].length) : -1;
  13294. }
  13295. function parseWeekNumberMonday(d, string, i) {
  13296. var n = numberRe.exec(string.slice(i, i + 2));
  13297. return n ? (d.W = +n[0], i + n[0].length) : -1;
  13298. }
  13299. function parseFullYear(d, string, i) {
  13300. var n = numberRe.exec(string.slice(i, i + 4));
  13301. return n ? (d.y = +n[0], i + n[0].length) : -1;
  13302. }
  13303. function parseYear(d, string, i) {
  13304. var n = numberRe.exec(string.slice(i, i + 2));
  13305. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  13306. }
  13307. function parseZone(d, string, i) {
  13308. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  13309. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  13310. }
  13311. function parseQuarter(d, string, i) {
  13312. var n = numberRe.exec(string.slice(i, i + 1));
  13313. return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
  13314. }
  13315. function parseMonthNumber(d, string, i) {
  13316. var n = numberRe.exec(string.slice(i, i + 2));
  13317. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  13318. }
  13319. function parseDayOfMonth(d, string, i) {
  13320. var n = numberRe.exec(string.slice(i, i + 2));
  13321. return n ? (d.d = +n[0], i + n[0].length) : -1;
  13322. }
  13323. function parseDayOfYear(d, string, i) {
  13324. var n = numberRe.exec(string.slice(i, i + 3));
  13325. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  13326. }
  13327. function parseHour24(d, string, i) {
  13328. var n = numberRe.exec(string.slice(i, i + 2));
  13329. return n ? (d.H = +n[0], i + n[0].length) : -1;
  13330. }
  13331. function parseMinutes(d, string, i) {
  13332. var n = numberRe.exec(string.slice(i, i + 2));
  13333. return n ? (d.M = +n[0], i + n[0].length) : -1;
  13334. }
  13335. function parseSeconds(d, string, i) {
  13336. var n = numberRe.exec(string.slice(i, i + 2));
  13337. return n ? (d.S = +n[0], i + n[0].length) : -1;
  13338. }
  13339. function parseMilliseconds(d, string, i) {
  13340. var n = numberRe.exec(string.slice(i, i + 3));
  13341. return n ? (d.L = +n[0], i + n[0].length) : -1;
  13342. }
  13343. function parseMicroseconds(d, string, i) {
  13344. var n = numberRe.exec(string.slice(i, i + 6));
  13345. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  13346. }
  13347. function parseLiteralPercent(d, string, i) {
  13348. var n = percentRe.exec(string.slice(i, i + 1));
  13349. return n ? i + n[0].length : -1;
  13350. }
  13351. function parseUnixTimestamp(d, string, i) {
  13352. var n = numberRe.exec(string.slice(i));
  13353. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  13354. }
  13355. function parseUnixTimestampSeconds(d, string, i) {
  13356. var n = numberRe.exec(string.slice(i));
  13357. return n ? (d.s = +n[0], i + n[0].length) : -1;
  13358. }
  13359. function formatDayOfMonth(d, p) {
  13360. return pad$1(d.getDate(), p, 2);
  13361. }
  13362. function formatHour24(d, p) {
  13363. return pad$1(d.getHours(), p, 2);
  13364. }
  13365. function formatHour12(d, p) {
  13366. return pad$1(d.getHours() % 12 || 12, p, 2);
  13367. }
  13368. function formatDayOfYear(d, p) {
  13369. return pad$1(1 + day.count(year(d), d), p, 3);
  13370. }
  13371. function formatMilliseconds(d, p) {
  13372. return pad$1(d.getMilliseconds(), p, 3);
  13373. }
  13374. function formatMicroseconds(d, p) {
  13375. return formatMilliseconds(d, p) + "000";
  13376. }
  13377. function formatMonthNumber(d, p) {
  13378. return pad$1(d.getMonth() + 1, p, 2);
  13379. }
  13380. function formatMinutes(d, p) {
  13381. return pad$1(d.getMinutes(), p, 2);
  13382. }
  13383. function formatSeconds(d, p) {
  13384. return pad$1(d.getSeconds(), p, 2);
  13385. }
  13386. function formatWeekdayNumberMonday(d) {
  13387. var day = d.getDay();
  13388. return day === 0 ? 7 : day;
  13389. }
  13390. function formatWeekNumberSunday(d, p) {
  13391. return pad$1(sunday.count(year(d) - 1, d), p, 2);
  13392. }
  13393. function dISO(d) {
  13394. var day = d.getDay();
  13395. return (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
  13396. }
  13397. function formatWeekNumberISO(d, p) {
  13398. d = dISO(d);
  13399. return pad$1(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  13400. }
  13401. function formatWeekdayNumberSunday(d) {
  13402. return d.getDay();
  13403. }
  13404. function formatWeekNumberMonday(d, p) {
  13405. return pad$1(monday.count(year(d) - 1, d), p, 2);
  13406. }
  13407. function formatYear$1(d, p) {
  13408. return pad$1(d.getFullYear() % 100, p, 2);
  13409. }
  13410. function formatYearISO(d, p) {
  13411. d = dISO(d);
  13412. return pad$1(d.getFullYear() % 100, p, 2);
  13413. }
  13414. function formatFullYear(d, p) {
  13415. return pad$1(d.getFullYear() % 10000, p, 4);
  13416. }
  13417. function formatFullYearISO(d, p) {
  13418. var day = d.getDay();
  13419. d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
  13420. return pad$1(d.getFullYear() % 10000, p, 4);
  13421. }
  13422. function formatZone(d) {
  13423. var z = d.getTimezoneOffset();
  13424. return (z > 0 ? "-" : (z *= -1, "+"))
  13425. + pad$1(z / 60 | 0, "0", 2)
  13426. + pad$1(z % 60, "0", 2);
  13427. }
  13428. function formatUTCDayOfMonth(d, p) {
  13429. return pad$1(d.getUTCDate(), p, 2);
  13430. }
  13431. function formatUTCHour24(d, p) {
  13432. return pad$1(d.getUTCHours(), p, 2);
  13433. }
  13434. function formatUTCHour12(d, p) {
  13435. return pad$1(d.getUTCHours() % 12 || 12, p, 2);
  13436. }
  13437. function formatUTCDayOfYear(d, p) {
  13438. return pad$1(1 + utcDay.count(utcYear(d), d), p, 3);
  13439. }
  13440. function formatUTCMilliseconds(d, p) {
  13441. return pad$1(d.getUTCMilliseconds(), p, 3);
  13442. }
  13443. function formatUTCMicroseconds(d, p) {
  13444. return formatUTCMilliseconds(d, p) + "000";
  13445. }
  13446. function formatUTCMonthNumber(d, p) {
  13447. return pad$1(d.getUTCMonth() + 1, p, 2);
  13448. }
  13449. function formatUTCMinutes(d, p) {
  13450. return pad$1(d.getUTCMinutes(), p, 2);
  13451. }
  13452. function formatUTCSeconds(d, p) {
  13453. return pad$1(d.getUTCSeconds(), p, 2);
  13454. }
  13455. function formatUTCWeekdayNumberMonday(d) {
  13456. var dow = d.getUTCDay();
  13457. return dow === 0 ? 7 : dow;
  13458. }
  13459. function formatUTCWeekNumberSunday(d, p) {
  13460. return pad$1(utcSunday.count(utcYear(d) - 1, d), p, 2);
  13461. }
  13462. function UTCdISO(d) {
  13463. var day = d.getUTCDay();
  13464. return (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  13465. }
  13466. function formatUTCWeekNumberISO(d, p) {
  13467. d = UTCdISO(d);
  13468. return pad$1(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  13469. }
  13470. function formatUTCWeekdayNumberSunday(d) {
  13471. return d.getUTCDay();
  13472. }
  13473. function formatUTCWeekNumberMonday(d, p) {
  13474. return pad$1(utcMonday.count(utcYear(d) - 1, d), p, 2);
  13475. }
  13476. function formatUTCYear(d, p) {
  13477. return pad$1(d.getUTCFullYear() % 100, p, 2);
  13478. }
  13479. function formatUTCYearISO(d, p) {
  13480. d = UTCdISO(d);
  13481. return pad$1(d.getUTCFullYear() % 100, p, 2);
  13482. }
  13483. function formatUTCFullYear(d, p) {
  13484. return pad$1(d.getUTCFullYear() % 10000, p, 4);
  13485. }
  13486. function formatUTCFullYearISO(d, p) {
  13487. var day = d.getUTCDay();
  13488. d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  13489. return pad$1(d.getUTCFullYear() % 10000, p, 4);
  13490. }
  13491. function formatUTCZone() {
  13492. return "+0000";
  13493. }
  13494. function formatLiteralPercent() {
  13495. return "%";
  13496. }
  13497. function formatUnixTimestamp(d) {
  13498. return +d;
  13499. }
  13500. function formatUnixTimestampSeconds(d) {
  13501. return Math.floor(+d / 1000);
  13502. }
  13503. var locale$1;
  13504. defaultLocale$1({
  13505. dateTime: "%x, %X",
  13506. date: "%-m/%-d/%Y",
  13507. time: "%-I:%M:%S %p",
  13508. periods: ["AM", "PM"],
  13509. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  13510. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  13511. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  13512. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  13513. });
  13514. function defaultLocale$1(definition) {
  13515. locale$1 = formatLocale$1(definition);
  13516. exports.timeFormat = locale$1.format;
  13517. exports.timeParse = locale$1.parse;
  13518. exports.utcFormat = locale$1.utcFormat;
  13519. exports.utcParse = locale$1.utcParse;
  13520. return locale$1;
  13521. }
  13522. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  13523. function formatIsoNative(date) {
  13524. return date.toISOString();
  13525. }
  13526. var formatIso = Date.prototype.toISOString
  13527. ? formatIsoNative
  13528. : exports.utcFormat(isoSpecifier);
  13529. function parseIsoNative(string) {
  13530. var date = new Date(string);
  13531. return isNaN(date) ? null : date;
  13532. }
  13533. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  13534. ? parseIsoNative
  13535. : exports.utcParse(isoSpecifier);
  13536. var durationSecond$1 = 1000,
  13537. durationMinute$1 = durationSecond$1 * 60,
  13538. durationHour$1 = durationMinute$1 * 60,
  13539. durationDay$1 = durationHour$1 * 24,
  13540. durationWeek$1 = durationDay$1 * 7,
  13541. durationMonth = durationDay$1 * 30,
  13542. durationYear = durationDay$1 * 365;
  13543. function date$1(t) {
  13544. return new Date(t);
  13545. }
  13546. function number$3(t) {
  13547. return t instanceof Date ? +t : +new Date(+t);
  13548. }
  13549. function calendar(year, month, week, day, hour, minute, second, millisecond, format) {
  13550. var scale = continuous(),
  13551. invert = scale.invert,
  13552. domain = scale.domain;
  13553. var formatMillisecond = format(".%L"),
  13554. formatSecond = format(":%S"),
  13555. formatMinute = format("%I:%M"),
  13556. formatHour = format("%I %p"),
  13557. formatDay = format("%a %d"),
  13558. formatWeek = format("%b %d"),
  13559. formatMonth = format("%B"),
  13560. formatYear = format("%Y");
  13561. var tickIntervals = [
  13562. [second, 1, durationSecond$1],
  13563. [second, 5, 5 * durationSecond$1],
  13564. [second, 15, 15 * durationSecond$1],
  13565. [second, 30, 30 * durationSecond$1],
  13566. [minute, 1, durationMinute$1],
  13567. [minute, 5, 5 * durationMinute$1],
  13568. [minute, 15, 15 * durationMinute$1],
  13569. [minute, 30, 30 * durationMinute$1],
  13570. [ hour, 1, durationHour$1 ],
  13571. [ hour, 3, 3 * durationHour$1 ],
  13572. [ hour, 6, 6 * durationHour$1 ],
  13573. [ hour, 12, 12 * durationHour$1 ],
  13574. [ day, 1, durationDay$1 ],
  13575. [ day, 2, 2 * durationDay$1 ],
  13576. [ week, 1, durationWeek$1 ],
  13577. [ month, 1, durationMonth ],
  13578. [ month, 3, 3 * durationMonth ],
  13579. [ year, 1, durationYear ]
  13580. ];
  13581. function tickFormat(date) {
  13582. return (second(date) < date ? formatMillisecond
  13583. : minute(date) < date ? formatSecond
  13584. : hour(date) < date ? formatMinute
  13585. : day(date) < date ? formatHour
  13586. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  13587. : year(date) < date ? formatMonth
  13588. : formatYear)(date);
  13589. }
  13590. function tickInterval(interval, start, stop) {
  13591. if (interval == null) interval = 10;
  13592. // If a desired tick count is specified, pick a reasonable tick interval
  13593. // based on the extent of the domain and a rough estimate of tick size.
  13594. // Otherwise, assume interval is already a time interval and use it.
  13595. if (typeof interval === "number") {
  13596. var target = Math.abs(stop - start) / interval,
  13597. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target),
  13598. step;
  13599. if (i === tickIntervals.length) {
  13600. step = tickStep(start / durationYear, stop / durationYear, interval);
  13601. interval = year;
  13602. } else if (i) {
  13603. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  13604. step = i[1];
  13605. interval = i[0];
  13606. } else {
  13607. step = Math.max(tickStep(start, stop, interval), 1);
  13608. interval = millisecond;
  13609. }
  13610. return interval.every(step);
  13611. }
  13612. return interval;
  13613. }
  13614. scale.invert = function(y) {
  13615. return new Date(invert(y));
  13616. };
  13617. scale.domain = function(_) {
  13618. return arguments.length ? domain(Array.from(_, number$3)) : domain().map(date$1);
  13619. };
  13620. scale.ticks = function(interval) {
  13621. var d = domain(),
  13622. t0 = d[0],
  13623. t1 = d[d.length - 1],
  13624. r = t1 < t0,
  13625. t;
  13626. if (r) t = t0, t0 = t1, t1 = t;
  13627. t = tickInterval(interval, t0, t1);
  13628. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  13629. return r ? t.reverse() : t;
  13630. };
  13631. scale.tickFormat = function(count, specifier) {
  13632. return specifier == null ? tickFormat : format(specifier);
  13633. };
  13634. scale.nice = function(interval) {
  13635. var d = domain();
  13636. return (interval = tickInterval(interval, d[0], d[d.length - 1]))
  13637. ? domain(nice$1(d, interval))
  13638. : scale;
  13639. };
  13640. scale.copy = function() {
  13641. return copy(scale, calendar(year, month, week, day, hour, minute, second, millisecond, format));
  13642. };
  13643. return scale;
  13644. }
  13645. function time() {
  13646. return initRange.apply(calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
  13647. }
  13648. function utcTime() {
  13649. return initRange.apply(calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
  13650. }
  13651. function transformer$2() {
  13652. var x0 = 0,
  13653. x1 = 1,
  13654. t0,
  13655. t1,
  13656. k10,
  13657. transform,
  13658. interpolator = identity$6,
  13659. clamp = false,
  13660. unknown;
  13661. function scale(x) {
  13662. return isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
  13663. }
  13664. scale.domain = function(_) {
  13665. return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
  13666. };
  13667. scale.clamp = function(_) {
  13668. return arguments.length ? (clamp = !!_, scale) : clamp;
  13669. };
  13670. scale.interpolator = function(_) {
  13671. return arguments.length ? (interpolator = _, scale) : interpolator;
  13672. };
  13673. function range(interpolate) {
  13674. return function(_) {
  13675. var r0, r1;
  13676. return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)];
  13677. };
  13678. }
  13679. scale.range = range(interpolate);
  13680. scale.rangeRound = range(interpolateRound);
  13681. scale.unknown = function(_) {
  13682. return arguments.length ? (unknown = _, scale) : unknown;
  13683. };
  13684. return function(t) {
  13685. transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
  13686. return scale;
  13687. };
  13688. }
  13689. function copy$1(source, target) {
  13690. return target
  13691. .domain(source.domain())
  13692. .interpolator(source.interpolator())
  13693. .clamp(source.clamp())
  13694. .unknown(source.unknown());
  13695. }
  13696. function sequential() {
  13697. var scale = linearish(transformer$2()(identity$6));
  13698. scale.copy = function() {
  13699. return copy$1(scale, sequential());
  13700. };
  13701. return initInterpolator.apply(scale, arguments);
  13702. }
  13703. function sequentialLog() {
  13704. var scale = loggish(transformer$2()).domain([1, 10]);
  13705. scale.copy = function() {
  13706. return copy$1(scale, sequentialLog()).base(scale.base());
  13707. };
  13708. return initInterpolator.apply(scale, arguments);
  13709. }
  13710. function sequentialSymlog() {
  13711. var scale = symlogish(transformer$2());
  13712. scale.copy = function() {
  13713. return copy$1(scale, sequentialSymlog()).constant(scale.constant());
  13714. };
  13715. return initInterpolator.apply(scale, arguments);
  13716. }
  13717. function sequentialPow() {
  13718. var scale = powish(transformer$2());
  13719. scale.copy = function() {
  13720. return copy$1(scale, sequentialPow()).exponent(scale.exponent());
  13721. };
  13722. return initInterpolator.apply(scale, arguments);
  13723. }
  13724. function sequentialSqrt() {
  13725. return sequentialPow.apply(null, arguments).exponent(0.5);
  13726. }
  13727. function sequentialQuantile() {
  13728. var domain = [],
  13729. interpolator = identity$6;
  13730. function scale(x) {
  13731. if (!isNaN(x = +x)) return interpolator((bisectRight(domain, x, 1) - 1) / (domain.length - 1));
  13732. }
  13733. scale.domain = function(_) {
  13734. if (!arguments.length) return domain.slice();
  13735. domain = [];
  13736. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  13737. domain.sort(ascending);
  13738. return scale;
  13739. };
  13740. scale.interpolator = function(_) {
  13741. return arguments.length ? (interpolator = _, scale) : interpolator;
  13742. };
  13743. scale.range = function() {
  13744. return domain.map((d, i) => interpolator(i / (domain.length - 1)));
  13745. };
  13746. scale.quantiles = function(n) {
  13747. return Array.from({length: n + 1}, (_, i) => quantile(domain, i / n));
  13748. };
  13749. scale.copy = function() {
  13750. return sequentialQuantile(interpolator).domain(domain);
  13751. };
  13752. return initInterpolator.apply(scale, arguments);
  13753. }
  13754. function transformer$3() {
  13755. var x0 = 0,
  13756. x1 = 0.5,
  13757. x2 = 1,
  13758. s = 1,
  13759. t0,
  13760. t1,
  13761. t2,
  13762. k10,
  13763. k21,
  13764. interpolator = identity$6,
  13765. transform,
  13766. clamp = false,
  13767. unknown;
  13768. function scale(x) {
  13769. 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));
  13770. }
  13771. scale.domain = function(_) {
  13772. 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];
  13773. };
  13774. scale.clamp = function(_) {
  13775. return arguments.length ? (clamp = !!_, scale) : clamp;
  13776. };
  13777. scale.interpolator = function(_) {
  13778. return arguments.length ? (interpolator = _, scale) : interpolator;
  13779. };
  13780. function range(interpolate) {
  13781. return function(_) {
  13782. var r0, r1, r2;
  13783. return arguments.length ? ([r0, r1, r2] = _, interpolator = piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)];
  13784. };
  13785. }
  13786. scale.range = range(interpolate);
  13787. scale.rangeRound = range(interpolateRound);
  13788. scale.unknown = function(_) {
  13789. return arguments.length ? (unknown = _, scale) : unknown;
  13790. };
  13791. return function(t) {
  13792. 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;
  13793. return scale;
  13794. };
  13795. }
  13796. function diverging() {
  13797. var scale = linearish(transformer$3()(identity$6));
  13798. scale.copy = function() {
  13799. return copy$1(scale, diverging());
  13800. };
  13801. return initInterpolator.apply(scale, arguments);
  13802. }
  13803. function divergingLog() {
  13804. var scale = loggish(transformer$3()).domain([0.1, 1, 10]);
  13805. scale.copy = function() {
  13806. return copy$1(scale, divergingLog()).base(scale.base());
  13807. };
  13808. return initInterpolator.apply(scale, arguments);
  13809. }
  13810. function divergingSymlog() {
  13811. var scale = symlogish(transformer$3());
  13812. scale.copy = function() {
  13813. return copy$1(scale, divergingSymlog()).constant(scale.constant());
  13814. };
  13815. return initInterpolator.apply(scale, arguments);
  13816. }
  13817. function divergingPow() {
  13818. var scale = powish(transformer$3());
  13819. scale.copy = function() {
  13820. return copy$1(scale, divergingPow()).exponent(scale.exponent());
  13821. };
  13822. return initInterpolator.apply(scale, arguments);
  13823. }
  13824. function divergingSqrt() {
  13825. return divergingPow.apply(null, arguments).exponent(0.5);
  13826. }
  13827. function colors(specifier) {
  13828. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  13829. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  13830. return colors;
  13831. }
  13832. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  13833. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  13834. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  13835. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  13836. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  13837. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  13838. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  13839. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  13840. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  13841. var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
  13842. var ramp = scheme => rgbBasis(scheme[scheme.length - 1]);
  13843. var scheme = new Array(3).concat(
  13844. "d8b365f5f5f55ab4ac",
  13845. "a6611adfc27d80cdc1018571",
  13846. "a6611adfc27df5f5f580cdc1018571",
  13847. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  13848. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  13849. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  13850. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  13851. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  13852. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  13853. ).map(colors);
  13854. var BrBG = ramp(scheme);
  13855. var scheme$1 = new Array(3).concat(
  13856. "af8dc3f7f7f77fbf7b",
  13857. "7b3294c2a5cfa6dba0008837",
  13858. "7b3294c2a5cff7f7f7a6dba0008837",
  13859. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  13860. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  13861. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  13862. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  13863. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  13864. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  13865. ).map(colors);
  13866. var PRGn = ramp(scheme$1);
  13867. var scheme$2 = new Array(3).concat(
  13868. "e9a3c9f7f7f7a1d76a",
  13869. "d01c8bf1b6dab8e1864dac26",
  13870. "d01c8bf1b6daf7f7f7b8e1864dac26",
  13871. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  13872. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  13873. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  13874. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  13875. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  13876. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  13877. ).map(colors);
  13878. var PiYG = ramp(scheme$2);
  13879. var scheme$3 = new Array(3).concat(
  13880. "998ec3f7f7f7f1a340",
  13881. "5e3c99b2abd2fdb863e66101",
  13882. "5e3c99b2abd2f7f7f7fdb863e66101",
  13883. "542788998ec3d8daebfee0b6f1a340b35806",
  13884. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  13885. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  13886. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  13887. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  13888. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  13889. ).map(colors);
  13890. var PuOr = ramp(scheme$3);
  13891. var scheme$4 = new Array(3).concat(
  13892. "ef8a62f7f7f767a9cf",
  13893. "ca0020f4a58292c5de0571b0",
  13894. "ca0020f4a582f7f7f792c5de0571b0",
  13895. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  13896. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  13897. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  13898. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  13899. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  13900. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  13901. ).map(colors);
  13902. var RdBu = ramp(scheme$4);
  13903. var scheme$5 = new Array(3).concat(
  13904. "ef8a62ffffff999999",
  13905. "ca0020f4a582bababa404040",
  13906. "ca0020f4a582ffffffbababa404040",
  13907. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  13908. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  13909. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  13910. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  13911. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  13912. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  13913. ).map(colors);
  13914. var RdGy = ramp(scheme$5);
  13915. var scheme$6 = new Array(3).concat(
  13916. "fc8d59ffffbf91bfdb",
  13917. "d7191cfdae61abd9e92c7bb6",
  13918. "d7191cfdae61ffffbfabd9e92c7bb6",
  13919. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  13920. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  13921. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  13922. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  13923. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  13924. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  13925. ).map(colors);
  13926. var RdYlBu = ramp(scheme$6);
  13927. var scheme$7 = new Array(3).concat(
  13928. "fc8d59ffffbf91cf60",
  13929. "d7191cfdae61a6d96a1a9641",
  13930. "d7191cfdae61ffffbfa6d96a1a9641",
  13931. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  13932. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  13933. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  13934. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  13935. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  13936. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  13937. ).map(colors);
  13938. var RdYlGn = ramp(scheme$7);
  13939. var scheme$8 = new Array(3).concat(
  13940. "fc8d59ffffbf99d594",
  13941. "d7191cfdae61abdda42b83ba",
  13942. "d7191cfdae61ffffbfabdda42b83ba",
  13943. "d53e4ffc8d59fee08be6f59899d5943288bd",
  13944. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  13945. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  13946. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  13947. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  13948. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  13949. ).map(colors);
  13950. var Spectral = ramp(scheme$8);
  13951. var scheme$9 = new Array(3).concat(
  13952. "e5f5f999d8c92ca25f",
  13953. "edf8fbb2e2e266c2a4238b45",
  13954. "edf8fbb2e2e266c2a42ca25f006d2c",
  13955. "edf8fbccece699d8c966c2a42ca25f006d2c",
  13956. "edf8fbccece699d8c966c2a441ae76238b45005824",
  13957. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  13958. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  13959. ).map(colors);
  13960. var BuGn = ramp(scheme$9);
  13961. var scheme$a = new Array(3).concat(
  13962. "e0ecf49ebcda8856a7",
  13963. "edf8fbb3cde38c96c688419d",
  13964. "edf8fbb3cde38c96c68856a7810f7c",
  13965. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  13966. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  13967. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  13968. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  13969. ).map(colors);
  13970. var BuPu = ramp(scheme$a);
  13971. var scheme$b = new Array(3).concat(
  13972. "e0f3dba8ddb543a2ca",
  13973. "f0f9e8bae4bc7bccc42b8cbe",
  13974. "f0f9e8bae4bc7bccc443a2ca0868ac",
  13975. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  13976. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  13977. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  13978. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  13979. ).map(colors);
  13980. var GnBu = ramp(scheme$b);
  13981. var scheme$c = new Array(3).concat(
  13982. "fee8c8fdbb84e34a33",
  13983. "fef0d9fdcc8afc8d59d7301f",
  13984. "fef0d9fdcc8afc8d59e34a33b30000",
  13985. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  13986. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  13987. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  13988. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  13989. ).map(colors);
  13990. var OrRd = ramp(scheme$c);
  13991. var scheme$d = new Array(3).concat(
  13992. "ece2f0a6bddb1c9099",
  13993. "f6eff7bdc9e167a9cf02818a",
  13994. "f6eff7bdc9e167a9cf1c9099016c59",
  13995. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  13996. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  13997. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  13998. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  13999. ).map(colors);
  14000. var PuBuGn = ramp(scheme$d);
  14001. var scheme$e = new Array(3).concat(
  14002. "ece7f2a6bddb2b8cbe",
  14003. "f1eef6bdc9e174a9cf0570b0",
  14004. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  14005. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  14006. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  14007. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  14008. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  14009. ).map(colors);
  14010. var PuBu = ramp(scheme$e);
  14011. var scheme$f = new Array(3).concat(
  14012. "e7e1efc994c7dd1c77",
  14013. "f1eef6d7b5d8df65b0ce1256",
  14014. "f1eef6d7b5d8df65b0dd1c77980043",
  14015. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  14016. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  14017. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  14018. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  14019. ).map(colors);
  14020. var PuRd = ramp(scheme$f);
  14021. var scheme$g = new Array(3).concat(
  14022. "fde0ddfa9fb5c51b8a",
  14023. "feebe2fbb4b9f768a1ae017e",
  14024. "feebe2fbb4b9f768a1c51b8a7a0177",
  14025. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  14026. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  14027. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  14028. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  14029. ).map(colors);
  14030. var RdPu = ramp(scheme$g);
  14031. var scheme$h = new Array(3).concat(
  14032. "edf8b17fcdbb2c7fb8",
  14033. "ffffcca1dab441b6c4225ea8",
  14034. "ffffcca1dab441b6c42c7fb8253494",
  14035. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  14036. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  14037. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  14038. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  14039. ).map(colors);
  14040. var YlGnBu = ramp(scheme$h);
  14041. var scheme$i = new Array(3).concat(
  14042. "f7fcb9addd8e31a354",
  14043. "ffffccc2e69978c679238443",
  14044. "ffffccc2e69978c67931a354006837",
  14045. "ffffccd9f0a3addd8e78c67931a354006837",
  14046. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  14047. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  14048. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  14049. ).map(colors);
  14050. var YlGn = ramp(scheme$i);
  14051. var scheme$j = new Array(3).concat(
  14052. "fff7bcfec44fd95f0e",
  14053. "ffffd4fed98efe9929cc4c02",
  14054. "ffffd4fed98efe9929d95f0e993404",
  14055. "ffffd4fee391fec44ffe9929d95f0e993404",
  14056. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  14057. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  14058. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  14059. ).map(colors);
  14060. var YlOrBr = ramp(scheme$j);
  14061. var scheme$k = new Array(3).concat(
  14062. "ffeda0feb24cf03b20",
  14063. "ffffb2fecc5cfd8d3ce31a1c",
  14064. "ffffb2fecc5cfd8d3cf03b20bd0026",
  14065. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  14066. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  14067. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  14068. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  14069. ).map(colors);
  14070. var YlOrRd = ramp(scheme$k);
  14071. var scheme$l = new Array(3).concat(
  14072. "deebf79ecae13182bd",
  14073. "eff3ffbdd7e76baed62171b5",
  14074. "eff3ffbdd7e76baed63182bd08519c",
  14075. "eff3ffc6dbef9ecae16baed63182bd08519c",
  14076. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  14077. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  14078. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  14079. ).map(colors);
  14080. var Blues = ramp(scheme$l);
  14081. var scheme$m = new Array(3).concat(
  14082. "e5f5e0a1d99b31a354",
  14083. "edf8e9bae4b374c476238b45",
  14084. "edf8e9bae4b374c47631a354006d2c",
  14085. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  14086. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  14087. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  14088. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  14089. ).map(colors);
  14090. var Greens = ramp(scheme$m);
  14091. var scheme$n = new Array(3).concat(
  14092. "f0f0f0bdbdbd636363",
  14093. "f7f7f7cccccc969696525252",
  14094. "f7f7f7cccccc969696636363252525",
  14095. "f7f7f7d9d9d9bdbdbd969696636363252525",
  14096. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  14097. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  14098. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  14099. ).map(colors);
  14100. var Greys = ramp(scheme$n);
  14101. var scheme$o = new Array(3).concat(
  14102. "efedf5bcbddc756bb1",
  14103. "f2f0f7cbc9e29e9ac86a51a3",
  14104. "f2f0f7cbc9e29e9ac8756bb154278f",
  14105. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  14106. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  14107. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  14108. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  14109. ).map(colors);
  14110. var Purples = ramp(scheme$o);
  14111. var scheme$p = new Array(3).concat(
  14112. "fee0d2fc9272de2d26",
  14113. "fee5d9fcae91fb6a4acb181d",
  14114. "fee5d9fcae91fb6a4ade2d26a50f15",
  14115. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  14116. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  14117. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  14118. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  14119. ).map(colors);
  14120. var Reds = ramp(scheme$p);
  14121. var scheme$q = new Array(3).concat(
  14122. "fee6cefdae6be6550d",
  14123. "feeddefdbe85fd8d3cd94701",
  14124. "feeddefdbe85fd8d3ce6550da63603",
  14125. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  14126. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  14127. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  14128. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  14129. ).map(colors);
  14130. var Oranges = ramp(scheme$q);
  14131. function cividis(t) {
  14132. t = Math.max(0, Math.min(1, t));
  14133. return "rgb("
  14134. + 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))))))) + ", "
  14135. + 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))))))) + ", "
  14136. + 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)))))))
  14137. + ")";
  14138. }
  14139. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  14140. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  14141. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  14142. var c$1 = cubehelix();
  14143. function rainbow(t) {
  14144. if (t < 0 || t > 1) t -= Math.floor(t);
  14145. var ts = Math.abs(t - 0.5);
  14146. c$1.h = 360 * t - 100;
  14147. c$1.s = 1.5 - 1.5 * ts;
  14148. c$1.l = 0.8 - 0.9 * ts;
  14149. return c$1 + "";
  14150. }
  14151. var c$2 = rgb(),
  14152. pi_1_3 = Math.PI / 3,
  14153. pi_2_3 = Math.PI * 2 / 3;
  14154. function sinebow(t) {
  14155. var x;
  14156. t = (0.5 - t) * Math.PI;
  14157. c$2.r = 255 * (x = Math.sin(t)) * x;
  14158. c$2.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  14159. c$2.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  14160. return c$2 + "";
  14161. }
  14162. function turbo(t) {
  14163. t = Math.max(0, Math.min(1, t));
  14164. return "rgb("
  14165. + 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))))))) + ", "
  14166. + 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))))))) + ", "
  14167. + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
  14168. + ")";
  14169. }
  14170. function ramp$1(range) {
  14171. var n = range.length;
  14172. return function(t) {
  14173. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  14174. };
  14175. }
  14176. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  14177. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  14178. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  14179. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  14180. function constant$a(x) {
  14181. return function constant() {
  14182. return x;
  14183. };
  14184. }
  14185. var abs$3 = Math.abs;
  14186. var atan2$1 = Math.atan2;
  14187. var cos$2 = Math.cos;
  14188. var max$3 = Math.max;
  14189. var min$2 = Math.min;
  14190. var sin$2 = Math.sin;
  14191. var sqrt$2 = Math.sqrt;
  14192. var epsilon$5 = 1e-12;
  14193. var pi$4 = Math.PI;
  14194. var halfPi$3 = pi$4 / 2;
  14195. var tau$5 = 2 * pi$4;
  14196. function acos$1(x) {
  14197. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  14198. }
  14199. function asin$1(x) {
  14200. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  14201. }
  14202. function arcInnerRadius(d) {
  14203. return d.innerRadius;
  14204. }
  14205. function arcOuterRadius(d) {
  14206. return d.outerRadius;
  14207. }
  14208. function arcStartAngle(d) {
  14209. return d.startAngle;
  14210. }
  14211. function arcEndAngle(d) {
  14212. return d.endAngle;
  14213. }
  14214. function arcPadAngle(d) {
  14215. return d && d.padAngle; // Note: optional!
  14216. }
  14217. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  14218. var x10 = x1 - x0, y10 = y1 - y0,
  14219. x32 = x3 - x2, y32 = y3 - y2,
  14220. t = y32 * x10 - x32 * y10;
  14221. if (t * t < epsilon$5) return;
  14222. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  14223. return [x0 + t * x10, y0 + t * y10];
  14224. }
  14225. // Compute perpendicular offset line of length rc.
  14226. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  14227. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  14228. var x01 = x0 - x1,
  14229. y01 = y0 - y1,
  14230. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  14231. ox = lo * y01,
  14232. oy = -lo * x01,
  14233. x11 = x0 + ox,
  14234. y11 = y0 + oy,
  14235. x10 = x1 + ox,
  14236. y10 = y1 + oy,
  14237. x00 = (x11 + x10) / 2,
  14238. y00 = (y11 + y10) / 2,
  14239. dx = x10 - x11,
  14240. dy = y10 - y11,
  14241. d2 = dx * dx + dy * dy,
  14242. r = r1 - rc,
  14243. D = x11 * y10 - x10 * y11,
  14244. d = (dy < 0 ? -1 : 1) * sqrt$2(max$3(0, r * r * d2 - D * D)),
  14245. cx0 = (D * dy - dx * d) / d2,
  14246. cy0 = (-D * dx - dy * d) / d2,
  14247. cx1 = (D * dy + dx * d) / d2,
  14248. cy1 = (-D * dx + dy * d) / d2,
  14249. dx0 = cx0 - x00,
  14250. dy0 = cy0 - y00,
  14251. dx1 = cx1 - x00,
  14252. dy1 = cy1 - y00;
  14253. // Pick the closer of the two intersection points.
  14254. // TODO Is there a faster way to determine which intersection to use?
  14255. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  14256. return {
  14257. cx: cx0,
  14258. cy: cy0,
  14259. x01: -ox,
  14260. y01: -oy,
  14261. x11: cx0 * (r1 / r - 1),
  14262. y11: cy0 * (r1 / r - 1)
  14263. };
  14264. }
  14265. function arc() {
  14266. var innerRadius = arcInnerRadius,
  14267. outerRadius = arcOuterRadius,
  14268. cornerRadius = constant$a(0),
  14269. padRadius = null,
  14270. startAngle = arcStartAngle,
  14271. endAngle = arcEndAngle,
  14272. padAngle = arcPadAngle,
  14273. context = null;
  14274. function arc() {
  14275. var buffer,
  14276. r,
  14277. r0 = +innerRadius.apply(this, arguments),
  14278. r1 = +outerRadius.apply(this, arguments),
  14279. a0 = startAngle.apply(this, arguments) - halfPi$3,
  14280. a1 = endAngle.apply(this, arguments) - halfPi$3,
  14281. da = abs$3(a1 - a0),
  14282. cw = a1 > a0;
  14283. if (!context) context = buffer = path();
  14284. // Ensure that the outer radius is always larger than the inner radius.
  14285. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  14286. // Is it a point?
  14287. if (!(r1 > epsilon$5)) context.moveTo(0, 0);
  14288. // Or is it a circle or annulus?
  14289. else if (da > tau$5 - epsilon$5) {
  14290. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  14291. context.arc(0, 0, r1, a0, a1, !cw);
  14292. if (r0 > epsilon$5) {
  14293. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  14294. context.arc(0, 0, r0, a1, a0, cw);
  14295. }
  14296. }
  14297. // Or is it a circular or annular sector?
  14298. else {
  14299. var a01 = a0,
  14300. a11 = a1,
  14301. a00 = a0,
  14302. a10 = a1,
  14303. da0 = da,
  14304. da1 = da,
  14305. ap = padAngle.apply(this, arguments) / 2,
  14306. rp = (ap > epsilon$5) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  14307. rc = min$2(abs$3(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  14308. rc0 = rc,
  14309. rc1 = rc,
  14310. t0,
  14311. t1;
  14312. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  14313. if (rp > epsilon$5) {
  14314. var p0 = asin$1(rp / r0 * sin$2(ap)),
  14315. p1 = asin$1(rp / r1 * sin$2(ap));
  14316. if ((da0 -= p0 * 2) > epsilon$5) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  14317. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  14318. if ((da1 -= p1 * 2) > epsilon$5) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  14319. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  14320. }
  14321. var x01 = r1 * cos$2(a01),
  14322. y01 = r1 * sin$2(a01),
  14323. x10 = r0 * cos$2(a10),
  14324. y10 = r0 * sin$2(a10);
  14325. // Apply rounded corners?
  14326. if (rc > epsilon$5) {
  14327. var x11 = r1 * cos$2(a11),
  14328. y11 = r1 * sin$2(a11),
  14329. x00 = r0 * cos$2(a00),
  14330. y00 = r0 * sin$2(a00),
  14331. oc;
  14332. // Restrict the corner radius according to the sector angle.
  14333. if (da < pi$4 && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
  14334. var ax = x01 - oc[0],
  14335. ay = y01 - oc[1],
  14336. bx = x11 - oc[0],
  14337. by = y11 - oc[1],
  14338. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  14339. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  14340. rc0 = min$2(rc, (r0 - lc) / (kc - 1));
  14341. rc1 = min$2(rc, (r1 - lc) / (kc + 1));
  14342. }
  14343. }
  14344. // Is the sector collapsed to a line?
  14345. if (!(da1 > epsilon$5)) context.moveTo(x01, y01);
  14346. // Does the sector’s outer ring have rounded corners?
  14347. else if (rc1 > epsilon$5) {
  14348. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  14349. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  14350. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  14351. // Have the corners merged?
  14352. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  14353. // Otherwise, draw the two corners and the ring.
  14354. else {
  14355. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  14356. context.arc(0, 0, r1, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  14357. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  14358. }
  14359. }
  14360. // Or is the outer ring just a circular arc?
  14361. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  14362. // Is there no inner ring, and it’s a circular sector?
  14363. // Or perhaps it’s an annular sector collapsed due to padding?
  14364. if (!(r0 > epsilon$5) || !(da0 > epsilon$5)) context.lineTo(x10, y10);
  14365. // Does the sector’s inner ring (or point) have rounded corners?
  14366. else if (rc0 > epsilon$5) {
  14367. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  14368. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  14369. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  14370. // Have the corners merged?
  14371. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  14372. // Otherwise, draw the two corners and the ring.
  14373. else {
  14374. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  14375. context.arc(0, 0, r0, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  14376. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  14377. }
  14378. }
  14379. // Or is the inner ring just a circular arc?
  14380. else context.arc(0, 0, r0, a10, a00, cw);
  14381. }
  14382. context.closePath();
  14383. if (buffer) return context = null, buffer + "" || null;
  14384. }
  14385. arc.centroid = function() {
  14386. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  14387. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  14388. return [cos$2(a) * r, sin$2(a) * r];
  14389. };
  14390. arc.innerRadius = function(_) {
  14391. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$a(+_), arc) : innerRadius;
  14392. };
  14393. arc.outerRadius = function(_) {
  14394. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$a(+_), arc) : outerRadius;
  14395. };
  14396. arc.cornerRadius = function(_) {
  14397. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$a(+_), arc) : cornerRadius;
  14398. };
  14399. arc.padRadius = function(_) {
  14400. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$a(+_), arc) : padRadius;
  14401. };
  14402. arc.startAngle = function(_) {
  14403. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$a(+_), arc) : startAngle;
  14404. };
  14405. arc.endAngle = function(_) {
  14406. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$a(+_), arc) : endAngle;
  14407. };
  14408. arc.padAngle = function(_) {
  14409. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$a(+_), arc) : padAngle;
  14410. };
  14411. arc.context = function(_) {
  14412. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  14413. };
  14414. return arc;
  14415. }
  14416. var slice$4 = Array.prototype.slice;
  14417. function array$5(x) {
  14418. return typeof x === "object" && "length" in x
  14419. ? x // Array, TypedArray, NodeList, array-like
  14420. : Array.from(x); // Map, Set, iterable, string, or anything else
  14421. }
  14422. function Linear(context) {
  14423. this._context = context;
  14424. }
  14425. Linear.prototype = {
  14426. areaStart: function() {
  14427. this._line = 0;
  14428. },
  14429. areaEnd: function() {
  14430. this._line = NaN;
  14431. },
  14432. lineStart: function() {
  14433. this._point = 0;
  14434. },
  14435. lineEnd: function() {
  14436. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  14437. this._line = 1 - this._line;
  14438. },
  14439. point: function(x, y) {
  14440. x = +x, y = +y;
  14441. switch (this._point) {
  14442. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  14443. case 1: this._point = 2; // proceed
  14444. default: this._context.lineTo(x, y); break;
  14445. }
  14446. }
  14447. };
  14448. function curveLinear(context) {
  14449. return new Linear(context);
  14450. }
  14451. function x$3(p) {
  14452. return p[0];
  14453. }
  14454. function y$3(p) {
  14455. return p[1];
  14456. }
  14457. function line(x, y) {
  14458. var defined = constant$a(true),
  14459. context = null,
  14460. curve = curveLinear,
  14461. output = null;
  14462. x = typeof x === "function" ? x : (x === undefined) ? x$3 : constant$a(x);
  14463. y = typeof y === "function" ? y : (y === undefined) ? y$3 : constant$a(y);
  14464. function line(data) {
  14465. var i,
  14466. n = (data = array$5(data)).length,
  14467. d,
  14468. defined0 = false,
  14469. buffer;
  14470. if (context == null) output = curve(buffer = path());
  14471. for (i = 0; i <= n; ++i) {
  14472. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  14473. if (defined0 = !defined0) output.lineStart();
  14474. else output.lineEnd();
  14475. }
  14476. if (defined0) output.point(+x(d, i, data), +y(d, i, data));
  14477. }
  14478. if (buffer) return output = null, buffer + "" || null;
  14479. }
  14480. line.x = function(_) {
  14481. return arguments.length ? (x = typeof _ === "function" ? _ : constant$a(+_), line) : x;
  14482. };
  14483. line.y = function(_) {
  14484. return arguments.length ? (y = typeof _ === "function" ? _ : constant$a(+_), line) : y;
  14485. };
  14486. line.defined = function(_) {
  14487. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$a(!!_), line) : defined;
  14488. };
  14489. line.curve = function(_) {
  14490. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  14491. };
  14492. line.context = function(_) {
  14493. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  14494. };
  14495. return line;
  14496. }
  14497. function area$3(x0, y0, y1) {
  14498. var x1 = null,
  14499. defined = constant$a(true),
  14500. context = null,
  14501. curve = curveLinear,
  14502. output = null;
  14503. x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x$3 : constant$a(+x0);
  14504. y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant$a(0) : constant$a(+y0);
  14505. y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y$3 : constant$a(+y1);
  14506. function area(data) {
  14507. var i,
  14508. j,
  14509. k,
  14510. n = (data = array$5(data)).length,
  14511. d,
  14512. defined0 = false,
  14513. buffer,
  14514. x0z = new Array(n),
  14515. y0z = new Array(n);
  14516. if (context == null) output = curve(buffer = path());
  14517. for (i = 0; i <= n; ++i) {
  14518. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  14519. if (defined0 = !defined0) {
  14520. j = i;
  14521. output.areaStart();
  14522. output.lineStart();
  14523. } else {
  14524. output.lineEnd();
  14525. output.lineStart();
  14526. for (k = i - 1; k >= j; --k) {
  14527. output.point(x0z[k], y0z[k]);
  14528. }
  14529. output.lineEnd();
  14530. output.areaEnd();
  14531. }
  14532. }
  14533. if (defined0) {
  14534. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  14535. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  14536. }
  14537. }
  14538. if (buffer) return output = null, buffer + "" || null;
  14539. }
  14540. function arealine() {
  14541. return line().defined(defined).curve(curve).context(context);
  14542. }
  14543. area.x = function(_) {
  14544. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$a(+_), x1 = null, area) : x0;
  14545. };
  14546. area.x0 = function(_) {
  14547. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$a(+_), area) : x0;
  14548. };
  14549. area.x1 = function(_) {
  14550. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$a(+_), area) : x1;
  14551. };
  14552. area.y = function(_) {
  14553. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$a(+_), y1 = null, area) : y0;
  14554. };
  14555. area.y0 = function(_) {
  14556. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$a(+_), area) : y0;
  14557. };
  14558. area.y1 = function(_) {
  14559. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$a(+_), area) : y1;
  14560. };
  14561. area.lineX0 =
  14562. area.lineY0 = function() {
  14563. return arealine().x(x0).y(y0);
  14564. };
  14565. area.lineY1 = function() {
  14566. return arealine().x(x0).y(y1);
  14567. };
  14568. area.lineX1 = function() {
  14569. return arealine().x(x1).y(y0);
  14570. };
  14571. area.defined = function(_) {
  14572. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$a(!!_), area) : defined;
  14573. };
  14574. area.curve = function(_) {
  14575. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  14576. };
  14577. area.context = function(_) {
  14578. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  14579. };
  14580. return area;
  14581. }
  14582. function descending$1(a, b) {
  14583. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  14584. }
  14585. function identity$8(d) {
  14586. return d;
  14587. }
  14588. function pie() {
  14589. var value = identity$8,
  14590. sortValues = descending$1,
  14591. sort = null,
  14592. startAngle = constant$a(0),
  14593. endAngle = constant$a(tau$5),
  14594. padAngle = constant$a(0);
  14595. function pie(data) {
  14596. var i,
  14597. n = (data = array$5(data)).length,
  14598. j,
  14599. k,
  14600. sum = 0,
  14601. index = new Array(n),
  14602. arcs = new Array(n),
  14603. a0 = +startAngle.apply(this, arguments),
  14604. da = Math.min(tau$5, Math.max(-tau$5, endAngle.apply(this, arguments) - a0)),
  14605. a1,
  14606. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  14607. pa = p * (da < 0 ? -1 : 1),
  14608. v;
  14609. for (i = 0; i < n; ++i) {
  14610. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  14611. sum += v;
  14612. }
  14613. }
  14614. // Optionally sort the arcs by previously-computed values or by data.
  14615. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  14616. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  14617. // Compute the arcs! They are stored in the original data's order.
  14618. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  14619. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  14620. data: data[j],
  14621. index: i,
  14622. value: v,
  14623. startAngle: a0,
  14624. endAngle: a1,
  14625. padAngle: p
  14626. };
  14627. }
  14628. return arcs;
  14629. }
  14630. pie.value = function(_) {
  14631. return arguments.length ? (value = typeof _ === "function" ? _ : constant$a(+_), pie) : value;
  14632. };
  14633. pie.sortValues = function(_) {
  14634. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  14635. };
  14636. pie.sort = function(_) {
  14637. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  14638. };
  14639. pie.startAngle = function(_) {
  14640. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$a(+_), pie) : startAngle;
  14641. };
  14642. pie.endAngle = function(_) {
  14643. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$a(+_), pie) : endAngle;
  14644. };
  14645. pie.padAngle = function(_) {
  14646. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$a(+_), pie) : padAngle;
  14647. };
  14648. return pie;
  14649. }
  14650. var curveRadialLinear = curveRadial(curveLinear);
  14651. function Radial(curve) {
  14652. this._curve = curve;
  14653. }
  14654. Radial.prototype = {
  14655. areaStart: function() {
  14656. this._curve.areaStart();
  14657. },
  14658. areaEnd: function() {
  14659. this._curve.areaEnd();
  14660. },
  14661. lineStart: function() {
  14662. this._curve.lineStart();
  14663. },
  14664. lineEnd: function() {
  14665. this._curve.lineEnd();
  14666. },
  14667. point: function(a, r) {
  14668. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  14669. }
  14670. };
  14671. function curveRadial(curve) {
  14672. function radial(context) {
  14673. return new Radial(curve(context));
  14674. }
  14675. radial._curve = curve;
  14676. return radial;
  14677. }
  14678. function lineRadial(l) {
  14679. var c = l.curve;
  14680. l.angle = l.x, delete l.x;
  14681. l.radius = l.y, delete l.y;
  14682. l.curve = function(_) {
  14683. return arguments.length ? c(curveRadial(_)) : c()._curve;
  14684. };
  14685. return l;
  14686. }
  14687. function lineRadial$1() {
  14688. return lineRadial(line().curve(curveRadialLinear));
  14689. }
  14690. function areaRadial() {
  14691. var a = area$3().curve(curveRadialLinear),
  14692. c = a.curve,
  14693. x0 = a.lineX0,
  14694. x1 = a.lineX1,
  14695. y0 = a.lineY0,
  14696. y1 = a.lineY1;
  14697. a.angle = a.x, delete a.x;
  14698. a.startAngle = a.x0, delete a.x0;
  14699. a.endAngle = a.x1, delete a.x1;
  14700. a.radius = a.y, delete a.y;
  14701. a.innerRadius = a.y0, delete a.y0;
  14702. a.outerRadius = a.y1, delete a.y1;
  14703. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  14704. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  14705. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  14706. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  14707. a.curve = function(_) {
  14708. return arguments.length ? c(curveRadial(_)) : c()._curve;
  14709. };
  14710. return a;
  14711. }
  14712. function pointRadial(x, y) {
  14713. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  14714. }
  14715. function linkSource(d) {
  14716. return d.source;
  14717. }
  14718. function linkTarget(d) {
  14719. return d.target;
  14720. }
  14721. function link$2(curve) {
  14722. var source = linkSource,
  14723. target = linkTarget,
  14724. x = x$3,
  14725. y = y$3,
  14726. context = null;
  14727. function link() {
  14728. var buffer, argv = slice$4.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  14729. if (!context) context = buffer = path();
  14730. curve(context, +x.apply(this, (argv[0] = s, argv)), +y.apply(this, argv), +x.apply(this, (argv[0] = t, argv)), +y.apply(this, argv));
  14731. if (buffer) return context = null, buffer + "" || null;
  14732. }
  14733. link.source = function(_) {
  14734. return arguments.length ? (source = _, link) : source;
  14735. };
  14736. link.target = function(_) {
  14737. return arguments.length ? (target = _, link) : target;
  14738. };
  14739. link.x = function(_) {
  14740. return arguments.length ? (x = typeof _ === "function" ? _ : constant$a(+_), link) : x;
  14741. };
  14742. link.y = function(_) {
  14743. return arguments.length ? (y = typeof _ === "function" ? _ : constant$a(+_), link) : y;
  14744. };
  14745. link.context = function(_) {
  14746. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  14747. };
  14748. return link;
  14749. }
  14750. function curveHorizontal(context, x0, y0, x1, y1) {
  14751. context.moveTo(x0, y0);
  14752. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  14753. }
  14754. function curveVertical(context, x0, y0, x1, y1) {
  14755. context.moveTo(x0, y0);
  14756. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  14757. }
  14758. function curveRadial$1(context, x0, y0, x1, y1) {
  14759. var p0 = pointRadial(x0, y0),
  14760. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  14761. p2 = pointRadial(x1, y0),
  14762. p3 = pointRadial(x1, y1);
  14763. context.moveTo(p0[0], p0[1]);
  14764. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  14765. }
  14766. function linkHorizontal() {
  14767. return link$2(curveHorizontal);
  14768. }
  14769. function linkVertical() {
  14770. return link$2(curveVertical);
  14771. }
  14772. function linkRadial() {
  14773. var l = link$2(curveRadial$1);
  14774. l.angle = l.x, delete l.x;
  14775. l.radius = l.y, delete l.y;
  14776. return l;
  14777. }
  14778. var circle$2 = {
  14779. draw: function(context, size) {
  14780. var r = Math.sqrt(size / pi$4);
  14781. context.moveTo(r, 0);
  14782. context.arc(0, 0, r, 0, tau$5);
  14783. }
  14784. };
  14785. var cross$2 = {
  14786. draw: function(context, size) {
  14787. var r = Math.sqrt(size / 5) / 2;
  14788. context.moveTo(-3 * r, -r);
  14789. context.lineTo(-r, -r);
  14790. context.lineTo(-r, -3 * r);
  14791. context.lineTo(r, -3 * r);
  14792. context.lineTo(r, -r);
  14793. context.lineTo(3 * r, -r);
  14794. context.lineTo(3 * r, r);
  14795. context.lineTo(r, r);
  14796. context.lineTo(r, 3 * r);
  14797. context.lineTo(-r, 3 * r);
  14798. context.lineTo(-r, r);
  14799. context.lineTo(-3 * r, r);
  14800. context.closePath();
  14801. }
  14802. };
  14803. var tan30 = Math.sqrt(1 / 3),
  14804. tan30_2 = tan30 * 2;
  14805. var diamond = {
  14806. draw: function(context, size) {
  14807. var y = Math.sqrt(size / tan30_2),
  14808. x = y * tan30;
  14809. context.moveTo(0, -y);
  14810. context.lineTo(x, 0);
  14811. context.lineTo(0, y);
  14812. context.lineTo(-x, 0);
  14813. context.closePath();
  14814. }
  14815. };
  14816. var ka = 0.89081309152928522810,
  14817. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  14818. kx = Math.sin(tau$5 / 10) * kr,
  14819. ky = -Math.cos(tau$5 / 10) * kr;
  14820. var star = {
  14821. draw: function(context, size) {
  14822. var r = Math.sqrt(size * ka),
  14823. x = kx * r,
  14824. y = ky * r;
  14825. context.moveTo(0, -r);
  14826. context.lineTo(x, y);
  14827. for (var i = 1; i < 5; ++i) {
  14828. var a = tau$5 * i / 5,
  14829. c = Math.cos(a),
  14830. s = Math.sin(a);
  14831. context.lineTo(s * r, -c * r);
  14832. context.lineTo(c * x - s * y, s * x + c * y);
  14833. }
  14834. context.closePath();
  14835. }
  14836. };
  14837. var square$1 = {
  14838. draw: function(context, size) {
  14839. var w = Math.sqrt(size),
  14840. x = -w / 2;
  14841. context.rect(x, x, w, w);
  14842. }
  14843. };
  14844. var sqrt3 = Math.sqrt(3);
  14845. var triangle = {
  14846. draw: function(context, size) {
  14847. var y = -Math.sqrt(size / (sqrt3 * 3));
  14848. context.moveTo(0, y * 2);
  14849. context.lineTo(-sqrt3 * y, -y);
  14850. context.lineTo(sqrt3 * y, -y);
  14851. context.closePath();
  14852. }
  14853. };
  14854. var c$3 = -0.5,
  14855. s = Math.sqrt(3) / 2,
  14856. k = 1 / Math.sqrt(12),
  14857. a$1 = (k / 2 + 1) * 3;
  14858. var wye = {
  14859. draw: function(context, size) {
  14860. var r = Math.sqrt(size / a$1),
  14861. x0 = r / 2,
  14862. y0 = r * k,
  14863. x1 = x0,
  14864. y1 = r * k + r,
  14865. x2 = -x1,
  14866. y2 = y1;
  14867. context.moveTo(x0, y0);
  14868. context.lineTo(x1, y1);
  14869. context.lineTo(x2, y2);
  14870. context.lineTo(c$3 * x0 - s * y0, s * x0 + c$3 * y0);
  14871. context.lineTo(c$3 * x1 - s * y1, s * x1 + c$3 * y1);
  14872. context.lineTo(c$3 * x2 - s * y2, s * x2 + c$3 * y2);
  14873. context.lineTo(c$3 * x0 + s * y0, c$3 * y0 - s * x0);
  14874. context.lineTo(c$3 * x1 + s * y1, c$3 * y1 - s * x1);
  14875. context.lineTo(c$3 * x2 + s * y2, c$3 * y2 - s * x2);
  14876. context.closePath();
  14877. }
  14878. };
  14879. var symbols = [
  14880. circle$2,
  14881. cross$2,
  14882. diamond,
  14883. square$1,
  14884. star,
  14885. triangle,
  14886. wye
  14887. ];
  14888. function symbol(type, size) {
  14889. var context = null;
  14890. type = typeof type === "function" ? type : constant$a(type || circle$2);
  14891. size = typeof size === "function" ? size : constant$a(size === undefined ? 64 : +size);
  14892. function symbol() {
  14893. var buffer;
  14894. if (!context) context = buffer = path();
  14895. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  14896. if (buffer) return context = null, buffer + "" || null;
  14897. }
  14898. symbol.type = function(_) {
  14899. return arguments.length ? (type = typeof _ === "function" ? _ : constant$a(_), symbol) : type;
  14900. };
  14901. symbol.size = function(_) {
  14902. return arguments.length ? (size = typeof _ === "function" ? _ : constant$a(+_), symbol) : size;
  14903. };
  14904. symbol.context = function(_) {
  14905. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  14906. };
  14907. return symbol;
  14908. }
  14909. function noop$3() {}
  14910. function point$1(that, x, y) {
  14911. that._context.bezierCurveTo(
  14912. (2 * that._x0 + that._x1) / 3,
  14913. (2 * that._y0 + that._y1) / 3,
  14914. (that._x0 + 2 * that._x1) / 3,
  14915. (that._y0 + 2 * that._y1) / 3,
  14916. (that._x0 + 4 * that._x1 + x) / 6,
  14917. (that._y0 + 4 * that._y1 + y) / 6
  14918. );
  14919. }
  14920. function Basis(context) {
  14921. this._context = context;
  14922. }
  14923. Basis.prototype = {
  14924. areaStart: function() {
  14925. this._line = 0;
  14926. },
  14927. areaEnd: function() {
  14928. this._line = NaN;
  14929. },
  14930. lineStart: function() {
  14931. this._x0 = this._x1 =
  14932. this._y0 = this._y1 = NaN;
  14933. this._point = 0;
  14934. },
  14935. lineEnd: function() {
  14936. switch (this._point) {
  14937. case 3: point$1(this, this._x1, this._y1); // proceed
  14938. case 2: this._context.lineTo(this._x1, this._y1); break;
  14939. }
  14940. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  14941. this._line = 1 - this._line;
  14942. },
  14943. point: function(x, y) {
  14944. x = +x, y = +y;
  14945. switch (this._point) {
  14946. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  14947. case 1: this._point = 2; break;
  14948. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  14949. default: point$1(this, x, y); break;
  14950. }
  14951. this._x0 = this._x1, this._x1 = x;
  14952. this._y0 = this._y1, this._y1 = y;
  14953. }
  14954. };
  14955. function basis$2(context) {
  14956. return new Basis(context);
  14957. }
  14958. function BasisClosed(context) {
  14959. this._context = context;
  14960. }
  14961. BasisClosed.prototype = {
  14962. areaStart: noop$3,
  14963. areaEnd: noop$3,
  14964. lineStart: function() {
  14965. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  14966. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  14967. this._point = 0;
  14968. },
  14969. lineEnd: function() {
  14970. switch (this._point) {
  14971. case 1: {
  14972. this._context.moveTo(this._x2, this._y2);
  14973. this._context.closePath();
  14974. break;
  14975. }
  14976. case 2: {
  14977. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  14978. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  14979. this._context.closePath();
  14980. break;
  14981. }
  14982. case 3: {
  14983. this.point(this._x2, this._y2);
  14984. this.point(this._x3, this._y3);
  14985. this.point(this._x4, this._y4);
  14986. break;
  14987. }
  14988. }
  14989. },
  14990. point: function(x, y) {
  14991. x = +x, y = +y;
  14992. switch (this._point) {
  14993. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  14994. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  14995. 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;
  14996. default: point$1(this, x, y); break;
  14997. }
  14998. this._x0 = this._x1, this._x1 = x;
  14999. this._y0 = this._y1, this._y1 = y;
  15000. }
  15001. };
  15002. function basisClosed$1(context) {
  15003. return new BasisClosed(context);
  15004. }
  15005. function BasisOpen(context) {
  15006. this._context = context;
  15007. }
  15008. BasisOpen.prototype = {
  15009. areaStart: function() {
  15010. this._line = 0;
  15011. },
  15012. areaEnd: function() {
  15013. this._line = NaN;
  15014. },
  15015. lineStart: function() {
  15016. this._x0 = this._x1 =
  15017. this._y0 = this._y1 = NaN;
  15018. this._point = 0;
  15019. },
  15020. lineEnd: function() {
  15021. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  15022. this._line = 1 - this._line;
  15023. },
  15024. point: function(x, y) {
  15025. x = +x, y = +y;
  15026. switch (this._point) {
  15027. case 0: this._point = 1; break;
  15028. case 1: this._point = 2; break;
  15029. 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;
  15030. case 3: this._point = 4; // proceed
  15031. default: point$1(this, x, y); break;
  15032. }
  15033. this._x0 = this._x1, this._x1 = x;
  15034. this._y0 = this._y1, this._y1 = y;
  15035. }
  15036. };
  15037. function basisOpen(context) {
  15038. return new BasisOpen(context);
  15039. }
  15040. function Bundle(context, beta) {
  15041. this._basis = new Basis(context);
  15042. this._beta = beta;
  15043. }
  15044. Bundle.prototype = {
  15045. lineStart: function() {
  15046. this._x = [];
  15047. this._y = [];
  15048. this._basis.lineStart();
  15049. },
  15050. lineEnd: function() {
  15051. var x = this._x,
  15052. y = this._y,
  15053. j = x.length - 1;
  15054. if (j > 0) {
  15055. var x0 = x[0],
  15056. y0 = y[0],
  15057. dx = x[j] - x0,
  15058. dy = y[j] - y0,
  15059. i = -1,
  15060. t;
  15061. while (++i <= j) {
  15062. t = i / j;
  15063. this._basis.point(
  15064. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  15065. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  15066. );
  15067. }
  15068. }
  15069. this._x = this._y = null;
  15070. this._basis.lineEnd();
  15071. },
  15072. point: function(x, y) {
  15073. this._x.push(+x);
  15074. this._y.push(+y);
  15075. }
  15076. };
  15077. var bundle = (function custom(beta) {
  15078. function bundle(context) {
  15079. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  15080. }
  15081. bundle.beta = function(beta) {
  15082. return custom(+beta);
  15083. };
  15084. return bundle;
  15085. })(0.85);
  15086. function point$2(that, x, y) {
  15087. that._context.bezierCurveTo(
  15088. that._x1 + that._k * (that._x2 - that._x0),
  15089. that._y1 + that._k * (that._y2 - that._y0),
  15090. that._x2 + that._k * (that._x1 - x),
  15091. that._y2 + that._k * (that._y1 - y),
  15092. that._x2,
  15093. that._y2
  15094. );
  15095. }
  15096. function Cardinal(context, tension) {
  15097. this._context = context;
  15098. this._k = (1 - tension) / 6;
  15099. }
  15100. Cardinal.prototype = {
  15101. areaStart: function() {
  15102. this._line = 0;
  15103. },
  15104. areaEnd: function() {
  15105. this._line = NaN;
  15106. },
  15107. lineStart: function() {
  15108. this._x0 = this._x1 = this._x2 =
  15109. this._y0 = this._y1 = this._y2 = NaN;
  15110. this._point = 0;
  15111. },
  15112. lineEnd: function() {
  15113. switch (this._point) {
  15114. case 2: this._context.lineTo(this._x2, this._y2); break;
  15115. case 3: point$2(this, this._x1, this._y1); break;
  15116. }
  15117. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15118. this._line = 1 - this._line;
  15119. },
  15120. point: function(x, y) {
  15121. x = +x, y = +y;
  15122. switch (this._point) {
  15123. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15124. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  15125. case 2: this._point = 3; // proceed
  15126. default: point$2(this, x, y); break;
  15127. }
  15128. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  15129. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  15130. }
  15131. };
  15132. var cardinal = (function custom(tension) {
  15133. function cardinal(context) {
  15134. return new Cardinal(context, tension);
  15135. }
  15136. cardinal.tension = function(tension) {
  15137. return custom(+tension);
  15138. };
  15139. return cardinal;
  15140. })(0);
  15141. function CardinalClosed(context, tension) {
  15142. this._context = context;
  15143. this._k = (1 - tension) / 6;
  15144. }
  15145. CardinalClosed.prototype = {
  15146. areaStart: noop$3,
  15147. areaEnd: noop$3,
  15148. lineStart: function() {
  15149. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  15150. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  15151. this._point = 0;
  15152. },
  15153. lineEnd: function() {
  15154. switch (this._point) {
  15155. case 1: {
  15156. this._context.moveTo(this._x3, this._y3);
  15157. this._context.closePath();
  15158. break;
  15159. }
  15160. case 2: {
  15161. this._context.lineTo(this._x3, this._y3);
  15162. this._context.closePath();
  15163. break;
  15164. }
  15165. case 3: {
  15166. this.point(this._x3, this._y3);
  15167. this.point(this._x4, this._y4);
  15168. this.point(this._x5, this._y5);
  15169. break;
  15170. }
  15171. }
  15172. },
  15173. point: function(x, y) {
  15174. x = +x, y = +y;
  15175. switch (this._point) {
  15176. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  15177. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  15178. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  15179. default: point$2(this, x, y); break;
  15180. }
  15181. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  15182. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  15183. }
  15184. };
  15185. var cardinalClosed = (function custom(tension) {
  15186. function cardinal(context) {
  15187. return new CardinalClosed(context, tension);
  15188. }
  15189. cardinal.tension = function(tension) {
  15190. return custom(+tension);
  15191. };
  15192. return cardinal;
  15193. })(0);
  15194. function CardinalOpen(context, tension) {
  15195. this._context = context;
  15196. this._k = (1 - tension) / 6;
  15197. }
  15198. CardinalOpen.prototype = {
  15199. areaStart: function() {
  15200. this._line = 0;
  15201. },
  15202. areaEnd: function() {
  15203. this._line = NaN;
  15204. },
  15205. lineStart: function() {
  15206. this._x0 = this._x1 = this._x2 =
  15207. this._y0 = this._y1 = this._y2 = NaN;
  15208. this._point = 0;
  15209. },
  15210. lineEnd: function() {
  15211. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  15212. this._line = 1 - this._line;
  15213. },
  15214. point: function(x, y) {
  15215. x = +x, y = +y;
  15216. switch (this._point) {
  15217. case 0: this._point = 1; break;
  15218. case 1: this._point = 2; break;
  15219. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  15220. case 3: this._point = 4; // proceed
  15221. default: point$2(this, x, y); break;
  15222. }
  15223. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  15224. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  15225. }
  15226. };
  15227. var cardinalOpen = (function custom(tension) {
  15228. function cardinal(context) {
  15229. return new CardinalOpen(context, tension);
  15230. }
  15231. cardinal.tension = function(tension) {
  15232. return custom(+tension);
  15233. };
  15234. return cardinal;
  15235. })(0);
  15236. function point$3(that, x, y) {
  15237. var x1 = that._x1,
  15238. y1 = that._y1,
  15239. x2 = that._x2,
  15240. y2 = that._y2;
  15241. if (that._l01_a > epsilon$5) {
  15242. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  15243. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  15244. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  15245. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  15246. }
  15247. if (that._l23_a > epsilon$5) {
  15248. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  15249. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  15250. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  15251. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  15252. }
  15253. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  15254. }
  15255. function CatmullRom(context, alpha) {
  15256. this._context = context;
  15257. this._alpha = alpha;
  15258. }
  15259. CatmullRom.prototype = {
  15260. areaStart: function() {
  15261. this._line = 0;
  15262. },
  15263. areaEnd: function() {
  15264. this._line = NaN;
  15265. },
  15266. lineStart: function() {
  15267. this._x0 = this._x1 = this._x2 =
  15268. this._y0 = this._y1 = this._y2 = NaN;
  15269. this._l01_a = this._l12_a = this._l23_a =
  15270. this._l01_2a = this._l12_2a = this._l23_2a =
  15271. this._point = 0;
  15272. },
  15273. lineEnd: function() {
  15274. switch (this._point) {
  15275. case 2: this._context.lineTo(this._x2, this._y2); break;
  15276. case 3: this.point(this._x2, this._y2); break;
  15277. }
  15278. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15279. this._line = 1 - this._line;
  15280. },
  15281. point: function(x, y) {
  15282. x = +x, y = +y;
  15283. if (this._point) {
  15284. var x23 = this._x2 - x,
  15285. y23 = this._y2 - y;
  15286. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  15287. }
  15288. switch (this._point) {
  15289. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15290. case 1: this._point = 2; break;
  15291. case 2: this._point = 3; // proceed
  15292. default: point$3(this, x, y); break;
  15293. }
  15294. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  15295. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  15296. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  15297. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  15298. }
  15299. };
  15300. var catmullRom = (function custom(alpha) {
  15301. function catmullRom(context) {
  15302. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  15303. }
  15304. catmullRom.alpha = function(alpha) {
  15305. return custom(+alpha);
  15306. };
  15307. return catmullRom;
  15308. })(0.5);
  15309. function CatmullRomClosed(context, alpha) {
  15310. this._context = context;
  15311. this._alpha = alpha;
  15312. }
  15313. CatmullRomClosed.prototype = {
  15314. areaStart: noop$3,
  15315. areaEnd: noop$3,
  15316. lineStart: function() {
  15317. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  15318. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  15319. this._l01_a = this._l12_a = this._l23_a =
  15320. this._l01_2a = this._l12_2a = this._l23_2a =
  15321. this._point = 0;
  15322. },
  15323. lineEnd: function() {
  15324. switch (this._point) {
  15325. case 1: {
  15326. this._context.moveTo(this._x3, this._y3);
  15327. this._context.closePath();
  15328. break;
  15329. }
  15330. case 2: {
  15331. this._context.lineTo(this._x3, this._y3);
  15332. this._context.closePath();
  15333. break;
  15334. }
  15335. case 3: {
  15336. this.point(this._x3, this._y3);
  15337. this.point(this._x4, this._y4);
  15338. this.point(this._x5, this._y5);
  15339. break;
  15340. }
  15341. }
  15342. },
  15343. point: function(x, y) {
  15344. x = +x, y = +y;
  15345. if (this._point) {
  15346. var x23 = this._x2 - x,
  15347. y23 = this._y2 - y;
  15348. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  15349. }
  15350. switch (this._point) {
  15351. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  15352. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  15353. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  15354. default: point$3(this, x, y); break;
  15355. }
  15356. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  15357. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  15358. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  15359. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  15360. }
  15361. };
  15362. var catmullRomClosed = (function custom(alpha) {
  15363. function catmullRom(context) {
  15364. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  15365. }
  15366. catmullRom.alpha = function(alpha) {
  15367. return custom(+alpha);
  15368. };
  15369. return catmullRom;
  15370. })(0.5);
  15371. function CatmullRomOpen(context, alpha) {
  15372. this._context = context;
  15373. this._alpha = alpha;
  15374. }
  15375. CatmullRomOpen.prototype = {
  15376. areaStart: function() {
  15377. this._line = 0;
  15378. },
  15379. areaEnd: function() {
  15380. this._line = NaN;
  15381. },
  15382. lineStart: function() {
  15383. this._x0 = this._x1 = this._x2 =
  15384. this._y0 = this._y1 = this._y2 = NaN;
  15385. this._l01_a = this._l12_a = this._l23_a =
  15386. this._l01_2a = this._l12_2a = this._l23_2a =
  15387. this._point = 0;
  15388. },
  15389. lineEnd: function() {
  15390. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  15391. this._line = 1 - this._line;
  15392. },
  15393. point: function(x, y) {
  15394. x = +x, y = +y;
  15395. if (this._point) {
  15396. var x23 = this._x2 - x,
  15397. y23 = this._y2 - y;
  15398. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  15399. }
  15400. switch (this._point) {
  15401. case 0: this._point = 1; break;
  15402. case 1: this._point = 2; break;
  15403. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  15404. case 3: this._point = 4; // proceed
  15405. default: point$3(this, x, y); break;
  15406. }
  15407. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  15408. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  15409. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  15410. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  15411. }
  15412. };
  15413. var catmullRomOpen = (function custom(alpha) {
  15414. function catmullRom(context) {
  15415. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  15416. }
  15417. catmullRom.alpha = function(alpha) {
  15418. return custom(+alpha);
  15419. };
  15420. return catmullRom;
  15421. })(0.5);
  15422. function LinearClosed(context) {
  15423. this._context = context;
  15424. }
  15425. LinearClosed.prototype = {
  15426. areaStart: noop$3,
  15427. areaEnd: noop$3,
  15428. lineStart: function() {
  15429. this._point = 0;
  15430. },
  15431. lineEnd: function() {
  15432. if (this._point) this._context.closePath();
  15433. },
  15434. point: function(x, y) {
  15435. x = +x, y = +y;
  15436. if (this._point) this._context.lineTo(x, y);
  15437. else this._point = 1, this._context.moveTo(x, y);
  15438. }
  15439. };
  15440. function linearClosed(context) {
  15441. return new LinearClosed(context);
  15442. }
  15443. function sign$1(x) {
  15444. return x < 0 ? -1 : 1;
  15445. }
  15446. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  15447. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  15448. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  15449. // NOV(II), P. 443, 1990.
  15450. function slope3(that, x2, y2) {
  15451. var h0 = that._x1 - that._x0,
  15452. h1 = x2 - that._x1,
  15453. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  15454. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  15455. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  15456. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  15457. }
  15458. // Calculate a one-sided slope.
  15459. function slope2(that, t) {
  15460. var h = that._x1 - that._x0;
  15461. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  15462. }
  15463. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  15464. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  15465. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  15466. function point$4(that, t0, t1) {
  15467. var x0 = that._x0,
  15468. y0 = that._y0,
  15469. x1 = that._x1,
  15470. y1 = that._y1,
  15471. dx = (x1 - x0) / 3;
  15472. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  15473. }
  15474. function MonotoneX(context) {
  15475. this._context = context;
  15476. }
  15477. MonotoneX.prototype = {
  15478. areaStart: function() {
  15479. this._line = 0;
  15480. },
  15481. areaEnd: function() {
  15482. this._line = NaN;
  15483. },
  15484. lineStart: function() {
  15485. this._x0 = this._x1 =
  15486. this._y0 = this._y1 =
  15487. this._t0 = NaN;
  15488. this._point = 0;
  15489. },
  15490. lineEnd: function() {
  15491. switch (this._point) {
  15492. case 2: this._context.lineTo(this._x1, this._y1); break;
  15493. case 3: point$4(this, this._t0, slope2(this, this._t0)); break;
  15494. }
  15495. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15496. this._line = 1 - this._line;
  15497. },
  15498. point: function(x, y) {
  15499. var t1 = NaN;
  15500. x = +x, y = +y;
  15501. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  15502. switch (this._point) {
  15503. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15504. case 1: this._point = 2; break;
  15505. case 2: this._point = 3; point$4(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  15506. default: point$4(this, this._t0, t1 = slope3(this, x, y)); break;
  15507. }
  15508. this._x0 = this._x1, this._x1 = x;
  15509. this._y0 = this._y1, this._y1 = y;
  15510. this._t0 = t1;
  15511. }
  15512. };
  15513. function MonotoneY(context) {
  15514. this._context = new ReflectContext(context);
  15515. }
  15516. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  15517. MonotoneX.prototype.point.call(this, y, x);
  15518. };
  15519. function ReflectContext(context) {
  15520. this._context = context;
  15521. }
  15522. ReflectContext.prototype = {
  15523. moveTo: function(x, y) { this._context.moveTo(y, x); },
  15524. closePath: function() { this._context.closePath(); },
  15525. lineTo: function(x, y) { this._context.lineTo(y, x); },
  15526. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  15527. };
  15528. function monotoneX(context) {
  15529. return new MonotoneX(context);
  15530. }
  15531. function monotoneY(context) {
  15532. return new MonotoneY(context);
  15533. }
  15534. function Natural(context) {
  15535. this._context = context;
  15536. }
  15537. Natural.prototype = {
  15538. areaStart: function() {
  15539. this._line = 0;
  15540. },
  15541. areaEnd: function() {
  15542. this._line = NaN;
  15543. },
  15544. lineStart: function() {
  15545. this._x = [];
  15546. this._y = [];
  15547. },
  15548. lineEnd: function() {
  15549. var x = this._x,
  15550. y = this._y,
  15551. n = x.length;
  15552. if (n) {
  15553. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  15554. if (n === 2) {
  15555. this._context.lineTo(x[1], y[1]);
  15556. } else {
  15557. var px = controlPoints(x),
  15558. py = controlPoints(y);
  15559. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  15560. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  15561. }
  15562. }
  15563. }
  15564. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  15565. this._line = 1 - this._line;
  15566. this._x = this._y = null;
  15567. },
  15568. point: function(x, y) {
  15569. this._x.push(+x);
  15570. this._y.push(+y);
  15571. }
  15572. };
  15573. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  15574. function controlPoints(x) {
  15575. var i,
  15576. n = x.length - 1,
  15577. m,
  15578. a = new Array(n),
  15579. b = new Array(n),
  15580. r = new Array(n);
  15581. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  15582. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  15583. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  15584. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  15585. a[n - 1] = r[n - 1] / b[n - 1];
  15586. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  15587. b[n - 1] = (x[n] + a[n - 1]) / 2;
  15588. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  15589. return [a, b];
  15590. }
  15591. function natural(context) {
  15592. return new Natural(context);
  15593. }
  15594. function Step(context, t) {
  15595. this._context = context;
  15596. this._t = t;
  15597. }
  15598. Step.prototype = {
  15599. areaStart: function() {
  15600. this._line = 0;
  15601. },
  15602. areaEnd: function() {
  15603. this._line = NaN;
  15604. },
  15605. lineStart: function() {
  15606. this._x = this._y = NaN;
  15607. this._point = 0;
  15608. },
  15609. lineEnd: function() {
  15610. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  15611. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15612. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  15613. },
  15614. point: function(x, y) {
  15615. x = +x, y = +y;
  15616. switch (this._point) {
  15617. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15618. case 1: this._point = 2; // proceed
  15619. default: {
  15620. if (this._t <= 0) {
  15621. this._context.lineTo(this._x, y);
  15622. this._context.lineTo(x, y);
  15623. } else {
  15624. var x1 = this._x * (1 - this._t) + x * this._t;
  15625. this._context.lineTo(x1, this._y);
  15626. this._context.lineTo(x1, y);
  15627. }
  15628. break;
  15629. }
  15630. }
  15631. this._x = x, this._y = y;
  15632. }
  15633. };
  15634. function step(context) {
  15635. return new Step(context, 0.5);
  15636. }
  15637. function stepBefore(context) {
  15638. return new Step(context, 0);
  15639. }
  15640. function stepAfter(context) {
  15641. return new Step(context, 1);
  15642. }
  15643. function none$1(series, order) {
  15644. if (!((n = series.length) > 1)) return;
  15645. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  15646. s0 = s1, s1 = series[order[i]];
  15647. for (j = 0; j < m; ++j) {
  15648. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  15649. }
  15650. }
  15651. }
  15652. function none$2(series) {
  15653. var n = series.length, o = new Array(n);
  15654. while (--n >= 0) o[n] = n;
  15655. return o;
  15656. }
  15657. function stackValue(d, key) {
  15658. return d[key];
  15659. }
  15660. function stackSeries(key) {
  15661. const series = [];
  15662. series.key = key;
  15663. return series;
  15664. }
  15665. function stack() {
  15666. var keys = constant$a([]),
  15667. order = none$2,
  15668. offset = none$1,
  15669. value = stackValue;
  15670. function stack(data) {
  15671. var sz = Array.from(keys.apply(this, arguments), stackSeries),
  15672. i, n = sz.length, j = -1,
  15673. oz;
  15674. for (const d of data) {
  15675. for (i = 0, ++j; i < n; ++i) {
  15676. (sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
  15677. }
  15678. }
  15679. for (i = 0, oz = array$5(order(sz)); i < n; ++i) {
  15680. sz[oz[i]].index = i;
  15681. }
  15682. offset(sz, oz);
  15683. return sz;
  15684. }
  15685. stack.keys = function(_) {
  15686. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$a(Array.from(_)), stack) : keys;
  15687. };
  15688. stack.value = function(_) {
  15689. return arguments.length ? (value = typeof _ === "function" ? _ : constant$a(+_), stack) : value;
  15690. };
  15691. stack.order = function(_) {
  15692. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$a(Array.from(_)), stack) : order;
  15693. };
  15694. stack.offset = function(_) {
  15695. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  15696. };
  15697. return stack;
  15698. }
  15699. function expand(series, order) {
  15700. if (!((n = series.length) > 0)) return;
  15701. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  15702. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  15703. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  15704. }
  15705. none$1(series, order);
  15706. }
  15707. function diverging$1(series, order) {
  15708. if (!((n = series.length) > 0)) return;
  15709. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  15710. for (yp = yn = 0, i = 0; i < n; ++i) {
  15711. if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
  15712. d[0] = yp, d[1] = yp += dy;
  15713. } else if (dy < 0) {
  15714. d[1] = yn, d[0] = yn += dy;
  15715. } else {
  15716. d[0] = 0, d[1] = dy;
  15717. }
  15718. }
  15719. }
  15720. }
  15721. function silhouette(series, order) {
  15722. if (!((n = series.length) > 0)) return;
  15723. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  15724. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  15725. s0[j][1] += s0[j][0] = -y / 2;
  15726. }
  15727. none$1(series, order);
  15728. }
  15729. function wiggle(series, order) {
  15730. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  15731. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  15732. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  15733. var si = series[order[i]],
  15734. sij0 = si[j][1] || 0,
  15735. sij1 = si[j - 1][1] || 0,
  15736. s3 = (sij0 - sij1) / 2;
  15737. for (var k = 0; k < i; ++k) {
  15738. var sk = series[order[k]],
  15739. skj0 = sk[j][1] || 0,
  15740. skj1 = sk[j - 1][1] || 0;
  15741. s3 += skj0 - skj1;
  15742. }
  15743. s1 += sij0, s2 += s3 * sij0;
  15744. }
  15745. s0[j - 1][1] += s0[j - 1][0] = y;
  15746. if (s1) y -= s2 / s1;
  15747. }
  15748. s0[j - 1][1] += s0[j - 1][0] = y;
  15749. none$1(series, order);
  15750. }
  15751. function appearance(series) {
  15752. var peaks = series.map(peak);
  15753. return none$2(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
  15754. }
  15755. function peak(series) {
  15756. var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
  15757. while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
  15758. return j;
  15759. }
  15760. function ascending$3(series) {
  15761. var sums = series.map(sum$1);
  15762. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  15763. }
  15764. function sum$1(series) {
  15765. var s = 0, i = -1, n = series.length, v;
  15766. while (++i < n) if (v = +series[i][1]) s += v;
  15767. return s;
  15768. }
  15769. function descending$2(series) {
  15770. return ascending$3(series).reverse();
  15771. }
  15772. function insideOut(series) {
  15773. var n = series.length,
  15774. i,
  15775. j,
  15776. sums = series.map(sum$1),
  15777. order = appearance(series),
  15778. top = 0,
  15779. bottom = 0,
  15780. tops = [],
  15781. bottoms = [];
  15782. for (i = 0; i < n; ++i) {
  15783. j = order[i];
  15784. if (top < bottom) {
  15785. top += sums[j];
  15786. tops.push(j);
  15787. } else {
  15788. bottom += sums[j];
  15789. bottoms.push(j);
  15790. }
  15791. }
  15792. return bottoms.reverse().concat(tops);
  15793. }
  15794. function reverse$1(series) {
  15795. return none$2(series).reverse();
  15796. }
  15797. var constant$b = x => () => x;
  15798. function ZoomEvent(type, {
  15799. sourceEvent,
  15800. target,
  15801. transform,
  15802. dispatch
  15803. }) {
  15804. Object.defineProperties(this, {
  15805. type: {value: type, enumerable: true, configurable: true},
  15806. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  15807. target: {value: target, enumerable: true, configurable: true},
  15808. transform: {value: transform, enumerable: true, configurable: true},
  15809. _: {value: dispatch}
  15810. });
  15811. }
  15812. function Transform(k, x, y) {
  15813. this.k = k;
  15814. this.x = x;
  15815. this.y = y;
  15816. }
  15817. Transform.prototype = {
  15818. constructor: Transform,
  15819. scale: function(k) {
  15820. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  15821. },
  15822. translate: function(x, y) {
  15823. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  15824. },
  15825. apply: function(point) {
  15826. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  15827. },
  15828. applyX: function(x) {
  15829. return x * this.k + this.x;
  15830. },
  15831. applyY: function(y) {
  15832. return y * this.k + this.y;
  15833. },
  15834. invert: function(location) {
  15835. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  15836. },
  15837. invertX: function(x) {
  15838. return (x - this.x) / this.k;
  15839. },
  15840. invertY: function(y) {
  15841. return (y - this.y) / this.k;
  15842. },
  15843. rescaleX: function(x) {
  15844. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  15845. },
  15846. rescaleY: function(y) {
  15847. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  15848. },
  15849. toString: function() {
  15850. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  15851. }
  15852. };
  15853. var identity$9 = new Transform(1, 0, 0);
  15854. transform$1.prototype = Transform.prototype;
  15855. function transform$1(node) {
  15856. while (!node.__zoom) if (!(node = node.parentNode)) return identity$9;
  15857. return node.__zoom;
  15858. }
  15859. function nopropagation$2(event) {
  15860. event.stopImmediatePropagation();
  15861. }
  15862. function noevent$2(event) {
  15863. event.preventDefault();
  15864. event.stopImmediatePropagation();
  15865. }
  15866. // Ignore right-click, since that should open the context menu.
  15867. // except for pinch-to-zoom, which is sent as a wheel+ctrlKey event
  15868. function defaultFilter$2(event) {
  15869. return (!event.ctrlKey || event.type === 'wheel') && !event.button;
  15870. }
  15871. function defaultExtent$1() {
  15872. var e = this;
  15873. if (e instanceof SVGElement) {
  15874. e = e.ownerSVGElement || e;
  15875. if (e.hasAttribute("viewBox")) {
  15876. e = e.viewBox.baseVal;
  15877. return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
  15878. }
  15879. return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
  15880. }
  15881. return [[0, 0], [e.clientWidth, e.clientHeight]];
  15882. }
  15883. function defaultTransform() {
  15884. return this.__zoom || identity$9;
  15885. }
  15886. function defaultWheelDelta(event) {
  15887. return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1);
  15888. }
  15889. function defaultTouchable$2() {
  15890. return navigator.maxTouchPoints || ("ontouchstart" in this);
  15891. }
  15892. function defaultConstrain(transform, extent, translateExtent) {
  15893. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  15894. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  15895. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  15896. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  15897. return transform.translate(
  15898. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  15899. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  15900. );
  15901. }
  15902. function zoom() {
  15903. var filter = defaultFilter$2,
  15904. extent = defaultExtent$1,
  15905. constrain = defaultConstrain,
  15906. wheelDelta = defaultWheelDelta,
  15907. touchable = defaultTouchable$2,
  15908. scaleExtent = [0, Infinity],
  15909. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  15910. duration = 250,
  15911. interpolate = interpolateZoom,
  15912. listeners = dispatch("start", "zoom", "end"),
  15913. touchstarting,
  15914. touchfirst,
  15915. touchending,
  15916. touchDelay = 500,
  15917. wheelDelay = 150,
  15918. clickDistance2 = 0,
  15919. tapDistance = 10;
  15920. function zoom(selection) {
  15921. selection
  15922. .property("__zoom", defaultTransform)
  15923. .on("wheel.zoom", wheeled)
  15924. .on("mousedown.zoom", mousedowned)
  15925. .on("dblclick.zoom", dblclicked)
  15926. .filter(touchable)
  15927. .on("touchstart.zoom", touchstarted)
  15928. .on("touchmove.zoom", touchmoved)
  15929. .on("touchend.zoom touchcancel.zoom", touchended)
  15930. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  15931. }
  15932. zoom.transform = function(collection, transform, point, event) {
  15933. var selection = collection.selection ? collection.selection() : collection;
  15934. selection.property("__zoom", defaultTransform);
  15935. if (collection !== selection) {
  15936. schedule(collection, transform, point, event);
  15937. } else {
  15938. selection.interrupt().each(function() {
  15939. gesture(this, arguments)
  15940. .event(event)
  15941. .start()
  15942. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  15943. .end();
  15944. });
  15945. }
  15946. };
  15947. zoom.scaleBy = function(selection, k, p, event) {
  15948. zoom.scaleTo(selection, function() {
  15949. var k0 = this.__zoom.k,
  15950. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  15951. return k0 * k1;
  15952. }, p, event);
  15953. };
  15954. zoom.scaleTo = function(selection, k, p, event) {
  15955. zoom.transform(selection, function() {
  15956. var e = extent.apply(this, arguments),
  15957. t0 = this.__zoom,
  15958. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
  15959. p1 = t0.invert(p0),
  15960. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  15961. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  15962. }, p, event);
  15963. };
  15964. zoom.translateBy = function(selection, x, y, event) {
  15965. zoom.transform(selection, function() {
  15966. return constrain(this.__zoom.translate(
  15967. typeof x === "function" ? x.apply(this, arguments) : x,
  15968. typeof y === "function" ? y.apply(this, arguments) : y
  15969. ), extent.apply(this, arguments), translateExtent);
  15970. }, null, event);
  15971. };
  15972. zoom.translateTo = function(selection, x, y, p, event) {
  15973. zoom.transform(selection, function() {
  15974. var e = extent.apply(this, arguments),
  15975. t = this.__zoom,
  15976. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
  15977. return constrain(identity$9.translate(p0[0], p0[1]).scale(t.k).translate(
  15978. typeof x === "function" ? -x.apply(this, arguments) : -x,
  15979. typeof y === "function" ? -y.apply(this, arguments) : -y
  15980. ), e, translateExtent);
  15981. }, p, event);
  15982. };
  15983. function scale(transform, k) {
  15984. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  15985. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  15986. }
  15987. function translate(transform, p0, p1) {
  15988. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  15989. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  15990. }
  15991. function centroid(extent) {
  15992. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  15993. }
  15994. function schedule(transition, transform, point, event) {
  15995. transition
  15996. .on("start.zoom", function() { gesture(this, arguments).event(event).start(); })
  15997. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).event(event).end(); })
  15998. .tween("zoom", function() {
  15999. var that = this,
  16000. args = arguments,
  16001. g = gesture(that, args).event(event),
  16002. e = extent.apply(that, args),
  16003. p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
  16004. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  16005. a = that.__zoom,
  16006. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  16007. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  16008. return function(t) {
  16009. if (t === 1) t = b; // Avoid rounding error on end.
  16010. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  16011. g.zoom(null, t);
  16012. };
  16013. });
  16014. }
  16015. function gesture(that, args, clean) {
  16016. return (!clean && that.__zooming) || new Gesture(that, args);
  16017. }
  16018. function Gesture(that, args) {
  16019. this.that = that;
  16020. this.args = args;
  16021. this.active = 0;
  16022. this.sourceEvent = null;
  16023. this.extent = extent.apply(that, args);
  16024. this.taps = 0;
  16025. }
  16026. Gesture.prototype = {
  16027. event: function(event) {
  16028. if (event) this.sourceEvent = event;
  16029. return this;
  16030. },
  16031. start: function() {
  16032. if (++this.active === 1) {
  16033. this.that.__zooming = this;
  16034. this.emit("start");
  16035. }
  16036. return this;
  16037. },
  16038. zoom: function(key, transform) {
  16039. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  16040. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  16041. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  16042. this.that.__zoom = transform;
  16043. this.emit("zoom");
  16044. return this;
  16045. },
  16046. end: function() {
  16047. if (--this.active === 0) {
  16048. delete this.that.__zooming;
  16049. this.emit("end");
  16050. }
  16051. return this;
  16052. },
  16053. emit: function(type) {
  16054. var d = select(this.that).datum();
  16055. listeners.call(
  16056. type,
  16057. this.that,
  16058. new ZoomEvent(type, {
  16059. sourceEvent: this.sourceEvent,
  16060. target: zoom,
  16061. type,
  16062. transform: this.that.__zoom,
  16063. dispatch: listeners
  16064. }),
  16065. d
  16066. );
  16067. }
  16068. };
  16069. function wheeled(event, ...args) {
  16070. if (!filter.apply(this, arguments)) return;
  16071. var g = gesture(this, args).event(event),
  16072. t = this.__zoom,
  16073. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  16074. p = pointer(event);
  16075. // If the mouse is in the same location as before, reuse it.
  16076. // If there were recent wheel events, reset the wheel idle timeout.
  16077. if (g.wheel) {
  16078. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  16079. g.mouse[1] = t.invert(g.mouse[0] = p);
  16080. }
  16081. clearTimeout(g.wheel);
  16082. }
  16083. // If this wheel event won’t trigger a transform change, ignore it.
  16084. else if (t.k === k) return;
  16085. // Otherwise, capture the mouse point and location at the start.
  16086. else {
  16087. g.mouse = [p, t.invert(p)];
  16088. interrupt(this);
  16089. g.start();
  16090. }
  16091. noevent$2(event);
  16092. g.wheel = setTimeout(wheelidled, wheelDelay);
  16093. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  16094. function wheelidled() {
  16095. g.wheel = null;
  16096. g.end();
  16097. }
  16098. }
  16099. function mousedowned(event, ...args) {
  16100. if (touchending || !filter.apply(this, arguments)) return;
  16101. var g = gesture(this, args, true).event(event),
  16102. v = select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  16103. p = pointer(event, currentTarget),
  16104. currentTarget = event.currentTarget,
  16105. x0 = event.clientX,
  16106. y0 = event.clientY;
  16107. dragDisable(event.view);
  16108. nopropagation$2(event);
  16109. g.mouse = [p, this.__zoom.invert(p)];
  16110. interrupt(this);
  16111. g.start();
  16112. function mousemoved(event) {
  16113. noevent$2(event);
  16114. if (!g.moved) {
  16115. var dx = event.clientX - x0, dy = event.clientY - y0;
  16116. g.moved = dx * dx + dy * dy > clickDistance2;
  16117. }
  16118. g.event(event)
  16119. .zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = pointer(event, currentTarget), g.mouse[1]), g.extent, translateExtent));
  16120. }
  16121. function mouseupped(event) {
  16122. v.on("mousemove.zoom mouseup.zoom", null);
  16123. yesdrag(event.view, g.moved);
  16124. noevent$2(event);
  16125. g.event(event).end();
  16126. }
  16127. }
  16128. function dblclicked(event, ...args) {
  16129. if (!filter.apply(this, arguments)) return;
  16130. var t0 = this.__zoom,
  16131. p0 = pointer(event.changedTouches ? event.changedTouches[0] : event, this),
  16132. p1 = t0.invert(p0),
  16133. k1 = t0.k * (event.shiftKey ? 0.5 : 2),
  16134. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, args), translateExtent);
  16135. noevent$2(event);
  16136. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0, event);
  16137. else select(this).call(zoom.transform, t1, p0, event);
  16138. }
  16139. function touchstarted(event, ...args) {
  16140. if (!filter.apply(this, arguments)) return;
  16141. var touches = event.touches,
  16142. n = touches.length,
  16143. g = gesture(this, args, event.changedTouches.length === n).event(event),
  16144. started, i, t, p;
  16145. nopropagation$2(event);
  16146. for (i = 0; i < n; ++i) {
  16147. t = touches[i], p = pointer(t, this);
  16148. p = [p, this.__zoom.invert(p), t.identifier];
  16149. if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
  16150. else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
  16151. }
  16152. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  16153. if (started) {
  16154. if (g.taps < 2) touchfirst = p[0], touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  16155. interrupt(this);
  16156. g.start();
  16157. }
  16158. }
  16159. function touchmoved(event, ...args) {
  16160. if (!this.__zooming) return;
  16161. var g = gesture(this, args).event(event),
  16162. touches = event.changedTouches,
  16163. n = touches.length, i, t, p, l;
  16164. noevent$2(event);
  16165. for (i = 0; i < n; ++i) {
  16166. t = touches[i], p = pointer(t, this);
  16167. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  16168. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  16169. }
  16170. t = g.that.__zoom;
  16171. if (g.touch1) {
  16172. var p0 = g.touch0[0], l0 = g.touch0[1],
  16173. p1 = g.touch1[0], l1 = g.touch1[1],
  16174. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  16175. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  16176. t = scale(t, Math.sqrt(dp / dl));
  16177. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  16178. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  16179. }
  16180. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  16181. else return;
  16182. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  16183. }
  16184. function touchended(event, ...args) {
  16185. if (!this.__zooming) return;
  16186. var g = gesture(this, args).event(event),
  16187. touches = event.changedTouches,
  16188. n = touches.length, i, t;
  16189. nopropagation$2(event);
  16190. if (touchending) clearTimeout(touchending);
  16191. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  16192. for (i = 0; i < n; ++i) {
  16193. t = touches[i];
  16194. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  16195. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  16196. }
  16197. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  16198. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  16199. else {
  16200. g.end();
  16201. // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
  16202. if (g.taps === 2) {
  16203. t = pointer(t, this);
  16204. if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) {
  16205. var p = select(this).on("dblclick.zoom");
  16206. if (p) p.apply(this, arguments);
  16207. }
  16208. }
  16209. }
  16210. }
  16211. zoom.wheelDelta = function(_) {
  16212. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$b(+_), zoom) : wheelDelta;
  16213. };
  16214. zoom.filter = function(_) {
  16215. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$b(!!_), zoom) : filter;
  16216. };
  16217. zoom.touchable = function(_) {
  16218. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$b(!!_), zoom) : touchable;
  16219. };
  16220. zoom.extent = function(_) {
  16221. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$b([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  16222. };
  16223. zoom.scaleExtent = function(_) {
  16224. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  16225. };
  16226. zoom.translateExtent = function(_) {
  16227. 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]]];
  16228. };
  16229. zoom.constrain = function(_) {
  16230. return arguments.length ? (constrain = _, zoom) : constrain;
  16231. };
  16232. zoom.duration = function(_) {
  16233. return arguments.length ? (duration = +_, zoom) : duration;
  16234. };
  16235. zoom.interpolate = function(_) {
  16236. return arguments.length ? (interpolate = _, zoom) : interpolate;
  16237. };
  16238. zoom.on = function() {
  16239. var value = listeners.on.apply(listeners, arguments);
  16240. return value === listeners ? zoom : value;
  16241. };
  16242. zoom.clickDistance = function(_) {
  16243. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  16244. };
  16245. zoom.tapDistance = function(_) {
  16246. return arguments.length ? (tapDistance = +_, zoom) : tapDistance;
  16247. };
  16248. return zoom;
  16249. }
  16250. exports.Adder = Adder;
  16251. exports.Delaunay = Delaunay;
  16252. exports.FormatSpecifier = FormatSpecifier;
  16253. exports.Voronoi = Voronoi;
  16254. exports.active = active;
  16255. exports.arc = arc;
  16256. exports.area = area$3;
  16257. exports.areaRadial = areaRadial;
  16258. exports.ascending = ascending;
  16259. exports.autoType = autoType;
  16260. exports.axisBottom = axisBottom;
  16261. exports.axisLeft = axisLeft;
  16262. exports.axisRight = axisRight;
  16263. exports.axisTop = axisTop;
  16264. exports.bin = bin;
  16265. exports.bisect = bisectRight;
  16266. exports.bisectCenter = bisectCenter;
  16267. exports.bisectLeft = bisectLeft;
  16268. exports.bisectRight = bisectRight;
  16269. exports.bisector = bisector;
  16270. exports.blob = blob;
  16271. exports.brush = brush;
  16272. exports.brushSelection = brushSelection;
  16273. exports.brushX = brushX;
  16274. exports.brushY = brushY;
  16275. exports.buffer = buffer;
  16276. exports.chord = chord;
  16277. exports.chordDirected = chordDirected;
  16278. exports.chordTranspose = chordTranspose;
  16279. exports.cluster = cluster;
  16280. exports.color = color;
  16281. exports.contourDensity = density;
  16282. exports.contours = contours;
  16283. exports.count = count;
  16284. exports.create = create;
  16285. exports.creator = creator;
  16286. exports.cross = cross;
  16287. exports.csv = csv$1;
  16288. exports.csvFormat = csvFormat;
  16289. exports.csvFormatBody = csvFormatBody;
  16290. exports.csvFormatRow = csvFormatRow;
  16291. exports.csvFormatRows = csvFormatRows;
  16292. exports.csvFormatValue = csvFormatValue;
  16293. exports.csvParse = csvParse;
  16294. exports.csvParseRows = csvParseRows;
  16295. exports.cubehelix = cubehelix;
  16296. exports.cumsum = cumsum;
  16297. exports.curveBasis = basis$2;
  16298. exports.curveBasisClosed = basisClosed$1;
  16299. exports.curveBasisOpen = basisOpen;
  16300. exports.curveBundle = bundle;
  16301. exports.curveCardinal = cardinal;
  16302. exports.curveCardinalClosed = cardinalClosed;
  16303. exports.curveCardinalOpen = cardinalOpen;
  16304. exports.curveCatmullRom = catmullRom;
  16305. exports.curveCatmullRomClosed = catmullRomClosed;
  16306. exports.curveCatmullRomOpen = catmullRomOpen;
  16307. exports.curveLinear = curveLinear;
  16308. exports.curveLinearClosed = linearClosed;
  16309. exports.curveMonotoneX = monotoneX;
  16310. exports.curveMonotoneY = monotoneY;
  16311. exports.curveNatural = natural;
  16312. exports.curveStep = step;
  16313. exports.curveStepAfter = stepAfter;
  16314. exports.curveStepBefore = stepBefore;
  16315. exports.descending = descending;
  16316. exports.deviation = deviation;
  16317. exports.difference = difference;
  16318. exports.disjoint = disjoint;
  16319. exports.dispatch = dispatch;
  16320. exports.drag = drag;
  16321. exports.dragDisable = dragDisable;
  16322. exports.dragEnable = yesdrag;
  16323. exports.dsv = dsv;
  16324. exports.dsvFormat = dsvFormat;
  16325. exports.easeBack = backInOut;
  16326. exports.easeBackIn = backIn;
  16327. exports.easeBackInOut = backInOut;
  16328. exports.easeBackOut = backOut;
  16329. exports.easeBounce = bounceOut;
  16330. exports.easeBounceIn = bounceIn;
  16331. exports.easeBounceInOut = bounceInOut;
  16332. exports.easeBounceOut = bounceOut;
  16333. exports.easeCircle = circleInOut;
  16334. exports.easeCircleIn = circleIn;
  16335. exports.easeCircleInOut = circleInOut;
  16336. exports.easeCircleOut = circleOut;
  16337. exports.easeCubic = cubicInOut;
  16338. exports.easeCubicIn = cubicIn;
  16339. exports.easeCubicInOut = cubicInOut;
  16340. exports.easeCubicOut = cubicOut;
  16341. exports.easeElastic = elasticOut;
  16342. exports.easeElasticIn = elasticIn;
  16343. exports.easeElasticInOut = elasticInOut;
  16344. exports.easeElasticOut = elasticOut;
  16345. exports.easeExp = expInOut;
  16346. exports.easeExpIn = expIn;
  16347. exports.easeExpInOut = expInOut;
  16348. exports.easeExpOut = expOut;
  16349. exports.easeLinear = linear$1;
  16350. exports.easePoly = polyInOut;
  16351. exports.easePolyIn = polyIn;
  16352. exports.easePolyInOut = polyInOut;
  16353. exports.easePolyOut = polyOut;
  16354. exports.easeQuad = quadInOut;
  16355. exports.easeQuadIn = quadIn;
  16356. exports.easeQuadInOut = quadInOut;
  16357. exports.easeQuadOut = quadOut;
  16358. exports.easeSin = sinInOut;
  16359. exports.easeSinIn = sinIn;
  16360. exports.easeSinInOut = sinInOut;
  16361. exports.easeSinOut = sinOut;
  16362. exports.every = every;
  16363. exports.extent = extent;
  16364. exports.filter = filter;
  16365. exports.forceCenter = center$1;
  16366. exports.forceCollide = collide;
  16367. exports.forceLink = link;
  16368. exports.forceManyBody = manyBody;
  16369. exports.forceRadial = radial;
  16370. exports.forceSimulation = simulation;
  16371. exports.forceX = x$2;
  16372. exports.forceY = y$2;
  16373. exports.formatDefaultLocale = defaultLocale;
  16374. exports.formatLocale = formatLocale;
  16375. exports.formatSpecifier = formatSpecifier;
  16376. exports.fsum = fsum;
  16377. exports.geoAlbers = albers;
  16378. exports.geoAlbersUsa = albersUsa;
  16379. exports.geoArea = area$1;
  16380. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  16381. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  16382. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  16383. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  16384. exports.geoBounds = bounds;
  16385. exports.geoCentroid = centroid;
  16386. exports.geoCircle = circle;
  16387. exports.geoClipAntimeridian = clipAntimeridian;
  16388. exports.geoClipCircle = clipCircle;
  16389. exports.geoClipExtent = extent$1;
  16390. exports.geoClipRectangle = clipRectangle;
  16391. exports.geoConicConformal = conicConformal;
  16392. exports.geoConicConformalRaw = conicConformalRaw;
  16393. exports.geoConicEqualArea = conicEqualArea;
  16394. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  16395. exports.geoConicEquidistant = conicEquidistant;
  16396. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  16397. exports.geoContains = contains$1;
  16398. exports.geoDistance = distance;
  16399. exports.geoEqualEarth = equalEarth;
  16400. exports.geoEqualEarthRaw = equalEarthRaw;
  16401. exports.geoEquirectangular = equirectangular;
  16402. exports.geoEquirectangularRaw = equirectangularRaw;
  16403. exports.geoGnomonic = gnomonic;
  16404. exports.geoGnomonicRaw = gnomonicRaw;
  16405. exports.geoGraticule = graticule;
  16406. exports.geoGraticule10 = graticule10;
  16407. exports.geoIdentity = identity$5;
  16408. exports.geoInterpolate = interpolate$2;
  16409. exports.geoLength = length$2;
  16410. exports.geoMercator = mercator;
  16411. exports.geoMercatorRaw = mercatorRaw;
  16412. exports.geoNaturalEarth1 = naturalEarth1;
  16413. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  16414. exports.geoOrthographic = orthographic;
  16415. exports.geoOrthographicRaw = orthographicRaw;
  16416. exports.geoPath = index$2;
  16417. exports.geoProjection = projection;
  16418. exports.geoProjectionMutator = projectionMutator;
  16419. exports.geoRotation = rotation;
  16420. exports.geoStereographic = stereographic;
  16421. exports.geoStereographicRaw = stereographicRaw;
  16422. exports.geoStream = geoStream;
  16423. exports.geoTransform = transform;
  16424. exports.geoTransverseMercator = transverseMercator;
  16425. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  16426. exports.gray = gray;
  16427. exports.greatest = greatest;
  16428. exports.greatestIndex = greatestIndex;
  16429. exports.group = group;
  16430. exports.groups = groups;
  16431. exports.hcl = hcl;
  16432. exports.hierarchy = hierarchy;
  16433. exports.histogram = bin;
  16434. exports.hsl = hsl;
  16435. exports.html = html;
  16436. exports.image = image;
  16437. exports.index = index;
  16438. exports.indexes = indexes;
  16439. exports.interpolate = interpolate;
  16440. exports.interpolateArray = array$2;
  16441. exports.interpolateBasis = basis$1;
  16442. exports.interpolateBasisClosed = basisClosed;
  16443. exports.interpolateBlues = Blues;
  16444. exports.interpolateBrBG = BrBG;
  16445. exports.interpolateBuGn = BuGn;
  16446. exports.interpolateBuPu = BuPu;
  16447. exports.interpolateCividis = cividis;
  16448. exports.interpolateCool = cool;
  16449. exports.interpolateCubehelix = cubehelix$2;
  16450. exports.interpolateCubehelixDefault = cubehelix$3;
  16451. exports.interpolateCubehelixLong = cubehelixLong;
  16452. exports.interpolateDate = date;
  16453. exports.interpolateDiscrete = discrete;
  16454. exports.interpolateGnBu = GnBu;
  16455. exports.interpolateGreens = Greens;
  16456. exports.interpolateGreys = Greys;
  16457. exports.interpolateHcl = hcl$2;
  16458. exports.interpolateHclLong = hclLong;
  16459. exports.interpolateHsl = hsl$2;
  16460. exports.interpolateHslLong = hslLong;
  16461. exports.interpolateHue = hue$1;
  16462. exports.interpolateInferno = inferno;
  16463. exports.interpolateLab = lab$1;
  16464. exports.interpolateMagma = magma;
  16465. exports.interpolateNumber = interpolateNumber;
  16466. exports.interpolateNumberArray = numberArray;
  16467. exports.interpolateObject = object;
  16468. exports.interpolateOrRd = OrRd;
  16469. exports.interpolateOranges = Oranges;
  16470. exports.interpolatePRGn = PRGn;
  16471. exports.interpolatePiYG = PiYG;
  16472. exports.interpolatePlasma = plasma;
  16473. exports.interpolatePuBu = PuBu;
  16474. exports.interpolatePuBuGn = PuBuGn;
  16475. exports.interpolatePuOr = PuOr;
  16476. exports.interpolatePuRd = PuRd;
  16477. exports.interpolatePurples = Purples;
  16478. exports.interpolateRainbow = rainbow;
  16479. exports.interpolateRdBu = RdBu;
  16480. exports.interpolateRdGy = RdGy;
  16481. exports.interpolateRdPu = RdPu;
  16482. exports.interpolateRdYlBu = RdYlBu;
  16483. exports.interpolateRdYlGn = RdYlGn;
  16484. exports.interpolateReds = Reds;
  16485. exports.interpolateRgb = interpolateRgb;
  16486. exports.interpolateRgbBasis = rgbBasis;
  16487. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  16488. exports.interpolateRound = interpolateRound;
  16489. exports.interpolateSinebow = sinebow;
  16490. exports.interpolateSpectral = Spectral;
  16491. exports.interpolateString = interpolateString;
  16492. exports.interpolateTransformCss = interpolateTransformCss;
  16493. exports.interpolateTransformSvg = interpolateTransformSvg;
  16494. exports.interpolateTurbo = turbo;
  16495. exports.interpolateViridis = viridis;
  16496. exports.interpolateWarm = warm;
  16497. exports.interpolateYlGn = YlGn;
  16498. exports.interpolateYlGnBu = YlGnBu;
  16499. exports.interpolateYlOrBr = YlOrBr;
  16500. exports.interpolateYlOrRd = YlOrRd;
  16501. exports.interpolateZoom = interpolateZoom;
  16502. exports.interrupt = interrupt;
  16503. exports.intersection = intersection;
  16504. exports.interval = interval$1;
  16505. exports.isoFormat = formatIso;
  16506. exports.isoParse = parseIso;
  16507. exports.json = json;
  16508. exports.lab = lab;
  16509. exports.lch = lch;
  16510. exports.least = least;
  16511. exports.leastIndex = leastIndex;
  16512. exports.line = line;
  16513. exports.lineRadial = lineRadial$1;
  16514. exports.linkHorizontal = linkHorizontal;
  16515. exports.linkRadial = linkRadial;
  16516. exports.linkVertical = linkVertical;
  16517. exports.local = local;
  16518. exports.map = map;
  16519. exports.matcher = matcher;
  16520. exports.max = max;
  16521. exports.maxIndex = maxIndex;
  16522. exports.mean = mean;
  16523. exports.median = median;
  16524. exports.merge = merge;
  16525. exports.min = min;
  16526. exports.minIndex = minIndex;
  16527. exports.namespace = namespace;
  16528. exports.namespaces = namespaces;
  16529. exports.nice = nice;
  16530. exports.now = now;
  16531. exports.pack = index$3;
  16532. exports.packEnclose = enclose;
  16533. exports.packSiblings = siblings;
  16534. exports.pairs = pairs;
  16535. exports.partition = partition;
  16536. exports.path = path;
  16537. exports.permute = permute;
  16538. exports.pie = pie;
  16539. exports.piecewise = piecewise;
  16540. exports.pointRadial = pointRadial;
  16541. exports.pointer = pointer;
  16542. exports.pointers = pointers;
  16543. exports.polygonArea = area$2;
  16544. exports.polygonCentroid = centroid$1;
  16545. exports.polygonContains = contains$2;
  16546. exports.polygonHull = hull;
  16547. exports.polygonLength = length$3;
  16548. exports.precisionFixed = precisionFixed;
  16549. exports.precisionPrefix = precisionPrefix;
  16550. exports.precisionRound = precisionRound;
  16551. exports.quadtree = quadtree;
  16552. exports.quantile = quantile;
  16553. exports.quantileSorted = quantileSorted;
  16554. exports.quantize = quantize;
  16555. exports.quickselect = quickselect;
  16556. exports.radialArea = areaRadial;
  16557. exports.radialLine = lineRadial$1;
  16558. exports.randomBates = bates;
  16559. exports.randomBernoulli = bernoulli;
  16560. exports.randomBeta = beta;
  16561. exports.randomBinomial = binomial;
  16562. exports.randomCauchy = cauchy;
  16563. exports.randomExponential = exponential$1;
  16564. exports.randomGamma = gamma$1;
  16565. exports.randomGeometric = geometric;
  16566. exports.randomInt = int;
  16567. exports.randomIrwinHall = irwinHall;
  16568. exports.randomLcg = lcg$1;
  16569. exports.randomLogNormal = logNormal;
  16570. exports.randomLogistic = logistic;
  16571. exports.randomNormal = normal;
  16572. exports.randomPareto = pareto;
  16573. exports.randomPoisson = poisson;
  16574. exports.randomUniform = uniform;
  16575. exports.randomWeibull = weibull;
  16576. exports.range = sequence;
  16577. exports.reduce = reduce;
  16578. exports.reverse = reverse;
  16579. exports.rgb = rgb;
  16580. exports.ribbon = ribbon$1;
  16581. exports.ribbonArrow = ribbonArrow;
  16582. exports.rollup = rollup;
  16583. exports.rollups = rollups;
  16584. exports.scaleBand = band;
  16585. exports.scaleDiverging = diverging;
  16586. exports.scaleDivergingLog = divergingLog;
  16587. exports.scaleDivergingPow = divergingPow;
  16588. exports.scaleDivergingSqrt = divergingSqrt;
  16589. exports.scaleDivergingSymlog = divergingSymlog;
  16590. exports.scaleIdentity = identity$7;
  16591. exports.scaleImplicit = implicit;
  16592. exports.scaleLinear = linear$2;
  16593. exports.scaleLog = log$1;
  16594. exports.scaleOrdinal = ordinal;
  16595. exports.scalePoint = point;
  16596. exports.scalePow = pow$2;
  16597. exports.scaleQuantile = quantile$1;
  16598. exports.scaleQuantize = quantize$1;
  16599. exports.scaleRadial = radial$1;
  16600. exports.scaleSequential = sequential;
  16601. exports.scaleSequentialLog = sequentialLog;
  16602. exports.scaleSequentialPow = sequentialPow;
  16603. exports.scaleSequentialQuantile = sequentialQuantile;
  16604. exports.scaleSequentialSqrt = sequentialSqrt;
  16605. exports.scaleSequentialSymlog = sequentialSymlog;
  16606. exports.scaleSqrt = sqrt$1;
  16607. exports.scaleSymlog = symlog;
  16608. exports.scaleThreshold = threshold;
  16609. exports.scaleTime = time;
  16610. exports.scaleUtc = utcTime;
  16611. exports.scan = scan;
  16612. exports.schemeAccent = Accent;
  16613. exports.schemeBlues = scheme$l;
  16614. exports.schemeBrBG = scheme;
  16615. exports.schemeBuGn = scheme$9;
  16616. exports.schemeBuPu = scheme$a;
  16617. exports.schemeCategory10 = category10;
  16618. exports.schemeDark2 = Dark2;
  16619. exports.schemeGnBu = scheme$b;
  16620. exports.schemeGreens = scheme$m;
  16621. exports.schemeGreys = scheme$n;
  16622. exports.schemeOrRd = scheme$c;
  16623. exports.schemeOranges = scheme$q;
  16624. exports.schemePRGn = scheme$1;
  16625. exports.schemePaired = Paired;
  16626. exports.schemePastel1 = Pastel1;
  16627. exports.schemePastel2 = Pastel2;
  16628. exports.schemePiYG = scheme$2;
  16629. exports.schemePuBu = scheme$e;
  16630. exports.schemePuBuGn = scheme$d;
  16631. exports.schemePuOr = scheme$3;
  16632. exports.schemePuRd = scheme$f;
  16633. exports.schemePurples = scheme$o;
  16634. exports.schemeRdBu = scheme$4;
  16635. exports.schemeRdGy = scheme$5;
  16636. exports.schemeRdPu = scheme$g;
  16637. exports.schemeRdYlBu = scheme$6;
  16638. exports.schemeRdYlGn = scheme$7;
  16639. exports.schemeReds = scheme$p;
  16640. exports.schemeSet1 = Set1;
  16641. exports.schemeSet2 = Set2;
  16642. exports.schemeSet3 = Set3;
  16643. exports.schemeSpectral = scheme$8;
  16644. exports.schemeTableau10 = Tableau10;
  16645. exports.schemeYlGn = scheme$i;
  16646. exports.schemeYlGnBu = scheme$h;
  16647. exports.schemeYlOrBr = scheme$j;
  16648. exports.schemeYlOrRd = scheme$k;
  16649. exports.select = select;
  16650. exports.selectAll = selectAll;
  16651. exports.selection = selection;
  16652. exports.selector = selector;
  16653. exports.selectorAll = selectorAll;
  16654. exports.shuffle = shuffle;
  16655. exports.shuffler = shuffler;
  16656. exports.some = some;
  16657. exports.sort = sort;
  16658. exports.stack = stack;
  16659. exports.stackOffsetDiverging = diverging$1;
  16660. exports.stackOffsetExpand = expand;
  16661. exports.stackOffsetNone = none$1;
  16662. exports.stackOffsetSilhouette = silhouette;
  16663. exports.stackOffsetWiggle = wiggle;
  16664. exports.stackOrderAppearance = appearance;
  16665. exports.stackOrderAscending = ascending$3;
  16666. exports.stackOrderDescending = descending$2;
  16667. exports.stackOrderInsideOut = insideOut;
  16668. exports.stackOrderNone = none$2;
  16669. exports.stackOrderReverse = reverse$1;
  16670. exports.stratify = stratify;
  16671. exports.style = styleValue;
  16672. exports.subset = subset;
  16673. exports.sum = sum;
  16674. exports.superset = superset;
  16675. exports.svg = svg;
  16676. exports.symbol = symbol;
  16677. exports.symbolCircle = circle$2;
  16678. exports.symbolCross = cross$2;
  16679. exports.symbolDiamond = diamond;
  16680. exports.symbolSquare = square$1;
  16681. exports.symbolStar = star;
  16682. exports.symbolTriangle = triangle;
  16683. exports.symbolWye = wye;
  16684. exports.symbols = symbols;
  16685. exports.text = text;
  16686. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  16687. exports.thresholdScott = scott;
  16688. exports.thresholdSturges = thresholdSturges;
  16689. exports.tickFormat = tickFormat;
  16690. exports.tickIncrement = tickIncrement;
  16691. exports.tickStep = tickStep;
  16692. exports.ticks = ticks;
  16693. exports.timeDay = day;
  16694. exports.timeDays = days;
  16695. exports.timeFormatDefaultLocale = defaultLocale$1;
  16696. exports.timeFormatLocale = formatLocale$1;
  16697. exports.timeFriday = friday;
  16698. exports.timeFridays = fridays;
  16699. exports.timeHour = hour;
  16700. exports.timeHours = hours;
  16701. exports.timeInterval = newInterval;
  16702. exports.timeMillisecond = millisecond;
  16703. exports.timeMilliseconds = milliseconds;
  16704. exports.timeMinute = minute;
  16705. exports.timeMinutes = minutes;
  16706. exports.timeMonday = monday;
  16707. exports.timeMondays = mondays;
  16708. exports.timeMonth = month;
  16709. exports.timeMonths = months;
  16710. exports.timeSaturday = saturday;
  16711. exports.timeSaturdays = saturdays;
  16712. exports.timeSecond = second;
  16713. exports.timeSeconds = seconds;
  16714. exports.timeSunday = sunday;
  16715. exports.timeSundays = sundays;
  16716. exports.timeThursday = thursday;
  16717. exports.timeThursdays = thursdays;
  16718. exports.timeTuesday = tuesday;
  16719. exports.timeTuesdays = tuesdays;
  16720. exports.timeWednesday = wednesday;
  16721. exports.timeWednesdays = wednesdays;
  16722. exports.timeWeek = sunday;
  16723. exports.timeWeeks = sundays;
  16724. exports.timeYear = year;
  16725. exports.timeYears = years;
  16726. exports.timeout = timeout$1;
  16727. exports.timer = timer;
  16728. exports.timerFlush = timerFlush;
  16729. exports.transition = transition;
  16730. exports.transpose = transpose;
  16731. exports.tree = tree;
  16732. exports.treemap = index$4;
  16733. exports.treemapBinary = binary;
  16734. exports.treemapDice = treemapDice;
  16735. exports.treemapResquarify = resquarify;
  16736. exports.treemapSlice = treemapSlice;
  16737. exports.treemapSliceDice = sliceDice;
  16738. exports.treemapSquarify = squarify;
  16739. exports.tsv = tsv$1;
  16740. exports.tsvFormat = tsvFormat;
  16741. exports.tsvFormatBody = tsvFormatBody;
  16742. exports.tsvFormatRow = tsvFormatRow;
  16743. exports.tsvFormatRows = tsvFormatRows;
  16744. exports.tsvFormatValue = tsvFormatValue;
  16745. exports.tsvParse = tsvParse;
  16746. exports.tsvParseRows = tsvParseRows;
  16747. exports.union = union;
  16748. exports.utcDay = utcDay;
  16749. exports.utcDays = utcDays;
  16750. exports.utcFriday = utcFriday;
  16751. exports.utcFridays = utcFridays;
  16752. exports.utcHour = utcHour;
  16753. exports.utcHours = utcHours;
  16754. exports.utcMillisecond = millisecond;
  16755. exports.utcMilliseconds = milliseconds;
  16756. exports.utcMinute = utcMinute;
  16757. exports.utcMinutes = utcMinutes;
  16758. exports.utcMonday = utcMonday;
  16759. exports.utcMondays = utcMondays;
  16760. exports.utcMonth = utcMonth;
  16761. exports.utcMonths = utcMonths;
  16762. exports.utcSaturday = utcSaturday;
  16763. exports.utcSaturdays = utcSaturdays;
  16764. exports.utcSecond = second;
  16765. exports.utcSeconds = seconds;
  16766. exports.utcSunday = utcSunday;
  16767. exports.utcSundays = utcSundays;
  16768. exports.utcThursday = utcThursday;
  16769. exports.utcThursdays = utcThursdays;
  16770. exports.utcTuesday = utcTuesday;
  16771. exports.utcTuesdays = utcTuesdays;
  16772. exports.utcWednesday = utcWednesday;
  16773. exports.utcWednesdays = utcWednesdays;
  16774. exports.utcWeek = utcSunday;
  16775. exports.utcWeeks = utcSundays;
  16776. exports.utcYear = utcYear;
  16777. exports.utcYears = utcYears;
  16778. exports.variance = variance;
  16779. exports.version = version;
  16780. exports.window = defaultView;
  16781. exports.xml = xml;
  16782. exports.zip = zip;
  16783. exports.zoom = zoom;
  16784. exports.zoomIdentity = identity$9;
  16785. exports.zoomTransform = transform$1;
  16786. Object.defineProperty(exports, '__esModule', { value: true });
  16787. })));