Node-Red configuration
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625
  1. // https://d3js.org v7.9.0 Copyright 2010-2023 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
  6. })(this, (function (exports) { 'use strict';
  7. var version = "7.9.0";
  8. function ascending$3(a, b) {
  9. return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function descending$2(a, b) {
  12. return a == null || b == null ? NaN
  13. : b < a ? -1
  14. : b > a ? 1
  15. : b >= a ? 0
  16. : NaN;
  17. }
  18. function bisector(f) {
  19. let compare1, compare2, delta;
  20. // If an accessor is specified, promote it to a comparator. In this case we
  21. // can test whether the search value is (self-) comparable. We can’t do this
  22. // for a comparator (except for specific, known comparators) because we can’t
  23. // tell if the comparator is symmetric, and an asymmetric comparator can’t be
  24. // used to test whether a single value is comparable.
  25. if (f.length !== 2) {
  26. compare1 = ascending$3;
  27. compare2 = (d, x) => ascending$3(f(d), x);
  28. delta = (d, x) => f(d) - x;
  29. } else {
  30. compare1 = f === ascending$3 || f === descending$2 ? f : zero$1;
  31. compare2 = f;
  32. delta = f;
  33. }
  34. function left(a, x, lo = 0, hi = a.length) {
  35. if (lo < hi) {
  36. if (compare1(x, x) !== 0) return hi;
  37. do {
  38. const mid = (lo + hi) >>> 1;
  39. if (compare2(a[mid], x) < 0) lo = mid + 1;
  40. else hi = mid;
  41. } while (lo < hi);
  42. }
  43. return lo;
  44. }
  45. function right(a, x, lo = 0, hi = a.length) {
  46. if (lo < hi) {
  47. if (compare1(x, x) !== 0) return hi;
  48. do {
  49. const mid = (lo + hi) >>> 1;
  50. if (compare2(a[mid], x) <= 0) lo = mid + 1;
  51. else hi = mid;
  52. } while (lo < hi);
  53. }
  54. return lo;
  55. }
  56. function center(a, x, lo = 0, hi = a.length) {
  57. const i = left(a, x, lo, hi - 1);
  58. return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
  59. }
  60. return {left, center, right};
  61. }
  62. function zero$1() {
  63. return 0;
  64. }
  65. function number$3(x) {
  66. return x === null ? NaN : +x;
  67. }
  68. function* numbers(values, valueof) {
  69. if (valueof === undefined) {
  70. for (let value of values) {
  71. if (value != null && (value = +value) >= value) {
  72. yield value;
  73. }
  74. }
  75. } else {
  76. let index = -1;
  77. for (let value of values) {
  78. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  79. yield value;
  80. }
  81. }
  82. }
  83. }
  84. const ascendingBisect = bisector(ascending$3);
  85. const bisectRight = ascendingBisect.right;
  86. const bisectLeft = ascendingBisect.left;
  87. const bisectCenter = bisector(number$3).center;
  88. var bisect = bisectRight;
  89. function blur(values, r) {
  90. if (!((r = +r) >= 0)) throw new RangeError("invalid r");
  91. let length = values.length;
  92. if (!((length = Math.floor(length)) >= 0)) throw new RangeError("invalid length");
  93. if (!length || !r) return values;
  94. const blur = blurf(r);
  95. const temp = values.slice();
  96. blur(values, temp, 0, length, 1);
  97. blur(temp, values, 0, length, 1);
  98. blur(values, temp, 0, length, 1);
  99. return values;
  100. }
  101. const blur2 = Blur2(blurf);
  102. const blurImage = Blur2(blurfImage);
  103. function Blur2(blur) {
  104. return function(data, rx, ry = rx) {
  105. if (!((rx = +rx) >= 0)) throw new RangeError("invalid rx");
  106. if (!((ry = +ry) >= 0)) throw new RangeError("invalid ry");
  107. let {data: values, width, height} = data;
  108. if (!((width = Math.floor(width)) >= 0)) throw new RangeError("invalid width");
  109. if (!((height = Math.floor(height !== undefined ? height : values.length / width)) >= 0)) throw new RangeError("invalid height");
  110. if (!width || !height || (!rx && !ry)) return data;
  111. const blurx = rx && blur(rx);
  112. const blury = ry && blur(ry);
  113. const temp = values.slice();
  114. if (blurx && blury) {
  115. blurh(blurx, temp, values, width, height);
  116. blurh(blurx, values, temp, width, height);
  117. blurh(blurx, temp, values, width, height);
  118. blurv(blury, values, temp, width, height);
  119. blurv(blury, temp, values, width, height);
  120. blurv(blury, values, temp, width, height);
  121. } else if (blurx) {
  122. blurh(blurx, values, temp, width, height);
  123. blurh(blurx, temp, values, width, height);
  124. blurh(blurx, values, temp, width, height);
  125. } else if (blury) {
  126. blurv(blury, values, temp, width, height);
  127. blurv(blury, temp, values, width, height);
  128. blurv(blury, values, temp, width, height);
  129. }
  130. return data;
  131. };
  132. }
  133. function blurh(blur, T, S, w, h) {
  134. for (let y = 0, n = w * h; y < n;) {
  135. blur(T, S, y, y += w, 1);
  136. }
  137. }
  138. function blurv(blur, T, S, w, h) {
  139. for (let x = 0, n = w * h; x < w; ++x) {
  140. blur(T, S, x, x + n, w);
  141. }
  142. }
  143. function blurfImage(radius) {
  144. const blur = blurf(radius);
  145. return (T, S, start, stop, step) => {
  146. start <<= 2, stop <<= 2, step <<= 2;
  147. blur(T, S, start + 0, stop + 0, step);
  148. blur(T, S, start + 1, stop + 1, step);
  149. blur(T, S, start + 2, stop + 2, step);
  150. blur(T, S, start + 3, stop + 3, step);
  151. };
  152. }
  153. // Given a target array T, a source array S, sets each value T[i] to the average
  154. // of {S[i - r], …, S[i], …, S[i + r]}, where r = ⌊radius⌋, start <= i < stop,
  155. // for each i, i + step, i + 2 * step, etc., and where S[j] is clamped between
  156. // S[start] (inclusive) and S[stop] (exclusive). If the given radius is not an
  157. // integer, S[i - r - 1] and S[i + r + 1] are added to the sum, each weighted
  158. // according to r - ⌊radius⌋.
  159. function blurf(radius) {
  160. const radius0 = Math.floor(radius);
  161. if (radius0 === radius) return bluri(radius);
  162. const t = radius - radius0;
  163. const w = 2 * radius + 1;
  164. return (T, S, start, stop, step) => { // stop must be aligned!
  165. if (!((stop -= step) >= start)) return; // inclusive stop
  166. let sum = radius0 * S[start];
  167. const s0 = step * radius0;
  168. const s1 = s0 + step;
  169. for (let i = start, j = start + s0; i < j; i += step) {
  170. sum += S[Math.min(stop, i)];
  171. }
  172. for (let i = start, j = stop; i <= j; i += step) {
  173. sum += S[Math.min(stop, i + s0)];
  174. T[i] = (sum + t * (S[Math.max(start, i - s1)] + S[Math.min(stop, i + s1)])) / w;
  175. sum -= S[Math.max(start, i - s0)];
  176. }
  177. };
  178. }
  179. // Like blurf, but optimized for integer radius.
  180. function bluri(radius) {
  181. const w = 2 * radius + 1;
  182. return (T, S, start, stop, step) => { // stop must be aligned!
  183. if (!((stop -= step) >= start)) return; // inclusive stop
  184. let sum = radius * S[start];
  185. const s = step * radius;
  186. for (let i = start, j = start + s; i < j; i += step) {
  187. sum += S[Math.min(stop, i)];
  188. }
  189. for (let i = start, j = stop; i <= j; i += step) {
  190. sum += S[Math.min(stop, i + s)];
  191. T[i] = sum / w;
  192. sum -= S[Math.max(start, i - s)];
  193. }
  194. };
  195. }
  196. function count$1(values, valueof) {
  197. let count = 0;
  198. if (valueof === undefined) {
  199. for (let value of values) {
  200. if (value != null && (value = +value) >= value) {
  201. ++count;
  202. }
  203. }
  204. } else {
  205. let index = -1;
  206. for (let value of values) {
  207. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  208. ++count;
  209. }
  210. }
  211. }
  212. return count;
  213. }
  214. function length$3(array) {
  215. return array.length | 0;
  216. }
  217. function empty$2(length) {
  218. return !(length > 0);
  219. }
  220. function arrayify(values) {
  221. return typeof values !== "object" || "length" in values ? values : Array.from(values);
  222. }
  223. function reducer(reduce) {
  224. return values => reduce(...values);
  225. }
  226. function cross$2(...values) {
  227. const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
  228. values = values.map(arrayify);
  229. const lengths = values.map(length$3);
  230. const j = values.length - 1;
  231. const index = new Array(j + 1).fill(0);
  232. const product = [];
  233. if (j < 0 || lengths.some(empty$2)) return product;
  234. while (true) {
  235. product.push(index.map((j, i) => values[i][j]));
  236. let i = j;
  237. while (++index[i] === lengths[i]) {
  238. if (i === 0) return reduce ? product.map(reduce) : product;
  239. index[i--] = 0;
  240. }
  241. }
  242. }
  243. function cumsum(values, valueof) {
  244. var sum = 0, index = 0;
  245. return Float64Array.from(values, valueof === undefined
  246. ? v => (sum += +v || 0)
  247. : v => (sum += +valueof(v, index++, values) || 0));
  248. }
  249. function variance(values, valueof) {
  250. let count = 0;
  251. let delta;
  252. let mean = 0;
  253. let sum = 0;
  254. if (valueof === undefined) {
  255. for (let value of values) {
  256. if (value != null && (value = +value) >= value) {
  257. delta = value - mean;
  258. mean += delta / ++count;
  259. sum += delta * (value - mean);
  260. }
  261. }
  262. } else {
  263. let index = -1;
  264. for (let value of values) {
  265. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  266. delta = value - mean;
  267. mean += delta / ++count;
  268. sum += delta * (value - mean);
  269. }
  270. }
  271. }
  272. if (count > 1) return sum / (count - 1);
  273. }
  274. function deviation(values, valueof) {
  275. const v = variance(values, valueof);
  276. return v ? Math.sqrt(v) : v;
  277. }
  278. function extent$1(values, valueof) {
  279. let min;
  280. let max;
  281. if (valueof === undefined) {
  282. for (const value of values) {
  283. if (value != null) {
  284. if (min === undefined) {
  285. if (value >= value) min = max = value;
  286. } else {
  287. if (min > value) min = value;
  288. if (max < value) max = value;
  289. }
  290. }
  291. }
  292. } else {
  293. let index = -1;
  294. for (let value of values) {
  295. if ((value = valueof(value, ++index, values)) != null) {
  296. if (min === undefined) {
  297. if (value >= value) min = max = value;
  298. } else {
  299. if (min > value) min = value;
  300. if (max < value) max = value;
  301. }
  302. }
  303. }
  304. }
  305. return [min, max];
  306. }
  307. // https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Modules/mathmodule.c#L1423
  308. class Adder {
  309. constructor() {
  310. this._partials = new Float64Array(32);
  311. this._n = 0;
  312. }
  313. add(x) {
  314. const p = this._partials;
  315. let i = 0;
  316. for (let j = 0; j < this._n && j < 32; j++) {
  317. const y = p[j],
  318. hi = x + y,
  319. lo = Math.abs(x) < Math.abs(y) ? x - (hi - y) : y - (hi - x);
  320. if (lo) p[i++] = lo;
  321. x = hi;
  322. }
  323. p[i] = x;
  324. this._n = i + 1;
  325. return this;
  326. }
  327. valueOf() {
  328. const p = this._partials;
  329. let n = this._n, x, y, lo, hi = 0;
  330. if (n > 0) {
  331. hi = p[--n];
  332. while (n > 0) {
  333. x = hi;
  334. y = p[--n];
  335. hi = x + y;
  336. lo = y - (hi - x);
  337. if (lo) break;
  338. }
  339. if (n > 0 && ((lo < 0 && p[n - 1] < 0) || (lo > 0 && p[n - 1] > 0))) {
  340. y = lo * 2;
  341. x = hi + y;
  342. if (y == x - hi) hi = x;
  343. }
  344. }
  345. return hi;
  346. }
  347. }
  348. function fsum(values, valueof) {
  349. const adder = new Adder();
  350. if (valueof === undefined) {
  351. for (let value of values) {
  352. if (value = +value) {
  353. adder.add(value);
  354. }
  355. }
  356. } else {
  357. let index = -1;
  358. for (let value of values) {
  359. if (value = +valueof(value, ++index, values)) {
  360. adder.add(value);
  361. }
  362. }
  363. }
  364. return +adder;
  365. }
  366. function fcumsum(values, valueof) {
  367. const adder = new Adder();
  368. let index = -1;
  369. return Float64Array.from(values, valueof === undefined
  370. ? v => adder.add(+v || 0)
  371. : v => adder.add(+valueof(v, ++index, values) || 0)
  372. );
  373. }
  374. class InternMap extends Map {
  375. constructor(entries, key = keyof) {
  376. super();
  377. Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
  378. if (entries != null) for (const [key, value] of entries) this.set(key, value);
  379. }
  380. get(key) {
  381. return super.get(intern_get(this, key));
  382. }
  383. has(key) {
  384. return super.has(intern_get(this, key));
  385. }
  386. set(key, value) {
  387. return super.set(intern_set(this, key), value);
  388. }
  389. delete(key) {
  390. return super.delete(intern_delete(this, key));
  391. }
  392. }
  393. class InternSet extends Set {
  394. constructor(values, key = keyof) {
  395. super();
  396. Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
  397. if (values != null) for (const value of values) this.add(value);
  398. }
  399. has(value) {
  400. return super.has(intern_get(this, value));
  401. }
  402. add(value) {
  403. return super.add(intern_set(this, value));
  404. }
  405. delete(value) {
  406. return super.delete(intern_delete(this, value));
  407. }
  408. }
  409. function intern_get({_intern, _key}, value) {
  410. const key = _key(value);
  411. return _intern.has(key) ? _intern.get(key) : value;
  412. }
  413. function intern_set({_intern, _key}, value) {
  414. const key = _key(value);
  415. if (_intern.has(key)) return _intern.get(key);
  416. _intern.set(key, value);
  417. return value;
  418. }
  419. function intern_delete({_intern, _key}, value) {
  420. const key = _key(value);
  421. if (_intern.has(key)) {
  422. value = _intern.get(key);
  423. _intern.delete(key);
  424. }
  425. return value;
  426. }
  427. function keyof(value) {
  428. return value !== null && typeof value === "object" ? value.valueOf() : value;
  429. }
  430. function identity$9(x) {
  431. return x;
  432. }
  433. function group(values, ...keys) {
  434. return nest(values, identity$9, identity$9, keys);
  435. }
  436. function groups(values, ...keys) {
  437. return nest(values, Array.from, identity$9, keys);
  438. }
  439. function flatten$1(groups, keys) {
  440. for (let i = 1, n = keys.length; i < n; ++i) {
  441. groups = groups.flatMap(g => g.pop().map(([key, value]) => [...g, key, value]));
  442. }
  443. return groups;
  444. }
  445. function flatGroup(values, ...keys) {
  446. return flatten$1(groups(values, ...keys), keys);
  447. }
  448. function flatRollup(values, reduce, ...keys) {
  449. return flatten$1(rollups(values, reduce, ...keys), keys);
  450. }
  451. function rollup(values, reduce, ...keys) {
  452. return nest(values, identity$9, reduce, keys);
  453. }
  454. function rollups(values, reduce, ...keys) {
  455. return nest(values, Array.from, reduce, keys);
  456. }
  457. function index$4(values, ...keys) {
  458. return nest(values, identity$9, unique, keys);
  459. }
  460. function indexes(values, ...keys) {
  461. return nest(values, Array.from, unique, keys);
  462. }
  463. function unique(values) {
  464. if (values.length !== 1) throw new Error("duplicate key");
  465. return values[0];
  466. }
  467. function nest(values, map, reduce, keys) {
  468. return (function regroup(values, i) {
  469. if (i >= keys.length) return reduce(values);
  470. const groups = new InternMap();
  471. const keyof = keys[i++];
  472. let index = -1;
  473. for (const value of values) {
  474. const key = keyof(value, ++index, values);
  475. const group = groups.get(key);
  476. if (group) group.push(value);
  477. else groups.set(key, [value]);
  478. }
  479. for (const [key, values] of groups) {
  480. groups.set(key, regroup(values, i));
  481. }
  482. return map(groups);
  483. })(values, 0);
  484. }
  485. function permute(source, keys) {
  486. return Array.from(keys, key => source[key]);
  487. }
  488. function sort(values, ...F) {
  489. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  490. values = Array.from(values);
  491. let [f] = F;
  492. if ((f && f.length !== 2) || F.length > 1) {
  493. const index = Uint32Array.from(values, (d, i) => i);
  494. if (F.length > 1) {
  495. F = F.map(f => values.map(f));
  496. index.sort((i, j) => {
  497. for (const f of F) {
  498. const c = ascendingDefined(f[i], f[j]);
  499. if (c) return c;
  500. }
  501. });
  502. } else {
  503. f = values.map(f);
  504. index.sort((i, j) => ascendingDefined(f[i], f[j]));
  505. }
  506. return permute(values, index);
  507. }
  508. return values.sort(compareDefined(f));
  509. }
  510. function compareDefined(compare = ascending$3) {
  511. if (compare === ascending$3) return ascendingDefined;
  512. if (typeof compare !== "function") throw new TypeError("compare is not a function");
  513. return (a, b) => {
  514. const x = compare(a, b);
  515. if (x || x === 0) return x;
  516. return (compare(b, b) === 0) - (compare(a, a) === 0);
  517. };
  518. }
  519. function ascendingDefined(a, b) {
  520. return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0);
  521. }
  522. function groupSort(values, reduce, key) {
  523. return (reduce.length !== 2
  524. ? sort(rollup(values, reduce, key), (([ak, av], [bk, bv]) => ascending$3(av, bv) || ascending$3(ak, bk)))
  525. : sort(group(values, key), (([ak, av], [bk, bv]) => reduce(av, bv) || ascending$3(ak, bk))))
  526. .map(([key]) => key);
  527. }
  528. var array$5 = Array.prototype;
  529. var slice$3 = array$5.slice;
  530. function constant$b(x) {
  531. return () => x;
  532. }
  533. const e10 = Math.sqrt(50),
  534. e5 = Math.sqrt(10),
  535. e2 = Math.sqrt(2);
  536. function tickSpec(start, stop, count) {
  537. const step = (stop - start) / Math.max(0, count),
  538. power = Math.floor(Math.log10(step)),
  539. error = step / Math.pow(10, power),
  540. factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
  541. let i1, i2, inc;
  542. if (power < 0) {
  543. inc = Math.pow(10, -power) / factor;
  544. i1 = Math.round(start * inc);
  545. i2 = Math.round(stop * inc);
  546. if (i1 / inc < start) ++i1;
  547. if (i2 / inc > stop) --i2;
  548. inc = -inc;
  549. } else {
  550. inc = Math.pow(10, power) * factor;
  551. i1 = Math.round(start / inc);
  552. i2 = Math.round(stop / inc);
  553. if (i1 * inc < start) ++i1;
  554. if (i2 * inc > stop) --i2;
  555. }
  556. if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2);
  557. return [i1, i2, inc];
  558. }
  559. function ticks(start, stop, count) {
  560. stop = +stop, start = +start, count = +count;
  561. if (!(count > 0)) return [];
  562. if (start === stop) return [start];
  563. const reverse = stop < start, [i1, i2, inc] = reverse ? tickSpec(stop, start, count) : tickSpec(start, stop, count);
  564. if (!(i2 >= i1)) return [];
  565. const n = i2 - i1 + 1, ticks = new Array(n);
  566. if (reverse) {
  567. if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) / -inc;
  568. else for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) * inc;
  569. } else {
  570. if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) / -inc;
  571. else for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) * inc;
  572. }
  573. return ticks;
  574. }
  575. function tickIncrement(start, stop, count) {
  576. stop = +stop, start = +start, count = +count;
  577. return tickSpec(start, stop, count)[2];
  578. }
  579. function tickStep(start, stop, count) {
  580. stop = +stop, start = +start, count = +count;
  581. const reverse = stop < start, inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count);
  582. return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc);
  583. }
  584. function nice$1(start, stop, count) {
  585. let prestep;
  586. while (true) {
  587. const step = tickIncrement(start, stop, count);
  588. if (step === prestep || step === 0 || !isFinite(step)) {
  589. return [start, stop];
  590. } else if (step > 0) {
  591. start = Math.floor(start / step) * step;
  592. stop = Math.ceil(stop / step) * step;
  593. } else if (step < 0) {
  594. start = Math.ceil(start * step) / step;
  595. stop = Math.floor(stop * step) / step;
  596. }
  597. prestep = step;
  598. }
  599. }
  600. function thresholdSturges(values) {
  601. return Math.max(1, Math.ceil(Math.log(count$1(values)) / Math.LN2) + 1);
  602. }
  603. function bin() {
  604. var value = identity$9,
  605. domain = extent$1,
  606. threshold = thresholdSturges;
  607. function histogram(data) {
  608. if (!Array.isArray(data)) data = Array.from(data);
  609. var i,
  610. n = data.length,
  611. x,
  612. step,
  613. values = new Array(n);
  614. for (i = 0; i < n; ++i) {
  615. values[i] = value(data[i], i, data);
  616. }
  617. var xz = domain(values),
  618. x0 = xz[0],
  619. x1 = xz[1],
  620. tz = threshold(values, x0, x1);
  621. // Convert number of thresholds into uniform thresholds, and nice the
  622. // default domain accordingly.
  623. if (!Array.isArray(tz)) {
  624. const max = x1, tn = +tz;
  625. if (domain === extent$1) [x0, x1] = nice$1(x0, x1, tn);
  626. tz = ticks(x0, x1, tn);
  627. // If the domain is aligned with the first tick (which it will by
  628. // default), then we can use quantization rather than bisection to bin
  629. // values, which is substantially faster.
  630. if (tz[0] <= x0) step = tickIncrement(x0, x1, tn);
  631. // If the last threshold is coincident with the domain’s upper bound, the
  632. // last bin will be zero-width. If the default domain is used, and this
  633. // last threshold is coincident with the maximum input value, we can
  634. // extend the niced upper bound by one tick to ensure uniform bin widths;
  635. // otherwise, we simply remove the last threshold. Note that we don’t
  636. // coerce values or the domain to numbers, and thus must be careful to
  637. // compare order (>=) rather than strict equality (===)!
  638. if (tz[tz.length - 1] >= x1) {
  639. if (max >= x1 && domain === extent$1) {
  640. const step = tickIncrement(x0, x1, tn);
  641. if (isFinite(step)) {
  642. if (step > 0) {
  643. x1 = (Math.floor(x1 / step) + 1) * step;
  644. } else if (step < 0) {
  645. x1 = (Math.ceil(x1 * -step) + 1) / -step;
  646. }
  647. }
  648. } else {
  649. tz.pop();
  650. }
  651. }
  652. }
  653. // Remove any thresholds outside the domain.
  654. // Be careful not to mutate an array owned by the user!
  655. var m = tz.length, a = 0, b = m;
  656. while (tz[a] <= x0) ++a;
  657. while (tz[b - 1] > x1) --b;
  658. if (a || b < m) tz = tz.slice(a, b), m = b - a;
  659. var bins = new Array(m + 1),
  660. bin;
  661. // Initialize bins.
  662. for (i = 0; i <= m; ++i) {
  663. bin = bins[i] = [];
  664. bin.x0 = i > 0 ? tz[i - 1] : x0;
  665. bin.x1 = i < m ? tz[i] : x1;
  666. }
  667. // Assign data to bins by value, ignoring any outside the domain.
  668. if (isFinite(step)) {
  669. if (step > 0) {
  670. for (i = 0; i < n; ++i) {
  671. if ((x = values[i]) != null && x0 <= x && x <= x1) {
  672. bins[Math.min(m, Math.floor((x - x0) / step))].push(data[i]);
  673. }
  674. }
  675. } else if (step < 0) {
  676. for (i = 0; i < n; ++i) {
  677. if ((x = values[i]) != null && x0 <= x && x <= x1) {
  678. const j = Math.floor((x0 - x) * step);
  679. bins[Math.min(m, j + (tz[j] <= x))].push(data[i]); // handle off-by-one due to rounding
  680. }
  681. }
  682. }
  683. } else {
  684. for (i = 0; i < n; ++i) {
  685. if ((x = values[i]) != null && x0 <= x && x <= x1) {
  686. bins[bisect(tz, x, 0, m)].push(data[i]);
  687. }
  688. }
  689. }
  690. return bins;
  691. }
  692. histogram.value = function(_) {
  693. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(_), histogram) : value;
  694. };
  695. histogram.domain = function(_) {
  696. return arguments.length ? (domain = typeof _ === "function" ? _ : constant$b([_[0], _[1]]), histogram) : domain;
  697. };
  698. histogram.thresholds = function(_) {
  699. return arguments.length ? (threshold = typeof _ === "function" ? _ : constant$b(Array.isArray(_) ? slice$3.call(_) : _), histogram) : threshold;
  700. };
  701. return histogram;
  702. }
  703. function max$3(values, valueof) {
  704. let max;
  705. if (valueof === undefined) {
  706. for (const value of values) {
  707. if (value != null
  708. && (max < value || (max === undefined && value >= value))) {
  709. max = value;
  710. }
  711. }
  712. } else {
  713. let index = -1;
  714. for (let value of values) {
  715. if ((value = valueof(value, ++index, values)) != null
  716. && (max < value || (max === undefined && value >= value))) {
  717. max = value;
  718. }
  719. }
  720. }
  721. return max;
  722. }
  723. function maxIndex(values, valueof) {
  724. let max;
  725. let maxIndex = -1;
  726. let index = -1;
  727. if (valueof === undefined) {
  728. for (const value of values) {
  729. ++index;
  730. if (value != null
  731. && (max < value || (max === undefined && value >= value))) {
  732. max = value, maxIndex = index;
  733. }
  734. }
  735. } else {
  736. for (let value of values) {
  737. if ((value = valueof(value, ++index, values)) != null
  738. && (max < value || (max === undefined && value >= value))) {
  739. max = value, maxIndex = index;
  740. }
  741. }
  742. }
  743. return maxIndex;
  744. }
  745. function min$2(values, valueof) {
  746. let min;
  747. if (valueof === undefined) {
  748. for (const value of values) {
  749. if (value != null
  750. && (min > value || (min === undefined && value >= value))) {
  751. min = value;
  752. }
  753. }
  754. } else {
  755. let index = -1;
  756. for (let value of values) {
  757. if ((value = valueof(value, ++index, values)) != null
  758. && (min > value || (min === undefined && value >= value))) {
  759. min = value;
  760. }
  761. }
  762. }
  763. return min;
  764. }
  765. function minIndex(values, valueof) {
  766. let min;
  767. let minIndex = -1;
  768. let index = -1;
  769. if (valueof === undefined) {
  770. for (const value of values) {
  771. ++index;
  772. if (value != null
  773. && (min > value || (min === undefined && value >= value))) {
  774. min = value, minIndex = index;
  775. }
  776. }
  777. } else {
  778. for (let value of values) {
  779. if ((value = valueof(value, ++index, values)) != null
  780. && (min > value || (min === undefined && value >= value))) {
  781. min = value, minIndex = index;
  782. }
  783. }
  784. }
  785. return minIndex;
  786. }
  787. // Based on https://github.com/mourner/quickselect
  788. // ISC license, Copyright 2018 Vladimir Agafonkin.
  789. function quickselect(array, k, left = 0, right = Infinity, compare) {
  790. k = Math.floor(k);
  791. left = Math.floor(Math.max(0, left));
  792. right = Math.floor(Math.min(array.length - 1, right));
  793. if (!(left <= k && k <= right)) return array;
  794. compare = compare === undefined ? ascendingDefined : compareDefined(compare);
  795. while (right > left) {
  796. if (right - left > 600) {
  797. const n = right - left + 1;
  798. const m = k - left + 1;
  799. const z = Math.log(n);
  800. const s = 0.5 * Math.exp(2 * z / 3);
  801. const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  802. const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  803. const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  804. quickselect(array, k, newLeft, newRight, compare);
  805. }
  806. const t = array[k];
  807. let i = left;
  808. let j = right;
  809. swap$1(array, left, k);
  810. if (compare(array[right], t) > 0) swap$1(array, left, right);
  811. while (i < j) {
  812. swap$1(array, i, j), ++i, --j;
  813. while (compare(array[i], t) < 0) ++i;
  814. while (compare(array[j], t) > 0) --j;
  815. }
  816. if (compare(array[left], t) === 0) swap$1(array, left, j);
  817. else ++j, swap$1(array, j, right);
  818. if (j <= k) left = j + 1;
  819. if (k <= j) right = j - 1;
  820. }
  821. return array;
  822. }
  823. function swap$1(array, i, j) {
  824. const t = array[i];
  825. array[i] = array[j];
  826. array[j] = t;
  827. }
  828. function greatest(values, compare = ascending$3) {
  829. let max;
  830. let defined = false;
  831. if (compare.length === 1) {
  832. let maxValue;
  833. for (const element of values) {
  834. const value = compare(element);
  835. if (defined
  836. ? ascending$3(value, maxValue) > 0
  837. : ascending$3(value, value) === 0) {
  838. max = element;
  839. maxValue = value;
  840. defined = true;
  841. }
  842. }
  843. } else {
  844. for (const value of values) {
  845. if (defined
  846. ? compare(value, max) > 0
  847. : compare(value, value) === 0) {
  848. max = value;
  849. defined = true;
  850. }
  851. }
  852. }
  853. return max;
  854. }
  855. function quantile$1(values, p, valueof) {
  856. values = Float64Array.from(numbers(values, valueof));
  857. if (!(n = values.length) || isNaN(p = +p)) return;
  858. if (p <= 0 || n < 2) return min$2(values);
  859. if (p >= 1) return max$3(values);
  860. var n,
  861. i = (n - 1) * p,
  862. i0 = Math.floor(i),
  863. value0 = max$3(quickselect(values, i0).subarray(0, i0 + 1)),
  864. value1 = min$2(values.subarray(i0 + 1));
  865. return value0 + (value1 - value0) * (i - i0);
  866. }
  867. function quantileSorted(values, p, valueof = number$3) {
  868. if (!(n = values.length) || isNaN(p = +p)) return;
  869. if (p <= 0 || n < 2) return +valueof(values[0], 0, values);
  870. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  871. var n,
  872. i = (n - 1) * p,
  873. i0 = Math.floor(i),
  874. value0 = +valueof(values[i0], i0, values),
  875. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  876. return value0 + (value1 - value0) * (i - i0);
  877. }
  878. function quantileIndex(values, p, valueof = number$3) {
  879. if (isNaN(p = +p)) return;
  880. numbers = Float64Array.from(values, (_, i) => number$3(valueof(values[i], i, values)));
  881. if (p <= 0) return minIndex(numbers);
  882. if (p >= 1) return maxIndex(numbers);
  883. var numbers,
  884. index = Uint32Array.from(values, (_, i) => i),
  885. j = numbers.length - 1,
  886. i = Math.floor(j * p);
  887. quickselect(index, i, 0, j, (i, j) => ascendingDefined(numbers[i], numbers[j]));
  888. i = greatest(index.subarray(0, i + 1), (i) => numbers[i]);
  889. return i >= 0 ? i : -1;
  890. }
  891. function thresholdFreedmanDiaconis(values, min, max) {
  892. const c = count$1(values), d = quantile$1(values, 0.75) - quantile$1(values, 0.25);
  893. return c && d ? Math.ceil((max - min) / (2 * d * Math.pow(c, -1 / 3))) : 1;
  894. }
  895. function thresholdScott(values, min, max) {
  896. const c = count$1(values), d = deviation(values);
  897. return c && d ? Math.ceil((max - min) * Math.cbrt(c) / (3.49 * d)) : 1;
  898. }
  899. function mean(values, valueof) {
  900. let count = 0;
  901. let sum = 0;
  902. if (valueof === undefined) {
  903. for (let value of values) {
  904. if (value != null && (value = +value) >= value) {
  905. ++count, sum += value;
  906. }
  907. }
  908. } else {
  909. let index = -1;
  910. for (let value of values) {
  911. if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
  912. ++count, sum += value;
  913. }
  914. }
  915. }
  916. if (count) return sum / count;
  917. }
  918. function median(values, valueof) {
  919. return quantile$1(values, 0.5, valueof);
  920. }
  921. function medianIndex(values, valueof) {
  922. return quantileIndex(values, 0.5, valueof);
  923. }
  924. function* flatten(arrays) {
  925. for (const array of arrays) {
  926. yield* array;
  927. }
  928. }
  929. function merge(arrays) {
  930. return Array.from(flatten(arrays));
  931. }
  932. function mode(values, valueof) {
  933. const counts = new InternMap();
  934. if (valueof === undefined) {
  935. for (let value of values) {
  936. if (value != null && value >= value) {
  937. counts.set(value, (counts.get(value) || 0) + 1);
  938. }
  939. }
  940. } else {
  941. let index = -1;
  942. for (let value of values) {
  943. if ((value = valueof(value, ++index, values)) != null && value >= value) {
  944. counts.set(value, (counts.get(value) || 0) + 1);
  945. }
  946. }
  947. }
  948. let modeValue;
  949. let modeCount = 0;
  950. for (const [value, count] of counts) {
  951. if (count > modeCount) {
  952. modeCount = count;
  953. modeValue = value;
  954. }
  955. }
  956. return modeValue;
  957. }
  958. function pairs(values, pairof = pair) {
  959. const pairs = [];
  960. let previous;
  961. let first = false;
  962. for (const value of values) {
  963. if (first) pairs.push(pairof(previous, value));
  964. previous = value;
  965. first = true;
  966. }
  967. return pairs;
  968. }
  969. function pair(a, b) {
  970. return [a, b];
  971. }
  972. function range$2(start, stop, step) {
  973. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  974. var i = -1,
  975. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  976. range = new Array(n);
  977. while (++i < n) {
  978. range[i] = start + i * step;
  979. }
  980. return range;
  981. }
  982. function rank(values, valueof = ascending$3) {
  983. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  984. let V = Array.from(values);
  985. const R = new Float64Array(V.length);
  986. if (valueof.length !== 2) V = V.map(valueof), valueof = ascending$3;
  987. const compareIndex = (i, j) => valueof(V[i], V[j]);
  988. let k, r;
  989. values = Uint32Array.from(V, (_, i) => i);
  990. // Risky chaining due to Safari 14 https://github.com/d3/d3-array/issues/123
  991. values.sort(valueof === ascending$3 ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex));
  992. values.forEach((j, i) => {
  993. const c = compareIndex(j, k === undefined ? j : k);
  994. if (c >= 0) {
  995. if (k === undefined || c > 0) k = j, r = i;
  996. R[j] = r;
  997. } else {
  998. R[j] = NaN;
  999. }
  1000. });
  1001. return R;
  1002. }
  1003. function least(values, compare = ascending$3) {
  1004. let min;
  1005. let defined = false;
  1006. if (compare.length === 1) {
  1007. let minValue;
  1008. for (const element of values) {
  1009. const value = compare(element);
  1010. if (defined
  1011. ? ascending$3(value, minValue) < 0
  1012. : ascending$3(value, value) === 0) {
  1013. min = element;
  1014. minValue = value;
  1015. defined = true;
  1016. }
  1017. }
  1018. } else {
  1019. for (const value of values) {
  1020. if (defined
  1021. ? compare(value, min) < 0
  1022. : compare(value, value) === 0) {
  1023. min = value;
  1024. defined = true;
  1025. }
  1026. }
  1027. }
  1028. return min;
  1029. }
  1030. function leastIndex(values, compare = ascending$3) {
  1031. if (compare.length === 1) return minIndex(values, compare);
  1032. let minValue;
  1033. let min = -1;
  1034. let index = -1;
  1035. for (const value of values) {
  1036. ++index;
  1037. if (min < 0
  1038. ? compare(value, value) === 0
  1039. : compare(value, minValue) < 0) {
  1040. minValue = value;
  1041. min = index;
  1042. }
  1043. }
  1044. return min;
  1045. }
  1046. function greatestIndex(values, compare = ascending$3) {
  1047. if (compare.length === 1) return maxIndex(values, compare);
  1048. let maxValue;
  1049. let max = -1;
  1050. let index = -1;
  1051. for (const value of values) {
  1052. ++index;
  1053. if (max < 0
  1054. ? compare(value, value) === 0
  1055. : compare(value, maxValue) > 0) {
  1056. maxValue = value;
  1057. max = index;
  1058. }
  1059. }
  1060. return max;
  1061. }
  1062. function scan(values, compare) {
  1063. const index = leastIndex(values, compare);
  1064. return index < 0 ? undefined : index;
  1065. }
  1066. var shuffle$1 = shuffler(Math.random);
  1067. function shuffler(random) {
  1068. return function shuffle(array, i0 = 0, i1 = array.length) {
  1069. let m = i1 - (i0 = +i0);
  1070. while (m) {
  1071. const i = random() * m-- | 0, t = array[m + i0];
  1072. array[m + i0] = array[i + i0];
  1073. array[i + i0] = t;
  1074. }
  1075. return array;
  1076. };
  1077. }
  1078. function sum$2(values, valueof) {
  1079. let sum = 0;
  1080. if (valueof === undefined) {
  1081. for (let value of values) {
  1082. if (value = +value) {
  1083. sum += value;
  1084. }
  1085. }
  1086. } else {
  1087. let index = -1;
  1088. for (let value of values) {
  1089. if (value = +valueof(value, ++index, values)) {
  1090. sum += value;
  1091. }
  1092. }
  1093. }
  1094. return sum;
  1095. }
  1096. function transpose(matrix) {
  1097. if (!(n = matrix.length)) return [];
  1098. for (var i = -1, m = min$2(matrix, length$2), transpose = new Array(m); ++i < m;) {
  1099. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  1100. row[j] = matrix[j][i];
  1101. }
  1102. }
  1103. return transpose;
  1104. }
  1105. function length$2(d) {
  1106. return d.length;
  1107. }
  1108. function zip() {
  1109. return transpose(arguments);
  1110. }
  1111. function every(values, test) {
  1112. if (typeof test !== "function") throw new TypeError("test is not a function");
  1113. let index = -1;
  1114. for (const value of values) {
  1115. if (!test(value, ++index, values)) {
  1116. return false;
  1117. }
  1118. }
  1119. return true;
  1120. }
  1121. function some(values, test) {
  1122. if (typeof test !== "function") throw new TypeError("test is not a function");
  1123. let index = -1;
  1124. for (const value of values) {
  1125. if (test(value, ++index, values)) {
  1126. return true;
  1127. }
  1128. }
  1129. return false;
  1130. }
  1131. function filter$1(values, test) {
  1132. if (typeof test !== "function") throw new TypeError("test is not a function");
  1133. const array = [];
  1134. let index = -1;
  1135. for (const value of values) {
  1136. if (test(value, ++index, values)) {
  1137. array.push(value);
  1138. }
  1139. }
  1140. return array;
  1141. }
  1142. function map$1(values, mapper) {
  1143. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  1144. if (typeof mapper !== "function") throw new TypeError("mapper is not a function");
  1145. return Array.from(values, (value, index) => mapper(value, index, values));
  1146. }
  1147. function reduce(values, reducer, value) {
  1148. if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
  1149. const iterator = values[Symbol.iterator]();
  1150. let done, next, index = -1;
  1151. if (arguments.length < 3) {
  1152. ({done, value} = iterator.next());
  1153. if (done) return;
  1154. ++index;
  1155. }
  1156. while (({done, value: next} = iterator.next()), !done) {
  1157. value = reducer(value, next, ++index, values);
  1158. }
  1159. return value;
  1160. }
  1161. function reverse$1(values) {
  1162. if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
  1163. return Array.from(values).reverse();
  1164. }
  1165. function difference(values, ...others) {
  1166. values = new InternSet(values);
  1167. for (const other of others) {
  1168. for (const value of other) {
  1169. values.delete(value);
  1170. }
  1171. }
  1172. return values;
  1173. }
  1174. function disjoint(values, other) {
  1175. const iterator = other[Symbol.iterator](), set = new InternSet();
  1176. for (const v of values) {
  1177. if (set.has(v)) return false;
  1178. let value, done;
  1179. while (({value, done} = iterator.next())) {
  1180. if (done) break;
  1181. if (Object.is(v, value)) return false;
  1182. set.add(value);
  1183. }
  1184. }
  1185. return true;
  1186. }
  1187. function intersection(values, ...others) {
  1188. values = new InternSet(values);
  1189. others = others.map(set$2);
  1190. out: for (const value of values) {
  1191. for (const other of others) {
  1192. if (!other.has(value)) {
  1193. values.delete(value);
  1194. continue out;
  1195. }
  1196. }
  1197. }
  1198. return values;
  1199. }
  1200. function set$2(values) {
  1201. return values instanceof InternSet ? values : new InternSet(values);
  1202. }
  1203. function superset(values, other) {
  1204. const iterator = values[Symbol.iterator](), set = new Set();
  1205. for (const o of other) {
  1206. const io = intern(o);
  1207. if (set.has(io)) continue;
  1208. let value, done;
  1209. while (({value, done} = iterator.next())) {
  1210. if (done) return false;
  1211. const ivalue = intern(value);
  1212. set.add(ivalue);
  1213. if (Object.is(io, ivalue)) break;
  1214. }
  1215. }
  1216. return true;
  1217. }
  1218. function intern(value) {
  1219. return value !== null && typeof value === "object" ? value.valueOf() : value;
  1220. }
  1221. function subset(values, other) {
  1222. return superset(other, values);
  1223. }
  1224. function union(...others) {
  1225. const set = new InternSet();
  1226. for (const other of others) {
  1227. for (const o of other) {
  1228. set.add(o);
  1229. }
  1230. }
  1231. return set;
  1232. }
  1233. function identity$8(x) {
  1234. return x;
  1235. }
  1236. var top = 1,
  1237. right = 2,
  1238. bottom = 3,
  1239. left = 4,
  1240. epsilon$6 = 1e-6;
  1241. function translateX(x) {
  1242. return "translate(" + x + ",0)";
  1243. }
  1244. function translateY(y) {
  1245. return "translate(0," + y + ")";
  1246. }
  1247. function number$2(scale) {
  1248. return d => +scale(d);
  1249. }
  1250. function center$1(scale, offset) {
  1251. offset = Math.max(0, scale.bandwidth() - offset * 2) / 2;
  1252. if (scale.round()) offset = Math.round(offset);
  1253. return d => +scale(d) + offset;
  1254. }
  1255. function entering() {
  1256. return !this.__axis;
  1257. }
  1258. function axis(orient, scale) {
  1259. var tickArguments = [],
  1260. tickValues = null,
  1261. tickFormat = null,
  1262. tickSizeInner = 6,
  1263. tickSizeOuter = 6,
  1264. tickPadding = 3,
  1265. offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5,
  1266. k = orient === top || orient === left ? -1 : 1,
  1267. x = orient === left || orient === right ? "x" : "y",
  1268. transform = orient === top || orient === bottom ? translateX : translateY;
  1269. function axis(context) {
  1270. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  1271. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$8) : tickFormat,
  1272. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  1273. range = scale.range(),
  1274. range0 = +range[0] + offset,
  1275. range1 = +range[range.length - 1] + offset,
  1276. position = (scale.bandwidth ? center$1 : number$2)(scale.copy(), offset),
  1277. selection = context.selection ? context.selection() : context,
  1278. path = selection.selectAll(".domain").data([null]),
  1279. tick = selection.selectAll(".tick").data(values, scale).order(),
  1280. tickExit = tick.exit(),
  1281. tickEnter = tick.enter().append("g").attr("class", "tick"),
  1282. line = tick.select("line"),
  1283. text = tick.select("text");
  1284. path = path.merge(path.enter().insert("path", ".tick")
  1285. .attr("class", "domain")
  1286. .attr("stroke", "currentColor"));
  1287. tick = tick.merge(tickEnter);
  1288. line = line.merge(tickEnter.append("line")
  1289. .attr("stroke", "currentColor")
  1290. .attr(x + "2", k * tickSizeInner));
  1291. text = text.merge(tickEnter.append("text")
  1292. .attr("fill", "currentColor")
  1293. .attr(x, k * spacing)
  1294. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  1295. if (context !== selection) {
  1296. path = path.transition(context);
  1297. tick = tick.transition(context);
  1298. line = line.transition(context);
  1299. text = text.transition(context);
  1300. tickExit = tickExit.transition(context)
  1301. .attr("opacity", epsilon$6)
  1302. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform"); });
  1303. tickEnter
  1304. .attr("opacity", epsilon$6)
  1305. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset); });
  1306. }
  1307. tickExit.remove();
  1308. path
  1309. .attr("d", orient === left || orient === right
  1310. ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1)
  1311. : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1));
  1312. tick
  1313. .attr("opacity", 1)
  1314. .attr("transform", function(d) { return transform(position(d) + offset); });
  1315. line
  1316. .attr(x + "2", k * tickSizeInner);
  1317. text
  1318. .attr(x, k * spacing)
  1319. .text(format);
  1320. selection.filter(entering)
  1321. .attr("fill", "none")
  1322. .attr("font-size", 10)
  1323. .attr("font-family", "sans-serif")
  1324. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  1325. selection
  1326. .each(function() { this.__axis = position; });
  1327. }
  1328. axis.scale = function(_) {
  1329. return arguments.length ? (scale = _, axis) : scale;
  1330. };
  1331. axis.ticks = function() {
  1332. return tickArguments = Array.from(arguments), axis;
  1333. };
  1334. axis.tickArguments = function(_) {
  1335. return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice();
  1336. };
  1337. axis.tickValues = function(_) {
  1338. return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice();
  1339. };
  1340. axis.tickFormat = function(_) {
  1341. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  1342. };
  1343. axis.tickSize = function(_) {
  1344. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  1345. };
  1346. axis.tickSizeInner = function(_) {
  1347. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  1348. };
  1349. axis.tickSizeOuter = function(_) {
  1350. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  1351. };
  1352. axis.tickPadding = function(_) {
  1353. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  1354. };
  1355. axis.offset = function(_) {
  1356. return arguments.length ? (offset = +_, axis) : offset;
  1357. };
  1358. return axis;
  1359. }
  1360. function axisTop(scale) {
  1361. return axis(top, scale);
  1362. }
  1363. function axisRight(scale) {
  1364. return axis(right, scale);
  1365. }
  1366. function axisBottom(scale) {
  1367. return axis(bottom, scale);
  1368. }
  1369. function axisLeft(scale) {
  1370. return axis(left, scale);
  1371. }
  1372. var noop$3 = {value: () => {}};
  1373. function dispatch() {
  1374. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  1375. if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
  1376. _[t] = [];
  1377. }
  1378. return new Dispatch(_);
  1379. }
  1380. function Dispatch(_) {
  1381. this._ = _;
  1382. }
  1383. function parseTypenames$1(typenames, types) {
  1384. return typenames.trim().split(/^|\s+/).map(function(t) {
  1385. var name = "", i = t.indexOf(".");
  1386. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1387. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  1388. return {type: t, name: name};
  1389. });
  1390. }
  1391. Dispatch.prototype = dispatch.prototype = {
  1392. constructor: Dispatch,
  1393. on: function(typename, callback) {
  1394. var _ = this._,
  1395. T = parseTypenames$1(typename + "", _),
  1396. t,
  1397. i = -1,
  1398. n = T.length;
  1399. // If no callback was specified, return the callback of the given type and name.
  1400. if (arguments.length < 2) {
  1401. while (++i < n) if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t;
  1402. return;
  1403. }
  1404. // If a type was specified, set the callback for the given type and name.
  1405. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  1406. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  1407. while (++i < n) {
  1408. if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
  1409. else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
  1410. }
  1411. return this;
  1412. },
  1413. copy: function() {
  1414. var copy = {}, _ = this._;
  1415. for (var t in _) copy[t] = _[t].slice();
  1416. return new Dispatch(copy);
  1417. },
  1418. call: function(type, that) {
  1419. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  1420. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  1421. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  1422. },
  1423. apply: function(type, that, args) {
  1424. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  1425. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  1426. }
  1427. };
  1428. function get$1(type, name) {
  1429. for (var i = 0, n = type.length, c; i < n; ++i) {
  1430. if ((c = type[i]).name === name) {
  1431. return c.value;
  1432. }
  1433. }
  1434. }
  1435. function set$1(type, name, callback) {
  1436. for (var i = 0, n = type.length; i < n; ++i) {
  1437. if (type[i].name === name) {
  1438. type[i] = noop$3, type = type.slice(0, i).concat(type.slice(i + 1));
  1439. break;
  1440. }
  1441. }
  1442. if (callback != null) type.push({name: name, value: callback});
  1443. return type;
  1444. }
  1445. var xhtml = "http://www.w3.org/1999/xhtml";
  1446. var namespaces = {
  1447. svg: "http://www.w3.org/2000/svg",
  1448. xhtml: xhtml,
  1449. xlink: "http://www.w3.org/1999/xlink",
  1450. xml: "http://www.w3.org/XML/1998/namespace",
  1451. xmlns: "http://www.w3.org/2000/xmlns/"
  1452. };
  1453. function namespace(name) {
  1454. var prefix = name += "", i = prefix.indexOf(":");
  1455. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  1456. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins
  1457. }
  1458. function creatorInherit(name) {
  1459. return function() {
  1460. var document = this.ownerDocument,
  1461. uri = this.namespaceURI;
  1462. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  1463. ? document.createElement(name)
  1464. : document.createElementNS(uri, name);
  1465. };
  1466. }
  1467. function creatorFixed(fullname) {
  1468. return function() {
  1469. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  1470. };
  1471. }
  1472. function creator(name) {
  1473. var fullname = namespace(name);
  1474. return (fullname.local
  1475. ? creatorFixed
  1476. : creatorInherit)(fullname);
  1477. }
  1478. function none$2() {}
  1479. function selector(selector) {
  1480. return selector == null ? none$2 : function() {
  1481. return this.querySelector(selector);
  1482. };
  1483. }
  1484. function selection_select(select) {
  1485. if (typeof select !== "function") select = selector(select);
  1486. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  1487. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  1488. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  1489. if ("__data__" in node) subnode.__data__ = node.__data__;
  1490. subgroup[i] = subnode;
  1491. }
  1492. }
  1493. }
  1494. return new Selection$1(subgroups, this._parents);
  1495. }
  1496. // Given something array like (or null), returns something that is strictly an
  1497. // array. This is used to ensure that array-like objects passed to d3.selectAll
  1498. // or selection.selectAll are converted into proper arrays when creating a
  1499. // selection; we don’t ever want to create a selection backed by a live
  1500. // HTMLCollection or NodeList. However, note that selection.selectAll will use a
  1501. // static NodeList as a group, since it safely derived from querySelectorAll.
  1502. function array$4(x) {
  1503. return x == null ? [] : Array.isArray(x) ? x : Array.from(x);
  1504. }
  1505. function empty$1() {
  1506. return [];
  1507. }
  1508. function selectorAll(selector) {
  1509. return selector == null ? empty$1 : function() {
  1510. return this.querySelectorAll(selector);
  1511. };
  1512. }
  1513. function arrayAll(select) {
  1514. return function() {
  1515. return array$4(select.apply(this, arguments));
  1516. };
  1517. }
  1518. function selection_selectAll(select) {
  1519. if (typeof select === "function") select = arrayAll(select);
  1520. else select = selectorAll(select);
  1521. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  1522. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  1523. if (node = group[i]) {
  1524. subgroups.push(select.call(node, node.__data__, i, group));
  1525. parents.push(node);
  1526. }
  1527. }
  1528. }
  1529. return new Selection$1(subgroups, parents);
  1530. }
  1531. function matcher(selector) {
  1532. return function() {
  1533. return this.matches(selector);
  1534. };
  1535. }
  1536. function childMatcher(selector) {
  1537. return function(node) {
  1538. return node.matches(selector);
  1539. };
  1540. }
  1541. var find$1 = Array.prototype.find;
  1542. function childFind(match) {
  1543. return function() {
  1544. return find$1.call(this.children, match);
  1545. };
  1546. }
  1547. function childFirst() {
  1548. return this.firstElementChild;
  1549. }
  1550. function selection_selectChild(match) {
  1551. return this.select(match == null ? childFirst
  1552. : childFind(typeof match === "function" ? match : childMatcher(match)));
  1553. }
  1554. var filter = Array.prototype.filter;
  1555. function children() {
  1556. return Array.from(this.children);
  1557. }
  1558. function childrenFilter(match) {
  1559. return function() {
  1560. return filter.call(this.children, match);
  1561. };
  1562. }
  1563. function selection_selectChildren(match) {
  1564. return this.selectAll(match == null ? children
  1565. : childrenFilter(typeof match === "function" ? match : childMatcher(match)));
  1566. }
  1567. function selection_filter(match) {
  1568. if (typeof match !== "function") match = matcher(match);
  1569. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  1570. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  1571. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  1572. subgroup.push(node);
  1573. }
  1574. }
  1575. }
  1576. return new Selection$1(subgroups, this._parents);
  1577. }
  1578. function sparse(update) {
  1579. return new Array(update.length);
  1580. }
  1581. function selection_enter() {
  1582. return new Selection$1(this._enter || this._groups.map(sparse), this._parents);
  1583. }
  1584. function EnterNode(parent, datum) {
  1585. this.ownerDocument = parent.ownerDocument;
  1586. this.namespaceURI = parent.namespaceURI;
  1587. this._next = null;
  1588. this._parent = parent;
  1589. this.__data__ = datum;
  1590. }
  1591. EnterNode.prototype = {
  1592. constructor: EnterNode,
  1593. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  1594. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  1595. querySelector: function(selector) { return this._parent.querySelector(selector); },
  1596. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  1597. };
  1598. function constant$a(x) {
  1599. return function() {
  1600. return x;
  1601. };
  1602. }
  1603. function bindIndex(parent, group, enter, update, exit, data) {
  1604. var i = 0,
  1605. node,
  1606. groupLength = group.length,
  1607. dataLength = data.length;
  1608. // Put any non-null nodes that fit into update.
  1609. // Put any null nodes into enter.
  1610. // Put any remaining data into enter.
  1611. for (; i < dataLength; ++i) {
  1612. if (node = group[i]) {
  1613. node.__data__ = data[i];
  1614. update[i] = node;
  1615. } else {
  1616. enter[i] = new EnterNode(parent, data[i]);
  1617. }
  1618. }
  1619. // Put any non-null nodes that don’t fit into exit.
  1620. for (; i < groupLength; ++i) {
  1621. if (node = group[i]) {
  1622. exit[i] = node;
  1623. }
  1624. }
  1625. }
  1626. function bindKey(parent, group, enter, update, exit, data, key) {
  1627. var i,
  1628. node,
  1629. nodeByKeyValue = new Map,
  1630. groupLength = group.length,
  1631. dataLength = data.length,
  1632. keyValues = new Array(groupLength),
  1633. keyValue;
  1634. // Compute the key for each node.
  1635. // If multiple nodes have the same key, the duplicates are added to exit.
  1636. for (i = 0; i < groupLength; ++i) {
  1637. if (node = group[i]) {
  1638. keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
  1639. if (nodeByKeyValue.has(keyValue)) {
  1640. exit[i] = node;
  1641. } else {
  1642. nodeByKeyValue.set(keyValue, node);
  1643. }
  1644. }
  1645. }
  1646. // Compute the key for each datum.
  1647. // If there a node associated with this key, join and add it to update.
  1648. // If there is not (or the key is a duplicate), add it to enter.
  1649. for (i = 0; i < dataLength; ++i) {
  1650. keyValue = key.call(parent, data[i], i, data) + "";
  1651. if (node = nodeByKeyValue.get(keyValue)) {
  1652. update[i] = node;
  1653. node.__data__ = data[i];
  1654. nodeByKeyValue.delete(keyValue);
  1655. } else {
  1656. enter[i] = new EnterNode(parent, data[i]);
  1657. }
  1658. }
  1659. // Add any remaining nodes that were not bound to data to exit.
  1660. for (i = 0; i < groupLength; ++i) {
  1661. if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) {
  1662. exit[i] = node;
  1663. }
  1664. }
  1665. }
  1666. function datum(node) {
  1667. return node.__data__;
  1668. }
  1669. function selection_data(value, key) {
  1670. if (!arguments.length) return Array.from(this, datum);
  1671. var bind = key ? bindKey : bindIndex,
  1672. parents = this._parents,
  1673. groups = this._groups;
  1674. if (typeof value !== "function") value = constant$a(value);
  1675. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  1676. var parent = parents[j],
  1677. group = groups[j],
  1678. groupLength = group.length,
  1679. data = arraylike(value.call(parent, parent && parent.__data__, j, parents)),
  1680. dataLength = data.length,
  1681. enterGroup = enter[j] = new Array(dataLength),
  1682. updateGroup = update[j] = new Array(dataLength),
  1683. exitGroup = exit[j] = new Array(groupLength);
  1684. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  1685. // Now connect the enter nodes to their following update node, such that
  1686. // appendChild can insert the materialized enter node before this node,
  1687. // rather than at the end of the parent node.
  1688. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  1689. if (previous = enterGroup[i0]) {
  1690. if (i0 >= i1) i1 = i0 + 1;
  1691. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  1692. previous._next = next || null;
  1693. }
  1694. }
  1695. }
  1696. update = new Selection$1(update, parents);
  1697. update._enter = enter;
  1698. update._exit = exit;
  1699. return update;
  1700. }
  1701. // Given some data, this returns an array-like view of it: an object that
  1702. // exposes a length property and allows numeric indexing. Note that unlike
  1703. // selectAll, this isn’t worried about “live” collections because the resulting
  1704. // array will only be used briefly while data is being bound. (It is possible to
  1705. // cause the data to change while iterating by using a key function, but please
  1706. // don’t; we’d rather avoid a gratuitous copy.)
  1707. function arraylike(data) {
  1708. return typeof data === "object" && "length" in data
  1709. ? data // Array, TypedArray, NodeList, array-like
  1710. : Array.from(data); // Map, Set, iterable, string, or anything else
  1711. }
  1712. function selection_exit() {
  1713. return new Selection$1(this._exit || this._groups.map(sparse), this._parents);
  1714. }
  1715. function selection_join(onenter, onupdate, onexit) {
  1716. var enter = this.enter(), update = this, exit = this.exit();
  1717. if (typeof onenter === "function") {
  1718. enter = onenter(enter);
  1719. if (enter) enter = enter.selection();
  1720. } else {
  1721. enter = enter.append(onenter + "");
  1722. }
  1723. if (onupdate != null) {
  1724. update = onupdate(update);
  1725. if (update) update = update.selection();
  1726. }
  1727. if (onexit == null) exit.remove(); else onexit(exit);
  1728. return enter && update ? enter.merge(update).order() : update;
  1729. }
  1730. function selection_merge(context) {
  1731. var selection = context.selection ? context.selection() : context;
  1732. for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  1733. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  1734. if (node = group0[i] || group1[i]) {
  1735. merge[i] = node;
  1736. }
  1737. }
  1738. }
  1739. for (; j < m0; ++j) {
  1740. merges[j] = groups0[j];
  1741. }
  1742. return new Selection$1(merges, this._parents);
  1743. }
  1744. function selection_order() {
  1745. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  1746. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  1747. if (node = group[i]) {
  1748. if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
  1749. next = node;
  1750. }
  1751. }
  1752. }
  1753. return this;
  1754. }
  1755. function selection_sort(compare) {
  1756. if (!compare) compare = ascending$2;
  1757. function compareNode(a, b) {
  1758. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  1759. }
  1760. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  1761. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  1762. if (node = group[i]) {
  1763. sortgroup[i] = node;
  1764. }
  1765. }
  1766. sortgroup.sort(compareNode);
  1767. }
  1768. return new Selection$1(sortgroups, this._parents).order();
  1769. }
  1770. function ascending$2(a, b) {
  1771. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  1772. }
  1773. function selection_call() {
  1774. var callback = arguments[0];
  1775. arguments[0] = this;
  1776. callback.apply(null, arguments);
  1777. return this;
  1778. }
  1779. function selection_nodes() {
  1780. return Array.from(this);
  1781. }
  1782. function selection_node() {
  1783. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1784. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  1785. var node = group[i];
  1786. if (node) return node;
  1787. }
  1788. }
  1789. return null;
  1790. }
  1791. function selection_size() {
  1792. let size = 0;
  1793. for (const node of this) ++size; // eslint-disable-line no-unused-vars
  1794. return size;
  1795. }
  1796. function selection_empty() {
  1797. return !this.node();
  1798. }
  1799. function selection_each(callback) {
  1800. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1801. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  1802. if (node = group[i]) callback.call(node, node.__data__, i, group);
  1803. }
  1804. }
  1805. return this;
  1806. }
  1807. function attrRemove$1(name) {
  1808. return function() {
  1809. this.removeAttribute(name);
  1810. };
  1811. }
  1812. function attrRemoveNS$1(fullname) {
  1813. return function() {
  1814. this.removeAttributeNS(fullname.space, fullname.local);
  1815. };
  1816. }
  1817. function attrConstant$1(name, value) {
  1818. return function() {
  1819. this.setAttribute(name, value);
  1820. };
  1821. }
  1822. function attrConstantNS$1(fullname, value) {
  1823. return function() {
  1824. this.setAttributeNS(fullname.space, fullname.local, value);
  1825. };
  1826. }
  1827. function attrFunction$1(name, value) {
  1828. return function() {
  1829. var v = value.apply(this, arguments);
  1830. if (v == null) this.removeAttribute(name);
  1831. else this.setAttribute(name, v);
  1832. };
  1833. }
  1834. function attrFunctionNS$1(fullname, value) {
  1835. return function() {
  1836. var v = value.apply(this, arguments);
  1837. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1838. else this.setAttributeNS(fullname.space, fullname.local, v);
  1839. };
  1840. }
  1841. function selection_attr(name, value) {
  1842. var fullname = namespace(name);
  1843. if (arguments.length < 2) {
  1844. var node = this.node();
  1845. return fullname.local
  1846. ? node.getAttributeNS(fullname.space, fullname.local)
  1847. : node.getAttribute(fullname);
  1848. }
  1849. return this.each((value == null
  1850. ? (fullname.local ? attrRemoveNS$1 : attrRemove$1) : (typeof value === "function"
  1851. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)
  1852. : (fullname.local ? attrConstantNS$1 : attrConstant$1)))(fullname, value));
  1853. }
  1854. function defaultView(node) {
  1855. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1856. || (node.document && node) // node is a Window
  1857. || node.defaultView; // node is a Document
  1858. }
  1859. function styleRemove$1(name) {
  1860. return function() {
  1861. this.style.removeProperty(name);
  1862. };
  1863. }
  1864. function styleConstant$1(name, value, priority) {
  1865. return function() {
  1866. this.style.setProperty(name, value, priority);
  1867. };
  1868. }
  1869. function styleFunction$1(name, value, priority) {
  1870. return function() {
  1871. var v = value.apply(this, arguments);
  1872. if (v == null) this.style.removeProperty(name);
  1873. else this.style.setProperty(name, v, priority);
  1874. };
  1875. }
  1876. function selection_style(name, value, priority) {
  1877. return arguments.length > 1
  1878. ? this.each((value == null
  1879. ? styleRemove$1 : typeof value === "function"
  1880. ? styleFunction$1
  1881. : styleConstant$1)(name, value, priority == null ? "" : priority))
  1882. : styleValue(this.node(), name);
  1883. }
  1884. function styleValue(node, name) {
  1885. return node.style.getPropertyValue(name)
  1886. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1887. }
  1888. function propertyRemove(name) {
  1889. return function() {
  1890. delete this[name];
  1891. };
  1892. }
  1893. function propertyConstant(name, value) {
  1894. return function() {
  1895. this[name] = value;
  1896. };
  1897. }
  1898. function propertyFunction(name, value) {
  1899. return function() {
  1900. var v = value.apply(this, arguments);
  1901. if (v == null) delete this[name];
  1902. else this[name] = v;
  1903. };
  1904. }
  1905. function selection_property(name, value) {
  1906. return arguments.length > 1
  1907. ? this.each((value == null
  1908. ? propertyRemove : typeof value === "function"
  1909. ? propertyFunction
  1910. : propertyConstant)(name, value))
  1911. : this.node()[name];
  1912. }
  1913. function classArray(string) {
  1914. return string.trim().split(/^|\s+/);
  1915. }
  1916. function classList(node) {
  1917. return node.classList || new ClassList(node);
  1918. }
  1919. function ClassList(node) {
  1920. this._node = node;
  1921. this._names = classArray(node.getAttribute("class") || "");
  1922. }
  1923. ClassList.prototype = {
  1924. add: function(name) {
  1925. var i = this._names.indexOf(name);
  1926. if (i < 0) {
  1927. this._names.push(name);
  1928. this._node.setAttribute("class", this._names.join(" "));
  1929. }
  1930. },
  1931. remove: function(name) {
  1932. var i = this._names.indexOf(name);
  1933. if (i >= 0) {
  1934. this._names.splice(i, 1);
  1935. this._node.setAttribute("class", this._names.join(" "));
  1936. }
  1937. },
  1938. contains: function(name) {
  1939. return this._names.indexOf(name) >= 0;
  1940. }
  1941. };
  1942. function classedAdd(node, names) {
  1943. var list = classList(node), i = -1, n = names.length;
  1944. while (++i < n) list.add(names[i]);
  1945. }
  1946. function classedRemove(node, names) {
  1947. var list = classList(node), i = -1, n = names.length;
  1948. while (++i < n) list.remove(names[i]);
  1949. }
  1950. function classedTrue(names) {
  1951. return function() {
  1952. classedAdd(this, names);
  1953. };
  1954. }
  1955. function classedFalse(names) {
  1956. return function() {
  1957. classedRemove(this, names);
  1958. };
  1959. }
  1960. function classedFunction(names, value) {
  1961. return function() {
  1962. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1963. };
  1964. }
  1965. function selection_classed(name, value) {
  1966. var names = classArray(name + "");
  1967. if (arguments.length < 2) {
  1968. var list = classList(this.node()), i = -1, n = names.length;
  1969. while (++i < n) if (!list.contains(names[i])) return false;
  1970. return true;
  1971. }
  1972. return this.each((typeof value === "function"
  1973. ? classedFunction : value
  1974. ? classedTrue
  1975. : classedFalse)(names, value));
  1976. }
  1977. function textRemove() {
  1978. this.textContent = "";
  1979. }
  1980. function textConstant$1(value) {
  1981. return function() {
  1982. this.textContent = value;
  1983. };
  1984. }
  1985. function textFunction$1(value) {
  1986. return function() {
  1987. var v = value.apply(this, arguments);
  1988. this.textContent = v == null ? "" : v;
  1989. };
  1990. }
  1991. function selection_text(value) {
  1992. return arguments.length
  1993. ? this.each(value == null
  1994. ? textRemove : (typeof value === "function"
  1995. ? textFunction$1
  1996. : textConstant$1)(value))
  1997. : this.node().textContent;
  1998. }
  1999. function htmlRemove() {
  2000. this.innerHTML = "";
  2001. }
  2002. function htmlConstant(value) {
  2003. return function() {
  2004. this.innerHTML = value;
  2005. };
  2006. }
  2007. function htmlFunction(value) {
  2008. return function() {
  2009. var v = value.apply(this, arguments);
  2010. this.innerHTML = v == null ? "" : v;
  2011. };
  2012. }
  2013. function selection_html(value) {
  2014. return arguments.length
  2015. ? this.each(value == null
  2016. ? htmlRemove : (typeof value === "function"
  2017. ? htmlFunction
  2018. : htmlConstant)(value))
  2019. : this.node().innerHTML;
  2020. }
  2021. function raise() {
  2022. if (this.nextSibling) this.parentNode.appendChild(this);
  2023. }
  2024. function selection_raise() {
  2025. return this.each(raise);
  2026. }
  2027. function lower() {
  2028. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  2029. }
  2030. function selection_lower() {
  2031. return this.each(lower);
  2032. }
  2033. function selection_append(name) {
  2034. var create = typeof name === "function" ? name : creator(name);
  2035. return this.select(function() {
  2036. return this.appendChild(create.apply(this, arguments));
  2037. });
  2038. }
  2039. function constantNull() {
  2040. return null;
  2041. }
  2042. function selection_insert(name, before) {
  2043. var create = typeof name === "function" ? name : creator(name),
  2044. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  2045. return this.select(function() {
  2046. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  2047. });
  2048. }
  2049. function remove() {
  2050. var parent = this.parentNode;
  2051. if (parent) parent.removeChild(this);
  2052. }
  2053. function selection_remove() {
  2054. return this.each(remove);
  2055. }
  2056. function selection_cloneShallow() {
  2057. var clone = this.cloneNode(false), parent = this.parentNode;
  2058. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  2059. }
  2060. function selection_cloneDeep() {
  2061. var clone = this.cloneNode(true), parent = this.parentNode;
  2062. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  2063. }
  2064. function selection_clone(deep) {
  2065. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  2066. }
  2067. function selection_datum(value) {
  2068. return arguments.length
  2069. ? this.property("__data__", value)
  2070. : this.node().__data__;
  2071. }
  2072. function contextListener(listener) {
  2073. return function(event) {
  2074. listener.call(this, event, this.__data__);
  2075. };
  2076. }
  2077. function parseTypenames(typenames) {
  2078. return typenames.trim().split(/^|\s+/).map(function(t) {
  2079. var name = "", i = t.indexOf(".");
  2080. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  2081. return {type: t, name: name};
  2082. });
  2083. }
  2084. function onRemove(typename) {
  2085. return function() {
  2086. var on = this.__on;
  2087. if (!on) return;
  2088. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  2089. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  2090. this.removeEventListener(o.type, o.listener, o.options);
  2091. } else {
  2092. on[++i] = o;
  2093. }
  2094. }
  2095. if (++i) on.length = i;
  2096. else delete this.__on;
  2097. };
  2098. }
  2099. function onAdd(typename, value, options) {
  2100. return function() {
  2101. var on = this.__on, o, listener = contextListener(value);
  2102. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  2103. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  2104. this.removeEventListener(o.type, o.listener, o.options);
  2105. this.addEventListener(o.type, o.listener = listener, o.options = options);
  2106. o.value = value;
  2107. return;
  2108. }
  2109. }
  2110. this.addEventListener(typename.type, listener, options);
  2111. o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options};
  2112. if (!on) this.__on = [o];
  2113. else on.push(o);
  2114. };
  2115. }
  2116. function selection_on(typename, value, options) {
  2117. var typenames = parseTypenames(typename + ""), i, n = typenames.length, t;
  2118. if (arguments.length < 2) {
  2119. var on = this.node().__on;
  2120. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  2121. for (i = 0, o = on[j]; i < n; ++i) {
  2122. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  2123. return o.value;
  2124. }
  2125. }
  2126. }
  2127. return;
  2128. }
  2129. on = value ? onAdd : onRemove;
  2130. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options));
  2131. return this;
  2132. }
  2133. function dispatchEvent(node, type, params) {
  2134. var window = defaultView(node),
  2135. event = window.CustomEvent;
  2136. if (typeof event === "function") {
  2137. event = new event(type, params);
  2138. } else {
  2139. event = window.document.createEvent("Event");
  2140. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  2141. else event.initEvent(type, false, false);
  2142. }
  2143. node.dispatchEvent(event);
  2144. }
  2145. function dispatchConstant(type, params) {
  2146. return function() {
  2147. return dispatchEvent(this, type, params);
  2148. };
  2149. }
  2150. function dispatchFunction(type, params) {
  2151. return function() {
  2152. return dispatchEvent(this, type, params.apply(this, arguments));
  2153. };
  2154. }
  2155. function selection_dispatch(type, params) {
  2156. return this.each((typeof params === "function"
  2157. ? dispatchFunction
  2158. : dispatchConstant)(type, params));
  2159. }
  2160. function* selection_iterator() {
  2161. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  2162. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  2163. if (node = group[i]) yield node;
  2164. }
  2165. }
  2166. }
  2167. var root$1 = [null];
  2168. function Selection$1(groups, parents) {
  2169. this._groups = groups;
  2170. this._parents = parents;
  2171. }
  2172. function selection() {
  2173. return new Selection$1([[document.documentElement]], root$1);
  2174. }
  2175. function selection_selection() {
  2176. return this;
  2177. }
  2178. Selection$1.prototype = selection.prototype = {
  2179. constructor: Selection$1,
  2180. select: selection_select,
  2181. selectAll: selection_selectAll,
  2182. selectChild: selection_selectChild,
  2183. selectChildren: selection_selectChildren,
  2184. filter: selection_filter,
  2185. data: selection_data,
  2186. enter: selection_enter,
  2187. exit: selection_exit,
  2188. join: selection_join,
  2189. merge: selection_merge,
  2190. selection: selection_selection,
  2191. order: selection_order,
  2192. sort: selection_sort,
  2193. call: selection_call,
  2194. nodes: selection_nodes,
  2195. node: selection_node,
  2196. size: selection_size,
  2197. empty: selection_empty,
  2198. each: selection_each,
  2199. attr: selection_attr,
  2200. style: selection_style,
  2201. property: selection_property,
  2202. classed: selection_classed,
  2203. text: selection_text,
  2204. html: selection_html,
  2205. raise: selection_raise,
  2206. lower: selection_lower,
  2207. append: selection_append,
  2208. insert: selection_insert,
  2209. remove: selection_remove,
  2210. clone: selection_clone,
  2211. datum: selection_datum,
  2212. on: selection_on,
  2213. dispatch: selection_dispatch,
  2214. [Symbol.iterator]: selection_iterator
  2215. };
  2216. function select(selector) {
  2217. return typeof selector === "string"
  2218. ? new Selection$1([[document.querySelector(selector)]], [document.documentElement])
  2219. : new Selection$1([[selector]], root$1);
  2220. }
  2221. function create$1(name) {
  2222. return select(creator(name).call(document.documentElement));
  2223. }
  2224. var nextId = 0;
  2225. function local$1() {
  2226. return new Local;
  2227. }
  2228. function Local() {
  2229. this._ = "@" + (++nextId).toString(36);
  2230. }
  2231. Local.prototype = local$1.prototype = {
  2232. constructor: Local,
  2233. get: function(node) {
  2234. var id = this._;
  2235. while (!(id in node)) if (!(node = node.parentNode)) return;
  2236. return node[id];
  2237. },
  2238. set: function(node, value) {
  2239. return node[this._] = value;
  2240. },
  2241. remove: function(node) {
  2242. return this._ in node && delete node[this._];
  2243. },
  2244. toString: function() {
  2245. return this._;
  2246. }
  2247. };
  2248. function sourceEvent(event) {
  2249. let sourceEvent;
  2250. while (sourceEvent = event.sourceEvent) event = sourceEvent;
  2251. return event;
  2252. }
  2253. function pointer(event, node) {
  2254. event = sourceEvent(event);
  2255. if (node === undefined) node = event.currentTarget;
  2256. if (node) {
  2257. var svg = node.ownerSVGElement || node;
  2258. if (svg.createSVGPoint) {
  2259. var point = svg.createSVGPoint();
  2260. point.x = event.clientX, point.y = event.clientY;
  2261. point = point.matrixTransform(node.getScreenCTM().inverse());
  2262. return [point.x, point.y];
  2263. }
  2264. if (node.getBoundingClientRect) {
  2265. var rect = node.getBoundingClientRect();
  2266. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  2267. }
  2268. }
  2269. return [event.pageX, event.pageY];
  2270. }
  2271. function pointers(events, node) {
  2272. if (events.target) { // i.e., instanceof Event, not TouchList or iterable
  2273. events = sourceEvent(events);
  2274. if (node === undefined) node = events.currentTarget;
  2275. events = events.touches || [events];
  2276. }
  2277. return Array.from(events, event => pointer(event, node));
  2278. }
  2279. function selectAll(selector) {
  2280. return typeof selector === "string"
  2281. ? new Selection$1([document.querySelectorAll(selector)], [document.documentElement])
  2282. : new Selection$1([array$4(selector)], root$1);
  2283. }
  2284. // These are typically used in conjunction with noevent to ensure that we can
  2285. // preventDefault on the event.
  2286. const nonpassive = {passive: false};
  2287. const nonpassivecapture = {capture: true, passive: false};
  2288. function nopropagation$2(event) {
  2289. event.stopImmediatePropagation();
  2290. }
  2291. function noevent$2(event) {
  2292. event.preventDefault();
  2293. event.stopImmediatePropagation();
  2294. }
  2295. function dragDisable(view) {
  2296. var root = view.document.documentElement,
  2297. selection = select(view).on("dragstart.drag", noevent$2, nonpassivecapture);
  2298. if ("onselectstart" in root) {
  2299. selection.on("selectstart.drag", noevent$2, nonpassivecapture);
  2300. } else {
  2301. root.__noselect = root.style.MozUserSelect;
  2302. root.style.MozUserSelect = "none";
  2303. }
  2304. }
  2305. function yesdrag(view, noclick) {
  2306. var root = view.document.documentElement,
  2307. selection = select(view).on("dragstart.drag", null);
  2308. if (noclick) {
  2309. selection.on("click.drag", noevent$2, nonpassivecapture);
  2310. setTimeout(function() { selection.on("click.drag", null); }, 0);
  2311. }
  2312. if ("onselectstart" in root) {
  2313. selection.on("selectstart.drag", null);
  2314. } else {
  2315. root.style.MozUserSelect = root.__noselect;
  2316. delete root.__noselect;
  2317. }
  2318. }
  2319. var constant$9 = x => () => x;
  2320. function DragEvent(type, {
  2321. sourceEvent,
  2322. subject,
  2323. target,
  2324. identifier,
  2325. active,
  2326. x, y, dx, dy,
  2327. dispatch
  2328. }) {
  2329. Object.defineProperties(this, {
  2330. type: {value: type, enumerable: true, configurable: true},
  2331. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  2332. subject: {value: subject, enumerable: true, configurable: true},
  2333. target: {value: target, enumerable: true, configurable: true},
  2334. identifier: {value: identifier, enumerable: true, configurable: true},
  2335. active: {value: active, enumerable: true, configurable: true},
  2336. x: {value: x, enumerable: true, configurable: true},
  2337. y: {value: y, enumerable: true, configurable: true},
  2338. dx: {value: dx, enumerable: true, configurable: true},
  2339. dy: {value: dy, enumerable: true, configurable: true},
  2340. _: {value: dispatch}
  2341. });
  2342. }
  2343. DragEvent.prototype.on = function() {
  2344. var value = this._.on.apply(this._, arguments);
  2345. return value === this._ ? this : value;
  2346. };
  2347. // Ignore right-click, since that should open the context menu.
  2348. function defaultFilter$2(event) {
  2349. return !event.ctrlKey && !event.button;
  2350. }
  2351. function defaultContainer() {
  2352. return this.parentNode;
  2353. }
  2354. function defaultSubject(event, d) {
  2355. return d == null ? {x: event.x, y: event.y} : d;
  2356. }
  2357. function defaultTouchable$2() {
  2358. return navigator.maxTouchPoints || ("ontouchstart" in this);
  2359. }
  2360. function drag() {
  2361. var filter = defaultFilter$2,
  2362. container = defaultContainer,
  2363. subject = defaultSubject,
  2364. touchable = defaultTouchable$2,
  2365. gestures = {},
  2366. listeners = dispatch("start", "drag", "end"),
  2367. active = 0,
  2368. mousedownx,
  2369. mousedowny,
  2370. mousemoving,
  2371. touchending,
  2372. clickDistance2 = 0;
  2373. function drag(selection) {
  2374. selection
  2375. .on("mousedown.drag", mousedowned)
  2376. .filter(touchable)
  2377. .on("touchstart.drag", touchstarted)
  2378. .on("touchmove.drag", touchmoved, nonpassive)
  2379. .on("touchend.drag touchcancel.drag", touchended)
  2380. .style("touch-action", "none")
  2381. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  2382. }
  2383. function mousedowned(event, d) {
  2384. if (touchending || !filter.call(this, event, d)) return;
  2385. var gesture = beforestart(this, container.call(this, event, d), event, d, "mouse");
  2386. if (!gesture) return;
  2387. select(event.view)
  2388. .on("mousemove.drag", mousemoved, nonpassivecapture)
  2389. .on("mouseup.drag", mouseupped, nonpassivecapture);
  2390. dragDisable(event.view);
  2391. nopropagation$2(event);
  2392. mousemoving = false;
  2393. mousedownx = event.clientX;
  2394. mousedowny = event.clientY;
  2395. gesture("start", event);
  2396. }
  2397. function mousemoved(event) {
  2398. noevent$2(event);
  2399. if (!mousemoving) {
  2400. var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
  2401. mousemoving = dx * dx + dy * dy > clickDistance2;
  2402. }
  2403. gestures.mouse("drag", event);
  2404. }
  2405. function mouseupped(event) {
  2406. select(event.view).on("mousemove.drag mouseup.drag", null);
  2407. yesdrag(event.view, mousemoving);
  2408. noevent$2(event);
  2409. gestures.mouse("end", event);
  2410. }
  2411. function touchstarted(event, d) {
  2412. if (!filter.call(this, event, d)) return;
  2413. var touches = event.changedTouches,
  2414. c = container.call(this, event, d),
  2415. n = touches.length, i, gesture;
  2416. for (i = 0; i < n; ++i) {
  2417. if (gesture = beforestart(this, c, event, d, touches[i].identifier, touches[i])) {
  2418. nopropagation$2(event);
  2419. gesture("start", event, touches[i]);
  2420. }
  2421. }
  2422. }
  2423. function touchmoved(event) {
  2424. var touches = event.changedTouches,
  2425. n = touches.length, i, gesture;
  2426. for (i = 0; i < n; ++i) {
  2427. if (gesture = gestures[touches[i].identifier]) {
  2428. noevent$2(event);
  2429. gesture("drag", event, touches[i]);
  2430. }
  2431. }
  2432. }
  2433. function touchended(event) {
  2434. var touches = event.changedTouches,
  2435. n = touches.length, i, gesture;
  2436. if (touchending) clearTimeout(touchending);
  2437. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  2438. for (i = 0; i < n; ++i) {
  2439. if (gesture = gestures[touches[i].identifier]) {
  2440. nopropagation$2(event);
  2441. gesture("end", event, touches[i]);
  2442. }
  2443. }
  2444. }
  2445. function beforestart(that, container, event, d, identifier, touch) {
  2446. var dispatch = listeners.copy(),
  2447. p = pointer(touch || event, container), dx, dy,
  2448. s;
  2449. if ((s = subject.call(that, new DragEvent("beforestart", {
  2450. sourceEvent: event,
  2451. target: drag,
  2452. identifier,
  2453. active,
  2454. x: p[0],
  2455. y: p[1],
  2456. dx: 0,
  2457. dy: 0,
  2458. dispatch
  2459. }), d)) == null) return;
  2460. dx = s.x - p[0] || 0;
  2461. dy = s.y - p[1] || 0;
  2462. return function gesture(type, event, touch) {
  2463. var p0 = p, n;
  2464. switch (type) {
  2465. case "start": gestures[identifier] = gesture, n = active++; break;
  2466. case "end": delete gestures[identifier], --active; // falls through
  2467. case "drag": p = pointer(touch || event, container), n = active; break;
  2468. }
  2469. dispatch.call(
  2470. type,
  2471. that,
  2472. new DragEvent(type, {
  2473. sourceEvent: event,
  2474. subject: s,
  2475. target: drag,
  2476. identifier,
  2477. active: n,
  2478. x: p[0] + dx,
  2479. y: p[1] + dy,
  2480. dx: p[0] - p0[0],
  2481. dy: p[1] - p0[1],
  2482. dispatch
  2483. }),
  2484. d
  2485. );
  2486. };
  2487. }
  2488. drag.filter = function(_) {
  2489. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), drag) : filter;
  2490. };
  2491. drag.container = function(_) {
  2492. return arguments.length ? (container = typeof _ === "function" ? _ : constant$9(_), drag) : container;
  2493. };
  2494. drag.subject = function(_) {
  2495. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$9(_), drag) : subject;
  2496. };
  2497. drag.touchable = function(_) {
  2498. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$9(!!_), drag) : touchable;
  2499. };
  2500. drag.on = function() {
  2501. var value = listeners.on.apply(listeners, arguments);
  2502. return value === listeners ? drag : value;
  2503. };
  2504. drag.clickDistance = function(_) {
  2505. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  2506. };
  2507. return drag;
  2508. }
  2509. function define(constructor, factory, prototype) {
  2510. constructor.prototype = factory.prototype = prototype;
  2511. prototype.constructor = constructor;
  2512. }
  2513. function extend(parent, definition) {
  2514. var prototype = Object.create(parent.prototype);
  2515. for (var key in definition) prototype[key] = definition[key];
  2516. return prototype;
  2517. }
  2518. function Color() {}
  2519. var darker = 0.7;
  2520. var brighter = 1 / darker;
  2521. var reI = "\\s*([+-]?\\d+)\\s*",
  2522. reN = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  2523. reP = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  2524. reHex = /^#([0-9a-f]{3,8})$/,
  2525. reRgbInteger = new RegExp(`^rgb\\(${reI},${reI},${reI}\\)$`),
  2526. reRgbPercent = new RegExp(`^rgb\\(${reP},${reP},${reP}\\)$`),
  2527. reRgbaInteger = new RegExp(`^rgba\\(${reI},${reI},${reI},${reN}\\)$`),
  2528. reRgbaPercent = new RegExp(`^rgba\\(${reP},${reP},${reP},${reN}\\)$`),
  2529. reHslPercent = new RegExp(`^hsl\\(${reN},${reP},${reP}\\)$`),
  2530. reHslaPercent = new RegExp(`^hsla\\(${reN},${reP},${reP},${reN}\\)$`);
  2531. var named = {
  2532. aliceblue: 0xf0f8ff,
  2533. antiquewhite: 0xfaebd7,
  2534. aqua: 0x00ffff,
  2535. aquamarine: 0x7fffd4,
  2536. azure: 0xf0ffff,
  2537. beige: 0xf5f5dc,
  2538. bisque: 0xffe4c4,
  2539. black: 0x000000,
  2540. blanchedalmond: 0xffebcd,
  2541. blue: 0x0000ff,
  2542. blueviolet: 0x8a2be2,
  2543. brown: 0xa52a2a,
  2544. burlywood: 0xdeb887,
  2545. cadetblue: 0x5f9ea0,
  2546. chartreuse: 0x7fff00,
  2547. chocolate: 0xd2691e,
  2548. coral: 0xff7f50,
  2549. cornflowerblue: 0x6495ed,
  2550. cornsilk: 0xfff8dc,
  2551. crimson: 0xdc143c,
  2552. cyan: 0x00ffff,
  2553. darkblue: 0x00008b,
  2554. darkcyan: 0x008b8b,
  2555. darkgoldenrod: 0xb8860b,
  2556. darkgray: 0xa9a9a9,
  2557. darkgreen: 0x006400,
  2558. darkgrey: 0xa9a9a9,
  2559. darkkhaki: 0xbdb76b,
  2560. darkmagenta: 0x8b008b,
  2561. darkolivegreen: 0x556b2f,
  2562. darkorange: 0xff8c00,
  2563. darkorchid: 0x9932cc,
  2564. darkred: 0x8b0000,
  2565. darksalmon: 0xe9967a,
  2566. darkseagreen: 0x8fbc8f,
  2567. darkslateblue: 0x483d8b,
  2568. darkslategray: 0x2f4f4f,
  2569. darkslategrey: 0x2f4f4f,
  2570. darkturquoise: 0x00ced1,
  2571. darkviolet: 0x9400d3,
  2572. deeppink: 0xff1493,
  2573. deepskyblue: 0x00bfff,
  2574. dimgray: 0x696969,
  2575. dimgrey: 0x696969,
  2576. dodgerblue: 0x1e90ff,
  2577. firebrick: 0xb22222,
  2578. floralwhite: 0xfffaf0,
  2579. forestgreen: 0x228b22,
  2580. fuchsia: 0xff00ff,
  2581. gainsboro: 0xdcdcdc,
  2582. ghostwhite: 0xf8f8ff,
  2583. gold: 0xffd700,
  2584. goldenrod: 0xdaa520,
  2585. gray: 0x808080,
  2586. green: 0x008000,
  2587. greenyellow: 0xadff2f,
  2588. grey: 0x808080,
  2589. honeydew: 0xf0fff0,
  2590. hotpink: 0xff69b4,
  2591. indianred: 0xcd5c5c,
  2592. indigo: 0x4b0082,
  2593. ivory: 0xfffff0,
  2594. khaki: 0xf0e68c,
  2595. lavender: 0xe6e6fa,
  2596. lavenderblush: 0xfff0f5,
  2597. lawngreen: 0x7cfc00,
  2598. lemonchiffon: 0xfffacd,
  2599. lightblue: 0xadd8e6,
  2600. lightcoral: 0xf08080,
  2601. lightcyan: 0xe0ffff,
  2602. lightgoldenrodyellow: 0xfafad2,
  2603. lightgray: 0xd3d3d3,
  2604. lightgreen: 0x90ee90,
  2605. lightgrey: 0xd3d3d3,
  2606. lightpink: 0xffb6c1,
  2607. lightsalmon: 0xffa07a,
  2608. lightseagreen: 0x20b2aa,
  2609. lightskyblue: 0x87cefa,
  2610. lightslategray: 0x778899,
  2611. lightslategrey: 0x778899,
  2612. lightsteelblue: 0xb0c4de,
  2613. lightyellow: 0xffffe0,
  2614. lime: 0x00ff00,
  2615. limegreen: 0x32cd32,
  2616. linen: 0xfaf0e6,
  2617. magenta: 0xff00ff,
  2618. maroon: 0x800000,
  2619. mediumaquamarine: 0x66cdaa,
  2620. mediumblue: 0x0000cd,
  2621. mediumorchid: 0xba55d3,
  2622. mediumpurple: 0x9370db,
  2623. mediumseagreen: 0x3cb371,
  2624. mediumslateblue: 0x7b68ee,
  2625. mediumspringgreen: 0x00fa9a,
  2626. mediumturquoise: 0x48d1cc,
  2627. mediumvioletred: 0xc71585,
  2628. midnightblue: 0x191970,
  2629. mintcream: 0xf5fffa,
  2630. mistyrose: 0xffe4e1,
  2631. moccasin: 0xffe4b5,
  2632. navajowhite: 0xffdead,
  2633. navy: 0x000080,
  2634. oldlace: 0xfdf5e6,
  2635. olive: 0x808000,
  2636. olivedrab: 0x6b8e23,
  2637. orange: 0xffa500,
  2638. orangered: 0xff4500,
  2639. orchid: 0xda70d6,
  2640. palegoldenrod: 0xeee8aa,
  2641. palegreen: 0x98fb98,
  2642. paleturquoise: 0xafeeee,
  2643. palevioletred: 0xdb7093,
  2644. papayawhip: 0xffefd5,
  2645. peachpuff: 0xffdab9,
  2646. peru: 0xcd853f,
  2647. pink: 0xffc0cb,
  2648. plum: 0xdda0dd,
  2649. powderblue: 0xb0e0e6,
  2650. purple: 0x800080,
  2651. rebeccapurple: 0x663399,
  2652. red: 0xff0000,
  2653. rosybrown: 0xbc8f8f,
  2654. royalblue: 0x4169e1,
  2655. saddlebrown: 0x8b4513,
  2656. salmon: 0xfa8072,
  2657. sandybrown: 0xf4a460,
  2658. seagreen: 0x2e8b57,
  2659. seashell: 0xfff5ee,
  2660. sienna: 0xa0522d,
  2661. silver: 0xc0c0c0,
  2662. skyblue: 0x87ceeb,
  2663. slateblue: 0x6a5acd,
  2664. slategray: 0x708090,
  2665. slategrey: 0x708090,
  2666. snow: 0xfffafa,
  2667. springgreen: 0x00ff7f,
  2668. steelblue: 0x4682b4,
  2669. tan: 0xd2b48c,
  2670. teal: 0x008080,
  2671. thistle: 0xd8bfd8,
  2672. tomato: 0xff6347,
  2673. turquoise: 0x40e0d0,
  2674. violet: 0xee82ee,
  2675. wheat: 0xf5deb3,
  2676. white: 0xffffff,
  2677. whitesmoke: 0xf5f5f5,
  2678. yellow: 0xffff00,
  2679. yellowgreen: 0x9acd32
  2680. };
  2681. define(Color, color, {
  2682. copy(channels) {
  2683. return Object.assign(new this.constructor, this, channels);
  2684. },
  2685. displayable() {
  2686. return this.rgb().displayable();
  2687. },
  2688. hex: color_formatHex, // Deprecated! Use color.formatHex.
  2689. formatHex: color_formatHex,
  2690. formatHex8: color_formatHex8,
  2691. formatHsl: color_formatHsl,
  2692. formatRgb: color_formatRgb,
  2693. toString: color_formatRgb
  2694. });
  2695. function color_formatHex() {
  2696. return this.rgb().formatHex();
  2697. }
  2698. function color_formatHex8() {
  2699. return this.rgb().formatHex8();
  2700. }
  2701. function color_formatHsl() {
  2702. return hslConvert(this).formatHsl();
  2703. }
  2704. function color_formatRgb() {
  2705. return this.rgb().formatRgb();
  2706. }
  2707. function color(format) {
  2708. var m, l;
  2709. format = (format + "").trim().toLowerCase();
  2710. return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
  2711. : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
  2712. : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
  2713. : l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
  2714. : null) // invalid hex
  2715. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  2716. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  2717. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  2718. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  2719. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  2720. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  2721. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  2722. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  2723. : null;
  2724. }
  2725. function rgbn(n) {
  2726. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  2727. }
  2728. function rgba(r, g, b, a) {
  2729. if (a <= 0) r = g = b = NaN;
  2730. return new Rgb(r, g, b, a);
  2731. }
  2732. function rgbConvert(o) {
  2733. if (!(o instanceof Color)) o = color(o);
  2734. if (!o) return new Rgb;
  2735. o = o.rgb();
  2736. return new Rgb(o.r, o.g, o.b, o.opacity);
  2737. }
  2738. function rgb(r, g, b, opacity) {
  2739. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  2740. }
  2741. function Rgb(r, g, b, opacity) {
  2742. this.r = +r;
  2743. this.g = +g;
  2744. this.b = +b;
  2745. this.opacity = +opacity;
  2746. }
  2747. define(Rgb, rgb, extend(Color, {
  2748. brighter(k) {
  2749. k = k == null ? brighter : Math.pow(brighter, k);
  2750. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  2751. },
  2752. darker(k) {
  2753. k = k == null ? darker : Math.pow(darker, k);
  2754. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  2755. },
  2756. rgb() {
  2757. return this;
  2758. },
  2759. clamp() {
  2760. return new Rgb(clampi(this.r), clampi(this.g), clampi(this.b), clampa(this.opacity));
  2761. },
  2762. displayable() {
  2763. return (-0.5 <= this.r && this.r < 255.5)
  2764. && (-0.5 <= this.g && this.g < 255.5)
  2765. && (-0.5 <= this.b && this.b < 255.5)
  2766. && (0 <= this.opacity && this.opacity <= 1);
  2767. },
  2768. hex: rgb_formatHex, // Deprecated! Use color.formatHex.
  2769. formatHex: rgb_formatHex,
  2770. formatHex8: rgb_formatHex8,
  2771. formatRgb: rgb_formatRgb,
  2772. toString: rgb_formatRgb
  2773. }));
  2774. function rgb_formatHex() {
  2775. return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}`;
  2776. }
  2777. function rgb_formatHex8() {
  2778. return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}${hex((isNaN(this.opacity) ? 1 : this.opacity) * 255)}`;
  2779. }
  2780. function rgb_formatRgb() {
  2781. const a = clampa(this.opacity);
  2782. return `${a === 1 ? "rgb(" : "rgba("}${clampi(this.r)}, ${clampi(this.g)}, ${clampi(this.b)}${a === 1 ? ")" : `, ${a})`}`;
  2783. }
  2784. function clampa(opacity) {
  2785. return isNaN(opacity) ? 1 : Math.max(0, Math.min(1, opacity));
  2786. }
  2787. function clampi(value) {
  2788. return Math.max(0, Math.min(255, Math.round(value) || 0));
  2789. }
  2790. function hex(value) {
  2791. value = clampi(value);
  2792. return (value < 16 ? "0" : "") + value.toString(16);
  2793. }
  2794. function hsla(h, s, l, a) {
  2795. if (a <= 0) h = s = l = NaN;
  2796. else if (l <= 0 || l >= 1) h = s = NaN;
  2797. else if (s <= 0) h = NaN;
  2798. return new Hsl(h, s, l, a);
  2799. }
  2800. function hslConvert(o) {
  2801. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  2802. if (!(o instanceof Color)) o = color(o);
  2803. if (!o) return new Hsl;
  2804. if (o instanceof Hsl) return o;
  2805. o = o.rgb();
  2806. var r = o.r / 255,
  2807. g = o.g / 255,
  2808. b = o.b / 255,
  2809. min = Math.min(r, g, b),
  2810. max = Math.max(r, g, b),
  2811. h = NaN,
  2812. s = max - min,
  2813. l = (max + min) / 2;
  2814. if (s) {
  2815. if (r === max) h = (g - b) / s + (g < b) * 6;
  2816. else if (g === max) h = (b - r) / s + 2;
  2817. else h = (r - g) / s + 4;
  2818. s /= l < 0.5 ? max + min : 2 - max - min;
  2819. h *= 60;
  2820. } else {
  2821. s = l > 0 && l < 1 ? 0 : h;
  2822. }
  2823. return new Hsl(h, s, l, o.opacity);
  2824. }
  2825. function hsl$2(h, s, l, opacity) {
  2826. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  2827. }
  2828. function Hsl(h, s, l, opacity) {
  2829. this.h = +h;
  2830. this.s = +s;
  2831. this.l = +l;
  2832. this.opacity = +opacity;
  2833. }
  2834. define(Hsl, hsl$2, extend(Color, {
  2835. brighter(k) {
  2836. k = k == null ? brighter : Math.pow(brighter, k);
  2837. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  2838. },
  2839. darker(k) {
  2840. k = k == null ? darker : Math.pow(darker, k);
  2841. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  2842. },
  2843. rgb() {
  2844. var h = this.h % 360 + (this.h < 0) * 360,
  2845. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  2846. l = this.l,
  2847. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  2848. m1 = 2 * l - m2;
  2849. return new Rgb(
  2850. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  2851. hsl2rgb(h, m1, m2),
  2852. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  2853. this.opacity
  2854. );
  2855. },
  2856. clamp() {
  2857. return new Hsl(clamph(this.h), clampt(this.s), clampt(this.l), clampa(this.opacity));
  2858. },
  2859. displayable() {
  2860. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  2861. && (0 <= this.l && this.l <= 1)
  2862. && (0 <= this.opacity && this.opacity <= 1);
  2863. },
  2864. formatHsl() {
  2865. const a = clampa(this.opacity);
  2866. return `${a === 1 ? "hsl(" : "hsla("}${clamph(this.h)}, ${clampt(this.s) * 100}%, ${clampt(this.l) * 100}%${a === 1 ? ")" : `, ${a})`}`;
  2867. }
  2868. }));
  2869. function clamph(value) {
  2870. value = (value || 0) % 360;
  2871. return value < 0 ? value + 360 : value;
  2872. }
  2873. function clampt(value) {
  2874. return Math.max(0, Math.min(1, value || 0));
  2875. }
  2876. /* From FvD 13.37, CSS Color Module Level 3 */
  2877. function hsl2rgb(h, m1, m2) {
  2878. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2879. : h < 180 ? m2
  2880. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2881. : m1) * 255;
  2882. }
  2883. const radians$1 = Math.PI / 180;
  2884. const degrees$2 = 180 / Math.PI;
  2885. // https://observablehq.com/@mbostock/lab-and-rgb
  2886. const K = 18,
  2887. Xn = 0.96422,
  2888. Yn = 1,
  2889. Zn = 0.82521,
  2890. t0$1 = 4 / 29,
  2891. t1$1 = 6 / 29,
  2892. t2 = 3 * t1$1 * t1$1,
  2893. t3 = t1$1 * t1$1 * t1$1;
  2894. function labConvert(o) {
  2895. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2896. if (o instanceof Hcl) return hcl2lab(o);
  2897. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2898. var r = rgb2lrgb(o.r),
  2899. g = rgb2lrgb(o.g),
  2900. b = rgb2lrgb(o.b),
  2901. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2902. if (r === g && g === b) x = z = y; else {
  2903. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2904. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2905. }
  2906. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2907. }
  2908. function gray(l, opacity) {
  2909. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2910. }
  2911. function lab$1(l, a, b, opacity) {
  2912. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2913. }
  2914. function Lab(l, a, b, opacity) {
  2915. this.l = +l;
  2916. this.a = +a;
  2917. this.b = +b;
  2918. this.opacity = +opacity;
  2919. }
  2920. define(Lab, lab$1, extend(Color, {
  2921. brighter(k) {
  2922. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2923. },
  2924. darker(k) {
  2925. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2926. },
  2927. rgb() {
  2928. var y = (this.l + 16) / 116,
  2929. x = isNaN(this.a) ? y : y + this.a / 500,
  2930. z = isNaN(this.b) ? y : y - this.b / 200;
  2931. x = Xn * lab2xyz(x);
  2932. y = Yn * lab2xyz(y);
  2933. z = Zn * lab2xyz(z);
  2934. return new Rgb(
  2935. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2936. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2937. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2938. this.opacity
  2939. );
  2940. }
  2941. }));
  2942. function xyz2lab(t) {
  2943. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0$1;
  2944. }
  2945. function lab2xyz(t) {
  2946. return t > t1$1 ? t * t * t : t2 * (t - t0$1);
  2947. }
  2948. function lrgb2rgb(x) {
  2949. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2950. }
  2951. function rgb2lrgb(x) {
  2952. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2953. }
  2954. function hclConvert(o) {
  2955. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2956. if (!(o instanceof Lab)) o = labConvert(o);
  2957. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
  2958. var h = Math.atan2(o.b, o.a) * degrees$2;
  2959. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2960. }
  2961. function lch(l, c, h, opacity) {
  2962. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2963. }
  2964. function hcl$2(h, c, l, opacity) {
  2965. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2966. }
  2967. function Hcl(h, c, l, opacity) {
  2968. this.h = +h;
  2969. this.c = +c;
  2970. this.l = +l;
  2971. this.opacity = +opacity;
  2972. }
  2973. function hcl2lab(o) {
  2974. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2975. var h = o.h * radians$1;
  2976. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2977. }
  2978. define(Hcl, hcl$2, extend(Color, {
  2979. brighter(k) {
  2980. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2981. },
  2982. darker(k) {
  2983. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2984. },
  2985. rgb() {
  2986. return hcl2lab(this).rgb();
  2987. }
  2988. }));
  2989. var A = -0.14861,
  2990. B$1 = +1.78277,
  2991. C = -0.29227,
  2992. D$1 = -0.90649,
  2993. E = +1.97294,
  2994. ED = E * D$1,
  2995. EB = E * B$1,
  2996. BC_DA = B$1 * C - D$1 * A;
  2997. function cubehelixConvert(o) {
  2998. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2999. if (!(o instanceof Rgb)) o = rgbConvert(o);
  3000. var r = o.r / 255,
  3001. g = o.g / 255,
  3002. b = o.b / 255,
  3003. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  3004. bl = b - l,
  3005. k = (E * (g - l) - C * bl) / D$1,
  3006. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  3007. h = s ? Math.atan2(k, bl) * degrees$2 - 120 : NaN;
  3008. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  3009. }
  3010. function cubehelix$3(h, s, l, opacity) {
  3011. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  3012. }
  3013. function Cubehelix(h, s, l, opacity) {
  3014. this.h = +h;
  3015. this.s = +s;
  3016. this.l = +l;
  3017. this.opacity = +opacity;
  3018. }
  3019. define(Cubehelix, cubehelix$3, extend(Color, {
  3020. brighter(k) {
  3021. k = k == null ? brighter : Math.pow(brighter, k);
  3022. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3023. },
  3024. darker(k) {
  3025. k = k == null ? darker : Math.pow(darker, k);
  3026. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3027. },
  3028. rgb() {
  3029. var h = isNaN(this.h) ? 0 : (this.h + 120) * radians$1,
  3030. l = +this.l,
  3031. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  3032. cosh = Math.cos(h),
  3033. sinh = Math.sin(h);
  3034. return new Rgb(
  3035. 255 * (l + a * (A * cosh + B$1 * sinh)),
  3036. 255 * (l + a * (C * cosh + D$1 * sinh)),
  3037. 255 * (l + a * (E * cosh)),
  3038. this.opacity
  3039. );
  3040. }
  3041. }));
  3042. function basis$1(t1, v0, v1, v2, v3) {
  3043. var t2 = t1 * t1, t3 = t2 * t1;
  3044. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  3045. + (4 - 6 * t2 + 3 * t3) * v1
  3046. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  3047. + t3 * v3) / 6;
  3048. }
  3049. function basis$2(values) {
  3050. var n = values.length - 1;
  3051. return function(t) {
  3052. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  3053. v1 = values[i],
  3054. v2 = values[i + 1],
  3055. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  3056. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  3057. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3058. };
  3059. }
  3060. function basisClosed$1(values) {
  3061. var n = values.length;
  3062. return function(t) {
  3063. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  3064. v0 = values[(i + n - 1) % n],
  3065. v1 = values[i % n],
  3066. v2 = values[(i + 1) % n],
  3067. v3 = values[(i + 2) % n];
  3068. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3069. };
  3070. }
  3071. var constant$8 = x => () => x;
  3072. function linear$2(a, d) {
  3073. return function(t) {
  3074. return a + t * d;
  3075. };
  3076. }
  3077. function exponential$1(a, b, y) {
  3078. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  3079. return Math.pow(a + t * b, y);
  3080. };
  3081. }
  3082. function hue$1(a, b) {
  3083. var d = b - a;
  3084. return d ? linear$2(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$8(isNaN(a) ? b : a);
  3085. }
  3086. function gamma$1(y) {
  3087. return (y = +y) === 1 ? nogamma : function(a, b) {
  3088. return b - a ? exponential$1(a, b, y) : constant$8(isNaN(a) ? b : a);
  3089. };
  3090. }
  3091. function nogamma(a, b) {
  3092. var d = b - a;
  3093. return d ? linear$2(a, d) : constant$8(isNaN(a) ? b : a);
  3094. }
  3095. var interpolateRgb = (function rgbGamma(y) {
  3096. var color = gamma$1(y);
  3097. function rgb$1(start, end) {
  3098. var r = color((start = rgb(start)).r, (end = rgb(end)).r),
  3099. g = color(start.g, end.g),
  3100. b = color(start.b, end.b),
  3101. opacity = nogamma(start.opacity, end.opacity);
  3102. return function(t) {
  3103. start.r = r(t);
  3104. start.g = g(t);
  3105. start.b = b(t);
  3106. start.opacity = opacity(t);
  3107. return start + "";
  3108. };
  3109. }
  3110. rgb$1.gamma = rgbGamma;
  3111. return rgb$1;
  3112. })(1);
  3113. function rgbSpline(spline) {
  3114. return function(colors) {
  3115. var n = colors.length,
  3116. r = new Array(n),
  3117. g = new Array(n),
  3118. b = new Array(n),
  3119. i, color;
  3120. for (i = 0; i < n; ++i) {
  3121. color = rgb(colors[i]);
  3122. r[i] = color.r || 0;
  3123. g[i] = color.g || 0;
  3124. b[i] = color.b || 0;
  3125. }
  3126. r = spline(r);
  3127. g = spline(g);
  3128. b = spline(b);
  3129. color.opacity = 1;
  3130. return function(t) {
  3131. color.r = r(t);
  3132. color.g = g(t);
  3133. color.b = b(t);
  3134. return color + "";
  3135. };
  3136. };
  3137. }
  3138. var rgbBasis = rgbSpline(basis$2);
  3139. var rgbBasisClosed = rgbSpline(basisClosed$1);
  3140. function numberArray(a, b) {
  3141. if (!b) b = [];
  3142. var n = a ? Math.min(b.length, a.length) : 0,
  3143. c = b.slice(),
  3144. i;
  3145. return function(t) {
  3146. for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
  3147. return c;
  3148. };
  3149. }
  3150. function isNumberArray(x) {
  3151. return ArrayBuffer.isView(x) && !(x instanceof DataView);
  3152. }
  3153. function array$3(a, b) {
  3154. return (isNumberArray(b) ? numberArray : genericArray)(a, b);
  3155. }
  3156. function genericArray(a, b) {
  3157. var nb = b ? b.length : 0,
  3158. na = a ? Math.min(nb, a.length) : 0,
  3159. x = new Array(na),
  3160. c = new Array(nb),
  3161. i;
  3162. for (i = 0; i < na; ++i) x[i] = interpolate$2(a[i], b[i]);
  3163. for (; i < nb; ++i) c[i] = b[i];
  3164. return function(t) {
  3165. for (i = 0; i < na; ++i) c[i] = x[i](t);
  3166. return c;
  3167. };
  3168. }
  3169. function date$1(a, b) {
  3170. var d = new Date;
  3171. return a = +a, b = +b, function(t) {
  3172. return d.setTime(a * (1 - t) + b * t), d;
  3173. };
  3174. }
  3175. function interpolateNumber(a, b) {
  3176. return a = +a, b = +b, function(t) {
  3177. return a * (1 - t) + b * t;
  3178. };
  3179. }
  3180. function object$1(a, b) {
  3181. var i = {},
  3182. c = {},
  3183. k;
  3184. if (a === null || typeof a !== "object") a = {};
  3185. if (b === null || typeof b !== "object") b = {};
  3186. for (k in b) {
  3187. if (k in a) {
  3188. i[k] = interpolate$2(a[k], b[k]);
  3189. } else {
  3190. c[k] = b[k];
  3191. }
  3192. }
  3193. return function(t) {
  3194. for (k in i) c[k] = i[k](t);
  3195. return c;
  3196. };
  3197. }
  3198. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  3199. reB = new RegExp(reA.source, "g");
  3200. function zero(b) {
  3201. return function() {
  3202. return b;
  3203. };
  3204. }
  3205. function one(b) {
  3206. return function(t) {
  3207. return b(t) + "";
  3208. };
  3209. }
  3210. function interpolateString(a, b) {
  3211. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  3212. am, // current match in a
  3213. bm, // current match in b
  3214. bs, // string preceding current number in b, if any
  3215. i = -1, // index in s
  3216. s = [], // string constants and placeholders
  3217. q = []; // number interpolators
  3218. // Coerce inputs to strings.
  3219. a = a + "", b = b + "";
  3220. // Interpolate pairs of numbers in a & b.
  3221. while ((am = reA.exec(a))
  3222. && (bm = reB.exec(b))) {
  3223. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  3224. bs = b.slice(bi, bs);
  3225. if (s[i]) s[i] += bs; // coalesce with previous string
  3226. else s[++i] = bs;
  3227. }
  3228. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  3229. if (s[i]) s[i] += bm; // coalesce with previous string
  3230. else s[++i] = bm;
  3231. } else { // interpolate non-matching numbers
  3232. s[++i] = null;
  3233. q.push({i: i, x: interpolateNumber(am, bm)});
  3234. }
  3235. bi = reB.lastIndex;
  3236. }
  3237. // Add remains of b.
  3238. if (bi < b.length) {
  3239. bs = b.slice(bi);
  3240. if (s[i]) s[i] += bs; // coalesce with previous string
  3241. else s[++i] = bs;
  3242. }
  3243. // Special optimization for only a single match.
  3244. // Otherwise, interpolate each of the numbers and rejoin the string.
  3245. return s.length < 2 ? (q[0]
  3246. ? one(q[0].x)
  3247. : zero(b))
  3248. : (b = q.length, function(t) {
  3249. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  3250. return s.join("");
  3251. });
  3252. }
  3253. function interpolate$2(a, b) {
  3254. var t = typeof b, c;
  3255. return b == null || t === "boolean" ? constant$8(b)
  3256. : (t === "number" ? interpolateNumber
  3257. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  3258. : b instanceof color ? interpolateRgb
  3259. : b instanceof Date ? date$1
  3260. : isNumberArray(b) ? numberArray
  3261. : Array.isArray(b) ? genericArray
  3262. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object$1
  3263. : interpolateNumber)(a, b);
  3264. }
  3265. function discrete(range) {
  3266. var n = range.length;
  3267. return function(t) {
  3268. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  3269. };
  3270. }
  3271. function hue(a, b) {
  3272. var i = hue$1(+a, +b);
  3273. return function(t) {
  3274. var x = i(t);
  3275. return x - 360 * Math.floor(x / 360);
  3276. };
  3277. }
  3278. function interpolateRound(a, b) {
  3279. return a = +a, b = +b, function(t) {
  3280. return Math.round(a * (1 - t) + b * t);
  3281. };
  3282. }
  3283. var degrees$1 = 180 / Math.PI;
  3284. var identity$7 = {
  3285. translateX: 0,
  3286. translateY: 0,
  3287. rotate: 0,
  3288. skewX: 0,
  3289. scaleX: 1,
  3290. scaleY: 1
  3291. };
  3292. function decompose(a, b, c, d, e, f) {
  3293. var scaleX, scaleY, skewX;
  3294. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  3295. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  3296. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  3297. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  3298. return {
  3299. translateX: e,
  3300. translateY: f,
  3301. rotate: Math.atan2(b, a) * degrees$1,
  3302. skewX: Math.atan(skewX) * degrees$1,
  3303. scaleX: scaleX,
  3304. scaleY: scaleY
  3305. };
  3306. }
  3307. var svgNode;
  3308. /* eslint-disable no-undef */
  3309. function parseCss(value) {
  3310. const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
  3311. return m.isIdentity ? identity$7 : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
  3312. }
  3313. function parseSvg(value) {
  3314. if (value == null) return identity$7;
  3315. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  3316. svgNode.setAttribute("transform", value);
  3317. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$7;
  3318. value = value.matrix;
  3319. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  3320. }
  3321. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  3322. function pop(s) {
  3323. return s.length ? s.pop() + " " : "";
  3324. }
  3325. function translate(xa, ya, xb, yb, s, q) {
  3326. if (xa !== xb || ya !== yb) {
  3327. var i = s.push("translate(", null, pxComma, null, pxParen);
  3328. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3329. } else if (xb || yb) {
  3330. s.push("translate(" + xb + pxComma + yb + pxParen);
  3331. }
  3332. }
  3333. function rotate(a, b, s, q) {
  3334. if (a !== b) {
  3335. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  3336. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3337. } else if (b) {
  3338. s.push(pop(s) + "rotate(" + b + degParen);
  3339. }
  3340. }
  3341. function skewX(a, b, s, q) {
  3342. if (a !== b) {
  3343. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3344. } else if (b) {
  3345. s.push(pop(s) + "skewX(" + b + degParen);
  3346. }
  3347. }
  3348. function scale(xa, ya, xb, yb, s, q) {
  3349. if (xa !== xb || ya !== yb) {
  3350. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  3351. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3352. } else if (xb !== 1 || yb !== 1) {
  3353. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  3354. }
  3355. }
  3356. return function(a, b) {
  3357. var s = [], // string constants and placeholders
  3358. q = []; // number interpolators
  3359. a = parse(a), b = parse(b);
  3360. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  3361. rotate(a.rotate, b.rotate, s, q);
  3362. skewX(a.skewX, b.skewX, s, q);
  3363. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  3364. a = b = null; // gc
  3365. return function(t) {
  3366. var i = -1, n = q.length, o;
  3367. while (++i < n) s[(o = q[i]).i] = o.x(t);
  3368. return s.join("");
  3369. };
  3370. };
  3371. }
  3372. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  3373. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  3374. var epsilon2$1 = 1e-12;
  3375. function cosh(x) {
  3376. return ((x = Math.exp(x)) + 1 / x) / 2;
  3377. }
  3378. function sinh(x) {
  3379. return ((x = Math.exp(x)) - 1 / x) / 2;
  3380. }
  3381. function tanh(x) {
  3382. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  3383. }
  3384. var interpolateZoom = (function zoomRho(rho, rho2, rho4) {
  3385. // p0 = [ux0, uy0, w0]
  3386. // p1 = [ux1, uy1, w1]
  3387. function zoom(p0, p1) {
  3388. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  3389. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  3390. dx = ux1 - ux0,
  3391. dy = uy1 - uy0,
  3392. d2 = dx * dx + dy * dy,
  3393. i,
  3394. S;
  3395. // Special case for u0 ≅ u1.
  3396. if (d2 < epsilon2$1) {
  3397. S = Math.log(w1 / w0) / rho;
  3398. i = function(t) {
  3399. return [
  3400. ux0 + t * dx,
  3401. uy0 + t * dy,
  3402. w0 * Math.exp(rho * t * S)
  3403. ];
  3404. };
  3405. }
  3406. // General case.
  3407. else {
  3408. var d1 = Math.sqrt(d2),
  3409. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  3410. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  3411. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  3412. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  3413. S = (r1 - r0) / rho;
  3414. i = function(t) {
  3415. var s = t * S,
  3416. coshr0 = cosh(r0),
  3417. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  3418. return [
  3419. ux0 + u * dx,
  3420. uy0 + u * dy,
  3421. w0 * coshr0 / cosh(rho * s + r0)
  3422. ];
  3423. };
  3424. }
  3425. i.duration = S * 1000 * rho / Math.SQRT2;
  3426. return i;
  3427. }
  3428. zoom.rho = function(_) {
  3429. var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
  3430. return zoomRho(_1, _2, _4);
  3431. };
  3432. return zoom;
  3433. })(Math.SQRT2, 2, 4);
  3434. function hsl(hue) {
  3435. return function(start, end) {
  3436. var h = hue((start = hsl$2(start)).h, (end = hsl$2(end)).h),
  3437. s = nogamma(start.s, end.s),
  3438. l = nogamma(start.l, end.l),
  3439. opacity = nogamma(start.opacity, end.opacity);
  3440. return function(t) {
  3441. start.h = h(t);
  3442. start.s = s(t);
  3443. start.l = l(t);
  3444. start.opacity = opacity(t);
  3445. return start + "";
  3446. };
  3447. }
  3448. }
  3449. var hsl$1 = hsl(hue$1);
  3450. var hslLong = hsl(nogamma);
  3451. function lab(start, end) {
  3452. var l = nogamma((start = lab$1(start)).l, (end = lab$1(end)).l),
  3453. a = nogamma(start.a, end.a),
  3454. b = nogamma(start.b, end.b),
  3455. opacity = nogamma(start.opacity, end.opacity);
  3456. return function(t) {
  3457. start.l = l(t);
  3458. start.a = a(t);
  3459. start.b = b(t);
  3460. start.opacity = opacity(t);
  3461. return start + "";
  3462. };
  3463. }
  3464. function hcl(hue) {
  3465. return function(start, end) {
  3466. var h = hue((start = hcl$2(start)).h, (end = hcl$2(end)).h),
  3467. c = nogamma(start.c, end.c),
  3468. l = nogamma(start.l, end.l),
  3469. opacity = nogamma(start.opacity, end.opacity);
  3470. return function(t) {
  3471. start.h = h(t);
  3472. start.c = c(t);
  3473. start.l = l(t);
  3474. start.opacity = opacity(t);
  3475. return start + "";
  3476. };
  3477. }
  3478. }
  3479. var hcl$1 = hcl(hue$1);
  3480. var hclLong = hcl(nogamma);
  3481. function cubehelix$1(hue) {
  3482. return (function cubehelixGamma(y) {
  3483. y = +y;
  3484. function cubehelix(start, end) {
  3485. var h = hue((start = cubehelix$3(start)).h, (end = cubehelix$3(end)).h),
  3486. s = nogamma(start.s, end.s),
  3487. l = nogamma(start.l, end.l),
  3488. opacity = nogamma(start.opacity, end.opacity);
  3489. return function(t) {
  3490. start.h = h(t);
  3491. start.s = s(t);
  3492. start.l = l(Math.pow(t, y));
  3493. start.opacity = opacity(t);
  3494. return start + "";
  3495. };
  3496. }
  3497. cubehelix.gamma = cubehelixGamma;
  3498. return cubehelix;
  3499. })(1);
  3500. }
  3501. var cubehelix$2 = cubehelix$1(hue$1);
  3502. var cubehelixLong = cubehelix$1(nogamma);
  3503. function piecewise(interpolate, values) {
  3504. if (values === undefined) values = interpolate, interpolate = interpolate$2;
  3505. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  3506. while (i < n) I[i] = interpolate(v, v = values[++i]);
  3507. return function(t) {
  3508. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  3509. return I[i](t - i);
  3510. };
  3511. }
  3512. function quantize$1(interpolator, n) {
  3513. var samples = new Array(n);
  3514. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  3515. return samples;
  3516. }
  3517. var frame = 0, // is an animation frame pending?
  3518. timeout$1 = 0, // is a timeout pending?
  3519. interval$1 = 0, // are any timers active?
  3520. pokeDelay = 1000, // how frequently we check for clock skew
  3521. taskHead,
  3522. taskTail,
  3523. clockLast = 0,
  3524. clockNow = 0,
  3525. clockSkew = 0,
  3526. clock = typeof performance === "object" && performance.now ? performance : Date,
  3527. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  3528. function now() {
  3529. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  3530. }
  3531. function clearNow() {
  3532. clockNow = 0;
  3533. }
  3534. function Timer() {
  3535. this._call =
  3536. this._time =
  3537. this._next = null;
  3538. }
  3539. Timer.prototype = timer.prototype = {
  3540. constructor: Timer,
  3541. restart: function(callback, delay, time) {
  3542. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  3543. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  3544. if (!this._next && taskTail !== this) {
  3545. if (taskTail) taskTail._next = this;
  3546. else taskHead = this;
  3547. taskTail = this;
  3548. }
  3549. this._call = callback;
  3550. this._time = time;
  3551. sleep();
  3552. },
  3553. stop: function() {
  3554. if (this._call) {
  3555. this._call = null;
  3556. this._time = Infinity;
  3557. sleep();
  3558. }
  3559. }
  3560. };
  3561. function timer(callback, delay, time) {
  3562. var t = new Timer;
  3563. t.restart(callback, delay, time);
  3564. return t;
  3565. }
  3566. function timerFlush() {
  3567. now(); // Get the current time, if not already set.
  3568. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  3569. var t = taskHead, e;
  3570. while (t) {
  3571. if ((e = clockNow - t._time) >= 0) t._call.call(undefined, e);
  3572. t = t._next;
  3573. }
  3574. --frame;
  3575. }
  3576. function wake() {
  3577. clockNow = (clockLast = clock.now()) + clockSkew;
  3578. frame = timeout$1 = 0;
  3579. try {
  3580. timerFlush();
  3581. } finally {
  3582. frame = 0;
  3583. nap();
  3584. clockNow = 0;
  3585. }
  3586. }
  3587. function poke() {
  3588. var now = clock.now(), delay = now - clockLast;
  3589. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  3590. }
  3591. function nap() {
  3592. var t0, t1 = taskHead, t2, time = Infinity;
  3593. while (t1) {
  3594. if (t1._call) {
  3595. if (time > t1._time) time = t1._time;
  3596. t0 = t1, t1 = t1._next;
  3597. } else {
  3598. t2 = t1._next, t1._next = null;
  3599. t1 = t0 ? t0._next = t2 : taskHead = t2;
  3600. }
  3601. }
  3602. taskTail = t0;
  3603. sleep(time);
  3604. }
  3605. function sleep(time) {
  3606. if (frame) return; // Soonest alarm already set, or will be.
  3607. if (timeout$1) timeout$1 = clearTimeout(timeout$1);
  3608. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  3609. if (delay > 24) {
  3610. if (time < Infinity) timeout$1 = setTimeout(wake, time - clock.now() - clockSkew);
  3611. if (interval$1) interval$1 = clearInterval(interval$1);
  3612. } else {
  3613. if (!interval$1) clockLast = clock.now(), interval$1 = setInterval(poke, pokeDelay);
  3614. frame = 1, setFrame(wake);
  3615. }
  3616. }
  3617. function timeout(callback, delay, time) {
  3618. var t = new Timer;
  3619. delay = delay == null ? 0 : +delay;
  3620. t.restart(elapsed => {
  3621. t.stop();
  3622. callback(elapsed + delay);
  3623. }, delay, time);
  3624. return t;
  3625. }
  3626. function interval(callback, delay, time) {
  3627. var t = new Timer, total = delay;
  3628. if (delay == null) return t.restart(callback, delay, time), t;
  3629. t._restart = t.restart;
  3630. t.restart = function(callback, delay, time) {
  3631. delay = +delay, time = time == null ? now() : +time;
  3632. t._restart(function tick(elapsed) {
  3633. elapsed += total;
  3634. t._restart(tick, total += delay, time);
  3635. callback(elapsed);
  3636. }, delay, time);
  3637. };
  3638. t.restart(callback, delay, time);
  3639. return t;
  3640. }
  3641. var emptyOn = dispatch("start", "end", "cancel", "interrupt");
  3642. var emptyTween = [];
  3643. var CREATED = 0;
  3644. var SCHEDULED = 1;
  3645. var STARTING = 2;
  3646. var STARTED = 3;
  3647. var RUNNING = 4;
  3648. var ENDING = 5;
  3649. var ENDED = 6;
  3650. function schedule(node, name, id, index, group, timing) {
  3651. var schedules = node.__transition;
  3652. if (!schedules) node.__transition = {};
  3653. else if (id in schedules) return;
  3654. create(node, id, {
  3655. name: name,
  3656. index: index, // For context during callback.
  3657. group: group, // For context during callback.
  3658. on: emptyOn,
  3659. tween: emptyTween,
  3660. time: timing.time,
  3661. delay: timing.delay,
  3662. duration: timing.duration,
  3663. ease: timing.ease,
  3664. timer: null,
  3665. state: CREATED
  3666. });
  3667. }
  3668. function init(node, id) {
  3669. var schedule = get(node, id);
  3670. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  3671. return schedule;
  3672. }
  3673. function set(node, id) {
  3674. var schedule = get(node, id);
  3675. if (schedule.state > STARTED) throw new Error("too late; already running");
  3676. return schedule;
  3677. }
  3678. function get(node, id) {
  3679. var schedule = node.__transition;
  3680. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  3681. return schedule;
  3682. }
  3683. function create(node, id, self) {
  3684. var schedules = node.__transition,
  3685. tween;
  3686. // Initialize the self timer when the transition is created.
  3687. // Note the actual delay is not known until the first callback!
  3688. schedules[id] = self;
  3689. self.timer = timer(schedule, 0, self.time);
  3690. function schedule(elapsed) {
  3691. self.state = SCHEDULED;
  3692. self.timer.restart(start, self.delay, self.time);
  3693. // If the elapsed delay is less than our first sleep, start immediately.
  3694. if (self.delay <= elapsed) start(elapsed - self.delay);
  3695. }
  3696. function start(elapsed) {
  3697. var i, j, n, o;
  3698. // If the state is not SCHEDULED, then we previously errored on start.
  3699. if (self.state !== SCHEDULED) return stop();
  3700. for (i in schedules) {
  3701. o = schedules[i];
  3702. if (o.name !== self.name) continue;
  3703. // While this element already has a starting transition during this frame,
  3704. // defer starting an interrupting transition until that transition has a
  3705. // chance to tick (and possibly end); see d3/d3-transition#54!
  3706. if (o.state === STARTED) return timeout(start);
  3707. // Interrupt the active transition, if any.
  3708. if (o.state === RUNNING) {
  3709. o.state = ENDED;
  3710. o.timer.stop();
  3711. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  3712. delete schedules[i];
  3713. }
  3714. // Cancel any pre-empted transitions.
  3715. else if (+i < id) {
  3716. o.state = ENDED;
  3717. o.timer.stop();
  3718. o.on.call("cancel", node, node.__data__, o.index, o.group);
  3719. delete schedules[i];
  3720. }
  3721. }
  3722. // Defer the first tick to end of the current frame; see d3/d3#1576.
  3723. // Note the transition may be canceled after start and before the first tick!
  3724. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  3725. // Assuming this is successful, subsequent callbacks go straight to tick.
  3726. timeout(function() {
  3727. if (self.state === STARTED) {
  3728. self.state = RUNNING;
  3729. self.timer.restart(tick, self.delay, self.time);
  3730. tick(elapsed);
  3731. }
  3732. });
  3733. // Dispatch the start event.
  3734. // Note this must be done before the tween are initialized.
  3735. self.state = STARTING;
  3736. self.on.call("start", node, node.__data__, self.index, self.group);
  3737. if (self.state !== STARTING) return; // interrupted
  3738. self.state = STARTED;
  3739. // Initialize the tween, deleting null tween.
  3740. tween = new Array(n = self.tween.length);
  3741. for (i = 0, j = -1; i < n; ++i) {
  3742. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  3743. tween[++j] = o;
  3744. }
  3745. }
  3746. tween.length = j + 1;
  3747. }
  3748. function tick(elapsed) {
  3749. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  3750. i = -1,
  3751. n = tween.length;
  3752. while (++i < n) {
  3753. tween[i].call(node, t);
  3754. }
  3755. // Dispatch the end event.
  3756. if (self.state === ENDING) {
  3757. self.on.call("end", node, node.__data__, self.index, self.group);
  3758. stop();
  3759. }
  3760. }
  3761. function stop() {
  3762. self.state = ENDED;
  3763. self.timer.stop();
  3764. delete schedules[id];
  3765. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  3766. delete node.__transition;
  3767. }
  3768. }
  3769. function interrupt(node, name) {
  3770. var schedules = node.__transition,
  3771. schedule,
  3772. active,
  3773. empty = true,
  3774. i;
  3775. if (!schedules) return;
  3776. name = name == null ? null : name + "";
  3777. for (i in schedules) {
  3778. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  3779. active = schedule.state > STARTING && schedule.state < ENDING;
  3780. schedule.state = ENDED;
  3781. schedule.timer.stop();
  3782. schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
  3783. delete schedules[i];
  3784. }
  3785. if (empty) delete node.__transition;
  3786. }
  3787. function selection_interrupt(name) {
  3788. return this.each(function() {
  3789. interrupt(this, name);
  3790. });
  3791. }
  3792. function tweenRemove(id, name) {
  3793. var tween0, tween1;
  3794. return function() {
  3795. var schedule = set(this, id),
  3796. tween = schedule.tween;
  3797. // If this node shared tween with the previous node,
  3798. // just assign the updated shared tween and we’re done!
  3799. // Otherwise, copy-on-write.
  3800. if (tween !== tween0) {
  3801. tween1 = tween0 = tween;
  3802. for (var i = 0, n = tween1.length; i < n; ++i) {
  3803. if (tween1[i].name === name) {
  3804. tween1 = tween1.slice();
  3805. tween1.splice(i, 1);
  3806. break;
  3807. }
  3808. }
  3809. }
  3810. schedule.tween = tween1;
  3811. };
  3812. }
  3813. function tweenFunction(id, name, value) {
  3814. var tween0, tween1;
  3815. if (typeof value !== "function") throw new Error;
  3816. return function() {
  3817. var schedule = set(this, id),
  3818. tween = schedule.tween;
  3819. // If this node shared tween with the previous node,
  3820. // just assign the updated shared tween and we’re done!
  3821. // Otherwise, copy-on-write.
  3822. if (tween !== tween0) {
  3823. tween1 = (tween0 = tween).slice();
  3824. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  3825. if (tween1[i].name === name) {
  3826. tween1[i] = t;
  3827. break;
  3828. }
  3829. }
  3830. if (i === n) tween1.push(t);
  3831. }
  3832. schedule.tween = tween1;
  3833. };
  3834. }
  3835. function transition_tween(name, value) {
  3836. var id = this._id;
  3837. name += "";
  3838. if (arguments.length < 2) {
  3839. var tween = get(this.node(), id).tween;
  3840. for (var i = 0, n = tween.length, t; i < n; ++i) {
  3841. if ((t = tween[i]).name === name) {
  3842. return t.value;
  3843. }
  3844. }
  3845. return null;
  3846. }
  3847. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  3848. }
  3849. function tweenValue(transition, name, value) {
  3850. var id = transition._id;
  3851. transition.each(function() {
  3852. var schedule = set(this, id);
  3853. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  3854. });
  3855. return function(node) {
  3856. return get(node, id).value[name];
  3857. };
  3858. }
  3859. function interpolate$1(a, b) {
  3860. var c;
  3861. return (typeof b === "number" ? interpolateNumber
  3862. : b instanceof color ? interpolateRgb
  3863. : (c = color(b)) ? (b = c, interpolateRgb)
  3864. : interpolateString)(a, b);
  3865. }
  3866. function attrRemove(name) {
  3867. return function() {
  3868. this.removeAttribute(name);
  3869. };
  3870. }
  3871. function attrRemoveNS(fullname) {
  3872. return function() {
  3873. this.removeAttributeNS(fullname.space, fullname.local);
  3874. };
  3875. }
  3876. function attrConstant(name, interpolate, value1) {
  3877. var string00,
  3878. string1 = value1 + "",
  3879. interpolate0;
  3880. return function() {
  3881. var string0 = this.getAttribute(name);
  3882. return string0 === string1 ? null
  3883. : string0 === string00 ? interpolate0
  3884. : interpolate0 = interpolate(string00 = string0, value1);
  3885. };
  3886. }
  3887. function attrConstantNS(fullname, interpolate, value1) {
  3888. var string00,
  3889. string1 = value1 + "",
  3890. interpolate0;
  3891. return function() {
  3892. var string0 = this.getAttributeNS(fullname.space, fullname.local);
  3893. return string0 === string1 ? null
  3894. : string0 === string00 ? interpolate0
  3895. : interpolate0 = interpolate(string00 = string0, value1);
  3896. };
  3897. }
  3898. function attrFunction(name, interpolate, value) {
  3899. var string00,
  3900. string10,
  3901. interpolate0;
  3902. return function() {
  3903. var string0, value1 = value(this), string1;
  3904. if (value1 == null) return void this.removeAttribute(name);
  3905. string0 = this.getAttribute(name);
  3906. string1 = value1 + "";
  3907. return string0 === string1 ? null
  3908. : string0 === string00 && string1 === string10 ? interpolate0
  3909. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3910. };
  3911. }
  3912. function attrFunctionNS(fullname, interpolate, value) {
  3913. var string00,
  3914. string10,
  3915. interpolate0;
  3916. return function() {
  3917. var string0, value1 = value(this), string1;
  3918. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3919. string0 = this.getAttributeNS(fullname.space, fullname.local);
  3920. string1 = value1 + "";
  3921. return string0 === string1 ? null
  3922. : string0 === string00 && string1 === string10 ? interpolate0
  3923. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3924. };
  3925. }
  3926. function transition_attr(name, value) {
  3927. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
  3928. return this.attrTween(name, typeof value === "function"
  3929. ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value))
  3930. : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname)
  3931. : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value));
  3932. }
  3933. function attrInterpolate(name, i) {
  3934. return function(t) {
  3935. this.setAttribute(name, i.call(this, t));
  3936. };
  3937. }
  3938. function attrInterpolateNS(fullname, i) {
  3939. return function(t) {
  3940. this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
  3941. };
  3942. }
  3943. function attrTweenNS(fullname, value) {
  3944. var t0, i0;
  3945. function tween() {
  3946. var i = value.apply(this, arguments);
  3947. if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
  3948. return t0;
  3949. }
  3950. tween._value = value;
  3951. return tween;
  3952. }
  3953. function attrTween(name, value) {
  3954. var t0, i0;
  3955. function tween() {
  3956. var i = value.apply(this, arguments);
  3957. if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
  3958. return t0;
  3959. }
  3960. tween._value = value;
  3961. return tween;
  3962. }
  3963. function transition_attrTween(name, value) {
  3964. var key = "attr." + name;
  3965. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3966. if (value == null) return this.tween(key, null);
  3967. if (typeof value !== "function") throw new Error;
  3968. var fullname = namespace(name);
  3969. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3970. }
  3971. function delayFunction(id, value) {
  3972. return function() {
  3973. init(this, id).delay = +value.apply(this, arguments);
  3974. };
  3975. }
  3976. function delayConstant(id, value) {
  3977. return value = +value, function() {
  3978. init(this, id).delay = value;
  3979. };
  3980. }
  3981. function transition_delay(value) {
  3982. var id = this._id;
  3983. return arguments.length
  3984. ? this.each((typeof value === "function"
  3985. ? delayFunction
  3986. : delayConstant)(id, value))
  3987. : get(this.node(), id).delay;
  3988. }
  3989. function durationFunction(id, value) {
  3990. return function() {
  3991. set(this, id).duration = +value.apply(this, arguments);
  3992. };
  3993. }
  3994. function durationConstant(id, value) {
  3995. return value = +value, function() {
  3996. set(this, id).duration = value;
  3997. };
  3998. }
  3999. function transition_duration(value) {
  4000. var id = this._id;
  4001. return arguments.length
  4002. ? this.each((typeof value === "function"
  4003. ? durationFunction
  4004. : durationConstant)(id, value))
  4005. : get(this.node(), id).duration;
  4006. }
  4007. function easeConstant(id, value) {
  4008. if (typeof value !== "function") throw new Error;
  4009. return function() {
  4010. set(this, id).ease = value;
  4011. };
  4012. }
  4013. function transition_ease(value) {
  4014. var id = this._id;
  4015. return arguments.length
  4016. ? this.each(easeConstant(id, value))
  4017. : get(this.node(), id).ease;
  4018. }
  4019. function easeVarying(id, value) {
  4020. return function() {
  4021. var v = value.apply(this, arguments);
  4022. if (typeof v !== "function") throw new Error;
  4023. set(this, id).ease = v;
  4024. };
  4025. }
  4026. function transition_easeVarying(value) {
  4027. if (typeof value !== "function") throw new Error;
  4028. return this.each(easeVarying(this._id, value));
  4029. }
  4030. function transition_filter(match) {
  4031. if (typeof match !== "function") match = matcher(match);
  4032. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  4033. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  4034. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  4035. subgroup.push(node);
  4036. }
  4037. }
  4038. }
  4039. return new Transition(subgroups, this._parents, this._name, this._id);
  4040. }
  4041. function transition_merge(transition) {
  4042. if (transition._id !== this._id) throw new Error;
  4043. for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  4044. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  4045. if (node = group0[i] || group1[i]) {
  4046. merge[i] = node;
  4047. }
  4048. }
  4049. }
  4050. for (; j < m0; ++j) {
  4051. merges[j] = groups0[j];
  4052. }
  4053. return new Transition(merges, this._parents, this._name, this._id);
  4054. }
  4055. function start(name) {
  4056. return (name + "").trim().split(/^|\s+/).every(function(t) {
  4057. var i = t.indexOf(".");
  4058. if (i >= 0) t = t.slice(0, i);
  4059. return !t || t === "start";
  4060. });
  4061. }
  4062. function onFunction(id, name, listener) {
  4063. var on0, on1, sit = start(name) ? init : set;
  4064. return function() {
  4065. var schedule = sit(this, id),
  4066. on = schedule.on;
  4067. // If this node shared a dispatch with the previous node,
  4068. // just assign the updated shared dispatch and we’re done!
  4069. // Otherwise, copy-on-write.
  4070. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  4071. schedule.on = on1;
  4072. };
  4073. }
  4074. function transition_on(name, listener) {
  4075. var id = this._id;
  4076. return arguments.length < 2
  4077. ? get(this.node(), id).on.on(name)
  4078. : this.each(onFunction(id, name, listener));
  4079. }
  4080. function removeFunction(id) {
  4081. return function() {
  4082. var parent = this.parentNode;
  4083. for (var i in this.__transition) if (+i !== id) return;
  4084. if (parent) parent.removeChild(this);
  4085. };
  4086. }
  4087. function transition_remove() {
  4088. return this.on("end.remove", removeFunction(this._id));
  4089. }
  4090. function transition_select(select) {
  4091. var name = this._name,
  4092. id = this._id;
  4093. if (typeof select !== "function") select = selector(select);
  4094. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  4095. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  4096. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  4097. if ("__data__" in node) subnode.__data__ = node.__data__;
  4098. subgroup[i] = subnode;
  4099. schedule(subgroup[i], name, id, i, subgroup, get(node, id));
  4100. }
  4101. }
  4102. }
  4103. return new Transition(subgroups, this._parents, name, id);
  4104. }
  4105. function transition_selectAll(select) {
  4106. var name = this._name,
  4107. id = this._id;
  4108. if (typeof select !== "function") select = selectorAll(select);
  4109. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  4110. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4111. if (node = group[i]) {
  4112. for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) {
  4113. if (child = children[k]) {
  4114. schedule(child, name, id, k, children, inherit);
  4115. }
  4116. }
  4117. subgroups.push(children);
  4118. parents.push(node);
  4119. }
  4120. }
  4121. }
  4122. return new Transition(subgroups, parents, name, id);
  4123. }
  4124. var Selection = selection.prototype.constructor;
  4125. function transition_selection() {
  4126. return new Selection(this._groups, this._parents);
  4127. }
  4128. function styleNull(name, interpolate) {
  4129. var string00,
  4130. string10,
  4131. interpolate0;
  4132. return function() {
  4133. var string0 = styleValue(this, name),
  4134. string1 = (this.style.removeProperty(name), styleValue(this, name));
  4135. return string0 === string1 ? null
  4136. : string0 === string00 && string1 === string10 ? interpolate0
  4137. : interpolate0 = interpolate(string00 = string0, string10 = string1);
  4138. };
  4139. }
  4140. function styleRemove(name) {
  4141. return function() {
  4142. this.style.removeProperty(name);
  4143. };
  4144. }
  4145. function styleConstant(name, interpolate, value1) {
  4146. var string00,
  4147. string1 = value1 + "",
  4148. interpolate0;
  4149. return function() {
  4150. var string0 = styleValue(this, name);
  4151. return string0 === string1 ? null
  4152. : string0 === string00 ? interpolate0
  4153. : interpolate0 = interpolate(string00 = string0, value1);
  4154. };
  4155. }
  4156. function styleFunction(name, interpolate, value) {
  4157. var string00,
  4158. string10,
  4159. interpolate0;
  4160. return function() {
  4161. var string0 = styleValue(this, name),
  4162. value1 = value(this),
  4163. string1 = value1 + "";
  4164. if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
  4165. return string0 === string1 ? null
  4166. : string0 === string00 && string1 === string10 ? interpolate0
  4167. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  4168. };
  4169. }
  4170. function styleMaybeRemove(id, name) {
  4171. var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
  4172. return function() {
  4173. var schedule = set(this, id),
  4174. on = schedule.on,
  4175. listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;
  4176. // If this node shared a dispatch with the previous node,
  4177. // just assign the updated shared dispatch and we’re done!
  4178. // Otherwise, copy-on-write.
  4179. if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
  4180. schedule.on = on1;
  4181. };
  4182. }
  4183. function transition_style(name, value, priority) {
  4184. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
  4185. return value == null ? this
  4186. .styleTween(name, styleNull(name, i))
  4187. .on("end.style." + name, styleRemove(name))
  4188. : typeof value === "function" ? this
  4189. .styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value)))
  4190. .each(styleMaybeRemove(this._id, name))
  4191. : this
  4192. .styleTween(name, styleConstant(name, i, value), priority)
  4193. .on("end.style." + name, null);
  4194. }
  4195. function styleInterpolate(name, i, priority) {
  4196. return function(t) {
  4197. this.style.setProperty(name, i.call(this, t), priority);
  4198. };
  4199. }
  4200. function styleTween(name, value, priority) {
  4201. var t, i0;
  4202. function tween() {
  4203. var i = value.apply(this, arguments);
  4204. if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
  4205. return t;
  4206. }
  4207. tween._value = value;
  4208. return tween;
  4209. }
  4210. function transition_styleTween(name, value, priority) {
  4211. var key = "style." + (name += "");
  4212. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  4213. if (value == null) return this.tween(key, null);
  4214. if (typeof value !== "function") throw new Error;
  4215. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  4216. }
  4217. function textConstant(value) {
  4218. return function() {
  4219. this.textContent = value;
  4220. };
  4221. }
  4222. function textFunction(value) {
  4223. return function() {
  4224. var value1 = value(this);
  4225. this.textContent = value1 == null ? "" : value1;
  4226. };
  4227. }
  4228. function transition_text(value) {
  4229. return this.tween("text", typeof value === "function"
  4230. ? textFunction(tweenValue(this, "text", value))
  4231. : textConstant(value == null ? "" : value + ""));
  4232. }
  4233. function textInterpolate(i) {
  4234. return function(t) {
  4235. this.textContent = i.call(this, t);
  4236. };
  4237. }
  4238. function textTween(value) {
  4239. var t0, i0;
  4240. function tween() {
  4241. var i = value.apply(this, arguments);
  4242. if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
  4243. return t0;
  4244. }
  4245. tween._value = value;
  4246. return tween;
  4247. }
  4248. function transition_textTween(value) {
  4249. var key = "text";
  4250. if (arguments.length < 1) return (key = this.tween(key)) && key._value;
  4251. if (value == null) return this.tween(key, null);
  4252. if (typeof value !== "function") throw new Error;
  4253. return this.tween(key, textTween(value));
  4254. }
  4255. function transition_transition() {
  4256. var name = this._name,
  4257. id0 = this._id,
  4258. id1 = newId();
  4259. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  4260. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4261. if (node = group[i]) {
  4262. var inherit = get(node, id0);
  4263. schedule(node, name, id1, i, group, {
  4264. time: inherit.time + inherit.delay + inherit.duration,
  4265. delay: 0,
  4266. duration: inherit.duration,
  4267. ease: inherit.ease
  4268. });
  4269. }
  4270. }
  4271. }
  4272. return new Transition(groups, this._parents, name, id1);
  4273. }
  4274. function transition_end() {
  4275. var on0, on1, that = this, id = that._id, size = that.size();
  4276. return new Promise(function(resolve, reject) {
  4277. var cancel = {value: reject},
  4278. end = {value: function() { if (--size === 0) resolve(); }};
  4279. that.each(function() {
  4280. var schedule = set(this, id),
  4281. on = schedule.on;
  4282. // If this node shared a dispatch with the previous node,
  4283. // just assign the updated shared dispatch and we’re done!
  4284. // Otherwise, copy-on-write.
  4285. if (on !== on0) {
  4286. on1 = (on0 = on).copy();
  4287. on1._.cancel.push(cancel);
  4288. on1._.interrupt.push(cancel);
  4289. on1._.end.push(end);
  4290. }
  4291. schedule.on = on1;
  4292. });
  4293. // The selection was empty, resolve end immediately
  4294. if (size === 0) resolve();
  4295. });
  4296. }
  4297. var id = 0;
  4298. function Transition(groups, parents, name, id) {
  4299. this._groups = groups;
  4300. this._parents = parents;
  4301. this._name = name;
  4302. this._id = id;
  4303. }
  4304. function transition(name) {
  4305. return selection().transition(name);
  4306. }
  4307. function newId() {
  4308. return ++id;
  4309. }
  4310. var selection_prototype = selection.prototype;
  4311. Transition.prototype = transition.prototype = {
  4312. constructor: Transition,
  4313. select: transition_select,
  4314. selectAll: transition_selectAll,
  4315. selectChild: selection_prototype.selectChild,
  4316. selectChildren: selection_prototype.selectChildren,
  4317. filter: transition_filter,
  4318. merge: transition_merge,
  4319. selection: transition_selection,
  4320. transition: transition_transition,
  4321. call: selection_prototype.call,
  4322. nodes: selection_prototype.nodes,
  4323. node: selection_prototype.node,
  4324. size: selection_prototype.size,
  4325. empty: selection_prototype.empty,
  4326. each: selection_prototype.each,
  4327. on: transition_on,
  4328. attr: transition_attr,
  4329. attrTween: transition_attrTween,
  4330. style: transition_style,
  4331. styleTween: transition_styleTween,
  4332. text: transition_text,
  4333. textTween: transition_textTween,
  4334. remove: transition_remove,
  4335. tween: transition_tween,
  4336. delay: transition_delay,
  4337. duration: transition_duration,
  4338. ease: transition_ease,
  4339. easeVarying: transition_easeVarying,
  4340. end: transition_end,
  4341. [Symbol.iterator]: selection_prototype[Symbol.iterator]
  4342. };
  4343. const linear$1 = t => +t;
  4344. function quadIn(t) {
  4345. return t * t;
  4346. }
  4347. function quadOut(t) {
  4348. return t * (2 - t);
  4349. }
  4350. function quadInOut(t) {
  4351. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  4352. }
  4353. function cubicIn(t) {
  4354. return t * t * t;
  4355. }
  4356. function cubicOut(t) {
  4357. return --t * t * t + 1;
  4358. }
  4359. function cubicInOut(t) {
  4360. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  4361. }
  4362. var exponent$1 = 3;
  4363. var polyIn = (function custom(e) {
  4364. e = +e;
  4365. function polyIn(t) {
  4366. return Math.pow(t, e);
  4367. }
  4368. polyIn.exponent = custom;
  4369. return polyIn;
  4370. })(exponent$1);
  4371. var polyOut = (function custom(e) {
  4372. e = +e;
  4373. function polyOut(t) {
  4374. return 1 - Math.pow(1 - t, e);
  4375. }
  4376. polyOut.exponent = custom;
  4377. return polyOut;
  4378. })(exponent$1);
  4379. var polyInOut = (function custom(e) {
  4380. e = +e;
  4381. function polyInOut(t) {
  4382. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  4383. }
  4384. polyInOut.exponent = custom;
  4385. return polyInOut;
  4386. })(exponent$1);
  4387. var pi$4 = Math.PI,
  4388. halfPi$3 = pi$4 / 2;
  4389. function sinIn(t) {
  4390. return (+t === 1) ? 1 : 1 - Math.cos(t * halfPi$3);
  4391. }
  4392. function sinOut(t) {
  4393. return Math.sin(t * halfPi$3);
  4394. }
  4395. function sinInOut(t) {
  4396. return (1 - Math.cos(pi$4 * t)) / 2;
  4397. }
  4398. // tpmt is two power minus ten times t scaled to [0,1]
  4399. function tpmt(x) {
  4400. return (Math.pow(2, -10 * x) - 0.0009765625) * 1.0009775171065494;
  4401. }
  4402. function expIn(t) {
  4403. return tpmt(1 - +t);
  4404. }
  4405. function expOut(t) {
  4406. return 1 - tpmt(t);
  4407. }
  4408. function expInOut(t) {
  4409. return ((t *= 2) <= 1 ? tpmt(1 - t) : 2 - tpmt(t - 1)) / 2;
  4410. }
  4411. function circleIn(t) {
  4412. return 1 - Math.sqrt(1 - t * t);
  4413. }
  4414. function circleOut(t) {
  4415. return Math.sqrt(1 - --t * t);
  4416. }
  4417. function circleInOut(t) {
  4418. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  4419. }
  4420. var b1 = 4 / 11,
  4421. b2 = 6 / 11,
  4422. b3 = 8 / 11,
  4423. b4 = 3 / 4,
  4424. b5 = 9 / 11,
  4425. b6 = 10 / 11,
  4426. b7 = 15 / 16,
  4427. b8 = 21 / 22,
  4428. b9 = 63 / 64,
  4429. b0 = 1 / b1 / b1;
  4430. function bounceIn(t) {
  4431. return 1 - bounceOut(1 - t);
  4432. }
  4433. function bounceOut(t) {
  4434. return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
  4435. }
  4436. function bounceInOut(t) {
  4437. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  4438. }
  4439. var overshoot = 1.70158;
  4440. var backIn = (function custom(s) {
  4441. s = +s;
  4442. function backIn(t) {
  4443. return (t = +t) * t * (s * (t - 1) + t);
  4444. }
  4445. backIn.overshoot = custom;
  4446. return backIn;
  4447. })(overshoot);
  4448. var backOut = (function custom(s) {
  4449. s = +s;
  4450. function backOut(t) {
  4451. return --t * t * ((t + 1) * s + t) + 1;
  4452. }
  4453. backOut.overshoot = custom;
  4454. return backOut;
  4455. })(overshoot);
  4456. var backInOut = (function custom(s) {
  4457. s = +s;
  4458. function backInOut(t) {
  4459. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  4460. }
  4461. backInOut.overshoot = custom;
  4462. return backInOut;
  4463. })(overshoot);
  4464. var tau$5 = 2 * Math.PI,
  4465. amplitude = 1,
  4466. period = 0.3;
  4467. var elasticIn = (function custom(a, p) {
  4468. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
  4469. function elasticIn(t) {
  4470. return a * tpmt(-(--t)) * Math.sin((s - t) / p);
  4471. }
  4472. elasticIn.amplitude = function(a) { return custom(a, p * tau$5); };
  4473. elasticIn.period = function(p) { return custom(a, p); };
  4474. return elasticIn;
  4475. })(amplitude, period);
  4476. var elasticOut = (function custom(a, p) {
  4477. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
  4478. function elasticOut(t) {
  4479. return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p);
  4480. }
  4481. elasticOut.amplitude = function(a) { return custom(a, p * tau$5); };
  4482. elasticOut.period = function(p) { return custom(a, p); };
  4483. return elasticOut;
  4484. })(amplitude, period);
  4485. var elasticInOut = (function custom(a, p) {
  4486. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
  4487. function elasticInOut(t) {
  4488. return ((t = t * 2 - 1) < 0
  4489. ? a * tpmt(-t) * Math.sin((s - t) / p)
  4490. : 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2;
  4491. }
  4492. elasticInOut.amplitude = function(a) { return custom(a, p * tau$5); };
  4493. elasticInOut.period = function(p) { return custom(a, p); };
  4494. return elasticInOut;
  4495. })(amplitude, period);
  4496. var defaultTiming = {
  4497. time: null, // Set on use.
  4498. delay: 0,
  4499. duration: 250,
  4500. ease: cubicInOut
  4501. };
  4502. function inherit(node, id) {
  4503. var timing;
  4504. while (!(timing = node.__transition) || !(timing = timing[id])) {
  4505. if (!(node = node.parentNode)) {
  4506. throw new Error(`transition ${id} not found`);
  4507. }
  4508. }
  4509. return timing;
  4510. }
  4511. function selection_transition(name) {
  4512. var id,
  4513. timing;
  4514. if (name instanceof Transition) {
  4515. id = name._id, name = name._name;
  4516. } else {
  4517. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  4518. }
  4519. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  4520. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  4521. if (node = group[i]) {
  4522. schedule(node, name, id, i, group, timing || inherit(node, id));
  4523. }
  4524. }
  4525. }
  4526. return new Transition(groups, this._parents, name, id);
  4527. }
  4528. selection.prototype.interrupt = selection_interrupt;
  4529. selection.prototype.transition = selection_transition;
  4530. var root = [null];
  4531. function active(node, name) {
  4532. var schedules = node.__transition,
  4533. schedule,
  4534. i;
  4535. if (schedules) {
  4536. name = name == null ? null : name + "";
  4537. for (i in schedules) {
  4538. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  4539. return new Transition([[node]], root, name, +i);
  4540. }
  4541. }
  4542. }
  4543. return null;
  4544. }
  4545. var constant$7 = x => () => x;
  4546. function BrushEvent(type, {
  4547. sourceEvent,
  4548. target,
  4549. selection,
  4550. mode,
  4551. dispatch
  4552. }) {
  4553. Object.defineProperties(this, {
  4554. type: {value: type, enumerable: true, configurable: true},
  4555. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  4556. target: {value: target, enumerable: true, configurable: true},
  4557. selection: {value: selection, enumerable: true, configurable: true},
  4558. mode: {value: mode, enumerable: true, configurable: true},
  4559. _: {value: dispatch}
  4560. });
  4561. }
  4562. function nopropagation$1(event) {
  4563. event.stopImmediatePropagation();
  4564. }
  4565. function noevent$1(event) {
  4566. event.preventDefault();
  4567. event.stopImmediatePropagation();
  4568. }
  4569. var MODE_DRAG = {name: "drag"},
  4570. MODE_SPACE = {name: "space"},
  4571. MODE_HANDLE = {name: "handle"},
  4572. MODE_CENTER = {name: "center"};
  4573. const {abs: abs$3, max: max$2, min: min$1} = Math;
  4574. function number1(e) {
  4575. return [+e[0], +e[1]];
  4576. }
  4577. function number2(e) {
  4578. return [number1(e[0]), number1(e[1])];
  4579. }
  4580. var X = {
  4581. name: "x",
  4582. handles: ["w", "e"].map(type),
  4583. input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
  4584. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  4585. };
  4586. var Y = {
  4587. name: "y",
  4588. handles: ["n", "s"].map(type),
  4589. input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
  4590. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  4591. };
  4592. var XY = {
  4593. name: "xy",
  4594. handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
  4595. input: function(xy) { return xy == null ? null : number2(xy); },
  4596. output: function(xy) { return xy; }
  4597. };
  4598. var cursors = {
  4599. overlay: "crosshair",
  4600. selection: "move",
  4601. n: "ns-resize",
  4602. e: "ew-resize",
  4603. s: "ns-resize",
  4604. w: "ew-resize",
  4605. nw: "nwse-resize",
  4606. ne: "nesw-resize",
  4607. se: "nwse-resize",
  4608. sw: "nesw-resize"
  4609. };
  4610. var flipX = {
  4611. e: "w",
  4612. w: "e",
  4613. nw: "ne",
  4614. ne: "nw",
  4615. se: "sw",
  4616. sw: "se"
  4617. };
  4618. var flipY = {
  4619. n: "s",
  4620. s: "n",
  4621. nw: "sw",
  4622. ne: "se",
  4623. se: "ne",
  4624. sw: "nw"
  4625. };
  4626. var signsX = {
  4627. overlay: +1,
  4628. selection: +1,
  4629. n: null,
  4630. e: +1,
  4631. s: null,
  4632. w: -1,
  4633. nw: -1,
  4634. ne: +1,
  4635. se: +1,
  4636. sw: -1
  4637. };
  4638. var signsY = {
  4639. overlay: +1,
  4640. selection: +1,
  4641. n: -1,
  4642. e: null,
  4643. s: +1,
  4644. w: null,
  4645. nw: -1,
  4646. ne: -1,
  4647. se: +1,
  4648. sw: +1
  4649. };
  4650. function type(t) {
  4651. return {type: t};
  4652. }
  4653. // Ignore right-click, since that should open the context menu.
  4654. function defaultFilter$1(event) {
  4655. return !event.ctrlKey && !event.button;
  4656. }
  4657. function defaultExtent$1() {
  4658. var svg = this.ownerSVGElement || this;
  4659. if (svg.hasAttribute("viewBox")) {
  4660. svg = svg.viewBox.baseVal;
  4661. return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
  4662. }
  4663. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  4664. }
  4665. function defaultTouchable$1() {
  4666. return navigator.maxTouchPoints || ("ontouchstart" in this);
  4667. }
  4668. // Like d3.local, but with the name “__brush” rather than auto-generated.
  4669. function local(node) {
  4670. while (!node.__brush) if (!(node = node.parentNode)) return;
  4671. return node.__brush;
  4672. }
  4673. function empty(extent) {
  4674. return extent[0][0] === extent[1][0]
  4675. || extent[0][1] === extent[1][1];
  4676. }
  4677. function brushSelection(node) {
  4678. var state = node.__brush;
  4679. return state ? state.dim.output(state.selection) : null;
  4680. }
  4681. function brushX() {
  4682. return brush$1(X);
  4683. }
  4684. function brushY() {
  4685. return brush$1(Y);
  4686. }
  4687. function brush() {
  4688. return brush$1(XY);
  4689. }
  4690. function brush$1(dim) {
  4691. var extent = defaultExtent$1,
  4692. filter = defaultFilter$1,
  4693. touchable = defaultTouchable$1,
  4694. keys = true,
  4695. listeners = dispatch("start", "brush", "end"),
  4696. handleSize = 6,
  4697. touchending;
  4698. function brush(group) {
  4699. var overlay = group
  4700. .property("__brush", initialize)
  4701. .selectAll(".overlay")
  4702. .data([type("overlay")]);
  4703. overlay.enter().append("rect")
  4704. .attr("class", "overlay")
  4705. .attr("pointer-events", "all")
  4706. .attr("cursor", cursors.overlay)
  4707. .merge(overlay)
  4708. .each(function() {
  4709. var extent = local(this).extent;
  4710. select(this)
  4711. .attr("x", extent[0][0])
  4712. .attr("y", extent[0][1])
  4713. .attr("width", extent[1][0] - extent[0][0])
  4714. .attr("height", extent[1][1] - extent[0][1]);
  4715. });
  4716. group.selectAll(".selection")
  4717. .data([type("selection")])
  4718. .enter().append("rect")
  4719. .attr("class", "selection")
  4720. .attr("cursor", cursors.selection)
  4721. .attr("fill", "#777")
  4722. .attr("fill-opacity", 0.3)
  4723. .attr("stroke", "#fff")
  4724. .attr("shape-rendering", "crispEdges");
  4725. var handle = group.selectAll(".handle")
  4726. .data(dim.handles, function(d) { return d.type; });
  4727. handle.exit().remove();
  4728. handle.enter().append("rect")
  4729. .attr("class", function(d) { return "handle handle--" + d.type; })
  4730. .attr("cursor", function(d) { return cursors[d.type]; });
  4731. group
  4732. .each(redraw)
  4733. .attr("fill", "none")
  4734. .attr("pointer-events", "all")
  4735. .on("mousedown.brush", started)
  4736. .filter(touchable)
  4737. .on("touchstart.brush", started)
  4738. .on("touchmove.brush", touchmoved)
  4739. .on("touchend.brush touchcancel.brush", touchended)
  4740. .style("touch-action", "none")
  4741. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  4742. }
  4743. brush.move = function(group, selection, event) {
  4744. if (group.tween) {
  4745. group
  4746. .on("start.brush", function(event) { emitter(this, arguments).beforestart().start(event); })
  4747. .on("interrupt.brush end.brush", function(event) { emitter(this, arguments).end(event); })
  4748. .tween("brush", function() {
  4749. var that = this,
  4750. state = that.__brush,
  4751. emit = emitter(that, arguments),
  4752. selection0 = state.selection,
  4753. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  4754. i = interpolate$2(selection0, selection1);
  4755. function tween(t) {
  4756. state.selection = t === 1 && selection1 === null ? null : i(t);
  4757. redraw.call(that);
  4758. emit.brush();
  4759. }
  4760. return selection0 !== null && selection1 !== null ? tween : tween(1);
  4761. });
  4762. } else {
  4763. group
  4764. .each(function() {
  4765. var that = this,
  4766. args = arguments,
  4767. state = that.__brush,
  4768. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  4769. emit = emitter(that, args).beforestart();
  4770. interrupt(that);
  4771. state.selection = selection1 === null ? null : selection1;
  4772. redraw.call(that);
  4773. emit.start(event).brush(event).end(event);
  4774. });
  4775. }
  4776. };
  4777. brush.clear = function(group, event) {
  4778. brush.move(group, null, event);
  4779. };
  4780. function redraw() {
  4781. var group = select(this),
  4782. selection = local(this).selection;
  4783. if (selection) {
  4784. group.selectAll(".selection")
  4785. .style("display", null)
  4786. .attr("x", selection[0][0])
  4787. .attr("y", selection[0][1])
  4788. .attr("width", selection[1][0] - selection[0][0])
  4789. .attr("height", selection[1][1] - selection[0][1]);
  4790. group.selectAll(".handle")
  4791. .style("display", null)
  4792. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  4793. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  4794. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  4795. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  4796. }
  4797. else {
  4798. group.selectAll(".selection,.handle")
  4799. .style("display", "none")
  4800. .attr("x", null)
  4801. .attr("y", null)
  4802. .attr("width", null)
  4803. .attr("height", null);
  4804. }
  4805. }
  4806. function emitter(that, args, clean) {
  4807. var emit = that.__brush.emitter;
  4808. return emit && (!clean || !emit.clean) ? emit : new Emitter(that, args, clean);
  4809. }
  4810. function Emitter(that, args, clean) {
  4811. this.that = that;
  4812. this.args = args;
  4813. this.state = that.__brush;
  4814. this.active = 0;
  4815. this.clean = clean;
  4816. }
  4817. Emitter.prototype = {
  4818. beforestart: function() {
  4819. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  4820. return this;
  4821. },
  4822. start: function(event, mode) {
  4823. if (this.starting) this.starting = false, this.emit("start", event, mode);
  4824. else this.emit("brush", event);
  4825. return this;
  4826. },
  4827. brush: function(event, mode) {
  4828. this.emit("brush", event, mode);
  4829. return this;
  4830. },
  4831. end: function(event, mode) {
  4832. if (--this.active === 0) delete this.state.emitter, this.emit("end", event, mode);
  4833. return this;
  4834. },
  4835. emit: function(type, event, mode) {
  4836. var d = select(this.that).datum();
  4837. listeners.call(
  4838. type,
  4839. this.that,
  4840. new BrushEvent(type, {
  4841. sourceEvent: event,
  4842. target: brush,
  4843. selection: dim.output(this.state.selection),
  4844. mode,
  4845. dispatch: listeners
  4846. }),
  4847. d
  4848. );
  4849. }
  4850. };
  4851. function started(event) {
  4852. if (touchending && !event.touches) return;
  4853. if (!filter.apply(this, arguments)) return;
  4854. var that = this,
  4855. type = event.target.__data__.type,
  4856. mode = (keys && event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && event.altKey ? MODE_CENTER : MODE_HANDLE),
  4857. signX = dim === Y ? null : signsX[type],
  4858. signY = dim === X ? null : signsY[type],
  4859. state = local(that),
  4860. extent = state.extent,
  4861. selection = state.selection,
  4862. W = extent[0][0], w0, w1,
  4863. N = extent[0][1], n0, n1,
  4864. E = extent[1][0], e0, e1,
  4865. S = extent[1][1], s0, s1,
  4866. dx = 0,
  4867. dy = 0,
  4868. moving,
  4869. shifting = signX && signY && keys && event.shiftKey,
  4870. lockX,
  4871. lockY,
  4872. points = Array.from(event.touches || [event], t => {
  4873. const i = t.identifier;
  4874. t = pointer(t, that);
  4875. t.point0 = t.slice();
  4876. t.identifier = i;
  4877. return t;
  4878. });
  4879. interrupt(that);
  4880. var emit = emitter(that, arguments, true).beforestart();
  4881. if (type === "overlay") {
  4882. if (selection) moving = true;
  4883. const pts = [points[0], points[1] || points[0]];
  4884. state.selection = selection = [[
  4885. w0 = dim === Y ? W : min$1(pts[0][0], pts[1][0]),
  4886. n0 = dim === X ? N : min$1(pts[0][1], pts[1][1])
  4887. ], [
  4888. e0 = dim === Y ? E : max$2(pts[0][0], pts[1][0]),
  4889. s0 = dim === X ? S : max$2(pts[0][1], pts[1][1])
  4890. ]];
  4891. if (points.length > 1) move(event);
  4892. } else {
  4893. w0 = selection[0][0];
  4894. n0 = selection[0][1];
  4895. e0 = selection[1][0];
  4896. s0 = selection[1][1];
  4897. }
  4898. w1 = w0;
  4899. n1 = n0;
  4900. e1 = e0;
  4901. s1 = s0;
  4902. var group = select(that)
  4903. .attr("pointer-events", "none");
  4904. var overlay = group.selectAll(".overlay")
  4905. .attr("cursor", cursors[type]);
  4906. if (event.touches) {
  4907. emit.moved = moved;
  4908. emit.ended = ended;
  4909. } else {
  4910. var view = select(event.view)
  4911. .on("mousemove.brush", moved, true)
  4912. .on("mouseup.brush", ended, true);
  4913. if (keys) view
  4914. .on("keydown.brush", keydowned, true)
  4915. .on("keyup.brush", keyupped, true);
  4916. dragDisable(event.view);
  4917. }
  4918. redraw.call(that);
  4919. emit.start(event, mode.name);
  4920. function moved(event) {
  4921. for (const p of event.changedTouches || [event]) {
  4922. for (const d of points)
  4923. if (d.identifier === p.identifier) d.cur = pointer(p, that);
  4924. }
  4925. if (shifting && !lockX && !lockY && points.length === 1) {
  4926. const point = points[0];
  4927. if (abs$3(point.cur[0] - point[0]) > abs$3(point.cur[1] - point[1]))
  4928. lockY = true;
  4929. else
  4930. lockX = true;
  4931. }
  4932. for (const point of points)
  4933. if (point.cur) point[0] = point.cur[0], point[1] = point.cur[1];
  4934. moving = true;
  4935. noevent$1(event);
  4936. move(event);
  4937. }
  4938. function move(event) {
  4939. const point = points[0], point0 = point.point0;
  4940. var t;
  4941. dx = point[0] - point0[0];
  4942. dy = point[1] - point0[1];
  4943. switch (mode) {
  4944. case MODE_SPACE:
  4945. case MODE_DRAG: {
  4946. if (signX) dx = max$2(W - w0, min$1(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  4947. if (signY) dy = max$2(N - n0, min$1(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  4948. break;
  4949. }
  4950. case MODE_HANDLE: {
  4951. if (points[1]) {
  4952. if (signX) w1 = max$2(W, min$1(E, points[0][0])), e1 = max$2(W, min$1(E, points[1][0])), signX = 1;
  4953. if (signY) n1 = max$2(N, min$1(S, points[0][1])), s1 = max$2(N, min$1(S, points[1][1])), signY = 1;
  4954. } else {
  4955. if (signX < 0) dx = max$2(W - w0, min$1(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  4956. else if (signX > 0) dx = max$2(W - e0, min$1(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  4957. if (signY < 0) dy = max$2(N - n0, min$1(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  4958. else if (signY > 0) dy = max$2(N - s0, min$1(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  4959. }
  4960. break;
  4961. }
  4962. case MODE_CENTER: {
  4963. if (signX) w1 = max$2(W, min$1(E, w0 - dx * signX)), e1 = max$2(W, min$1(E, e0 + dx * signX));
  4964. if (signY) n1 = max$2(N, min$1(S, n0 - dy * signY)), s1 = max$2(N, min$1(S, s0 + dy * signY));
  4965. break;
  4966. }
  4967. }
  4968. if (e1 < w1) {
  4969. signX *= -1;
  4970. t = w0, w0 = e0, e0 = t;
  4971. t = w1, w1 = e1, e1 = t;
  4972. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  4973. }
  4974. if (s1 < n1) {
  4975. signY *= -1;
  4976. t = n0, n0 = s0, s0 = t;
  4977. t = n1, n1 = s1, s1 = t;
  4978. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  4979. }
  4980. if (state.selection) selection = state.selection; // May be set by brush.move!
  4981. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  4982. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  4983. if (selection[0][0] !== w1
  4984. || selection[0][1] !== n1
  4985. || selection[1][0] !== e1
  4986. || selection[1][1] !== s1) {
  4987. state.selection = [[w1, n1], [e1, s1]];
  4988. redraw.call(that);
  4989. emit.brush(event, mode.name);
  4990. }
  4991. }
  4992. function ended(event) {
  4993. nopropagation$1(event);
  4994. if (event.touches) {
  4995. if (event.touches.length) return;
  4996. if (touchending) clearTimeout(touchending);
  4997. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  4998. } else {
  4999. yesdrag(event.view, moving);
  5000. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  5001. }
  5002. group.attr("pointer-events", "all");
  5003. overlay.attr("cursor", cursors.overlay);
  5004. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  5005. if (empty(selection)) state.selection = null, redraw.call(that);
  5006. emit.end(event, mode.name);
  5007. }
  5008. function keydowned(event) {
  5009. switch (event.keyCode) {
  5010. case 16: { // SHIFT
  5011. shifting = signX && signY;
  5012. break;
  5013. }
  5014. case 18: { // ALT
  5015. if (mode === MODE_HANDLE) {
  5016. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  5017. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  5018. mode = MODE_CENTER;
  5019. move(event);
  5020. }
  5021. break;
  5022. }
  5023. case 32: { // SPACE; takes priority over ALT
  5024. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  5025. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  5026. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  5027. mode = MODE_SPACE;
  5028. overlay.attr("cursor", cursors.selection);
  5029. move(event);
  5030. }
  5031. break;
  5032. }
  5033. default: return;
  5034. }
  5035. noevent$1(event);
  5036. }
  5037. function keyupped(event) {
  5038. switch (event.keyCode) {
  5039. case 16: { // SHIFT
  5040. if (shifting) {
  5041. lockX = lockY = shifting = false;
  5042. move(event);
  5043. }
  5044. break;
  5045. }
  5046. case 18: { // ALT
  5047. if (mode === MODE_CENTER) {
  5048. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  5049. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  5050. mode = MODE_HANDLE;
  5051. move(event);
  5052. }
  5053. break;
  5054. }
  5055. case 32: { // SPACE
  5056. if (mode === MODE_SPACE) {
  5057. if (event.altKey) {
  5058. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  5059. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  5060. mode = MODE_CENTER;
  5061. } else {
  5062. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  5063. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  5064. mode = MODE_HANDLE;
  5065. }
  5066. overlay.attr("cursor", cursors[type]);
  5067. move(event);
  5068. }
  5069. break;
  5070. }
  5071. default: return;
  5072. }
  5073. noevent$1(event);
  5074. }
  5075. }
  5076. function touchmoved(event) {
  5077. emitter(this, arguments).moved(event);
  5078. }
  5079. function touchended(event) {
  5080. emitter(this, arguments).ended(event);
  5081. }
  5082. function initialize() {
  5083. var state = this.__brush || {selection: null};
  5084. state.extent = number2(extent.apply(this, arguments));
  5085. state.dim = dim;
  5086. return state;
  5087. }
  5088. brush.extent = function(_) {
  5089. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$7(number2(_)), brush) : extent;
  5090. };
  5091. brush.filter = function(_) {
  5092. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), brush) : filter;
  5093. };
  5094. brush.touchable = function(_) {
  5095. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$7(!!_), brush) : touchable;
  5096. };
  5097. brush.handleSize = function(_) {
  5098. return arguments.length ? (handleSize = +_, brush) : handleSize;
  5099. };
  5100. brush.keyModifiers = function(_) {
  5101. return arguments.length ? (keys = !!_, brush) : keys;
  5102. };
  5103. brush.on = function() {
  5104. var value = listeners.on.apply(listeners, arguments);
  5105. return value === listeners ? brush : value;
  5106. };
  5107. return brush;
  5108. }
  5109. var abs$2 = Math.abs;
  5110. var cos$2 = Math.cos;
  5111. var sin$2 = Math.sin;
  5112. var pi$3 = Math.PI;
  5113. var halfPi$2 = pi$3 / 2;
  5114. var tau$4 = pi$3 * 2;
  5115. var max$1 = Math.max;
  5116. var epsilon$5 = 1e-12;
  5117. function range$1(i, j) {
  5118. return Array.from({length: j - i}, (_, k) => i + k);
  5119. }
  5120. function compareValue(compare) {
  5121. return function(a, b) {
  5122. return compare(
  5123. a.source.value + a.target.value,
  5124. b.source.value + b.target.value
  5125. );
  5126. };
  5127. }
  5128. function chord() {
  5129. return chord$1(false, false);
  5130. }
  5131. function chordTranspose() {
  5132. return chord$1(false, true);
  5133. }
  5134. function chordDirected() {
  5135. return chord$1(true, false);
  5136. }
  5137. function chord$1(directed, transpose) {
  5138. var padAngle = 0,
  5139. sortGroups = null,
  5140. sortSubgroups = null,
  5141. sortChords = null;
  5142. function chord(matrix) {
  5143. var n = matrix.length,
  5144. groupSums = new Array(n),
  5145. groupIndex = range$1(0, n),
  5146. chords = new Array(n * n),
  5147. groups = new Array(n),
  5148. k = 0, dx;
  5149. matrix = Float64Array.from({length: n * n}, transpose
  5150. ? (_, i) => matrix[i % n][i / n | 0]
  5151. : (_, i) => matrix[i / n | 0][i % n]);
  5152. // Compute the scaling factor from value to angle in [0, 2pi].
  5153. for (let i = 0; i < n; ++i) {
  5154. let x = 0;
  5155. for (let j = 0; j < n; ++j) x += matrix[i * n + j] + directed * matrix[j * n + i];
  5156. k += groupSums[i] = x;
  5157. }
  5158. k = max$1(0, tau$4 - padAngle * n) / k;
  5159. dx = k ? padAngle : tau$4 / n;
  5160. // Compute the angles for each group and constituent chord.
  5161. {
  5162. let x = 0;
  5163. if (sortGroups) groupIndex.sort((a, b) => sortGroups(groupSums[a], groupSums[b]));
  5164. for (const i of groupIndex) {
  5165. const x0 = x;
  5166. if (directed) {
  5167. const subgroupIndex = range$1(~n + 1, n).filter(j => j < 0 ? matrix[~j * n + i] : matrix[i * n + j]);
  5168. if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(a < 0 ? -matrix[~a * n + i] : matrix[i * n + a], b < 0 ? -matrix[~b * n + i] : matrix[i * n + b]));
  5169. for (const j of subgroupIndex) {
  5170. if (j < 0) {
  5171. const chord = chords[~j * n + i] || (chords[~j * n + i] = {source: null, target: null});
  5172. chord.target = {index: i, startAngle: x, endAngle: x += matrix[~j * n + i] * k, value: matrix[~j * n + i]};
  5173. } else {
  5174. const chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
  5175. chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  5176. }
  5177. }
  5178. groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
  5179. } else {
  5180. const subgroupIndex = range$1(0, n).filter(j => matrix[i * n + j] || matrix[j * n + i]);
  5181. if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(matrix[i * n + a], matrix[i * n + b]));
  5182. for (const j of subgroupIndex) {
  5183. let chord;
  5184. if (i < j) {
  5185. chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
  5186. chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  5187. } else {
  5188. chord = chords[j * n + i] || (chords[j * n + i] = {source: null, target: null});
  5189. chord.target = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
  5190. if (i === j) chord.source = chord.target;
  5191. }
  5192. if (chord.source && chord.target && chord.source.value < chord.target.value) {
  5193. const source = chord.source;
  5194. chord.source = chord.target;
  5195. chord.target = source;
  5196. }
  5197. }
  5198. groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
  5199. }
  5200. x += dx;
  5201. }
  5202. }
  5203. // Remove empty chords.
  5204. chords = Object.values(chords);
  5205. chords.groups = groups;
  5206. return sortChords ? chords.sort(sortChords) : chords;
  5207. }
  5208. chord.padAngle = function(_) {
  5209. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  5210. };
  5211. chord.sortGroups = function(_) {
  5212. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  5213. };
  5214. chord.sortSubgroups = function(_) {
  5215. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  5216. };
  5217. chord.sortChords = function(_) {
  5218. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  5219. };
  5220. return chord;
  5221. }
  5222. const pi$2 = Math.PI,
  5223. tau$3 = 2 * pi$2,
  5224. epsilon$4 = 1e-6,
  5225. tauEpsilon = tau$3 - epsilon$4;
  5226. function append$1(strings) {
  5227. this._ += strings[0];
  5228. for (let i = 1, n = strings.length; i < n; ++i) {
  5229. this._ += arguments[i] + strings[i];
  5230. }
  5231. }
  5232. function appendRound$1(digits) {
  5233. let d = Math.floor(digits);
  5234. if (!(d >= 0)) throw new Error(`invalid digits: ${digits}`);
  5235. if (d > 15) return append$1;
  5236. const k = 10 ** d;
  5237. return function(strings) {
  5238. this._ += strings[0];
  5239. for (let i = 1, n = strings.length; i < n; ++i) {
  5240. this._ += Math.round(arguments[i] * k) / k + strings[i];
  5241. }
  5242. };
  5243. }
  5244. let Path$1 = class Path {
  5245. constructor(digits) {
  5246. this._x0 = this._y0 = // start of current subpath
  5247. this._x1 = this._y1 = null; // end of current subpath
  5248. this._ = "";
  5249. this._append = digits == null ? append$1 : appendRound$1(digits);
  5250. }
  5251. moveTo(x, y) {
  5252. this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
  5253. }
  5254. closePath() {
  5255. if (this._x1 !== null) {
  5256. this._x1 = this._x0, this._y1 = this._y0;
  5257. this._append`Z`;
  5258. }
  5259. }
  5260. lineTo(x, y) {
  5261. this._append`L${this._x1 = +x},${this._y1 = +y}`;
  5262. }
  5263. quadraticCurveTo(x1, y1, x, y) {
  5264. this._append`Q${+x1},${+y1},${this._x1 = +x},${this._y1 = +y}`;
  5265. }
  5266. bezierCurveTo(x1, y1, x2, y2, x, y) {
  5267. this._append`C${+x1},${+y1},${+x2},${+y2},${this._x1 = +x},${this._y1 = +y}`;
  5268. }
  5269. arcTo(x1, y1, x2, y2, r) {
  5270. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  5271. // Is the radius negative? Error.
  5272. if (r < 0) throw new Error(`negative radius: ${r}`);
  5273. let x0 = this._x1,
  5274. y0 = this._y1,
  5275. x21 = x2 - x1,
  5276. y21 = y2 - y1,
  5277. x01 = x0 - x1,
  5278. y01 = y0 - y1,
  5279. l01_2 = x01 * x01 + y01 * y01;
  5280. // Is this path empty? Move to (x1,y1).
  5281. if (this._x1 === null) {
  5282. this._append`M${this._x1 = x1},${this._y1 = y1}`;
  5283. }
  5284. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  5285. else if (!(l01_2 > epsilon$4));
  5286. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  5287. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  5288. // Or, is the radius zero? Line to (x1,y1).
  5289. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$4) || !r) {
  5290. this._append`L${this._x1 = x1},${this._y1 = y1}`;
  5291. }
  5292. // Otherwise, draw an arc!
  5293. else {
  5294. let x20 = x2 - x0,
  5295. y20 = y2 - y0,
  5296. l21_2 = x21 * x21 + y21 * y21,
  5297. l20_2 = x20 * x20 + y20 * y20,
  5298. l21 = Math.sqrt(l21_2),
  5299. l01 = Math.sqrt(l01_2),
  5300. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  5301. t01 = l / l01,
  5302. t21 = l / l21;
  5303. // If the start tangent is not coincident with (x0,y0), line to.
  5304. if (Math.abs(t01 - 1) > epsilon$4) {
  5305. this._append`L${x1 + t01 * x01},${y1 + t01 * y01}`;
  5306. }
  5307. this._append`A${r},${r},0,0,${+(y01 * x20 > x01 * y20)},${this._x1 = x1 + t21 * x21},${this._y1 = y1 + t21 * y21}`;
  5308. }
  5309. }
  5310. arc(x, y, r, a0, a1, ccw) {
  5311. x = +x, y = +y, r = +r, ccw = !!ccw;
  5312. // Is the radius negative? Error.
  5313. if (r < 0) throw new Error(`negative radius: ${r}`);
  5314. let dx = r * Math.cos(a0),
  5315. dy = r * Math.sin(a0),
  5316. x0 = x + dx,
  5317. y0 = y + dy,
  5318. cw = 1 ^ ccw,
  5319. da = ccw ? a0 - a1 : a1 - a0;
  5320. // Is this path empty? Move to (x0,y0).
  5321. if (this._x1 === null) {
  5322. this._append`M${x0},${y0}`;
  5323. }
  5324. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  5325. else if (Math.abs(this._x1 - x0) > epsilon$4 || Math.abs(this._y1 - y0) > epsilon$4) {
  5326. this._append`L${x0},${y0}`;
  5327. }
  5328. // Is this arc empty? We’re done.
  5329. if (!r) return;
  5330. // Does the angle go the wrong way? Flip the direction.
  5331. if (da < 0) da = da % tau$3 + tau$3;
  5332. // Is this a complete circle? Draw two arcs to complete the circle.
  5333. if (da > tauEpsilon) {
  5334. this._append`A${r},${r},0,1,${cw},${x - dx},${y - dy}A${r},${r},0,1,${cw},${this._x1 = x0},${this._y1 = y0}`;
  5335. }
  5336. // Is this arc non-empty? Draw an arc!
  5337. else if (da > epsilon$4) {
  5338. this._append`A${r},${r},0,${+(da >= pi$2)},${cw},${this._x1 = x + r * Math.cos(a1)},${this._y1 = y + r * Math.sin(a1)}`;
  5339. }
  5340. }
  5341. rect(x, y, w, h) {
  5342. this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${w = +w}v${+h}h${-w}Z`;
  5343. }
  5344. toString() {
  5345. return this._;
  5346. }
  5347. };
  5348. function path() {
  5349. return new Path$1;
  5350. }
  5351. // Allow instanceof d3.path
  5352. path.prototype = Path$1.prototype;
  5353. function pathRound(digits = 3) {
  5354. return new Path$1(+digits);
  5355. }
  5356. var slice$2 = Array.prototype.slice;
  5357. function constant$6(x) {
  5358. return function() {
  5359. return x;
  5360. };
  5361. }
  5362. function defaultSource$1(d) {
  5363. return d.source;
  5364. }
  5365. function defaultTarget(d) {
  5366. return d.target;
  5367. }
  5368. function defaultRadius$1(d) {
  5369. return d.radius;
  5370. }
  5371. function defaultStartAngle(d) {
  5372. return d.startAngle;
  5373. }
  5374. function defaultEndAngle(d) {
  5375. return d.endAngle;
  5376. }
  5377. function defaultPadAngle() {
  5378. return 0;
  5379. }
  5380. function defaultArrowheadRadius() {
  5381. return 10;
  5382. }
  5383. function ribbon(headRadius) {
  5384. var source = defaultSource$1,
  5385. target = defaultTarget,
  5386. sourceRadius = defaultRadius$1,
  5387. targetRadius = defaultRadius$1,
  5388. startAngle = defaultStartAngle,
  5389. endAngle = defaultEndAngle,
  5390. padAngle = defaultPadAngle,
  5391. context = null;
  5392. function ribbon() {
  5393. var buffer,
  5394. s = source.apply(this, arguments),
  5395. t = target.apply(this, arguments),
  5396. ap = padAngle.apply(this, arguments) / 2,
  5397. argv = slice$2.call(arguments),
  5398. sr = +sourceRadius.apply(this, (argv[0] = s, argv)),
  5399. sa0 = startAngle.apply(this, argv) - halfPi$2,
  5400. sa1 = endAngle.apply(this, argv) - halfPi$2,
  5401. tr = +targetRadius.apply(this, (argv[0] = t, argv)),
  5402. ta0 = startAngle.apply(this, argv) - halfPi$2,
  5403. ta1 = endAngle.apply(this, argv) - halfPi$2;
  5404. if (!context) context = buffer = path();
  5405. if (ap > epsilon$5) {
  5406. if (abs$2(sa1 - sa0) > ap * 2 + epsilon$5) sa1 > sa0 ? (sa0 += ap, sa1 -= ap) : (sa0 -= ap, sa1 += ap);
  5407. else sa0 = sa1 = (sa0 + sa1) / 2;
  5408. if (abs$2(ta1 - ta0) > ap * 2 + epsilon$5) ta1 > ta0 ? (ta0 += ap, ta1 -= ap) : (ta0 -= ap, ta1 += ap);
  5409. else ta0 = ta1 = (ta0 + ta1) / 2;
  5410. }
  5411. context.moveTo(sr * cos$2(sa0), sr * sin$2(sa0));
  5412. context.arc(0, 0, sr, sa0, sa1);
  5413. if (sa0 !== ta0 || sa1 !== ta1) {
  5414. if (headRadius) {
  5415. var hr = +headRadius.apply(this, arguments), tr2 = tr - hr, ta2 = (ta0 + ta1) / 2;
  5416. context.quadraticCurveTo(0, 0, tr2 * cos$2(ta0), tr2 * sin$2(ta0));
  5417. context.lineTo(tr * cos$2(ta2), tr * sin$2(ta2));
  5418. context.lineTo(tr2 * cos$2(ta1), tr2 * sin$2(ta1));
  5419. } else {
  5420. context.quadraticCurveTo(0, 0, tr * cos$2(ta0), tr * sin$2(ta0));
  5421. context.arc(0, 0, tr, ta0, ta1);
  5422. }
  5423. }
  5424. context.quadraticCurveTo(0, 0, sr * cos$2(sa0), sr * sin$2(sa0));
  5425. context.closePath();
  5426. if (buffer) return context = null, buffer + "" || null;
  5427. }
  5428. if (headRadius) ribbon.headRadius = function(_) {
  5429. return arguments.length ? (headRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : headRadius;
  5430. };
  5431. ribbon.radius = function(_) {
  5432. return arguments.length ? (sourceRadius = targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
  5433. };
  5434. ribbon.sourceRadius = function(_) {
  5435. return arguments.length ? (sourceRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
  5436. };
  5437. ribbon.targetRadius = function(_) {
  5438. return arguments.length ? (targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : targetRadius;
  5439. };
  5440. ribbon.startAngle = function(_) {
  5441. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : startAngle;
  5442. };
  5443. ribbon.endAngle = function(_) {
  5444. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : endAngle;
  5445. };
  5446. ribbon.padAngle = function(_) {
  5447. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : padAngle;
  5448. };
  5449. ribbon.source = function(_) {
  5450. return arguments.length ? (source = _, ribbon) : source;
  5451. };
  5452. ribbon.target = function(_) {
  5453. return arguments.length ? (target = _, ribbon) : target;
  5454. };
  5455. ribbon.context = function(_) {
  5456. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  5457. };
  5458. return ribbon;
  5459. }
  5460. function ribbon$1() {
  5461. return ribbon();
  5462. }
  5463. function ribbonArrow() {
  5464. return ribbon(defaultArrowheadRadius);
  5465. }
  5466. var array$2 = Array.prototype;
  5467. var slice$1 = array$2.slice;
  5468. function ascending$1(a, b) {
  5469. return a - b;
  5470. }
  5471. function area$3(ring) {
  5472. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  5473. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  5474. return area;
  5475. }
  5476. var constant$5 = x => () => x;
  5477. function contains$2(ring, hole) {
  5478. var i = -1, n = hole.length, c;
  5479. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  5480. return 0;
  5481. }
  5482. function ringContains(ring, point) {
  5483. var x = point[0], y = point[1], contains = -1;
  5484. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  5485. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  5486. if (segmentContains(pi, pj, point)) return 0;
  5487. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  5488. }
  5489. return contains;
  5490. }
  5491. function segmentContains(a, b, c) {
  5492. var i; return collinear$1(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  5493. }
  5494. function collinear$1(a, b, c) {
  5495. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  5496. }
  5497. function within(p, q, r) {
  5498. return p <= q && q <= r || r <= q && q <= p;
  5499. }
  5500. function noop$2() {}
  5501. var cases = [
  5502. [],
  5503. [[[1.0, 1.5], [0.5, 1.0]]],
  5504. [[[1.5, 1.0], [1.0, 1.5]]],
  5505. [[[1.5, 1.0], [0.5, 1.0]]],
  5506. [[[1.0, 0.5], [1.5, 1.0]]],
  5507. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  5508. [[[1.0, 0.5], [1.0, 1.5]]],
  5509. [[[1.0, 0.5], [0.5, 1.0]]],
  5510. [[[0.5, 1.0], [1.0, 0.5]]],
  5511. [[[1.0, 1.5], [1.0, 0.5]]],
  5512. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  5513. [[[1.5, 1.0], [1.0, 0.5]]],
  5514. [[[0.5, 1.0], [1.5, 1.0]]],
  5515. [[[1.0, 1.5], [1.5, 1.0]]],
  5516. [[[0.5, 1.0], [1.0, 1.5]]],
  5517. []
  5518. ];
  5519. function Contours() {
  5520. var dx = 1,
  5521. dy = 1,
  5522. threshold = thresholdSturges,
  5523. smooth = smoothLinear;
  5524. function contours(values) {
  5525. var tz = threshold(values);
  5526. // Convert number of thresholds into uniform thresholds.
  5527. if (!Array.isArray(tz)) {
  5528. const e = extent$1(values, finite);
  5529. tz = ticks(...nice$1(e[0], e[1], tz), tz);
  5530. while (tz[tz.length - 1] >= e[1]) tz.pop();
  5531. while (tz[1] < e[0]) tz.shift();
  5532. } else {
  5533. tz = tz.slice().sort(ascending$1);
  5534. }
  5535. return tz.map(value => contour(values, value));
  5536. }
  5537. // Accumulate, smooth contour rings, assign holes to exterior rings.
  5538. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  5539. function contour(values, value) {
  5540. const v = value == null ? NaN : +value;
  5541. if (isNaN(v)) throw new Error(`invalid value: ${value}`);
  5542. var polygons = [],
  5543. holes = [];
  5544. isorings(values, v, function(ring) {
  5545. smooth(ring, values, v);
  5546. if (area$3(ring) > 0) polygons.push([ring]);
  5547. else holes.push(ring);
  5548. });
  5549. holes.forEach(function(hole) {
  5550. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  5551. if (contains$2((polygon = polygons[i])[0], hole) !== -1) {
  5552. polygon.push(hole);
  5553. return;
  5554. }
  5555. }
  5556. });
  5557. return {
  5558. type: "MultiPolygon",
  5559. value: value,
  5560. coordinates: polygons
  5561. };
  5562. }
  5563. // Marching squares with isolines stitched into rings.
  5564. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  5565. function isorings(values, value, callback) {
  5566. var fragmentByStart = new Array,
  5567. fragmentByEnd = new Array,
  5568. x, y, t0, t1, t2, t3;
  5569. // Special case for the first row (y = -1, t2 = t3 = 0).
  5570. x = y = -1;
  5571. t1 = above(values[0], value);
  5572. cases[t1 << 1].forEach(stitch);
  5573. while (++x < dx - 1) {
  5574. t0 = t1, t1 = above(values[x + 1], value);
  5575. cases[t0 | t1 << 1].forEach(stitch);
  5576. }
  5577. cases[t1 << 0].forEach(stitch);
  5578. // General case for the intermediate rows.
  5579. while (++y < dy - 1) {
  5580. x = -1;
  5581. t1 = above(values[y * dx + dx], value);
  5582. t2 = above(values[y * dx], value);
  5583. cases[t1 << 1 | t2 << 2].forEach(stitch);
  5584. while (++x < dx - 1) {
  5585. t0 = t1, t1 = above(values[y * dx + dx + x + 1], value);
  5586. t3 = t2, t2 = above(values[y * dx + x + 1], value);
  5587. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  5588. }
  5589. cases[t1 | t2 << 3].forEach(stitch);
  5590. }
  5591. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  5592. x = -1;
  5593. t2 = values[y * dx] >= value;
  5594. cases[t2 << 2].forEach(stitch);
  5595. while (++x < dx - 1) {
  5596. t3 = t2, t2 = above(values[y * dx + x + 1], value);
  5597. cases[t2 << 2 | t3 << 3].forEach(stitch);
  5598. }
  5599. cases[t2 << 3].forEach(stitch);
  5600. function stitch(line) {
  5601. var start = [line[0][0] + x, line[0][1] + y],
  5602. end = [line[1][0] + x, line[1][1] + y],
  5603. startIndex = index(start),
  5604. endIndex = index(end),
  5605. f, g;
  5606. if (f = fragmentByEnd[startIndex]) {
  5607. if (g = fragmentByStart[endIndex]) {
  5608. delete fragmentByEnd[f.end];
  5609. delete fragmentByStart[g.start];
  5610. if (f === g) {
  5611. f.ring.push(end);
  5612. callback(f.ring);
  5613. } else {
  5614. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  5615. }
  5616. } else {
  5617. delete fragmentByEnd[f.end];
  5618. f.ring.push(end);
  5619. fragmentByEnd[f.end = endIndex] = f;
  5620. }
  5621. } else if (f = fragmentByStart[endIndex]) {
  5622. if (g = fragmentByEnd[startIndex]) {
  5623. delete fragmentByStart[f.start];
  5624. delete fragmentByEnd[g.end];
  5625. if (f === g) {
  5626. f.ring.push(end);
  5627. callback(f.ring);
  5628. } else {
  5629. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  5630. }
  5631. } else {
  5632. delete fragmentByStart[f.start];
  5633. f.ring.unshift(start);
  5634. fragmentByStart[f.start = startIndex] = f;
  5635. }
  5636. } else {
  5637. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  5638. }
  5639. }
  5640. }
  5641. function index(point) {
  5642. return point[0] * 2 + point[1] * (dx + 1) * 4;
  5643. }
  5644. function smoothLinear(ring, values, value) {
  5645. ring.forEach(function(point) {
  5646. var x = point[0],
  5647. y = point[1],
  5648. xt = x | 0,
  5649. yt = y | 0,
  5650. v1 = valid(values[yt * dx + xt]);
  5651. if (x > 0 && x < dx && xt === x) {
  5652. point[0] = smooth1(x, valid(values[yt * dx + xt - 1]), v1, value);
  5653. }
  5654. if (y > 0 && y < dy && yt === y) {
  5655. point[1] = smooth1(y, valid(values[(yt - 1) * dx + xt]), v1, value);
  5656. }
  5657. });
  5658. }
  5659. contours.contour = contour;
  5660. contours.size = function(_) {
  5661. if (!arguments.length) return [dx, dy];
  5662. var _0 = Math.floor(_[0]), _1 = Math.floor(_[1]);
  5663. if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
  5664. return dx = _0, dy = _1, contours;
  5665. };
  5666. contours.thresholds = function(_) {
  5667. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), contours) : threshold;
  5668. };
  5669. contours.smooth = function(_) {
  5670. return arguments.length ? (smooth = _ ? smoothLinear : noop$2, contours) : smooth === smoothLinear;
  5671. };
  5672. return contours;
  5673. }
  5674. // When computing the extent, ignore infinite values (as well as invalid ones).
  5675. function finite(x) {
  5676. return isFinite(x) ? x : NaN;
  5677. }
  5678. // Is the (possibly invalid) x greater than or equal to the (known valid) value?
  5679. // Treat any invalid value as below negative infinity.
  5680. function above(x, value) {
  5681. return x == null ? false : +x >= value;
  5682. }
  5683. // During smoothing, treat any invalid value as negative infinity.
  5684. function valid(v) {
  5685. return v == null || isNaN(v = +v) ? -Infinity : v;
  5686. }
  5687. function smooth1(x, v0, v1, value) {
  5688. const a = value - v0;
  5689. const b = v1 - v0;
  5690. const d = isFinite(a) || isFinite(b) ? a / b : Math.sign(a) / Math.sign(b);
  5691. return isNaN(d) ? x : x + d - 0.5;
  5692. }
  5693. function defaultX$1(d) {
  5694. return d[0];
  5695. }
  5696. function defaultY$1(d) {
  5697. return d[1];
  5698. }
  5699. function defaultWeight() {
  5700. return 1;
  5701. }
  5702. function density() {
  5703. var x = defaultX$1,
  5704. y = defaultY$1,
  5705. weight = defaultWeight,
  5706. dx = 960,
  5707. dy = 500,
  5708. r = 20, // blur radius
  5709. k = 2, // log2(grid cell size)
  5710. o = r * 3, // grid offset, to pad for blur
  5711. n = (dx + o * 2) >> k, // grid width
  5712. m = (dy + o * 2) >> k, // grid height
  5713. threshold = constant$5(20);
  5714. function grid(data) {
  5715. var values = new Float32Array(n * m),
  5716. pow2k = Math.pow(2, -k),
  5717. i = -1;
  5718. for (const d of data) {
  5719. var xi = (x(d, ++i, data) + o) * pow2k,
  5720. yi = (y(d, i, data) + o) * pow2k,
  5721. wi = +weight(d, i, data);
  5722. if (wi && xi >= 0 && xi < n && yi >= 0 && yi < m) {
  5723. var x0 = Math.floor(xi),
  5724. y0 = Math.floor(yi),
  5725. xt = xi - x0 - 0.5,
  5726. yt = yi - y0 - 0.5;
  5727. values[x0 + y0 * n] += (1 - xt) * (1 - yt) * wi;
  5728. values[x0 + 1 + y0 * n] += xt * (1 - yt) * wi;
  5729. values[x0 + 1 + (y0 + 1) * n] += xt * yt * wi;
  5730. values[x0 + (y0 + 1) * n] += (1 - xt) * yt * wi;
  5731. }
  5732. }
  5733. blur2({data: values, width: n, height: m}, r * pow2k);
  5734. return values;
  5735. }
  5736. function density(data) {
  5737. var values = grid(data),
  5738. tz = threshold(values),
  5739. pow4k = Math.pow(2, 2 * k);
  5740. // Convert number of thresholds into uniform thresholds.
  5741. if (!Array.isArray(tz)) {
  5742. tz = ticks(Number.MIN_VALUE, max$3(values) / pow4k, tz);
  5743. }
  5744. return Contours()
  5745. .size([n, m])
  5746. .thresholds(tz.map(d => d * pow4k))
  5747. (values)
  5748. .map((c, i) => (c.value = +tz[i], transform(c)));
  5749. }
  5750. density.contours = function(data) {
  5751. var values = grid(data),
  5752. contours = Contours().size([n, m]),
  5753. pow4k = Math.pow(2, 2 * k),
  5754. contour = value => {
  5755. value = +value;
  5756. var c = transform(contours.contour(values, value * pow4k));
  5757. c.value = value; // preserve exact threshold value
  5758. return c;
  5759. };
  5760. Object.defineProperty(contour, "max", {get: () => max$3(values) / pow4k});
  5761. return contour;
  5762. };
  5763. function transform(geometry) {
  5764. geometry.coordinates.forEach(transformPolygon);
  5765. return geometry;
  5766. }
  5767. function transformPolygon(coordinates) {
  5768. coordinates.forEach(transformRing);
  5769. }
  5770. function transformRing(coordinates) {
  5771. coordinates.forEach(transformPoint);
  5772. }
  5773. // TODO Optimize.
  5774. function transformPoint(coordinates) {
  5775. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  5776. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  5777. }
  5778. function resize() {
  5779. o = r * 3;
  5780. n = (dx + o * 2) >> k;
  5781. m = (dy + o * 2) >> k;
  5782. return density;
  5783. }
  5784. density.x = function(_) {
  5785. return arguments.length ? (x = typeof _ === "function" ? _ : constant$5(+_), density) : x;
  5786. };
  5787. density.y = function(_) {
  5788. return arguments.length ? (y = typeof _ === "function" ? _ : constant$5(+_), density) : y;
  5789. };
  5790. density.weight = function(_) {
  5791. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$5(+_), density) : weight;
  5792. };
  5793. density.size = function(_) {
  5794. if (!arguments.length) return [dx, dy];
  5795. var _0 = +_[0], _1 = +_[1];
  5796. if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
  5797. return dx = _0, dy = _1, resize();
  5798. };
  5799. density.cellSize = function(_) {
  5800. if (!arguments.length) return 1 << k;
  5801. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  5802. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  5803. };
  5804. density.thresholds = function(_) {
  5805. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), density) : threshold;
  5806. };
  5807. density.bandwidth = function(_) {
  5808. if (!arguments.length) return Math.sqrt(r * (r + 1));
  5809. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  5810. return r = (Math.sqrt(4 * _ * _ + 1) - 1) / 2, resize();
  5811. };
  5812. return density;
  5813. }
  5814. const epsilon$3 = 1.1102230246251565e-16;
  5815. const splitter = 134217729;
  5816. const resulterrbound = (3 + 8 * epsilon$3) * epsilon$3;
  5817. // fast_expansion_sum_zeroelim routine from oritinal code
  5818. function sum$1(elen, e, flen, f, h) {
  5819. let Q, Qnew, hh, bvirt;
  5820. let enow = e[0];
  5821. let fnow = f[0];
  5822. let eindex = 0;
  5823. let findex = 0;
  5824. if ((fnow > enow) === (fnow > -enow)) {
  5825. Q = enow;
  5826. enow = e[++eindex];
  5827. } else {
  5828. Q = fnow;
  5829. fnow = f[++findex];
  5830. }
  5831. let hindex = 0;
  5832. if (eindex < elen && findex < flen) {
  5833. if ((fnow > enow) === (fnow > -enow)) {
  5834. Qnew = enow + Q;
  5835. hh = Q - (Qnew - enow);
  5836. enow = e[++eindex];
  5837. } else {
  5838. Qnew = fnow + Q;
  5839. hh = Q - (Qnew - fnow);
  5840. fnow = f[++findex];
  5841. }
  5842. Q = Qnew;
  5843. if (hh !== 0) {
  5844. h[hindex++] = hh;
  5845. }
  5846. while (eindex < elen && findex < flen) {
  5847. if ((fnow > enow) === (fnow > -enow)) {
  5848. Qnew = Q + enow;
  5849. bvirt = Qnew - Q;
  5850. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  5851. enow = e[++eindex];
  5852. } else {
  5853. Qnew = Q + fnow;
  5854. bvirt = Qnew - Q;
  5855. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  5856. fnow = f[++findex];
  5857. }
  5858. Q = Qnew;
  5859. if (hh !== 0) {
  5860. h[hindex++] = hh;
  5861. }
  5862. }
  5863. }
  5864. while (eindex < elen) {
  5865. Qnew = Q + enow;
  5866. bvirt = Qnew - Q;
  5867. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  5868. enow = e[++eindex];
  5869. Q = Qnew;
  5870. if (hh !== 0) {
  5871. h[hindex++] = hh;
  5872. }
  5873. }
  5874. while (findex < flen) {
  5875. Qnew = Q + fnow;
  5876. bvirt = Qnew - Q;
  5877. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  5878. fnow = f[++findex];
  5879. Q = Qnew;
  5880. if (hh !== 0) {
  5881. h[hindex++] = hh;
  5882. }
  5883. }
  5884. if (Q !== 0 || hindex === 0) {
  5885. h[hindex++] = Q;
  5886. }
  5887. return hindex;
  5888. }
  5889. function estimate(elen, e) {
  5890. let Q = e[0];
  5891. for (let i = 1; i < elen; i++) Q += e[i];
  5892. return Q;
  5893. }
  5894. function vec(n) {
  5895. return new Float64Array(n);
  5896. }
  5897. const ccwerrboundA = (3 + 16 * epsilon$3) * epsilon$3;
  5898. const ccwerrboundB = (2 + 12 * epsilon$3) * epsilon$3;
  5899. const ccwerrboundC = (9 + 64 * epsilon$3) * epsilon$3 * epsilon$3;
  5900. const B = vec(4);
  5901. const C1 = vec(8);
  5902. const C2 = vec(12);
  5903. const D = vec(16);
  5904. const u = vec(4);
  5905. function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
  5906. let acxtail, acytail, bcxtail, bcytail;
  5907. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  5908. const acx = ax - cx;
  5909. const bcx = bx - cx;
  5910. const acy = ay - cy;
  5911. const bcy = by - cy;
  5912. s1 = acx * bcy;
  5913. c = splitter * acx;
  5914. ahi = c - (c - acx);
  5915. alo = acx - ahi;
  5916. c = splitter * bcy;
  5917. bhi = c - (c - bcy);
  5918. blo = bcy - bhi;
  5919. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  5920. t1 = acy * bcx;
  5921. c = splitter * acy;
  5922. ahi = c - (c - acy);
  5923. alo = acy - ahi;
  5924. c = splitter * bcx;
  5925. bhi = c - (c - bcx);
  5926. blo = bcx - bhi;
  5927. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  5928. _i = s0 - t0;
  5929. bvirt = s0 - _i;
  5930. B[0] = s0 - (_i + bvirt) + (bvirt - t0);
  5931. _j = s1 + _i;
  5932. bvirt = _j - s1;
  5933. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  5934. _i = _0 - t1;
  5935. bvirt = _0 - _i;
  5936. B[1] = _0 - (_i + bvirt) + (bvirt - t1);
  5937. u3 = _j + _i;
  5938. bvirt = u3 - _j;
  5939. B[2] = _j - (u3 - bvirt) + (_i - bvirt);
  5940. B[3] = u3;
  5941. let det = estimate(4, B);
  5942. let errbound = ccwerrboundB * detsum;
  5943. if (det >= errbound || -det >= errbound) {
  5944. return det;
  5945. }
  5946. bvirt = ax - acx;
  5947. acxtail = ax - (acx + bvirt) + (bvirt - cx);
  5948. bvirt = bx - bcx;
  5949. bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
  5950. bvirt = ay - acy;
  5951. acytail = ay - (acy + bvirt) + (bvirt - cy);
  5952. bvirt = by - bcy;
  5953. bcytail = by - (bcy + bvirt) + (bvirt - cy);
  5954. if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
  5955. return det;
  5956. }
  5957. errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
  5958. det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
  5959. if (det >= errbound || -det >= errbound) return det;
  5960. s1 = acxtail * bcy;
  5961. c = splitter * acxtail;
  5962. ahi = c - (c - acxtail);
  5963. alo = acxtail - ahi;
  5964. c = splitter * bcy;
  5965. bhi = c - (c - bcy);
  5966. blo = bcy - bhi;
  5967. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  5968. t1 = acytail * bcx;
  5969. c = splitter * acytail;
  5970. ahi = c - (c - acytail);
  5971. alo = acytail - ahi;
  5972. c = splitter * bcx;
  5973. bhi = c - (c - bcx);
  5974. blo = bcx - bhi;
  5975. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  5976. _i = s0 - t0;
  5977. bvirt = s0 - _i;
  5978. u[0] = s0 - (_i + bvirt) + (bvirt - t0);
  5979. _j = s1 + _i;
  5980. bvirt = _j - s1;
  5981. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  5982. _i = _0 - t1;
  5983. bvirt = _0 - _i;
  5984. u[1] = _0 - (_i + bvirt) + (bvirt - t1);
  5985. u3 = _j + _i;
  5986. bvirt = u3 - _j;
  5987. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  5988. u[3] = u3;
  5989. const C1len = sum$1(4, B, 4, u, C1);
  5990. s1 = acx * bcytail;
  5991. c = splitter * acx;
  5992. ahi = c - (c - acx);
  5993. alo = acx - ahi;
  5994. c = splitter * bcytail;
  5995. bhi = c - (c - bcytail);
  5996. blo = bcytail - bhi;
  5997. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  5998. t1 = acy * bcxtail;
  5999. c = splitter * acy;
  6000. ahi = c - (c - acy);
  6001. alo = acy - ahi;
  6002. c = splitter * bcxtail;
  6003. bhi = c - (c - bcxtail);
  6004. blo = bcxtail - bhi;
  6005. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  6006. _i = s0 - t0;
  6007. bvirt = s0 - _i;
  6008. u[0] = s0 - (_i + bvirt) + (bvirt - t0);
  6009. _j = s1 + _i;
  6010. bvirt = _j - s1;
  6011. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  6012. _i = _0 - t1;
  6013. bvirt = _0 - _i;
  6014. u[1] = _0 - (_i + bvirt) + (bvirt - t1);
  6015. u3 = _j + _i;
  6016. bvirt = u3 - _j;
  6017. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  6018. u[3] = u3;
  6019. const C2len = sum$1(C1len, C1, 4, u, C2);
  6020. s1 = acxtail * bcytail;
  6021. c = splitter * acxtail;
  6022. ahi = c - (c - acxtail);
  6023. alo = acxtail - ahi;
  6024. c = splitter * bcytail;
  6025. bhi = c - (c - bcytail);
  6026. blo = bcytail - bhi;
  6027. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  6028. t1 = acytail * bcxtail;
  6029. c = splitter * acytail;
  6030. ahi = c - (c - acytail);
  6031. alo = acytail - ahi;
  6032. c = splitter * bcxtail;
  6033. bhi = c - (c - bcxtail);
  6034. blo = bcxtail - bhi;
  6035. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  6036. _i = s0 - t0;
  6037. bvirt = s0 - _i;
  6038. u[0] = s0 - (_i + bvirt) + (bvirt - t0);
  6039. _j = s1 + _i;
  6040. bvirt = _j - s1;
  6041. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  6042. _i = _0 - t1;
  6043. bvirt = _0 - _i;
  6044. u[1] = _0 - (_i + bvirt) + (bvirt - t1);
  6045. u3 = _j + _i;
  6046. bvirt = u3 - _j;
  6047. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  6048. u[3] = u3;
  6049. const Dlen = sum$1(C2len, C2, 4, u, D);
  6050. return D[Dlen - 1];
  6051. }
  6052. function orient2d(ax, ay, bx, by, cx, cy) {
  6053. const detleft = (ay - cy) * (bx - cx);
  6054. const detright = (ax - cx) * (by - cy);
  6055. const det = detleft - detright;
  6056. const detsum = Math.abs(detleft + detright);
  6057. if (Math.abs(det) >= ccwerrboundA * detsum) return det;
  6058. return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
  6059. }
  6060. const EPSILON = Math.pow(2, -52);
  6061. const EDGE_STACK = new Uint32Array(512);
  6062. class Delaunator {
  6063. static from(points, getX = defaultGetX, getY = defaultGetY) {
  6064. const n = points.length;
  6065. const coords = new Float64Array(n * 2);
  6066. for (let i = 0; i < n; i++) {
  6067. const p = points[i];
  6068. coords[2 * i] = getX(p);
  6069. coords[2 * i + 1] = getY(p);
  6070. }
  6071. return new Delaunator(coords);
  6072. }
  6073. constructor(coords) {
  6074. const n = coords.length >> 1;
  6075. if (n > 0 && typeof coords[0] !== 'number') throw new Error('Expected coords to contain numbers.');
  6076. this.coords = coords;
  6077. // arrays that will store the triangulation graph
  6078. const maxTriangles = Math.max(2 * n - 5, 0);
  6079. this._triangles = new Uint32Array(maxTriangles * 3);
  6080. this._halfedges = new Int32Array(maxTriangles * 3);
  6081. // temporary arrays for tracking the edges of the advancing convex hull
  6082. this._hashSize = Math.ceil(Math.sqrt(n));
  6083. this._hullPrev = new Uint32Array(n); // edge to prev edge
  6084. this._hullNext = new Uint32Array(n); // edge to next edge
  6085. this._hullTri = new Uint32Array(n); // edge to adjacent triangle
  6086. this._hullHash = new Int32Array(this._hashSize); // angular edge hash
  6087. // temporary arrays for sorting points
  6088. this._ids = new Uint32Array(n);
  6089. this._dists = new Float64Array(n);
  6090. this.update();
  6091. }
  6092. update() {
  6093. const {coords, _hullPrev: hullPrev, _hullNext: hullNext, _hullTri: hullTri, _hullHash: hullHash} = this;
  6094. const n = coords.length >> 1;
  6095. // populate an array of point indices; calculate input data bbox
  6096. let minX = Infinity;
  6097. let minY = Infinity;
  6098. let maxX = -Infinity;
  6099. let maxY = -Infinity;
  6100. for (let i = 0; i < n; i++) {
  6101. const x = coords[2 * i];
  6102. const y = coords[2 * i + 1];
  6103. if (x < minX) minX = x;
  6104. if (y < minY) minY = y;
  6105. if (x > maxX) maxX = x;
  6106. if (y > maxY) maxY = y;
  6107. this._ids[i] = i;
  6108. }
  6109. const cx = (minX + maxX) / 2;
  6110. const cy = (minY + maxY) / 2;
  6111. let i0, i1, i2;
  6112. // pick a seed point close to the center
  6113. for (let i = 0, minDist = Infinity; i < n; i++) {
  6114. const d = dist(cx, cy, coords[2 * i], coords[2 * i + 1]);
  6115. if (d < minDist) {
  6116. i0 = i;
  6117. minDist = d;
  6118. }
  6119. }
  6120. const i0x = coords[2 * i0];
  6121. const i0y = coords[2 * i0 + 1];
  6122. // find the point closest to the seed
  6123. for (let i = 0, minDist = Infinity; i < n; i++) {
  6124. if (i === i0) continue;
  6125. const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
  6126. if (d < minDist && d > 0) {
  6127. i1 = i;
  6128. minDist = d;
  6129. }
  6130. }
  6131. let i1x = coords[2 * i1];
  6132. let i1y = coords[2 * i1 + 1];
  6133. let minRadius = Infinity;
  6134. // find the third point which forms the smallest circumcircle with the first two
  6135. for (let i = 0; i < n; i++) {
  6136. if (i === i0 || i === i1) continue;
  6137. const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
  6138. if (r < minRadius) {
  6139. i2 = i;
  6140. minRadius = r;
  6141. }
  6142. }
  6143. let i2x = coords[2 * i2];
  6144. let i2y = coords[2 * i2 + 1];
  6145. if (minRadius === Infinity) {
  6146. // order collinear points by dx (or dy if all x are identical)
  6147. // and return the list as a hull
  6148. for (let i = 0; i < n; i++) {
  6149. this._dists[i] = (coords[2 * i] - coords[0]) || (coords[2 * i + 1] - coords[1]);
  6150. }
  6151. quicksort(this._ids, this._dists, 0, n - 1);
  6152. const hull = new Uint32Array(n);
  6153. let j = 0;
  6154. for (let i = 0, d0 = -Infinity; i < n; i++) {
  6155. const id = this._ids[i];
  6156. const d = this._dists[id];
  6157. if (d > d0) {
  6158. hull[j++] = id;
  6159. d0 = d;
  6160. }
  6161. }
  6162. this.hull = hull.subarray(0, j);
  6163. this.triangles = new Uint32Array(0);
  6164. this.halfedges = new Uint32Array(0);
  6165. return;
  6166. }
  6167. // swap the order of the seed points for counter-clockwise orientation
  6168. if (orient2d(i0x, i0y, i1x, i1y, i2x, i2y) < 0) {
  6169. const i = i1;
  6170. const x = i1x;
  6171. const y = i1y;
  6172. i1 = i2;
  6173. i1x = i2x;
  6174. i1y = i2y;
  6175. i2 = i;
  6176. i2x = x;
  6177. i2y = y;
  6178. }
  6179. const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
  6180. this._cx = center.x;
  6181. this._cy = center.y;
  6182. for (let i = 0; i < n; i++) {
  6183. this._dists[i] = dist(coords[2 * i], coords[2 * i + 1], center.x, center.y);
  6184. }
  6185. // sort the points by distance from the seed triangle circumcenter
  6186. quicksort(this._ids, this._dists, 0, n - 1);
  6187. // set up the seed triangle as the starting hull
  6188. this._hullStart = i0;
  6189. let hullSize = 3;
  6190. hullNext[i0] = hullPrev[i2] = i1;
  6191. hullNext[i1] = hullPrev[i0] = i2;
  6192. hullNext[i2] = hullPrev[i1] = i0;
  6193. hullTri[i0] = 0;
  6194. hullTri[i1] = 1;
  6195. hullTri[i2] = 2;
  6196. hullHash.fill(-1);
  6197. hullHash[this._hashKey(i0x, i0y)] = i0;
  6198. hullHash[this._hashKey(i1x, i1y)] = i1;
  6199. hullHash[this._hashKey(i2x, i2y)] = i2;
  6200. this.trianglesLen = 0;
  6201. this._addTriangle(i0, i1, i2, -1, -1, -1);
  6202. for (let k = 0, xp, yp; k < this._ids.length; k++) {
  6203. const i = this._ids[k];
  6204. const x = coords[2 * i];
  6205. const y = coords[2 * i + 1];
  6206. // skip near-duplicate points
  6207. if (k > 0 && Math.abs(x - xp) <= EPSILON && Math.abs(y - yp) <= EPSILON) continue;
  6208. xp = x;
  6209. yp = y;
  6210. // skip seed triangle points
  6211. if (i === i0 || i === i1 || i === i2) continue;
  6212. // find a visible edge on the convex hull using edge hash
  6213. let start = 0;
  6214. for (let j = 0, key = this._hashKey(x, y); j < this._hashSize; j++) {
  6215. start = hullHash[(key + j) % this._hashSize];
  6216. if (start !== -1 && start !== hullNext[start]) break;
  6217. }
  6218. start = hullPrev[start];
  6219. let e = start, q;
  6220. while (q = hullNext[e], orient2d(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1]) >= 0) {
  6221. e = q;
  6222. if (e === start) {
  6223. e = -1;
  6224. break;
  6225. }
  6226. }
  6227. if (e === -1) continue; // likely a near-duplicate point; skip it
  6228. // add the first triangle from the point
  6229. let t = this._addTriangle(e, i, hullNext[e], -1, -1, hullTri[e]);
  6230. // recursively flip triangles from the point until they satisfy the Delaunay condition
  6231. hullTri[i] = this._legalize(t + 2);
  6232. hullTri[e] = t; // keep track of boundary triangles on the hull
  6233. hullSize++;
  6234. // walk forward through the hull, adding more triangles and flipping recursively
  6235. let n = hullNext[e];
  6236. while (q = hullNext[n], orient2d(x, y, coords[2 * n], coords[2 * n + 1], coords[2 * q], coords[2 * q + 1]) < 0) {
  6237. t = this._addTriangle(n, i, q, hullTri[i], -1, hullTri[n]);
  6238. hullTri[i] = this._legalize(t + 2);
  6239. hullNext[n] = n; // mark as removed
  6240. hullSize--;
  6241. n = q;
  6242. }
  6243. // walk backward from the other side, adding more triangles and flipping
  6244. if (e === start) {
  6245. while (q = hullPrev[e], orient2d(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1]) < 0) {
  6246. t = this._addTriangle(q, i, e, -1, hullTri[e], hullTri[q]);
  6247. this._legalize(t + 2);
  6248. hullTri[q] = t;
  6249. hullNext[e] = e; // mark as removed
  6250. hullSize--;
  6251. e = q;
  6252. }
  6253. }
  6254. // update the hull indices
  6255. this._hullStart = hullPrev[i] = e;
  6256. hullNext[e] = hullPrev[n] = i;
  6257. hullNext[i] = n;
  6258. // save the two new edges in the hash table
  6259. hullHash[this._hashKey(x, y)] = i;
  6260. hullHash[this._hashKey(coords[2 * e], coords[2 * e + 1])] = e;
  6261. }
  6262. this.hull = new Uint32Array(hullSize);
  6263. for (let i = 0, e = this._hullStart; i < hullSize; i++) {
  6264. this.hull[i] = e;
  6265. e = hullNext[e];
  6266. }
  6267. // trim typed triangle mesh arrays
  6268. this.triangles = this._triangles.subarray(0, this.trianglesLen);
  6269. this.halfedges = this._halfedges.subarray(0, this.trianglesLen);
  6270. }
  6271. _hashKey(x, y) {
  6272. return Math.floor(pseudoAngle(x - this._cx, y - this._cy) * this._hashSize) % this._hashSize;
  6273. }
  6274. _legalize(a) {
  6275. const {_triangles: triangles, _halfedges: halfedges, coords} = this;
  6276. let i = 0;
  6277. let ar = 0;
  6278. // recursion eliminated with a fixed-size stack
  6279. while (true) {
  6280. const b = halfedges[a];
  6281. /* if the pair of triangles doesn't satisfy the Delaunay condition
  6282. * (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
  6283. * then do the same check/flip recursively for the new pair of triangles
  6284. *
  6285. * pl pl
  6286. * /||\ / \
  6287. * al/ || \bl al/ \a
  6288. * / || \ / \
  6289. * / a||b \ flip /___ar___\
  6290. * p0\ || /p1 => p0\---bl---/p1
  6291. * \ || / \ /
  6292. * ar\ || /br b\ /br
  6293. * \||/ \ /
  6294. * pr pr
  6295. */
  6296. const a0 = a - a % 3;
  6297. ar = a0 + (a + 2) % 3;
  6298. if (b === -1) { // convex hull edge
  6299. if (i === 0) break;
  6300. a = EDGE_STACK[--i];
  6301. continue;
  6302. }
  6303. const b0 = b - b % 3;
  6304. const al = a0 + (a + 1) % 3;
  6305. const bl = b0 + (b + 2) % 3;
  6306. const p0 = triangles[ar];
  6307. const pr = triangles[a];
  6308. const pl = triangles[al];
  6309. const p1 = triangles[bl];
  6310. const illegal = inCircle(
  6311. coords[2 * p0], coords[2 * p0 + 1],
  6312. coords[2 * pr], coords[2 * pr + 1],
  6313. coords[2 * pl], coords[2 * pl + 1],
  6314. coords[2 * p1], coords[2 * p1 + 1]);
  6315. if (illegal) {
  6316. triangles[a] = p1;
  6317. triangles[b] = p0;
  6318. const hbl = halfedges[bl];
  6319. // edge swapped on the other side of the hull (rare); fix the halfedge reference
  6320. if (hbl === -1) {
  6321. let e = this._hullStart;
  6322. do {
  6323. if (this._hullTri[e] === bl) {
  6324. this._hullTri[e] = a;
  6325. break;
  6326. }
  6327. e = this._hullPrev[e];
  6328. } while (e !== this._hullStart);
  6329. }
  6330. this._link(a, hbl);
  6331. this._link(b, halfedges[ar]);
  6332. this._link(ar, bl);
  6333. const br = b0 + (b + 1) % 3;
  6334. // don't worry about hitting the cap: it can only happen on extremely degenerate input
  6335. if (i < EDGE_STACK.length) {
  6336. EDGE_STACK[i++] = br;
  6337. }
  6338. } else {
  6339. if (i === 0) break;
  6340. a = EDGE_STACK[--i];
  6341. }
  6342. }
  6343. return ar;
  6344. }
  6345. _link(a, b) {
  6346. this._halfedges[a] = b;
  6347. if (b !== -1) this._halfedges[b] = a;
  6348. }
  6349. // add a new triangle given vertex indices and adjacent half-edge ids
  6350. _addTriangle(i0, i1, i2, a, b, c) {
  6351. const t = this.trianglesLen;
  6352. this._triangles[t] = i0;
  6353. this._triangles[t + 1] = i1;
  6354. this._triangles[t + 2] = i2;
  6355. this._link(t, a);
  6356. this._link(t + 1, b);
  6357. this._link(t + 2, c);
  6358. this.trianglesLen += 3;
  6359. return t;
  6360. }
  6361. }
  6362. // monotonically increases with real angle, but doesn't need expensive trigonometry
  6363. function pseudoAngle(dx, dy) {
  6364. const p = dx / (Math.abs(dx) + Math.abs(dy));
  6365. return (dy > 0 ? 3 - p : 1 + p) / 4; // [0..1]
  6366. }
  6367. function dist(ax, ay, bx, by) {
  6368. const dx = ax - bx;
  6369. const dy = ay - by;
  6370. return dx * dx + dy * dy;
  6371. }
  6372. function inCircle(ax, ay, bx, by, cx, cy, px, py) {
  6373. const dx = ax - px;
  6374. const dy = ay - py;
  6375. const ex = bx - px;
  6376. const ey = by - py;
  6377. const fx = cx - px;
  6378. const fy = cy - py;
  6379. const ap = dx * dx + dy * dy;
  6380. const bp = ex * ex + ey * ey;
  6381. const cp = fx * fx + fy * fy;
  6382. return dx * (ey * cp - bp * fy) -
  6383. dy * (ex * cp - bp * fx) +
  6384. ap * (ex * fy - ey * fx) < 0;
  6385. }
  6386. function circumradius(ax, ay, bx, by, cx, cy) {
  6387. const dx = bx - ax;
  6388. const dy = by - ay;
  6389. const ex = cx - ax;
  6390. const ey = cy - ay;
  6391. const bl = dx * dx + dy * dy;
  6392. const cl = ex * ex + ey * ey;
  6393. const d = 0.5 / (dx * ey - dy * ex);
  6394. const x = (ey * bl - dy * cl) * d;
  6395. const y = (dx * cl - ex * bl) * d;
  6396. return x * x + y * y;
  6397. }
  6398. function circumcenter(ax, ay, bx, by, cx, cy) {
  6399. const dx = bx - ax;
  6400. const dy = by - ay;
  6401. const ex = cx - ax;
  6402. const ey = cy - ay;
  6403. const bl = dx * dx + dy * dy;
  6404. const cl = ex * ex + ey * ey;
  6405. const d = 0.5 / (dx * ey - dy * ex);
  6406. const x = ax + (ey * bl - dy * cl) * d;
  6407. const y = ay + (dx * cl - ex * bl) * d;
  6408. return {x, y};
  6409. }
  6410. function quicksort(ids, dists, left, right) {
  6411. if (right - left <= 20) {
  6412. for (let i = left + 1; i <= right; i++) {
  6413. const temp = ids[i];
  6414. const tempDist = dists[temp];
  6415. let j = i - 1;
  6416. while (j >= left && dists[ids[j]] > tempDist) ids[j + 1] = ids[j--];
  6417. ids[j + 1] = temp;
  6418. }
  6419. } else {
  6420. const median = (left + right) >> 1;
  6421. let i = left + 1;
  6422. let j = right;
  6423. swap(ids, median, i);
  6424. if (dists[ids[left]] > dists[ids[right]]) swap(ids, left, right);
  6425. if (dists[ids[i]] > dists[ids[right]]) swap(ids, i, right);
  6426. if (dists[ids[left]] > dists[ids[i]]) swap(ids, left, i);
  6427. const temp = ids[i];
  6428. const tempDist = dists[temp];
  6429. while (true) {
  6430. do i++; while (dists[ids[i]] < tempDist);
  6431. do j--; while (dists[ids[j]] > tempDist);
  6432. if (j < i) break;
  6433. swap(ids, i, j);
  6434. }
  6435. ids[left + 1] = ids[j];
  6436. ids[j] = temp;
  6437. if (right - i + 1 >= j - left) {
  6438. quicksort(ids, dists, i, right);
  6439. quicksort(ids, dists, left, j - 1);
  6440. } else {
  6441. quicksort(ids, dists, left, j - 1);
  6442. quicksort(ids, dists, i, right);
  6443. }
  6444. }
  6445. }
  6446. function swap(arr, i, j) {
  6447. const tmp = arr[i];
  6448. arr[i] = arr[j];
  6449. arr[j] = tmp;
  6450. }
  6451. function defaultGetX(p) {
  6452. return p[0];
  6453. }
  6454. function defaultGetY(p) {
  6455. return p[1];
  6456. }
  6457. const epsilon$2 = 1e-6;
  6458. class Path {
  6459. constructor() {
  6460. this._x0 = this._y0 = // start of current subpath
  6461. this._x1 = this._y1 = null; // end of current subpath
  6462. this._ = "";
  6463. }
  6464. moveTo(x, y) {
  6465. this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
  6466. }
  6467. closePath() {
  6468. if (this._x1 !== null) {
  6469. this._x1 = this._x0, this._y1 = this._y0;
  6470. this._ += "Z";
  6471. }
  6472. }
  6473. lineTo(x, y) {
  6474. this._ += `L${this._x1 = +x},${this._y1 = +y}`;
  6475. }
  6476. arc(x, y, r) {
  6477. x = +x, y = +y, r = +r;
  6478. const x0 = x + r;
  6479. const y0 = y;
  6480. if (r < 0) throw new Error("negative radius");
  6481. if (this._x1 === null) this._ += `M${x0},${y0}`;
  6482. else if (Math.abs(this._x1 - x0) > epsilon$2 || Math.abs(this._y1 - y0) > epsilon$2) this._ += "L" + x0 + "," + y0;
  6483. if (!r) return;
  6484. this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`;
  6485. }
  6486. rect(x, y, w, h) {
  6487. this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`;
  6488. }
  6489. value() {
  6490. return this._ || null;
  6491. }
  6492. }
  6493. class Polygon {
  6494. constructor() {
  6495. this._ = [];
  6496. }
  6497. moveTo(x, y) {
  6498. this._.push([x, y]);
  6499. }
  6500. closePath() {
  6501. this._.push(this._[0].slice());
  6502. }
  6503. lineTo(x, y) {
  6504. this._.push([x, y]);
  6505. }
  6506. value() {
  6507. return this._.length ? this._ : null;
  6508. }
  6509. }
  6510. class Voronoi {
  6511. constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) {
  6512. if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds");
  6513. this.delaunay = delaunay;
  6514. this._circumcenters = new Float64Array(delaunay.points.length * 2);
  6515. this.vectors = new Float64Array(delaunay.points.length * 2);
  6516. this.xmax = xmax, this.xmin = xmin;
  6517. this.ymax = ymax, this.ymin = ymin;
  6518. this._init();
  6519. }
  6520. update() {
  6521. this.delaunay.update();
  6522. this._init();
  6523. return this;
  6524. }
  6525. _init() {
  6526. const {delaunay: {points, hull, triangles}, vectors} = this;
  6527. let bx, by; // lazily computed barycenter of the hull
  6528. // Compute circumcenters.
  6529. const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2);
  6530. for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
  6531. const t1 = triangles[i] * 2;
  6532. const t2 = triangles[i + 1] * 2;
  6533. const t3 = triangles[i + 2] * 2;
  6534. const x1 = points[t1];
  6535. const y1 = points[t1 + 1];
  6536. const x2 = points[t2];
  6537. const y2 = points[t2 + 1];
  6538. const x3 = points[t3];
  6539. const y3 = points[t3 + 1];
  6540. const dx = x2 - x1;
  6541. const dy = y2 - y1;
  6542. const ex = x3 - x1;
  6543. const ey = y3 - y1;
  6544. const ab = (dx * ey - dy * ex) * 2;
  6545. if (Math.abs(ab) < 1e-9) {
  6546. // For a degenerate triangle, the circumcenter is at the infinity, in a
  6547. // direction orthogonal to the halfedge and away from the “center” of
  6548. // the diagram <bx, by>, defined as the hull’s barycenter.
  6549. if (bx === undefined) {
  6550. bx = by = 0;
  6551. for (const i of hull) bx += points[i * 2], by += points[i * 2 + 1];
  6552. bx /= hull.length, by /= hull.length;
  6553. }
  6554. const a = 1e9 * Math.sign((bx - x1) * ey - (by - y1) * ex);
  6555. x = (x1 + x3) / 2 - a * ey;
  6556. y = (y1 + y3) / 2 + a * ex;
  6557. } else {
  6558. const d = 1 / ab;
  6559. const bl = dx * dx + dy * dy;
  6560. const cl = ex * ex + ey * ey;
  6561. x = x1 + (ey * bl - dy * cl) * d;
  6562. y = y1 + (dx * cl - ex * bl) * d;
  6563. }
  6564. circumcenters[j] = x;
  6565. circumcenters[j + 1] = y;
  6566. }
  6567. // Compute exterior cell rays.
  6568. let h = hull[hull.length - 1];
  6569. let p0, p1 = h * 4;
  6570. let x0, x1 = points[2 * h];
  6571. let y0, y1 = points[2 * h + 1];
  6572. vectors.fill(0);
  6573. for (let i = 0; i < hull.length; ++i) {
  6574. h = hull[i];
  6575. p0 = p1, x0 = x1, y0 = y1;
  6576. p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1];
  6577. vectors[p0 + 2] = vectors[p1] = y0 - y1;
  6578. vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
  6579. }
  6580. }
  6581. render(context) {
  6582. const buffer = context == null ? context = new Path : undefined;
  6583. const {delaunay: {halfedges, inedges, hull}, circumcenters, vectors} = this;
  6584. if (hull.length <= 1) return null;
  6585. for (let i = 0, n = halfedges.length; i < n; ++i) {
  6586. const j = halfedges[i];
  6587. if (j < i) continue;
  6588. const ti = Math.floor(i / 3) * 2;
  6589. const tj = Math.floor(j / 3) * 2;
  6590. const xi = circumcenters[ti];
  6591. const yi = circumcenters[ti + 1];
  6592. const xj = circumcenters[tj];
  6593. const yj = circumcenters[tj + 1];
  6594. this._renderSegment(xi, yi, xj, yj, context);
  6595. }
  6596. let h0, h1 = hull[hull.length - 1];
  6597. for (let i = 0; i < hull.length; ++i) {
  6598. h0 = h1, h1 = hull[i];
  6599. const t = Math.floor(inedges[h1] / 3) * 2;
  6600. const x = circumcenters[t];
  6601. const y = circumcenters[t + 1];
  6602. const v = h0 * 4;
  6603. const p = this._project(x, y, vectors[v + 2], vectors[v + 3]);
  6604. if (p) this._renderSegment(x, y, p[0], p[1], context);
  6605. }
  6606. return buffer && buffer.value();
  6607. }
  6608. renderBounds(context) {
  6609. const buffer = context == null ? context = new Path : undefined;
  6610. context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin);
  6611. return buffer && buffer.value();
  6612. }
  6613. renderCell(i, context) {
  6614. const buffer = context == null ? context = new Path : undefined;
  6615. const points = this._clip(i);
  6616. if (points === null || !points.length) return;
  6617. context.moveTo(points[0], points[1]);
  6618. let n = points.length;
  6619. while (points[0] === points[n-2] && points[1] === points[n-1] && n > 1) n -= 2;
  6620. for (let i = 2; i < n; i += 2) {
  6621. if (points[i] !== points[i-2] || points[i+1] !== points[i-1])
  6622. context.lineTo(points[i], points[i + 1]);
  6623. }
  6624. context.closePath();
  6625. return buffer && buffer.value();
  6626. }
  6627. *cellPolygons() {
  6628. const {delaunay: {points}} = this;
  6629. for (let i = 0, n = points.length / 2; i < n; ++i) {
  6630. const cell = this.cellPolygon(i);
  6631. if (cell) cell.index = i, yield cell;
  6632. }
  6633. }
  6634. cellPolygon(i) {
  6635. const polygon = new Polygon;
  6636. this.renderCell(i, polygon);
  6637. return polygon.value();
  6638. }
  6639. _renderSegment(x0, y0, x1, y1, context) {
  6640. let S;
  6641. const c0 = this._regioncode(x0, y0);
  6642. const c1 = this._regioncode(x1, y1);
  6643. if (c0 === 0 && c1 === 0) {
  6644. context.moveTo(x0, y0);
  6645. context.lineTo(x1, y1);
  6646. } else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) {
  6647. context.moveTo(S[0], S[1]);
  6648. context.lineTo(S[2], S[3]);
  6649. }
  6650. }
  6651. contains(i, x, y) {
  6652. if ((x = +x, x !== x) || (y = +y, y !== y)) return false;
  6653. return this.delaunay._step(i, x, y) === i;
  6654. }
  6655. *neighbors(i) {
  6656. const ci = this._clip(i);
  6657. if (ci) for (const j of this.delaunay.neighbors(i)) {
  6658. const cj = this._clip(j);
  6659. // find the common edge
  6660. if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) {
  6661. for (let aj = 0, lj = cj.length; aj < lj; aj += 2) {
  6662. if (ci[ai] === cj[aj]
  6663. && ci[ai + 1] === cj[aj + 1]
  6664. && ci[(ai + 2) % li] === cj[(aj + lj - 2) % lj]
  6665. && ci[(ai + 3) % li] === cj[(aj + lj - 1) % lj]) {
  6666. yield j;
  6667. break loop;
  6668. }
  6669. }
  6670. }
  6671. }
  6672. }
  6673. _cell(i) {
  6674. const {circumcenters, delaunay: {inedges, halfedges, triangles}} = this;
  6675. const e0 = inedges[i];
  6676. if (e0 === -1) return null; // coincident point
  6677. const points = [];
  6678. let e = e0;
  6679. do {
  6680. const t = Math.floor(e / 3);
  6681. points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]);
  6682. e = e % 3 === 2 ? e - 2 : e + 1;
  6683. if (triangles[e] !== i) break; // bad triangulation
  6684. e = halfedges[e];
  6685. } while (e !== e0 && e !== -1);
  6686. return points;
  6687. }
  6688. _clip(i) {
  6689. // degenerate case (1 valid point: return the box)
  6690. if (i === 0 && this.delaunay.hull.length === 1) {
  6691. return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
  6692. }
  6693. const points = this._cell(i);
  6694. if (points === null) return null;
  6695. const {vectors: V} = this;
  6696. const v = i * 4;
  6697. return this._simplify(V[v] || V[v + 1]
  6698. ? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3])
  6699. : this._clipFinite(i, points));
  6700. }
  6701. _clipFinite(i, points) {
  6702. const n = points.length;
  6703. let P = null;
  6704. let x0, y0, x1 = points[n - 2], y1 = points[n - 1];
  6705. let c0, c1 = this._regioncode(x1, y1);
  6706. let e0, e1 = 0;
  6707. for (let j = 0; j < n; j += 2) {
  6708. x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1];
  6709. c0 = c1, c1 = this._regioncode(x1, y1);
  6710. if (c0 === 0 && c1 === 0) {
  6711. e0 = e1, e1 = 0;
  6712. if (P) P.push(x1, y1);
  6713. else P = [x1, y1];
  6714. } else {
  6715. let S, sx0, sy0, sx1, sy1;
  6716. if (c0 === 0) {
  6717. if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue;
  6718. [sx0, sy0, sx1, sy1] = S;
  6719. } else {
  6720. if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue;
  6721. [sx1, sy1, sx0, sy0] = S;
  6722. e0 = e1, e1 = this._edgecode(sx0, sy0);
  6723. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6724. if (P) P.push(sx0, sy0);
  6725. else P = [sx0, sy0];
  6726. }
  6727. e0 = e1, e1 = this._edgecode(sx1, sy1);
  6728. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6729. if (P) P.push(sx1, sy1);
  6730. else P = [sx1, sy1];
  6731. }
  6732. }
  6733. if (P) {
  6734. e0 = e1, e1 = this._edgecode(P[0], P[1]);
  6735. if (e0 && e1) this._edge(i, e0, e1, P, P.length);
  6736. } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
  6737. return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
  6738. }
  6739. return P;
  6740. }
  6741. _clipSegment(x0, y0, x1, y1, c0, c1) {
  6742. // for more robustness, always consider the segment in the same order
  6743. const flip = c0 < c1;
  6744. if (flip) [x0, y0, x1, y1, c0, c1] = [x1, y1, x0, y0, c1, c0];
  6745. while (true) {
  6746. if (c0 === 0 && c1 === 0) return flip ? [x1, y1, x0, y0] : [x0, y0, x1, y1];
  6747. if (c0 & c1) return null;
  6748. let x, y, c = c0 || c1;
  6749. if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax;
  6750. else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin;
  6751. else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax;
  6752. else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin;
  6753. if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0);
  6754. else x1 = x, y1 = y, c1 = this._regioncode(x1, y1);
  6755. }
  6756. }
  6757. _clipInfinite(i, points, vx0, vy0, vxn, vyn) {
  6758. let P = Array.from(points), p;
  6759. if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]);
  6760. if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]);
  6761. if (P = this._clipFinite(i, P)) {
  6762. for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) {
  6763. c0 = c1, c1 = this._edgecode(P[j], P[j + 1]);
  6764. if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length;
  6765. }
  6766. } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
  6767. P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax];
  6768. }
  6769. return P;
  6770. }
  6771. _edge(i, e0, e1, P, j) {
  6772. while (e0 !== e1) {
  6773. let x, y;
  6774. switch (e0) {
  6775. case 0b0101: e0 = 0b0100; continue; // top-left
  6776. case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break; // top
  6777. case 0b0110: e0 = 0b0010; continue; // top-right
  6778. case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break; // right
  6779. case 0b1010: e0 = 0b1000; continue; // bottom-right
  6780. case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break; // bottom
  6781. case 0b1001: e0 = 0b0001; continue; // bottom-left
  6782. case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break; // left
  6783. }
  6784. // Note: this implicitly checks for out of bounds: if P[j] or P[j+1] are
  6785. // undefined, the conditional statement will be executed.
  6786. if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) {
  6787. P.splice(j, 0, x, y), j += 2;
  6788. }
  6789. }
  6790. return j;
  6791. }
  6792. _project(x0, y0, vx, vy) {
  6793. let t = Infinity, c, x, y;
  6794. if (vy < 0) { // top
  6795. if (y0 <= this.ymin) return null;
  6796. if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx;
  6797. } else if (vy > 0) { // bottom
  6798. if (y0 >= this.ymax) return null;
  6799. if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx;
  6800. }
  6801. if (vx > 0) { // right
  6802. if (x0 >= this.xmax) return null;
  6803. if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy;
  6804. } else if (vx < 0) { // left
  6805. if (x0 <= this.xmin) return null;
  6806. if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy;
  6807. }
  6808. return [x, y];
  6809. }
  6810. _edgecode(x, y) {
  6811. return (x === this.xmin ? 0b0001
  6812. : x === this.xmax ? 0b0010 : 0b0000)
  6813. | (y === this.ymin ? 0b0100
  6814. : y === this.ymax ? 0b1000 : 0b0000);
  6815. }
  6816. _regioncode(x, y) {
  6817. return (x < this.xmin ? 0b0001
  6818. : x > this.xmax ? 0b0010 : 0b0000)
  6819. | (y < this.ymin ? 0b0100
  6820. : y > this.ymax ? 0b1000 : 0b0000);
  6821. }
  6822. _simplify(P) {
  6823. if (P && P.length > 4) {
  6824. for (let i = 0; i < P.length; i+= 2) {
  6825. const j = (i + 2) % P.length, k = (i + 4) % P.length;
  6826. if (P[i] === P[j] && P[j] === P[k] || P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1]) {
  6827. P.splice(j, 2), i -= 2;
  6828. }
  6829. }
  6830. if (!P.length) P = null;
  6831. }
  6832. return P;
  6833. }
  6834. }
  6835. const tau$2 = 2 * Math.PI, pow$2 = Math.pow;
  6836. function pointX(p) {
  6837. return p[0];
  6838. }
  6839. function pointY(p) {
  6840. return p[1];
  6841. }
  6842. // A triangulation is collinear if all its triangles have a non-null area
  6843. function collinear(d) {
  6844. const {triangles, coords} = d;
  6845. for (let i = 0; i < triangles.length; i += 3) {
  6846. const a = 2 * triangles[i],
  6847. b = 2 * triangles[i + 1],
  6848. c = 2 * triangles[i + 2],
  6849. cross = (coords[c] - coords[a]) * (coords[b + 1] - coords[a + 1])
  6850. - (coords[b] - coords[a]) * (coords[c + 1] - coords[a + 1]);
  6851. if (cross > 1e-10) return false;
  6852. }
  6853. return true;
  6854. }
  6855. function jitter(x, y, r) {
  6856. return [x + Math.sin(x + y) * r, y + Math.cos(x - y) * r];
  6857. }
  6858. class Delaunay {
  6859. static from(points, fx = pointX, fy = pointY, that) {
  6860. return new Delaunay("length" in points
  6861. ? flatArray(points, fx, fy, that)
  6862. : Float64Array.from(flatIterable(points, fx, fy, that)));
  6863. }
  6864. constructor(points) {
  6865. this._delaunator = new Delaunator(points);
  6866. this.inedges = new Int32Array(points.length / 2);
  6867. this._hullIndex = new Int32Array(points.length / 2);
  6868. this.points = this._delaunator.coords;
  6869. this._init();
  6870. }
  6871. update() {
  6872. this._delaunator.update();
  6873. this._init();
  6874. return this;
  6875. }
  6876. _init() {
  6877. const d = this._delaunator, points = this.points;
  6878. // check for collinear
  6879. if (d.hull && d.hull.length > 2 && collinear(d)) {
  6880. this.collinear = Int32Array.from({length: points.length/2}, (_,i) => i)
  6881. .sort((i, j) => points[2 * i] - points[2 * j] || points[2 * i + 1] - points[2 * j + 1]); // for exact neighbors
  6882. const e = this.collinear[0], f = this.collinear[this.collinear.length - 1],
  6883. bounds = [ points[2 * e], points[2 * e + 1], points[2 * f], points[2 * f + 1] ],
  6884. r = 1e-8 * Math.hypot(bounds[3] - bounds[1], bounds[2] - bounds[0]);
  6885. for (let i = 0, n = points.length / 2; i < n; ++i) {
  6886. const p = jitter(points[2 * i], points[2 * i + 1], r);
  6887. points[2 * i] = p[0];
  6888. points[2 * i + 1] = p[1];
  6889. }
  6890. this._delaunator = new Delaunator(points);
  6891. } else {
  6892. delete this.collinear;
  6893. }
  6894. const halfedges = this.halfedges = this._delaunator.halfedges;
  6895. const hull = this.hull = this._delaunator.hull;
  6896. const triangles = this.triangles = this._delaunator.triangles;
  6897. const inedges = this.inedges.fill(-1);
  6898. const hullIndex = this._hullIndex.fill(-1);
  6899. // Compute an index from each point to an (arbitrary) incoming halfedge
  6900. // Used to give the first neighbor of each point; for this reason,
  6901. // on the hull we give priority to exterior halfedges
  6902. for (let e = 0, n = halfedges.length; e < n; ++e) {
  6903. const p = triangles[e % 3 === 2 ? e - 2 : e + 1];
  6904. if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e;
  6905. }
  6906. for (let i = 0, n = hull.length; i < n; ++i) {
  6907. hullIndex[hull[i]] = i;
  6908. }
  6909. // degenerate case: 1 or 2 (distinct) points
  6910. if (hull.length <= 2 && hull.length > 0) {
  6911. this.triangles = new Int32Array(3).fill(-1);
  6912. this.halfedges = new Int32Array(3).fill(-1);
  6913. this.triangles[0] = hull[0];
  6914. inedges[hull[0]] = 1;
  6915. if (hull.length === 2) {
  6916. inedges[hull[1]] = 0;
  6917. this.triangles[1] = hull[1];
  6918. this.triangles[2] = hull[1];
  6919. }
  6920. }
  6921. }
  6922. voronoi(bounds) {
  6923. return new Voronoi(this, bounds);
  6924. }
  6925. *neighbors(i) {
  6926. const {inedges, hull, _hullIndex, halfedges, triangles, collinear} = this;
  6927. // degenerate case with several collinear points
  6928. if (collinear) {
  6929. const l = collinear.indexOf(i);
  6930. if (l > 0) yield collinear[l - 1];
  6931. if (l < collinear.length - 1) yield collinear[l + 1];
  6932. return;
  6933. }
  6934. const e0 = inedges[i];
  6935. if (e0 === -1) return; // coincident point
  6936. let e = e0, p0 = -1;
  6937. do {
  6938. yield p0 = triangles[e];
  6939. e = e % 3 === 2 ? e - 2 : e + 1;
  6940. if (triangles[e] !== i) return; // bad triangulation
  6941. e = halfedges[e];
  6942. if (e === -1) {
  6943. const p = hull[(_hullIndex[i] + 1) % hull.length];
  6944. if (p !== p0) yield p;
  6945. return;
  6946. }
  6947. } while (e !== e0);
  6948. }
  6949. find(x, y, i = 0) {
  6950. if ((x = +x, x !== x) || (y = +y, y !== y)) return -1;
  6951. const i0 = i;
  6952. let c;
  6953. while ((c = this._step(i, x, y)) >= 0 && c !== i && c !== i0) i = c;
  6954. return c;
  6955. }
  6956. _step(i, x, y) {
  6957. const {inedges, hull, _hullIndex, halfedges, triangles, points} = this;
  6958. if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1);
  6959. let c = i;
  6960. let dc = pow$2(x - points[i * 2], 2) + pow$2(y - points[i * 2 + 1], 2);
  6961. const e0 = inedges[i];
  6962. let e = e0;
  6963. do {
  6964. let t = triangles[e];
  6965. const dt = pow$2(x - points[t * 2], 2) + pow$2(y - points[t * 2 + 1], 2);
  6966. if (dt < dc) dc = dt, c = t;
  6967. e = e % 3 === 2 ? e - 2 : e + 1;
  6968. if (triangles[e] !== i) break; // bad triangulation
  6969. e = halfedges[e];
  6970. if (e === -1) {
  6971. e = hull[(_hullIndex[i] + 1) % hull.length];
  6972. if (e !== t) {
  6973. if (pow$2(x - points[e * 2], 2) + pow$2(y - points[e * 2 + 1], 2) < dc) return e;
  6974. }
  6975. break;
  6976. }
  6977. } while (e !== e0);
  6978. return c;
  6979. }
  6980. render(context) {
  6981. const buffer = context == null ? context = new Path : undefined;
  6982. const {points, halfedges, triangles} = this;
  6983. for (let i = 0, n = halfedges.length; i < n; ++i) {
  6984. const j = halfedges[i];
  6985. if (j < i) continue;
  6986. const ti = triangles[i] * 2;
  6987. const tj = triangles[j] * 2;
  6988. context.moveTo(points[ti], points[ti + 1]);
  6989. context.lineTo(points[tj], points[tj + 1]);
  6990. }
  6991. this.renderHull(context);
  6992. return buffer && buffer.value();
  6993. }
  6994. renderPoints(context, r) {
  6995. if (r === undefined && (!context || typeof context.moveTo !== "function")) r = context, context = null;
  6996. r = r == undefined ? 2 : +r;
  6997. const buffer = context == null ? context = new Path : undefined;
  6998. const {points} = this;
  6999. for (let i = 0, n = points.length; i < n; i += 2) {
  7000. const x = points[i], y = points[i + 1];
  7001. context.moveTo(x + r, y);
  7002. context.arc(x, y, r, 0, tau$2);
  7003. }
  7004. return buffer && buffer.value();
  7005. }
  7006. renderHull(context) {
  7007. const buffer = context == null ? context = new Path : undefined;
  7008. const {hull, points} = this;
  7009. const h = hull[0] * 2, n = hull.length;
  7010. context.moveTo(points[h], points[h + 1]);
  7011. for (let i = 1; i < n; ++i) {
  7012. const h = 2 * hull[i];
  7013. context.lineTo(points[h], points[h + 1]);
  7014. }
  7015. context.closePath();
  7016. return buffer && buffer.value();
  7017. }
  7018. hullPolygon() {
  7019. const polygon = new Polygon;
  7020. this.renderHull(polygon);
  7021. return polygon.value();
  7022. }
  7023. renderTriangle(i, context) {
  7024. const buffer = context == null ? context = new Path : undefined;
  7025. const {points, triangles} = this;
  7026. const t0 = triangles[i *= 3] * 2;
  7027. const t1 = triangles[i + 1] * 2;
  7028. const t2 = triangles[i + 2] * 2;
  7029. context.moveTo(points[t0], points[t0 + 1]);
  7030. context.lineTo(points[t1], points[t1 + 1]);
  7031. context.lineTo(points[t2], points[t2 + 1]);
  7032. context.closePath();
  7033. return buffer && buffer.value();
  7034. }
  7035. *trianglePolygons() {
  7036. const {triangles} = this;
  7037. for (let i = 0, n = triangles.length / 3; i < n; ++i) {
  7038. yield this.trianglePolygon(i);
  7039. }
  7040. }
  7041. trianglePolygon(i) {
  7042. const polygon = new Polygon;
  7043. this.renderTriangle(i, polygon);
  7044. return polygon.value();
  7045. }
  7046. }
  7047. function flatArray(points, fx, fy, that) {
  7048. const n = points.length;
  7049. const array = new Float64Array(n * 2);
  7050. for (let i = 0; i < n; ++i) {
  7051. const p = points[i];
  7052. array[i * 2] = fx.call(that, p, i, points);
  7053. array[i * 2 + 1] = fy.call(that, p, i, points);
  7054. }
  7055. return array;
  7056. }
  7057. function* flatIterable(points, fx, fy, that) {
  7058. let i = 0;
  7059. for (const p of points) {
  7060. yield fx.call(that, p, i, points);
  7061. yield fy.call(that, p, i, points);
  7062. ++i;
  7063. }
  7064. }
  7065. var EOL = {},
  7066. EOF = {},
  7067. QUOTE = 34,
  7068. NEWLINE = 10,
  7069. RETURN = 13;
  7070. function objectConverter(columns) {
  7071. return new Function("d", "return {" + columns.map(function(name, i) {
  7072. return JSON.stringify(name) + ": d[" + i + "] || \"\"";
  7073. }).join(",") + "}");
  7074. }
  7075. function customConverter(columns, f) {
  7076. var object = objectConverter(columns);
  7077. return function(row, i) {
  7078. return f(object(row), i, columns);
  7079. };
  7080. }
  7081. // Compute unique columns in order of discovery.
  7082. function inferColumns(rows) {
  7083. var columnSet = Object.create(null),
  7084. columns = [];
  7085. rows.forEach(function(row) {
  7086. for (var column in row) {
  7087. if (!(column in columnSet)) {
  7088. columns.push(columnSet[column] = column);
  7089. }
  7090. }
  7091. });
  7092. return columns;
  7093. }
  7094. function pad$1(value, width) {
  7095. var s = value + "", length = s.length;
  7096. return length < width ? new Array(width - length + 1).join(0) + s : s;
  7097. }
  7098. function formatYear$1(year) {
  7099. return year < 0 ? "-" + pad$1(-year, 6)
  7100. : year > 9999 ? "+" + pad$1(year, 6)
  7101. : pad$1(year, 4);
  7102. }
  7103. function formatDate(date) {
  7104. var hours = date.getUTCHours(),
  7105. minutes = date.getUTCMinutes(),
  7106. seconds = date.getUTCSeconds(),
  7107. milliseconds = date.getUTCMilliseconds();
  7108. return isNaN(date) ? "Invalid Date"
  7109. : formatYear$1(date.getUTCFullYear()) + "-" + pad$1(date.getUTCMonth() + 1, 2) + "-" + pad$1(date.getUTCDate(), 2)
  7110. + (milliseconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "." + pad$1(milliseconds, 3) + "Z"
  7111. : seconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "Z"
  7112. : minutes || hours ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + "Z"
  7113. : "");
  7114. }
  7115. function dsvFormat(delimiter) {
  7116. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  7117. DELIMITER = delimiter.charCodeAt(0);
  7118. function parse(text, f) {
  7119. var convert, columns, rows = parseRows(text, function(row, i) {
  7120. if (convert) return convert(row, i - 1);
  7121. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  7122. });
  7123. rows.columns = columns || [];
  7124. return rows;
  7125. }
  7126. function parseRows(text, f) {
  7127. var rows = [], // output rows
  7128. N = text.length,
  7129. I = 0, // current character index
  7130. n = 0, // current line number
  7131. t, // current token
  7132. eof = N <= 0, // current token followed by EOF?
  7133. eol = false; // current token followed by EOL?
  7134. // Strip the trailing newline.
  7135. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  7136. if (text.charCodeAt(N - 1) === RETURN) --N;
  7137. function token() {
  7138. if (eof) return EOF;
  7139. if (eol) return eol = false, EOL;
  7140. // Unescape quotes.
  7141. var i, j = I, c;
  7142. if (text.charCodeAt(j) === QUOTE) {
  7143. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  7144. if ((i = I) >= N) eof = true;
  7145. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  7146. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  7147. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  7148. }
  7149. // Find next delimiter or newline.
  7150. while (I < N) {
  7151. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  7152. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  7153. else if (c !== DELIMITER) continue;
  7154. return text.slice(j, i);
  7155. }
  7156. // Return last token before EOF.
  7157. return eof = true, text.slice(j, N);
  7158. }
  7159. while ((t = token()) !== EOF) {
  7160. var row = [];
  7161. while (t !== EOL && t !== EOF) row.push(t), t = token();
  7162. if (f && (row = f(row, n++)) == null) continue;
  7163. rows.push(row);
  7164. }
  7165. return rows;
  7166. }
  7167. function preformatBody(rows, columns) {
  7168. return rows.map(function(row) {
  7169. return columns.map(function(column) {
  7170. return formatValue(row[column]);
  7171. }).join(delimiter);
  7172. });
  7173. }
  7174. function format(rows, columns) {
  7175. if (columns == null) columns = inferColumns(rows);
  7176. return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
  7177. }
  7178. function formatBody(rows, columns) {
  7179. if (columns == null) columns = inferColumns(rows);
  7180. return preformatBody(rows, columns).join("\n");
  7181. }
  7182. function formatRows(rows) {
  7183. return rows.map(formatRow).join("\n");
  7184. }
  7185. function formatRow(row) {
  7186. return row.map(formatValue).join(delimiter);
  7187. }
  7188. function formatValue(value) {
  7189. return value == null ? ""
  7190. : value instanceof Date ? formatDate(value)
  7191. : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
  7192. : value;
  7193. }
  7194. return {
  7195. parse: parse,
  7196. parseRows: parseRows,
  7197. format: format,
  7198. formatBody: formatBody,
  7199. formatRows: formatRows,
  7200. formatRow: formatRow,
  7201. formatValue: formatValue
  7202. };
  7203. }
  7204. var csv$1 = dsvFormat(",");
  7205. var csvParse = csv$1.parse;
  7206. var csvParseRows = csv$1.parseRows;
  7207. var csvFormat = csv$1.format;
  7208. var csvFormatBody = csv$1.formatBody;
  7209. var csvFormatRows = csv$1.formatRows;
  7210. var csvFormatRow = csv$1.formatRow;
  7211. var csvFormatValue = csv$1.formatValue;
  7212. var tsv$1 = dsvFormat("\t");
  7213. var tsvParse = tsv$1.parse;
  7214. var tsvParseRows = tsv$1.parseRows;
  7215. var tsvFormat = tsv$1.format;
  7216. var tsvFormatBody = tsv$1.formatBody;
  7217. var tsvFormatRows = tsv$1.formatRows;
  7218. var tsvFormatRow = tsv$1.formatRow;
  7219. var tsvFormatValue = tsv$1.formatValue;
  7220. function autoType(object) {
  7221. for (var key in object) {
  7222. var value = object[key].trim(), number, m;
  7223. if (!value) value = null;
  7224. else if (value === "true") value = true;
  7225. else if (value === "false") value = false;
  7226. else if (value === "NaN") value = NaN;
  7227. else if (!isNaN(number = +value)) value = number;
  7228. 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})?)?$/)) {
  7229. if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
  7230. value = new Date(value);
  7231. }
  7232. else continue;
  7233. object[key] = value;
  7234. }
  7235. return object;
  7236. }
  7237. // https://github.com/d3/d3-dsv/issues/45
  7238. const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
  7239. function responseBlob(response) {
  7240. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7241. return response.blob();
  7242. }
  7243. function blob(input, init) {
  7244. return fetch(input, init).then(responseBlob);
  7245. }
  7246. function responseArrayBuffer(response) {
  7247. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7248. return response.arrayBuffer();
  7249. }
  7250. function buffer(input, init) {
  7251. return fetch(input, init).then(responseArrayBuffer);
  7252. }
  7253. function responseText(response) {
  7254. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7255. return response.text();
  7256. }
  7257. function text(input, init) {
  7258. return fetch(input, init).then(responseText);
  7259. }
  7260. function dsvParse(parse) {
  7261. return function(input, init, row) {
  7262. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  7263. return text(input, init).then(function(response) {
  7264. return parse(response, row);
  7265. });
  7266. };
  7267. }
  7268. function dsv(delimiter, input, init, row) {
  7269. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  7270. var format = dsvFormat(delimiter);
  7271. return text(input, init).then(function(response) {
  7272. return format.parse(response, row);
  7273. });
  7274. }
  7275. var csv = dsvParse(csvParse);
  7276. var tsv = dsvParse(tsvParse);
  7277. function image(input, init) {
  7278. return new Promise(function(resolve, reject) {
  7279. var image = new Image;
  7280. for (var key in init) image[key] = init[key];
  7281. image.onerror = reject;
  7282. image.onload = function() { resolve(image); };
  7283. image.src = input;
  7284. });
  7285. }
  7286. function responseJson(response) {
  7287. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  7288. if (response.status === 204 || response.status === 205) return;
  7289. return response.json();
  7290. }
  7291. function json(input, init) {
  7292. return fetch(input, init).then(responseJson);
  7293. }
  7294. function parser(type) {
  7295. return (input, init) => text(input, init)
  7296. .then(text => (new DOMParser).parseFromString(text, type));
  7297. }
  7298. var xml = parser("application/xml");
  7299. var html = parser("text/html");
  7300. var svg = parser("image/svg+xml");
  7301. function center(x, y) {
  7302. var nodes, strength = 1;
  7303. if (x == null) x = 0;
  7304. if (y == null) y = 0;
  7305. function force() {
  7306. var i,
  7307. n = nodes.length,
  7308. node,
  7309. sx = 0,
  7310. sy = 0;
  7311. for (i = 0; i < n; ++i) {
  7312. node = nodes[i], sx += node.x, sy += node.y;
  7313. }
  7314. for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
  7315. node = nodes[i], node.x -= sx, node.y -= sy;
  7316. }
  7317. }
  7318. force.initialize = function(_) {
  7319. nodes = _;
  7320. };
  7321. force.x = function(_) {
  7322. return arguments.length ? (x = +_, force) : x;
  7323. };
  7324. force.y = function(_) {
  7325. return arguments.length ? (y = +_, force) : y;
  7326. };
  7327. force.strength = function(_) {
  7328. return arguments.length ? (strength = +_, force) : strength;
  7329. };
  7330. return force;
  7331. }
  7332. function tree_add(d) {
  7333. const x = +this._x.call(null, d),
  7334. y = +this._y.call(null, d);
  7335. return add(this.cover(x, y), x, y, d);
  7336. }
  7337. function add(tree, x, y, d) {
  7338. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  7339. var parent,
  7340. node = tree._root,
  7341. leaf = {data: d},
  7342. x0 = tree._x0,
  7343. y0 = tree._y0,
  7344. x1 = tree._x1,
  7345. y1 = tree._y1,
  7346. xm,
  7347. ym,
  7348. xp,
  7349. yp,
  7350. right,
  7351. bottom,
  7352. i,
  7353. j;
  7354. // If the tree is empty, initialize the root as a leaf.
  7355. if (!node) return tree._root = leaf, tree;
  7356. // Find the existing leaf for the new point, or add it.
  7357. while (node.length) {
  7358. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  7359. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  7360. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  7361. }
  7362. // Is the new point is exactly coincident with the existing point?
  7363. xp = +tree._x.call(null, node.data);
  7364. yp = +tree._y.call(null, node.data);
  7365. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  7366. // Otherwise, split the leaf node until the old and new point are separated.
  7367. do {
  7368. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  7369. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  7370. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  7371. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  7372. return parent[j] = node, parent[i] = leaf, tree;
  7373. }
  7374. function addAll(data) {
  7375. var d, i, n = data.length,
  7376. x,
  7377. y,
  7378. xz = new Array(n),
  7379. yz = new Array(n),
  7380. x0 = Infinity,
  7381. y0 = Infinity,
  7382. x1 = -Infinity,
  7383. y1 = -Infinity;
  7384. // Compute the points and their extent.
  7385. for (i = 0; i < n; ++i) {
  7386. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  7387. xz[i] = x;
  7388. yz[i] = y;
  7389. if (x < x0) x0 = x;
  7390. if (x > x1) x1 = x;
  7391. if (y < y0) y0 = y;
  7392. if (y > y1) y1 = y;
  7393. }
  7394. // If there were no (valid) points, abort.
  7395. if (x0 > x1 || y0 > y1) return this;
  7396. // Expand the tree to cover the new points.
  7397. this.cover(x0, y0).cover(x1, y1);
  7398. // Add the new points.
  7399. for (i = 0; i < n; ++i) {
  7400. add(this, xz[i], yz[i], data[i]);
  7401. }
  7402. return this;
  7403. }
  7404. function tree_cover(x, y) {
  7405. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  7406. var x0 = this._x0,
  7407. y0 = this._y0,
  7408. x1 = this._x1,
  7409. y1 = this._y1;
  7410. // If the quadtree has no extent, initialize them.
  7411. // Integer extent are necessary so that if we later double the extent,
  7412. // the existing quadrant boundaries don’t change due to floating point error!
  7413. if (isNaN(x0)) {
  7414. x1 = (x0 = Math.floor(x)) + 1;
  7415. y1 = (y0 = Math.floor(y)) + 1;
  7416. }
  7417. // Otherwise, double repeatedly to cover.
  7418. else {
  7419. var z = x1 - x0 || 1,
  7420. node = this._root,
  7421. parent,
  7422. i;
  7423. while (x0 > x || x >= x1 || y0 > y || y >= y1) {
  7424. i = (y < y0) << 1 | (x < x0);
  7425. parent = new Array(4), parent[i] = node, node = parent, z *= 2;
  7426. switch (i) {
  7427. case 0: x1 = x0 + z, y1 = y0 + z; break;
  7428. case 1: x0 = x1 - z, y1 = y0 + z; break;
  7429. case 2: x1 = x0 + z, y0 = y1 - z; break;
  7430. case 3: x0 = x1 - z, y0 = y1 - z; break;
  7431. }
  7432. }
  7433. if (this._root && this._root.length) this._root = node;
  7434. }
  7435. this._x0 = x0;
  7436. this._y0 = y0;
  7437. this._x1 = x1;
  7438. this._y1 = y1;
  7439. return this;
  7440. }
  7441. function tree_data() {
  7442. var data = [];
  7443. this.visit(function(node) {
  7444. if (!node.length) do data.push(node.data); while (node = node.next)
  7445. });
  7446. return data;
  7447. }
  7448. function tree_extent(_) {
  7449. return arguments.length
  7450. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  7451. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  7452. }
  7453. function Quad(node, x0, y0, x1, y1) {
  7454. this.node = node;
  7455. this.x0 = x0;
  7456. this.y0 = y0;
  7457. this.x1 = x1;
  7458. this.y1 = y1;
  7459. }
  7460. function tree_find(x, y, radius) {
  7461. var data,
  7462. x0 = this._x0,
  7463. y0 = this._y0,
  7464. x1,
  7465. y1,
  7466. x2,
  7467. y2,
  7468. x3 = this._x1,
  7469. y3 = this._y1,
  7470. quads = [],
  7471. node = this._root,
  7472. q,
  7473. i;
  7474. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  7475. if (radius == null) radius = Infinity;
  7476. else {
  7477. x0 = x - radius, y0 = y - radius;
  7478. x3 = x + radius, y3 = y + radius;
  7479. radius *= radius;
  7480. }
  7481. while (q = quads.pop()) {
  7482. // Stop searching if this quadrant can’t contain a closer node.
  7483. if (!(node = q.node)
  7484. || (x1 = q.x0) > x3
  7485. || (y1 = q.y0) > y3
  7486. || (x2 = q.x1) < x0
  7487. || (y2 = q.y1) < y0) continue;
  7488. // Bisect the current quadrant.
  7489. if (node.length) {
  7490. var xm = (x1 + x2) / 2,
  7491. ym = (y1 + y2) / 2;
  7492. quads.push(
  7493. new Quad(node[3], xm, ym, x2, y2),
  7494. new Quad(node[2], x1, ym, xm, y2),
  7495. new Quad(node[1], xm, y1, x2, ym),
  7496. new Quad(node[0], x1, y1, xm, ym)
  7497. );
  7498. // Visit the closest quadrant first.
  7499. if (i = (y >= ym) << 1 | (x >= xm)) {
  7500. q = quads[quads.length - 1];
  7501. quads[quads.length - 1] = quads[quads.length - 1 - i];
  7502. quads[quads.length - 1 - i] = q;
  7503. }
  7504. }
  7505. // Visit this point. (Visiting coincident points isn’t necessary!)
  7506. else {
  7507. var dx = x - +this._x.call(null, node.data),
  7508. dy = y - +this._y.call(null, node.data),
  7509. d2 = dx * dx + dy * dy;
  7510. if (d2 < radius) {
  7511. var d = Math.sqrt(radius = d2);
  7512. x0 = x - d, y0 = y - d;
  7513. x3 = x + d, y3 = y + d;
  7514. data = node.data;
  7515. }
  7516. }
  7517. }
  7518. return data;
  7519. }
  7520. function tree_remove(d) {
  7521. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  7522. var parent,
  7523. node = this._root,
  7524. retainer,
  7525. previous,
  7526. next,
  7527. x0 = this._x0,
  7528. y0 = this._y0,
  7529. x1 = this._x1,
  7530. y1 = this._y1,
  7531. x,
  7532. y,
  7533. xm,
  7534. ym,
  7535. right,
  7536. bottom,
  7537. i,
  7538. j;
  7539. // If the tree is empty, initialize the root as a leaf.
  7540. if (!node) return this;
  7541. // Find the leaf node for the point.
  7542. // While descending, also retain the deepest parent with a non-removed sibling.
  7543. if (node.length) while (true) {
  7544. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  7545. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  7546. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  7547. if (!node.length) break;
  7548. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  7549. }
  7550. // Find the point to remove.
  7551. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  7552. if (next = node.next) delete node.next;
  7553. // If there are multiple coincident points, remove just the point.
  7554. if (previous) return (next ? previous.next = next : delete previous.next), this;
  7555. // If this is the root point, remove it.
  7556. if (!parent) return this._root = next, this;
  7557. // Remove this leaf.
  7558. next ? parent[i] = next : delete parent[i];
  7559. // If the parent now contains exactly one leaf, collapse superfluous parents.
  7560. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  7561. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  7562. && !node.length) {
  7563. if (retainer) retainer[j] = node;
  7564. else this._root = node;
  7565. }
  7566. return this;
  7567. }
  7568. function removeAll(data) {
  7569. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  7570. return this;
  7571. }
  7572. function tree_root() {
  7573. return this._root;
  7574. }
  7575. function tree_size() {
  7576. var size = 0;
  7577. this.visit(function(node) {
  7578. if (!node.length) do ++size; while (node = node.next)
  7579. });
  7580. return size;
  7581. }
  7582. function tree_visit(callback) {
  7583. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  7584. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  7585. while (q = quads.pop()) {
  7586. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  7587. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  7588. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  7589. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  7590. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  7591. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  7592. }
  7593. }
  7594. return this;
  7595. }
  7596. function tree_visitAfter(callback) {
  7597. var quads = [], next = [], q;
  7598. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  7599. while (q = quads.pop()) {
  7600. var node = q.node;
  7601. if (node.length) {
  7602. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  7603. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  7604. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  7605. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  7606. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  7607. }
  7608. next.push(q);
  7609. }
  7610. while (q = next.pop()) {
  7611. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  7612. }
  7613. return this;
  7614. }
  7615. function defaultX(d) {
  7616. return d[0];
  7617. }
  7618. function tree_x(_) {
  7619. return arguments.length ? (this._x = _, this) : this._x;
  7620. }
  7621. function defaultY(d) {
  7622. return d[1];
  7623. }
  7624. function tree_y(_) {
  7625. return arguments.length ? (this._y = _, this) : this._y;
  7626. }
  7627. function quadtree(nodes, x, y) {
  7628. var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
  7629. return nodes == null ? tree : tree.addAll(nodes);
  7630. }
  7631. function Quadtree(x, y, x0, y0, x1, y1) {
  7632. this._x = x;
  7633. this._y = y;
  7634. this._x0 = x0;
  7635. this._y0 = y0;
  7636. this._x1 = x1;
  7637. this._y1 = y1;
  7638. this._root = undefined;
  7639. }
  7640. function leaf_copy(leaf) {
  7641. var copy = {data: leaf.data}, next = copy;
  7642. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  7643. return copy;
  7644. }
  7645. var treeProto = quadtree.prototype = Quadtree.prototype;
  7646. treeProto.copy = function() {
  7647. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  7648. node = this._root,
  7649. nodes,
  7650. child;
  7651. if (!node) return copy;
  7652. if (!node.length) return copy._root = leaf_copy(node), copy;
  7653. nodes = [{source: node, target: copy._root = new Array(4)}];
  7654. while (node = nodes.pop()) {
  7655. for (var i = 0; i < 4; ++i) {
  7656. if (child = node.source[i]) {
  7657. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  7658. else node.target[i] = leaf_copy(child);
  7659. }
  7660. }
  7661. }
  7662. return copy;
  7663. };
  7664. treeProto.add = tree_add;
  7665. treeProto.addAll = addAll;
  7666. treeProto.cover = tree_cover;
  7667. treeProto.data = tree_data;
  7668. treeProto.extent = tree_extent;
  7669. treeProto.find = tree_find;
  7670. treeProto.remove = tree_remove;
  7671. treeProto.removeAll = removeAll;
  7672. treeProto.root = tree_root;
  7673. treeProto.size = tree_size;
  7674. treeProto.visit = tree_visit;
  7675. treeProto.visitAfter = tree_visitAfter;
  7676. treeProto.x = tree_x;
  7677. treeProto.y = tree_y;
  7678. function constant$4(x) {
  7679. return function() {
  7680. return x;
  7681. };
  7682. }
  7683. function jiggle(random) {
  7684. return (random() - 0.5) * 1e-6;
  7685. }
  7686. function x$3(d) {
  7687. return d.x + d.vx;
  7688. }
  7689. function y$3(d) {
  7690. return d.y + d.vy;
  7691. }
  7692. function collide(radius) {
  7693. var nodes,
  7694. radii,
  7695. random,
  7696. strength = 1,
  7697. iterations = 1;
  7698. if (typeof radius !== "function") radius = constant$4(radius == null ? 1 : +radius);
  7699. function force() {
  7700. var i, n = nodes.length,
  7701. tree,
  7702. node,
  7703. xi,
  7704. yi,
  7705. ri,
  7706. ri2;
  7707. for (var k = 0; k < iterations; ++k) {
  7708. tree = quadtree(nodes, x$3, y$3).visitAfter(prepare);
  7709. for (i = 0; i < n; ++i) {
  7710. node = nodes[i];
  7711. ri = radii[node.index], ri2 = ri * ri;
  7712. xi = node.x + node.vx;
  7713. yi = node.y + node.vy;
  7714. tree.visit(apply);
  7715. }
  7716. }
  7717. function apply(quad, x0, y0, x1, y1) {
  7718. var data = quad.data, rj = quad.r, r = ri + rj;
  7719. if (data) {
  7720. if (data.index > node.index) {
  7721. var x = xi - data.x - data.vx,
  7722. y = yi - data.y - data.vy,
  7723. l = x * x + y * y;
  7724. if (l < r * r) {
  7725. if (x === 0) x = jiggle(random), l += x * x;
  7726. if (y === 0) y = jiggle(random), l += y * y;
  7727. l = (r - (l = Math.sqrt(l))) / l * strength;
  7728. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  7729. node.vy += (y *= l) * r;
  7730. data.vx -= x * (r = 1 - r);
  7731. data.vy -= y * r;
  7732. }
  7733. }
  7734. return;
  7735. }
  7736. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  7737. }
  7738. }
  7739. function prepare(quad) {
  7740. if (quad.data) return quad.r = radii[quad.data.index];
  7741. for (var i = quad.r = 0; i < 4; ++i) {
  7742. if (quad[i] && quad[i].r > quad.r) {
  7743. quad.r = quad[i].r;
  7744. }
  7745. }
  7746. }
  7747. function initialize() {
  7748. if (!nodes) return;
  7749. var i, n = nodes.length, node;
  7750. radii = new Array(n);
  7751. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  7752. }
  7753. force.initialize = function(_nodes, _random) {
  7754. nodes = _nodes;
  7755. random = _random;
  7756. initialize();
  7757. };
  7758. force.iterations = function(_) {
  7759. return arguments.length ? (iterations = +_, force) : iterations;
  7760. };
  7761. force.strength = function(_) {
  7762. return arguments.length ? (strength = +_, force) : strength;
  7763. };
  7764. force.radius = function(_) {
  7765. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
  7766. };
  7767. return force;
  7768. }
  7769. function index$3(d) {
  7770. return d.index;
  7771. }
  7772. function find(nodeById, nodeId) {
  7773. var node = nodeById.get(nodeId);
  7774. if (!node) throw new Error("node not found: " + nodeId);
  7775. return node;
  7776. }
  7777. function link$2(links) {
  7778. var id = index$3,
  7779. strength = defaultStrength,
  7780. strengths,
  7781. distance = constant$4(30),
  7782. distances,
  7783. nodes,
  7784. count,
  7785. bias,
  7786. random,
  7787. iterations = 1;
  7788. if (links == null) links = [];
  7789. function defaultStrength(link) {
  7790. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  7791. }
  7792. function force(alpha) {
  7793. for (var k = 0, n = links.length; k < iterations; ++k) {
  7794. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  7795. link = links[i], source = link.source, target = link.target;
  7796. x = target.x + target.vx - source.x - source.vx || jiggle(random);
  7797. y = target.y + target.vy - source.y - source.vy || jiggle(random);
  7798. l = Math.sqrt(x * x + y * y);
  7799. l = (l - distances[i]) / l * alpha * strengths[i];
  7800. x *= l, y *= l;
  7801. target.vx -= x * (b = bias[i]);
  7802. target.vy -= y * b;
  7803. source.vx += x * (b = 1 - b);
  7804. source.vy += y * b;
  7805. }
  7806. }
  7807. }
  7808. function initialize() {
  7809. if (!nodes) return;
  7810. var i,
  7811. n = nodes.length,
  7812. m = links.length,
  7813. nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
  7814. link;
  7815. for (i = 0, count = new Array(n); i < m; ++i) {
  7816. link = links[i], link.index = i;
  7817. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  7818. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  7819. count[link.source.index] = (count[link.source.index] || 0) + 1;
  7820. count[link.target.index] = (count[link.target.index] || 0) + 1;
  7821. }
  7822. for (i = 0, bias = new Array(m); i < m; ++i) {
  7823. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  7824. }
  7825. strengths = new Array(m), initializeStrength();
  7826. distances = new Array(m), initializeDistance();
  7827. }
  7828. function initializeStrength() {
  7829. if (!nodes) return;
  7830. for (var i = 0, n = links.length; i < n; ++i) {
  7831. strengths[i] = +strength(links[i], i, links);
  7832. }
  7833. }
  7834. function initializeDistance() {
  7835. if (!nodes) return;
  7836. for (var i = 0, n = links.length; i < n; ++i) {
  7837. distances[i] = +distance(links[i], i, links);
  7838. }
  7839. }
  7840. force.initialize = function(_nodes, _random) {
  7841. nodes = _nodes;
  7842. random = _random;
  7843. initialize();
  7844. };
  7845. force.links = function(_) {
  7846. return arguments.length ? (links = _, initialize(), force) : links;
  7847. };
  7848. force.id = function(_) {
  7849. return arguments.length ? (id = _, force) : id;
  7850. };
  7851. force.iterations = function(_) {
  7852. return arguments.length ? (iterations = +_, force) : iterations;
  7853. };
  7854. force.strength = function(_) {
  7855. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initializeStrength(), force) : strength;
  7856. };
  7857. force.distance = function(_) {
  7858. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$4(+_), initializeDistance(), force) : distance;
  7859. };
  7860. return force;
  7861. }
  7862. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  7863. const a$2 = 1664525;
  7864. const c$4 = 1013904223;
  7865. const m$1 = 4294967296; // 2^32
  7866. function lcg$2() {
  7867. let s = 1;
  7868. return () => (s = (a$2 * s + c$4) % m$1) / m$1;
  7869. }
  7870. function x$2(d) {
  7871. return d.x;
  7872. }
  7873. function y$2(d) {
  7874. return d.y;
  7875. }
  7876. var initialRadius = 10,
  7877. initialAngle = Math.PI * (3 - Math.sqrt(5));
  7878. function simulation(nodes) {
  7879. var simulation,
  7880. alpha = 1,
  7881. alphaMin = 0.001,
  7882. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  7883. alphaTarget = 0,
  7884. velocityDecay = 0.6,
  7885. forces = new Map(),
  7886. stepper = timer(step),
  7887. event = dispatch("tick", "end"),
  7888. random = lcg$2();
  7889. if (nodes == null) nodes = [];
  7890. function step() {
  7891. tick();
  7892. event.call("tick", simulation);
  7893. if (alpha < alphaMin) {
  7894. stepper.stop();
  7895. event.call("end", simulation);
  7896. }
  7897. }
  7898. function tick(iterations) {
  7899. var i, n = nodes.length, node;
  7900. if (iterations === undefined) iterations = 1;
  7901. for (var k = 0; k < iterations; ++k) {
  7902. alpha += (alphaTarget - alpha) * alphaDecay;
  7903. forces.forEach(function(force) {
  7904. force(alpha);
  7905. });
  7906. for (i = 0; i < n; ++i) {
  7907. node = nodes[i];
  7908. if (node.fx == null) node.x += node.vx *= velocityDecay;
  7909. else node.x = node.fx, node.vx = 0;
  7910. if (node.fy == null) node.y += node.vy *= velocityDecay;
  7911. else node.y = node.fy, node.vy = 0;
  7912. }
  7913. }
  7914. return simulation;
  7915. }
  7916. function initializeNodes() {
  7917. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  7918. node = nodes[i], node.index = i;
  7919. if (node.fx != null) node.x = node.fx;
  7920. if (node.fy != null) node.y = node.fy;
  7921. if (isNaN(node.x) || isNaN(node.y)) {
  7922. var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
  7923. node.x = radius * Math.cos(angle);
  7924. node.y = radius * Math.sin(angle);
  7925. }
  7926. if (isNaN(node.vx) || isNaN(node.vy)) {
  7927. node.vx = node.vy = 0;
  7928. }
  7929. }
  7930. }
  7931. function initializeForce(force) {
  7932. if (force.initialize) force.initialize(nodes, random);
  7933. return force;
  7934. }
  7935. initializeNodes();
  7936. return simulation = {
  7937. tick: tick,
  7938. restart: function() {
  7939. return stepper.restart(step), simulation;
  7940. },
  7941. stop: function() {
  7942. return stepper.stop(), simulation;
  7943. },
  7944. nodes: function(_) {
  7945. return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
  7946. },
  7947. alpha: function(_) {
  7948. return arguments.length ? (alpha = +_, simulation) : alpha;
  7949. },
  7950. alphaMin: function(_) {
  7951. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  7952. },
  7953. alphaDecay: function(_) {
  7954. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  7955. },
  7956. alphaTarget: function(_) {
  7957. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  7958. },
  7959. velocityDecay: function(_) {
  7960. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  7961. },
  7962. randomSource: function(_) {
  7963. return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
  7964. },
  7965. force: function(name, _) {
  7966. return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  7967. },
  7968. find: function(x, y, radius) {
  7969. var i = 0,
  7970. n = nodes.length,
  7971. dx,
  7972. dy,
  7973. d2,
  7974. node,
  7975. closest;
  7976. if (radius == null) radius = Infinity;
  7977. else radius *= radius;
  7978. for (i = 0; i < n; ++i) {
  7979. node = nodes[i];
  7980. dx = x - node.x;
  7981. dy = y - node.y;
  7982. d2 = dx * dx + dy * dy;
  7983. if (d2 < radius) closest = node, radius = d2;
  7984. }
  7985. return closest;
  7986. },
  7987. on: function(name, _) {
  7988. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  7989. }
  7990. };
  7991. }
  7992. function manyBody() {
  7993. var nodes,
  7994. node,
  7995. random,
  7996. alpha,
  7997. strength = constant$4(-30),
  7998. strengths,
  7999. distanceMin2 = 1,
  8000. distanceMax2 = Infinity,
  8001. theta2 = 0.81;
  8002. function force(_) {
  8003. var i, n = nodes.length, tree = quadtree(nodes, x$2, y$2).visitAfter(accumulate);
  8004. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  8005. }
  8006. function initialize() {
  8007. if (!nodes) return;
  8008. var i, n = nodes.length, node;
  8009. strengths = new Array(n);
  8010. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  8011. }
  8012. function accumulate(quad) {
  8013. var strength = 0, q, c, weight = 0, x, y, i;
  8014. // For internal nodes, accumulate forces from child quadrants.
  8015. if (quad.length) {
  8016. for (x = y = i = 0; i < 4; ++i) {
  8017. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  8018. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  8019. }
  8020. }
  8021. quad.x = x / weight;
  8022. quad.y = y / weight;
  8023. }
  8024. // For leaf nodes, accumulate forces from coincident quadrants.
  8025. else {
  8026. q = quad;
  8027. q.x = q.data.x;
  8028. q.y = q.data.y;
  8029. do strength += strengths[q.data.index];
  8030. while (q = q.next);
  8031. }
  8032. quad.value = strength;
  8033. }
  8034. function apply(quad, x1, _, x2) {
  8035. if (!quad.value) return true;
  8036. var x = quad.x - node.x,
  8037. y = quad.y - node.y,
  8038. w = x2 - x1,
  8039. l = x * x + y * y;
  8040. // Apply the Barnes-Hut approximation if possible.
  8041. // Limit forces for very close nodes; randomize direction if coincident.
  8042. if (w * w / theta2 < l) {
  8043. if (l < distanceMax2) {
  8044. if (x === 0) x = jiggle(random), l += x * x;
  8045. if (y === 0) y = jiggle(random), l += y * y;
  8046. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  8047. node.vx += x * quad.value * alpha / l;
  8048. node.vy += y * quad.value * alpha / l;
  8049. }
  8050. return true;
  8051. }
  8052. // Otherwise, process points directly.
  8053. else if (quad.length || l >= distanceMax2) return;
  8054. // Limit forces for very close nodes; randomize direction if coincident.
  8055. if (quad.data !== node || quad.next) {
  8056. if (x === 0) x = jiggle(random), l += x * x;
  8057. if (y === 0) y = jiggle(random), l += y * y;
  8058. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  8059. }
  8060. do if (quad.data !== node) {
  8061. w = strengths[quad.data.index] * alpha / l;
  8062. node.vx += x * w;
  8063. node.vy += y * w;
  8064. } while (quad = quad.next);
  8065. }
  8066. force.initialize = function(_nodes, _random) {
  8067. nodes = _nodes;
  8068. random = _random;
  8069. initialize();
  8070. };
  8071. force.strength = function(_) {
  8072. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8073. };
  8074. force.distanceMin = function(_) {
  8075. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  8076. };
  8077. force.distanceMax = function(_) {
  8078. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  8079. };
  8080. force.theta = function(_) {
  8081. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  8082. };
  8083. return force;
  8084. }
  8085. function radial$1(radius, x, y) {
  8086. var nodes,
  8087. strength = constant$4(0.1),
  8088. strengths,
  8089. radiuses;
  8090. if (typeof radius !== "function") radius = constant$4(+radius);
  8091. if (x == null) x = 0;
  8092. if (y == null) y = 0;
  8093. function force(alpha) {
  8094. for (var i = 0, n = nodes.length; i < n; ++i) {
  8095. var node = nodes[i],
  8096. dx = node.x - x || 1e-6,
  8097. dy = node.y - y || 1e-6,
  8098. r = Math.sqrt(dx * dx + dy * dy),
  8099. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  8100. node.vx += dx * k;
  8101. node.vy += dy * k;
  8102. }
  8103. }
  8104. function initialize() {
  8105. if (!nodes) return;
  8106. var i, n = nodes.length;
  8107. strengths = new Array(n);
  8108. radiuses = new Array(n);
  8109. for (i = 0; i < n; ++i) {
  8110. radiuses[i] = +radius(nodes[i], i, nodes);
  8111. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  8112. }
  8113. }
  8114. force.initialize = function(_) {
  8115. nodes = _, initialize();
  8116. };
  8117. force.strength = function(_) {
  8118. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8119. };
  8120. force.radius = function(_) {
  8121. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
  8122. };
  8123. force.x = function(_) {
  8124. return arguments.length ? (x = +_, force) : x;
  8125. };
  8126. force.y = function(_) {
  8127. return arguments.length ? (y = +_, force) : y;
  8128. };
  8129. return force;
  8130. }
  8131. function x$1(x) {
  8132. var strength = constant$4(0.1),
  8133. nodes,
  8134. strengths,
  8135. xz;
  8136. if (typeof x !== "function") x = constant$4(x == null ? 0 : +x);
  8137. function force(alpha) {
  8138. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  8139. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  8140. }
  8141. }
  8142. function initialize() {
  8143. if (!nodes) return;
  8144. var i, n = nodes.length;
  8145. strengths = new Array(n);
  8146. xz = new Array(n);
  8147. for (i = 0; i < n; ++i) {
  8148. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  8149. }
  8150. }
  8151. force.initialize = function(_) {
  8152. nodes = _;
  8153. initialize();
  8154. };
  8155. force.strength = function(_) {
  8156. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8157. };
  8158. force.x = function(_) {
  8159. return arguments.length ? (x = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : x;
  8160. };
  8161. return force;
  8162. }
  8163. function y$1(y) {
  8164. var strength = constant$4(0.1),
  8165. nodes,
  8166. strengths,
  8167. yz;
  8168. if (typeof y !== "function") y = constant$4(y == null ? 0 : +y);
  8169. function force(alpha) {
  8170. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  8171. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  8172. }
  8173. }
  8174. function initialize() {
  8175. if (!nodes) return;
  8176. var i, n = nodes.length;
  8177. strengths = new Array(n);
  8178. yz = new Array(n);
  8179. for (i = 0; i < n; ++i) {
  8180. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  8181. }
  8182. }
  8183. force.initialize = function(_) {
  8184. nodes = _;
  8185. initialize();
  8186. };
  8187. force.strength = function(_) {
  8188. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
  8189. };
  8190. force.y = function(_) {
  8191. return arguments.length ? (y = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : y;
  8192. };
  8193. return force;
  8194. }
  8195. function formatDecimal(x) {
  8196. return Math.abs(x = Math.round(x)) >= 1e21
  8197. ? x.toLocaleString("en").replace(/,/g, "")
  8198. : x.toString(10);
  8199. }
  8200. // Computes the decimal coefficient and exponent of the specified number x with
  8201. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  8202. // For example, formatDecimalParts(1.23) returns ["123", 0].
  8203. function formatDecimalParts(x, p) {
  8204. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  8205. var i, coefficient = x.slice(0, i);
  8206. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  8207. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  8208. return [
  8209. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  8210. +x.slice(i + 1)
  8211. ];
  8212. }
  8213. function exponent(x) {
  8214. return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
  8215. }
  8216. function formatGroup(grouping, thousands) {
  8217. return function(value, width) {
  8218. var i = value.length,
  8219. t = [],
  8220. j = 0,
  8221. g = grouping[0],
  8222. length = 0;
  8223. while (i > 0 && g > 0) {
  8224. if (length + g + 1 > width) g = Math.max(1, width - length);
  8225. t.push(value.substring(i -= g, i + g));
  8226. if ((length += g + 1) > width) break;
  8227. g = grouping[j = (j + 1) % grouping.length];
  8228. }
  8229. return t.reverse().join(thousands);
  8230. };
  8231. }
  8232. function formatNumerals(numerals) {
  8233. return function(value) {
  8234. return value.replace(/[0-9]/g, function(i) {
  8235. return numerals[+i];
  8236. });
  8237. };
  8238. }
  8239. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  8240. var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  8241. function formatSpecifier(specifier) {
  8242. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  8243. var match;
  8244. return new FormatSpecifier({
  8245. fill: match[1],
  8246. align: match[2],
  8247. sign: match[3],
  8248. symbol: match[4],
  8249. zero: match[5],
  8250. width: match[6],
  8251. comma: match[7],
  8252. precision: match[8] && match[8].slice(1),
  8253. trim: match[9],
  8254. type: match[10]
  8255. });
  8256. }
  8257. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  8258. function FormatSpecifier(specifier) {
  8259. this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
  8260. this.align = specifier.align === undefined ? ">" : specifier.align + "";
  8261. this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
  8262. this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
  8263. this.zero = !!specifier.zero;
  8264. this.width = specifier.width === undefined ? undefined : +specifier.width;
  8265. this.comma = !!specifier.comma;
  8266. this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
  8267. this.trim = !!specifier.trim;
  8268. this.type = specifier.type === undefined ? "" : specifier.type + "";
  8269. }
  8270. FormatSpecifier.prototype.toString = function() {
  8271. return this.fill
  8272. + this.align
  8273. + this.sign
  8274. + this.symbol
  8275. + (this.zero ? "0" : "")
  8276. + (this.width === undefined ? "" : Math.max(1, this.width | 0))
  8277. + (this.comma ? "," : "")
  8278. + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
  8279. + (this.trim ? "~" : "")
  8280. + this.type;
  8281. };
  8282. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  8283. function formatTrim(s) {
  8284. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  8285. switch (s[i]) {
  8286. case ".": i0 = i1 = i; break;
  8287. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  8288. default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
  8289. }
  8290. }
  8291. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  8292. }
  8293. var prefixExponent;
  8294. function formatPrefixAuto(x, p) {
  8295. var d = formatDecimalParts(x, p);
  8296. if (!d) return x + "";
  8297. var coefficient = d[0],
  8298. exponent = d[1],
  8299. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  8300. n = coefficient.length;
  8301. return i === n ? coefficient
  8302. : i > n ? coefficient + new Array(i - n + 1).join("0")
  8303. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  8304. : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  8305. }
  8306. function formatRounded(x, p) {
  8307. var d = formatDecimalParts(x, p);
  8308. if (!d) return x + "";
  8309. var coefficient = d[0],
  8310. exponent = d[1];
  8311. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  8312. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  8313. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  8314. }
  8315. var formatTypes = {
  8316. "%": (x, p) => (x * 100).toFixed(p),
  8317. "b": (x) => Math.round(x).toString(2),
  8318. "c": (x) => x + "",
  8319. "d": formatDecimal,
  8320. "e": (x, p) => x.toExponential(p),
  8321. "f": (x, p) => x.toFixed(p),
  8322. "g": (x, p) => x.toPrecision(p),
  8323. "o": (x) => Math.round(x).toString(8),
  8324. "p": (x, p) => formatRounded(x * 100, p),
  8325. "r": formatRounded,
  8326. "s": formatPrefixAuto,
  8327. "X": (x) => Math.round(x).toString(16).toUpperCase(),
  8328. "x": (x) => Math.round(x).toString(16)
  8329. };
  8330. function identity$6(x) {
  8331. return x;
  8332. }
  8333. var map = Array.prototype.map,
  8334. prefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];
  8335. function formatLocale$1(locale) {
  8336. var group = locale.grouping === undefined || locale.thousands === undefined ? identity$6 : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""),
  8337. currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
  8338. currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
  8339. decimal = locale.decimal === undefined ? "." : locale.decimal + "",
  8340. numerals = locale.numerals === undefined ? identity$6 : formatNumerals(map.call(locale.numerals, String)),
  8341. percent = locale.percent === undefined ? "%" : locale.percent + "",
  8342. minus = locale.minus === undefined ? "−" : locale.minus + "",
  8343. nan = locale.nan === undefined ? "NaN" : locale.nan + "";
  8344. function newFormat(specifier) {
  8345. specifier = formatSpecifier(specifier);
  8346. var fill = specifier.fill,
  8347. align = specifier.align,
  8348. sign = specifier.sign,
  8349. symbol = specifier.symbol,
  8350. zero = specifier.zero,
  8351. width = specifier.width,
  8352. comma = specifier.comma,
  8353. precision = specifier.precision,
  8354. trim = specifier.trim,
  8355. type = specifier.type;
  8356. // The "n" type is an alias for ",g".
  8357. if (type === "n") comma = true, type = "g";
  8358. // The "" type, and any invalid type, is an alias for ".12~g".
  8359. else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
  8360. // If zero fill is specified, padding goes after sign and before digits.
  8361. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  8362. // Compute the prefix and suffix.
  8363. // For SI-prefix, the suffix is lazily computed.
  8364. var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  8365. suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
  8366. // What format function should we use?
  8367. // Is this an integer type?
  8368. // Can this type generate exponential notation?
  8369. var formatType = formatTypes[type],
  8370. maybeSuffix = /[defgprs%]/.test(type);
  8371. // Set the default precision if not specified,
  8372. // or clamp the specified precision to the supported range.
  8373. // For significant precision, it must be in [1, 21].
  8374. // For fixed precision, it must be in [0, 20].
  8375. precision = precision === undefined ? 6
  8376. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  8377. : Math.max(0, Math.min(20, precision));
  8378. function format(value) {
  8379. var valuePrefix = prefix,
  8380. valueSuffix = suffix,
  8381. i, n, c;
  8382. if (type === "c") {
  8383. valueSuffix = formatType(value) + valueSuffix;
  8384. value = "";
  8385. } else {
  8386. value = +value;
  8387. // Determine the sign. -0 is not less than 0, but 1 / -0 is!
  8388. var valueNegative = value < 0 || 1 / value < 0;
  8389. // Perform the initial formatting.
  8390. value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
  8391. // Trim insignificant zeros.
  8392. if (trim) value = formatTrim(value);
  8393. // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
  8394. if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
  8395. // Compute the prefix and suffix.
  8396. valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  8397. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  8398. // Break the formatted value into the integer “value” part that can be
  8399. // grouped, and fractional or exponential “suffix” part that is not.
  8400. if (maybeSuffix) {
  8401. i = -1, n = value.length;
  8402. while (++i < n) {
  8403. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  8404. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  8405. value = value.slice(0, i);
  8406. break;
  8407. }
  8408. }
  8409. }
  8410. }
  8411. // If the fill character is not "0", grouping is applied before padding.
  8412. if (comma && !zero) value = group(value, Infinity);
  8413. // Compute the padding.
  8414. var length = valuePrefix.length + value.length + valueSuffix.length,
  8415. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  8416. // If the fill character is "0", grouping is applied after padding.
  8417. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  8418. // Reconstruct the final output based on the desired alignment.
  8419. switch (align) {
  8420. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  8421. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  8422. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  8423. default: value = padding + valuePrefix + value + valueSuffix; break;
  8424. }
  8425. return numerals(value);
  8426. }
  8427. format.toString = function() {
  8428. return specifier + "";
  8429. };
  8430. return format;
  8431. }
  8432. function formatPrefix(specifier, value) {
  8433. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  8434. e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
  8435. k = Math.pow(10, -e),
  8436. prefix = prefixes[8 + e / 3];
  8437. return function(value) {
  8438. return f(k * value) + prefix;
  8439. };
  8440. }
  8441. return {
  8442. format: newFormat,
  8443. formatPrefix: formatPrefix
  8444. };
  8445. }
  8446. var locale$1;
  8447. exports.format = void 0;
  8448. exports.formatPrefix = void 0;
  8449. defaultLocale$1({
  8450. thousands: ",",
  8451. grouping: [3],
  8452. currency: ["$", ""]
  8453. });
  8454. function defaultLocale$1(definition) {
  8455. locale$1 = formatLocale$1(definition);
  8456. exports.format = locale$1.format;
  8457. exports.formatPrefix = locale$1.formatPrefix;
  8458. return locale$1;
  8459. }
  8460. function precisionFixed(step) {
  8461. return Math.max(0, -exponent(Math.abs(step)));
  8462. }
  8463. function precisionPrefix(step, value) {
  8464. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
  8465. }
  8466. function precisionRound(step, max) {
  8467. step = Math.abs(step), max = Math.abs(max) - step;
  8468. return Math.max(0, exponent(max) - exponent(step)) + 1;
  8469. }
  8470. var epsilon$1 = 1e-6;
  8471. var epsilon2 = 1e-12;
  8472. var pi$1 = Math.PI;
  8473. var halfPi$1 = pi$1 / 2;
  8474. var quarterPi = pi$1 / 4;
  8475. var tau$1 = pi$1 * 2;
  8476. var degrees = 180 / pi$1;
  8477. var radians = pi$1 / 180;
  8478. var abs$1 = Math.abs;
  8479. var atan = Math.atan;
  8480. var atan2$1 = Math.atan2;
  8481. var cos$1 = Math.cos;
  8482. var ceil = Math.ceil;
  8483. var exp = Math.exp;
  8484. var hypot = Math.hypot;
  8485. var log$1 = Math.log;
  8486. var pow$1 = Math.pow;
  8487. var sin$1 = Math.sin;
  8488. var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  8489. var sqrt$2 = Math.sqrt;
  8490. var tan = Math.tan;
  8491. function acos$1(x) {
  8492. return x > 1 ? 0 : x < -1 ? pi$1 : Math.acos(x);
  8493. }
  8494. function asin$1(x) {
  8495. return x > 1 ? halfPi$1 : x < -1 ? -halfPi$1 : Math.asin(x);
  8496. }
  8497. function haversin(x) {
  8498. return (x = sin$1(x / 2)) * x;
  8499. }
  8500. function noop$1() {}
  8501. function streamGeometry(geometry, stream) {
  8502. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  8503. streamGeometryType[geometry.type](geometry, stream);
  8504. }
  8505. }
  8506. var streamObjectType = {
  8507. Feature: function(object, stream) {
  8508. streamGeometry(object.geometry, stream);
  8509. },
  8510. FeatureCollection: function(object, stream) {
  8511. var features = object.features, i = -1, n = features.length;
  8512. while (++i < n) streamGeometry(features[i].geometry, stream);
  8513. }
  8514. };
  8515. var streamGeometryType = {
  8516. Sphere: function(object, stream) {
  8517. stream.sphere();
  8518. },
  8519. Point: function(object, stream) {
  8520. object = object.coordinates;
  8521. stream.point(object[0], object[1], object[2]);
  8522. },
  8523. MultiPoint: function(object, stream) {
  8524. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  8525. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  8526. },
  8527. LineString: function(object, stream) {
  8528. streamLine(object.coordinates, stream, 0);
  8529. },
  8530. MultiLineString: function(object, stream) {
  8531. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  8532. while (++i < n) streamLine(coordinates[i], stream, 0);
  8533. },
  8534. Polygon: function(object, stream) {
  8535. streamPolygon(object.coordinates, stream);
  8536. },
  8537. MultiPolygon: function(object, stream) {
  8538. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  8539. while (++i < n) streamPolygon(coordinates[i], stream);
  8540. },
  8541. GeometryCollection: function(object, stream) {
  8542. var geometries = object.geometries, i = -1, n = geometries.length;
  8543. while (++i < n) streamGeometry(geometries[i], stream);
  8544. }
  8545. };
  8546. function streamLine(coordinates, stream, closed) {
  8547. var i = -1, n = coordinates.length - closed, coordinate;
  8548. stream.lineStart();
  8549. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  8550. stream.lineEnd();
  8551. }
  8552. function streamPolygon(coordinates, stream) {
  8553. var i = -1, n = coordinates.length;
  8554. stream.polygonStart();
  8555. while (++i < n) streamLine(coordinates[i], stream, 1);
  8556. stream.polygonEnd();
  8557. }
  8558. function geoStream(object, stream) {
  8559. if (object && streamObjectType.hasOwnProperty(object.type)) {
  8560. streamObjectType[object.type](object, stream);
  8561. } else {
  8562. streamGeometry(object, stream);
  8563. }
  8564. }
  8565. var areaRingSum$1 = new Adder();
  8566. // hello?
  8567. var areaSum$1 = new Adder(),
  8568. lambda00$2,
  8569. phi00$2,
  8570. lambda0$2,
  8571. cosPhi0$1,
  8572. sinPhi0$1;
  8573. var areaStream$1 = {
  8574. point: noop$1,
  8575. lineStart: noop$1,
  8576. lineEnd: noop$1,
  8577. polygonStart: function() {
  8578. areaRingSum$1 = new Adder();
  8579. areaStream$1.lineStart = areaRingStart$1;
  8580. areaStream$1.lineEnd = areaRingEnd$1;
  8581. },
  8582. polygonEnd: function() {
  8583. var areaRing = +areaRingSum$1;
  8584. areaSum$1.add(areaRing < 0 ? tau$1 + areaRing : areaRing);
  8585. this.lineStart = this.lineEnd = this.point = noop$1;
  8586. },
  8587. sphere: function() {
  8588. areaSum$1.add(tau$1);
  8589. }
  8590. };
  8591. function areaRingStart$1() {
  8592. areaStream$1.point = areaPointFirst$1;
  8593. }
  8594. function areaRingEnd$1() {
  8595. areaPoint$1(lambda00$2, phi00$2);
  8596. }
  8597. function areaPointFirst$1(lambda, phi) {
  8598. areaStream$1.point = areaPoint$1;
  8599. lambda00$2 = lambda, phi00$2 = phi;
  8600. lambda *= radians, phi *= radians;
  8601. lambda0$2 = lambda, cosPhi0$1 = cos$1(phi = phi / 2 + quarterPi), sinPhi0$1 = sin$1(phi);
  8602. }
  8603. function areaPoint$1(lambda, phi) {
  8604. lambda *= radians, phi *= radians;
  8605. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  8606. // Spherical excess E for a spherical triangle with vertices: south pole,
  8607. // previous point, current point. Uses a formula derived from Cagnoli’s
  8608. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  8609. var dLambda = lambda - lambda0$2,
  8610. sdLambda = dLambda >= 0 ? 1 : -1,
  8611. adLambda = sdLambda * dLambda,
  8612. cosPhi = cos$1(phi),
  8613. sinPhi = sin$1(phi),
  8614. k = sinPhi0$1 * sinPhi,
  8615. u = cosPhi0$1 * cosPhi + k * cos$1(adLambda),
  8616. v = k * sdLambda * sin$1(adLambda);
  8617. areaRingSum$1.add(atan2$1(v, u));
  8618. // Advance the previous points.
  8619. lambda0$2 = lambda, cosPhi0$1 = cosPhi, sinPhi0$1 = sinPhi;
  8620. }
  8621. function area$2(object) {
  8622. areaSum$1 = new Adder();
  8623. geoStream(object, areaStream$1);
  8624. return areaSum$1 * 2;
  8625. }
  8626. function spherical(cartesian) {
  8627. return [atan2$1(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
  8628. }
  8629. function cartesian(spherical) {
  8630. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  8631. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  8632. }
  8633. function cartesianDot(a, b) {
  8634. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  8635. }
  8636. function cartesianCross(a, b) {
  8637. 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]];
  8638. }
  8639. // TODO return a
  8640. function cartesianAddInPlace(a, b) {
  8641. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  8642. }
  8643. function cartesianScale(vector, k) {
  8644. return [vector[0] * k, vector[1] * k, vector[2] * k];
  8645. }
  8646. // TODO return d
  8647. function cartesianNormalizeInPlace(d) {
  8648. var l = sqrt$2(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  8649. d[0] /= l, d[1] /= l, d[2] /= l;
  8650. }
  8651. var lambda0$1, phi0, lambda1, phi1, // bounds
  8652. lambda2, // previous lambda-coordinate
  8653. lambda00$1, phi00$1, // first point
  8654. p0, // previous 3D point
  8655. deltaSum,
  8656. ranges,
  8657. range;
  8658. var boundsStream$2 = {
  8659. point: boundsPoint$1,
  8660. lineStart: boundsLineStart,
  8661. lineEnd: boundsLineEnd,
  8662. polygonStart: function() {
  8663. boundsStream$2.point = boundsRingPoint;
  8664. boundsStream$2.lineStart = boundsRingStart;
  8665. boundsStream$2.lineEnd = boundsRingEnd;
  8666. deltaSum = new Adder();
  8667. areaStream$1.polygonStart();
  8668. },
  8669. polygonEnd: function() {
  8670. areaStream$1.polygonEnd();
  8671. boundsStream$2.point = boundsPoint$1;
  8672. boundsStream$2.lineStart = boundsLineStart;
  8673. boundsStream$2.lineEnd = boundsLineEnd;
  8674. if (areaRingSum$1 < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  8675. else if (deltaSum > epsilon$1) phi1 = 90;
  8676. else if (deltaSum < -epsilon$1) phi0 = -90;
  8677. range[0] = lambda0$1, range[1] = lambda1;
  8678. },
  8679. sphere: function() {
  8680. lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  8681. }
  8682. };
  8683. function boundsPoint$1(lambda, phi) {
  8684. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  8685. if (phi < phi0) phi0 = phi;
  8686. if (phi > phi1) phi1 = phi;
  8687. }
  8688. function linePoint(lambda, phi) {
  8689. var p = cartesian([lambda * radians, phi * radians]);
  8690. if (p0) {
  8691. var normal = cartesianCross(p0, p),
  8692. equatorial = [normal[1], -normal[0], 0],
  8693. inflection = cartesianCross(equatorial, normal);
  8694. cartesianNormalizeInPlace(inflection);
  8695. inflection = spherical(inflection);
  8696. var delta = lambda - lambda2,
  8697. sign = delta > 0 ? 1 : -1,
  8698. lambdai = inflection[0] * degrees * sign,
  8699. phii,
  8700. antimeridian = abs$1(delta) > 180;
  8701. if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  8702. phii = inflection[1] * degrees;
  8703. if (phii > phi1) phi1 = phii;
  8704. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  8705. phii = -inflection[1] * degrees;
  8706. if (phii < phi0) phi0 = phii;
  8707. } else {
  8708. if (phi < phi0) phi0 = phi;
  8709. if (phi > phi1) phi1 = phi;
  8710. }
  8711. if (antimeridian) {
  8712. if (lambda < lambda2) {
  8713. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  8714. } else {
  8715. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  8716. }
  8717. } else {
  8718. if (lambda1 >= lambda0$1) {
  8719. if (lambda < lambda0$1) lambda0$1 = lambda;
  8720. if (lambda > lambda1) lambda1 = lambda;
  8721. } else {
  8722. if (lambda > lambda2) {
  8723. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  8724. } else {
  8725. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  8726. }
  8727. }
  8728. }
  8729. } else {
  8730. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  8731. }
  8732. if (phi < phi0) phi0 = phi;
  8733. if (phi > phi1) phi1 = phi;
  8734. p0 = p, lambda2 = lambda;
  8735. }
  8736. function boundsLineStart() {
  8737. boundsStream$2.point = linePoint;
  8738. }
  8739. function boundsLineEnd() {
  8740. range[0] = lambda0$1, range[1] = lambda1;
  8741. boundsStream$2.point = boundsPoint$1;
  8742. p0 = null;
  8743. }
  8744. function boundsRingPoint(lambda, phi) {
  8745. if (p0) {
  8746. var delta = lambda - lambda2;
  8747. deltaSum.add(abs$1(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  8748. } else {
  8749. lambda00$1 = lambda, phi00$1 = phi;
  8750. }
  8751. areaStream$1.point(lambda, phi);
  8752. linePoint(lambda, phi);
  8753. }
  8754. function boundsRingStart() {
  8755. areaStream$1.lineStart();
  8756. }
  8757. function boundsRingEnd() {
  8758. boundsRingPoint(lambda00$1, phi00$1);
  8759. areaStream$1.lineEnd();
  8760. if (abs$1(deltaSum) > epsilon$1) lambda0$1 = -(lambda1 = 180);
  8761. range[0] = lambda0$1, range[1] = lambda1;
  8762. p0 = null;
  8763. }
  8764. // Finds the left-right distance between two longitudes.
  8765. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  8766. // the distance between ±180° to be 360°.
  8767. function angle(lambda0, lambda1) {
  8768. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  8769. }
  8770. function rangeCompare(a, b) {
  8771. return a[0] - b[0];
  8772. }
  8773. function rangeContains(range, x) {
  8774. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  8775. }
  8776. function bounds(feature) {
  8777. var i, n, a, b, merged, deltaMax, delta;
  8778. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  8779. ranges = [];
  8780. geoStream(feature, boundsStream$2);
  8781. // First, sort ranges by their minimum longitudes.
  8782. if (n = ranges.length) {
  8783. ranges.sort(rangeCompare);
  8784. // Then, merge any ranges that overlap.
  8785. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  8786. b = ranges[i];
  8787. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  8788. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  8789. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  8790. } else {
  8791. merged.push(a = b);
  8792. }
  8793. }
  8794. // Finally, find the largest gap between the merged ranges.
  8795. // The final bounding box will be the inverse of this gap.
  8796. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  8797. b = merged[i];
  8798. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  8799. }
  8800. }
  8801. ranges = range = null;
  8802. return lambda0$1 === Infinity || phi0 === Infinity
  8803. ? [[NaN, NaN], [NaN, NaN]]
  8804. : [[lambda0$1, phi0], [lambda1, phi1]];
  8805. }
  8806. var W0, W1,
  8807. X0$1, Y0$1, Z0$1,
  8808. X1$1, Y1$1, Z1$1,
  8809. X2$1, Y2$1, Z2$1,
  8810. lambda00, phi00, // first point
  8811. x0$4, y0$4, z0; // previous point
  8812. var centroidStream$1 = {
  8813. sphere: noop$1,
  8814. point: centroidPoint$1,
  8815. lineStart: centroidLineStart$1,
  8816. lineEnd: centroidLineEnd$1,
  8817. polygonStart: function() {
  8818. centroidStream$1.lineStart = centroidRingStart$1;
  8819. centroidStream$1.lineEnd = centroidRingEnd$1;
  8820. },
  8821. polygonEnd: function() {
  8822. centroidStream$1.lineStart = centroidLineStart$1;
  8823. centroidStream$1.lineEnd = centroidLineEnd$1;
  8824. }
  8825. };
  8826. // Arithmetic mean of Cartesian vectors.
  8827. function centroidPoint$1(lambda, phi) {
  8828. lambda *= radians, phi *= radians;
  8829. var cosPhi = cos$1(phi);
  8830. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  8831. }
  8832. function centroidPointCartesian(x, y, z) {
  8833. ++W0;
  8834. X0$1 += (x - X0$1) / W0;
  8835. Y0$1 += (y - Y0$1) / W0;
  8836. Z0$1 += (z - Z0$1) / W0;
  8837. }
  8838. function centroidLineStart$1() {
  8839. centroidStream$1.point = centroidLinePointFirst;
  8840. }
  8841. function centroidLinePointFirst(lambda, phi) {
  8842. lambda *= radians, phi *= radians;
  8843. var cosPhi = cos$1(phi);
  8844. x0$4 = cosPhi * cos$1(lambda);
  8845. y0$4 = cosPhi * sin$1(lambda);
  8846. z0 = sin$1(phi);
  8847. centroidStream$1.point = centroidLinePoint;
  8848. centroidPointCartesian(x0$4, y0$4, z0);
  8849. }
  8850. function centroidLinePoint(lambda, phi) {
  8851. lambda *= radians, phi *= radians;
  8852. var cosPhi = cos$1(phi),
  8853. x = cosPhi * cos$1(lambda),
  8854. y = cosPhi * sin$1(lambda),
  8855. z = sin$1(phi),
  8856. w = atan2$1(sqrt$2((w = y0$4 * z - z0 * y) * w + (w = z0 * x - x0$4 * z) * w + (w = x0$4 * y - y0$4 * x) * w), x0$4 * x + y0$4 * y + z0 * z);
  8857. W1 += w;
  8858. X1$1 += w * (x0$4 + (x0$4 = x));
  8859. Y1$1 += w * (y0$4 + (y0$4 = y));
  8860. Z1$1 += w * (z0 + (z0 = z));
  8861. centroidPointCartesian(x0$4, y0$4, z0);
  8862. }
  8863. function centroidLineEnd$1() {
  8864. centroidStream$1.point = centroidPoint$1;
  8865. }
  8866. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  8867. // J. Applied Mechanics 42, 239 (1975).
  8868. function centroidRingStart$1() {
  8869. centroidStream$1.point = centroidRingPointFirst;
  8870. }
  8871. function centroidRingEnd$1() {
  8872. centroidRingPoint(lambda00, phi00);
  8873. centroidStream$1.point = centroidPoint$1;
  8874. }
  8875. function centroidRingPointFirst(lambda, phi) {
  8876. lambda00 = lambda, phi00 = phi;
  8877. lambda *= radians, phi *= radians;
  8878. centroidStream$1.point = centroidRingPoint;
  8879. var cosPhi = cos$1(phi);
  8880. x0$4 = cosPhi * cos$1(lambda);
  8881. y0$4 = cosPhi * sin$1(lambda);
  8882. z0 = sin$1(phi);
  8883. centroidPointCartesian(x0$4, y0$4, z0);
  8884. }
  8885. function centroidRingPoint(lambda, phi) {
  8886. lambda *= radians, phi *= radians;
  8887. var cosPhi = cos$1(phi),
  8888. x = cosPhi * cos$1(lambda),
  8889. y = cosPhi * sin$1(lambda),
  8890. z = sin$1(phi),
  8891. cx = y0$4 * z - z0 * y,
  8892. cy = z0 * x - x0$4 * z,
  8893. cz = x0$4 * y - y0$4 * x,
  8894. m = hypot(cx, cy, cz),
  8895. w = asin$1(m), // line weight = angle
  8896. v = m && -w / m; // area weight multiplier
  8897. X2$1.add(v * cx);
  8898. Y2$1.add(v * cy);
  8899. Z2$1.add(v * cz);
  8900. W1 += w;
  8901. X1$1 += w * (x0$4 + (x0$4 = x));
  8902. Y1$1 += w * (y0$4 + (y0$4 = y));
  8903. Z1$1 += w * (z0 + (z0 = z));
  8904. centroidPointCartesian(x0$4, y0$4, z0);
  8905. }
  8906. function centroid$1(object) {
  8907. W0 = W1 =
  8908. X0$1 = Y0$1 = Z0$1 =
  8909. X1$1 = Y1$1 = Z1$1 = 0;
  8910. X2$1 = new Adder();
  8911. Y2$1 = new Adder();
  8912. Z2$1 = new Adder();
  8913. geoStream(object, centroidStream$1);
  8914. var x = +X2$1,
  8915. y = +Y2$1,
  8916. z = +Z2$1,
  8917. m = hypot(x, y, z);
  8918. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  8919. if (m < epsilon2) {
  8920. x = X1$1, y = Y1$1, z = Z1$1;
  8921. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  8922. if (W1 < epsilon$1) x = X0$1, y = Y0$1, z = Z0$1;
  8923. m = hypot(x, y, z);
  8924. // If the feature still has an undefined ccentroid, then return.
  8925. if (m < epsilon2) return [NaN, NaN];
  8926. }
  8927. return [atan2$1(y, x) * degrees, asin$1(z / m) * degrees];
  8928. }
  8929. function constant$3(x) {
  8930. return function() {
  8931. return x;
  8932. };
  8933. }
  8934. function compose(a, b) {
  8935. function compose(x, y) {
  8936. return x = a(x, y), b(x[0], x[1]);
  8937. }
  8938. if (a.invert && b.invert) compose.invert = function(x, y) {
  8939. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  8940. };
  8941. return compose;
  8942. }
  8943. function rotationIdentity(lambda, phi) {
  8944. if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1;
  8945. return [lambda, phi];
  8946. }
  8947. rotationIdentity.invert = rotationIdentity;
  8948. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  8949. return (deltaLambda %= tau$1) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  8950. : rotationLambda(deltaLambda))
  8951. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  8952. : rotationIdentity);
  8953. }
  8954. function forwardRotationLambda(deltaLambda) {
  8955. return function(lambda, phi) {
  8956. lambda += deltaLambda;
  8957. if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1;
  8958. return [lambda, phi];
  8959. };
  8960. }
  8961. function rotationLambda(deltaLambda) {
  8962. var rotation = forwardRotationLambda(deltaLambda);
  8963. rotation.invert = forwardRotationLambda(-deltaLambda);
  8964. return rotation;
  8965. }
  8966. function rotationPhiGamma(deltaPhi, deltaGamma) {
  8967. var cosDeltaPhi = cos$1(deltaPhi),
  8968. sinDeltaPhi = sin$1(deltaPhi),
  8969. cosDeltaGamma = cos$1(deltaGamma),
  8970. sinDeltaGamma = sin$1(deltaGamma);
  8971. function rotation(lambda, phi) {
  8972. var cosPhi = cos$1(phi),
  8973. x = cos$1(lambda) * cosPhi,
  8974. y = sin$1(lambda) * cosPhi,
  8975. z = sin$1(phi),
  8976. k = z * cosDeltaPhi + x * sinDeltaPhi;
  8977. return [
  8978. atan2$1(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  8979. asin$1(k * cosDeltaGamma + y * sinDeltaGamma)
  8980. ];
  8981. }
  8982. rotation.invert = function(lambda, phi) {
  8983. var cosPhi = cos$1(phi),
  8984. x = cos$1(lambda) * cosPhi,
  8985. y = sin$1(lambda) * cosPhi,
  8986. z = sin$1(phi),
  8987. k = z * cosDeltaGamma - y * sinDeltaGamma;
  8988. return [
  8989. atan2$1(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  8990. asin$1(k * cosDeltaPhi - x * sinDeltaPhi)
  8991. ];
  8992. };
  8993. return rotation;
  8994. }
  8995. function rotation(rotate) {
  8996. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  8997. function forward(coordinates) {
  8998. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  8999. return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
  9000. }
  9001. forward.invert = function(coordinates) {
  9002. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  9003. return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
  9004. };
  9005. return forward;
  9006. }
  9007. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  9008. function circleStream(stream, radius, delta, direction, t0, t1) {
  9009. if (!delta) return;
  9010. var cosRadius = cos$1(radius),
  9011. sinRadius = sin$1(radius),
  9012. step = direction * delta;
  9013. if (t0 == null) {
  9014. t0 = radius + direction * tau$1;
  9015. t1 = radius - step / 2;
  9016. } else {
  9017. t0 = circleRadius(cosRadius, t0);
  9018. t1 = circleRadius(cosRadius, t1);
  9019. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$1;
  9020. }
  9021. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  9022. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  9023. stream.point(point[0], point[1]);
  9024. }
  9025. }
  9026. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  9027. function circleRadius(cosRadius, point) {
  9028. point = cartesian(point), point[0] -= cosRadius;
  9029. cartesianNormalizeInPlace(point);
  9030. var radius = acos$1(-point[1]);
  9031. return ((-point[2] < 0 ? -radius : radius) + tau$1 - epsilon$1) % tau$1;
  9032. }
  9033. function circle$1() {
  9034. var center = constant$3([0, 0]),
  9035. radius = constant$3(90),
  9036. precision = constant$3(2),
  9037. ring,
  9038. rotate,
  9039. stream = {point: point};
  9040. function point(x, y) {
  9041. ring.push(x = rotate(x, y));
  9042. x[0] *= degrees, x[1] *= degrees;
  9043. }
  9044. function circle() {
  9045. var c = center.apply(this, arguments),
  9046. r = radius.apply(this, arguments) * radians,
  9047. p = precision.apply(this, arguments) * radians;
  9048. ring = [];
  9049. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  9050. circleStream(stream, r, p, 1);
  9051. c = {type: "Polygon", coordinates: [ring]};
  9052. ring = rotate = null;
  9053. return c;
  9054. }
  9055. circle.center = function(_) {
  9056. return arguments.length ? (center = typeof _ === "function" ? _ : constant$3([+_[0], +_[1]]), circle) : center;
  9057. };
  9058. circle.radius = function(_) {
  9059. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$3(+_), circle) : radius;
  9060. };
  9061. circle.precision = function(_) {
  9062. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$3(+_), circle) : precision;
  9063. };
  9064. return circle;
  9065. }
  9066. function clipBuffer() {
  9067. var lines = [],
  9068. line;
  9069. return {
  9070. point: function(x, y, m) {
  9071. line.push([x, y, m]);
  9072. },
  9073. lineStart: function() {
  9074. lines.push(line = []);
  9075. },
  9076. lineEnd: noop$1,
  9077. rejoin: function() {
  9078. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  9079. },
  9080. result: function() {
  9081. var result = lines;
  9082. lines = [];
  9083. line = null;
  9084. return result;
  9085. }
  9086. };
  9087. }
  9088. function pointEqual(a, b) {
  9089. return abs$1(a[0] - b[0]) < epsilon$1 && abs$1(a[1] - b[1]) < epsilon$1;
  9090. }
  9091. function Intersection(point, points, other, entry) {
  9092. this.x = point;
  9093. this.z = points;
  9094. this.o = other; // another intersection
  9095. this.e = entry; // is an entry?
  9096. this.v = false; // visited
  9097. this.n = this.p = null; // next & previous
  9098. }
  9099. // A generalized polygon clipping algorithm: given a polygon that has been cut
  9100. // into its visible line segments, and rejoins the segments by interpolating
  9101. // along the clip edge.
  9102. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  9103. var subject = [],
  9104. clip = [],
  9105. i,
  9106. n;
  9107. segments.forEach(function(segment) {
  9108. if ((n = segment.length - 1) <= 0) return;
  9109. var n, p0 = segment[0], p1 = segment[n], x;
  9110. if (pointEqual(p0, p1)) {
  9111. if (!p0[2] && !p1[2]) {
  9112. stream.lineStart();
  9113. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  9114. stream.lineEnd();
  9115. return;
  9116. }
  9117. // handle degenerate cases by moving the point
  9118. p1[0] += 2 * epsilon$1;
  9119. }
  9120. subject.push(x = new Intersection(p0, segment, null, true));
  9121. clip.push(x.o = new Intersection(p0, null, x, false));
  9122. subject.push(x = new Intersection(p1, segment, null, false));
  9123. clip.push(x.o = new Intersection(p1, null, x, true));
  9124. });
  9125. if (!subject.length) return;
  9126. clip.sort(compareIntersection);
  9127. link$1(subject);
  9128. link$1(clip);
  9129. for (i = 0, n = clip.length; i < n; ++i) {
  9130. clip[i].e = startInside = !startInside;
  9131. }
  9132. var start = subject[0],
  9133. points,
  9134. point;
  9135. while (1) {
  9136. // Find first unvisited intersection.
  9137. var current = start,
  9138. isSubject = true;
  9139. while (current.v) if ((current = current.n) === start) return;
  9140. points = current.z;
  9141. stream.lineStart();
  9142. do {
  9143. current.v = current.o.v = true;
  9144. if (current.e) {
  9145. if (isSubject) {
  9146. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  9147. } else {
  9148. interpolate(current.x, current.n.x, 1, stream);
  9149. }
  9150. current = current.n;
  9151. } else {
  9152. if (isSubject) {
  9153. points = current.p.z;
  9154. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  9155. } else {
  9156. interpolate(current.x, current.p.x, -1, stream);
  9157. }
  9158. current = current.p;
  9159. }
  9160. current = current.o;
  9161. points = current.z;
  9162. isSubject = !isSubject;
  9163. } while (!current.v);
  9164. stream.lineEnd();
  9165. }
  9166. }
  9167. function link$1(array) {
  9168. if (!(n = array.length)) return;
  9169. var n,
  9170. i = 0,
  9171. a = array[0],
  9172. b;
  9173. while (++i < n) {
  9174. a.n = b = array[i];
  9175. b.p = a;
  9176. a = b;
  9177. }
  9178. a.n = b = array[0];
  9179. b.p = a;
  9180. }
  9181. function longitude(point) {
  9182. return abs$1(point[0]) <= pi$1 ? point[0] : sign$1(point[0]) * ((abs$1(point[0]) + pi$1) % tau$1 - pi$1);
  9183. }
  9184. function polygonContains(polygon, point) {
  9185. var lambda = longitude(point),
  9186. phi = point[1],
  9187. sinPhi = sin$1(phi),
  9188. normal = [sin$1(lambda), -cos$1(lambda), 0],
  9189. angle = 0,
  9190. winding = 0;
  9191. var sum = new Adder();
  9192. if (sinPhi === 1) phi = halfPi$1 + epsilon$1;
  9193. else if (sinPhi === -1) phi = -halfPi$1 - epsilon$1;
  9194. for (var i = 0, n = polygon.length; i < n; ++i) {
  9195. if (!(m = (ring = polygon[i]).length)) continue;
  9196. var ring,
  9197. m,
  9198. point0 = ring[m - 1],
  9199. lambda0 = longitude(point0),
  9200. phi0 = point0[1] / 2 + quarterPi,
  9201. sinPhi0 = sin$1(phi0),
  9202. cosPhi0 = cos$1(phi0);
  9203. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  9204. var point1 = ring[j],
  9205. lambda1 = longitude(point1),
  9206. phi1 = point1[1] / 2 + quarterPi,
  9207. sinPhi1 = sin$1(phi1),
  9208. cosPhi1 = cos$1(phi1),
  9209. delta = lambda1 - lambda0,
  9210. sign = delta >= 0 ? 1 : -1,
  9211. absDelta = sign * delta,
  9212. antimeridian = absDelta > pi$1,
  9213. k = sinPhi0 * sinPhi1;
  9214. sum.add(atan2$1(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  9215. angle += antimeridian ? delta + sign * tau$1 : delta;
  9216. // Are the longitudes either side of the point’s meridian (lambda),
  9217. // and are the latitudes smaller than the parallel (phi)?
  9218. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  9219. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  9220. cartesianNormalizeInPlace(arc);
  9221. var intersection = cartesianCross(normal, arc);
  9222. cartesianNormalizeInPlace(intersection);
  9223. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
  9224. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  9225. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  9226. }
  9227. }
  9228. }
  9229. }
  9230. // First, determine whether the South pole is inside or outside:
  9231. //
  9232. // It is inside if:
  9233. // * the polygon winds around it in a clockwise direction.
  9234. // * the polygon does not (cumulatively) wind around it, but has a negative
  9235. // (counter-clockwise) area.
  9236. //
  9237. // Second, count the (signed) number of times a segment crosses a lambda
  9238. // from the point to the South pole. If it is zero, then the point is the
  9239. // same side as the South pole.
  9240. return (angle < -epsilon$1 || angle < epsilon$1 && sum < -epsilon2) ^ (winding & 1);
  9241. }
  9242. function clip(pointVisible, clipLine, interpolate, start) {
  9243. return function(sink) {
  9244. var line = clipLine(sink),
  9245. ringBuffer = clipBuffer(),
  9246. ringSink = clipLine(ringBuffer),
  9247. polygonStarted = false,
  9248. polygon,
  9249. segments,
  9250. ring;
  9251. var clip = {
  9252. point: point,
  9253. lineStart: lineStart,
  9254. lineEnd: lineEnd,
  9255. polygonStart: function() {
  9256. clip.point = pointRing;
  9257. clip.lineStart = ringStart;
  9258. clip.lineEnd = ringEnd;
  9259. segments = [];
  9260. polygon = [];
  9261. },
  9262. polygonEnd: function() {
  9263. clip.point = point;
  9264. clip.lineStart = lineStart;
  9265. clip.lineEnd = lineEnd;
  9266. segments = merge(segments);
  9267. var startInside = polygonContains(polygon, start);
  9268. if (segments.length) {
  9269. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  9270. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  9271. } else if (startInside) {
  9272. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  9273. sink.lineStart();
  9274. interpolate(null, null, 1, sink);
  9275. sink.lineEnd();
  9276. }
  9277. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  9278. segments = polygon = null;
  9279. },
  9280. sphere: function() {
  9281. sink.polygonStart();
  9282. sink.lineStart();
  9283. interpolate(null, null, 1, sink);
  9284. sink.lineEnd();
  9285. sink.polygonEnd();
  9286. }
  9287. };
  9288. function point(lambda, phi) {
  9289. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  9290. }
  9291. function pointLine(lambda, phi) {
  9292. line.point(lambda, phi);
  9293. }
  9294. function lineStart() {
  9295. clip.point = pointLine;
  9296. line.lineStart();
  9297. }
  9298. function lineEnd() {
  9299. clip.point = point;
  9300. line.lineEnd();
  9301. }
  9302. function pointRing(lambda, phi) {
  9303. ring.push([lambda, phi]);
  9304. ringSink.point(lambda, phi);
  9305. }
  9306. function ringStart() {
  9307. ringSink.lineStart();
  9308. ring = [];
  9309. }
  9310. function ringEnd() {
  9311. pointRing(ring[0][0], ring[0][1]);
  9312. ringSink.lineEnd();
  9313. var clean = ringSink.clean(),
  9314. ringSegments = ringBuffer.result(),
  9315. i, n = ringSegments.length, m,
  9316. segment,
  9317. point;
  9318. ring.pop();
  9319. polygon.push(ring);
  9320. ring = null;
  9321. if (!n) return;
  9322. // No intersections.
  9323. if (clean & 1) {
  9324. segment = ringSegments[0];
  9325. if ((m = segment.length - 1) > 0) {
  9326. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  9327. sink.lineStart();
  9328. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  9329. sink.lineEnd();
  9330. }
  9331. return;
  9332. }
  9333. // Rejoin connected segments.
  9334. // TODO reuse ringBuffer.rejoin()?
  9335. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  9336. segments.push(ringSegments.filter(validSegment));
  9337. }
  9338. return clip;
  9339. };
  9340. }
  9341. function validSegment(segment) {
  9342. return segment.length > 1;
  9343. }
  9344. // Intersections are sorted along the clip edge. For both antimeridian cutting
  9345. // and circle clipping, the same comparison is used.
  9346. function compareIntersection(a, b) {
  9347. return ((a = a.x)[0] < 0 ? a[1] - halfPi$1 - epsilon$1 : halfPi$1 - a[1])
  9348. - ((b = b.x)[0] < 0 ? b[1] - halfPi$1 - epsilon$1 : halfPi$1 - b[1]);
  9349. }
  9350. var clipAntimeridian = clip(
  9351. function() { return true; },
  9352. clipAntimeridianLine,
  9353. clipAntimeridianInterpolate,
  9354. [-pi$1, -halfPi$1]
  9355. );
  9356. // Takes a line and cuts into visible segments. Return values: 0 - there were
  9357. // intersections or the line was empty; 1 - no intersections; 2 - there were
  9358. // intersections, and the first and last segments should be rejoined.
  9359. function clipAntimeridianLine(stream) {
  9360. var lambda0 = NaN,
  9361. phi0 = NaN,
  9362. sign0 = NaN,
  9363. clean; // no intersections
  9364. return {
  9365. lineStart: function() {
  9366. stream.lineStart();
  9367. clean = 1;
  9368. },
  9369. point: function(lambda1, phi1) {
  9370. var sign1 = lambda1 > 0 ? pi$1 : -pi$1,
  9371. delta = abs$1(lambda1 - lambda0);
  9372. if (abs$1(delta - pi$1) < epsilon$1) { // line crosses a pole
  9373. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$1 : -halfPi$1);
  9374. stream.point(sign0, phi0);
  9375. stream.lineEnd();
  9376. stream.lineStart();
  9377. stream.point(sign1, phi0);
  9378. stream.point(lambda1, phi0);
  9379. clean = 0;
  9380. } else if (sign0 !== sign1 && delta >= pi$1) { // line crosses antimeridian
  9381. if (abs$1(lambda0 - sign0) < epsilon$1) lambda0 -= sign0 * epsilon$1; // handle degeneracies
  9382. if (abs$1(lambda1 - sign1) < epsilon$1) lambda1 -= sign1 * epsilon$1;
  9383. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  9384. stream.point(sign0, phi0);
  9385. stream.lineEnd();
  9386. stream.lineStart();
  9387. stream.point(sign1, phi0);
  9388. clean = 0;
  9389. }
  9390. stream.point(lambda0 = lambda1, phi0 = phi1);
  9391. sign0 = sign1;
  9392. },
  9393. lineEnd: function() {
  9394. stream.lineEnd();
  9395. lambda0 = phi0 = NaN;
  9396. },
  9397. clean: function() {
  9398. return 2 - clean; // if intersections, rejoin first and last segments
  9399. }
  9400. };
  9401. }
  9402. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  9403. var cosPhi0,
  9404. cosPhi1,
  9405. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  9406. return abs$1(sinLambda0Lambda1) > epsilon$1
  9407. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  9408. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  9409. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  9410. : (phi0 + phi1) / 2;
  9411. }
  9412. function clipAntimeridianInterpolate(from, to, direction, stream) {
  9413. var phi;
  9414. if (from == null) {
  9415. phi = direction * halfPi$1;
  9416. stream.point(-pi$1, phi);
  9417. stream.point(0, phi);
  9418. stream.point(pi$1, phi);
  9419. stream.point(pi$1, 0);
  9420. stream.point(pi$1, -phi);
  9421. stream.point(0, -phi);
  9422. stream.point(-pi$1, -phi);
  9423. stream.point(-pi$1, 0);
  9424. stream.point(-pi$1, phi);
  9425. } else if (abs$1(from[0] - to[0]) > epsilon$1) {
  9426. var lambda = from[0] < to[0] ? pi$1 : -pi$1;
  9427. phi = direction * lambda / 2;
  9428. stream.point(-lambda, phi);
  9429. stream.point(0, phi);
  9430. stream.point(lambda, phi);
  9431. } else {
  9432. stream.point(to[0], to[1]);
  9433. }
  9434. }
  9435. function clipCircle(radius) {
  9436. var cr = cos$1(radius),
  9437. delta = 2 * radians,
  9438. smallRadius = cr > 0,
  9439. notHemisphere = abs$1(cr) > epsilon$1; // TODO optimise for this common case
  9440. function interpolate(from, to, direction, stream) {
  9441. circleStream(stream, radius, delta, direction, from, to);
  9442. }
  9443. function visible(lambda, phi) {
  9444. return cos$1(lambda) * cos$1(phi) > cr;
  9445. }
  9446. // Takes a line and cuts into visible segments. Return values used for polygon
  9447. // clipping: 0 - there were intersections or the line was empty; 1 - no
  9448. // intersections 2 - there were intersections, and the first and last segments
  9449. // should be rejoined.
  9450. function clipLine(stream) {
  9451. var point0, // previous point
  9452. c0, // code for previous point
  9453. v0, // visibility of previous point
  9454. v00, // visibility of first point
  9455. clean; // no intersections
  9456. return {
  9457. lineStart: function() {
  9458. v00 = v0 = false;
  9459. clean = 1;
  9460. },
  9461. point: function(lambda, phi) {
  9462. var point1 = [lambda, phi],
  9463. point2,
  9464. v = visible(lambda, phi),
  9465. c = smallRadius
  9466. ? v ? 0 : code(lambda, phi)
  9467. : v ? code(lambda + (lambda < 0 ? pi$1 : -pi$1), phi) : 0;
  9468. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  9469. if (v !== v0) {
  9470. point2 = intersect(point0, point1);
  9471. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2))
  9472. point1[2] = 1;
  9473. }
  9474. if (v !== v0) {
  9475. clean = 0;
  9476. if (v) {
  9477. // outside going in
  9478. stream.lineStart();
  9479. point2 = intersect(point1, point0);
  9480. stream.point(point2[0], point2[1]);
  9481. } else {
  9482. // inside going out
  9483. point2 = intersect(point0, point1);
  9484. stream.point(point2[0], point2[1], 2);
  9485. stream.lineEnd();
  9486. }
  9487. point0 = point2;
  9488. } else if (notHemisphere && point0 && smallRadius ^ v) {
  9489. var t;
  9490. // If the codes for two points are different, or are both zero,
  9491. // and there this segment intersects with the small circle.
  9492. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  9493. clean = 0;
  9494. if (smallRadius) {
  9495. stream.lineStart();
  9496. stream.point(t[0][0], t[0][1]);
  9497. stream.point(t[1][0], t[1][1]);
  9498. stream.lineEnd();
  9499. } else {
  9500. stream.point(t[1][0], t[1][1]);
  9501. stream.lineEnd();
  9502. stream.lineStart();
  9503. stream.point(t[0][0], t[0][1], 3);
  9504. }
  9505. }
  9506. }
  9507. if (v && (!point0 || !pointEqual(point0, point1))) {
  9508. stream.point(point1[0], point1[1]);
  9509. }
  9510. point0 = point1, v0 = v, c0 = c;
  9511. },
  9512. lineEnd: function() {
  9513. if (v0) stream.lineEnd();
  9514. point0 = null;
  9515. },
  9516. // Rejoin first and last segments if there were intersections and the first
  9517. // and last points were visible.
  9518. clean: function() {
  9519. return clean | ((v00 && v0) << 1);
  9520. }
  9521. };
  9522. }
  9523. // Intersects the great circle between a and b with the clip circle.
  9524. function intersect(a, b, two) {
  9525. var pa = cartesian(a),
  9526. pb = cartesian(b);
  9527. // We have two planes, n1.p = d1 and n2.p = d2.
  9528. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  9529. var n1 = [1, 0, 0], // normal
  9530. n2 = cartesianCross(pa, pb),
  9531. n2n2 = cartesianDot(n2, n2),
  9532. n1n2 = n2[0], // cartesianDot(n1, n2),
  9533. determinant = n2n2 - n1n2 * n1n2;
  9534. // Two polar points.
  9535. if (!determinant) return !two && a;
  9536. var c1 = cr * n2n2 / determinant,
  9537. c2 = -cr * n1n2 / determinant,
  9538. n1xn2 = cartesianCross(n1, n2),
  9539. A = cartesianScale(n1, c1),
  9540. B = cartesianScale(n2, c2);
  9541. cartesianAddInPlace(A, B);
  9542. // Solve |p(t)|^2 = 1.
  9543. var u = n1xn2,
  9544. w = cartesianDot(A, u),
  9545. uu = cartesianDot(u, u),
  9546. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  9547. if (t2 < 0) return;
  9548. var t = sqrt$2(t2),
  9549. q = cartesianScale(u, (-w - t) / uu);
  9550. cartesianAddInPlace(q, A);
  9551. q = spherical(q);
  9552. if (!two) return q;
  9553. // Two intersection points.
  9554. var lambda0 = a[0],
  9555. lambda1 = b[0],
  9556. phi0 = a[1],
  9557. phi1 = b[1],
  9558. z;
  9559. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  9560. var delta = lambda1 - lambda0,
  9561. polar = abs$1(delta - pi$1) < epsilon$1,
  9562. meridian = polar || delta < epsilon$1;
  9563. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  9564. // Check that the first point is between a and b.
  9565. if (meridian
  9566. ? polar
  9567. ? phi0 + phi1 > 0 ^ q[1] < (abs$1(q[0] - lambda0) < epsilon$1 ? phi0 : phi1)
  9568. : phi0 <= q[1] && q[1] <= phi1
  9569. : delta > pi$1 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  9570. var q1 = cartesianScale(u, (-w + t) / uu);
  9571. cartesianAddInPlace(q1, A);
  9572. return [q, spherical(q1)];
  9573. }
  9574. }
  9575. // Generates a 4-bit vector representing the location of a point relative to
  9576. // the small circle's bounding box.
  9577. function code(lambda, phi) {
  9578. var r = smallRadius ? radius : pi$1 - radius,
  9579. code = 0;
  9580. if (lambda < -r) code |= 1; // left
  9581. else if (lambda > r) code |= 2; // right
  9582. if (phi < -r) code |= 4; // below
  9583. else if (phi > r) code |= 8; // above
  9584. return code;
  9585. }
  9586. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$1, radius - pi$1]);
  9587. }
  9588. function clipLine(a, b, x0, y0, x1, y1) {
  9589. var ax = a[0],
  9590. ay = a[1],
  9591. bx = b[0],
  9592. by = b[1],
  9593. t0 = 0,
  9594. t1 = 1,
  9595. dx = bx - ax,
  9596. dy = by - ay,
  9597. r;
  9598. r = x0 - ax;
  9599. if (!dx && r > 0) return;
  9600. r /= dx;
  9601. if (dx < 0) {
  9602. if (r < t0) return;
  9603. if (r < t1) t1 = r;
  9604. } else if (dx > 0) {
  9605. if (r > t1) return;
  9606. if (r > t0) t0 = r;
  9607. }
  9608. r = x1 - ax;
  9609. if (!dx && r < 0) return;
  9610. r /= dx;
  9611. if (dx < 0) {
  9612. if (r > t1) return;
  9613. if (r > t0) t0 = r;
  9614. } else if (dx > 0) {
  9615. if (r < t0) return;
  9616. if (r < t1) t1 = r;
  9617. }
  9618. r = y0 - ay;
  9619. if (!dy && r > 0) return;
  9620. r /= dy;
  9621. if (dy < 0) {
  9622. if (r < t0) return;
  9623. if (r < t1) t1 = r;
  9624. } else if (dy > 0) {
  9625. if (r > t1) return;
  9626. if (r > t0) t0 = r;
  9627. }
  9628. r = y1 - ay;
  9629. if (!dy && r < 0) return;
  9630. r /= dy;
  9631. if (dy < 0) {
  9632. if (r > t1) return;
  9633. if (r > t0) t0 = r;
  9634. } else if (dy > 0) {
  9635. if (r < t0) return;
  9636. if (r < t1) t1 = r;
  9637. }
  9638. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  9639. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  9640. return true;
  9641. }
  9642. var clipMax = 1e9, clipMin = -clipMax;
  9643. // TODO Use d3-polygon’s polygonContains here for the ring check?
  9644. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  9645. function clipRectangle(x0, y0, x1, y1) {
  9646. function visible(x, y) {
  9647. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  9648. }
  9649. function interpolate(from, to, direction, stream) {
  9650. var a = 0, a1 = 0;
  9651. if (from == null
  9652. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  9653. || comparePoint(from, to) < 0 ^ direction > 0) {
  9654. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  9655. while ((a = (a + direction + 4) % 4) !== a1);
  9656. } else {
  9657. stream.point(to[0], to[1]);
  9658. }
  9659. }
  9660. function corner(p, direction) {
  9661. return abs$1(p[0] - x0) < epsilon$1 ? direction > 0 ? 0 : 3
  9662. : abs$1(p[0] - x1) < epsilon$1 ? direction > 0 ? 2 : 1
  9663. : abs$1(p[1] - y0) < epsilon$1 ? direction > 0 ? 1 : 0
  9664. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  9665. }
  9666. function compareIntersection(a, b) {
  9667. return comparePoint(a.x, b.x);
  9668. }
  9669. function comparePoint(a, b) {
  9670. var ca = corner(a, 1),
  9671. cb = corner(b, 1);
  9672. return ca !== cb ? ca - cb
  9673. : ca === 0 ? b[1] - a[1]
  9674. : ca === 1 ? a[0] - b[0]
  9675. : ca === 2 ? a[1] - b[1]
  9676. : b[0] - a[0];
  9677. }
  9678. return function(stream) {
  9679. var activeStream = stream,
  9680. bufferStream = clipBuffer(),
  9681. segments,
  9682. polygon,
  9683. ring,
  9684. x__, y__, v__, // first point
  9685. x_, y_, v_, // previous point
  9686. first,
  9687. clean;
  9688. var clipStream = {
  9689. point: point,
  9690. lineStart: lineStart,
  9691. lineEnd: lineEnd,
  9692. polygonStart: polygonStart,
  9693. polygonEnd: polygonEnd
  9694. };
  9695. function point(x, y) {
  9696. if (visible(x, y)) activeStream.point(x, y);
  9697. }
  9698. function polygonInside() {
  9699. var winding = 0;
  9700. for (var i = 0, n = polygon.length; i < n; ++i) {
  9701. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  9702. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  9703. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  9704. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  9705. }
  9706. }
  9707. return winding;
  9708. }
  9709. // Buffer geometry within a polygon and then clip it en masse.
  9710. function polygonStart() {
  9711. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  9712. }
  9713. function polygonEnd() {
  9714. var startInside = polygonInside(),
  9715. cleanInside = clean && startInside,
  9716. visible = (segments = merge(segments)).length;
  9717. if (cleanInside || visible) {
  9718. stream.polygonStart();
  9719. if (cleanInside) {
  9720. stream.lineStart();
  9721. interpolate(null, null, 1, stream);
  9722. stream.lineEnd();
  9723. }
  9724. if (visible) {
  9725. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  9726. }
  9727. stream.polygonEnd();
  9728. }
  9729. activeStream = stream, segments = polygon = ring = null;
  9730. }
  9731. function lineStart() {
  9732. clipStream.point = linePoint;
  9733. if (polygon) polygon.push(ring = []);
  9734. first = true;
  9735. v_ = false;
  9736. x_ = y_ = NaN;
  9737. }
  9738. // TODO rather than special-case polygons, simply handle them separately.
  9739. // Ideally, coincident intersection points should be jittered to avoid
  9740. // clipping issues.
  9741. function lineEnd() {
  9742. if (segments) {
  9743. linePoint(x__, y__);
  9744. if (v__ && v_) bufferStream.rejoin();
  9745. segments.push(bufferStream.result());
  9746. }
  9747. clipStream.point = point;
  9748. if (v_) activeStream.lineEnd();
  9749. }
  9750. function linePoint(x, y) {
  9751. var v = visible(x, y);
  9752. if (polygon) ring.push([x, y]);
  9753. if (first) {
  9754. x__ = x, y__ = y, v__ = v;
  9755. first = false;
  9756. if (v) {
  9757. activeStream.lineStart();
  9758. activeStream.point(x, y);
  9759. }
  9760. } else {
  9761. if (v && v_) activeStream.point(x, y);
  9762. else {
  9763. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  9764. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  9765. if (clipLine(a, b, x0, y0, x1, y1)) {
  9766. if (!v_) {
  9767. activeStream.lineStart();
  9768. activeStream.point(a[0], a[1]);
  9769. }
  9770. activeStream.point(b[0], b[1]);
  9771. if (!v) activeStream.lineEnd();
  9772. clean = false;
  9773. } else if (v) {
  9774. activeStream.lineStart();
  9775. activeStream.point(x, y);
  9776. clean = false;
  9777. }
  9778. }
  9779. }
  9780. x_ = x, y_ = y, v_ = v;
  9781. }
  9782. return clipStream;
  9783. };
  9784. }
  9785. function extent() {
  9786. var x0 = 0,
  9787. y0 = 0,
  9788. x1 = 960,
  9789. y1 = 500,
  9790. cache,
  9791. cacheStream,
  9792. clip;
  9793. return clip = {
  9794. stream: function(stream) {
  9795. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  9796. },
  9797. extent: function(_) {
  9798. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  9799. }
  9800. };
  9801. }
  9802. var lengthSum$1,
  9803. lambda0,
  9804. sinPhi0,
  9805. cosPhi0;
  9806. var lengthStream$1 = {
  9807. sphere: noop$1,
  9808. point: noop$1,
  9809. lineStart: lengthLineStart,
  9810. lineEnd: noop$1,
  9811. polygonStart: noop$1,
  9812. polygonEnd: noop$1
  9813. };
  9814. function lengthLineStart() {
  9815. lengthStream$1.point = lengthPointFirst$1;
  9816. lengthStream$1.lineEnd = lengthLineEnd;
  9817. }
  9818. function lengthLineEnd() {
  9819. lengthStream$1.point = lengthStream$1.lineEnd = noop$1;
  9820. }
  9821. function lengthPointFirst$1(lambda, phi) {
  9822. lambda *= radians, phi *= radians;
  9823. lambda0 = lambda, sinPhi0 = sin$1(phi), cosPhi0 = cos$1(phi);
  9824. lengthStream$1.point = lengthPoint$1;
  9825. }
  9826. function lengthPoint$1(lambda, phi) {
  9827. lambda *= radians, phi *= radians;
  9828. var sinPhi = sin$1(phi),
  9829. cosPhi = cos$1(phi),
  9830. delta = abs$1(lambda - lambda0),
  9831. cosDelta = cos$1(delta),
  9832. sinDelta = sin$1(delta),
  9833. x = cosPhi * sinDelta,
  9834. y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta,
  9835. z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta;
  9836. lengthSum$1.add(atan2$1(sqrt$2(x * x + y * y), z));
  9837. lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi;
  9838. }
  9839. function length$1(object) {
  9840. lengthSum$1 = new Adder();
  9841. geoStream(object, lengthStream$1);
  9842. return +lengthSum$1;
  9843. }
  9844. var coordinates = [null, null],
  9845. object = {type: "LineString", coordinates: coordinates};
  9846. function distance(a, b) {
  9847. coordinates[0] = a;
  9848. coordinates[1] = b;
  9849. return length$1(object);
  9850. }
  9851. var containsObjectType = {
  9852. Feature: function(object, point) {
  9853. return containsGeometry(object.geometry, point);
  9854. },
  9855. FeatureCollection: function(object, point) {
  9856. var features = object.features, i = -1, n = features.length;
  9857. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  9858. return false;
  9859. }
  9860. };
  9861. var containsGeometryType = {
  9862. Sphere: function() {
  9863. return true;
  9864. },
  9865. Point: function(object, point) {
  9866. return containsPoint(object.coordinates, point);
  9867. },
  9868. MultiPoint: function(object, point) {
  9869. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9870. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  9871. return false;
  9872. },
  9873. LineString: function(object, point) {
  9874. return containsLine(object.coordinates, point);
  9875. },
  9876. MultiLineString: function(object, point) {
  9877. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9878. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  9879. return false;
  9880. },
  9881. Polygon: function(object, point) {
  9882. return containsPolygon(object.coordinates, point);
  9883. },
  9884. MultiPolygon: function(object, point) {
  9885. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  9886. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  9887. return false;
  9888. },
  9889. GeometryCollection: function(object, point) {
  9890. var geometries = object.geometries, i = -1, n = geometries.length;
  9891. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  9892. return false;
  9893. }
  9894. };
  9895. function containsGeometry(geometry, point) {
  9896. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  9897. ? containsGeometryType[geometry.type](geometry, point)
  9898. : false;
  9899. }
  9900. function containsPoint(coordinates, point) {
  9901. return distance(coordinates, point) === 0;
  9902. }
  9903. function containsLine(coordinates, point) {
  9904. var ao, bo, ab;
  9905. for (var i = 0, n = coordinates.length; i < n; i++) {
  9906. bo = distance(coordinates[i], point);
  9907. if (bo === 0) return true;
  9908. if (i > 0) {
  9909. ab = distance(coordinates[i], coordinates[i - 1]);
  9910. if (
  9911. ab > 0 &&
  9912. ao <= ab &&
  9913. bo <= ab &&
  9914. (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2 * ab
  9915. )
  9916. return true;
  9917. }
  9918. ao = bo;
  9919. }
  9920. return false;
  9921. }
  9922. function containsPolygon(coordinates, point) {
  9923. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  9924. }
  9925. function ringRadians(ring) {
  9926. return ring = ring.map(pointRadians), ring.pop(), ring;
  9927. }
  9928. function pointRadians(point) {
  9929. return [point[0] * radians, point[1] * radians];
  9930. }
  9931. function contains$1(object, point) {
  9932. return (object && containsObjectType.hasOwnProperty(object.type)
  9933. ? containsObjectType[object.type]
  9934. : containsGeometry)(object, point);
  9935. }
  9936. function graticuleX(y0, y1, dy) {
  9937. var y = range$2(y0, y1 - epsilon$1, dy).concat(y1);
  9938. return function(x) { return y.map(function(y) { return [x, y]; }); };
  9939. }
  9940. function graticuleY(x0, x1, dx) {
  9941. var x = range$2(x0, x1 - epsilon$1, dx).concat(x1);
  9942. return function(y) { return x.map(function(x) { return [x, y]; }); };
  9943. }
  9944. function graticule() {
  9945. var x1, x0, X1, X0,
  9946. y1, y0, Y1, Y0,
  9947. dx = 10, dy = dx, DX = 90, DY = 360,
  9948. x, y, X, Y,
  9949. precision = 2.5;
  9950. function graticule() {
  9951. return {type: "MultiLineString", coordinates: lines()};
  9952. }
  9953. function lines() {
  9954. return range$2(ceil(X0 / DX) * DX, X1, DX).map(X)
  9955. .concat(range$2(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  9956. .concat(range$2(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs$1(x % DX) > epsilon$1; }).map(x))
  9957. .concat(range$2(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs$1(y % DY) > epsilon$1; }).map(y));
  9958. }
  9959. graticule.lines = function() {
  9960. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  9961. };
  9962. graticule.outline = function() {
  9963. return {
  9964. type: "Polygon",
  9965. coordinates: [
  9966. X(X0).concat(
  9967. Y(Y1).slice(1),
  9968. X(X1).reverse().slice(1),
  9969. Y(Y0).reverse().slice(1))
  9970. ]
  9971. };
  9972. };
  9973. graticule.extent = function(_) {
  9974. if (!arguments.length) return graticule.extentMinor();
  9975. return graticule.extentMajor(_).extentMinor(_);
  9976. };
  9977. graticule.extentMajor = function(_) {
  9978. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  9979. X0 = +_[0][0], X1 = +_[1][0];
  9980. Y0 = +_[0][1], Y1 = +_[1][1];
  9981. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  9982. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  9983. return graticule.precision(precision);
  9984. };
  9985. graticule.extentMinor = function(_) {
  9986. if (!arguments.length) return [[x0, y0], [x1, y1]];
  9987. x0 = +_[0][0], x1 = +_[1][0];
  9988. y0 = +_[0][1], y1 = +_[1][1];
  9989. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  9990. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  9991. return graticule.precision(precision);
  9992. };
  9993. graticule.step = function(_) {
  9994. if (!arguments.length) return graticule.stepMinor();
  9995. return graticule.stepMajor(_).stepMinor(_);
  9996. };
  9997. graticule.stepMajor = function(_) {
  9998. if (!arguments.length) return [DX, DY];
  9999. DX = +_[0], DY = +_[1];
  10000. return graticule;
  10001. };
  10002. graticule.stepMinor = function(_) {
  10003. if (!arguments.length) return [dx, dy];
  10004. dx = +_[0], dy = +_[1];
  10005. return graticule;
  10006. };
  10007. graticule.precision = function(_) {
  10008. if (!arguments.length) return precision;
  10009. precision = +_;
  10010. x = graticuleX(y0, y1, 90);
  10011. y = graticuleY(x0, x1, precision);
  10012. X = graticuleX(Y0, Y1, 90);
  10013. Y = graticuleY(X0, X1, precision);
  10014. return graticule;
  10015. };
  10016. return graticule
  10017. .extentMajor([[-180, -90 + epsilon$1], [180, 90 - epsilon$1]])
  10018. .extentMinor([[-180, -80 - epsilon$1], [180, 80 + epsilon$1]]);
  10019. }
  10020. function graticule10() {
  10021. return graticule()();
  10022. }
  10023. function interpolate(a, b) {
  10024. var x0 = a[0] * radians,
  10025. y0 = a[1] * radians,
  10026. x1 = b[0] * radians,
  10027. y1 = b[1] * radians,
  10028. cy0 = cos$1(y0),
  10029. sy0 = sin$1(y0),
  10030. cy1 = cos$1(y1),
  10031. sy1 = sin$1(y1),
  10032. kx0 = cy0 * cos$1(x0),
  10033. ky0 = cy0 * sin$1(x0),
  10034. kx1 = cy1 * cos$1(x1),
  10035. ky1 = cy1 * sin$1(x1),
  10036. d = 2 * asin$1(sqrt$2(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  10037. k = sin$1(d);
  10038. var interpolate = d ? function(t) {
  10039. var B = sin$1(t *= d) / k,
  10040. A = sin$1(d - t) / k,
  10041. x = A * kx0 + B * kx1,
  10042. y = A * ky0 + B * ky1,
  10043. z = A * sy0 + B * sy1;
  10044. return [
  10045. atan2$1(y, x) * degrees,
  10046. atan2$1(z, sqrt$2(x * x + y * y)) * degrees
  10047. ];
  10048. } : function() {
  10049. return [x0 * degrees, y0 * degrees];
  10050. };
  10051. interpolate.distance = d;
  10052. return interpolate;
  10053. }
  10054. var identity$5 = x => x;
  10055. var areaSum = new Adder(),
  10056. areaRingSum = new Adder(),
  10057. x00$2,
  10058. y00$2,
  10059. x0$3,
  10060. y0$3;
  10061. var areaStream = {
  10062. point: noop$1,
  10063. lineStart: noop$1,
  10064. lineEnd: noop$1,
  10065. polygonStart: function() {
  10066. areaStream.lineStart = areaRingStart;
  10067. areaStream.lineEnd = areaRingEnd;
  10068. },
  10069. polygonEnd: function() {
  10070. areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop$1;
  10071. areaSum.add(abs$1(areaRingSum));
  10072. areaRingSum = new Adder();
  10073. },
  10074. result: function() {
  10075. var area = areaSum / 2;
  10076. areaSum = new Adder();
  10077. return area;
  10078. }
  10079. };
  10080. function areaRingStart() {
  10081. areaStream.point = areaPointFirst;
  10082. }
  10083. function areaPointFirst(x, y) {
  10084. areaStream.point = areaPoint;
  10085. x00$2 = x0$3 = x, y00$2 = y0$3 = y;
  10086. }
  10087. function areaPoint(x, y) {
  10088. areaRingSum.add(y0$3 * x - x0$3 * y);
  10089. x0$3 = x, y0$3 = y;
  10090. }
  10091. function areaRingEnd() {
  10092. areaPoint(x00$2, y00$2);
  10093. }
  10094. var pathArea = areaStream;
  10095. var x0$2 = Infinity,
  10096. y0$2 = x0$2,
  10097. x1 = -x0$2,
  10098. y1 = x1;
  10099. var boundsStream = {
  10100. point: boundsPoint,
  10101. lineStart: noop$1,
  10102. lineEnd: noop$1,
  10103. polygonStart: noop$1,
  10104. polygonEnd: noop$1,
  10105. result: function() {
  10106. var bounds = [[x0$2, y0$2], [x1, y1]];
  10107. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  10108. return bounds;
  10109. }
  10110. };
  10111. function boundsPoint(x, y) {
  10112. if (x < x0$2) x0$2 = x;
  10113. if (x > x1) x1 = x;
  10114. if (y < y0$2) y0$2 = y;
  10115. if (y > y1) y1 = y;
  10116. }
  10117. var boundsStream$1 = boundsStream;
  10118. // TODO Enforce positive area for exterior, negative area for interior?
  10119. var X0 = 0,
  10120. Y0 = 0,
  10121. Z0 = 0,
  10122. X1 = 0,
  10123. Y1 = 0,
  10124. Z1 = 0,
  10125. X2 = 0,
  10126. Y2 = 0,
  10127. Z2 = 0,
  10128. x00$1,
  10129. y00$1,
  10130. x0$1,
  10131. y0$1;
  10132. var centroidStream = {
  10133. point: centroidPoint,
  10134. lineStart: centroidLineStart,
  10135. lineEnd: centroidLineEnd,
  10136. polygonStart: function() {
  10137. centroidStream.lineStart = centroidRingStart;
  10138. centroidStream.lineEnd = centroidRingEnd;
  10139. },
  10140. polygonEnd: function() {
  10141. centroidStream.point = centroidPoint;
  10142. centroidStream.lineStart = centroidLineStart;
  10143. centroidStream.lineEnd = centroidLineEnd;
  10144. },
  10145. result: function() {
  10146. var centroid = Z2 ? [X2 / Z2, Y2 / Z2]
  10147. : Z1 ? [X1 / Z1, Y1 / Z1]
  10148. : Z0 ? [X0 / Z0, Y0 / Z0]
  10149. : [NaN, NaN];
  10150. X0 = Y0 = Z0 =
  10151. X1 = Y1 = Z1 =
  10152. X2 = Y2 = Z2 = 0;
  10153. return centroid;
  10154. }
  10155. };
  10156. function centroidPoint(x, y) {
  10157. X0 += x;
  10158. Y0 += y;
  10159. ++Z0;
  10160. }
  10161. function centroidLineStart() {
  10162. centroidStream.point = centroidPointFirstLine;
  10163. }
  10164. function centroidPointFirstLine(x, y) {
  10165. centroidStream.point = centroidPointLine;
  10166. centroidPoint(x0$1 = x, y0$1 = y);
  10167. }
  10168. function centroidPointLine(x, y) {
  10169. var dx = x - x0$1, dy = y - y0$1, z = sqrt$2(dx * dx + dy * dy);
  10170. X1 += z * (x0$1 + x) / 2;
  10171. Y1 += z * (y0$1 + y) / 2;
  10172. Z1 += z;
  10173. centroidPoint(x0$1 = x, y0$1 = y);
  10174. }
  10175. function centroidLineEnd() {
  10176. centroidStream.point = centroidPoint;
  10177. }
  10178. function centroidRingStart() {
  10179. centroidStream.point = centroidPointFirstRing;
  10180. }
  10181. function centroidRingEnd() {
  10182. centroidPointRing(x00$1, y00$1);
  10183. }
  10184. function centroidPointFirstRing(x, y) {
  10185. centroidStream.point = centroidPointRing;
  10186. centroidPoint(x00$1 = x0$1 = x, y00$1 = y0$1 = y);
  10187. }
  10188. function centroidPointRing(x, y) {
  10189. var dx = x - x0$1,
  10190. dy = y - y0$1,
  10191. z = sqrt$2(dx * dx + dy * dy);
  10192. X1 += z * (x0$1 + x) / 2;
  10193. Y1 += z * (y0$1 + y) / 2;
  10194. Z1 += z;
  10195. z = y0$1 * x - x0$1 * y;
  10196. X2 += z * (x0$1 + x);
  10197. Y2 += z * (y0$1 + y);
  10198. Z2 += z * 3;
  10199. centroidPoint(x0$1 = x, y0$1 = y);
  10200. }
  10201. var pathCentroid = centroidStream;
  10202. function PathContext(context) {
  10203. this._context = context;
  10204. }
  10205. PathContext.prototype = {
  10206. _radius: 4.5,
  10207. pointRadius: function(_) {
  10208. return this._radius = _, this;
  10209. },
  10210. polygonStart: function() {
  10211. this._line = 0;
  10212. },
  10213. polygonEnd: function() {
  10214. this._line = NaN;
  10215. },
  10216. lineStart: function() {
  10217. this._point = 0;
  10218. },
  10219. lineEnd: function() {
  10220. if (this._line === 0) this._context.closePath();
  10221. this._point = NaN;
  10222. },
  10223. point: function(x, y) {
  10224. switch (this._point) {
  10225. case 0: {
  10226. this._context.moveTo(x, y);
  10227. this._point = 1;
  10228. break;
  10229. }
  10230. case 1: {
  10231. this._context.lineTo(x, y);
  10232. break;
  10233. }
  10234. default: {
  10235. this._context.moveTo(x + this._radius, y);
  10236. this._context.arc(x, y, this._radius, 0, tau$1);
  10237. break;
  10238. }
  10239. }
  10240. },
  10241. result: noop$1
  10242. };
  10243. var lengthSum = new Adder(),
  10244. lengthRing,
  10245. x00,
  10246. y00,
  10247. x0,
  10248. y0;
  10249. var lengthStream = {
  10250. point: noop$1,
  10251. lineStart: function() {
  10252. lengthStream.point = lengthPointFirst;
  10253. },
  10254. lineEnd: function() {
  10255. if (lengthRing) lengthPoint(x00, y00);
  10256. lengthStream.point = noop$1;
  10257. },
  10258. polygonStart: function() {
  10259. lengthRing = true;
  10260. },
  10261. polygonEnd: function() {
  10262. lengthRing = null;
  10263. },
  10264. result: function() {
  10265. var length = +lengthSum;
  10266. lengthSum = new Adder();
  10267. return length;
  10268. }
  10269. };
  10270. function lengthPointFirst(x, y) {
  10271. lengthStream.point = lengthPoint;
  10272. x00 = x0 = x, y00 = y0 = y;
  10273. }
  10274. function lengthPoint(x, y) {
  10275. x0 -= x, y0 -= y;
  10276. lengthSum.add(sqrt$2(x0 * x0 + y0 * y0));
  10277. x0 = x, y0 = y;
  10278. }
  10279. var pathMeasure = lengthStream;
  10280. // Simple caching for constant-radius points.
  10281. let cacheDigits, cacheAppend, cacheRadius, cacheCircle;
  10282. class PathString {
  10283. constructor(digits) {
  10284. this._append = digits == null ? append : appendRound(digits);
  10285. this._radius = 4.5;
  10286. this._ = "";
  10287. }
  10288. pointRadius(_) {
  10289. this._radius = +_;
  10290. return this;
  10291. }
  10292. polygonStart() {
  10293. this._line = 0;
  10294. }
  10295. polygonEnd() {
  10296. this._line = NaN;
  10297. }
  10298. lineStart() {
  10299. this._point = 0;
  10300. }
  10301. lineEnd() {
  10302. if (this._line === 0) this._ += "Z";
  10303. this._point = NaN;
  10304. }
  10305. point(x, y) {
  10306. switch (this._point) {
  10307. case 0: {
  10308. this._append`M${x},${y}`;
  10309. this._point = 1;
  10310. break;
  10311. }
  10312. case 1: {
  10313. this._append`L${x},${y}`;
  10314. break;
  10315. }
  10316. default: {
  10317. this._append`M${x},${y}`;
  10318. if (this._radius !== cacheRadius || this._append !== cacheAppend) {
  10319. const r = this._radius;
  10320. const s = this._;
  10321. this._ = ""; // stash the old string so we can cache the circle path fragment
  10322. this._append`m0,${r}a${r},${r} 0 1,1 0,${-2 * r}a${r},${r} 0 1,1 0,${2 * r}z`;
  10323. cacheRadius = r;
  10324. cacheAppend = this._append;
  10325. cacheCircle = this._;
  10326. this._ = s;
  10327. }
  10328. this._ += cacheCircle;
  10329. break;
  10330. }
  10331. }
  10332. }
  10333. result() {
  10334. const result = this._;
  10335. this._ = "";
  10336. return result.length ? result : null;
  10337. }
  10338. }
  10339. function append(strings) {
  10340. let i = 1;
  10341. this._ += strings[0];
  10342. for (const j = strings.length; i < j; ++i) {
  10343. this._ += arguments[i] + strings[i];
  10344. }
  10345. }
  10346. function appendRound(digits) {
  10347. const d = Math.floor(digits);
  10348. if (!(d >= 0)) throw new RangeError(`invalid digits: ${digits}`);
  10349. if (d > 15) return append;
  10350. if (d !== cacheDigits) {
  10351. const k = 10 ** d;
  10352. cacheDigits = d;
  10353. cacheAppend = function append(strings) {
  10354. let i = 1;
  10355. this._ += strings[0];
  10356. for (const j = strings.length; i < j; ++i) {
  10357. this._ += Math.round(arguments[i] * k) / k + strings[i];
  10358. }
  10359. };
  10360. }
  10361. return cacheAppend;
  10362. }
  10363. function index$2(projection, context) {
  10364. let digits = 3,
  10365. pointRadius = 4.5,
  10366. projectionStream,
  10367. contextStream;
  10368. function path(object) {
  10369. if (object) {
  10370. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  10371. geoStream(object, projectionStream(contextStream));
  10372. }
  10373. return contextStream.result();
  10374. }
  10375. path.area = function(object) {
  10376. geoStream(object, projectionStream(pathArea));
  10377. return pathArea.result();
  10378. };
  10379. path.measure = function(object) {
  10380. geoStream(object, projectionStream(pathMeasure));
  10381. return pathMeasure.result();
  10382. };
  10383. path.bounds = function(object) {
  10384. geoStream(object, projectionStream(boundsStream$1));
  10385. return boundsStream$1.result();
  10386. };
  10387. path.centroid = function(object) {
  10388. geoStream(object, projectionStream(pathCentroid));
  10389. return pathCentroid.result();
  10390. };
  10391. path.projection = function(_) {
  10392. if (!arguments.length) return projection;
  10393. projectionStream = _ == null ? (projection = null, identity$5) : (projection = _).stream;
  10394. return path;
  10395. };
  10396. path.context = function(_) {
  10397. if (!arguments.length) return context;
  10398. contextStream = _ == null ? (context = null, new PathString(digits)) : new PathContext(context = _);
  10399. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  10400. return path;
  10401. };
  10402. path.pointRadius = function(_) {
  10403. if (!arguments.length) return pointRadius;
  10404. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  10405. return path;
  10406. };
  10407. path.digits = function(_) {
  10408. if (!arguments.length) return digits;
  10409. if (_ == null) digits = null;
  10410. else {
  10411. const d = Math.floor(_);
  10412. if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
  10413. digits = d;
  10414. }
  10415. if (context === null) contextStream = new PathString(digits);
  10416. return path;
  10417. };
  10418. return path.projection(projection).digits(digits).context(context);
  10419. }
  10420. function transform$1(methods) {
  10421. return {
  10422. stream: transformer$3(methods)
  10423. };
  10424. }
  10425. function transformer$3(methods) {
  10426. return function(stream) {
  10427. var s = new TransformStream;
  10428. for (var key in methods) s[key] = methods[key];
  10429. s.stream = stream;
  10430. return s;
  10431. };
  10432. }
  10433. function TransformStream() {}
  10434. TransformStream.prototype = {
  10435. constructor: TransformStream,
  10436. point: function(x, y) { this.stream.point(x, y); },
  10437. sphere: function() { this.stream.sphere(); },
  10438. lineStart: function() { this.stream.lineStart(); },
  10439. lineEnd: function() { this.stream.lineEnd(); },
  10440. polygonStart: function() { this.stream.polygonStart(); },
  10441. polygonEnd: function() { this.stream.polygonEnd(); }
  10442. };
  10443. function fit(projection, fitBounds, object) {
  10444. var clip = projection.clipExtent && projection.clipExtent();
  10445. projection.scale(150).translate([0, 0]);
  10446. if (clip != null) projection.clipExtent(null);
  10447. geoStream(object, projection.stream(boundsStream$1));
  10448. fitBounds(boundsStream$1.result());
  10449. if (clip != null) projection.clipExtent(clip);
  10450. return projection;
  10451. }
  10452. function fitExtent(projection, extent, object) {
  10453. return fit(projection, function(b) {
  10454. var w = extent[1][0] - extent[0][0],
  10455. h = extent[1][1] - extent[0][1],
  10456. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  10457. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  10458. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  10459. projection.scale(150 * k).translate([x, y]);
  10460. }, object);
  10461. }
  10462. function fitSize(projection, size, object) {
  10463. return fitExtent(projection, [[0, 0], size], object);
  10464. }
  10465. function fitWidth(projection, width, object) {
  10466. return fit(projection, function(b) {
  10467. var w = +width,
  10468. k = w / (b[1][0] - b[0][0]),
  10469. x = (w - k * (b[1][0] + b[0][0])) / 2,
  10470. y = -k * b[0][1];
  10471. projection.scale(150 * k).translate([x, y]);
  10472. }, object);
  10473. }
  10474. function fitHeight(projection, height, object) {
  10475. return fit(projection, function(b) {
  10476. var h = +height,
  10477. k = h / (b[1][1] - b[0][1]),
  10478. x = -k * b[0][0],
  10479. y = (h - k * (b[1][1] + b[0][1])) / 2;
  10480. projection.scale(150 * k).translate([x, y]);
  10481. }, object);
  10482. }
  10483. var maxDepth = 16, // maximum depth of subdivision
  10484. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  10485. function resample(project, delta2) {
  10486. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  10487. }
  10488. function resampleNone(project) {
  10489. return transformer$3({
  10490. point: function(x, y) {
  10491. x = project(x, y);
  10492. this.stream.point(x[0], x[1]);
  10493. }
  10494. });
  10495. }
  10496. function resample$1(project, delta2) {
  10497. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  10498. var dx = x1 - x0,
  10499. dy = y1 - y0,
  10500. d2 = dx * dx + dy * dy;
  10501. if (d2 > 4 * delta2 && depth--) {
  10502. var a = a0 + a1,
  10503. b = b0 + b1,
  10504. c = c0 + c1,
  10505. m = sqrt$2(a * a + b * b + c * c),
  10506. phi2 = asin$1(c /= m),
  10507. lambda2 = abs$1(abs$1(c) - 1) < epsilon$1 || abs$1(lambda0 - lambda1) < epsilon$1 ? (lambda0 + lambda1) / 2 : atan2$1(b, a),
  10508. p = project(lambda2, phi2),
  10509. x2 = p[0],
  10510. y2 = p[1],
  10511. dx2 = x2 - x0,
  10512. dy2 = y2 - y0,
  10513. dz = dy * dx2 - dx * dy2;
  10514. if (dz * dz / d2 > delta2 // perpendicular projected distance
  10515. || abs$1((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  10516. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  10517. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  10518. stream.point(x2, y2);
  10519. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  10520. }
  10521. }
  10522. }
  10523. return function(stream) {
  10524. var lambda00, x00, y00, a00, b00, c00, // first point
  10525. lambda0, x0, y0, a0, b0, c0; // previous point
  10526. var resampleStream = {
  10527. point: point,
  10528. lineStart: lineStart,
  10529. lineEnd: lineEnd,
  10530. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  10531. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  10532. };
  10533. function point(x, y) {
  10534. x = project(x, y);
  10535. stream.point(x[0], x[1]);
  10536. }
  10537. function lineStart() {
  10538. x0 = NaN;
  10539. resampleStream.point = linePoint;
  10540. stream.lineStart();
  10541. }
  10542. function linePoint(lambda, phi) {
  10543. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  10544. 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);
  10545. stream.point(x0, y0);
  10546. }
  10547. function lineEnd() {
  10548. resampleStream.point = point;
  10549. stream.lineEnd();
  10550. }
  10551. function ringStart() {
  10552. lineStart();
  10553. resampleStream.point = ringPoint;
  10554. resampleStream.lineEnd = ringEnd;
  10555. }
  10556. function ringPoint(lambda, phi) {
  10557. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  10558. resampleStream.point = linePoint;
  10559. }
  10560. function ringEnd() {
  10561. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  10562. resampleStream.lineEnd = lineEnd;
  10563. lineEnd();
  10564. }
  10565. return resampleStream;
  10566. };
  10567. }
  10568. var transformRadians = transformer$3({
  10569. point: function(x, y) {
  10570. this.stream.point(x * radians, y * radians);
  10571. }
  10572. });
  10573. function transformRotate(rotate) {
  10574. return transformer$3({
  10575. point: function(x, y) {
  10576. var r = rotate(x, y);
  10577. return this.stream.point(r[0], r[1]);
  10578. }
  10579. });
  10580. }
  10581. function scaleTranslate(k, dx, dy, sx, sy) {
  10582. function transform(x, y) {
  10583. x *= sx; y *= sy;
  10584. return [dx + k * x, dy - k * y];
  10585. }
  10586. transform.invert = function(x, y) {
  10587. return [(x - dx) / k * sx, (dy - y) / k * sy];
  10588. };
  10589. return transform;
  10590. }
  10591. function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {
  10592. if (!alpha) return scaleTranslate(k, dx, dy, sx, sy);
  10593. var cosAlpha = cos$1(alpha),
  10594. sinAlpha = sin$1(alpha),
  10595. a = cosAlpha * k,
  10596. b = sinAlpha * k,
  10597. ai = cosAlpha / k,
  10598. bi = sinAlpha / k,
  10599. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  10600. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  10601. function transform(x, y) {
  10602. x *= sx; y *= sy;
  10603. return [a * x - b * y + dx, dy - b * x - a * y];
  10604. }
  10605. transform.invert = function(x, y) {
  10606. return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];
  10607. };
  10608. return transform;
  10609. }
  10610. function projection(project) {
  10611. return projectionMutator(function() { return project; })();
  10612. }
  10613. function projectionMutator(projectAt) {
  10614. var project,
  10615. k = 150, // scale
  10616. x = 480, y = 250, // translate
  10617. lambda = 0, phi = 0, // center
  10618. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  10619. alpha = 0, // post-rotate angle
  10620. sx = 1, // reflectX
  10621. sy = 1, // reflectX
  10622. theta = null, preclip = clipAntimeridian, // pre-clip angle
  10623. x0 = null, y0, x1, y1, postclip = identity$5, // post-clip extent
  10624. delta2 = 0.5, // precision
  10625. projectResample,
  10626. projectTransform,
  10627. projectRotateTransform,
  10628. cache,
  10629. cacheStream;
  10630. function projection(point) {
  10631. return projectRotateTransform(point[0] * radians, point[1] * radians);
  10632. }
  10633. function invert(point) {
  10634. point = projectRotateTransform.invert(point[0], point[1]);
  10635. return point && [point[0] * degrees, point[1] * degrees];
  10636. }
  10637. projection.stream = function(stream) {
  10638. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  10639. };
  10640. projection.preclip = function(_) {
  10641. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  10642. };
  10643. projection.postclip = function(_) {
  10644. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  10645. };
  10646. projection.clipAngle = function(_) {
  10647. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees;
  10648. };
  10649. projection.clipExtent = function(_) {
  10650. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  10651. };
  10652. projection.scale = function(_) {
  10653. return arguments.length ? (k = +_, recenter()) : k;
  10654. };
  10655. projection.translate = function(_) {
  10656. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  10657. };
  10658. projection.center = function(_) {
  10659. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees];
  10660. };
  10661. projection.rotate = function(_) {
  10662. return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees, deltaPhi * degrees, deltaGamma * degrees];
  10663. };
  10664. projection.angle = function(_) {
  10665. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees;
  10666. };
  10667. projection.reflectX = function(_) {
  10668. return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;
  10669. };
  10670. projection.reflectY = function(_) {
  10671. return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;
  10672. };
  10673. projection.precision = function(_) {
  10674. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$2(delta2);
  10675. };
  10676. projection.fitExtent = function(extent, object) {
  10677. return fitExtent(projection, extent, object);
  10678. };
  10679. projection.fitSize = function(size, object) {
  10680. return fitSize(projection, size, object);
  10681. };
  10682. projection.fitWidth = function(width, object) {
  10683. return fitWidth(projection, width, object);
  10684. };
  10685. projection.fitHeight = function(height, object) {
  10686. return fitHeight(projection, height, object);
  10687. };
  10688. function recenter() {
  10689. var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),
  10690. transform = scaleTranslateRotate(k, x - center[0], y - center[1], sx, sy, alpha);
  10691. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  10692. projectTransform = compose(project, transform);
  10693. projectRotateTransform = compose(rotate, projectTransform);
  10694. projectResample = resample(projectTransform, delta2);
  10695. return reset();
  10696. }
  10697. function reset() {
  10698. cache = cacheStream = null;
  10699. return projection;
  10700. }
  10701. return function() {
  10702. project = projectAt.apply(this, arguments);
  10703. projection.invert = project.invert && invert;
  10704. return recenter();
  10705. };
  10706. }
  10707. function conicProjection(projectAt) {
  10708. var phi0 = 0,
  10709. phi1 = pi$1 / 3,
  10710. m = projectionMutator(projectAt),
  10711. p = m(phi0, phi1);
  10712. p.parallels = function(_) {
  10713. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees, phi1 * degrees];
  10714. };
  10715. return p;
  10716. }
  10717. function cylindricalEqualAreaRaw(phi0) {
  10718. var cosPhi0 = cos$1(phi0);
  10719. function forward(lambda, phi) {
  10720. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  10721. }
  10722. forward.invert = function(x, y) {
  10723. return [x / cosPhi0, asin$1(y * cosPhi0)];
  10724. };
  10725. return forward;
  10726. }
  10727. function conicEqualAreaRaw(y0, y1) {
  10728. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  10729. // Are the parallels symmetrical around the Equator?
  10730. if (abs$1(n) < epsilon$1) return cylindricalEqualAreaRaw(y0);
  10731. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt$2(c) / n;
  10732. function project(x, y) {
  10733. var r = sqrt$2(c - 2 * n * sin$1(y)) / n;
  10734. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  10735. }
  10736. project.invert = function(x, y) {
  10737. var r0y = r0 - y,
  10738. l = atan2$1(x, abs$1(r0y)) * sign$1(r0y);
  10739. if (r0y * n < 0)
  10740. l -= pi$1 * sign$1(x) * sign$1(r0y);
  10741. return [l / n, asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  10742. };
  10743. return project;
  10744. }
  10745. function conicEqualArea() {
  10746. return conicProjection(conicEqualAreaRaw)
  10747. .scale(155.424)
  10748. .center([0, 33.6442]);
  10749. }
  10750. function albers() {
  10751. return conicEqualArea()
  10752. .parallels([29.5, 45.5])
  10753. .scale(1070)
  10754. .translate([480, 250])
  10755. .rotate([96, 0])
  10756. .center([-0.6, 38.7]);
  10757. }
  10758. // The projections must have mutually exclusive clip regions on the sphere,
  10759. // as this will avoid emitting interleaving lines and polygons.
  10760. function multiplex(streams) {
  10761. var n = streams.length;
  10762. return {
  10763. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  10764. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  10765. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  10766. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  10767. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  10768. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  10769. };
  10770. }
  10771. // A composite projection for the United States, configured by default for
  10772. // 960×500. The projection also works quite well at 960×600 if you change the
  10773. // scale to 1285 and adjust the translate accordingly. The set of standard
  10774. // parallels for each region comes from USGS, which is published here:
  10775. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  10776. function albersUsa() {
  10777. var cache,
  10778. cacheStream,
  10779. lower48 = albers(), lower48Point,
  10780. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  10781. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  10782. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  10783. function albersUsa(coordinates) {
  10784. var x = coordinates[0], y = coordinates[1];
  10785. return point = null,
  10786. (lower48Point.point(x, y), point)
  10787. || (alaskaPoint.point(x, y), point)
  10788. || (hawaiiPoint.point(x, y), point);
  10789. }
  10790. albersUsa.invert = function(coordinates) {
  10791. var k = lower48.scale(),
  10792. t = lower48.translate(),
  10793. x = (coordinates[0] - t[0]) / k,
  10794. y = (coordinates[1] - t[1]) / k;
  10795. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  10796. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  10797. : lower48).invert(coordinates);
  10798. };
  10799. albersUsa.stream = function(stream) {
  10800. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  10801. };
  10802. albersUsa.precision = function(_) {
  10803. if (!arguments.length) return lower48.precision();
  10804. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  10805. return reset();
  10806. };
  10807. albersUsa.scale = function(_) {
  10808. if (!arguments.length) return lower48.scale();
  10809. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  10810. return albersUsa.translate(lower48.translate());
  10811. };
  10812. albersUsa.translate = function(_) {
  10813. if (!arguments.length) return lower48.translate();
  10814. var k = lower48.scale(), x = +_[0], y = +_[1];
  10815. lower48Point = lower48
  10816. .translate(_)
  10817. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  10818. .stream(pointStream);
  10819. alaskaPoint = alaska
  10820. .translate([x - 0.307 * k, y + 0.201 * k])
  10821. .clipExtent([[x - 0.425 * k + epsilon$1, y + 0.120 * k + epsilon$1], [x - 0.214 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
  10822. .stream(pointStream);
  10823. hawaiiPoint = hawaii
  10824. .translate([x - 0.205 * k, y + 0.212 * k])
  10825. .clipExtent([[x - 0.214 * k + epsilon$1, y + 0.166 * k + epsilon$1], [x - 0.115 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
  10826. .stream(pointStream);
  10827. return reset();
  10828. };
  10829. albersUsa.fitExtent = function(extent, object) {
  10830. return fitExtent(albersUsa, extent, object);
  10831. };
  10832. albersUsa.fitSize = function(size, object) {
  10833. return fitSize(albersUsa, size, object);
  10834. };
  10835. albersUsa.fitWidth = function(width, object) {
  10836. return fitWidth(albersUsa, width, object);
  10837. };
  10838. albersUsa.fitHeight = function(height, object) {
  10839. return fitHeight(albersUsa, height, object);
  10840. };
  10841. function reset() {
  10842. cache = cacheStream = null;
  10843. return albersUsa;
  10844. }
  10845. return albersUsa.scale(1070);
  10846. }
  10847. function azimuthalRaw(scale) {
  10848. return function(x, y) {
  10849. var cx = cos$1(x),
  10850. cy = cos$1(y),
  10851. k = scale(cx * cy);
  10852. if (k === Infinity) return [2, 0];
  10853. return [
  10854. k * cy * sin$1(x),
  10855. k * sin$1(y)
  10856. ];
  10857. }
  10858. }
  10859. function azimuthalInvert(angle) {
  10860. return function(x, y) {
  10861. var z = sqrt$2(x * x + y * y),
  10862. c = angle(z),
  10863. sc = sin$1(c),
  10864. cc = cos$1(c);
  10865. return [
  10866. atan2$1(x * sc, z * cc),
  10867. asin$1(z && y * sc / z)
  10868. ];
  10869. }
  10870. }
  10871. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  10872. return sqrt$2(2 / (1 + cxcy));
  10873. });
  10874. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  10875. return 2 * asin$1(z / 2);
  10876. });
  10877. function azimuthalEqualArea() {
  10878. return projection(azimuthalEqualAreaRaw)
  10879. .scale(124.75)
  10880. .clipAngle(180 - 1e-3);
  10881. }
  10882. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  10883. return (c = acos$1(c)) && c / sin$1(c);
  10884. });
  10885. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  10886. return z;
  10887. });
  10888. function azimuthalEquidistant() {
  10889. return projection(azimuthalEquidistantRaw)
  10890. .scale(79.4188)
  10891. .clipAngle(180 - 1e-3);
  10892. }
  10893. function mercatorRaw(lambda, phi) {
  10894. return [lambda, log$1(tan((halfPi$1 + phi) / 2))];
  10895. }
  10896. mercatorRaw.invert = function(x, y) {
  10897. return [x, 2 * atan(exp(y)) - halfPi$1];
  10898. };
  10899. function mercator() {
  10900. return mercatorProjection(mercatorRaw)
  10901. .scale(961 / tau$1);
  10902. }
  10903. function mercatorProjection(project) {
  10904. var m = projection(project),
  10905. center = m.center,
  10906. scale = m.scale,
  10907. translate = m.translate,
  10908. clipExtent = m.clipExtent,
  10909. x0 = null, y0, x1, y1; // clip extent
  10910. m.scale = function(_) {
  10911. return arguments.length ? (scale(_), reclip()) : scale();
  10912. };
  10913. m.translate = function(_) {
  10914. return arguments.length ? (translate(_), reclip()) : translate();
  10915. };
  10916. m.center = function(_) {
  10917. return arguments.length ? (center(_), reclip()) : center();
  10918. };
  10919. m.clipExtent = function(_) {
  10920. 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]];
  10921. };
  10922. function reclip() {
  10923. var k = pi$1 * scale(),
  10924. t = m(rotation(m.rotate()).invert([0, 0]));
  10925. return clipExtent(x0 == null
  10926. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  10927. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  10928. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  10929. }
  10930. return reclip();
  10931. }
  10932. function tany(y) {
  10933. return tan((halfPi$1 + y) / 2);
  10934. }
  10935. function conicConformalRaw(y0, y1) {
  10936. var cy0 = cos$1(y0),
  10937. n = y0 === y1 ? sin$1(y0) : log$1(cy0 / cos$1(y1)) / log$1(tany(y1) / tany(y0)),
  10938. f = cy0 * pow$1(tany(y0), n) / n;
  10939. if (!n) return mercatorRaw;
  10940. function project(x, y) {
  10941. if (f > 0) { if (y < -halfPi$1 + epsilon$1) y = -halfPi$1 + epsilon$1; }
  10942. else { if (y > halfPi$1 - epsilon$1) y = halfPi$1 - epsilon$1; }
  10943. var r = f / pow$1(tany(y), n);
  10944. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  10945. }
  10946. project.invert = function(x, y) {
  10947. var fy = f - y, r = sign$1(n) * sqrt$2(x * x + fy * fy),
  10948. l = atan2$1(x, abs$1(fy)) * sign$1(fy);
  10949. if (fy * n < 0)
  10950. l -= pi$1 * sign$1(x) * sign$1(fy);
  10951. return [l / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$1];
  10952. };
  10953. return project;
  10954. }
  10955. function conicConformal() {
  10956. return conicProjection(conicConformalRaw)
  10957. .scale(109.5)
  10958. .parallels([30, 30]);
  10959. }
  10960. function equirectangularRaw(lambda, phi) {
  10961. return [lambda, phi];
  10962. }
  10963. equirectangularRaw.invert = equirectangularRaw;
  10964. function equirectangular() {
  10965. return projection(equirectangularRaw)
  10966. .scale(152.63);
  10967. }
  10968. function conicEquidistantRaw(y0, y1) {
  10969. var cy0 = cos$1(y0),
  10970. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  10971. g = cy0 / n + y0;
  10972. if (abs$1(n) < epsilon$1) return equirectangularRaw;
  10973. function project(x, y) {
  10974. var gy = g - y, nx = n * x;
  10975. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  10976. }
  10977. project.invert = function(x, y) {
  10978. var gy = g - y,
  10979. l = atan2$1(x, abs$1(gy)) * sign$1(gy);
  10980. if (gy * n < 0)
  10981. l -= pi$1 * sign$1(x) * sign$1(gy);
  10982. return [l / n, g - sign$1(n) * sqrt$2(x * x + gy * gy)];
  10983. };
  10984. return project;
  10985. }
  10986. function conicEquidistant() {
  10987. return conicProjection(conicEquidistantRaw)
  10988. .scale(131.154)
  10989. .center([0, 13.9389]);
  10990. }
  10991. var A1 = 1.340264,
  10992. A2 = -0.081106,
  10993. A3 = 0.000893,
  10994. A4 = 0.003796,
  10995. M = sqrt$2(3) / 2,
  10996. iterations = 12;
  10997. function equalEarthRaw(lambda, phi) {
  10998. var l = asin$1(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
  10999. return [
  11000. lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
  11001. l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
  11002. ];
  11003. }
  11004. equalEarthRaw.invert = function(x, y) {
  11005. var l = y, l2 = l * l, l6 = l2 * l2 * l2;
  11006. for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
  11007. fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
  11008. fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
  11009. l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
  11010. if (abs$1(delta) < epsilon2) break;
  11011. }
  11012. return [
  11013. M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
  11014. asin$1(sin$1(l) / M)
  11015. ];
  11016. };
  11017. function equalEarth() {
  11018. return projection(equalEarthRaw)
  11019. .scale(177.158);
  11020. }
  11021. function gnomonicRaw(x, y) {
  11022. var cy = cos$1(y), k = cos$1(x) * cy;
  11023. return [cy * sin$1(x) / k, sin$1(y) / k];
  11024. }
  11025. gnomonicRaw.invert = azimuthalInvert(atan);
  11026. function gnomonic() {
  11027. return projection(gnomonicRaw)
  11028. .scale(144.049)
  11029. .clipAngle(60);
  11030. }
  11031. function identity$4() {
  11032. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect
  11033. alpha = 0, ca, sa, // angle
  11034. x0 = null, y0, x1, y1, // clip extent
  11035. kx = 1, ky = 1,
  11036. transform = transformer$3({
  11037. point: function(x, y) {
  11038. var p = projection([x, y]);
  11039. this.stream.point(p[0], p[1]);
  11040. }
  11041. }),
  11042. postclip = identity$5,
  11043. cache,
  11044. cacheStream;
  11045. function reset() {
  11046. kx = k * sx;
  11047. ky = k * sy;
  11048. cache = cacheStream = null;
  11049. return projection;
  11050. }
  11051. function projection (p) {
  11052. var x = p[0] * kx, y = p[1] * ky;
  11053. if (alpha) {
  11054. var t = y * ca - x * sa;
  11055. x = x * ca + y * sa;
  11056. y = t;
  11057. }
  11058. return [x + tx, y + ty];
  11059. }
  11060. projection.invert = function(p) {
  11061. var x = p[0] - tx, y = p[1] - ty;
  11062. if (alpha) {
  11063. var t = y * ca + x * sa;
  11064. x = x * ca - y * sa;
  11065. y = t;
  11066. }
  11067. return [x / kx, y / ky];
  11068. };
  11069. projection.stream = function(stream) {
  11070. return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
  11071. };
  11072. projection.postclip = function(_) {
  11073. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  11074. };
  11075. projection.clipExtent = function(_) {
  11076. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  11077. };
  11078. projection.scale = function(_) {
  11079. return arguments.length ? (k = +_, reset()) : k;
  11080. };
  11081. projection.translate = function(_) {
  11082. return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];
  11083. };
  11084. projection.angle = function(_) {
  11085. return arguments.length ? (alpha = _ % 360 * radians, sa = sin$1(alpha), ca = cos$1(alpha), reset()) : alpha * degrees;
  11086. };
  11087. projection.reflectX = function(_) {
  11088. return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;
  11089. };
  11090. projection.reflectY = function(_) {
  11091. return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;
  11092. };
  11093. projection.fitExtent = function(extent, object) {
  11094. return fitExtent(projection, extent, object);
  11095. };
  11096. projection.fitSize = function(size, object) {
  11097. return fitSize(projection, size, object);
  11098. };
  11099. projection.fitWidth = function(width, object) {
  11100. return fitWidth(projection, width, object);
  11101. };
  11102. projection.fitHeight = function(height, object) {
  11103. return fitHeight(projection, height, object);
  11104. };
  11105. return projection;
  11106. }
  11107. function naturalEarth1Raw(lambda, phi) {
  11108. var phi2 = phi * phi, phi4 = phi2 * phi2;
  11109. return [
  11110. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  11111. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  11112. ];
  11113. }
  11114. naturalEarth1Raw.invert = function(x, y) {
  11115. var phi = y, i = 25, delta;
  11116. do {
  11117. var phi2 = phi * phi, phi4 = phi2 * phi2;
  11118. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  11119. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  11120. } while (abs$1(delta) > epsilon$1 && --i > 0);
  11121. return [
  11122. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  11123. phi
  11124. ];
  11125. };
  11126. function naturalEarth1() {
  11127. return projection(naturalEarth1Raw)
  11128. .scale(175.295);
  11129. }
  11130. function orthographicRaw(x, y) {
  11131. return [cos$1(y) * sin$1(x), sin$1(y)];
  11132. }
  11133. orthographicRaw.invert = azimuthalInvert(asin$1);
  11134. function orthographic() {
  11135. return projection(orthographicRaw)
  11136. .scale(249.5)
  11137. .clipAngle(90 + epsilon$1);
  11138. }
  11139. function stereographicRaw(x, y) {
  11140. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  11141. return [cy * sin$1(x) / k, sin$1(y) / k];
  11142. }
  11143. stereographicRaw.invert = azimuthalInvert(function(z) {
  11144. return 2 * atan(z);
  11145. });
  11146. function stereographic() {
  11147. return projection(stereographicRaw)
  11148. .scale(250)
  11149. .clipAngle(142);
  11150. }
  11151. function transverseMercatorRaw(lambda, phi) {
  11152. return [log$1(tan((halfPi$1 + phi) / 2)), -lambda];
  11153. }
  11154. transverseMercatorRaw.invert = function(x, y) {
  11155. return [-y, 2 * atan(exp(x)) - halfPi$1];
  11156. };
  11157. function transverseMercator() {
  11158. var m = mercatorProjection(transverseMercatorRaw),
  11159. center = m.center,
  11160. rotate = m.rotate;
  11161. m.center = function(_) {
  11162. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  11163. };
  11164. m.rotate = function(_) {
  11165. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  11166. };
  11167. return rotate([0, 0, 90])
  11168. .scale(159.155);
  11169. }
  11170. function defaultSeparation$1(a, b) {
  11171. return a.parent === b.parent ? 1 : 2;
  11172. }
  11173. function meanX(children) {
  11174. return children.reduce(meanXReduce, 0) / children.length;
  11175. }
  11176. function meanXReduce(x, c) {
  11177. return x + c.x;
  11178. }
  11179. function maxY(children) {
  11180. return 1 + children.reduce(maxYReduce, 0);
  11181. }
  11182. function maxYReduce(y, c) {
  11183. return Math.max(y, c.y);
  11184. }
  11185. function leafLeft(node) {
  11186. var children;
  11187. while (children = node.children) node = children[0];
  11188. return node;
  11189. }
  11190. function leafRight(node) {
  11191. var children;
  11192. while (children = node.children) node = children[children.length - 1];
  11193. return node;
  11194. }
  11195. function cluster() {
  11196. var separation = defaultSeparation$1,
  11197. dx = 1,
  11198. dy = 1,
  11199. nodeSize = false;
  11200. function cluster(root) {
  11201. var previousNode,
  11202. x = 0;
  11203. // First walk, computing the initial x & y values.
  11204. root.eachAfter(function(node) {
  11205. var children = node.children;
  11206. if (children) {
  11207. node.x = meanX(children);
  11208. node.y = maxY(children);
  11209. } else {
  11210. node.x = previousNode ? x += separation(node, previousNode) : 0;
  11211. node.y = 0;
  11212. previousNode = node;
  11213. }
  11214. });
  11215. var left = leafLeft(root),
  11216. right = leafRight(root),
  11217. x0 = left.x - separation(left, right) / 2,
  11218. x1 = right.x + separation(right, left) / 2;
  11219. // Second walk, normalizing x & y to the desired size.
  11220. return root.eachAfter(nodeSize ? function(node) {
  11221. node.x = (node.x - root.x) * dx;
  11222. node.y = (root.y - node.y) * dy;
  11223. } : function(node) {
  11224. node.x = (node.x - x0) / (x1 - x0) * dx;
  11225. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  11226. });
  11227. }
  11228. cluster.separation = function(x) {
  11229. return arguments.length ? (separation = x, cluster) : separation;
  11230. };
  11231. cluster.size = function(x) {
  11232. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  11233. };
  11234. cluster.nodeSize = function(x) {
  11235. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  11236. };
  11237. return cluster;
  11238. }
  11239. function count(node) {
  11240. var sum = 0,
  11241. children = node.children,
  11242. i = children && children.length;
  11243. if (!i) sum = 1;
  11244. else while (--i >= 0) sum += children[i].value;
  11245. node.value = sum;
  11246. }
  11247. function node_count() {
  11248. return this.eachAfter(count);
  11249. }
  11250. function node_each(callback, that) {
  11251. let index = -1;
  11252. for (const node of this) {
  11253. callback.call(that, node, ++index, this);
  11254. }
  11255. return this;
  11256. }
  11257. function node_eachBefore(callback, that) {
  11258. var node = this, nodes = [node], children, i, index = -1;
  11259. while (node = nodes.pop()) {
  11260. callback.call(that, node, ++index, this);
  11261. if (children = node.children) {
  11262. for (i = children.length - 1; i >= 0; --i) {
  11263. nodes.push(children[i]);
  11264. }
  11265. }
  11266. }
  11267. return this;
  11268. }
  11269. function node_eachAfter(callback, that) {
  11270. var node = this, nodes = [node], next = [], children, i, n, index = -1;
  11271. while (node = nodes.pop()) {
  11272. next.push(node);
  11273. if (children = node.children) {
  11274. for (i = 0, n = children.length; i < n; ++i) {
  11275. nodes.push(children[i]);
  11276. }
  11277. }
  11278. }
  11279. while (node = next.pop()) {
  11280. callback.call(that, node, ++index, this);
  11281. }
  11282. return this;
  11283. }
  11284. function node_find(callback, that) {
  11285. let index = -1;
  11286. for (const node of this) {
  11287. if (callback.call(that, node, ++index, this)) {
  11288. return node;
  11289. }
  11290. }
  11291. }
  11292. function node_sum(value) {
  11293. return this.eachAfter(function(node) {
  11294. var sum = +value(node.data) || 0,
  11295. children = node.children,
  11296. i = children && children.length;
  11297. while (--i >= 0) sum += children[i].value;
  11298. node.value = sum;
  11299. });
  11300. }
  11301. function node_sort(compare) {
  11302. return this.eachBefore(function(node) {
  11303. if (node.children) {
  11304. node.children.sort(compare);
  11305. }
  11306. });
  11307. }
  11308. function node_path(end) {
  11309. var start = this,
  11310. ancestor = leastCommonAncestor(start, end),
  11311. nodes = [start];
  11312. while (start !== ancestor) {
  11313. start = start.parent;
  11314. nodes.push(start);
  11315. }
  11316. var k = nodes.length;
  11317. while (end !== ancestor) {
  11318. nodes.splice(k, 0, end);
  11319. end = end.parent;
  11320. }
  11321. return nodes;
  11322. }
  11323. function leastCommonAncestor(a, b) {
  11324. if (a === b) return a;
  11325. var aNodes = a.ancestors(),
  11326. bNodes = b.ancestors(),
  11327. c = null;
  11328. a = aNodes.pop();
  11329. b = bNodes.pop();
  11330. while (a === b) {
  11331. c = a;
  11332. a = aNodes.pop();
  11333. b = bNodes.pop();
  11334. }
  11335. return c;
  11336. }
  11337. function node_ancestors() {
  11338. var node = this, nodes = [node];
  11339. while (node = node.parent) {
  11340. nodes.push(node);
  11341. }
  11342. return nodes;
  11343. }
  11344. function node_descendants() {
  11345. return Array.from(this);
  11346. }
  11347. function node_leaves() {
  11348. var leaves = [];
  11349. this.eachBefore(function(node) {
  11350. if (!node.children) {
  11351. leaves.push(node);
  11352. }
  11353. });
  11354. return leaves;
  11355. }
  11356. function node_links() {
  11357. var root = this, links = [];
  11358. root.each(function(node) {
  11359. if (node !== root) { // Don’t include the root’s parent, if any.
  11360. links.push({source: node.parent, target: node});
  11361. }
  11362. });
  11363. return links;
  11364. }
  11365. function* node_iterator() {
  11366. var node = this, current, next = [node], children, i, n;
  11367. do {
  11368. current = next.reverse(), next = [];
  11369. while (node = current.pop()) {
  11370. yield node;
  11371. if (children = node.children) {
  11372. for (i = 0, n = children.length; i < n; ++i) {
  11373. next.push(children[i]);
  11374. }
  11375. }
  11376. }
  11377. } while (next.length);
  11378. }
  11379. function hierarchy(data, children) {
  11380. if (data instanceof Map) {
  11381. data = [undefined, data];
  11382. if (children === undefined) children = mapChildren;
  11383. } else if (children === undefined) {
  11384. children = objectChildren;
  11385. }
  11386. var root = new Node$1(data),
  11387. node,
  11388. nodes = [root],
  11389. child,
  11390. childs,
  11391. i,
  11392. n;
  11393. while (node = nodes.pop()) {
  11394. if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
  11395. node.children = childs;
  11396. for (i = n - 1; i >= 0; --i) {
  11397. nodes.push(child = childs[i] = new Node$1(childs[i]));
  11398. child.parent = node;
  11399. child.depth = node.depth + 1;
  11400. }
  11401. }
  11402. }
  11403. return root.eachBefore(computeHeight);
  11404. }
  11405. function node_copy() {
  11406. return hierarchy(this).eachBefore(copyData);
  11407. }
  11408. function objectChildren(d) {
  11409. return d.children;
  11410. }
  11411. function mapChildren(d) {
  11412. return Array.isArray(d) ? d[1] : null;
  11413. }
  11414. function copyData(node) {
  11415. if (node.data.value !== undefined) node.value = node.data.value;
  11416. node.data = node.data.data;
  11417. }
  11418. function computeHeight(node) {
  11419. var height = 0;
  11420. do node.height = height;
  11421. while ((node = node.parent) && (node.height < ++height));
  11422. }
  11423. function Node$1(data) {
  11424. this.data = data;
  11425. this.depth =
  11426. this.height = 0;
  11427. this.parent = null;
  11428. }
  11429. Node$1.prototype = hierarchy.prototype = {
  11430. constructor: Node$1,
  11431. count: node_count,
  11432. each: node_each,
  11433. eachAfter: node_eachAfter,
  11434. eachBefore: node_eachBefore,
  11435. find: node_find,
  11436. sum: node_sum,
  11437. sort: node_sort,
  11438. path: node_path,
  11439. ancestors: node_ancestors,
  11440. descendants: node_descendants,
  11441. leaves: node_leaves,
  11442. links: node_links,
  11443. copy: node_copy,
  11444. [Symbol.iterator]: node_iterator
  11445. };
  11446. function optional(f) {
  11447. return f == null ? null : required(f);
  11448. }
  11449. function required(f) {
  11450. if (typeof f !== "function") throw new Error;
  11451. return f;
  11452. }
  11453. function constantZero() {
  11454. return 0;
  11455. }
  11456. function constant$2(x) {
  11457. return function() {
  11458. return x;
  11459. };
  11460. }
  11461. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  11462. const a$1 = 1664525;
  11463. const c$3 = 1013904223;
  11464. const m = 4294967296; // 2^32
  11465. function lcg$1() {
  11466. let s = 1;
  11467. return () => (s = (a$1 * s + c$3) % m) / m;
  11468. }
  11469. function array$1(x) {
  11470. return typeof x === "object" && "length" in x
  11471. ? x // Array, TypedArray, NodeList, array-like
  11472. : Array.from(x); // Map, Set, iterable, string, or anything else
  11473. }
  11474. function shuffle(array, random) {
  11475. let m = array.length,
  11476. t,
  11477. i;
  11478. while (m) {
  11479. i = random() * m-- | 0;
  11480. t = array[m];
  11481. array[m] = array[i];
  11482. array[i] = t;
  11483. }
  11484. return array;
  11485. }
  11486. function enclose(circles) {
  11487. return packEncloseRandom(circles, lcg$1());
  11488. }
  11489. function packEncloseRandom(circles, random) {
  11490. var i = 0, n = (circles = shuffle(Array.from(circles), random)).length, B = [], p, e;
  11491. while (i < n) {
  11492. p = circles[i];
  11493. if (e && enclosesWeak(e, p)) ++i;
  11494. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  11495. }
  11496. return e;
  11497. }
  11498. function extendBasis(B, p) {
  11499. var i, j;
  11500. if (enclosesWeakAll(p, B)) return [p];
  11501. // If we get here then B must have at least one element.
  11502. for (i = 0; i < B.length; ++i) {
  11503. if (enclosesNot(p, B[i])
  11504. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  11505. return [B[i], p];
  11506. }
  11507. }
  11508. // If we get here then B must have at least two elements.
  11509. for (i = 0; i < B.length - 1; ++i) {
  11510. for (j = i + 1; j < B.length; ++j) {
  11511. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  11512. && enclosesNot(encloseBasis2(B[i], p), B[j])
  11513. && enclosesNot(encloseBasis2(B[j], p), B[i])
  11514. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  11515. return [B[i], B[j], p];
  11516. }
  11517. }
  11518. }
  11519. // If we get here then something is very wrong.
  11520. throw new Error;
  11521. }
  11522. function enclosesNot(a, b) {
  11523. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  11524. return dr < 0 || dr * dr < dx * dx + dy * dy;
  11525. }
  11526. function enclosesWeak(a, b) {
  11527. 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;
  11528. return dr > 0 && dr * dr > dx * dx + dy * dy;
  11529. }
  11530. function enclosesWeakAll(a, B) {
  11531. for (var i = 0; i < B.length; ++i) {
  11532. if (!enclosesWeak(a, B[i])) {
  11533. return false;
  11534. }
  11535. }
  11536. return true;
  11537. }
  11538. function encloseBasis(B) {
  11539. switch (B.length) {
  11540. case 1: return encloseBasis1(B[0]);
  11541. case 2: return encloseBasis2(B[0], B[1]);
  11542. case 3: return encloseBasis3(B[0], B[1], B[2]);
  11543. }
  11544. }
  11545. function encloseBasis1(a) {
  11546. return {
  11547. x: a.x,
  11548. y: a.y,
  11549. r: a.r
  11550. };
  11551. }
  11552. function encloseBasis2(a, b) {
  11553. var x1 = a.x, y1 = a.y, r1 = a.r,
  11554. x2 = b.x, y2 = b.y, r2 = b.r,
  11555. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  11556. l = Math.sqrt(x21 * x21 + y21 * y21);
  11557. return {
  11558. x: (x1 + x2 + x21 / l * r21) / 2,
  11559. y: (y1 + y2 + y21 / l * r21) / 2,
  11560. r: (l + r1 + r2) / 2
  11561. };
  11562. }
  11563. function encloseBasis3(a, b, c) {
  11564. var x1 = a.x, y1 = a.y, r1 = a.r,
  11565. x2 = b.x, y2 = b.y, r2 = b.r,
  11566. x3 = c.x, y3 = c.y, r3 = c.r,
  11567. a2 = x1 - x2,
  11568. a3 = x1 - x3,
  11569. b2 = y1 - y2,
  11570. b3 = y1 - y3,
  11571. c2 = r2 - r1,
  11572. c3 = r3 - r1,
  11573. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  11574. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  11575. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  11576. ab = a3 * b2 - a2 * b3,
  11577. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  11578. xb = (b3 * c2 - b2 * c3) / ab,
  11579. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  11580. yb = (a2 * c3 - a3 * c2) / ab,
  11581. A = xb * xb + yb * yb - 1,
  11582. B = 2 * (r1 + xa * xb + ya * yb),
  11583. C = xa * xa + ya * ya - r1 * r1,
  11584. r = -(Math.abs(A) > 1e-6 ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  11585. return {
  11586. x: x1 + xa + xb * r,
  11587. y: y1 + ya + yb * r,
  11588. r: r
  11589. };
  11590. }
  11591. function place(b, a, c) {
  11592. var dx = b.x - a.x, x, a2,
  11593. dy = b.y - a.y, y, b2,
  11594. d2 = dx * dx + dy * dy;
  11595. if (d2) {
  11596. a2 = a.r + c.r, a2 *= a2;
  11597. b2 = b.r + c.r, b2 *= b2;
  11598. if (a2 > b2) {
  11599. x = (d2 + b2 - a2) / (2 * d2);
  11600. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  11601. c.x = b.x - x * dx - y * dy;
  11602. c.y = b.y - x * dy + y * dx;
  11603. } else {
  11604. x = (d2 + a2 - b2) / (2 * d2);
  11605. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  11606. c.x = a.x + x * dx - y * dy;
  11607. c.y = a.y + x * dy + y * dx;
  11608. }
  11609. } else {
  11610. c.x = a.x + c.r;
  11611. c.y = a.y;
  11612. }
  11613. }
  11614. function intersects(a, b) {
  11615. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  11616. return dr > 0 && dr * dr > dx * dx + dy * dy;
  11617. }
  11618. function score(node) {
  11619. var a = node._,
  11620. b = node.next._,
  11621. ab = a.r + b.r,
  11622. dx = (a.x * b.r + b.x * a.r) / ab,
  11623. dy = (a.y * b.r + b.y * a.r) / ab;
  11624. return dx * dx + dy * dy;
  11625. }
  11626. function Node(circle) {
  11627. this._ = circle;
  11628. this.next = null;
  11629. this.previous = null;
  11630. }
  11631. function packSiblingsRandom(circles, random) {
  11632. if (!(n = (circles = array$1(circles)).length)) return 0;
  11633. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  11634. // Place the first circle.
  11635. a = circles[0], a.x = 0, a.y = 0;
  11636. if (!(n > 1)) return a.r;
  11637. // Place the second circle.
  11638. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  11639. if (!(n > 2)) return a.r + b.r;
  11640. // Place the third circle.
  11641. place(b, a, c = circles[2]);
  11642. // Initialize the front-chain using the first three circles a, b and c.
  11643. a = new Node(a), b = new Node(b), c = new Node(c);
  11644. a.next = c.previous = b;
  11645. b.next = a.previous = c;
  11646. c.next = b.previous = a;
  11647. // Attempt to place each remaining circle…
  11648. pack: for (i = 3; i < n; ++i) {
  11649. place(a._, b._, c = circles[i]), c = new Node(c);
  11650. // Find the closest intersecting circle on the front-chain, if any.
  11651. // “Closeness” is determined by linear distance along the front-chain.
  11652. // “Ahead” or “behind” is likewise determined by linear distance.
  11653. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  11654. do {
  11655. if (sj <= sk) {
  11656. if (intersects(j._, c._)) {
  11657. b = j, a.next = b, b.previous = a, --i;
  11658. continue pack;
  11659. }
  11660. sj += j._.r, j = j.next;
  11661. } else {
  11662. if (intersects(k._, c._)) {
  11663. a = k, a.next = b, b.previous = a, --i;
  11664. continue pack;
  11665. }
  11666. sk += k._.r, k = k.previous;
  11667. }
  11668. } while (j !== k.next);
  11669. // Success! Insert the new circle c between a and b.
  11670. c.previous = a, c.next = b, a.next = b.previous = b = c;
  11671. // Compute the new closest circle pair to the centroid.
  11672. aa = score(a);
  11673. while ((c = c.next) !== b) {
  11674. if ((ca = score(c)) < aa) {
  11675. a = c, aa = ca;
  11676. }
  11677. }
  11678. b = a.next;
  11679. }
  11680. // Compute the enclosing circle of the front chain.
  11681. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = packEncloseRandom(a, random);
  11682. // Translate the circles to put the enclosing circle around the origin.
  11683. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  11684. return c.r;
  11685. }
  11686. function siblings(circles) {
  11687. packSiblingsRandom(circles, lcg$1());
  11688. return circles;
  11689. }
  11690. function defaultRadius(d) {
  11691. return Math.sqrt(d.value);
  11692. }
  11693. function index$1() {
  11694. var radius = null,
  11695. dx = 1,
  11696. dy = 1,
  11697. padding = constantZero;
  11698. function pack(root) {
  11699. const random = lcg$1();
  11700. root.x = dx / 2, root.y = dy / 2;
  11701. if (radius) {
  11702. root.eachBefore(radiusLeaf(radius))
  11703. .eachAfter(packChildrenRandom(padding, 0.5, random))
  11704. .eachBefore(translateChild(1));
  11705. } else {
  11706. root.eachBefore(radiusLeaf(defaultRadius))
  11707. .eachAfter(packChildrenRandom(constantZero, 1, random))
  11708. .eachAfter(packChildrenRandom(padding, root.r / Math.min(dx, dy), random))
  11709. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  11710. }
  11711. return root;
  11712. }
  11713. pack.radius = function(x) {
  11714. return arguments.length ? (radius = optional(x), pack) : radius;
  11715. };
  11716. pack.size = function(x) {
  11717. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  11718. };
  11719. pack.padding = function(x) {
  11720. return arguments.length ? (padding = typeof x === "function" ? x : constant$2(+x), pack) : padding;
  11721. };
  11722. return pack;
  11723. }
  11724. function radiusLeaf(radius) {
  11725. return function(node) {
  11726. if (!node.children) {
  11727. node.r = Math.max(0, +radius(node) || 0);
  11728. }
  11729. };
  11730. }
  11731. function packChildrenRandom(padding, k, random) {
  11732. return function(node) {
  11733. if (children = node.children) {
  11734. var children,
  11735. i,
  11736. n = children.length,
  11737. r = padding(node) * k || 0,
  11738. e;
  11739. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  11740. e = packSiblingsRandom(children, random);
  11741. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  11742. node.r = e + r;
  11743. }
  11744. };
  11745. }
  11746. function translateChild(k) {
  11747. return function(node) {
  11748. var parent = node.parent;
  11749. node.r *= k;
  11750. if (parent) {
  11751. node.x = parent.x + k * node.x;
  11752. node.y = parent.y + k * node.y;
  11753. }
  11754. };
  11755. }
  11756. function roundNode(node) {
  11757. node.x0 = Math.round(node.x0);
  11758. node.y0 = Math.round(node.y0);
  11759. node.x1 = Math.round(node.x1);
  11760. node.y1 = Math.round(node.y1);
  11761. }
  11762. function treemapDice(parent, x0, y0, x1, y1) {
  11763. var nodes = parent.children,
  11764. node,
  11765. i = -1,
  11766. n = nodes.length,
  11767. k = parent.value && (x1 - x0) / parent.value;
  11768. while (++i < n) {
  11769. node = nodes[i], node.y0 = y0, node.y1 = y1;
  11770. node.x0 = x0, node.x1 = x0 += node.value * k;
  11771. }
  11772. }
  11773. function partition() {
  11774. var dx = 1,
  11775. dy = 1,
  11776. padding = 0,
  11777. round = false;
  11778. function partition(root) {
  11779. var n = root.height + 1;
  11780. root.x0 =
  11781. root.y0 = padding;
  11782. root.x1 = dx;
  11783. root.y1 = dy / n;
  11784. root.eachBefore(positionNode(dy, n));
  11785. if (round) root.eachBefore(roundNode);
  11786. return root;
  11787. }
  11788. function positionNode(dy, n) {
  11789. return function(node) {
  11790. if (node.children) {
  11791. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  11792. }
  11793. var x0 = node.x0,
  11794. y0 = node.y0,
  11795. x1 = node.x1 - padding,
  11796. y1 = node.y1 - padding;
  11797. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  11798. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  11799. node.x0 = x0;
  11800. node.y0 = y0;
  11801. node.x1 = x1;
  11802. node.y1 = y1;
  11803. };
  11804. }
  11805. partition.round = function(x) {
  11806. return arguments.length ? (round = !!x, partition) : round;
  11807. };
  11808. partition.size = function(x) {
  11809. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  11810. };
  11811. partition.padding = function(x) {
  11812. return arguments.length ? (padding = +x, partition) : padding;
  11813. };
  11814. return partition;
  11815. }
  11816. var preroot = {depth: -1},
  11817. ambiguous = {},
  11818. imputed = {};
  11819. function defaultId(d) {
  11820. return d.id;
  11821. }
  11822. function defaultParentId(d) {
  11823. return d.parentId;
  11824. }
  11825. function stratify() {
  11826. var id = defaultId,
  11827. parentId = defaultParentId,
  11828. path;
  11829. function stratify(data) {
  11830. var nodes = Array.from(data),
  11831. currentId = id,
  11832. currentParentId = parentId,
  11833. n,
  11834. d,
  11835. i,
  11836. root,
  11837. parent,
  11838. node,
  11839. nodeId,
  11840. nodeKey,
  11841. nodeByKey = new Map;
  11842. if (path != null) {
  11843. const I = nodes.map((d, i) => normalize$1(path(d, i, data)));
  11844. const P = I.map(parentof);
  11845. const S = new Set(I).add("");
  11846. for (const i of P) {
  11847. if (!S.has(i)) {
  11848. S.add(i);
  11849. I.push(i);
  11850. P.push(parentof(i));
  11851. nodes.push(imputed);
  11852. }
  11853. }
  11854. currentId = (_, i) => I[i];
  11855. currentParentId = (_, i) => P[i];
  11856. }
  11857. for (i = 0, n = nodes.length; i < n; ++i) {
  11858. d = nodes[i], node = nodes[i] = new Node$1(d);
  11859. if ((nodeId = currentId(d, i, data)) != null && (nodeId += "")) {
  11860. nodeKey = node.id = nodeId;
  11861. nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
  11862. }
  11863. if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += "")) {
  11864. node.parent = nodeId;
  11865. }
  11866. }
  11867. for (i = 0; i < n; ++i) {
  11868. node = nodes[i];
  11869. if (nodeId = node.parent) {
  11870. parent = nodeByKey.get(nodeId);
  11871. if (!parent) throw new Error("missing: " + nodeId);
  11872. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  11873. if (parent.children) parent.children.push(node);
  11874. else parent.children = [node];
  11875. node.parent = parent;
  11876. } else {
  11877. if (root) throw new Error("multiple roots");
  11878. root = node;
  11879. }
  11880. }
  11881. if (!root) throw new Error("no root");
  11882. // When imputing internal nodes, only introduce roots if needed.
  11883. // Then replace the imputed marker data with null.
  11884. if (path != null) {
  11885. while (root.data === imputed && root.children.length === 1) {
  11886. root = root.children[0], --n;
  11887. }
  11888. for (let i = nodes.length - 1; i >= 0; --i) {
  11889. node = nodes[i];
  11890. if (node.data !== imputed) break;
  11891. node.data = null;
  11892. }
  11893. }
  11894. root.parent = preroot;
  11895. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  11896. root.parent = null;
  11897. if (n > 0) throw new Error("cycle");
  11898. return root;
  11899. }
  11900. stratify.id = function(x) {
  11901. return arguments.length ? (id = optional(x), stratify) : id;
  11902. };
  11903. stratify.parentId = function(x) {
  11904. return arguments.length ? (parentId = optional(x), stratify) : parentId;
  11905. };
  11906. stratify.path = function(x) {
  11907. return arguments.length ? (path = optional(x), stratify) : path;
  11908. };
  11909. return stratify;
  11910. }
  11911. // To normalize a path, we coerce to a string, strip the trailing slash if any
  11912. // (as long as the trailing slash is not immediately preceded by another slash),
  11913. // and add leading slash if missing.
  11914. function normalize$1(path) {
  11915. path = `${path}`;
  11916. let i = path.length;
  11917. if (slash(path, i - 1) && !slash(path, i - 2)) path = path.slice(0, -1);
  11918. return path[0] === "/" ? path : `/${path}`;
  11919. }
  11920. // Walk backwards to find the first slash that is not the leading slash, e.g.:
  11921. // "/foo/bar" ⇥ "/foo", "/foo" ⇥ "/", "/" ↦ "". (The root is special-cased
  11922. // because the id of the root must be a truthy value.)
  11923. function parentof(path) {
  11924. let i = path.length;
  11925. if (i < 2) return "";
  11926. while (--i > 1) if (slash(path, i)) break;
  11927. return path.slice(0, i);
  11928. }
  11929. // Slashes can be escaped; to determine whether a slash is a path delimiter, we
  11930. // count the number of preceding backslashes escaping the forward slash: an odd
  11931. // number indicates an escaped forward slash.
  11932. function slash(path, i) {
  11933. if (path[i] === "/") {
  11934. let k = 0;
  11935. while (i > 0 && path[--i] === "\\") ++k;
  11936. if ((k & 1) === 0) return true;
  11937. }
  11938. return false;
  11939. }
  11940. function defaultSeparation(a, b) {
  11941. return a.parent === b.parent ? 1 : 2;
  11942. }
  11943. // function radialSeparation(a, b) {
  11944. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  11945. // }
  11946. // This function is used to traverse the left contour of a subtree (or
  11947. // subforest). It returns the successor of v on this contour. This successor is
  11948. // either given by the leftmost child of v or by the thread of v. The function
  11949. // returns null if and only if v is on the highest level of its subtree.
  11950. function nextLeft(v) {
  11951. var children = v.children;
  11952. return children ? children[0] : v.t;
  11953. }
  11954. // This function works analogously to nextLeft.
  11955. function nextRight(v) {
  11956. var children = v.children;
  11957. return children ? children[children.length - 1] : v.t;
  11958. }
  11959. // Shifts the current subtree rooted at w+. This is done by increasing
  11960. // prelim(w+) and mod(w+) by shift.
  11961. function moveSubtree(wm, wp, shift) {
  11962. var change = shift / (wp.i - wm.i);
  11963. wp.c -= change;
  11964. wp.s += shift;
  11965. wm.c += change;
  11966. wp.z += shift;
  11967. wp.m += shift;
  11968. }
  11969. // All other shifts, applied to the smaller subtrees between w- and w+, are
  11970. // performed by this function. To prepare the shifts, we have to adjust
  11971. // change(w+), shift(w+), and change(w-).
  11972. function executeShifts(v) {
  11973. var shift = 0,
  11974. change = 0,
  11975. children = v.children,
  11976. i = children.length,
  11977. w;
  11978. while (--i >= 0) {
  11979. w = children[i];
  11980. w.z += shift;
  11981. w.m += shift;
  11982. shift += w.s + (change += w.c);
  11983. }
  11984. }
  11985. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  11986. // returns the specified (default) ancestor.
  11987. function nextAncestor(vim, v, ancestor) {
  11988. return vim.a.parent === v.parent ? vim.a : ancestor;
  11989. }
  11990. function TreeNode(node, i) {
  11991. this._ = node;
  11992. this.parent = null;
  11993. this.children = null;
  11994. this.A = null; // default ancestor
  11995. this.a = this; // ancestor
  11996. this.z = 0; // prelim
  11997. this.m = 0; // mod
  11998. this.c = 0; // change
  11999. this.s = 0; // shift
  12000. this.t = null; // thread
  12001. this.i = i; // number
  12002. }
  12003. TreeNode.prototype = Object.create(Node$1.prototype);
  12004. function treeRoot(root) {
  12005. var tree = new TreeNode(root, 0),
  12006. node,
  12007. nodes = [tree],
  12008. child,
  12009. children,
  12010. i,
  12011. n;
  12012. while (node = nodes.pop()) {
  12013. if (children = node._.children) {
  12014. node.children = new Array(n = children.length);
  12015. for (i = n - 1; i >= 0; --i) {
  12016. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  12017. child.parent = node;
  12018. }
  12019. }
  12020. }
  12021. (tree.parent = new TreeNode(null, 0)).children = [tree];
  12022. return tree;
  12023. }
  12024. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  12025. function tree() {
  12026. var separation = defaultSeparation,
  12027. dx = 1,
  12028. dy = 1,
  12029. nodeSize = null;
  12030. function tree(root) {
  12031. var t = treeRoot(root);
  12032. // Compute the layout using Buchheim et al.’s algorithm.
  12033. t.eachAfter(firstWalk), t.parent.m = -t.z;
  12034. t.eachBefore(secondWalk);
  12035. // If a fixed node size is specified, scale x and y.
  12036. if (nodeSize) root.eachBefore(sizeNode);
  12037. // If a fixed tree size is specified, scale x and y based on the extent.
  12038. // Compute the left-most, right-most, and depth-most nodes for extents.
  12039. else {
  12040. var left = root,
  12041. right = root,
  12042. bottom = root;
  12043. root.eachBefore(function(node) {
  12044. if (node.x < left.x) left = node;
  12045. if (node.x > right.x) right = node;
  12046. if (node.depth > bottom.depth) bottom = node;
  12047. });
  12048. var s = left === right ? 1 : separation(left, right) / 2,
  12049. tx = s - left.x,
  12050. kx = dx / (right.x + s + tx),
  12051. ky = dy / (bottom.depth || 1);
  12052. root.eachBefore(function(node) {
  12053. node.x = (node.x + tx) * kx;
  12054. node.y = node.depth * ky;
  12055. });
  12056. }
  12057. return root;
  12058. }
  12059. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  12060. // applied recursively to the children of v, as well as the function
  12061. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  12062. // node v is placed to the midpoint of its outermost children.
  12063. function firstWalk(v) {
  12064. var children = v.children,
  12065. siblings = v.parent.children,
  12066. w = v.i ? siblings[v.i - 1] : null;
  12067. if (children) {
  12068. executeShifts(v);
  12069. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  12070. if (w) {
  12071. v.z = w.z + separation(v._, w._);
  12072. v.m = v.z - midpoint;
  12073. } else {
  12074. v.z = midpoint;
  12075. }
  12076. } else if (w) {
  12077. v.z = w.z + separation(v._, w._);
  12078. }
  12079. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  12080. }
  12081. // Computes all real x-coordinates by summing up the modifiers recursively.
  12082. function secondWalk(v) {
  12083. v._.x = v.z + v.parent.m;
  12084. v.m += v.parent.m;
  12085. }
  12086. // The core of the algorithm. Here, a new subtree is combined with the
  12087. // previous subtrees. Threads are used to traverse the inside and outside
  12088. // contours of the left and right subtree up to the highest common level. The
  12089. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  12090. // superscript o means outside and i means inside, the subscript - means left
  12091. // subtree and + means right subtree. For summing up the modifiers along the
  12092. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  12093. // nodes of the inside contours conflict, we compute the left one of the
  12094. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  12095. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  12096. // Finally, we add a new thread (if necessary).
  12097. function apportion(v, w, ancestor) {
  12098. if (w) {
  12099. var vip = v,
  12100. vop = v,
  12101. vim = w,
  12102. vom = vip.parent.children[0],
  12103. sip = vip.m,
  12104. sop = vop.m,
  12105. sim = vim.m,
  12106. som = vom.m,
  12107. shift;
  12108. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  12109. vom = nextLeft(vom);
  12110. vop = nextRight(vop);
  12111. vop.a = v;
  12112. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  12113. if (shift > 0) {
  12114. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  12115. sip += shift;
  12116. sop += shift;
  12117. }
  12118. sim += vim.m;
  12119. sip += vip.m;
  12120. som += vom.m;
  12121. sop += vop.m;
  12122. }
  12123. if (vim && !nextRight(vop)) {
  12124. vop.t = vim;
  12125. vop.m += sim - sop;
  12126. }
  12127. if (vip && !nextLeft(vom)) {
  12128. vom.t = vip;
  12129. vom.m += sip - som;
  12130. ancestor = v;
  12131. }
  12132. }
  12133. return ancestor;
  12134. }
  12135. function sizeNode(node) {
  12136. node.x *= dx;
  12137. node.y = node.depth * dy;
  12138. }
  12139. tree.separation = function(x) {
  12140. return arguments.length ? (separation = x, tree) : separation;
  12141. };
  12142. tree.size = function(x) {
  12143. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  12144. };
  12145. tree.nodeSize = function(x) {
  12146. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  12147. };
  12148. return tree;
  12149. }
  12150. function treemapSlice(parent, x0, y0, x1, y1) {
  12151. var nodes = parent.children,
  12152. node,
  12153. i = -1,
  12154. n = nodes.length,
  12155. k = parent.value && (y1 - y0) / parent.value;
  12156. while (++i < n) {
  12157. node = nodes[i], node.x0 = x0, node.x1 = x1;
  12158. node.y0 = y0, node.y1 = y0 += node.value * k;
  12159. }
  12160. }
  12161. var phi = (1 + Math.sqrt(5)) / 2;
  12162. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  12163. var rows = [],
  12164. nodes = parent.children,
  12165. row,
  12166. nodeValue,
  12167. i0 = 0,
  12168. i1 = 0,
  12169. n = nodes.length,
  12170. dx, dy,
  12171. value = parent.value,
  12172. sumValue,
  12173. minValue,
  12174. maxValue,
  12175. newRatio,
  12176. minRatio,
  12177. alpha,
  12178. beta;
  12179. while (i0 < n) {
  12180. dx = x1 - x0, dy = y1 - y0;
  12181. // Find the next non-empty node.
  12182. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  12183. minValue = maxValue = sumValue;
  12184. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  12185. beta = sumValue * sumValue * alpha;
  12186. minRatio = Math.max(maxValue / beta, beta / minValue);
  12187. // Keep adding nodes while the aspect ratio maintains or improves.
  12188. for (; i1 < n; ++i1) {
  12189. sumValue += nodeValue = nodes[i1].value;
  12190. if (nodeValue < minValue) minValue = nodeValue;
  12191. if (nodeValue > maxValue) maxValue = nodeValue;
  12192. beta = sumValue * sumValue * alpha;
  12193. newRatio = Math.max(maxValue / beta, beta / minValue);
  12194. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  12195. minRatio = newRatio;
  12196. }
  12197. // Position and record the row orientation.
  12198. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  12199. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  12200. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  12201. value -= sumValue, i0 = i1;
  12202. }
  12203. return rows;
  12204. }
  12205. var squarify = (function custom(ratio) {
  12206. function squarify(parent, x0, y0, x1, y1) {
  12207. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  12208. }
  12209. squarify.ratio = function(x) {
  12210. return custom((x = +x) > 1 ? x : 1);
  12211. };
  12212. return squarify;
  12213. })(phi);
  12214. function index() {
  12215. var tile = squarify,
  12216. round = false,
  12217. dx = 1,
  12218. dy = 1,
  12219. paddingStack = [0],
  12220. paddingInner = constantZero,
  12221. paddingTop = constantZero,
  12222. paddingRight = constantZero,
  12223. paddingBottom = constantZero,
  12224. paddingLeft = constantZero;
  12225. function treemap(root) {
  12226. root.x0 =
  12227. root.y0 = 0;
  12228. root.x1 = dx;
  12229. root.y1 = dy;
  12230. root.eachBefore(positionNode);
  12231. paddingStack = [0];
  12232. if (round) root.eachBefore(roundNode);
  12233. return root;
  12234. }
  12235. function positionNode(node) {
  12236. var p = paddingStack[node.depth],
  12237. x0 = node.x0 + p,
  12238. y0 = node.y0 + p,
  12239. x1 = node.x1 - p,
  12240. y1 = node.y1 - p;
  12241. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  12242. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  12243. node.x0 = x0;
  12244. node.y0 = y0;
  12245. node.x1 = x1;
  12246. node.y1 = y1;
  12247. if (node.children) {
  12248. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  12249. x0 += paddingLeft(node) - p;
  12250. y0 += paddingTop(node) - p;
  12251. x1 -= paddingRight(node) - p;
  12252. y1 -= paddingBottom(node) - p;
  12253. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  12254. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  12255. tile(node, x0, y0, x1, y1);
  12256. }
  12257. }
  12258. treemap.round = function(x) {
  12259. return arguments.length ? (round = !!x, treemap) : round;
  12260. };
  12261. treemap.size = function(x) {
  12262. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  12263. };
  12264. treemap.tile = function(x) {
  12265. return arguments.length ? (tile = required(x), treemap) : tile;
  12266. };
  12267. treemap.padding = function(x) {
  12268. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  12269. };
  12270. treemap.paddingInner = function(x) {
  12271. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$2(+x), treemap) : paddingInner;
  12272. };
  12273. treemap.paddingOuter = function(x) {
  12274. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  12275. };
  12276. treemap.paddingTop = function(x) {
  12277. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$2(+x), treemap) : paddingTop;
  12278. };
  12279. treemap.paddingRight = function(x) {
  12280. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$2(+x), treemap) : paddingRight;
  12281. };
  12282. treemap.paddingBottom = function(x) {
  12283. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$2(+x), treemap) : paddingBottom;
  12284. };
  12285. treemap.paddingLeft = function(x) {
  12286. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$2(+x), treemap) : paddingLeft;
  12287. };
  12288. return treemap;
  12289. }
  12290. function binary(parent, x0, y0, x1, y1) {
  12291. var nodes = parent.children,
  12292. i, n = nodes.length,
  12293. sum, sums = new Array(n + 1);
  12294. for (sums[0] = sum = i = 0; i < n; ++i) {
  12295. sums[i + 1] = sum += nodes[i].value;
  12296. }
  12297. partition(0, n, parent.value, x0, y0, x1, y1);
  12298. function partition(i, j, value, x0, y0, x1, y1) {
  12299. if (i >= j - 1) {
  12300. var node = nodes[i];
  12301. node.x0 = x0, node.y0 = y0;
  12302. node.x1 = x1, node.y1 = y1;
  12303. return;
  12304. }
  12305. var valueOffset = sums[i],
  12306. valueTarget = (value / 2) + valueOffset,
  12307. k = i + 1,
  12308. hi = j - 1;
  12309. while (k < hi) {
  12310. var mid = k + hi >>> 1;
  12311. if (sums[mid] < valueTarget) k = mid + 1;
  12312. else hi = mid;
  12313. }
  12314. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  12315. var valueLeft = sums[k] - valueOffset,
  12316. valueRight = value - valueLeft;
  12317. if ((x1 - x0) > (y1 - y0)) {
  12318. var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
  12319. partition(i, k, valueLeft, x0, y0, xk, y1);
  12320. partition(k, j, valueRight, xk, y0, x1, y1);
  12321. } else {
  12322. var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
  12323. partition(i, k, valueLeft, x0, y0, x1, yk);
  12324. partition(k, j, valueRight, x0, yk, x1, y1);
  12325. }
  12326. }
  12327. }
  12328. function sliceDice(parent, x0, y0, x1, y1) {
  12329. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  12330. }
  12331. var resquarify = (function custom(ratio) {
  12332. function resquarify(parent, x0, y0, x1, y1) {
  12333. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  12334. var rows,
  12335. row,
  12336. nodes,
  12337. i,
  12338. j = -1,
  12339. n,
  12340. m = rows.length,
  12341. value = parent.value;
  12342. while (++j < m) {
  12343. row = rows[j], nodes = row.children;
  12344. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  12345. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1);
  12346. else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1);
  12347. value -= row.value;
  12348. }
  12349. } else {
  12350. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  12351. rows.ratio = ratio;
  12352. }
  12353. }
  12354. resquarify.ratio = function(x) {
  12355. return custom((x = +x) > 1 ? x : 1);
  12356. };
  12357. return resquarify;
  12358. })(phi);
  12359. function area$1(polygon) {
  12360. var i = -1,
  12361. n = polygon.length,
  12362. a,
  12363. b = polygon[n - 1],
  12364. area = 0;
  12365. while (++i < n) {
  12366. a = b;
  12367. b = polygon[i];
  12368. area += a[1] * b[0] - a[0] * b[1];
  12369. }
  12370. return area / 2;
  12371. }
  12372. function centroid(polygon) {
  12373. var i = -1,
  12374. n = polygon.length,
  12375. x = 0,
  12376. y = 0,
  12377. a,
  12378. b = polygon[n - 1],
  12379. c,
  12380. k = 0;
  12381. while (++i < n) {
  12382. a = b;
  12383. b = polygon[i];
  12384. k += c = a[0] * b[1] - b[0] * a[1];
  12385. x += (a[0] + b[0]) * c;
  12386. y += (a[1] + b[1]) * c;
  12387. }
  12388. return k *= 3, [x / k, y / k];
  12389. }
  12390. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  12391. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  12392. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  12393. // negative if clockwise, and zero if the points are collinear.
  12394. function cross$1(a, b, c) {
  12395. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  12396. }
  12397. function lexicographicOrder(a, b) {
  12398. return a[0] - b[0] || a[1] - b[1];
  12399. }
  12400. // Computes the upper convex hull per the monotone chain algorithm.
  12401. // Assumes points.length >= 3, is sorted by x, unique in y.
  12402. // Returns an array of indices into points in left-to-right order.
  12403. function computeUpperHullIndexes(points) {
  12404. const n = points.length,
  12405. indexes = [0, 1];
  12406. let size = 2, i;
  12407. for (i = 2; i < n; ++i) {
  12408. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  12409. indexes[size++] = i;
  12410. }
  12411. return indexes.slice(0, size); // remove popped points
  12412. }
  12413. function hull(points) {
  12414. if ((n = points.length) < 3) return null;
  12415. var i,
  12416. n,
  12417. sortedPoints = new Array(n),
  12418. flippedPoints = new Array(n);
  12419. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  12420. sortedPoints.sort(lexicographicOrder);
  12421. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  12422. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  12423. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  12424. // Construct the hull polygon, removing possible duplicate endpoints.
  12425. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  12426. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  12427. hull = [];
  12428. // Add upper hull in right-to-l order.
  12429. // Then add lower hull in left-to-right order.
  12430. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  12431. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  12432. return hull;
  12433. }
  12434. function contains(polygon, point) {
  12435. var n = polygon.length,
  12436. p = polygon[n - 1],
  12437. x = point[0], y = point[1],
  12438. x0 = p[0], y0 = p[1],
  12439. x1, y1,
  12440. inside = false;
  12441. for (var i = 0; i < n; ++i) {
  12442. p = polygon[i], x1 = p[0], y1 = p[1];
  12443. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  12444. x0 = x1, y0 = y1;
  12445. }
  12446. return inside;
  12447. }
  12448. function length(polygon) {
  12449. var i = -1,
  12450. n = polygon.length,
  12451. b = polygon[n - 1],
  12452. xa,
  12453. ya,
  12454. xb = b[0],
  12455. yb = b[1],
  12456. perimeter = 0;
  12457. while (++i < n) {
  12458. xa = xb;
  12459. ya = yb;
  12460. b = polygon[i];
  12461. xb = b[0];
  12462. yb = b[1];
  12463. xa -= xb;
  12464. ya -= yb;
  12465. perimeter += Math.hypot(xa, ya);
  12466. }
  12467. return perimeter;
  12468. }
  12469. var defaultSource = Math.random;
  12470. var uniform = (function sourceRandomUniform(source) {
  12471. function randomUniform(min, max) {
  12472. min = min == null ? 0 : +min;
  12473. max = max == null ? 1 : +max;
  12474. if (arguments.length === 1) max = min, min = 0;
  12475. else max -= min;
  12476. return function() {
  12477. return source() * max + min;
  12478. };
  12479. }
  12480. randomUniform.source = sourceRandomUniform;
  12481. return randomUniform;
  12482. })(defaultSource);
  12483. var int = (function sourceRandomInt(source) {
  12484. function randomInt(min, max) {
  12485. if (arguments.length < 2) max = min, min = 0;
  12486. min = Math.floor(min);
  12487. max = Math.floor(max) - min;
  12488. return function() {
  12489. return Math.floor(source() * max + min);
  12490. };
  12491. }
  12492. randomInt.source = sourceRandomInt;
  12493. return randomInt;
  12494. })(defaultSource);
  12495. var normal = (function sourceRandomNormal(source) {
  12496. function randomNormal(mu, sigma) {
  12497. var x, r;
  12498. mu = mu == null ? 0 : +mu;
  12499. sigma = sigma == null ? 1 : +sigma;
  12500. return function() {
  12501. var y;
  12502. // If available, use the second previously-generated uniform random.
  12503. if (x != null) y = x, x = null;
  12504. // Otherwise, generate a new x and y.
  12505. else do {
  12506. x = source() * 2 - 1;
  12507. y = source() * 2 - 1;
  12508. r = x * x + y * y;
  12509. } while (!r || r > 1);
  12510. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  12511. };
  12512. }
  12513. randomNormal.source = sourceRandomNormal;
  12514. return randomNormal;
  12515. })(defaultSource);
  12516. var logNormal = (function sourceRandomLogNormal(source) {
  12517. var N = normal.source(source);
  12518. function randomLogNormal() {
  12519. var randomNormal = N.apply(this, arguments);
  12520. return function() {
  12521. return Math.exp(randomNormal());
  12522. };
  12523. }
  12524. randomLogNormal.source = sourceRandomLogNormal;
  12525. return randomLogNormal;
  12526. })(defaultSource);
  12527. var irwinHall = (function sourceRandomIrwinHall(source) {
  12528. function randomIrwinHall(n) {
  12529. if ((n = +n) <= 0) return () => 0;
  12530. return function() {
  12531. for (var sum = 0, i = n; i > 1; --i) sum += source();
  12532. return sum + i * source();
  12533. };
  12534. }
  12535. randomIrwinHall.source = sourceRandomIrwinHall;
  12536. return randomIrwinHall;
  12537. })(defaultSource);
  12538. var bates = (function sourceRandomBates(source) {
  12539. var I = irwinHall.source(source);
  12540. function randomBates(n) {
  12541. // use limiting distribution at n === 0
  12542. if ((n = +n) === 0) return source;
  12543. var randomIrwinHall = I(n);
  12544. return function() {
  12545. return randomIrwinHall() / n;
  12546. };
  12547. }
  12548. randomBates.source = sourceRandomBates;
  12549. return randomBates;
  12550. })(defaultSource);
  12551. var exponential = (function sourceRandomExponential(source) {
  12552. function randomExponential(lambda) {
  12553. return function() {
  12554. return -Math.log1p(-source()) / lambda;
  12555. };
  12556. }
  12557. randomExponential.source = sourceRandomExponential;
  12558. return randomExponential;
  12559. })(defaultSource);
  12560. var pareto = (function sourceRandomPareto(source) {
  12561. function randomPareto(alpha) {
  12562. if ((alpha = +alpha) < 0) throw new RangeError("invalid alpha");
  12563. alpha = 1 / -alpha;
  12564. return function() {
  12565. return Math.pow(1 - source(), alpha);
  12566. };
  12567. }
  12568. randomPareto.source = sourceRandomPareto;
  12569. return randomPareto;
  12570. })(defaultSource);
  12571. var bernoulli = (function sourceRandomBernoulli(source) {
  12572. function randomBernoulli(p) {
  12573. if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
  12574. return function() {
  12575. return Math.floor(source() + p);
  12576. };
  12577. }
  12578. randomBernoulli.source = sourceRandomBernoulli;
  12579. return randomBernoulli;
  12580. })(defaultSource);
  12581. var geometric = (function sourceRandomGeometric(source) {
  12582. function randomGeometric(p) {
  12583. if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
  12584. if (p === 0) return () => Infinity;
  12585. if (p === 1) return () => 1;
  12586. p = Math.log1p(-p);
  12587. return function() {
  12588. return 1 + Math.floor(Math.log1p(-source()) / p);
  12589. };
  12590. }
  12591. randomGeometric.source = sourceRandomGeometric;
  12592. return randomGeometric;
  12593. })(defaultSource);
  12594. var gamma = (function sourceRandomGamma(source) {
  12595. var randomNormal = normal.source(source)();
  12596. function randomGamma(k, theta) {
  12597. if ((k = +k) < 0) throw new RangeError("invalid k");
  12598. // degenerate distribution if k === 0
  12599. if (k === 0) return () => 0;
  12600. theta = theta == null ? 1 : +theta;
  12601. // exponential distribution if k === 1
  12602. if (k === 1) return () => -Math.log1p(-source()) * theta;
  12603. var d = (k < 1 ? k + 1 : k) - 1 / 3,
  12604. c = 1 / (3 * Math.sqrt(d)),
  12605. multiplier = k < 1 ? () => Math.pow(source(), 1 / k) : () => 1;
  12606. return function() {
  12607. do {
  12608. do {
  12609. var x = randomNormal(),
  12610. v = 1 + c * x;
  12611. } while (v <= 0);
  12612. v *= v * v;
  12613. var u = 1 - source();
  12614. } while (u >= 1 - 0.0331 * x * x * x * x && Math.log(u) >= 0.5 * x * x + d * (1 - v + Math.log(v)));
  12615. return d * v * multiplier() * theta;
  12616. };
  12617. }
  12618. randomGamma.source = sourceRandomGamma;
  12619. return randomGamma;
  12620. })(defaultSource);
  12621. var beta = (function sourceRandomBeta(source) {
  12622. var G = gamma.source(source);
  12623. function randomBeta(alpha, beta) {
  12624. var X = G(alpha),
  12625. Y = G(beta);
  12626. return function() {
  12627. var x = X();
  12628. return x === 0 ? 0 : x / (x + Y());
  12629. };
  12630. }
  12631. randomBeta.source = sourceRandomBeta;
  12632. return randomBeta;
  12633. })(defaultSource);
  12634. var binomial = (function sourceRandomBinomial(source) {
  12635. var G = geometric.source(source),
  12636. B = beta.source(source);
  12637. function randomBinomial(n, p) {
  12638. n = +n;
  12639. if ((p = +p) >= 1) return () => n;
  12640. if (p <= 0) return () => 0;
  12641. return function() {
  12642. var acc = 0, nn = n, pp = p;
  12643. while (nn * pp > 16 && nn * (1 - pp) > 16) {
  12644. var i = Math.floor((nn + 1) * pp),
  12645. y = B(i, nn - i + 1)();
  12646. if (y <= pp) {
  12647. acc += i;
  12648. nn -= i;
  12649. pp = (pp - y) / (1 - y);
  12650. } else {
  12651. nn = i - 1;
  12652. pp /= y;
  12653. }
  12654. }
  12655. var sign = pp < 0.5,
  12656. pFinal = sign ? pp : 1 - pp,
  12657. g = G(pFinal);
  12658. for (var s = g(), k = 0; s <= nn; ++k) s += g();
  12659. return acc + (sign ? k : nn - k);
  12660. };
  12661. }
  12662. randomBinomial.source = sourceRandomBinomial;
  12663. return randomBinomial;
  12664. })(defaultSource);
  12665. var weibull = (function sourceRandomWeibull(source) {
  12666. function randomWeibull(k, a, b) {
  12667. var outerFunc;
  12668. if ((k = +k) === 0) {
  12669. outerFunc = x => -Math.log(x);
  12670. } else {
  12671. k = 1 / k;
  12672. outerFunc = x => Math.pow(x, k);
  12673. }
  12674. a = a == null ? 0 : +a;
  12675. b = b == null ? 1 : +b;
  12676. return function() {
  12677. return a + b * outerFunc(-Math.log1p(-source()));
  12678. };
  12679. }
  12680. randomWeibull.source = sourceRandomWeibull;
  12681. return randomWeibull;
  12682. })(defaultSource);
  12683. var cauchy = (function sourceRandomCauchy(source) {
  12684. function randomCauchy(a, b) {
  12685. a = a == null ? 0 : +a;
  12686. b = b == null ? 1 : +b;
  12687. return function() {
  12688. return a + b * Math.tan(Math.PI * source());
  12689. };
  12690. }
  12691. randomCauchy.source = sourceRandomCauchy;
  12692. return randomCauchy;
  12693. })(defaultSource);
  12694. var logistic = (function sourceRandomLogistic(source) {
  12695. function randomLogistic(a, b) {
  12696. a = a == null ? 0 : +a;
  12697. b = b == null ? 1 : +b;
  12698. return function() {
  12699. var u = source();
  12700. return a + b * Math.log(u / (1 - u));
  12701. };
  12702. }
  12703. randomLogistic.source = sourceRandomLogistic;
  12704. return randomLogistic;
  12705. })(defaultSource);
  12706. var poisson = (function sourceRandomPoisson(source) {
  12707. var G = gamma.source(source),
  12708. B = binomial.source(source);
  12709. function randomPoisson(lambda) {
  12710. return function() {
  12711. var acc = 0, l = lambda;
  12712. while (l > 16) {
  12713. var n = Math.floor(0.875 * l),
  12714. t = G(n)();
  12715. if (t > l) return acc + B(n - 1, l / t)();
  12716. acc += n;
  12717. l -= t;
  12718. }
  12719. for (var s = -Math.log1p(-source()), k = 0; s <= l; ++k) s -= Math.log1p(-source());
  12720. return acc + k;
  12721. };
  12722. }
  12723. randomPoisson.source = sourceRandomPoisson;
  12724. return randomPoisson;
  12725. })(defaultSource);
  12726. // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  12727. const mul = 0x19660D;
  12728. const inc = 0x3C6EF35F;
  12729. const eps = 1 / 0x100000000;
  12730. function lcg(seed = Math.random()) {
  12731. let state = (0 <= seed && seed < 1 ? seed / eps : Math.abs(seed)) | 0;
  12732. return () => (state = mul * state + inc | 0, eps * (state >>> 0));
  12733. }
  12734. function initRange(domain, range) {
  12735. switch (arguments.length) {
  12736. case 0: break;
  12737. case 1: this.range(domain); break;
  12738. default: this.range(range).domain(domain); break;
  12739. }
  12740. return this;
  12741. }
  12742. function initInterpolator(domain, interpolator) {
  12743. switch (arguments.length) {
  12744. case 0: break;
  12745. case 1: {
  12746. if (typeof domain === "function") this.interpolator(domain);
  12747. else this.range(domain);
  12748. break;
  12749. }
  12750. default: {
  12751. this.domain(domain);
  12752. if (typeof interpolator === "function") this.interpolator(interpolator);
  12753. else this.range(interpolator);
  12754. break;
  12755. }
  12756. }
  12757. return this;
  12758. }
  12759. const implicit = Symbol("implicit");
  12760. function ordinal() {
  12761. var index = new InternMap(),
  12762. domain = [],
  12763. range = [],
  12764. unknown = implicit;
  12765. function scale(d) {
  12766. let i = index.get(d);
  12767. if (i === undefined) {
  12768. if (unknown !== implicit) return unknown;
  12769. index.set(d, i = domain.push(d) - 1);
  12770. }
  12771. return range[i % range.length];
  12772. }
  12773. scale.domain = function(_) {
  12774. if (!arguments.length) return domain.slice();
  12775. domain = [], index = new InternMap();
  12776. for (const value of _) {
  12777. if (index.has(value)) continue;
  12778. index.set(value, domain.push(value) - 1);
  12779. }
  12780. return scale;
  12781. };
  12782. scale.range = function(_) {
  12783. return arguments.length ? (range = Array.from(_), scale) : range.slice();
  12784. };
  12785. scale.unknown = function(_) {
  12786. return arguments.length ? (unknown = _, scale) : unknown;
  12787. };
  12788. scale.copy = function() {
  12789. return ordinal(domain, range).unknown(unknown);
  12790. };
  12791. initRange.apply(scale, arguments);
  12792. return scale;
  12793. }
  12794. function band() {
  12795. var scale = ordinal().unknown(undefined),
  12796. domain = scale.domain,
  12797. ordinalRange = scale.range,
  12798. r0 = 0,
  12799. r1 = 1,
  12800. step,
  12801. bandwidth,
  12802. round = false,
  12803. paddingInner = 0,
  12804. paddingOuter = 0,
  12805. align = 0.5;
  12806. delete scale.unknown;
  12807. function rescale() {
  12808. var n = domain().length,
  12809. reverse = r1 < r0,
  12810. start = reverse ? r1 : r0,
  12811. stop = reverse ? r0 : r1;
  12812. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  12813. if (round) step = Math.floor(step);
  12814. start += (stop - start - step * (n - paddingInner)) * align;
  12815. bandwidth = step * (1 - paddingInner);
  12816. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  12817. var values = range$2(n).map(function(i) { return start + step * i; });
  12818. return ordinalRange(reverse ? values.reverse() : values);
  12819. }
  12820. scale.domain = function(_) {
  12821. return arguments.length ? (domain(_), rescale()) : domain();
  12822. };
  12823. scale.range = function(_) {
  12824. return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
  12825. };
  12826. scale.rangeRound = function(_) {
  12827. return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
  12828. };
  12829. scale.bandwidth = function() {
  12830. return bandwidth;
  12831. };
  12832. scale.step = function() {
  12833. return step;
  12834. };
  12835. scale.round = function(_) {
  12836. return arguments.length ? (round = !!_, rescale()) : round;
  12837. };
  12838. scale.padding = function(_) {
  12839. return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
  12840. };
  12841. scale.paddingInner = function(_) {
  12842. return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
  12843. };
  12844. scale.paddingOuter = function(_) {
  12845. return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
  12846. };
  12847. scale.align = function(_) {
  12848. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  12849. };
  12850. scale.copy = function() {
  12851. return band(domain(), [r0, r1])
  12852. .round(round)
  12853. .paddingInner(paddingInner)
  12854. .paddingOuter(paddingOuter)
  12855. .align(align);
  12856. };
  12857. return initRange.apply(rescale(), arguments);
  12858. }
  12859. function pointish(scale) {
  12860. var copy = scale.copy;
  12861. scale.padding = scale.paddingOuter;
  12862. delete scale.paddingInner;
  12863. delete scale.paddingOuter;
  12864. scale.copy = function() {
  12865. return pointish(copy());
  12866. };
  12867. return scale;
  12868. }
  12869. function point$4() {
  12870. return pointish(band.apply(null, arguments).paddingInner(1));
  12871. }
  12872. function constants(x) {
  12873. return function() {
  12874. return x;
  12875. };
  12876. }
  12877. function number$1(x) {
  12878. return +x;
  12879. }
  12880. var unit = [0, 1];
  12881. function identity$3(x) {
  12882. return x;
  12883. }
  12884. function normalize(a, b) {
  12885. return (b -= (a = +a))
  12886. ? function(x) { return (x - a) / b; }
  12887. : constants(isNaN(b) ? NaN : 0.5);
  12888. }
  12889. function clamper(a, b) {
  12890. var t;
  12891. if (a > b) t = a, a = b, b = t;
  12892. return function(x) { return Math.max(a, Math.min(b, x)); };
  12893. }
  12894. // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  12895. // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
  12896. function bimap(domain, range, interpolate) {
  12897. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  12898. if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
  12899. else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
  12900. return function(x) { return r0(d0(x)); };
  12901. }
  12902. function polymap(domain, range, interpolate) {
  12903. var j = Math.min(domain.length, range.length) - 1,
  12904. d = new Array(j),
  12905. r = new Array(j),
  12906. i = -1;
  12907. // Reverse descending domains.
  12908. if (domain[j] < domain[0]) {
  12909. domain = domain.slice().reverse();
  12910. range = range.slice().reverse();
  12911. }
  12912. while (++i < j) {
  12913. d[i] = normalize(domain[i], domain[i + 1]);
  12914. r[i] = interpolate(range[i], range[i + 1]);
  12915. }
  12916. return function(x) {
  12917. var i = bisect(domain, x, 1, j) - 1;
  12918. return r[i](d[i](x));
  12919. };
  12920. }
  12921. function copy$1(source, target) {
  12922. return target
  12923. .domain(source.domain())
  12924. .range(source.range())
  12925. .interpolate(source.interpolate())
  12926. .clamp(source.clamp())
  12927. .unknown(source.unknown());
  12928. }
  12929. function transformer$2() {
  12930. var domain = unit,
  12931. range = unit,
  12932. interpolate = interpolate$2,
  12933. transform,
  12934. untransform,
  12935. unknown,
  12936. clamp = identity$3,
  12937. piecewise,
  12938. output,
  12939. input;
  12940. function rescale() {
  12941. var n = Math.min(domain.length, range.length);
  12942. if (clamp !== identity$3) clamp = clamper(domain[0], domain[n - 1]);
  12943. piecewise = n > 2 ? polymap : bimap;
  12944. output = input = null;
  12945. return scale;
  12946. }
  12947. function scale(x) {
  12948. return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
  12949. }
  12950. scale.invert = function(y) {
  12951. return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
  12952. };
  12953. scale.domain = function(_) {
  12954. return arguments.length ? (domain = Array.from(_, number$1), rescale()) : domain.slice();
  12955. };
  12956. scale.range = function(_) {
  12957. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  12958. };
  12959. scale.rangeRound = function(_) {
  12960. return range = Array.from(_), interpolate = interpolateRound, rescale();
  12961. };
  12962. scale.clamp = function(_) {
  12963. return arguments.length ? (clamp = _ ? true : identity$3, rescale()) : clamp !== identity$3;
  12964. };
  12965. scale.interpolate = function(_) {
  12966. return arguments.length ? (interpolate = _, rescale()) : interpolate;
  12967. };
  12968. scale.unknown = function(_) {
  12969. return arguments.length ? (unknown = _, scale) : unknown;
  12970. };
  12971. return function(t, u) {
  12972. transform = t, untransform = u;
  12973. return rescale();
  12974. };
  12975. }
  12976. function continuous() {
  12977. return transformer$2()(identity$3, identity$3);
  12978. }
  12979. function tickFormat(start, stop, count, specifier) {
  12980. var step = tickStep(start, stop, count),
  12981. precision;
  12982. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  12983. switch (specifier.type) {
  12984. case "s": {
  12985. var value = Math.max(Math.abs(start), Math.abs(stop));
  12986. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  12987. return exports.formatPrefix(specifier, value);
  12988. }
  12989. case "":
  12990. case "e":
  12991. case "g":
  12992. case "p":
  12993. case "r": {
  12994. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  12995. break;
  12996. }
  12997. case "f":
  12998. case "%": {
  12999. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  13000. break;
  13001. }
  13002. }
  13003. return exports.format(specifier);
  13004. }
  13005. function linearish(scale) {
  13006. var domain = scale.domain;
  13007. scale.ticks = function(count) {
  13008. var d = domain();
  13009. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  13010. };
  13011. scale.tickFormat = function(count, specifier) {
  13012. var d = domain();
  13013. return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
  13014. };
  13015. scale.nice = function(count) {
  13016. if (count == null) count = 10;
  13017. var d = domain();
  13018. var i0 = 0;
  13019. var i1 = d.length - 1;
  13020. var start = d[i0];
  13021. var stop = d[i1];
  13022. var prestep;
  13023. var step;
  13024. var maxIter = 10;
  13025. if (stop < start) {
  13026. step = start, start = stop, stop = step;
  13027. step = i0, i0 = i1, i1 = step;
  13028. }
  13029. while (maxIter-- > 0) {
  13030. step = tickIncrement(start, stop, count);
  13031. if (step === prestep) {
  13032. d[i0] = start;
  13033. d[i1] = stop;
  13034. return domain(d);
  13035. } else if (step > 0) {
  13036. start = Math.floor(start / step) * step;
  13037. stop = Math.ceil(stop / step) * step;
  13038. } else if (step < 0) {
  13039. start = Math.ceil(start * step) / step;
  13040. stop = Math.floor(stop * step) / step;
  13041. } else {
  13042. break;
  13043. }
  13044. prestep = step;
  13045. }
  13046. return scale;
  13047. };
  13048. return scale;
  13049. }
  13050. function linear() {
  13051. var scale = continuous();
  13052. scale.copy = function() {
  13053. return copy$1(scale, linear());
  13054. };
  13055. initRange.apply(scale, arguments);
  13056. return linearish(scale);
  13057. }
  13058. function identity$2(domain) {
  13059. var unknown;
  13060. function scale(x) {
  13061. return x == null || isNaN(x = +x) ? unknown : x;
  13062. }
  13063. scale.invert = scale;
  13064. scale.domain = scale.range = function(_) {
  13065. return arguments.length ? (domain = Array.from(_, number$1), scale) : domain.slice();
  13066. };
  13067. scale.unknown = function(_) {
  13068. return arguments.length ? (unknown = _, scale) : unknown;
  13069. };
  13070. scale.copy = function() {
  13071. return identity$2(domain).unknown(unknown);
  13072. };
  13073. domain = arguments.length ? Array.from(domain, number$1) : [0, 1];
  13074. return linearish(scale);
  13075. }
  13076. function nice(domain, interval) {
  13077. domain = domain.slice();
  13078. var i0 = 0,
  13079. i1 = domain.length - 1,
  13080. x0 = domain[i0],
  13081. x1 = domain[i1],
  13082. t;
  13083. if (x1 < x0) {
  13084. t = i0, i0 = i1, i1 = t;
  13085. t = x0, x0 = x1, x1 = t;
  13086. }
  13087. domain[i0] = interval.floor(x0);
  13088. domain[i1] = interval.ceil(x1);
  13089. return domain;
  13090. }
  13091. function transformLog(x) {
  13092. return Math.log(x);
  13093. }
  13094. function transformExp(x) {
  13095. return Math.exp(x);
  13096. }
  13097. function transformLogn(x) {
  13098. return -Math.log(-x);
  13099. }
  13100. function transformExpn(x) {
  13101. return -Math.exp(-x);
  13102. }
  13103. function pow10(x) {
  13104. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  13105. }
  13106. function powp(base) {
  13107. return base === 10 ? pow10
  13108. : base === Math.E ? Math.exp
  13109. : x => Math.pow(base, x);
  13110. }
  13111. function logp(base) {
  13112. return base === Math.E ? Math.log
  13113. : base === 10 && Math.log10
  13114. || base === 2 && Math.log2
  13115. || (base = Math.log(base), x => Math.log(x) / base);
  13116. }
  13117. function reflect(f) {
  13118. return (x, k) => -f(-x, k);
  13119. }
  13120. function loggish(transform) {
  13121. const scale = transform(transformLog, transformExp);
  13122. const domain = scale.domain;
  13123. let base = 10;
  13124. let logs;
  13125. let pows;
  13126. function rescale() {
  13127. logs = logp(base), pows = powp(base);
  13128. if (domain()[0] < 0) {
  13129. logs = reflect(logs), pows = reflect(pows);
  13130. transform(transformLogn, transformExpn);
  13131. } else {
  13132. transform(transformLog, transformExp);
  13133. }
  13134. return scale;
  13135. }
  13136. scale.base = function(_) {
  13137. return arguments.length ? (base = +_, rescale()) : base;
  13138. };
  13139. scale.domain = function(_) {
  13140. return arguments.length ? (domain(_), rescale()) : domain();
  13141. };
  13142. scale.ticks = count => {
  13143. const d = domain();
  13144. let u = d[0];
  13145. let v = d[d.length - 1];
  13146. const r = v < u;
  13147. if (r) ([u, v] = [v, u]);
  13148. let i = logs(u);
  13149. let j = logs(v);
  13150. let k;
  13151. let t;
  13152. const n = count == null ? 10 : +count;
  13153. let z = [];
  13154. if (!(base % 1) && j - i < n) {
  13155. i = Math.floor(i), j = Math.ceil(j);
  13156. if (u > 0) for (; i <= j; ++i) {
  13157. for (k = 1; k < base; ++k) {
  13158. t = i < 0 ? k / pows(-i) : k * pows(i);
  13159. if (t < u) continue;
  13160. if (t > v) break;
  13161. z.push(t);
  13162. }
  13163. } else for (; i <= j; ++i) {
  13164. for (k = base - 1; k >= 1; --k) {
  13165. t = i > 0 ? k / pows(-i) : k * pows(i);
  13166. if (t < u) continue;
  13167. if (t > v) break;
  13168. z.push(t);
  13169. }
  13170. }
  13171. if (z.length * 2 < n) z = ticks(u, v, n);
  13172. } else {
  13173. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  13174. }
  13175. return r ? z.reverse() : z;
  13176. };
  13177. scale.tickFormat = (count, specifier) => {
  13178. if (count == null) count = 10;
  13179. if (specifier == null) specifier = base === 10 ? "s" : ",";
  13180. if (typeof specifier !== "function") {
  13181. if (!(base % 1) && (specifier = formatSpecifier(specifier)).precision == null) specifier.trim = true;
  13182. specifier = exports.format(specifier);
  13183. }
  13184. if (count === Infinity) return specifier;
  13185. const k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  13186. return d => {
  13187. let i = d / pows(Math.round(logs(d)));
  13188. if (i * base < base - 0.5) i *= base;
  13189. return i <= k ? specifier(d) : "";
  13190. };
  13191. };
  13192. scale.nice = () => {
  13193. return domain(nice(domain(), {
  13194. floor: x => pows(Math.floor(logs(x))),
  13195. ceil: x => pows(Math.ceil(logs(x)))
  13196. }));
  13197. };
  13198. return scale;
  13199. }
  13200. function log() {
  13201. const scale = loggish(transformer$2()).domain([1, 10]);
  13202. scale.copy = () => copy$1(scale, log()).base(scale.base());
  13203. initRange.apply(scale, arguments);
  13204. return scale;
  13205. }
  13206. function transformSymlog(c) {
  13207. return function(x) {
  13208. return Math.sign(x) * Math.log1p(Math.abs(x / c));
  13209. };
  13210. }
  13211. function transformSymexp(c) {
  13212. return function(x) {
  13213. return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
  13214. };
  13215. }
  13216. function symlogish(transform) {
  13217. var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
  13218. scale.constant = function(_) {
  13219. return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
  13220. };
  13221. return linearish(scale);
  13222. }
  13223. function symlog() {
  13224. var scale = symlogish(transformer$2());
  13225. scale.copy = function() {
  13226. return copy$1(scale, symlog()).constant(scale.constant());
  13227. };
  13228. return initRange.apply(scale, arguments);
  13229. }
  13230. function transformPow(exponent) {
  13231. return function(x) {
  13232. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  13233. };
  13234. }
  13235. function transformSqrt(x) {
  13236. return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
  13237. }
  13238. function transformSquare(x) {
  13239. return x < 0 ? -x * x : x * x;
  13240. }
  13241. function powish(transform) {
  13242. var scale = transform(identity$3, identity$3),
  13243. exponent = 1;
  13244. function rescale() {
  13245. return exponent === 1 ? transform(identity$3, identity$3)
  13246. : exponent === 0.5 ? transform(transformSqrt, transformSquare)
  13247. : transform(transformPow(exponent), transformPow(1 / exponent));
  13248. }
  13249. scale.exponent = function(_) {
  13250. return arguments.length ? (exponent = +_, rescale()) : exponent;
  13251. };
  13252. return linearish(scale);
  13253. }
  13254. function pow() {
  13255. var scale = powish(transformer$2());
  13256. scale.copy = function() {
  13257. return copy$1(scale, pow()).exponent(scale.exponent());
  13258. };
  13259. initRange.apply(scale, arguments);
  13260. return scale;
  13261. }
  13262. function sqrt$1() {
  13263. return pow.apply(null, arguments).exponent(0.5);
  13264. }
  13265. function square$1(x) {
  13266. return Math.sign(x) * x * x;
  13267. }
  13268. function unsquare(x) {
  13269. return Math.sign(x) * Math.sqrt(Math.abs(x));
  13270. }
  13271. function radial() {
  13272. var squared = continuous(),
  13273. range = [0, 1],
  13274. round = false,
  13275. unknown;
  13276. function scale(x) {
  13277. var y = unsquare(squared(x));
  13278. return isNaN(y) ? unknown : round ? Math.round(y) : y;
  13279. }
  13280. scale.invert = function(y) {
  13281. return squared.invert(square$1(y));
  13282. };
  13283. scale.domain = function(_) {
  13284. return arguments.length ? (squared.domain(_), scale) : squared.domain();
  13285. };
  13286. scale.range = function(_) {
  13287. return arguments.length ? (squared.range((range = Array.from(_, number$1)).map(square$1)), scale) : range.slice();
  13288. };
  13289. scale.rangeRound = function(_) {
  13290. return scale.range(_).round(true);
  13291. };
  13292. scale.round = function(_) {
  13293. return arguments.length ? (round = !!_, scale) : round;
  13294. };
  13295. scale.clamp = function(_) {
  13296. return arguments.length ? (squared.clamp(_), scale) : squared.clamp();
  13297. };
  13298. scale.unknown = function(_) {
  13299. return arguments.length ? (unknown = _, scale) : unknown;
  13300. };
  13301. scale.copy = function() {
  13302. return radial(squared.domain(), range)
  13303. .round(round)
  13304. .clamp(squared.clamp())
  13305. .unknown(unknown);
  13306. };
  13307. initRange.apply(scale, arguments);
  13308. return linearish(scale);
  13309. }
  13310. function quantile() {
  13311. var domain = [],
  13312. range = [],
  13313. thresholds = [],
  13314. unknown;
  13315. function rescale() {
  13316. var i = 0, n = Math.max(1, range.length);
  13317. thresholds = new Array(n - 1);
  13318. while (++i < n) thresholds[i - 1] = quantileSorted(domain, i / n);
  13319. return scale;
  13320. }
  13321. function scale(x) {
  13322. return x == null || isNaN(x = +x) ? unknown : range[bisect(thresholds, x)];
  13323. }
  13324. scale.invertExtent = function(y) {
  13325. var i = range.indexOf(y);
  13326. return i < 0 ? [NaN, NaN] : [
  13327. i > 0 ? thresholds[i - 1] : domain[0],
  13328. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  13329. ];
  13330. };
  13331. scale.domain = function(_) {
  13332. if (!arguments.length) return domain.slice();
  13333. domain = [];
  13334. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  13335. domain.sort(ascending$3);
  13336. return rescale();
  13337. };
  13338. scale.range = function(_) {
  13339. return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
  13340. };
  13341. scale.unknown = function(_) {
  13342. return arguments.length ? (unknown = _, scale) : unknown;
  13343. };
  13344. scale.quantiles = function() {
  13345. return thresholds.slice();
  13346. };
  13347. scale.copy = function() {
  13348. return quantile()
  13349. .domain(domain)
  13350. .range(range)
  13351. .unknown(unknown);
  13352. };
  13353. return initRange.apply(scale, arguments);
  13354. }
  13355. function quantize() {
  13356. var x0 = 0,
  13357. x1 = 1,
  13358. n = 1,
  13359. domain = [0.5],
  13360. range = [0, 1],
  13361. unknown;
  13362. function scale(x) {
  13363. return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
  13364. }
  13365. function rescale() {
  13366. var i = -1;
  13367. domain = new Array(n);
  13368. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  13369. return scale;
  13370. }
  13371. scale.domain = function(_) {
  13372. return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
  13373. };
  13374. scale.range = function(_) {
  13375. return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
  13376. };
  13377. scale.invertExtent = function(y) {
  13378. var i = range.indexOf(y);
  13379. return i < 0 ? [NaN, NaN]
  13380. : i < 1 ? [x0, domain[0]]
  13381. : i >= n ? [domain[n - 1], x1]
  13382. : [domain[i - 1], domain[i]];
  13383. };
  13384. scale.unknown = function(_) {
  13385. return arguments.length ? (unknown = _, scale) : scale;
  13386. };
  13387. scale.thresholds = function() {
  13388. return domain.slice();
  13389. };
  13390. scale.copy = function() {
  13391. return quantize()
  13392. .domain([x0, x1])
  13393. .range(range)
  13394. .unknown(unknown);
  13395. };
  13396. return initRange.apply(linearish(scale), arguments);
  13397. }
  13398. function threshold() {
  13399. var domain = [0.5],
  13400. range = [0, 1],
  13401. unknown,
  13402. n = 1;
  13403. function scale(x) {
  13404. return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
  13405. }
  13406. scale.domain = function(_) {
  13407. return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  13408. };
  13409. scale.range = function(_) {
  13410. return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  13411. };
  13412. scale.invertExtent = function(y) {
  13413. var i = range.indexOf(y);
  13414. return [domain[i - 1], domain[i]];
  13415. };
  13416. scale.unknown = function(_) {
  13417. return arguments.length ? (unknown = _, scale) : unknown;
  13418. };
  13419. scale.copy = function() {
  13420. return threshold()
  13421. .domain(domain)
  13422. .range(range)
  13423. .unknown(unknown);
  13424. };
  13425. return initRange.apply(scale, arguments);
  13426. }
  13427. const t0 = new Date, t1 = new Date;
  13428. function timeInterval(floori, offseti, count, field) {
  13429. function interval(date) {
  13430. return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
  13431. }
  13432. interval.floor = (date) => {
  13433. return floori(date = new Date(+date)), date;
  13434. };
  13435. interval.ceil = (date) => {
  13436. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  13437. };
  13438. interval.round = (date) => {
  13439. const d0 = interval(date), d1 = interval.ceil(date);
  13440. return date - d0 < d1 - date ? d0 : d1;
  13441. };
  13442. interval.offset = (date, step) => {
  13443. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  13444. };
  13445. interval.range = (start, stop, step) => {
  13446. const range = [];
  13447. start = interval.ceil(start);
  13448. step = step == null ? 1 : Math.floor(step);
  13449. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  13450. let previous;
  13451. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  13452. while (previous < start && start < stop);
  13453. return range;
  13454. };
  13455. interval.filter = (test) => {
  13456. return timeInterval((date) => {
  13457. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  13458. }, (date, step) => {
  13459. if (date >= date) {
  13460. if (step < 0) while (++step <= 0) {
  13461. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  13462. } else while (--step >= 0) {
  13463. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  13464. }
  13465. }
  13466. });
  13467. };
  13468. if (count) {
  13469. interval.count = (start, end) => {
  13470. t0.setTime(+start), t1.setTime(+end);
  13471. floori(t0), floori(t1);
  13472. return Math.floor(count(t0, t1));
  13473. };
  13474. interval.every = (step) => {
  13475. step = Math.floor(step);
  13476. return !isFinite(step) || !(step > 0) ? null
  13477. : !(step > 1) ? interval
  13478. : interval.filter(field
  13479. ? (d) => field(d) % step === 0
  13480. : (d) => interval.count(0, d) % step === 0);
  13481. };
  13482. }
  13483. return interval;
  13484. }
  13485. const millisecond = timeInterval(() => {
  13486. // noop
  13487. }, (date, step) => {
  13488. date.setTime(+date + step);
  13489. }, (start, end) => {
  13490. return end - start;
  13491. });
  13492. // An optimized implementation for this simple case.
  13493. millisecond.every = (k) => {
  13494. k = Math.floor(k);
  13495. if (!isFinite(k) || !(k > 0)) return null;
  13496. if (!(k > 1)) return millisecond;
  13497. return timeInterval((date) => {
  13498. date.setTime(Math.floor(date / k) * k);
  13499. }, (date, step) => {
  13500. date.setTime(+date + step * k);
  13501. }, (start, end) => {
  13502. return (end - start) / k;
  13503. });
  13504. };
  13505. const milliseconds = millisecond.range;
  13506. const durationSecond = 1000;
  13507. const durationMinute = durationSecond * 60;
  13508. const durationHour = durationMinute * 60;
  13509. const durationDay = durationHour * 24;
  13510. const durationWeek = durationDay * 7;
  13511. const durationMonth = durationDay * 30;
  13512. const durationYear = durationDay * 365;
  13513. const second = timeInterval((date) => {
  13514. date.setTime(date - date.getMilliseconds());
  13515. }, (date, step) => {
  13516. date.setTime(+date + step * durationSecond);
  13517. }, (start, end) => {
  13518. return (end - start) / durationSecond;
  13519. }, (date) => {
  13520. return date.getUTCSeconds();
  13521. });
  13522. const seconds = second.range;
  13523. const timeMinute = timeInterval((date) => {
  13524. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
  13525. }, (date, step) => {
  13526. date.setTime(+date + step * durationMinute);
  13527. }, (start, end) => {
  13528. return (end - start) / durationMinute;
  13529. }, (date) => {
  13530. return date.getMinutes();
  13531. });
  13532. const timeMinutes = timeMinute.range;
  13533. const utcMinute = timeInterval((date) => {
  13534. date.setUTCSeconds(0, 0);
  13535. }, (date, step) => {
  13536. date.setTime(+date + step * durationMinute);
  13537. }, (start, end) => {
  13538. return (end - start) / durationMinute;
  13539. }, (date) => {
  13540. return date.getUTCMinutes();
  13541. });
  13542. const utcMinutes = utcMinute.range;
  13543. const timeHour = timeInterval((date) => {
  13544. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
  13545. }, (date, step) => {
  13546. date.setTime(+date + step * durationHour);
  13547. }, (start, end) => {
  13548. return (end - start) / durationHour;
  13549. }, (date) => {
  13550. return date.getHours();
  13551. });
  13552. const timeHours = timeHour.range;
  13553. const utcHour = timeInterval((date) => {
  13554. date.setUTCMinutes(0, 0, 0);
  13555. }, (date, step) => {
  13556. date.setTime(+date + step * durationHour);
  13557. }, (start, end) => {
  13558. return (end - start) / durationHour;
  13559. }, (date) => {
  13560. return date.getUTCHours();
  13561. });
  13562. const utcHours = utcHour.range;
  13563. const timeDay = timeInterval(
  13564. date => date.setHours(0, 0, 0, 0),
  13565. (date, step) => date.setDate(date.getDate() + step),
  13566. (start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay,
  13567. date => date.getDate() - 1
  13568. );
  13569. const timeDays = timeDay.range;
  13570. const utcDay = timeInterval((date) => {
  13571. date.setUTCHours(0, 0, 0, 0);
  13572. }, (date, step) => {
  13573. date.setUTCDate(date.getUTCDate() + step);
  13574. }, (start, end) => {
  13575. return (end - start) / durationDay;
  13576. }, (date) => {
  13577. return date.getUTCDate() - 1;
  13578. });
  13579. const utcDays = utcDay.range;
  13580. const unixDay = timeInterval((date) => {
  13581. date.setUTCHours(0, 0, 0, 0);
  13582. }, (date, step) => {
  13583. date.setUTCDate(date.getUTCDate() + step);
  13584. }, (start, end) => {
  13585. return (end - start) / durationDay;
  13586. }, (date) => {
  13587. return Math.floor(date / durationDay);
  13588. });
  13589. const unixDays = unixDay.range;
  13590. function timeWeekday(i) {
  13591. return timeInterval((date) => {
  13592. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  13593. date.setHours(0, 0, 0, 0);
  13594. }, (date, step) => {
  13595. date.setDate(date.getDate() + step * 7);
  13596. }, (start, end) => {
  13597. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  13598. });
  13599. }
  13600. const timeSunday = timeWeekday(0);
  13601. const timeMonday = timeWeekday(1);
  13602. const timeTuesday = timeWeekday(2);
  13603. const timeWednesday = timeWeekday(3);
  13604. const timeThursday = timeWeekday(4);
  13605. const timeFriday = timeWeekday(5);
  13606. const timeSaturday = timeWeekday(6);
  13607. const timeSundays = timeSunday.range;
  13608. const timeMondays = timeMonday.range;
  13609. const timeTuesdays = timeTuesday.range;
  13610. const timeWednesdays = timeWednesday.range;
  13611. const timeThursdays = timeThursday.range;
  13612. const timeFridays = timeFriday.range;
  13613. const timeSaturdays = timeSaturday.range;
  13614. function utcWeekday(i) {
  13615. return timeInterval((date) => {
  13616. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  13617. date.setUTCHours(0, 0, 0, 0);
  13618. }, (date, step) => {
  13619. date.setUTCDate(date.getUTCDate() + step * 7);
  13620. }, (start, end) => {
  13621. return (end - start) / durationWeek;
  13622. });
  13623. }
  13624. const utcSunday = utcWeekday(0);
  13625. const utcMonday = utcWeekday(1);
  13626. const utcTuesday = utcWeekday(2);
  13627. const utcWednesday = utcWeekday(3);
  13628. const utcThursday = utcWeekday(4);
  13629. const utcFriday = utcWeekday(5);
  13630. const utcSaturday = utcWeekday(6);
  13631. const utcSundays = utcSunday.range;
  13632. const utcMondays = utcMonday.range;
  13633. const utcTuesdays = utcTuesday.range;
  13634. const utcWednesdays = utcWednesday.range;
  13635. const utcThursdays = utcThursday.range;
  13636. const utcFridays = utcFriday.range;
  13637. const utcSaturdays = utcSaturday.range;
  13638. const timeMonth = timeInterval((date) => {
  13639. date.setDate(1);
  13640. date.setHours(0, 0, 0, 0);
  13641. }, (date, step) => {
  13642. date.setMonth(date.getMonth() + step);
  13643. }, (start, end) => {
  13644. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  13645. }, (date) => {
  13646. return date.getMonth();
  13647. });
  13648. const timeMonths = timeMonth.range;
  13649. const utcMonth = timeInterval((date) => {
  13650. date.setUTCDate(1);
  13651. date.setUTCHours(0, 0, 0, 0);
  13652. }, (date, step) => {
  13653. date.setUTCMonth(date.getUTCMonth() + step);
  13654. }, (start, end) => {
  13655. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  13656. }, (date) => {
  13657. return date.getUTCMonth();
  13658. });
  13659. const utcMonths = utcMonth.range;
  13660. const timeYear = timeInterval((date) => {
  13661. date.setMonth(0, 1);
  13662. date.setHours(0, 0, 0, 0);
  13663. }, (date, step) => {
  13664. date.setFullYear(date.getFullYear() + step);
  13665. }, (start, end) => {
  13666. return end.getFullYear() - start.getFullYear();
  13667. }, (date) => {
  13668. return date.getFullYear();
  13669. });
  13670. // An optimized implementation for this simple case.
  13671. timeYear.every = (k) => {
  13672. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
  13673. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  13674. date.setMonth(0, 1);
  13675. date.setHours(0, 0, 0, 0);
  13676. }, (date, step) => {
  13677. date.setFullYear(date.getFullYear() + step * k);
  13678. });
  13679. };
  13680. const timeYears = timeYear.range;
  13681. const utcYear = timeInterval((date) => {
  13682. date.setUTCMonth(0, 1);
  13683. date.setUTCHours(0, 0, 0, 0);
  13684. }, (date, step) => {
  13685. date.setUTCFullYear(date.getUTCFullYear() + step);
  13686. }, (start, end) => {
  13687. return end.getUTCFullYear() - start.getUTCFullYear();
  13688. }, (date) => {
  13689. return date.getUTCFullYear();
  13690. });
  13691. // An optimized implementation for this simple case.
  13692. utcYear.every = (k) => {
  13693. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
  13694. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  13695. date.setUTCMonth(0, 1);
  13696. date.setUTCHours(0, 0, 0, 0);
  13697. }, (date, step) => {
  13698. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  13699. });
  13700. };
  13701. const utcYears = utcYear.range;
  13702. function ticker(year, month, week, day, hour, minute) {
  13703. const tickIntervals = [
  13704. [second, 1, durationSecond],
  13705. [second, 5, 5 * durationSecond],
  13706. [second, 15, 15 * durationSecond],
  13707. [second, 30, 30 * durationSecond],
  13708. [minute, 1, durationMinute],
  13709. [minute, 5, 5 * durationMinute],
  13710. [minute, 15, 15 * durationMinute],
  13711. [minute, 30, 30 * durationMinute],
  13712. [ hour, 1, durationHour ],
  13713. [ hour, 3, 3 * durationHour ],
  13714. [ hour, 6, 6 * durationHour ],
  13715. [ hour, 12, 12 * durationHour ],
  13716. [ day, 1, durationDay ],
  13717. [ day, 2, 2 * durationDay ],
  13718. [ week, 1, durationWeek ],
  13719. [ month, 1, durationMonth ],
  13720. [ month, 3, 3 * durationMonth ],
  13721. [ year, 1, durationYear ]
  13722. ];
  13723. function ticks(start, stop, count) {
  13724. const reverse = stop < start;
  13725. if (reverse) [start, stop] = [stop, start];
  13726. const interval = count && typeof count.range === "function" ? count : tickInterval(start, stop, count);
  13727. const ticks = interval ? interval.range(start, +stop + 1) : []; // inclusive stop
  13728. return reverse ? ticks.reverse() : ticks;
  13729. }
  13730. function tickInterval(start, stop, count) {
  13731. const target = Math.abs(stop - start) / count;
  13732. const i = bisector(([,, step]) => step).right(tickIntervals, target);
  13733. if (i === tickIntervals.length) return year.every(tickStep(start / durationYear, stop / durationYear, count));
  13734. if (i === 0) return millisecond.every(Math.max(tickStep(start, stop, count), 1));
  13735. const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  13736. return t.every(step);
  13737. }
  13738. return [ticks, tickInterval];
  13739. }
  13740. const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute);
  13741. const [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);
  13742. function localDate(d) {
  13743. if (0 <= d.y && d.y < 100) {
  13744. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  13745. date.setFullYear(d.y);
  13746. return date;
  13747. }
  13748. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  13749. }
  13750. function utcDate(d) {
  13751. if (0 <= d.y && d.y < 100) {
  13752. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  13753. date.setUTCFullYear(d.y);
  13754. return date;
  13755. }
  13756. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  13757. }
  13758. function newDate(y, m, d) {
  13759. return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
  13760. }
  13761. function formatLocale(locale) {
  13762. var locale_dateTime = locale.dateTime,
  13763. locale_date = locale.date,
  13764. locale_time = locale.time,
  13765. locale_periods = locale.periods,
  13766. locale_weekdays = locale.days,
  13767. locale_shortWeekdays = locale.shortDays,
  13768. locale_months = locale.months,
  13769. locale_shortMonths = locale.shortMonths;
  13770. var periodRe = formatRe(locale_periods),
  13771. periodLookup = formatLookup(locale_periods),
  13772. weekdayRe = formatRe(locale_weekdays),
  13773. weekdayLookup = formatLookup(locale_weekdays),
  13774. shortWeekdayRe = formatRe(locale_shortWeekdays),
  13775. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  13776. monthRe = formatRe(locale_months),
  13777. monthLookup = formatLookup(locale_months),
  13778. shortMonthRe = formatRe(locale_shortMonths),
  13779. shortMonthLookup = formatLookup(locale_shortMonths);
  13780. var formats = {
  13781. "a": formatShortWeekday,
  13782. "A": formatWeekday,
  13783. "b": formatShortMonth,
  13784. "B": formatMonth,
  13785. "c": null,
  13786. "d": formatDayOfMonth,
  13787. "e": formatDayOfMonth,
  13788. "f": formatMicroseconds,
  13789. "g": formatYearISO,
  13790. "G": formatFullYearISO,
  13791. "H": formatHour24,
  13792. "I": formatHour12,
  13793. "j": formatDayOfYear,
  13794. "L": formatMilliseconds,
  13795. "m": formatMonthNumber,
  13796. "M": formatMinutes,
  13797. "p": formatPeriod,
  13798. "q": formatQuarter,
  13799. "Q": formatUnixTimestamp,
  13800. "s": formatUnixTimestampSeconds,
  13801. "S": formatSeconds,
  13802. "u": formatWeekdayNumberMonday,
  13803. "U": formatWeekNumberSunday,
  13804. "V": formatWeekNumberISO,
  13805. "w": formatWeekdayNumberSunday,
  13806. "W": formatWeekNumberMonday,
  13807. "x": null,
  13808. "X": null,
  13809. "y": formatYear,
  13810. "Y": formatFullYear,
  13811. "Z": formatZone,
  13812. "%": formatLiteralPercent
  13813. };
  13814. var utcFormats = {
  13815. "a": formatUTCShortWeekday,
  13816. "A": formatUTCWeekday,
  13817. "b": formatUTCShortMonth,
  13818. "B": formatUTCMonth,
  13819. "c": null,
  13820. "d": formatUTCDayOfMonth,
  13821. "e": formatUTCDayOfMonth,
  13822. "f": formatUTCMicroseconds,
  13823. "g": formatUTCYearISO,
  13824. "G": formatUTCFullYearISO,
  13825. "H": formatUTCHour24,
  13826. "I": formatUTCHour12,
  13827. "j": formatUTCDayOfYear,
  13828. "L": formatUTCMilliseconds,
  13829. "m": formatUTCMonthNumber,
  13830. "M": formatUTCMinutes,
  13831. "p": formatUTCPeriod,
  13832. "q": formatUTCQuarter,
  13833. "Q": formatUnixTimestamp,
  13834. "s": formatUnixTimestampSeconds,
  13835. "S": formatUTCSeconds,
  13836. "u": formatUTCWeekdayNumberMonday,
  13837. "U": formatUTCWeekNumberSunday,
  13838. "V": formatUTCWeekNumberISO,
  13839. "w": formatUTCWeekdayNumberSunday,
  13840. "W": formatUTCWeekNumberMonday,
  13841. "x": null,
  13842. "X": null,
  13843. "y": formatUTCYear,
  13844. "Y": formatUTCFullYear,
  13845. "Z": formatUTCZone,
  13846. "%": formatLiteralPercent
  13847. };
  13848. var parses = {
  13849. "a": parseShortWeekday,
  13850. "A": parseWeekday,
  13851. "b": parseShortMonth,
  13852. "B": parseMonth,
  13853. "c": parseLocaleDateTime,
  13854. "d": parseDayOfMonth,
  13855. "e": parseDayOfMonth,
  13856. "f": parseMicroseconds,
  13857. "g": parseYear,
  13858. "G": parseFullYear,
  13859. "H": parseHour24,
  13860. "I": parseHour24,
  13861. "j": parseDayOfYear,
  13862. "L": parseMilliseconds,
  13863. "m": parseMonthNumber,
  13864. "M": parseMinutes,
  13865. "p": parsePeriod,
  13866. "q": parseQuarter,
  13867. "Q": parseUnixTimestamp,
  13868. "s": parseUnixTimestampSeconds,
  13869. "S": parseSeconds,
  13870. "u": parseWeekdayNumberMonday,
  13871. "U": parseWeekNumberSunday,
  13872. "V": parseWeekNumberISO,
  13873. "w": parseWeekdayNumberSunday,
  13874. "W": parseWeekNumberMonday,
  13875. "x": parseLocaleDate,
  13876. "X": parseLocaleTime,
  13877. "y": parseYear,
  13878. "Y": parseFullYear,
  13879. "Z": parseZone,
  13880. "%": parseLiteralPercent
  13881. };
  13882. // These recursive directive definitions must be deferred.
  13883. formats.x = newFormat(locale_date, formats);
  13884. formats.X = newFormat(locale_time, formats);
  13885. formats.c = newFormat(locale_dateTime, formats);
  13886. utcFormats.x = newFormat(locale_date, utcFormats);
  13887. utcFormats.X = newFormat(locale_time, utcFormats);
  13888. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  13889. function newFormat(specifier, formats) {
  13890. return function(date) {
  13891. var string = [],
  13892. i = -1,
  13893. j = 0,
  13894. n = specifier.length,
  13895. c,
  13896. pad,
  13897. format;
  13898. if (!(date instanceof Date)) date = new Date(+date);
  13899. while (++i < n) {
  13900. if (specifier.charCodeAt(i) === 37) {
  13901. string.push(specifier.slice(j, i));
  13902. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  13903. else pad = c === "e" ? " " : "0";
  13904. if (format = formats[c]) c = format(date, pad);
  13905. string.push(c);
  13906. j = i + 1;
  13907. }
  13908. }
  13909. string.push(specifier.slice(j, i));
  13910. return string.join("");
  13911. };
  13912. }
  13913. function newParse(specifier, Z) {
  13914. return function(string) {
  13915. var d = newDate(1900, undefined, 1),
  13916. i = parseSpecifier(d, specifier, string += "", 0),
  13917. week, day;
  13918. if (i != string.length) return null;
  13919. // If a UNIX timestamp is specified, return it.
  13920. if ("Q" in d) return new Date(d.Q);
  13921. if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
  13922. // If this is utcParse, never use the local timezone.
  13923. if (Z && !("Z" in d)) d.Z = 0;
  13924. // The am-pm flag is 0 for AM, and 1 for PM.
  13925. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  13926. // If the month was not specified, inherit from the quarter.
  13927. if (d.m === undefined) d.m = "q" in d ? d.q : 0;
  13928. // Convert day-of-week and week-of-year to day-of-year.
  13929. if ("V" in d) {
  13930. if (d.V < 1 || d.V > 53) return null;
  13931. if (!("w" in d)) d.w = 1;
  13932. if ("Z" in d) {
  13933. week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
  13934. week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
  13935. week = utcDay.offset(week, (d.V - 1) * 7);
  13936. d.y = week.getUTCFullYear();
  13937. d.m = week.getUTCMonth();
  13938. d.d = week.getUTCDate() + (d.w + 6) % 7;
  13939. } else {
  13940. week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
  13941. week = day > 4 || day === 0 ? timeMonday.ceil(week) : timeMonday(week);
  13942. week = timeDay.offset(week, (d.V - 1) * 7);
  13943. d.y = week.getFullYear();
  13944. d.m = week.getMonth();
  13945. d.d = week.getDate() + (d.w + 6) % 7;
  13946. }
  13947. } else if ("W" in d || "U" in d) {
  13948. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  13949. day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
  13950. d.m = 0;
  13951. d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
  13952. }
  13953. // If a time zone is specified, all fields are interpreted as UTC and then
  13954. // offset according to the specified time zone.
  13955. if ("Z" in d) {
  13956. d.H += d.Z / 100 | 0;
  13957. d.M += d.Z % 100;
  13958. return utcDate(d);
  13959. }
  13960. // Otherwise, all fields are in local time.
  13961. return localDate(d);
  13962. };
  13963. }
  13964. function parseSpecifier(d, specifier, string, j) {
  13965. var i = 0,
  13966. n = specifier.length,
  13967. m = string.length,
  13968. c,
  13969. parse;
  13970. while (i < n) {
  13971. if (j >= m) return -1;
  13972. c = specifier.charCodeAt(i++);
  13973. if (c === 37) {
  13974. c = specifier.charAt(i++);
  13975. parse = parses[c in pads ? specifier.charAt(i++) : c];
  13976. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  13977. } else if (c != string.charCodeAt(j++)) {
  13978. return -1;
  13979. }
  13980. }
  13981. return j;
  13982. }
  13983. function parsePeriod(d, string, i) {
  13984. var n = periodRe.exec(string.slice(i));
  13985. return n ? (d.p = periodLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13986. }
  13987. function parseShortWeekday(d, string, i) {
  13988. var n = shortWeekdayRe.exec(string.slice(i));
  13989. return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13990. }
  13991. function parseWeekday(d, string, i) {
  13992. var n = weekdayRe.exec(string.slice(i));
  13993. return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13994. }
  13995. function parseShortMonth(d, string, i) {
  13996. var n = shortMonthRe.exec(string.slice(i));
  13997. return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  13998. }
  13999. function parseMonth(d, string, i) {
  14000. var n = monthRe.exec(string.slice(i));
  14001. return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  14002. }
  14003. function parseLocaleDateTime(d, string, i) {
  14004. return parseSpecifier(d, locale_dateTime, string, i);
  14005. }
  14006. function parseLocaleDate(d, string, i) {
  14007. return parseSpecifier(d, locale_date, string, i);
  14008. }
  14009. function parseLocaleTime(d, string, i) {
  14010. return parseSpecifier(d, locale_time, string, i);
  14011. }
  14012. function formatShortWeekday(d) {
  14013. return locale_shortWeekdays[d.getDay()];
  14014. }
  14015. function formatWeekday(d) {
  14016. return locale_weekdays[d.getDay()];
  14017. }
  14018. function formatShortMonth(d) {
  14019. return locale_shortMonths[d.getMonth()];
  14020. }
  14021. function formatMonth(d) {
  14022. return locale_months[d.getMonth()];
  14023. }
  14024. function formatPeriod(d) {
  14025. return locale_periods[+(d.getHours() >= 12)];
  14026. }
  14027. function formatQuarter(d) {
  14028. return 1 + ~~(d.getMonth() / 3);
  14029. }
  14030. function formatUTCShortWeekday(d) {
  14031. return locale_shortWeekdays[d.getUTCDay()];
  14032. }
  14033. function formatUTCWeekday(d) {
  14034. return locale_weekdays[d.getUTCDay()];
  14035. }
  14036. function formatUTCShortMonth(d) {
  14037. return locale_shortMonths[d.getUTCMonth()];
  14038. }
  14039. function formatUTCMonth(d) {
  14040. return locale_months[d.getUTCMonth()];
  14041. }
  14042. function formatUTCPeriod(d) {
  14043. return locale_periods[+(d.getUTCHours() >= 12)];
  14044. }
  14045. function formatUTCQuarter(d) {
  14046. return 1 + ~~(d.getUTCMonth() / 3);
  14047. }
  14048. return {
  14049. format: function(specifier) {
  14050. var f = newFormat(specifier += "", formats);
  14051. f.toString = function() { return specifier; };
  14052. return f;
  14053. },
  14054. parse: function(specifier) {
  14055. var p = newParse(specifier += "", false);
  14056. p.toString = function() { return specifier; };
  14057. return p;
  14058. },
  14059. utcFormat: function(specifier) {
  14060. var f = newFormat(specifier += "", utcFormats);
  14061. f.toString = function() { return specifier; };
  14062. return f;
  14063. },
  14064. utcParse: function(specifier) {
  14065. var p = newParse(specifier += "", true);
  14066. p.toString = function() { return specifier; };
  14067. return p;
  14068. }
  14069. };
  14070. }
  14071. var pads = {"-": "", "_": " ", "0": "0"},
  14072. numberRe = /^\s*\d+/, // note: ignores next directive
  14073. percentRe = /^%/,
  14074. requoteRe = /[\\^$*+?|[\]().{}]/g;
  14075. function pad(value, fill, width) {
  14076. var sign = value < 0 ? "-" : "",
  14077. string = (sign ? -value : value) + "",
  14078. length = string.length;
  14079. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  14080. }
  14081. function requote(s) {
  14082. return s.replace(requoteRe, "\\$&");
  14083. }
  14084. function formatRe(names) {
  14085. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  14086. }
  14087. function formatLookup(names) {
  14088. return new Map(names.map((name, i) => [name.toLowerCase(), i]));
  14089. }
  14090. function parseWeekdayNumberSunday(d, string, i) {
  14091. var n = numberRe.exec(string.slice(i, i + 1));
  14092. return n ? (d.w = +n[0], i + n[0].length) : -1;
  14093. }
  14094. function parseWeekdayNumberMonday(d, string, i) {
  14095. var n = numberRe.exec(string.slice(i, i + 1));
  14096. return n ? (d.u = +n[0], i + n[0].length) : -1;
  14097. }
  14098. function parseWeekNumberSunday(d, string, i) {
  14099. var n = numberRe.exec(string.slice(i, i + 2));
  14100. return n ? (d.U = +n[0], i + n[0].length) : -1;
  14101. }
  14102. function parseWeekNumberISO(d, string, i) {
  14103. var n = numberRe.exec(string.slice(i, i + 2));
  14104. return n ? (d.V = +n[0], i + n[0].length) : -1;
  14105. }
  14106. function parseWeekNumberMonday(d, string, i) {
  14107. var n = numberRe.exec(string.slice(i, i + 2));
  14108. return n ? (d.W = +n[0], i + n[0].length) : -1;
  14109. }
  14110. function parseFullYear(d, string, i) {
  14111. var n = numberRe.exec(string.slice(i, i + 4));
  14112. return n ? (d.y = +n[0], i + n[0].length) : -1;
  14113. }
  14114. function parseYear(d, string, i) {
  14115. var n = numberRe.exec(string.slice(i, i + 2));
  14116. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  14117. }
  14118. function parseZone(d, string, i) {
  14119. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  14120. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  14121. }
  14122. function parseQuarter(d, string, i) {
  14123. var n = numberRe.exec(string.slice(i, i + 1));
  14124. return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
  14125. }
  14126. function parseMonthNumber(d, string, i) {
  14127. var n = numberRe.exec(string.slice(i, i + 2));
  14128. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  14129. }
  14130. function parseDayOfMonth(d, string, i) {
  14131. var n = numberRe.exec(string.slice(i, i + 2));
  14132. return n ? (d.d = +n[0], i + n[0].length) : -1;
  14133. }
  14134. function parseDayOfYear(d, string, i) {
  14135. var n = numberRe.exec(string.slice(i, i + 3));
  14136. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  14137. }
  14138. function parseHour24(d, string, i) {
  14139. var n = numberRe.exec(string.slice(i, i + 2));
  14140. return n ? (d.H = +n[0], i + n[0].length) : -1;
  14141. }
  14142. function parseMinutes(d, string, i) {
  14143. var n = numberRe.exec(string.slice(i, i + 2));
  14144. return n ? (d.M = +n[0], i + n[0].length) : -1;
  14145. }
  14146. function parseSeconds(d, string, i) {
  14147. var n = numberRe.exec(string.slice(i, i + 2));
  14148. return n ? (d.S = +n[0], i + n[0].length) : -1;
  14149. }
  14150. function parseMilliseconds(d, string, i) {
  14151. var n = numberRe.exec(string.slice(i, i + 3));
  14152. return n ? (d.L = +n[0], i + n[0].length) : -1;
  14153. }
  14154. function parseMicroseconds(d, string, i) {
  14155. var n = numberRe.exec(string.slice(i, i + 6));
  14156. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  14157. }
  14158. function parseLiteralPercent(d, string, i) {
  14159. var n = percentRe.exec(string.slice(i, i + 1));
  14160. return n ? i + n[0].length : -1;
  14161. }
  14162. function parseUnixTimestamp(d, string, i) {
  14163. var n = numberRe.exec(string.slice(i));
  14164. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  14165. }
  14166. function parseUnixTimestampSeconds(d, string, i) {
  14167. var n = numberRe.exec(string.slice(i));
  14168. return n ? (d.s = +n[0], i + n[0].length) : -1;
  14169. }
  14170. function formatDayOfMonth(d, p) {
  14171. return pad(d.getDate(), p, 2);
  14172. }
  14173. function formatHour24(d, p) {
  14174. return pad(d.getHours(), p, 2);
  14175. }
  14176. function formatHour12(d, p) {
  14177. return pad(d.getHours() % 12 || 12, p, 2);
  14178. }
  14179. function formatDayOfYear(d, p) {
  14180. return pad(1 + timeDay.count(timeYear(d), d), p, 3);
  14181. }
  14182. function formatMilliseconds(d, p) {
  14183. return pad(d.getMilliseconds(), p, 3);
  14184. }
  14185. function formatMicroseconds(d, p) {
  14186. return formatMilliseconds(d, p) + "000";
  14187. }
  14188. function formatMonthNumber(d, p) {
  14189. return pad(d.getMonth() + 1, p, 2);
  14190. }
  14191. function formatMinutes(d, p) {
  14192. return pad(d.getMinutes(), p, 2);
  14193. }
  14194. function formatSeconds(d, p) {
  14195. return pad(d.getSeconds(), p, 2);
  14196. }
  14197. function formatWeekdayNumberMonday(d) {
  14198. var day = d.getDay();
  14199. return day === 0 ? 7 : day;
  14200. }
  14201. function formatWeekNumberSunday(d, p) {
  14202. return pad(timeSunday.count(timeYear(d) - 1, d), p, 2);
  14203. }
  14204. function dISO(d) {
  14205. var day = d.getDay();
  14206. return (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d);
  14207. }
  14208. function formatWeekNumberISO(d, p) {
  14209. d = dISO(d);
  14210. return pad(timeThursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2);
  14211. }
  14212. function formatWeekdayNumberSunday(d) {
  14213. return d.getDay();
  14214. }
  14215. function formatWeekNumberMonday(d, p) {
  14216. return pad(timeMonday.count(timeYear(d) - 1, d), p, 2);
  14217. }
  14218. function formatYear(d, p) {
  14219. return pad(d.getFullYear() % 100, p, 2);
  14220. }
  14221. function formatYearISO(d, p) {
  14222. d = dISO(d);
  14223. return pad(d.getFullYear() % 100, p, 2);
  14224. }
  14225. function formatFullYear(d, p) {
  14226. return pad(d.getFullYear() % 10000, p, 4);
  14227. }
  14228. function formatFullYearISO(d, p) {
  14229. var day = d.getDay();
  14230. d = (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d);
  14231. return pad(d.getFullYear() % 10000, p, 4);
  14232. }
  14233. function formatZone(d) {
  14234. var z = d.getTimezoneOffset();
  14235. return (z > 0 ? "-" : (z *= -1, "+"))
  14236. + pad(z / 60 | 0, "0", 2)
  14237. + pad(z % 60, "0", 2);
  14238. }
  14239. function formatUTCDayOfMonth(d, p) {
  14240. return pad(d.getUTCDate(), p, 2);
  14241. }
  14242. function formatUTCHour24(d, p) {
  14243. return pad(d.getUTCHours(), p, 2);
  14244. }
  14245. function formatUTCHour12(d, p) {
  14246. return pad(d.getUTCHours() % 12 || 12, p, 2);
  14247. }
  14248. function formatUTCDayOfYear(d, p) {
  14249. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  14250. }
  14251. function formatUTCMilliseconds(d, p) {
  14252. return pad(d.getUTCMilliseconds(), p, 3);
  14253. }
  14254. function formatUTCMicroseconds(d, p) {
  14255. return formatUTCMilliseconds(d, p) + "000";
  14256. }
  14257. function formatUTCMonthNumber(d, p) {
  14258. return pad(d.getUTCMonth() + 1, p, 2);
  14259. }
  14260. function formatUTCMinutes(d, p) {
  14261. return pad(d.getUTCMinutes(), p, 2);
  14262. }
  14263. function formatUTCSeconds(d, p) {
  14264. return pad(d.getUTCSeconds(), p, 2);
  14265. }
  14266. function formatUTCWeekdayNumberMonday(d) {
  14267. var dow = d.getUTCDay();
  14268. return dow === 0 ? 7 : dow;
  14269. }
  14270. function formatUTCWeekNumberSunday(d, p) {
  14271. return pad(utcSunday.count(utcYear(d) - 1, d), p, 2);
  14272. }
  14273. function UTCdISO(d) {
  14274. var day = d.getUTCDay();
  14275. return (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  14276. }
  14277. function formatUTCWeekNumberISO(d, p) {
  14278. d = UTCdISO(d);
  14279. return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  14280. }
  14281. function formatUTCWeekdayNumberSunday(d) {
  14282. return d.getUTCDay();
  14283. }
  14284. function formatUTCWeekNumberMonday(d, p) {
  14285. return pad(utcMonday.count(utcYear(d) - 1, d), p, 2);
  14286. }
  14287. function formatUTCYear(d, p) {
  14288. return pad(d.getUTCFullYear() % 100, p, 2);
  14289. }
  14290. function formatUTCYearISO(d, p) {
  14291. d = UTCdISO(d);
  14292. return pad(d.getUTCFullYear() % 100, p, 2);
  14293. }
  14294. function formatUTCFullYear(d, p) {
  14295. return pad(d.getUTCFullYear() % 10000, p, 4);
  14296. }
  14297. function formatUTCFullYearISO(d, p) {
  14298. var day = d.getUTCDay();
  14299. d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  14300. return pad(d.getUTCFullYear() % 10000, p, 4);
  14301. }
  14302. function formatUTCZone() {
  14303. return "+0000";
  14304. }
  14305. function formatLiteralPercent() {
  14306. return "%";
  14307. }
  14308. function formatUnixTimestamp(d) {
  14309. return +d;
  14310. }
  14311. function formatUnixTimestampSeconds(d) {
  14312. return Math.floor(+d / 1000);
  14313. }
  14314. var locale;
  14315. exports.timeFormat = void 0;
  14316. exports.timeParse = void 0;
  14317. exports.utcFormat = void 0;
  14318. exports.utcParse = void 0;
  14319. defaultLocale({
  14320. dateTime: "%x, %X",
  14321. date: "%-m/%-d/%Y",
  14322. time: "%-I:%M:%S %p",
  14323. periods: ["AM", "PM"],
  14324. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  14325. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  14326. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  14327. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  14328. });
  14329. function defaultLocale(definition) {
  14330. locale = formatLocale(definition);
  14331. exports.timeFormat = locale.format;
  14332. exports.timeParse = locale.parse;
  14333. exports.utcFormat = locale.utcFormat;
  14334. exports.utcParse = locale.utcParse;
  14335. return locale;
  14336. }
  14337. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  14338. function formatIsoNative(date) {
  14339. return date.toISOString();
  14340. }
  14341. var formatIso = Date.prototype.toISOString
  14342. ? formatIsoNative
  14343. : exports.utcFormat(isoSpecifier);
  14344. var formatIso$1 = formatIso;
  14345. function parseIsoNative(string) {
  14346. var date = new Date(string);
  14347. return isNaN(date) ? null : date;
  14348. }
  14349. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  14350. ? parseIsoNative
  14351. : exports.utcParse(isoSpecifier);
  14352. var parseIso$1 = parseIso;
  14353. function date(t) {
  14354. return new Date(t);
  14355. }
  14356. function number(t) {
  14357. return t instanceof Date ? +t : +new Date(+t);
  14358. }
  14359. function calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format) {
  14360. var scale = continuous(),
  14361. invert = scale.invert,
  14362. domain = scale.domain;
  14363. var formatMillisecond = format(".%L"),
  14364. formatSecond = format(":%S"),
  14365. formatMinute = format("%I:%M"),
  14366. formatHour = format("%I %p"),
  14367. formatDay = format("%a %d"),
  14368. formatWeek = format("%b %d"),
  14369. formatMonth = format("%B"),
  14370. formatYear = format("%Y");
  14371. function tickFormat(date) {
  14372. return (second(date) < date ? formatMillisecond
  14373. : minute(date) < date ? formatSecond
  14374. : hour(date) < date ? formatMinute
  14375. : day(date) < date ? formatHour
  14376. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  14377. : year(date) < date ? formatMonth
  14378. : formatYear)(date);
  14379. }
  14380. scale.invert = function(y) {
  14381. return new Date(invert(y));
  14382. };
  14383. scale.domain = function(_) {
  14384. return arguments.length ? domain(Array.from(_, number)) : domain().map(date);
  14385. };
  14386. scale.ticks = function(interval) {
  14387. var d = domain();
  14388. return ticks(d[0], d[d.length - 1], interval == null ? 10 : interval);
  14389. };
  14390. scale.tickFormat = function(count, specifier) {
  14391. return specifier == null ? tickFormat : format(specifier);
  14392. };
  14393. scale.nice = function(interval) {
  14394. var d = domain();
  14395. if (!interval || typeof interval.range !== "function") interval = tickInterval(d[0], d[d.length - 1], interval == null ? 10 : interval);
  14396. return interval ? domain(nice(d, interval)) : scale;
  14397. };
  14398. scale.copy = function() {
  14399. return copy$1(scale, calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format));
  14400. };
  14401. return scale;
  14402. }
  14403. function time() {
  14404. return initRange.apply(calendar(timeTicks, timeTickInterval, timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute, second, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
  14405. }
  14406. function utcTime() {
  14407. return initRange.apply(calendar(utcTicks, utcTickInterval, utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
  14408. }
  14409. function transformer$1() {
  14410. var x0 = 0,
  14411. x1 = 1,
  14412. t0,
  14413. t1,
  14414. k10,
  14415. transform,
  14416. interpolator = identity$3,
  14417. clamp = false,
  14418. unknown;
  14419. function scale(x) {
  14420. return x == null || isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
  14421. }
  14422. scale.domain = function(_) {
  14423. return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
  14424. };
  14425. scale.clamp = function(_) {
  14426. return arguments.length ? (clamp = !!_, scale) : clamp;
  14427. };
  14428. scale.interpolator = function(_) {
  14429. return arguments.length ? (interpolator = _, scale) : interpolator;
  14430. };
  14431. function range(interpolate) {
  14432. return function(_) {
  14433. var r0, r1;
  14434. return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)];
  14435. };
  14436. }
  14437. scale.range = range(interpolate$2);
  14438. scale.rangeRound = range(interpolateRound);
  14439. scale.unknown = function(_) {
  14440. return arguments.length ? (unknown = _, scale) : unknown;
  14441. };
  14442. return function(t) {
  14443. transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
  14444. return scale;
  14445. };
  14446. }
  14447. function copy(source, target) {
  14448. return target
  14449. .domain(source.domain())
  14450. .interpolator(source.interpolator())
  14451. .clamp(source.clamp())
  14452. .unknown(source.unknown());
  14453. }
  14454. function sequential() {
  14455. var scale = linearish(transformer$1()(identity$3));
  14456. scale.copy = function() {
  14457. return copy(scale, sequential());
  14458. };
  14459. return initInterpolator.apply(scale, arguments);
  14460. }
  14461. function sequentialLog() {
  14462. var scale = loggish(transformer$1()).domain([1, 10]);
  14463. scale.copy = function() {
  14464. return copy(scale, sequentialLog()).base(scale.base());
  14465. };
  14466. return initInterpolator.apply(scale, arguments);
  14467. }
  14468. function sequentialSymlog() {
  14469. var scale = symlogish(transformer$1());
  14470. scale.copy = function() {
  14471. return copy(scale, sequentialSymlog()).constant(scale.constant());
  14472. };
  14473. return initInterpolator.apply(scale, arguments);
  14474. }
  14475. function sequentialPow() {
  14476. var scale = powish(transformer$1());
  14477. scale.copy = function() {
  14478. return copy(scale, sequentialPow()).exponent(scale.exponent());
  14479. };
  14480. return initInterpolator.apply(scale, arguments);
  14481. }
  14482. function sequentialSqrt() {
  14483. return sequentialPow.apply(null, arguments).exponent(0.5);
  14484. }
  14485. function sequentialQuantile() {
  14486. var domain = [],
  14487. interpolator = identity$3;
  14488. function scale(x) {
  14489. if (x != null && !isNaN(x = +x)) return interpolator((bisect(domain, x, 1) - 1) / (domain.length - 1));
  14490. }
  14491. scale.domain = function(_) {
  14492. if (!arguments.length) return domain.slice();
  14493. domain = [];
  14494. for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
  14495. domain.sort(ascending$3);
  14496. return scale;
  14497. };
  14498. scale.interpolator = function(_) {
  14499. return arguments.length ? (interpolator = _, scale) : interpolator;
  14500. };
  14501. scale.range = function() {
  14502. return domain.map((d, i) => interpolator(i / (domain.length - 1)));
  14503. };
  14504. scale.quantiles = function(n) {
  14505. return Array.from({length: n + 1}, (_, i) => quantile$1(domain, i / n));
  14506. };
  14507. scale.copy = function() {
  14508. return sequentialQuantile(interpolator).domain(domain);
  14509. };
  14510. return initInterpolator.apply(scale, arguments);
  14511. }
  14512. function transformer() {
  14513. var x0 = 0,
  14514. x1 = 0.5,
  14515. x2 = 1,
  14516. s = 1,
  14517. t0,
  14518. t1,
  14519. t2,
  14520. k10,
  14521. k21,
  14522. interpolator = identity$3,
  14523. transform,
  14524. clamp = false,
  14525. unknown;
  14526. function scale(x) {
  14527. 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));
  14528. }
  14529. scale.domain = function(_) {
  14530. 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];
  14531. };
  14532. scale.clamp = function(_) {
  14533. return arguments.length ? (clamp = !!_, scale) : clamp;
  14534. };
  14535. scale.interpolator = function(_) {
  14536. return arguments.length ? (interpolator = _, scale) : interpolator;
  14537. };
  14538. function range(interpolate) {
  14539. return function(_) {
  14540. var r0, r1, r2;
  14541. return arguments.length ? ([r0, r1, r2] = _, interpolator = piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)];
  14542. };
  14543. }
  14544. scale.range = range(interpolate$2);
  14545. scale.rangeRound = range(interpolateRound);
  14546. scale.unknown = function(_) {
  14547. return arguments.length ? (unknown = _, scale) : unknown;
  14548. };
  14549. return function(t) {
  14550. 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;
  14551. return scale;
  14552. };
  14553. }
  14554. function diverging$1() {
  14555. var scale = linearish(transformer()(identity$3));
  14556. scale.copy = function() {
  14557. return copy(scale, diverging$1());
  14558. };
  14559. return initInterpolator.apply(scale, arguments);
  14560. }
  14561. function divergingLog() {
  14562. var scale = loggish(transformer()).domain([0.1, 1, 10]);
  14563. scale.copy = function() {
  14564. return copy(scale, divergingLog()).base(scale.base());
  14565. };
  14566. return initInterpolator.apply(scale, arguments);
  14567. }
  14568. function divergingSymlog() {
  14569. var scale = symlogish(transformer());
  14570. scale.copy = function() {
  14571. return copy(scale, divergingSymlog()).constant(scale.constant());
  14572. };
  14573. return initInterpolator.apply(scale, arguments);
  14574. }
  14575. function divergingPow() {
  14576. var scale = powish(transformer());
  14577. scale.copy = function() {
  14578. return copy(scale, divergingPow()).exponent(scale.exponent());
  14579. };
  14580. return initInterpolator.apply(scale, arguments);
  14581. }
  14582. function divergingSqrt() {
  14583. return divergingPow.apply(null, arguments).exponent(0.5);
  14584. }
  14585. function colors(specifier) {
  14586. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  14587. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  14588. return colors;
  14589. }
  14590. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  14591. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  14592. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  14593. var observable10 = colors("4269d0efb118ff725c6cc5b03ca951ff8ab7a463f297bbf59c6b4e9498a0");
  14594. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  14595. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  14596. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  14597. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  14598. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  14599. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  14600. var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
  14601. var ramp$1 = scheme => rgbBasis(scheme[scheme.length - 1]);
  14602. var scheme$q = new Array(3).concat(
  14603. "d8b365f5f5f55ab4ac",
  14604. "a6611adfc27d80cdc1018571",
  14605. "a6611adfc27df5f5f580cdc1018571",
  14606. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  14607. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  14608. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  14609. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  14610. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  14611. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  14612. ).map(colors);
  14613. var BrBG = ramp$1(scheme$q);
  14614. var scheme$p = new Array(3).concat(
  14615. "af8dc3f7f7f77fbf7b",
  14616. "7b3294c2a5cfa6dba0008837",
  14617. "7b3294c2a5cff7f7f7a6dba0008837",
  14618. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  14619. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  14620. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  14621. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  14622. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  14623. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  14624. ).map(colors);
  14625. var PRGn = ramp$1(scheme$p);
  14626. var scheme$o = new Array(3).concat(
  14627. "e9a3c9f7f7f7a1d76a",
  14628. "d01c8bf1b6dab8e1864dac26",
  14629. "d01c8bf1b6daf7f7f7b8e1864dac26",
  14630. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  14631. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  14632. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  14633. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  14634. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  14635. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  14636. ).map(colors);
  14637. var PiYG = ramp$1(scheme$o);
  14638. var scheme$n = new Array(3).concat(
  14639. "998ec3f7f7f7f1a340",
  14640. "5e3c99b2abd2fdb863e66101",
  14641. "5e3c99b2abd2f7f7f7fdb863e66101",
  14642. "542788998ec3d8daebfee0b6f1a340b35806",
  14643. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  14644. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  14645. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  14646. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  14647. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  14648. ).map(colors);
  14649. var PuOr = ramp$1(scheme$n);
  14650. var scheme$m = new Array(3).concat(
  14651. "ef8a62f7f7f767a9cf",
  14652. "ca0020f4a58292c5de0571b0",
  14653. "ca0020f4a582f7f7f792c5de0571b0",
  14654. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  14655. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  14656. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  14657. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  14658. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  14659. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  14660. ).map(colors);
  14661. var RdBu = ramp$1(scheme$m);
  14662. var scheme$l = new Array(3).concat(
  14663. "ef8a62ffffff999999",
  14664. "ca0020f4a582bababa404040",
  14665. "ca0020f4a582ffffffbababa404040",
  14666. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  14667. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  14668. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  14669. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  14670. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  14671. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  14672. ).map(colors);
  14673. var RdGy = ramp$1(scheme$l);
  14674. var scheme$k = new Array(3).concat(
  14675. "fc8d59ffffbf91bfdb",
  14676. "d7191cfdae61abd9e92c7bb6",
  14677. "d7191cfdae61ffffbfabd9e92c7bb6",
  14678. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  14679. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  14680. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  14681. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  14682. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  14683. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  14684. ).map(colors);
  14685. var RdYlBu = ramp$1(scheme$k);
  14686. var scheme$j = new Array(3).concat(
  14687. "fc8d59ffffbf91cf60",
  14688. "d7191cfdae61a6d96a1a9641",
  14689. "d7191cfdae61ffffbfa6d96a1a9641",
  14690. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  14691. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  14692. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  14693. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  14694. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  14695. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  14696. ).map(colors);
  14697. var RdYlGn = ramp$1(scheme$j);
  14698. var scheme$i = new Array(3).concat(
  14699. "fc8d59ffffbf99d594",
  14700. "d7191cfdae61abdda42b83ba",
  14701. "d7191cfdae61ffffbfabdda42b83ba",
  14702. "d53e4ffc8d59fee08be6f59899d5943288bd",
  14703. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  14704. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  14705. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  14706. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  14707. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  14708. ).map(colors);
  14709. var Spectral = ramp$1(scheme$i);
  14710. var scheme$h = new Array(3).concat(
  14711. "e5f5f999d8c92ca25f",
  14712. "edf8fbb2e2e266c2a4238b45",
  14713. "edf8fbb2e2e266c2a42ca25f006d2c",
  14714. "edf8fbccece699d8c966c2a42ca25f006d2c",
  14715. "edf8fbccece699d8c966c2a441ae76238b45005824",
  14716. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  14717. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  14718. ).map(colors);
  14719. var BuGn = ramp$1(scheme$h);
  14720. var scheme$g = new Array(3).concat(
  14721. "e0ecf49ebcda8856a7",
  14722. "edf8fbb3cde38c96c688419d",
  14723. "edf8fbb3cde38c96c68856a7810f7c",
  14724. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  14725. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  14726. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  14727. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  14728. ).map(colors);
  14729. var BuPu = ramp$1(scheme$g);
  14730. var scheme$f = new Array(3).concat(
  14731. "e0f3dba8ddb543a2ca",
  14732. "f0f9e8bae4bc7bccc42b8cbe",
  14733. "f0f9e8bae4bc7bccc443a2ca0868ac",
  14734. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  14735. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  14736. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  14737. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  14738. ).map(colors);
  14739. var GnBu = ramp$1(scheme$f);
  14740. var scheme$e = new Array(3).concat(
  14741. "fee8c8fdbb84e34a33",
  14742. "fef0d9fdcc8afc8d59d7301f",
  14743. "fef0d9fdcc8afc8d59e34a33b30000",
  14744. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  14745. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  14746. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  14747. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  14748. ).map(colors);
  14749. var OrRd = ramp$1(scheme$e);
  14750. var scheme$d = new Array(3).concat(
  14751. "ece2f0a6bddb1c9099",
  14752. "f6eff7bdc9e167a9cf02818a",
  14753. "f6eff7bdc9e167a9cf1c9099016c59",
  14754. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  14755. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  14756. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  14757. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  14758. ).map(colors);
  14759. var PuBuGn = ramp$1(scheme$d);
  14760. var scheme$c = new Array(3).concat(
  14761. "ece7f2a6bddb2b8cbe",
  14762. "f1eef6bdc9e174a9cf0570b0",
  14763. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  14764. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  14765. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  14766. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  14767. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  14768. ).map(colors);
  14769. var PuBu = ramp$1(scheme$c);
  14770. var scheme$b = new Array(3).concat(
  14771. "e7e1efc994c7dd1c77",
  14772. "f1eef6d7b5d8df65b0ce1256",
  14773. "f1eef6d7b5d8df65b0dd1c77980043",
  14774. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  14775. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  14776. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  14777. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  14778. ).map(colors);
  14779. var PuRd = ramp$1(scheme$b);
  14780. var scheme$a = new Array(3).concat(
  14781. "fde0ddfa9fb5c51b8a",
  14782. "feebe2fbb4b9f768a1ae017e",
  14783. "feebe2fbb4b9f768a1c51b8a7a0177",
  14784. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  14785. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  14786. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  14787. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  14788. ).map(colors);
  14789. var RdPu = ramp$1(scheme$a);
  14790. var scheme$9 = new Array(3).concat(
  14791. "edf8b17fcdbb2c7fb8",
  14792. "ffffcca1dab441b6c4225ea8",
  14793. "ffffcca1dab441b6c42c7fb8253494",
  14794. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  14795. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  14796. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  14797. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  14798. ).map(colors);
  14799. var YlGnBu = ramp$1(scheme$9);
  14800. var scheme$8 = new Array(3).concat(
  14801. "f7fcb9addd8e31a354",
  14802. "ffffccc2e69978c679238443",
  14803. "ffffccc2e69978c67931a354006837",
  14804. "ffffccd9f0a3addd8e78c67931a354006837",
  14805. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  14806. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  14807. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  14808. ).map(colors);
  14809. var YlGn = ramp$1(scheme$8);
  14810. var scheme$7 = new Array(3).concat(
  14811. "fff7bcfec44fd95f0e",
  14812. "ffffd4fed98efe9929cc4c02",
  14813. "ffffd4fed98efe9929d95f0e993404",
  14814. "ffffd4fee391fec44ffe9929d95f0e993404",
  14815. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  14816. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  14817. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  14818. ).map(colors);
  14819. var YlOrBr = ramp$1(scheme$7);
  14820. var scheme$6 = new Array(3).concat(
  14821. "ffeda0feb24cf03b20",
  14822. "ffffb2fecc5cfd8d3ce31a1c",
  14823. "ffffb2fecc5cfd8d3cf03b20bd0026",
  14824. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  14825. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  14826. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  14827. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  14828. ).map(colors);
  14829. var YlOrRd = ramp$1(scheme$6);
  14830. var scheme$5 = new Array(3).concat(
  14831. "deebf79ecae13182bd",
  14832. "eff3ffbdd7e76baed62171b5",
  14833. "eff3ffbdd7e76baed63182bd08519c",
  14834. "eff3ffc6dbef9ecae16baed63182bd08519c",
  14835. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  14836. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  14837. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  14838. ).map(colors);
  14839. var Blues = ramp$1(scheme$5);
  14840. var scheme$4 = new Array(3).concat(
  14841. "e5f5e0a1d99b31a354",
  14842. "edf8e9bae4b374c476238b45",
  14843. "edf8e9bae4b374c47631a354006d2c",
  14844. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  14845. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  14846. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  14847. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  14848. ).map(colors);
  14849. var Greens = ramp$1(scheme$4);
  14850. var scheme$3 = new Array(3).concat(
  14851. "f0f0f0bdbdbd636363",
  14852. "f7f7f7cccccc969696525252",
  14853. "f7f7f7cccccc969696636363252525",
  14854. "f7f7f7d9d9d9bdbdbd969696636363252525",
  14855. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  14856. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  14857. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  14858. ).map(colors);
  14859. var Greys = ramp$1(scheme$3);
  14860. var scheme$2 = new Array(3).concat(
  14861. "efedf5bcbddc756bb1",
  14862. "f2f0f7cbc9e29e9ac86a51a3",
  14863. "f2f0f7cbc9e29e9ac8756bb154278f",
  14864. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  14865. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  14866. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  14867. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  14868. ).map(colors);
  14869. var Purples = ramp$1(scheme$2);
  14870. var scheme$1 = new Array(3).concat(
  14871. "fee0d2fc9272de2d26",
  14872. "fee5d9fcae91fb6a4acb181d",
  14873. "fee5d9fcae91fb6a4ade2d26a50f15",
  14874. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  14875. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  14876. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  14877. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  14878. ).map(colors);
  14879. var Reds = ramp$1(scheme$1);
  14880. var scheme = new Array(3).concat(
  14881. "fee6cefdae6be6550d",
  14882. "feeddefdbe85fd8d3cd94701",
  14883. "feeddefdbe85fd8d3ce6550da63603",
  14884. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  14885. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  14886. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  14887. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  14888. ).map(colors);
  14889. var Oranges = ramp$1(scheme);
  14890. function cividis(t) {
  14891. t = Math.max(0, Math.min(1, t));
  14892. return "rgb("
  14893. + Math.max(0, Math.min(255, Math.round(-4.54 - t * (35.34 - t * (2381.73 - t * (6402.7 - t * (7024.72 - t * 2710.57))))))) + ", "
  14894. + Math.max(0, Math.min(255, Math.round(32.49 + t * (170.73 + t * (52.82 - t * (131.46 - t * (176.58 - t * 67.37))))))) + ", "
  14895. + Math.max(0, Math.min(255, Math.round(81.24 + t * (442.36 - t * (2482.43 - t * (6167.24 - t * (6614.94 - t * 2475.67)))))))
  14896. + ")";
  14897. }
  14898. var cubehelix = cubehelixLong(cubehelix$3(300, 0.5, 0.0), cubehelix$3(-240, 0.5, 1.0));
  14899. var warm = cubehelixLong(cubehelix$3(-100, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
  14900. var cool = cubehelixLong(cubehelix$3(260, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
  14901. var c$2 = cubehelix$3();
  14902. function rainbow(t) {
  14903. if (t < 0 || t > 1) t -= Math.floor(t);
  14904. var ts = Math.abs(t - 0.5);
  14905. c$2.h = 360 * t - 100;
  14906. c$2.s = 1.5 - 1.5 * ts;
  14907. c$2.l = 0.8 - 0.9 * ts;
  14908. return c$2 + "";
  14909. }
  14910. var c$1 = rgb(),
  14911. pi_1_3 = Math.PI / 3,
  14912. pi_2_3 = Math.PI * 2 / 3;
  14913. function sinebow(t) {
  14914. var x;
  14915. t = (0.5 - t) * Math.PI;
  14916. c$1.r = 255 * (x = Math.sin(t)) * x;
  14917. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  14918. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  14919. return c$1 + "";
  14920. }
  14921. function turbo(t) {
  14922. t = Math.max(0, Math.min(1, t));
  14923. return "rgb("
  14924. + Math.max(0, Math.min(255, Math.round(34.61 + t * (1172.33 - t * (10793.56 - t * (33300.12 - t * (38394.49 - t * 14825.05))))))) + ", "
  14925. + Math.max(0, Math.min(255, Math.round(23.31 + t * (557.33 + t * (1225.33 - t * (3574.96 - t * (1073.77 + t * 707.56))))))) + ", "
  14926. + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
  14927. + ")";
  14928. }
  14929. function ramp(range) {
  14930. var n = range.length;
  14931. return function(t) {
  14932. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  14933. };
  14934. }
  14935. var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  14936. var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  14937. var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  14938. var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  14939. function constant$1(x) {
  14940. return function constant() {
  14941. return x;
  14942. };
  14943. }
  14944. const abs = Math.abs;
  14945. const atan2 = Math.atan2;
  14946. const cos = Math.cos;
  14947. const max = Math.max;
  14948. const min = Math.min;
  14949. const sin = Math.sin;
  14950. const sqrt = Math.sqrt;
  14951. const epsilon = 1e-12;
  14952. const pi = Math.PI;
  14953. const halfPi = pi / 2;
  14954. const tau = 2 * pi;
  14955. function acos(x) {
  14956. return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
  14957. }
  14958. function asin(x) {
  14959. return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
  14960. }
  14961. function withPath(shape) {
  14962. let digits = 3;
  14963. shape.digits = function(_) {
  14964. if (!arguments.length) return digits;
  14965. if (_ == null) {
  14966. digits = null;
  14967. } else {
  14968. const d = Math.floor(_);
  14969. if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
  14970. digits = d;
  14971. }
  14972. return shape;
  14973. };
  14974. return () => new Path$1(digits);
  14975. }
  14976. function arcInnerRadius(d) {
  14977. return d.innerRadius;
  14978. }
  14979. function arcOuterRadius(d) {
  14980. return d.outerRadius;
  14981. }
  14982. function arcStartAngle(d) {
  14983. return d.startAngle;
  14984. }
  14985. function arcEndAngle(d) {
  14986. return d.endAngle;
  14987. }
  14988. function arcPadAngle(d) {
  14989. return d && d.padAngle; // Note: optional!
  14990. }
  14991. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  14992. var x10 = x1 - x0, y10 = y1 - y0,
  14993. x32 = x3 - x2, y32 = y3 - y2,
  14994. t = y32 * x10 - x32 * y10;
  14995. if (t * t < epsilon) return;
  14996. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  14997. return [x0 + t * x10, y0 + t * y10];
  14998. }
  14999. // Compute perpendicular offset line of length rc.
  15000. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  15001. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  15002. var x01 = x0 - x1,
  15003. y01 = y0 - y1,
  15004. lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),
  15005. ox = lo * y01,
  15006. oy = -lo * x01,
  15007. x11 = x0 + ox,
  15008. y11 = y0 + oy,
  15009. x10 = x1 + ox,
  15010. y10 = y1 + oy,
  15011. x00 = (x11 + x10) / 2,
  15012. y00 = (y11 + y10) / 2,
  15013. dx = x10 - x11,
  15014. dy = y10 - y11,
  15015. d2 = dx * dx + dy * dy,
  15016. r = r1 - rc,
  15017. D = x11 * y10 - x10 * y11,
  15018. d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),
  15019. cx0 = (D * dy - dx * d) / d2,
  15020. cy0 = (-D * dx - dy * d) / d2,
  15021. cx1 = (D * dy + dx * d) / d2,
  15022. cy1 = (-D * dx + dy * d) / d2,
  15023. dx0 = cx0 - x00,
  15024. dy0 = cy0 - y00,
  15025. dx1 = cx1 - x00,
  15026. dy1 = cy1 - y00;
  15027. // Pick the closer of the two intersection points.
  15028. // TODO Is there a faster way to determine which intersection to use?
  15029. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  15030. return {
  15031. cx: cx0,
  15032. cy: cy0,
  15033. x01: -ox,
  15034. y01: -oy,
  15035. x11: cx0 * (r1 / r - 1),
  15036. y11: cy0 * (r1 / r - 1)
  15037. };
  15038. }
  15039. function arc() {
  15040. var innerRadius = arcInnerRadius,
  15041. outerRadius = arcOuterRadius,
  15042. cornerRadius = constant$1(0),
  15043. padRadius = null,
  15044. startAngle = arcStartAngle,
  15045. endAngle = arcEndAngle,
  15046. padAngle = arcPadAngle,
  15047. context = null,
  15048. path = withPath(arc);
  15049. function arc() {
  15050. var buffer,
  15051. r,
  15052. r0 = +innerRadius.apply(this, arguments),
  15053. r1 = +outerRadius.apply(this, arguments),
  15054. a0 = startAngle.apply(this, arguments) - halfPi,
  15055. a1 = endAngle.apply(this, arguments) - halfPi,
  15056. da = abs(a1 - a0),
  15057. cw = a1 > a0;
  15058. if (!context) context = buffer = path();
  15059. // Ensure that the outer radius is always larger than the inner radius.
  15060. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  15061. // Is it a point?
  15062. if (!(r1 > epsilon)) context.moveTo(0, 0);
  15063. // Or is it a circle or annulus?
  15064. else if (da > tau - epsilon) {
  15065. context.moveTo(r1 * cos(a0), r1 * sin(a0));
  15066. context.arc(0, 0, r1, a0, a1, !cw);
  15067. if (r0 > epsilon) {
  15068. context.moveTo(r0 * cos(a1), r0 * sin(a1));
  15069. context.arc(0, 0, r0, a1, a0, cw);
  15070. }
  15071. }
  15072. // Or is it a circular or annular sector?
  15073. else {
  15074. var a01 = a0,
  15075. a11 = a1,
  15076. a00 = a0,
  15077. a10 = a1,
  15078. da0 = da,
  15079. da1 = da,
  15080. ap = padAngle.apply(this, arguments) / 2,
  15081. rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),
  15082. rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  15083. rc0 = rc,
  15084. rc1 = rc,
  15085. t0,
  15086. t1;
  15087. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  15088. if (rp > epsilon) {
  15089. var p0 = asin(rp / r0 * sin(ap)),
  15090. p1 = asin(rp / r1 * sin(ap));
  15091. if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  15092. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  15093. if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  15094. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  15095. }
  15096. var x01 = r1 * cos(a01),
  15097. y01 = r1 * sin(a01),
  15098. x10 = r0 * cos(a10),
  15099. y10 = r0 * sin(a10);
  15100. // Apply rounded corners?
  15101. if (rc > epsilon) {
  15102. var x11 = r1 * cos(a11),
  15103. y11 = r1 * sin(a11),
  15104. x00 = r0 * cos(a00),
  15105. y00 = r0 * sin(a00),
  15106. oc;
  15107. // Restrict the corner radius according to the sector angle. If this
  15108. // intersection fails, it’s probably because the arc is too small, so
  15109. // disable the corner radius entirely.
  15110. if (da < pi) {
  15111. if (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10)) {
  15112. var ax = x01 - oc[0],
  15113. ay = y01 - oc[1],
  15114. bx = x11 - oc[0],
  15115. by = y11 - oc[1],
  15116. kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),
  15117. lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  15118. rc0 = min(rc, (r0 - lc) / (kc - 1));
  15119. rc1 = min(rc, (r1 - lc) / (kc + 1));
  15120. } else {
  15121. rc0 = rc1 = 0;
  15122. }
  15123. }
  15124. }
  15125. // Is the sector collapsed to a line?
  15126. if (!(da1 > epsilon)) context.moveTo(x01, y01);
  15127. // Does the sector’s outer ring have rounded corners?
  15128. else if (rc1 > epsilon) {
  15129. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  15130. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  15131. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  15132. // Have the corners merged?
  15133. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
  15134. // Otherwise, draw the two corners and the ring.
  15135. else {
  15136. context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
  15137. context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  15138. context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
  15139. }
  15140. }
  15141. // Or is the outer ring just a circular arc?
  15142. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  15143. // Is there no inner ring, and it’s a circular sector?
  15144. // Or perhaps it’s an annular sector collapsed due to padding?
  15145. if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);
  15146. // Does the sector’s inner ring (or point) have rounded corners?
  15147. else if (rc0 > epsilon) {
  15148. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  15149. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  15150. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  15151. // Have the corners merged?
  15152. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
  15153. // Otherwise, draw the two corners and the ring.
  15154. else {
  15155. context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
  15156. context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  15157. context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
  15158. }
  15159. }
  15160. // Or is the inner ring just a circular arc?
  15161. else context.arc(0, 0, r0, a10, a00, cw);
  15162. }
  15163. context.closePath();
  15164. if (buffer) return context = null, buffer + "" || null;
  15165. }
  15166. arc.centroid = function() {
  15167. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  15168. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
  15169. return [cos(a) * r, sin(a) * r];
  15170. };
  15171. arc.innerRadius = function(_) {
  15172. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : innerRadius;
  15173. };
  15174. arc.outerRadius = function(_) {
  15175. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : outerRadius;
  15176. };
  15177. arc.cornerRadius = function(_) {
  15178. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : cornerRadius;
  15179. };
  15180. arc.padRadius = function(_) {
  15181. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), arc) : padRadius;
  15182. };
  15183. arc.startAngle = function(_) {
  15184. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : startAngle;
  15185. };
  15186. arc.endAngle = function(_) {
  15187. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : endAngle;
  15188. };
  15189. arc.padAngle = function(_) {
  15190. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : padAngle;
  15191. };
  15192. arc.context = function(_) {
  15193. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  15194. };
  15195. return arc;
  15196. }
  15197. var slice = Array.prototype.slice;
  15198. function array(x) {
  15199. return typeof x === "object" && "length" in x
  15200. ? x // Array, TypedArray, NodeList, array-like
  15201. : Array.from(x); // Map, Set, iterable, string, or anything else
  15202. }
  15203. function Linear(context) {
  15204. this._context = context;
  15205. }
  15206. Linear.prototype = {
  15207. areaStart: function() {
  15208. this._line = 0;
  15209. },
  15210. areaEnd: function() {
  15211. this._line = NaN;
  15212. },
  15213. lineStart: function() {
  15214. this._point = 0;
  15215. },
  15216. lineEnd: function() {
  15217. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15218. this._line = 1 - this._line;
  15219. },
  15220. point: function(x, y) {
  15221. x = +x, y = +y;
  15222. switch (this._point) {
  15223. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15224. case 1: this._point = 2; // falls through
  15225. default: this._context.lineTo(x, y); break;
  15226. }
  15227. }
  15228. };
  15229. function curveLinear(context) {
  15230. return new Linear(context);
  15231. }
  15232. function x(p) {
  15233. return p[0];
  15234. }
  15235. function y(p) {
  15236. return p[1];
  15237. }
  15238. function line(x$1, y$1) {
  15239. var defined = constant$1(true),
  15240. context = null,
  15241. curve = curveLinear,
  15242. output = null,
  15243. path = withPath(line);
  15244. x$1 = typeof x$1 === "function" ? x$1 : (x$1 === undefined) ? x : constant$1(x$1);
  15245. y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant$1(y$1);
  15246. function line(data) {
  15247. var i,
  15248. n = (data = array(data)).length,
  15249. d,
  15250. defined0 = false,
  15251. buffer;
  15252. if (context == null) output = curve(buffer = path());
  15253. for (i = 0; i <= n; ++i) {
  15254. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  15255. if (defined0 = !defined0) output.lineStart();
  15256. else output.lineEnd();
  15257. }
  15258. if (defined0) output.point(+x$1(d, i, data), +y$1(d, i, data));
  15259. }
  15260. if (buffer) return output = null, buffer + "" || null;
  15261. }
  15262. line.x = function(_) {
  15263. return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), line) : x$1;
  15264. };
  15265. line.y = function(_) {
  15266. return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), line) : y$1;
  15267. };
  15268. line.defined = function(_) {
  15269. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), line) : defined;
  15270. };
  15271. line.curve = function(_) {
  15272. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  15273. };
  15274. line.context = function(_) {
  15275. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  15276. };
  15277. return line;
  15278. }
  15279. function area(x0, y0, y1) {
  15280. var x1 = null,
  15281. defined = constant$1(true),
  15282. context = null,
  15283. curve = curveLinear,
  15284. output = null,
  15285. path = withPath(area);
  15286. x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x : constant$1(+x0);
  15287. y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant$1(0) : constant$1(+y0);
  15288. y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant$1(+y1);
  15289. function area(data) {
  15290. var i,
  15291. j,
  15292. k,
  15293. n = (data = array(data)).length,
  15294. d,
  15295. defined0 = false,
  15296. buffer,
  15297. x0z = new Array(n),
  15298. y0z = new Array(n);
  15299. if (context == null) output = curve(buffer = path());
  15300. for (i = 0; i <= n; ++i) {
  15301. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  15302. if (defined0 = !defined0) {
  15303. j = i;
  15304. output.areaStart();
  15305. output.lineStart();
  15306. } else {
  15307. output.lineEnd();
  15308. output.lineStart();
  15309. for (k = i - 1; k >= j; --k) {
  15310. output.point(x0z[k], y0z[k]);
  15311. }
  15312. output.lineEnd();
  15313. output.areaEnd();
  15314. }
  15315. }
  15316. if (defined0) {
  15317. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  15318. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  15319. }
  15320. }
  15321. if (buffer) return output = null, buffer + "" || null;
  15322. }
  15323. function arealine() {
  15324. return line().defined(defined).curve(curve).context(context);
  15325. }
  15326. area.x = function(_) {
  15327. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), x1 = null, area) : x0;
  15328. };
  15329. area.x0 = function(_) {
  15330. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), area) : x0;
  15331. };
  15332. area.x1 = function(_) {
  15333. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : x1;
  15334. };
  15335. area.y = function(_) {
  15336. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), y1 = null, area) : y0;
  15337. };
  15338. area.y0 = function(_) {
  15339. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), area) : y0;
  15340. };
  15341. area.y1 = function(_) {
  15342. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : y1;
  15343. };
  15344. area.lineX0 =
  15345. area.lineY0 = function() {
  15346. return arealine().x(x0).y(y0);
  15347. };
  15348. area.lineY1 = function() {
  15349. return arealine().x(x0).y(y1);
  15350. };
  15351. area.lineX1 = function() {
  15352. return arealine().x(x1).y(y0);
  15353. };
  15354. area.defined = function(_) {
  15355. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), area) : defined;
  15356. };
  15357. area.curve = function(_) {
  15358. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  15359. };
  15360. area.context = function(_) {
  15361. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  15362. };
  15363. return area;
  15364. }
  15365. function descending$1(a, b) {
  15366. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  15367. }
  15368. function identity$1(d) {
  15369. return d;
  15370. }
  15371. function pie() {
  15372. var value = identity$1,
  15373. sortValues = descending$1,
  15374. sort = null,
  15375. startAngle = constant$1(0),
  15376. endAngle = constant$1(tau),
  15377. padAngle = constant$1(0);
  15378. function pie(data) {
  15379. var i,
  15380. n = (data = array(data)).length,
  15381. j,
  15382. k,
  15383. sum = 0,
  15384. index = new Array(n),
  15385. arcs = new Array(n),
  15386. a0 = +startAngle.apply(this, arguments),
  15387. da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),
  15388. a1,
  15389. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  15390. pa = p * (da < 0 ? -1 : 1),
  15391. v;
  15392. for (i = 0; i < n; ++i) {
  15393. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  15394. sum += v;
  15395. }
  15396. }
  15397. // Optionally sort the arcs by previously-computed values or by data.
  15398. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  15399. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  15400. // Compute the arcs! They are stored in the original data's order.
  15401. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  15402. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  15403. data: data[j],
  15404. index: i,
  15405. value: v,
  15406. startAngle: a0,
  15407. endAngle: a1,
  15408. padAngle: p
  15409. };
  15410. }
  15411. return arcs;
  15412. }
  15413. pie.value = function(_) {
  15414. return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value;
  15415. };
  15416. pie.sortValues = function(_) {
  15417. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  15418. };
  15419. pie.sort = function(_) {
  15420. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  15421. };
  15422. pie.startAngle = function(_) {
  15423. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : startAngle;
  15424. };
  15425. pie.endAngle = function(_) {
  15426. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : endAngle;
  15427. };
  15428. pie.padAngle = function(_) {
  15429. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : padAngle;
  15430. };
  15431. return pie;
  15432. }
  15433. var curveRadialLinear = curveRadial(curveLinear);
  15434. function Radial(curve) {
  15435. this._curve = curve;
  15436. }
  15437. Radial.prototype = {
  15438. areaStart: function() {
  15439. this._curve.areaStart();
  15440. },
  15441. areaEnd: function() {
  15442. this._curve.areaEnd();
  15443. },
  15444. lineStart: function() {
  15445. this._curve.lineStart();
  15446. },
  15447. lineEnd: function() {
  15448. this._curve.lineEnd();
  15449. },
  15450. point: function(a, r) {
  15451. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  15452. }
  15453. };
  15454. function curveRadial(curve) {
  15455. function radial(context) {
  15456. return new Radial(curve(context));
  15457. }
  15458. radial._curve = curve;
  15459. return radial;
  15460. }
  15461. function lineRadial(l) {
  15462. var c = l.curve;
  15463. l.angle = l.x, delete l.x;
  15464. l.radius = l.y, delete l.y;
  15465. l.curve = function(_) {
  15466. return arguments.length ? c(curveRadial(_)) : c()._curve;
  15467. };
  15468. return l;
  15469. }
  15470. function lineRadial$1() {
  15471. return lineRadial(line().curve(curveRadialLinear));
  15472. }
  15473. function areaRadial() {
  15474. var a = area().curve(curveRadialLinear),
  15475. c = a.curve,
  15476. x0 = a.lineX0,
  15477. x1 = a.lineX1,
  15478. y0 = a.lineY0,
  15479. y1 = a.lineY1;
  15480. a.angle = a.x, delete a.x;
  15481. a.startAngle = a.x0, delete a.x0;
  15482. a.endAngle = a.x1, delete a.x1;
  15483. a.radius = a.y, delete a.y;
  15484. a.innerRadius = a.y0, delete a.y0;
  15485. a.outerRadius = a.y1, delete a.y1;
  15486. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  15487. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  15488. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  15489. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  15490. a.curve = function(_) {
  15491. return arguments.length ? c(curveRadial(_)) : c()._curve;
  15492. };
  15493. return a;
  15494. }
  15495. function pointRadial(x, y) {
  15496. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  15497. }
  15498. class Bump {
  15499. constructor(context, x) {
  15500. this._context = context;
  15501. this._x = x;
  15502. }
  15503. areaStart() {
  15504. this._line = 0;
  15505. }
  15506. areaEnd() {
  15507. this._line = NaN;
  15508. }
  15509. lineStart() {
  15510. this._point = 0;
  15511. }
  15512. lineEnd() {
  15513. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15514. this._line = 1 - this._line;
  15515. }
  15516. point(x, y) {
  15517. x = +x, y = +y;
  15518. switch (this._point) {
  15519. case 0: {
  15520. this._point = 1;
  15521. if (this._line) this._context.lineTo(x, y);
  15522. else this._context.moveTo(x, y);
  15523. break;
  15524. }
  15525. case 1: this._point = 2; // falls through
  15526. default: {
  15527. if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
  15528. else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
  15529. break;
  15530. }
  15531. }
  15532. this._x0 = x, this._y0 = y;
  15533. }
  15534. }
  15535. class BumpRadial {
  15536. constructor(context) {
  15537. this._context = context;
  15538. }
  15539. lineStart() {
  15540. this._point = 0;
  15541. }
  15542. lineEnd() {}
  15543. point(x, y) {
  15544. x = +x, y = +y;
  15545. if (this._point === 0) {
  15546. this._point = 1;
  15547. } else {
  15548. const p0 = pointRadial(this._x0, this._y0);
  15549. const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2);
  15550. const p2 = pointRadial(x, this._y0);
  15551. const p3 = pointRadial(x, y);
  15552. this._context.moveTo(...p0);
  15553. this._context.bezierCurveTo(...p1, ...p2, ...p3);
  15554. }
  15555. this._x0 = x, this._y0 = y;
  15556. }
  15557. }
  15558. function bumpX(context) {
  15559. return new Bump(context, true);
  15560. }
  15561. function bumpY(context) {
  15562. return new Bump(context, false);
  15563. }
  15564. function bumpRadial(context) {
  15565. return new BumpRadial(context);
  15566. }
  15567. function linkSource(d) {
  15568. return d.source;
  15569. }
  15570. function linkTarget(d) {
  15571. return d.target;
  15572. }
  15573. function link(curve) {
  15574. let source = linkSource,
  15575. target = linkTarget,
  15576. x$1 = x,
  15577. y$1 = y,
  15578. context = null,
  15579. output = null,
  15580. path = withPath(link);
  15581. function link() {
  15582. let buffer;
  15583. const argv = slice.call(arguments);
  15584. const s = source.apply(this, argv);
  15585. const t = target.apply(this, argv);
  15586. if (context == null) output = curve(buffer = path());
  15587. output.lineStart();
  15588. argv[0] = s, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
  15589. argv[0] = t, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
  15590. output.lineEnd();
  15591. if (buffer) return output = null, buffer + "" || null;
  15592. }
  15593. link.source = function(_) {
  15594. return arguments.length ? (source = _, link) : source;
  15595. };
  15596. link.target = function(_) {
  15597. return arguments.length ? (target = _, link) : target;
  15598. };
  15599. link.x = function(_) {
  15600. return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), link) : x$1;
  15601. };
  15602. link.y = function(_) {
  15603. return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), link) : y$1;
  15604. };
  15605. link.context = function(_) {
  15606. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), link) : context;
  15607. };
  15608. return link;
  15609. }
  15610. function linkHorizontal() {
  15611. return link(bumpX);
  15612. }
  15613. function linkVertical() {
  15614. return link(bumpY);
  15615. }
  15616. function linkRadial() {
  15617. const l = link(bumpRadial);
  15618. l.angle = l.x, delete l.x;
  15619. l.radius = l.y, delete l.y;
  15620. return l;
  15621. }
  15622. const sqrt3$2 = sqrt(3);
  15623. var asterisk = {
  15624. draw(context, size) {
  15625. const r = sqrt(size + min(size / 28, 0.75)) * 0.59436;
  15626. const t = r / 2;
  15627. const u = t * sqrt3$2;
  15628. context.moveTo(0, r);
  15629. context.lineTo(0, -r);
  15630. context.moveTo(-u, -t);
  15631. context.lineTo(u, t);
  15632. context.moveTo(-u, t);
  15633. context.lineTo(u, -t);
  15634. }
  15635. };
  15636. var circle = {
  15637. draw(context, size) {
  15638. const r = sqrt(size / pi);
  15639. context.moveTo(r, 0);
  15640. context.arc(0, 0, r, 0, tau);
  15641. }
  15642. };
  15643. var cross = {
  15644. draw(context, size) {
  15645. const r = sqrt(size / 5) / 2;
  15646. context.moveTo(-3 * r, -r);
  15647. context.lineTo(-r, -r);
  15648. context.lineTo(-r, -3 * r);
  15649. context.lineTo(r, -3 * r);
  15650. context.lineTo(r, -r);
  15651. context.lineTo(3 * r, -r);
  15652. context.lineTo(3 * r, r);
  15653. context.lineTo(r, r);
  15654. context.lineTo(r, 3 * r);
  15655. context.lineTo(-r, 3 * r);
  15656. context.lineTo(-r, r);
  15657. context.lineTo(-3 * r, r);
  15658. context.closePath();
  15659. }
  15660. };
  15661. const tan30 = sqrt(1 / 3);
  15662. const tan30_2 = tan30 * 2;
  15663. var diamond = {
  15664. draw(context, size) {
  15665. const y = sqrt(size / tan30_2);
  15666. const x = y * tan30;
  15667. context.moveTo(0, -y);
  15668. context.lineTo(x, 0);
  15669. context.lineTo(0, y);
  15670. context.lineTo(-x, 0);
  15671. context.closePath();
  15672. }
  15673. };
  15674. var diamond2 = {
  15675. draw(context, size) {
  15676. const r = sqrt(size) * 0.62625;
  15677. context.moveTo(0, -r);
  15678. context.lineTo(r, 0);
  15679. context.lineTo(0, r);
  15680. context.lineTo(-r, 0);
  15681. context.closePath();
  15682. }
  15683. };
  15684. var plus = {
  15685. draw(context, size) {
  15686. const r = sqrt(size - min(size / 7, 2)) * 0.87559;
  15687. context.moveTo(-r, 0);
  15688. context.lineTo(r, 0);
  15689. context.moveTo(0, r);
  15690. context.lineTo(0, -r);
  15691. }
  15692. };
  15693. var square = {
  15694. draw(context, size) {
  15695. const w = sqrt(size);
  15696. const x = -w / 2;
  15697. context.rect(x, x, w, w);
  15698. }
  15699. };
  15700. var square2 = {
  15701. draw(context, size) {
  15702. const r = sqrt(size) * 0.4431;
  15703. context.moveTo(r, r);
  15704. context.lineTo(r, -r);
  15705. context.lineTo(-r, -r);
  15706. context.lineTo(-r, r);
  15707. context.closePath();
  15708. }
  15709. };
  15710. const ka = 0.89081309152928522810;
  15711. const kr = sin(pi / 10) / sin(7 * pi / 10);
  15712. const kx = sin(tau / 10) * kr;
  15713. const ky = -cos(tau / 10) * kr;
  15714. var star = {
  15715. draw(context, size) {
  15716. const r = sqrt(size * ka);
  15717. const x = kx * r;
  15718. const y = ky * r;
  15719. context.moveTo(0, -r);
  15720. context.lineTo(x, y);
  15721. for (let i = 1; i < 5; ++i) {
  15722. const a = tau * i / 5;
  15723. const c = cos(a);
  15724. const s = sin(a);
  15725. context.lineTo(s * r, -c * r);
  15726. context.lineTo(c * x - s * y, s * x + c * y);
  15727. }
  15728. context.closePath();
  15729. }
  15730. };
  15731. const sqrt3$1 = sqrt(3);
  15732. var triangle = {
  15733. draw(context, size) {
  15734. const y = -sqrt(size / (sqrt3$1 * 3));
  15735. context.moveTo(0, y * 2);
  15736. context.lineTo(-sqrt3$1 * y, -y);
  15737. context.lineTo(sqrt3$1 * y, -y);
  15738. context.closePath();
  15739. }
  15740. };
  15741. const sqrt3 = sqrt(3);
  15742. var triangle2 = {
  15743. draw(context, size) {
  15744. const s = sqrt(size) * 0.6824;
  15745. const t = s / 2;
  15746. const u = (s * sqrt3) / 2; // cos(Math.PI / 6)
  15747. context.moveTo(0, -s);
  15748. context.lineTo(u, t);
  15749. context.lineTo(-u, t);
  15750. context.closePath();
  15751. }
  15752. };
  15753. const c = -0.5;
  15754. const s = sqrt(3) / 2;
  15755. const k = 1 / sqrt(12);
  15756. const a = (k / 2 + 1) * 3;
  15757. var wye = {
  15758. draw(context, size) {
  15759. const r = sqrt(size / a);
  15760. const x0 = r / 2, y0 = r * k;
  15761. const x1 = x0, y1 = r * k + r;
  15762. const x2 = -x1, y2 = y1;
  15763. context.moveTo(x0, y0);
  15764. context.lineTo(x1, y1);
  15765. context.lineTo(x2, y2);
  15766. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  15767. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  15768. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  15769. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  15770. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  15771. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  15772. context.closePath();
  15773. }
  15774. };
  15775. var times = {
  15776. draw(context, size) {
  15777. const r = sqrt(size - min(size / 6, 1.7)) * 0.6189;
  15778. context.moveTo(-r, -r);
  15779. context.lineTo(r, r);
  15780. context.moveTo(-r, r);
  15781. context.lineTo(r, -r);
  15782. }
  15783. };
  15784. // These symbols are designed to be filled.
  15785. const symbolsFill = [
  15786. circle,
  15787. cross,
  15788. diamond,
  15789. square,
  15790. star,
  15791. triangle,
  15792. wye
  15793. ];
  15794. // These symbols are designed to be stroked (with a width of 1.5px and round caps).
  15795. const symbolsStroke = [
  15796. circle,
  15797. plus,
  15798. times,
  15799. triangle2,
  15800. asterisk,
  15801. square2,
  15802. diamond2
  15803. ];
  15804. function Symbol$1(type, size) {
  15805. let context = null,
  15806. path = withPath(symbol);
  15807. type = typeof type === "function" ? type : constant$1(type || circle);
  15808. size = typeof size === "function" ? size : constant$1(size === undefined ? 64 : +size);
  15809. function symbol() {
  15810. let buffer;
  15811. if (!context) context = buffer = path();
  15812. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  15813. if (buffer) return context = null, buffer + "" || null;
  15814. }
  15815. symbol.type = function(_) {
  15816. return arguments.length ? (type = typeof _ === "function" ? _ : constant$1(_), symbol) : type;
  15817. };
  15818. symbol.size = function(_) {
  15819. return arguments.length ? (size = typeof _ === "function" ? _ : constant$1(+_), symbol) : size;
  15820. };
  15821. symbol.context = function(_) {
  15822. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  15823. };
  15824. return symbol;
  15825. }
  15826. function noop() {}
  15827. function point$3(that, x, y) {
  15828. that._context.bezierCurveTo(
  15829. (2 * that._x0 + that._x1) / 3,
  15830. (2 * that._y0 + that._y1) / 3,
  15831. (that._x0 + 2 * that._x1) / 3,
  15832. (that._y0 + 2 * that._y1) / 3,
  15833. (that._x0 + 4 * that._x1 + x) / 6,
  15834. (that._y0 + 4 * that._y1 + y) / 6
  15835. );
  15836. }
  15837. function Basis(context) {
  15838. this._context = context;
  15839. }
  15840. Basis.prototype = {
  15841. areaStart: function() {
  15842. this._line = 0;
  15843. },
  15844. areaEnd: function() {
  15845. this._line = NaN;
  15846. },
  15847. lineStart: function() {
  15848. this._x0 = this._x1 =
  15849. this._y0 = this._y1 = NaN;
  15850. this._point = 0;
  15851. },
  15852. lineEnd: function() {
  15853. switch (this._point) {
  15854. case 3: point$3(this, this._x1, this._y1); // falls through
  15855. case 2: this._context.lineTo(this._x1, this._y1); break;
  15856. }
  15857. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  15858. this._line = 1 - this._line;
  15859. },
  15860. point: function(x, y) {
  15861. x = +x, y = +y;
  15862. switch (this._point) {
  15863. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  15864. case 1: this._point = 2; break;
  15865. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through
  15866. default: point$3(this, x, y); break;
  15867. }
  15868. this._x0 = this._x1, this._x1 = x;
  15869. this._y0 = this._y1, this._y1 = y;
  15870. }
  15871. };
  15872. function basis(context) {
  15873. return new Basis(context);
  15874. }
  15875. function BasisClosed(context) {
  15876. this._context = context;
  15877. }
  15878. BasisClosed.prototype = {
  15879. areaStart: noop,
  15880. areaEnd: noop,
  15881. lineStart: function() {
  15882. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  15883. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  15884. this._point = 0;
  15885. },
  15886. lineEnd: function() {
  15887. switch (this._point) {
  15888. case 1: {
  15889. this._context.moveTo(this._x2, this._y2);
  15890. this._context.closePath();
  15891. break;
  15892. }
  15893. case 2: {
  15894. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  15895. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  15896. this._context.closePath();
  15897. break;
  15898. }
  15899. case 3: {
  15900. this.point(this._x2, this._y2);
  15901. this.point(this._x3, this._y3);
  15902. this.point(this._x4, this._y4);
  15903. break;
  15904. }
  15905. }
  15906. },
  15907. point: function(x, y) {
  15908. x = +x, y = +y;
  15909. switch (this._point) {
  15910. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  15911. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  15912. case 2: this._point = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
  15913. default: point$3(this, x, y); break;
  15914. }
  15915. this._x0 = this._x1, this._x1 = x;
  15916. this._y0 = this._y1, this._y1 = y;
  15917. }
  15918. };
  15919. function basisClosed(context) {
  15920. return new BasisClosed(context);
  15921. }
  15922. function BasisOpen(context) {
  15923. this._context = context;
  15924. }
  15925. BasisOpen.prototype = {
  15926. areaStart: function() {
  15927. this._line = 0;
  15928. },
  15929. areaEnd: function() {
  15930. this._line = NaN;
  15931. },
  15932. lineStart: function() {
  15933. this._x0 = this._x1 =
  15934. this._y0 = this._y1 = NaN;
  15935. this._point = 0;
  15936. },
  15937. lineEnd: function() {
  15938. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  15939. this._line = 1 - this._line;
  15940. },
  15941. point: function(x, y) {
  15942. x = +x, y = +y;
  15943. switch (this._point) {
  15944. case 0: this._point = 1; break;
  15945. case 1: this._point = 2; break;
  15946. case 2: this._point = 3; var x0 = (this._x0 + 4 * this._x1 + x) / 6, y0 = (this._y0 + 4 * this._y1 + y) / 6; this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0); break;
  15947. case 3: this._point = 4; // falls through
  15948. default: point$3(this, x, y); break;
  15949. }
  15950. this._x0 = this._x1, this._x1 = x;
  15951. this._y0 = this._y1, this._y1 = y;
  15952. }
  15953. };
  15954. function basisOpen(context) {
  15955. return new BasisOpen(context);
  15956. }
  15957. function Bundle(context, beta) {
  15958. this._basis = new Basis(context);
  15959. this._beta = beta;
  15960. }
  15961. Bundle.prototype = {
  15962. lineStart: function() {
  15963. this._x = [];
  15964. this._y = [];
  15965. this._basis.lineStart();
  15966. },
  15967. lineEnd: function() {
  15968. var x = this._x,
  15969. y = this._y,
  15970. j = x.length - 1;
  15971. if (j > 0) {
  15972. var x0 = x[0],
  15973. y0 = y[0],
  15974. dx = x[j] - x0,
  15975. dy = y[j] - y0,
  15976. i = -1,
  15977. t;
  15978. while (++i <= j) {
  15979. t = i / j;
  15980. this._basis.point(
  15981. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  15982. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  15983. );
  15984. }
  15985. }
  15986. this._x = this._y = null;
  15987. this._basis.lineEnd();
  15988. },
  15989. point: function(x, y) {
  15990. this._x.push(+x);
  15991. this._y.push(+y);
  15992. }
  15993. };
  15994. var bundle = (function custom(beta) {
  15995. function bundle(context) {
  15996. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  15997. }
  15998. bundle.beta = function(beta) {
  15999. return custom(+beta);
  16000. };
  16001. return bundle;
  16002. })(0.85);
  16003. function point$2(that, x, y) {
  16004. that._context.bezierCurveTo(
  16005. that._x1 + that._k * (that._x2 - that._x0),
  16006. that._y1 + that._k * (that._y2 - that._y0),
  16007. that._x2 + that._k * (that._x1 - x),
  16008. that._y2 + that._k * (that._y1 - y),
  16009. that._x2,
  16010. that._y2
  16011. );
  16012. }
  16013. function Cardinal(context, tension) {
  16014. this._context = context;
  16015. this._k = (1 - tension) / 6;
  16016. }
  16017. Cardinal.prototype = {
  16018. areaStart: function() {
  16019. this._line = 0;
  16020. },
  16021. areaEnd: function() {
  16022. this._line = NaN;
  16023. },
  16024. lineStart: function() {
  16025. this._x0 = this._x1 = this._x2 =
  16026. this._y0 = this._y1 = this._y2 = NaN;
  16027. this._point = 0;
  16028. },
  16029. lineEnd: function() {
  16030. switch (this._point) {
  16031. case 2: this._context.lineTo(this._x2, this._y2); break;
  16032. case 3: point$2(this, this._x1, this._y1); break;
  16033. }
  16034. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16035. this._line = 1 - this._line;
  16036. },
  16037. point: function(x, y) {
  16038. x = +x, y = +y;
  16039. switch (this._point) {
  16040. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16041. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  16042. case 2: this._point = 3; // falls through
  16043. default: point$2(this, x, y); break;
  16044. }
  16045. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16046. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16047. }
  16048. };
  16049. var cardinal = (function custom(tension) {
  16050. function cardinal(context) {
  16051. return new Cardinal(context, tension);
  16052. }
  16053. cardinal.tension = function(tension) {
  16054. return custom(+tension);
  16055. };
  16056. return cardinal;
  16057. })(0);
  16058. function CardinalClosed(context, tension) {
  16059. this._context = context;
  16060. this._k = (1 - tension) / 6;
  16061. }
  16062. CardinalClosed.prototype = {
  16063. areaStart: noop,
  16064. areaEnd: noop,
  16065. lineStart: function() {
  16066. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  16067. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  16068. this._point = 0;
  16069. },
  16070. lineEnd: function() {
  16071. switch (this._point) {
  16072. case 1: {
  16073. this._context.moveTo(this._x3, this._y3);
  16074. this._context.closePath();
  16075. break;
  16076. }
  16077. case 2: {
  16078. this._context.lineTo(this._x3, this._y3);
  16079. this._context.closePath();
  16080. break;
  16081. }
  16082. case 3: {
  16083. this.point(this._x3, this._y3);
  16084. this.point(this._x4, this._y4);
  16085. this.point(this._x5, this._y5);
  16086. break;
  16087. }
  16088. }
  16089. },
  16090. point: function(x, y) {
  16091. x = +x, y = +y;
  16092. switch (this._point) {
  16093. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  16094. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  16095. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  16096. default: point$2(this, x, y); break;
  16097. }
  16098. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16099. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16100. }
  16101. };
  16102. var cardinalClosed = (function custom(tension) {
  16103. function cardinal(context) {
  16104. return new CardinalClosed(context, tension);
  16105. }
  16106. cardinal.tension = function(tension) {
  16107. return custom(+tension);
  16108. };
  16109. return cardinal;
  16110. })(0);
  16111. function CardinalOpen(context, tension) {
  16112. this._context = context;
  16113. this._k = (1 - tension) / 6;
  16114. }
  16115. CardinalOpen.prototype = {
  16116. areaStart: function() {
  16117. this._line = 0;
  16118. },
  16119. areaEnd: function() {
  16120. this._line = NaN;
  16121. },
  16122. lineStart: function() {
  16123. this._x0 = this._x1 = this._x2 =
  16124. this._y0 = this._y1 = this._y2 = NaN;
  16125. this._point = 0;
  16126. },
  16127. lineEnd: function() {
  16128. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  16129. this._line = 1 - this._line;
  16130. },
  16131. point: function(x, y) {
  16132. x = +x, y = +y;
  16133. switch (this._point) {
  16134. case 0: this._point = 1; break;
  16135. case 1: this._point = 2; break;
  16136. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  16137. case 3: this._point = 4; // falls through
  16138. default: point$2(this, x, y); break;
  16139. }
  16140. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16141. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16142. }
  16143. };
  16144. var cardinalOpen = (function custom(tension) {
  16145. function cardinal(context) {
  16146. return new CardinalOpen(context, tension);
  16147. }
  16148. cardinal.tension = function(tension) {
  16149. return custom(+tension);
  16150. };
  16151. return cardinal;
  16152. })(0);
  16153. function point$1(that, x, y) {
  16154. var x1 = that._x1,
  16155. y1 = that._y1,
  16156. x2 = that._x2,
  16157. y2 = that._y2;
  16158. if (that._l01_a > epsilon) {
  16159. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  16160. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  16161. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  16162. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  16163. }
  16164. if (that._l23_a > epsilon) {
  16165. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  16166. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  16167. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  16168. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  16169. }
  16170. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  16171. }
  16172. function CatmullRom(context, alpha) {
  16173. this._context = context;
  16174. this._alpha = alpha;
  16175. }
  16176. CatmullRom.prototype = {
  16177. areaStart: function() {
  16178. this._line = 0;
  16179. },
  16180. areaEnd: function() {
  16181. this._line = NaN;
  16182. },
  16183. lineStart: function() {
  16184. this._x0 = this._x1 = this._x2 =
  16185. this._y0 = this._y1 = this._y2 = NaN;
  16186. this._l01_a = this._l12_a = this._l23_a =
  16187. this._l01_2a = this._l12_2a = this._l23_2a =
  16188. this._point = 0;
  16189. },
  16190. lineEnd: function() {
  16191. switch (this._point) {
  16192. case 2: this._context.lineTo(this._x2, this._y2); break;
  16193. case 3: this.point(this._x2, this._y2); break;
  16194. }
  16195. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16196. this._line = 1 - this._line;
  16197. },
  16198. point: function(x, y) {
  16199. x = +x, y = +y;
  16200. if (this._point) {
  16201. var x23 = this._x2 - x,
  16202. y23 = this._y2 - y;
  16203. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  16204. }
  16205. switch (this._point) {
  16206. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16207. case 1: this._point = 2; break;
  16208. case 2: this._point = 3; // falls through
  16209. default: point$1(this, x, y); break;
  16210. }
  16211. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  16212. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  16213. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16214. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16215. }
  16216. };
  16217. var catmullRom = (function custom(alpha) {
  16218. function catmullRom(context) {
  16219. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  16220. }
  16221. catmullRom.alpha = function(alpha) {
  16222. return custom(+alpha);
  16223. };
  16224. return catmullRom;
  16225. })(0.5);
  16226. function CatmullRomClosed(context, alpha) {
  16227. this._context = context;
  16228. this._alpha = alpha;
  16229. }
  16230. CatmullRomClosed.prototype = {
  16231. areaStart: noop,
  16232. areaEnd: noop,
  16233. lineStart: function() {
  16234. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  16235. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  16236. this._l01_a = this._l12_a = this._l23_a =
  16237. this._l01_2a = this._l12_2a = this._l23_2a =
  16238. this._point = 0;
  16239. },
  16240. lineEnd: function() {
  16241. switch (this._point) {
  16242. case 1: {
  16243. this._context.moveTo(this._x3, this._y3);
  16244. this._context.closePath();
  16245. break;
  16246. }
  16247. case 2: {
  16248. this._context.lineTo(this._x3, this._y3);
  16249. this._context.closePath();
  16250. break;
  16251. }
  16252. case 3: {
  16253. this.point(this._x3, this._y3);
  16254. this.point(this._x4, this._y4);
  16255. this.point(this._x5, this._y5);
  16256. break;
  16257. }
  16258. }
  16259. },
  16260. point: function(x, y) {
  16261. x = +x, y = +y;
  16262. if (this._point) {
  16263. var x23 = this._x2 - x,
  16264. y23 = this._y2 - y;
  16265. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  16266. }
  16267. switch (this._point) {
  16268. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  16269. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  16270. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  16271. default: point$1(this, x, y); break;
  16272. }
  16273. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  16274. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  16275. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16276. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16277. }
  16278. };
  16279. var catmullRomClosed = (function custom(alpha) {
  16280. function catmullRom(context) {
  16281. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  16282. }
  16283. catmullRom.alpha = function(alpha) {
  16284. return custom(+alpha);
  16285. };
  16286. return catmullRom;
  16287. })(0.5);
  16288. function CatmullRomOpen(context, alpha) {
  16289. this._context = context;
  16290. this._alpha = alpha;
  16291. }
  16292. CatmullRomOpen.prototype = {
  16293. areaStart: function() {
  16294. this._line = 0;
  16295. },
  16296. areaEnd: function() {
  16297. this._line = NaN;
  16298. },
  16299. lineStart: function() {
  16300. this._x0 = this._x1 = this._x2 =
  16301. this._y0 = this._y1 = this._y2 = NaN;
  16302. this._l01_a = this._l12_a = this._l23_a =
  16303. this._l01_2a = this._l12_2a = this._l23_2a =
  16304. this._point = 0;
  16305. },
  16306. lineEnd: function() {
  16307. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  16308. this._line = 1 - this._line;
  16309. },
  16310. point: function(x, y) {
  16311. x = +x, y = +y;
  16312. if (this._point) {
  16313. var x23 = this._x2 - x,
  16314. y23 = this._y2 - y;
  16315. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  16316. }
  16317. switch (this._point) {
  16318. case 0: this._point = 1; break;
  16319. case 1: this._point = 2; break;
  16320. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  16321. case 3: this._point = 4; // falls through
  16322. default: point$1(this, x, y); break;
  16323. }
  16324. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  16325. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  16326. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  16327. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  16328. }
  16329. };
  16330. var catmullRomOpen = (function custom(alpha) {
  16331. function catmullRom(context) {
  16332. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  16333. }
  16334. catmullRom.alpha = function(alpha) {
  16335. return custom(+alpha);
  16336. };
  16337. return catmullRom;
  16338. })(0.5);
  16339. function LinearClosed(context) {
  16340. this._context = context;
  16341. }
  16342. LinearClosed.prototype = {
  16343. areaStart: noop,
  16344. areaEnd: noop,
  16345. lineStart: function() {
  16346. this._point = 0;
  16347. },
  16348. lineEnd: function() {
  16349. if (this._point) this._context.closePath();
  16350. },
  16351. point: function(x, y) {
  16352. x = +x, y = +y;
  16353. if (this._point) this._context.lineTo(x, y);
  16354. else this._point = 1, this._context.moveTo(x, y);
  16355. }
  16356. };
  16357. function linearClosed(context) {
  16358. return new LinearClosed(context);
  16359. }
  16360. function sign(x) {
  16361. return x < 0 ? -1 : 1;
  16362. }
  16363. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  16364. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  16365. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  16366. // NOV(II), P. 443, 1990.
  16367. function slope3(that, x2, y2) {
  16368. var h0 = that._x1 - that._x0,
  16369. h1 = x2 - that._x1,
  16370. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  16371. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  16372. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  16373. return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  16374. }
  16375. // Calculate a one-sided slope.
  16376. function slope2(that, t) {
  16377. var h = that._x1 - that._x0;
  16378. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  16379. }
  16380. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  16381. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  16382. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  16383. function point(that, t0, t1) {
  16384. var x0 = that._x0,
  16385. y0 = that._y0,
  16386. x1 = that._x1,
  16387. y1 = that._y1,
  16388. dx = (x1 - x0) / 3;
  16389. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  16390. }
  16391. function MonotoneX(context) {
  16392. this._context = context;
  16393. }
  16394. MonotoneX.prototype = {
  16395. areaStart: function() {
  16396. this._line = 0;
  16397. },
  16398. areaEnd: function() {
  16399. this._line = NaN;
  16400. },
  16401. lineStart: function() {
  16402. this._x0 = this._x1 =
  16403. this._y0 = this._y1 =
  16404. this._t0 = NaN;
  16405. this._point = 0;
  16406. },
  16407. lineEnd: function() {
  16408. switch (this._point) {
  16409. case 2: this._context.lineTo(this._x1, this._y1); break;
  16410. case 3: point(this, this._t0, slope2(this, this._t0)); break;
  16411. }
  16412. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16413. this._line = 1 - this._line;
  16414. },
  16415. point: function(x, y) {
  16416. var t1 = NaN;
  16417. x = +x, y = +y;
  16418. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  16419. switch (this._point) {
  16420. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16421. case 1: this._point = 2; break;
  16422. case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  16423. default: point(this, this._t0, t1 = slope3(this, x, y)); break;
  16424. }
  16425. this._x0 = this._x1, this._x1 = x;
  16426. this._y0 = this._y1, this._y1 = y;
  16427. this._t0 = t1;
  16428. }
  16429. };
  16430. function MonotoneY(context) {
  16431. this._context = new ReflectContext(context);
  16432. }
  16433. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  16434. MonotoneX.prototype.point.call(this, y, x);
  16435. };
  16436. function ReflectContext(context) {
  16437. this._context = context;
  16438. }
  16439. ReflectContext.prototype = {
  16440. moveTo: function(x, y) { this._context.moveTo(y, x); },
  16441. closePath: function() { this._context.closePath(); },
  16442. lineTo: function(x, y) { this._context.lineTo(y, x); },
  16443. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  16444. };
  16445. function monotoneX(context) {
  16446. return new MonotoneX(context);
  16447. }
  16448. function monotoneY(context) {
  16449. return new MonotoneY(context);
  16450. }
  16451. function Natural(context) {
  16452. this._context = context;
  16453. }
  16454. Natural.prototype = {
  16455. areaStart: function() {
  16456. this._line = 0;
  16457. },
  16458. areaEnd: function() {
  16459. this._line = NaN;
  16460. },
  16461. lineStart: function() {
  16462. this._x = [];
  16463. this._y = [];
  16464. },
  16465. lineEnd: function() {
  16466. var x = this._x,
  16467. y = this._y,
  16468. n = x.length;
  16469. if (n) {
  16470. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  16471. if (n === 2) {
  16472. this._context.lineTo(x[1], y[1]);
  16473. } else {
  16474. var px = controlPoints(x),
  16475. py = controlPoints(y);
  16476. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  16477. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  16478. }
  16479. }
  16480. }
  16481. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  16482. this._line = 1 - this._line;
  16483. this._x = this._y = null;
  16484. },
  16485. point: function(x, y) {
  16486. this._x.push(+x);
  16487. this._y.push(+y);
  16488. }
  16489. };
  16490. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  16491. function controlPoints(x) {
  16492. var i,
  16493. n = x.length - 1,
  16494. m,
  16495. a = new Array(n),
  16496. b = new Array(n),
  16497. r = new Array(n);
  16498. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  16499. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  16500. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  16501. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  16502. a[n - 1] = r[n - 1] / b[n - 1];
  16503. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  16504. b[n - 1] = (x[n] + a[n - 1]) / 2;
  16505. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  16506. return [a, b];
  16507. }
  16508. function natural(context) {
  16509. return new Natural(context);
  16510. }
  16511. function Step(context, t) {
  16512. this._context = context;
  16513. this._t = t;
  16514. }
  16515. Step.prototype = {
  16516. areaStart: function() {
  16517. this._line = 0;
  16518. },
  16519. areaEnd: function() {
  16520. this._line = NaN;
  16521. },
  16522. lineStart: function() {
  16523. this._x = this._y = NaN;
  16524. this._point = 0;
  16525. },
  16526. lineEnd: function() {
  16527. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  16528. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  16529. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  16530. },
  16531. point: function(x, y) {
  16532. x = +x, y = +y;
  16533. switch (this._point) {
  16534. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  16535. case 1: this._point = 2; // falls through
  16536. default: {
  16537. if (this._t <= 0) {
  16538. this._context.lineTo(this._x, y);
  16539. this._context.lineTo(x, y);
  16540. } else {
  16541. var x1 = this._x * (1 - this._t) + x * this._t;
  16542. this._context.lineTo(x1, this._y);
  16543. this._context.lineTo(x1, y);
  16544. }
  16545. break;
  16546. }
  16547. }
  16548. this._x = x, this._y = y;
  16549. }
  16550. };
  16551. function step(context) {
  16552. return new Step(context, 0.5);
  16553. }
  16554. function stepBefore(context) {
  16555. return new Step(context, 0);
  16556. }
  16557. function stepAfter(context) {
  16558. return new Step(context, 1);
  16559. }
  16560. function none$1(series, order) {
  16561. if (!((n = series.length) > 1)) return;
  16562. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  16563. s0 = s1, s1 = series[order[i]];
  16564. for (j = 0; j < m; ++j) {
  16565. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  16566. }
  16567. }
  16568. }
  16569. function none(series) {
  16570. var n = series.length, o = new Array(n);
  16571. while (--n >= 0) o[n] = n;
  16572. return o;
  16573. }
  16574. function stackValue(d, key) {
  16575. return d[key];
  16576. }
  16577. function stackSeries(key) {
  16578. const series = [];
  16579. series.key = key;
  16580. return series;
  16581. }
  16582. function stack() {
  16583. var keys = constant$1([]),
  16584. order = none,
  16585. offset = none$1,
  16586. value = stackValue;
  16587. function stack(data) {
  16588. var sz = Array.from(keys.apply(this, arguments), stackSeries),
  16589. i, n = sz.length, j = -1,
  16590. oz;
  16591. for (const d of data) {
  16592. for (i = 0, ++j; i < n; ++i) {
  16593. (sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
  16594. }
  16595. }
  16596. for (i = 0, oz = array(order(sz)); i < n; ++i) {
  16597. sz[oz[i]].index = i;
  16598. }
  16599. offset(sz, oz);
  16600. return sz;
  16601. }
  16602. stack.keys = function(_) {
  16603. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : keys;
  16604. };
  16605. stack.value = function(_) {
  16606. return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), stack) : value;
  16607. };
  16608. stack.order = function(_) {
  16609. return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : order;
  16610. };
  16611. stack.offset = function(_) {
  16612. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  16613. };
  16614. return stack;
  16615. }
  16616. function expand(series, order) {
  16617. if (!((n = series.length) > 0)) return;
  16618. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  16619. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  16620. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  16621. }
  16622. none$1(series, order);
  16623. }
  16624. function diverging(series, order) {
  16625. if (!((n = series.length) > 0)) return;
  16626. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  16627. for (yp = yn = 0, i = 0; i < n; ++i) {
  16628. if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
  16629. d[0] = yp, d[1] = yp += dy;
  16630. } else if (dy < 0) {
  16631. d[1] = yn, d[0] = yn += dy;
  16632. } else {
  16633. d[0] = 0, d[1] = dy;
  16634. }
  16635. }
  16636. }
  16637. }
  16638. function silhouette(series, order) {
  16639. if (!((n = series.length) > 0)) return;
  16640. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  16641. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  16642. s0[j][1] += s0[j][0] = -y / 2;
  16643. }
  16644. none$1(series, order);
  16645. }
  16646. function wiggle(series, order) {
  16647. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  16648. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  16649. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  16650. var si = series[order[i]],
  16651. sij0 = si[j][1] || 0,
  16652. sij1 = si[j - 1][1] || 0,
  16653. s3 = (sij0 - sij1) / 2;
  16654. for (var k = 0; k < i; ++k) {
  16655. var sk = series[order[k]],
  16656. skj0 = sk[j][1] || 0,
  16657. skj1 = sk[j - 1][1] || 0;
  16658. s3 += skj0 - skj1;
  16659. }
  16660. s1 += sij0, s2 += s3 * sij0;
  16661. }
  16662. s0[j - 1][1] += s0[j - 1][0] = y;
  16663. if (s1) y -= s2 / s1;
  16664. }
  16665. s0[j - 1][1] += s0[j - 1][0] = y;
  16666. none$1(series, order);
  16667. }
  16668. function appearance(series) {
  16669. var peaks = series.map(peak);
  16670. return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
  16671. }
  16672. function peak(series) {
  16673. var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
  16674. while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
  16675. return j;
  16676. }
  16677. function ascending(series) {
  16678. var sums = series.map(sum);
  16679. return none(series).sort(function(a, b) { return sums[a] - sums[b]; });
  16680. }
  16681. function sum(series) {
  16682. var s = 0, i = -1, n = series.length, v;
  16683. while (++i < n) if (v = +series[i][1]) s += v;
  16684. return s;
  16685. }
  16686. function descending(series) {
  16687. return ascending(series).reverse();
  16688. }
  16689. function insideOut(series) {
  16690. var n = series.length,
  16691. i,
  16692. j,
  16693. sums = series.map(sum),
  16694. order = appearance(series),
  16695. top = 0,
  16696. bottom = 0,
  16697. tops = [],
  16698. bottoms = [];
  16699. for (i = 0; i < n; ++i) {
  16700. j = order[i];
  16701. if (top < bottom) {
  16702. top += sums[j];
  16703. tops.push(j);
  16704. } else {
  16705. bottom += sums[j];
  16706. bottoms.push(j);
  16707. }
  16708. }
  16709. return bottoms.reverse().concat(tops);
  16710. }
  16711. function reverse(series) {
  16712. return none(series).reverse();
  16713. }
  16714. var constant = x => () => x;
  16715. function ZoomEvent(type, {
  16716. sourceEvent,
  16717. target,
  16718. transform,
  16719. dispatch
  16720. }) {
  16721. Object.defineProperties(this, {
  16722. type: {value: type, enumerable: true, configurable: true},
  16723. sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
  16724. target: {value: target, enumerable: true, configurable: true},
  16725. transform: {value: transform, enumerable: true, configurable: true},
  16726. _: {value: dispatch}
  16727. });
  16728. }
  16729. function Transform(k, x, y) {
  16730. this.k = k;
  16731. this.x = x;
  16732. this.y = y;
  16733. }
  16734. Transform.prototype = {
  16735. constructor: Transform,
  16736. scale: function(k) {
  16737. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  16738. },
  16739. translate: function(x, y) {
  16740. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  16741. },
  16742. apply: function(point) {
  16743. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  16744. },
  16745. applyX: function(x) {
  16746. return x * this.k + this.x;
  16747. },
  16748. applyY: function(y) {
  16749. return y * this.k + this.y;
  16750. },
  16751. invert: function(location) {
  16752. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  16753. },
  16754. invertX: function(x) {
  16755. return (x - this.x) / this.k;
  16756. },
  16757. invertY: function(y) {
  16758. return (y - this.y) / this.k;
  16759. },
  16760. rescaleX: function(x) {
  16761. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  16762. },
  16763. rescaleY: function(y) {
  16764. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  16765. },
  16766. toString: function() {
  16767. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  16768. }
  16769. };
  16770. var identity = new Transform(1, 0, 0);
  16771. transform.prototype = Transform.prototype;
  16772. function transform(node) {
  16773. while (!node.__zoom) if (!(node = node.parentNode)) return identity;
  16774. return node.__zoom;
  16775. }
  16776. function nopropagation(event) {
  16777. event.stopImmediatePropagation();
  16778. }
  16779. function noevent(event) {
  16780. event.preventDefault();
  16781. event.stopImmediatePropagation();
  16782. }
  16783. // Ignore right-click, since that should open the context menu.
  16784. // except for pinch-to-zoom, which is sent as a wheel+ctrlKey event
  16785. function defaultFilter(event) {
  16786. return (!event.ctrlKey || event.type === 'wheel') && !event.button;
  16787. }
  16788. function defaultExtent() {
  16789. var e = this;
  16790. if (e instanceof SVGElement) {
  16791. e = e.ownerSVGElement || e;
  16792. if (e.hasAttribute("viewBox")) {
  16793. e = e.viewBox.baseVal;
  16794. return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
  16795. }
  16796. return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
  16797. }
  16798. return [[0, 0], [e.clientWidth, e.clientHeight]];
  16799. }
  16800. function defaultTransform() {
  16801. return this.__zoom || identity;
  16802. }
  16803. function defaultWheelDelta(event) {
  16804. return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1);
  16805. }
  16806. function defaultTouchable() {
  16807. return navigator.maxTouchPoints || ("ontouchstart" in this);
  16808. }
  16809. function defaultConstrain(transform, extent, translateExtent) {
  16810. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  16811. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  16812. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  16813. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  16814. return transform.translate(
  16815. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  16816. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  16817. );
  16818. }
  16819. function zoom() {
  16820. var filter = defaultFilter,
  16821. extent = defaultExtent,
  16822. constrain = defaultConstrain,
  16823. wheelDelta = defaultWheelDelta,
  16824. touchable = defaultTouchable,
  16825. scaleExtent = [0, Infinity],
  16826. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  16827. duration = 250,
  16828. interpolate = interpolateZoom,
  16829. listeners = dispatch("start", "zoom", "end"),
  16830. touchstarting,
  16831. touchfirst,
  16832. touchending,
  16833. touchDelay = 500,
  16834. wheelDelay = 150,
  16835. clickDistance2 = 0,
  16836. tapDistance = 10;
  16837. function zoom(selection) {
  16838. selection
  16839. .property("__zoom", defaultTransform)
  16840. .on("wheel.zoom", wheeled, {passive: false})
  16841. .on("mousedown.zoom", mousedowned)
  16842. .on("dblclick.zoom", dblclicked)
  16843. .filter(touchable)
  16844. .on("touchstart.zoom", touchstarted)
  16845. .on("touchmove.zoom", touchmoved)
  16846. .on("touchend.zoom touchcancel.zoom", touchended)
  16847. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  16848. }
  16849. zoom.transform = function(collection, transform, point, event) {
  16850. var selection = collection.selection ? collection.selection() : collection;
  16851. selection.property("__zoom", defaultTransform);
  16852. if (collection !== selection) {
  16853. schedule(collection, transform, point, event);
  16854. } else {
  16855. selection.interrupt().each(function() {
  16856. gesture(this, arguments)
  16857. .event(event)
  16858. .start()
  16859. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  16860. .end();
  16861. });
  16862. }
  16863. };
  16864. zoom.scaleBy = function(selection, k, p, event) {
  16865. zoom.scaleTo(selection, function() {
  16866. var k0 = this.__zoom.k,
  16867. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  16868. return k0 * k1;
  16869. }, p, event);
  16870. };
  16871. zoom.scaleTo = function(selection, k, p, event) {
  16872. zoom.transform(selection, function() {
  16873. var e = extent.apply(this, arguments),
  16874. t0 = this.__zoom,
  16875. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
  16876. p1 = t0.invert(p0),
  16877. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  16878. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  16879. }, p, event);
  16880. };
  16881. zoom.translateBy = function(selection, x, y, event) {
  16882. zoom.transform(selection, function() {
  16883. return constrain(this.__zoom.translate(
  16884. typeof x === "function" ? x.apply(this, arguments) : x,
  16885. typeof y === "function" ? y.apply(this, arguments) : y
  16886. ), extent.apply(this, arguments), translateExtent);
  16887. }, null, event);
  16888. };
  16889. zoom.translateTo = function(selection, x, y, p, event) {
  16890. zoom.transform(selection, function() {
  16891. var e = extent.apply(this, arguments),
  16892. t = this.__zoom,
  16893. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
  16894. return constrain(identity.translate(p0[0], p0[1]).scale(t.k).translate(
  16895. typeof x === "function" ? -x.apply(this, arguments) : -x,
  16896. typeof y === "function" ? -y.apply(this, arguments) : -y
  16897. ), e, translateExtent);
  16898. }, p, event);
  16899. };
  16900. function scale(transform, k) {
  16901. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  16902. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  16903. }
  16904. function translate(transform, p0, p1) {
  16905. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  16906. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  16907. }
  16908. function centroid(extent) {
  16909. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  16910. }
  16911. function schedule(transition, transform, point, event) {
  16912. transition
  16913. .on("start.zoom", function() { gesture(this, arguments).event(event).start(); })
  16914. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).event(event).end(); })
  16915. .tween("zoom", function() {
  16916. var that = this,
  16917. args = arguments,
  16918. g = gesture(that, args).event(event),
  16919. e = extent.apply(that, args),
  16920. p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
  16921. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  16922. a = that.__zoom,
  16923. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  16924. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  16925. return function(t) {
  16926. if (t === 1) t = b; // Avoid rounding error on end.
  16927. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  16928. g.zoom(null, t);
  16929. };
  16930. });
  16931. }
  16932. function gesture(that, args, clean) {
  16933. return (!clean && that.__zooming) || new Gesture(that, args);
  16934. }
  16935. function Gesture(that, args) {
  16936. this.that = that;
  16937. this.args = args;
  16938. this.active = 0;
  16939. this.sourceEvent = null;
  16940. this.extent = extent.apply(that, args);
  16941. this.taps = 0;
  16942. }
  16943. Gesture.prototype = {
  16944. event: function(event) {
  16945. if (event) this.sourceEvent = event;
  16946. return this;
  16947. },
  16948. start: function() {
  16949. if (++this.active === 1) {
  16950. this.that.__zooming = this;
  16951. this.emit("start");
  16952. }
  16953. return this;
  16954. },
  16955. zoom: function(key, transform) {
  16956. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  16957. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  16958. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  16959. this.that.__zoom = transform;
  16960. this.emit("zoom");
  16961. return this;
  16962. },
  16963. end: function() {
  16964. if (--this.active === 0) {
  16965. delete this.that.__zooming;
  16966. this.emit("end");
  16967. }
  16968. return this;
  16969. },
  16970. emit: function(type) {
  16971. var d = select(this.that).datum();
  16972. listeners.call(
  16973. type,
  16974. this.that,
  16975. new ZoomEvent(type, {
  16976. sourceEvent: this.sourceEvent,
  16977. target: zoom,
  16978. type,
  16979. transform: this.that.__zoom,
  16980. dispatch: listeners
  16981. }),
  16982. d
  16983. );
  16984. }
  16985. };
  16986. function wheeled(event, ...args) {
  16987. if (!filter.apply(this, arguments)) return;
  16988. var g = gesture(this, args).event(event),
  16989. t = this.__zoom,
  16990. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  16991. p = pointer(event);
  16992. // If the mouse is in the same location as before, reuse it.
  16993. // If there were recent wheel events, reset the wheel idle timeout.
  16994. if (g.wheel) {
  16995. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  16996. g.mouse[1] = t.invert(g.mouse[0] = p);
  16997. }
  16998. clearTimeout(g.wheel);
  16999. }
  17000. // If this wheel event won’t trigger a transform change, ignore it.
  17001. else if (t.k === k) return;
  17002. // Otherwise, capture the mouse point and location at the start.
  17003. else {
  17004. g.mouse = [p, t.invert(p)];
  17005. interrupt(this);
  17006. g.start();
  17007. }
  17008. noevent(event);
  17009. g.wheel = setTimeout(wheelidled, wheelDelay);
  17010. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  17011. function wheelidled() {
  17012. g.wheel = null;
  17013. g.end();
  17014. }
  17015. }
  17016. function mousedowned(event, ...args) {
  17017. if (touchending || !filter.apply(this, arguments)) return;
  17018. var currentTarget = event.currentTarget,
  17019. g = gesture(this, args, true).event(event),
  17020. v = select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  17021. p = pointer(event, currentTarget),
  17022. x0 = event.clientX,
  17023. y0 = event.clientY;
  17024. dragDisable(event.view);
  17025. nopropagation(event);
  17026. g.mouse = [p, this.__zoom.invert(p)];
  17027. interrupt(this);
  17028. g.start();
  17029. function mousemoved(event) {
  17030. noevent(event);
  17031. if (!g.moved) {
  17032. var dx = event.clientX - x0, dy = event.clientY - y0;
  17033. g.moved = dx * dx + dy * dy > clickDistance2;
  17034. }
  17035. g.event(event)
  17036. .zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = pointer(event, currentTarget), g.mouse[1]), g.extent, translateExtent));
  17037. }
  17038. function mouseupped(event) {
  17039. v.on("mousemove.zoom mouseup.zoom", null);
  17040. yesdrag(event.view, g.moved);
  17041. noevent(event);
  17042. g.event(event).end();
  17043. }
  17044. }
  17045. function dblclicked(event, ...args) {
  17046. if (!filter.apply(this, arguments)) return;
  17047. var t0 = this.__zoom,
  17048. p0 = pointer(event.changedTouches ? event.changedTouches[0] : event, this),
  17049. p1 = t0.invert(p0),
  17050. k1 = t0.k * (event.shiftKey ? 0.5 : 2),
  17051. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, args), translateExtent);
  17052. noevent(event);
  17053. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0, event);
  17054. else select(this).call(zoom.transform, t1, p0, event);
  17055. }
  17056. function touchstarted(event, ...args) {
  17057. if (!filter.apply(this, arguments)) return;
  17058. var touches = event.touches,
  17059. n = touches.length,
  17060. g = gesture(this, args, event.changedTouches.length === n).event(event),
  17061. started, i, t, p;
  17062. nopropagation(event);
  17063. for (i = 0; i < n; ++i) {
  17064. t = touches[i], p = pointer(t, this);
  17065. p = [p, this.__zoom.invert(p), t.identifier];
  17066. if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
  17067. else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
  17068. }
  17069. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  17070. if (started) {
  17071. if (g.taps < 2) touchfirst = p[0], touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  17072. interrupt(this);
  17073. g.start();
  17074. }
  17075. }
  17076. function touchmoved(event, ...args) {
  17077. if (!this.__zooming) return;
  17078. var g = gesture(this, args).event(event),
  17079. touches = event.changedTouches,
  17080. n = touches.length, i, t, p, l;
  17081. noevent(event);
  17082. for (i = 0; i < n; ++i) {
  17083. t = touches[i], p = pointer(t, this);
  17084. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  17085. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  17086. }
  17087. t = g.that.__zoom;
  17088. if (g.touch1) {
  17089. var p0 = g.touch0[0], l0 = g.touch0[1],
  17090. p1 = g.touch1[0], l1 = g.touch1[1],
  17091. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  17092. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  17093. t = scale(t, Math.sqrt(dp / dl));
  17094. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  17095. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  17096. }
  17097. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  17098. else return;
  17099. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  17100. }
  17101. function touchended(event, ...args) {
  17102. if (!this.__zooming) return;
  17103. var g = gesture(this, args).event(event),
  17104. touches = event.changedTouches,
  17105. n = touches.length, i, t;
  17106. nopropagation(event);
  17107. if (touchending) clearTimeout(touchending);
  17108. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  17109. for (i = 0; i < n; ++i) {
  17110. t = touches[i];
  17111. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  17112. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  17113. }
  17114. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  17115. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  17116. else {
  17117. g.end();
  17118. // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
  17119. if (g.taps === 2) {
  17120. t = pointer(t, this);
  17121. if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) {
  17122. var p = select(this).on("dblclick.zoom");
  17123. if (p) p.apply(this, arguments);
  17124. }
  17125. }
  17126. }
  17127. }
  17128. zoom.wheelDelta = function(_) {
  17129. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant(+_), zoom) : wheelDelta;
  17130. };
  17131. zoom.filter = function(_) {
  17132. return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter;
  17133. };
  17134. zoom.touchable = function(_) {
  17135. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), zoom) : touchable;
  17136. };
  17137. zoom.extent = function(_) {
  17138. return arguments.length ? (extent = typeof _ === "function" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  17139. };
  17140. zoom.scaleExtent = function(_) {
  17141. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  17142. };
  17143. zoom.translateExtent = function(_) {
  17144. return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
  17145. };
  17146. zoom.constrain = function(_) {
  17147. return arguments.length ? (constrain = _, zoom) : constrain;
  17148. };
  17149. zoom.duration = function(_) {
  17150. return arguments.length ? (duration = +_, zoom) : duration;
  17151. };
  17152. zoom.interpolate = function(_) {
  17153. return arguments.length ? (interpolate = _, zoom) : interpolate;
  17154. };
  17155. zoom.on = function() {
  17156. var value = listeners.on.apply(listeners, arguments);
  17157. return value === listeners ? zoom : value;
  17158. };
  17159. zoom.clickDistance = function(_) {
  17160. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  17161. };
  17162. zoom.tapDistance = function(_) {
  17163. return arguments.length ? (tapDistance = +_, zoom) : tapDistance;
  17164. };
  17165. return zoom;
  17166. }
  17167. exports.Adder = Adder;
  17168. exports.Delaunay = Delaunay;
  17169. exports.FormatSpecifier = FormatSpecifier;
  17170. exports.InternMap = InternMap;
  17171. exports.InternSet = InternSet;
  17172. exports.Node = Node$1;
  17173. exports.Path = Path$1;
  17174. exports.Voronoi = Voronoi;
  17175. exports.ZoomTransform = Transform;
  17176. exports.active = active;
  17177. exports.arc = arc;
  17178. exports.area = area;
  17179. exports.areaRadial = areaRadial;
  17180. exports.ascending = ascending$3;
  17181. exports.autoType = autoType;
  17182. exports.axisBottom = axisBottom;
  17183. exports.axisLeft = axisLeft;
  17184. exports.axisRight = axisRight;
  17185. exports.axisTop = axisTop;
  17186. exports.bin = bin;
  17187. exports.bisect = bisect;
  17188. exports.bisectCenter = bisectCenter;
  17189. exports.bisectLeft = bisectLeft;
  17190. exports.bisectRight = bisectRight;
  17191. exports.bisector = bisector;
  17192. exports.blob = blob;
  17193. exports.blur = blur;
  17194. exports.blur2 = blur2;
  17195. exports.blurImage = blurImage;
  17196. exports.brush = brush;
  17197. exports.brushSelection = brushSelection;
  17198. exports.brushX = brushX;
  17199. exports.brushY = brushY;
  17200. exports.buffer = buffer;
  17201. exports.chord = chord;
  17202. exports.chordDirected = chordDirected;
  17203. exports.chordTranspose = chordTranspose;
  17204. exports.cluster = cluster;
  17205. exports.color = color;
  17206. exports.contourDensity = density;
  17207. exports.contours = Contours;
  17208. exports.count = count$1;
  17209. exports.create = create$1;
  17210. exports.creator = creator;
  17211. exports.cross = cross$2;
  17212. exports.csv = csv;
  17213. exports.csvFormat = csvFormat;
  17214. exports.csvFormatBody = csvFormatBody;
  17215. exports.csvFormatRow = csvFormatRow;
  17216. exports.csvFormatRows = csvFormatRows;
  17217. exports.csvFormatValue = csvFormatValue;
  17218. exports.csvParse = csvParse;
  17219. exports.csvParseRows = csvParseRows;
  17220. exports.cubehelix = cubehelix$3;
  17221. exports.cumsum = cumsum;
  17222. exports.curveBasis = basis;
  17223. exports.curveBasisClosed = basisClosed;
  17224. exports.curveBasisOpen = basisOpen;
  17225. exports.curveBumpX = bumpX;
  17226. exports.curveBumpY = bumpY;
  17227. exports.curveBundle = bundle;
  17228. exports.curveCardinal = cardinal;
  17229. exports.curveCardinalClosed = cardinalClosed;
  17230. exports.curveCardinalOpen = cardinalOpen;
  17231. exports.curveCatmullRom = catmullRom;
  17232. exports.curveCatmullRomClosed = catmullRomClosed;
  17233. exports.curveCatmullRomOpen = catmullRomOpen;
  17234. exports.curveLinear = curveLinear;
  17235. exports.curveLinearClosed = linearClosed;
  17236. exports.curveMonotoneX = monotoneX;
  17237. exports.curveMonotoneY = monotoneY;
  17238. exports.curveNatural = natural;
  17239. exports.curveStep = step;
  17240. exports.curveStepAfter = stepAfter;
  17241. exports.curveStepBefore = stepBefore;
  17242. exports.descending = descending$2;
  17243. exports.deviation = deviation;
  17244. exports.difference = difference;
  17245. exports.disjoint = disjoint;
  17246. exports.dispatch = dispatch;
  17247. exports.drag = drag;
  17248. exports.dragDisable = dragDisable;
  17249. exports.dragEnable = yesdrag;
  17250. exports.dsv = dsv;
  17251. exports.dsvFormat = dsvFormat;
  17252. exports.easeBack = backInOut;
  17253. exports.easeBackIn = backIn;
  17254. exports.easeBackInOut = backInOut;
  17255. exports.easeBackOut = backOut;
  17256. exports.easeBounce = bounceOut;
  17257. exports.easeBounceIn = bounceIn;
  17258. exports.easeBounceInOut = bounceInOut;
  17259. exports.easeBounceOut = bounceOut;
  17260. exports.easeCircle = circleInOut;
  17261. exports.easeCircleIn = circleIn;
  17262. exports.easeCircleInOut = circleInOut;
  17263. exports.easeCircleOut = circleOut;
  17264. exports.easeCubic = cubicInOut;
  17265. exports.easeCubicIn = cubicIn;
  17266. exports.easeCubicInOut = cubicInOut;
  17267. exports.easeCubicOut = cubicOut;
  17268. exports.easeElastic = elasticOut;
  17269. exports.easeElasticIn = elasticIn;
  17270. exports.easeElasticInOut = elasticInOut;
  17271. exports.easeElasticOut = elasticOut;
  17272. exports.easeExp = expInOut;
  17273. exports.easeExpIn = expIn;
  17274. exports.easeExpInOut = expInOut;
  17275. exports.easeExpOut = expOut;
  17276. exports.easeLinear = linear$1;
  17277. exports.easePoly = polyInOut;
  17278. exports.easePolyIn = polyIn;
  17279. exports.easePolyInOut = polyInOut;
  17280. exports.easePolyOut = polyOut;
  17281. exports.easeQuad = quadInOut;
  17282. exports.easeQuadIn = quadIn;
  17283. exports.easeQuadInOut = quadInOut;
  17284. exports.easeQuadOut = quadOut;
  17285. exports.easeSin = sinInOut;
  17286. exports.easeSinIn = sinIn;
  17287. exports.easeSinInOut = sinInOut;
  17288. exports.easeSinOut = sinOut;
  17289. exports.every = every;
  17290. exports.extent = extent$1;
  17291. exports.fcumsum = fcumsum;
  17292. exports.filter = filter$1;
  17293. exports.flatGroup = flatGroup;
  17294. exports.flatRollup = flatRollup;
  17295. exports.forceCenter = center;
  17296. exports.forceCollide = collide;
  17297. exports.forceLink = link$2;
  17298. exports.forceManyBody = manyBody;
  17299. exports.forceRadial = radial$1;
  17300. exports.forceSimulation = simulation;
  17301. exports.forceX = x$1;
  17302. exports.forceY = y$1;
  17303. exports.formatDefaultLocale = defaultLocale$1;
  17304. exports.formatLocale = formatLocale$1;
  17305. exports.formatSpecifier = formatSpecifier;
  17306. exports.fsum = fsum;
  17307. exports.geoAlbers = albers;
  17308. exports.geoAlbersUsa = albersUsa;
  17309. exports.geoArea = area$2;
  17310. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  17311. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  17312. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  17313. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  17314. exports.geoBounds = bounds;
  17315. exports.geoCentroid = centroid$1;
  17316. exports.geoCircle = circle$1;
  17317. exports.geoClipAntimeridian = clipAntimeridian;
  17318. exports.geoClipCircle = clipCircle;
  17319. exports.geoClipExtent = extent;
  17320. exports.geoClipRectangle = clipRectangle;
  17321. exports.geoConicConformal = conicConformal;
  17322. exports.geoConicConformalRaw = conicConformalRaw;
  17323. exports.geoConicEqualArea = conicEqualArea;
  17324. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  17325. exports.geoConicEquidistant = conicEquidistant;
  17326. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  17327. exports.geoContains = contains$1;
  17328. exports.geoDistance = distance;
  17329. exports.geoEqualEarth = equalEarth;
  17330. exports.geoEqualEarthRaw = equalEarthRaw;
  17331. exports.geoEquirectangular = equirectangular;
  17332. exports.geoEquirectangularRaw = equirectangularRaw;
  17333. exports.geoGnomonic = gnomonic;
  17334. exports.geoGnomonicRaw = gnomonicRaw;
  17335. exports.geoGraticule = graticule;
  17336. exports.geoGraticule10 = graticule10;
  17337. exports.geoIdentity = identity$4;
  17338. exports.geoInterpolate = interpolate;
  17339. exports.geoLength = length$1;
  17340. exports.geoMercator = mercator;
  17341. exports.geoMercatorRaw = mercatorRaw;
  17342. exports.geoNaturalEarth1 = naturalEarth1;
  17343. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  17344. exports.geoOrthographic = orthographic;
  17345. exports.geoOrthographicRaw = orthographicRaw;
  17346. exports.geoPath = index$2;
  17347. exports.geoProjection = projection;
  17348. exports.geoProjectionMutator = projectionMutator;
  17349. exports.geoRotation = rotation;
  17350. exports.geoStereographic = stereographic;
  17351. exports.geoStereographicRaw = stereographicRaw;
  17352. exports.geoStream = geoStream;
  17353. exports.geoTransform = transform$1;
  17354. exports.geoTransverseMercator = transverseMercator;
  17355. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  17356. exports.gray = gray;
  17357. exports.greatest = greatest;
  17358. exports.greatestIndex = greatestIndex;
  17359. exports.group = group;
  17360. exports.groupSort = groupSort;
  17361. exports.groups = groups;
  17362. exports.hcl = hcl$2;
  17363. exports.hierarchy = hierarchy;
  17364. exports.histogram = bin;
  17365. exports.hsl = hsl$2;
  17366. exports.html = html;
  17367. exports.image = image;
  17368. exports.index = index$4;
  17369. exports.indexes = indexes;
  17370. exports.interpolate = interpolate$2;
  17371. exports.interpolateArray = array$3;
  17372. exports.interpolateBasis = basis$2;
  17373. exports.interpolateBasisClosed = basisClosed$1;
  17374. exports.interpolateBlues = Blues;
  17375. exports.interpolateBrBG = BrBG;
  17376. exports.interpolateBuGn = BuGn;
  17377. exports.interpolateBuPu = BuPu;
  17378. exports.interpolateCividis = cividis;
  17379. exports.interpolateCool = cool;
  17380. exports.interpolateCubehelix = cubehelix$2;
  17381. exports.interpolateCubehelixDefault = cubehelix;
  17382. exports.interpolateCubehelixLong = cubehelixLong;
  17383. exports.interpolateDate = date$1;
  17384. exports.interpolateDiscrete = discrete;
  17385. exports.interpolateGnBu = GnBu;
  17386. exports.interpolateGreens = Greens;
  17387. exports.interpolateGreys = Greys;
  17388. exports.interpolateHcl = hcl$1;
  17389. exports.interpolateHclLong = hclLong;
  17390. exports.interpolateHsl = hsl$1;
  17391. exports.interpolateHslLong = hslLong;
  17392. exports.interpolateHue = hue;
  17393. exports.interpolateInferno = inferno;
  17394. exports.interpolateLab = lab;
  17395. exports.interpolateMagma = magma;
  17396. exports.interpolateNumber = interpolateNumber;
  17397. exports.interpolateNumberArray = numberArray;
  17398. exports.interpolateObject = object$1;
  17399. exports.interpolateOrRd = OrRd;
  17400. exports.interpolateOranges = Oranges;
  17401. exports.interpolatePRGn = PRGn;
  17402. exports.interpolatePiYG = PiYG;
  17403. exports.interpolatePlasma = plasma;
  17404. exports.interpolatePuBu = PuBu;
  17405. exports.interpolatePuBuGn = PuBuGn;
  17406. exports.interpolatePuOr = PuOr;
  17407. exports.interpolatePuRd = PuRd;
  17408. exports.interpolatePurples = Purples;
  17409. exports.interpolateRainbow = rainbow;
  17410. exports.interpolateRdBu = RdBu;
  17411. exports.interpolateRdGy = RdGy;
  17412. exports.interpolateRdPu = RdPu;
  17413. exports.interpolateRdYlBu = RdYlBu;
  17414. exports.interpolateRdYlGn = RdYlGn;
  17415. exports.interpolateReds = Reds;
  17416. exports.interpolateRgb = interpolateRgb;
  17417. exports.interpolateRgbBasis = rgbBasis;
  17418. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  17419. exports.interpolateRound = interpolateRound;
  17420. exports.interpolateSinebow = sinebow;
  17421. exports.interpolateSpectral = Spectral;
  17422. exports.interpolateString = interpolateString;
  17423. exports.interpolateTransformCss = interpolateTransformCss;
  17424. exports.interpolateTransformSvg = interpolateTransformSvg;
  17425. exports.interpolateTurbo = turbo;
  17426. exports.interpolateViridis = viridis;
  17427. exports.interpolateWarm = warm;
  17428. exports.interpolateYlGn = YlGn;
  17429. exports.interpolateYlGnBu = YlGnBu;
  17430. exports.interpolateYlOrBr = YlOrBr;
  17431. exports.interpolateYlOrRd = YlOrRd;
  17432. exports.interpolateZoom = interpolateZoom;
  17433. exports.interrupt = interrupt;
  17434. exports.intersection = intersection;
  17435. exports.interval = interval;
  17436. exports.isoFormat = formatIso$1;
  17437. exports.isoParse = parseIso$1;
  17438. exports.json = json;
  17439. exports.lab = lab$1;
  17440. exports.lch = lch;
  17441. exports.least = least;
  17442. exports.leastIndex = leastIndex;
  17443. exports.line = line;
  17444. exports.lineRadial = lineRadial$1;
  17445. exports.link = link;
  17446. exports.linkHorizontal = linkHorizontal;
  17447. exports.linkRadial = linkRadial;
  17448. exports.linkVertical = linkVertical;
  17449. exports.local = local$1;
  17450. exports.map = map$1;
  17451. exports.matcher = matcher;
  17452. exports.max = max$3;
  17453. exports.maxIndex = maxIndex;
  17454. exports.mean = mean;
  17455. exports.median = median;
  17456. exports.medianIndex = medianIndex;
  17457. exports.merge = merge;
  17458. exports.min = min$2;
  17459. exports.minIndex = minIndex;
  17460. exports.mode = mode;
  17461. exports.namespace = namespace;
  17462. exports.namespaces = namespaces;
  17463. exports.nice = nice$1;
  17464. exports.now = now;
  17465. exports.pack = index$1;
  17466. exports.packEnclose = enclose;
  17467. exports.packSiblings = siblings;
  17468. exports.pairs = pairs;
  17469. exports.partition = partition;
  17470. exports.path = path;
  17471. exports.pathRound = pathRound;
  17472. exports.permute = permute;
  17473. exports.pie = pie;
  17474. exports.piecewise = piecewise;
  17475. exports.pointRadial = pointRadial;
  17476. exports.pointer = pointer;
  17477. exports.pointers = pointers;
  17478. exports.polygonArea = area$1;
  17479. exports.polygonCentroid = centroid;
  17480. exports.polygonContains = contains;
  17481. exports.polygonHull = hull;
  17482. exports.polygonLength = length;
  17483. exports.precisionFixed = precisionFixed;
  17484. exports.precisionPrefix = precisionPrefix;
  17485. exports.precisionRound = precisionRound;
  17486. exports.quadtree = quadtree;
  17487. exports.quantile = quantile$1;
  17488. exports.quantileIndex = quantileIndex;
  17489. exports.quantileSorted = quantileSorted;
  17490. exports.quantize = quantize$1;
  17491. exports.quickselect = quickselect;
  17492. exports.radialArea = areaRadial;
  17493. exports.radialLine = lineRadial$1;
  17494. exports.randomBates = bates;
  17495. exports.randomBernoulli = bernoulli;
  17496. exports.randomBeta = beta;
  17497. exports.randomBinomial = binomial;
  17498. exports.randomCauchy = cauchy;
  17499. exports.randomExponential = exponential;
  17500. exports.randomGamma = gamma;
  17501. exports.randomGeometric = geometric;
  17502. exports.randomInt = int;
  17503. exports.randomIrwinHall = irwinHall;
  17504. exports.randomLcg = lcg;
  17505. exports.randomLogNormal = logNormal;
  17506. exports.randomLogistic = logistic;
  17507. exports.randomNormal = normal;
  17508. exports.randomPareto = pareto;
  17509. exports.randomPoisson = poisson;
  17510. exports.randomUniform = uniform;
  17511. exports.randomWeibull = weibull;
  17512. exports.range = range$2;
  17513. exports.rank = rank;
  17514. exports.reduce = reduce;
  17515. exports.reverse = reverse$1;
  17516. exports.rgb = rgb;
  17517. exports.ribbon = ribbon$1;
  17518. exports.ribbonArrow = ribbonArrow;
  17519. exports.rollup = rollup;
  17520. exports.rollups = rollups;
  17521. exports.scaleBand = band;
  17522. exports.scaleDiverging = diverging$1;
  17523. exports.scaleDivergingLog = divergingLog;
  17524. exports.scaleDivergingPow = divergingPow;
  17525. exports.scaleDivergingSqrt = divergingSqrt;
  17526. exports.scaleDivergingSymlog = divergingSymlog;
  17527. exports.scaleIdentity = identity$2;
  17528. exports.scaleImplicit = implicit;
  17529. exports.scaleLinear = linear;
  17530. exports.scaleLog = log;
  17531. exports.scaleOrdinal = ordinal;
  17532. exports.scalePoint = point$4;
  17533. exports.scalePow = pow;
  17534. exports.scaleQuantile = quantile;
  17535. exports.scaleQuantize = quantize;
  17536. exports.scaleRadial = radial;
  17537. exports.scaleSequential = sequential;
  17538. exports.scaleSequentialLog = sequentialLog;
  17539. exports.scaleSequentialPow = sequentialPow;
  17540. exports.scaleSequentialQuantile = sequentialQuantile;
  17541. exports.scaleSequentialSqrt = sequentialSqrt;
  17542. exports.scaleSequentialSymlog = sequentialSymlog;
  17543. exports.scaleSqrt = sqrt$1;
  17544. exports.scaleSymlog = symlog;
  17545. exports.scaleThreshold = threshold;
  17546. exports.scaleTime = time;
  17547. exports.scaleUtc = utcTime;
  17548. exports.scan = scan;
  17549. exports.schemeAccent = Accent;
  17550. exports.schemeBlues = scheme$5;
  17551. exports.schemeBrBG = scheme$q;
  17552. exports.schemeBuGn = scheme$h;
  17553. exports.schemeBuPu = scheme$g;
  17554. exports.schemeCategory10 = category10;
  17555. exports.schemeDark2 = Dark2;
  17556. exports.schemeGnBu = scheme$f;
  17557. exports.schemeGreens = scheme$4;
  17558. exports.schemeGreys = scheme$3;
  17559. exports.schemeObservable10 = observable10;
  17560. exports.schemeOrRd = scheme$e;
  17561. exports.schemeOranges = scheme;
  17562. exports.schemePRGn = scheme$p;
  17563. exports.schemePaired = Paired;
  17564. exports.schemePastel1 = Pastel1;
  17565. exports.schemePastel2 = Pastel2;
  17566. exports.schemePiYG = scheme$o;
  17567. exports.schemePuBu = scheme$c;
  17568. exports.schemePuBuGn = scheme$d;
  17569. exports.schemePuOr = scheme$n;
  17570. exports.schemePuRd = scheme$b;
  17571. exports.schemePurples = scheme$2;
  17572. exports.schemeRdBu = scheme$m;
  17573. exports.schemeRdGy = scheme$l;
  17574. exports.schemeRdPu = scheme$a;
  17575. exports.schemeRdYlBu = scheme$k;
  17576. exports.schemeRdYlGn = scheme$j;
  17577. exports.schemeReds = scheme$1;
  17578. exports.schemeSet1 = Set1;
  17579. exports.schemeSet2 = Set2;
  17580. exports.schemeSet3 = Set3;
  17581. exports.schemeSpectral = scheme$i;
  17582. exports.schemeTableau10 = Tableau10;
  17583. exports.schemeYlGn = scheme$8;
  17584. exports.schemeYlGnBu = scheme$9;
  17585. exports.schemeYlOrBr = scheme$7;
  17586. exports.schemeYlOrRd = scheme$6;
  17587. exports.select = select;
  17588. exports.selectAll = selectAll;
  17589. exports.selection = selection;
  17590. exports.selector = selector;
  17591. exports.selectorAll = selectorAll;
  17592. exports.shuffle = shuffle$1;
  17593. exports.shuffler = shuffler;
  17594. exports.some = some;
  17595. exports.sort = sort;
  17596. exports.stack = stack;
  17597. exports.stackOffsetDiverging = diverging;
  17598. exports.stackOffsetExpand = expand;
  17599. exports.stackOffsetNone = none$1;
  17600. exports.stackOffsetSilhouette = silhouette;
  17601. exports.stackOffsetWiggle = wiggle;
  17602. exports.stackOrderAppearance = appearance;
  17603. exports.stackOrderAscending = ascending;
  17604. exports.stackOrderDescending = descending;
  17605. exports.stackOrderInsideOut = insideOut;
  17606. exports.stackOrderNone = none;
  17607. exports.stackOrderReverse = reverse;
  17608. exports.stratify = stratify;
  17609. exports.style = styleValue;
  17610. exports.subset = subset;
  17611. exports.sum = sum$2;
  17612. exports.superset = superset;
  17613. exports.svg = svg;
  17614. exports.symbol = Symbol$1;
  17615. exports.symbolAsterisk = asterisk;
  17616. exports.symbolCircle = circle;
  17617. exports.symbolCross = cross;
  17618. exports.symbolDiamond = diamond;
  17619. exports.symbolDiamond2 = diamond2;
  17620. exports.symbolPlus = plus;
  17621. exports.symbolSquare = square;
  17622. exports.symbolSquare2 = square2;
  17623. exports.symbolStar = star;
  17624. exports.symbolTimes = times;
  17625. exports.symbolTriangle = triangle;
  17626. exports.symbolTriangle2 = triangle2;
  17627. exports.symbolWye = wye;
  17628. exports.symbolX = times;
  17629. exports.symbols = symbolsFill;
  17630. exports.symbolsFill = symbolsFill;
  17631. exports.symbolsStroke = symbolsStroke;
  17632. exports.text = text;
  17633. exports.thresholdFreedmanDiaconis = thresholdFreedmanDiaconis;
  17634. exports.thresholdScott = thresholdScott;
  17635. exports.thresholdSturges = thresholdSturges;
  17636. exports.tickFormat = tickFormat;
  17637. exports.tickIncrement = tickIncrement;
  17638. exports.tickStep = tickStep;
  17639. exports.ticks = ticks;
  17640. exports.timeDay = timeDay;
  17641. exports.timeDays = timeDays;
  17642. exports.timeFormatDefaultLocale = defaultLocale;
  17643. exports.timeFormatLocale = formatLocale;
  17644. exports.timeFriday = timeFriday;
  17645. exports.timeFridays = timeFridays;
  17646. exports.timeHour = timeHour;
  17647. exports.timeHours = timeHours;
  17648. exports.timeInterval = timeInterval;
  17649. exports.timeMillisecond = millisecond;
  17650. exports.timeMilliseconds = milliseconds;
  17651. exports.timeMinute = timeMinute;
  17652. exports.timeMinutes = timeMinutes;
  17653. exports.timeMonday = timeMonday;
  17654. exports.timeMondays = timeMondays;
  17655. exports.timeMonth = timeMonth;
  17656. exports.timeMonths = timeMonths;
  17657. exports.timeSaturday = timeSaturday;
  17658. exports.timeSaturdays = timeSaturdays;
  17659. exports.timeSecond = second;
  17660. exports.timeSeconds = seconds;
  17661. exports.timeSunday = timeSunday;
  17662. exports.timeSundays = timeSundays;
  17663. exports.timeThursday = timeThursday;
  17664. exports.timeThursdays = timeThursdays;
  17665. exports.timeTickInterval = timeTickInterval;
  17666. exports.timeTicks = timeTicks;
  17667. exports.timeTuesday = timeTuesday;
  17668. exports.timeTuesdays = timeTuesdays;
  17669. exports.timeWednesday = timeWednesday;
  17670. exports.timeWednesdays = timeWednesdays;
  17671. exports.timeWeek = timeSunday;
  17672. exports.timeWeeks = timeSundays;
  17673. exports.timeYear = timeYear;
  17674. exports.timeYears = timeYears;
  17675. exports.timeout = timeout;
  17676. exports.timer = timer;
  17677. exports.timerFlush = timerFlush;
  17678. exports.transition = transition;
  17679. exports.transpose = transpose;
  17680. exports.tree = tree;
  17681. exports.treemap = index;
  17682. exports.treemapBinary = binary;
  17683. exports.treemapDice = treemapDice;
  17684. exports.treemapResquarify = resquarify;
  17685. exports.treemapSlice = treemapSlice;
  17686. exports.treemapSliceDice = sliceDice;
  17687. exports.treemapSquarify = squarify;
  17688. exports.tsv = tsv;
  17689. exports.tsvFormat = tsvFormat;
  17690. exports.tsvFormatBody = tsvFormatBody;
  17691. exports.tsvFormatRow = tsvFormatRow;
  17692. exports.tsvFormatRows = tsvFormatRows;
  17693. exports.tsvFormatValue = tsvFormatValue;
  17694. exports.tsvParse = tsvParse;
  17695. exports.tsvParseRows = tsvParseRows;
  17696. exports.union = union;
  17697. exports.unixDay = unixDay;
  17698. exports.unixDays = unixDays;
  17699. exports.utcDay = utcDay;
  17700. exports.utcDays = utcDays;
  17701. exports.utcFriday = utcFriday;
  17702. exports.utcFridays = utcFridays;
  17703. exports.utcHour = utcHour;
  17704. exports.utcHours = utcHours;
  17705. exports.utcMillisecond = millisecond;
  17706. exports.utcMilliseconds = milliseconds;
  17707. exports.utcMinute = utcMinute;
  17708. exports.utcMinutes = utcMinutes;
  17709. exports.utcMonday = utcMonday;
  17710. exports.utcMondays = utcMondays;
  17711. exports.utcMonth = utcMonth;
  17712. exports.utcMonths = utcMonths;
  17713. exports.utcSaturday = utcSaturday;
  17714. exports.utcSaturdays = utcSaturdays;
  17715. exports.utcSecond = second;
  17716. exports.utcSeconds = seconds;
  17717. exports.utcSunday = utcSunday;
  17718. exports.utcSundays = utcSundays;
  17719. exports.utcThursday = utcThursday;
  17720. exports.utcThursdays = utcThursdays;
  17721. exports.utcTickInterval = utcTickInterval;
  17722. exports.utcTicks = utcTicks;
  17723. exports.utcTuesday = utcTuesday;
  17724. exports.utcTuesdays = utcTuesdays;
  17725. exports.utcWednesday = utcWednesday;
  17726. exports.utcWednesdays = utcWednesdays;
  17727. exports.utcWeek = utcSunday;
  17728. exports.utcWeeks = utcSundays;
  17729. exports.utcYear = utcYear;
  17730. exports.utcYears = utcYears;
  17731. exports.variance = variance;
  17732. exports.version = version;
  17733. exports.window = defaultView;
  17734. exports.xml = xml;
  17735. exports.zip = zip;
  17736. exports.zoom = zoom;
  17737. exports.zoomIdentity = identity;
  17738. exports.zoomTransform = transform;
  17739. }));