d3.js 504 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568
  1. // https://d3js.org v5.16.0 Copyright 2020 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = global || self, factory(global.d3 = global.d3 || {}));
  6. }(this, function (exports) { 'use strict';
  7. var version = "5.16.0";
  8. function ascending(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function bisector(compare) {
  12. if (compare.length === 1) compare = ascendingComparator(compare);
  13. return {
  14. left: function(a, x, lo, hi) {
  15. if (lo == null) lo = 0;
  16. if (hi == null) hi = a.length;
  17. while (lo < hi) {
  18. var mid = lo + hi >>> 1;
  19. if (compare(a[mid], x) < 0) lo = mid + 1;
  20. else hi = mid;
  21. }
  22. return lo;
  23. },
  24. right: function(a, x, lo, hi) {
  25. if (lo == null) lo = 0;
  26. if (hi == null) hi = a.length;
  27. while (lo < hi) {
  28. var mid = lo + hi >>> 1;
  29. if (compare(a[mid], x) > 0) hi = mid;
  30. else lo = mid + 1;
  31. }
  32. return lo;
  33. }
  34. };
  35. }
  36. function ascendingComparator(f) {
  37. return function(d, x) {
  38. return ascending(f(d), x);
  39. };
  40. }
  41. var ascendingBisect = bisector(ascending);
  42. var bisectRight = ascendingBisect.right;
  43. var bisectLeft = ascendingBisect.left;
  44. function pairs(array, f) {
  45. if (f == null) f = pair;
  46. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  47. while (i < n) pairs[i] = f(p, p = array[++i]);
  48. return pairs;
  49. }
  50. function pair(a, b) {
  51. return [a, b];
  52. }
  53. function cross(values0, values1, reduce) {
  54. var n0 = values0.length,
  55. n1 = values1.length,
  56. values = new Array(n0 * n1),
  57. i0,
  58. i1,
  59. i,
  60. value0;
  61. if (reduce == null) reduce = pair;
  62. for (i0 = i = 0; i0 < n0; ++i0) {
  63. for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
  64. values[i] = reduce(value0, values1[i1]);
  65. }
  66. }
  67. return values;
  68. }
  69. function descending(a, b) {
  70. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  71. }
  72. function number(x) {
  73. return x === null ? NaN : +x;
  74. }
  75. function variance(values, valueof) {
  76. var n = values.length,
  77. m = 0,
  78. i = -1,
  79. mean = 0,
  80. value,
  81. delta,
  82. sum = 0;
  83. if (valueof == null) {
  84. while (++i < n) {
  85. if (!isNaN(value = number(values[i]))) {
  86. delta = value - mean;
  87. mean += delta / ++m;
  88. sum += delta * (value - mean);
  89. }
  90. }
  91. }
  92. else {
  93. while (++i < n) {
  94. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  95. delta = value - mean;
  96. mean += delta / ++m;
  97. sum += delta * (value - mean);
  98. }
  99. }
  100. }
  101. if (m > 1) return sum / (m - 1);
  102. }
  103. function deviation(array, f) {
  104. var v = variance(array, f);
  105. return v ? Math.sqrt(v) : v;
  106. }
  107. function extent(values, valueof) {
  108. var n = values.length,
  109. i = -1,
  110. value,
  111. min,
  112. max;
  113. if (valueof == null) {
  114. while (++i < n) { // Find the first comparable value.
  115. if ((value = values[i]) != null && value >= value) {
  116. min = max = value;
  117. while (++i < n) { // Compare the remaining values.
  118. if ((value = values[i]) != null) {
  119. if (min > value) min = value;
  120. if (max < value) max = value;
  121. }
  122. }
  123. }
  124. }
  125. }
  126. else {
  127. while (++i < n) { // Find the first comparable value.
  128. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  129. min = max = value;
  130. while (++i < n) { // Compare the remaining values.
  131. if ((value = valueof(values[i], i, values)) != null) {
  132. if (min > value) min = value;
  133. if (max < value) max = value;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. return [min, max];
  140. }
  141. var array = Array.prototype;
  142. var slice = array.slice;
  143. var map = array.map;
  144. function constant(x) {
  145. return function() {
  146. return x;
  147. };
  148. }
  149. function identity(x) {
  150. return x;
  151. }
  152. function sequence(start, stop, step) {
  153. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  154. var i = -1,
  155. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  156. range = new Array(n);
  157. while (++i < n) {
  158. range[i] = start + i * step;
  159. }
  160. return range;
  161. }
  162. var e10 = Math.sqrt(50),
  163. e5 = Math.sqrt(10),
  164. e2 = Math.sqrt(2);
  165. function ticks(start, stop, count) {
  166. var reverse,
  167. i = -1,
  168. n,
  169. ticks,
  170. step;
  171. stop = +stop, start = +start, count = +count;
  172. if (start === stop && count > 0) return [start];
  173. if (reverse = stop < start) n = start, start = stop, stop = n;
  174. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  175. if (step > 0) {
  176. start = Math.ceil(start / step);
  177. stop = Math.floor(stop / step);
  178. ticks = new Array(n = Math.ceil(stop - start + 1));
  179. while (++i < n) ticks[i] = (start + i) * step;
  180. } else {
  181. start = Math.floor(start * step);
  182. stop = Math.ceil(stop * step);
  183. ticks = new Array(n = Math.ceil(start - stop + 1));
  184. while (++i < n) ticks[i] = (start - i) / step;
  185. }
  186. if (reverse) ticks.reverse();
  187. return ticks;
  188. }
  189. function tickIncrement(start, stop, count) {
  190. var step = (stop - start) / Math.max(0, count),
  191. power = Math.floor(Math.log(step) / Math.LN10),
  192. error = step / Math.pow(10, power);
  193. return power >= 0
  194. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  195. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  196. }
  197. function tickStep(start, stop, count) {
  198. var step0 = Math.abs(stop - start) / Math.max(0, count),
  199. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  200. error = step0 / step1;
  201. if (error >= e10) step1 *= 10;
  202. else if (error >= e5) step1 *= 5;
  203. else if (error >= e2) step1 *= 2;
  204. return stop < start ? -step1 : step1;
  205. }
  206. function thresholdSturges(values) {
  207. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  208. }
  209. function histogram() {
  210. var value = identity,
  211. domain = extent,
  212. threshold = thresholdSturges;
  213. function histogram(data) {
  214. var i,
  215. n = data.length,
  216. x,
  217. values = new Array(n);
  218. for (i = 0; i < n; ++i) {
  219. values[i] = value(data[i], i, data);
  220. }
  221. var xz = domain(values),
  222. x0 = xz[0],
  223. x1 = xz[1],
  224. tz = threshold(values, x0, x1);
  225. // Convert number of thresholds into uniform thresholds.
  226. if (!Array.isArray(tz)) {
  227. tz = tickStep(x0, x1, tz);
  228. tz = sequence(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive
  229. }
  230. // Remove any thresholds outside the domain.
  231. var m = tz.length;
  232. while (tz[0] <= x0) tz.shift(), --m;
  233. while (tz[m - 1] > x1) tz.pop(), --m;
  234. var bins = new Array(m + 1),
  235. bin;
  236. // Initialize bins.
  237. for (i = 0; i <= m; ++i) {
  238. bin = bins[i] = [];
  239. bin.x0 = i > 0 ? tz[i - 1] : x0;
  240. bin.x1 = i < m ? tz[i] : x1;
  241. }
  242. // Assign data to bins by value, ignoring any outside the domain.
  243. for (i = 0; i < n; ++i) {
  244. x = values[i];
  245. if (x0 <= x && x <= x1) {
  246. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  247. }
  248. }
  249. return bins;
  250. }
  251. histogram.value = function(_) {
  252. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  253. };
  254. histogram.domain = function(_) {
  255. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  256. };
  257. histogram.thresholds = function(_) {
  258. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  259. };
  260. return histogram;
  261. }
  262. function threshold(values, p, valueof) {
  263. if (valueof == null) valueof = number;
  264. if (!(n = values.length)) return;
  265. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  266. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  267. var n,
  268. i = (n - 1) * p,
  269. i0 = Math.floor(i),
  270. value0 = +valueof(values[i0], i0, values),
  271. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  272. return value0 + (value1 - value0) * (i - i0);
  273. }
  274. function freedmanDiaconis(values, min, max) {
  275. values = map.call(values, number).sort(ascending);
  276. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  277. }
  278. function scott(values, min, max) {
  279. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  280. }
  281. function max(values, valueof) {
  282. var n = values.length,
  283. i = -1,
  284. value,
  285. max;
  286. if (valueof == null) {
  287. while (++i < n) { // Find the first comparable value.
  288. if ((value = values[i]) != null && value >= value) {
  289. max = value;
  290. while (++i < n) { // Compare the remaining values.
  291. if ((value = values[i]) != null && value > max) {
  292. max = value;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. else {
  299. while (++i < n) { // Find the first comparable value.
  300. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  301. max = value;
  302. while (++i < n) { // Compare the remaining values.
  303. if ((value = valueof(values[i], i, values)) != null && value > max) {
  304. max = value;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. return max;
  311. }
  312. function mean(values, valueof) {
  313. var n = values.length,
  314. m = n,
  315. i = -1,
  316. value,
  317. sum = 0;
  318. if (valueof == null) {
  319. while (++i < n) {
  320. if (!isNaN(value = number(values[i]))) sum += value;
  321. else --m;
  322. }
  323. }
  324. else {
  325. while (++i < n) {
  326. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  327. else --m;
  328. }
  329. }
  330. if (m) return sum / m;
  331. }
  332. function median(values, valueof) {
  333. var n = values.length,
  334. i = -1,
  335. value,
  336. numbers = [];
  337. if (valueof == null) {
  338. while (++i < n) {
  339. if (!isNaN(value = number(values[i]))) {
  340. numbers.push(value);
  341. }
  342. }
  343. }
  344. else {
  345. while (++i < n) {
  346. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  347. numbers.push(value);
  348. }
  349. }
  350. }
  351. return threshold(numbers.sort(ascending), 0.5);
  352. }
  353. function merge(arrays) {
  354. var n = arrays.length,
  355. m,
  356. i = -1,
  357. j = 0,
  358. merged,
  359. array;
  360. while (++i < n) j += arrays[i].length;
  361. merged = new Array(j);
  362. while (--n >= 0) {
  363. array = arrays[n];
  364. m = array.length;
  365. while (--m >= 0) {
  366. merged[--j] = array[m];
  367. }
  368. }
  369. return merged;
  370. }
  371. function min(values, valueof) {
  372. var n = values.length,
  373. i = -1,
  374. value,
  375. min;
  376. if (valueof == null) {
  377. while (++i < n) { // Find the first comparable value.
  378. if ((value = values[i]) != null && value >= value) {
  379. min = value;
  380. while (++i < n) { // Compare the remaining values.
  381. if ((value = values[i]) != null && min > value) {
  382. min = value;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. else {
  389. while (++i < n) { // Find the first comparable value.
  390. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  391. min = value;
  392. while (++i < n) { // Compare the remaining values.
  393. if ((value = valueof(values[i], i, values)) != null && min > value) {
  394. min = value;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. return min;
  401. }
  402. function permute(array, indexes) {
  403. var i = indexes.length, permutes = new Array(i);
  404. while (i--) permutes[i] = array[indexes[i]];
  405. return permutes;
  406. }
  407. function scan(values, compare) {
  408. if (!(n = values.length)) return;
  409. var n,
  410. i = 0,
  411. j = 0,
  412. xi,
  413. xj = values[j];
  414. if (compare == null) compare = ascending;
  415. while (++i < n) {
  416. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  417. xj = xi, j = i;
  418. }
  419. }
  420. if (compare(xj, xj) === 0) return j;
  421. }
  422. function shuffle(array, i0, i1) {
  423. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  424. t,
  425. i;
  426. while (m) {
  427. i = Math.random() * m-- | 0;
  428. t = array[m + i0];
  429. array[m + i0] = array[i + i0];
  430. array[i + i0] = t;
  431. }
  432. return array;
  433. }
  434. function sum(values, valueof) {
  435. var n = values.length,
  436. i = -1,
  437. value,
  438. sum = 0;
  439. if (valueof == null) {
  440. while (++i < n) {
  441. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  442. }
  443. }
  444. else {
  445. while (++i < n) {
  446. if (value = +valueof(values[i], i, values)) sum += value;
  447. }
  448. }
  449. return sum;
  450. }
  451. function transpose(matrix) {
  452. if (!(n = matrix.length)) return [];
  453. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  454. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  455. row[j] = matrix[j][i];
  456. }
  457. }
  458. return transpose;
  459. }
  460. function length(d) {
  461. return d.length;
  462. }
  463. function zip() {
  464. return transpose(arguments);
  465. }
  466. var slice$1 = Array.prototype.slice;
  467. function identity$1(x) {
  468. return x;
  469. }
  470. var top = 1,
  471. right = 2,
  472. bottom = 3,
  473. left = 4,
  474. epsilon = 1e-6;
  475. function translateX(x) {
  476. return "translate(" + (x + 0.5) + ",0)";
  477. }
  478. function translateY(y) {
  479. return "translate(0," + (y + 0.5) + ")";
  480. }
  481. function number$1(scale) {
  482. return function(d) {
  483. return +scale(d);
  484. };
  485. }
  486. function center(scale) {
  487. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  488. if (scale.round()) offset = Math.round(offset);
  489. return function(d) {
  490. return +scale(d) + offset;
  491. };
  492. }
  493. function entering() {
  494. return !this.__axis;
  495. }
  496. function axis(orient, scale) {
  497. var tickArguments = [],
  498. tickValues = null,
  499. tickFormat = null,
  500. tickSizeInner = 6,
  501. tickSizeOuter = 6,
  502. tickPadding = 3,
  503. k = orient === top || orient === left ? -1 : 1,
  504. x = orient === left || orient === right ? "x" : "y",
  505. transform = orient === top || orient === bottom ? translateX : translateY;
  506. function axis(context) {
  507. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  508. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  509. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  510. range = scale.range(),
  511. range0 = +range[0] + 0.5,
  512. range1 = +range[range.length - 1] + 0.5,
  513. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  514. selection = context.selection ? context.selection() : context,
  515. path = selection.selectAll(".domain").data([null]),
  516. tick = selection.selectAll(".tick").data(values, scale).order(),
  517. tickExit = tick.exit(),
  518. tickEnter = tick.enter().append("g").attr("class", "tick"),
  519. line = tick.select("line"),
  520. text = tick.select("text");
  521. path = path.merge(path.enter().insert("path", ".tick")
  522. .attr("class", "domain")
  523. .attr("stroke", "currentColor"));
  524. tick = tick.merge(tickEnter);
  525. line = line.merge(tickEnter.append("line")
  526. .attr("stroke", "currentColor")
  527. .attr(x + "2", k * tickSizeInner));
  528. text = text.merge(tickEnter.append("text")
  529. .attr("fill", "currentColor")
  530. .attr(x, k * spacing)
  531. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  532. if (context !== selection) {
  533. path = path.transition(context);
  534. tick = tick.transition(context);
  535. line = line.transition(context);
  536. text = text.transition(context);
  537. tickExit = tickExit.transition(context)
  538. .attr("opacity", epsilon)
  539. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  540. tickEnter
  541. .attr("opacity", epsilon)
  542. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  543. }
  544. tickExit.remove();
  545. path
  546. .attr("d", orient === left || orient == right
  547. ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M0.5," + range0 + "V" + range1)
  548. : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + ",0.5H" + range1));
  549. tick
  550. .attr("opacity", 1)
  551. .attr("transform", function(d) { return transform(position(d)); });
  552. line
  553. .attr(x + "2", k * tickSizeInner);
  554. text
  555. .attr(x, k * spacing)
  556. .text(format);
  557. selection.filter(entering)
  558. .attr("fill", "none")
  559. .attr("font-size", 10)
  560. .attr("font-family", "sans-serif")
  561. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  562. selection
  563. .each(function() { this.__axis = position; });
  564. }
  565. axis.scale = function(_) {
  566. return arguments.length ? (scale = _, axis) : scale;
  567. };
  568. axis.ticks = function() {
  569. return tickArguments = slice$1.call(arguments), axis;
  570. };
  571. axis.tickArguments = function(_) {
  572. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  573. };
  574. axis.tickValues = function(_) {
  575. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  576. };
  577. axis.tickFormat = function(_) {
  578. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  579. };
  580. axis.tickSize = function(_) {
  581. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  582. };
  583. axis.tickSizeInner = function(_) {
  584. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  585. };
  586. axis.tickSizeOuter = function(_) {
  587. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  588. };
  589. axis.tickPadding = function(_) {
  590. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  591. };
  592. return axis;
  593. }
  594. function axisTop(scale) {
  595. return axis(top, scale);
  596. }
  597. function axisRight(scale) {
  598. return axis(right, scale);
  599. }
  600. function axisBottom(scale) {
  601. return axis(bottom, scale);
  602. }
  603. function axisLeft(scale) {
  604. return axis(left, scale);
  605. }
  606. var noop = {value: function() {}};
  607. function dispatch() {
  608. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  609. if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
  610. _[t] = [];
  611. }
  612. return new Dispatch(_);
  613. }
  614. function Dispatch(_) {
  615. this._ = _;
  616. }
  617. function parseTypenames(typenames, types) {
  618. return typenames.trim().split(/^|\s+/).map(function(t) {
  619. var name = "", i = t.indexOf(".");
  620. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  621. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  622. return {type: t, name: name};
  623. });
  624. }
  625. Dispatch.prototype = dispatch.prototype = {
  626. constructor: Dispatch,
  627. on: function(typename, callback) {
  628. var _ = this._,
  629. T = parseTypenames(typename + "", _),
  630. t,
  631. i = -1,
  632. n = T.length;
  633. // If no callback was specified, return the callback of the given type and name.
  634. if (arguments.length < 2) {
  635. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  636. return;
  637. }
  638. // If a type was specified, set the callback for the given type and name.
  639. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  640. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  641. while (++i < n) {
  642. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  643. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  644. }
  645. return this;
  646. },
  647. copy: function() {
  648. var copy = {}, _ = this._;
  649. for (var t in _) copy[t] = _[t].slice();
  650. return new Dispatch(copy);
  651. },
  652. call: function(type, that) {
  653. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  654. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  655. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  656. },
  657. apply: function(type, that, args) {
  658. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  659. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  660. }
  661. };
  662. function get(type, name) {
  663. for (var i = 0, n = type.length, c; i < n; ++i) {
  664. if ((c = type[i]).name === name) {
  665. return c.value;
  666. }
  667. }
  668. }
  669. function set(type, name, callback) {
  670. for (var i = 0, n = type.length; i < n; ++i) {
  671. if (type[i].name === name) {
  672. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  673. break;
  674. }
  675. }
  676. if (callback != null) type.push({name: name, value: callback});
  677. return type;
  678. }
  679. var xhtml = "http://www.w3.org/1999/xhtml";
  680. var namespaces = {
  681. svg: "http://www.w3.org/2000/svg",
  682. xhtml: xhtml,
  683. xlink: "http://www.w3.org/1999/xlink",
  684. xml: "http://www.w3.org/XML/1998/namespace",
  685. xmlns: "http://www.w3.org/2000/xmlns/"
  686. };
  687. function namespace(name) {
  688. var prefix = name += "", i = prefix.indexOf(":");
  689. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  690. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  691. }
  692. function creatorInherit(name) {
  693. return function() {
  694. var document = this.ownerDocument,
  695. uri = this.namespaceURI;
  696. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  697. ? document.createElement(name)
  698. : document.createElementNS(uri, name);
  699. };
  700. }
  701. function creatorFixed(fullname) {
  702. return function() {
  703. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  704. };
  705. }
  706. function creator(name) {
  707. var fullname = namespace(name);
  708. return (fullname.local
  709. ? creatorFixed
  710. : creatorInherit)(fullname);
  711. }
  712. function none() {}
  713. function selector(selector) {
  714. return selector == null ? none : function() {
  715. return this.querySelector(selector);
  716. };
  717. }
  718. function selection_select(select) {
  719. if (typeof select !== "function") select = selector(select);
  720. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  721. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  722. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  723. if ("__data__" in node) subnode.__data__ = node.__data__;
  724. subgroup[i] = subnode;
  725. }
  726. }
  727. }
  728. return new Selection(subgroups, this._parents);
  729. }
  730. function empty() {
  731. return [];
  732. }
  733. function selectorAll(selector) {
  734. return selector == null ? empty : function() {
  735. return this.querySelectorAll(selector);
  736. };
  737. }
  738. function selection_selectAll(select) {
  739. if (typeof select !== "function") select = selectorAll(select);
  740. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  741. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  742. if (node = group[i]) {
  743. subgroups.push(select.call(node, node.__data__, i, group));
  744. parents.push(node);
  745. }
  746. }
  747. }
  748. return new Selection(subgroups, parents);
  749. }
  750. function matcher(selector) {
  751. return function() {
  752. return this.matches(selector);
  753. };
  754. }
  755. function selection_filter(match) {
  756. if (typeof match !== "function") match = matcher(match);
  757. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  758. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  759. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  760. subgroup.push(node);
  761. }
  762. }
  763. }
  764. return new Selection(subgroups, this._parents);
  765. }
  766. function sparse(update) {
  767. return new Array(update.length);
  768. }
  769. function selection_enter() {
  770. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  771. }
  772. function EnterNode(parent, datum) {
  773. this.ownerDocument = parent.ownerDocument;
  774. this.namespaceURI = parent.namespaceURI;
  775. this._next = null;
  776. this._parent = parent;
  777. this.__data__ = datum;
  778. }
  779. EnterNode.prototype = {
  780. constructor: EnterNode,
  781. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  782. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  783. querySelector: function(selector) { return this._parent.querySelector(selector); },
  784. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  785. };
  786. function constant$1(x) {
  787. return function() {
  788. return x;
  789. };
  790. }
  791. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  792. function bindIndex(parent, group, enter, update, exit, data) {
  793. var i = 0,
  794. node,
  795. groupLength = group.length,
  796. dataLength = data.length;
  797. // Put any non-null nodes that fit into update.
  798. // Put any null nodes into enter.
  799. // Put any remaining data into enter.
  800. for (; i < dataLength; ++i) {
  801. if (node = group[i]) {
  802. node.__data__ = data[i];
  803. update[i] = node;
  804. } else {
  805. enter[i] = new EnterNode(parent, data[i]);
  806. }
  807. }
  808. // Put any non-null nodes that don’t fit into exit.
  809. for (; i < groupLength; ++i) {
  810. if (node = group[i]) {
  811. exit[i] = node;
  812. }
  813. }
  814. }
  815. function bindKey(parent, group, enter, update, exit, data, key) {
  816. var i,
  817. node,
  818. nodeByKeyValue = {},
  819. groupLength = group.length,
  820. dataLength = data.length,
  821. keyValues = new Array(groupLength),
  822. keyValue;
  823. // Compute the key for each node.
  824. // If multiple nodes have the same key, the duplicates are added to exit.
  825. for (i = 0; i < groupLength; ++i) {
  826. if (node = group[i]) {
  827. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  828. if (keyValue in nodeByKeyValue) {
  829. exit[i] = node;
  830. } else {
  831. nodeByKeyValue[keyValue] = node;
  832. }
  833. }
  834. }
  835. // Compute the key for each datum.
  836. // If there a node associated with this key, join and add it to update.
  837. // If there is not (or the key is a duplicate), add it to enter.
  838. for (i = 0; i < dataLength; ++i) {
  839. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  840. if (node = nodeByKeyValue[keyValue]) {
  841. update[i] = node;
  842. node.__data__ = data[i];
  843. nodeByKeyValue[keyValue] = null;
  844. } else {
  845. enter[i] = new EnterNode(parent, data[i]);
  846. }
  847. }
  848. // Add any remaining nodes that were not bound to data to exit.
  849. for (i = 0; i < groupLength; ++i) {
  850. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  851. exit[i] = node;
  852. }
  853. }
  854. }
  855. function selection_data(value, key) {
  856. if (!value) {
  857. data = new Array(this.size()), j = -1;
  858. this.each(function(d) { data[++j] = d; });
  859. return data;
  860. }
  861. var bind = key ? bindKey : bindIndex,
  862. parents = this._parents,
  863. groups = this._groups;
  864. if (typeof value !== "function") value = constant$1(value);
  865. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  866. var parent = parents[j],
  867. group = groups[j],
  868. groupLength = group.length,
  869. data = value.call(parent, parent && parent.__data__, j, parents),
  870. dataLength = data.length,
  871. enterGroup = enter[j] = new Array(dataLength),
  872. updateGroup = update[j] = new Array(dataLength),
  873. exitGroup = exit[j] = new Array(groupLength);
  874. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  875. // Now connect the enter nodes to their following update node, such that
  876. // appendChild can insert the materialized enter node before this node,
  877. // rather than at the end of the parent node.
  878. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  879. if (previous = enterGroup[i0]) {
  880. if (i0 >= i1) i1 = i0 + 1;
  881. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  882. previous._next = next || null;
  883. }
  884. }
  885. }
  886. update = new Selection(update, parents);
  887. update._enter = enter;
  888. update._exit = exit;
  889. return update;
  890. }
  891. function selection_exit() {
  892. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  893. }
  894. function selection_join(onenter, onupdate, onexit) {
  895. var enter = this.enter(), update = this, exit = this.exit();
  896. enter = typeof onenter === "function" ? onenter(enter) : enter.append(onenter + "");
  897. if (onupdate != null) update = onupdate(update);
  898. if (onexit == null) exit.remove(); else onexit(exit);
  899. return enter && update ? enter.merge(update).order() : update;
  900. }
  901. function selection_merge(selection) {
  902. 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) {
  903. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  904. if (node = group0[i] || group1[i]) {
  905. merge[i] = node;
  906. }
  907. }
  908. }
  909. for (; j < m0; ++j) {
  910. merges[j] = groups0[j];
  911. }
  912. return new Selection(merges, this._parents);
  913. }
  914. function selection_order() {
  915. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  916. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  917. if (node = group[i]) {
  918. if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
  919. next = node;
  920. }
  921. }
  922. }
  923. return this;
  924. }
  925. function selection_sort(compare) {
  926. if (!compare) compare = ascending$1;
  927. function compareNode(a, b) {
  928. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  929. }
  930. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  931. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  932. if (node = group[i]) {
  933. sortgroup[i] = node;
  934. }
  935. }
  936. sortgroup.sort(compareNode);
  937. }
  938. return new Selection(sortgroups, this._parents).order();
  939. }
  940. function ascending$1(a, b) {
  941. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  942. }
  943. function selection_call() {
  944. var callback = arguments[0];
  945. arguments[0] = this;
  946. callback.apply(null, arguments);
  947. return this;
  948. }
  949. function selection_nodes() {
  950. var nodes = new Array(this.size()), i = -1;
  951. this.each(function() { nodes[++i] = this; });
  952. return nodes;
  953. }
  954. function selection_node() {
  955. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  956. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  957. var node = group[i];
  958. if (node) return node;
  959. }
  960. }
  961. return null;
  962. }
  963. function selection_size() {
  964. var size = 0;
  965. this.each(function() { ++size; });
  966. return size;
  967. }
  968. function selection_empty() {
  969. return !this.node();
  970. }
  971. function selection_each(callback) {
  972. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  973. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  974. if (node = group[i]) callback.call(node, node.__data__, i, group);
  975. }
  976. }
  977. return this;
  978. }
  979. function attrRemove(name) {
  980. return function() {
  981. this.removeAttribute(name);
  982. };
  983. }
  984. function attrRemoveNS(fullname) {
  985. return function() {
  986. this.removeAttributeNS(fullname.space, fullname.local);
  987. };
  988. }
  989. function attrConstant(name, value) {
  990. return function() {
  991. this.setAttribute(name, value);
  992. };
  993. }
  994. function attrConstantNS(fullname, value) {
  995. return function() {
  996. this.setAttributeNS(fullname.space, fullname.local, value);
  997. };
  998. }
  999. function attrFunction(name, value) {
  1000. return function() {
  1001. var v = value.apply(this, arguments);
  1002. if (v == null) this.removeAttribute(name);
  1003. else this.setAttribute(name, v);
  1004. };
  1005. }
  1006. function attrFunctionNS(fullname, value) {
  1007. return function() {
  1008. var v = value.apply(this, arguments);
  1009. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1010. else this.setAttributeNS(fullname.space, fullname.local, v);
  1011. };
  1012. }
  1013. function selection_attr(name, value) {
  1014. var fullname = namespace(name);
  1015. if (arguments.length < 2) {
  1016. var node = this.node();
  1017. return fullname.local
  1018. ? node.getAttributeNS(fullname.space, fullname.local)
  1019. : node.getAttribute(fullname);
  1020. }
  1021. return this.each((value == null
  1022. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1023. ? (fullname.local ? attrFunctionNS : attrFunction)
  1024. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1025. }
  1026. function defaultView(node) {
  1027. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1028. || (node.document && node) // node is a Window
  1029. || node.defaultView; // node is a Document
  1030. }
  1031. function styleRemove(name) {
  1032. return function() {
  1033. this.style.removeProperty(name);
  1034. };
  1035. }
  1036. function styleConstant(name, value, priority) {
  1037. return function() {
  1038. this.style.setProperty(name, value, priority);
  1039. };
  1040. }
  1041. function styleFunction(name, value, priority) {
  1042. return function() {
  1043. var v = value.apply(this, arguments);
  1044. if (v == null) this.style.removeProperty(name);
  1045. else this.style.setProperty(name, v, priority);
  1046. };
  1047. }
  1048. function selection_style(name, value, priority) {
  1049. return arguments.length > 1
  1050. ? this.each((value == null
  1051. ? styleRemove : typeof value === "function"
  1052. ? styleFunction
  1053. : styleConstant)(name, value, priority == null ? "" : priority))
  1054. : styleValue(this.node(), name);
  1055. }
  1056. function styleValue(node, name) {
  1057. return node.style.getPropertyValue(name)
  1058. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1059. }
  1060. function propertyRemove(name) {
  1061. return function() {
  1062. delete this[name];
  1063. };
  1064. }
  1065. function propertyConstant(name, value) {
  1066. return function() {
  1067. this[name] = value;
  1068. };
  1069. }
  1070. function propertyFunction(name, value) {
  1071. return function() {
  1072. var v = value.apply(this, arguments);
  1073. if (v == null) delete this[name];
  1074. else this[name] = v;
  1075. };
  1076. }
  1077. function selection_property(name, value) {
  1078. return arguments.length > 1
  1079. ? this.each((value == null
  1080. ? propertyRemove : typeof value === "function"
  1081. ? propertyFunction
  1082. : propertyConstant)(name, value))
  1083. : this.node()[name];
  1084. }
  1085. function classArray(string) {
  1086. return string.trim().split(/^|\s+/);
  1087. }
  1088. function classList(node) {
  1089. return node.classList || new ClassList(node);
  1090. }
  1091. function ClassList(node) {
  1092. this._node = node;
  1093. this._names = classArray(node.getAttribute("class") || "");
  1094. }
  1095. ClassList.prototype = {
  1096. add: function(name) {
  1097. var i = this._names.indexOf(name);
  1098. if (i < 0) {
  1099. this._names.push(name);
  1100. this._node.setAttribute("class", this._names.join(" "));
  1101. }
  1102. },
  1103. remove: function(name) {
  1104. var i = this._names.indexOf(name);
  1105. if (i >= 0) {
  1106. this._names.splice(i, 1);
  1107. this._node.setAttribute("class", this._names.join(" "));
  1108. }
  1109. },
  1110. contains: function(name) {
  1111. return this._names.indexOf(name) >= 0;
  1112. }
  1113. };
  1114. function classedAdd(node, names) {
  1115. var list = classList(node), i = -1, n = names.length;
  1116. while (++i < n) list.add(names[i]);
  1117. }
  1118. function classedRemove(node, names) {
  1119. var list = classList(node), i = -1, n = names.length;
  1120. while (++i < n) list.remove(names[i]);
  1121. }
  1122. function classedTrue(names) {
  1123. return function() {
  1124. classedAdd(this, names);
  1125. };
  1126. }
  1127. function classedFalse(names) {
  1128. return function() {
  1129. classedRemove(this, names);
  1130. };
  1131. }
  1132. function classedFunction(names, value) {
  1133. return function() {
  1134. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1135. };
  1136. }
  1137. function selection_classed(name, value) {
  1138. var names = classArray(name + "");
  1139. if (arguments.length < 2) {
  1140. var list = classList(this.node()), i = -1, n = names.length;
  1141. while (++i < n) if (!list.contains(names[i])) return false;
  1142. return true;
  1143. }
  1144. return this.each((typeof value === "function"
  1145. ? classedFunction : value
  1146. ? classedTrue
  1147. : classedFalse)(names, value));
  1148. }
  1149. function textRemove() {
  1150. this.textContent = "";
  1151. }
  1152. function textConstant(value) {
  1153. return function() {
  1154. this.textContent = value;
  1155. };
  1156. }
  1157. function textFunction(value) {
  1158. return function() {
  1159. var v = value.apply(this, arguments);
  1160. this.textContent = v == null ? "" : v;
  1161. };
  1162. }
  1163. function selection_text(value) {
  1164. return arguments.length
  1165. ? this.each(value == null
  1166. ? textRemove : (typeof value === "function"
  1167. ? textFunction
  1168. : textConstant)(value))
  1169. : this.node().textContent;
  1170. }
  1171. function htmlRemove() {
  1172. this.innerHTML = "";
  1173. }
  1174. function htmlConstant(value) {
  1175. return function() {
  1176. this.innerHTML = value;
  1177. };
  1178. }
  1179. function htmlFunction(value) {
  1180. return function() {
  1181. var v = value.apply(this, arguments);
  1182. this.innerHTML = v == null ? "" : v;
  1183. };
  1184. }
  1185. function selection_html(value) {
  1186. return arguments.length
  1187. ? this.each(value == null
  1188. ? htmlRemove : (typeof value === "function"
  1189. ? htmlFunction
  1190. : htmlConstant)(value))
  1191. : this.node().innerHTML;
  1192. }
  1193. function raise() {
  1194. if (this.nextSibling) this.parentNode.appendChild(this);
  1195. }
  1196. function selection_raise() {
  1197. return this.each(raise);
  1198. }
  1199. function lower() {
  1200. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1201. }
  1202. function selection_lower() {
  1203. return this.each(lower);
  1204. }
  1205. function selection_append(name) {
  1206. var create = typeof name === "function" ? name : creator(name);
  1207. return this.select(function() {
  1208. return this.appendChild(create.apply(this, arguments));
  1209. });
  1210. }
  1211. function constantNull() {
  1212. return null;
  1213. }
  1214. function selection_insert(name, before) {
  1215. var create = typeof name === "function" ? name : creator(name),
  1216. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1217. return this.select(function() {
  1218. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1219. });
  1220. }
  1221. function remove() {
  1222. var parent = this.parentNode;
  1223. if (parent) parent.removeChild(this);
  1224. }
  1225. function selection_remove() {
  1226. return this.each(remove);
  1227. }
  1228. function selection_cloneShallow() {
  1229. var clone = this.cloneNode(false), parent = this.parentNode;
  1230. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  1231. }
  1232. function selection_cloneDeep() {
  1233. var clone = this.cloneNode(true), parent = this.parentNode;
  1234. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  1235. }
  1236. function selection_clone(deep) {
  1237. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  1238. }
  1239. function selection_datum(value) {
  1240. return arguments.length
  1241. ? this.property("__data__", value)
  1242. : this.node().__data__;
  1243. }
  1244. var filterEvents = {};
  1245. exports.event = null;
  1246. if (typeof document !== "undefined") {
  1247. var element = document.documentElement;
  1248. if (!("onmouseenter" in element)) {
  1249. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  1250. }
  1251. }
  1252. function filterContextListener(listener, index, group) {
  1253. listener = contextListener(listener, index, group);
  1254. return function(event) {
  1255. var related = event.relatedTarget;
  1256. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  1257. listener.call(this, event);
  1258. }
  1259. };
  1260. }
  1261. function contextListener(listener, index, group) {
  1262. return function(event1) {
  1263. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  1264. exports.event = event1;
  1265. try {
  1266. listener.call(this, this.__data__, index, group);
  1267. } finally {
  1268. exports.event = event0;
  1269. }
  1270. };
  1271. }
  1272. function parseTypenames$1(typenames) {
  1273. return typenames.trim().split(/^|\s+/).map(function(t) {
  1274. var name = "", i = t.indexOf(".");
  1275. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1276. return {type: t, name: name};
  1277. });
  1278. }
  1279. function onRemove(typename) {
  1280. return function() {
  1281. var on = this.__on;
  1282. if (!on) return;
  1283. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  1284. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  1285. this.removeEventListener(o.type, o.listener, o.capture);
  1286. } else {
  1287. on[++i] = o;
  1288. }
  1289. }
  1290. if (++i) on.length = i;
  1291. else delete this.__on;
  1292. };
  1293. }
  1294. function onAdd(typename, value, capture) {
  1295. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  1296. return function(d, i, group) {
  1297. var on = this.__on, o, listener = wrap(value, i, group);
  1298. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  1299. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  1300. this.removeEventListener(o.type, o.listener, o.capture);
  1301. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  1302. o.value = value;
  1303. return;
  1304. }
  1305. }
  1306. this.addEventListener(typename.type, listener, capture);
  1307. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  1308. if (!on) this.__on = [o];
  1309. else on.push(o);
  1310. };
  1311. }
  1312. function selection_on(typename, value, capture) {
  1313. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  1314. if (arguments.length < 2) {
  1315. var on = this.node().__on;
  1316. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  1317. for (i = 0, o = on[j]; i < n; ++i) {
  1318. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  1319. return o.value;
  1320. }
  1321. }
  1322. }
  1323. return;
  1324. }
  1325. on = value ? onAdd : onRemove;
  1326. if (capture == null) capture = false;
  1327. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  1328. return this;
  1329. }
  1330. function customEvent(event1, listener, that, args) {
  1331. var event0 = exports.event;
  1332. event1.sourceEvent = exports.event;
  1333. exports.event = event1;
  1334. try {
  1335. return listener.apply(that, args);
  1336. } finally {
  1337. exports.event = event0;
  1338. }
  1339. }
  1340. function dispatchEvent(node, type, params) {
  1341. var window = defaultView(node),
  1342. event = window.CustomEvent;
  1343. if (typeof event === "function") {
  1344. event = new event(type, params);
  1345. } else {
  1346. event = window.document.createEvent("Event");
  1347. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1348. else event.initEvent(type, false, false);
  1349. }
  1350. node.dispatchEvent(event);
  1351. }
  1352. function dispatchConstant(type, params) {
  1353. return function() {
  1354. return dispatchEvent(this, type, params);
  1355. };
  1356. }
  1357. function dispatchFunction(type, params) {
  1358. return function() {
  1359. return dispatchEvent(this, type, params.apply(this, arguments));
  1360. };
  1361. }
  1362. function selection_dispatch(type, params) {
  1363. return this.each((typeof params === "function"
  1364. ? dispatchFunction
  1365. : dispatchConstant)(type, params));
  1366. }
  1367. var root = [null];
  1368. function Selection(groups, parents) {
  1369. this._groups = groups;
  1370. this._parents = parents;
  1371. }
  1372. function selection() {
  1373. return new Selection([[document.documentElement]], root);
  1374. }
  1375. Selection.prototype = selection.prototype = {
  1376. constructor: Selection,
  1377. select: selection_select,
  1378. selectAll: selection_selectAll,
  1379. filter: selection_filter,
  1380. data: selection_data,
  1381. enter: selection_enter,
  1382. exit: selection_exit,
  1383. join: selection_join,
  1384. merge: selection_merge,
  1385. order: selection_order,
  1386. sort: selection_sort,
  1387. call: selection_call,
  1388. nodes: selection_nodes,
  1389. node: selection_node,
  1390. size: selection_size,
  1391. empty: selection_empty,
  1392. each: selection_each,
  1393. attr: selection_attr,
  1394. style: selection_style,
  1395. property: selection_property,
  1396. classed: selection_classed,
  1397. text: selection_text,
  1398. html: selection_html,
  1399. raise: selection_raise,
  1400. lower: selection_lower,
  1401. append: selection_append,
  1402. insert: selection_insert,
  1403. remove: selection_remove,
  1404. clone: selection_clone,
  1405. datum: selection_datum,
  1406. on: selection_on,
  1407. dispatch: selection_dispatch
  1408. };
  1409. function select(selector) {
  1410. return typeof selector === "string"
  1411. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1412. : new Selection([[selector]], root);
  1413. }
  1414. function create(name) {
  1415. return select(creator(name).call(document.documentElement));
  1416. }
  1417. var nextId = 0;
  1418. function local() {
  1419. return new Local;
  1420. }
  1421. function Local() {
  1422. this._ = "@" + (++nextId).toString(36);
  1423. }
  1424. Local.prototype = local.prototype = {
  1425. constructor: Local,
  1426. get: function(node) {
  1427. var id = this._;
  1428. while (!(id in node)) if (!(node = node.parentNode)) return;
  1429. return node[id];
  1430. },
  1431. set: function(node, value) {
  1432. return node[this._] = value;
  1433. },
  1434. remove: function(node) {
  1435. return this._ in node && delete node[this._];
  1436. },
  1437. toString: function() {
  1438. return this._;
  1439. }
  1440. };
  1441. function sourceEvent() {
  1442. var current = exports.event, source;
  1443. while (source = current.sourceEvent) current = source;
  1444. return current;
  1445. }
  1446. function point(node, event) {
  1447. var svg = node.ownerSVGElement || node;
  1448. if (svg.createSVGPoint) {
  1449. var point = svg.createSVGPoint();
  1450. point.x = event.clientX, point.y = event.clientY;
  1451. point = point.matrixTransform(node.getScreenCTM().inverse());
  1452. return [point.x, point.y];
  1453. }
  1454. var rect = node.getBoundingClientRect();
  1455. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  1456. }
  1457. function mouse(node) {
  1458. var event = sourceEvent();
  1459. if (event.changedTouches) event = event.changedTouches[0];
  1460. return point(node, event);
  1461. }
  1462. function selectAll(selector) {
  1463. return typeof selector === "string"
  1464. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1465. : new Selection([selector == null ? [] : selector], root);
  1466. }
  1467. function touch(node, touches, identifier) {
  1468. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1469. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1470. if ((touch = touches[i]).identifier === identifier) {
  1471. return point(node, touch);
  1472. }
  1473. }
  1474. return null;
  1475. }
  1476. function touches(node, touches) {
  1477. if (touches == null) touches = sourceEvent().touches;
  1478. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1479. points[i] = point(node, touches[i]);
  1480. }
  1481. return points;
  1482. }
  1483. function nopropagation() {
  1484. exports.event.stopImmediatePropagation();
  1485. }
  1486. function noevent() {
  1487. exports.event.preventDefault();
  1488. exports.event.stopImmediatePropagation();
  1489. }
  1490. function dragDisable(view) {
  1491. var root = view.document.documentElement,
  1492. selection = select(view).on("dragstart.drag", noevent, true);
  1493. if ("onselectstart" in root) {
  1494. selection.on("selectstart.drag", noevent, true);
  1495. } else {
  1496. root.__noselect = root.style.MozUserSelect;
  1497. root.style.MozUserSelect = "none";
  1498. }
  1499. }
  1500. function yesdrag(view, noclick) {
  1501. var root = view.document.documentElement,
  1502. selection = select(view).on("dragstart.drag", null);
  1503. if (noclick) {
  1504. selection.on("click.drag", noevent, true);
  1505. setTimeout(function() { selection.on("click.drag", null); }, 0);
  1506. }
  1507. if ("onselectstart" in root) {
  1508. selection.on("selectstart.drag", null);
  1509. } else {
  1510. root.style.MozUserSelect = root.__noselect;
  1511. delete root.__noselect;
  1512. }
  1513. }
  1514. function constant$2(x) {
  1515. return function() {
  1516. return x;
  1517. };
  1518. }
  1519. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1520. this.target = target;
  1521. this.type = type;
  1522. this.subject = subject;
  1523. this.identifier = id;
  1524. this.active = active;
  1525. this.x = x;
  1526. this.y = y;
  1527. this.dx = dx;
  1528. this.dy = dy;
  1529. this._ = dispatch;
  1530. }
  1531. DragEvent.prototype.on = function() {
  1532. var value = this._.on.apply(this._, arguments);
  1533. return value === this._ ? this : value;
  1534. };
  1535. // Ignore right-click, since that should open the context menu.
  1536. function defaultFilter() {
  1537. return !exports.event.ctrlKey && !exports.event.button;
  1538. }
  1539. function defaultContainer() {
  1540. return this.parentNode;
  1541. }
  1542. function defaultSubject(d) {
  1543. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1544. }
  1545. function defaultTouchable() {
  1546. return navigator.maxTouchPoints || ("ontouchstart" in this);
  1547. }
  1548. function drag() {
  1549. var filter = defaultFilter,
  1550. container = defaultContainer,
  1551. subject = defaultSubject,
  1552. touchable = defaultTouchable,
  1553. gestures = {},
  1554. listeners = dispatch("start", "drag", "end"),
  1555. active = 0,
  1556. mousedownx,
  1557. mousedowny,
  1558. mousemoving,
  1559. touchending,
  1560. clickDistance2 = 0;
  1561. function drag(selection) {
  1562. selection
  1563. .on("mousedown.drag", mousedowned)
  1564. .filter(touchable)
  1565. .on("touchstart.drag", touchstarted)
  1566. .on("touchmove.drag", touchmoved)
  1567. .on("touchend.drag touchcancel.drag", touchended)
  1568. .style("touch-action", "none")
  1569. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1570. }
  1571. function mousedowned() {
  1572. if (touchending || !filter.apply(this, arguments)) return;
  1573. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1574. if (!gesture) return;
  1575. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1576. dragDisable(exports.event.view);
  1577. nopropagation();
  1578. mousemoving = false;
  1579. mousedownx = exports.event.clientX;
  1580. mousedowny = exports.event.clientY;
  1581. gesture("start");
  1582. }
  1583. function mousemoved() {
  1584. noevent();
  1585. if (!mousemoving) {
  1586. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1587. mousemoving = dx * dx + dy * dy > clickDistance2;
  1588. }
  1589. gestures.mouse("drag");
  1590. }
  1591. function mouseupped() {
  1592. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1593. yesdrag(exports.event.view, mousemoving);
  1594. noevent();
  1595. gestures.mouse("end");
  1596. }
  1597. function touchstarted() {
  1598. if (!filter.apply(this, arguments)) return;
  1599. var touches = exports.event.changedTouches,
  1600. c = container.apply(this, arguments),
  1601. n = touches.length, i, gesture;
  1602. for (i = 0; i < n; ++i) {
  1603. if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
  1604. nopropagation();
  1605. gesture("start");
  1606. }
  1607. }
  1608. }
  1609. function touchmoved() {
  1610. var touches = exports.event.changedTouches,
  1611. n = touches.length, i, gesture;
  1612. for (i = 0; i < n; ++i) {
  1613. if (gesture = gestures[touches[i].identifier]) {
  1614. noevent();
  1615. gesture("drag");
  1616. }
  1617. }
  1618. }
  1619. function touchended() {
  1620. var touches = exports.event.changedTouches,
  1621. n = touches.length, i, gesture;
  1622. if (touchending) clearTimeout(touchending);
  1623. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1624. for (i = 0; i < n; ++i) {
  1625. if (gesture = gestures[touches[i].identifier]) {
  1626. nopropagation();
  1627. gesture("end");
  1628. }
  1629. }
  1630. }
  1631. function beforestart(id, container, point, that, args) {
  1632. var p = point(container, id), s, dx, dy,
  1633. sublisteners = listeners.copy();
  1634. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1635. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1636. dx = s.x - p[0] || 0;
  1637. dy = s.y - p[1] || 0;
  1638. return true;
  1639. })) return;
  1640. return function gesture(type) {
  1641. var p0 = p, n;
  1642. switch (type) {
  1643. case "start": gestures[id] = gesture, n = active++; break;
  1644. case "end": delete gestures[id], --active; // nobreak
  1645. case "drag": p = point(container, id), n = active; break;
  1646. }
  1647. customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
  1648. };
  1649. }
  1650. drag.filter = function(_) {
  1651. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1652. };
  1653. drag.container = function(_) {
  1654. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1655. };
  1656. drag.subject = function(_) {
  1657. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1658. };
  1659. drag.touchable = function(_) {
  1660. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  1661. };
  1662. drag.on = function() {
  1663. var value = listeners.on.apply(listeners, arguments);
  1664. return value === listeners ? drag : value;
  1665. };
  1666. drag.clickDistance = function(_) {
  1667. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1668. };
  1669. return drag;
  1670. }
  1671. function define(constructor, factory, prototype) {
  1672. constructor.prototype = factory.prototype = prototype;
  1673. prototype.constructor = constructor;
  1674. }
  1675. function extend(parent, definition) {
  1676. var prototype = Object.create(parent.prototype);
  1677. for (var key in definition) prototype[key] = definition[key];
  1678. return prototype;
  1679. }
  1680. function Color() {}
  1681. var darker = 0.7;
  1682. var brighter = 1 / darker;
  1683. var reI = "\\s*([+-]?\\d+)\\s*",
  1684. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  1685. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  1686. reHex = /^#([0-9a-f]{3,8})$/,
  1687. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  1688. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  1689. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  1690. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  1691. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  1692. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1693. var named = {
  1694. aliceblue: 0xf0f8ff,
  1695. antiquewhite: 0xfaebd7,
  1696. aqua: 0x00ffff,
  1697. aquamarine: 0x7fffd4,
  1698. azure: 0xf0ffff,
  1699. beige: 0xf5f5dc,
  1700. bisque: 0xffe4c4,
  1701. black: 0x000000,
  1702. blanchedalmond: 0xffebcd,
  1703. blue: 0x0000ff,
  1704. blueviolet: 0x8a2be2,
  1705. brown: 0xa52a2a,
  1706. burlywood: 0xdeb887,
  1707. cadetblue: 0x5f9ea0,
  1708. chartreuse: 0x7fff00,
  1709. chocolate: 0xd2691e,
  1710. coral: 0xff7f50,
  1711. cornflowerblue: 0x6495ed,
  1712. cornsilk: 0xfff8dc,
  1713. crimson: 0xdc143c,
  1714. cyan: 0x00ffff,
  1715. darkblue: 0x00008b,
  1716. darkcyan: 0x008b8b,
  1717. darkgoldenrod: 0xb8860b,
  1718. darkgray: 0xa9a9a9,
  1719. darkgreen: 0x006400,
  1720. darkgrey: 0xa9a9a9,
  1721. darkkhaki: 0xbdb76b,
  1722. darkmagenta: 0x8b008b,
  1723. darkolivegreen: 0x556b2f,
  1724. darkorange: 0xff8c00,
  1725. darkorchid: 0x9932cc,
  1726. darkred: 0x8b0000,
  1727. darksalmon: 0xe9967a,
  1728. darkseagreen: 0x8fbc8f,
  1729. darkslateblue: 0x483d8b,
  1730. darkslategray: 0x2f4f4f,
  1731. darkslategrey: 0x2f4f4f,
  1732. darkturquoise: 0x00ced1,
  1733. darkviolet: 0x9400d3,
  1734. deeppink: 0xff1493,
  1735. deepskyblue: 0x00bfff,
  1736. dimgray: 0x696969,
  1737. dimgrey: 0x696969,
  1738. dodgerblue: 0x1e90ff,
  1739. firebrick: 0xb22222,
  1740. floralwhite: 0xfffaf0,
  1741. forestgreen: 0x228b22,
  1742. fuchsia: 0xff00ff,
  1743. gainsboro: 0xdcdcdc,
  1744. ghostwhite: 0xf8f8ff,
  1745. gold: 0xffd700,
  1746. goldenrod: 0xdaa520,
  1747. gray: 0x808080,
  1748. green: 0x008000,
  1749. greenyellow: 0xadff2f,
  1750. grey: 0x808080,
  1751. honeydew: 0xf0fff0,
  1752. hotpink: 0xff69b4,
  1753. indianred: 0xcd5c5c,
  1754. indigo: 0x4b0082,
  1755. ivory: 0xfffff0,
  1756. khaki: 0xf0e68c,
  1757. lavender: 0xe6e6fa,
  1758. lavenderblush: 0xfff0f5,
  1759. lawngreen: 0x7cfc00,
  1760. lemonchiffon: 0xfffacd,
  1761. lightblue: 0xadd8e6,
  1762. lightcoral: 0xf08080,
  1763. lightcyan: 0xe0ffff,
  1764. lightgoldenrodyellow: 0xfafad2,
  1765. lightgray: 0xd3d3d3,
  1766. lightgreen: 0x90ee90,
  1767. lightgrey: 0xd3d3d3,
  1768. lightpink: 0xffb6c1,
  1769. lightsalmon: 0xffa07a,
  1770. lightseagreen: 0x20b2aa,
  1771. lightskyblue: 0x87cefa,
  1772. lightslategray: 0x778899,
  1773. lightslategrey: 0x778899,
  1774. lightsteelblue: 0xb0c4de,
  1775. lightyellow: 0xffffe0,
  1776. lime: 0x00ff00,
  1777. limegreen: 0x32cd32,
  1778. linen: 0xfaf0e6,
  1779. magenta: 0xff00ff,
  1780. maroon: 0x800000,
  1781. mediumaquamarine: 0x66cdaa,
  1782. mediumblue: 0x0000cd,
  1783. mediumorchid: 0xba55d3,
  1784. mediumpurple: 0x9370db,
  1785. mediumseagreen: 0x3cb371,
  1786. mediumslateblue: 0x7b68ee,
  1787. mediumspringgreen: 0x00fa9a,
  1788. mediumturquoise: 0x48d1cc,
  1789. mediumvioletred: 0xc71585,
  1790. midnightblue: 0x191970,
  1791. mintcream: 0xf5fffa,
  1792. mistyrose: 0xffe4e1,
  1793. moccasin: 0xffe4b5,
  1794. navajowhite: 0xffdead,
  1795. navy: 0x000080,
  1796. oldlace: 0xfdf5e6,
  1797. olive: 0x808000,
  1798. olivedrab: 0x6b8e23,
  1799. orange: 0xffa500,
  1800. orangered: 0xff4500,
  1801. orchid: 0xda70d6,
  1802. palegoldenrod: 0xeee8aa,
  1803. palegreen: 0x98fb98,
  1804. paleturquoise: 0xafeeee,
  1805. palevioletred: 0xdb7093,
  1806. papayawhip: 0xffefd5,
  1807. peachpuff: 0xffdab9,
  1808. peru: 0xcd853f,
  1809. pink: 0xffc0cb,
  1810. plum: 0xdda0dd,
  1811. powderblue: 0xb0e0e6,
  1812. purple: 0x800080,
  1813. rebeccapurple: 0x663399,
  1814. red: 0xff0000,
  1815. rosybrown: 0xbc8f8f,
  1816. royalblue: 0x4169e1,
  1817. saddlebrown: 0x8b4513,
  1818. salmon: 0xfa8072,
  1819. sandybrown: 0xf4a460,
  1820. seagreen: 0x2e8b57,
  1821. seashell: 0xfff5ee,
  1822. sienna: 0xa0522d,
  1823. silver: 0xc0c0c0,
  1824. skyblue: 0x87ceeb,
  1825. slateblue: 0x6a5acd,
  1826. slategray: 0x708090,
  1827. slategrey: 0x708090,
  1828. snow: 0xfffafa,
  1829. springgreen: 0x00ff7f,
  1830. steelblue: 0x4682b4,
  1831. tan: 0xd2b48c,
  1832. teal: 0x008080,
  1833. thistle: 0xd8bfd8,
  1834. tomato: 0xff6347,
  1835. turquoise: 0x40e0d0,
  1836. violet: 0xee82ee,
  1837. wheat: 0xf5deb3,
  1838. white: 0xffffff,
  1839. whitesmoke: 0xf5f5f5,
  1840. yellow: 0xffff00,
  1841. yellowgreen: 0x9acd32
  1842. };
  1843. define(Color, color, {
  1844. copy: function(channels) {
  1845. return Object.assign(new this.constructor, this, channels);
  1846. },
  1847. displayable: function() {
  1848. return this.rgb().displayable();
  1849. },
  1850. hex: color_formatHex, // Deprecated! Use color.formatHex.
  1851. formatHex: color_formatHex,
  1852. formatHsl: color_formatHsl,
  1853. formatRgb: color_formatRgb,
  1854. toString: color_formatRgb
  1855. });
  1856. function color_formatHex() {
  1857. return this.rgb().formatHex();
  1858. }
  1859. function color_formatHsl() {
  1860. return hslConvert(this).formatHsl();
  1861. }
  1862. function color_formatRgb() {
  1863. return this.rgb().formatRgb();
  1864. }
  1865. function color(format) {
  1866. var m, l;
  1867. format = (format + "").trim().toLowerCase();
  1868. return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
  1869. : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
  1870. : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
  1871. : 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
  1872. : null) // invalid hex
  1873. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1874. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1875. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1876. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1877. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1878. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1879. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  1880. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1881. : null;
  1882. }
  1883. function rgbn(n) {
  1884. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1885. }
  1886. function rgba(r, g, b, a) {
  1887. if (a <= 0) r = g = b = NaN;
  1888. return new Rgb(r, g, b, a);
  1889. }
  1890. function rgbConvert(o) {
  1891. if (!(o instanceof Color)) o = color(o);
  1892. if (!o) return new Rgb;
  1893. o = o.rgb();
  1894. return new Rgb(o.r, o.g, o.b, o.opacity);
  1895. }
  1896. function rgb(r, g, b, opacity) {
  1897. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1898. }
  1899. function Rgb(r, g, b, opacity) {
  1900. this.r = +r;
  1901. this.g = +g;
  1902. this.b = +b;
  1903. this.opacity = +opacity;
  1904. }
  1905. define(Rgb, rgb, extend(Color, {
  1906. brighter: function(k) {
  1907. k = k == null ? brighter : Math.pow(brighter, k);
  1908. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1909. },
  1910. darker: function(k) {
  1911. k = k == null ? darker : Math.pow(darker, k);
  1912. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1913. },
  1914. rgb: function() {
  1915. return this;
  1916. },
  1917. displayable: function() {
  1918. return (-0.5 <= this.r && this.r < 255.5)
  1919. && (-0.5 <= this.g && this.g < 255.5)
  1920. && (-0.5 <= this.b && this.b < 255.5)
  1921. && (0 <= this.opacity && this.opacity <= 1);
  1922. },
  1923. hex: rgb_formatHex, // Deprecated! Use color.formatHex.
  1924. formatHex: rgb_formatHex,
  1925. formatRgb: rgb_formatRgb,
  1926. toString: rgb_formatRgb
  1927. }));
  1928. function rgb_formatHex() {
  1929. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  1930. }
  1931. function rgb_formatRgb() {
  1932. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1933. return (a === 1 ? "rgb(" : "rgba(")
  1934. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1935. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1936. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1937. + (a === 1 ? ")" : ", " + a + ")");
  1938. }
  1939. function hex(value) {
  1940. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  1941. return (value < 16 ? "0" : "") + value.toString(16);
  1942. }
  1943. function hsla(h, s, l, a) {
  1944. if (a <= 0) h = s = l = NaN;
  1945. else if (l <= 0 || l >= 1) h = s = NaN;
  1946. else if (s <= 0) h = NaN;
  1947. return new Hsl(h, s, l, a);
  1948. }
  1949. function hslConvert(o) {
  1950. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1951. if (!(o instanceof Color)) o = color(o);
  1952. if (!o) return new Hsl;
  1953. if (o instanceof Hsl) return o;
  1954. o = o.rgb();
  1955. var r = o.r / 255,
  1956. g = o.g / 255,
  1957. b = o.b / 255,
  1958. min = Math.min(r, g, b),
  1959. max = Math.max(r, g, b),
  1960. h = NaN,
  1961. s = max - min,
  1962. l = (max + min) / 2;
  1963. if (s) {
  1964. if (r === max) h = (g - b) / s + (g < b) * 6;
  1965. else if (g === max) h = (b - r) / s + 2;
  1966. else h = (r - g) / s + 4;
  1967. s /= l < 0.5 ? max + min : 2 - max - min;
  1968. h *= 60;
  1969. } else {
  1970. s = l > 0 && l < 1 ? 0 : h;
  1971. }
  1972. return new Hsl(h, s, l, o.opacity);
  1973. }
  1974. function hsl(h, s, l, opacity) {
  1975. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1976. }
  1977. function Hsl(h, s, l, opacity) {
  1978. this.h = +h;
  1979. this.s = +s;
  1980. this.l = +l;
  1981. this.opacity = +opacity;
  1982. }
  1983. define(Hsl, hsl, extend(Color, {
  1984. brighter: function(k) {
  1985. k = k == null ? brighter : Math.pow(brighter, k);
  1986. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1987. },
  1988. darker: function(k) {
  1989. k = k == null ? darker : Math.pow(darker, k);
  1990. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1991. },
  1992. rgb: function() {
  1993. var h = this.h % 360 + (this.h < 0) * 360,
  1994. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1995. l = this.l,
  1996. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1997. m1 = 2 * l - m2;
  1998. return new Rgb(
  1999. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  2000. hsl2rgb(h, m1, m2),
  2001. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  2002. this.opacity
  2003. );
  2004. },
  2005. displayable: function() {
  2006. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  2007. && (0 <= this.l && this.l <= 1)
  2008. && (0 <= this.opacity && this.opacity <= 1);
  2009. },
  2010. formatHsl: function() {
  2011. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  2012. return (a === 1 ? "hsl(" : "hsla(")
  2013. + (this.h || 0) + ", "
  2014. + (this.s || 0) * 100 + "%, "
  2015. + (this.l || 0) * 100 + "%"
  2016. + (a === 1 ? ")" : ", " + a + ")");
  2017. }
  2018. }));
  2019. /* From FvD 13.37, CSS Color Module Level 3 */
  2020. function hsl2rgb(h, m1, m2) {
  2021. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2022. : h < 180 ? m2
  2023. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2024. : m1) * 255;
  2025. }
  2026. var deg2rad = Math.PI / 180;
  2027. var rad2deg = 180 / Math.PI;
  2028. // https://observablehq.com/@mbostock/lab-and-rgb
  2029. var K = 18,
  2030. Xn = 0.96422,
  2031. Yn = 1,
  2032. Zn = 0.82521,
  2033. t0 = 4 / 29,
  2034. t1 = 6 / 29,
  2035. t2 = 3 * t1 * t1,
  2036. t3 = t1 * t1 * t1;
  2037. function labConvert(o) {
  2038. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2039. if (o instanceof Hcl) return hcl2lab(o);
  2040. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2041. var r = rgb2lrgb(o.r),
  2042. g = rgb2lrgb(o.g),
  2043. b = rgb2lrgb(o.b),
  2044. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2045. if (r === g && g === b) x = z = y; else {
  2046. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2047. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2048. }
  2049. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2050. }
  2051. function gray(l, opacity) {
  2052. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2053. }
  2054. function lab(l, a, b, opacity) {
  2055. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2056. }
  2057. function Lab(l, a, b, opacity) {
  2058. this.l = +l;
  2059. this.a = +a;
  2060. this.b = +b;
  2061. this.opacity = +opacity;
  2062. }
  2063. define(Lab, lab, extend(Color, {
  2064. brighter: function(k) {
  2065. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2066. },
  2067. darker: function(k) {
  2068. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2069. },
  2070. rgb: function() {
  2071. var y = (this.l + 16) / 116,
  2072. x = isNaN(this.a) ? y : y + this.a / 500,
  2073. z = isNaN(this.b) ? y : y - this.b / 200;
  2074. x = Xn * lab2xyz(x);
  2075. y = Yn * lab2xyz(y);
  2076. z = Zn * lab2xyz(z);
  2077. return new Rgb(
  2078. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2079. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2080. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2081. this.opacity
  2082. );
  2083. }
  2084. }));
  2085. function xyz2lab(t) {
  2086. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2087. }
  2088. function lab2xyz(t) {
  2089. return t > t1 ? t * t * t : t2 * (t - t0);
  2090. }
  2091. function lrgb2rgb(x) {
  2092. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2093. }
  2094. function rgb2lrgb(x) {
  2095. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2096. }
  2097. function hclConvert(o) {
  2098. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2099. if (!(o instanceof Lab)) o = labConvert(o);
  2100. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
  2101. var h = Math.atan2(o.b, o.a) * rad2deg;
  2102. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2103. }
  2104. function lch(l, c, h, opacity) {
  2105. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2106. }
  2107. function hcl(h, c, l, opacity) {
  2108. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2109. }
  2110. function Hcl(h, c, l, opacity) {
  2111. this.h = +h;
  2112. this.c = +c;
  2113. this.l = +l;
  2114. this.opacity = +opacity;
  2115. }
  2116. function hcl2lab(o) {
  2117. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2118. var h = o.h * deg2rad;
  2119. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2120. }
  2121. define(Hcl, hcl, extend(Color, {
  2122. brighter: function(k) {
  2123. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2124. },
  2125. darker: function(k) {
  2126. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2127. },
  2128. rgb: function() {
  2129. return hcl2lab(this).rgb();
  2130. }
  2131. }));
  2132. var A = -0.14861,
  2133. B = +1.78277,
  2134. C = -0.29227,
  2135. D = -0.90649,
  2136. E = +1.97294,
  2137. ED = E * D,
  2138. EB = E * B,
  2139. BC_DA = B * C - D * A;
  2140. function cubehelixConvert(o) {
  2141. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2142. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2143. var r = o.r / 255,
  2144. g = o.g / 255,
  2145. b = o.b / 255,
  2146. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2147. bl = b - l,
  2148. k = (E * (g - l) - C * bl) / D,
  2149. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2150. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2151. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2152. }
  2153. function cubehelix(h, s, l, opacity) {
  2154. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2155. }
  2156. function Cubehelix(h, s, l, opacity) {
  2157. this.h = +h;
  2158. this.s = +s;
  2159. this.l = +l;
  2160. this.opacity = +opacity;
  2161. }
  2162. define(Cubehelix, cubehelix, extend(Color, {
  2163. brighter: function(k) {
  2164. k = k == null ? brighter : Math.pow(brighter, k);
  2165. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2166. },
  2167. darker: function(k) {
  2168. k = k == null ? darker : Math.pow(darker, k);
  2169. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2170. },
  2171. rgb: function() {
  2172. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2173. l = +this.l,
  2174. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2175. cosh = Math.cos(h),
  2176. sinh = Math.sin(h);
  2177. return new Rgb(
  2178. 255 * (l + a * (A * cosh + B * sinh)),
  2179. 255 * (l + a * (C * cosh + D * sinh)),
  2180. 255 * (l + a * (E * cosh)),
  2181. this.opacity
  2182. );
  2183. }
  2184. }));
  2185. function basis(t1, v0, v1, v2, v3) {
  2186. var t2 = t1 * t1, t3 = t2 * t1;
  2187. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2188. + (4 - 6 * t2 + 3 * t3) * v1
  2189. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2190. + t3 * v3) / 6;
  2191. }
  2192. function basis$1(values) {
  2193. var n = values.length - 1;
  2194. return function(t) {
  2195. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2196. v1 = values[i],
  2197. v2 = values[i + 1],
  2198. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2199. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2200. return basis((t - i / n) * n, v0, v1, v2, v3);
  2201. };
  2202. }
  2203. function basisClosed(values) {
  2204. var n = values.length;
  2205. return function(t) {
  2206. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2207. v0 = values[(i + n - 1) % n],
  2208. v1 = values[i % n],
  2209. v2 = values[(i + 1) % n],
  2210. v3 = values[(i + 2) % n];
  2211. return basis((t - i / n) * n, v0, v1, v2, v3);
  2212. };
  2213. }
  2214. function constant$3(x) {
  2215. return function() {
  2216. return x;
  2217. };
  2218. }
  2219. function linear(a, d) {
  2220. return function(t) {
  2221. return a + t * d;
  2222. };
  2223. }
  2224. function exponential(a, b, y) {
  2225. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2226. return Math.pow(a + t * b, y);
  2227. };
  2228. }
  2229. function hue(a, b) {
  2230. var d = b - a;
  2231. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2232. }
  2233. function gamma(y) {
  2234. return (y = +y) === 1 ? nogamma : function(a, b) {
  2235. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2236. };
  2237. }
  2238. function nogamma(a, b) {
  2239. var d = b - a;
  2240. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2241. }
  2242. var interpolateRgb = (function rgbGamma(y) {
  2243. var color = gamma(y);
  2244. function rgb$1(start, end) {
  2245. var r = color((start = rgb(start)).r, (end = rgb(end)).r),
  2246. g = color(start.g, end.g),
  2247. b = color(start.b, end.b),
  2248. opacity = nogamma(start.opacity, end.opacity);
  2249. return function(t) {
  2250. start.r = r(t);
  2251. start.g = g(t);
  2252. start.b = b(t);
  2253. start.opacity = opacity(t);
  2254. return start + "";
  2255. };
  2256. }
  2257. rgb$1.gamma = rgbGamma;
  2258. return rgb$1;
  2259. })(1);
  2260. function rgbSpline(spline) {
  2261. return function(colors) {
  2262. var n = colors.length,
  2263. r = new Array(n),
  2264. g = new Array(n),
  2265. b = new Array(n),
  2266. i, color;
  2267. for (i = 0; i < n; ++i) {
  2268. color = rgb(colors[i]);
  2269. r[i] = color.r || 0;
  2270. g[i] = color.g || 0;
  2271. b[i] = color.b || 0;
  2272. }
  2273. r = spline(r);
  2274. g = spline(g);
  2275. b = spline(b);
  2276. color.opacity = 1;
  2277. return function(t) {
  2278. color.r = r(t);
  2279. color.g = g(t);
  2280. color.b = b(t);
  2281. return color + "";
  2282. };
  2283. };
  2284. }
  2285. var rgbBasis = rgbSpline(basis$1);
  2286. var rgbBasisClosed = rgbSpline(basisClosed);
  2287. function numberArray(a, b) {
  2288. if (!b) b = [];
  2289. var n = a ? Math.min(b.length, a.length) : 0,
  2290. c = b.slice(),
  2291. i;
  2292. return function(t) {
  2293. for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
  2294. return c;
  2295. };
  2296. }
  2297. function isNumberArray(x) {
  2298. return ArrayBuffer.isView(x) && !(x instanceof DataView);
  2299. }
  2300. function array$1(a, b) {
  2301. return (isNumberArray(b) ? numberArray : genericArray)(a, b);
  2302. }
  2303. function genericArray(a, b) {
  2304. var nb = b ? b.length : 0,
  2305. na = a ? Math.min(nb, a.length) : 0,
  2306. x = new Array(na),
  2307. c = new Array(nb),
  2308. i;
  2309. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2310. for (; i < nb; ++i) c[i] = b[i];
  2311. return function(t) {
  2312. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2313. return c;
  2314. };
  2315. }
  2316. function date(a, b) {
  2317. var d = new Date;
  2318. return a = +a, b = +b, function(t) {
  2319. return d.setTime(a * (1 - t) + b * t), d;
  2320. };
  2321. }
  2322. function interpolateNumber(a, b) {
  2323. return a = +a, b = +b, function(t) {
  2324. return a * (1 - t) + b * t;
  2325. };
  2326. }
  2327. function object(a, b) {
  2328. var i = {},
  2329. c = {},
  2330. k;
  2331. if (a === null || typeof a !== "object") a = {};
  2332. if (b === null || typeof b !== "object") b = {};
  2333. for (k in b) {
  2334. if (k in a) {
  2335. i[k] = interpolateValue(a[k], b[k]);
  2336. } else {
  2337. c[k] = b[k];
  2338. }
  2339. }
  2340. return function(t) {
  2341. for (k in i) c[k] = i[k](t);
  2342. return c;
  2343. };
  2344. }
  2345. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  2346. reB = new RegExp(reA.source, "g");
  2347. function zero(b) {
  2348. return function() {
  2349. return b;
  2350. };
  2351. }
  2352. function one(b) {
  2353. return function(t) {
  2354. return b(t) + "";
  2355. };
  2356. }
  2357. function interpolateString(a, b) {
  2358. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2359. am, // current match in a
  2360. bm, // current match in b
  2361. bs, // string preceding current number in b, if any
  2362. i = -1, // index in s
  2363. s = [], // string constants and placeholders
  2364. q = []; // number interpolators
  2365. // Coerce inputs to strings.
  2366. a = a + "", b = b + "";
  2367. // Interpolate pairs of numbers in a & b.
  2368. while ((am = reA.exec(a))
  2369. && (bm = reB.exec(b))) {
  2370. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2371. bs = b.slice(bi, bs);
  2372. if (s[i]) s[i] += bs; // coalesce with previous string
  2373. else s[++i] = bs;
  2374. }
  2375. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2376. if (s[i]) s[i] += bm; // coalesce with previous string
  2377. else s[++i] = bm;
  2378. } else { // interpolate non-matching numbers
  2379. s[++i] = null;
  2380. q.push({i: i, x: interpolateNumber(am, bm)});
  2381. }
  2382. bi = reB.lastIndex;
  2383. }
  2384. // Add remains of b.
  2385. if (bi < b.length) {
  2386. bs = b.slice(bi);
  2387. if (s[i]) s[i] += bs; // coalesce with previous string
  2388. else s[++i] = bs;
  2389. }
  2390. // Special optimization for only a single match.
  2391. // Otherwise, interpolate each of the numbers and rejoin the string.
  2392. return s.length < 2 ? (q[0]
  2393. ? one(q[0].x)
  2394. : zero(b))
  2395. : (b = q.length, function(t) {
  2396. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2397. return s.join("");
  2398. });
  2399. }
  2400. function interpolateValue(a, b) {
  2401. var t = typeof b, c;
  2402. return b == null || t === "boolean" ? constant$3(b)
  2403. : (t === "number" ? interpolateNumber
  2404. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2405. : b instanceof color ? interpolateRgb
  2406. : b instanceof Date ? date
  2407. : isNumberArray(b) ? numberArray
  2408. : Array.isArray(b) ? genericArray
  2409. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2410. : interpolateNumber)(a, b);
  2411. }
  2412. function discrete(range) {
  2413. var n = range.length;
  2414. return function(t) {
  2415. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  2416. };
  2417. }
  2418. function hue$1(a, b) {
  2419. var i = hue(+a, +b);
  2420. return function(t) {
  2421. var x = i(t);
  2422. return x - 360 * Math.floor(x / 360);
  2423. };
  2424. }
  2425. function interpolateRound(a, b) {
  2426. return a = +a, b = +b, function(t) {
  2427. return Math.round(a * (1 - t) + b * t);
  2428. };
  2429. }
  2430. var degrees = 180 / Math.PI;
  2431. var identity$2 = {
  2432. translateX: 0,
  2433. translateY: 0,
  2434. rotate: 0,
  2435. skewX: 0,
  2436. scaleX: 1,
  2437. scaleY: 1
  2438. };
  2439. function decompose(a, b, c, d, e, f) {
  2440. var scaleX, scaleY, skewX;
  2441. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2442. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2443. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2444. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2445. return {
  2446. translateX: e,
  2447. translateY: f,
  2448. rotate: Math.atan2(b, a) * degrees,
  2449. skewX: Math.atan(skewX) * degrees,
  2450. scaleX: scaleX,
  2451. scaleY: scaleY
  2452. };
  2453. }
  2454. var cssNode,
  2455. cssRoot,
  2456. cssView,
  2457. svgNode;
  2458. function parseCss(value) {
  2459. if (value === "none") return identity$2;
  2460. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2461. cssNode.style.transform = value;
  2462. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2463. cssRoot.removeChild(cssNode);
  2464. value = value.slice(7, -1).split(",");
  2465. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2466. }
  2467. function parseSvg(value) {
  2468. if (value == null) return identity$2;
  2469. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2470. svgNode.setAttribute("transform", value);
  2471. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2472. value = value.matrix;
  2473. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2474. }
  2475. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2476. function pop(s) {
  2477. return s.length ? s.pop() + " " : "";
  2478. }
  2479. function translate(xa, ya, xb, yb, s, q) {
  2480. if (xa !== xb || ya !== yb) {
  2481. var i = s.push("translate(", null, pxComma, null, pxParen);
  2482. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2483. } else if (xb || yb) {
  2484. s.push("translate(" + xb + pxComma + yb + pxParen);
  2485. }
  2486. }
  2487. function rotate(a, b, s, q) {
  2488. if (a !== b) {
  2489. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2490. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2491. } else if (b) {
  2492. s.push(pop(s) + "rotate(" + b + degParen);
  2493. }
  2494. }
  2495. function skewX(a, b, s, q) {
  2496. if (a !== b) {
  2497. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2498. } else if (b) {
  2499. s.push(pop(s) + "skewX(" + b + degParen);
  2500. }
  2501. }
  2502. function scale(xa, ya, xb, yb, s, q) {
  2503. if (xa !== xb || ya !== yb) {
  2504. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2505. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2506. } else if (xb !== 1 || yb !== 1) {
  2507. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2508. }
  2509. }
  2510. return function(a, b) {
  2511. var s = [], // string constants and placeholders
  2512. q = []; // number interpolators
  2513. a = parse(a), b = parse(b);
  2514. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2515. rotate(a.rotate, b.rotate, s, q);
  2516. skewX(a.skewX, b.skewX, s, q);
  2517. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2518. a = b = null; // gc
  2519. return function(t) {
  2520. var i = -1, n = q.length, o;
  2521. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2522. return s.join("");
  2523. };
  2524. };
  2525. }
  2526. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2527. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2528. var rho = Math.SQRT2,
  2529. rho2 = 2,
  2530. rho4 = 4,
  2531. epsilon2 = 1e-12;
  2532. function cosh(x) {
  2533. return ((x = Math.exp(x)) + 1 / x) / 2;
  2534. }
  2535. function sinh(x) {
  2536. return ((x = Math.exp(x)) - 1 / x) / 2;
  2537. }
  2538. function tanh(x) {
  2539. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2540. }
  2541. // p0 = [ux0, uy0, w0]
  2542. // p1 = [ux1, uy1, w1]
  2543. function interpolateZoom(p0, p1) {
  2544. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2545. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2546. dx = ux1 - ux0,
  2547. dy = uy1 - uy0,
  2548. d2 = dx * dx + dy * dy,
  2549. i,
  2550. S;
  2551. // Special case for u0 ≅ u1.
  2552. if (d2 < epsilon2) {
  2553. S = Math.log(w1 / w0) / rho;
  2554. i = function(t) {
  2555. return [
  2556. ux0 + t * dx,
  2557. uy0 + t * dy,
  2558. w0 * Math.exp(rho * t * S)
  2559. ];
  2560. };
  2561. }
  2562. // General case.
  2563. else {
  2564. var d1 = Math.sqrt(d2),
  2565. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2566. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2567. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2568. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2569. S = (r1 - r0) / rho;
  2570. i = function(t) {
  2571. var s = t * S,
  2572. coshr0 = cosh(r0),
  2573. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2574. return [
  2575. ux0 + u * dx,
  2576. uy0 + u * dy,
  2577. w0 * coshr0 / cosh(rho * s + r0)
  2578. ];
  2579. };
  2580. }
  2581. i.duration = S * 1000;
  2582. return i;
  2583. }
  2584. function hsl$1(hue) {
  2585. return function(start, end) {
  2586. var h = hue((start = hsl(start)).h, (end = hsl(end)).h),
  2587. s = nogamma(start.s, end.s),
  2588. l = nogamma(start.l, end.l),
  2589. opacity = nogamma(start.opacity, end.opacity);
  2590. return function(t) {
  2591. start.h = h(t);
  2592. start.s = s(t);
  2593. start.l = l(t);
  2594. start.opacity = opacity(t);
  2595. return start + "";
  2596. };
  2597. }
  2598. }
  2599. var hsl$2 = hsl$1(hue);
  2600. var hslLong = hsl$1(nogamma);
  2601. function lab$1(start, end) {
  2602. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2603. a = nogamma(start.a, end.a),
  2604. b = nogamma(start.b, end.b),
  2605. opacity = nogamma(start.opacity, end.opacity);
  2606. return function(t) {
  2607. start.l = l(t);
  2608. start.a = a(t);
  2609. start.b = b(t);
  2610. start.opacity = opacity(t);
  2611. return start + "";
  2612. };
  2613. }
  2614. function hcl$1(hue) {
  2615. return function(start, end) {
  2616. var h = hue((start = hcl(start)).h, (end = hcl(end)).h),
  2617. c = nogamma(start.c, end.c),
  2618. l = nogamma(start.l, end.l),
  2619. opacity = nogamma(start.opacity, end.opacity);
  2620. return function(t) {
  2621. start.h = h(t);
  2622. start.c = c(t);
  2623. start.l = l(t);
  2624. start.opacity = opacity(t);
  2625. return start + "";
  2626. };
  2627. }
  2628. }
  2629. var hcl$2 = hcl$1(hue);
  2630. var hclLong = hcl$1(nogamma);
  2631. function cubehelix$1(hue) {
  2632. return (function cubehelixGamma(y) {
  2633. y = +y;
  2634. function cubehelix$1(start, end) {
  2635. var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2636. s = nogamma(start.s, end.s),
  2637. l = nogamma(start.l, end.l),
  2638. opacity = nogamma(start.opacity, end.opacity);
  2639. return function(t) {
  2640. start.h = h(t);
  2641. start.s = s(t);
  2642. start.l = l(Math.pow(t, y));
  2643. start.opacity = opacity(t);
  2644. return start + "";
  2645. };
  2646. }
  2647. cubehelix$1.gamma = cubehelixGamma;
  2648. return cubehelix$1;
  2649. })(1);
  2650. }
  2651. var cubehelix$2 = cubehelix$1(hue);
  2652. var cubehelixLong = cubehelix$1(nogamma);
  2653. function piecewise(interpolate, values) {
  2654. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  2655. while (i < n) I[i] = interpolate(v, v = values[++i]);
  2656. return function(t) {
  2657. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  2658. return I[i](t - i);
  2659. };
  2660. }
  2661. function quantize(interpolator, n) {
  2662. var samples = new Array(n);
  2663. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2664. return samples;
  2665. }
  2666. var frame = 0, // is an animation frame pending?
  2667. timeout = 0, // is a timeout pending?
  2668. interval = 0, // are any timers active?
  2669. pokeDelay = 1000, // how frequently we check for clock skew
  2670. taskHead,
  2671. taskTail,
  2672. clockLast = 0,
  2673. clockNow = 0,
  2674. clockSkew = 0,
  2675. clock = typeof performance === "object" && performance.now ? performance : Date,
  2676. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2677. function now() {
  2678. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2679. }
  2680. function clearNow() {
  2681. clockNow = 0;
  2682. }
  2683. function Timer() {
  2684. this._call =
  2685. this._time =
  2686. this._next = null;
  2687. }
  2688. Timer.prototype = timer.prototype = {
  2689. constructor: Timer,
  2690. restart: function(callback, delay, time) {
  2691. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2692. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2693. if (!this._next && taskTail !== this) {
  2694. if (taskTail) taskTail._next = this;
  2695. else taskHead = this;
  2696. taskTail = this;
  2697. }
  2698. this._call = callback;
  2699. this._time = time;
  2700. sleep();
  2701. },
  2702. stop: function() {
  2703. if (this._call) {
  2704. this._call = null;
  2705. this._time = Infinity;
  2706. sleep();
  2707. }
  2708. }
  2709. };
  2710. function timer(callback, delay, time) {
  2711. var t = new Timer;
  2712. t.restart(callback, delay, time);
  2713. return t;
  2714. }
  2715. function timerFlush() {
  2716. now(); // Get the current time, if not already set.
  2717. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2718. var t = taskHead, e;
  2719. while (t) {
  2720. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2721. t = t._next;
  2722. }
  2723. --frame;
  2724. }
  2725. function wake() {
  2726. clockNow = (clockLast = clock.now()) + clockSkew;
  2727. frame = timeout = 0;
  2728. try {
  2729. timerFlush();
  2730. } finally {
  2731. frame = 0;
  2732. nap();
  2733. clockNow = 0;
  2734. }
  2735. }
  2736. function poke() {
  2737. var now = clock.now(), delay = now - clockLast;
  2738. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2739. }
  2740. function nap() {
  2741. var t0, t1 = taskHead, t2, time = Infinity;
  2742. while (t1) {
  2743. if (t1._call) {
  2744. if (time > t1._time) time = t1._time;
  2745. t0 = t1, t1 = t1._next;
  2746. } else {
  2747. t2 = t1._next, t1._next = null;
  2748. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2749. }
  2750. }
  2751. taskTail = t0;
  2752. sleep(time);
  2753. }
  2754. function sleep(time) {
  2755. if (frame) return; // Soonest alarm already set, or will be.
  2756. if (timeout) timeout = clearTimeout(timeout);
  2757. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2758. if (delay > 24) {
  2759. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2760. if (interval) interval = clearInterval(interval);
  2761. } else {
  2762. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2763. frame = 1, setFrame(wake);
  2764. }
  2765. }
  2766. function timeout$1(callback, delay, time) {
  2767. var t = new Timer;
  2768. delay = delay == null ? 0 : +delay;
  2769. t.restart(function(elapsed) {
  2770. t.stop();
  2771. callback(elapsed + delay);
  2772. }, delay, time);
  2773. return t;
  2774. }
  2775. function interval$1(callback, delay, time) {
  2776. var t = new Timer, total = delay;
  2777. if (delay == null) return t.restart(callback, delay, time), t;
  2778. delay = +delay, time = time == null ? now() : +time;
  2779. t.restart(function tick(elapsed) {
  2780. elapsed += total;
  2781. t.restart(tick, total += delay, time);
  2782. callback(elapsed);
  2783. }, delay, time);
  2784. return t;
  2785. }
  2786. var emptyOn = dispatch("start", "end", "cancel", "interrupt");
  2787. var emptyTween = [];
  2788. var CREATED = 0;
  2789. var SCHEDULED = 1;
  2790. var STARTING = 2;
  2791. var STARTED = 3;
  2792. var RUNNING = 4;
  2793. var ENDING = 5;
  2794. var ENDED = 6;
  2795. function schedule(node, name, id, index, group, timing) {
  2796. var schedules = node.__transition;
  2797. if (!schedules) node.__transition = {};
  2798. else if (id in schedules) return;
  2799. create$1(node, id, {
  2800. name: name,
  2801. index: index, // For context during callback.
  2802. group: group, // For context during callback.
  2803. on: emptyOn,
  2804. tween: emptyTween,
  2805. time: timing.time,
  2806. delay: timing.delay,
  2807. duration: timing.duration,
  2808. ease: timing.ease,
  2809. timer: null,
  2810. state: CREATED
  2811. });
  2812. }
  2813. function init(node, id) {
  2814. var schedule = get$1(node, id);
  2815. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  2816. return schedule;
  2817. }
  2818. function set$1(node, id) {
  2819. var schedule = get$1(node, id);
  2820. if (schedule.state > STARTED) throw new Error("too late; already running");
  2821. return schedule;
  2822. }
  2823. function get$1(node, id) {
  2824. var schedule = node.__transition;
  2825. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  2826. return schedule;
  2827. }
  2828. function create$1(node, id, self) {
  2829. var schedules = node.__transition,
  2830. tween;
  2831. // Initialize the self timer when the transition is created.
  2832. // Note the actual delay is not known until the first callback!
  2833. schedules[id] = self;
  2834. self.timer = timer(schedule, 0, self.time);
  2835. function schedule(elapsed) {
  2836. self.state = SCHEDULED;
  2837. self.timer.restart(start, self.delay, self.time);
  2838. // If the elapsed delay is less than our first sleep, start immediately.
  2839. if (self.delay <= elapsed) start(elapsed - self.delay);
  2840. }
  2841. function start(elapsed) {
  2842. var i, j, n, o;
  2843. // If the state is not SCHEDULED, then we previously errored on start.
  2844. if (self.state !== SCHEDULED) return stop();
  2845. for (i in schedules) {
  2846. o = schedules[i];
  2847. if (o.name !== self.name) continue;
  2848. // While this element already has a starting transition during this frame,
  2849. // defer starting an interrupting transition until that transition has a
  2850. // chance to tick (and possibly end); see d3/d3-transition#54!
  2851. if (o.state === STARTED) return timeout$1(start);
  2852. // Interrupt the active transition, if any.
  2853. if (o.state === RUNNING) {
  2854. o.state = ENDED;
  2855. o.timer.stop();
  2856. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2857. delete schedules[i];
  2858. }
  2859. // Cancel any pre-empted transitions.
  2860. else if (+i < id) {
  2861. o.state = ENDED;
  2862. o.timer.stop();
  2863. o.on.call("cancel", node, node.__data__, o.index, o.group);
  2864. delete schedules[i];
  2865. }
  2866. }
  2867. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2868. // Note the transition may be canceled after start and before the first tick!
  2869. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2870. // Assuming this is successful, subsequent callbacks go straight to tick.
  2871. timeout$1(function() {
  2872. if (self.state === STARTED) {
  2873. self.state = RUNNING;
  2874. self.timer.restart(tick, self.delay, self.time);
  2875. tick(elapsed);
  2876. }
  2877. });
  2878. // Dispatch the start event.
  2879. // Note this must be done before the tween are initialized.
  2880. self.state = STARTING;
  2881. self.on.call("start", node, node.__data__, self.index, self.group);
  2882. if (self.state !== STARTING) return; // interrupted
  2883. self.state = STARTED;
  2884. // Initialize the tween, deleting null tween.
  2885. tween = new Array(n = self.tween.length);
  2886. for (i = 0, j = -1; i < n; ++i) {
  2887. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2888. tween[++j] = o;
  2889. }
  2890. }
  2891. tween.length = j + 1;
  2892. }
  2893. function tick(elapsed) {
  2894. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2895. i = -1,
  2896. n = tween.length;
  2897. while (++i < n) {
  2898. tween[i].call(node, t);
  2899. }
  2900. // Dispatch the end event.
  2901. if (self.state === ENDING) {
  2902. self.on.call("end", node, node.__data__, self.index, self.group);
  2903. stop();
  2904. }
  2905. }
  2906. function stop() {
  2907. self.state = ENDED;
  2908. self.timer.stop();
  2909. delete schedules[id];
  2910. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2911. delete node.__transition;
  2912. }
  2913. }
  2914. function interrupt(node, name) {
  2915. var schedules = node.__transition,
  2916. schedule,
  2917. active,
  2918. empty = true,
  2919. i;
  2920. if (!schedules) return;
  2921. name = name == null ? null : name + "";
  2922. for (i in schedules) {
  2923. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  2924. active = schedule.state > STARTING && schedule.state < ENDING;
  2925. schedule.state = ENDED;
  2926. schedule.timer.stop();
  2927. schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
  2928. delete schedules[i];
  2929. }
  2930. if (empty) delete node.__transition;
  2931. }
  2932. function selection_interrupt(name) {
  2933. return this.each(function() {
  2934. interrupt(this, name);
  2935. });
  2936. }
  2937. function tweenRemove(id, name) {
  2938. var tween0, tween1;
  2939. return function() {
  2940. var schedule = set$1(this, id),
  2941. tween = schedule.tween;
  2942. // If this node shared tween with the previous node,
  2943. // just assign the updated shared tween and we’re done!
  2944. // Otherwise, copy-on-write.
  2945. if (tween !== tween0) {
  2946. tween1 = tween0 = tween;
  2947. for (var i = 0, n = tween1.length; i < n; ++i) {
  2948. if (tween1[i].name === name) {
  2949. tween1 = tween1.slice();
  2950. tween1.splice(i, 1);
  2951. break;
  2952. }
  2953. }
  2954. }
  2955. schedule.tween = tween1;
  2956. };
  2957. }
  2958. function tweenFunction(id, name, value) {
  2959. var tween0, tween1;
  2960. if (typeof value !== "function") throw new Error;
  2961. return function() {
  2962. var schedule = set$1(this, id),
  2963. tween = schedule.tween;
  2964. // If this node shared tween with the previous node,
  2965. // just assign the updated shared tween and we’re done!
  2966. // Otherwise, copy-on-write.
  2967. if (tween !== tween0) {
  2968. tween1 = (tween0 = tween).slice();
  2969. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2970. if (tween1[i].name === name) {
  2971. tween1[i] = t;
  2972. break;
  2973. }
  2974. }
  2975. if (i === n) tween1.push(t);
  2976. }
  2977. schedule.tween = tween1;
  2978. };
  2979. }
  2980. function transition_tween(name, value) {
  2981. var id = this._id;
  2982. name += "";
  2983. if (arguments.length < 2) {
  2984. var tween = get$1(this.node(), id).tween;
  2985. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2986. if ((t = tween[i]).name === name) {
  2987. return t.value;
  2988. }
  2989. }
  2990. return null;
  2991. }
  2992. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2993. }
  2994. function tweenValue(transition, name, value) {
  2995. var id = transition._id;
  2996. transition.each(function() {
  2997. var schedule = set$1(this, id);
  2998. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  2999. });
  3000. return function(node) {
  3001. return get$1(node, id).value[name];
  3002. };
  3003. }
  3004. function interpolate(a, b) {
  3005. var c;
  3006. return (typeof b === "number" ? interpolateNumber
  3007. : b instanceof color ? interpolateRgb
  3008. : (c = color(b)) ? (b = c, interpolateRgb)
  3009. : interpolateString)(a, b);
  3010. }
  3011. function attrRemove$1(name) {
  3012. return function() {
  3013. this.removeAttribute(name);
  3014. };
  3015. }
  3016. function attrRemoveNS$1(fullname) {
  3017. return function() {
  3018. this.removeAttributeNS(fullname.space, fullname.local);
  3019. };
  3020. }
  3021. function attrConstant$1(name, interpolate, value1) {
  3022. var string00,
  3023. string1 = value1 + "",
  3024. interpolate0;
  3025. return function() {
  3026. var string0 = this.getAttribute(name);
  3027. return string0 === string1 ? null
  3028. : string0 === string00 ? interpolate0
  3029. : interpolate0 = interpolate(string00 = string0, value1);
  3030. };
  3031. }
  3032. function attrConstantNS$1(fullname, interpolate, value1) {
  3033. var string00,
  3034. string1 = value1 + "",
  3035. interpolate0;
  3036. return function() {
  3037. var string0 = this.getAttributeNS(fullname.space, fullname.local);
  3038. return string0 === string1 ? null
  3039. : string0 === string00 ? interpolate0
  3040. : interpolate0 = interpolate(string00 = string0, value1);
  3041. };
  3042. }
  3043. function attrFunction$1(name, interpolate, value) {
  3044. var string00,
  3045. string10,
  3046. interpolate0;
  3047. return function() {
  3048. var string0, value1 = value(this), string1;
  3049. if (value1 == null) return void this.removeAttribute(name);
  3050. string0 = this.getAttribute(name);
  3051. string1 = value1 + "";
  3052. return string0 === string1 ? null
  3053. : string0 === string00 && string1 === string10 ? interpolate0
  3054. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3055. };
  3056. }
  3057. function attrFunctionNS$1(fullname, interpolate, value) {
  3058. var string00,
  3059. string10,
  3060. interpolate0;
  3061. return function() {
  3062. var string0, value1 = value(this), string1;
  3063. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3064. string0 = this.getAttributeNS(fullname.space, fullname.local);
  3065. string1 = value1 + "";
  3066. return string0 === string1 ? null
  3067. : string0 === string00 && string1 === string10 ? interpolate0
  3068. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3069. };
  3070. }
  3071. function transition_attr(name, value) {
  3072. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  3073. return this.attrTween(name, typeof value === "function"
  3074. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  3075. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  3076. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
  3077. }
  3078. function attrInterpolate(name, i) {
  3079. return function(t) {
  3080. this.setAttribute(name, i.call(this, t));
  3081. };
  3082. }
  3083. function attrInterpolateNS(fullname, i) {
  3084. return function(t) {
  3085. this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
  3086. };
  3087. }
  3088. function attrTweenNS(fullname, value) {
  3089. var t0, i0;
  3090. function tween() {
  3091. var i = value.apply(this, arguments);
  3092. if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
  3093. return t0;
  3094. }
  3095. tween._value = value;
  3096. return tween;
  3097. }
  3098. function attrTween(name, value) {
  3099. var t0, i0;
  3100. function tween() {
  3101. var i = value.apply(this, arguments);
  3102. if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
  3103. return t0;
  3104. }
  3105. tween._value = value;
  3106. return tween;
  3107. }
  3108. function transition_attrTween(name, value) {
  3109. var key = "attr." + name;
  3110. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3111. if (value == null) return this.tween(key, null);
  3112. if (typeof value !== "function") throw new Error;
  3113. var fullname = namespace(name);
  3114. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3115. }
  3116. function delayFunction(id, value) {
  3117. return function() {
  3118. init(this, id).delay = +value.apply(this, arguments);
  3119. };
  3120. }
  3121. function delayConstant(id, value) {
  3122. return value = +value, function() {
  3123. init(this, id).delay = value;
  3124. };
  3125. }
  3126. function transition_delay(value) {
  3127. var id = this._id;
  3128. return arguments.length
  3129. ? this.each((typeof value === "function"
  3130. ? delayFunction
  3131. : delayConstant)(id, value))
  3132. : get$1(this.node(), id).delay;
  3133. }
  3134. function durationFunction(id, value) {
  3135. return function() {
  3136. set$1(this, id).duration = +value.apply(this, arguments);
  3137. };
  3138. }
  3139. function durationConstant(id, value) {
  3140. return value = +value, function() {
  3141. set$1(this, id).duration = value;
  3142. };
  3143. }
  3144. function transition_duration(value) {
  3145. var id = this._id;
  3146. return arguments.length
  3147. ? this.each((typeof value === "function"
  3148. ? durationFunction
  3149. : durationConstant)(id, value))
  3150. : get$1(this.node(), id).duration;
  3151. }
  3152. function easeConstant(id, value) {
  3153. if (typeof value !== "function") throw new Error;
  3154. return function() {
  3155. set$1(this, id).ease = value;
  3156. };
  3157. }
  3158. function transition_ease(value) {
  3159. var id = this._id;
  3160. return arguments.length
  3161. ? this.each(easeConstant(id, value))
  3162. : get$1(this.node(), id).ease;
  3163. }
  3164. function transition_filter(match) {
  3165. if (typeof match !== "function") match = matcher(match);
  3166. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3167. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3168. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3169. subgroup.push(node);
  3170. }
  3171. }
  3172. }
  3173. return new Transition(subgroups, this._parents, this._name, this._id);
  3174. }
  3175. function transition_merge(transition) {
  3176. if (transition._id !== this._id) throw new Error;
  3177. 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) {
  3178. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3179. if (node = group0[i] || group1[i]) {
  3180. merge[i] = node;
  3181. }
  3182. }
  3183. }
  3184. for (; j < m0; ++j) {
  3185. merges[j] = groups0[j];
  3186. }
  3187. return new Transition(merges, this._parents, this._name, this._id);
  3188. }
  3189. function start(name) {
  3190. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3191. var i = t.indexOf(".");
  3192. if (i >= 0) t = t.slice(0, i);
  3193. return !t || t === "start";
  3194. });
  3195. }
  3196. function onFunction(id, name, listener) {
  3197. var on0, on1, sit = start(name) ? init : set$1;
  3198. return function() {
  3199. var schedule = sit(this, id),
  3200. on = schedule.on;
  3201. // If this node shared a dispatch with the previous node,
  3202. // just assign the updated shared dispatch and we’re done!
  3203. // Otherwise, copy-on-write.
  3204. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3205. schedule.on = on1;
  3206. };
  3207. }
  3208. function transition_on(name, listener) {
  3209. var id = this._id;
  3210. return arguments.length < 2
  3211. ? get$1(this.node(), id).on.on(name)
  3212. : this.each(onFunction(id, name, listener));
  3213. }
  3214. function removeFunction(id) {
  3215. return function() {
  3216. var parent = this.parentNode;
  3217. for (var i in this.__transition) if (+i !== id) return;
  3218. if (parent) parent.removeChild(this);
  3219. };
  3220. }
  3221. function transition_remove() {
  3222. return this.on("end.remove", removeFunction(this._id));
  3223. }
  3224. function transition_select(select) {
  3225. var name = this._name,
  3226. id = this._id;
  3227. if (typeof select !== "function") select = selector(select);
  3228. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3229. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3230. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  3231. if ("__data__" in node) subnode.__data__ = node.__data__;
  3232. subgroup[i] = subnode;
  3233. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3234. }
  3235. }
  3236. }
  3237. return new Transition(subgroups, this._parents, name, id);
  3238. }
  3239. function transition_selectAll(select) {
  3240. var name = this._name,
  3241. id = this._id;
  3242. if (typeof select !== "function") select = selectorAll(select);
  3243. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3244. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3245. if (node = group[i]) {
  3246. for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3247. if (child = children[k]) {
  3248. schedule(child, name, id, k, children, inherit);
  3249. }
  3250. }
  3251. subgroups.push(children);
  3252. parents.push(node);
  3253. }
  3254. }
  3255. }
  3256. return new Transition(subgroups, parents, name, id);
  3257. }
  3258. var Selection$1 = selection.prototype.constructor;
  3259. function transition_selection() {
  3260. return new Selection$1(this._groups, this._parents);
  3261. }
  3262. function styleNull(name, interpolate) {
  3263. var string00,
  3264. string10,
  3265. interpolate0;
  3266. return function() {
  3267. var string0 = styleValue(this, name),
  3268. string1 = (this.style.removeProperty(name), styleValue(this, name));
  3269. return string0 === string1 ? null
  3270. : string0 === string00 && string1 === string10 ? interpolate0
  3271. : interpolate0 = interpolate(string00 = string0, string10 = string1);
  3272. };
  3273. }
  3274. function styleRemove$1(name) {
  3275. return function() {
  3276. this.style.removeProperty(name);
  3277. };
  3278. }
  3279. function styleConstant$1(name, interpolate, value1) {
  3280. var string00,
  3281. string1 = value1 + "",
  3282. interpolate0;
  3283. return function() {
  3284. var string0 = styleValue(this, name);
  3285. return string0 === string1 ? null
  3286. : string0 === string00 ? interpolate0
  3287. : interpolate0 = interpolate(string00 = string0, value1);
  3288. };
  3289. }
  3290. function styleFunction$1(name, interpolate, value) {
  3291. var string00,
  3292. string10,
  3293. interpolate0;
  3294. return function() {
  3295. var string0 = styleValue(this, name),
  3296. value1 = value(this),
  3297. string1 = value1 + "";
  3298. if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
  3299. return string0 === string1 ? null
  3300. : string0 === string00 && string1 === string10 ? interpolate0
  3301. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3302. };
  3303. }
  3304. function styleMaybeRemove(id, name) {
  3305. var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
  3306. return function() {
  3307. var schedule = set$1(this, id),
  3308. on = schedule.on,
  3309. listener = schedule.value[key] == null ? remove || (remove = styleRemove$1(name)) : undefined;
  3310. // If this node shared a dispatch with the previous node,
  3311. // just assign the updated shared dispatch and we’re done!
  3312. // Otherwise, copy-on-write.
  3313. if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
  3314. schedule.on = on1;
  3315. };
  3316. }
  3317. function transition_style(name, value, priority) {
  3318. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3319. return value == null ? this
  3320. .styleTween(name, styleNull(name, i))
  3321. .on("end.style." + name, styleRemove$1(name))
  3322. : typeof value === "function" ? this
  3323. .styleTween(name, styleFunction$1(name, i, tweenValue(this, "style." + name, value)))
  3324. .each(styleMaybeRemove(this._id, name))
  3325. : this
  3326. .styleTween(name, styleConstant$1(name, i, value), priority)
  3327. .on("end.style." + name, null);
  3328. }
  3329. function styleInterpolate(name, i, priority) {
  3330. return function(t) {
  3331. this.style.setProperty(name, i.call(this, t), priority);
  3332. };
  3333. }
  3334. function styleTween(name, value, priority) {
  3335. var t, i0;
  3336. function tween() {
  3337. var i = value.apply(this, arguments);
  3338. if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
  3339. return t;
  3340. }
  3341. tween._value = value;
  3342. return tween;
  3343. }
  3344. function transition_styleTween(name, value, priority) {
  3345. var key = "style." + (name += "");
  3346. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3347. if (value == null) return this.tween(key, null);
  3348. if (typeof value !== "function") throw new Error;
  3349. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3350. }
  3351. function textConstant$1(value) {
  3352. return function() {
  3353. this.textContent = value;
  3354. };
  3355. }
  3356. function textFunction$1(value) {
  3357. return function() {
  3358. var value1 = value(this);
  3359. this.textContent = value1 == null ? "" : value1;
  3360. };
  3361. }
  3362. function transition_text(value) {
  3363. return this.tween("text", typeof value === "function"
  3364. ? textFunction$1(tweenValue(this, "text", value))
  3365. : textConstant$1(value == null ? "" : value + ""));
  3366. }
  3367. function textInterpolate(i) {
  3368. return function(t) {
  3369. this.textContent = i.call(this, t);
  3370. };
  3371. }
  3372. function textTween(value) {
  3373. var t0, i0;
  3374. function tween() {
  3375. var i = value.apply(this, arguments);
  3376. if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
  3377. return t0;
  3378. }
  3379. tween._value = value;
  3380. return tween;
  3381. }
  3382. function transition_textTween(value) {
  3383. var key = "text";
  3384. if (arguments.length < 1) return (key = this.tween(key)) && key._value;
  3385. if (value == null) return this.tween(key, null);
  3386. if (typeof value !== "function") throw new Error;
  3387. return this.tween(key, textTween(value));
  3388. }
  3389. function transition_transition() {
  3390. var name = this._name,
  3391. id0 = this._id,
  3392. id1 = newId();
  3393. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3394. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3395. if (node = group[i]) {
  3396. var inherit = get$1(node, id0);
  3397. schedule(node, name, id1, i, group, {
  3398. time: inherit.time + inherit.delay + inherit.duration,
  3399. delay: 0,
  3400. duration: inherit.duration,
  3401. ease: inherit.ease
  3402. });
  3403. }
  3404. }
  3405. }
  3406. return new Transition(groups, this._parents, name, id1);
  3407. }
  3408. function transition_end() {
  3409. var on0, on1, that = this, id = that._id, size = that.size();
  3410. return new Promise(function(resolve, reject) {
  3411. var cancel = {value: reject},
  3412. end = {value: function() { if (--size === 0) resolve(); }};
  3413. that.each(function() {
  3414. var schedule = set$1(this, id),
  3415. on = schedule.on;
  3416. // If this node shared a dispatch with the previous node,
  3417. // just assign the updated shared dispatch and we’re done!
  3418. // Otherwise, copy-on-write.
  3419. if (on !== on0) {
  3420. on1 = (on0 = on).copy();
  3421. on1._.cancel.push(cancel);
  3422. on1._.interrupt.push(cancel);
  3423. on1._.end.push(end);
  3424. }
  3425. schedule.on = on1;
  3426. });
  3427. });
  3428. }
  3429. var id = 0;
  3430. function Transition(groups, parents, name, id) {
  3431. this._groups = groups;
  3432. this._parents = parents;
  3433. this._name = name;
  3434. this._id = id;
  3435. }
  3436. function transition(name) {
  3437. return selection().transition(name);
  3438. }
  3439. function newId() {
  3440. return ++id;
  3441. }
  3442. var selection_prototype = selection.prototype;
  3443. Transition.prototype = transition.prototype = {
  3444. constructor: Transition,
  3445. select: transition_select,
  3446. selectAll: transition_selectAll,
  3447. filter: transition_filter,
  3448. merge: transition_merge,
  3449. selection: transition_selection,
  3450. transition: transition_transition,
  3451. call: selection_prototype.call,
  3452. nodes: selection_prototype.nodes,
  3453. node: selection_prototype.node,
  3454. size: selection_prototype.size,
  3455. empty: selection_prototype.empty,
  3456. each: selection_prototype.each,
  3457. on: transition_on,
  3458. attr: transition_attr,
  3459. attrTween: transition_attrTween,
  3460. style: transition_style,
  3461. styleTween: transition_styleTween,
  3462. text: transition_text,
  3463. textTween: transition_textTween,
  3464. remove: transition_remove,
  3465. tween: transition_tween,
  3466. delay: transition_delay,
  3467. duration: transition_duration,
  3468. ease: transition_ease,
  3469. end: transition_end
  3470. };
  3471. function linear$1(t) {
  3472. return +t;
  3473. }
  3474. function quadIn(t) {
  3475. return t * t;
  3476. }
  3477. function quadOut(t) {
  3478. return t * (2 - t);
  3479. }
  3480. function quadInOut(t) {
  3481. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3482. }
  3483. function cubicIn(t) {
  3484. return t * t * t;
  3485. }
  3486. function cubicOut(t) {
  3487. return --t * t * t + 1;
  3488. }
  3489. function cubicInOut(t) {
  3490. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3491. }
  3492. var exponent = 3;
  3493. var polyIn = (function custom(e) {
  3494. e = +e;
  3495. function polyIn(t) {
  3496. return Math.pow(t, e);
  3497. }
  3498. polyIn.exponent = custom;
  3499. return polyIn;
  3500. })(exponent);
  3501. var polyOut = (function custom(e) {
  3502. e = +e;
  3503. function polyOut(t) {
  3504. return 1 - Math.pow(1 - t, e);
  3505. }
  3506. polyOut.exponent = custom;
  3507. return polyOut;
  3508. })(exponent);
  3509. var polyInOut = (function custom(e) {
  3510. e = +e;
  3511. function polyInOut(t) {
  3512. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3513. }
  3514. polyInOut.exponent = custom;
  3515. return polyInOut;
  3516. })(exponent);
  3517. var pi = Math.PI,
  3518. halfPi = pi / 2;
  3519. function sinIn(t) {
  3520. return 1 - Math.cos(t * halfPi);
  3521. }
  3522. function sinOut(t) {
  3523. return Math.sin(t * halfPi);
  3524. }
  3525. function sinInOut(t) {
  3526. return (1 - Math.cos(pi * t)) / 2;
  3527. }
  3528. function expIn(t) {
  3529. return Math.pow(2, 10 * t - 10);
  3530. }
  3531. function expOut(t) {
  3532. return 1 - Math.pow(2, -10 * t);
  3533. }
  3534. function expInOut(t) {
  3535. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3536. }
  3537. function circleIn(t) {
  3538. return 1 - Math.sqrt(1 - t * t);
  3539. }
  3540. function circleOut(t) {
  3541. return Math.sqrt(1 - --t * t);
  3542. }
  3543. function circleInOut(t) {
  3544. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3545. }
  3546. var b1 = 4 / 11,
  3547. b2 = 6 / 11,
  3548. b3 = 8 / 11,
  3549. b4 = 3 / 4,
  3550. b5 = 9 / 11,
  3551. b6 = 10 / 11,
  3552. b7 = 15 / 16,
  3553. b8 = 21 / 22,
  3554. b9 = 63 / 64,
  3555. b0 = 1 / b1 / b1;
  3556. function bounceIn(t) {
  3557. return 1 - bounceOut(1 - t);
  3558. }
  3559. function bounceOut(t) {
  3560. 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;
  3561. }
  3562. function bounceInOut(t) {
  3563. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3564. }
  3565. var overshoot = 1.70158;
  3566. var backIn = (function custom(s) {
  3567. s = +s;
  3568. function backIn(t) {
  3569. return t * t * ((s + 1) * t - s);
  3570. }
  3571. backIn.overshoot = custom;
  3572. return backIn;
  3573. })(overshoot);
  3574. var backOut = (function custom(s) {
  3575. s = +s;
  3576. function backOut(t) {
  3577. return --t * t * ((s + 1) * t + s) + 1;
  3578. }
  3579. backOut.overshoot = custom;
  3580. return backOut;
  3581. })(overshoot);
  3582. var backInOut = (function custom(s) {
  3583. s = +s;
  3584. function backInOut(t) {
  3585. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3586. }
  3587. backInOut.overshoot = custom;
  3588. return backInOut;
  3589. })(overshoot);
  3590. var tau = 2 * Math.PI,
  3591. amplitude = 1,
  3592. period = 0.3;
  3593. var elasticIn = (function custom(a, p) {
  3594. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3595. function elasticIn(t) {
  3596. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3597. }
  3598. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3599. elasticIn.period = function(p) { return custom(a, p); };
  3600. return elasticIn;
  3601. })(amplitude, period);
  3602. var elasticOut = (function custom(a, p) {
  3603. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3604. function elasticOut(t) {
  3605. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3606. }
  3607. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3608. elasticOut.period = function(p) { return custom(a, p); };
  3609. return elasticOut;
  3610. })(amplitude, period);
  3611. var elasticInOut = (function custom(a, p) {
  3612. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3613. function elasticInOut(t) {
  3614. return ((t = t * 2 - 1) < 0
  3615. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3616. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3617. }
  3618. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3619. elasticInOut.period = function(p) { return custom(a, p); };
  3620. return elasticInOut;
  3621. })(amplitude, period);
  3622. var defaultTiming = {
  3623. time: null, // Set on use.
  3624. delay: 0,
  3625. duration: 250,
  3626. ease: cubicInOut
  3627. };
  3628. function inherit(node, id) {
  3629. var timing;
  3630. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3631. if (!(node = node.parentNode)) {
  3632. return defaultTiming.time = now(), defaultTiming;
  3633. }
  3634. }
  3635. return timing;
  3636. }
  3637. function selection_transition(name) {
  3638. var id,
  3639. timing;
  3640. if (name instanceof Transition) {
  3641. id = name._id, name = name._name;
  3642. } else {
  3643. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3644. }
  3645. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3646. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3647. if (node = group[i]) {
  3648. schedule(node, name, id, i, group, timing || inherit(node, id));
  3649. }
  3650. }
  3651. }
  3652. return new Transition(groups, this._parents, name, id);
  3653. }
  3654. selection.prototype.interrupt = selection_interrupt;
  3655. selection.prototype.transition = selection_transition;
  3656. var root$1 = [null];
  3657. function active(node, name) {
  3658. var schedules = node.__transition,
  3659. schedule,
  3660. i;
  3661. if (schedules) {
  3662. name = name == null ? null : name + "";
  3663. for (i in schedules) {
  3664. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  3665. return new Transition([[node]], root$1, name, +i);
  3666. }
  3667. }
  3668. }
  3669. return null;
  3670. }
  3671. function constant$4(x) {
  3672. return function() {
  3673. return x;
  3674. };
  3675. }
  3676. function BrushEvent(target, type, selection) {
  3677. this.target = target;
  3678. this.type = type;
  3679. this.selection = selection;
  3680. }
  3681. function nopropagation$1() {
  3682. exports.event.stopImmediatePropagation();
  3683. }
  3684. function noevent$1() {
  3685. exports.event.preventDefault();
  3686. exports.event.stopImmediatePropagation();
  3687. }
  3688. var MODE_DRAG = {name: "drag"},
  3689. MODE_SPACE = {name: "space"},
  3690. MODE_HANDLE = {name: "handle"},
  3691. MODE_CENTER = {name: "center"};
  3692. function number1(e) {
  3693. return [+e[0], +e[1]];
  3694. }
  3695. function number2(e) {
  3696. return [number1(e[0]), number1(e[1])];
  3697. }
  3698. function toucher(identifier) {
  3699. return function(target) {
  3700. return touch(target, exports.event.touches, identifier);
  3701. };
  3702. }
  3703. var X = {
  3704. name: "x",
  3705. handles: ["w", "e"].map(type),
  3706. input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
  3707. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3708. };
  3709. var Y = {
  3710. name: "y",
  3711. handles: ["n", "s"].map(type),
  3712. input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
  3713. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3714. };
  3715. var XY = {
  3716. name: "xy",
  3717. handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
  3718. input: function(xy) { return xy == null ? null : number2(xy); },
  3719. output: function(xy) { return xy; }
  3720. };
  3721. var cursors = {
  3722. overlay: "crosshair",
  3723. selection: "move",
  3724. n: "ns-resize",
  3725. e: "ew-resize",
  3726. s: "ns-resize",
  3727. w: "ew-resize",
  3728. nw: "nwse-resize",
  3729. ne: "nesw-resize",
  3730. se: "nwse-resize",
  3731. sw: "nesw-resize"
  3732. };
  3733. var flipX = {
  3734. e: "w",
  3735. w: "e",
  3736. nw: "ne",
  3737. ne: "nw",
  3738. se: "sw",
  3739. sw: "se"
  3740. };
  3741. var flipY = {
  3742. n: "s",
  3743. s: "n",
  3744. nw: "sw",
  3745. ne: "se",
  3746. se: "ne",
  3747. sw: "nw"
  3748. };
  3749. var signsX = {
  3750. overlay: +1,
  3751. selection: +1,
  3752. n: null,
  3753. e: +1,
  3754. s: null,
  3755. w: -1,
  3756. nw: -1,
  3757. ne: +1,
  3758. se: +1,
  3759. sw: -1
  3760. };
  3761. var signsY = {
  3762. overlay: +1,
  3763. selection: +1,
  3764. n: -1,
  3765. e: null,
  3766. s: +1,
  3767. w: null,
  3768. nw: -1,
  3769. ne: -1,
  3770. se: +1,
  3771. sw: +1
  3772. };
  3773. function type(t) {
  3774. return {type: t};
  3775. }
  3776. // Ignore right-click, since that should open the context menu.
  3777. function defaultFilter$1() {
  3778. return !exports.event.ctrlKey && !exports.event.button;
  3779. }
  3780. function defaultExtent() {
  3781. var svg = this.ownerSVGElement || this;
  3782. if (svg.hasAttribute("viewBox")) {
  3783. svg = svg.viewBox.baseVal;
  3784. return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
  3785. }
  3786. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3787. }
  3788. function defaultTouchable$1() {
  3789. return navigator.maxTouchPoints || ("ontouchstart" in this);
  3790. }
  3791. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3792. function local$1(node) {
  3793. while (!node.__brush) if (!(node = node.parentNode)) return;
  3794. return node.__brush;
  3795. }
  3796. function empty$1(extent) {
  3797. return extent[0][0] === extent[1][0]
  3798. || extent[0][1] === extent[1][1];
  3799. }
  3800. function brushSelection(node) {
  3801. var state = node.__brush;
  3802. return state ? state.dim.output(state.selection) : null;
  3803. }
  3804. function brushX() {
  3805. return brush$1(X);
  3806. }
  3807. function brushY() {
  3808. return brush$1(Y);
  3809. }
  3810. function brush() {
  3811. return brush$1(XY);
  3812. }
  3813. function brush$1(dim) {
  3814. var extent = defaultExtent,
  3815. filter = defaultFilter$1,
  3816. touchable = defaultTouchable$1,
  3817. keys = true,
  3818. listeners = dispatch("start", "brush", "end"),
  3819. handleSize = 6,
  3820. touchending;
  3821. function brush(group) {
  3822. var overlay = group
  3823. .property("__brush", initialize)
  3824. .selectAll(".overlay")
  3825. .data([type("overlay")]);
  3826. overlay.enter().append("rect")
  3827. .attr("class", "overlay")
  3828. .attr("pointer-events", "all")
  3829. .attr("cursor", cursors.overlay)
  3830. .merge(overlay)
  3831. .each(function() {
  3832. var extent = local$1(this).extent;
  3833. select(this)
  3834. .attr("x", extent[0][0])
  3835. .attr("y", extent[0][1])
  3836. .attr("width", extent[1][0] - extent[0][0])
  3837. .attr("height", extent[1][1] - extent[0][1]);
  3838. });
  3839. group.selectAll(".selection")
  3840. .data([type("selection")])
  3841. .enter().append("rect")
  3842. .attr("class", "selection")
  3843. .attr("cursor", cursors.selection)
  3844. .attr("fill", "#777")
  3845. .attr("fill-opacity", 0.3)
  3846. .attr("stroke", "#fff")
  3847. .attr("shape-rendering", "crispEdges");
  3848. var handle = group.selectAll(".handle")
  3849. .data(dim.handles, function(d) { return d.type; });
  3850. handle.exit().remove();
  3851. handle.enter().append("rect")
  3852. .attr("class", function(d) { return "handle handle--" + d.type; })
  3853. .attr("cursor", function(d) { return cursors[d.type]; });
  3854. group
  3855. .each(redraw)
  3856. .attr("fill", "none")
  3857. .attr("pointer-events", "all")
  3858. .on("mousedown.brush", started)
  3859. .filter(touchable)
  3860. .on("touchstart.brush", started)
  3861. .on("touchmove.brush", touchmoved)
  3862. .on("touchend.brush touchcancel.brush", touchended)
  3863. .style("touch-action", "none")
  3864. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  3865. }
  3866. brush.move = function(group, selection) {
  3867. if (group.selection) {
  3868. group
  3869. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3870. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3871. .tween("brush", function() {
  3872. var that = this,
  3873. state = that.__brush,
  3874. emit = emitter(that, arguments),
  3875. selection0 = state.selection,
  3876. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  3877. i = interpolateValue(selection0, selection1);
  3878. function tween(t) {
  3879. state.selection = t === 1 && selection1 === null ? null : i(t);
  3880. redraw.call(that);
  3881. emit.brush();
  3882. }
  3883. return selection0 !== null && selection1 !== null ? tween : tween(1);
  3884. });
  3885. } else {
  3886. group
  3887. .each(function() {
  3888. var that = this,
  3889. args = arguments,
  3890. state = that.__brush,
  3891. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  3892. emit = emitter(that, args).beforestart();
  3893. interrupt(that);
  3894. state.selection = selection1 === null ? null : selection1;
  3895. redraw.call(that);
  3896. emit.start().brush().end();
  3897. });
  3898. }
  3899. };
  3900. brush.clear = function(group) {
  3901. brush.move(group, null);
  3902. };
  3903. function redraw() {
  3904. var group = select(this),
  3905. selection = local$1(this).selection;
  3906. if (selection) {
  3907. group.selectAll(".selection")
  3908. .style("display", null)
  3909. .attr("x", selection[0][0])
  3910. .attr("y", selection[0][1])
  3911. .attr("width", selection[1][0] - selection[0][0])
  3912. .attr("height", selection[1][1] - selection[0][1]);
  3913. group.selectAll(".handle")
  3914. .style("display", null)
  3915. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  3916. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  3917. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  3918. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  3919. }
  3920. else {
  3921. group.selectAll(".selection,.handle")
  3922. .style("display", "none")
  3923. .attr("x", null)
  3924. .attr("y", null)
  3925. .attr("width", null)
  3926. .attr("height", null);
  3927. }
  3928. }
  3929. function emitter(that, args, clean) {
  3930. return (!clean && that.__brush.emitter) || new Emitter(that, args);
  3931. }
  3932. function Emitter(that, args) {
  3933. this.that = that;
  3934. this.args = args;
  3935. this.state = that.__brush;
  3936. this.active = 0;
  3937. }
  3938. Emitter.prototype = {
  3939. beforestart: function() {
  3940. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3941. return this;
  3942. },
  3943. start: function() {
  3944. if (this.starting) this.starting = false, this.emit("start");
  3945. else this.emit("brush");
  3946. return this;
  3947. },
  3948. brush: function() {
  3949. this.emit("brush");
  3950. return this;
  3951. },
  3952. end: function() {
  3953. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3954. return this;
  3955. },
  3956. emit: function(type) {
  3957. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3958. }
  3959. };
  3960. function started() {
  3961. if (touchending && !exports.event.touches) return;
  3962. if (!filter.apply(this, arguments)) return;
  3963. var that = this,
  3964. type = exports.event.target.__data__.type,
  3965. mode = (keys && exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3966. signX = dim === Y ? null : signsX[type],
  3967. signY = dim === X ? null : signsY[type],
  3968. state = local$1(that),
  3969. extent = state.extent,
  3970. selection = state.selection,
  3971. W = extent[0][0], w0, w1,
  3972. N = extent[0][1], n0, n1,
  3973. E = extent[1][0], e0, e1,
  3974. S = extent[1][1], s0, s1,
  3975. dx = 0,
  3976. dy = 0,
  3977. moving,
  3978. shifting = signX && signY && keys && exports.event.shiftKey,
  3979. lockX,
  3980. lockY,
  3981. pointer = exports.event.touches ? toucher(exports.event.changedTouches[0].identifier) : mouse,
  3982. point0 = pointer(that),
  3983. point = point0,
  3984. emit = emitter(that, arguments, true).beforestart();
  3985. if (type === "overlay") {
  3986. if (selection) moving = true;
  3987. state.selection = selection = [
  3988. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3989. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3990. ];
  3991. } else {
  3992. w0 = selection[0][0];
  3993. n0 = selection[0][1];
  3994. e0 = selection[1][0];
  3995. s0 = selection[1][1];
  3996. }
  3997. w1 = w0;
  3998. n1 = n0;
  3999. e1 = e0;
  4000. s1 = s0;
  4001. var group = select(that)
  4002. .attr("pointer-events", "none");
  4003. var overlay = group.selectAll(".overlay")
  4004. .attr("cursor", cursors[type]);
  4005. if (exports.event.touches) {
  4006. emit.moved = moved;
  4007. emit.ended = ended;
  4008. } else {
  4009. var view = select(exports.event.view)
  4010. .on("mousemove.brush", moved, true)
  4011. .on("mouseup.brush", ended, true);
  4012. if (keys) view
  4013. .on("keydown.brush", keydowned, true)
  4014. .on("keyup.brush", keyupped, true);
  4015. dragDisable(exports.event.view);
  4016. }
  4017. nopropagation$1();
  4018. interrupt(that);
  4019. redraw.call(that);
  4020. emit.start();
  4021. function moved() {
  4022. var point1 = pointer(that);
  4023. if (shifting && !lockX && !lockY) {
  4024. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  4025. else lockX = true;
  4026. }
  4027. point = point1;
  4028. moving = true;
  4029. noevent$1();
  4030. move();
  4031. }
  4032. function move() {
  4033. var t;
  4034. dx = point[0] - point0[0];
  4035. dy = point[1] - point0[1];
  4036. switch (mode) {
  4037. case MODE_SPACE:
  4038. case MODE_DRAG: {
  4039. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  4040. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  4041. break;
  4042. }
  4043. case MODE_HANDLE: {
  4044. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  4045. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  4046. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  4047. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  4048. break;
  4049. }
  4050. case MODE_CENTER: {
  4051. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  4052. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  4053. break;
  4054. }
  4055. }
  4056. if (e1 < w1) {
  4057. signX *= -1;
  4058. t = w0, w0 = e0, e0 = t;
  4059. t = w1, w1 = e1, e1 = t;
  4060. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  4061. }
  4062. if (s1 < n1) {
  4063. signY *= -1;
  4064. t = n0, n0 = s0, s0 = t;
  4065. t = n1, n1 = s1, s1 = t;
  4066. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  4067. }
  4068. if (state.selection) selection = state.selection; // May be set by brush.move!
  4069. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  4070. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  4071. if (selection[0][0] !== w1
  4072. || selection[0][1] !== n1
  4073. || selection[1][0] !== e1
  4074. || selection[1][1] !== s1) {
  4075. state.selection = [[w1, n1], [e1, s1]];
  4076. redraw.call(that);
  4077. emit.brush();
  4078. }
  4079. }
  4080. function ended() {
  4081. nopropagation$1();
  4082. if (exports.event.touches) {
  4083. if (exports.event.touches.length) return;
  4084. if (touchending) clearTimeout(touchending);
  4085. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  4086. } else {
  4087. yesdrag(exports.event.view, moving);
  4088. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  4089. }
  4090. group.attr("pointer-events", "all");
  4091. overlay.attr("cursor", cursors.overlay);
  4092. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  4093. if (empty$1(selection)) state.selection = null, redraw.call(that);
  4094. emit.end();
  4095. }
  4096. function keydowned() {
  4097. switch (exports.event.keyCode) {
  4098. case 16: { // SHIFT
  4099. shifting = signX && signY;
  4100. break;
  4101. }
  4102. case 18: { // ALT
  4103. if (mode === MODE_HANDLE) {
  4104. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4105. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4106. mode = MODE_CENTER;
  4107. move();
  4108. }
  4109. break;
  4110. }
  4111. case 32: { // SPACE; takes priority over ALT
  4112. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  4113. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  4114. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  4115. mode = MODE_SPACE;
  4116. overlay.attr("cursor", cursors.selection);
  4117. move();
  4118. }
  4119. break;
  4120. }
  4121. default: return;
  4122. }
  4123. noevent$1();
  4124. }
  4125. function keyupped() {
  4126. switch (exports.event.keyCode) {
  4127. case 16: { // SHIFT
  4128. if (shifting) {
  4129. lockX = lockY = shifting = false;
  4130. move();
  4131. }
  4132. break;
  4133. }
  4134. case 18: { // ALT
  4135. if (mode === MODE_CENTER) {
  4136. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4137. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4138. mode = MODE_HANDLE;
  4139. move();
  4140. }
  4141. break;
  4142. }
  4143. case 32: { // SPACE
  4144. if (mode === MODE_SPACE) {
  4145. if (exports.event.altKey) {
  4146. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4147. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4148. mode = MODE_CENTER;
  4149. } else {
  4150. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4151. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4152. mode = MODE_HANDLE;
  4153. }
  4154. overlay.attr("cursor", cursors[type]);
  4155. move();
  4156. }
  4157. break;
  4158. }
  4159. default: return;
  4160. }
  4161. noevent$1();
  4162. }
  4163. }
  4164. function touchmoved() {
  4165. emitter(this, arguments).moved();
  4166. }
  4167. function touchended() {
  4168. emitter(this, arguments).ended();
  4169. }
  4170. function initialize() {
  4171. var state = this.__brush || {selection: null};
  4172. state.extent = number2(extent.apply(this, arguments));
  4173. state.dim = dim;
  4174. return state;
  4175. }
  4176. brush.extent = function(_) {
  4177. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4(number2(_)), brush) : extent;
  4178. };
  4179. brush.filter = function(_) {
  4180. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  4181. };
  4182. brush.touchable = function(_) {
  4183. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$4(!!_), brush) : touchable;
  4184. };
  4185. brush.handleSize = function(_) {
  4186. return arguments.length ? (handleSize = +_, brush) : handleSize;
  4187. };
  4188. brush.keyModifiers = function(_) {
  4189. return arguments.length ? (keys = !!_, brush) : keys;
  4190. };
  4191. brush.on = function() {
  4192. var value = listeners.on.apply(listeners, arguments);
  4193. return value === listeners ? brush : value;
  4194. };
  4195. return brush;
  4196. }
  4197. var cos = Math.cos;
  4198. var sin = Math.sin;
  4199. var pi$1 = Math.PI;
  4200. var halfPi$1 = pi$1 / 2;
  4201. var tau$1 = pi$1 * 2;
  4202. var max$1 = Math.max;
  4203. function compareValue(compare) {
  4204. return function(a, b) {
  4205. return compare(
  4206. a.source.value + a.target.value,
  4207. b.source.value + b.target.value
  4208. );
  4209. };
  4210. }
  4211. function chord() {
  4212. var padAngle = 0,
  4213. sortGroups = null,
  4214. sortSubgroups = null,
  4215. sortChords = null;
  4216. function chord(matrix) {
  4217. var n = matrix.length,
  4218. groupSums = [],
  4219. groupIndex = sequence(n),
  4220. subgroupIndex = [],
  4221. chords = [],
  4222. groups = chords.groups = new Array(n),
  4223. subgroups = new Array(n * n),
  4224. k,
  4225. x,
  4226. x0,
  4227. dx,
  4228. i,
  4229. j;
  4230. // Compute the sum.
  4231. k = 0, i = -1; while (++i < n) {
  4232. x = 0, j = -1; while (++j < n) {
  4233. x += matrix[i][j];
  4234. }
  4235. groupSums.push(x);
  4236. subgroupIndex.push(sequence(n));
  4237. k += x;
  4238. }
  4239. // Sort groups…
  4240. if (sortGroups) groupIndex.sort(function(a, b) {
  4241. return sortGroups(groupSums[a], groupSums[b]);
  4242. });
  4243. // Sort subgroups…
  4244. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4245. d.sort(function(a, b) {
  4246. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4247. });
  4248. });
  4249. // Convert the sum to scaling factor for [0, 2pi].
  4250. // TODO Allow start and end angle to be specified?
  4251. // TODO Allow padding to be specified as percentage?
  4252. k = max$1(0, tau$1 - padAngle * n) / k;
  4253. dx = k ? padAngle : tau$1 / n;
  4254. // Compute the start and end angle for each group and subgroup.
  4255. // Note: Opera has a bug reordering object literal properties!
  4256. x = 0, i = -1; while (++i < n) {
  4257. x0 = x, j = -1; while (++j < n) {
  4258. var di = groupIndex[i],
  4259. dj = subgroupIndex[di][j],
  4260. v = matrix[di][dj],
  4261. a0 = x,
  4262. a1 = x += v * k;
  4263. subgroups[dj * n + di] = {
  4264. index: di,
  4265. subindex: dj,
  4266. startAngle: a0,
  4267. endAngle: a1,
  4268. value: v
  4269. };
  4270. }
  4271. groups[di] = {
  4272. index: di,
  4273. startAngle: x0,
  4274. endAngle: x,
  4275. value: groupSums[di]
  4276. };
  4277. x += dx;
  4278. }
  4279. // Generate chords for each (non-empty) subgroup-subgroup link.
  4280. i = -1; while (++i < n) {
  4281. j = i - 1; while (++j < n) {
  4282. var source = subgroups[j * n + i],
  4283. target = subgroups[i * n + j];
  4284. if (source.value || target.value) {
  4285. chords.push(source.value < target.value
  4286. ? {source: target, target: source}
  4287. : {source: source, target: target});
  4288. }
  4289. }
  4290. }
  4291. return sortChords ? chords.sort(sortChords) : chords;
  4292. }
  4293. chord.padAngle = function(_) {
  4294. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4295. };
  4296. chord.sortGroups = function(_) {
  4297. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4298. };
  4299. chord.sortSubgroups = function(_) {
  4300. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4301. };
  4302. chord.sortChords = function(_) {
  4303. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4304. };
  4305. return chord;
  4306. }
  4307. var slice$2 = Array.prototype.slice;
  4308. function constant$5(x) {
  4309. return function() {
  4310. return x;
  4311. };
  4312. }
  4313. var pi$2 = Math.PI,
  4314. tau$2 = 2 * pi$2,
  4315. epsilon$1 = 1e-6,
  4316. tauEpsilon = tau$2 - epsilon$1;
  4317. function Path() {
  4318. this._x0 = this._y0 = // start of current subpath
  4319. this._x1 = this._y1 = null; // end of current subpath
  4320. this._ = "";
  4321. }
  4322. function path() {
  4323. return new Path;
  4324. }
  4325. Path.prototype = path.prototype = {
  4326. constructor: Path,
  4327. moveTo: function(x, y) {
  4328. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4329. },
  4330. closePath: function() {
  4331. if (this._x1 !== null) {
  4332. this._x1 = this._x0, this._y1 = this._y0;
  4333. this._ += "Z";
  4334. }
  4335. },
  4336. lineTo: function(x, y) {
  4337. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4338. },
  4339. quadraticCurveTo: function(x1, y1, x, y) {
  4340. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4341. },
  4342. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4343. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4344. },
  4345. arcTo: function(x1, y1, x2, y2, r) {
  4346. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4347. var x0 = this._x1,
  4348. y0 = this._y1,
  4349. x21 = x2 - x1,
  4350. y21 = y2 - y1,
  4351. x01 = x0 - x1,
  4352. y01 = y0 - y1,
  4353. l01_2 = x01 * x01 + y01 * y01;
  4354. // Is the radius negative? Error.
  4355. if (r < 0) throw new Error("negative radius: " + r);
  4356. // Is this path empty? Move to (x1,y1).
  4357. if (this._x1 === null) {
  4358. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4359. }
  4360. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4361. else if (!(l01_2 > epsilon$1));
  4362. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4363. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4364. // Or, is the radius zero? Line to (x1,y1).
  4365. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4366. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4367. }
  4368. // Otherwise, draw an arc!
  4369. else {
  4370. var x20 = x2 - x0,
  4371. y20 = y2 - y0,
  4372. l21_2 = x21 * x21 + y21 * y21,
  4373. l20_2 = x20 * x20 + y20 * y20,
  4374. l21 = Math.sqrt(l21_2),
  4375. l01 = Math.sqrt(l01_2),
  4376. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4377. t01 = l / l01,
  4378. t21 = l / l21;
  4379. // If the start tangent is not coincident with (x0,y0), line to.
  4380. if (Math.abs(t01 - 1) > epsilon$1) {
  4381. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4382. }
  4383. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4384. }
  4385. },
  4386. arc: function(x, y, r, a0, a1, ccw) {
  4387. x = +x, y = +y, r = +r, ccw = !!ccw;
  4388. var dx = r * Math.cos(a0),
  4389. dy = r * Math.sin(a0),
  4390. x0 = x + dx,
  4391. y0 = y + dy,
  4392. cw = 1 ^ ccw,
  4393. da = ccw ? a0 - a1 : a1 - a0;
  4394. // Is the radius negative? Error.
  4395. if (r < 0) throw new Error("negative radius: " + r);
  4396. // Is this path empty? Move to (x0,y0).
  4397. if (this._x1 === null) {
  4398. this._ += "M" + x0 + "," + y0;
  4399. }
  4400. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4401. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4402. this._ += "L" + x0 + "," + y0;
  4403. }
  4404. // Is this arc empty? We’re done.
  4405. if (!r) return;
  4406. // Does the angle go the wrong way? Flip the direction.
  4407. if (da < 0) da = da % tau$2 + tau$2;
  4408. // Is this a complete circle? Draw two arcs to complete the circle.
  4409. if (da > tauEpsilon) {
  4410. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4411. }
  4412. // Is this arc non-empty? Draw an arc!
  4413. else if (da > epsilon$1) {
  4414. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4415. }
  4416. },
  4417. rect: function(x, y, w, h) {
  4418. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4419. },
  4420. toString: function() {
  4421. return this._;
  4422. }
  4423. };
  4424. function defaultSource(d) {
  4425. return d.source;
  4426. }
  4427. function defaultTarget(d) {
  4428. return d.target;
  4429. }
  4430. function defaultRadius(d) {
  4431. return d.radius;
  4432. }
  4433. function defaultStartAngle(d) {
  4434. return d.startAngle;
  4435. }
  4436. function defaultEndAngle(d) {
  4437. return d.endAngle;
  4438. }
  4439. function ribbon() {
  4440. var source = defaultSource,
  4441. target = defaultTarget,
  4442. radius = defaultRadius,
  4443. startAngle = defaultStartAngle,
  4444. endAngle = defaultEndAngle,
  4445. context = null;
  4446. function ribbon() {
  4447. var buffer,
  4448. argv = slice$2.call(arguments),
  4449. s = source.apply(this, argv),
  4450. t = target.apply(this, argv),
  4451. sr = +radius.apply(this, (argv[0] = s, argv)),
  4452. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4453. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4454. sx0 = sr * cos(sa0),
  4455. sy0 = sr * sin(sa0),
  4456. tr = +radius.apply(this, (argv[0] = t, argv)),
  4457. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4458. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4459. if (!context) context = buffer = path();
  4460. context.moveTo(sx0, sy0);
  4461. context.arc(0, 0, sr, sa0, sa1);
  4462. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4463. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4464. context.arc(0, 0, tr, ta0, ta1);
  4465. }
  4466. context.quadraticCurveTo(0, 0, sx0, sy0);
  4467. context.closePath();
  4468. if (buffer) return context = null, buffer + "" || null;
  4469. }
  4470. ribbon.radius = function(_) {
  4471. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4472. };
  4473. ribbon.startAngle = function(_) {
  4474. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4475. };
  4476. ribbon.endAngle = function(_) {
  4477. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4478. };
  4479. ribbon.source = function(_) {
  4480. return arguments.length ? (source = _, ribbon) : source;
  4481. };
  4482. ribbon.target = function(_) {
  4483. return arguments.length ? (target = _, ribbon) : target;
  4484. };
  4485. ribbon.context = function(_) {
  4486. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  4487. };
  4488. return ribbon;
  4489. }
  4490. var prefix = "$";
  4491. function Map() {}
  4492. Map.prototype = map$1.prototype = {
  4493. constructor: Map,
  4494. has: function(key) {
  4495. return (prefix + key) in this;
  4496. },
  4497. get: function(key) {
  4498. return this[prefix + key];
  4499. },
  4500. set: function(key, value) {
  4501. this[prefix + key] = value;
  4502. return this;
  4503. },
  4504. remove: function(key) {
  4505. var property = prefix + key;
  4506. return property in this && delete this[property];
  4507. },
  4508. clear: function() {
  4509. for (var property in this) if (property[0] === prefix) delete this[property];
  4510. },
  4511. keys: function() {
  4512. var keys = [];
  4513. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4514. return keys;
  4515. },
  4516. values: function() {
  4517. var values = [];
  4518. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4519. return values;
  4520. },
  4521. entries: function() {
  4522. var entries = [];
  4523. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4524. return entries;
  4525. },
  4526. size: function() {
  4527. var size = 0;
  4528. for (var property in this) if (property[0] === prefix) ++size;
  4529. return size;
  4530. },
  4531. empty: function() {
  4532. for (var property in this) if (property[0] === prefix) return false;
  4533. return true;
  4534. },
  4535. each: function(f) {
  4536. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4537. }
  4538. };
  4539. function map$1(object, f) {
  4540. var map = new Map;
  4541. // Copy constructor.
  4542. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4543. // Index array by numeric index or specified key function.
  4544. else if (Array.isArray(object)) {
  4545. var i = -1,
  4546. n = object.length,
  4547. o;
  4548. if (f == null) while (++i < n) map.set(i, object[i]);
  4549. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4550. }
  4551. // Convert object to map.
  4552. else if (object) for (var key in object) map.set(key, object[key]);
  4553. return map;
  4554. }
  4555. function nest() {
  4556. var keys = [],
  4557. sortKeys = [],
  4558. sortValues,
  4559. rollup,
  4560. nest;
  4561. function apply(array, depth, createResult, setResult) {
  4562. if (depth >= keys.length) {
  4563. if (sortValues != null) array.sort(sortValues);
  4564. return rollup != null ? rollup(array) : array;
  4565. }
  4566. var i = -1,
  4567. n = array.length,
  4568. key = keys[depth++],
  4569. keyValue,
  4570. value,
  4571. valuesByKey = map$1(),
  4572. values,
  4573. result = createResult();
  4574. while (++i < n) {
  4575. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4576. values.push(value);
  4577. } else {
  4578. valuesByKey.set(keyValue, [value]);
  4579. }
  4580. }
  4581. valuesByKey.each(function(values, key) {
  4582. setResult(result, key, apply(values, depth, createResult, setResult));
  4583. });
  4584. return result;
  4585. }
  4586. function entries(map, depth) {
  4587. if (++depth > keys.length) return map;
  4588. var array, sortKey = sortKeys[depth - 1];
  4589. if (rollup != null && depth >= keys.length) array = map.entries();
  4590. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4591. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4592. }
  4593. return nest = {
  4594. object: function(array) { return apply(array, 0, createObject, setObject); },
  4595. map: function(array) { return apply(array, 0, createMap, setMap); },
  4596. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4597. key: function(d) { keys.push(d); return nest; },
  4598. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4599. sortValues: function(order) { sortValues = order; return nest; },
  4600. rollup: function(f) { rollup = f; return nest; }
  4601. };
  4602. }
  4603. function createObject() {
  4604. return {};
  4605. }
  4606. function setObject(object, key, value) {
  4607. object[key] = value;
  4608. }
  4609. function createMap() {
  4610. return map$1();
  4611. }
  4612. function setMap(map, key, value) {
  4613. map.set(key, value);
  4614. }
  4615. function Set() {}
  4616. var proto = map$1.prototype;
  4617. Set.prototype = set$2.prototype = {
  4618. constructor: Set,
  4619. has: proto.has,
  4620. add: function(value) {
  4621. value += "";
  4622. this[prefix + value] = value;
  4623. return this;
  4624. },
  4625. remove: proto.remove,
  4626. clear: proto.clear,
  4627. values: proto.keys,
  4628. size: proto.size,
  4629. empty: proto.empty,
  4630. each: proto.each
  4631. };
  4632. function set$2(object, f) {
  4633. var set = new Set;
  4634. // Copy constructor.
  4635. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4636. // Otherwise, assume it’s an array.
  4637. else if (object) {
  4638. var i = -1, n = object.length;
  4639. if (f == null) while (++i < n) set.add(object[i]);
  4640. else while (++i < n) set.add(f(object[i], i, object));
  4641. }
  4642. return set;
  4643. }
  4644. function keys(map) {
  4645. var keys = [];
  4646. for (var key in map) keys.push(key);
  4647. return keys;
  4648. }
  4649. function values(map) {
  4650. var values = [];
  4651. for (var key in map) values.push(map[key]);
  4652. return values;
  4653. }
  4654. function entries(map) {
  4655. var entries = [];
  4656. for (var key in map) entries.push({key: key, value: map[key]});
  4657. return entries;
  4658. }
  4659. var array$2 = Array.prototype;
  4660. var slice$3 = array$2.slice;
  4661. function ascending$2(a, b) {
  4662. return a - b;
  4663. }
  4664. function area(ring) {
  4665. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  4666. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  4667. return area;
  4668. }
  4669. function constant$6(x) {
  4670. return function() {
  4671. return x;
  4672. };
  4673. }
  4674. function contains(ring, hole) {
  4675. var i = -1, n = hole.length, c;
  4676. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  4677. return 0;
  4678. }
  4679. function ringContains(ring, point) {
  4680. var x = point[0], y = point[1], contains = -1;
  4681. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  4682. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  4683. if (segmentContains(pi, pj, point)) return 0;
  4684. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  4685. }
  4686. return contains;
  4687. }
  4688. function segmentContains(a, b, c) {
  4689. var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  4690. }
  4691. function collinear(a, b, c) {
  4692. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  4693. }
  4694. function within(p, q, r) {
  4695. return p <= q && q <= r || r <= q && q <= p;
  4696. }
  4697. function noop$1() {}
  4698. var cases = [
  4699. [],
  4700. [[[1.0, 1.5], [0.5, 1.0]]],
  4701. [[[1.5, 1.0], [1.0, 1.5]]],
  4702. [[[1.5, 1.0], [0.5, 1.0]]],
  4703. [[[1.0, 0.5], [1.5, 1.0]]],
  4704. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  4705. [[[1.0, 0.5], [1.0, 1.5]]],
  4706. [[[1.0, 0.5], [0.5, 1.0]]],
  4707. [[[0.5, 1.0], [1.0, 0.5]]],
  4708. [[[1.0, 1.5], [1.0, 0.5]]],
  4709. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  4710. [[[1.5, 1.0], [1.0, 0.5]]],
  4711. [[[0.5, 1.0], [1.5, 1.0]]],
  4712. [[[1.0, 1.5], [1.5, 1.0]]],
  4713. [[[0.5, 1.0], [1.0, 1.5]]],
  4714. []
  4715. ];
  4716. function contours() {
  4717. var dx = 1,
  4718. dy = 1,
  4719. threshold = thresholdSturges,
  4720. smooth = smoothLinear;
  4721. function contours(values) {
  4722. var tz = threshold(values);
  4723. // Convert number of thresholds into uniform thresholds.
  4724. if (!Array.isArray(tz)) {
  4725. var domain = extent(values), start = domain[0], stop = domain[1];
  4726. tz = tickStep(start, stop, tz);
  4727. tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
  4728. } else {
  4729. tz = tz.slice().sort(ascending$2);
  4730. }
  4731. return tz.map(function(value) {
  4732. return contour(values, value);
  4733. });
  4734. }
  4735. // Accumulate, smooth contour rings, assign holes to exterior rings.
  4736. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  4737. function contour(values, value) {
  4738. var polygons = [],
  4739. holes = [];
  4740. isorings(values, value, function(ring) {
  4741. smooth(ring, values, value);
  4742. if (area(ring) > 0) polygons.push([ring]);
  4743. else holes.push(ring);
  4744. });
  4745. holes.forEach(function(hole) {
  4746. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  4747. if (contains((polygon = polygons[i])[0], hole) !== -1) {
  4748. polygon.push(hole);
  4749. return;
  4750. }
  4751. }
  4752. });
  4753. return {
  4754. type: "MultiPolygon",
  4755. value: value,
  4756. coordinates: polygons
  4757. };
  4758. }
  4759. // Marching squares with isolines stitched into rings.
  4760. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  4761. function isorings(values, value, callback) {
  4762. var fragmentByStart = new Array,
  4763. fragmentByEnd = new Array,
  4764. x, y, t0, t1, t2, t3;
  4765. // Special case for the first row (y = -1, t2 = t3 = 0).
  4766. x = y = -1;
  4767. t1 = values[0] >= value;
  4768. cases[t1 << 1].forEach(stitch);
  4769. while (++x < dx - 1) {
  4770. t0 = t1, t1 = values[x + 1] >= value;
  4771. cases[t0 | t1 << 1].forEach(stitch);
  4772. }
  4773. cases[t1 << 0].forEach(stitch);
  4774. // General case for the intermediate rows.
  4775. while (++y < dy - 1) {
  4776. x = -1;
  4777. t1 = values[y * dx + dx] >= value;
  4778. t2 = values[y * dx] >= value;
  4779. cases[t1 << 1 | t2 << 2].forEach(stitch);
  4780. while (++x < dx - 1) {
  4781. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  4782. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4783. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  4784. }
  4785. cases[t1 | t2 << 3].forEach(stitch);
  4786. }
  4787. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  4788. x = -1;
  4789. t2 = values[y * dx] >= value;
  4790. cases[t2 << 2].forEach(stitch);
  4791. while (++x < dx - 1) {
  4792. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4793. cases[t2 << 2 | t3 << 3].forEach(stitch);
  4794. }
  4795. cases[t2 << 3].forEach(stitch);
  4796. function stitch(line) {
  4797. var start = [line[0][0] + x, line[0][1] + y],
  4798. end = [line[1][0] + x, line[1][1] + y],
  4799. startIndex = index(start),
  4800. endIndex = index(end),
  4801. f, g;
  4802. if (f = fragmentByEnd[startIndex]) {
  4803. if (g = fragmentByStart[endIndex]) {
  4804. delete fragmentByEnd[f.end];
  4805. delete fragmentByStart[g.start];
  4806. if (f === g) {
  4807. f.ring.push(end);
  4808. callback(f.ring);
  4809. } else {
  4810. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  4811. }
  4812. } else {
  4813. delete fragmentByEnd[f.end];
  4814. f.ring.push(end);
  4815. fragmentByEnd[f.end = endIndex] = f;
  4816. }
  4817. } else if (f = fragmentByStart[endIndex]) {
  4818. if (g = fragmentByEnd[startIndex]) {
  4819. delete fragmentByStart[f.start];
  4820. delete fragmentByEnd[g.end];
  4821. if (f === g) {
  4822. f.ring.push(end);
  4823. callback(f.ring);
  4824. } else {
  4825. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  4826. }
  4827. } else {
  4828. delete fragmentByStart[f.start];
  4829. f.ring.unshift(start);
  4830. fragmentByStart[f.start = startIndex] = f;
  4831. }
  4832. } else {
  4833. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  4834. }
  4835. }
  4836. }
  4837. function index(point) {
  4838. return point[0] * 2 + point[1] * (dx + 1) * 4;
  4839. }
  4840. function smoothLinear(ring, values, value) {
  4841. ring.forEach(function(point) {
  4842. var x = point[0],
  4843. y = point[1],
  4844. xt = x | 0,
  4845. yt = y | 0,
  4846. v0,
  4847. v1 = values[yt * dx + xt];
  4848. if (x > 0 && x < dx && xt === x) {
  4849. v0 = values[yt * dx + xt - 1];
  4850. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  4851. }
  4852. if (y > 0 && y < dy && yt === y) {
  4853. v0 = values[(yt - 1) * dx + xt];
  4854. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  4855. }
  4856. });
  4857. }
  4858. contours.contour = contour;
  4859. contours.size = function(_) {
  4860. if (!arguments.length) return [dx, dy];
  4861. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4862. if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
  4863. return dx = _0, dy = _1, contours;
  4864. };
  4865. contours.thresholds = function(_) {
  4866. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold;
  4867. };
  4868. contours.smooth = function(_) {
  4869. return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
  4870. };
  4871. return contours;
  4872. }
  4873. // TODO Optimize edge cases.
  4874. // TODO Optimize index calculation.
  4875. // TODO Optimize arguments.
  4876. function blurX(source, target, r) {
  4877. var n = source.width,
  4878. m = source.height,
  4879. w = (r << 1) + 1;
  4880. for (var j = 0; j < m; ++j) {
  4881. for (var i = 0, sr = 0; i < n + r; ++i) {
  4882. if (i < n) {
  4883. sr += source.data[i + j * n];
  4884. }
  4885. if (i >= r) {
  4886. if (i >= w) {
  4887. sr -= source.data[i - w + j * n];
  4888. }
  4889. target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
  4890. }
  4891. }
  4892. }
  4893. }
  4894. // TODO Optimize edge cases.
  4895. // TODO Optimize index calculation.
  4896. // TODO Optimize arguments.
  4897. function blurY(source, target, r) {
  4898. var n = source.width,
  4899. m = source.height,
  4900. w = (r << 1) + 1;
  4901. for (var i = 0; i < n; ++i) {
  4902. for (var j = 0, sr = 0; j < m + r; ++j) {
  4903. if (j < m) {
  4904. sr += source.data[i + j * n];
  4905. }
  4906. if (j >= r) {
  4907. if (j >= w) {
  4908. sr -= source.data[i + (j - w) * n];
  4909. }
  4910. target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
  4911. }
  4912. }
  4913. }
  4914. }
  4915. function defaultX(d) {
  4916. return d[0];
  4917. }
  4918. function defaultY(d) {
  4919. return d[1];
  4920. }
  4921. function defaultWeight() {
  4922. return 1;
  4923. }
  4924. function density() {
  4925. var x = defaultX,
  4926. y = defaultY,
  4927. weight = defaultWeight,
  4928. dx = 960,
  4929. dy = 500,
  4930. r = 20, // blur radius
  4931. k = 2, // log2(grid cell size)
  4932. o = r * 3, // grid offset, to pad for blur
  4933. n = (dx + o * 2) >> k, // grid width
  4934. m = (dy + o * 2) >> k, // grid height
  4935. threshold = constant$6(20);
  4936. function density(data) {
  4937. var values0 = new Float32Array(n * m),
  4938. values1 = new Float32Array(n * m);
  4939. data.forEach(function(d, i, data) {
  4940. var xi = (+x(d, i, data) + o) >> k,
  4941. yi = (+y(d, i, data) + o) >> k,
  4942. wi = +weight(d, i, data);
  4943. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  4944. values0[xi + yi * n] += wi;
  4945. }
  4946. });
  4947. // TODO Optimize.
  4948. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4949. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4950. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4951. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4952. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4953. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4954. var tz = threshold(values0);
  4955. // Convert number of thresholds into uniform thresholds.
  4956. if (!Array.isArray(tz)) {
  4957. var stop = max(values0);
  4958. tz = tickStep(0, stop, tz);
  4959. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  4960. tz.shift();
  4961. }
  4962. return contours()
  4963. .thresholds(tz)
  4964. .size([n, m])
  4965. (values0)
  4966. .map(transform);
  4967. }
  4968. function transform(geometry) {
  4969. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  4970. geometry.coordinates.forEach(transformPolygon);
  4971. return geometry;
  4972. }
  4973. function transformPolygon(coordinates) {
  4974. coordinates.forEach(transformRing);
  4975. }
  4976. function transformRing(coordinates) {
  4977. coordinates.forEach(transformPoint);
  4978. }
  4979. // TODO Optimize.
  4980. function transformPoint(coordinates) {
  4981. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  4982. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  4983. }
  4984. function resize() {
  4985. o = r * 3;
  4986. n = (dx + o * 2) >> k;
  4987. m = (dy + o * 2) >> k;
  4988. return density;
  4989. }
  4990. density.x = function(_) {
  4991. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  4992. };
  4993. density.y = function(_) {
  4994. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  4995. };
  4996. density.weight = function(_) {
  4997. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
  4998. };
  4999. density.size = function(_) {
  5000. if (!arguments.length) return [dx, dy];
  5001. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  5002. if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
  5003. return dx = _0, dy = _1, resize();
  5004. };
  5005. density.cellSize = function(_) {
  5006. if (!arguments.length) return 1 << k;
  5007. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  5008. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  5009. };
  5010. density.thresholds = function(_) {
  5011. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold;
  5012. };
  5013. density.bandwidth = function(_) {
  5014. if (!arguments.length) return Math.sqrt(r * (r + 1));
  5015. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  5016. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  5017. };
  5018. return density;
  5019. }
  5020. var EOL = {},
  5021. EOF = {},
  5022. QUOTE = 34,
  5023. NEWLINE = 10,
  5024. RETURN = 13;
  5025. function objectConverter(columns) {
  5026. return new Function("d", "return {" + columns.map(function(name, i) {
  5027. return JSON.stringify(name) + ": d[" + i + "] || \"\"";
  5028. }).join(",") + "}");
  5029. }
  5030. function customConverter(columns, f) {
  5031. var object = objectConverter(columns);
  5032. return function(row, i) {
  5033. return f(object(row), i, columns);
  5034. };
  5035. }
  5036. // Compute unique columns in order of discovery.
  5037. function inferColumns(rows) {
  5038. var columnSet = Object.create(null),
  5039. columns = [];
  5040. rows.forEach(function(row) {
  5041. for (var column in row) {
  5042. if (!(column in columnSet)) {
  5043. columns.push(columnSet[column] = column);
  5044. }
  5045. }
  5046. });
  5047. return columns;
  5048. }
  5049. function pad(value, width) {
  5050. var s = value + "", length = s.length;
  5051. return length < width ? new Array(width - length + 1).join(0) + s : s;
  5052. }
  5053. function formatYear(year) {
  5054. return year < 0 ? "-" + pad(-year, 6)
  5055. : year > 9999 ? "+" + pad(year, 6)
  5056. : pad(year, 4);
  5057. }
  5058. function formatDate(date) {
  5059. var hours = date.getUTCHours(),
  5060. minutes = date.getUTCMinutes(),
  5061. seconds = date.getUTCSeconds(),
  5062. milliseconds = date.getUTCMilliseconds();
  5063. return isNaN(date) ? "Invalid Date"
  5064. : formatYear(date.getUTCFullYear()) + "-" + pad(date.getUTCMonth() + 1, 2) + "-" + pad(date.getUTCDate(), 2)
  5065. + (milliseconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "." + pad(milliseconds, 3) + "Z"
  5066. : seconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "Z"
  5067. : minutes || hours ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + "Z"
  5068. : "");
  5069. }
  5070. function dsvFormat(delimiter) {
  5071. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  5072. DELIMITER = delimiter.charCodeAt(0);
  5073. function parse(text, f) {
  5074. var convert, columns, rows = parseRows(text, function(row, i) {
  5075. if (convert) return convert(row, i - 1);
  5076. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  5077. });
  5078. rows.columns = columns || [];
  5079. return rows;
  5080. }
  5081. function parseRows(text, f) {
  5082. var rows = [], // output rows
  5083. N = text.length,
  5084. I = 0, // current character index
  5085. n = 0, // current line number
  5086. t, // current token
  5087. eof = N <= 0, // current token followed by EOF?
  5088. eol = false; // current token followed by EOL?
  5089. // Strip the trailing newline.
  5090. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  5091. if (text.charCodeAt(N - 1) === RETURN) --N;
  5092. function token() {
  5093. if (eof) return EOF;
  5094. if (eol) return eol = false, EOL;
  5095. // Unescape quotes.
  5096. var i, j = I, c;
  5097. if (text.charCodeAt(j) === QUOTE) {
  5098. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  5099. if ((i = I) >= N) eof = true;
  5100. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  5101. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  5102. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  5103. }
  5104. // Find next delimiter or newline.
  5105. while (I < N) {
  5106. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  5107. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  5108. else if (c !== DELIMITER) continue;
  5109. return text.slice(j, i);
  5110. }
  5111. // Return last token before EOF.
  5112. return eof = true, text.slice(j, N);
  5113. }
  5114. while ((t = token()) !== EOF) {
  5115. var row = [];
  5116. while (t !== EOL && t !== EOF) row.push(t), t = token();
  5117. if (f && (row = f(row, n++)) == null) continue;
  5118. rows.push(row);
  5119. }
  5120. return rows;
  5121. }
  5122. function preformatBody(rows, columns) {
  5123. return rows.map(function(row) {
  5124. return columns.map(function(column) {
  5125. return formatValue(row[column]);
  5126. }).join(delimiter);
  5127. });
  5128. }
  5129. function format(rows, columns) {
  5130. if (columns == null) columns = inferColumns(rows);
  5131. return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
  5132. }
  5133. function formatBody(rows, columns) {
  5134. if (columns == null) columns = inferColumns(rows);
  5135. return preformatBody(rows, columns).join("\n");
  5136. }
  5137. function formatRows(rows) {
  5138. return rows.map(formatRow).join("\n");
  5139. }
  5140. function formatRow(row) {
  5141. return row.map(formatValue).join(delimiter);
  5142. }
  5143. function formatValue(value) {
  5144. return value == null ? ""
  5145. : value instanceof Date ? formatDate(value)
  5146. : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
  5147. : value;
  5148. }
  5149. return {
  5150. parse: parse,
  5151. parseRows: parseRows,
  5152. format: format,
  5153. formatBody: formatBody,
  5154. formatRows: formatRows,
  5155. formatRow: formatRow,
  5156. formatValue: formatValue
  5157. };
  5158. }
  5159. var csv = dsvFormat(",");
  5160. var csvParse = csv.parse;
  5161. var csvParseRows = csv.parseRows;
  5162. var csvFormat = csv.format;
  5163. var csvFormatBody = csv.formatBody;
  5164. var csvFormatRows = csv.formatRows;
  5165. var csvFormatRow = csv.formatRow;
  5166. var csvFormatValue = csv.formatValue;
  5167. var tsv = dsvFormat("\t");
  5168. var tsvParse = tsv.parse;
  5169. var tsvParseRows = tsv.parseRows;
  5170. var tsvFormat = tsv.format;
  5171. var tsvFormatBody = tsv.formatBody;
  5172. var tsvFormatRows = tsv.formatRows;
  5173. var tsvFormatRow = tsv.formatRow;
  5174. var tsvFormatValue = tsv.formatValue;
  5175. function autoType(object) {
  5176. for (var key in object) {
  5177. var value = object[key].trim(), number, m;
  5178. if (!value) value = null;
  5179. else if (value === "true") value = true;
  5180. else if (value === "false") value = false;
  5181. else if (value === "NaN") value = NaN;
  5182. else if (!isNaN(number = +value)) value = number;
  5183. 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})?)?$/)) {
  5184. if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
  5185. value = new Date(value);
  5186. }
  5187. else continue;
  5188. object[key] = value;
  5189. }
  5190. return object;
  5191. }
  5192. // https://github.com/d3/d3-dsv/issues/45
  5193. var fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
  5194. function responseBlob(response) {
  5195. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5196. return response.blob();
  5197. }
  5198. function blob(input, init) {
  5199. return fetch(input, init).then(responseBlob);
  5200. }
  5201. function responseArrayBuffer(response) {
  5202. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5203. return response.arrayBuffer();
  5204. }
  5205. function buffer(input, init) {
  5206. return fetch(input, init).then(responseArrayBuffer);
  5207. }
  5208. function responseText(response) {
  5209. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5210. return response.text();
  5211. }
  5212. function text(input, init) {
  5213. return fetch(input, init).then(responseText);
  5214. }
  5215. function dsvParse(parse) {
  5216. return function(input, init, row) {
  5217. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  5218. return text(input, init).then(function(response) {
  5219. return parse(response, row);
  5220. });
  5221. };
  5222. }
  5223. function dsv(delimiter, input, init, row) {
  5224. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  5225. var format = dsvFormat(delimiter);
  5226. return text(input, init).then(function(response) {
  5227. return format.parse(response, row);
  5228. });
  5229. }
  5230. var csv$1 = dsvParse(csvParse);
  5231. var tsv$1 = dsvParse(tsvParse);
  5232. function image(input, init) {
  5233. return new Promise(function(resolve, reject) {
  5234. var image = new Image;
  5235. for (var key in init) image[key] = init[key];
  5236. image.onerror = reject;
  5237. image.onload = function() { resolve(image); };
  5238. image.src = input;
  5239. });
  5240. }
  5241. function responseJson(response) {
  5242. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5243. return response.json();
  5244. }
  5245. function json(input, init) {
  5246. return fetch(input, init).then(responseJson);
  5247. }
  5248. function parser(type) {
  5249. return function(input, init) {
  5250. return text(input, init).then(function(text) {
  5251. return (new DOMParser).parseFromString(text, type);
  5252. });
  5253. };
  5254. }
  5255. var xml = parser("application/xml");
  5256. var html = parser("text/html");
  5257. var svg = parser("image/svg+xml");
  5258. function center$1(x, y) {
  5259. var nodes;
  5260. if (x == null) x = 0;
  5261. if (y == null) y = 0;
  5262. function force() {
  5263. var i,
  5264. n = nodes.length,
  5265. node,
  5266. sx = 0,
  5267. sy = 0;
  5268. for (i = 0; i < n; ++i) {
  5269. node = nodes[i], sx += node.x, sy += node.y;
  5270. }
  5271. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  5272. node = nodes[i], node.x -= sx, node.y -= sy;
  5273. }
  5274. }
  5275. force.initialize = function(_) {
  5276. nodes = _;
  5277. };
  5278. force.x = function(_) {
  5279. return arguments.length ? (x = +_, force) : x;
  5280. };
  5281. force.y = function(_) {
  5282. return arguments.length ? (y = +_, force) : y;
  5283. };
  5284. return force;
  5285. }
  5286. function constant$7(x) {
  5287. return function() {
  5288. return x;
  5289. };
  5290. }
  5291. function jiggle() {
  5292. return (Math.random() - 0.5) * 1e-6;
  5293. }
  5294. function tree_add(d) {
  5295. var x = +this._x.call(null, d),
  5296. y = +this._y.call(null, d);
  5297. return add(this.cover(x, y), x, y, d);
  5298. }
  5299. function add(tree, x, y, d) {
  5300. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  5301. var parent,
  5302. node = tree._root,
  5303. leaf = {data: d},
  5304. x0 = tree._x0,
  5305. y0 = tree._y0,
  5306. x1 = tree._x1,
  5307. y1 = tree._y1,
  5308. xm,
  5309. ym,
  5310. xp,
  5311. yp,
  5312. right,
  5313. bottom,
  5314. i,
  5315. j;
  5316. // If the tree is empty, initialize the root as a leaf.
  5317. if (!node) return tree._root = leaf, tree;
  5318. // Find the existing leaf for the new point, or add it.
  5319. while (node.length) {
  5320. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5321. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5322. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  5323. }
  5324. // Is the new point is exactly coincident with the existing point?
  5325. xp = +tree._x.call(null, node.data);
  5326. yp = +tree._y.call(null, node.data);
  5327. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  5328. // Otherwise, split the leaf node until the old and new point are separated.
  5329. do {
  5330. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  5331. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5332. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5333. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  5334. return parent[j] = node, parent[i] = leaf, tree;
  5335. }
  5336. function addAll(data) {
  5337. var d, i, n = data.length,
  5338. x,
  5339. y,
  5340. xz = new Array(n),
  5341. yz = new Array(n),
  5342. x0 = Infinity,
  5343. y0 = Infinity,
  5344. x1 = -Infinity,
  5345. y1 = -Infinity;
  5346. // Compute the points and their extent.
  5347. for (i = 0; i < n; ++i) {
  5348. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  5349. xz[i] = x;
  5350. yz[i] = y;
  5351. if (x < x0) x0 = x;
  5352. if (x > x1) x1 = x;
  5353. if (y < y0) y0 = y;
  5354. if (y > y1) y1 = y;
  5355. }
  5356. // If there were no (valid) points, abort.
  5357. if (x0 > x1 || y0 > y1) return this;
  5358. // Expand the tree to cover the new points.
  5359. this.cover(x0, y0).cover(x1, y1);
  5360. // Add the new points.
  5361. for (i = 0; i < n; ++i) {
  5362. add(this, xz[i], yz[i], data[i]);
  5363. }
  5364. return this;
  5365. }
  5366. function tree_cover(x, y) {
  5367. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  5368. var x0 = this._x0,
  5369. y0 = this._y0,
  5370. x1 = this._x1,
  5371. y1 = this._y1;
  5372. // If the quadtree has no extent, initialize them.
  5373. // Integer extent are necessary so that if we later double the extent,
  5374. // the existing quadrant boundaries don’t change due to floating point error!
  5375. if (isNaN(x0)) {
  5376. x1 = (x0 = Math.floor(x)) + 1;
  5377. y1 = (y0 = Math.floor(y)) + 1;
  5378. }
  5379. // Otherwise, double repeatedly to cover.
  5380. else {
  5381. var z = x1 - x0,
  5382. node = this._root,
  5383. parent,
  5384. i;
  5385. while (x0 > x || x >= x1 || y0 > y || y >= y1) {
  5386. i = (y < y0) << 1 | (x < x0);
  5387. parent = new Array(4), parent[i] = node, node = parent, z *= 2;
  5388. switch (i) {
  5389. case 0: x1 = x0 + z, y1 = y0 + z; break;
  5390. case 1: x0 = x1 - z, y1 = y0 + z; break;
  5391. case 2: x1 = x0 + z, y0 = y1 - z; break;
  5392. case 3: x0 = x1 - z, y0 = y1 - z; break;
  5393. }
  5394. }
  5395. if (this._root && this._root.length) this._root = node;
  5396. }
  5397. this._x0 = x0;
  5398. this._y0 = y0;
  5399. this._x1 = x1;
  5400. this._y1 = y1;
  5401. return this;
  5402. }
  5403. function tree_data() {
  5404. var data = [];
  5405. this.visit(function(node) {
  5406. if (!node.length) do data.push(node.data); while (node = node.next)
  5407. });
  5408. return data;
  5409. }
  5410. function tree_extent(_) {
  5411. return arguments.length
  5412. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  5413. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  5414. }
  5415. function Quad(node, x0, y0, x1, y1) {
  5416. this.node = node;
  5417. this.x0 = x0;
  5418. this.y0 = y0;
  5419. this.x1 = x1;
  5420. this.y1 = y1;
  5421. }
  5422. function tree_find(x, y, radius) {
  5423. var data,
  5424. x0 = this._x0,
  5425. y0 = this._y0,
  5426. x1,
  5427. y1,
  5428. x2,
  5429. y2,
  5430. x3 = this._x1,
  5431. y3 = this._y1,
  5432. quads = [],
  5433. node = this._root,
  5434. q,
  5435. i;
  5436. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  5437. if (radius == null) radius = Infinity;
  5438. else {
  5439. x0 = x - radius, y0 = y - radius;
  5440. x3 = x + radius, y3 = y + radius;
  5441. radius *= radius;
  5442. }
  5443. while (q = quads.pop()) {
  5444. // Stop searching if this quadrant can’t contain a closer node.
  5445. if (!(node = q.node)
  5446. || (x1 = q.x0) > x3
  5447. || (y1 = q.y0) > y3
  5448. || (x2 = q.x1) < x0
  5449. || (y2 = q.y1) < y0) continue;
  5450. // Bisect the current quadrant.
  5451. if (node.length) {
  5452. var xm = (x1 + x2) / 2,
  5453. ym = (y1 + y2) / 2;
  5454. quads.push(
  5455. new Quad(node[3], xm, ym, x2, y2),
  5456. new Quad(node[2], x1, ym, xm, y2),
  5457. new Quad(node[1], xm, y1, x2, ym),
  5458. new Quad(node[0], x1, y1, xm, ym)
  5459. );
  5460. // Visit the closest quadrant first.
  5461. if (i = (y >= ym) << 1 | (x >= xm)) {
  5462. q = quads[quads.length - 1];
  5463. quads[quads.length - 1] = quads[quads.length - 1 - i];
  5464. quads[quads.length - 1 - i] = q;
  5465. }
  5466. }
  5467. // Visit this point. (Visiting coincident points isn’t necessary!)
  5468. else {
  5469. var dx = x - +this._x.call(null, node.data),
  5470. dy = y - +this._y.call(null, node.data),
  5471. d2 = dx * dx + dy * dy;
  5472. if (d2 < radius) {
  5473. var d = Math.sqrt(radius = d2);
  5474. x0 = x - d, y0 = y - d;
  5475. x3 = x + d, y3 = y + d;
  5476. data = node.data;
  5477. }
  5478. }
  5479. }
  5480. return data;
  5481. }
  5482. function tree_remove(d) {
  5483. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  5484. var parent,
  5485. node = this._root,
  5486. retainer,
  5487. previous,
  5488. next,
  5489. x0 = this._x0,
  5490. y0 = this._y0,
  5491. x1 = this._x1,
  5492. y1 = this._y1,
  5493. x,
  5494. y,
  5495. xm,
  5496. ym,
  5497. right,
  5498. bottom,
  5499. i,
  5500. j;
  5501. // If the tree is empty, initialize the root as a leaf.
  5502. if (!node) return this;
  5503. // Find the leaf node for the point.
  5504. // While descending, also retain the deepest parent with a non-removed sibling.
  5505. if (node.length) while (true) {
  5506. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5507. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5508. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  5509. if (!node.length) break;
  5510. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  5511. }
  5512. // Find the point to remove.
  5513. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  5514. if (next = node.next) delete node.next;
  5515. // If there are multiple coincident points, remove just the point.
  5516. if (previous) return (next ? previous.next = next : delete previous.next), this;
  5517. // If this is the root point, remove it.
  5518. if (!parent) return this._root = next, this;
  5519. // Remove this leaf.
  5520. next ? parent[i] = next : delete parent[i];
  5521. // If the parent now contains exactly one leaf, collapse superfluous parents.
  5522. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  5523. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  5524. && !node.length) {
  5525. if (retainer) retainer[j] = node;
  5526. else this._root = node;
  5527. }
  5528. return this;
  5529. }
  5530. function removeAll(data) {
  5531. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  5532. return this;
  5533. }
  5534. function tree_root() {
  5535. return this._root;
  5536. }
  5537. function tree_size() {
  5538. var size = 0;
  5539. this.visit(function(node) {
  5540. if (!node.length) do ++size; while (node = node.next)
  5541. });
  5542. return size;
  5543. }
  5544. function tree_visit(callback) {
  5545. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  5546. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  5547. while (q = quads.pop()) {
  5548. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  5549. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5550. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5551. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5552. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5553. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5554. }
  5555. }
  5556. return this;
  5557. }
  5558. function tree_visitAfter(callback) {
  5559. var quads = [], next = [], q;
  5560. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  5561. while (q = quads.pop()) {
  5562. var node = q.node;
  5563. if (node.length) {
  5564. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5565. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5566. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5567. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5568. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5569. }
  5570. next.push(q);
  5571. }
  5572. while (q = next.pop()) {
  5573. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  5574. }
  5575. return this;
  5576. }
  5577. function defaultX$1(d) {
  5578. return d[0];
  5579. }
  5580. function tree_x(_) {
  5581. return arguments.length ? (this._x = _, this) : this._x;
  5582. }
  5583. function defaultY$1(d) {
  5584. return d[1];
  5585. }
  5586. function tree_y(_) {
  5587. return arguments.length ? (this._y = _, this) : this._y;
  5588. }
  5589. function quadtree(nodes, x, y) {
  5590. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  5591. return nodes == null ? tree : tree.addAll(nodes);
  5592. }
  5593. function Quadtree(x, y, x0, y0, x1, y1) {
  5594. this._x = x;
  5595. this._y = y;
  5596. this._x0 = x0;
  5597. this._y0 = y0;
  5598. this._x1 = x1;
  5599. this._y1 = y1;
  5600. this._root = undefined;
  5601. }
  5602. function leaf_copy(leaf) {
  5603. var copy = {data: leaf.data}, next = copy;
  5604. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  5605. return copy;
  5606. }
  5607. var treeProto = quadtree.prototype = Quadtree.prototype;
  5608. treeProto.copy = function() {
  5609. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  5610. node = this._root,
  5611. nodes,
  5612. child;
  5613. if (!node) return copy;
  5614. if (!node.length) return copy._root = leaf_copy(node), copy;
  5615. nodes = [{source: node, target: copy._root = new Array(4)}];
  5616. while (node = nodes.pop()) {
  5617. for (var i = 0; i < 4; ++i) {
  5618. if (child = node.source[i]) {
  5619. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  5620. else node.target[i] = leaf_copy(child);
  5621. }
  5622. }
  5623. }
  5624. return copy;
  5625. };
  5626. treeProto.add = tree_add;
  5627. treeProto.addAll = addAll;
  5628. treeProto.cover = tree_cover;
  5629. treeProto.data = tree_data;
  5630. treeProto.extent = tree_extent;
  5631. treeProto.find = tree_find;
  5632. treeProto.remove = tree_remove;
  5633. treeProto.removeAll = removeAll;
  5634. treeProto.root = tree_root;
  5635. treeProto.size = tree_size;
  5636. treeProto.visit = tree_visit;
  5637. treeProto.visitAfter = tree_visitAfter;
  5638. treeProto.x = tree_x;
  5639. treeProto.y = tree_y;
  5640. function x(d) {
  5641. return d.x + d.vx;
  5642. }
  5643. function y(d) {
  5644. return d.y + d.vy;
  5645. }
  5646. function collide(radius) {
  5647. var nodes,
  5648. radii,
  5649. strength = 1,
  5650. iterations = 1;
  5651. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  5652. function force() {
  5653. var i, n = nodes.length,
  5654. tree,
  5655. node,
  5656. xi,
  5657. yi,
  5658. ri,
  5659. ri2;
  5660. for (var k = 0; k < iterations; ++k) {
  5661. tree = quadtree(nodes, x, y).visitAfter(prepare);
  5662. for (i = 0; i < n; ++i) {
  5663. node = nodes[i];
  5664. ri = radii[node.index], ri2 = ri * ri;
  5665. xi = node.x + node.vx;
  5666. yi = node.y + node.vy;
  5667. tree.visit(apply);
  5668. }
  5669. }
  5670. function apply(quad, x0, y0, x1, y1) {
  5671. var data = quad.data, rj = quad.r, r = ri + rj;
  5672. if (data) {
  5673. if (data.index > node.index) {
  5674. var x = xi - data.x - data.vx,
  5675. y = yi - data.y - data.vy,
  5676. l = x * x + y * y;
  5677. if (l < r * r) {
  5678. if (x === 0) x = jiggle(), l += x * x;
  5679. if (y === 0) y = jiggle(), l += y * y;
  5680. l = (r - (l = Math.sqrt(l))) / l * strength;
  5681. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5682. node.vy += (y *= l) * r;
  5683. data.vx -= x * (r = 1 - r);
  5684. data.vy -= y * r;
  5685. }
  5686. }
  5687. return;
  5688. }
  5689. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5690. }
  5691. }
  5692. function prepare(quad) {
  5693. if (quad.data) return quad.r = radii[quad.data.index];
  5694. for (var i = quad.r = 0; i < 4; ++i) {
  5695. if (quad[i] && quad[i].r > quad.r) {
  5696. quad.r = quad[i].r;
  5697. }
  5698. }
  5699. }
  5700. function initialize() {
  5701. if (!nodes) return;
  5702. var i, n = nodes.length, node;
  5703. radii = new Array(n);
  5704. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5705. }
  5706. force.initialize = function(_) {
  5707. nodes = _;
  5708. initialize();
  5709. };
  5710. force.iterations = function(_) {
  5711. return arguments.length ? (iterations = +_, force) : iterations;
  5712. };
  5713. force.strength = function(_) {
  5714. return arguments.length ? (strength = +_, force) : strength;
  5715. };
  5716. force.radius = function(_) {
  5717. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5718. };
  5719. return force;
  5720. }
  5721. function index(d) {
  5722. return d.index;
  5723. }
  5724. function find(nodeById, nodeId) {
  5725. var node = nodeById.get(nodeId);
  5726. if (!node) throw new Error("missing: " + nodeId);
  5727. return node;
  5728. }
  5729. function link(links) {
  5730. var id = index,
  5731. strength = defaultStrength,
  5732. strengths,
  5733. distance = constant$7(30),
  5734. distances,
  5735. nodes,
  5736. count,
  5737. bias,
  5738. iterations = 1;
  5739. if (links == null) links = [];
  5740. function defaultStrength(link) {
  5741. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5742. }
  5743. function force(alpha) {
  5744. for (var k = 0, n = links.length; k < iterations; ++k) {
  5745. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5746. link = links[i], source = link.source, target = link.target;
  5747. x = target.x + target.vx - source.x - source.vx || jiggle();
  5748. y = target.y + target.vy - source.y - source.vy || jiggle();
  5749. l = Math.sqrt(x * x + y * y);
  5750. l = (l - distances[i]) / l * alpha * strengths[i];
  5751. x *= l, y *= l;
  5752. target.vx -= x * (b = bias[i]);
  5753. target.vy -= y * b;
  5754. source.vx += x * (b = 1 - b);
  5755. source.vy += y * b;
  5756. }
  5757. }
  5758. }
  5759. function initialize() {
  5760. if (!nodes) return;
  5761. var i,
  5762. n = nodes.length,
  5763. m = links.length,
  5764. nodeById = map$1(nodes, id),
  5765. link;
  5766. for (i = 0, count = new Array(n); i < m; ++i) {
  5767. link = links[i], link.index = i;
  5768. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5769. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5770. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5771. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5772. }
  5773. for (i = 0, bias = new Array(m); i < m; ++i) {
  5774. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5775. }
  5776. strengths = new Array(m), initializeStrength();
  5777. distances = new Array(m), initializeDistance();
  5778. }
  5779. function initializeStrength() {
  5780. if (!nodes) return;
  5781. for (var i = 0, n = links.length; i < n; ++i) {
  5782. strengths[i] = +strength(links[i], i, links);
  5783. }
  5784. }
  5785. function initializeDistance() {
  5786. if (!nodes) return;
  5787. for (var i = 0, n = links.length; i < n; ++i) {
  5788. distances[i] = +distance(links[i], i, links);
  5789. }
  5790. }
  5791. force.initialize = function(_) {
  5792. nodes = _;
  5793. initialize();
  5794. };
  5795. force.links = function(_) {
  5796. return arguments.length ? (links = _, initialize(), force) : links;
  5797. };
  5798. force.id = function(_) {
  5799. return arguments.length ? (id = _, force) : id;
  5800. };
  5801. force.iterations = function(_) {
  5802. return arguments.length ? (iterations = +_, force) : iterations;
  5803. };
  5804. force.strength = function(_) {
  5805. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  5806. };
  5807. force.distance = function(_) {
  5808. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  5809. };
  5810. return force;
  5811. }
  5812. function x$1(d) {
  5813. return d.x;
  5814. }
  5815. function y$1(d) {
  5816. return d.y;
  5817. }
  5818. var initialRadius = 10,
  5819. initialAngle = Math.PI * (3 - Math.sqrt(5));
  5820. function simulation(nodes) {
  5821. var simulation,
  5822. alpha = 1,
  5823. alphaMin = 0.001,
  5824. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5825. alphaTarget = 0,
  5826. velocityDecay = 0.6,
  5827. forces = map$1(),
  5828. stepper = timer(step),
  5829. event = dispatch("tick", "end");
  5830. if (nodes == null) nodes = [];
  5831. function step() {
  5832. tick();
  5833. event.call("tick", simulation);
  5834. if (alpha < alphaMin) {
  5835. stepper.stop();
  5836. event.call("end", simulation);
  5837. }
  5838. }
  5839. function tick(iterations) {
  5840. var i, n = nodes.length, node;
  5841. if (iterations === undefined) iterations = 1;
  5842. for (var k = 0; k < iterations; ++k) {
  5843. alpha += (alphaTarget - alpha) * alphaDecay;
  5844. forces.each(function (force) {
  5845. force(alpha);
  5846. });
  5847. for (i = 0; i < n; ++i) {
  5848. node = nodes[i];
  5849. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5850. else node.x = node.fx, node.vx = 0;
  5851. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5852. else node.y = node.fy, node.vy = 0;
  5853. }
  5854. }
  5855. return simulation;
  5856. }
  5857. function initializeNodes() {
  5858. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5859. node = nodes[i], node.index = i;
  5860. if (node.fx != null) node.x = node.fx;
  5861. if (node.fy != null) node.y = node.fy;
  5862. if (isNaN(node.x) || isNaN(node.y)) {
  5863. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5864. node.x = radius * Math.cos(angle);
  5865. node.y = radius * Math.sin(angle);
  5866. }
  5867. if (isNaN(node.vx) || isNaN(node.vy)) {
  5868. node.vx = node.vy = 0;
  5869. }
  5870. }
  5871. }
  5872. function initializeForce(force) {
  5873. if (force.initialize) force.initialize(nodes);
  5874. return force;
  5875. }
  5876. initializeNodes();
  5877. return simulation = {
  5878. tick: tick,
  5879. restart: function() {
  5880. return stepper.restart(step), simulation;
  5881. },
  5882. stop: function() {
  5883. return stepper.stop(), simulation;
  5884. },
  5885. nodes: function(_) {
  5886. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5887. },
  5888. alpha: function(_) {
  5889. return arguments.length ? (alpha = +_, simulation) : alpha;
  5890. },
  5891. alphaMin: function(_) {
  5892. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5893. },
  5894. alphaDecay: function(_) {
  5895. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5896. },
  5897. alphaTarget: function(_) {
  5898. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5899. },
  5900. velocityDecay: function(_) {
  5901. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5902. },
  5903. force: function(name, _) {
  5904. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  5905. },
  5906. find: function(x, y, radius) {
  5907. var i = 0,
  5908. n = nodes.length,
  5909. dx,
  5910. dy,
  5911. d2,
  5912. node,
  5913. closest;
  5914. if (radius == null) radius = Infinity;
  5915. else radius *= radius;
  5916. for (i = 0; i < n; ++i) {
  5917. node = nodes[i];
  5918. dx = x - node.x;
  5919. dy = y - node.y;
  5920. d2 = dx * dx + dy * dy;
  5921. if (d2 < radius) closest = node, radius = d2;
  5922. }
  5923. return closest;
  5924. },
  5925. on: function(name, _) {
  5926. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5927. }
  5928. };
  5929. }
  5930. function manyBody() {
  5931. var nodes,
  5932. node,
  5933. alpha,
  5934. strength = constant$7(-30),
  5935. strengths,
  5936. distanceMin2 = 1,
  5937. distanceMax2 = Infinity,
  5938. theta2 = 0.81;
  5939. function force(_) {
  5940. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5941. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5942. }
  5943. function initialize() {
  5944. if (!nodes) return;
  5945. var i, n = nodes.length, node;
  5946. strengths = new Array(n);
  5947. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5948. }
  5949. function accumulate(quad) {
  5950. var strength = 0, q, c, weight = 0, x, y, i;
  5951. // For internal nodes, accumulate forces from child quadrants.
  5952. if (quad.length) {
  5953. for (x = y = i = 0; i < 4; ++i) {
  5954. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5955. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5956. }
  5957. }
  5958. quad.x = x / weight;
  5959. quad.y = y / weight;
  5960. }
  5961. // For leaf nodes, accumulate forces from coincident quadrants.
  5962. else {
  5963. q = quad;
  5964. q.x = q.data.x;
  5965. q.y = q.data.y;
  5966. do strength += strengths[q.data.index];
  5967. while (q = q.next);
  5968. }
  5969. quad.value = strength;
  5970. }
  5971. function apply(quad, x1, _, x2) {
  5972. if (!quad.value) return true;
  5973. var x = quad.x - node.x,
  5974. y = quad.y - node.y,
  5975. w = x2 - x1,
  5976. l = x * x + y * y;
  5977. // Apply the Barnes-Hut approximation if possible.
  5978. // Limit forces for very close nodes; randomize direction if coincident.
  5979. if (w * w / theta2 < l) {
  5980. if (l < distanceMax2) {
  5981. if (x === 0) x = jiggle(), l += x * x;
  5982. if (y === 0) y = jiggle(), l += y * y;
  5983. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5984. node.vx += x * quad.value * alpha / l;
  5985. node.vy += y * quad.value * alpha / l;
  5986. }
  5987. return true;
  5988. }
  5989. // Otherwise, process points directly.
  5990. else if (quad.length || l >= distanceMax2) return;
  5991. // Limit forces for very close nodes; randomize direction if coincident.
  5992. if (quad.data !== node || quad.next) {
  5993. if (x === 0) x = jiggle(), l += x * x;
  5994. if (y === 0) y = jiggle(), l += y * y;
  5995. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5996. }
  5997. do if (quad.data !== node) {
  5998. w = strengths[quad.data.index] * alpha / l;
  5999. node.vx += x * w;
  6000. node.vy += y * w;
  6001. } while (quad = quad.next);
  6002. }
  6003. force.initialize = function(_) {
  6004. nodes = _;
  6005. initialize();
  6006. };
  6007. force.strength = function(_) {
  6008. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6009. };
  6010. force.distanceMin = function(_) {
  6011. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  6012. };
  6013. force.distanceMax = function(_) {
  6014. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  6015. };
  6016. force.theta = function(_) {
  6017. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  6018. };
  6019. return force;
  6020. }
  6021. function radial(radius, x, y) {
  6022. var nodes,
  6023. strength = constant$7(0.1),
  6024. strengths,
  6025. radiuses;
  6026. if (typeof radius !== "function") radius = constant$7(+radius);
  6027. if (x == null) x = 0;
  6028. if (y == null) y = 0;
  6029. function force(alpha) {
  6030. for (var i = 0, n = nodes.length; i < n; ++i) {
  6031. var node = nodes[i],
  6032. dx = node.x - x || 1e-6,
  6033. dy = node.y - y || 1e-6,
  6034. r = Math.sqrt(dx * dx + dy * dy),
  6035. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  6036. node.vx += dx * k;
  6037. node.vy += dy * k;
  6038. }
  6039. }
  6040. function initialize() {
  6041. if (!nodes) return;
  6042. var i, n = nodes.length;
  6043. strengths = new Array(n);
  6044. radiuses = new Array(n);
  6045. for (i = 0; i < n; ++i) {
  6046. radiuses[i] = +radius(nodes[i], i, nodes);
  6047. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  6048. }
  6049. }
  6050. force.initialize = function(_) {
  6051. nodes = _, initialize();
  6052. };
  6053. force.strength = function(_) {
  6054. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6055. };
  6056. force.radius = function(_) {
  6057. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  6058. };
  6059. force.x = function(_) {
  6060. return arguments.length ? (x = +_, force) : x;
  6061. };
  6062. force.y = function(_) {
  6063. return arguments.length ? (y = +_, force) : y;
  6064. };
  6065. return force;
  6066. }
  6067. function x$2(x) {
  6068. var strength = constant$7(0.1),
  6069. nodes,
  6070. strengths,
  6071. xz;
  6072. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  6073. function force(alpha) {
  6074. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  6075. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  6076. }
  6077. }
  6078. function initialize() {
  6079. if (!nodes) return;
  6080. var i, n = nodes.length;
  6081. strengths = new Array(n);
  6082. xz = new Array(n);
  6083. for (i = 0; i < n; ++i) {
  6084. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  6085. }
  6086. }
  6087. force.initialize = function(_) {
  6088. nodes = _;
  6089. initialize();
  6090. };
  6091. force.strength = function(_) {
  6092. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6093. };
  6094. force.x = function(_) {
  6095. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  6096. };
  6097. return force;
  6098. }
  6099. function y$2(y) {
  6100. var strength = constant$7(0.1),
  6101. nodes,
  6102. strengths,
  6103. yz;
  6104. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  6105. function force(alpha) {
  6106. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  6107. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  6108. }
  6109. }
  6110. function initialize() {
  6111. if (!nodes) return;
  6112. var i, n = nodes.length;
  6113. strengths = new Array(n);
  6114. yz = new Array(n);
  6115. for (i = 0; i < n; ++i) {
  6116. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  6117. }
  6118. }
  6119. force.initialize = function(_) {
  6120. nodes = _;
  6121. initialize();
  6122. };
  6123. force.strength = function(_) {
  6124. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6125. };
  6126. force.y = function(_) {
  6127. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  6128. };
  6129. return force;
  6130. }
  6131. // Computes the decimal coefficient and exponent of the specified number x with
  6132. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  6133. // For example, formatDecimal(1.23) returns ["123", 0].
  6134. function formatDecimal(x, p) {
  6135. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  6136. var i, coefficient = x.slice(0, i);
  6137. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  6138. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  6139. return [
  6140. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  6141. +x.slice(i + 1)
  6142. ];
  6143. }
  6144. function exponent$1(x) {
  6145. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  6146. }
  6147. function formatGroup(grouping, thousands) {
  6148. return function(value, width) {
  6149. var i = value.length,
  6150. t = [],
  6151. j = 0,
  6152. g = grouping[0],
  6153. length = 0;
  6154. while (i > 0 && g > 0) {
  6155. if (length + g + 1 > width) g = Math.max(1, width - length);
  6156. t.push(value.substring(i -= g, i + g));
  6157. if ((length += g + 1) > width) break;
  6158. g = grouping[j = (j + 1) % grouping.length];
  6159. }
  6160. return t.reverse().join(thousands);
  6161. };
  6162. }
  6163. function formatNumerals(numerals) {
  6164. return function(value) {
  6165. return value.replace(/[0-9]/g, function(i) {
  6166. return numerals[+i];
  6167. });
  6168. };
  6169. }
  6170. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  6171. var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  6172. function formatSpecifier(specifier) {
  6173. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  6174. var match;
  6175. return new FormatSpecifier({
  6176. fill: match[1],
  6177. align: match[2],
  6178. sign: match[3],
  6179. symbol: match[4],
  6180. zero: match[5],
  6181. width: match[6],
  6182. comma: match[7],
  6183. precision: match[8] && match[8].slice(1),
  6184. trim: match[9],
  6185. type: match[10]
  6186. });
  6187. }
  6188. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  6189. function FormatSpecifier(specifier) {
  6190. this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
  6191. this.align = specifier.align === undefined ? ">" : specifier.align + "";
  6192. this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
  6193. this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
  6194. this.zero = !!specifier.zero;
  6195. this.width = specifier.width === undefined ? undefined : +specifier.width;
  6196. this.comma = !!specifier.comma;
  6197. this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
  6198. this.trim = !!specifier.trim;
  6199. this.type = specifier.type === undefined ? "" : specifier.type + "";
  6200. }
  6201. FormatSpecifier.prototype.toString = function() {
  6202. return this.fill
  6203. + this.align
  6204. + this.sign
  6205. + this.symbol
  6206. + (this.zero ? "0" : "")
  6207. + (this.width === undefined ? "" : Math.max(1, this.width | 0))
  6208. + (this.comma ? "," : "")
  6209. + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
  6210. + (this.trim ? "~" : "")
  6211. + this.type;
  6212. };
  6213. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  6214. function formatTrim(s) {
  6215. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  6216. switch (s[i]) {
  6217. case ".": i0 = i1 = i; break;
  6218. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  6219. default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
  6220. }
  6221. }
  6222. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  6223. }
  6224. var prefixExponent;
  6225. function formatPrefixAuto(x, p) {
  6226. var d = formatDecimal(x, p);
  6227. if (!d) return x + "";
  6228. var coefficient = d[0],
  6229. exponent = d[1],
  6230. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  6231. n = coefficient.length;
  6232. return i === n ? coefficient
  6233. : i > n ? coefficient + new Array(i - n + 1).join("0")
  6234. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  6235. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  6236. }
  6237. function formatRounded(x, p) {
  6238. var d = formatDecimal(x, p);
  6239. if (!d) return x + "";
  6240. var coefficient = d[0],
  6241. exponent = d[1];
  6242. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  6243. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  6244. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  6245. }
  6246. var formatTypes = {
  6247. "%": function(x, p) { return (x * 100).toFixed(p); },
  6248. "b": function(x) { return Math.round(x).toString(2); },
  6249. "c": function(x) { return x + ""; },
  6250. "d": function(x) { return Math.round(x).toString(10); },
  6251. "e": function(x, p) { return x.toExponential(p); },
  6252. "f": function(x, p) { return x.toFixed(p); },
  6253. "g": function(x, p) { return x.toPrecision(p); },
  6254. "o": function(x) { return Math.round(x).toString(8); },
  6255. "p": function(x, p) { return formatRounded(x * 100, p); },
  6256. "r": formatRounded,
  6257. "s": formatPrefixAuto,
  6258. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  6259. "x": function(x) { return Math.round(x).toString(16); }
  6260. };
  6261. function identity$3(x) {
  6262. return x;
  6263. }
  6264. var map$2 = Array.prototype.map,
  6265. prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  6266. function formatLocale(locale) {
  6267. var group = locale.grouping === undefined || locale.thousands === undefined ? identity$3 : formatGroup(map$2.call(locale.grouping, Number), locale.thousands + ""),
  6268. currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
  6269. currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
  6270. decimal = locale.decimal === undefined ? "." : locale.decimal + "",
  6271. numerals = locale.numerals === undefined ? identity$3 : formatNumerals(map$2.call(locale.numerals, String)),
  6272. percent = locale.percent === undefined ? "%" : locale.percent + "",
  6273. minus = locale.minus === undefined ? "-" : locale.minus + "",
  6274. nan = locale.nan === undefined ? "NaN" : locale.nan + "";
  6275. function newFormat(specifier) {
  6276. specifier = formatSpecifier(specifier);
  6277. var fill = specifier.fill,
  6278. align = specifier.align,
  6279. sign = specifier.sign,
  6280. symbol = specifier.symbol,
  6281. zero = specifier.zero,
  6282. width = specifier.width,
  6283. comma = specifier.comma,
  6284. precision = specifier.precision,
  6285. trim = specifier.trim,
  6286. type = specifier.type;
  6287. // The "n" type is an alias for ",g".
  6288. if (type === "n") comma = true, type = "g";
  6289. // The "" type, and any invalid type, is an alias for ".12~g".
  6290. else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
  6291. // If zero fill is specified, padding goes after sign and before digits.
  6292. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  6293. // Compute the prefix and suffix.
  6294. // For SI-prefix, the suffix is lazily computed.
  6295. var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  6296. suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
  6297. // What format function should we use?
  6298. // Is this an integer type?
  6299. // Can this type generate exponential notation?
  6300. var formatType = formatTypes[type],
  6301. maybeSuffix = /[defgprs%]/.test(type);
  6302. // Set the default precision if not specified,
  6303. // or clamp the specified precision to the supported range.
  6304. // For significant precision, it must be in [1, 21].
  6305. // For fixed precision, it must be in [0, 20].
  6306. precision = precision === undefined ? 6
  6307. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  6308. : Math.max(0, Math.min(20, precision));
  6309. function format(value) {
  6310. var valuePrefix = prefix,
  6311. valueSuffix = suffix,
  6312. i, n, c;
  6313. if (type === "c") {
  6314. valueSuffix = formatType(value) + valueSuffix;
  6315. value = "";
  6316. } else {
  6317. value = +value;
  6318. // Determine the sign. -0 is not less than 0, but 1 / -0 is!
  6319. var valueNegative = value < 0 || 1 / value < 0;
  6320. // Perform the initial formatting.
  6321. value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
  6322. // Trim insignificant zeros.
  6323. if (trim) value = formatTrim(value);
  6324. // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
  6325. if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
  6326. // Compute the prefix and suffix.
  6327. valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  6328. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  6329. // Break the formatted value into the integer “value” part that can be
  6330. // grouped, and fractional or exponential “suffix” part that is not.
  6331. if (maybeSuffix) {
  6332. i = -1, n = value.length;
  6333. while (++i < n) {
  6334. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  6335. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  6336. value = value.slice(0, i);
  6337. break;
  6338. }
  6339. }
  6340. }
  6341. }
  6342. // If the fill character is not "0", grouping is applied before padding.
  6343. if (comma && !zero) value = group(value, Infinity);
  6344. // Compute the padding.
  6345. var length = valuePrefix.length + value.length + valueSuffix.length,
  6346. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  6347. // If the fill character is "0", grouping is applied after padding.
  6348. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  6349. // Reconstruct the final output based on the desired alignment.
  6350. switch (align) {
  6351. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  6352. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  6353. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  6354. default: value = padding + valuePrefix + value + valueSuffix; break;
  6355. }
  6356. return numerals(value);
  6357. }
  6358. format.toString = function() {
  6359. return specifier + "";
  6360. };
  6361. return format;
  6362. }
  6363. function formatPrefix(specifier, value) {
  6364. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  6365. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  6366. k = Math.pow(10, -e),
  6367. prefix = prefixes[8 + e / 3];
  6368. return function(value) {
  6369. return f(k * value) + prefix;
  6370. };
  6371. }
  6372. return {
  6373. format: newFormat,
  6374. formatPrefix: formatPrefix
  6375. };
  6376. }
  6377. var locale;
  6378. defaultLocale({
  6379. decimal: ".",
  6380. thousands: ",",
  6381. grouping: [3],
  6382. currency: ["$", ""],
  6383. minus: "-"
  6384. });
  6385. function defaultLocale(definition) {
  6386. locale = formatLocale(definition);
  6387. exports.format = locale.format;
  6388. exports.formatPrefix = locale.formatPrefix;
  6389. return locale;
  6390. }
  6391. function precisionFixed(step) {
  6392. return Math.max(0, -exponent$1(Math.abs(step)));
  6393. }
  6394. function precisionPrefix(step, value) {
  6395. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  6396. }
  6397. function precisionRound(step, max) {
  6398. step = Math.abs(step), max = Math.abs(max) - step;
  6399. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  6400. }
  6401. // Adds floating point numbers with twice the normal precision.
  6402. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  6403. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  6404. // 305–363 (1997).
  6405. // Code adapted from GeographicLib by Charles F. F. Karney,
  6406. // http://geographiclib.sourceforge.net/
  6407. function adder() {
  6408. return new Adder;
  6409. }
  6410. function Adder() {
  6411. this.reset();
  6412. }
  6413. Adder.prototype = {
  6414. constructor: Adder,
  6415. reset: function() {
  6416. this.s = // rounded value
  6417. this.t = 0; // exact error
  6418. },
  6419. add: function(y) {
  6420. add$1(temp, y, this.t);
  6421. add$1(this, temp.s, this.s);
  6422. if (this.s) this.t += temp.t;
  6423. else this.s = temp.t;
  6424. },
  6425. valueOf: function() {
  6426. return this.s;
  6427. }
  6428. };
  6429. var temp = new Adder;
  6430. function add$1(adder, a, b) {
  6431. var x = adder.s = a + b,
  6432. bv = x - a,
  6433. av = x - bv;
  6434. adder.t = (a - av) + (b - bv);
  6435. }
  6436. var epsilon$2 = 1e-6;
  6437. var epsilon2$1 = 1e-12;
  6438. var pi$3 = Math.PI;
  6439. var halfPi$2 = pi$3 / 2;
  6440. var quarterPi = pi$3 / 4;
  6441. var tau$3 = pi$3 * 2;
  6442. var degrees$1 = 180 / pi$3;
  6443. var radians = pi$3 / 180;
  6444. var abs = Math.abs;
  6445. var atan = Math.atan;
  6446. var atan2 = Math.atan2;
  6447. var cos$1 = Math.cos;
  6448. var ceil = Math.ceil;
  6449. var exp = Math.exp;
  6450. var log = Math.log;
  6451. var pow = Math.pow;
  6452. var sin$1 = Math.sin;
  6453. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  6454. var sqrt = Math.sqrt;
  6455. var tan = Math.tan;
  6456. function acos(x) {
  6457. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  6458. }
  6459. function asin(x) {
  6460. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  6461. }
  6462. function haversin(x) {
  6463. return (x = sin$1(x / 2)) * x;
  6464. }
  6465. function noop$2() {}
  6466. function streamGeometry(geometry, stream) {
  6467. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  6468. streamGeometryType[geometry.type](geometry, stream);
  6469. }
  6470. }
  6471. var streamObjectType = {
  6472. Feature: function(object, stream) {
  6473. streamGeometry(object.geometry, stream);
  6474. },
  6475. FeatureCollection: function(object, stream) {
  6476. var features = object.features, i = -1, n = features.length;
  6477. while (++i < n) streamGeometry(features[i].geometry, stream);
  6478. }
  6479. };
  6480. var streamGeometryType = {
  6481. Sphere: function(object, stream) {
  6482. stream.sphere();
  6483. },
  6484. Point: function(object, stream) {
  6485. object = object.coordinates;
  6486. stream.point(object[0], object[1], object[2]);
  6487. },
  6488. MultiPoint: function(object, stream) {
  6489. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6490. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  6491. },
  6492. LineString: function(object, stream) {
  6493. streamLine(object.coordinates, stream, 0);
  6494. },
  6495. MultiLineString: function(object, stream) {
  6496. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6497. while (++i < n) streamLine(coordinates[i], stream, 0);
  6498. },
  6499. Polygon: function(object, stream) {
  6500. streamPolygon(object.coordinates, stream);
  6501. },
  6502. MultiPolygon: function(object, stream) {
  6503. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6504. while (++i < n) streamPolygon(coordinates[i], stream);
  6505. },
  6506. GeometryCollection: function(object, stream) {
  6507. var geometries = object.geometries, i = -1, n = geometries.length;
  6508. while (++i < n) streamGeometry(geometries[i], stream);
  6509. }
  6510. };
  6511. function streamLine(coordinates, stream, closed) {
  6512. var i = -1, n = coordinates.length - closed, coordinate;
  6513. stream.lineStart();
  6514. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  6515. stream.lineEnd();
  6516. }
  6517. function streamPolygon(coordinates, stream) {
  6518. var i = -1, n = coordinates.length;
  6519. stream.polygonStart();
  6520. while (++i < n) streamLine(coordinates[i], stream, 1);
  6521. stream.polygonEnd();
  6522. }
  6523. function geoStream(object, stream) {
  6524. if (object && streamObjectType.hasOwnProperty(object.type)) {
  6525. streamObjectType[object.type](object, stream);
  6526. } else {
  6527. streamGeometry(object, stream);
  6528. }
  6529. }
  6530. var areaRingSum = adder();
  6531. var areaSum = adder(),
  6532. lambda00,
  6533. phi00,
  6534. lambda0,
  6535. cosPhi0,
  6536. sinPhi0;
  6537. var areaStream = {
  6538. point: noop$2,
  6539. lineStart: noop$2,
  6540. lineEnd: noop$2,
  6541. polygonStart: function() {
  6542. areaRingSum.reset();
  6543. areaStream.lineStart = areaRingStart;
  6544. areaStream.lineEnd = areaRingEnd;
  6545. },
  6546. polygonEnd: function() {
  6547. var areaRing = +areaRingSum;
  6548. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  6549. this.lineStart = this.lineEnd = this.point = noop$2;
  6550. },
  6551. sphere: function() {
  6552. areaSum.add(tau$3);
  6553. }
  6554. };
  6555. function areaRingStart() {
  6556. areaStream.point = areaPointFirst;
  6557. }
  6558. function areaRingEnd() {
  6559. areaPoint(lambda00, phi00);
  6560. }
  6561. function areaPointFirst(lambda, phi) {
  6562. areaStream.point = areaPoint;
  6563. lambda00 = lambda, phi00 = phi;
  6564. lambda *= radians, phi *= radians;
  6565. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  6566. }
  6567. function areaPoint(lambda, phi) {
  6568. lambda *= radians, phi *= radians;
  6569. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  6570. // Spherical excess E for a spherical triangle with vertices: south pole,
  6571. // previous point, current point. Uses a formula derived from Cagnoli’s
  6572. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  6573. var dLambda = lambda - lambda0,
  6574. sdLambda = dLambda >= 0 ? 1 : -1,
  6575. adLambda = sdLambda * dLambda,
  6576. cosPhi = cos$1(phi),
  6577. sinPhi = sin$1(phi),
  6578. k = sinPhi0 * sinPhi,
  6579. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  6580. v = k * sdLambda * sin$1(adLambda);
  6581. areaRingSum.add(atan2(v, u));
  6582. // Advance the previous points.
  6583. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  6584. }
  6585. function area$1(object) {
  6586. areaSum.reset();
  6587. geoStream(object, areaStream);
  6588. return areaSum * 2;
  6589. }
  6590. function spherical(cartesian) {
  6591. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  6592. }
  6593. function cartesian(spherical) {
  6594. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  6595. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  6596. }
  6597. function cartesianDot(a, b) {
  6598. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6599. }
  6600. function cartesianCross(a, b) {
  6601. 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]];
  6602. }
  6603. // TODO return a
  6604. function cartesianAddInPlace(a, b) {
  6605. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  6606. }
  6607. function cartesianScale(vector, k) {
  6608. return [vector[0] * k, vector[1] * k, vector[2] * k];
  6609. }
  6610. // TODO return d
  6611. function cartesianNormalizeInPlace(d) {
  6612. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  6613. d[0] /= l, d[1] /= l, d[2] /= l;
  6614. }
  6615. var lambda0$1, phi0, lambda1, phi1, // bounds
  6616. lambda2, // previous lambda-coordinate
  6617. lambda00$1, phi00$1, // first point
  6618. p0, // previous 3D point
  6619. deltaSum = adder(),
  6620. ranges,
  6621. range;
  6622. var boundsStream = {
  6623. point: boundsPoint,
  6624. lineStart: boundsLineStart,
  6625. lineEnd: boundsLineEnd,
  6626. polygonStart: function() {
  6627. boundsStream.point = boundsRingPoint;
  6628. boundsStream.lineStart = boundsRingStart;
  6629. boundsStream.lineEnd = boundsRingEnd;
  6630. deltaSum.reset();
  6631. areaStream.polygonStart();
  6632. },
  6633. polygonEnd: function() {
  6634. areaStream.polygonEnd();
  6635. boundsStream.point = boundsPoint;
  6636. boundsStream.lineStart = boundsLineStart;
  6637. boundsStream.lineEnd = boundsLineEnd;
  6638. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6639. else if (deltaSum > epsilon$2) phi1 = 90;
  6640. else if (deltaSum < -epsilon$2) phi0 = -90;
  6641. range[0] = lambda0$1, range[1] = lambda1;
  6642. },
  6643. sphere: function() {
  6644. lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6645. }
  6646. };
  6647. function boundsPoint(lambda, phi) {
  6648. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6649. if (phi < phi0) phi0 = phi;
  6650. if (phi > phi1) phi1 = phi;
  6651. }
  6652. function linePoint(lambda, phi) {
  6653. var p = cartesian([lambda * radians, phi * radians]);
  6654. if (p0) {
  6655. var normal = cartesianCross(p0, p),
  6656. equatorial = [normal[1], -normal[0], 0],
  6657. inflection = cartesianCross(equatorial, normal);
  6658. cartesianNormalizeInPlace(inflection);
  6659. inflection = spherical(inflection);
  6660. var delta = lambda - lambda2,
  6661. sign = delta > 0 ? 1 : -1,
  6662. lambdai = inflection[0] * degrees$1 * sign,
  6663. phii,
  6664. antimeridian = abs(delta) > 180;
  6665. if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  6666. phii = inflection[1] * degrees$1;
  6667. if (phii > phi1) phi1 = phii;
  6668. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  6669. phii = -inflection[1] * degrees$1;
  6670. if (phii < phi0) phi0 = phii;
  6671. } else {
  6672. if (phi < phi0) phi0 = phi;
  6673. if (phi > phi1) phi1 = phi;
  6674. }
  6675. if (antimeridian) {
  6676. if (lambda < lambda2) {
  6677. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6678. } else {
  6679. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6680. }
  6681. } else {
  6682. if (lambda1 >= lambda0$1) {
  6683. if (lambda < lambda0$1) lambda0$1 = lambda;
  6684. if (lambda > lambda1) lambda1 = lambda;
  6685. } else {
  6686. if (lambda > lambda2) {
  6687. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6688. } else {
  6689. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6690. }
  6691. }
  6692. }
  6693. } else {
  6694. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6695. }
  6696. if (phi < phi0) phi0 = phi;
  6697. if (phi > phi1) phi1 = phi;
  6698. p0 = p, lambda2 = lambda;
  6699. }
  6700. function boundsLineStart() {
  6701. boundsStream.point = linePoint;
  6702. }
  6703. function boundsLineEnd() {
  6704. range[0] = lambda0$1, range[1] = lambda1;
  6705. boundsStream.point = boundsPoint;
  6706. p0 = null;
  6707. }
  6708. function boundsRingPoint(lambda, phi) {
  6709. if (p0) {
  6710. var delta = lambda - lambda2;
  6711. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6712. } else {
  6713. lambda00$1 = lambda, phi00$1 = phi;
  6714. }
  6715. areaStream.point(lambda, phi);
  6716. linePoint(lambda, phi);
  6717. }
  6718. function boundsRingStart() {
  6719. areaStream.lineStart();
  6720. }
  6721. function boundsRingEnd() {
  6722. boundsRingPoint(lambda00$1, phi00$1);
  6723. areaStream.lineEnd();
  6724. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6725. range[0] = lambda0$1, range[1] = lambda1;
  6726. p0 = null;
  6727. }
  6728. // Finds the left-right distance between two longitudes.
  6729. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6730. // the distance between ±180° to be 360°.
  6731. function angle(lambda0, lambda1) {
  6732. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6733. }
  6734. function rangeCompare(a, b) {
  6735. return a[0] - b[0];
  6736. }
  6737. function rangeContains(range, x) {
  6738. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6739. }
  6740. function bounds(feature) {
  6741. var i, n, a, b, merged, deltaMax, delta;
  6742. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6743. ranges = [];
  6744. geoStream(feature, boundsStream);
  6745. // First, sort ranges by their minimum longitudes.
  6746. if (n = ranges.length) {
  6747. ranges.sort(rangeCompare);
  6748. // Then, merge any ranges that overlap.
  6749. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6750. b = ranges[i];
  6751. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6752. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6753. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6754. } else {
  6755. merged.push(a = b);
  6756. }
  6757. }
  6758. // Finally, find the largest gap between the merged ranges.
  6759. // The final bounding box will be the inverse of this gap.
  6760. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6761. b = merged[i];
  6762. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6763. }
  6764. }
  6765. ranges = range = null;
  6766. return lambda0$1 === Infinity || phi0 === Infinity
  6767. ? [[NaN, NaN], [NaN, NaN]]
  6768. : [[lambda0$1, phi0], [lambda1, phi1]];
  6769. }
  6770. var W0, W1,
  6771. X0, Y0, Z0,
  6772. X1, Y1, Z1,
  6773. X2, Y2, Z2,
  6774. lambda00$2, phi00$2, // first point
  6775. x0, y0, z0; // previous point
  6776. var centroidStream = {
  6777. sphere: noop$2,
  6778. point: centroidPoint,
  6779. lineStart: centroidLineStart,
  6780. lineEnd: centroidLineEnd,
  6781. polygonStart: function() {
  6782. centroidStream.lineStart = centroidRingStart;
  6783. centroidStream.lineEnd = centroidRingEnd;
  6784. },
  6785. polygonEnd: function() {
  6786. centroidStream.lineStart = centroidLineStart;
  6787. centroidStream.lineEnd = centroidLineEnd;
  6788. }
  6789. };
  6790. // Arithmetic mean of Cartesian vectors.
  6791. function centroidPoint(lambda, phi) {
  6792. lambda *= radians, phi *= radians;
  6793. var cosPhi = cos$1(phi);
  6794. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6795. }
  6796. function centroidPointCartesian(x, y, z) {
  6797. ++W0;
  6798. X0 += (x - X0) / W0;
  6799. Y0 += (y - Y0) / W0;
  6800. Z0 += (z - Z0) / W0;
  6801. }
  6802. function centroidLineStart() {
  6803. centroidStream.point = centroidLinePointFirst;
  6804. }
  6805. function centroidLinePointFirst(lambda, phi) {
  6806. lambda *= radians, phi *= radians;
  6807. var cosPhi = cos$1(phi);
  6808. x0 = cosPhi * cos$1(lambda);
  6809. y0 = cosPhi * sin$1(lambda);
  6810. z0 = sin$1(phi);
  6811. centroidStream.point = centroidLinePoint;
  6812. centroidPointCartesian(x0, y0, z0);
  6813. }
  6814. function centroidLinePoint(lambda, phi) {
  6815. lambda *= radians, phi *= radians;
  6816. var cosPhi = cos$1(phi),
  6817. x = cosPhi * cos$1(lambda),
  6818. y = cosPhi * sin$1(lambda),
  6819. z = sin$1(phi),
  6820. w = atan2(sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
  6821. W1 += w;
  6822. X1 += w * (x0 + (x0 = x));
  6823. Y1 += w * (y0 + (y0 = y));
  6824. Z1 += w * (z0 + (z0 = z));
  6825. centroidPointCartesian(x0, y0, z0);
  6826. }
  6827. function centroidLineEnd() {
  6828. centroidStream.point = centroidPoint;
  6829. }
  6830. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6831. // J. Applied Mechanics 42, 239 (1975).
  6832. function centroidRingStart() {
  6833. centroidStream.point = centroidRingPointFirst;
  6834. }
  6835. function centroidRingEnd() {
  6836. centroidRingPoint(lambda00$2, phi00$2);
  6837. centroidStream.point = centroidPoint;
  6838. }
  6839. function centroidRingPointFirst(lambda, phi) {
  6840. lambda00$2 = lambda, phi00$2 = phi;
  6841. lambda *= radians, phi *= radians;
  6842. centroidStream.point = centroidRingPoint;
  6843. var cosPhi = cos$1(phi);
  6844. x0 = cosPhi * cos$1(lambda);
  6845. y0 = cosPhi * sin$1(lambda);
  6846. z0 = sin$1(phi);
  6847. centroidPointCartesian(x0, y0, z0);
  6848. }
  6849. function centroidRingPoint(lambda, phi) {
  6850. lambda *= radians, phi *= radians;
  6851. var cosPhi = cos$1(phi),
  6852. x = cosPhi * cos$1(lambda),
  6853. y = cosPhi * sin$1(lambda),
  6854. z = sin$1(phi),
  6855. cx = y0 * z - z0 * y,
  6856. cy = z0 * x - x0 * z,
  6857. cz = x0 * y - y0 * x,
  6858. m = sqrt(cx * cx + cy * cy + cz * cz),
  6859. w = asin(m), // line weight = angle
  6860. v = m && -w / m; // area weight multiplier
  6861. X2 += v * cx;
  6862. Y2 += v * cy;
  6863. Z2 += v * cz;
  6864. W1 += w;
  6865. X1 += w * (x0 + (x0 = x));
  6866. Y1 += w * (y0 + (y0 = y));
  6867. Z1 += w * (z0 + (z0 = z));
  6868. centroidPointCartesian(x0, y0, z0);
  6869. }
  6870. function centroid(object) {
  6871. W0 = W1 =
  6872. X0 = Y0 = Z0 =
  6873. X1 = Y1 = Z1 =
  6874. X2 = Y2 = Z2 = 0;
  6875. geoStream(object, centroidStream);
  6876. var x = X2,
  6877. y = Y2,
  6878. z = Z2,
  6879. m = x * x + y * y + z * z;
  6880. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6881. if (m < epsilon2$1) {
  6882. x = X1, y = Y1, z = Z1;
  6883. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6884. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6885. m = x * x + y * y + z * z;
  6886. // If the feature still has an undefined ccentroid, then return.
  6887. if (m < epsilon2$1) return [NaN, NaN];
  6888. }
  6889. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6890. }
  6891. function constant$8(x) {
  6892. return function() {
  6893. return x;
  6894. };
  6895. }
  6896. function compose(a, b) {
  6897. function compose(x, y) {
  6898. return x = a(x, y), b(x[0], x[1]);
  6899. }
  6900. if (a.invert && b.invert) compose.invert = function(x, y) {
  6901. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6902. };
  6903. return compose;
  6904. }
  6905. function rotationIdentity(lambda, phi) {
  6906. return [abs(lambda) > pi$3 ? lambda + Math.round(-lambda / tau$3) * tau$3 : lambda, phi];
  6907. }
  6908. rotationIdentity.invert = rotationIdentity;
  6909. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6910. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6911. : rotationLambda(deltaLambda))
  6912. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6913. : rotationIdentity);
  6914. }
  6915. function forwardRotationLambda(deltaLambda) {
  6916. return function(lambda, phi) {
  6917. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6918. };
  6919. }
  6920. function rotationLambda(deltaLambda) {
  6921. var rotation = forwardRotationLambda(deltaLambda);
  6922. rotation.invert = forwardRotationLambda(-deltaLambda);
  6923. return rotation;
  6924. }
  6925. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6926. var cosDeltaPhi = cos$1(deltaPhi),
  6927. sinDeltaPhi = sin$1(deltaPhi),
  6928. cosDeltaGamma = cos$1(deltaGamma),
  6929. sinDeltaGamma = sin$1(deltaGamma);
  6930. function rotation(lambda, phi) {
  6931. var cosPhi = cos$1(phi),
  6932. x = cos$1(lambda) * cosPhi,
  6933. y = sin$1(lambda) * cosPhi,
  6934. z = sin$1(phi),
  6935. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6936. return [
  6937. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6938. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6939. ];
  6940. }
  6941. rotation.invert = function(lambda, phi) {
  6942. var cosPhi = cos$1(phi),
  6943. x = cos$1(lambda) * cosPhi,
  6944. y = sin$1(lambda) * cosPhi,
  6945. z = sin$1(phi),
  6946. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6947. return [
  6948. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6949. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6950. ];
  6951. };
  6952. return rotation;
  6953. }
  6954. function rotation(rotate) {
  6955. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6956. function forward(coordinates) {
  6957. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6958. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6959. }
  6960. forward.invert = function(coordinates) {
  6961. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6962. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6963. };
  6964. return forward;
  6965. }
  6966. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6967. function circleStream(stream, radius, delta, direction, t0, t1) {
  6968. if (!delta) return;
  6969. var cosRadius = cos$1(radius),
  6970. sinRadius = sin$1(radius),
  6971. step = direction * delta;
  6972. if (t0 == null) {
  6973. t0 = radius + direction * tau$3;
  6974. t1 = radius - step / 2;
  6975. } else {
  6976. t0 = circleRadius(cosRadius, t0);
  6977. t1 = circleRadius(cosRadius, t1);
  6978. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6979. }
  6980. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6981. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6982. stream.point(point[0], point[1]);
  6983. }
  6984. }
  6985. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6986. function circleRadius(cosRadius, point) {
  6987. point = cartesian(point), point[0] -= cosRadius;
  6988. cartesianNormalizeInPlace(point);
  6989. var radius = acos(-point[1]);
  6990. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6991. }
  6992. function circle() {
  6993. var center = constant$8([0, 0]),
  6994. radius = constant$8(90),
  6995. precision = constant$8(6),
  6996. ring,
  6997. rotate,
  6998. stream = {point: point};
  6999. function point(x, y) {
  7000. ring.push(x = rotate(x, y));
  7001. x[0] *= degrees$1, x[1] *= degrees$1;
  7002. }
  7003. function circle() {
  7004. var c = center.apply(this, arguments),
  7005. r = radius.apply(this, arguments) * radians,
  7006. p = precision.apply(this, arguments) * radians;
  7007. ring = [];
  7008. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  7009. circleStream(stream, r, p, 1);
  7010. c = {type: "Polygon", coordinates: [ring]};
  7011. ring = rotate = null;
  7012. return c;
  7013. }
  7014. circle.center = function(_) {
  7015. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  7016. };
  7017. circle.radius = function(_) {
  7018. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  7019. };
  7020. circle.precision = function(_) {
  7021. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  7022. };
  7023. return circle;
  7024. }
  7025. function clipBuffer() {
  7026. var lines = [],
  7027. line;
  7028. return {
  7029. point: function(x, y) {
  7030. line.push([x, y]);
  7031. },
  7032. lineStart: function() {
  7033. lines.push(line = []);
  7034. },
  7035. lineEnd: noop$2,
  7036. rejoin: function() {
  7037. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  7038. },
  7039. result: function() {
  7040. var result = lines;
  7041. lines = [];
  7042. line = null;
  7043. return result;
  7044. }
  7045. };
  7046. }
  7047. function pointEqual(a, b) {
  7048. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  7049. }
  7050. function Intersection(point, points, other, entry) {
  7051. this.x = point;
  7052. this.z = points;
  7053. this.o = other; // another intersection
  7054. this.e = entry; // is an entry?
  7055. this.v = false; // visited
  7056. this.n = this.p = null; // next & previous
  7057. }
  7058. // A generalized polygon clipping algorithm: given a polygon that has been cut
  7059. // into its visible line segments, and rejoins the segments by interpolating
  7060. // along the clip edge.
  7061. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  7062. var subject = [],
  7063. clip = [],
  7064. i,
  7065. n;
  7066. segments.forEach(function(segment) {
  7067. if ((n = segment.length - 1) <= 0) return;
  7068. var n, p0 = segment[0], p1 = segment[n], x;
  7069. // If the first and last points of a segment are coincident, then treat as a
  7070. // closed ring. TODO if all rings are closed, then the winding order of the
  7071. // exterior ring should be checked.
  7072. if (pointEqual(p0, p1)) {
  7073. stream.lineStart();
  7074. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  7075. stream.lineEnd();
  7076. return;
  7077. }
  7078. subject.push(x = new Intersection(p0, segment, null, true));
  7079. clip.push(x.o = new Intersection(p0, null, x, false));
  7080. subject.push(x = new Intersection(p1, segment, null, false));
  7081. clip.push(x.o = new Intersection(p1, null, x, true));
  7082. });
  7083. if (!subject.length) return;
  7084. clip.sort(compareIntersection);
  7085. link$1(subject);
  7086. link$1(clip);
  7087. for (i = 0, n = clip.length; i < n; ++i) {
  7088. clip[i].e = startInside = !startInside;
  7089. }
  7090. var start = subject[0],
  7091. points,
  7092. point;
  7093. while (1) {
  7094. // Find first unvisited intersection.
  7095. var current = start,
  7096. isSubject = true;
  7097. while (current.v) if ((current = current.n) === start) return;
  7098. points = current.z;
  7099. stream.lineStart();
  7100. do {
  7101. current.v = current.o.v = true;
  7102. if (current.e) {
  7103. if (isSubject) {
  7104. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  7105. } else {
  7106. interpolate(current.x, current.n.x, 1, stream);
  7107. }
  7108. current = current.n;
  7109. } else {
  7110. if (isSubject) {
  7111. points = current.p.z;
  7112. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  7113. } else {
  7114. interpolate(current.x, current.p.x, -1, stream);
  7115. }
  7116. current = current.p;
  7117. }
  7118. current = current.o;
  7119. points = current.z;
  7120. isSubject = !isSubject;
  7121. } while (!current.v);
  7122. stream.lineEnd();
  7123. }
  7124. }
  7125. function link$1(array) {
  7126. if (!(n = array.length)) return;
  7127. var n,
  7128. i = 0,
  7129. a = array[0],
  7130. b;
  7131. while (++i < n) {
  7132. a.n = b = array[i];
  7133. b.p = a;
  7134. a = b;
  7135. }
  7136. a.n = b = array[0];
  7137. b.p = a;
  7138. }
  7139. var sum$1 = adder();
  7140. function longitude(point) {
  7141. if (abs(point[0]) <= pi$3)
  7142. return point[0];
  7143. else
  7144. return sign(point[0]) * ((abs(point[0]) + pi$3) % tau$3 - pi$3);
  7145. }
  7146. function polygonContains(polygon, point) {
  7147. var lambda = longitude(point),
  7148. phi = point[1],
  7149. sinPhi = sin$1(phi),
  7150. normal = [sin$1(lambda), -cos$1(lambda), 0],
  7151. angle = 0,
  7152. winding = 0;
  7153. sum$1.reset();
  7154. if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
  7155. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
  7156. for (var i = 0, n = polygon.length; i < n; ++i) {
  7157. if (!(m = (ring = polygon[i]).length)) continue;
  7158. var ring,
  7159. m,
  7160. point0 = ring[m - 1],
  7161. lambda0 = longitude(point0),
  7162. phi0 = point0[1] / 2 + quarterPi,
  7163. sinPhi0 = sin$1(phi0),
  7164. cosPhi0 = cos$1(phi0);
  7165. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  7166. var point1 = ring[j],
  7167. lambda1 = longitude(point1),
  7168. phi1 = point1[1] / 2 + quarterPi,
  7169. sinPhi1 = sin$1(phi1),
  7170. cosPhi1 = cos$1(phi1),
  7171. delta = lambda1 - lambda0,
  7172. sign = delta >= 0 ? 1 : -1,
  7173. absDelta = sign * delta,
  7174. antimeridian = absDelta > pi$3,
  7175. k = sinPhi0 * sinPhi1;
  7176. sum$1.add(atan2(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  7177. angle += antimeridian ? delta + sign * tau$3 : delta;
  7178. // Are the longitudes either side of the point’s meridian (lambda),
  7179. // and are the latitudes smaller than the parallel (phi)?
  7180. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  7181. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  7182. cartesianNormalizeInPlace(arc);
  7183. var intersection = cartesianCross(normal, arc);
  7184. cartesianNormalizeInPlace(intersection);
  7185. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  7186. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  7187. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  7188. }
  7189. }
  7190. }
  7191. }
  7192. // First, determine whether the South pole is inside or outside:
  7193. //
  7194. // It is inside if:
  7195. // * the polygon winds around it in a clockwise direction.
  7196. // * the polygon does not (cumulatively) wind around it, but has a negative
  7197. // (counter-clockwise) area.
  7198. //
  7199. // Second, count the (signed) number of times a segment crosses a lambda
  7200. // from the point to the South pole. If it is zero, then the point is the
  7201. // same side as the South pole.
  7202. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  7203. }
  7204. function clip(pointVisible, clipLine, interpolate, start) {
  7205. return function(sink) {
  7206. var line = clipLine(sink),
  7207. ringBuffer = clipBuffer(),
  7208. ringSink = clipLine(ringBuffer),
  7209. polygonStarted = false,
  7210. polygon,
  7211. segments,
  7212. ring;
  7213. var clip = {
  7214. point: point,
  7215. lineStart: lineStart,
  7216. lineEnd: lineEnd,
  7217. polygonStart: function() {
  7218. clip.point = pointRing;
  7219. clip.lineStart = ringStart;
  7220. clip.lineEnd = ringEnd;
  7221. segments = [];
  7222. polygon = [];
  7223. },
  7224. polygonEnd: function() {
  7225. clip.point = point;
  7226. clip.lineStart = lineStart;
  7227. clip.lineEnd = lineEnd;
  7228. segments = merge(segments);
  7229. var startInside = polygonContains(polygon, start);
  7230. if (segments.length) {
  7231. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7232. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  7233. } else if (startInside) {
  7234. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7235. sink.lineStart();
  7236. interpolate(null, null, 1, sink);
  7237. sink.lineEnd();
  7238. }
  7239. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  7240. segments = polygon = null;
  7241. },
  7242. sphere: function() {
  7243. sink.polygonStart();
  7244. sink.lineStart();
  7245. interpolate(null, null, 1, sink);
  7246. sink.lineEnd();
  7247. sink.polygonEnd();
  7248. }
  7249. };
  7250. function point(lambda, phi) {
  7251. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  7252. }
  7253. function pointLine(lambda, phi) {
  7254. line.point(lambda, phi);
  7255. }
  7256. function lineStart() {
  7257. clip.point = pointLine;
  7258. line.lineStart();
  7259. }
  7260. function lineEnd() {
  7261. clip.point = point;
  7262. line.lineEnd();
  7263. }
  7264. function pointRing(lambda, phi) {
  7265. ring.push([lambda, phi]);
  7266. ringSink.point(lambda, phi);
  7267. }
  7268. function ringStart() {
  7269. ringSink.lineStart();
  7270. ring = [];
  7271. }
  7272. function ringEnd() {
  7273. pointRing(ring[0][0], ring[0][1]);
  7274. ringSink.lineEnd();
  7275. var clean = ringSink.clean(),
  7276. ringSegments = ringBuffer.result(),
  7277. i, n = ringSegments.length, m,
  7278. segment,
  7279. point;
  7280. ring.pop();
  7281. polygon.push(ring);
  7282. ring = null;
  7283. if (!n) return;
  7284. // No intersections.
  7285. if (clean & 1) {
  7286. segment = ringSegments[0];
  7287. if ((m = segment.length - 1) > 0) {
  7288. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7289. sink.lineStart();
  7290. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7291. sink.lineEnd();
  7292. }
  7293. return;
  7294. }
  7295. // Rejoin connected segments.
  7296. // TODO reuse ringBuffer.rejoin()?
  7297. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7298. segments.push(ringSegments.filter(validSegment));
  7299. }
  7300. return clip;
  7301. };
  7302. }
  7303. function validSegment(segment) {
  7304. return segment.length > 1;
  7305. }
  7306. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7307. // and circle clipping, the same comparison is used.
  7308. function compareIntersection(a, b) {
  7309. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7310. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7311. }
  7312. var clipAntimeridian = clip(
  7313. function() { return true; },
  7314. clipAntimeridianLine,
  7315. clipAntimeridianInterpolate,
  7316. [-pi$3, -halfPi$2]
  7317. );
  7318. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7319. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7320. // intersections, and the first and last segments should be rejoined.
  7321. function clipAntimeridianLine(stream) {
  7322. var lambda0 = NaN,
  7323. phi0 = NaN,
  7324. sign0 = NaN,
  7325. clean; // no intersections
  7326. return {
  7327. lineStart: function() {
  7328. stream.lineStart();
  7329. clean = 1;
  7330. },
  7331. point: function(lambda1, phi1) {
  7332. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7333. delta = abs(lambda1 - lambda0);
  7334. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7335. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7336. stream.point(sign0, phi0);
  7337. stream.lineEnd();
  7338. stream.lineStart();
  7339. stream.point(sign1, phi0);
  7340. stream.point(lambda1, phi0);
  7341. clean = 0;
  7342. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7343. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7344. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7345. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7346. stream.point(sign0, phi0);
  7347. stream.lineEnd();
  7348. stream.lineStart();
  7349. stream.point(sign1, phi0);
  7350. clean = 0;
  7351. }
  7352. stream.point(lambda0 = lambda1, phi0 = phi1);
  7353. sign0 = sign1;
  7354. },
  7355. lineEnd: function() {
  7356. stream.lineEnd();
  7357. lambda0 = phi0 = NaN;
  7358. },
  7359. clean: function() {
  7360. return 2 - clean; // if intersections, rejoin first and last segments
  7361. }
  7362. };
  7363. }
  7364. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7365. var cosPhi0,
  7366. cosPhi1,
  7367. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7368. return abs(sinLambda0Lambda1) > epsilon$2
  7369. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7370. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7371. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7372. : (phi0 + phi1) / 2;
  7373. }
  7374. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7375. var phi;
  7376. if (from == null) {
  7377. phi = direction * halfPi$2;
  7378. stream.point(-pi$3, phi);
  7379. stream.point(0, phi);
  7380. stream.point(pi$3, phi);
  7381. stream.point(pi$3, 0);
  7382. stream.point(pi$3, -phi);
  7383. stream.point(0, -phi);
  7384. stream.point(-pi$3, -phi);
  7385. stream.point(-pi$3, 0);
  7386. stream.point(-pi$3, phi);
  7387. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7388. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7389. phi = direction * lambda / 2;
  7390. stream.point(-lambda, phi);
  7391. stream.point(0, phi);
  7392. stream.point(lambda, phi);
  7393. } else {
  7394. stream.point(to[0], to[1]);
  7395. }
  7396. }
  7397. function clipCircle(radius) {
  7398. var cr = cos$1(radius),
  7399. delta = 6 * radians,
  7400. smallRadius = cr > 0,
  7401. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7402. function interpolate(from, to, direction, stream) {
  7403. circleStream(stream, radius, delta, direction, from, to);
  7404. }
  7405. function visible(lambda, phi) {
  7406. return cos$1(lambda) * cos$1(phi) > cr;
  7407. }
  7408. // Takes a line and cuts into visible segments. Return values used for polygon
  7409. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7410. // intersections 2 - there were intersections, and the first and last segments
  7411. // should be rejoined.
  7412. function clipLine(stream) {
  7413. var point0, // previous point
  7414. c0, // code for previous point
  7415. v0, // visibility of previous point
  7416. v00, // visibility of first point
  7417. clean; // no intersections
  7418. return {
  7419. lineStart: function() {
  7420. v00 = v0 = false;
  7421. clean = 1;
  7422. },
  7423. point: function(lambda, phi) {
  7424. var point1 = [lambda, phi],
  7425. point2,
  7426. v = visible(lambda, phi),
  7427. c = smallRadius
  7428. ? v ? 0 : code(lambda, phi)
  7429. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7430. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7431. // Handle degeneracies.
  7432. // TODO ignore if not clipping polygons.
  7433. if (v !== v0) {
  7434. point2 = intersect(point0, point1);
  7435. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7436. point1[0] += epsilon$2;
  7437. point1[1] += epsilon$2;
  7438. v = visible(point1[0], point1[1]);
  7439. }
  7440. }
  7441. if (v !== v0) {
  7442. clean = 0;
  7443. if (v) {
  7444. // outside going in
  7445. stream.lineStart();
  7446. point2 = intersect(point1, point0);
  7447. stream.point(point2[0], point2[1]);
  7448. } else {
  7449. // inside going out
  7450. point2 = intersect(point0, point1);
  7451. stream.point(point2[0], point2[1]);
  7452. stream.lineEnd();
  7453. }
  7454. point0 = point2;
  7455. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7456. var t;
  7457. // If the codes for two points are different, or are both zero,
  7458. // and there this segment intersects with the small circle.
  7459. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7460. clean = 0;
  7461. if (smallRadius) {
  7462. stream.lineStart();
  7463. stream.point(t[0][0], t[0][1]);
  7464. stream.point(t[1][0], t[1][1]);
  7465. stream.lineEnd();
  7466. } else {
  7467. stream.point(t[1][0], t[1][1]);
  7468. stream.lineEnd();
  7469. stream.lineStart();
  7470. stream.point(t[0][0], t[0][1]);
  7471. }
  7472. }
  7473. }
  7474. if (v && (!point0 || !pointEqual(point0, point1))) {
  7475. stream.point(point1[0], point1[1]);
  7476. }
  7477. point0 = point1, v0 = v, c0 = c;
  7478. },
  7479. lineEnd: function() {
  7480. if (v0) stream.lineEnd();
  7481. point0 = null;
  7482. },
  7483. // Rejoin first and last segments if there were intersections and the first
  7484. // and last points were visible.
  7485. clean: function() {
  7486. return clean | ((v00 && v0) << 1);
  7487. }
  7488. };
  7489. }
  7490. // Intersects the great circle between a and b with the clip circle.
  7491. function intersect(a, b, two) {
  7492. var pa = cartesian(a),
  7493. pb = cartesian(b);
  7494. // We have two planes, n1.p = d1 and n2.p = d2.
  7495. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7496. var n1 = [1, 0, 0], // normal
  7497. n2 = cartesianCross(pa, pb),
  7498. n2n2 = cartesianDot(n2, n2),
  7499. n1n2 = n2[0], // cartesianDot(n1, n2),
  7500. determinant = n2n2 - n1n2 * n1n2;
  7501. // Two polar points.
  7502. if (!determinant) return !two && a;
  7503. var c1 = cr * n2n2 / determinant,
  7504. c2 = -cr * n1n2 / determinant,
  7505. n1xn2 = cartesianCross(n1, n2),
  7506. A = cartesianScale(n1, c1),
  7507. B = cartesianScale(n2, c2);
  7508. cartesianAddInPlace(A, B);
  7509. // Solve |p(t)|^2 = 1.
  7510. var u = n1xn2,
  7511. w = cartesianDot(A, u),
  7512. uu = cartesianDot(u, u),
  7513. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7514. if (t2 < 0) return;
  7515. var t = sqrt(t2),
  7516. q = cartesianScale(u, (-w - t) / uu);
  7517. cartesianAddInPlace(q, A);
  7518. q = spherical(q);
  7519. if (!two) return q;
  7520. // Two intersection points.
  7521. var lambda0 = a[0],
  7522. lambda1 = b[0],
  7523. phi0 = a[1],
  7524. phi1 = b[1],
  7525. z;
  7526. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7527. var delta = lambda1 - lambda0,
  7528. polar = abs(delta - pi$3) < epsilon$2,
  7529. meridian = polar || delta < epsilon$2;
  7530. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7531. // Check that the first point is between a and b.
  7532. if (meridian
  7533. ? polar
  7534. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7535. : phi0 <= q[1] && q[1] <= phi1
  7536. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7537. var q1 = cartesianScale(u, (-w + t) / uu);
  7538. cartesianAddInPlace(q1, A);
  7539. return [q, spherical(q1)];
  7540. }
  7541. }
  7542. // Generates a 4-bit vector representing the location of a point relative to
  7543. // the small circle's bounding box.
  7544. function code(lambda, phi) {
  7545. var r = smallRadius ? radius : pi$3 - radius,
  7546. code = 0;
  7547. if (lambda < -r) code |= 1; // left
  7548. else if (lambda > r) code |= 2; // right
  7549. if (phi < -r) code |= 4; // below
  7550. else if (phi > r) code |= 8; // above
  7551. return code;
  7552. }
  7553. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7554. }
  7555. function clipLine(a, b, x0, y0, x1, y1) {
  7556. var ax = a[0],
  7557. ay = a[1],
  7558. bx = b[0],
  7559. by = b[1],
  7560. t0 = 0,
  7561. t1 = 1,
  7562. dx = bx - ax,
  7563. dy = by - ay,
  7564. r;
  7565. r = x0 - ax;
  7566. if (!dx && r > 0) return;
  7567. r /= dx;
  7568. if (dx < 0) {
  7569. if (r < t0) return;
  7570. if (r < t1) t1 = r;
  7571. } else if (dx > 0) {
  7572. if (r > t1) return;
  7573. if (r > t0) t0 = r;
  7574. }
  7575. r = x1 - ax;
  7576. if (!dx && r < 0) return;
  7577. r /= dx;
  7578. if (dx < 0) {
  7579. if (r > t1) return;
  7580. if (r > t0) t0 = r;
  7581. } else if (dx > 0) {
  7582. if (r < t0) return;
  7583. if (r < t1) t1 = r;
  7584. }
  7585. r = y0 - ay;
  7586. if (!dy && r > 0) return;
  7587. r /= dy;
  7588. if (dy < 0) {
  7589. if (r < t0) return;
  7590. if (r < t1) t1 = r;
  7591. } else if (dy > 0) {
  7592. if (r > t1) return;
  7593. if (r > t0) t0 = r;
  7594. }
  7595. r = y1 - ay;
  7596. if (!dy && r < 0) return;
  7597. r /= dy;
  7598. if (dy < 0) {
  7599. if (r > t1) return;
  7600. if (r > t0) t0 = r;
  7601. } else if (dy > 0) {
  7602. if (r < t0) return;
  7603. if (r < t1) t1 = r;
  7604. }
  7605. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  7606. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  7607. return true;
  7608. }
  7609. var clipMax = 1e9, clipMin = -clipMax;
  7610. // TODO Use d3-polygon’s polygonContains here for the ring check?
  7611. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  7612. function clipRectangle(x0, y0, x1, y1) {
  7613. function visible(x, y) {
  7614. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  7615. }
  7616. function interpolate(from, to, direction, stream) {
  7617. var a = 0, a1 = 0;
  7618. if (from == null
  7619. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  7620. || comparePoint(from, to) < 0 ^ direction > 0) {
  7621. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  7622. while ((a = (a + direction + 4) % 4) !== a1);
  7623. } else {
  7624. stream.point(to[0], to[1]);
  7625. }
  7626. }
  7627. function corner(p, direction) {
  7628. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  7629. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  7630. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  7631. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  7632. }
  7633. function compareIntersection(a, b) {
  7634. return comparePoint(a.x, b.x);
  7635. }
  7636. function comparePoint(a, b) {
  7637. var ca = corner(a, 1),
  7638. cb = corner(b, 1);
  7639. return ca !== cb ? ca - cb
  7640. : ca === 0 ? b[1] - a[1]
  7641. : ca === 1 ? a[0] - b[0]
  7642. : ca === 2 ? a[1] - b[1]
  7643. : b[0] - a[0];
  7644. }
  7645. return function(stream) {
  7646. var activeStream = stream,
  7647. bufferStream = clipBuffer(),
  7648. segments,
  7649. polygon,
  7650. ring,
  7651. x__, y__, v__, // first point
  7652. x_, y_, v_, // previous point
  7653. first,
  7654. clean;
  7655. var clipStream = {
  7656. point: point,
  7657. lineStart: lineStart,
  7658. lineEnd: lineEnd,
  7659. polygonStart: polygonStart,
  7660. polygonEnd: polygonEnd
  7661. };
  7662. function point(x, y) {
  7663. if (visible(x, y)) activeStream.point(x, y);
  7664. }
  7665. function polygonInside() {
  7666. var winding = 0;
  7667. for (var i = 0, n = polygon.length; i < n; ++i) {
  7668. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  7669. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  7670. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  7671. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  7672. }
  7673. }
  7674. return winding;
  7675. }
  7676. // Buffer geometry within a polygon and then clip it en masse.
  7677. function polygonStart() {
  7678. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  7679. }
  7680. function polygonEnd() {
  7681. var startInside = polygonInside(),
  7682. cleanInside = clean && startInside,
  7683. visible = (segments = merge(segments)).length;
  7684. if (cleanInside || visible) {
  7685. stream.polygonStart();
  7686. if (cleanInside) {
  7687. stream.lineStart();
  7688. interpolate(null, null, 1, stream);
  7689. stream.lineEnd();
  7690. }
  7691. if (visible) {
  7692. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7693. }
  7694. stream.polygonEnd();
  7695. }
  7696. activeStream = stream, segments = polygon = ring = null;
  7697. }
  7698. function lineStart() {
  7699. clipStream.point = linePoint;
  7700. if (polygon) polygon.push(ring = []);
  7701. first = true;
  7702. v_ = false;
  7703. x_ = y_ = NaN;
  7704. }
  7705. // TODO rather than special-case polygons, simply handle them separately.
  7706. // Ideally, coincident intersection points should be jittered to avoid
  7707. // clipping issues.
  7708. function lineEnd() {
  7709. if (segments) {
  7710. linePoint(x__, y__);
  7711. if (v__ && v_) bufferStream.rejoin();
  7712. segments.push(bufferStream.result());
  7713. }
  7714. clipStream.point = point;
  7715. if (v_) activeStream.lineEnd();
  7716. }
  7717. function linePoint(x, y) {
  7718. var v = visible(x, y);
  7719. if (polygon) ring.push([x, y]);
  7720. if (first) {
  7721. x__ = x, y__ = y, v__ = v;
  7722. first = false;
  7723. if (v) {
  7724. activeStream.lineStart();
  7725. activeStream.point(x, y);
  7726. }
  7727. } else {
  7728. if (v && v_) activeStream.point(x, y);
  7729. else {
  7730. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7731. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7732. if (clipLine(a, b, x0, y0, x1, y1)) {
  7733. if (!v_) {
  7734. activeStream.lineStart();
  7735. activeStream.point(a[0], a[1]);
  7736. }
  7737. activeStream.point(b[0], b[1]);
  7738. if (!v) activeStream.lineEnd();
  7739. clean = false;
  7740. } else if (v) {
  7741. activeStream.lineStart();
  7742. activeStream.point(x, y);
  7743. clean = false;
  7744. }
  7745. }
  7746. }
  7747. x_ = x, y_ = y, v_ = v;
  7748. }
  7749. return clipStream;
  7750. };
  7751. }
  7752. function extent$1() {
  7753. var x0 = 0,
  7754. y0 = 0,
  7755. x1 = 960,
  7756. y1 = 500,
  7757. cache,
  7758. cacheStream,
  7759. clip;
  7760. return clip = {
  7761. stream: function(stream) {
  7762. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7763. },
  7764. extent: function(_) {
  7765. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7766. }
  7767. };
  7768. }
  7769. var lengthSum = adder(),
  7770. lambda0$2,
  7771. sinPhi0$1,
  7772. cosPhi0$1;
  7773. var lengthStream = {
  7774. sphere: noop$2,
  7775. point: noop$2,
  7776. lineStart: lengthLineStart,
  7777. lineEnd: noop$2,
  7778. polygonStart: noop$2,
  7779. polygonEnd: noop$2
  7780. };
  7781. function lengthLineStart() {
  7782. lengthStream.point = lengthPointFirst;
  7783. lengthStream.lineEnd = lengthLineEnd;
  7784. }
  7785. function lengthLineEnd() {
  7786. lengthStream.point = lengthStream.lineEnd = noop$2;
  7787. }
  7788. function lengthPointFirst(lambda, phi) {
  7789. lambda *= radians, phi *= radians;
  7790. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7791. lengthStream.point = lengthPoint;
  7792. }
  7793. function lengthPoint(lambda, phi) {
  7794. lambda *= radians, phi *= radians;
  7795. var sinPhi = sin$1(phi),
  7796. cosPhi = cos$1(phi),
  7797. delta = abs(lambda - lambda0$2),
  7798. cosDelta = cos$1(delta),
  7799. sinDelta = sin$1(delta),
  7800. x = cosPhi * sinDelta,
  7801. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7802. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7803. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7804. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7805. }
  7806. function length$1(object) {
  7807. lengthSum.reset();
  7808. geoStream(object, lengthStream);
  7809. return +lengthSum;
  7810. }
  7811. var coordinates = [null, null],
  7812. object$1 = {type: "LineString", coordinates: coordinates};
  7813. function distance(a, b) {
  7814. coordinates[0] = a;
  7815. coordinates[1] = b;
  7816. return length$1(object$1);
  7817. }
  7818. var containsObjectType = {
  7819. Feature: function(object, point) {
  7820. return containsGeometry(object.geometry, point);
  7821. },
  7822. FeatureCollection: function(object, point) {
  7823. var features = object.features, i = -1, n = features.length;
  7824. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7825. return false;
  7826. }
  7827. };
  7828. var containsGeometryType = {
  7829. Sphere: function() {
  7830. return true;
  7831. },
  7832. Point: function(object, point) {
  7833. return containsPoint(object.coordinates, point);
  7834. },
  7835. MultiPoint: function(object, point) {
  7836. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7837. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7838. return false;
  7839. },
  7840. LineString: function(object, point) {
  7841. return containsLine(object.coordinates, point);
  7842. },
  7843. MultiLineString: function(object, point) {
  7844. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7845. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7846. return false;
  7847. },
  7848. Polygon: function(object, point) {
  7849. return containsPolygon(object.coordinates, point);
  7850. },
  7851. MultiPolygon: function(object, point) {
  7852. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7853. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7854. return false;
  7855. },
  7856. GeometryCollection: function(object, point) {
  7857. var geometries = object.geometries, i = -1, n = geometries.length;
  7858. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7859. return false;
  7860. }
  7861. };
  7862. function containsGeometry(geometry, point) {
  7863. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7864. ? containsGeometryType[geometry.type](geometry, point)
  7865. : false;
  7866. }
  7867. function containsPoint(coordinates, point) {
  7868. return distance(coordinates, point) === 0;
  7869. }
  7870. function containsLine(coordinates, point) {
  7871. var ao, bo, ab;
  7872. for (var i = 0, n = coordinates.length; i < n; i++) {
  7873. bo = distance(coordinates[i], point);
  7874. if (bo === 0) return true;
  7875. if (i > 0) {
  7876. ab = distance(coordinates[i], coordinates[i - 1]);
  7877. if (
  7878. ab > 0 &&
  7879. ao <= ab &&
  7880. bo <= ab &&
  7881. (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2$1 * ab
  7882. )
  7883. return true;
  7884. }
  7885. ao = bo;
  7886. }
  7887. return false;
  7888. }
  7889. function containsPolygon(coordinates, point) {
  7890. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7891. }
  7892. function ringRadians(ring) {
  7893. return ring = ring.map(pointRadians), ring.pop(), ring;
  7894. }
  7895. function pointRadians(point) {
  7896. return [point[0] * radians, point[1] * radians];
  7897. }
  7898. function contains$1(object, point) {
  7899. return (object && containsObjectType.hasOwnProperty(object.type)
  7900. ? containsObjectType[object.type]
  7901. : containsGeometry)(object, point);
  7902. }
  7903. function graticuleX(y0, y1, dy) {
  7904. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7905. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7906. }
  7907. function graticuleY(x0, x1, dx) {
  7908. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7909. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7910. }
  7911. function graticule() {
  7912. var x1, x0, X1, X0,
  7913. y1, y0, Y1, Y0,
  7914. dx = 10, dy = dx, DX = 90, DY = 360,
  7915. x, y, X, Y,
  7916. precision = 2.5;
  7917. function graticule() {
  7918. return {type: "MultiLineString", coordinates: lines()};
  7919. }
  7920. function lines() {
  7921. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7922. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7923. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7924. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7925. }
  7926. graticule.lines = function() {
  7927. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7928. };
  7929. graticule.outline = function() {
  7930. return {
  7931. type: "Polygon",
  7932. coordinates: [
  7933. X(X0).concat(
  7934. Y(Y1).slice(1),
  7935. X(X1).reverse().slice(1),
  7936. Y(Y0).reverse().slice(1))
  7937. ]
  7938. };
  7939. };
  7940. graticule.extent = function(_) {
  7941. if (!arguments.length) return graticule.extentMinor();
  7942. return graticule.extentMajor(_).extentMinor(_);
  7943. };
  7944. graticule.extentMajor = function(_) {
  7945. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7946. X0 = +_[0][0], X1 = +_[1][0];
  7947. Y0 = +_[0][1], Y1 = +_[1][1];
  7948. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7949. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7950. return graticule.precision(precision);
  7951. };
  7952. graticule.extentMinor = function(_) {
  7953. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7954. x0 = +_[0][0], x1 = +_[1][0];
  7955. y0 = +_[0][1], y1 = +_[1][1];
  7956. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7957. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7958. return graticule.precision(precision);
  7959. };
  7960. graticule.step = function(_) {
  7961. if (!arguments.length) return graticule.stepMinor();
  7962. return graticule.stepMajor(_).stepMinor(_);
  7963. };
  7964. graticule.stepMajor = function(_) {
  7965. if (!arguments.length) return [DX, DY];
  7966. DX = +_[0], DY = +_[1];
  7967. return graticule;
  7968. };
  7969. graticule.stepMinor = function(_) {
  7970. if (!arguments.length) return [dx, dy];
  7971. dx = +_[0], dy = +_[1];
  7972. return graticule;
  7973. };
  7974. graticule.precision = function(_) {
  7975. if (!arguments.length) return precision;
  7976. precision = +_;
  7977. x = graticuleX(y0, y1, 90);
  7978. y = graticuleY(x0, x1, precision);
  7979. X = graticuleX(Y0, Y1, 90);
  7980. Y = graticuleY(X0, X1, precision);
  7981. return graticule;
  7982. };
  7983. return graticule
  7984. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7985. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7986. }
  7987. function graticule10() {
  7988. return graticule()();
  7989. }
  7990. function interpolate$1(a, b) {
  7991. var x0 = a[0] * radians,
  7992. y0 = a[1] * radians,
  7993. x1 = b[0] * radians,
  7994. y1 = b[1] * radians,
  7995. cy0 = cos$1(y0),
  7996. sy0 = sin$1(y0),
  7997. cy1 = cos$1(y1),
  7998. sy1 = sin$1(y1),
  7999. kx0 = cy0 * cos$1(x0),
  8000. ky0 = cy0 * sin$1(x0),
  8001. kx1 = cy1 * cos$1(x1),
  8002. ky1 = cy1 * sin$1(x1),
  8003. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  8004. k = sin$1(d);
  8005. var interpolate = d ? function(t) {
  8006. var B = sin$1(t *= d) / k,
  8007. A = sin$1(d - t) / k,
  8008. x = A * kx0 + B * kx1,
  8009. y = A * ky0 + B * ky1,
  8010. z = A * sy0 + B * sy1;
  8011. return [
  8012. atan2(y, x) * degrees$1,
  8013. atan2(z, sqrt(x * x + y * y)) * degrees$1
  8014. ];
  8015. } : function() {
  8016. return [x0 * degrees$1, y0 * degrees$1];
  8017. };
  8018. interpolate.distance = d;
  8019. return interpolate;
  8020. }
  8021. function identity$4(x) {
  8022. return x;
  8023. }
  8024. var areaSum$1 = adder(),
  8025. areaRingSum$1 = adder(),
  8026. x00,
  8027. y00,
  8028. x0$1,
  8029. y0$1;
  8030. var areaStream$1 = {
  8031. point: noop$2,
  8032. lineStart: noop$2,
  8033. lineEnd: noop$2,
  8034. polygonStart: function() {
  8035. areaStream$1.lineStart = areaRingStart$1;
  8036. areaStream$1.lineEnd = areaRingEnd$1;
  8037. },
  8038. polygonEnd: function() {
  8039. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  8040. areaSum$1.add(abs(areaRingSum$1));
  8041. areaRingSum$1.reset();
  8042. },
  8043. result: function() {
  8044. var area = areaSum$1 / 2;
  8045. areaSum$1.reset();
  8046. return area;
  8047. }
  8048. };
  8049. function areaRingStart$1() {
  8050. areaStream$1.point = areaPointFirst$1;
  8051. }
  8052. function areaPointFirst$1(x, y) {
  8053. areaStream$1.point = areaPoint$1;
  8054. x00 = x0$1 = x, y00 = y0$1 = y;
  8055. }
  8056. function areaPoint$1(x, y) {
  8057. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  8058. x0$1 = x, y0$1 = y;
  8059. }
  8060. function areaRingEnd$1() {
  8061. areaPoint$1(x00, y00);
  8062. }
  8063. var x0$2 = Infinity,
  8064. y0$2 = x0$2,
  8065. x1 = -x0$2,
  8066. y1 = x1;
  8067. var boundsStream$1 = {
  8068. point: boundsPoint$1,
  8069. lineStart: noop$2,
  8070. lineEnd: noop$2,
  8071. polygonStart: noop$2,
  8072. polygonEnd: noop$2,
  8073. result: function() {
  8074. var bounds = [[x0$2, y0$2], [x1, y1]];
  8075. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  8076. return bounds;
  8077. }
  8078. };
  8079. function boundsPoint$1(x, y) {
  8080. if (x < x0$2) x0$2 = x;
  8081. if (x > x1) x1 = x;
  8082. if (y < y0$2) y0$2 = y;
  8083. if (y > y1) y1 = y;
  8084. }
  8085. // TODO Enforce positive area for exterior, negative area for interior?
  8086. var X0$1 = 0,
  8087. Y0$1 = 0,
  8088. Z0$1 = 0,
  8089. X1$1 = 0,
  8090. Y1$1 = 0,
  8091. Z1$1 = 0,
  8092. X2$1 = 0,
  8093. Y2$1 = 0,
  8094. Z2$1 = 0,
  8095. x00$1,
  8096. y00$1,
  8097. x0$3,
  8098. y0$3;
  8099. var centroidStream$1 = {
  8100. point: centroidPoint$1,
  8101. lineStart: centroidLineStart$1,
  8102. lineEnd: centroidLineEnd$1,
  8103. polygonStart: function() {
  8104. centroidStream$1.lineStart = centroidRingStart$1;
  8105. centroidStream$1.lineEnd = centroidRingEnd$1;
  8106. },
  8107. polygonEnd: function() {
  8108. centroidStream$1.point = centroidPoint$1;
  8109. centroidStream$1.lineStart = centroidLineStart$1;
  8110. centroidStream$1.lineEnd = centroidLineEnd$1;
  8111. },
  8112. result: function() {
  8113. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  8114. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  8115. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  8116. : [NaN, NaN];
  8117. X0$1 = Y0$1 = Z0$1 =
  8118. X1$1 = Y1$1 = Z1$1 =
  8119. X2$1 = Y2$1 = Z2$1 = 0;
  8120. return centroid;
  8121. }
  8122. };
  8123. function centroidPoint$1(x, y) {
  8124. X0$1 += x;
  8125. Y0$1 += y;
  8126. ++Z0$1;
  8127. }
  8128. function centroidLineStart$1() {
  8129. centroidStream$1.point = centroidPointFirstLine;
  8130. }
  8131. function centroidPointFirstLine(x, y) {
  8132. centroidStream$1.point = centroidPointLine;
  8133. centroidPoint$1(x0$3 = x, y0$3 = y);
  8134. }
  8135. function centroidPointLine(x, y) {
  8136. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  8137. X1$1 += z * (x0$3 + x) / 2;
  8138. Y1$1 += z * (y0$3 + y) / 2;
  8139. Z1$1 += z;
  8140. centroidPoint$1(x0$3 = x, y0$3 = y);
  8141. }
  8142. function centroidLineEnd$1() {
  8143. centroidStream$1.point = centroidPoint$1;
  8144. }
  8145. function centroidRingStart$1() {
  8146. centroidStream$1.point = centroidPointFirstRing;
  8147. }
  8148. function centroidRingEnd$1() {
  8149. centroidPointRing(x00$1, y00$1);
  8150. }
  8151. function centroidPointFirstRing(x, y) {
  8152. centroidStream$1.point = centroidPointRing;
  8153. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  8154. }
  8155. function centroidPointRing(x, y) {
  8156. var dx = x - x0$3,
  8157. dy = y - y0$3,
  8158. z = sqrt(dx * dx + dy * dy);
  8159. X1$1 += z * (x0$3 + x) / 2;
  8160. Y1$1 += z * (y0$3 + y) / 2;
  8161. Z1$1 += z;
  8162. z = y0$3 * x - x0$3 * y;
  8163. X2$1 += z * (x0$3 + x);
  8164. Y2$1 += z * (y0$3 + y);
  8165. Z2$1 += z * 3;
  8166. centroidPoint$1(x0$3 = x, y0$3 = y);
  8167. }
  8168. function PathContext(context) {
  8169. this._context = context;
  8170. }
  8171. PathContext.prototype = {
  8172. _radius: 4.5,
  8173. pointRadius: function(_) {
  8174. return this._radius = _, this;
  8175. },
  8176. polygonStart: function() {
  8177. this._line = 0;
  8178. },
  8179. polygonEnd: function() {
  8180. this._line = NaN;
  8181. },
  8182. lineStart: function() {
  8183. this._point = 0;
  8184. },
  8185. lineEnd: function() {
  8186. if (this._line === 0) this._context.closePath();
  8187. this._point = NaN;
  8188. },
  8189. point: function(x, y) {
  8190. switch (this._point) {
  8191. case 0: {
  8192. this._context.moveTo(x, y);
  8193. this._point = 1;
  8194. break;
  8195. }
  8196. case 1: {
  8197. this._context.lineTo(x, y);
  8198. break;
  8199. }
  8200. default: {
  8201. this._context.moveTo(x + this._radius, y);
  8202. this._context.arc(x, y, this._radius, 0, tau$3);
  8203. break;
  8204. }
  8205. }
  8206. },
  8207. result: noop$2
  8208. };
  8209. var lengthSum$1 = adder(),
  8210. lengthRing,
  8211. x00$2,
  8212. y00$2,
  8213. x0$4,
  8214. y0$4;
  8215. var lengthStream$1 = {
  8216. point: noop$2,
  8217. lineStart: function() {
  8218. lengthStream$1.point = lengthPointFirst$1;
  8219. },
  8220. lineEnd: function() {
  8221. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  8222. lengthStream$1.point = noop$2;
  8223. },
  8224. polygonStart: function() {
  8225. lengthRing = true;
  8226. },
  8227. polygonEnd: function() {
  8228. lengthRing = null;
  8229. },
  8230. result: function() {
  8231. var length = +lengthSum$1;
  8232. lengthSum$1.reset();
  8233. return length;
  8234. }
  8235. };
  8236. function lengthPointFirst$1(x, y) {
  8237. lengthStream$1.point = lengthPoint$1;
  8238. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  8239. }
  8240. function lengthPoint$1(x, y) {
  8241. x0$4 -= x, y0$4 -= y;
  8242. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  8243. x0$4 = x, y0$4 = y;
  8244. }
  8245. function PathString() {
  8246. this._string = [];
  8247. }
  8248. PathString.prototype = {
  8249. _radius: 4.5,
  8250. _circle: circle$1(4.5),
  8251. pointRadius: function(_) {
  8252. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  8253. return this;
  8254. },
  8255. polygonStart: function() {
  8256. this._line = 0;
  8257. },
  8258. polygonEnd: function() {
  8259. this._line = NaN;
  8260. },
  8261. lineStart: function() {
  8262. this._point = 0;
  8263. },
  8264. lineEnd: function() {
  8265. if (this._line === 0) this._string.push("Z");
  8266. this._point = NaN;
  8267. },
  8268. point: function(x, y) {
  8269. switch (this._point) {
  8270. case 0: {
  8271. this._string.push("M", x, ",", y);
  8272. this._point = 1;
  8273. break;
  8274. }
  8275. case 1: {
  8276. this._string.push("L", x, ",", y);
  8277. break;
  8278. }
  8279. default: {
  8280. if (this._circle == null) this._circle = circle$1(this._radius);
  8281. this._string.push("M", x, ",", y, this._circle);
  8282. break;
  8283. }
  8284. }
  8285. },
  8286. result: function() {
  8287. if (this._string.length) {
  8288. var result = this._string.join("");
  8289. this._string = [];
  8290. return result;
  8291. } else {
  8292. return null;
  8293. }
  8294. }
  8295. };
  8296. function circle$1(radius) {
  8297. return "m0," + radius
  8298. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  8299. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  8300. + "z";
  8301. }
  8302. function index$1(projection, context) {
  8303. var pointRadius = 4.5,
  8304. projectionStream,
  8305. contextStream;
  8306. function path(object) {
  8307. if (object) {
  8308. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  8309. geoStream(object, projectionStream(contextStream));
  8310. }
  8311. return contextStream.result();
  8312. }
  8313. path.area = function(object) {
  8314. geoStream(object, projectionStream(areaStream$1));
  8315. return areaStream$1.result();
  8316. };
  8317. path.measure = function(object) {
  8318. geoStream(object, projectionStream(lengthStream$1));
  8319. return lengthStream$1.result();
  8320. };
  8321. path.bounds = function(object) {
  8322. geoStream(object, projectionStream(boundsStream$1));
  8323. return boundsStream$1.result();
  8324. };
  8325. path.centroid = function(object) {
  8326. geoStream(object, projectionStream(centroidStream$1));
  8327. return centroidStream$1.result();
  8328. };
  8329. path.projection = function(_) {
  8330. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  8331. };
  8332. path.context = function(_) {
  8333. if (!arguments.length) return context;
  8334. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  8335. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  8336. return path;
  8337. };
  8338. path.pointRadius = function(_) {
  8339. if (!arguments.length) return pointRadius;
  8340. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  8341. return path;
  8342. };
  8343. return path.projection(projection).context(context);
  8344. }
  8345. function transform(methods) {
  8346. return {
  8347. stream: transformer(methods)
  8348. };
  8349. }
  8350. function transformer(methods) {
  8351. return function(stream) {
  8352. var s = new TransformStream;
  8353. for (var key in methods) s[key] = methods[key];
  8354. s.stream = stream;
  8355. return s;
  8356. };
  8357. }
  8358. function TransformStream() {}
  8359. TransformStream.prototype = {
  8360. constructor: TransformStream,
  8361. point: function(x, y) { this.stream.point(x, y); },
  8362. sphere: function() { this.stream.sphere(); },
  8363. lineStart: function() { this.stream.lineStart(); },
  8364. lineEnd: function() { this.stream.lineEnd(); },
  8365. polygonStart: function() { this.stream.polygonStart(); },
  8366. polygonEnd: function() { this.stream.polygonEnd(); }
  8367. };
  8368. function fit(projection, fitBounds, object) {
  8369. var clip = projection.clipExtent && projection.clipExtent();
  8370. projection.scale(150).translate([0, 0]);
  8371. if (clip != null) projection.clipExtent(null);
  8372. geoStream(object, projection.stream(boundsStream$1));
  8373. fitBounds(boundsStream$1.result());
  8374. if (clip != null) projection.clipExtent(clip);
  8375. return projection;
  8376. }
  8377. function fitExtent(projection, extent, object) {
  8378. return fit(projection, function(b) {
  8379. var w = extent[1][0] - extent[0][0],
  8380. h = extent[1][1] - extent[0][1],
  8381. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  8382. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  8383. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  8384. projection.scale(150 * k).translate([x, y]);
  8385. }, object);
  8386. }
  8387. function fitSize(projection, size, object) {
  8388. return fitExtent(projection, [[0, 0], size], object);
  8389. }
  8390. function fitWidth(projection, width, object) {
  8391. return fit(projection, function(b) {
  8392. var w = +width,
  8393. k = w / (b[1][0] - b[0][0]),
  8394. x = (w - k * (b[1][0] + b[0][0])) / 2,
  8395. y = -k * b[0][1];
  8396. projection.scale(150 * k).translate([x, y]);
  8397. }, object);
  8398. }
  8399. function fitHeight(projection, height, object) {
  8400. return fit(projection, function(b) {
  8401. var h = +height,
  8402. k = h / (b[1][1] - b[0][1]),
  8403. x = -k * b[0][0],
  8404. y = (h - k * (b[1][1] + b[0][1])) / 2;
  8405. projection.scale(150 * k).translate([x, y]);
  8406. }, object);
  8407. }
  8408. var maxDepth = 16, // maximum depth of subdivision
  8409. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  8410. function resample(project, delta2) {
  8411. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  8412. }
  8413. function resampleNone(project) {
  8414. return transformer({
  8415. point: function(x, y) {
  8416. x = project(x, y);
  8417. this.stream.point(x[0], x[1]);
  8418. }
  8419. });
  8420. }
  8421. function resample$1(project, delta2) {
  8422. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  8423. var dx = x1 - x0,
  8424. dy = y1 - y0,
  8425. d2 = dx * dx + dy * dy;
  8426. if (d2 > 4 * delta2 && depth--) {
  8427. var a = a0 + a1,
  8428. b = b0 + b1,
  8429. c = c0 + c1,
  8430. m = sqrt(a * a + b * b + c * c),
  8431. phi2 = asin(c /= m),
  8432. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  8433. p = project(lambda2, phi2),
  8434. x2 = p[0],
  8435. y2 = p[1],
  8436. dx2 = x2 - x0,
  8437. dy2 = y2 - y0,
  8438. dz = dy * dx2 - dx * dy2;
  8439. if (dz * dz / d2 > delta2 // perpendicular projected distance
  8440. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  8441. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  8442. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  8443. stream.point(x2, y2);
  8444. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  8445. }
  8446. }
  8447. }
  8448. return function(stream) {
  8449. var lambda00, x00, y00, a00, b00, c00, // first point
  8450. lambda0, x0, y0, a0, b0, c0; // previous point
  8451. var resampleStream = {
  8452. point: point,
  8453. lineStart: lineStart,
  8454. lineEnd: lineEnd,
  8455. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  8456. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  8457. };
  8458. function point(x, y) {
  8459. x = project(x, y);
  8460. stream.point(x[0], x[1]);
  8461. }
  8462. function lineStart() {
  8463. x0 = NaN;
  8464. resampleStream.point = linePoint;
  8465. stream.lineStart();
  8466. }
  8467. function linePoint(lambda, phi) {
  8468. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  8469. 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);
  8470. stream.point(x0, y0);
  8471. }
  8472. function lineEnd() {
  8473. resampleStream.point = point;
  8474. stream.lineEnd();
  8475. }
  8476. function ringStart() {
  8477. lineStart();
  8478. resampleStream.point = ringPoint;
  8479. resampleStream.lineEnd = ringEnd;
  8480. }
  8481. function ringPoint(lambda, phi) {
  8482. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  8483. resampleStream.point = linePoint;
  8484. }
  8485. function ringEnd() {
  8486. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  8487. resampleStream.lineEnd = lineEnd;
  8488. lineEnd();
  8489. }
  8490. return resampleStream;
  8491. };
  8492. }
  8493. var transformRadians = transformer({
  8494. point: function(x, y) {
  8495. this.stream.point(x * radians, y * radians);
  8496. }
  8497. });
  8498. function transformRotate(rotate) {
  8499. return transformer({
  8500. point: function(x, y) {
  8501. var r = rotate(x, y);
  8502. return this.stream.point(r[0], r[1]);
  8503. }
  8504. });
  8505. }
  8506. function scaleTranslate(k, dx, dy, sx, sy) {
  8507. function transform(x, y) {
  8508. x *= sx; y *= sy;
  8509. return [dx + k * x, dy - k * y];
  8510. }
  8511. transform.invert = function(x, y) {
  8512. return [(x - dx) / k * sx, (dy - y) / k * sy];
  8513. };
  8514. return transform;
  8515. }
  8516. function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {
  8517. var cosAlpha = cos$1(alpha),
  8518. sinAlpha = sin$1(alpha),
  8519. a = cosAlpha * k,
  8520. b = sinAlpha * k,
  8521. ai = cosAlpha / k,
  8522. bi = sinAlpha / k,
  8523. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  8524. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  8525. function transform(x, y) {
  8526. x *= sx; y *= sy;
  8527. return [a * x - b * y + dx, dy - b * x - a * y];
  8528. }
  8529. transform.invert = function(x, y) {
  8530. return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];
  8531. };
  8532. return transform;
  8533. }
  8534. function projection(project) {
  8535. return projectionMutator(function() { return project; })();
  8536. }
  8537. function projectionMutator(projectAt) {
  8538. var project,
  8539. k = 150, // scale
  8540. x = 480, y = 250, // translate
  8541. lambda = 0, phi = 0, // center
  8542. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  8543. alpha = 0, // post-rotate angle
  8544. sx = 1, // reflectX
  8545. sy = 1, // reflectX
  8546. theta = null, preclip = clipAntimeridian, // pre-clip angle
  8547. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  8548. delta2 = 0.5, // precision
  8549. projectResample,
  8550. projectTransform,
  8551. projectRotateTransform,
  8552. cache,
  8553. cacheStream;
  8554. function projection(point) {
  8555. return projectRotateTransform(point[0] * radians, point[1] * radians);
  8556. }
  8557. function invert(point) {
  8558. point = projectRotateTransform.invert(point[0], point[1]);
  8559. return point && [point[0] * degrees$1, point[1] * degrees$1];
  8560. }
  8561. projection.stream = function(stream) {
  8562. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  8563. };
  8564. projection.preclip = function(_) {
  8565. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  8566. };
  8567. projection.postclip = function(_) {
  8568. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8569. };
  8570. projection.clipAngle = function(_) {
  8571. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  8572. };
  8573. projection.clipExtent = function(_) {
  8574. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  8575. };
  8576. projection.scale = function(_) {
  8577. return arguments.length ? (k = +_, recenter()) : k;
  8578. };
  8579. projection.translate = function(_) {
  8580. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  8581. };
  8582. projection.center = function(_) {
  8583. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  8584. };
  8585. projection.rotate = function(_) {
  8586. return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees$1, deltaPhi * degrees$1, deltaGamma * degrees$1];
  8587. };
  8588. projection.angle = function(_) {
  8589. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
  8590. };
  8591. projection.reflectX = function(_) {
  8592. return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;
  8593. };
  8594. projection.reflectY = function(_) {
  8595. return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;
  8596. };
  8597. projection.precision = function(_) {
  8598. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  8599. };
  8600. projection.fitExtent = function(extent, object) {
  8601. return fitExtent(projection, extent, object);
  8602. };
  8603. projection.fitSize = function(size, object) {
  8604. return fitSize(projection, size, object);
  8605. };
  8606. projection.fitWidth = function(width, object) {
  8607. return fitWidth(projection, width, object);
  8608. };
  8609. projection.fitHeight = function(height, object) {
  8610. return fitHeight(projection, height, object);
  8611. };
  8612. function recenter() {
  8613. var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),
  8614. transform = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], sx, sy, alpha);
  8615. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  8616. projectTransform = compose(project, transform);
  8617. projectRotateTransform = compose(rotate, projectTransform);
  8618. projectResample = resample(projectTransform, delta2);
  8619. return reset();
  8620. }
  8621. function reset() {
  8622. cache = cacheStream = null;
  8623. return projection;
  8624. }
  8625. return function() {
  8626. project = projectAt.apply(this, arguments);
  8627. projection.invert = project.invert && invert;
  8628. return recenter();
  8629. };
  8630. }
  8631. function conicProjection(projectAt) {
  8632. var phi0 = 0,
  8633. phi1 = pi$3 / 3,
  8634. m = projectionMutator(projectAt),
  8635. p = m(phi0, phi1);
  8636. p.parallels = function(_) {
  8637. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  8638. };
  8639. return p;
  8640. }
  8641. function cylindricalEqualAreaRaw(phi0) {
  8642. var cosPhi0 = cos$1(phi0);
  8643. function forward(lambda, phi) {
  8644. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  8645. }
  8646. forward.invert = function(x, y) {
  8647. return [x / cosPhi0, asin(y * cosPhi0)];
  8648. };
  8649. return forward;
  8650. }
  8651. function conicEqualAreaRaw(y0, y1) {
  8652. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  8653. // Are the parallels symmetrical around the Equator?
  8654. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  8655. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  8656. function project(x, y) {
  8657. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  8658. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  8659. }
  8660. project.invert = function(x, y) {
  8661. var r0y = r0 - y,
  8662. l = atan2(x, abs(r0y)) * sign(r0y);
  8663. if (r0y * n < 0)
  8664. l -= pi$3 * sign(x) * sign(r0y);
  8665. return [l / n, asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  8666. };
  8667. return project;
  8668. }
  8669. function conicEqualArea() {
  8670. return conicProjection(conicEqualAreaRaw)
  8671. .scale(155.424)
  8672. .center([0, 33.6442]);
  8673. }
  8674. function albers() {
  8675. return conicEqualArea()
  8676. .parallels([29.5, 45.5])
  8677. .scale(1070)
  8678. .translate([480, 250])
  8679. .rotate([96, 0])
  8680. .center([-0.6, 38.7]);
  8681. }
  8682. // The projections must have mutually exclusive clip regions on the sphere,
  8683. // as this will avoid emitting interleaving lines and polygons.
  8684. function multiplex(streams) {
  8685. var n = streams.length;
  8686. return {
  8687. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  8688. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  8689. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  8690. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  8691. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  8692. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  8693. };
  8694. }
  8695. // A composite projection for the United States, configured by default for
  8696. // 960×500. The projection also works quite well at 960×600 if you change the
  8697. // scale to 1285 and adjust the translate accordingly. The set of standard
  8698. // parallels for each region comes from USGS, which is published here:
  8699. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  8700. function albersUsa() {
  8701. var cache,
  8702. cacheStream,
  8703. lower48 = albers(), lower48Point,
  8704. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  8705. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  8706. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  8707. function albersUsa(coordinates) {
  8708. var x = coordinates[0], y = coordinates[1];
  8709. return point = null,
  8710. (lower48Point.point(x, y), point)
  8711. || (alaskaPoint.point(x, y), point)
  8712. || (hawaiiPoint.point(x, y), point);
  8713. }
  8714. albersUsa.invert = function(coordinates) {
  8715. var k = lower48.scale(),
  8716. t = lower48.translate(),
  8717. x = (coordinates[0] - t[0]) / k,
  8718. y = (coordinates[1] - t[1]) / k;
  8719. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  8720. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  8721. : lower48).invert(coordinates);
  8722. };
  8723. albersUsa.stream = function(stream) {
  8724. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  8725. };
  8726. albersUsa.precision = function(_) {
  8727. if (!arguments.length) return lower48.precision();
  8728. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  8729. return reset();
  8730. };
  8731. albersUsa.scale = function(_) {
  8732. if (!arguments.length) return lower48.scale();
  8733. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  8734. return albersUsa.translate(lower48.translate());
  8735. };
  8736. albersUsa.translate = function(_) {
  8737. if (!arguments.length) return lower48.translate();
  8738. var k = lower48.scale(), x = +_[0], y = +_[1];
  8739. lower48Point = lower48
  8740. .translate(_)
  8741. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8742. .stream(pointStream);
  8743. alaskaPoint = alaska
  8744. .translate([x - 0.307 * k, y + 0.201 * k])
  8745. .clipExtent([[x - 0.425 * k + epsilon$2, y + 0.120 * k + epsilon$2], [x - 0.214 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
  8746. .stream(pointStream);
  8747. hawaiiPoint = hawaii
  8748. .translate([x - 0.205 * k, y + 0.212 * k])
  8749. .clipExtent([[x - 0.214 * k + epsilon$2, y + 0.166 * k + epsilon$2], [x - 0.115 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
  8750. .stream(pointStream);
  8751. return reset();
  8752. };
  8753. albersUsa.fitExtent = function(extent, object) {
  8754. return fitExtent(albersUsa, extent, object);
  8755. };
  8756. albersUsa.fitSize = function(size, object) {
  8757. return fitSize(albersUsa, size, object);
  8758. };
  8759. albersUsa.fitWidth = function(width, object) {
  8760. return fitWidth(albersUsa, width, object);
  8761. };
  8762. albersUsa.fitHeight = function(height, object) {
  8763. return fitHeight(albersUsa, height, object);
  8764. };
  8765. function reset() {
  8766. cache = cacheStream = null;
  8767. return albersUsa;
  8768. }
  8769. return albersUsa.scale(1070);
  8770. }
  8771. function azimuthalRaw(scale) {
  8772. return function(x, y) {
  8773. var cx = cos$1(x),
  8774. cy = cos$1(y),
  8775. k = scale(cx * cy);
  8776. return [
  8777. k * cy * sin$1(x),
  8778. k * sin$1(y)
  8779. ];
  8780. }
  8781. }
  8782. function azimuthalInvert(angle) {
  8783. return function(x, y) {
  8784. var z = sqrt(x * x + y * y),
  8785. c = angle(z),
  8786. sc = sin$1(c),
  8787. cc = cos$1(c);
  8788. return [
  8789. atan2(x * sc, z * cc),
  8790. asin(z && y * sc / z)
  8791. ];
  8792. }
  8793. }
  8794. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8795. return sqrt(2 / (1 + cxcy));
  8796. });
  8797. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8798. return 2 * asin(z / 2);
  8799. });
  8800. function azimuthalEqualArea() {
  8801. return projection(azimuthalEqualAreaRaw)
  8802. .scale(124.75)
  8803. .clipAngle(180 - 1e-3);
  8804. }
  8805. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8806. return (c = acos(c)) && c / sin$1(c);
  8807. });
  8808. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8809. return z;
  8810. });
  8811. function azimuthalEquidistant() {
  8812. return projection(azimuthalEquidistantRaw)
  8813. .scale(79.4188)
  8814. .clipAngle(180 - 1e-3);
  8815. }
  8816. function mercatorRaw(lambda, phi) {
  8817. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8818. }
  8819. mercatorRaw.invert = function(x, y) {
  8820. return [x, 2 * atan(exp(y)) - halfPi$2];
  8821. };
  8822. function mercator() {
  8823. return mercatorProjection(mercatorRaw)
  8824. .scale(961 / tau$3);
  8825. }
  8826. function mercatorProjection(project) {
  8827. var m = projection(project),
  8828. center = m.center,
  8829. scale = m.scale,
  8830. translate = m.translate,
  8831. clipExtent = m.clipExtent,
  8832. x0 = null, y0, x1, y1; // clip extent
  8833. m.scale = function(_) {
  8834. return arguments.length ? (scale(_), reclip()) : scale();
  8835. };
  8836. m.translate = function(_) {
  8837. return arguments.length ? (translate(_), reclip()) : translate();
  8838. };
  8839. m.center = function(_) {
  8840. return arguments.length ? (center(_), reclip()) : center();
  8841. };
  8842. m.clipExtent = function(_) {
  8843. 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]];
  8844. };
  8845. function reclip() {
  8846. var k = pi$3 * scale(),
  8847. t = m(rotation(m.rotate()).invert([0, 0]));
  8848. return clipExtent(x0 == null
  8849. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8850. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8851. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8852. }
  8853. return reclip();
  8854. }
  8855. function tany(y) {
  8856. return tan((halfPi$2 + y) / 2);
  8857. }
  8858. function conicConformalRaw(y0, y1) {
  8859. var cy0 = cos$1(y0),
  8860. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8861. f = cy0 * pow(tany(y0), n) / n;
  8862. if (!n) return mercatorRaw;
  8863. function project(x, y) {
  8864. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8865. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8866. var r = f / pow(tany(y), n);
  8867. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8868. }
  8869. project.invert = function(x, y) {
  8870. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy),
  8871. l = atan2(x, abs(fy)) * sign(fy);
  8872. if (fy * n < 0)
  8873. l -= pi$3 * sign(x) * sign(fy);
  8874. return [l / n, 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8875. };
  8876. return project;
  8877. }
  8878. function conicConformal() {
  8879. return conicProjection(conicConformalRaw)
  8880. .scale(109.5)
  8881. .parallels([30, 30]);
  8882. }
  8883. function equirectangularRaw(lambda, phi) {
  8884. return [lambda, phi];
  8885. }
  8886. equirectangularRaw.invert = equirectangularRaw;
  8887. function equirectangular() {
  8888. return projection(equirectangularRaw)
  8889. .scale(152.63);
  8890. }
  8891. function conicEquidistantRaw(y0, y1) {
  8892. var cy0 = cos$1(y0),
  8893. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8894. g = cy0 / n + y0;
  8895. if (abs(n) < epsilon$2) return equirectangularRaw;
  8896. function project(x, y) {
  8897. var gy = g - y, nx = n * x;
  8898. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8899. }
  8900. project.invert = function(x, y) {
  8901. var gy = g - y,
  8902. l = atan2(x, abs(gy)) * sign(gy);
  8903. if (gy * n < 0)
  8904. l -= pi$3 * sign(x) * sign(gy);
  8905. return [l / n, g - sign(n) * sqrt(x * x + gy * gy)];
  8906. };
  8907. return project;
  8908. }
  8909. function conicEquidistant() {
  8910. return conicProjection(conicEquidistantRaw)
  8911. .scale(131.154)
  8912. .center([0, 13.9389]);
  8913. }
  8914. var A1 = 1.340264,
  8915. A2 = -0.081106,
  8916. A3 = 0.000893,
  8917. A4 = 0.003796,
  8918. M = sqrt(3) / 2,
  8919. iterations = 12;
  8920. function equalEarthRaw(lambda, phi) {
  8921. var l = asin(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
  8922. return [
  8923. lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
  8924. l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
  8925. ];
  8926. }
  8927. equalEarthRaw.invert = function(x, y) {
  8928. var l = y, l2 = l * l, l6 = l2 * l2 * l2;
  8929. for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
  8930. fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
  8931. fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
  8932. l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
  8933. if (abs(delta) < epsilon2$1) break;
  8934. }
  8935. return [
  8936. M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
  8937. asin(sin$1(l) / M)
  8938. ];
  8939. };
  8940. function equalEarth() {
  8941. return projection(equalEarthRaw)
  8942. .scale(177.158);
  8943. }
  8944. function gnomonicRaw(x, y) {
  8945. var cy = cos$1(y), k = cos$1(x) * cy;
  8946. return [cy * sin$1(x) / k, sin$1(y) / k];
  8947. }
  8948. gnomonicRaw.invert = azimuthalInvert(atan);
  8949. function gnomonic() {
  8950. return projection(gnomonicRaw)
  8951. .scale(144.049)
  8952. .clipAngle(60);
  8953. }
  8954. function identity$5() {
  8955. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect
  8956. alpha = 0, ca, sa, // angle
  8957. x0 = null, y0, x1, y1, // clip extent
  8958. kx = 1, ky = 1,
  8959. transform = transformer({
  8960. point: function(x, y) {
  8961. var p = projection([x, y]);
  8962. this.stream.point(p[0], p[1]);
  8963. }
  8964. }),
  8965. postclip = identity$4,
  8966. cache,
  8967. cacheStream;
  8968. function reset() {
  8969. kx = k * sx;
  8970. ky = k * sy;
  8971. cache = cacheStream = null;
  8972. return projection;
  8973. }
  8974. function projection (p) {
  8975. var x = p[0] * kx, y = p[1] * ky;
  8976. if (alpha) {
  8977. var t = y * ca - x * sa;
  8978. x = x * ca + y * sa;
  8979. y = t;
  8980. }
  8981. return [x + tx, y + ty];
  8982. }
  8983. projection.invert = function(p) {
  8984. var x = p[0] - tx, y = p[1] - ty;
  8985. if (alpha) {
  8986. var t = y * ca + x * sa;
  8987. x = x * ca - y * sa;
  8988. y = t;
  8989. }
  8990. return [x / kx, y / ky];
  8991. };
  8992. projection.stream = function(stream) {
  8993. return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
  8994. };
  8995. projection.postclip = function(_) {
  8996. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8997. };
  8998. projection.clipExtent = function(_) {
  8999. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  9000. };
  9001. projection.scale = function(_) {
  9002. return arguments.length ? (k = +_, reset()) : k;
  9003. };
  9004. projection.translate = function(_) {
  9005. return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];
  9006. };
  9007. projection.angle = function(_) {
  9008. return arguments.length ? (alpha = _ % 360 * radians, sa = sin$1(alpha), ca = cos$1(alpha), reset()) : alpha * degrees$1;
  9009. };
  9010. projection.reflectX = function(_) {
  9011. return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;
  9012. };
  9013. projection.reflectY = function(_) {
  9014. return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;
  9015. };
  9016. projection.fitExtent = function(extent, object) {
  9017. return fitExtent(projection, extent, object);
  9018. };
  9019. projection.fitSize = function(size, object) {
  9020. return fitSize(projection, size, object);
  9021. };
  9022. projection.fitWidth = function(width, object) {
  9023. return fitWidth(projection, width, object);
  9024. };
  9025. projection.fitHeight = function(height, object) {
  9026. return fitHeight(projection, height, object);
  9027. };
  9028. return projection;
  9029. }
  9030. function naturalEarth1Raw(lambda, phi) {
  9031. var phi2 = phi * phi, phi4 = phi2 * phi2;
  9032. return [
  9033. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  9034. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  9035. ];
  9036. }
  9037. naturalEarth1Raw.invert = function(x, y) {
  9038. var phi = y, i = 25, delta;
  9039. do {
  9040. var phi2 = phi * phi, phi4 = phi2 * phi2;
  9041. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  9042. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  9043. } while (abs(delta) > epsilon$2 && --i > 0);
  9044. return [
  9045. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  9046. phi
  9047. ];
  9048. };
  9049. function naturalEarth1() {
  9050. return projection(naturalEarth1Raw)
  9051. .scale(175.295);
  9052. }
  9053. function orthographicRaw(x, y) {
  9054. return [cos$1(y) * sin$1(x), sin$1(y)];
  9055. }
  9056. orthographicRaw.invert = azimuthalInvert(asin);
  9057. function orthographic() {
  9058. return projection(orthographicRaw)
  9059. .scale(249.5)
  9060. .clipAngle(90 + epsilon$2);
  9061. }
  9062. function stereographicRaw(x, y) {
  9063. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  9064. return [cy * sin$1(x) / k, sin$1(y) / k];
  9065. }
  9066. stereographicRaw.invert = azimuthalInvert(function(z) {
  9067. return 2 * atan(z);
  9068. });
  9069. function stereographic() {
  9070. return projection(stereographicRaw)
  9071. .scale(250)
  9072. .clipAngle(142);
  9073. }
  9074. function transverseMercatorRaw(lambda, phi) {
  9075. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  9076. }
  9077. transverseMercatorRaw.invert = function(x, y) {
  9078. return [-y, 2 * atan(exp(x)) - halfPi$2];
  9079. };
  9080. function transverseMercator() {
  9081. var m = mercatorProjection(transverseMercatorRaw),
  9082. center = m.center,
  9083. rotate = m.rotate;
  9084. m.center = function(_) {
  9085. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  9086. };
  9087. m.rotate = function(_) {
  9088. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  9089. };
  9090. return rotate([0, 0, 90])
  9091. .scale(159.155);
  9092. }
  9093. function defaultSeparation(a, b) {
  9094. return a.parent === b.parent ? 1 : 2;
  9095. }
  9096. function meanX(children) {
  9097. return children.reduce(meanXReduce, 0) / children.length;
  9098. }
  9099. function meanXReduce(x, c) {
  9100. return x + c.x;
  9101. }
  9102. function maxY(children) {
  9103. return 1 + children.reduce(maxYReduce, 0);
  9104. }
  9105. function maxYReduce(y, c) {
  9106. return Math.max(y, c.y);
  9107. }
  9108. function leafLeft(node) {
  9109. var children;
  9110. while (children = node.children) node = children[0];
  9111. return node;
  9112. }
  9113. function leafRight(node) {
  9114. var children;
  9115. while (children = node.children) node = children[children.length - 1];
  9116. return node;
  9117. }
  9118. function cluster() {
  9119. var separation = defaultSeparation,
  9120. dx = 1,
  9121. dy = 1,
  9122. nodeSize = false;
  9123. function cluster(root) {
  9124. var previousNode,
  9125. x = 0;
  9126. // First walk, computing the initial x & y values.
  9127. root.eachAfter(function(node) {
  9128. var children = node.children;
  9129. if (children) {
  9130. node.x = meanX(children);
  9131. node.y = maxY(children);
  9132. } else {
  9133. node.x = previousNode ? x += separation(node, previousNode) : 0;
  9134. node.y = 0;
  9135. previousNode = node;
  9136. }
  9137. });
  9138. var left = leafLeft(root),
  9139. right = leafRight(root),
  9140. x0 = left.x - separation(left, right) / 2,
  9141. x1 = right.x + separation(right, left) / 2;
  9142. // Second walk, normalizing x & y to the desired size.
  9143. return root.eachAfter(nodeSize ? function(node) {
  9144. node.x = (node.x - root.x) * dx;
  9145. node.y = (root.y - node.y) * dy;
  9146. } : function(node) {
  9147. node.x = (node.x - x0) / (x1 - x0) * dx;
  9148. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  9149. });
  9150. }
  9151. cluster.separation = function(x) {
  9152. return arguments.length ? (separation = x, cluster) : separation;
  9153. };
  9154. cluster.size = function(x) {
  9155. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  9156. };
  9157. cluster.nodeSize = function(x) {
  9158. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  9159. };
  9160. return cluster;
  9161. }
  9162. function count(node) {
  9163. var sum = 0,
  9164. children = node.children,
  9165. i = children && children.length;
  9166. if (!i) sum = 1;
  9167. else while (--i >= 0) sum += children[i].value;
  9168. node.value = sum;
  9169. }
  9170. function node_count() {
  9171. return this.eachAfter(count);
  9172. }
  9173. function node_each(callback) {
  9174. var node = this, current, next = [node], children, i, n;
  9175. do {
  9176. current = next.reverse(), next = [];
  9177. while (node = current.pop()) {
  9178. callback(node), children = node.children;
  9179. if (children) for (i = 0, n = children.length; i < n; ++i) {
  9180. next.push(children[i]);
  9181. }
  9182. }
  9183. } while (next.length);
  9184. return this;
  9185. }
  9186. function node_eachBefore(callback) {
  9187. var node = this, nodes = [node], children, i;
  9188. while (node = nodes.pop()) {
  9189. callback(node), children = node.children;
  9190. if (children) for (i = children.length - 1; i >= 0; --i) {
  9191. nodes.push(children[i]);
  9192. }
  9193. }
  9194. return this;
  9195. }
  9196. function node_eachAfter(callback) {
  9197. var node = this, nodes = [node], next = [], children, i, n;
  9198. while (node = nodes.pop()) {
  9199. next.push(node), children = node.children;
  9200. if (children) for (i = 0, n = children.length; i < n; ++i) {
  9201. nodes.push(children[i]);
  9202. }
  9203. }
  9204. while (node = next.pop()) {
  9205. callback(node);
  9206. }
  9207. return this;
  9208. }
  9209. function node_sum(value) {
  9210. return this.eachAfter(function(node) {
  9211. var sum = +value(node.data) || 0,
  9212. children = node.children,
  9213. i = children && children.length;
  9214. while (--i >= 0) sum += children[i].value;
  9215. node.value = sum;
  9216. });
  9217. }
  9218. function node_sort(compare) {
  9219. return this.eachBefore(function(node) {
  9220. if (node.children) {
  9221. node.children.sort(compare);
  9222. }
  9223. });
  9224. }
  9225. function node_path(end) {
  9226. var start = this,
  9227. ancestor = leastCommonAncestor(start, end),
  9228. nodes = [start];
  9229. while (start !== ancestor) {
  9230. start = start.parent;
  9231. nodes.push(start);
  9232. }
  9233. var k = nodes.length;
  9234. while (end !== ancestor) {
  9235. nodes.splice(k, 0, end);
  9236. end = end.parent;
  9237. }
  9238. return nodes;
  9239. }
  9240. function leastCommonAncestor(a, b) {
  9241. if (a === b) return a;
  9242. var aNodes = a.ancestors(),
  9243. bNodes = b.ancestors(),
  9244. c = null;
  9245. a = aNodes.pop();
  9246. b = bNodes.pop();
  9247. while (a === b) {
  9248. c = a;
  9249. a = aNodes.pop();
  9250. b = bNodes.pop();
  9251. }
  9252. return c;
  9253. }
  9254. function node_ancestors() {
  9255. var node = this, nodes = [node];
  9256. while (node = node.parent) {
  9257. nodes.push(node);
  9258. }
  9259. return nodes;
  9260. }
  9261. function node_descendants() {
  9262. var nodes = [];
  9263. this.each(function(node) {
  9264. nodes.push(node);
  9265. });
  9266. return nodes;
  9267. }
  9268. function node_leaves() {
  9269. var leaves = [];
  9270. this.eachBefore(function(node) {
  9271. if (!node.children) {
  9272. leaves.push(node);
  9273. }
  9274. });
  9275. return leaves;
  9276. }
  9277. function node_links() {
  9278. var root = this, links = [];
  9279. root.each(function(node) {
  9280. if (node !== root) { // Don’t include the root’s parent, if any.
  9281. links.push({source: node.parent, target: node});
  9282. }
  9283. });
  9284. return links;
  9285. }
  9286. function hierarchy(data, children) {
  9287. var root = new Node(data),
  9288. valued = +data.value && (root.value = data.value),
  9289. node,
  9290. nodes = [root],
  9291. child,
  9292. childs,
  9293. i,
  9294. n;
  9295. if (children == null) children = defaultChildren;
  9296. while (node = nodes.pop()) {
  9297. if (valued) node.value = +node.data.value;
  9298. if ((childs = children(node.data)) && (n = childs.length)) {
  9299. node.children = new Array(n);
  9300. for (i = n - 1; i >= 0; --i) {
  9301. nodes.push(child = node.children[i] = new Node(childs[i]));
  9302. child.parent = node;
  9303. child.depth = node.depth + 1;
  9304. }
  9305. }
  9306. }
  9307. return root.eachBefore(computeHeight);
  9308. }
  9309. function node_copy() {
  9310. return hierarchy(this).eachBefore(copyData);
  9311. }
  9312. function defaultChildren(d) {
  9313. return d.children;
  9314. }
  9315. function copyData(node) {
  9316. node.data = node.data.data;
  9317. }
  9318. function computeHeight(node) {
  9319. var height = 0;
  9320. do node.height = height;
  9321. while ((node = node.parent) && (node.height < ++height));
  9322. }
  9323. function Node(data) {
  9324. this.data = data;
  9325. this.depth =
  9326. this.height = 0;
  9327. this.parent = null;
  9328. }
  9329. Node.prototype = hierarchy.prototype = {
  9330. constructor: Node,
  9331. count: node_count,
  9332. each: node_each,
  9333. eachAfter: node_eachAfter,
  9334. eachBefore: node_eachBefore,
  9335. sum: node_sum,
  9336. sort: node_sort,
  9337. path: node_path,
  9338. ancestors: node_ancestors,
  9339. descendants: node_descendants,
  9340. leaves: node_leaves,
  9341. links: node_links,
  9342. copy: node_copy
  9343. };
  9344. var slice$4 = Array.prototype.slice;
  9345. function shuffle$1(array) {
  9346. var m = array.length,
  9347. t,
  9348. i;
  9349. while (m) {
  9350. i = Math.random() * m-- | 0;
  9351. t = array[m];
  9352. array[m] = array[i];
  9353. array[i] = t;
  9354. }
  9355. return array;
  9356. }
  9357. function enclose(circles) {
  9358. var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
  9359. while (i < n) {
  9360. p = circles[i];
  9361. if (e && enclosesWeak(e, p)) ++i;
  9362. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  9363. }
  9364. return e;
  9365. }
  9366. function extendBasis(B, p) {
  9367. var i, j;
  9368. if (enclosesWeakAll(p, B)) return [p];
  9369. // If we get here then B must have at least one element.
  9370. for (i = 0; i < B.length; ++i) {
  9371. if (enclosesNot(p, B[i])
  9372. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  9373. return [B[i], p];
  9374. }
  9375. }
  9376. // If we get here then B must have at least two elements.
  9377. for (i = 0; i < B.length - 1; ++i) {
  9378. for (j = i + 1; j < B.length; ++j) {
  9379. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  9380. && enclosesNot(encloseBasis2(B[i], p), B[j])
  9381. && enclosesNot(encloseBasis2(B[j], p), B[i])
  9382. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  9383. return [B[i], B[j], p];
  9384. }
  9385. }
  9386. }
  9387. // If we get here then something is very wrong.
  9388. throw new Error;
  9389. }
  9390. function enclosesNot(a, b) {
  9391. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  9392. return dr < 0 || dr * dr < dx * dx + dy * dy;
  9393. }
  9394. function enclosesWeak(a, b) {
  9395. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9396. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9397. }
  9398. function enclosesWeakAll(a, B) {
  9399. for (var i = 0; i < B.length; ++i) {
  9400. if (!enclosesWeak(a, B[i])) {
  9401. return false;
  9402. }
  9403. }
  9404. return true;
  9405. }
  9406. function encloseBasis(B) {
  9407. switch (B.length) {
  9408. case 1: return encloseBasis1(B[0]);
  9409. case 2: return encloseBasis2(B[0], B[1]);
  9410. case 3: return encloseBasis3(B[0], B[1], B[2]);
  9411. }
  9412. }
  9413. function encloseBasis1(a) {
  9414. return {
  9415. x: a.x,
  9416. y: a.y,
  9417. r: a.r
  9418. };
  9419. }
  9420. function encloseBasis2(a, b) {
  9421. var x1 = a.x, y1 = a.y, r1 = a.r,
  9422. x2 = b.x, y2 = b.y, r2 = b.r,
  9423. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  9424. l = Math.sqrt(x21 * x21 + y21 * y21);
  9425. return {
  9426. x: (x1 + x2 + x21 / l * r21) / 2,
  9427. y: (y1 + y2 + y21 / l * r21) / 2,
  9428. r: (l + r1 + r2) / 2
  9429. };
  9430. }
  9431. function encloseBasis3(a, b, c) {
  9432. var x1 = a.x, y1 = a.y, r1 = a.r,
  9433. x2 = b.x, y2 = b.y, r2 = b.r,
  9434. x3 = c.x, y3 = c.y, r3 = c.r,
  9435. a2 = x1 - x2,
  9436. a3 = x1 - x3,
  9437. b2 = y1 - y2,
  9438. b3 = y1 - y3,
  9439. c2 = r2 - r1,
  9440. c3 = r3 - r1,
  9441. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  9442. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  9443. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  9444. ab = a3 * b2 - a2 * b3,
  9445. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  9446. xb = (b3 * c2 - b2 * c3) / ab,
  9447. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  9448. yb = (a2 * c3 - a3 * c2) / ab,
  9449. A = xb * xb + yb * yb - 1,
  9450. B = 2 * (r1 + xa * xb + ya * yb),
  9451. C = xa * xa + ya * ya - r1 * r1,
  9452. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  9453. return {
  9454. x: x1 + xa + xb * r,
  9455. y: y1 + ya + yb * r,
  9456. r: r
  9457. };
  9458. }
  9459. function place(b, a, c) {
  9460. var dx = b.x - a.x, x, a2,
  9461. dy = b.y - a.y, y, b2,
  9462. d2 = dx * dx + dy * dy;
  9463. if (d2) {
  9464. a2 = a.r + c.r, a2 *= a2;
  9465. b2 = b.r + c.r, b2 *= b2;
  9466. if (a2 > b2) {
  9467. x = (d2 + b2 - a2) / (2 * d2);
  9468. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  9469. c.x = b.x - x * dx - y * dy;
  9470. c.y = b.y - x * dy + y * dx;
  9471. } else {
  9472. x = (d2 + a2 - b2) / (2 * d2);
  9473. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  9474. c.x = a.x + x * dx - y * dy;
  9475. c.y = a.y + x * dy + y * dx;
  9476. }
  9477. } else {
  9478. c.x = a.x + c.r;
  9479. c.y = a.y;
  9480. }
  9481. }
  9482. function intersects(a, b) {
  9483. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9484. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9485. }
  9486. function score(node) {
  9487. var a = node._,
  9488. b = node.next._,
  9489. ab = a.r + b.r,
  9490. dx = (a.x * b.r + b.x * a.r) / ab,
  9491. dy = (a.y * b.r + b.y * a.r) / ab;
  9492. return dx * dx + dy * dy;
  9493. }
  9494. function Node$1(circle) {
  9495. this._ = circle;
  9496. this.next = null;
  9497. this.previous = null;
  9498. }
  9499. function packEnclose(circles) {
  9500. if (!(n = circles.length)) return 0;
  9501. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  9502. // Place the first circle.
  9503. a = circles[0], a.x = 0, a.y = 0;
  9504. if (!(n > 1)) return a.r;
  9505. // Place the second circle.
  9506. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  9507. if (!(n > 2)) return a.r + b.r;
  9508. // Place the third circle.
  9509. place(b, a, c = circles[2]);
  9510. // Initialize the front-chain using the first three circles a, b and c.
  9511. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  9512. a.next = c.previous = b;
  9513. b.next = a.previous = c;
  9514. c.next = b.previous = a;
  9515. // Attempt to place each remaining circle…
  9516. pack: for (i = 3; i < n; ++i) {
  9517. place(a._, b._, c = circles[i]), c = new Node$1(c);
  9518. // Find the closest intersecting circle on the front-chain, if any.
  9519. // “Closeness” is determined by linear distance along the front-chain.
  9520. // “Ahead” or “behind” is likewise determined by linear distance.
  9521. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  9522. do {
  9523. if (sj <= sk) {
  9524. if (intersects(j._, c._)) {
  9525. b = j, a.next = b, b.previous = a, --i;
  9526. continue pack;
  9527. }
  9528. sj += j._.r, j = j.next;
  9529. } else {
  9530. if (intersects(k._, c._)) {
  9531. a = k, a.next = b, b.previous = a, --i;
  9532. continue pack;
  9533. }
  9534. sk += k._.r, k = k.previous;
  9535. }
  9536. } while (j !== k.next);
  9537. // Success! Insert the new circle c between a and b.
  9538. c.previous = a, c.next = b, a.next = b.previous = b = c;
  9539. // Compute the new closest circle pair to the centroid.
  9540. aa = score(a);
  9541. while ((c = c.next) !== b) {
  9542. if ((ca = score(c)) < aa) {
  9543. a = c, aa = ca;
  9544. }
  9545. }
  9546. b = a.next;
  9547. }
  9548. // Compute the enclosing circle of the front chain.
  9549. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  9550. // Translate the circles to put the enclosing circle around the origin.
  9551. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  9552. return c.r;
  9553. }
  9554. function siblings(circles) {
  9555. packEnclose(circles);
  9556. return circles;
  9557. }
  9558. function optional(f) {
  9559. return f == null ? null : required(f);
  9560. }
  9561. function required(f) {
  9562. if (typeof f !== "function") throw new Error;
  9563. return f;
  9564. }
  9565. function constantZero() {
  9566. return 0;
  9567. }
  9568. function constant$9(x) {
  9569. return function() {
  9570. return x;
  9571. };
  9572. }
  9573. function defaultRadius$1(d) {
  9574. return Math.sqrt(d.value);
  9575. }
  9576. function index$2() {
  9577. var radius = null,
  9578. dx = 1,
  9579. dy = 1,
  9580. padding = constantZero;
  9581. function pack(root) {
  9582. root.x = dx / 2, root.y = dy / 2;
  9583. if (radius) {
  9584. root.eachBefore(radiusLeaf(radius))
  9585. .eachAfter(packChildren(padding, 0.5))
  9586. .eachBefore(translateChild(1));
  9587. } else {
  9588. root.eachBefore(radiusLeaf(defaultRadius$1))
  9589. .eachAfter(packChildren(constantZero, 1))
  9590. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  9591. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  9592. }
  9593. return root;
  9594. }
  9595. pack.radius = function(x) {
  9596. return arguments.length ? (radius = optional(x), pack) : radius;
  9597. };
  9598. pack.size = function(x) {
  9599. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  9600. };
  9601. pack.padding = function(x) {
  9602. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  9603. };
  9604. return pack;
  9605. }
  9606. function radiusLeaf(radius) {
  9607. return function(node) {
  9608. if (!node.children) {
  9609. node.r = Math.max(0, +radius(node) || 0);
  9610. }
  9611. };
  9612. }
  9613. function packChildren(padding, k) {
  9614. return function(node) {
  9615. if (children = node.children) {
  9616. var children,
  9617. i,
  9618. n = children.length,
  9619. r = padding(node) * k || 0,
  9620. e;
  9621. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  9622. e = packEnclose(children);
  9623. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  9624. node.r = e + r;
  9625. }
  9626. };
  9627. }
  9628. function translateChild(k) {
  9629. return function(node) {
  9630. var parent = node.parent;
  9631. node.r *= k;
  9632. if (parent) {
  9633. node.x = parent.x + k * node.x;
  9634. node.y = parent.y + k * node.y;
  9635. }
  9636. };
  9637. }
  9638. function roundNode(node) {
  9639. node.x0 = Math.round(node.x0);
  9640. node.y0 = Math.round(node.y0);
  9641. node.x1 = Math.round(node.x1);
  9642. node.y1 = Math.round(node.y1);
  9643. }
  9644. function treemapDice(parent, x0, y0, x1, y1) {
  9645. var nodes = parent.children,
  9646. node,
  9647. i = -1,
  9648. n = nodes.length,
  9649. k = parent.value && (x1 - x0) / parent.value;
  9650. while (++i < n) {
  9651. node = nodes[i], node.y0 = y0, node.y1 = y1;
  9652. node.x0 = x0, node.x1 = x0 += node.value * k;
  9653. }
  9654. }
  9655. function partition() {
  9656. var dx = 1,
  9657. dy = 1,
  9658. padding = 0,
  9659. round = false;
  9660. function partition(root) {
  9661. var n = root.height + 1;
  9662. root.x0 =
  9663. root.y0 = padding;
  9664. root.x1 = dx;
  9665. root.y1 = dy / n;
  9666. root.eachBefore(positionNode(dy, n));
  9667. if (round) root.eachBefore(roundNode);
  9668. return root;
  9669. }
  9670. function positionNode(dy, n) {
  9671. return function(node) {
  9672. if (node.children) {
  9673. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  9674. }
  9675. var x0 = node.x0,
  9676. y0 = node.y0,
  9677. x1 = node.x1 - padding,
  9678. y1 = node.y1 - padding;
  9679. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9680. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9681. node.x0 = x0;
  9682. node.y0 = y0;
  9683. node.x1 = x1;
  9684. node.y1 = y1;
  9685. };
  9686. }
  9687. partition.round = function(x) {
  9688. return arguments.length ? (round = !!x, partition) : round;
  9689. };
  9690. partition.size = function(x) {
  9691. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  9692. };
  9693. partition.padding = function(x) {
  9694. return arguments.length ? (padding = +x, partition) : padding;
  9695. };
  9696. return partition;
  9697. }
  9698. var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
  9699. preroot = {depth: -1},
  9700. ambiguous = {};
  9701. function defaultId(d) {
  9702. return d.id;
  9703. }
  9704. function defaultParentId(d) {
  9705. return d.parentId;
  9706. }
  9707. function stratify() {
  9708. var id = defaultId,
  9709. parentId = defaultParentId;
  9710. function stratify(data) {
  9711. var d,
  9712. i,
  9713. n = data.length,
  9714. root,
  9715. parent,
  9716. node,
  9717. nodes = new Array(n),
  9718. nodeId,
  9719. nodeKey,
  9720. nodeByKey = {};
  9721. for (i = 0; i < n; ++i) {
  9722. d = data[i], node = nodes[i] = new Node(d);
  9723. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  9724. nodeKey = keyPrefix$1 + (node.id = nodeId);
  9725. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  9726. }
  9727. }
  9728. for (i = 0; i < n; ++i) {
  9729. node = nodes[i], nodeId = parentId(data[i], i, data);
  9730. if (nodeId == null || !(nodeId += "")) {
  9731. if (root) throw new Error("multiple roots");
  9732. root = node;
  9733. } else {
  9734. parent = nodeByKey[keyPrefix$1 + nodeId];
  9735. if (!parent) throw new Error("missing: " + nodeId);
  9736. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  9737. if (parent.children) parent.children.push(node);
  9738. else parent.children = [node];
  9739. node.parent = parent;
  9740. }
  9741. }
  9742. if (!root) throw new Error("no root");
  9743. root.parent = preroot;
  9744. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  9745. root.parent = null;
  9746. if (n > 0) throw new Error("cycle");
  9747. return root;
  9748. }
  9749. stratify.id = function(x) {
  9750. return arguments.length ? (id = required(x), stratify) : id;
  9751. };
  9752. stratify.parentId = function(x) {
  9753. return arguments.length ? (parentId = required(x), stratify) : parentId;
  9754. };
  9755. return stratify;
  9756. }
  9757. function defaultSeparation$1(a, b) {
  9758. return a.parent === b.parent ? 1 : 2;
  9759. }
  9760. // function radialSeparation(a, b) {
  9761. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  9762. // }
  9763. // This function is used to traverse the left contour of a subtree (or
  9764. // subforest). It returns the successor of v on this contour. This successor is
  9765. // either given by the leftmost child of v or by the thread of v. The function
  9766. // returns null if and only if v is on the highest level of its subtree.
  9767. function nextLeft(v) {
  9768. var children = v.children;
  9769. return children ? children[0] : v.t;
  9770. }
  9771. // This function works analogously to nextLeft.
  9772. function nextRight(v) {
  9773. var children = v.children;
  9774. return children ? children[children.length - 1] : v.t;
  9775. }
  9776. // Shifts the current subtree rooted at w+. This is done by increasing
  9777. // prelim(w+) and mod(w+) by shift.
  9778. function moveSubtree(wm, wp, shift) {
  9779. var change = shift / (wp.i - wm.i);
  9780. wp.c -= change;
  9781. wp.s += shift;
  9782. wm.c += change;
  9783. wp.z += shift;
  9784. wp.m += shift;
  9785. }
  9786. // All other shifts, applied to the smaller subtrees between w- and w+, are
  9787. // performed by this function. To prepare the shifts, we have to adjust
  9788. // change(w+), shift(w+), and change(w-).
  9789. function executeShifts(v) {
  9790. var shift = 0,
  9791. change = 0,
  9792. children = v.children,
  9793. i = children.length,
  9794. w;
  9795. while (--i >= 0) {
  9796. w = children[i];
  9797. w.z += shift;
  9798. w.m += shift;
  9799. shift += w.s + (change += w.c);
  9800. }
  9801. }
  9802. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9803. // returns the specified (default) ancestor.
  9804. function nextAncestor(vim, v, ancestor) {
  9805. return vim.a.parent === v.parent ? vim.a : ancestor;
  9806. }
  9807. function TreeNode(node, i) {
  9808. this._ = node;
  9809. this.parent = null;
  9810. this.children = null;
  9811. this.A = null; // default ancestor
  9812. this.a = this; // ancestor
  9813. this.z = 0; // prelim
  9814. this.m = 0; // mod
  9815. this.c = 0; // change
  9816. this.s = 0; // shift
  9817. this.t = null; // thread
  9818. this.i = i; // number
  9819. }
  9820. TreeNode.prototype = Object.create(Node.prototype);
  9821. function treeRoot(root) {
  9822. var tree = new TreeNode(root, 0),
  9823. node,
  9824. nodes = [tree],
  9825. child,
  9826. children,
  9827. i,
  9828. n;
  9829. while (node = nodes.pop()) {
  9830. if (children = node._.children) {
  9831. node.children = new Array(n = children.length);
  9832. for (i = n - 1; i >= 0; --i) {
  9833. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9834. child.parent = node;
  9835. }
  9836. }
  9837. }
  9838. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9839. return tree;
  9840. }
  9841. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9842. function tree() {
  9843. var separation = defaultSeparation$1,
  9844. dx = 1,
  9845. dy = 1,
  9846. nodeSize = null;
  9847. function tree(root) {
  9848. var t = treeRoot(root);
  9849. // Compute the layout using Buchheim et al.’s algorithm.
  9850. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9851. t.eachBefore(secondWalk);
  9852. // If a fixed node size is specified, scale x and y.
  9853. if (nodeSize) root.eachBefore(sizeNode);
  9854. // If a fixed tree size is specified, scale x and y based on the extent.
  9855. // Compute the left-most, right-most, and depth-most nodes for extents.
  9856. else {
  9857. var left = root,
  9858. right = root,
  9859. bottom = root;
  9860. root.eachBefore(function(node) {
  9861. if (node.x < left.x) left = node;
  9862. if (node.x > right.x) right = node;
  9863. if (node.depth > bottom.depth) bottom = node;
  9864. });
  9865. var s = left === right ? 1 : separation(left, right) / 2,
  9866. tx = s - left.x,
  9867. kx = dx / (right.x + s + tx),
  9868. ky = dy / (bottom.depth || 1);
  9869. root.eachBefore(function(node) {
  9870. node.x = (node.x + tx) * kx;
  9871. node.y = node.depth * ky;
  9872. });
  9873. }
  9874. return root;
  9875. }
  9876. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9877. // applied recursively to the children of v, as well as the function
  9878. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9879. // node v is placed to the midpoint of its outermost children.
  9880. function firstWalk(v) {
  9881. var children = v.children,
  9882. siblings = v.parent.children,
  9883. w = v.i ? siblings[v.i - 1] : null;
  9884. if (children) {
  9885. executeShifts(v);
  9886. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9887. if (w) {
  9888. v.z = w.z + separation(v._, w._);
  9889. v.m = v.z - midpoint;
  9890. } else {
  9891. v.z = midpoint;
  9892. }
  9893. } else if (w) {
  9894. v.z = w.z + separation(v._, w._);
  9895. }
  9896. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9897. }
  9898. // Computes all real x-coordinates by summing up the modifiers recursively.
  9899. function secondWalk(v) {
  9900. v._.x = v.z + v.parent.m;
  9901. v.m += v.parent.m;
  9902. }
  9903. // The core of the algorithm. Here, a new subtree is combined with the
  9904. // previous subtrees. Threads are used to traverse the inside and outside
  9905. // contours of the left and right subtree up to the highest common level. The
  9906. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9907. // superscript o means outside and i means inside, the subscript - means left
  9908. // subtree and + means right subtree. For summing up the modifiers along the
  9909. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9910. // nodes of the inside contours conflict, we compute the left one of the
  9911. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9912. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9913. // Finally, we add a new thread (if necessary).
  9914. function apportion(v, w, ancestor) {
  9915. if (w) {
  9916. var vip = v,
  9917. vop = v,
  9918. vim = w,
  9919. vom = vip.parent.children[0],
  9920. sip = vip.m,
  9921. sop = vop.m,
  9922. sim = vim.m,
  9923. som = vom.m,
  9924. shift;
  9925. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9926. vom = nextLeft(vom);
  9927. vop = nextRight(vop);
  9928. vop.a = v;
  9929. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9930. if (shift > 0) {
  9931. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9932. sip += shift;
  9933. sop += shift;
  9934. }
  9935. sim += vim.m;
  9936. sip += vip.m;
  9937. som += vom.m;
  9938. sop += vop.m;
  9939. }
  9940. if (vim && !nextRight(vop)) {
  9941. vop.t = vim;
  9942. vop.m += sim - sop;
  9943. }
  9944. if (vip && !nextLeft(vom)) {
  9945. vom.t = vip;
  9946. vom.m += sip - som;
  9947. ancestor = v;
  9948. }
  9949. }
  9950. return ancestor;
  9951. }
  9952. function sizeNode(node) {
  9953. node.x *= dx;
  9954. node.y = node.depth * dy;
  9955. }
  9956. tree.separation = function(x) {
  9957. return arguments.length ? (separation = x, tree) : separation;
  9958. };
  9959. tree.size = function(x) {
  9960. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9961. };
  9962. tree.nodeSize = function(x) {
  9963. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9964. };
  9965. return tree;
  9966. }
  9967. function treemapSlice(parent, x0, y0, x1, y1) {
  9968. var nodes = parent.children,
  9969. node,
  9970. i = -1,
  9971. n = nodes.length,
  9972. k = parent.value && (y1 - y0) / parent.value;
  9973. while (++i < n) {
  9974. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9975. node.y0 = y0, node.y1 = y0 += node.value * k;
  9976. }
  9977. }
  9978. var phi = (1 + Math.sqrt(5)) / 2;
  9979. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9980. var rows = [],
  9981. nodes = parent.children,
  9982. row,
  9983. nodeValue,
  9984. i0 = 0,
  9985. i1 = 0,
  9986. n = nodes.length,
  9987. dx, dy,
  9988. value = parent.value,
  9989. sumValue,
  9990. minValue,
  9991. maxValue,
  9992. newRatio,
  9993. minRatio,
  9994. alpha,
  9995. beta;
  9996. while (i0 < n) {
  9997. dx = x1 - x0, dy = y1 - y0;
  9998. // Find the next non-empty node.
  9999. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  10000. minValue = maxValue = sumValue;
  10001. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  10002. beta = sumValue * sumValue * alpha;
  10003. minRatio = Math.max(maxValue / beta, beta / minValue);
  10004. // Keep adding nodes while the aspect ratio maintains or improves.
  10005. for (; i1 < n; ++i1) {
  10006. sumValue += nodeValue = nodes[i1].value;
  10007. if (nodeValue < minValue) minValue = nodeValue;
  10008. if (nodeValue > maxValue) maxValue = nodeValue;
  10009. beta = sumValue * sumValue * alpha;
  10010. newRatio = Math.max(maxValue / beta, beta / minValue);
  10011. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  10012. minRatio = newRatio;
  10013. }
  10014. // Position and record the row orientation.
  10015. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  10016. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  10017. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  10018. value -= sumValue, i0 = i1;
  10019. }
  10020. return rows;
  10021. }
  10022. var squarify = (function custom(ratio) {
  10023. function squarify(parent, x0, y0, x1, y1) {
  10024. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  10025. }
  10026. squarify.ratio = function(x) {
  10027. return custom((x = +x) > 1 ? x : 1);
  10028. };
  10029. return squarify;
  10030. })(phi);
  10031. function index$3() {
  10032. var tile = squarify,
  10033. round = false,
  10034. dx = 1,
  10035. dy = 1,
  10036. paddingStack = [0],
  10037. paddingInner = constantZero,
  10038. paddingTop = constantZero,
  10039. paddingRight = constantZero,
  10040. paddingBottom = constantZero,
  10041. paddingLeft = constantZero;
  10042. function treemap(root) {
  10043. root.x0 =
  10044. root.y0 = 0;
  10045. root.x1 = dx;
  10046. root.y1 = dy;
  10047. root.eachBefore(positionNode);
  10048. paddingStack = [0];
  10049. if (round) root.eachBefore(roundNode);
  10050. return root;
  10051. }
  10052. function positionNode(node) {
  10053. var p = paddingStack[node.depth],
  10054. x0 = node.x0 + p,
  10055. y0 = node.y0 + p,
  10056. x1 = node.x1 - p,
  10057. y1 = node.y1 - p;
  10058. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  10059. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  10060. node.x0 = x0;
  10061. node.y0 = y0;
  10062. node.x1 = x1;
  10063. node.y1 = y1;
  10064. if (node.children) {
  10065. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  10066. x0 += paddingLeft(node) - p;
  10067. y0 += paddingTop(node) - p;
  10068. x1 -= paddingRight(node) - p;
  10069. y1 -= paddingBottom(node) - p;
  10070. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  10071. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  10072. tile(node, x0, y0, x1, y1);
  10073. }
  10074. }
  10075. treemap.round = function(x) {
  10076. return arguments.length ? (round = !!x, treemap) : round;
  10077. };
  10078. treemap.size = function(x) {
  10079. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  10080. };
  10081. treemap.tile = function(x) {
  10082. return arguments.length ? (tile = required(x), treemap) : tile;
  10083. };
  10084. treemap.padding = function(x) {
  10085. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  10086. };
  10087. treemap.paddingInner = function(x) {
  10088. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  10089. };
  10090. treemap.paddingOuter = function(x) {
  10091. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  10092. };
  10093. treemap.paddingTop = function(x) {
  10094. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  10095. };
  10096. treemap.paddingRight = function(x) {
  10097. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  10098. };
  10099. treemap.paddingBottom = function(x) {
  10100. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  10101. };
  10102. treemap.paddingLeft = function(x) {
  10103. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  10104. };
  10105. return treemap;
  10106. }
  10107. function binary(parent, x0, y0, x1, y1) {
  10108. var nodes = parent.children,
  10109. i, n = nodes.length,
  10110. sum, sums = new Array(n + 1);
  10111. for (sums[0] = sum = i = 0; i < n; ++i) {
  10112. sums[i + 1] = sum += nodes[i].value;
  10113. }
  10114. partition(0, n, parent.value, x0, y0, x1, y1);
  10115. function partition(i, j, value, x0, y0, x1, y1) {
  10116. if (i >= j - 1) {
  10117. var node = nodes[i];
  10118. node.x0 = x0, node.y0 = y0;
  10119. node.x1 = x1, node.y1 = y1;
  10120. return;
  10121. }
  10122. var valueOffset = sums[i],
  10123. valueTarget = (value / 2) + valueOffset,
  10124. k = i + 1,
  10125. hi = j - 1;
  10126. while (k < hi) {
  10127. var mid = k + hi >>> 1;
  10128. if (sums[mid] < valueTarget) k = mid + 1;
  10129. else hi = mid;
  10130. }
  10131. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  10132. var valueLeft = sums[k] - valueOffset,
  10133. valueRight = value - valueLeft;
  10134. if ((x1 - x0) > (y1 - y0)) {
  10135. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  10136. partition(i, k, valueLeft, x0, y0, xk, y1);
  10137. partition(k, j, valueRight, xk, y0, x1, y1);
  10138. } else {
  10139. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  10140. partition(i, k, valueLeft, x0, y0, x1, yk);
  10141. partition(k, j, valueRight, x0, yk, x1, y1);
  10142. }
  10143. }
  10144. }
  10145. function sliceDice(parent, x0, y0, x1, y1) {
  10146. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  10147. }
  10148. var resquarify = (function custom(ratio) {
  10149. function resquarify(parent, x0, y0, x1, y1) {
  10150. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  10151. var rows,
  10152. row,
  10153. nodes,
  10154. i,
  10155. j = -1,
  10156. n,
  10157. m = rows.length,
  10158. value = parent.value;
  10159. while (++j < m) {
  10160. row = rows[j], nodes = row.children;
  10161. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  10162. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  10163. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  10164. value -= row.value;
  10165. }
  10166. } else {
  10167. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  10168. rows.ratio = ratio;
  10169. }
  10170. }
  10171. resquarify.ratio = function(x) {
  10172. return custom((x = +x) > 1 ? x : 1);
  10173. };
  10174. return resquarify;
  10175. })(phi);
  10176. function area$2(polygon) {
  10177. var i = -1,
  10178. n = polygon.length,
  10179. a,
  10180. b = polygon[n - 1],
  10181. area = 0;
  10182. while (++i < n) {
  10183. a = b;
  10184. b = polygon[i];
  10185. area += a[1] * b[0] - a[0] * b[1];
  10186. }
  10187. return area / 2;
  10188. }
  10189. function centroid$1(polygon) {
  10190. var i = -1,
  10191. n = polygon.length,
  10192. x = 0,
  10193. y = 0,
  10194. a,
  10195. b = polygon[n - 1],
  10196. c,
  10197. k = 0;
  10198. while (++i < n) {
  10199. a = b;
  10200. b = polygon[i];
  10201. k += c = a[0] * b[1] - b[0] * a[1];
  10202. x += (a[0] + b[0]) * c;
  10203. y += (a[1] + b[1]) * c;
  10204. }
  10205. return k *= 3, [x / k, y / k];
  10206. }
  10207. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  10208. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  10209. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  10210. // negative if clockwise, and zero if the points are collinear.
  10211. function cross$1(a, b, c) {
  10212. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  10213. }
  10214. function lexicographicOrder(a, b) {
  10215. return a[0] - b[0] || a[1] - b[1];
  10216. }
  10217. // Computes the upper convex hull per the monotone chain algorithm.
  10218. // Assumes points.length >= 3, is sorted by x, unique in y.
  10219. // Returns an array of indices into points in left-to-right order.
  10220. function computeUpperHullIndexes(points) {
  10221. var n = points.length,
  10222. indexes = [0, 1],
  10223. size = 2;
  10224. for (var i = 2; i < n; ++i) {
  10225. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  10226. indexes[size++] = i;
  10227. }
  10228. return indexes.slice(0, size); // remove popped points
  10229. }
  10230. function hull(points) {
  10231. if ((n = points.length) < 3) return null;
  10232. var i,
  10233. n,
  10234. sortedPoints = new Array(n),
  10235. flippedPoints = new Array(n);
  10236. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  10237. sortedPoints.sort(lexicographicOrder);
  10238. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  10239. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  10240. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  10241. // Construct the hull polygon, removing possible duplicate endpoints.
  10242. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  10243. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  10244. hull = [];
  10245. // Add upper hull in right-to-l order.
  10246. // Then add lower hull in left-to-right order.
  10247. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  10248. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  10249. return hull;
  10250. }
  10251. function contains$2(polygon, point) {
  10252. var n = polygon.length,
  10253. p = polygon[n - 1],
  10254. x = point[0], y = point[1],
  10255. x0 = p[0], y0 = p[1],
  10256. x1, y1,
  10257. inside = false;
  10258. for (var i = 0; i < n; ++i) {
  10259. p = polygon[i], x1 = p[0], y1 = p[1];
  10260. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  10261. x0 = x1, y0 = y1;
  10262. }
  10263. return inside;
  10264. }
  10265. function length$2(polygon) {
  10266. var i = -1,
  10267. n = polygon.length,
  10268. b = polygon[n - 1],
  10269. xa,
  10270. ya,
  10271. xb = b[0],
  10272. yb = b[1],
  10273. perimeter = 0;
  10274. while (++i < n) {
  10275. xa = xb;
  10276. ya = yb;
  10277. b = polygon[i];
  10278. xb = b[0];
  10279. yb = b[1];
  10280. xa -= xb;
  10281. ya -= yb;
  10282. perimeter += Math.sqrt(xa * xa + ya * ya);
  10283. }
  10284. return perimeter;
  10285. }
  10286. function defaultSource$1() {
  10287. return Math.random();
  10288. }
  10289. var uniform = (function sourceRandomUniform(source) {
  10290. function randomUniform(min, max) {
  10291. min = min == null ? 0 : +min;
  10292. max = max == null ? 1 : +max;
  10293. if (arguments.length === 1) max = min, min = 0;
  10294. else max -= min;
  10295. return function() {
  10296. return source() * max + min;
  10297. };
  10298. }
  10299. randomUniform.source = sourceRandomUniform;
  10300. return randomUniform;
  10301. })(defaultSource$1);
  10302. var normal = (function sourceRandomNormal(source) {
  10303. function randomNormal(mu, sigma) {
  10304. var x, r;
  10305. mu = mu == null ? 0 : +mu;
  10306. sigma = sigma == null ? 1 : +sigma;
  10307. return function() {
  10308. var y;
  10309. // If available, use the second previously-generated uniform random.
  10310. if (x != null) y = x, x = null;
  10311. // Otherwise, generate a new x and y.
  10312. else do {
  10313. x = source() * 2 - 1;
  10314. y = source() * 2 - 1;
  10315. r = x * x + y * y;
  10316. } while (!r || r > 1);
  10317. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  10318. };
  10319. }
  10320. randomNormal.source = sourceRandomNormal;
  10321. return randomNormal;
  10322. })(defaultSource$1);
  10323. var logNormal = (function sourceRandomLogNormal(source) {
  10324. function randomLogNormal() {
  10325. var randomNormal = normal.source(source).apply(this, arguments);
  10326. return function() {
  10327. return Math.exp(randomNormal());
  10328. };
  10329. }
  10330. randomLogNormal.source = sourceRandomLogNormal;
  10331. return randomLogNormal;
  10332. })(defaultSource$1);
  10333. var irwinHall = (function sourceRandomIrwinHall(source) {
  10334. function randomIrwinHall(n) {
  10335. return function() {
  10336. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  10337. return sum;
  10338. };
  10339. }
  10340. randomIrwinHall.source = sourceRandomIrwinHall;
  10341. return randomIrwinHall;
  10342. })(defaultSource$1);
  10343. var bates = (function sourceRandomBates(source) {
  10344. function randomBates(n) {
  10345. var randomIrwinHall = irwinHall.source(source)(n);
  10346. return function() {
  10347. return randomIrwinHall() / n;
  10348. };
  10349. }
  10350. randomBates.source = sourceRandomBates;
  10351. return randomBates;
  10352. })(defaultSource$1);
  10353. var exponential$1 = (function sourceRandomExponential(source) {
  10354. function randomExponential(lambda) {
  10355. return function() {
  10356. return -Math.log(1 - source()) / lambda;
  10357. };
  10358. }
  10359. randomExponential.source = sourceRandomExponential;
  10360. return randomExponential;
  10361. })(defaultSource$1);
  10362. function initRange(domain, range) {
  10363. switch (arguments.length) {
  10364. case 0: break;
  10365. case 1: this.range(domain); break;
  10366. default: this.range(range).domain(domain); break;
  10367. }
  10368. return this;
  10369. }
  10370. function initInterpolator(domain, interpolator) {
  10371. switch (arguments.length) {
  10372. case 0: break;
  10373. case 1: this.interpolator(domain); break;
  10374. default: this.interpolator(interpolator).domain(domain); break;
  10375. }
  10376. return this;
  10377. }
  10378. var array$3 = Array.prototype;
  10379. var map$3 = array$3.map;
  10380. var slice$5 = array$3.slice;
  10381. var implicit = {name: "implicit"};
  10382. function ordinal() {
  10383. var index = map$1(),
  10384. domain = [],
  10385. range = [],
  10386. unknown = implicit;
  10387. function scale(d) {
  10388. var key = d + "", i = index.get(key);
  10389. if (!i) {
  10390. if (unknown !== implicit) return unknown;
  10391. index.set(key, i = domain.push(d));
  10392. }
  10393. return range[(i - 1) % range.length];
  10394. }
  10395. scale.domain = function(_) {
  10396. if (!arguments.length) return domain.slice();
  10397. domain = [], index = map$1();
  10398. var i = -1, n = _.length, d, key;
  10399. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  10400. return scale;
  10401. };
  10402. scale.range = function(_) {
  10403. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  10404. };
  10405. scale.unknown = function(_) {
  10406. return arguments.length ? (unknown = _, scale) : unknown;
  10407. };
  10408. scale.copy = function() {
  10409. return ordinal(domain, range).unknown(unknown);
  10410. };
  10411. initRange.apply(scale, arguments);
  10412. return scale;
  10413. }
  10414. function band() {
  10415. var scale = ordinal().unknown(undefined),
  10416. domain = scale.domain,
  10417. ordinalRange = scale.range,
  10418. range = [0, 1],
  10419. step,
  10420. bandwidth,
  10421. round = false,
  10422. paddingInner = 0,
  10423. paddingOuter = 0,
  10424. align = 0.5;
  10425. delete scale.unknown;
  10426. function rescale() {
  10427. var n = domain().length,
  10428. reverse = range[1] < range[0],
  10429. start = range[reverse - 0],
  10430. stop = range[1 - reverse];
  10431. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  10432. if (round) step = Math.floor(step);
  10433. start += (stop - start - step * (n - paddingInner)) * align;
  10434. bandwidth = step * (1 - paddingInner);
  10435. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  10436. var values = sequence(n).map(function(i) { return start + step * i; });
  10437. return ordinalRange(reverse ? values.reverse() : values);
  10438. }
  10439. scale.domain = function(_) {
  10440. return arguments.length ? (domain(_), rescale()) : domain();
  10441. };
  10442. scale.range = function(_) {
  10443. return arguments.length ? (range = [+_[0], +_[1]], rescale()) : range.slice();
  10444. };
  10445. scale.rangeRound = function(_) {
  10446. return range = [+_[0], +_[1]], round = true, rescale();
  10447. };
  10448. scale.bandwidth = function() {
  10449. return bandwidth;
  10450. };
  10451. scale.step = function() {
  10452. return step;
  10453. };
  10454. scale.round = function(_) {
  10455. return arguments.length ? (round = !!_, rescale()) : round;
  10456. };
  10457. scale.padding = function(_) {
  10458. return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
  10459. };
  10460. scale.paddingInner = function(_) {
  10461. return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
  10462. };
  10463. scale.paddingOuter = function(_) {
  10464. return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
  10465. };
  10466. scale.align = function(_) {
  10467. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  10468. };
  10469. scale.copy = function() {
  10470. return band(domain(), range)
  10471. .round(round)
  10472. .paddingInner(paddingInner)
  10473. .paddingOuter(paddingOuter)
  10474. .align(align);
  10475. };
  10476. return initRange.apply(rescale(), arguments);
  10477. }
  10478. function pointish(scale) {
  10479. var copy = scale.copy;
  10480. scale.padding = scale.paddingOuter;
  10481. delete scale.paddingInner;
  10482. delete scale.paddingOuter;
  10483. scale.copy = function() {
  10484. return pointish(copy());
  10485. };
  10486. return scale;
  10487. }
  10488. function point$1() {
  10489. return pointish(band.apply(null, arguments).paddingInner(1));
  10490. }
  10491. function constant$a(x) {
  10492. return function() {
  10493. return x;
  10494. };
  10495. }
  10496. function number$2(x) {
  10497. return +x;
  10498. }
  10499. var unit = [0, 1];
  10500. function identity$6(x) {
  10501. return x;
  10502. }
  10503. function normalize(a, b) {
  10504. return (b -= (a = +a))
  10505. ? function(x) { return (x - a) / b; }
  10506. : constant$a(isNaN(b) ? NaN : 0.5);
  10507. }
  10508. function clamper(domain) {
  10509. var a = domain[0], b = domain[domain.length - 1], t;
  10510. if (a > b) t = a, a = b, b = t;
  10511. return function(x) { return Math.max(a, Math.min(b, x)); };
  10512. }
  10513. // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10514. // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
  10515. function bimap(domain, range, interpolate) {
  10516. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  10517. if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
  10518. else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
  10519. return function(x) { return r0(d0(x)); };
  10520. }
  10521. function polymap(domain, range, interpolate) {
  10522. var j = Math.min(domain.length, range.length) - 1,
  10523. d = new Array(j),
  10524. r = new Array(j),
  10525. i = -1;
  10526. // Reverse descending domains.
  10527. if (domain[j] < domain[0]) {
  10528. domain = domain.slice().reverse();
  10529. range = range.slice().reverse();
  10530. }
  10531. while (++i < j) {
  10532. d[i] = normalize(domain[i], domain[i + 1]);
  10533. r[i] = interpolate(range[i], range[i + 1]);
  10534. }
  10535. return function(x) {
  10536. var i = bisectRight(domain, x, 1, j) - 1;
  10537. return r[i](d[i](x));
  10538. };
  10539. }
  10540. function copy(source, target) {
  10541. return target
  10542. .domain(source.domain())
  10543. .range(source.range())
  10544. .interpolate(source.interpolate())
  10545. .clamp(source.clamp())
  10546. .unknown(source.unknown());
  10547. }
  10548. function transformer$1() {
  10549. var domain = unit,
  10550. range = unit,
  10551. interpolate = interpolateValue,
  10552. transform,
  10553. untransform,
  10554. unknown,
  10555. clamp = identity$6,
  10556. piecewise,
  10557. output,
  10558. input;
  10559. function rescale() {
  10560. piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10561. output = input = null;
  10562. return scale;
  10563. }
  10564. function scale(x) {
  10565. return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
  10566. }
  10567. scale.invert = function(y) {
  10568. return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
  10569. };
  10570. scale.domain = function(_) {
  10571. return arguments.length ? (domain = map$3.call(_, number$2), clamp === identity$6 || (clamp = clamper(domain)), rescale()) : domain.slice();
  10572. };
  10573. scale.range = function(_) {
  10574. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10575. };
  10576. scale.rangeRound = function(_) {
  10577. return range = slice$5.call(_), interpolate = interpolateRound, rescale();
  10578. };
  10579. scale.clamp = function(_) {
  10580. return arguments.length ? (clamp = _ ? clamper(domain) : identity$6, scale) : clamp !== identity$6;
  10581. };
  10582. scale.interpolate = function(_) {
  10583. return arguments.length ? (interpolate = _, rescale()) : interpolate;
  10584. };
  10585. scale.unknown = function(_) {
  10586. return arguments.length ? (unknown = _, scale) : unknown;
  10587. };
  10588. return function(t, u) {
  10589. transform = t, untransform = u;
  10590. return rescale();
  10591. };
  10592. }
  10593. function continuous(transform, untransform) {
  10594. return transformer$1()(transform, untransform);
  10595. }
  10596. function tickFormat(start, stop, count, specifier) {
  10597. var step = tickStep(start, stop, count),
  10598. precision;
  10599. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10600. switch (specifier.type) {
  10601. case "s": {
  10602. var value = Math.max(Math.abs(start), Math.abs(stop));
  10603. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10604. return exports.formatPrefix(specifier, value);
  10605. }
  10606. case "":
  10607. case "e":
  10608. case "g":
  10609. case "p":
  10610. case "r": {
  10611. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10612. break;
  10613. }
  10614. case "f":
  10615. case "%": {
  10616. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10617. break;
  10618. }
  10619. }
  10620. return exports.format(specifier);
  10621. }
  10622. function linearish(scale) {
  10623. var domain = scale.domain;
  10624. scale.ticks = function(count) {
  10625. var d = domain();
  10626. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10627. };
  10628. scale.tickFormat = function(count, specifier) {
  10629. var d = domain();
  10630. return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
  10631. };
  10632. scale.nice = function(count) {
  10633. if (count == null) count = 10;
  10634. var d = domain(),
  10635. i0 = 0,
  10636. i1 = d.length - 1,
  10637. start = d[i0],
  10638. stop = d[i1],
  10639. step;
  10640. if (stop < start) {
  10641. step = start, start = stop, stop = step;
  10642. step = i0, i0 = i1, i1 = step;
  10643. }
  10644. step = tickIncrement(start, stop, count);
  10645. if (step > 0) {
  10646. start = Math.floor(start / step) * step;
  10647. stop = Math.ceil(stop / step) * step;
  10648. step = tickIncrement(start, stop, count);
  10649. } else if (step < 0) {
  10650. start = Math.ceil(start * step) / step;
  10651. stop = Math.floor(stop * step) / step;
  10652. step = tickIncrement(start, stop, count);
  10653. }
  10654. if (step > 0) {
  10655. d[i0] = Math.floor(start / step) * step;
  10656. d[i1] = Math.ceil(stop / step) * step;
  10657. domain(d);
  10658. } else if (step < 0) {
  10659. d[i0] = Math.ceil(start * step) / step;
  10660. d[i1] = Math.floor(stop * step) / step;
  10661. domain(d);
  10662. }
  10663. return scale;
  10664. };
  10665. return scale;
  10666. }
  10667. function linear$2() {
  10668. var scale = continuous(identity$6, identity$6);
  10669. scale.copy = function() {
  10670. return copy(scale, linear$2());
  10671. };
  10672. initRange.apply(scale, arguments);
  10673. return linearish(scale);
  10674. }
  10675. function identity$7(domain) {
  10676. var unknown;
  10677. function scale(x) {
  10678. return isNaN(x = +x) ? unknown : x;
  10679. }
  10680. scale.invert = scale;
  10681. scale.domain = scale.range = function(_) {
  10682. return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
  10683. };
  10684. scale.unknown = function(_) {
  10685. return arguments.length ? (unknown = _, scale) : unknown;
  10686. };
  10687. scale.copy = function() {
  10688. return identity$7(domain).unknown(unknown);
  10689. };
  10690. domain = arguments.length ? map$3.call(domain, number$2) : [0, 1];
  10691. return linearish(scale);
  10692. }
  10693. function nice(domain, interval) {
  10694. domain = domain.slice();
  10695. var i0 = 0,
  10696. i1 = domain.length - 1,
  10697. x0 = domain[i0],
  10698. x1 = domain[i1],
  10699. t;
  10700. if (x1 < x0) {
  10701. t = i0, i0 = i1, i1 = t;
  10702. t = x0, x0 = x1, x1 = t;
  10703. }
  10704. domain[i0] = interval.floor(x0);
  10705. domain[i1] = interval.ceil(x1);
  10706. return domain;
  10707. }
  10708. function transformLog(x) {
  10709. return Math.log(x);
  10710. }
  10711. function transformExp(x) {
  10712. return Math.exp(x);
  10713. }
  10714. function transformLogn(x) {
  10715. return -Math.log(-x);
  10716. }
  10717. function transformExpn(x) {
  10718. return -Math.exp(-x);
  10719. }
  10720. function pow10(x) {
  10721. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10722. }
  10723. function powp(base) {
  10724. return base === 10 ? pow10
  10725. : base === Math.E ? Math.exp
  10726. : function(x) { return Math.pow(base, x); };
  10727. }
  10728. function logp(base) {
  10729. return base === Math.E ? Math.log
  10730. : base === 10 && Math.log10
  10731. || base === 2 && Math.log2
  10732. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10733. }
  10734. function reflect(f) {
  10735. return function(x) {
  10736. return -f(-x);
  10737. };
  10738. }
  10739. function loggish(transform) {
  10740. var scale = transform(transformLog, transformExp),
  10741. domain = scale.domain,
  10742. base = 10,
  10743. logs,
  10744. pows;
  10745. function rescale() {
  10746. logs = logp(base), pows = powp(base);
  10747. if (domain()[0] < 0) {
  10748. logs = reflect(logs), pows = reflect(pows);
  10749. transform(transformLogn, transformExpn);
  10750. } else {
  10751. transform(transformLog, transformExp);
  10752. }
  10753. return scale;
  10754. }
  10755. scale.base = function(_) {
  10756. return arguments.length ? (base = +_, rescale()) : base;
  10757. };
  10758. scale.domain = function(_) {
  10759. return arguments.length ? (domain(_), rescale()) : domain();
  10760. };
  10761. scale.ticks = function(count) {
  10762. var d = domain(),
  10763. u = d[0],
  10764. v = d[d.length - 1],
  10765. r;
  10766. if (r = v < u) i = u, u = v, v = i;
  10767. var i = logs(u),
  10768. j = logs(v),
  10769. p,
  10770. k,
  10771. t,
  10772. n = count == null ? 10 : +count,
  10773. z = [];
  10774. if (!(base % 1) && j - i < n) {
  10775. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10776. if (u > 0) for (; i < j; ++i) {
  10777. for (k = 1, p = pows(i); k < base; ++k) {
  10778. t = p * k;
  10779. if (t < u) continue;
  10780. if (t > v) break;
  10781. z.push(t);
  10782. }
  10783. } else for (; i < j; ++i) {
  10784. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10785. t = p * k;
  10786. if (t < u) continue;
  10787. if (t > v) break;
  10788. z.push(t);
  10789. }
  10790. }
  10791. } else {
  10792. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10793. }
  10794. return r ? z.reverse() : z;
  10795. };
  10796. scale.tickFormat = function(count, specifier) {
  10797. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10798. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10799. if (count === Infinity) return specifier;
  10800. if (count == null) count = 10;
  10801. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10802. return function(d) {
  10803. var i = d / pows(Math.round(logs(d)));
  10804. if (i * base < base - 0.5) i *= base;
  10805. return i <= k ? specifier(d) : "";
  10806. };
  10807. };
  10808. scale.nice = function() {
  10809. return domain(nice(domain(), {
  10810. floor: function(x) { return pows(Math.floor(logs(x))); },
  10811. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10812. }));
  10813. };
  10814. return scale;
  10815. }
  10816. function log$1() {
  10817. var scale = loggish(transformer$1()).domain([1, 10]);
  10818. scale.copy = function() {
  10819. return copy(scale, log$1()).base(scale.base());
  10820. };
  10821. initRange.apply(scale, arguments);
  10822. return scale;
  10823. }
  10824. function transformSymlog(c) {
  10825. return function(x) {
  10826. return Math.sign(x) * Math.log1p(Math.abs(x / c));
  10827. };
  10828. }
  10829. function transformSymexp(c) {
  10830. return function(x) {
  10831. return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
  10832. };
  10833. }
  10834. function symlogish(transform) {
  10835. var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
  10836. scale.constant = function(_) {
  10837. return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
  10838. };
  10839. return linearish(scale);
  10840. }
  10841. function symlog() {
  10842. var scale = symlogish(transformer$1());
  10843. scale.copy = function() {
  10844. return copy(scale, symlog()).constant(scale.constant());
  10845. };
  10846. return initRange.apply(scale, arguments);
  10847. }
  10848. function transformPow(exponent) {
  10849. return function(x) {
  10850. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10851. };
  10852. }
  10853. function transformSqrt(x) {
  10854. return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
  10855. }
  10856. function transformSquare(x) {
  10857. return x < 0 ? -x * x : x * x;
  10858. }
  10859. function powish(transform) {
  10860. var scale = transform(identity$6, identity$6),
  10861. exponent = 1;
  10862. function rescale() {
  10863. return exponent === 1 ? transform(identity$6, identity$6)
  10864. : exponent === 0.5 ? transform(transformSqrt, transformSquare)
  10865. : transform(transformPow(exponent), transformPow(1 / exponent));
  10866. }
  10867. scale.exponent = function(_) {
  10868. return arguments.length ? (exponent = +_, rescale()) : exponent;
  10869. };
  10870. return linearish(scale);
  10871. }
  10872. function pow$1() {
  10873. var scale = powish(transformer$1());
  10874. scale.copy = function() {
  10875. return copy(scale, pow$1()).exponent(scale.exponent());
  10876. };
  10877. initRange.apply(scale, arguments);
  10878. return scale;
  10879. }
  10880. function sqrt$1() {
  10881. return pow$1.apply(null, arguments).exponent(0.5);
  10882. }
  10883. function quantile() {
  10884. var domain = [],
  10885. range = [],
  10886. thresholds = [],
  10887. unknown;
  10888. function rescale() {
  10889. var i = 0, n = Math.max(1, range.length);
  10890. thresholds = new Array(n - 1);
  10891. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10892. return scale;
  10893. }
  10894. function scale(x) {
  10895. return isNaN(x = +x) ? unknown : range[bisectRight(thresholds, x)];
  10896. }
  10897. scale.invertExtent = function(y) {
  10898. var i = range.indexOf(y);
  10899. return i < 0 ? [NaN, NaN] : [
  10900. i > 0 ? thresholds[i - 1] : domain[0],
  10901. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10902. ];
  10903. };
  10904. scale.domain = function(_) {
  10905. if (!arguments.length) return domain.slice();
  10906. domain = [];
  10907. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10908. domain.sort(ascending);
  10909. return rescale();
  10910. };
  10911. scale.range = function(_) {
  10912. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10913. };
  10914. scale.unknown = function(_) {
  10915. return arguments.length ? (unknown = _, scale) : unknown;
  10916. };
  10917. scale.quantiles = function() {
  10918. return thresholds.slice();
  10919. };
  10920. scale.copy = function() {
  10921. return quantile()
  10922. .domain(domain)
  10923. .range(range)
  10924. .unknown(unknown);
  10925. };
  10926. return initRange.apply(scale, arguments);
  10927. }
  10928. function quantize$1() {
  10929. var x0 = 0,
  10930. x1 = 1,
  10931. n = 1,
  10932. domain = [0.5],
  10933. range = [0, 1],
  10934. unknown;
  10935. function scale(x) {
  10936. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  10937. }
  10938. function rescale() {
  10939. var i = -1;
  10940. domain = new Array(n);
  10941. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10942. return scale;
  10943. }
  10944. scale.domain = function(_) {
  10945. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10946. };
  10947. scale.range = function(_) {
  10948. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10949. };
  10950. scale.invertExtent = function(y) {
  10951. var i = range.indexOf(y);
  10952. return i < 0 ? [NaN, NaN]
  10953. : i < 1 ? [x0, domain[0]]
  10954. : i >= n ? [domain[n - 1], x1]
  10955. : [domain[i - 1], domain[i]];
  10956. };
  10957. scale.unknown = function(_) {
  10958. return arguments.length ? (unknown = _, scale) : scale;
  10959. };
  10960. scale.thresholds = function() {
  10961. return domain.slice();
  10962. };
  10963. scale.copy = function() {
  10964. return quantize$1()
  10965. .domain([x0, x1])
  10966. .range(range)
  10967. .unknown(unknown);
  10968. };
  10969. return initRange.apply(linearish(scale), arguments);
  10970. }
  10971. function threshold$1() {
  10972. var domain = [0.5],
  10973. range = [0, 1],
  10974. unknown,
  10975. n = 1;
  10976. function scale(x) {
  10977. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  10978. }
  10979. scale.domain = function(_) {
  10980. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10981. };
  10982. scale.range = function(_) {
  10983. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10984. };
  10985. scale.invertExtent = function(y) {
  10986. var i = range.indexOf(y);
  10987. return [domain[i - 1], domain[i]];
  10988. };
  10989. scale.unknown = function(_) {
  10990. return arguments.length ? (unknown = _, scale) : unknown;
  10991. };
  10992. scale.copy = function() {
  10993. return threshold$1()
  10994. .domain(domain)
  10995. .range(range)
  10996. .unknown(unknown);
  10997. };
  10998. return initRange.apply(scale, arguments);
  10999. }
  11000. var t0$1 = new Date,
  11001. t1$1 = new Date;
  11002. function newInterval(floori, offseti, count, field) {
  11003. function interval(date) {
  11004. return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
  11005. }
  11006. interval.floor = function(date) {
  11007. return floori(date = new Date(+date)), date;
  11008. };
  11009. interval.ceil = function(date) {
  11010. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  11011. };
  11012. interval.round = function(date) {
  11013. var d0 = interval(date),
  11014. d1 = interval.ceil(date);
  11015. return date - d0 < d1 - date ? d0 : d1;
  11016. };
  11017. interval.offset = function(date, step) {
  11018. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  11019. };
  11020. interval.range = function(start, stop, step) {
  11021. var range = [], previous;
  11022. start = interval.ceil(start);
  11023. step = step == null ? 1 : Math.floor(step);
  11024. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  11025. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  11026. while (previous < start && start < stop);
  11027. return range;
  11028. };
  11029. interval.filter = function(test) {
  11030. return newInterval(function(date) {
  11031. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  11032. }, function(date, step) {
  11033. if (date >= date) {
  11034. if (step < 0) while (++step <= 0) {
  11035. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  11036. } else while (--step >= 0) {
  11037. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  11038. }
  11039. }
  11040. });
  11041. };
  11042. if (count) {
  11043. interval.count = function(start, end) {
  11044. t0$1.setTime(+start), t1$1.setTime(+end);
  11045. floori(t0$1), floori(t1$1);
  11046. return Math.floor(count(t0$1, t1$1));
  11047. };
  11048. interval.every = function(step) {
  11049. step = Math.floor(step);
  11050. return !isFinite(step) || !(step > 0) ? null
  11051. : !(step > 1) ? interval
  11052. : interval.filter(field
  11053. ? function(d) { return field(d) % step === 0; }
  11054. : function(d) { return interval.count(0, d) % step === 0; });
  11055. };
  11056. }
  11057. return interval;
  11058. }
  11059. var millisecond = newInterval(function() {
  11060. // noop
  11061. }, function(date, step) {
  11062. date.setTime(+date + step);
  11063. }, function(start, end) {
  11064. return end - start;
  11065. });
  11066. // An optimized implementation for this simple case.
  11067. millisecond.every = function(k) {
  11068. k = Math.floor(k);
  11069. if (!isFinite(k) || !(k > 0)) return null;
  11070. if (!(k > 1)) return millisecond;
  11071. return newInterval(function(date) {
  11072. date.setTime(Math.floor(date / k) * k);
  11073. }, function(date, step) {
  11074. date.setTime(+date + step * k);
  11075. }, function(start, end) {
  11076. return (end - start) / k;
  11077. });
  11078. };
  11079. var milliseconds = millisecond.range;
  11080. var durationSecond = 1e3;
  11081. var durationMinute = 6e4;
  11082. var durationHour = 36e5;
  11083. var durationDay = 864e5;
  11084. var durationWeek = 6048e5;
  11085. var second = newInterval(function(date) {
  11086. date.setTime(date - date.getMilliseconds());
  11087. }, function(date, step) {
  11088. date.setTime(+date + step * durationSecond);
  11089. }, function(start, end) {
  11090. return (end - start) / durationSecond;
  11091. }, function(date) {
  11092. return date.getUTCSeconds();
  11093. });
  11094. var seconds = second.range;
  11095. var minute = newInterval(function(date) {
  11096. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
  11097. }, function(date, step) {
  11098. date.setTime(+date + step * durationMinute);
  11099. }, function(start, end) {
  11100. return (end - start) / durationMinute;
  11101. }, function(date) {
  11102. return date.getMinutes();
  11103. });
  11104. var minutes = minute.range;
  11105. var hour = newInterval(function(date) {
  11106. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
  11107. }, function(date, step) {
  11108. date.setTime(+date + step * durationHour);
  11109. }, function(start, end) {
  11110. return (end - start) / durationHour;
  11111. }, function(date) {
  11112. return date.getHours();
  11113. });
  11114. var hours = hour.range;
  11115. var day = newInterval(function(date) {
  11116. date.setHours(0, 0, 0, 0);
  11117. }, function(date, step) {
  11118. date.setDate(date.getDate() + step);
  11119. }, function(start, end) {
  11120. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  11121. }, function(date) {
  11122. return date.getDate() - 1;
  11123. });
  11124. var days = day.range;
  11125. function weekday(i) {
  11126. return newInterval(function(date) {
  11127. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  11128. date.setHours(0, 0, 0, 0);
  11129. }, function(date, step) {
  11130. date.setDate(date.getDate() + step * 7);
  11131. }, function(start, end) {
  11132. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  11133. });
  11134. }
  11135. var sunday = weekday(0);
  11136. var monday = weekday(1);
  11137. var tuesday = weekday(2);
  11138. var wednesday = weekday(3);
  11139. var thursday = weekday(4);
  11140. var friday = weekday(5);
  11141. var saturday = weekday(6);
  11142. var sundays = sunday.range;
  11143. var mondays = monday.range;
  11144. var tuesdays = tuesday.range;
  11145. var wednesdays = wednesday.range;
  11146. var thursdays = thursday.range;
  11147. var fridays = friday.range;
  11148. var saturdays = saturday.range;
  11149. var month = newInterval(function(date) {
  11150. date.setDate(1);
  11151. date.setHours(0, 0, 0, 0);
  11152. }, function(date, step) {
  11153. date.setMonth(date.getMonth() + step);
  11154. }, function(start, end) {
  11155. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  11156. }, function(date) {
  11157. return date.getMonth();
  11158. });
  11159. var months = month.range;
  11160. var year = newInterval(function(date) {
  11161. date.setMonth(0, 1);
  11162. date.setHours(0, 0, 0, 0);
  11163. }, function(date, step) {
  11164. date.setFullYear(date.getFullYear() + step);
  11165. }, function(start, end) {
  11166. return end.getFullYear() - start.getFullYear();
  11167. }, function(date) {
  11168. return date.getFullYear();
  11169. });
  11170. // An optimized implementation for this simple case.
  11171. year.every = function(k) {
  11172. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  11173. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  11174. date.setMonth(0, 1);
  11175. date.setHours(0, 0, 0, 0);
  11176. }, function(date, step) {
  11177. date.setFullYear(date.getFullYear() + step * k);
  11178. });
  11179. };
  11180. var years = year.range;
  11181. var utcMinute = newInterval(function(date) {
  11182. date.setUTCSeconds(0, 0);
  11183. }, function(date, step) {
  11184. date.setTime(+date + step * durationMinute);
  11185. }, function(start, end) {
  11186. return (end - start) / durationMinute;
  11187. }, function(date) {
  11188. return date.getUTCMinutes();
  11189. });
  11190. var utcMinutes = utcMinute.range;
  11191. var utcHour = newInterval(function(date) {
  11192. date.setUTCMinutes(0, 0, 0);
  11193. }, function(date, step) {
  11194. date.setTime(+date + step * durationHour);
  11195. }, function(start, end) {
  11196. return (end - start) / durationHour;
  11197. }, function(date) {
  11198. return date.getUTCHours();
  11199. });
  11200. var utcHours = utcHour.range;
  11201. var utcDay = newInterval(function(date) {
  11202. date.setUTCHours(0, 0, 0, 0);
  11203. }, function(date, step) {
  11204. date.setUTCDate(date.getUTCDate() + step);
  11205. }, function(start, end) {
  11206. return (end - start) / durationDay;
  11207. }, function(date) {
  11208. return date.getUTCDate() - 1;
  11209. });
  11210. var utcDays = utcDay.range;
  11211. function utcWeekday(i) {
  11212. return newInterval(function(date) {
  11213. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  11214. date.setUTCHours(0, 0, 0, 0);
  11215. }, function(date, step) {
  11216. date.setUTCDate(date.getUTCDate() + step * 7);
  11217. }, function(start, end) {
  11218. return (end - start) / durationWeek;
  11219. });
  11220. }
  11221. var utcSunday = utcWeekday(0);
  11222. var utcMonday = utcWeekday(1);
  11223. var utcTuesday = utcWeekday(2);
  11224. var utcWednesday = utcWeekday(3);
  11225. var utcThursday = utcWeekday(4);
  11226. var utcFriday = utcWeekday(5);
  11227. var utcSaturday = utcWeekday(6);
  11228. var utcSundays = utcSunday.range;
  11229. var utcMondays = utcMonday.range;
  11230. var utcTuesdays = utcTuesday.range;
  11231. var utcWednesdays = utcWednesday.range;
  11232. var utcThursdays = utcThursday.range;
  11233. var utcFridays = utcFriday.range;
  11234. var utcSaturdays = utcSaturday.range;
  11235. var utcMonth = newInterval(function(date) {
  11236. date.setUTCDate(1);
  11237. date.setUTCHours(0, 0, 0, 0);
  11238. }, function(date, step) {
  11239. date.setUTCMonth(date.getUTCMonth() + step);
  11240. }, function(start, end) {
  11241. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  11242. }, function(date) {
  11243. return date.getUTCMonth();
  11244. });
  11245. var utcMonths = utcMonth.range;
  11246. var utcYear = newInterval(function(date) {
  11247. date.setUTCMonth(0, 1);
  11248. date.setUTCHours(0, 0, 0, 0);
  11249. }, function(date, step) {
  11250. date.setUTCFullYear(date.getUTCFullYear() + step);
  11251. }, function(start, end) {
  11252. return end.getUTCFullYear() - start.getUTCFullYear();
  11253. }, function(date) {
  11254. return date.getUTCFullYear();
  11255. });
  11256. // An optimized implementation for this simple case.
  11257. utcYear.every = function(k) {
  11258. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  11259. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  11260. date.setUTCMonth(0, 1);
  11261. date.setUTCHours(0, 0, 0, 0);
  11262. }, function(date, step) {
  11263. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  11264. });
  11265. };
  11266. var utcYears = utcYear.range;
  11267. function localDate(d) {
  11268. if (0 <= d.y && d.y < 100) {
  11269. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  11270. date.setFullYear(d.y);
  11271. return date;
  11272. }
  11273. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  11274. }
  11275. function utcDate(d) {
  11276. if (0 <= d.y && d.y < 100) {
  11277. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  11278. date.setUTCFullYear(d.y);
  11279. return date;
  11280. }
  11281. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  11282. }
  11283. function newDate(y, m, d) {
  11284. return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
  11285. }
  11286. function formatLocale$1(locale) {
  11287. var locale_dateTime = locale.dateTime,
  11288. locale_date = locale.date,
  11289. locale_time = locale.time,
  11290. locale_periods = locale.periods,
  11291. locale_weekdays = locale.days,
  11292. locale_shortWeekdays = locale.shortDays,
  11293. locale_months = locale.months,
  11294. locale_shortMonths = locale.shortMonths;
  11295. var periodRe = formatRe(locale_periods),
  11296. periodLookup = formatLookup(locale_periods),
  11297. weekdayRe = formatRe(locale_weekdays),
  11298. weekdayLookup = formatLookup(locale_weekdays),
  11299. shortWeekdayRe = formatRe(locale_shortWeekdays),
  11300. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  11301. monthRe = formatRe(locale_months),
  11302. monthLookup = formatLookup(locale_months),
  11303. shortMonthRe = formatRe(locale_shortMonths),
  11304. shortMonthLookup = formatLookup(locale_shortMonths);
  11305. var formats = {
  11306. "a": formatShortWeekday,
  11307. "A": formatWeekday,
  11308. "b": formatShortMonth,
  11309. "B": formatMonth,
  11310. "c": null,
  11311. "d": formatDayOfMonth,
  11312. "e": formatDayOfMonth,
  11313. "f": formatMicroseconds,
  11314. "H": formatHour24,
  11315. "I": formatHour12,
  11316. "j": formatDayOfYear,
  11317. "L": formatMilliseconds,
  11318. "m": formatMonthNumber,
  11319. "M": formatMinutes,
  11320. "p": formatPeriod,
  11321. "q": formatQuarter,
  11322. "Q": formatUnixTimestamp,
  11323. "s": formatUnixTimestampSeconds,
  11324. "S": formatSeconds,
  11325. "u": formatWeekdayNumberMonday,
  11326. "U": formatWeekNumberSunday,
  11327. "V": formatWeekNumberISO,
  11328. "w": formatWeekdayNumberSunday,
  11329. "W": formatWeekNumberMonday,
  11330. "x": null,
  11331. "X": null,
  11332. "y": formatYear$1,
  11333. "Y": formatFullYear,
  11334. "Z": formatZone,
  11335. "%": formatLiteralPercent
  11336. };
  11337. var utcFormats = {
  11338. "a": formatUTCShortWeekday,
  11339. "A": formatUTCWeekday,
  11340. "b": formatUTCShortMonth,
  11341. "B": formatUTCMonth,
  11342. "c": null,
  11343. "d": formatUTCDayOfMonth,
  11344. "e": formatUTCDayOfMonth,
  11345. "f": formatUTCMicroseconds,
  11346. "H": formatUTCHour24,
  11347. "I": formatUTCHour12,
  11348. "j": formatUTCDayOfYear,
  11349. "L": formatUTCMilliseconds,
  11350. "m": formatUTCMonthNumber,
  11351. "M": formatUTCMinutes,
  11352. "p": formatUTCPeriod,
  11353. "q": formatUTCQuarter,
  11354. "Q": formatUnixTimestamp,
  11355. "s": formatUnixTimestampSeconds,
  11356. "S": formatUTCSeconds,
  11357. "u": formatUTCWeekdayNumberMonday,
  11358. "U": formatUTCWeekNumberSunday,
  11359. "V": formatUTCWeekNumberISO,
  11360. "w": formatUTCWeekdayNumberSunday,
  11361. "W": formatUTCWeekNumberMonday,
  11362. "x": null,
  11363. "X": null,
  11364. "y": formatUTCYear,
  11365. "Y": formatUTCFullYear,
  11366. "Z": formatUTCZone,
  11367. "%": formatLiteralPercent
  11368. };
  11369. var parses = {
  11370. "a": parseShortWeekday,
  11371. "A": parseWeekday,
  11372. "b": parseShortMonth,
  11373. "B": parseMonth,
  11374. "c": parseLocaleDateTime,
  11375. "d": parseDayOfMonth,
  11376. "e": parseDayOfMonth,
  11377. "f": parseMicroseconds,
  11378. "H": parseHour24,
  11379. "I": parseHour24,
  11380. "j": parseDayOfYear,
  11381. "L": parseMilliseconds,
  11382. "m": parseMonthNumber,
  11383. "M": parseMinutes,
  11384. "p": parsePeriod,
  11385. "q": parseQuarter,
  11386. "Q": parseUnixTimestamp,
  11387. "s": parseUnixTimestampSeconds,
  11388. "S": parseSeconds,
  11389. "u": parseWeekdayNumberMonday,
  11390. "U": parseWeekNumberSunday,
  11391. "V": parseWeekNumberISO,
  11392. "w": parseWeekdayNumberSunday,
  11393. "W": parseWeekNumberMonday,
  11394. "x": parseLocaleDate,
  11395. "X": parseLocaleTime,
  11396. "y": parseYear,
  11397. "Y": parseFullYear,
  11398. "Z": parseZone,
  11399. "%": parseLiteralPercent
  11400. };
  11401. // These recursive directive definitions must be deferred.
  11402. formats.x = newFormat(locale_date, formats);
  11403. formats.X = newFormat(locale_time, formats);
  11404. formats.c = newFormat(locale_dateTime, formats);
  11405. utcFormats.x = newFormat(locale_date, utcFormats);
  11406. utcFormats.X = newFormat(locale_time, utcFormats);
  11407. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  11408. function newFormat(specifier, formats) {
  11409. return function(date) {
  11410. var string = [],
  11411. i = -1,
  11412. j = 0,
  11413. n = specifier.length,
  11414. c,
  11415. pad,
  11416. format;
  11417. if (!(date instanceof Date)) date = new Date(+date);
  11418. while (++i < n) {
  11419. if (specifier.charCodeAt(i) === 37) {
  11420. string.push(specifier.slice(j, i));
  11421. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  11422. else pad = c === "e" ? " " : "0";
  11423. if (format = formats[c]) c = format(date, pad);
  11424. string.push(c);
  11425. j = i + 1;
  11426. }
  11427. }
  11428. string.push(specifier.slice(j, i));
  11429. return string.join("");
  11430. };
  11431. }
  11432. function newParse(specifier, Z) {
  11433. return function(string) {
  11434. var d = newDate(1900, undefined, 1),
  11435. i = parseSpecifier(d, specifier, string += "", 0),
  11436. week, day$1;
  11437. if (i != string.length) return null;
  11438. // If a UNIX timestamp is specified, return it.
  11439. if ("Q" in d) return new Date(d.Q);
  11440. if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
  11441. // If this is utcParse, never use the local timezone.
  11442. if (Z && !("Z" in d)) d.Z = 0;
  11443. // The am-pm flag is 0 for AM, and 1 for PM.
  11444. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  11445. // If the month was not specified, inherit from the quarter.
  11446. if (d.m === undefined) d.m = "q" in d ? d.q : 0;
  11447. // Convert day-of-week and week-of-year to day-of-year.
  11448. if ("V" in d) {
  11449. if (d.V < 1 || d.V > 53) return null;
  11450. if (!("w" in d)) d.w = 1;
  11451. if ("Z" in d) {
  11452. week = utcDate(newDate(d.y, 0, 1)), day$1 = week.getUTCDay();
  11453. week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  11454. week = utcDay.offset(week, (d.V - 1) * 7);
  11455. d.y = week.getUTCFullYear();
  11456. d.m = week.getUTCMonth();
  11457. d.d = week.getUTCDate() + (d.w + 6) % 7;
  11458. } else {
  11459. week = localDate(newDate(d.y, 0, 1)), day$1 = week.getDay();
  11460. week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
  11461. week = day.offset(week, (d.V - 1) * 7);
  11462. d.y = week.getFullYear();
  11463. d.m = week.getMonth();
  11464. d.d = week.getDate() + (d.w + 6) % 7;
  11465. }
  11466. } else if ("W" in d || "U" in d) {
  11467. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  11468. day$1 = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
  11469. d.m = 0;
  11470. d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$1 + 5) % 7 : d.w + d.U * 7 - (day$1 + 6) % 7;
  11471. }
  11472. // If a time zone is specified, all fields are interpreted as UTC and then
  11473. // offset according to the specified time zone.
  11474. if ("Z" in d) {
  11475. d.H += d.Z / 100 | 0;
  11476. d.M += d.Z % 100;
  11477. return utcDate(d);
  11478. }
  11479. // Otherwise, all fields are in local time.
  11480. return localDate(d);
  11481. };
  11482. }
  11483. function parseSpecifier(d, specifier, string, j) {
  11484. var i = 0,
  11485. n = specifier.length,
  11486. m = string.length,
  11487. c,
  11488. parse;
  11489. while (i < n) {
  11490. if (j >= m) return -1;
  11491. c = specifier.charCodeAt(i++);
  11492. if (c === 37) {
  11493. c = specifier.charAt(i++);
  11494. parse = parses[c in pads ? specifier.charAt(i++) : c];
  11495. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  11496. } else if (c != string.charCodeAt(j++)) {
  11497. return -1;
  11498. }
  11499. }
  11500. return j;
  11501. }
  11502. function parsePeriod(d, string, i) {
  11503. var n = periodRe.exec(string.slice(i));
  11504. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11505. }
  11506. function parseShortWeekday(d, string, i) {
  11507. var n = shortWeekdayRe.exec(string.slice(i));
  11508. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11509. }
  11510. function parseWeekday(d, string, i) {
  11511. var n = weekdayRe.exec(string.slice(i));
  11512. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11513. }
  11514. function parseShortMonth(d, string, i) {
  11515. var n = shortMonthRe.exec(string.slice(i));
  11516. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11517. }
  11518. function parseMonth(d, string, i) {
  11519. var n = monthRe.exec(string.slice(i));
  11520. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11521. }
  11522. function parseLocaleDateTime(d, string, i) {
  11523. return parseSpecifier(d, locale_dateTime, string, i);
  11524. }
  11525. function parseLocaleDate(d, string, i) {
  11526. return parseSpecifier(d, locale_date, string, i);
  11527. }
  11528. function parseLocaleTime(d, string, i) {
  11529. return parseSpecifier(d, locale_time, string, i);
  11530. }
  11531. function formatShortWeekday(d) {
  11532. return locale_shortWeekdays[d.getDay()];
  11533. }
  11534. function formatWeekday(d) {
  11535. return locale_weekdays[d.getDay()];
  11536. }
  11537. function formatShortMonth(d) {
  11538. return locale_shortMonths[d.getMonth()];
  11539. }
  11540. function formatMonth(d) {
  11541. return locale_months[d.getMonth()];
  11542. }
  11543. function formatPeriod(d) {
  11544. return locale_periods[+(d.getHours() >= 12)];
  11545. }
  11546. function formatQuarter(d) {
  11547. return 1 + ~~(d.getMonth() / 3);
  11548. }
  11549. function formatUTCShortWeekday(d) {
  11550. return locale_shortWeekdays[d.getUTCDay()];
  11551. }
  11552. function formatUTCWeekday(d) {
  11553. return locale_weekdays[d.getUTCDay()];
  11554. }
  11555. function formatUTCShortMonth(d) {
  11556. return locale_shortMonths[d.getUTCMonth()];
  11557. }
  11558. function formatUTCMonth(d) {
  11559. return locale_months[d.getUTCMonth()];
  11560. }
  11561. function formatUTCPeriod(d) {
  11562. return locale_periods[+(d.getUTCHours() >= 12)];
  11563. }
  11564. function formatUTCQuarter(d) {
  11565. return 1 + ~~(d.getUTCMonth() / 3);
  11566. }
  11567. return {
  11568. format: function(specifier) {
  11569. var f = newFormat(specifier += "", formats);
  11570. f.toString = function() { return specifier; };
  11571. return f;
  11572. },
  11573. parse: function(specifier) {
  11574. var p = newParse(specifier += "", false);
  11575. p.toString = function() { return specifier; };
  11576. return p;
  11577. },
  11578. utcFormat: function(specifier) {
  11579. var f = newFormat(specifier += "", utcFormats);
  11580. f.toString = function() { return specifier; };
  11581. return f;
  11582. },
  11583. utcParse: function(specifier) {
  11584. var p = newParse(specifier += "", true);
  11585. p.toString = function() { return specifier; };
  11586. return p;
  11587. }
  11588. };
  11589. }
  11590. var pads = {"-": "", "_": " ", "0": "0"},
  11591. numberRe = /^\s*\d+/, // note: ignores next directive
  11592. percentRe = /^%/,
  11593. requoteRe = /[\\^$*+?|[\]().{}]/g;
  11594. function pad$1(value, fill, width) {
  11595. var sign = value < 0 ? "-" : "",
  11596. string = (sign ? -value : value) + "",
  11597. length = string.length;
  11598. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  11599. }
  11600. function requote(s) {
  11601. return s.replace(requoteRe, "\\$&");
  11602. }
  11603. function formatRe(names) {
  11604. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  11605. }
  11606. function formatLookup(names) {
  11607. var map = {}, i = -1, n = names.length;
  11608. while (++i < n) map[names[i].toLowerCase()] = i;
  11609. return map;
  11610. }
  11611. function parseWeekdayNumberSunday(d, string, i) {
  11612. var n = numberRe.exec(string.slice(i, i + 1));
  11613. return n ? (d.w = +n[0], i + n[0].length) : -1;
  11614. }
  11615. function parseWeekdayNumberMonday(d, string, i) {
  11616. var n = numberRe.exec(string.slice(i, i + 1));
  11617. return n ? (d.u = +n[0], i + n[0].length) : -1;
  11618. }
  11619. function parseWeekNumberSunday(d, string, i) {
  11620. var n = numberRe.exec(string.slice(i, i + 2));
  11621. return n ? (d.U = +n[0], i + n[0].length) : -1;
  11622. }
  11623. function parseWeekNumberISO(d, string, i) {
  11624. var n = numberRe.exec(string.slice(i, i + 2));
  11625. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11626. }
  11627. function parseWeekNumberMonday(d, string, i) {
  11628. var n = numberRe.exec(string.slice(i, i + 2));
  11629. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11630. }
  11631. function parseFullYear(d, string, i) {
  11632. var n = numberRe.exec(string.slice(i, i + 4));
  11633. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11634. }
  11635. function parseYear(d, string, i) {
  11636. var n = numberRe.exec(string.slice(i, i + 2));
  11637. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11638. }
  11639. function parseZone(d, string, i) {
  11640. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11641. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11642. }
  11643. function parseQuarter(d, string, i) {
  11644. var n = numberRe.exec(string.slice(i, i + 1));
  11645. return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
  11646. }
  11647. function parseMonthNumber(d, string, i) {
  11648. var n = numberRe.exec(string.slice(i, i + 2));
  11649. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11650. }
  11651. function parseDayOfMonth(d, string, i) {
  11652. var n = numberRe.exec(string.slice(i, i + 2));
  11653. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11654. }
  11655. function parseDayOfYear(d, string, i) {
  11656. var n = numberRe.exec(string.slice(i, i + 3));
  11657. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11658. }
  11659. function parseHour24(d, string, i) {
  11660. var n = numberRe.exec(string.slice(i, i + 2));
  11661. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11662. }
  11663. function parseMinutes(d, string, i) {
  11664. var n = numberRe.exec(string.slice(i, i + 2));
  11665. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11666. }
  11667. function parseSeconds(d, string, i) {
  11668. var n = numberRe.exec(string.slice(i, i + 2));
  11669. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11670. }
  11671. function parseMilliseconds(d, string, i) {
  11672. var n = numberRe.exec(string.slice(i, i + 3));
  11673. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11674. }
  11675. function parseMicroseconds(d, string, i) {
  11676. var n = numberRe.exec(string.slice(i, i + 6));
  11677. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11678. }
  11679. function parseLiteralPercent(d, string, i) {
  11680. var n = percentRe.exec(string.slice(i, i + 1));
  11681. return n ? i + n[0].length : -1;
  11682. }
  11683. function parseUnixTimestamp(d, string, i) {
  11684. var n = numberRe.exec(string.slice(i));
  11685. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11686. }
  11687. function parseUnixTimestampSeconds(d, string, i) {
  11688. var n = numberRe.exec(string.slice(i));
  11689. return n ? (d.s = +n[0], i + n[0].length) : -1;
  11690. }
  11691. function formatDayOfMonth(d, p) {
  11692. return pad$1(d.getDate(), p, 2);
  11693. }
  11694. function formatHour24(d, p) {
  11695. return pad$1(d.getHours(), p, 2);
  11696. }
  11697. function formatHour12(d, p) {
  11698. return pad$1(d.getHours() % 12 || 12, p, 2);
  11699. }
  11700. function formatDayOfYear(d, p) {
  11701. return pad$1(1 + day.count(year(d), d), p, 3);
  11702. }
  11703. function formatMilliseconds(d, p) {
  11704. return pad$1(d.getMilliseconds(), p, 3);
  11705. }
  11706. function formatMicroseconds(d, p) {
  11707. return formatMilliseconds(d, p) + "000";
  11708. }
  11709. function formatMonthNumber(d, p) {
  11710. return pad$1(d.getMonth() + 1, p, 2);
  11711. }
  11712. function formatMinutes(d, p) {
  11713. return pad$1(d.getMinutes(), p, 2);
  11714. }
  11715. function formatSeconds(d, p) {
  11716. return pad$1(d.getSeconds(), p, 2);
  11717. }
  11718. function formatWeekdayNumberMonday(d) {
  11719. var day = d.getDay();
  11720. return day === 0 ? 7 : day;
  11721. }
  11722. function formatWeekNumberSunday(d, p) {
  11723. return pad$1(sunday.count(year(d) - 1, d), p, 2);
  11724. }
  11725. function formatWeekNumberISO(d, p) {
  11726. var day = d.getDay();
  11727. d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
  11728. return pad$1(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11729. }
  11730. function formatWeekdayNumberSunday(d) {
  11731. return d.getDay();
  11732. }
  11733. function formatWeekNumberMonday(d, p) {
  11734. return pad$1(monday.count(year(d) - 1, d), p, 2);
  11735. }
  11736. function formatYear$1(d, p) {
  11737. return pad$1(d.getFullYear() % 100, p, 2);
  11738. }
  11739. function formatFullYear(d, p) {
  11740. return pad$1(d.getFullYear() % 10000, p, 4);
  11741. }
  11742. function formatZone(d) {
  11743. var z = d.getTimezoneOffset();
  11744. return (z > 0 ? "-" : (z *= -1, "+"))
  11745. + pad$1(z / 60 | 0, "0", 2)
  11746. + pad$1(z % 60, "0", 2);
  11747. }
  11748. function formatUTCDayOfMonth(d, p) {
  11749. return pad$1(d.getUTCDate(), p, 2);
  11750. }
  11751. function formatUTCHour24(d, p) {
  11752. return pad$1(d.getUTCHours(), p, 2);
  11753. }
  11754. function formatUTCHour12(d, p) {
  11755. return pad$1(d.getUTCHours() % 12 || 12, p, 2);
  11756. }
  11757. function formatUTCDayOfYear(d, p) {
  11758. return pad$1(1 + utcDay.count(utcYear(d), d), p, 3);
  11759. }
  11760. function formatUTCMilliseconds(d, p) {
  11761. return pad$1(d.getUTCMilliseconds(), p, 3);
  11762. }
  11763. function formatUTCMicroseconds(d, p) {
  11764. return formatUTCMilliseconds(d, p) + "000";
  11765. }
  11766. function formatUTCMonthNumber(d, p) {
  11767. return pad$1(d.getUTCMonth() + 1, p, 2);
  11768. }
  11769. function formatUTCMinutes(d, p) {
  11770. return pad$1(d.getUTCMinutes(), p, 2);
  11771. }
  11772. function formatUTCSeconds(d, p) {
  11773. return pad$1(d.getUTCSeconds(), p, 2);
  11774. }
  11775. function formatUTCWeekdayNumberMonday(d) {
  11776. var dow = d.getUTCDay();
  11777. return dow === 0 ? 7 : dow;
  11778. }
  11779. function formatUTCWeekNumberSunday(d, p) {
  11780. return pad$1(utcSunday.count(utcYear(d) - 1, d), p, 2);
  11781. }
  11782. function formatUTCWeekNumberISO(d, p) {
  11783. var day = d.getUTCDay();
  11784. d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11785. return pad$1(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11786. }
  11787. function formatUTCWeekdayNumberSunday(d) {
  11788. return d.getUTCDay();
  11789. }
  11790. function formatUTCWeekNumberMonday(d, p) {
  11791. return pad$1(utcMonday.count(utcYear(d) - 1, d), p, 2);
  11792. }
  11793. function formatUTCYear(d, p) {
  11794. return pad$1(d.getUTCFullYear() % 100, p, 2);
  11795. }
  11796. function formatUTCFullYear(d, p) {
  11797. return pad$1(d.getUTCFullYear() % 10000, p, 4);
  11798. }
  11799. function formatUTCZone() {
  11800. return "+0000";
  11801. }
  11802. function formatLiteralPercent() {
  11803. return "%";
  11804. }
  11805. function formatUnixTimestamp(d) {
  11806. return +d;
  11807. }
  11808. function formatUnixTimestampSeconds(d) {
  11809. return Math.floor(+d / 1000);
  11810. }
  11811. var locale$1;
  11812. defaultLocale$1({
  11813. dateTime: "%x, %X",
  11814. date: "%-m/%-d/%Y",
  11815. time: "%-I:%M:%S %p",
  11816. periods: ["AM", "PM"],
  11817. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11818. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11819. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11820. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11821. });
  11822. function defaultLocale$1(definition) {
  11823. locale$1 = formatLocale$1(definition);
  11824. exports.timeFormat = locale$1.format;
  11825. exports.timeParse = locale$1.parse;
  11826. exports.utcFormat = locale$1.utcFormat;
  11827. exports.utcParse = locale$1.utcParse;
  11828. return locale$1;
  11829. }
  11830. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11831. function formatIsoNative(date) {
  11832. return date.toISOString();
  11833. }
  11834. var formatIso = Date.prototype.toISOString
  11835. ? formatIsoNative
  11836. : exports.utcFormat(isoSpecifier);
  11837. function parseIsoNative(string) {
  11838. var date = new Date(string);
  11839. return isNaN(date) ? null : date;
  11840. }
  11841. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11842. ? parseIsoNative
  11843. : exports.utcParse(isoSpecifier);
  11844. var durationSecond$1 = 1000,
  11845. durationMinute$1 = durationSecond$1 * 60,
  11846. durationHour$1 = durationMinute$1 * 60,
  11847. durationDay$1 = durationHour$1 * 24,
  11848. durationWeek$1 = durationDay$1 * 7,
  11849. durationMonth = durationDay$1 * 30,
  11850. durationYear = durationDay$1 * 365;
  11851. function date$1(t) {
  11852. return new Date(t);
  11853. }
  11854. function number$3(t) {
  11855. return t instanceof Date ? +t : +new Date(+t);
  11856. }
  11857. function calendar(year, month, week, day, hour, minute, second, millisecond, format) {
  11858. var scale = continuous(identity$6, identity$6),
  11859. invert = scale.invert,
  11860. domain = scale.domain;
  11861. var formatMillisecond = format(".%L"),
  11862. formatSecond = format(":%S"),
  11863. formatMinute = format("%I:%M"),
  11864. formatHour = format("%I %p"),
  11865. formatDay = format("%a %d"),
  11866. formatWeek = format("%b %d"),
  11867. formatMonth = format("%B"),
  11868. formatYear = format("%Y");
  11869. var tickIntervals = [
  11870. [second, 1, durationSecond$1],
  11871. [second, 5, 5 * durationSecond$1],
  11872. [second, 15, 15 * durationSecond$1],
  11873. [second, 30, 30 * durationSecond$1],
  11874. [minute, 1, durationMinute$1],
  11875. [minute, 5, 5 * durationMinute$1],
  11876. [minute, 15, 15 * durationMinute$1],
  11877. [minute, 30, 30 * durationMinute$1],
  11878. [ hour, 1, durationHour$1 ],
  11879. [ hour, 3, 3 * durationHour$1 ],
  11880. [ hour, 6, 6 * durationHour$1 ],
  11881. [ hour, 12, 12 * durationHour$1 ],
  11882. [ day, 1, durationDay$1 ],
  11883. [ day, 2, 2 * durationDay$1 ],
  11884. [ week, 1, durationWeek$1 ],
  11885. [ month, 1, durationMonth ],
  11886. [ month, 3, 3 * durationMonth ],
  11887. [ year, 1, durationYear ]
  11888. ];
  11889. function tickFormat(date) {
  11890. return (second(date) < date ? formatMillisecond
  11891. : minute(date) < date ? formatSecond
  11892. : hour(date) < date ? formatMinute
  11893. : day(date) < date ? formatHour
  11894. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  11895. : year(date) < date ? formatMonth
  11896. : formatYear)(date);
  11897. }
  11898. function tickInterval(interval, start, stop, step) {
  11899. if (interval == null) interval = 10;
  11900. // If a desired tick count is specified, pick a reasonable tick interval
  11901. // based on the extent of the domain and a rough estimate of tick size.
  11902. // Otherwise, assume interval is already a time interval and use it.
  11903. if (typeof interval === "number") {
  11904. var target = Math.abs(stop - start) / interval,
  11905. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11906. if (i === tickIntervals.length) {
  11907. step = tickStep(start / durationYear, stop / durationYear, interval);
  11908. interval = year;
  11909. } else if (i) {
  11910. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11911. step = i[1];
  11912. interval = i[0];
  11913. } else {
  11914. step = Math.max(tickStep(start, stop, interval), 1);
  11915. interval = millisecond;
  11916. }
  11917. }
  11918. return step == null ? interval : interval.every(step);
  11919. }
  11920. scale.invert = function(y) {
  11921. return new Date(invert(y));
  11922. };
  11923. scale.domain = function(_) {
  11924. return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
  11925. };
  11926. scale.ticks = function(interval, step) {
  11927. var d = domain(),
  11928. t0 = d[0],
  11929. t1 = d[d.length - 1],
  11930. r = t1 < t0,
  11931. t;
  11932. if (r) t = t0, t0 = t1, t1 = t;
  11933. t = tickInterval(interval, t0, t1, step);
  11934. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11935. return r ? t.reverse() : t;
  11936. };
  11937. scale.tickFormat = function(count, specifier) {
  11938. return specifier == null ? tickFormat : format(specifier);
  11939. };
  11940. scale.nice = function(interval, step) {
  11941. var d = domain();
  11942. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11943. ? domain(nice(d, interval))
  11944. : scale;
  11945. };
  11946. scale.copy = function() {
  11947. return copy(scale, calendar(year, month, week, day, hour, minute, second, millisecond, format));
  11948. };
  11949. return scale;
  11950. }
  11951. function time() {
  11952. return initRange.apply(calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
  11953. }
  11954. function utcTime() {
  11955. return initRange.apply(calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
  11956. }
  11957. function transformer$2() {
  11958. var x0 = 0,
  11959. x1 = 1,
  11960. t0,
  11961. t1,
  11962. k10,
  11963. transform,
  11964. interpolator = identity$6,
  11965. clamp = false,
  11966. unknown;
  11967. function scale(x) {
  11968. return isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
  11969. }
  11970. scale.domain = function(_) {
  11971. return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
  11972. };
  11973. scale.clamp = function(_) {
  11974. return arguments.length ? (clamp = !!_, scale) : clamp;
  11975. };
  11976. scale.interpolator = function(_) {
  11977. return arguments.length ? (interpolator = _, scale) : interpolator;
  11978. };
  11979. scale.unknown = function(_) {
  11980. return arguments.length ? (unknown = _, scale) : unknown;
  11981. };
  11982. return function(t) {
  11983. transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
  11984. return scale;
  11985. };
  11986. }
  11987. function copy$1(source, target) {
  11988. return target
  11989. .domain(source.domain())
  11990. .interpolator(source.interpolator())
  11991. .clamp(source.clamp())
  11992. .unknown(source.unknown());
  11993. }
  11994. function sequential() {
  11995. var scale = linearish(transformer$2()(identity$6));
  11996. scale.copy = function() {
  11997. return copy$1(scale, sequential());
  11998. };
  11999. return initInterpolator.apply(scale, arguments);
  12000. }
  12001. function sequentialLog() {
  12002. var scale = loggish(transformer$2()).domain([1, 10]);
  12003. scale.copy = function() {
  12004. return copy$1(scale, sequentialLog()).base(scale.base());
  12005. };
  12006. return initInterpolator.apply(scale, arguments);
  12007. }
  12008. function sequentialSymlog() {
  12009. var scale = symlogish(transformer$2());
  12010. scale.copy = function() {
  12011. return copy$1(scale, sequentialSymlog()).constant(scale.constant());
  12012. };
  12013. return initInterpolator.apply(scale, arguments);
  12014. }
  12015. function sequentialPow() {
  12016. var scale = powish(transformer$2());
  12017. scale.copy = function() {
  12018. return copy$1(scale, sequentialPow()).exponent(scale.exponent());
  12019. };
  12020. return initInterpolator.apply(scale, arguments);
  12021. }
  12022. function sequentialSqrt() {
  12023. return sequentialPow.apply(null, arguments).exponent(0.5);
  12024. }
  12025. function sequentialQuantile() {
  12026. var domain = [],
  12027. interpolator = identity$6;
  12028. function scale(x) {
  12029. if (!isNaN(x = +x)) return interpolator((bisectRight(domain, x) - 1) / (domain.length - 1));
  12030. }
  12031. scale.domain = function(_) {
  12032. if (!arguments.length) return domain.slice();
  12033. domain = [];
  12034. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  12035. domain.sort(ascending);
  12036. return scale;
  12037. };
  12038. scale.interpolator = function(_) {
  12039. return arguments.length ? (interpolator = _, scale) : interpolator;
  12040. };
  12041. scale.copy = function() {
  12042. return sequentialQuantile(interpolator).domain(domain);
  12043. };
  12044. return initInterpolator.apply(scale, arguments);
  12045. }
  12046. function transformer$3() {
  12047. var x0 = 0,
  12048. x1 = 0.5,
  12049. x2 = 1,
  12050. t0,
  12051. t1,
  12052. t2,
  12053. k10,
  12054. k21,
  12055. interpolator = identity$6,
  12056. transform,
  12057. clamp = false,
  12058. unknown;
  12059. function scale(x) {
  12060. return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (x < t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
  12061. }
  12062. scale.domain = function(_) {
  12063. return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), t2 = transform(x2 = +_[2]), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), scale) : [x0, x1, x2];
  12064. };
  12065. scale.clamp = function(_) {
  12066. return arguments.length ? (clamp = !!_, scale) : clamp;
  12067. };
  12068. scale.interpolator = function(_) {
  12069. return arguments.length ? (interpolator = _, scale) : interpolator;
  12070. };
  12071. scale.unknown = function(_) {
  12072. return arguments.length ? (unknown = _, scale) : unknown;
  12073. };
  12074. return function(t) {
  12075. 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);
  12076. return scale;
  12077. };
  12078. }
  12079. function diverging() {
  12080. var scale = linearish(transformer$3()(identity$6));
  12081. scale.copy = function() {
  12082. return copy$1(scale, diverging());
  12083. };
  12084. return initInterpolator.apply(scale, arguments);
  12085. }
  12086. function divergingLog() {
  12087. var scale = loggish(transformer$3()).domain([0.1, 1, 10]);
  12088. scale.copy = function() {
  12089. return copy$1(scale, divergingLog()).base(scale.base());
  12090. };
  12091. return initInterpolator.apply(scale, arguments);
  12092. }
  12093. function divergingSymlog() {
  12094. var scale = symlogish(transformer$3());
  12095. scale.copy = function() {
  12096. return copy$1(scale, divergingSymlog()).constant(scale.constant());
  12097. };
  12098. return initInterpolator.apply(scale, arguments);
  12099. }
  12100. function divergingPow() {
  12101. var scale = powish(transformer$3());
  12102. scale.copy = function() {
  12103. return copy$1(scale, divergingPow()).exponent(scale.exponent());
  12104. };
  12105. return initInterpolator.apply(scale, arguments);
  12106. }
  12107. function divergingSqrt() {
  12108. return divergingPow.apply(null, arguments).exponent(0.5);
  12109. }
  12110. function colors(specifier) {
  12111. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  12112. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  12113. return colors;
  12114. }
  12115. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  12116. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  12117. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  12118. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  12119. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  12120. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  12121. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  12122. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  12123. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  12124. var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
  12125. function ramp(scheme) {
  12126. return rgbBasis(scheme[scheme.length - 1]);
  12127. }
  12128. var scheme = new Array(3).concat(
  12129. "d8b365f5f5f55ab4ac",
  12130. "a6611adfc27d80cdc1018571",
  12131. "a6611adfc27df5f5f580cdc1018571",
  12132. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  12133. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  12134. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  12135. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  12136. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  12137. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  12138. ).map(colors);
  12139. var BrBG = ramp(scheme);
  12140. var scheme$1 = new Array(3).concat(
  12141. "af8dc3f7f7f77fbf7b",
  12142. "7b3294c2a5cfa6dba0008837",
  12143. "7b3294c2a5cff7f7f7a6dba0008837",
  12144. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  12145. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  12146. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  12147. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  12148. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  12149. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  12150. ).map(colors);
  12151. var PRGn = ramp(scheme$1);
  12152. var scheme$2 = new Array(3).concat(
  12153. "e9a3c9f7f7f7a1d76a",
  12154. "d01c8bf1b6dab8e1864dac26",
  12155. "d01c8bf1b6daf7f7f7b8e1864dac26",
  12156. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  12157. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  12158. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  12159. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  12160. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  12161. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  12162. ).map(colors);
  12163. var PiYG = ramp(scheme$2);
  12164. var scheme$3 = new Array(3).concat(
  12165. "998ec3f7f7f7f1a340",
  12166. "5e3c99b2abd2fdb863e66101",
  12167. "5e3c99b2abd2f7f7f7fdb863e66101",
  12168. "542788998ec3d8daebfee0b6f1a340b35806",
  12169. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  12170. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  12171. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  12172. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  12173. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  12174. ).map(colors);
  12175. var PuOr = ramp(scheme$3);
  12176. var scheme$4 = new Array(3).concat(
  12177. "ef8a62f7f7f767a9cf",
  12178. "ca0020f4a58292c5de0571b0",
  12179. "ca0020f4a582f7f7f792c5de0571b0",
  12180. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  12181. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  12182. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  12183. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  12184. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  12185. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  12186. ).map(colors);
  12187. var RdBu = ramp(scheme$4);
  12188. var scheme$5 = new Array(3).concat(
  12189. "ef8a62ffffff999999",
  12190. "ca0020f4a582bababa404040",
  12191. "ca0020f4a582ffffffbababa404040",
  12192. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  12193. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  12194. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  12195. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  12196. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  12197. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  12198. ).map(colors);
  12199. var RdGy = ramp(scheme$5);
  12200. var scheme$6 = new Array(3).concat(
  12201. "fc8d59ffffbf91bfdb",
  12202. "d7191cfdae61abd9e92c7bb6",
  12203. "d7191cfdae61ffffbfabd9e92c7bb6",
  12204. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  12205. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  12206. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  12207. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  12208. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  12209. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  12210. ).map(colors);
  12211. var RdYlBu = ramp(scheme$6);
  12212. var scheme$7 = new Array(3).concat(
  12213. "fc8d59ffffbf91cf60",
  12214. "d7191cfdae61a6d96a1a9641",
  12215. "d7191cfdae61ffffbfa6d96a1a9641",
  12216. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  12217. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  12218. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  12219. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  12220. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  12221. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  12222. ).map(colors);
  12223. var RdYlGn = ramp(scheme$7);
  12224. var scheme$8 = new Array(3).concat(
  12225. "fc8d59ffffbf99d594",
  12226. "d7191cfdae61abdda42b83ba",
  12227. "d7191cfdae61ffffbfabdda42b83ba",
  12228. "d53e4ffc8d59fee08be6f59899d5943288bd",
  12229. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  12230. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  12231. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  12232. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  12233. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  12234. ).map(colors);
  12235. var Spectral = ramp(scheme$8);
  12236. var scheme$9 = new Array(3).concat(
  12237. "e5f5f999d8c92ca25f",
  12238. "edf8fbb2e2e266c2a4238b45",
  12239. "edf8fbb2e2e266c2a42ca25f006d2c",
  12240. "edf8fbccece699d8c966c2a42ca25f006d2c",
  12241. "edf8fbccece699d8c966c2a441ae76238b45005824",
  12242. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  12243. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  12244. ).map(colors);
  12245. var BuGn = ramp(scheme$9);
  12246. var scheme$a = new Array(3).concat(
  12247. "e0ecf49ebcda8856a7",
  12248. "edf8fbb3cde38c96c688419d",
  12249. "edf8fbb3cde38c96c68856a7810f7c",
  12250. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  12251. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  12252. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  12253. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  12254. ).map(colors);
  12255. var BuPu = ramp(scheme$a);
  12256. var scheme$b = new Array(3).concat(
  12257. "e0f3dba8ddb543a2ca",
  12258. "f0f9e8bae4bc7bccc42b8cbe",
  12259. "f0f9e8bae4bc7bccc443a2ca0868ac",
  12260. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  12261. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  12262. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  12263. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  12264. ).map(colors);
  12265. var GnBu = ramp(scheme$b);
  12266. var scheme$c = new Array(3).concat(
  12267. "fee8c8fdbb84e34a33",
  12268. "fef0d9fdcc8afc8d59d7301f",
  12269. "fef0d9fdcc8afc8d59e34a33b30000",
  12270. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  12271. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  12272. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  12273. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  12274. ).map(colors);
  12275. var OrRd = ramp(scheme$c);
  12276. var scheme$d = new Array(3).concat(
  12277. "ece2f0a6bddb1c9099",
  12278. "f6eff7bdc9e167a9cf02818a",
  12279. "f6eff7bdc9e167a9cf1c9099016c59",
  12280. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  12281. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  12282. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  12283. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  12284. ).map(colors);
  12285. var PuBuGn = ramp(scheme$d);
  12286. var scheme$e = new Array(3).concat(
  12287. "ece7f2a6bddb2b8cbe",
  12288. "f1eef6bdc9e174a9cf0570b0",
  12289. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  12290. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  12291. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  12292. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  12293. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  12294. ).map(colors);
  12295. var PuBu = ramp(scheme$e);
  12296. var scheme$f = new Array(3).concat(
  12297. "e7e1efc994c7dd1c77",
  12298. "f1eef6d7b5d8df65b0ce1256",
  12299. "f1eef6d7b5d8df65b0dd1c77980043",
  12300. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  12301. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  12302. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  12303. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  12304. ).map(colors);
  12305. var PuRd = ramp(scheme$f);
  12306. var scheme$g = new Array(3).concat(
  12307. "fde0ddfa9fb5c51b8a",
  12308. "feebe2fbb4b9f768a1ae017e",
  12309. "feebe2fbb4b9f768a1c51b8a7a0177",
  12310. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  12311. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  12312. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  12313. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  12314. ).map(colors);
  12315. var RdPu = ramp(scheme$g);
  12316. var scheme$h = new Array(3).concat(
  12317. "edf8b17fcdbb2c7fb8",
  12318. "ffffcca1dab441b6c4225ea8",
  12319. "ffffcca1dab441b6c42c7fb8253494",
  12320. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  12321. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  12322. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  12323. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  12324. ).map(colors);
  12325. var YlGnBu = ramp(scheme$h);
  12326. var scheme$i = new Array(3).concat(
  12327. "f7fcb9addd8e31a354",
  12328. "ffffccc2e69978c679238443",
  12329. "ffffccc2e69978c67931a354006837",
  12330. "ffffccd9f0a3addd8e78c67931a354006837",
  12331. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  12332. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  12333. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  12334. ).map(colors);
  12335. var YlGn = ramp(scheme$i);
  12336. var scheme$j = new Array(3).concat(
  12337. "fff7bcfec44fd95f0e",
  12338. "ffffd4fed98efe9929cc4c02",
  12339. "ffffd4fed98efe9929d95f0e993404",
  12340. "ffffd4fee391fec44ffe9929d95f0e993404",
  12341. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  12342. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  12343. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  12344. ).map(colors);
  12345. var YlOrBr = ramp(scheme$j);
  12346. var scheme$k = new Array(3).concat(
  12347. "ffeda0feb24cf03b20",
  12348. "ffffb2fecc5cfd8d3ce31a1c",
  12349. "ffffb2fecc5cfd8d3cf03b20bd0026",
  12350. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  12351. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  12352. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  12353. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  12354. ).map(colors);
  12355. var YlOrRd = ramp(scheme$k);
  12356. var scheme$l = new Array(3).concat(
  12357. "deebf79ecae13182bd",
  12358. "eff3ffbdd7e76baed62171b5",
  12359. "eff3ffbdd7e76baed63182bd08519c",
  12360. "eff3ffc6dbef9ecae16baed63182bd08519c",
  12361. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  12362. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  12363. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  12364. ).map(colors);
  12365. var Blues = ramp(scheme$l);
  12366. var scheme$m = new Array(3).concat(
  12367. "e5f5e0a1d99b31a354",
  12368. "edf8e9bae4b374c476238b45",
  12369. "edf8e9bae4b374c47631a354006d2c",
  12370. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  12371. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  12372. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  12373. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  12374. ).map(colors);
  12375. var Greens = ramp(scheme$m);
  12376. var scheme$n = new Array(3).concat(
  12377. "f0f0f0bdbdbd636363",
  12378. "f7f7f7cccccc969696525252",
  12379. "f7f7f7cccccc969696636363252525",
  12380. "f7f7f7d9d9d9bdbdbd969696636363252525",
  12381. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  12382. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  12383. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  12384. ).map(colors);
  12385. var Greys = ramp(scheme$n);
  12386. var scheme$o = new Array(3).concat(
  12387. "efedf5bcbddc756bb1",
  12388. "f2f0f7cbc9e29e9ac86a51a3",
  12389. "f2f0f7cbc9e29e9ac8756bb154278f",
  12390. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  12391. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  12392. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  12393. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  12394. ).map(colors);
  12395. var Purples = ramp(scheme$o);
  12396. var scheme$p = new Array(3).concat(
  12397. "fee0d2fc9272de2d26",
  12398. "fee5d9fcae91fb6a4acb181d",
  12399. "fee5d9fcae91fb6a4ade2d26a50f15",
  12400. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  12401. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  12402. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  12403. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  12404. ).map(colors);
  12405. var Reds = ramp(scheme$p);
  12406. var scheme$q = new Array(3).concat(
  12407. "fee6cefdae6be6550d",
  12408. "feeddefdbe85fd8d3cd94701",
  12409. "feeddefdbe85fd8d3ce6550da63603",
  12410. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  12411. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  12412. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  12413. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  12414. ).map(colors);
  12415. var Oranges = ramp(scheme$q);
  12416. function cividis(t) {
  12417. t = Math.max(0, Math.min(1, t));
  12418. return "rgb("
  12419. + 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))))))) + ", "
  12420. + 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))))))) + ", "
  12421. + 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)))))))
  12422. + ")";
  12423. }
  12424. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  12425. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  12426. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  12427. var c = cubehelix();
  12428. function rainbow(t) {
  12429. if (t < 0 || t > 1) t -= Math.floor(t);
  12430. var ts = Math.abs(t - 0.5);
  12431. c.h = 360 * t - 100;
  12432. c.s = 1.5 - 1.5 * ts;
  12433. c.l = 0.8 - 0.9 * ts;
  12434. return c + "";
  12435. }
  12436. var c$1 = rgb(),
  12437. pi_1_3 = Math.PI / 3,
  12438. pi_2_3 = Math.PI * 2 / 3;
  12439. function sinebow(t) {
  12440. var x;
  12441. t = (0.5 - t) * Math.PI;
  12442. c$1.r = 255 * (x = Math.sin(t)) * x;
  12443. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  12444. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  12445. return c$1 + "";
  12446. }
  12447. function turbo(t) {
  12448. t = Math.max(0, Math.min(1, t));
  12449. return "rgb("
  12450. + 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))))))) + ", "
  12451. + 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))))))) + ", "
  12452. + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
  12453. + ")";
  12454. }
  12455. function ramp$1(range) {
  12456. var n = range.length;
  12457. return function(t) {
  12458. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  12459. };
  12460. }
  12461. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  12462. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  12463. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  12464. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  12465. function constant$b(x) {
  12466. return function constant() {
  12467. return x;
  12468. };
  12469. }
  12470. var abs$1 = Math.abs;
  12471. var atan2$1 = Math.atan2;
  12472. var cos$2 = Math.cos;
  12473. var max$2 = Math.max;
  12474. var min$1 = Math.min;
  12475. var sin$2 = Math.sin;
  12476. var sqrt$2 = Math.sqrt;
  12477. var epsilon$3 = 1e-12;
  12478. var pi$4 = Math.PI;
  12479. var halfPi$3 = pi$4 / 2;
  12480. var tau$4 = 2 * pi$4;
  12481. function acos$1(x) {
  12482. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  12483. }
  12484. function asin$1(x) {
  12485. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  12486. }
  12487. function arcInnerRadius(d) {
  12488. return d.innerRadius;
  12489. }
  12490. function arcOuterRadius(d) {
  12491. return d.outerRadius;
  12492. }
  12493. function arcStartAngle(d) {
  12494. return d.startAngle;
  12495. }
  12496. function arcEndAngle(d) {
  12497. return d.endAngle;
  12498. }
  12499. function arcPadAngle(d) {
  12500. return d && d.padAngle; // Note: optional!
  12501. }
  12502. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  12503. var x10 = x1 - x0, y10 = y1 - y0,
  12504. x32 = x3 - x2, y32 = y3 - y2,
  12505. t = y32 * x10 - x32 * y10;
  12506. if (t * t < epsilon$3) return;
  12507. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  12508. return [x0 + t * x10, y0 + t * y10];
  12509. }
  12510. // Compute perpendicular offset line of length rc.
  12511. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  12512. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  12513. var x01 = x0 - x1,
  12514. y01 = y0 - y1,
  12515. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  12516. ox = lo * y01,
  12517. oy = -lo * x01,
  12518. x11 = x0 + ox,
  12519. y11 = y0 + oy,
  12520. x10 = x1 + ox,
  12521. y10 = y1 + oy,
  12522. x00 = (x11 + x10) / 2,
  12523. y00 = (y11 + y10) / 2,
  12524. dx = x10 - x11,
  12525. dy = y10 - y11,
  12526. d2 = dx * dx + dy * dy,
  12527. r = r1 - rc,
  12528. D = x11 * y10 - x10 * y11,
  12529. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  12530. cx0 = (D * dy - dx * d) / d2,
  12531. cy0 = (-D * dx - dy * d) / d2,
  12532. cx1 = (D * dy + dx * d) / d2,
  12533. cy1 = (-D * dx + dy * d) / d2,
  12534. dx0 = cx0 - x00,
  12535. dy0 = cy0 - y00,
  12536. dx1 = cx1 - x00,
  12537. dy1 = cy1 - y00;
  12538. // Pick the closer of the two intersection points.
  12539. // TODO Is there a faster way to determine which intersection to use?
  12540. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  12541. return {
  12542. cx: cx0,
  12543. cy: cy0,
  12544. x01: -ox,
  12545. y01: -oy,
  12546. x11: cx0 * (r1 / r - 1),
  12547. y11: cy0 * (r1 / r - 1)
  12548. };
  12549. }
  12550. function arc() {
  12551. var innerRadius = arcInnerRadius,
  12552. outerRadius = arcOuterRadius,
  12553. cornerRadius = constant$b(0),
  12554. padRadius = null,
  12555. startAngle = arcStartAngle,
  12556. endAngle = arcEndAngle,
  12557. padAngle = arcPadAngle,
  12558. context = null;
  12559. function arc() {
  12560. var buffer,
  12561. r,
  12562. r0 = +innerRadius.apply(this, arguments),
  12563. r1 = +outerRadius.apply(this, arguments),
  12564. a0 = startAngle.apply(this, arguments) - halfPi$3,
  12565. a1 = endAngle.apply(this, arguments) - halfPi$3,
  12566. da = abs$1(a1 - a0),
  12567. cw = a1 > a0;
  12568. if (!context) context = buffer = path();
  12569. // Ensure that the outer radius is always larger than the inner radius.
  12570. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  12571. // Is it a point?
  12572. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  12573. // Or is it a circle or annulus?
  12574. else if (da > tau$4 - epsilon$3) {
  12575. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  12576. context.arc(0, 0, r1, a0, a1, !cw);
  12577. if (r0 > epsilon$3) {
  12578. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  12579. context.arc(0, 0, r0, a1, a0, cw);
  12580. }
  12581. }
  12582. // Or is it a circular or annular sector?
  12583. else {
  12584. var a01 = a0,
  12585. a11 = a1,
  12586. a00 = a0,
  12587. a10 = a1,
  12588. da0 = da,
  12589. da1 = da,
  12590. ap = padAngle.apply(this, arguments) / 2,
  12591. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  12592. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  12593. rc0 = rc,
  12594. rc1 = rc,
  12595. t0,
  12596. t1;
  12597. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  12598. if (rp > epsilon$3) {
  12599. var p0 = asin$1(rp / r0 * sin$2(ap)),
  12600. p1 = asin$1(rp / r1 * sin$2(ap));
  12601. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  12602. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  12603. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  12604. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  12605. }
  12606. var x01 = r1 * cos$2(a01),
  12607. y01 = r1 * sin$2(a01),
  12608. x10 = r0 * cos$2(a10),
  12609. y10 = r0 * sin$2(a10);
  12610. // Apply rounded corners?
  12611. if (rc > epsilon$3) {
  12612. var x11 = r1 * cos$2(a11),
  12613. y11 = r1 * sin$2(a11),
  12614. x00 = r0 * cos$2(a00),
  12615. y00 = r0 * sin$2(a00),
  12616. oc;
  12617. // Restrict the corner radius according to the sector angle.
  12618. if (da < pi$4 && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
  12619. var ax = x01 - oc[0],
  12620. ay = y01 - oc[1],
  12621. bx = x11 - oc[0],
  12622. by = y11 - oc[1],
  12623. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  12624. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  12625. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  12626. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  12627. }
  12628. }
  12629. // Is the sector collapsed to a line?
  12630. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  12631. // Does the sector’s outer ring have rounded corners?
  12632. else if (rc1 > epsilon$3) {
  12633. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  12634. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  12635. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12636. // Have the corners merged?
  12637. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12638. // Otherwise, draw the two corners and the ring.
  12639. else {
  12640. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12641. context.arc(0, 0, r1, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  12642. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12643. }
  12644. }
  12645. // Or is the outer ring just a circular arc?
  12646. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  12647. // Is there no inner ring, and it’s a circular sector?
  12648. // Or perhaps it’s an annular sector collapsed due to padding?
  12649. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  12650. // Does the sector’s inner ring (or point) have rounded corners?
  12651. else if (rc0 > epsilon$3) {
  12652. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  12653. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  12654. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12655. // Have the corners merged?
  12656. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12657. // Otherwise, draw the two corners and the ring.
  12658. else {
  12659. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12660. context.arc(0, 0, r0, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  12661. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12662. }
  12663. }
  12664. // Or is the inner ring just a circular arc?
  12665. else context.arc(0, 0, r0, a10, a00, cw);
  12666. }
  12667. context.closePath();
  12668. if (buffer) return context = null, buffer + "" || null;
  12669. }
  12670. arc.centroid = function() {
  12671. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  12672. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  12673. return [cos$2(a) * r, sin$2(a) * r];
  12674. };
  12675. arc.innerRadius = function(_) {
  12676. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : innerRadius;
  12677. };
  12678. arc.outerRadius = function(_) {
  12679. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : outerRadius;
  12680. };
  12681. arc.cornerRadius = function(_) {
  12682. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : cornerRadius;
  12683. };
  12684. arc.padRadius = function(_) {
  12685. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), arc) : padRadius;
  12686. };
  12687. arc.startAngle = function(_) {
  12688. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : startAngle;
  12689. };
  12690. arc.endAngle = function(_) {
  12691. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : endAngle;
  12692. };
  12693. arc.padAngle = function(_) {
  12694. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : padAngle;
  12695. };
  12696. arc.context = function(_) {
  12697. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  12698. };
  12699. return arc;
  12700. }
  12701. function Linear(context) {
  12702. this._context = context;
  12703. }
  12704. Linear.prototype = {
  12705. areaStart: function() {
  12706. this._line = 0;
  12707. },
  12708. areaEnd: function() {
  12709. this._line = NaN;
  12710. },
  12711. lineStart: function() {
  12712. this._point = 0;
  12713. },
  12714. lineEnd: function() {
  12715. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12716. this._line = 1 - this._line;
  12717. },
  12718. point: function(x, y) {
  12719. x = +x, y = +y;
  12720. switch (this._point) {
  12721. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12722. case 1: this._point = 2; // proceed
  12723. default: this._context.lineTo(x, y); break;
  12724. }
  12725. }
  12726. };
  12727. function curveLinear(context) {
  12728. return new Linear(context);
  12729. }
  12730. function x$3(p) {
  12731. return p[0];
  12732. }
  12733. function y$3(p) {
  12734. return p[1];
  12735. }
  12736. function line() {
  12737. var x = x$3,
  12738. y = y$3,
  12739. defined = constant$b(true),
  12740. context = null,
  12741. curve = curveLinear,
  12742. output = null;
  12743. function line(data) {
  12744. var i,
  12745. n = data.length,
  12746. d,
  12747. defined0 = false,
  12748. buffer;
  12749. if (context == null) output = curve(buffer = path());
  12750. for (i = 0; i <= n; ++i) {
  12751. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12752. if (defined0 = !defined0) output.lineStart();
  12753. else output.lineEnd();
  12754. }
  12755. if (defined0) output.point(+x(d, i, data), +y(d, i, data));
  12756. }
  12757. if (buffer) return output = null, buffer + "" || null;
  12758. }
  12759. line.x = function(_) {
  12760. return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), line) : x;
  12761. };
  12762. line.y = function(_) {
  12763. return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), line) : y;
  12764. };
  12765. line.defined = function(_) {
  12766. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), line) : defined;
  12767. };
  12768. line.curve = function(_) {
  12769. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  12770. };
  12771. line.context = function(_) {
  12772. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  12773. };
  12774. return line;
  12775. }
  12776. function area$3() {
  12777. var x0 = x$3,
  12778. x1 = null,
  12779. y0 = constant$b(0),
  12780. y1 = y$3,
  12781. defined = constant$b(true),
  12782. context = null,
  12783. curve = curveLinear,
  12784. output = null;
  12785. function area(data) {
  12786. var i,
  12787. j,
  12788. k,
  12789. n = data.length,
  12790. d,
  12791. defined0 = false,
  12792. buffer,
  12793. x0z = new Array(n),
  12794. y0z = new Array(n);
  12795. if (context == null) output = curve(buffer = path());
  12796. for (i = 0; i <= n; ++i) {
  12797. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12798. if (defined0 = !defined0) {
  12799. j = i;
  12800. output.areaStart();
  12801. output.lineStart();
  12802. } else {
  12803. output.lineEnd();
  12804. output.lineStart();
  12805. for (k = i - 1; k >= j; --k) {
  12806. output.point(x0z[k], y0z[k]);
  12807. }
  12808. output.lineEnd();
  12809. output.areaEnd();
  12810. }
  12811. }
  12812. if (defined0) {
  12813. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  12814. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  12815. }
  12816. }
  12817. if (buffer) return output = null, buffer + "" || null;
  12818. }
  12819. function arealine() {
  12820. return line().defined(defined).curve(curve).context(context);
  12821. }
  12822. area.x = function(_) {
  12823. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), x1 = null, area) : x0;
  12824. };
  12825. area.x0 = function(_) {
  12826. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), area) : x0;
  12827. };
  12828. area.x1 = function(_) {
  12829. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : x1;
  12830. };
  12831. area.y = function(_) {
  12832. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), y1 = null, area) : y0;
  12833. };
  12834. area.y0 = function(_) {
  12835. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), area) : y0;
  12836. };
  12837. area.y1 = function(_) {
  12838. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : y1;
  12839. };
  12840. area.lineX0 =
  12841. area.lineY0 = function() {
  12842. return arealine().x(x0).y(y0);
  12843. };
  12844. area.lineY1 = function() {
  12845. return arealine().x(x0).y(y1);
  12846. };
  12847. area.lineX1 = function() {
  12848. return arealine().x(x1).y(y0);
  12849. };
  12850. area.defined = function(_) {
  12851. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), area) : defined;
  12852. };
  12853. area.curve = function(_) {
  12854. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  12855. };
  12856. area.context = function(_) {
  12857. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  12858. };
  12859. return area;
  12860. }
  12861. function descending$1(a, b) {
  12862. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  12863. }
  12864. function identity$8(d) {
  12865. return d;
  12866. }
  12867. function pie() {
  12868. var value = identity$8,
  12869. sortValues = descending$1,
  12870. sort = null,
  12871. startAngle = constant$b(0),
  12872. endAngle = constant$b(tau$4),
  12873. padAngle = constant$b(0);
  12874. function pie(data) {
  12875. var i,
  12876. n = data.length,
  12877. j,
  12878. k,
  12879. sum = 0,
  12880. index = new Array(n),
  12881. arcs = new Array(n),
  12882. a0 = +startAngle.apply(this, arguments),
  12883. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  12884. a1,
  12885. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  12886. pa = p * (da < 0 ? -1 : 1),
  12887. v;
  12888. for (i = 0; i < n; ++i) {
  12889. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  12890. sum += v;
  12891. }
  12892. }
  12893. // Optionally sort the arcs by previously-computed values or by data.
  12894. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  12895. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  12896. // Compute the arcs! They are stored in the original data's order.
  12897. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  12898. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  12899. data: data[j],
  12900. index: i,
  12901. value: v,
  12902. startAngle: a0,
  12903. endAngle: a1,
  12904. padAngle: p
  12905. };
  12906. }
  12907. return arcs;
  12908. }
  12909. pie.value = function(_) {
  12910. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), pie) : value;
  12911. };
  12912. pie.sortValues = function(_) {
  12913. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  12914. };
  12915. pie.sort = function(_) {
  12916. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  12917. };
  12918. pie.startAngle = function(_) {
  12919. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : startAngle;
  12920. };
  12921. pie.endAngle = function(_) {
  12922. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : endAngle;
  12923. };
  12924. pie.padAngle = function(_) {
  12925. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : padAngle;
  12926. };
  12927. return pie;
  12928. }
  12929. var curveRadialLinear = curveRadial(curveLinear);
  12930. function Radial(curve) {
  12931. this._curve = curve;
  12932. }
  12933. Radial.prototype = {
  12934. areaStart: function() {
  12935. this._curve.areaStart();
  12936. },
  12937. areaEnd: function() {
  12938. this._curve.areaEnd();
  12939. },
  12940. lineStart: function() {
  12941. this._curve.lineStart();
  12942. },
  12943. lineEnd: function() {
  12944. this._curve.lineEnd();
  12945. },
  12946. point: function(a, r) {
  12947. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  12948. }
  12949. };
  12950. function curveRadial(curve) {
  12951. function radial(context) {
  12952. return new Radial(curve(context));
  12953. }
  12954. radial._curve = curve;
  12955. return radial;
  12956. }
  12957. function lineRadial(l) {
  12958. var c = l.curve;
  12959. l.angle = l.x, delete l.x;
  12960. l.radius = l.y, delete l.y;
  12961. l.curve = function(_) {
  12962. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12963. };
  12964. return l;
  12965. }
  12966. function lineRadial$1() {
  12967. return lineRadial(line().curve(curveRadialLinear));
  12968. }
  12969. function areaRadial() {
  12970. var a = area$3().curve(curveRadialLinear),
  12971. c = a.curve,
  12972. x0 = a.lineX0,
  12973. x1 = a.lineX1,
  12974. y0 = a.lineY0,
  12975. y1 = a.lineY1;
  12976. a.angle = a.x, delete a.x;
  12977. a.startAngle = a.x0, delete a.x0;
  12978. a.endAngle = a.x1, delete a.x1;
  12979. a.radius = a.y, delete a.y;
  12980. a.innerRadius = a.y0, delete a.y0;
  12981. a.outerRadius = a.y1, delete a.y1;
  12982. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  12983. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  12984. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  12985. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  12986. a.curve = function(_) {
  12987. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12988. };
  12989. return a;
  12990. }
  12991. function pointRadial(x, y) {
  12992. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  12993. }
  12994. var slice$6 = Array.prototype.slice;
  12995. function linkSource(d) {
  12996. return d.source;
  12997. }
  12998. function linkTarget(d) {
  12999. return d.target;
  13000. }
  13001. function link$2(curve) {
  13002. var source = linkSource,
  13003. target = linkTarget,
  13004. x = x$3,
  13005. y = y$3,
  13006. context = null;
  13007. function link() {
  13008. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  13009. if (!context) context = buffer = path();
  13010. curve(context, +x.apply(this, (argv[0] = s, argv)), +y.apply(this, argv), +x.apply(this, (argv[0] = t, argv)), +y.apply(this, argv));
  13011. if (buffer) return context = null, buffer + "" || null;
  13012. }
  13013. link.source = function(_) {
  13014. return arguments.length ? (source = _, link) : source;
  13015. };
  13016. link.target = function(_) {
  13017. return arguments.length ? (target = _, link) : target;
  13018. };
  13019. link.x = function(_) {
  13020. return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), link) : x;
  13021. };
  13022. link.y = function(_) {
  13023. return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), link) : y;
  13024. };
  13025. link.context = function(_) {
  13026. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  13027. };
  13028. return link;
  13029. }
  13030. function curveHorizontal(context, x0, y0, x1, y1) {
  13031. context.moveTo(x0, y0);
  13032. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  13033. }
  13034. function curveVertical(context, x0, y0, x1, y1) {
  13035. context.moveTo(x0, y0);
  13036. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  13037. }
  13038. function curveRadial$1(context, x0, y0, x1, y1) {
  13039. var p0 = pointRadial(x0, y0),
  13040. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  13041. p2 = pointRadial(x1, y0),
  13042. p3 = pointRadial(x1, y1);
  13043. context.moveTo(p0[0], p0[1]);
  13044. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  13045. }
  13046. function linkHorizontal() {
  13047. return link$2(curveHorizontal);
  13048. }
  13049. function linkVertical() {
  13050. return link$2(curveVertical);
  13051. }
  13052. function linkRadial() {
  13053. var l = link$2(curveRadial$1);
  13054. l.angle = l.x, delete l.x;
  13055. l.radius = l.y, delete l.y;
  13056. return l;
  13057. }
  13058. var circle$2 = {
  13059. draw: function(context, size) {
  13060. var r = Math.sqrt(size / pi$4);
  13061. context.moveTo(r, 0);
  13062. context.arc(0, 0, r, 0, tau$4);
  13063. }
  13064. };
  13065. var cross$2 = {
  13066. draw: function(context, size) {
  13067. var r = Math.sqrt(size / 5) / 2;
  13068. context.moveTo(-3 * r, -r);
  13069. context.lineTo(-r, -r);
  13070. context.lineTo(-r, -3 * r);
  13071. context.lineTo(r, -3 * r);
  13072. context.lineTo(r, -r);
  13073. context.lineTo(3 * r, -r);
  13074. context.lineTo(3 * r, r);
  13075. context.lineTo(r, r);
  13076. context.lineTo(r, 3 * r);
  13077. context.lineTo(-r, 3 * r);
  13078. context.lineTo(-r, r);
  13079. context.lineTo(-3 * r, r);
  13080. context.closePath();
  13081. }
  13082. };
  13083. var tan30 = Math.sqrt(1 / 3),
  13084. tan30_2 = tan30 * 2;
  13085. var diamond = {
  13086. draw: function(context, size) {
  13087. var y = Math.sqrt(size / tan30_2),
  13088. x = y * tan30;
  13089. context.moveTo(0, -y);
  13090. context.lineTo(x, 0);
  13091. context.lineTo(0, y);
  13092. context.lineTo(-x, 0);
  13093. context.closePath();
  13094. }
  13095. };
  13096. var ka = 0.89081309152928522810,
  13097. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  13098. kx = Math.sin(tau$4 / 10) * kr,
  13099. ky = -Math.cos(tau$4 / 10) * kr;
  13100. var star = {
  13101. draw: function(context, size) {
  13102. var r = Math.sqrt(size * ka),
  13103. x = kx * r,
  13104. y = ky * r;
  13105. context.moveTo(0, -r);
  13106. context.lineTo(x, y);
  13107. for (var i = 1; i < 5; ++i) {
  13108. var a = tau$4 * i / 5,
  13109. c = Math.cos(a),
  13110. s = Math.sin(a);
  13111. context.lineTo(s * r, -c * r);
  13112. context.lineTo(c * x - s * y, s * x + c * y);
  13113. }
  13114. context.closePath();
  13115. }
  13116. };
  13117. var square = {
  13118. draw: function(context, size) {
  13119. var w = Math.sqrt(size),
  13120. x = -w / 2;
  13121. context.rect(x, x, w, w);
  13122. }
  13123. };
  13124. var sqrt3 = Math.sqrt(3);
  13125. var triangle = {
  13126. draw: function(context, size) {
  13127. var y = -Math.sqrt(size / (sqrt3 * 3));
  13128. context.moveTo(0, y * 2);
  13129. context.lineTo(-sqrt3 * y, -y);
  13130. context.lineTo(sqrt3 * y, -y);
  13131. context.closePath();
  13132. }
  13133. };
  13134. var c$2 = -0.5,
  13135. s = Math.sqrt(3) / 2,
  13136. k = 1 / Math.sqrt(12),
  13137. a = (k / 2 + 1) * 3;
  13138. var wye = {
  13139. draw: function(context, size) {
  13140. var r = Math.sqrt(size / a),
  13141. x0 = r / 2,
  13142. y0 = r * k,
  13143. x1 = x0,
  13144. y1 = r * k + r,
  13145. x2 = -x1,
  13146. y2 = y1;
  13147. context.moveTo(x0, y0);
  13148. context.lineTo(x1, y1);
  13149. context.lineTo(x2, y2);
  13150. context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
  13151. context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
  13152. context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
  13153. context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
  13154. context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
  13155. context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
  13156. context.closePath();
  13157. }
  13158. };
  13159. var symbols = [
  13160. circle$2,
  13161. cross$2,
  13162. diamond,
  13163. square,
  13164. star,
  13165. triangle,
  13166. wye
  13167. ];
  13168. function symbol() {
  13169. var type = constant$b(circle$2),
  13170. size = constant$b(64),
  13171. context = null;
  13172. function symbol() {
  13173. var buffer;
  13174. if (!context) context = buffer = path();
  13175. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  13176. if (buffer) return context = null, buffer + "" || null;
  13177. }
  13178. symbol.type = function(_) {
  13179. return arguments.length ? (type = typeof _ === "function" ? _ : constant$b(_), symbol) : type;
  13180. };
  13181. symbol.size = function(_) {
  13182. return arguments.length ? (size = typeof _ === "function" ? _ : constant$b(+_), symbol) : size;
  13183. };
  13184. symbol.context = function(_) {
  13185. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  13186. };
  13187. return symbol;
  13188. }
  13189. function noop$3() {}
  13190. function point$2(that, x, y) {
  13191. that._context.bezierCurveTo(
  13192. (2 * that._x0 + that._x1) / 3,
  13193. (2 * that._y0 + that._y1) / 3,
  13194. (that._x0 + 2 * that._x1) / 3,
  13195. (that._y0 + 2 * that._y1) / 3,
  13196. (that._x0 + 4 * that._x1 + x) / 6,
  13197. (that._y0 + 4 * that._y1 + y) / 6
  13198. );
  13199. }
  13200. function Basis(context) {
  13201. this._context = context;
  13202. }
  13203. Basis.prototype = {
  13204. areaStart: function() {
  13205. this._line = 0;
  13206. },
  13207. areaEnd: function() {
  13208. this._line = NaN;
  13209. },
  13210. lineStart: function() {
  13211. this._x0 = this._x1 =
  13212. this._y0 = this._y1 = NaN;
  13213. this._point = 0;
  13214. },
  13215. lineEnd: function() {
  13216. switch (this._point) {
  13217. case 3: point$2(this, this._x1, this._y1); // proceed
  13218. case 2: this._context.lineTo(this._x1, this._y1); break;
  13219. }
  13220. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13221. this._line = 1 - this._line;
  13222. },
  13223. point: function(x, y) {
  13224. x = +x, y = +y;
  13225. switch (this._point) {
  13226. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13227. case 1: this._point = 2; break;
  13228. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  13229. default: point$2(this, x, y); break;
  13230. }
  13231. this._x0 = this._x1, this._x1 = x;
  13232. this._y0 = this._y1, this._y1 = y;
  13233. }
  13234. };
  13235. function basis$2(context) {
  13236. return new Basis(context);
  13237. }
  13238. function BasisClosed(context) {
  13239. this._context = context;
  13240. }
  13241. BasisClosed.prototype = {
  13242. areaStart: noop$3,
  13243. areaEnd: noop$3,
  13244. lineStart: function() {
  13245. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  13246. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  13247. this._point = 0;
  13248. },
  13249. lineEnd: function() {
  13250. switch (this._point) {
  13251. case 1: {
  13252. this._context.moveTo(this._x2, this._y2);
  13253. this._context.closePath();
  13254. break;
  13255. }
  13256. case 2: {
  13257. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  13258. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  13259. this._context.closePath();
  13260. break;
  13261. }
  13262. case 3: {
  13263. this.point(this._x2, this._y2);
  13264. this.point(this._x3, this._y3);
  13265. this.point(this._x4, this._y4);
  13266. break;
  13267. }
  13268. }
  13269. },
  13270. point: function(x, y) {
  13271. x = +x, y = +y;
  13272. switch (this._point) {
  13273. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  13274. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  13275. 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;
  13276. default: point$2(this, x, y); break;
  13277. }
  13278. this._x0 = this._x1, this._x1 = x;
  13279. this._y0 = this._y1, this._y1 = y;
  13280. }
  13281. };
  13282. function basisClosed$1(context) {
  13283. return new BasisClosed(context);
  13284. }
  13285. function BasisOpen(context) {
  13286. this._context = context;
  13287. }
  13288. BasisOpen.prototype = {
  13289. areaStart: function() {
  13290. this._line = 0;
  13291. },
  13292. areaEnd: function() {
  13293. this._line = NaN;
  13294. },
  13295. lineStart: function() {
  13296. this._x0 = this._x1 =
  13297. this._y0 = this._y1 = NaN;
  13298. this._point = 0;
  13299. },
  13300. lineEnd: function() {
  13301. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13302. this._line = 1 - this._line;
  13303. },
  13304. point: function(x, y) {
  13305. x = +x, y = +y;
  13306. switch (this._point) {
  13307. case 0: this._point = 1; break;
  13308. case 1: this._point = 2; break;
  13309. 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;
  13310. case 3: this._point = 4; // proceed
  13311. default: point$2(this, x, y); break;
  13312. }
  13313. this._x0 = this._x1, this._x1 = x;
  13314. this._y0 = this._y1, this._y1 = y;
  13315. }
  13316. };
  13317. function basisOpen(context) {
  13318. return new BasisOpen(context);
  13319. }
  13320. function Bundle(context, beta) {
  13321. this._basis = new Basis(context);
  13322. this._beta = beta;
  13323. }
  13324. Bundle.prototype = {
  13325. lineStart: function() {
  13326. this._x = [];
  13327. this._y = [];
  13328. this._basis.lineStart();
  13329. },
  13330. lineEnd: function() {
  13331. var x = this._x,
  13332. y = this._y,
  13333. j = x.length - 1;
  13334. if (j > 0) {
  13335. var x0 = x[0],
  13336. y0 = y[0],
  13337. dx = x[j] - x0,
  13338. dy = y[j] - y0,
  13339. i = -1,
  13340. t;
  13341. while (++i <= j) {
  13342. t = i / j;
  13343. this._basis.point(
  13344. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  13345. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  13346. );
  13347. }
  13348. }
  13349. this._x = this._y = null;
  13350. this._basis.lineEnd();
  13351. },
  13352. point: function(x, y) {
  13353. this._x.push(+x);
  13354. this._y.push(+y);
  13355. }
  13356. };
  13357. var bundle = (function custom(beta) {
  13358. function bundle(context) {
  13359. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  13360. }
  13361. bundle.beta = function(beta) {
  13362. return custom(+beta);
  13363. };
  13364. return bundle;
  13365. })(0.85);
  13366. function point$3(that, x, y) {
  13367. that._context.bezierCurveTo(
  13368. that._x1 + that._k * (that._x2 - that._x0),
  13369. that._y1 + that._k * (that._y2 - that._y0),
  13370. that._x2 + that._k * (that._x1 - x),
  13371. that._y2 + that._k * (that._y1 - y),
  13372. that._x2,
  13373. that._y2
  13374. );
  13375. }
  13376. function Cardinal(context, tension) {
  13377. this._context = context;
  13378. this._k = (1 - tension) / 6;
  13379. }
  13380. Cardinal.prototype = {
  13381. areaStart: function() {
  13382. this._line = 0;
  13383. },
  13384. areaEnd: function() {
  13385. this._line = NaN;
  13386. },
  13387. lineStart: function() {
  13388. this._x0 = this._x1 = this._x2 =
  13389. this._y0 = this._y1 = this._y2 = NaN;
  13390. this._point = 0;
  13391. },
  13392. lineEnd: function() {
  13393. switch (this._point) {
  13394. case 2: this._context.lineTo(this._x2, this._y2); break;
  13395. case 3: point$3(this, this._x1, this._y1); break;
  13396. }
  13397. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13398. this._line = 1 - this._line;
  13399. },
  13400. point: function(x, y) {
  13401. x = +x, y = +y;
  13402. switch (this._point) {
  13403. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13404. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  13405. case 2: this._point = 3; // proceed
  13406. default: point$3(this, x, y); break;
  13407. }
  13408. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13409. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13410. }
  13411. };
  13412. var cardinal = (function custom(tension) {
  13413. function cardinal(context) {
  13414. return new Cardinal(context, tension);
  13415. }
  13416. cardinal.tension = function(tension) {
  13417. return custom(+tension);
  13418. };
  13419. return cardinal;
  13420. })(0);
  13421. function CardinalClosed(context, tension) {
  13422. this._context = context;
  13423. this._k = (1 - tension) / 6;
  13424. }
  13425. CardinalClosed.prototype = {
  13426. areaStart: noop$3,
  13427. areaEnd: noop$3,
  13428. lineStart: function() {
  13429. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13430. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13431. this._point = 0;
  13432. },
  13433. lineEnd: function() {
  13434. switch (this._point) {
  13435. case 1: {
  13436. this._context.moveTo(this._x3, this._y3);
  13437. this._context.closePath();
  13438. break;
  13439. }
  13440. case 2: {
  13441. this._context.lineTo(this._x3, this._y3);
  13442. this._context.closePath();
  13443. break;
  13444. }
  13445. case 3: {
  13446. this.point(this._x3, this._y3);
  13447. this.point(this._x4, this._y4);
  13448. this.point(this._x5, this._y5);
  13449. break;
  13450. }
  13451. }
  13452. },
  13453. point: function(x, y) {
  13454. x = +x, y = +y;
  13455. switch (this._point) {
  13456. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13457. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13458. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13459. default: point$3(this, x, y); break;
  13460. }
  13461. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13462. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13463. }
  13464. };
  13465. var cardinalClosed = (function custom(tension) {
  13466. function cardinal(context) {
  13467. return new CardinalClosed(context, tension);
  13468. }
  13469. cardinal.tension = function(tension) {
  13470. return custom(+tension);
  13471. };
  13472. return cardinal;
  13473. })(0);
  13474. function CardinalOpen(context, tension) {
  13475. this._context = context;
  13476. this._k = (1 - tension) / 6;
  13477. }
  13478. CardinalOpen.prototype = {
  13479. areaStart: function() {
  13480. this._line = 0;
  13481. },
  13482. areaEnd: function() {
  13483. this._line = NaN;
  13484. },
  13485. lineStart: function() {
  13486. this._x0 = this._x1 = this._x2 =
  13487. this._y0 = this._y1 = this._y2 = NaN;
  13488. this._point = 0;
  13489. },
  13490. lineEnd: function() {
  13491. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13492. this._line = 1 - this._line;
  13493. },
  13494. point: function(x, y) {
  13495. x = +x, y = +y;
  13496. switch (this._point) {
  13497. case 0: this._point = 1; break;
  13498. case 1: this._point = 2; break;
  13499. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13500. case 3: this._point = 4; // proceed
  13501. default: point$3(this, x, y); break;
  13502. }
  13503. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13504. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13505. }
  13506. };
  13507. var cardinalOpen = (function custom(tension) {
  13508. function cardinal(context) {
  13509. return new CardinalOpen(context, tension);
  13510. }
  13511. cardinal.tension = function(tension) {
  13512. return custom(+tension);
  13513. };
  13514. return cardinal;
  13515. })(0);
  13516. function point$4(that, x, y) {
  13517. var x1 = that._x1,
  13518. y1 = that._y1,
  13519. x2 = that._x2,
  13520. y2 = that._y2;
  13521. if (that._l01_a > epsilon$3) {
  13522. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  13523. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  13524. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  13525. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  13526. }
  13527. if (that._l23_a > epsilon$3) {
  13528. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  13529. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  13530. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  13531. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  13532. }
  13533. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  13534. }
  13535. function CatmullRom(context, alpha) {
  13536. this._context = context;
  13537. this._alpha = alpha;
  13538. }
  13539. CatmullRom.prototype = {
  13540. areaStart: function() {
  13541. this._line = 0;
  13542. },
  13543. areaEnd: function() {
  13544. this._line = NaN;
  13545. },
  13546. lineStart: function() {
  13547. this._x0 = this._x1 = this._x2 =
  13548. this._y0 = this._y1 = this._y2 = NaN;
  13549. this._l01_a = this._l12_a = this._l23_a =
  13550. this._l01_2a = this._l12_2a = this._l23_2a =
  13551. this._point = 0;
  13552. },
  13553. lineEnd: function() {
  13554. switch (this._point) {
  13555. case 2: this._context.lineTo(this._x2, this._y2); break;
  13556. case 3: this.point(this._x2, this._y2); break;
  13557. }
  13558. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13559. this._line = 1 - this._line;
  13560. },
  13561. point: function(x, y) {
  13562. x = +x, y = +y;
  13563. if (this._point) {
  13564. var x23 = this._x2 - x,
  13565. y23 = this._y2 - y;
  13566. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13567. }
  13568. switch (this._point) {
  13569. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13570. case 1: this._point = 2; break;
  13571. case 2: this._point = 3; // proceed
  13572. default: point$4(this, x, y); break;
  13573. }
  13574. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13575. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13576. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13577. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13578. }
  13579. };
  13580. var catmullRom = (function custom(alpha) {
  13581. function catmullRom(context) {
  13582. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  13583. }
  13584. catmullRom.alpha = function(alpha) {
  13585. return custom(+alpha);
  13586. };
  13587. return catmullRom;
  13588. })(0.5);
  13589. function CatmullRomClosed(context, alpha) {
  13590. this._context = context;
  13591. this._alpha = alpha;
  13592. }
  13593. CatmullRomClosed.prototype = {
  13594. areaStart: noop$3,
  13595. areaEnd: noop$3,
  13596. lineStart: function() {
  13597. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13598. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13599. this._l01_a = this._l12_a = this._l23_a =
  13600. this._l01_2a = this._l12_2a = this._l23_2a =
  13601. this._point = 0;
  13602. },
  13603. lineEnd: function() {
  13604. switch (this._point) {
  13605. case 1: {
  13606. this._context.moveTo(this._x3, this._y3);
  13607. this._context.closePath();
  13608. break;
  13609. }
  13610. case 2: {
  13611. this._context.lineTo(this._x3, this._y3);
  13612. this._context.closePath();
  13613. break;
  13614. }
  13615. case 3: {
  13616. this.point(this._x3, this._y3);
  13617. this.point(this._x4, this._y4);
  13618. this.point(this._x5, this._y5);
  13619. break;
  13620. }
  13621. }
  13622. },
  13623. point: function(x, y) {
  13624. x = +x, y = +y;
  13625. if (this._point) {
  13626. var x23 = this._x2 - x,
  13627. y23 = this._y2 - y;
  13628. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13629. }
  13630. switch (this._point) {
  13631. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13632. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13633. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13634. default: point$4(this, x, y); break;
  13635. }
  13636. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13637. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13638. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13639. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13640. }
  13641. };
  13642. var catmullRomClosed = (function custom(alpha) {
  13643. function catmullRom(context) {
  13644. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  13645. }
  13646. catmullRom.alpha = function(alpha) {
  13647. return custom(+alpha);
  13648. };
  13649. return catmullRom;
  13650. })(0.5);
  13651. function CatmullRomOpen(context, alpha) {
  13652. this._context = context;
  13653. this._alpha = alpha;
  13654. }
  13655. CatmullRomOpen.prototype = {
  13656. areaStart: function() {
  13657. this._line = 0;
  13658. },
  13659. areaEnd: function() {
  13660. this._line = NaN;
  13661. },
  13662. lineStart: function() {
  13663. this._x0 = this._x1 = this._x2 =
  13664. this._y0 = this._y1 = this._y2 = NaN;
  13665. this._l01_a = this._l12_a = this._l23_a =
  13666. this._l01_2a = this._l12_2a = this._l23_2a =
  13667. this._point = 0;
  13668. },
  13669. lineEnd: function() {
  13670. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13671. this._line = 1 - this._line;
  13672. },
  13673. point: function(x, y) {
  13674. x = +x, y = +y;
  13675. if (this._point) {
  13676. var x23 = this._x2 - x,
  13677. y23 = this._y2 - y;
  13678. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13679. }
  13680. switch (this._point) {
  13681. case 0: this._point = 1; break;
  13682. case 1: this._point = 2; break;
  13683. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13684. case 3: this._point = 4; // proceed
  13685. default: point$4(this, x, y); break;
  13686. }
  13687. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13688. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13689. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13690. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13691. }
  13692. };
  13693. var catmullRomOpen = (function custom(alpha) {
  13694. function catmullRom(context) {
  13695. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  13696. }
  13697. catmullRom.alpha = function(alpha) {
  13698. return custom(+alpha);
  13699. };
  13700. return catmullRom;
  13701. })(0.5);
  13702. function LinearClosed(context) {
  13703. this._context = context;
  13704. }
  13705. LinearClosed.prototype = {
  13706. areaStart: noop$3,
  13707. areaEnd: noop$3,
  13708. lineStart: function() {
  13709. this._point = 0;
  13710. },
  13711. lineEnd: function() {
  13712. if (this._point) this._context.closePath();
  13713. },
  13714. point: function(x, y) {
  13715. x = +x, y = +y;
  13716. if (this._point) this._context.lineTo(x, y);
  13717. else this._point = 1, this._context.moveTo(x, y);
  13718. }
  13719. };
  13720. function linearClosed(context) {
  13721. return new LinearClosed(context);
  13722. }
  13723. function sign$1(x) {
  13724. return x < 0 ? -1 : 1;
  13725. }
  13726. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  13727. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  13728. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  13729. // NOV(II), P. 443, 1990.
  13730. function slope3(that, x2, y2) {
  13731. var h0 = that._x1 - that._x0,
  13732. h1 = x2 - that._x1,
  13733. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  13734. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  13735. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  13736. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  13737. }
  13738. // Calculate a one-sided slope.
  13739. function slope2(that, t) {
  13740. var h = that._x1 - that._x0;
  13741. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  13742. }
  13743. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  13744. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  13745. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  13746. function point$5(that, t0, t1) {
  13747. var x0 = that._x0,
  13748. y0 = that._y0,
  13749. x1 = that._x1,
  13750. y1 = that._y1,
  13751. dx = (x1 - x0) / 3;
  13752. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  13753. }
  13754. function MonotoneX(context) {
  13755. this._context = context;
  13756. }
  13757. MonotoneX.prototype = {
  13758. areaStart: function() {
  13759. this._line = 0;
  13760. },
  13761. areaEnd: function() {
  13762. this._line = NaN;
  13763. },
  13764. lineStart: function() {
  13765. this._x0 = this._x1 =
  13766. this._y0 = this._y1 =
  13767. this._t0 = NaN;
  13768. this._point = 0;
  13769. },
  13770. lineEnd: function() {
  13771. switch (this._point) {
  13772. case 2: this._context.lineTo(this._x1, this._y1); break;
  13773. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  13774. }
  13775. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13776. this._line = 1 - this._line;
  13777. },
  13778. point: function(x, y) {
  13779. var t1 = NaN;
  13780. x = +x, y = +y;
  13781. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  13782. switch (this._point) {
  13783. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13784. case 1: this._point = 2; break;
  13785. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  13786. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  13787. }
  13788. this._x0 = this._x1, this._x1 = x;
  13789. this._y0 = this._y1, this._y1 = y;
  13790. this._t0 = t1;
  13791. }
  13792. };
  13793. function MonotoneY(context) {
  13794. this._context = new ReflectContext(context);
  13795. }
  13796. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  13797. MonotoneX.prototype.point.call(this, y, x);
  13798. };
  13799. function ReflectContext(context) {
  13800. this._context = context;
  13801. }
  13802. ReflectContext.prototype = {
  13803. moveTo: function(x, y) { this._context.moveTo(y, x); },
  13804. closePath: function() { this._context.closePath(); },
  13805. lineTo: function(x, y) { this._context.lineTo(y, x); },
  13806. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  13807. };
  13808. function monotoneX(context) {
  13809. return new MonotoneX(context);
  13810. }
  13811. function monotoneY(context) {
  13812. return new MonotoneY(context);
  13813. }
  13814. function Natural(context) {
  13815. this._context = context;
  13816. }
  13817. Natural.prototype = {
  13818. areaStart: function() {
  13819. this._line = 0;
  13820. },
  13821. areaEnd: function() {
  13822. this._line = NaN;
  13823. },
  13824. lineStart: function() {
  13825. this._x = [];
  13826. this._y = [];
  13827. },
  13828. lineEnd: function() {
  13829. var x = this._x,
  13830. y = this._y,
  13831. n = x.length;
  13832. if (n) {
  13833. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  13834. if (n === 2) {
  13835. this._context.lineTo(x[1], y[1]);
  13836. } else {
  13837. var px = controlPoints(x),
  13838. py = controlPoints(y);
  13839. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  13840. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  13841. }
  13842. }
  13843. }
  13844. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  13845. this._line = 1 - this._line;
  13846. this._x = this._y = null;
  13847. },
  13848. point: function(x, y) {
  13849. this._x.push(+x);
  13850. this._y.push(+y);
  13851. }
  13852. };
  13853. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  13854. function controlPoints(x) {
  13855. var i,
  13856. n = x.length - 1,
  13857. m,
  13858. a = new Array(n),
  13859. b = new Array(n),
  13860. r = new Array(n);
  13861. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  13862. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  13863. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  13864. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  13865. a[n - 1] = r[n - 1] / b[n - 1];
  13866. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  13867. b[n - 1] = (x[n] + a[n - 1]) / 2;
  13868. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  13869. return [a, b];
  13870. }
  13871. function natural(context) {
  13872. return new Natural(context);
  13873. }
  13874. function Step(context, t) {
  13875. this._context = context;
  13876. this._t = t;
  13877. }
  13878. Step.prototype = {
  13879. areaStart: function() {
  13880. this._line = 0;
  13881. },
  13882. areaEnd: function() {
  13883. this._line = NaN;
  13884. },
  13885. lineStart: function() {
  13886. this._x = this._y = NaN;
  13887. this._point = 0;
  13888. },
  13889. lineEnd: function() {
  13890. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  13891. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13892. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  13893. },
  13894. point: function(x, y) {
  13895. x = +x, y = +y;
  13896. switch (this._point) {
  13897. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13898. case 1: this._point = 2; // proceed
  13899. default: {
  13900. if (this._t <= 0) {
  13901. this._context.lineTo(this._x, y);
  13902. this._context.lineTo(x, y);
  13903. } else {
  13904. var x1 = this._x * (1 - this._t) + x * this._t;
  13905. this._context.lineTo(x1, this._y);
  13906. this._context.lineTo(x1, y);
  13907. }
  13908. break;
  13909. }
  13910. }
  13911. this._x = x, this._y = y;
  13912. }
  13913. };
  13914. function step(context) {
  13915. return new Step(context, 0.5);
  13916. }
  13917. function stepBefore(context) {
  13918. return new Step(context, 0);
  13919. }
  13920. function stepAfter(context) {
  13921. return new Step(context, 1);
  13922. }
  13923. function none$1(series, order) {
  13924. if (!((n = series.length) > 1)) return;
  13925. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  13926. s0 = s1, s1 = series[order[i]];
  13927. for (j = 0; j < m; ++j) {
  13928. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  13929. }
  13930. }
  13931. }
  13932. function none$2(series) {
  13933. var n = series.length, o = new Array(n);
  13934. while (--n >= 0) o[n] = n;
  13935. return o;
  13936. }
  13937. function stackValue(d, key) {
  13938. return d[key];
  13939. }
  13940. function stack() {
  13941. var keys = constant$b([]),
  13942. order = none$2,
  13943. offset = none$1,
  13944. value = stackValue;
  13945. function stack(data) {
  13946. var kz = keys.apply(this, arguments),
  13947. i,
  13948. m = data.length,
  13949. n = kz.length,
  13950. sz = new Array(n),
  13951. oz;
  13952. for (i = 0; i < n; ++i) {
  13953. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  13954. si[j] = sij = [0, +value(data[j], ki, j, data)];
  13955. sij.data = data[j];
  13956. }
  13957. si.key = ki;
  13958. }
  13959. for (i = 0, oz = order(sz); i < n; ++i) {
  13960. sz[oz[i]].index = i;
  13961. }
  13962. offset(sz, oz);
  13963. return sz;
  13964. }
  13965. stack.keys = function(_) {
  13966. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : keys;
  13967. };
  13968. stack.value = function(_) {
  13969. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), stack) : value;
  13970. };
  13971. stack.order = function(_) {
  13972. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : order;
  13973. };
  13974. stack.offset = function(_) {
  13975. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  13976. };
  13977. return stack;
  13978. }
  13979. function expand(series, order) {
  13980. if (!((n = series.length) > 0)) return;
  13981. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  13982. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  13983. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  13984. }
  13985. none$1(series, order);
  13986. }
  13987. function diverging$1(series, order) {
  13988. if (!((n = series.length) > 0)) return;
  13989. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  13990. for (yp = yn = 0, i = 0; i < n; ++i) {
  13991. if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
  13992. d[0] = yp, d[1] = yp += dy;
  13993. } else if (dy < 0) {
  13994. d[1] = yn, d[0] = yn += dy;
  13995. } else {
  13996. d[0] = 0, d[1] = dy;
  13997. }
  13998. }
  13999. }
  14000. }
  14001. function silhouette(series, order) {
  14002. if (!((n = series.length) > 0)) return;
  14003. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  14004. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  14005. s0[j][1] += s0[j][0] = -y / 2;
  14006. }
  14007. none$1(series, order);
  14008. }
  14009. function wiggle(series, order) {
  14010. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  14011. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  14012. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  14013. var si = series[order[i]],
  14014. sij0 = si[j][1] || 0,
  14015. sij1 = si[j - 1][1] || 0,
  14016. s3 = (sij0 - sij1) / 2;
  14017. for (var k = 0; k < i; ++k) {
  14018. var sk = series[order[k]],
  14019. skj0 = sk[j][1] || 0,
  14020. skj1 = sk[j - 1][1] || 0;
  14021. s3 += skj0 - skj1;
  14022. }
  14023. s1 += sij0, s2 += s3 * sij0;
  14024. }
  14025. s0[j - 1][1] += s0[j - 1][0] = y;
  14026. if (s1) y -= s2 / s1;
  14027. }
  14028. s0[j - 1][1] += s0[j - 1][0] = y;
  14029. none$1(series, order);
  14030. }
  14031. function appearance(series) {
  14032. var peaks = series.map(peak);
  14033. return none$2(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
  14034. }
  14035. function peak(series) {
  14036. var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
  14037. while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
  14038. return j;
  14039. }
  14040. function ascending$3(series) {
  14041. var sums = series.map(sum$2);
  14042. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  14043. }
  14044. function sum$2(series) {
  14045. var s = 0, i = -1, n = series.length, v;
  14046. while (++i < n) if (v = +series[i][1]) s += v;
  14047. return s;
  14048. }
  14049. function descending$2(series) {
  14050. return ascending$3(series).reverse();
  14051. }
  14052. function insideOut(series) {
  14053. var n = series.length,
  14054. i,
  14055. j,
  14056. sums = series.map(sum$2),
  14057. order = appearance(series),
  14058. top = 0,
  14059. bottom = 0,
  14060. tops = [],
  14061. bottoms = [];
  14062. for (i = 0; i < n; ++i) {
  14063. j = order[i];
  14064. if (top < bottom) {
  14065. top += sums[j];
  14066. tops.push(j);
  14067. } else {
  14068. bottom += sums[j];
  14069. bottoms.push(j);
  14070. }
  14071. }
  14072. return bottoms.reverse().concat(tops);
  14073. }
  14074. function reverse(series) {
  14075. return none$2(series).reverse();
  14076. }
  14077. function constant$c(x) {
  14078. return function() {
  14079. return x;
  14080. };
  14081. }
  14082. function x$4(d) {
  14083. return d[0];
  14084. }
  14085. function y$4(d) {
  14086. return d[1];
  14087. }
  14088. function RedBlackTree() {
  14089. this._ = null; // root node
  14090. }
  14091. function RedBlackNode(node) {
  14092. node.U = // parent node
  14093. node.C = // color - true for red, false for black
  14094. node.L = // left node
  14095. node.R = // right node
  14096. node.P = // previous node
  14097. node.N = null; // next node
  14098. }
  14099. RedBlackTree.prototype = {
  14100. constructor: RedBlackTree,
  14101. insert: function(after, node) {
  14102. var parent, grandpa, uncle;
  14103. if (after) {
  14104. node.P = after;
  14105. node.N = after.N;
  14106. if (after.N) after.N.P = node;
  14107. after.N = node;
  14108. if (after.R) {
  14109. after = after.R;
  14110. while (after.L) after = after.L;
  14111. after.L = node;
  14112. } else {
  14113. after.R = node;
  14114. }
  14115. parent = after;
  14116. } else if (this._) {
  14117. after = RedBlackFirst(this._);
  14118. node.P = null;
  14119. node.N = after;
  14120. after.P = after.L = node;
  14121. parent = after;
  14122. } else {
  14123. node.P = node.N = null;
  14124. this._ = node;
  14125. parent = null;
  14126. }
  14127. node.L = node.R = null;
  14128. node.U = parent;
  14129. node.C = true;
  14130. after = node;
  14131. while (parent && parent.C) {
  14132. grandpa = parent.U;
  14133. if (parent === grandpa.L) {
  14134. uncle = grandpa.R;
  14135. if (uncle && uncle.C) {
  14136. parent.C = uncle.C = false;
  14137. grandpa.C = true;
  14138. after = grandpa;
  14139. } else {
  14140. if (after === parent.R) {
  14141. RedBlackRotateLeft(this, parent);
  14142. after = parent;
  14143. parent = after.U;
  14144. }
  14145. parent.C = false;
  14146. grandpa.C = true;
  14147. RedBlackRotateRight(this, grandpa);
  14148. }
  14149. } else {
  14150. uncle = grandpa.L;
  14151. if (uncle && uncle.C) {
  14152. parent.C = uncle.C = false;
  14153. grandpa.C = true;
  14154. after = grandpa;
  14155. } else {
  14156. if (after === parent.L) {
  14157. RedBlackRotateRight(this, parent);
  14158. after = parent;
  14159. parent = after.U;
  14160. }
  14161. parent.C = false;
  14162. grandpa.C = true;
  14163. RedBlackRotateLeft(this, grandpa);
  14164. }
  14165. }
  14166. parent = after.U;
  14167. }
  14168. this._.C = false;
  14169. },
  14170. remove: function(node) {
  14171. if (node.N) node.N.P = node.P;
  14172. if (node.P) node.P.N = node.N;
  14173. node.N = node.P = null;
  14174. var parent = node.U,
  14175. sibling,
  14176. left = node.L,
  14177. right = node.R,
  14178. next,
  14179. red;
  14180. if (!left) next = right;
  14181. else if (!right) next = left;
  14182. else next = RedBlackFirst(right);
  14183. if (parent) {
  14184. if (parent.L === node) parent.L = next;
  14185. else parent.R = next;
  14186. } else {
  14187. this._ = next;
  14188. }
  14189. if (left && right) {
  14190. red = next.C;
  14191. next.C = node.C;
  14192. next.L = left;
  14193. left.U = next;
  14194. if (next !== right) {
  14195. parent = next.U;
  14196. next.U = node.U;
  14197. node = next.R;
  14198. parent.L = node;
  14199. next.R = right;
  14200. right.U = next;
  14201. } else {
  14202. next.U = parent;
  14203. parent = next;
  14204. node = next.R;
  14205. }
  14206. } else {
  14207. red = node.C;
  14208. node = next;
  14209. }
  14210. if (node) node.U = parent;
  14211. if (red) return;
  14212. if (node && node.C) { node.C = false; return; }
  14213. do {
  14214. if (node === this._) break;
  14215. if (node === parent.L) {
  14216. sibling = parent.R;
  14217. if (sibling.C) {
  14218. sibling.C = false;
  14219. parent.C = true;
  14220. RedBlackRotateLeft(this, parent);
  14221. sibling = parent.R;
  14222. }
  14223. if ((sibling.L && sibling.L.C)
  14224. || (sibling.R && sibling.R.C)) {
  14225. if (!sibling.R || !sibling.R.C) {
  14226. sibling.L.C = false;
  14227. sibling.C = true;
  14228. RedBlackRotateRight(this, sibling);
  14229. sibling = parent.R;
  14230. }
  14231. sibling.C = parent.C;
  14232. parent.C = sibling.R.C = false;
  14233. RedBlackRotateLeft(this, parent);
  14234. node = this._;
  14235. break;
  14236. }
  14237. } else {
  14238. sibling = parent.L;
  14239. if (sibling.C) {
  14240. sibling.C = false;
  14241. parent.C = true;
  14242. RedBlackRotateRight(this, parent);
  14243. sibling = parent.L;
  14244. }
  14245. if ((sibling.L && sibling.L.C)
  14246. || (sibling.R && sibling.R.C)) {
  14247. if (!sibling.L || !sibling.L.C) {
  14248. sibling.R.C = false;
  14249. sibling.C = true;
  14250. RedBlackRotateLeft(this, sibling);
  14251. sibling = parent.L;
  14252. }
  14253. sibling.C = parent.C;
  14254. parent.C = sibling.L.C = false;
  14255. RedBlackRotateRight(this, parent);
  14256. node = this._;
  14257. break;
  14258. }
  14259. }
  14260. sibling.C = true;
  14261. node = parent;
  14262. parent = parent.U;
  14263. } while (!node.C);
  14264. if (node) node.C = false;
  14265. }
  14266. };
  14267. function RedBlackRotateLeft(tree, node) {
  14268. var p = node,
  14269. q = node.R,
  14270. parent = p.U;
  14271. if (parent) {
  14272. if (parent.L === p) parent.L = q;
  14273. else parent.R = q;
  14274. } else {
  14275. tree._ = q;
  14276. }
  14277. q.U = parent;
  14278. p.U = q;
  14279. p.R = q.L;
  14280. if (p.R) p.R.U = p;
  14281. q.L = p;
  14282. }
  14283. function RedBlackRotateRight(tree, node) {
  14284. var p = node,
  14285. q = node.L,
  14286. parent = p.U;
  14287. if (parent) {
  14288. if (parent.L === p) parent.L = q;
  14289. else parent.R = q;
  14290. } else {
  14291. tree._ = q;
  14292. }
  14293. q.U = parent;
  14294. p.U = q;
  14295. p.L = q.R;
  14296. if (p.L) p.L.U = p;
  14297. q.R = p;
  14298. }
  14299. function RedBlackFirst(node) {
  14300. while (node.L) node = node.L;
  14301. return node;
  14302. }
  14303. function createEdge(left, right, v0, v1) {
  14304. var edge = [null, null],
  14305. index = edges.push(edge) - 1;
  14306. edge.left = left;
  14307. edge.right = right;
  14308. if (v0) setEdgeEnd(edge, left, right, v0);
  14309. if (v1) setEdgeEnd(edge, right, left, v1);
  14310. cells[left.index].halfedges.push(index);
  14311. cells[right.index].halfedges.push(index);
  14312. return edge;
  14313. }
  14314. function createBorderEdge(left, v0, v1) {
  14315. var edge = [v0, v1];
  14316. edge.left = left;
  14317. return edge;
  14318. }
  14319. function setEdgeEnd(edge, left, right, vertex) {
  14320. if (!edge[0] && !edge[1]) {
  14321. edge[0] = vertex;
  14322. edge.left = left;
  14323. edge.right = right;
  14324. } else if (edge.left === right) {
  14325. edge[1] = vertex;
  14326. } else {
  14327. edge[0] = vertex;
  14328. }
  14329. }
  14330. // Liang–Barsky line clipping.
  14331. function clipEdge(edge, x0, y0, x1, y1) {
  14332. var a = edge[0],
  14333. b = edge[1],
  14334. ax = a[0],
  14335. ay = a[1],
  14336. bx = b[0],
  14337. by = b[1],
  14338. t0 = 0,
  14339. t1 = 1,
  14340. dx = bx - ax,
  14341. dy = by - ay,
  14342. r;
  14343. r = x0 - ax;
  14344. if (!dx && r > 0) return;
  14345. r /= dx;
  14346. if (dx < 0) {
  14347. if (r < t0) return;
  14348. if (r < t1) t1 = r;
  14349. } else if (dx > 0) {
  14350. if (r > t1) return;
  14351. if (r > t0) t0 = r;
  14352. }
  14353. r = x1 - ax;
  14354. if (!dx && r < 0) return;
  14355. r /= dx;
  14356. if (dx < 0) {
  14357. if (r > t1) return;
  14358. if (r > t0) t0 = r;
  14359. } else if (dx > 0) {
  14360. if (r < t0) return;
  14361. if (r < t1) t1 = r;
  14362. }
  14363. r = y0 - ay;
  14364. if (!dy && r > 0) return;
  14365. r /= dy;
  14366. if (dy < 0) {
  14367. if (r < t0) return;
  14368. if (r < t1) t1 = r;
  14369. } else if (dy > 0) {
  14370. if (r > t1) return;
  14371. if (r > t0) t0 = r;
  14372. }
  14373. r = y1 - ay;
  14374. if (!dy && r < 0) return;
  14375. r /= dy;
  14376. if (dy < 0) {
  14377. if (r > t1) return;
  14378. if (r > t0) t0 = r;
  14379. } else if (dy > 0) {
  14380. if (r < t0) return;
  14381. if (r < t1) t1 = r;
  14382. }
  14383. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  14384. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  14385. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  14386. return true;
  14387. }
  14388. function connectEdge(edge, x0, y0, x1, y1) {
  14389. var v1 = edge[1];
  14390. if (v1) return true;
  14391. var v0 = edge[0],
  14392. left = edge.left,
  14393. right = edge.right,
  14394. lx = left[0],
  14395. ly = left[1],
  14396. rx = right[0],
  14397. ry = right[1],
  14398. fx = (lx + rx) / 2,
  14399. fy = (ly + ry) / 2,
  14400. fm,
  14401. fb;
  14402. if (ry === ly) {
  14403. if (fx < x0 || fx >= x1) return;
  14404. if (lx > rx) {
  14405. if (!v0) v0 = [fx, y0];
  14406. else if (v0[1] >= y1) return;
  14407. v1 = [fx, y1];
  14408. } else {
  14409. if (!v0) v0 = [fx, y1];
  14410. else if (v0[1] < y0) return;
  14411. v1 = [fx, y0];
  14412. }
  14413. } else {
  14414. fm = (lx - rx) / (ry - ly);
  14415. fb = fy - fm * fx;
  14416. if (fm < -1 || fm > 1) {
  14417. if (lx > rx) {
  14418. if (!v0) v0 = [(y0 - fb) / fm, y0];
  14419. else if (v0[1] >= y1) return;
  14420. v1 = [(y1 - fb) / fm, y1];
  14421. } else {
  14422. if (!v0) v0 = [(y1 - fb) / fm, y1];
  14423. else if (v0[1] < y0) return;
  14424. v1 = [(y0 - fb) / fm, y0];
  14425. }
  14426. } else {
  14427. if (ly < ry) {
  14428. if (!v0) v0 = [x0, fm * x0 + fb];
  14429. else if (v0[0] >= x1) return;
  14430. v1 = [x1, fm * x1 + fb];
  14431. } else {
  14432. if (!v0) v0 = [x1, fm * x1 + fb];
  14433. else if (v0[0] < x0) return;
  14434. v1 = [x0, fm * x0 + fb];
  14435. }
  14436. }
  14437. }
  14438. edge[0] = v0;
  14439. edge[1] = v1;
  14440. return true;
  14441. }
  14442. function clipEdges(x0, y0, x1, y1) {
  14443. var i = edges.length,
  14444. edge;
  14445. while (i--) {
  14446. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  14447. || !clipEdge(edge, x0, y0, x1, y1)
  14448. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  14449. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  14450. delete edges[i];
  14451. }
  14452. }
  14453. }
  14454. function createCell(site) {
  14455. return cells[site.index] = {
  14456. site: site,
  14457. halfedges: []
  14458. };
  14459. }
  14460. function cellHalfedgeAngle(cell, edge) {
  14461. var site = cell.site,
  14462. va = edge.left,
  14463. vb = edge.right;
  14464. if (site === vb) vb = va, va = site;
  14465. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  14466. if (site === va) va = edge[1], vb = edge[0];
  14467. else va = edge[0], vb = edge[1];
  14468. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  14469. }
  14470. function cellHalfedgeStart(cell, edge) {
  14471. return edge[+(edge.left !== cell.site)];
  14472. }
  14473. function cellHalfedgeEnd(cell, edge) {
  14474. return edge[+(edge.left === cell.site)];
  14475. }
  14476. function sortCellHalfedges() {
  14477. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  14478. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  14479. var index = new Array(m),
  14480. array = new Array(m);
  14481. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  14482. index.sort(function(i, j) { return array[j] - array[i]; });
  14483. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  14484. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  14485. }
  14486. }
  14487. }
  14488. function clipCells(x0, y0, x1, y1) {
  14489. var nCells = cells.length,
  14490. iCell,
  14491. cell,
  14492. site,
  14493. iHalfedge,
  14494. halfedges,
  14495. nHalfedges,
  14496. start,
  14497. startX,
  14498. startY,
  14499. end,
  14500. endX,
  14501. endY,
  14502. cover = true;
  14503. for (iCell = 0; iCell < nCells; ++iCell) {
  14504. if (cell = cells[iCell]) {
  14505. site = cell.site;
  14506. halfedges = cell.halfedges;
  14507. iHalfedge = halfedges.length;
  14508. // Remove any dangling clipped edges.
  14509. while (iHalfedge--) {
  14510. if (!edges[halfedges[iHalfedge]]) {
  14511. halfedges.splice(iHalfedge, 1);
  14512. }
  14513. }
  14514. // Insert any border edges as necessary.
  14515. iHalfedge = 0, nHalfedges = halfedges.length;
  14516. while (iHalfedge < nHalfedges) {
  14517. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  14518. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  14519. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  14520. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  14521. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  14522. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  14523. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  14524. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  14525. : null)) - 1);
  14526. ++nHalfedges;
  14527. }
  14528. }
  14529. if (nHalfedges) cover = false;
  14530. }
  14531. }
  14532. // If there weren’t any edges, have the closest site cover the extent.
  14533. // It doesn’t matter which corner of the extent we measure!
  14534. if (cover) {
  14535. var dx, dy, d2, dc = Infinity;
  14536. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  14537. if (cell = cells[iCell]) {
  14538. site = cell.site;
  14539. dx = site[0] - x0;
  14540. dy = site[1] - y0;
  14541. d2 = dx * dx + dy * dy;
  14542. if (d2 < dc) dc = d2, cover = cell;
  14543. }
  14544. }
  14545. if (cover) {
  14546. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  14547. cover.halfedges.push(
  14548. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  14549. edges.push(createBorderEdge(site, v01, v11)) - 1,
  14550. edges.push(createBorderEdge(site, v11, v10)) - 1,
  14551. edges.push(createBorderEdge(site, v10, v00)) - 1
  14552. );
  14553. }
  14554. }
  14555. // Lastly delete any cells with no edges; these were entirely clipped.
  14556. for (iCell = 0; iCell < nCells; ++iCell) {
  14557. if (cell = cells[iCell]) {
  14558. if (!cell.halfedges.length) {
  14559. delete cells[iCell];
  14560. }
  14561. }
  14562. }
  14563. }
  14564. var circlePool = [];
  14565. var firstCircle;
  14566. function Circle() {
  14567. RedBlackNode(this);
  14568. this.x =
  14569. this.y =
  14570. this.arc =
  14571. this.site =
  14572. this.cy = null;
  14573. }
  14574. function attachCircle(arc) {
  14575. var lArc = arc.P,
  14576. rArc = arc.N;
  14577. if (!lArc || !rArc) return;
  14578. var lSite = lArc.site,
  14579. cSite = arc.site,
  14580. rSite = rArc.site;
  14581. if (lSite === rSite) return;
  14582. var bx = cSite[0],
  14583. by = cSite[1],
  14584. ax = lSite[0] - bx,
  14585. ay = lSite[1] - by,
  14586. cx = rSite[0] - bx,
  14587. cy = rSite[1] - by;
  14588. var d = 2 * (ax * cy - ay * cx);
  14589. if (d >= -epsilon2$2) return;
  14590. var ha = ax * ax + ay * ay,
  14591. hc = cx * cx + cy * cy,
  14592. x = (cy * ha - ay * hc) / d,
  14593. y = (ax * hc - cx * ha) / d;
  14594. var circle = circlePool.pop() || new Circle;
  14595. circle.arc = arc;
  14596. circle.site = cSite;
  14597. circle.x = x + bx;
  14598. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  14599. arc.circle = circle;
  14600. var before = null,
  14601. node = circles._;
  14602. while (node) {
  14603. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  14604. if (node.L) node = node.L;
  14605. else { before = node.P; break; }
  14606. } else {
  14607. if (node.R) node = node.R;
  14608. else { before = node; break; }
  14609. }
  14610. }
  14611. circles.insert(before, circle);
  14612. if (!before) firstCircle = circle;
  14613. }
  14614. function detachCircle(arc) {
  14615. var circle = arc.circle;
  14616. if (circle) {
  14617. if (!circle.P) firstCircle = circle.N;
  14618. circles.remove(circle);
  14619. circlePool.push(circle);
  14620. RedBlackNode(circle);
  14621. arc.circle = null;
  14622. }
  14623. }
  14624. var beachPool = [];
  14625. function Beach() {
  14626. RedBlackNode(this);
  14627. this.edge =
  14628. this.site =
  14629. this.circle = null;
  14630. }
  14631. function createBeach(site) {
  14632. var beach = beachPool.pop() || new Beach;
  14633. beach.site = site;
  14634. return beach;
  14635. }
  14636. function detachBeach(beach) {
  14637. detachCircle(beach);
  14638. beaches.remove(beach);
  14639. beachPool.push(beach);
  14640. RedBlackNode(beach);
  14641. }
  14642. function removeBeach(beach) {
  14643. var circle = beach.circle,
  14644. x = circle.x,
  14645. y = circle.cy,
  14646. vertex = [x, y],
  14647. previous = beach.P,
  14648. next = beach.N,
  14649. disappearing = [beach];
  14650. detachBeach(beach);
  14651. var lArc = previous;
  14652. while (lArc.circle
  14653. && Math.abs(x - lArc.circle.x) < epsilon$4
  14654. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  14655. previous = lArc.P;
  14656. disappearing.unshift(lArc);
  14657. detachBeach(lArc);
  14658. lArc = previous;
  14659. }
  14660. disappearing.unshift(lArc);
  14661. detachCircle(lArc);
  14662. var rArc = next;
  14663. while (rArc.circle
  14664. && Math.abs(x - rArc.circle.x) < epsilon$4
  14665. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  14666. next = rArc.N;
  14667. disappearing.push(rArc);
  14668. detachBeach(rArc);
  14669. rArc = next;
  14670. }
  14671. disappearing.push(rArc);
  14672. detachCircle(rArc);
  14673. var nArcs = disappearing.length,
  14674. iArc;
  14675. for (iArc = 1; iArc < nArcs; ++iArc) {
  14676. rArc = disappearing[iArc];
  14677. lArc = disappearing[iArc - 1];
  14678. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  14679. }
  14680. lArc = disappearing[0];
  14681. rArc = disappearing[nArcs - 1];
  14682. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  14683. attachCircle(lArc);
  14684. attachCircle(rArc);
  14685. }
  14686. function addBeach(site) {
  14687. var x = site[0],
  14688. directrix = site[1],
  14689. lArc,
  14690. rArc,
  14691. dxl,
  14692. dxr,
  14693. node = beaches._;
  14694. while (node) {
  14695. dxl = leftBreakPoint(node, directrix) - x;
  14696. if (dxl > epsilon$4) node = node.L; else {
  14697. dxr = x - rightBreakPoint(node, directrix);
  14698. if (dxr > epsilon$4) {
  14699. if (!node.R) {
  14700. lArc = node;
  14701. break;
  14702. }
  14703. node = node.R;
  14704. } else {
  14705. if (dxl > -epsilon$4) {
  14706. lArc = node.P;
  14707. rArc = node;
  14708. } else if (dxr > -epsilon$4) {
  14709. lArc = node;
  14710. rArc = node.N;
  14711. } else {
  14712. lArc = rArc = node;
  14713. }
  14714. break;
  14715. }
  14716. }
  14717. }
  14718. createCell(site);
  14719. var newArc = createBeach(site);
  14720. beaches.insert(lArc, newArc);
  14721. if (!lArc && !rArc) return;
  14722. if (lArc === rArc) {
  14723. detachCircle(lArc);
  14724. rArc = createBeach(lArc.site);
  14725. beaches.insert(newArc, rArc);
  14726. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  14727. attachCircle(lArc);
  14728. attachCircle(rArc);
  14729. return;
  14730. }
  14731. if (!rArc) { // && lArc
  14732. newArc.edge = createEdge(lArc.site, newArc.site);
  14733. return;
  14734. }
  14735. // else lArc !== rArc
  14736. detachCircle(lArc);
  14737. detachCircle(rArc);
  14738. var lSite = lArc.site,
  14739. ax = lSite[0],
  14740. ay = lSite[1],
  14741. bx = site[0] - ax,
  14742. by = site[1] - ay,
  14743. rSite = rArc.site,
  14744. cx = rSite[0] - ax,
  14745. cy = rSite[1] - ay,
  14746. d = 2 * (bx * cy - by * cx),
  14747. hb = bx * bx + by * by,
  14748. hc = cx * cx + cy * cy,
  14749. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  14750. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  14751. newArc.edge = createEdge(lSite, site, null, vertex);
  14752. rArc.edge = createEdge(site, rSite, null, vertex);
  14753. attachCircle(lArc);
  14754. attachCircle(rArc);
  14755. }
  14756. function leftBreakPoint(arc, directrix) {
  14757. var site = arc.site,
  14758. rfocx = site[0],
  14759. rfocy = site[1],
  14760. pby2 = rfocy - directrix;
  14761. if (!pby2) return rfocx;
  14762. var lArc = arc.P;
  14763. if (!lArc) return -Infinity;
  14764. site = lArc.site;
  14765. var lfocx = site[0],
  14766. lfocy = site[1],
  14767. plby2 = lfocy - directrix;
  14768. if (!plby2) return lfocx;
  14769. var hl = lfocx - rfocx,
  14770. aby2 = 1 / pby2 - 1 / plby2,
  14771. b = hl / plby2;
  14772. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  14773. return (rfocx + lfocx) / 2;
  14774. }
  14775. function rightBreakPoint(arc, directrix) {
  14776. var rArc = arc.N;
  14777. if (rArc) return leftBreakPoint(rArc, directrix);
  14778. var site = arc.site;
  14779. return site[1] === directrix ? site[0] : Infinity;
  14780. }
  14781. var epsilon$4 = 1e-6;
  14782. var epsilon2$2 = 1e-12;
  14783. var beaches;
  14784. var cells;
  14785. var circles;
  14786. var edges;
  14787. function triangleArea(a, b, c) {
  14788. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  14789. }
  14790. function lexicographic(a, b) {
  14791. return b[1] - a[1]
  14792. || b[0] - a[0];
  14793. }
  14794. function Diagram(sites, extent) {
  14795. var site = sites.sort(lexicographic).pop(),
  14796. x,
  14797. y,
  14798. circle;
  14799. edges = [];
  14800. cells = new Array(sites.length);
  14801. beaches = new RedBlackTree;
  14802. circles = new RedBlackTree;
  14803. while (true) {
  14804. circle = firstCircle;
  14805. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  14806. if (site[0] !== x || site[1] !== y) {
  14807. addBeach(site);
  14808. x = site[0], y = site[1];
  14809. }
  14810. site = sites.pop();
  14811. } else if (circle) {
  14812. removeBeach(circle.arc);
  14813. } else {
  14814. break;
  14815. }
  14816. }
  14817. sortCellHalfedges();
  14818. if (extent) {
  14819. var x0 = +extent[0][0],
  14820. y0 = +extent[0][1],
  14821. x1 = +extent[1][0],
  14822. y1 = +extent[1][1];
  14823. clipEdges(x0, y0, x1, y1);
  14824. clipCells(x0, y0, x1, y1);
  14825. }
  14826. this.edges = edges;
  14827. this.cells = cells;
  14828. beaches =
  14829. circles =
  14830. edges =
  14831. cells = null;
  14832. }
  14833. Diagram.prototype = {
  14834. constructor: Diagram,
  14835. polygons: function() {
  14836. var edges = this.edges;
  14837. return this.cells.map(function(cell) {
  14838. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  14839. polygon.data = cell.site.data;
  14840. return polygon;
  14841. });
  14842. },
  14843. triangles: function() {
  14844. var triangles = [],
  14845. edges = this.edges;
  14846. this.cells.forEach(function(cell, i) {
  14847. if (!(m = (halfedges = cell.halfedges).length)) return;
  14848. var site = cell.site,
  14849. halfedges,
  14850. j = -1,
  14851. m,
  14852. s0,
  14853. e1 = edges[halfedges[m - 1]],
  14854. s1 = e1.left === site ? e1.right : e1.left;
  14855. while (++j < m) {
  14856. s0 = s1;
  14857. e1 = edges[halfedges[j]];
  14858. s1 = e1.left === site ? e1.right : e1.left;
  14859. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  14860. triangles.push([site.data, s0.data, s1.data]);
  14861. }
  14862. }
  14863. });
  14864. return triangles;
  14865. },
  14866. links: function() {
  14867. return this.edges.filter(function(edge) {
  14868. return edge.right;
  14869. }).map(function(edge) {
  14870. return {
  14871. source: edge.left.data,
  14872. target: edge.right.data
  14873. };
  14874. });
  14875. },
  14876. find: function(x, y, radius) {
  14877. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  14878. // Use the previously-found cell, or start with an arbitrary one.
  14879. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  14880. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  14881. // Traverse the half-edges to find a closer cell, if any.
  14882. do {
  14883. cell = that.cells[i0 = i1], i1 = null;
  14884. cell.halfedges.forEach(function(e) {
  14885. var edge = that.edges[e], v = edge.left;
  14886. if ((v === cell.site || !v) && !(v = edge.right)) return;
  14887. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  14888. if (v2 < d2) d2 = v2, i1 = v.index;
  14889. });
  14890. } while (i1 !== null);
  14891. that._found = i0;
  14892. return radius == null || d2 <= radius * radius ? cell.site : null;
  14893. }
  14894. };
  14895. function voronoi() {
  14896. var x = x$4,
  14897. y = y$4,
  14898. extent = null;
  14899. function voronoi(data) {
  14900. return new Diagram(data.map(function(d, i) {
  14901. var s = [Math.round(x(d, i, data) / epsilon$4) * epsilon$4, Math.round(y(d, i, data) / epsilon$4) * epsilon$4];
  14902. s.index = i;
  14903. s.data = d;
  14904. return s;
  14905. }), extent);
  14906. }
  14907. voronoi.polygons = function(data) {
  14908. return voronoi(data).polygons();
  14909. };
  14910. voronoi.links = function(data) {
  14911. return voronoi(data).links();
  14912. };
  14913. voronoi.triangles = function(data) {
  14914. return voronoi(data).triangles();
  14915. };
  14916. voronoi.x = function(_) {
  14917. return arguments.length ? (x = typeof _ === "function" ? _ : constant$c(+_), voronoi) : x;
  14918. };
  14919. voronoi.y = function(_) {
  14920. return arguments.length ? (y = typeof _ === "function" ? _ : constant$c(+_), voronoi) : y;
  14921. };
  14922. voronoi.extent = function(_) {
  14923. return arguments.length ? (extent = _ == null ? null : [[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]], voronoi) : extent && [[extent[0][0], extent[0][1]], [extent[1][0], extent[1][1]]];
  14924. };
  14925. voronoi.size = function(_) {
  14926. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  14927. };
  14928. return voronoi;
  14929. }
  14930. function constant$d(x) {
  14931. return function() {
  14932. return x;
  14933. };
  14934. }
  14935. function ZoomEvent(target, type, transform) {
  14936. this.target = target;
  14937. this.type = type;
  14938. this.transform = transform;
  14939. }
  14940. function Transform(k, x, y) {
  14941. this.k = k;
  14942. this.x = x;
  14943. this.y = y;
  14944. }
  14945. Transform.prototype = {
  14946. constructor: Transform,
  14947. scale: function(k) {
  14948. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  14949. },
  14950. translate: function(x, y) {
  14951. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  14952. },
  14953. apply: function(point) {
  14954. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  14955. },
  14956. applyX: function(x) {
  14957. return x * this.k + this.x;
  14958. },
  14959. applyY: function(y) {
  14960. return y * this.k + this.y;
  14961. },
  14962. invert: function(location) {
  14963. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  14964. },
  14965. invertX: function(x) {
  14966. return (x - this.x) / this.k;
  14967. },
  14968. invertY: function(y) {
  14969. return (y - this.y) / this.k;
  14970. },
  14971. rescaleX: function(x) {
  14972. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  14973. },
  14974. rescaleY: function(y) {
  14975. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  14976. },
  14977. toString: function() {
  14978. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  14979. }
  14980. };
  14981. var identity$9 = new Transform(1, 0, 0);
  14982. transform$1.prototype = Transform.prototype;
  14983. function transform$1(node) {
  14984. while (!node.__zoom) if (!(node = node.parentNode)) return identity$9;
  14985. return node.__zoom;
  14986. }
  14987. function nopropagation$2() {
  14988. exports.event.stopImmediatePropagation();
  14989. }
  14990. function noevent$2() {
  14991. exports.event.preventDefault();
  14992. exports.event.stopImmediatePropagation();
  14993. }
  14994. // Ignore right-click, since that should open the context menu.
  14995. function defaultFilter$2() {
  14996. return !exports.event.ctrlKey && !exports.event.button;
  14997. }
  14998. function defaultExtent$1() {
  14999. var e = this;
  15000. if (e instanceof SVGElement) {
  15001. e = e.ownerSVGElement || e;
  15002. if (e.hasAttribute("viewBox")) {
  15003. e = e.viewBox.baseVal;
  15004. return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
  15005. }
  15006. return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
  15007. }
  15008. return [[0, 0], [e.clientWidth, e.clientHeight]];
  15009. }
  15010. function defaultTransform() {
  15011. return this.__zoom || identity$9;
  15012. }
  15013. function defaultWheelDelta() {
  15014. return -exports.event.deltaY * (exports.event.deltaMode === 1 ? 0.05 : exports.event.deltaMode ? 1 : 0.002);
  15015. }
  15016. function defaultTouchable$2() {
  15017. return navigator.maxTouchPoints || ("ontouchstart" in this);
  15018. }
  15019. function defaultConstrain(transform, extent, translateExtent) {
  15020. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  15021. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  15022. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  15023. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  15024. return transform.translate(
  15025. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  15026. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  15027. );
  15028. }
  15029. function zoom() {
  15030. var filter = defaultFilter$2,
  15031. extent = defaultExtent$1,
  15032. constrain = defaultConstrain,
  15033. wheelDelta = defaultWheelDelta,
  15034. touchable = defaultTouchable$2,
  15035. scaleExtent = [0, Infinity],
  15036. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  15037. duration = 250,
  15038. interpolate = interpolateZoom,
  15039. listeners = dispatch("start", "zoom", "end"),
  15040. touchstarting,
  15041. touchending,
  15042. touchDelay = 500,
  15043. wheelDelay = 150,
  15044. clickDistance2 = 0;
  15045. function zoom(selection) {
  15046. selection
  15047. .property("__zoom", defaultTransform)
  15048. .on("wheel.zoom", wheeled)
  15049. .on("mousedown.zoom", mousedowned)
  15050. .on("dblclick.zoom", dblclicked)
  15051. .filter(touchable)
  15052. .on("touchstart.zoom", touchstarted)
  15053. .on("touchmove.zoom", touchmoved)
  15054. .on("touchend.zoom touchcancel.zoom", touchended)
  15055. .style("touch-action", "none")
  15056. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  15057. }
  15058. zoom.transform = function(collection, transform, point) {
  15059. var selection = collection.selection ? collection.selection() : collection;
  15060. selection.property("__zoom", defaultTransform);
  15061. if (collection !== selection) {
  15062. schedule(collection, transform, point);
  15063. } else {
  15064. selection.interrupt().each(function() {
  15065. gesture(this, arguments)
  15066. .start()
  15067. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  15068. .end();
  15069. });
  15070. }
  15071. };
  15072. zoom.scaleBy = function(selection, k, p) {
  15073. zoom.scaleTo(selection, function() {
  15074. var k0 = this.__zoom.k,
  15075. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  15076. return k0 * k1;
  15077. }, p);
  15078. };
  15079. zoom.scaleTo = function(selection, k, p) {
  15080. zoom.transform(selection, function() {
  15081. var e = extent.apply(this, arguments),
  15082. t0 = this.__zoom,
  15083. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
  15084. p1 = t0.invert(p0),
  15085. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  15086. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  15087. }, p);
  15088. };
  15089. zoom.translateBy = function(selection, x, y) {
  15090. zoom.transform(selection, function() {
  15091. return constrain(this.__zoom.translate(
  15092. typeof x === "function" ? x.apply(this, arguments) : x,
  15093. typeof y === "function" ? y.apply(this, arguments) : y
  15094. ), extent.apply(this, arguments), translateExtent);
  15095. });
  15096. };
  15097. zoom.translateTo = function(selection, x, y, p) {
  15098. zoom.transform(selection, function() {
  15099. var e = extent.apply(this, arguments),
  15100. t = this.__zoom,
  15101. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
  15102. return constrain(identity$9.translate(p0[0], p0[1]).scale(t.k).translate(
  15103. typeof x === "function" ? -x.apply(this, arguments) : -x,
  15104. typeof y === "function" ? -y.apply(this, arguments) : -y
  15105. ), e, translateExtent);
  15106. }, p);
  15107. };
  15108. function scale(transform, k) {
  15109. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  15110. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  15111. }
  15112. function translate(transform, p0, p1) {
  15113. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  15114. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  15115. }
  15116. function centroid(extent) {
  15117. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  15118. }
  15119. function schedule(transition, transform, point) {
  15120. transition
  15121. .on("start.zoom", function() { gesture(this, arguments).start(); })
  15122. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  15123. .tween("zoom", function() {
  15124. var that = this,
  15125. args = arguments,
  15126. g = gesture(that, args),
  15127. e = extent.apply(that, args),
  15128. p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
  15129. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  15130. a = that.__zoom,
  15131. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  15132. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  15133. return function(t) {
  15134. if (t === 1) t = b; // Avoid rounding error on end.
  15135. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  15136. g.zoom(null, t);
  15137. };
  15138. });
  15139. }
  15140. function gesture(that, args, clean) {
  15141. return (!clean && that.__zooming) || new Gesture(that, args);
  15142. }
  15143. function Gesture(that, args) {
  15144. this.that = that;
  15145. this.args = args;
  15146. this.active = 0;
  15147. this.extent = extent.apply(that, args);
  15148. this.taps = 0;
  15149. }
  15150. Gesture.prototype = {
  15151. start: function() {
  15152. if (++this.active === 1) {
  15153. this.that.__zooming = this;
  15154. this.emit("start");
  15155. }
  15156. return this;
  15157. },
  15158. zoom: function(key, transform) {
  15159. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  15160. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  15161. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  15162. this.that.__zoom = transform;
  15163. this.emit("zoom");
  15164. return this;
  15165. },
  15166. end: function() {
  15167. if (--this.active === 0) {
  15168. delete this.that.__zooming;
  15169. this.emit("end");
  15170. }
  15171. return this;
  15172. },
  15173. emit: function(type) {
  15174. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  15175. }
  15176. };
  15177. function wheeled() {
  15178. if (!filter.apply(this, arguments)) return;
  15179. var g = gesture(this, arguments),
  15180. t = this.__zoom,
  15181. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  15182. p = mouse(this);
  15183. // If the mouse is in the same location as before, reuse it.
  15184. // If there were recent wheel events, reset the wheel idle timeout.
  15185. if (g.wheel) {
  15186. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  15187. g.mouse[1] = t.invert(g.mouse[0] = p);
  15188. }
  15189. clearTimeout(g.wheel);
  15190. }
  15191. // If this wheel event won’t trigger a transform change, ignore it.
  15192. else if (t.k === k) return;
  15193. // Otherwise, capture the mouse point and location at the start.
  15194. else {
  15195. g.mouse = [p, t.invert(p)];
  15196. interrupt(this);
  15197. g.start();
  15198. }
  15199. noevent$2();
  15200. g.wheel = setTimeout(wheelidled, wheelDelay);
  15201. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  15202. function wheelidled() {
  15203. g.wheel = null;
  15204. g.end();
  15205. }
  15206. }
  15207. function mousedowned() {
  15208. if (touchending || !filter.apply(this, arguments)) return;
  15209. var g = gesture(this, arguments, true),
  15210. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  15211. p = mouse(this),
  15212. x0 = exports.event.clientX,
  15213. y0 = exports.event.clientY;
  15214. dragDisable(exports.event.view);
  15215. nopropagation$2();
  15216. g.mouse = [p, this.__zoom.invert(p)];
  15217. interrupt(this);
  15218. g.start();
  15219. function mousemoved() {
  15220. noevent$2();
  15221. if (!g.moved) {
  15222. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  15223. g.moved = dx * dx + dy * dy > clickDistance2;
  15224. }
  15225. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  15226. }
  15227. function mouseupped() {
  15228. v.on("mousemove.zoom mouseup.zoom", null);
  15229. yesdrag(exports.event.view, g.moved);
  15230. noevent$2();
  15231. g.end();
  15232. }
  15233. }
  15234. function dblclicked() {
  15235. if (!filter.apply(this, arguments)) return;
  15236. var t0 = this.__zoom,
  15237. p0 = mouse(this),
  15238. p1 = t0.invert(p0),
  15239. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  15240. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  15241. noevent$2();
  15242. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  15243. else select(this).call(zoom.transform, t1);
  15244. }
  15245. function touchstarted() {
  15246. if (!filter.apply(this, arguments)) return;
  15247. var touches = exports.event.touches,
  15248. n = touches.length,
  15249. g = gesture(this, arguments, exports.event.changedTouches.length === n),
  15250. started, i, t, p;
  15251. nopropagation$2();
  15252. for (i = 0; i < n; ++i) {
  15253. t = touches[i], p = touch(this, touches, t.identifier);
  15254. p = [p, this.__zoom.invert(p), t.identifier];
  15255. if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
  15256. else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
  15257. }
  15258. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  15259. if (started) {
  15260. if (g.taps < 2) touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  15261. interrupt(this);
  15262. g.start();
  15263. }
  15264. }
  15265. function touchmoved() {
  15266. if (!this.__zooming) return;
  15267. var g = gesture(this, arguments),
  15268. touches = exports.event.changedTouches,
  15269. n = touches.length, i, t, p, l;
  15270. noevent$2();
  15271. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  15272. g.taps = 0;
  15273. for (i = 0; i < n; ++i) {
  15274. t = touches[i], p = touch(this, touches, t.identifier);
  15275. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  15276. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  15277. }
  15278. t = g.that.__zoom;
  15279. if (g.touch1) {
  15280. var p0 = g.touch0[0], l0 = g.touch0[1],
  15281. p1 = g.touch1[0], l1 = g.touch1[1],
  15282. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  15283. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  15284. t = scale(t, Math.sqrt(dp / dl));
  15285. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  15286. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  15287. }
  15288. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  15289. else return;
  15290. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  15291. }
  15292. function touchended() {
  15293. if (!this.__zooming) return;
  15294. var g = gesture(this, arguments),
  15295. touches = exports.event.changedTouches,
  15296. n = touches.length, i, t;
  15297. nopropagation$2();
  15298. if (touchending) clearTimeout(touchending);
  15299. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  15300. for (i = 0; i < n; ++i) {
  15301. t = touches[i];
  15302. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  15303. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  15304. }
  15305. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  15306. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  15307. else {
  15308. g.end();
  15309. // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
  15310. if (g.taps === 2) {
  15311. var p = select(this).on("dblclick.zoom");
  15312. if (p) p.apply(this, arguments);
  15313. }
  15314. }
  15315. }
  15316. zoom.wheelDelta = function(_) {
  15317. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$d(+_), zoom) : wheelDelta;
  15318. };
  15319. zoom.filter = function(_) {
  15320. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$d(!!_), zoom) : filter;
  15321. };
  15322. zoom.touchable = function(_) {
  15323. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$d(!!_), zoom) : touchable;
  15324. };
  15325. zoom.extent = function(_) {
  15326. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$d([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  15327. };
  15328. zoom.scaleExtent = function(_) {
  15329. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  15330. };
  15331. zoom.translateExtent = function(_) {
  15332. 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]]];
  15333. };
  15334. zoom.constrain = function(_) {
  15335. return arguments.length ? (constrain = _, zoom) : constrain;
  15336. };
  15337. zoom.duration = function(_) {
  15338. return arguments.length ? (duration = +_, zoom) : duration;
  15339. };
  15340. zoom.interpolate = function(_) {
  15341. return arguments.length ? (interpolate = _, zoom) : interpolate;
  15342. };
  15343. zoom.on = function() {
  15344. var value = listeners.on.apply(listeners, arguments);
  15345. return value === listeners ? zoom : value;
  15346. };
  15347. zoom.clickDistance = function(_) {
  15348. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  15349. };
  15350. return zoom;
  15351. }
  15352. exports.FormatSpecifier = FormatSpecifier;
  15353. exports.active = active;
  15354. exports.arc = arc;
  15355. exports.area = area$3;
  15356. exports.areaRadial = areaRadial;
  15357. exports.ascending = ascending;
  15358. exports.autoType = autoType;
  15359. exports.axisBottom = axisBottom;
  15360. exports.axisLeft = axisLeft;
  15361. exports.axisRight = axisRight;
  15362. exports.axisTop = axisTop;
  15363. exports.bisect = bisectRight;
  15364. exports.bisectLeft = bisectLeft;
  15365. exports.bisectRight = bisectRight;
  15366. exports.bisector = bisector;
  15367. exports.blob = blob;
  15368. exports.brush = brush;
  15369. exports.brushSelection = brushSelection;
  15370. exports.brushX = brushX;
  15371. exports.brushY = brushY;
  15372. exports.buffer = buffer;
  15373. exports.chord = chord;
  15374. exports.clientPoint = point;
  15375. exports.cluster = cluster;
  15376. exports.color = color;
  15377. exports.contourDensity = density;
  15378. exports.contours = contours;
  15379. exports.create = create;
  15380. exports.creator = creator;
  15381. exports.cross = cross;
  15382. exports.csv = csv$1;
  15383. exports.csvFormat = csvFormat;
  15384. exports.csvFormatBody = csvFormatBody;
  15385. exports.csvFormatRow = csvFormatRow;
  15386. exports.csvFormatRows = csvFormatRows;
  15387. exports.csvFormatValue = csvFormatValue;
  15388. exports.csvParse = csvParse;
  15389. exports.csvParseRows = csvParseRows;
  15390. exports.cubehelix = cubehelix;
  15391. exports.curveBasis = basis$2;
  15392. exports.curveBasisClosed = basisClosed$1;
  15393. exports.curveBasisOpen = basisOpen;
  15394. exports.curveBundle = bundle;
  15395. exports.curveCardinal = cardinal;
  15396. exports.curveCardinalClosed = cardinalClosed;
  15397. exports.curveCardinalOpen = cardinalOpen;
  15398. exports.curveCatmullRom = catmullRom;
  15399. exports.curveCatmullRomClosed = catmullRomClosed;
  15400. exports.curveCatmullRomOpen = catmullRomOpen;
  15401. exports.curveLinear = curveLinear;
  15402. exports.curveLinearClosed = linearClosed;
  15403. exports.curveMonotoneX = monotoneX;
  15404. exports.curveMonotoneY = monotoneY;
  15405. exports.curveNatural = natural;
  15406. exports.curveStep = step;
  15407. exports.curveStepAfter = stepAfter;
  15408. exports.curveStepBefore = stepBefore;
  15409. exports.customEvent = customEvent;
  15410. exports.descending = descending;
  15411. exports.deviation = deviation;
  15412. exports.dispatch = dispatch;
  15413. exports.drag = drag;
  15414. exports.dragDisable = dragDisable;
  15415. exports.dragEnable = yesdrag;
  15416. exports.dsv = dsv;
  15417. exports.dsvFormat = dsvFormat;
  15418. exports.easeBack = backInOut;
  15419. exports.easeBackIn = backIn;
  15420. exports.easeBackInOut = backInOut;
  15421. exports.easeBackOut = backOut;
  15422. exports.easeBounce = bounceOut;
  15423. exports.easeBounceIn = bounceIn;
  15424. exports.easeBounceInOut = bounceInOut;
  15425. exports.easeBounceOut = bounceOut;
  15426. exports.easeCircle = circleInOut;
  15427. exports.easeCircleIn = circleIn;
  15428. exports.easeCircleInOut = circleInOut;
  15429. exports.easeCircleOut = circleOut;
  15430. exports.easeCubic = cubicInOut;
  15431. exports.easeCubicIn = cubicIn;
  15432. exports.easeCubicInOut = cubicInOut;
  15433. exports.easeCubicOut = cubicOut;
  15434. exports.easeElastic = elasticOut;
  15435. exports.easeElasticIn = elasticIn;
  15436. exports.easeElasticInOut = elasticInOut;
  15437. exports.easeElasticOut = elasticOut;
  15438. exports.easeExp = expInOut;
  15439. exports.easeExpIn = expIn;
  15440. exports.easeExpInOut = expInOut;
  15441. exports.easeExpOut = expOut;
  15442. exports.easeLinear = linear$1;
  15443. exports.easePoly = polyInOut;
  15444. exports.easePolyIn = polyIn;
  15445. exports.easePolyInOut = polyInOut;
  15446. exports.easePolyOut = polyOut;
  15447. exports.easeQuad = quadInOut;
  15448. exports.easeQuadIn = quadIn;
  15449. exports.easeQuadInOut = quadInOut;
  15450. exports.easeQuadOut = quadOut;
  15451. exports.easeSin = sinInOut;
  15452. exports.easeSinIn = sinIn;
  15453. exports.easeSinInOut = sinInOut;
  15454. exports.easeSinOut = sinOut;
  15455. exports.entries = entries;
  15456. exports.extent = extent;
  15457. exports.forceCenter = center$1;
  15458. exports.forceCollide = collide;
  15459. exports.forceLink = link;
  15460. exports.forceManyBody = manyBody;
  15461. exports.forceRadial = radial;
  15462. exports.forceSimulation = simulation;
  15463. exports.forceX = x$2;
  15464. exports.forceY = y$2;
  15465. exports.formatDefaultLocale = defaultLocale;
  15466. exports.formatLocale = formatLocale;
  15467. exports.formatSpecifier = formatSpecifier;
  15468. exports.geoAlbers = albers;
  15469. exports.geoAlbersUsa = albersUsa;
  15470. exports.geoArea = area$1;
  15471. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  15472. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  15473. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  15474. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  15475. exports.geoBounds = bounds;
  15476. exports.geoCentroid = centroid;
  15477. exports.geoCircle = circle;
  15478. exports.geoClipAntimeridian = clipAntimeridian;
  15479. exports.geoClipCircle = clipCircle;
  15480. exports.geoClipExtent = extent$1;
  15481. exports.geoClipRectangle = clipRectangle;
  15482. exports.geoConicConformal = conicConformal;
  15483. exports.geoConicConformalRaw = conicConformalRaw;
  15484. exports.geoConicEqualArea = conicEqualArea;
  15485. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  15486. exports.geoConicEquidistant = conicEquidistant;
  15487. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  15488. exports.geoContains = contains$1;
  15489. exports.geoDistance = distance;
  15490. exports.geoEqualEarth = equalEarth;
  15491. exports.geoEqualEarthRaw = equalEarthRaw;
  15492. exports.geoEquirectangular = equirectangular;
  15493. exports.geoEquirectangularRaw = equirectangularRaw;
  15494. exports.geoGnomonic = gnomonic;
  15495. exports.geoGnomonicRaw = gnomonicRaw;
  15496. exports.geoGraticule = graticule;
  15497. exports.geoGraticule10 = graticule10;
  15498. exports.geoIdentity = identity$5;
  15499. exports.geoInterpolate = interpolate$1;
  15500. exports.geoLength = length$1;
  15501. exports.geoMercator = mercator;
  15502. exports.geoMercatorRaw = mercatorRaw;
  15503. exports.geoNaturalEarth1 = naturalEarth1;
  15504. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  15505. exports.geoOrthographic = orthographic;
  15506. exports.geoOrthographicRaw = orthographicRaw;
  15507. exports.geoPath = index$1;
  15508. exports.geoProjection = projection;
  15509. exports.geoProjectionMutator = projectionMutator;
  15510. exports.geoRotation = rotation;
  15511. exports.geoStereographic = stereographic;
  15512. exports.geoStereographicRaw = stereographicRaw;
  15513. exports.geoStream = geoStream;
  15514. exports.geoTransform = transform;
  15515. exports.geoTransverseMercator = transverseMercator;
  15516. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  15517. exports.gray = gray;
  15518. exports.hcl = hcl;
  15519. exports.hierarchy = hierarchy;
  15520. exports.histogram = histogram;
  15521. exports.hsl = hsl;
  15522. exports.html = html;
  15523. exports.image = image;
  15524. exports.interpolate = interpolateValue;
  15525. exports.interpolateArray = array$1;
  15526. exports.interpolateBasis = basis$1;
  15527. exports.interpolateBasisClosed = basisClosed;
  15528. exports.interpolateBlues = Blues;
  15529. exports.interpolateBrBG = BrBG;
  15530. exports.interpolateBuGn = BuGn;
  15531. exports.interpolateBuPu = BuPu;
  15532. exports.interpolateCividis = cividis;
  15533. exports.interpolateCool = cool;
  15534. exports.interpolateCubehelix = cubehelix$2;
  15535. exports.interpolateCubehelixDefault = cubehelix$3;
  15536. exports.interpolateCubehelixLong = cubehelixLong;
  15537. exports.interpolateDate = date;
  15538. exports.interpolateDiscrete = discrete;
  15539. exports.interpolateGnBu = GnBu;
  15540. exports.interpolateGreens = Greens;
  15541. exports.interpolateGreys = Greys;
  15542. exports.interpolateHcl = hcl$2;
  15543. exports.interpolateHclLong = hclLong;
  15544. exports.interpolateHsl = hsl$2;
  15545. exports.interpolateHslLong = hslLong;
  15546. exports.interpolateHue = hue$1;
  15547. exports.interpolateInferno = inferno;
  15548. exports.interpolateLab = lab$1;
  15549. exports.interpolateMagma = magma;
  15550. exports.interpolateNumber = interpolateNumber;
  15551. exports.interpolateNumberArray = numberArray;
  15552. exports.interpolateObject = object;
  15553. exports.interpolateOrRd = OrRd;
  15554. exports.interpolateOranges = Oranges;
  15555. exports.interpolatePRGn = PRGn;
  15556. exports.interpolatePiYG = PiYG;
  15557. exports.interpolatePlasma = plasma;
  15558. exports.interpolatePuBu = PuBu;
  15559. exports.interpolatePuBuGn = PuBuGn;
  15560. exports.interpolatePuOr = PuOr;
  15561. exports.interpolatePuRd = PuRd;
  15562. exports.interpolatePurples = Purples;
  15563. exports.interpolateRainbow = rainbow;
  15564. exports.interpolateRdBu = RdBu;
  15565. exports.interpolateRdGy = RdGy;
  15566. exports.interpolateRdPu = RdPu;
  15567. exports.interpolateRdYlBu = RdYlBu;
  15568. exports.interpolateRdYlGn = RdYlGn;
  15569. exports.interpolateReds = Reds;
  15570. exports.interpolateRgb = interpolateRgb;
  15571. exports.interpolateRgbBasis = rgbBasis;
  15572. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  15573. exports.interpolateRound = interpolateRound;
  15574. exports.interpolateSinebow = sinebow;
  15575. exports.interpolateSpectral = Spectral;
  15576. exports.interpolateString = interpolateString;
  15577. exports.interpolateTransformCss = interpolateTransformCss;
  15578. exports.interpolateTransformSvg = interpolateTransformSvg;
  15579. exports.interpolateTurbo = turbo;
  15580. exports.interpolateViridis = viridis;
  15581. exports.interpolateWarm = warm;
  15582. exports.interpolateYlGn = YlGn;
  15583. exports.interpolateYlGnBu = YlGnBu;
  15584. exports.interpolateYlOrBr = YlOrBr;
  15585. exports.interpolateYlOrRd = YlOrRd;
  15586. exports.interpolateZoom = interpolateZoom;
  15587. exports.interrupt = interrupt;
  15588. exports.interval = interval$1;
  15589. exports.isoFormat = formatIso;
  15590. exports.isoParse = parseIso;
  15591. exports.json = json;
  15592. exports.keys = keys;
  15593. exports.lab = lab;
  15594. exports.lch = lch;
  15595. exports.line = line;
  15596. exports.lineRadial = lineRadial$1;
  15597. exports.linkHorizontal = linkHorizontal;
  15598. exports.linkRadial = linkRadial;
  15599. exports.linkVertical = linkVertical;
  15600. exports.local = local;
  15601. exports.map = map$1;
  15602. exports.matcher = matcher;
  15603. exports.max = max;
  15604. exports.mean = mean;
  15605. exports.median = median;
  15606. exports.merge = merge;
  15607. exports.min = min;
  15608. exports.mouse = mouse;
  15609. exports.namespace = namespace;
  15610. exports.namespaces = namespaces;
  15611. exports.nest = nest;
  15612. exports.now = now;
  15613. exports.pack = index$2;
  15614. exports.packEnclose = enclose;
  15615. exports.packSiblings = siblings;
  15616. exports.pairs = pairs;
  15617. exports.partition = partition;
  15618. exports.path = path;
  15619. exports.permute = permute;
  15620. exports.pie = pie;
  15621. exports.piecewise = piecewise;
  15622. exports.pointRadial = pointRadial;
  15623. exports.polygonArea = area$2;
  15624. exports.polygonCentroid = centroid$1;
  15625. exports.polygonContains = contains$2;
  15626. exports.polygonHull = hull;
  15627. exports.polygonLength = length$2;
  15628. exports.precisionFixed = precisionFixed;
  15629. exports.precisionPrefix = precisionPrefix;
  15630. exports.precisionRound = precisionRound;
  15631. exports.quadtree = quadtree;
  15632. exports.quantile = threshold;
  15633. exports.quantize = quantize;
  15634. exports.radialArea = areaRadial;
  15635. exports.radialLine = lineRadial$1;
  15636. exports.randomBates = bates;
  15637. exports.randomExponential = exponential$1;
  15638. exports.randomIrwinHall = irwinHall;
  15639. exports.randomLogNormal = logNormal;
  15640. exports.randomNormal = normal;
  15641. exports.randomUniform = uniform;
  15642. exports.range = sequence;
  15643. exports.rgb = rgb;
  15644. exports.ribbon = ribbon;
  15645. exports.scaleBand = band;
  15646. exports.scaleDiverging = diverging;
  15647. exports.scaleDivergingLog = divergingLog;
  15648. exports.scaleDivergingPow = divergingPow;
  15649. exports.scaleDivergingSqrt = divergingSqrt;
  15650. exports.scaleDivergingSymlog = divergingSymlog;
  15651. exports.scaleIdentity = identity$7;
  15652. exports.scaleImplicit = implicit;
  15653. exports.scaleLinear = linear$2;
  15654. exports.scaleLog = log$1;
  15655. exports.scaleOrdinal = ordinal;
  15656. exports.scalePoint = point$1;
  15657. exports.scalePow = pow$1;
  15658. exports.scaleQuantile = quantile;
  15659. exports.scaleQuantize = quantize$1;
  15660. exports.scaleSequential = sequential;
  15661. exports.scaleSequentialLog = sequentialLog;
  15662. exports.scaleSequentialPow = sequentialPow;
  15663. exports.scaleSequentialQuantile = sequentialQuantile;
  15664. exports.scaleSequentialSqrt = sequentialSqrt;
  15665. exports.scaleSequentialSymlog = sequentialSymlog;
  15666. exports.scaleSqrt = sqrt$1;
  15667. exports.scaleSymlog = symlog;
  15668. exports.scaleThreshold = threshold$1;
  15669. exports.scaleTime = time;
  15670. exports.scaleUtc = utcTime;
  15671. exports.scan = scan;
  15672. exports.schemeAccent = Accent;
  15673. exports.schemeBlues = scheme$l;
  15674. exports.schemeBrBG = scheme;
  15675. exports.schemeBuGn = scheme$9;
  15676. exports.schemeBuPu = scheme$a;
  15677. exports.schemeCategory10 = category10;
  15678. exports.schemeDark2 = Dark2;
  15679. exports.schemeGnBu = scheme$b;
  15680. exports.schemeGreens = scheme$m;
  15681. exports.schemeGreys = scheme$n;
  15682. exports.schemeOrRd = scheme$c;
  15683. exports.schemeOranges = scheme$q;
  15684. exports.schemePRGn = scheme$1;
  15685. exports.schemePaired = Paired;
  15686. exports.schemePastel1 = Pastel1;
  15687. exports.schemePastel2 = Pastel2;
  15688. exports.schemePiYG = scheme$2;
  15689. exports.schemePuBu = scheme$e;
  15690. exports.schemePuBuGn = scheme$d;
  15691. exports.schemePuOr = scheme$3;
  15692. exports.schemePuRd = scheme$f;
  15693. exports.schemePurples = scheme$o;
  15694. exports.schemeRdBu = scheme$4;
  15695. exports.schemeRdGy = scheme$5;
  15696. exports.schemeRdPu = scheme$g;
  15697. exports.schemeRdYlBu = scheme$6;
  15698. exports.schemeRdYlGn = scheme$7;
  15699. exports.schemeReds = scheme$p;
  15700. exports.schemeSet1 = Set1;
  15701. exports.schemeSet2 = Set2;
  15702. exports.schemeSet3 = Set3;
  15703. exports.schemeSpectral = scheme$8;
  15704. exports.schemeTableau10 = Tableau10;
  15705. exports.schemeYlGn = scheme$i;
  15706. exports.schemeYlGnBu = scheme$h;
  15707. exports.schemeYlOrBr = scheme$j;
  15708. exports.schemeYlOrRd = scheme$k;
  15709. exports.select = select;
  15710. exports.selectAll = selectAll;
  15711. exports.selection = selection;
  15712. exports.selector = selector;
  15713. exports.selectorAll = selectorAll;
  15714. exports.set = set$2;
  15715. exports.shuffle = shuffle;
  15716. exports.stack = stack;
  15717. exports.stackOffsetDiverging = diverging$1;
  15718. exports.stackOffsetExpand = expand;
  15719. exports.stackOffsetNone = none$1;
  15720. exports.stackOffsetSilhouette = silhouette;
  15721. exports.stackOffsetWiggle = wiggle;
  15722. exports.stackOrderAppearance = appearance;
  15723. exports.stackOrderAscending = ascending$3;
  15724. exports.stackOrderDescending = descending$2;
  15725. exports.stackOrderInsideOut = insideOut;
  15726. exports.stackOrderNone = none$2;
  15727. exports.stackOrderReverse = reverse;
  15728. exports.stratify = stratify;
  15729. exports.style = styleValue;
  15730. exports.sum = sum;
  15731. exports.svg = svg;
  15732. exports.symbol = symbol;
  15733. exports.symbolCircle = circle$2;
  15734. exports.symbolCross = cross$2;
  15735. exports.symbolDiamond = diamond;
  15736. exports.symbolSquare = square;
  15737. exports.symbolStar = star;
  15738. exports.symbolTriangle = triangle;
  15739. exports.symbolWye = wye;
  15740. exports.symbols = symbols;
  15741. exports.text = text;
  15742. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  15743. exports.thresholdScott = scott;
  15744. exports.thresholdSturges = thresholdSturges;
  15745. exports.tickFormat = tickFormat;
  15746. exports.tickIncrement = tickIncrement;
  15747. exports.tickStep = tickStep;
  15748. exports.ticks = ticks;
  15749. exports.timeDay = day;
  15750. exports.timeDays = days;
  15751. exports.timeFormatDefaultLocale = defaultLocale$1;
  15752. exports.timeFormatLocale = formatLocale$1;
  15753. exports.timeFriday = friday;
  15754. exports.timeFridays = fridays;
  15755. exports.timeHour = hour;
  15756. exports.timeHours = hours;
  15757. exports.timeInterval = newInterval;
  15758. exports.timeMillisecond = millisecond;
  15759. exports.timeMilliseconds = milliseconds;
  15760. exports.timeMinute = minute;
  15761. exports.timeMinutes = minutes;
  15762. exports.timeMonday = monday;
  15763. exports.timeMondays = mondays;
  15764. exports.timeMonth = month;
  15765. exports.timeMonths = months;
  15766. exports.timeSaturday = saturday;
  15767. exports.timeSaturdays = saturdays;
  15768. exports.timeSecond = second;
  15769. exports.timeSeconds = seconds;
  15770. exports.timeSunday = sunday;
  15771. exports.timeSundays = sundays;
  15772. exports.timeThursday = thursday;
  15773. exports.timeThursdays = thursdays;
  15774. exports.timeTuesday = tuesday;
  15775. exports.timeTuesdays = tuesdays;
  15776. exports.timeWednesday = wednesday;
  15777. exports.timeWednesdays = wednesdays;
  15778. exports.timeWeek = sunday;
  15779. exports.timeWeeks = sundays;
  15780. exports.timeYear = year;
  15781. exports.timeYears = years;
  15782. exports.timeout = timeout$1;
  15783. exports.timer = timer;
  15784. exports.timerFlush = timerFlush;
  15785. exports.touch = touch;
  15786. exports.touches = touches;
  15787. exports.transition = transition;
  15788. exports.transpose = transpose;
  15789. exports.tree = tree;
  15790. exports.treemap = index$3;
  15791. exports.treemapBinary = binary;
  15792. exports.treemapDice = treemapDice;
  15793. exports.treemapResquarify = resquarify;
  15794. exports.treemapSlice = treemapSlice;
  15795. exports.treemapSliceDice = sliceDice;
  15796. exports.treemapSquarify = squarify;
  15797. exports.tsv = tsv$1;
  15798. exports.tsvFormat = tsvFormat;
  15799. exports.tsvFormatBody = tsvFormatBody;
  15800. exports.tsvFormatRow = tsvFormatRow;
  15801. exports.tsvFormatRows = tsvFormatRows;
  15802. exports.tsvFormatValue = tsvFormatValue;
  15803. exports.tsvParse = tsvParse;
  15804. exports.tsvParseRows = tsvParseRows;
  15805. exports.utcDay = utcDay;
  15806. exports.utcDays = utcDays;
  15807. exports.utcFriday = utcFriday;
  15808. exports.utcFridays = utcFridays;
  15809. exports.utcHour = utcHour;
  15810. exports.utcHours = utcHours;
  15811. exports.utcMillisecond = millisecond;
  15812. exports.utcMilliseconds = milliseconds;
  15813. exports.utcMinute = utcMinute;
  15814. exports.utcMinutes = utcMinutes;
  15815. exports.utcMonday = utcMonday;
  15816. exports.utcMondays = utcMondays;
  15817. exports.utcMonth = utcMonth;
  15818. exports.utcMonths = utcMonths;
  15819. exports.utcSaturday = utcSaturday;
  15820. exports.utcSaturdays = utcSaturdays;
  15821. exports.utcSecond = second;
  15822. exports.utcSeconds = seconds;
  15823. exports.utcSunday = utcSunday;
  15824. exports.utcSundays = utcSundays;
  15825. exports.utcThursday = utcThursday;
  15826. exports.utcThursdays = utcThursdays;
  15827. exports.utcTuesday = utcTuesday;
  15828. exports.utcTuesdays = utcTuesdays;
  15829. exports.utcWednesday = utcWednesday;
  15830. exports.utcWednesdays = utcWednesdays;
  15831. exports.utcWeek = utcSunday;
  15832. exports.utcWeeks = utcSundays;
  15833. exports.utcYear = utcYear;
  15834. exports.utcYears = utcYears;
  15835. exports.values = values;
  15836. exports.variance = variance;
  15837. exports.version = version;
  15838. exports.voronoi = voronoi;
  15839. exports.window = defaultView;
  15840. exports.xml = xml;
  15841. exports.zip = zip;
  15842. exports.zoom = zoom;
  15843. exports.zoomIdentity = identity$9;
  15844. exports.zoomTransform = transform$1;
  15845. Object.defineProperty(exports, '__esModule', { value: true });
  15846. }));